Improve runnersFromRepoUrl() 86/107786/2
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 10 Sep 2023 19:10:50 +0000 (21:10 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 10 Sep 2023 19:14:32 +0000 (21:14 +0200)
There is no need to issue a plain copy, just return whatever we got
from getFeatures().

Change-Id: I474ce91faa3646d4ece2254bbb23581f331604cf
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
features-test/src/main/java/org/opendaylight/odlparent/featuretest/PerRepoTestRunner.java

index 7ce2bd01edea8c04c23c4b928e9e972cb433d96a..d44563dcafb878fd543bf44276ce778e687190a4 100644 (file)
@@ -14,7 +14,6 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import javax.xml.bind.JAXBException;
-import org.apache.karaf.features.internal.model.Feature;
 import org.apache.karaf.features.internal.model.Features;
 import org.apache.karaf.features.internal.model.JaxbUtil;
 import org.junit.runner.Description;
@@ -33,11 +32,11 @@ public class PerRepoTestRunner extends ParentRunner<PerFeatureRunner> {
     private static final String[] FEATURES_FILENAMES = new String[] { "features.xml", "feature.xml" };
 
     private static boolean isURLStreamHandlerFactorySet = false;
-    // Do NOT static { URL.setURLStreamHandlerFactory(new CustomBundleUrlStreamHandlerFactory()); }
-    // This is VERY BAD practice, because it leads to VERY HARD TO TRACK errors in case ANYTHING
-    // goes wrong in this.  For example, we had a case where (following an upgrade of PAX Exam)
-    // a dependency was missing.  This appeared as a confusing error because the root cause
-    // of static initialization errors is typically lost in Java; so best is NOT to use it!
+    // Do NOT static {@code { URL.setURLStreamHandlerFactory(new CustomBundleUrlStreamHandlerFactory()); }}
+    // This is VERY BAD practice, because it leads to VERY HARD TO TRACK errors in case ANYTHING goes wrong in this.
+    // For example, we had a case where (following an upgrade of PAX Exam) a dependency was missing. This appeared
+    // as a confusing error because the root cause of static initialization errors is typically lost in Java; so best is
+    // NOT to use it!
     // ("NoClassDefFoundError: Could not initialize class ...PerRepoTestRunner")
 
     private final List<PerFeatureRunner> children = new ArrayList<>();
@@ -77,9 +76,10 @@ public class PerRepoTestRunner extends ParentRunner<PerFeatureRunner> {
                 URL.setURLStreamHandlerFactory(new CustomBundleUrlStreamHandlerFactory());
                 isURLStreamHandlerFactorySet = true;
             } catch (Error e) {
-                LOG.warn("Failed to setURLStreamHandlerFactory to CustomBundleUrlStreamHandlerFactory "
-                        + "(depending on which is already set, this may or may not actually be a problem"
-                        + "; e.g. Karaf 4 already registers the neccessary handlers, so OK to ignore)", e);
+                LOG.warn("""
+                    Failed to setURLStreamHandlerFactory to CustomBundleUrlStreamHandlerFactory (depending on which is
+                    already set, this may or may not actually be a problem; e.g. Karaf 4 already registers
+                    the neccessary handlers, so OK to ignore)""", e);
             }
         }
     }
@@ -96,10 +96,7 @@ public class PerRepoTestRunner extends ParentRunner<PerFeatureRunner> {
 
     protected List<PerFeatureRunner> runnersFromRepoUrl(final URL repoUrl, final Class<?> testClass)
             throws JAXBException, IOException, InitializationError {
-        final List<PerFeatureRunner> runners = new ArrayList<>();
-        final Features features = getFeatures(repoUrl);
-        runners.addAll(runnersFromFeatures(repoUrl, features, testClass));
-        return runners;
+        return runnersFromFeatures(repoUrl, getFeatures(repoUrl), testClass);
     }
 
     protected List<PerFeatureRunner> recursiveRunnersFromRepoUrl(final URL repoUrl, final Class<?> testClass)
@@ -116,9 +113,9 @@ public class PerRepoTestRunner extends ParentRunner<PerFeatureRunner> {
 
     protected List<PerFeatureRunner> runnersFromFeatures(
             final URL repoUrl, final Features features, final Class<?> testClass) throws InitializationError {
-        final List<PerFeatureRunner> runners = new ArrayList<>();
-        final List<Feature> featureList = features.getFeature();
-        for (final Feature f : featureList) {
+        final var runners = new ArrayList<PerFeatureRunner>();
+        final var featureList = features.getFeature();
+        for (var f : featureList) {
             // If the features have more than one feature, ignore any feature with the same name as the
             // repository — these are the aggregator features generated by the Karaf Maven plugin, and
             // which are expensive to test