Mercurial > hg > release > thermostat-1.6
changeset 1933:c5dc33321342
Also look in user plugin dirs for jars.
PR3031
Reviewed-by: jerboaa
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-June/019695.html
author | Jie Kang <jkang@redhat.com> |
---|---|
date | Thu, 23 Jun 2016 09:21:02 -0400 |
parents | 9e860337de11 |
children | 8942de6227a9 |
files | launcher/src/main/java/com/redhat/thermostat/launcher/internal/BundleManagerImpl.java launcher/src/test/java/com/redhat/thermostat/launcher/internal/BundleManagerImplTest.java |
diffstat | 2 files changed, 47 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/BundleManagerImpl.java Thu Jun 23 14:51:53 2016 +0200 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/BundleManagerImpl.java Thu Jun 23 09:21:02 2016 -0400 @@ -36,7 +36,6 @@ package com.redhat.thermostat.launcher.internal; -import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.FileVisitResult; @@ -79,7 +78,6 @@ // http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=1514 private final Map<BundleInformation, Path> known; private CommonPaths paths; - private boolean printOSGiInfo = false; private boolean ignoreBundleVersions = false; private BundleLoader loader; @@ -96,8 +94,8 @@ long t1 = System.nanoTime(); try { - for (File root : new File[] { paths.getSystemLibRoot(), paths.getSystemPluginRoot() }) { - Files.walkFileTree(root.toPath(), new SimpleFileVisitor<Path>() { + for (Path root : getRootsToSearch(paths)) { + Files.walkFileTree(root, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.toFile().getName().endsWith(".jar")) { @@ -106,7 +104,7 @@ String name = mf.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME); String version = mf.getMainAttributes().getValue(Constants.BUNDLE_VERSION); if (name == null || version == null) { - logger.config("file " + file.toString() + " is missing osgi metadata; wont be usable for dependencies"); + logger.finer("file " + file.toString() + " is missing osgi metadata; wont be usable for dependencies"); } else { BundleInformation info = new BundleInformation(name, version); Path old = known.get(info); @@ -134,16 +132,24 @@ } long t2 = System.nanoTime(); - if (printOSGiInfo) { - logger.fine("Found: " + known.size() + " bundles"); - logger.fine("Took " + (t2 -t1) + "ns"); - } + logger.fine("Found: " + known.size() + " bundles"); + logger.fine("Took " + (t2 -t1) + "ns"); for (Entry<BundleInformation, Path> bundles : known.entrySet()) { logger.finest(bundles.getKey().toString() + " is at " + bundles.getValue().toString()); } } + /** For TESTS only */ + static Path[] getRootsToSearch(CommonPaths paths) { + Path[] pluginsFolders = new Path[] { + paths.getSystemLibRoot().toPath(), + paths.getSystemPluginRoot().toPath(), + paths.getUserPluginRoot().toPath() + }; + return pluginsFolders; + } + /** For TESTS only: explicitly specify known bundles */ void setKnownBundles(Map<BundleInformation,Path> knownData) { known.clear(); @@ -154,7 +160,6 @@ /* Used via reflection from launcher */ public void setPrintOSGiInfo(boolean printOSGiInfo) { - this.printOSGiInfo = printOSGiInfo; loader.setPrintOSGiInfo(printOSGiInfo); }
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/BundleManagerImplTest.java Thu Jun 23 14:51:53 2016 +0200 +++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/BundleManagerImplTest.java Thu Jun 23 09:21:02 2016 -0400 @@ -36,6 +36,7 @@ package com.redhat.thermostat.launcher.internal; +import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -56,8 +57,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.junit.After; import org.junit.Before; @@ -103,6 +106,7 @@ paths = mock(CommonPaths.class); when(paths.getSystemLibRoot()).thenReturn(jarRootDir.toFile()); when(paths.getSystemPluginRoot()).thenReturn(pluginRootDir.toFile()); + when(paths.getUserPluginRoot()).thenReturn(pluginRootDir.toFile()); theContext = mock(BundleContext.class); theFramework = mock(Framework.class); @@ -289,5 +293,33 @@ m.invoke(registry, true); // If this fails, then API has changed in ways that break FrameworkProvider. } + @Test + public void verifyUserPluginsAreUsedForDepScanning() throws Exception { + CommonPaths customPaths = mock(CommonPaths.class); + File systemsLibFile = mock(File.class); + Path systemsLibPath = mock(Path.class); + when(systemsLibFile.toPath()).thenReturn(systemsLibPath); + File systemPluginsFile = mock(File.class); + Path systemPluginsPath = mock(Path.class); + when(systemPluginsFile.toPath()).thenReturn(systemPluginsPath); + File userPluginsFile = mock(File.class); + Path userPluginsPath = mock(Path.class); + when(userPluginsFile.toPath()).thenReturn(userPluginsPath); + when(customPaths.getSystemLibRoot()).thenReturn(systemsLibFile); + when(customPaths.getSystemPluginRoot()).thenReturn(systemPluginsFile); + when(customPaths.getUserPluginRoot()).thenReturn(userPluginsFile); + + Path[] paths = BundleManagerImpl.getRootsToSearch(customPaths); + assertEquals(3, paths.length); + + Set<Path> expected = new HashSet<>(); + expected.add(systemsLibPath); + expected.add(systemPluginsPath); + expected.add(userPluginsPath); + + Set<Path> actual = new HashSet<>(); + actual.addAll(Arrays.asList(paths)); + assertEquals(expected, actual); + } }