sonar fixes
diff --git a/src/main/java/org/apache/sling/pipes/AbstractInputStreamPipe.java b/src/main/java/org/apache/sling/pipes/AbstractInputStreamPipe.java index 6c2f790..bfb29b5 100644 --- a/src/main/java/org/apache/sling/pipes/AbstractInputStreamPipe.java +++ b/src/main/java/org/apache/sling/pipes/AbstractInputStreamPipe.java
@@ -42,7 +42,7 @@ public static final String REMOTE_START = "http"; - protected static final Pattern VALID_PATH = Pattern.compile("/([\\w\\d\\.-_]+/)+[\\w\\d\\.-_]+"); + protected static final Pattern VALID_PATH = Pattern.compile("/([\\w\\.\\-_]+/)+[\\w\\.\\-_]+"); public static final String BINDING_IS = "org.apache.sling.pipes.RequestInputStream";
diff --git a/src/main/java/org/apache/sling/pipes/OutputWriter.java b/src/main/java/org/apache/sling/pipes/OutputWriter.java index 9e22a70..ea734b1 100644 --- a/src/main/java/org/apache/sling/pipes/OutputWriter.java +++ b/src/main/java/org/apache/sling/pipes/OutputWriter.java
@@ -97,7 +97,7 @@ } String writerParam = request.getParameter(PARAM_WRITER); if (StringUtils.isNotBlank(writerParam)){ - customOutputs = stringToMap(writerParam, s -> PipeBindings.embedAsScript(s)); + customOutputs = stringToMap(writerParam, PipeBindings::embedAsScript); } setWriter(response.getWriter()); initResponse(response);
diff --git a/src/main/java/org/apache/sling/pipes/PipeBuilder.java b/src/main/java/org/apache/sling/pipes/PipeBuilder.java index 2ceed52..d36bfda 100644 --- a/src/main/java/org/apache/sling/pipes/PipeBuilder.java +++ b/src/main/java/org/apache/sling/pipes/PipeBuilder.java
@@ -217,6 +217,7 @@ */ @PipeExecutor(command = "$", resourceType = FindPipe.RESOURCE_TYPE, pipeClass = FindPipe.class, description = "find resource from the current, with the given expression as a parameter") + @SuppressWarnings("squid:S100") // we use that not very conventionnal name to match jQuery well known constant PipeBuilder $(String expr); /**
diff --git a/src/main/java/org/apache/sling/pipes/internal/AuthorizablePipe.java b/src/main/java/org/apache/sling/pipes/internal/AuthorizablePipe.java index 9fde30a..1107c34 100644 --- a/src/main/java/org/apache/sling/pipes/internal/AuthorizablePipe.java +++ b/src/main/java/org/apache/sling/pipes/internal/AuthorizablePipe.java
@@ -91,13 +91,13 @@ if (auth != null) { logger.debug("Retrieved authorizable {}", auth.getID()); if (StringUtils.isNotBlank(addToGroup)) { - addToGroup(auth); + addAuthorizableToGroup(auth); } if (StringUtils.isNotBlank(addMembers)) { - addMembers(auth); + addMembersToAuthorizable(auth); } if (bindMembers) { - bindMembers(auth); + bindMembersToAuthorizable(auth); } Resource resource = resolver.getResource(auth.getPath()); return Collections.singleton(resource).iterator(); @@ -140,7 +140,7 @@ * Add current authorizable to configured addToGroup expression (should resolve as a group id) * @param auth authorizable to add to the group */ - void addToGroup(Authorizable auth){ + void addAuthorizableToGroup(Authorizable auth){ try { //if addToGroup is set to true, we try to find the corresponding //group and to add current auth to it as a member @@ -161,7 +161,7 @@ * Add to current authorizable (that should be a group) the configured members in addMembers expression * @param auth group to which members should be added */ - void addMembers(Authorizable auth) { + void addMembersToAuthorizable(Authorizable auth) { try { if (auth.isGroup()) { Group group = (Group)auth; @@ -191,7 +191,7 @@ * add current group's members to the bindings * @param auth group whose members should be bound in the pipe bindings */ - void bindMembers(Authorizable auth){ + void bindMembersToAuthorizable(Authorizable auth){ try { if (auth.isGroup()){ Group group = (Group)auth;
diff --git a/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java b/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java index 366a16a..32fc28a 100644 --- a/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java +++ b/src/main/java/org/apache/sling/pipes/internal/CommandExecutorImpl.java
@@ -184,49 +184,39 @@ return cmds; } - @Override - protected void doPost(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws IOException { - String currentCommand = null; + protected void executeCommands(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws IOException { PrintWriter writer = response.getWriter(); + String currentCommand = null; try { - if (request.getParameter(REQ_PARAM_HELP) != null) { - writer.println(help()); - } else { - ResourceResolver resolver = request.getResourceResolver(); - Map<String, Object> bindings = plumber.getBindingsFromRequest(request, true); - List<String> cmds = getCommandList(request, bindings); - if (cmds.isEmpty()) { - writer.println("No command to execute!"); - } - short idxLine = 0; - - OutputWriter pipeWriter = getWriter(request, response); - if (pipeWriter == null) { - pipeWriter = new NopWriter(); - } - pipeWriter.disableAutoClose(); - pipeWriter.init(request, response); - for (String command : cmds) { - if (StringUtils.isNotBlank(command)) { - currentCommand = command; - PipeBuilder pipeBuilder = parse(resolver, command); - Pipe pipe = pipeBuilder.build(); - bindings.put(CMD_LINE_PREFIX + idxLine++, pipe.getResource().getPath()); - ModifiableValueMap root = pipe.getResource().adaptTo(ModifiableValueMap.class); - root.put(PN_DESCRIPTION, command); - plumber.execute(resolver, pipe, bindings, pipeWriter, true); - } - } - pipeWriter.ends(); + ResourceResolver resolver = request.getResourceResolver(); + Map<String, Object> bindings = plumber.getBindingsFromRequest(request, true); + List<String> cmds = getCommandList(request, bindings); + if (cmds.isEmpty()) { + writer.println("No command to execute!"); } - writer.println(""); - response.setStatus(SC_OK); - } - catch (AccessControlException e) { - response.setStatus(SC_FORBIDDEN); - response.sendError(SC_FORBIDDEN); - } - catch (IllegalAccessException | InvocationTargetException e) { + short idxLine = 0; + + OutputWriter pipeWriter = getWriter(request, response); + if (pipeWriter == null) { + pipeWriter = new NopWriter(); + } + pipeWriter.disableAutoClose(); + pipeWriter.init(request, response); + for (String command : cmds) { + if (StringUtils.isNotBlank(command)) { + currentCommand = command; + PipeBuilder pipeBuilder = parse(resolver, command); + Pipe pipe = pipeBuilder.build(); + bindings.put(CMD_LINE_PREFIX + idxLine++, pipe.getResource().getPath()); + ModifiableValueMap root = pipe.getResource().adaptTo(ModifiableValueMap.class); + if (root != null) { + root.put(PN_DESCRIPTION, command); + } + plumber.execute(resolver, pipe, bindings, pipeWriter, true); + } + } + pipeWriter.ends(); + } catch (IllegalAccessException | InvocationTargetException e) { writer.println("Error executing " + currentCommand); e.printStackTrace(writer); response.setStatus(SC_INTERNAL_SERVER_ERROR); @@ -243,6 +233,24 @@ } @Override + protected void doPost(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws IOException { + PrintWriter writer = response.getWriter(); + try { + if (request.getParameter(REQ_PARAM_HELP) != null) { + writer.println(help()); + } else { + executeCommands(request, response); + } + writer.println(""); + response.setStatus(SC_OK); + } + catch (AccessControlException e) { + response.setStatus(SC_FORBIDDEN); + response.sendError(SC_FORBIDDEN); + } + } + + @Override public ExecutionResult execute(ResourceResolver resolver, String path, String... optionTokens) { Resource resource = resolver.getResource(path); if (resource == null){
diff --git a/src/main/java/org/apache/sling/pipes/internal/ContainerPipe.java b/src/main/java/org/apache/sling/pipes/internal/ContainerPipe.java index fce3d7a..a2de937 100644 --- a/src/main/java/org/apache/sling/pipes/internal/ContainerPipe.java +++ b/src/main/java/org/apache/sling/pipes/internal/ContainerPipe.java
@@ -42,9 +42,8 @@ * @param plumber plumber * @param resource container's configuration resource * @param upperBindings pipe bindings - * @throws Exception bad configuration handling */ - public ContainerPipe(Plumber plumber, Resource resource, PipeBindings upperBindings) throws Exception{ + public ContainerPipe(Plumber plumber, Resource resource, PipeBindings upperBindings) { super(plumber, resource, upperBindings); }
diff --git a/src/main/java/org/apache/sling/pipes/internal/CsvWriter.java b/src/main/java/org/apache/sling/pipes/internal/CsvWriter.java index 6cc243d..7109366 100644 --- a/src/main/java/org/apache/sling/pipes/internal/CsvWriter.java +++ b/src/main/java/org/apache/sling/pipes/internal/CsvWriter.java
@@ -16,7 +16,6 @@ */ package org.apache.sling.pipes.internal; -import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.Resource;
diff --git a/src/main/java/org/apache/sling/pipes/internal/GogoCommands.java b/src/main/java/org/apache/sling/pipes/internal/GogoCommands.java index fb64e6d..833685f 100644 --- a/src/main/java/org/apache/sling/pipes/internal/GogoCommands.java +++ b/src/main/java/org/apache/sling/pipes/internal/GogoCommands.java
@@ -59,7 +59,8 @@ @Reference Plumber plumber; - + + @SuppressWarnings("squid:S106") // we want here output of the error PrintStream print() { return System.out; }
diff --git a/src/main/java/org/apache/sling/pipes/internal/JsonWriter.java b/src/main/java/org/apache/sling/pipes/internal/JsonWriter.java index f4451ca..fe4d779 100644 --- a/src/main/java/org/apache/sling/pipes/internal/JsonWriter.java +++ b/src/main/java/org/apache/sling/pipes/internal/JsonWriter.java
@@ -16,18 +16,13 @@ */ package org.apache.sling.pipes.internal; -import org.apache.commons.lang3.StringUtils; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; import org.apache.sling.api.resource.Resource; import org.apache.sling.pipes.OutputWriter; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.json.Json; -import javax.json.JsonValue; import javax.json.stream.JsonGenerator; -import javax.script.ScriptException; import java.io.StringWriter; import java.util.Map; @@ -35,8 +30,6 @@ * default output writer, that outputs JSON with size and output resources' path */ public class JsonWriter extends OutputWriter { - private static final Logger LOGGER = LoggerFactory.getLogger(JsonWriter.class); - protected JsonGenerator jsonGenerator; public static final String JSON_EXTENSION = "json";
diff --git a/src/main/java/org/apache/sling/pipes/internal/PackagePipe.java b/src/main/java/org/apache/sling/pipes/internal/PackagePipe.java index 368f1da..50afd86 100644 --- a/src/main/java/org/apache/sling/pipes/internal/PackagePipe.java +++ b/src/main/java/org/apache/sling/pipes/internal/PackagePipe.java
@@ -69,9 +69,8 @@ * @param plumber plumber * @param resource configuration resource * @param upperBindings super pipe's bindings - * @throws Exception in case configuration is not working */ - public PackagePipe(Plumber plumber, Resource resource, PipeBindings upperBindings) throws Exception { + public PackagePipe(Plumber plumber, Resource resource, PipeBindings upperBindings) { super(plumber, resource, upperBindings); assemble = properties.get(PN_ASSEMBLE, true); checkExistence = properties.get(PN_CHECKEXISTENCE, true);
diff --git a/src/main/java/org/apache/sling/pipes/internal/PathPipe.java b/src/main/java/org/apache/sling/pipes/internal/PathPipe.java index e51b476..aa328c1 100644 --- a/src/main/java/org/apache/sling/pipes/internal/PathPipe.java +++ b/src/main/java/org/apache/sling/pipes/internal/PathPipe.java
@@ -89,7 +89,7 @@ ResourceUtil.getOrCreateResource(resolver, path, resourceType, intermediateType, autosave); } Resource resource = resolver.getResource(path); - if (modified) { + if (modified && resource != null) { plumber.markWithJcrLastModified(this, resource); } output = Collections.singleton(resource).iterator();
diff --git a/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java b/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java index 2e1c948..354a35e 100644 --- a/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java +++ b/src/main/java/org/apache/sling/pipes/internal/PlumberImpl.java
@@ -146,9 +146,11 @@ int maxAge() default 31; @AttributeDefinition(description = "should add pipe path to updated properties") + @SuppressWarnings("squid:S100") // osgi convention boolean mark_pipe_path() default false; @AttributeDefinition(description = "schedule of purge process") + @SuppressWarnings("squid:S100") // osgi convention String scheduler_expression() default "0 0 12 */7 * ?"; } @@ -599,7 +601,7 @@ log.debug("starting removal of {}", resource); Resource parent = resource.getParent(); resource.getResourceResolver().delete(resource); - if (!parent.hasChildren() && !PIPES_REPOSITORY_PATH.equals(parent.getPath())) { + if (parent != null && !parent.hasChildren() && !PIPES_REPOSITORY_PATH.equals(parent.getPath())) { cleanResourceAndEmptyParents(parent); } } @@ -616,7 +618,7 @@ } }; visitor.accept(resolver.getResource(PIPES_REPOSITORY_PATH)); - if (pipesToRemove.size() > 0) { + if (!pipesToRemove.isEmpty()) { log.info("about to remove {} pipe instances", pipesToRemove.size()); for (String path : pipesToRemove) { cleanResourceAndEmptyParents(resolver.getResource(path));
diff --git a/src/main/java/org/apache/sling/pipes/internal/ShallowReferencePipe.java b/src/main/java/org/apache/sling/pipes/internal/ShallowReferencePipe.java index 0b0a0e1..5bb576c 100644 --- a/src/main/java/org/apache/sling/pipes/internal/ShallowReferencePipe.java +++ b/src/main/java/org/apache/sling/pipes/internal/ShallowReferencePipe.java
@@ -38,9 +38,11 @@ @Override public void before() { + //we don't want anything to be executed before } @Override public void after() { + //we don't want anything to be executed after } }
diff --git a/src/main/java/org/apache/sling/pipes/internal/slingquery/AbstractExpressionSlingQueryPipe.java b/src/main/java/org/apache/sling/pipes/internal/slingquery/AbstractExpressionSlingQueryPipe.java index 1ae9346..15436be 100644 --- a/src/main/java/org/apache/sling/pipes/internal/slingquery/AbstractExpressionSlingQueryPipe.java +++ b/src/main/java/org/apache/sling/pipes/internal/slingquery/AbstractExpressionSlingQueryPipe.java
@@ -28,7 +28,7 @@ */ public abstract class AbstractExpressionSlingQueryPipe extends AbstractSlingQueryPipe { Logger logger = LoggerFactory.getLogger(AbstractExpressionSlingQueryPipe.class); - public AbstractExpressionSlingQueryPipe(Plumber plumber, Resource resource, PipeBindings upperBindings) { + protected AbstractExpressionSlingQueryPipe(Plumber plumber, Resource resource, PipeBindings upperBindings) { super(plumber, resource, upperBindings); }
diff --git a/src/main/java/org/apache/sling/pipes/internal/slingquery/AbstractSlingQueryPipe.java b/src/main/java/org/apache/sling/pipes/internal/slingquery/AbstractSlingQueryPipe.java index a7d539e..a8d9a7e 100644 --- a/src/main/java/org/apache/sling/pipes/internal/slingquery/AbstractSlingQueryPipe.java +++ b/src/main/java/org/apache/sling/pipes/internal/slingquery/AbstractSlingQueryPipe.java
@@ -29,7 +29,7 @@ */ public abstract class AbstractSlingQueryPipe extends BasePipe { - public AbstractSlingQueryPipe(Plumber plumber, Resource resource, PipeBindings upperBindings) { + protected AbstractSlingQueryPipe(Plumber plumber, Resource resource, PipeBindings upperBindings) { super(plumber, resource, upperBindings); } @Override @@ -48,6 +48,7 @@ * generate outputs out of input resource and abstract query * @return output's resource iterator, empty in case input is null */ + @Override protected Iterator<Resource> computeOutput() { Resource resource = getInput(); if (resource != null) {