From c7470b49c349021bfab0092d2242d7a5b2e01a4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Thu, 26 Oct 2023 09:03:56 +0200 Subject: [PATCH] eclipse.ini: skip comment lines #361 Commment lines have '#' its first character https://github.com/eclipse-equinox/p2/issues/361 --- .../equinox/utils/FileUtils.java | 37 +++++++++++++------ .../frameworkadmin/tests/TestVMArg.java | 23 ++++++++++-- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java index 4740319a9a..46f8252856 100644 --- a/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java +++ b/bundles/org.eclipse.equinox.frameworkadmin.equinox/src/org/eclipse/equinox/internal/frameworkadmin/equinox/utils/FileUtils.java @@ -17,7 +17,8 @@ import java.io.*; import java.net.*; import java.util.*; -import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.URIUtil; import org.eclipse.equinox.internal.frameworkadmin.equinox.EquinoxConstants; import org.eclipse.equinox.internal.frameworkadmin.equinox.ParserUtils; import org.eclipse.equinox.internal.provisional.frameworkadmin.LauncherData; @@ -33,10 +34,14 @@ public class FileUtils { // based on org.eclipse.core.runtime.adaptor.EclipseStarter#searchForBundle public static URI getEclipseRealLocation(Manipulator manipulator, String location) { - //if this is some form of URL just return it + // if this is some form of URL just return it try { new URL(location); - return URIUtil.makeAbsolute(new URI(location), ParserUtils.getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), manipulator.getConfigData().getProperties(), manipulator.getLauncherData()).toURI()); + return URIUtil.makeAbsolute(new URI(location), + ParserUtils + .getOSGiInstallArea(Arrays.asList(manipulator.getLauncherData().getProgramArgs()), + manipulator.getConfigData().getProperties(), manipulator.getLauncherData()) + .toURI()); } catch (URISyntaxException e) { // expected } catch (MalformedURLException e) { @@ -54,7 +59,7 @@ public static URI getEclipseRealLocation(Manipulator manipulator, String locatio return getEclipsePluginFullLocation(base.getName(), base.getParentFile()); } - //This mimics the logic of EclipseStarter#getSysPath(); + // This mimics the logic of EclipseStarter#getSysPath(); private static String getSysPath(final Manipulator manipulator) { Properties properties = manipulator.getConfigData().getProperties(); String path = (String) properties.get(EquinoxConstants.PROP_OSGI_SYSPATH); @@ -80,7 +85,7 @@ else if (launcherData.getLauncher() != null) { if (Constants.OS_MACOSX.equals(launcherData.getOS())) { IPath launcherPath = IPath.fromOSString(launcherData.getLauncher().getAbsolutePath()); if (launcherPath.segmentCount() > 2) { - launcherPath = launcherPath.removeLastSegments(2).append("Eclipse"); + launcherPath = launcherPath.removeLastSegments(2).append("Eclipse"); //$NON-NLS-1$ launcherDir = launcherPath.toFile(); } } else @@ -108,8 +113,9 @@ public static URI getRealLocation(Manipulator manipulator, final String location } /** - * If a bundle of the specified location is in the Eclipse plugin format (either plugin-name_version.jar - * or as a folder named plugin-name_version ), return version string.Otherwise, return null; + * If a bundle of the specified location is in the Eclipse plugin format (either + * plugin-name_version.jar or as a folder named plugin-name_version ), return + * version string.Otherwise, return null; * * @return version string. If invalid format, return null. */ @@ -130,6 +136,7 @@ private static Version getVersion(String version) { /** * Find the named plugin in the given bundlesDir + * * @param pluginName * @param bundlesDir * @return a URL string for the found plugin, or null @@ -151,7 +158,8 @@ public static URI getEclipsePluginFullLocation(String pluginName, File bundlesDi continue; if (candidateName.length() > pluginName.length() && candidateName.charAt(pluginName.length()) != '_') { // allow jar file with no _version tacked on the end - if (!candidate.isFile() || (candidateName.length() != 4 + pluginName.length()) || !candidateName.endsWith(".jar")) { + if (!candidate.isFile() || (candidateName.length() != 4 + pluginName.length()) + || !candidateName.endsWith(".jar")) { //$NON-NLS-1$ continue; } } @@ -198,22 +206,27 @@ public static String toFileURL(URI uri) { public static URI fromFileURL(String url) throws URISyntaxException { if (url.startsWith(FILE_PROTOCOL)) { - return URIUtil.fromString(new File(url.substring(FILE_PROTOCOL.length())).isAbsolute() ? url : url.substring(FILE_PROTOCOL.length())); + return URIUtil.fromString(new File(url.substring(FILE_PROTOCOL.length())).isAbsolute() ? url + : url.substring(FILE_PROTOCOL.length())); } throw new URISyntaxException(url, "Not a file url"); //$NON-NLS-1$ } /** - * Loads an ini file, returning a list of all non-blank lines in the file. + * Loads an ini file, returning a list of all non-blank lines in the file. Like + * eclipseConfig.c/readConfigFile() comment lines ('#' its first character) are + * skipped too. */ public static List loadFile(File file) throws IOException { try (BufferedReader br = new BufferedReader(new FileReader(file));) { String line; List list = new ArrayList<>(); while ((line = br.readLine()) != null) { - //skip whitespace - if (line.trim().length() > 0) + // skip whitespace and comments + String stripped = line.strip(); + if (!stripped.isEmpty() && !line.startsWith("#")) {//$NON-NLS-1$ list.add(line); + } } return list; } 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 9ae0682a41..e8a887b8ed 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,11 +13,11 @@ *******************************************************************************/ package org.eclipse.equinox.frameworkadmin.tests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.io.File; import java.io.IOException; +import java.util.Arrays; import org.eclipse.core.runtime.Platform; import org.eclipse.equinox.internal.provisional.frameworkadmin.FrameworkAdminRuntimeException; import org.eclipse.equinox.internal.provisional.frameworkadmin.Manipulator; @@ -109,7 +109,24 @@ public void test269502() throws FrameworkAdminRuntimeException, IOException { m.load(); assertEquals(jreLocation, m.getLauncherData().getJvm()); } - + @Test + public void testGH361() throws FrameworkAdminRuntimeException, IOException { + String arg1 = "#mycommentline1"; + String arg2 = "!noncommentline2"; + String arg3 = " #noncommentline3"; + String arg4 = "#mycommentline4"; + m.getLauncherData().addProgramArg(arg1); + m.getLauncherData().addProgramArg(arg2); + m.getLauncherData().addProgramArg(arg3); + m.getLauncherData().addProgramArg(arg4); + m.save(false); + m.load(); + String[] programArgs = m.getLauncherData().getProgramArgs(); + assertFalse(Arrays.asList(programArgs).contains(arg1)); + assertTrue(Arrays.asList(programArgs).contains(arg2)); + assertTrue(Arrays.asList(programArgs).contains(arg3)); + assertFalse(Arrays.asList(programArgs).contains(arg4)); + } // public void test269502_MacOS() throws Exception { // m = createMinimalConfiguration(TestEclipseDataArea.class.getName(), Constants.OS_MACOSX); //