diff options
5 files changed, 130 insertions, 29 deletions
diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java index 87c22c4f3..1154b6bbb 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/EclipseLauncherParser.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 IBM Corporation and others. + * Copyright (c) 2007, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Pascal Rapicault - Support for bundled macosx http://bugs.eclipse.org/57349 + * Christian Georgi - Relativize VM path https://bugs.eclipse.org/bugs/437680 *******************************************************************************/ package org.eclipse.equinox.internal.frameworkadmin.equinox; @@ -24,7 +25,7 @@ import org.eclipse.osgi.util.NLS; import org.osgi.service.log.LogService; public class EclipseLauncherParser { - private static final String MAC_OS_APP_FOLDER = ".app/Contents/MacOS"; //$NON-NLS-1$ + public static final String MAC_OS_APP_FOLDER = ".app/Contents/MacOS"; //$NON-NLS-1$ private static final String CONFIGURATION_FOLDER = "configuration"; //$NON-NLS-1$ public static final String MACOSX_BUNDLED = "macosx-bundled"; //$NON-NLS-1$ @@ -115,7 +116,7 @@ public class EclipseLauncherParser { } } - private void setVM(List<String> lines, File vm, URI launcherFolder) { + private void setVM(List<String> lines, File vm, URI launcherFolder, File installHome) { if (vm == null) { if (ParserUtils.getValueForArgument(EquinoxConstants.OPTION_VM, lines) != null) return; @@ -126,7 +127,20 @@ public class EclipseLauncherParser { URI vmRelativePath = null; if (vm.isAbsolute()) { - vmRelativePath = launcherFolder.relativize(vm.toURI()); + // Bug 437680: Correctly relativize on MacOS + // Example: (traditional layout) (bundled layout) + // Install home: install/ Eclipse.app/ + // Launcher: Eclipse.app/Contents/MacOS/ Contents/MacOS/ + // VM: jre/ jre/ + // Result: ../../../jre ../../jre + URI vmRelativePathToHome = installHome.toURI().relativize(vm.toURI()); + if (vmRelativePathToHome.isAbsolute()) { + // VM is not below the install root -> use absolute path + vmRelativePath = vmRelativePathToHome; + } else { + // make VM path relative to launcher folder (which is different to the install root in MacOS installs) + vmRelativePath = URIUtil.makeRelative(vm.toURI(), launcherFolder); + } } else { //For relative files, File#toURI will create an absolute URI by resolving against the current working directory, we don't want that String path = vm.getPath().replace('\\', '/'); @@ -296,7 +310,7 @@ public class EclipseLauncherParser { setConfigurationLocation(newlines, osgiInstallArea.toURI(), launcherData); setLauncherLibrary(newlines, launcherFolder.toURI()); // setFrameworkJar(newlines, launcherData.getFwJar()); - setVM(newlines, launcherData.getJvm(), launcherFolder.toURI()); + setVM(newlines, launcherData.getJvm(), launcherFolder.toURI(), launcherData.getHome()); //We are done, let's update the program args in the launcher data launcherData.setProgramArgs(null); 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"); |