diff options
author | Christian Georgi | 2014-06-25 08:15:30 +0000 |
---|---|---|
committer | Tobias Oberlies | 2015-01-12 09:26:29 +0000 |
commit | 17907d0431365abe39ac5242252723cf3b307a7d (patch) | |
tree | 75f232af3785eb6cff8384cb24db79f9ad2e02e7 /bundles/org.eclipse.equinox.frameworkadmin.test | |
parent | 3e1ee0a24a2946e1acc975c39a687c559262c4de (diff) | |
download | rt.equinox.p2-17907d0431365abe39ac5242252723cf3b307a7d.tar.gz rt.equinox.p2-17907d0431365abe39ac5242252723cf3b307a7d.tar.xz rt.equinox.p2-17907d0431365abe39ac5242252723cf3b307a7d.zip |
Bug 437680 - Correctly relativize VM pathI20150116-1000I20150113-0800
Especially on Mac OS the launcher path and the VM path have only some
path segments in common, and URI.relativize(URI) fails in this case.
Bug: 437680
Change-Id: I4b854bcba8d7738dc1cca96f5d492474f41ab6d8
Signed-off-by: Christian Georgi <christian.georgi@sap.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.frameworkadmin.test')
4 files changed, 111 insertions, 24 deletions
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AbstractFwkAdminTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AbstractFwkAdminTest.java index dcf57b42c..ec5646665 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AbstractFwkAdminTest.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/AbstractFwkAdminTest.java @@ -26,7 +26,7 @@ import org.osgi.framework.*; import org.osgi.util.tracker.ServiceTracker; public abstract class AbstractFwkAdminTest extends TestCase { - private ServiceTracker fwAdminTracker; + private ServiceTracker<Object, FrameworkAdmin> fwAdminTracker; private File testFolder; public AbstractFwkAdminTest(String name) { @@ -88,14 +88,14 @@ public abstract class AbstractFwkAdminTest extends TestCase { Filter filter; try { filter = Activator.getContext().createFilter(filterFwAdmin); - fwAdminTracker = new ServiceTracker(Activator.getContext(), filter, null); + fwAdminTracker = new ServiceTracker<Object, FrameworkAdmin>(Activator.getContext(), filter, null); fwAdminTracker.open(); } catch (InvalidSyntaxException e) { // never happens e.printStackTrace(); } } - return (FrameworkAdmin) fwAdminTracker.getService(); + return fwAdminTracker.getService(); } protected File getTestFolder(String name) { @@ -117,6 +117,7 @@ public abstract class AbstractFwkAdminTest extends TestCase { return testFolder; } + @Override protected void runTest() throws Throwable { super.runTest(); @@ -127,6 +128,7 @@ public abstract class AbstractFwkAdminTest extends TestCase { } } + @Override protected void tearDown() throws Exception { super.tearDown(); if (fwAdminTracker != null) { @@ -154,16 +156,28 @@ public abstract class AbstractFwkAdminTest extends TestCase { } public void assertNotContent(File file, String search) { + assertNotContent(null, file, search); + } + + public void assertNotContent(String message, File file, String search) { if (!file.exists()) fail("File: " + file.toString() + " can't be found."); try { BufferedReader reader = null; try { + String failure = null; + StringBuilder fileContent = new StringBuilder(); reader = new BufferedReader(new FileReader(file)); while (reader.ready()) { String line = reader.readLine(); - if (line.indexOf(search) >= 0) - fail("The string: " + search + " was not expected in this file: " + file.getAbsolutePath()); + fileContent.append(line).append('\n'); + if (line.indexOf(search) >= 0 && failure == null) { + failure = "The string: " + search + " was not expected in file '" + file.getAbsolutePath() + "'"; + } + } + if (failure != null) { + // dump whole file content + fail((message != null ? message : failure) + "\n" + fileContent); } } finally { if (reader != null) @@ -177,7 +191,7 @@ public abstract class AbstractFwkAdminTest extends TestCase { } public void assertIniFileNotContain(File file, String argument, String value) { - List args = null; + List<String> args = null; try { args = FileUtils.loadFile(file); } catch (IOException e) { @@ -243,19 +257,22 @@ public abstract class AbstractFwkAdminTest extends TestCase { } } - public void assertContent(File file, String search) { - assertContents(file, new String [] { search } ); + public void assertContent(File file, String... search) { + assertContent(null, file, search); } - public void assertContents(File file, String [] lines) { + + public void assertContent(String message, File file, String... lines) { if (!file.exists()) fail("File: " + file.toString() + " can't be found."); int idx = 0; + StringBuilder fileContent = new StringBuilder(); try { BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); while (reader.ready()) { String line = reader.readLine(); + fileContent.append(line).append('\n'); if (line.indexOf(lines[idx]) >= 0) { if(++idx >= lines.length) return; @@ -270,7 +287,7 @@ public abstract class AbstractFwkAdminTest extends TestCase { } catch (IOException e) { fail("String: " + lines[idx] + " not found in " + file.getAbsolutePath()); } - fail("String:" + lines[idx] + " not found"); + fail("String: " + lines[idx] + " not found in\n" + fileContent); } public void startSimpleConfiguratorManipulator() { diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/FwkAdminAndSimpleConfiguratorTest.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/FwkAdminAndSimpleConfiguratorTest.java index 145b62e9d..a571c74cc 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/FwkAdminAndSimpleConfiguratorTest.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/FwkAdminAndSimpleConfiguratorTest.java @@ -12,27 +12,34 @@ package org.eclipse.equinox.frameworkadmin.tests; import java.io.File; import java.io.IOException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.URIUtil; +import org.eclipse.core.runtime.*; import org.eclipse.equinox.frameworkadmin.BundleInfo; +import org.eclipse.equinox.internal.frameworkadmin.equinox.EclipseLauncherParser; import org.eclipse.equinox.internal.provisional.frameworkadmin.*; +import org.eclipse.osgi.service.environment.Constants; import org.osgi.framework.BundleException; public abstract class FwkAdminAndSimpleConfiguratorTest extends AbstractFwkAdminTest { private File installFolder; private File configurationFolder; private String launcherName; + private IPath launcherPath; public FwkAdminAndSimpleConfiguratorTest(String name) { super(name); } + @Override protected void setUp() throws Exception { super.setUp(); startSimpleConfiguratorManipulator(); } protected Manipulator getNewManipulator(String workArea) throws FrameworkAdminRuntimeException, IOException, BundleException { + return getNewManipulator(workArea, null); + } + + protected Manipulator getNewManipulator(String workArea, String os) throws FrameworkAdminRuntimeException, IOException, BundleException { FrameworkAdmin fwkAdmin = getEquinoxFrameworkAdmin(); Manipulator manipulator = fwkAdmin.getManipulator(); @@ -40,9 +47,14 @@ public abstract class FwkAdminAndSimpleConfiguratorTest extends AbstractFwkAdmin configurationFolder = new File(installFolder, "configuration"); launcherName = "eclipse"; + boolean isMacOS = Constants.OS_MACOSX.equals(os) || EclipseLauncherParser.MACOSX_BUNDLED.equals(os); + launcherPath = isMacOS ? new Path("Eclipse" + EclipseLauncherParser.MAC_OS_APP_FOLDER).append(launcherName) : new Path(launcherName); + LauncherData launcherData = manipulator.getLauncherData(); + launcherData.setHome(installFolder); launcherData.setFwConfigLocation(configurationFolder); - launcherData.setLauncher(new File(installFolder, launcherName)); + launcherData.setLauncher(new File(installFolder, launcherPath.toOSString())); + launcherData.setOS(os); try { manipulator.load(); } catch (IllegalStateException e) { @@ -52,7 +64,11 @@ public abstract class FwkAdminAndSimpleConfiguratorTest extends AbstractFwkAdmin } protected Manipulator createMinimalConfiguration(String workArea) throws Exception { - Manipulator manipulator = getNewManipulator(workArea); + return createMinimalConfiguration(workArea, null); + } + + protected Manipulator createMinimalConfiguration(String workArea, String os) throws Exception { + Manipulator manipulator = getNewManipulator(workArea, os); BundleInfo osgiBi = new BundleInfo("org.eclipse.osgi", "3.3.1", URIUtil.toURI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.osgi.jar"))), 0, true); BundleInfo configuratorBi = new BundleInfo("org.eclipse.equinox.simpleconfigurator", "1.0.0", URIUtil.toURI(FileLocator.resolve(Activator.getContext().getBundle().getEntry("dataFile/org.eclipse.equinox.simpleconfigurator.jar"))), 1, true); @@ -70,6 +86,7 @@ public abstract class FwkAdminAndSimpleConfiguratorTest extends AbstractFwkAdmin return manipulator; } + @Override protected void tearDown() throws Exception { super.tearDown(); if (installFolder != null) @@ -80,6 +97,11 @@ public abstract class FwkAdminAndSimpleConfiguratorTest extends AbstractFwkAdmin return installFolder; } + public File getLauncherConfigFile() { + File launcherDir = new File(getInstallFolder(), launcherPath.toOSString()).getParentFile(); + return new File(launcherDir, getLauncherName() + ".ini"); + } + public File getConfigurationFolder() { return configurationFolder; } diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ManipulatorTests.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ManipulatorTests.java index 01b1667b1..65ecd4f6b 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ManipulatorTests.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/ManipulatorTests.java @@ -97,7 +97,7 @@ public class ManipulatorTests extends AbstractFwkAdminTest { manipulator.getConfigData().addBundle(osgiBi); manipulator.save(false); - assertContents(ini, new String[] {"-foo", "bar", "-console", "-vmargs", "-Xmx256m", "-Xms64m"}); + assertContent(ini, "-foo", "bar", "-console", "-vmargs", "-Xmx256m", "-Xms64m"); } } diff --git a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/TestVMArg.java b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/TestVMArg.java index dbee6e69c..d1a011457 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/TestVMArg.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.test/src/org/eclipse/equinox/frameworkadmin/tests/TestVMArg.java @@ -13,16 +13,20 @@ package org.eclipse.equinox.frameworkadmin.tests; import java.io.File; import java.io.IOException; import org.eclipse.core.runtime.Platform; +import org.eclipse.equinox.internal.frameworkadmin.equinox.EclipseLauncherParser; import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdminRuntimeException; import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator; +import org.eclipse.osgi.service.environment.Constants; public class TestVMArg extends FwkAdminAndSimpleConfiguratorTest { + private Manipulator m; public TestVMArg(String name) { super(name); } + @Override protected void setUp() throws Exception { super.setUp(); m = createMinimalConfiguration(TestEclipseDataArea.class.getName()); @@ -33,33 +37,60 @@ public class TestVMArg extends FwkAdminAndSimpleConfiguratorTest { File jreLocation = new File(m.getLauncherData().getLauncher().getParentFile(), "jre"); m.getLauncherData().setJvm(jreLocation); m.save(false); - assertNotContent(new File(getInstallFolder(), "eclipse.ini"), jreLocation.getAbsolutePath()); - assertContent(new File(getInstallFolder(), "eclipse.ini"), "jre"); + assertNotContent(getLauncherConfigFile(), jreLocation.getAbsolutePath()); + assertContent(getLauncherConfigFile(), "jre"); assertContent(m.getLauncherData().getLauncherConfigLocation(), "-vm"); assertContent(m.getLauncherData().getLauncherConfigLocation(), "jre"); assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "file:"); m.load(); assertEquals(jreLocation, m.getLauncherData().getJvm()); - + m.getLauncherData().setJvm(null); m.save(false); assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "-vm"); assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "jre"); } + public void testVMInsideInstall_MacOS() throws Exception { + m = createMinimalConfiguration(TestEclipseDataArea.class.getName(), Constants.OS_MACOSX); + final String expectedRelativePath = "../../../jre"; + + File jreLocation = new File(m.getLauncherData().getLauncher().getParentFile(), expectedRelativePath); + m.getLauncherData().setJvm(jreLocation); + m.save(false); + + File launcherConfigFile = getLauncherConfigFile(); + assertNotContent("No absolute JRE path must be present in " + launcherConfigFile, launcherConfigFile, jreLocation.getAbsolutePath()); + assertContent("Relative JRE path must be present in " + launcherConfigFile, launcherConfigFile, expectedRelativePath); + } + + public void testVMInsideInstall_MacOS_BundledLayout() throws Exception { + m = createMinimalConfiguration(TestEclipseDataArea.class.getName(), EclipseLauncherParser.MACOSX_BUNDLED); + // note the difference the traditional layout: one segment less + final String expectedRelativePath = "../../jre"; + + File jreLocation = new File(m.getLauncherData().getLauncher().getParentFile(), expectedRelativePath); + m.getLauncherData().setJvm(jreLocation); + m.save(false); + + File launcherConfigFile = getLauncherConfigFile(); + assertNotContent("No absolute JRE path must be present in " + launcherConfigFile, launcherConfigFile, jreLocation.getAbsolutePath()); + assertContent("Relative JRE path must be present in " + launcherConfigFile, launcherConfigFile, expectedRelativePath); + } + public void testVMOutsideInstall() throws FrameworkAdminRuntimeException, IOException { //Test VM path in the install folder File jreLocation = new File(m.getLauncherData().getLauncher().getParentFile(), "../../jre").getCanonicalFile(); m.getLauncherData().setJvm(jreLocation); m.save(false); - assertContent(new File(getInstallFolder(), "eclipse.ini"), jreLocation.getAbsolutePath().replace('\\','/')); + assertContent(getLauncherConfigFile(), jreLocation.getAbsolutePath().replace('\\','/')); assertContent(m.getLauncherData().getLauncherConfigLocation(), "-vm"); assertContent(m.getLauncherData().getLauncherConfigLocation(), "jre"); assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "file:"); m.load(); assertEquals(jreLocation, m.getLauncherData().getJvm()); } - + public void test269502() throws FrameworkAdminRuntimeException, IOException { //Test VM path in the install folder String winPath = "c:/ibm5sr3/bin"; @@ -68,13 +99,30 @@ public class TestVMArg extends FwkAdminAndSimpleConfiguratorTest { File jreLocation = new File(chosenPath); m.getLauncherData().setJvm(jreLocation); m.save(false); - assertContent(new File(getInstallFolder(), "eclipse.ini"), chosenPath); + assertContent(getLauncherConfigFile(), chosenPath); + assertContent(m.getLauncherData().getLauncherConfigLocation(), "-vm"); + assertContent(m.getLauncherData().getLauncherConfigLocation(), chosenPath); + assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "file:"); + m.load(); + assertEquals(jreLocation, m.getLauncherData().getJvm()); + } + + public void test269502_MacOS() throws Exception { + m = createMinimalConfiguration(TestEclipseDataArea.class.getName(), Constants.OS_MACOSX); + + //Test VM path in the install folder + String chosenPath = "/Users/Pascal/ibm5sr3/bin"; + File jreLocation = new File(chosenPath); + m.getLauncherData().setJvm(jreLocation); + m.save(false); + assertContent(getLauncherConfigFile(), chosenPath); assertContent(m.getLauncherData().getLauncherConfigLocation(), "-vm"); assertContent(m.getLauncherData().getLauncherConfigLocation(), chosenPath); assertNotContent(m.getLauncherData().getLauncherConfigLocation(), "file:"); m.load(); assertEquals(jreLocation, m.getLauncherData().getJvm()); } + /** * But 282303: * Have -vm ../jre as program arguments. @@ -84,9 +132,9 @@ public class TestVMArg extends FwkAdminAndSimpleConfiguratorTest { * @throws IOException */ public void test282303() throws FrameworkAdminRuntimeException, IOException { - assertNotContent(new File(getInstallFolder(), "eclipse.ini"), "-vm"); - assertNotContent(new File(getInstallFolder(), "eclipse.ini"), "../mylocation"); - assertNotContent(new File(getInstallFolder(), "eclipse.ini"), "-otherarg"); + assertNotContent(getLauncherConfigFile(), "-vm"); + assertNotContent(getLauncherConfigFile(), "../mylocation"); + assertNotContent(getLauncherConfigFile(), "-otherarg"); m.getLauncherData().addProgramArg("-vm"); m.getLauncherData().addProgramArg("../mylocation"); m.getLauncherData().addProgramArg("-otherarg"); |