Skip to content

Commit

Permalink
Add a ExecutionEnvironmentDescription(Map) constructor
Browse files Browse the repository at this point in the history
This allows creating ExecutionEnvironmentDescription directly from a
Map, without the need to write the Map content to a file.
  • Loading branch information
HannesWell committed Sep 14, 2023
1 parent 1885f18 commit cce7843
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.jdt.launching/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.launching; singleton:=true
Bundle-Version: 3.20.200.qualifier
Bundle-Version: 3.21.0.qualifier
Bundle-Activator: org.eclipse.jdt.internal.launching.LaunchingPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,35 @@ public final class ExecutionEnvironmentDescription {
/**
* Execution environment description properties
*/
private Map<String, String> fProperties = null;
private final Map<String, String> fProperties;

/**
* Creates an execution environment description based on the properties defined in the given
* execution environment description file. The format of the file is defined by
* <code>http://wiki.eclipse.org/Execution_Environment_Descriptions</code>.
* Creates an execution environment description based on the properties defined in the given execution environment description file. The format of
* the file is defined by <code>https://wiki.eclipse.org/Execution_Environment_Descriptions</code>.
*
* @param eeFile execution environment description file
* @throws CoreException if unable to read or parse the file
*/
public ExecutionEnvironmentDescription(File eeFile) throws CoreException {
initProperties(eeFile);
this(loadProperties(eeFile), null);
}

/**
* Creates an execution environment description based on the given execution environment description properties. The contained properties are
* defined in <code>https://wiki.eclipse.org/Execution_Environment_Descriptions</code>.
*
* @param eeProperties execution environment description properties
* @throws CoreException if unable to read or parse the file
* @since 3.21
*/
public ExecutionEnvironmentDescription(Map<String, String> eeProperties) {
this(new LinkedHashMap<>(eeProperties), null); // defensive copy
}

private ExecutionEnvironmentDescription(Map<String, String> eeProperties, @SuppressWarnings("unused") Object internal) {
fProperties = eeProperties; // has to be set before resolveHome() is called
// resolve things with ${ee.home} in them
fProperties.replaceAll((k, value) -> value != null ? resolveHome(value) : ""); //$NON-NLS-1$
}

/**
Expand Down Expand Up @@ -348,13 +365,12 @@ public File getConsoleExecutable() {
}

/**
* Initializes the properties in the given execution environment
* description file.
* Loads the properties from the given execution environment description file.
*
* @param eeFile the EE file
* @exception CoreException if unable to read the file
*/
private void initProperties(File eeFile) throws CoreException {
private static Map<String, String> loadProperties(File eeFile) throws CoreException {
Map<String, String> properties = new LinkedHashMap<>();
try (Stream<String> lines = Files.lines(eeFile.toPath(), Charset.defaultCharset())) {
lines.filter(l -> !l.startsWith("#") && !l.isBlank()).forEach(line -> { //$NON-NLS-1$
Expand All @@ -375,9 +391,7 @@ private void initProperties(File eeFile) throws CoreException {
eeFile.getPath() }), e));
}
properties.putIfAbsent(EE_HOME, eeFile.getParentFile().getAbsolutePath());
// resolve things with ${ee.home} in them
fProperties = properties; // needs to be done to resolve
fProperties.replaceAll((k, value) -> value != null ? resolveHome(value) : ""); //$NON-NLS-1$
return properties;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.launching/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.launching</artifactId>
<version>3.20.200-SNAPSHOT</version>
<version>3.21.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<build>
Expand Down

0 comments on commit cce7843

Please sign in to comment.