Skip to content

Commit

Permalink
chore(meta): get project to build and test
Browse files Browse the repository at this point in the history
  • Loading branch information
sabberworm committed Sep 27, 2024
1 parent b44aa16 commit c80e539
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 119 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ node_modules/

*.iml
/gradle.properties
/.idea/
108 changes: 108 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import com.cognifide.gradle.aem.bundle.tasks.bundle

plugins {
java
`maven-publish`
alias(libs.plugins.gap.bundle)
alias(libs.plugins.gap.pkg)
alias(libs.plugins.nebula)
alias(libs.plugins.quality)
alias(libs.plugins.cpd)
alias(libs.plugins.node)
}

group = "com.swisscom.aem.tools"

defaultTasks("check")

quality {
checkstyleVersion = libs.versions.checkstyle.get()
pmdVersion = libs.versions.pmd.get()
spotbugsVersion = libs.versions.spotbugs.get()
spotbugsEffort = "max" // min, less, more or max
spotbugsLevel = "low" // low, medium, high
}

afterEvaluate {
tasks.named("check") {
dependsOn("checkQualityMain")
}

dependencies {
add("spotbugsPlugins", libs.findsecbugs)
add("spotbugsPlugins", libs.sbContrib)
add("pmd", libs.pmd.ant)
add("pmd", libs.pmd.java)

// Spotbugs runtime annotations
add("compileOnly", libs.spotbugs.annotations)
}
}

tasks {
withType<JavaCompile> {
options.encoding = "UTF-8"
options.compilerArgs.add("-Xlint:all")
options.compilerArgs.add("-Xlint:-processing")
options.compilerArgs.add("-Xlint:-serial")
options.compilerArgs.add("-Werror")
}

test {
useJUnitPlatform()
}

javadoc {
options.encoding = "UTF-8"
}
}

java {
afterEvaluate {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
// Lombok
annotationProcessor(libs.lombok)
compileOnly(libs.lombok)

// AEM
compileOnly(libs.servlet)
compileOnly(libs.gson)
compileOnly(libs.apacheCommons.lang3)
compileOnly(libs.osgi.cmpn)
compileOnly(libs.jcr)
compileOnly(libs.spiCommons)
compileOnly(libs.sling.api)
compileOnly(libs.sling.annotations)

// Test framework
testImplementation(libs.junit)
testImplementation(libs.aemMock)
}
}

node {
version.set(libs.versions.node.get())
npmVersion.set(libs.versions.npm.get())
npmInstallCommand.set("ci")
download.set(true)
}

