sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From npelt...@apache.org
Subject [sling-org-apache-sling-pipes] branch master updated: SLING-7772 fix few sonar bugs
Date Tue, 30 Jun 2020 13:56:27 GMT
This is an automated email from the ASF dual-hosted git repository.

npeltier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-pipes.git


The following commit(s) were added to refs/heads/master by this push:
     new b970cb8  SLING-7772 fix few sonar bugs
b970cb8 is described below

commit b970cb80806245e47eb1cb3ab2ca7c144b442f8c
Author: Nicolas Peltier <peltier.nicolas@gmail.com>
AuthorDate: Tue Jun 30 15:56:10 2020 +0200

    SLING-7772 fix few sonar bugs
---
 pom.xml                                            | 23 +++++++++++-----------
 .../sling/pipes/AbstractInputStreamPipe.java       | 21 +++++++++++++++-----
 src/main/java/org/apache/sling/pipes/BasePipe.java |  8 +++++---
 .../java/org/apache/sling/pipes/PipeBindings.java  | 11 +++++------
 .../sling/pipes/internal/AuthorizablePipe.java     |  2 +-
 src/test/resources/simplelogger.properties         |  2 +-
 6 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7e4ddeb..b66079c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -195,12 +195,6 @@
       <scope>provided</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-text</artifactId>
-      <version>1.8</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
       <groupId>commons-collections</groupId>
       <artifactId>commons-collections</artifactId>
       <version>3.2.2</version>
@@ -259,6 +253,17 @@
       <version>2.14.0</version>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-jexl3</artifactId>
+      <version>3.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jetbrains</groupId>
+      <artifactId>annotations</artifactId>
+      <scope>provided</scope>
+    </dependency>
     <!-- testing -->
     <dependency>
       <groupId>junit</groupId>
@@ -374,11 +379,5 @@
       <version>2.4.15</version>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-jexl3</artifactId>
-      <version>3.0</version>
-      <scope>provided</scope>
-    </dependency>
   </dependencies>
 </project>
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/pipes/AbstractInputStreamPipe.java b/src/main/java/org/apache/sling/pipes/AbstractInputStreamPipe.java
index fe43cee..45c7a28 100644
--- a/src/main/java/org/apache/sling/pipes/AbstractInputStreamPipe.java
+++ b/src/main/java/org/apache/sling/pipes/AbstractInputStreamPipe.java
@@ -73,6 +73,14 @@ public abstract class AbstractInputStreamPipe extends BasePipe {
         client.getParams().setAuthenticationPreemptive(false);
     }
 
+    InputStream getInputStreamFromResource(String expr) {
+        Resource resource = resolver.getResource(expr);
+        if (resource != null) {
+            return resource.adaptTo(InputStream.class);
+        }
+        return null;
+    }
+
     InputStream getInputStream() throws Exception {
         String expr = getExpr();
         if (expr.startsWith(REMOTE_START)) {
@@ -88,11 +96,14 @@ public abstract class AbstractInputStreamPipe extends BasePipe {
                     return method.getResponseBodyAsStream();
                 }
             }
-        } else if (VALID_PATH.matcher(expr).find()
-                && resolver.getResource(expr) != null
-                && resolver.getResource(expr).adaptTo(InputStream.class) != null)
{
-            return resolver.getResource(expr).adaptTo(InputStream.class);
-        } else if (getBindings().getBindings().get(BINDING_IS) != null){
+        }
+        if (VALID_PATH.matcher(expr).find()) {
+            InputStream is = getInputStreamFromResource(expr);
+            if (is != null) {
+                return is;
+            }
+        }
+        if (getBindings().getBindings().get(BINDING_IS) != null) {
             return (InputStream)getBindings().getBindings().get(BINDING_IS);
         }
         return new ByteArrayInputStream(expr.getBytes(StandardCharsets.UTF_8));
