Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Path instead of URL-String in ClasspathHelper.writeDevEntries() #1530

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/org.eclipse.pde.build/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.pde.build;singleton:=true
Bundle-Version: 3.12.600.qualifier
Bundle-Version: 3.12.700.qualifier
Bundle-ClassPath: pdebuild.jar
Bundle-Activator: org.eclipse.pde.internal.build.BuildActivator
Bundle-Vendor: %providerName
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 @@ -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 @@
// 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 @@ -620,11 +621,11 @@
try {
String destination = ""; //$NON-NLS-1$
if (publishingP2Metadata()) {
destination = new File(fBuildTempMetadataLocation).toURL().toString();

Check warning on line 624 in ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/exports/FeatureExportOperation.java

View check run for this annotation

Jenkins - eclipse-pde / Compiler and API Tools

Deprecation

NORMAL: The method toURL() from the type File is deprecated
map.put(IBuildPropertiesConstants.PROPERTY_P2_BUILD_REPO, destination);
} else {
if (fInfo.toDirectory) {
destination = new File(fInfo.destinationDirectory).toURL().toString();

Check warning on line 628 in ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/exports/FeatureExportOperation.java

View check run for this annotation

Jenkins - eclipse-pde / Compiler and API Tools

Deprecation

NORMAL: The method toURL() from the type File is deprecated
} else {
destination = new File(fBuildTempMetadataLocation).toURI().toURL().toString();
}
Expand Down Expand Up @@ -823,7 +824,7 @@
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
Loading