aem {
bundleEmbed(libs.apacheCommons.jexl, "org.apache.commons.jexl3.*", export = false)

tasks {
packageCompose {

}

withType<Jar> {
bundle {
javaPackage.set("${project.group}.jcrhopper")
}
}
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ dependencyResolutionManagement {
}
}

rootProject.name = "JCR Hopper"
rootProject.name = "jcr-hopper"
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import org.apache.sling.api.request.RequestParameterMap;
import org.apache.sling.api.resource.ResourceResolver;

import com.day.cq.wcm.api.PageManager;

/**
* The context for all portal scripts.
*
Expand Down Expand Up @@ -66,11 +64,4 @@ public interface PortalScriptContext {
* @return Resource Resolver
*/
ResourceResolver getResourceResolver();

/**
* Returns the page manager which is attached with the current session.
*
* @return PageManager
*/
PageManager getPageManager();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;

Expand All @@ -13,7 +14,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.ResourceResolver;

import com.google.common.collect.Sets;
import com.swisscom.aem.tools.jcrhopper.MyTask;
import com.swisscom.aem.tools.jcrhopper.api.PortalScript;
import com.swisscom.aem.tools.jcrhopper.api.PortalScriptContext;
Expand All @@ -26,7 +26,8 @@ public abstract class AbstractPortalScript implements PortalScript, PortalScript

public static final String PARAMETER_DRY_RUN = "dryRun";
private static final int DEFAULT_MAX_DURATION_IN_SECONDS = 60;
private static final Set<String> VALID_DRY_RUN_VALUES = Sets.newHashSet("true", "false", "on", "off");
private static final Set<String> VALID_DRY_RUN_VALUES = new HashSet<>(Arrays.asList("true", "false", "on", "off"));
private static final Set<String> IGNORED_SYSTEM_QUERY_PARAMS = new HashSet<>(Arrays.asList("run", "submit", ":cq_csrf_token"));

@Getter(AccessLevel.PROTECTED)
private final PortalScriptContext context;
Expand Down Expand Up @@ -86,7 +87,8 @@ public void process() throws Exception {
logParameters();
checkDryRunValue();
doProcess();
} finally {
}
finally {
MyTask.unregisterTaskName();
// Note: Risky function (MyTask.resetCancellation()) as a second task with the same class name may exist,
// instead of the intended task. But we accept that, as we assume that only one
Expand All @@ -100,10 +102,9 @@ public void process() throws Exception {
}

private void logParameters() {
final Set<String> ignoreParameters = Sets.newHashSet("run", "submit", ":cq_csrf_token");
context.getParameters().entrySet()
.stream()
.filter(e -> !ignoreParameters.contains(e.getKey()))
.filter(e -> !IGNORED_SYSTEM_QUERY_PARAMS.contains(e.getKey()))
.forEach(e -> info("Parameter %s: %s", e.getKey(), Arrays.toString(e.getValue())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

import java.io.PrintWriter;

import com.swisscom.aem.tools.jcrhopper.api.PortalScriptContext;
import com.swisscom.aem.tools.jcrhopper.api.PortalScriptOutputWriter;

import lombok.Getter;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.request.RequestParameterMap;
import org.apache.sling.api.resource.ResourceResolver;

import com.day.cq.wcm.api.PageManager;
import com.swisscom.aem.tools.jcrhopper.api.PortalScriptContext;
import com.swisscom.aem.tools.jcrhopper.api.PortalScriptOutputWriter;

/**
* Default portal script context configuration.
*
*/
public class DefaultPortalScriptContext implements PortalScriptContext {

Expand All @@ -25,9 +22,6 @@ public class DefaultPortalScriptContext implements PortalScriptContext {

private final SlingHttpServletRequest request;

@Getter
private final PageManager pageManager;

/**
* Creates a new portal script context with a servlet request as input and a writer for the output.
*
Expand All @@ -38,7 +32,6 @@ public DefaultPortalScriptContext(SlingHttpServletRequest request, PrintWriter w
this.request = request;
final LogLevel logLevel = LogLevel.fromString(request.getParameter("log"));
this.outputWriter = new DefaultPortalScriptOutput(writer, logLevel);
pageManager = getResourceResolver().adaptTo(PageManager.class);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse

if (isAbort(request)) {
handleAbort(context);
} else {
}
else {
executeOnetimerScript(response, context);
}
}
Expand Down Expand Up @@ -75,7 +76,8 @@ private void executeOnetimerScript(SlingHttpServletResponse response, PortalScri
final long duration = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS);
context.getOutputWriter().info("Successfully finished %s in %sms", SCRIPT_NAME, duration);

} catch (Exception e) {
}
catch (Exception e) {
logException(context, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import java.util.AbstractMap;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import com.google.common.collect.Sets;

@RequiredArgsConstructor
public class DerivedMap<K, V> implements Map<K, V> {
@NonNull
Expand Down Expand Up @@ -78,7 +77,10 @@ public void clear() {

@Override
public Set<K> keySet() {
return Sets.union(backing.keySet(), local.keySet());
final Set<K> result = new HashSet<>();
result.addAll(backing.keySet());
result.addAll(local.keySet());
return result;
}

@Override
Expand Down
Loading

0 comments on commit c80e539

Please sign in to comment.