You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2017/10/02 08:53:05 UTC

svn commit: r1810314 - in /felix/sandbox/cziegeler/osgicheck-maven-plugin: pom.xml src/main/java/org/apache/felix/maven/osgicheck/impl/CheckMojo.java src/main/java/org/apache/felix/maven/osgicheck/impl/checks/SCRCheck.java

Author: cziegeler
Date: Mon Oct  2 08:53:05 2017
New Revision: 1810314

URL: http://svn.apache.org/viewvc?rev=1810314&view=rev
Log:
Switch to 'mode' configuration instead of a set of booleans. Correct immediate check

Modified:
    felix/sandbox/cziegeler/osgicheck-maven-plugin/pom.xml
    felix/sandbox/cziegeler/osgicheck-maven-plugin/src/main/java/org/apache/felix/maven/osgicheck/impl/CheckMojo.java
    felix/sandbox/cziegeler/osgicheck-maven-plugin/src/main/java/org/apache/felix/maven/osgicheck/impl/checks/SCRCheck.java

Modified: felix/sandbox/cziegeler/osgicheck-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/osgicheck-maven-plugin/pom.xml?rev=1810314&r1=1810313&r2=1810314&view=diff
==============================================================================
--- felix/sandbox/cziegeler/osgicheck-maven-plugin/pom.xml (original)
+++ felix/sandbox/cziegeler/osgicheck-maven-plugin/pom.xml Mon Oct  2 08:53:05 2017
@@ -33,7 +33,7 @@
 
     <properties>
         <maven.version>3.5.0</maven.version>
-        <felix.java.version>8</felix.java.version>
+        <felix.java.version>7</felix.java.version>
     </properties>
 
     <prerequisites>

Modified: felix/sandbox/cziegeler/osgicheck-maven-plugin/src/main/java/org/apache/felix/maven/osgicheck/impl/CheckMojo.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/osgicheck-maven-plugin/src/main/java/org/apache/felix/maven/osgicheck/impl/CheckMojo.java?rev=1810314&r1=1810313&r2=1810314&view=diff
==============================================================================
--- felix/sandbox/cziegeler/osgicheck-maven-plugin/src/main/java/org/apache/felix/maven/osgicheck/impl/CheckMojo.java (original)
+++ felix/sandbox/cziegeler/osgicheck-maven-plugin/src/main/java/org/apache/felix/maven/osgicheck/impl/CheckMojo.java Mon Oct  2 08:53:05 2017
@@ -55,17 +55,18 @@ import org.osgi.framework.Constants;
     )
 public class CheckMojo extends AbstractMojo {
 
-    /**
-     * Whether to skip all checking
-     */
-    @Parameter(defaultValue = "false")
-    protected boolean skipCheck;
+    public enum Mode {
+        OFF,
+        DEFAULT,
+        STRICT,
+        ERRORS_ONLY
+    }
 
     /**
-     * Whether strict checking is turned on (warnings are errors in strict mode)
+     * The mode
      */
-    @Parameter(defaultValue = "false")
-    protected boolean strictCheck;
+    @Parameter(defaultValue = "DEFAULT")
+    protected Mode mode;
 
     /**
      * The configuration for the checks
@@ -107,7 +108,7 @@ public class CheckMojo extends AbstractM
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         if ( isOSGiProject() ) {
-            if ( !skipCheck ) {
+            if ( mode != Mode.OFF ) {
                 getLog().debug("Checking OSGi project...");
                 doExecute();
             } else {
@@ -164,6 +165,7 @@ public class CheckMojo extends AbstractM
                             } else {
                                 conf = Collections.emptyMap();
                             }
+                            getLog().debug("Configuration for " + check.getName() + " : " + conf);
                         }
 
                         @Override
@@ -210,8 +212,10 @@ public class CheckMojo extends AbstractM
             throw new MojoExecutionException(ioe.getMessage(), ioe);
         }
 
-        for(final String msg : warnings) {
-            getLog().warn(msg);
+        if ( mode != Mode.ERRORS_ONLY ) {
+            for(final String msg : warnings) {
+                getLog().warn(msg);
+            }
         }
         for(final String msg : errors) {
             getLog().error(msg);
@@ -220,7 +224,7 @@ public class CheckMojo extends AbstractM
         if ( !errors.isEmpty() ) {
             throw new MojoExecutionException("Check detected errors. See log output for error messages.");
         }
-        if ( strictCheck && !warnings.isEmpty() ) {
+        if ( mode == Mode.STRICT && !warnings.isEmpty() ) {
             throw new MojoExecutionException("Check detected warnings and strict mode is enabled. See log output for warning messages.");
         }
     }

Modified: felix/sandbox/cziegeler/osgicheck-maven-plugin/src/main/java/org/apache/felix/maven/osgicheck/impl/checks/SCRCheck.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/osgicheck-maven-plugin/src/main/java/org/apache/felix/maven/osgicheck/impl/checks/SCRCheck.java?rev=1810314&r1=1810313&r2=1810314&view=diff
==============================================================================
--- felix/sandbox/cziegeler/osgicheck-maven-plugin/src/main/java/org/apache/felix/maven/osgicheck/impl/checks/SCRCheck.java (original)
+++ felix/sandbox/cziegeler/osgicheck-maven-plugin/src/main/java/org/apache/felix/maven/osgicheck/impl/checks/SCRCheck.java Mon Oct  2 08:53:05 2017
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.lang.reflect.Field;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.cert.X509Certificate;
@@ -95,15 +96,34 @@ public class SCRCheck implements Check {
      * <ul>
      * @param ctx
      * @param md
+     * @throws SecurityException
+     * @throws NoSuchFieldException
      */
     private void checkImmediate(final CheckContext ctx, final ComponentMetadata md) {
+        // we have to use reflection
+        Boolean immediate = null;
+        try {
+            final Field immediateField = md.getClass().getDeclaredField("m_immediate");
+            immediateField.setAccessible(true);
+            immediate = (Boolean) immediateField.get(md);
+        } catch ( final NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
         if ( md.getServiceMetadata() == null ) {
-            if ( md.isImmediate() ) {
-                ctx.reportError("Component " + md.getName() + " must not be declared as 'immediate'. (It's a component)");
+            if ( immediate != null ) {
+                if ( immediate.booleanValue() ) {
+                    ctx.reportError("Component " + md.getName() + " must not be declared as 'immediate'. It's a component. Remove the attribute.");
+                } else {
+                    ctx.reportError("Component " + md.getName() + " must not be declared as not 'immediate'.It's a component. Remove the attribute.");
+                }
             }
         } else {
-            if ( md.isImmediate() ) {
-                ctx.reportError("Service " + md.getName() + " should not be declared as 'immediate'.");
+            if ( immediate != null ) {
+                if ( immediate.booleanValue() ) {
+                    ctx.reportWarning("Service " + md.getName() + " should not be declared as 'immediate'.");
+                } else {
+                    ctx.reportWarning("Service " + md.getName() + " should not declare 'immediate' attribute but rather use the default.");
+                }
             }
         }
     }