changeset 1308:41126b42f1e3

Remove printOSGiInfo and ignoreVersion from Configuration Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-November/008680.html
author Omair Majid <omajid@redhat.com>
date Fri, 08 Nov 2013 04:24:41 -0500
parents 75fe7ce6dea2
children e66baba3918e
files config/src/main/java/com/redhat/thermostat/shared/config/Configuration.java launcher/src/main/java/com/redhat/thermostat/launcher/BundleManager.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/BundleLoader.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/BundleManagerImpl.java launcher/src/test/java/com/redhat/thermostat/launcher/BundleManagerTest.java launcher/src/test/java/com/redhat/thermostat/launcher/internal/BundleManagerImplTest.java main/src/main/java/com/redhat/thermostat/main/Thermostat.java main/src/main/java/com/redhat/thermostat/main/impl/FrameworkProvider.java
diffstat 8 files changed, 42 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/config/src/main/java/com/redhat/thermostat/shared/config/Configuration.java	Thu Nov 07 15:27:27 2013 -0500
+++ b/config/src/main/java/com/redhat/thermostat/shared/config/Configuration.java	Fri Nov 08 04:24:41 2013 -0500
@@ -88,9 +88,6 @@
     private final String home;
     private final UserDirectories userDirectories;
 
-    private boolean printOsgiInfo = false;
-    private boolean ignoreVersions = false;
-
     public Configuration() throws InvalidConfigurationException {
         // allow this to be specified also as a property, especially for
         // tests, this overrides the env setting
@@ -227,22 +224,6 @@
     // TODO add logging files here (see LoggingUtils)
     // TODO add ssl.properties file here (see SSLConfiguration)
 
-    public boolean getPrintOSGiInfo() {
-        return printOsgiInfo;
-    }
-
-    public void setPrintOSGiInfo(boolean newValue) {
-        printOsgiInfo = newValue;
-    }
-
-    public void setIgnoreVersions(boolean ignore) {
-        this.ignoreVersions  = ignore;
-    }
-
-    public boolean getIgnoreVersions() {
-        return ignoreVersions;
-    }
-
     private interface UserDirectories {
 
         public File getSystemRoot();
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/BundleManager.java	Thu Nov 07 15:27:27 2013 -0500
+++ b/launcher/src/main/java/com/redhat/thermostat/launcher/BundleManager.java	Fri Nov 08 04:24:41 2013 -0500
@@ -55,19 +55,6 @@
 @Service
 public abstract class BundleManager {
 
-    public abstract void setPrintOSGiInfo(boolean printOSGiInfo);
-
-    /**
-     * Indicates that versions in thermostat-specific config files (including
-     * thermostat-plugin.xml files) should be ignored and the latest version
-     * used.
-     * <p>
-     * This does not change OSGi's requirements; if OSGi bundles need specific
-     * versions and the latest version is not within the asked range, things
-     * will break.
-     */
-    public abstract void setIgnoreVersions(boolean ignore);
-
     /**
      * Load and start bundles using the metadata about a bundle.
      */
@@ -75,7 +62,8 @@
 
     public static void preLoadBundles(Framework framework, List<String> bundleLocations,
             boolean printOSGiInfo) throws BundleException {
-        BundleLoader loader = new BundleLoader(printOSGiInfo);
+        BundleLoader loader = new BundleLoader();
+        loader.setPrintOSGiInfo(printOSGiInfo);
         loader.installAndStartBundles(framework, bundleLocations);
     }
 
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/BundleLoader.java	Thu Nov 07 15:27:27 2013 -0500
+++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/BundleLoader.java	Fri Nov 08 04:24:41 2013 -0500
@@ -49,12 +49,7 @@
 
     private boolean printOSGiInfo = false;
 
-    BundleLoader() {
-        this(false);
-    }
-
-    public BundleLoader(boolean printOSGiInfo) {
-        setPrintOSGiInfo(printOSGiInfo);
+    public BundleLoader() {
     }
 
     public void setPrintOSGiInfo(boolean printOSGiInfo) {
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/BundleManagerImpl.java	Thu Nov 07 15:27:27 2013 -0500
+++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/BundleManagerImpl.java	Fri Nov 08 04:24:41 2013 -0500
@@ -81,13 +81,15 @@
     // http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=1514
     private final Map<BundleInformation, Path> known;
     private Configuration configuration;
+    private boolean printOSGiInfo = false;
+    private boolean ignoreBundleVersions = false;
     private BundleLoader loader;
 
     BundleManagerImpl(Configuration configuration) throws ConfigurationException, FileNotFoundException, IOException {
         known = new HashMap<>();
 
         this.configuration = configuration;
-        loader = new BundleLoader(configuration.getPrintOSGiInfo());
+        loader = new BundleLoader();
 
         scanForBundles();
     }
@@ -134,7 +136,7 @@
         }
 
         long t2 = System.nanoTime();
-        if (configuration.getPrintOSGiInfo()) {
+        if (printOSGiInfo) {
             logger.fine("Found: " + known.size() + " bundles");
             logger.fine("Took " + (t2 -t1) + "ns");
         }
@@ -152,15 +154,24 @@
         }
     }
 
-    @Override
+    /* Used via reflection from launcher */
     public void setPrintOSGiInfo(boolean printOSGiInfo) {
-        configuration.setPrintOSGiInfo(printOSGiInfo);
+        this.printOSGiInfo = printOSGiInfo;
         loader.setPrintOSGiInfo(printOSGiInfo);
     }
 
-    @Override
-    public void setIgnoreVersions(boolean ignore) {
-        configuration.setIgnoreVersions(ignore);
+    /**
+     * Indicates that versions in thermostat-specific config files (including
+     * thermostat-plugin.xml files) should be ignored and the latest version
+     * used.
+     * <p>
+     * This does not change OSGi's requirements; if OSGi bundles need specific
+     * versions and the latest version is not within the asked range, things
+     * will break.
+     */
+    /* Used via reflection from launcher */
+    public void setIgnoreBundleVersions(boolean ignore) {
+        this.ignoreBundleVersions = ignore;
     }
 
     @Override
@@ -169,7 +180,7 @@
         for (BundleInformation info : bundles) {
             Path bundlePath = null;
 
-            if (configuration.getIgnoreVersions()) {
+            if (ignoreBundleVersions) {
                 bundlePath = findLatestVersion(info.getName());
             } else {
                 bundlePath = known.get(info);
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/BundleManagerTest.java	Thu Nov 07 15:27:27 2013 -0500
+++ b/launcher/src/test/java/com/redhat/thermostat/launcher/BundleManagerTest.java	Fri Nov 08 04:24:41 2013 -0500
@@ -36,7 +36,6 @@
 
 package com.redhat.thermostat.launcher;
 
-import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.powermock.api.mockito.PowerMockito.whenNew;
@@ -61,8 +60,9 @@
         Framework framework = mock(Framework.class);
         ArrayList<String> bundleLocations = new ArrayList<>();
         BundleLoader loader = mock(BundleLoader.class);
-        whenNew(BundleLoader.class).withParameterTypes(Boolean.TYPE).
-                withArguments(any()).thenReturn(loader);
+        whenNew(BundleLoader.class)
+            .withNoArguments()
+            .thenReturn(loader);
 
         BundleManager.preLoadBundles(framework, bundleLocations, true);
         verify(loader).installAndStartBundles(framework, bundleLocations);
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/BundleManagerImplTest.java	Thu Nov 07 15:27:27 2013 -0500
+++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/BundleManagerImplTest.java	Fri Nov 08 04:24:41 2013 -0500
@@ -40,7 +40,6 @@
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 import static org.powermock.api.mockito.PowerMockito.mockStatic;
 import static org.powermock.api.mockito.PowerMockito.whenNew;
@@ -125,8 +124,9 @@
         loader = mock(BundleLoader.class);
         when(loader.installAndStartBundles(any(Framework.class), eq(bundleLocs))).
                 thenReturn(installed);
-        whenNew(BundleLoader.class).withParameterTypes(Boolean.TYPE).
-                withArguments(any()).thenReturn(loader);
+        whenNew(BundleLoader.class)
+            .withNoArguments()
+            .thenReturn(loader);
     }
 
     @After
@@ -216,9 +216,8 @@
 
         when(FrameworkUtil.getBundle(any(Class.class))).thenReturn(theBundle);
 
-        when(conf.getIgnoreVersions()).thenReturn(true);
-
         BundleManagerImpl registry = new BundleManagerImpl(conf);
+        registry.setIgnoreBundleVersions(true);
         Map<BundleInformation, Path> bundleToPath = new HashMap<>();
         bundleToPath.put(new BundleInformation("foo", "1.0"), Paths.get(jar1Name));
         bundleToPath.put(new BundleInformation("foo", "2.0"), Paths.get(jar2Name));
--- a/main/src/main/java/com/redhat/thermostat/main/Thermostat.java	Thu Nov 07 15:27:27 2013 -0500
+++ b/main/src/main/java/com/redhat/thermostat/main/Thermostat.java	Fri Nov 08 04:24:41 2013 -0500
@@ -51,23 +51,25 @@
      */
     public static void main(String[] args) {
 
-        Configuration config = new Configuration();
+        boolean printOSGiInfo = false;
+        boolean ignoreBundleVersions = false;
 
         List<String> toProcess = new ArrayList<>(Arrays.asList(args));
         Iterator<String> iter = toProcess.iterator();
         while (iter.hasNext()) {
             String arg = iter.next();
             if ("--print-osgi-info".equals(arg)) {
-                config.setPrintOSGiInfo(true);
+                printOSGiInfo = true;
                 iter.remove();
             }
             if ("--ignore-bundle-versions".equals(arg)) {
-                config.setIgnoreVersions(true);
+                ignoreBundleVersions = true;
                 iter.remove();
             }
         }
 
-        FrameworkProvider frameworkProvider = new FrameworkProvider(config);
+        Configuration config = new Configuration();
+        FrameworkProvider frameworkProvider = new FrameworkProvider(config, printOSGiInfo, ignoreBundleVersions);
         frameworkProvider.start(toProcess.toArray(new String[0]));
     }
 
--- a/main/src/main/java/com/redhat/thermostat/main/impl/FrameworkProvider.java	Thu Nov 07 15:27:27 2013 -0500
+++ b/main/src/main/java/com/redhat/thermostat/main/impl/FrameworkProvider.java	Fri Nov 08 04:24:41 2013 -0500
@@ -72,14 +72,16 @@
 
     private Configuration configuration;
     private boolean printOSGiInfo;
-    private boolean ignoreVersions;
+    private boolean ignoreBundleVersions;
+
     // The framework cache location; Must not be shared between apps!
     private Path osgiCacheStorage;
 
-    public FrameworkProvider(Configuration config) {
+    public FrameworkProvider(Configuration config, boolean printOSGiInfo, boolean ignoreBundleVersions) {
         this.configuration = config;
-        printOSGiInfo = config.getPrintOSGiInfo();
-        ignoreVersions = config.getIgnoreVersions();
+
+        this.printOSGiInfo = printOSGiInfo;
+        this.ignoreBundleVersions = ignoreBundleVersions;
     }
 
     // This is our ticket into OSGi land. Unfortunately, we to use a bit of reflection here.
@@ -232,7 +234,7 @@
 
     private void setIgnoreBundleVersions(Framework framework) throws InterruptedException {
         Object loader = getService(framework, BundleManager.class.getName());
-        callVoidReflectedMethod(loader, "setIgnoreVersions", ignoreVersions);
+        callVoidReflectedMethod(loader, "setIgnoreBundleVersions", ignoreBundleVersions);
     }
 
     private void runLauncher(Framework framework, String[] args) throws InterruptedException {