Skip to content

Commit

Permalink
Return Path instead of URL-String in ClasspathHelper.writeDevEntries()
Browse files Browse the repository at this point in the history
Instead returning a file-URL in it's string representation better use
the actual type of value, i.e. a Path.
  • Loading branch information
HannesWell committed Dec 19, 2024
1 parent 0d51f20 commit 17bbd75
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -469,9 +470,10 @@ public void setChildren(boolean children) {
this.children = children;
}

public void setDevEntries(String devEntries) {
if (devEntries != null)
public void setDevEntries(Path devEntries) {
if (devEntries != null) {
this.devEntries = new DevClassPathHelper(devEntries);
}
}

public void setElements(String[] elements) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,6 +15,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -67,7 +68,7 @@ static public Properties getExecutionEnvironmentMappings() {
return executionEnvironmentMappings;
}

public void setDevEntries(String entries) {
public void setDevEntries(Path entries) {
devEntries = new DevClassPathHelper(entries);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2017 IBM Corporation and others.
* Copyright (c) 2004, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,8 +15,8 @@

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;

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

public DevClassPathHelper(String devInfo) {
// Check the osgi.dev property to see if dev classpath entries have been defined.
String osgiDev = devInfo;
public DevClassPathHelper(Path osgiDev) {
if (osgiDev != null) {
try {
inDevelopmentMode = true;
URL location = new URL(osgiDev);
devProperties = load(location);
devDefaultClasspath = Utils.getArrayFromString(devProperties.getProperty("*")); //$NON-NLS-1$
} catch (MalformedURLException e) {
devDefaultClasspath = Utils.getArrayFromString(osgiDev);
}
inDevelopmentMode = true;
devProperties = load(osgiDev);
devDefaultClasspath = Utils.getArrayFromString(devProperties.getProperty("*")); //$NON-NLS-1$
}
}

Expand All @@ -66,12 +59,12 @@ public boolean inDevelopmentMode() {
/*
* Load the given properties file
*/
private static Properties load(URL url) {
private static Properties load(Path path) {
Properties props = new Properties();
try (InputStream is = url.openStream()) {
try (InputStream is = Files.newInputStream(path)) {
props.load(is);
} catch (IOException e) {
String message = NLS.bind(Messages.exception_missingFile, url.toExternalForm());
String message = NLS.bind(Messages.exception_missingFile, path);
BundleHelper.getDefault().getLog().log(new Status(IStatus.WARNING, IPDEBuildConstants.PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_READING_FILE, message, null));
}
return props;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -16,6 +16,7 @@
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Properties;

Expand Down Expand Up @@ -59,7 +60,7 @@ public void setChildren(boolean children) {
*
* @param devEntries the classpath dev entries
*/
public void setDevEntries(String devEntries) {
public void setDevEntries(Path devEntries) {
generator.setDevEntries(devEntries);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -70,7 +72,7 @@ private ClasspathHelper() { // static use only
private static final String DEV_CLASSPATH_ENTRY_SEPARATOR = ","; //$NON-NLS-1$
private static final String DEV_CLASSPATH_VERSION_SEPARATOR = ";"; //$NON-NLS-1$

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

public static String getDevEntriesProperties(String fileName, Map<String, List<IPluginModelBase>> map)
public static Path getDevEntriesProperties(String fileName, Map<String, List<IPluginModelBase>> map)
throws CoreException {
Properties properties = getDevEntriesProperties(map, true);
return writeDevEntries(fileName, properties);
}

public static String writeDevEntries(String fileName, Properties properties) throws CoreException {
File file = new File(fileName);
if (!file.exists()) {
File directory = file.getParentFile();
if (directory != null && (!directory.exists() || directory.isFile())) {
directory.mkdirs();
public static Path writeDevEntries(String fileName, Properties properties) throws CoreException {
Path file = Path.of(fileName);
try {
Files.createDirectories(file.getParent());
try (OutputStream stream = new FileOutputStream(fileName)) {
properties.store(stream, ""); //$NON-NLS-1$
return file;
}
}
try (FileOutputStream stream = new FileOutputStream(fileName)) {
properties.store(stream, ""); //$NON-NLS-1$
return new URL("file:" + fileName).toString(); //$NON-NLS-1$
} catch (IOException e) {
PDECore.logException(e);
throw new CoreException(Status.error("Failed to create dev.properties file", e)); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2022 IBM Corporation and others.
* Copyright (c) 2006, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -27,6 +27,7 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Dictionary;
Expand Down Expand Up @@ -113,7 +114,7 @@ public class FeatureExportOperation extends Job {
// Location where the build takes place
protected String fBuildTempLocation;
protected String fBuildTempMetadataLocation;
private String fDevProperties;
private Path fDevProperties;
private static boolean fHasErrors;
protected HashMap<String, String> fAntBuildProperties;
protected WorkspaceExportHelper fWorkspaceExportHelper;
Expand Down Expand Up @@ -823,7 +824,7 @@ protected void copyState(State state) {
fStateCopy.setPlatformProperties(state.getPlatformProperties());
}

private String getDevProperties() throws CoreException {
private Path getDevProperties() throws CoreException {
if (fDevProperties == null) {
fDevProperties = ClasspathHelper.getDevEntriesProperties(fBuildTempLocation + "/dev.properties", false); //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2021 IBM Corporation and others.
* Copyright (c) 2005, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -128,7 +128,7 @@ public String[] getProgramArguments(ILaunchConfiguration configuration) throws C

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

String[] args = super.getProgramArguments(configuration);
Collections.addAll(programArgs, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2022 IBM Corporation and others.
* Copyright (c) 2005, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -84,7 +84,7 @@ public String[] getProgramArguments(ILaunchConfiguration configuration) throws C
ArrayList<String> programArgs = new ArrayList<>();

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

saveConfigurationFile(configuration);
programArgs.add("-configuration"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2022 IBM Corporation and others.
* Copyright (c) 2006, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -240,7 +240,7 @@ protected void collectExecutionArguments(ILaunchConfiguration configuration, Lis
ClasspathHelper.addDevClasspath(testPlugin, devProperties, relativePath.toString(), true);
});
}
programArgs.add(ClasspathHelper.writeDevEntries(getConfigurationDirectory(configuration).toString() + "/dev.properties", devProperties)); //$NON-NLS-1$
programArgs.add(ClasspathHelper.writeDevEntries(getConfigurationDirectory(configuration).toString() + "/dev.properties", devProperties).toUri().toString()); //$NON-NLS-1$

// Create the .options file if tracing is turned on
if (configuration.getAttribute(IPDELauncherConstants.TRACING, false) && !IPDELauncherConstants.TRACING_NONE.equals(configuration.getAttribute(IPDELauncherConstants.TRACING_CHECKED, (String) null))) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2021 Sonatype, Inc. and others.
* Copyright (c) 2011, 2024 Sonatype, Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -23,11 +23,9 @@
import static org.junit.Assert.assertNull;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
Expand Down Expand Up @@ -133,9 +131,9 @@ public void testGetDevProperties() throws Exception {
mockTPWithRunningPlatformAndBundles(); // running-platform only

File devProperties = tempFolder.newFile("dev.properties").getCanonicalFile();
String devPropertiesURL = ClasspathHelper.getDevEntriesProperties(devProperties.getPath(), false);
Path devPropertiesFile = ClasspathHelper.getDevEntriesProperties(devProperties.getPath(), false);

Properties properties = loadProperties(devPropertiesURL);
Properties properties = loadProperties(devPropertiesFile);

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

private static Properties loadProperties(String devPropertiesURL) throws IOException {
File propertiesFile = new File(new URL(devPropertiesURL).getPath());
private static Properties loadProperties(Path devPropertiesFile) throws IOException {
Properties devProperties = new Properties();
try (InputStream stream = new FileInputStream(propertiesFile)) {
try (InputStream stream = Files.newInputStream(devPropertiesFile )) {
devProperties.load(stream);
}
return devProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,6 +14,7 @@
package org.eclipse.pde.internal.ui.build;

import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
Expand Down Expand Up @@ -55,8 +56,8 @@ protected void makeScripts(IProgressMonitor monitor) throws InvocationTargetExce
generator.setChildren(true);
AbstractScriptGenerator.setEmbeddedSource(AbstractScriptGenerator.getDefaultEmbeddedSource());

String url = ClasspathHelper.getDevEntriesProperties(fManifestFile.getProject().getLocation().addTrailingSeparator().toString() + "dev.properties", false); //$NON-NLS-1$
generator.setDevEntries(url);
Path path = ClasspathHelper.getDevEntriesProperties(fManifestFile.getProject().getLocation().addTrailingSeparator().toString() + "dev.properties", false); //$NON-NLS-1$
generator.setDevEntries(path);
generator.setWorkingDirectory(fManifestFile.getProject().getLocation().toOSString());
String configInfo = TargetPlatform.getOS() + ", " + TargetPlatform.getWS() + ", " + TargetPlatform.getOSArch(); //$NON-NLS-1$ //$NON-NLS-2$
AbstractScriptGenerator.setConfigInfo(configInfo); //This needs to be set before we set the format
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2015 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,6 +15,7 @@
package org.eclipse.pde.internal.ui.build;

import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;
import java.util.Properties;

import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -55,8 +56,8 @@ protected void makeScripts(IProgressMonitor monitor) throws InvocationTargetExce
AbstractScriptGenerator.setConfigInfo(AbstractScriptGenerator.getDefaultConfigInfos());

generator.setWorkingDirectory(project.getLocation().toOSString());
String url = ClasspathHelper.getDevEntriesProperties(project.getLocation().addTrailingSeparator().toString() + "dev.properties", false); //$NON-NLS-1$
generator.setDevEntries(url);
Path path = ClasspathHelper.getDevEntriesProperties(project.getLocation().addTrailingSeparator().toString() + "dev.properties", false); //$NON-NLS-1$
generator.setDevEntries(path);
generator.setPDEState(TargetPlatformHelper.getState());
generator.setNextId(TargetPlatformHelper.getPDEState().getNextId());
generator.setStateExtraData(TargetPlatformHelper.getBundleClasspaths(TargetPlatformHelper.getPDEState()), TargetPlatformHelper.getPatchMap(TargetPlatformHelper.getPDEState()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 Red Hat Inc. and others.
* Copyright (c) 2021, 2024 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -545,8 +545,11 @@ protected void collectExecutionArguments(ILaunchConfiguration configuration, Lis

// Specify the output folder names
programArgs.add("-dev"); //$NON-NLS-1$
programArgs.add(ClasspathHelper.getDevEntriesProperties(
getConfigurationDirectory(configuration).toString() + "/dev.properties", fAllBundles)); //$NON-NLS-1$
programArgs
.add(ClasspathHelper
.getDevEntriesProperties(
getConfigurationDirectory(configuration).toString() + "/dev.properties", fAllBundles) //$NON-NLS-1$
.toUri().toString());

// Create the .options file if tracing is turned on
if (configuration.getAttribute(IPDELauncherConstants.TRACING, false) && !IPDELauncherConstants.TRACING_NONE
Expand Down

0 comments on commit 17bbd75

Please sign in to comment.