Skip to content

Commit

Permalink
eclipse.ini: skip comment lines eclipse-equinox#361
Browse files Browse the repository at this point in the history
Commment lines have '#' its first character

eclipse-equinox#361
  • Loading branch information
EcljpseB0T authored and merks committed Nov 6, 2023
1 parent 1c013dd commit c7470b4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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<String> loadFile(File file) throws IOException {
try (BufferedReader br = new BufferedReader(new FileReader(file));) {
String line;
List<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
//
Expand Down

0 comments on commit c7470b4

Please sign in to comment.