Skip to content

Commit 04785c9

Browse files
HannesWellakurtakov
authored andcommitted
Return Path instead of URL-String in ClasspathHelper.writeDevEntries()
Instead returning a file-URL in it's string representation better use the actual type of value, i.e. a Path.
1 parent 1535dde commit 04785c9

File tree

13 files changed

+64
-65
lines changed

13 files changed

+64
-65
lines changed

build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/BuildScriptGenerator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2021 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323
import java.io.OutputStream;
24+
import java.nio.file.Path;
2425
import java.util.ArrayList;
2526
import java.util.Collection;
2627
import java.util.HashMap;
@@ -469,9 +470,10 @@ public void setChildren(boolean children) {
469470
this.children = children;
470471
}
471472

472-
public void setDevEntries(String devEntries) {
473-
if (devEntries != null)
473+
public void setDevEntries(Path devEntries) {
474+
if (devEntries != null) {
474475
this.devEntries = new DevClassPathHelper(devEntries);
476+
}
475477
}
476478

477479
public void setElements(String[] elements) {

build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/AbstractBuildScriptGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2017 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,6 +15,7 @@
1515

1616
import java.io.IOException;
1717
import java.io.InputStream;
18+
import java.nio.file.Path;
1819
import java.util.ArrayList;
1920
import java.util.HashSet;
2021
import java.util.Iterator;
@@ -67,7 +68,7 @@ static public Properties getExecutionEnvironmentMappings() {
6768
return executionEnvironmentMappings;
6869
}
6970

70-
public void setDevEntries(String entries) {
71+
public void setDevEntries(Path entries) {
7172
devEntries = new DevClassPathHelper(entries);
7273
}
7374

build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/DevClassPathHelper.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2017 IBM Corporation and others.
2+
* Copyright (c) 2004, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -15,8 +15,8 @@
1515

1616
import java.io.IOException;
1717
import java.io.InputStream;
18-
import java.net.MalformedURLException;
19-
import java.net.URL;
18+
import java.nio.file.Files;
19+
import java.nio.file.Path;
2020
import java.util.Properties;
2121

2222
import org.eclipse.core.runtime.IStatus;
@@ -32,18 +32,11 @@ public class DevClassPathHelper {
3232
protected String[] devDefaultClasspath;
3333
protected Properties devProperties = null;
3434

35-
public DevClassPathHelper(String devInfo) {
36-
// Check the osgi.dev property to see if dev classpath entries have been defined.
37-
String osgiDev = devInfo;
35+
public DevClassPathHelper(Path osgiDev) {
3836
if (osgiDev != null) {
39-
try {
40-
inDevelopmentMode = true;
41-
URL location = new URL(osgiDev);
42-
devProperties = load(location);
43-
devDefaultClasspath = Utils.getArrayFromString(devProperties.getProperty("*")); //$NON-NLS-1$
44-
} catch (MalformedURLException e) {
45-
devDefaultClasspath = Utils.getArrayFromString(osgiDev);
46-
}
37+
inDevelopmentMode = true;
38+
devProperties = load(osgiDev);
39+
devDefaultClasspath = Utils.getArrayFromString(devProperties.getProperty("*")); //$NON-NLS-1$
4740
}
4841
}
4942

@@ -66,12 +59,12 @@ public boolean inDevelopmentMode() {
6659
/*
6760
* Load the given properties file
6861
*/
69-
private static Properties load(URL url) {
62+
private static Properties load(Path path) {
7063
Properties props = new Properties();
71-
try (InputStream is = url.openStream()) {
64+
try (InputStream is = Files.newInputStream(path)) {
7265
props.load(is);
7366
} catch (IOException e) {
74-
String message = NLS.bind(Messages.exception_missingFile, url.toExternalForm());
67+
String message = NLS.bind(Messages.exception_missingFile, path);
7568
BundleHelper.getDefault().getLog().log(new Status(IStatus.WARNING, IPDEBuildConstants.PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_READING_FILE, message, null));
7669
}
7770
return props;

build/org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/tasks/BuildScriptGeneratorTask.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2021 IBM Corporation and others.
2+
* Copyright (c) 2000, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,6 +16,7 @@
1616
import java.io.File;
1717
import java.net.URI;
1818
import java.net.URISyntaxException;
19+
import java.nio.file.Path;
1920
import java.util.ArrayList;
2021
import java.util.Properties;
2122

@@ -59,7 +60,7 @@ public void setChildren(boolean children) {
5960
*
6061
* @param devEntries the classpath dev entries
6162
*/
62-
public void setDevEntries(String devEntries) {
63+
public void setDevEntries(Path devEntries) {
6364
generator.setDevEntries(devEntries);
6465
}
6566

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/ClasspathHelper.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.io.File;
2020
import java.io.FileOutputStream;
2121
import java.io.IOException;
22-
import java.net.URL;
22+
import java.io.OutputStream;
23+
import java.nio.file.Files;
24+
import java.nio.file.Path;
2325
import java.util.ArrayList;
2426
import java.util.Arrays;
2527
import java.util.Collection;
@@ -70,7 +72,7 @@ private ClasspathHelper() { // static use only
7072
private static final String DEV_CLASSPATH_ENTRY_SEPARATOR = ","; //$NON-NLS-1$
7173
private static final String DEV_CLASSPATH_VERSION_SEPARATOR = ";"; //$NON-NLS-1$
7274

73-
public static String getDevEntriesProperties(String fileName, boolean checkExcluded) throws CoreException {
75+
public static Path getDevEntriesProperties(String fileName, boolean checkExcluded) throws CoreException {
7476
IPluginModelBase[] models = PluginRegistry.getWorkspaceModels();
7577
Map<String, List<IPluginModelBase>> bundleModels = Arrays.stream(models)
7678
.filter(o -> o.toString() != null) //toString() used as key
@@ -80,23 +82,20 @@ public static String getDevEntriesProperties(String fileName, boolean checkExclu
8082
return writeDevEntries(fileName, properties);
8183
}
8284

83-
public static String getDevEntriesProperties(String fileName, Map<String, List<IPluginModelBase>> map)
85+
public static Path getDevEntriesProperties(String fileName, Map<String, List<IPluginModelBase>> map)
8486
throws CoreException {
8587
Properties properties = getDevEntriesProperties(map, true);
8688
return writeDevEntries(fileName, properties);
8789
}
8890

89-
public static String writeDevEntries(String fileName, Properties properties) throws CoreException {
90-
File file = new File(fileName);
91-
if (!file.exists()) {
92-
File directory = file.getParentFile();
93-
if (directory != null && (!directory.exists() || directory.isFile())) {
94-
directory.mkdirs();
91+
public static Path writeDevEntries(String fileName, Properties properties) throws CoreException {
92+
Path file = Path.of(fileName);
93+
try {
94+
Files.createDirectories(file.getParent());
95+
try (OutputStream stream = new FileOutputStream(fileName)) {
96+
properties.store(stream, ""); //$NON-NLS-1$
97+
return file;
9598
}
96-
}
97-
try (FileOutputStream stream = new FileOutputStream(fileName)) {
98-
properties.store(stream, ""); //$NON-NLS-1$
99-
return new URL("file:" + fileName).toString(); //$NON-NLS-1$
10099
} catch (IOException e) {
101100
PDECore.logException(e);
102101
throw new CoreException(Status.error("Failed to create dev.properties file", e)); //$NON-NLS-1$

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/exports/FeatureExportOperation.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2022 IBM Corporation and others.
2+
* Copyright (c) 2006, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -27,6 +27,7 @@
2727
import java.net.MalformedURLException;
2828
import java.net.URI;
2929
import java.net.URL;
30+
import java.nio.file.Path;
3031
import java.util.ArrayList;
3132
import java.util.Arrays;
3233
import java.util.Dictionary;
@@ -113,7 +114,7 @@ public class FeatureExportOperation extends Job {
113114
// Location where the build takes place
114115
protected String fBuildTempLocation;
115116
protected String fBuildTempMetadataLocation;
116-
private String fDevProperties;
117+
private Path fDevProperties;
117118
private static boolean fHasErrors;
118119
protected HashMap<String, String> fAntBuildProperties;
119120
protected WorkspaceExportHelper fWorkspaceExportHelper;
@@ -823,7 +824,7 @@ protected void copyState(State state) {
823824
fStateCopy.setPlatformProperties(state.getPlatformProperties());
824825
}
825826

826-
private String getDevProperties() throws CoreException {
827+
private Path getDevProperties() throws CoreException {
827828
if (fDevProperties == null) {
828829
fDevProperties = ClasspathHelper.getDevEntriesProperties(fBuildTempLocation + "/dev.properties", false); //$NON-NLS-1$
829830
}

ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/EclipseApplicationLaunchConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2021 IBM Corporation and others.
2+
* Copyright (c) 2005, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -128,7 +128,7 @@ public String[] getProgramArguments(ILaunchConfiguration configuration) throws C
128128

129129
// add the output folder names
130130
programArgs.add("-dev"); //$NON-NLS-1$
131-
programArgs.add(ClasspathHelper.getDevEntriesProperties(getConfigDir(configuration).toString() + "/dev.properties", fAllBundles)); //$NON-NLS-1$
131+
programArgs.add(ClasspathHelper.getDevEntriesProperties(getConfigDir(configuration).toString() + "/dev.properties", fAllBundles).toUri().toString()); //$NON-NLS-1$
132132

133133
String[] args = super.getProgramArguments(configuration);
134134
Collections.addAll(programArgs, args);

ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/EquinoxLaunchConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2022 IBM Corporation and others.
2+
* Copyright (c) 2005, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -84,7 +84,7 @@ public String[] getProgramArguments(ILaunchConfiguration configuration) throws C
8484
ArrayList<String> programArgs = new ArrayList<>();
8585

8686
programArgs.add("-dev"); //$NON-NLS-1$
87-
programArgs.add(ClasspathHelper.getDevEntriesProperties(getConfigDir(configuration).toString() + "/dev.properties", fAllBundles)); //$NON-NLS-1$
87+
programArgs.add(ClasspathHelper.getDevEntriesProperties(getConfigDir(configuration).toString() + "/dev.properties", fAllBundles).toUri().toString()); //$NON-NLS-1$
8888

8989
saveConfigurationFile(configuration);
9090
programArgs.add("-configuration"); //$NON-NLS-1$

ui/org.eclipse.pde.launching/src/org/eclipse/pde/launching/JUnitLaunchConfigurationDelegate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2022 IBM Corporation and others.
2+
* Copyright (c) 2006, 2024 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -240,7 +240,7 @@ protected void collectExecutionArguments(ILaunchConfiguration configuration, Lis
240240
ClasspathHelper.addDevClasspath(testPlugin, devProperties, relativePath.toString(), true);
241241
});
242242
}
243-
programArgs.add(ClasspathHelper.writeDevEntries(getConfigurationDirectory(configuration).toString() + "/dev.properties", devProperties)); //$NON-NLS-1$
243+
programArgs.add(ClasspathHelper.writeDevEntries(getConfigurationDirectory(configuration).toString() + "/dev.properties", devProperties).toUri().toString()); //$NON-NLS-1$
244244

245245
// Create the .options file if tracing is turned on
246246
if (configuration.getAttribute(IPDELauncherConstants.TRACING, false) && !IPDELauncherConstants.TRACING_NONE.equals(configuration.getAttribute(IPDELauncherConstants.TRACING_CHECKED, (String) null))) {

ui/org.eclipse.pde.ui.tests/src/org/eclipse/pde/ui/tests/classpathresolver/ClasspathResolverTest.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2021 Sonatype, Inc. and others.
2+
* Copyright (c) 2011, 2024 Sonatype, Inc. and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -23,11 +23,9 @@
2323
import static org.junit.Assert.assertNull;
2424

2525
import java.io.File;
26-
import java.io.FileInputStream;
2726
import java.io.IOException;
2827
import java.io.InputStream;
2928
import java.lang.reflect.Field;
30-
import java.net.URL;
3129
import java.nio.file.Files;
3230
import java.nio.file.Path;
3331
import java.util.List;
@@ -133,9 +131,9 @@ public void testGetDevProperties() throws Exception {
133131
mockTPWithRunningPlatformAndBundles(); // running-platform only
134132

135133
File devProperties = tempFolder.newFile("dev.properties").getCanonicalFile();
136-
String devPropertiesURL = ClasspathHelper.getDevEntriesProperties(devProperties.getPath(), false);
134+
Path devPropertiesFile = ClasspathHelper.getDevEntriesProperties(devProperties.getPath(), false);
137135

138-
Properties properties = loadProperties(devPropertiesURL);
136+
Properties properties = loadProperties(devPropertiesFile);
139137

140138
String expectedDevCP = project.getFolder("cpe").getLocation().toPortableString();
141139
assertEquals(expectedDevCP, properties.get(bundleName));
@@ -404,14 +402,13 @@ private Properties createDevEntryProperties(List<IPluginModelBase> launchedBundl
404402
throws IOException, CoreException {
405403
File devPropertiesFile = tempFolder.newFile("dev.properties").getCanonicalFile();
406404
Map<String, List<IPluginModelBase>> bundlesMap = Map.of(HOST_BUNDLE_ID, launchedBundles);
407-
String devPropertiesURL = ClasspathHelper.getDevEntriesProperties(devPropertiesFile.getPath(), bundlesMap);
408-
return loadProperties(devPropertiesURL);
405+
Path devProperties = ClasspathHelper.getDevEntriesProperties(devPropertiesFile.getPath(), bundlesMap);
406+
return loadProperties(devProperties);
409407
}
410408

411-
private static Properties loadProperties(String devPropertiesURL) throws IOException {
412-
File propertiesFile = new File(new URL(devPropertiesURL).getPath());
409+
private static Properties loadProperties(Path devPropertiesFile) throws IOException {
413410
Properties devProperties = new Properties();
414-
try (InputStream stream = new FileInputStream(propertiesFile)) {
411+
try (InputStream stream = Files.newInputStream(devPropertiesFile )) {
415412
devProperties.load(stream);
416413
}
417414
return devProperties;

0 commit comments

Comments
 (0)