diff --git a/src/main/java/org/apache/sling/pipes/BasePipe.java b/src/main/java/org/apache/sling/pipes/BasePipe.java
index 067c3ed..5b7c9fd 100644
--- a/src/main/java/org/apache/sling/pipes/BasePipe.java
+++ b/src/main/java/org/apache/sling/pipes/BasePipe.java
@@ -21,6 +21,8 @@ import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.api.resource.ValueMap;
 import org.apache.sling.pipes.internal.BindingProvider;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -101,9 +103,9 @@ public class BasePipe implements Pipe {
      * @param upperBindings already set bindings, can be null
      * @throws Exception in case configuration is not working
      */
-    public BasePipe(Plumber plumber, Resource resource, PipeBindings upperBindings) throws
Exception {
+    public BasePipe(@NotNull Plumber plumber, @NotNull Resource resource, @Nullable PipeBindings
upperBindings) throws Exception {
         this.resource = resource;
-        properties = resource.adaptTo(ValueMap.class);
+        properties = resource.getValueMap();
         resolver = resource.getResourceResolver();
         this.plumber = plumber;
         name = properties.get(PN_NAME, resource.getName());
@@ -119,7 +121,7 @@ public class BasePipe implements Pipe {
      * @param upperBindings
      * @throws ScriptException
      */
-    private void extractAdditionalBindings(Resource resource, PipeBindings upperBindings)
throws ScriptException {
+    private void extractAdditionalBindings(@NotNull Resource resource, @Nullable PipeBindings
upperBindings) throws ScriptException {
         bindings = upperBindings == null ? new PipeBindings(resource) : upperBindings;
         //additional bindings (global variables to use in child pipes expressions)
         Resource additionalBindings = resource.getChild(NN_ADDITIONALBINDINGS);
diff --git a/src/main/java/org/apache/sling/pipes/PipeBindings.java b/src/main/java/org/apache/sling/pipes/PipeBindings.java
index 075898c..4250088 100644
--- a/src/main/java/org/apache/sling/pipes/PipeBindings.java
+++ b/src/main/java/org/apache/sling/pipes/PipeBindings.java
@@ -21,6 +21,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceResolver;
 import org.apache.sling.pipes.internal.JxltEngine;
+import org.jetbrains.annotations.NotNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -85,13 +86,11 @@ public class PipeBindings {
      * @param resource pipe's configuration resource
      * @throws ScriptException in case scripts associated with the bindings are not assessable
      */
-    public PipeBindings(Resource resource) throws ScriptException {
+    public PipeBindings(@NotNull Resource resource) throws ScriptException {
     	//Setup script engines
-        if (resource.getChild(PN_ENGINE) != null) {
-            String engineName = resource.getChild(PN_ENGINE).adaptTo(String.class);
-            if (StringUtils.isNotBlank(engineName)) {
-                initializeScriptEngine(engineName);
-            }
+        String engineName = resource.getValueMap().get(PN_ENGINE, String.class);
+        if (StringUtils.isNotBlank(engineName)) {
+            initializeScriptEngine(engineName);
         }
     	
         //add path bindings where path.MyPipe will give MyPipe current resource path
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 0fd4779..940d3e0 100644
--- a/src/main/java/org/apache/sling/pipes/internal/AuthorizablePipe.java
+++ b/src/main/java/org/apache/sling/pipes/internal/AuthorizablePipe.java
@@ -79,7 +79,7 @@ public class AuthorizablePipe extends BasePipe {
         resolver = resource.getResourceResolver();
         userManager = resolver.adaptTo(UserManager.class);
         if (getConfiguration() != null) {
-            ValueMap properties = getConfiguration().adaptTo(ValueMap.class);
+            ValueMap properties = getConfiguration().getValueMap();
             createGroup = properties.get(PN_CREATEGROUP, false);
             bindMembers = properties.get(PN_BINDMEMBERS, false);
             addToGroup = properties.get(PN_ADDTOGROUP, String.class);
diff --git a/src/test/resources/simplelogger.properties b/src/test/resources/simplelogger.properties
index 5b30b3d..568efd8 100644
--- a/src/test/resources/simplelogger.properties
+++ b/src/test/resources/simplelogger.properties
@@ -18,4 +18,4 @@ org.slf4j.simpleLogger.logFile=System.out
 org.slf4j.simpleLogger.defaultLogLevel=info
 org.slf4j.simpleLogger.log.org.apache.jackrabbit.oak.plugins.index.IndexUpdate=warn
 org.slf4j.simpleLogger.log.org.apache.sling.scripting.core.impl.ScriptEngineManagerFactory=warn
-org.slf4j.simpleLogger.log.org.apache.sling.resourceresolver.impl.mapping.MapEntries=warn
\ No newline at end of file
+org.slf4j.simpleLogger.log.org.apache.sling.resourceresolver.impl.mapping.MapEntries=warn


Mime
View raw message