You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by hu...@apache.org on 2015/03/30 15:19:45 UTC

svn commit: r1670088 - in /aries/trunk/versioning: versioning-checker/src/main/java/org/apache/aries/versioning/check/ versioning-checker/src/test/java/org/apache/aries/versioning/tests/ versioning-checker/src/test/resources/ versioning-plugin/src/main...

Author: hughesj
Date: Mon Mar 30 13:19:44 2015
New Revision: 1670088

URL: http://svn.apache.org/r1670088
Log:
ARIES-1303: Add ability to exclude semantic versioning errors. This is only for extreme circumstances when the human knows best!

Added:
    aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/FilterResultsTest.java
    aries/trunk/versioning/versioning-checker/src/test/resources/
    aries/trunk/versioning/versioning-checker/src/test/resources/api_1.0.0.jar   (with props)
    aries/trunk/versioning/versioning-checker/src/test/resources/api_1.0.1.jar   (with props)
Modified:
    aries/trunk/versioning/versioning-checker/src/main/java/org/apache/aries/versioning/check/BundleCompatibility.java
    aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/VersionCheckerMojo.java

Modified: aries/trunk/versioning/versioning-checker/src/main/java/org/apache/aries/versioning/check/BundleCompatibility.java
URL: http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-checker/src/main/java/org/apache/aries/versioning/check/BundleCompatibility.java?rev=1670088&r1=1670087&r2=1670088&view=diff
==============================================================================
--- aries/trunk/versioning/versioning-checker/src/main/java/org/apache/aries/versioning/check/BundleCompatibility.java (original)
+++ aries/trunk/versioning/versioning-checker/src/main/java/org/apache/aries/versioning/check/BundleCompatibility.java Mon Mar 30 13:19:44 2015
@@ -29,6 +29,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URLClassLoader;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -68,16 +69,28 @@ public class BundleCompatibility {
   private BundleInfo currentBundle;
   private BundleInfo baseBundle;
   private StringBuilder pkgElements = new StringBuilder();
+  private List<String> pkgElementsList = new ArrayList<String>();
+  private List<String> excludes;
 
   private VersionChange bundleChange;
   private final Map<String, VersionChange> packageChanges = new HashMap<String, VersionChange>();
 
   public BundleCompatibility(String bundleSymbolicName, BundleInfo currentBundle, BundleInfo baseBundle, URLClassLoader oldJarsLoader, URLClassLoader newJarsLoader) {
+    this(bundleSymbolicName,
+         currentBundle,
+         baseBundle,
+         oldJarsLoader,
+         newJarsLoader,
+         null);
+  }
+  
+  public BundleCompatibility(String bundleSymbolicName, BundleInfo currentBundle, BundleInfo baseBundle, URLClassLoader oldJarsLoader, URLClassLoader newJarsLoader, List<String> excludes) {
     this.bundleSymbolicName = bundleSymbolicName;
     this.currentBundle = currentBundle;
     this.baseBundle = baseBundle;
     this.oldJarsLoader = oldJarsLoader;
     this.newJarsLoader = newJarsLoader;
+    this.excludes = excludes != null ? excludes : new ArrayList<String>();
   }
 
   public VersionChange getBundleChange() {
@@ -95,7 +108,19 @@ public class BundleCompatibility {
   public StringBuilder getPkgElements() {
     return pkgElements;
   }
-
+  
+  private boolean ignoreChange(String reason) {
+    if ((reason == null) || (this.excludes.isEmpty())) return false;
+    
+    for (String exclude : this.excludes) {
+      // Could have interpreted each exclude as a regex, but that makes it easy to write loose rules
+      // that match more strings than intended.
+      if ((reason != null) && reason.contains(exclude)) return true; 
+    }
+    
+    return false;
+  }
+  
   public boolean isBundleVersionCorrect() {
     return bundleVersionCorrect;
   }
@@ -145,26 +170,24 @@ public class BundleCompatibility {
           //                    if (majorChange.isChange() || minorChange.isChange()) {
           String oldVersion = pkg.getValue().getPackageVersion();
           String newVersion = currPkgContents.getPackageVersion();
-          if (majorChange.isChange()) {
+          if (majorChange.isChange() && !!!ignoreChange(majorChange.getReason())) {
             packageChanges.put(pkgName, new VersionChange(VERSION_CHANGE_TYPE.MAJOR_CHANGE, oldVersion, newVersion));
             pkg_major_change = true;
             fatal_package = pkgName;
             if (!!!isVersionCorrect(VERSION_CHANGE_TYPE.MAJOR_CHANGE, oldVersion, newVersion)) {
-              pkgElements.append(getPkgStatusText(pkgName, VERSION_CHANGE_TYPE.MAJOR_CHANGE, oldVersion, newVersion, majorChange.getReason(), majorChange.getChangeClass()));
+              pkgElementsList.add(getPkgStatusText(pkgName, VERSION_CHANGE_TYPE.MAJOR_CHANGE, oldVersion, newVersion, majorChange.getReason(), majorChange.getChangeClass()));
             }
-          } else if (minorChange.isChange()) {
+          } else if (minorChange.isChange() && !!!ignoreChange(minorChange.getReason())) {
             packageChanges.put(pkgName, new VersionChange(VERSION_CHANGE_TYPE.MINOR_CHANGE, oldVersion, newVersion));
             pkg_minor_change = true;
             if (fatal_package == null) fatal_package = pkgName;
             if (!!!isVersionCorrect(VERSION_CHANGE_TYPE.MINOR_CHANGE, oldVersion, newVersion)) {
-              pkgElements.append(getPkgStatusText(pkgName, VERSION_CHANGE_TYPE.MINOR_CHANGE, pkg.getValue().getPackageVersion(), currPkgContents.getPackageVersion(), minorChange.getReason(), minorChange.getChangeClass()));
+              pkgElementsList.add(getPkgStatusText(pkgName, VERSION_CHANGE_TYPE.MINOR_CHANGE, pkg.getValue().getPackageVersion(), currPkgContents.getPackageVersion(), minorChange.getReason(), minorChange.getChangeClass()));
             }
           }  else {
             packageChanges.put(pkgName, new VersionChange(VERSION_CHANGE_TYPE.NO_CHANGE, oldVersion, newVersion));
-            pkgElements.append(getPkgStatusText(pkgName, VERSION_CHANGE_TYPE.NO_CHANGE, pkg.getValue().getPackageVersion(), currPkgContents.getPackageVersion(), "", ""));
+            pkgElementsList.add(getPkgStatusText(pkgName, VERSION_CHANGE_TYPE.NO_CHANGE, pkg.getValue().getPackageVersion(), currPkgContents.getPackageVersion(), "", ""));
           }
-          pkgElements.append("\r\n");
-          //                    }
       }
       }
       // If there is a package version change, the bundle version needs to be updated.

Added: aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/FilterResultsTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/FilterResultsTest.java?rev=1670088&view=auto
==============================================================================
--- aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/FilterResultsTest.java (added)
+++ aries/trunk/versioning/versioning-checker/src/test/java/org/apache/aries/versioning/tests/FilterResultsTest.java Mon Mar 30 13:19:44 2015
@@ -0,0 +1,82 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.aries.versioning.tests;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.aries.util.manifest.BundleManifest;
+import org.apache.aries.versioning.check.BundleCompatibility;
+import org.apache.aries.versioning.check.BundleInfo;
+import org.junit.Test;
+
+
+/**
+ * Test that results can be excluded.
+ */
+public class FilterResultsTest {
+
+  /**
+   * Test an error is excluded when required. This test uses two bundles each containing the same
+   * class, where the later versioned class has had a method removed.
+   */
+    @Test
+    public void testApiMethodErrorExcluded() {
+   
+      try {
+        File oldBundleFile = new File("../src/test/resources/api_1.0.0.jar");
+        BundleInfo oldBundle = new BundleInfo(BundleManifest.fromBundle(oldBundleFile), oldBundleFile);
+  
+        File newBundleFile = new File("../src/test/resources/api_1.0.1.jar");
+        BundleInfo newBundle = new BundleInfo(BundleManifest.fromBundle(newBundleFile), newBundleFile);
+        
+        String bundleSymbolicName = newBundle.getBundleManifest().getSymbolicName();
+        URLClassLoader oldClassLoader = new URLClassLoader(new URL[] {oldBundle.getBundle().toURI()
+            .toURL()});
+        URLClassLoader newClassLoader = new URLClassLoader(new URL[] {newBundle.getBundle().toURI()
+            .toURL()});
+  
+        List<String> excludes = new ArrayList<String>();
+        excludes.add("method void methodToBeExcludedFrom() has been deleted");
+        
+        BundleCompatibility bundleCompatibility = new BundleCompatibility(bundleSymbolicName,
+            newBundle, oldBundle,
+            oldClassLoader,
+            newClassLoader,
+            excludes);
+        
+        bundleCompatibility.invoke();
+        String bundleElement = bundleCompatibility.getBundleElement();
+        String pkgElement = bundleCompatibility.getPkgElements().toString();
+
+        assertTrue("Unexpected bundle versioning issue", bundleElement==null);
+        assertTrue("Unexpected package versioning issue", pkgElement.trim().length() == 0);
+      
+      } catch (IOException e) {
+        fail("Unexpected IOException " + e);
+      }
+    }
+}

Added: aries/trunk/versioning/versioning-checker/src/test/resources/api_1.0.0.jar
URL: http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-checker/src/test/resources/api_1.0.0.jar?rev=1670088&view=auto
==============================================================================
Binary file - no diff available.

Propchange: aries/trunk/versioning/versioning-checker/src/test/resources/api_1.0.0.jar
------------------------------------------------------------------------------
    svn:mime-type = application/java-archive

Added: aries/trunk/versioning/versioning-checker/src/test/resources/api_1.0.1.jar
URL: http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-checker/src/test/resources/api_1.0.1.jar?rev=1670088&view=auto
==============================================================================
Binary file - no diff available.

Propchange: aries/trunk/versioning/versioning-checker/src/test/resources/api_1.0.1.jar
------------------------------------------------------------------------------
    svn:mime-type = application/java-archive

Modified: aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/VersionCheckerMojo.java
URL: http://svn.apache.org/viewvc/aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/VersionCheckerMojo.java?rev=1670088&r1=1670087&r2=1670088&view=diff
==============================================================================
--- aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/VersionCheckerMojo.java (original)
+++ aries/trunk/versioning/versioning-plugin/src/main/java/org/apache/aries/versioning/mojo/VersionCheckerMojo.java Mon Mar 30 13:19:44 2015
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.aries.util.manifest.BundleManifest;
@@ -77,6 +78,9 @@ public class VersionCheckerMojo extends
     @Parameter(defaultValue="${project.basedir}/src/main/java")
     private File source;
 
+    @Parameter
+    private List<String> excludes;
+    
     @Component
     private RepositorySystem repository;
     
@@ -121,7 +125,8 @@ public class VersionCheckerMojo extends
                 BundleCompatibility bundleCompatibility = new BundleCompatibility(bundleSymbolicName,
                                                                                   newBundle, oldBundle,
                                                                                   oldClassLoader,
-                                                                                  newClassLoader);
+                                                                                  newClassLoader,
+                                                                                  excludes);
                 bundleCompatibility.invoke();
                 String bundleElement = bundleCompatibility.getBundleElement();
                 String pkgElement = bundleCompatibility.getPkgElements().toString();