Skip to content

Commit

Permalink
Set the real output location for embedded jars in ApiAnalysis
Browse files Browse the repository at this point in the history
Currently when one configures embedded extra jars these are not found by
the ApiAnalysis because they are placed in different location than the
main classes.

THis computes all jars and compares there resulting path with the
current output location updating those if needed.
  • Loading branch information
laeubi committed Nov 6, 2023
1 parent cd282d1 commit 4678431
Showing 1 changed file with 78 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -63,6 +65,11 @@
import org.eclipse.pde.api.tools.internal.provisional.model.IApiBaseline;
import org.eclipse.pde.api.tools.internal.provisional.model.IApiComponent;
import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem;
import org.eclipse.pde.core.build.IBuild;
import org.eclipse.pde.core.build.IBuildEntry;
import org.eclipse.pde.core.build.IBuildModel;
import org.eclipse.pde.core.plugin.IPluginModelBase;
import org.eclipse.pde.core.plugin.PluginRegistry;
import org.eclipse.pde.core.target.ITargetDefinition;
import org.eclipse.pde.core.target.ITargetLocation;
import org.eclipse.pde.core.target.ITargetPlatformService;
Expand Down Expand Up @@ -163,6 +170,7 @@ public void aboutToRun(IJobChangeEvent event) {
debug(String.valueOf(problem));
}
} finally {
// FIXME restore original classpath file!
analyzer.dispose();
ResourcesPlugin.getWorkspace().save(true, new NullProgressMonitor());
}
Expand Down Expand Up @@ -222,32 +230,96 @@ private BundleComponent importProject() throws CoreException, IOException {
}

private void createOutputFolder(IProject project, IPath projectPath) throws IOException, CoreException {
// TODO maybe just *copy* the data from the maven > eclipse location?!?
Map<String, String> outputJars = computeOutputJars(project);
IJavaProject javaProject = JavaCore.create(project);
if (javaProject != null) {
IPath fullPath = project.getFolder(outputDir).getFullPath();
IFolder outputFolder = project.getFolder(outputDir);
IPath mainOutputLocation = javaProject.getOutputLocation();
IPath mainRealPath = getRealPath(mainOutputLocation, outputJars, outputFolder);
// FIXME see bug https://github.com/eclipse-pde/eclipse.pde/issues/801
// it can happen that project output location != maven compiled classes, usually
// eclipse uses output = bin/ while maven uses target/classes if not
// specifically configured to be even
javaProject.setOutputLocation(fullPath, null);
makeOutputFolder(javaProject.getOutputLocation(), projectPath);
if (!mainOutputLocation.equals(mainRealPath)) {
javaProject.setOutputLocation(mainRealPath, null);
}
makeOutputFolder(mainRealPath);
IClasspathEntry[] classpath = javaProject.getRawClasspath();
for (IClasspathEntry entry : classpath) {
// FIXME see bug https://github.com/eclipse-pde/eclipse.pde/issues/791
makeOutputFolder(entry.getOutputLocation(), projectPath);
IPath entryOutputLocation = entry.getOutputLocation();
if (entryOutputLocation != null) {
IPath realEntryPath = getRealPath(entryOutputLocation, outputJars, outputFolder);
// FIXME see bug https://github.com/eclipse-pde/eclipse.pde/issues/791
if (realEntryPath != entryOutputLocation) {
// TODO need to update classpath!
}
makeOutputFolder(realEntryPath);
}
}
}
}

private Map<String, String> computeOutputJars(IProject project) throws CoreException {
Map<String, String> outputJars = new HashMap<String, String>();
IPluginModelBase base = PluginRegistry.findModel(project);
if (base != null) {
IBuildModel model = PluginRegistry.createBuildModel(base);
if (model != null) {
IBuild ibuild = model.getBuild();
IBuildEntry[] entries = ibuild.getBuildEntries();
for (IBuildEntry entry : entries) {
String name = entry.getName();
if (name.startsWith(IBuildEntry.OUTPUT_PREFIX)) {
String key = name.substring(IBuildEntry.OUTPUT_PREFIX.length());
if (".".equals(key)) {
// thats actually the default...
continue;
}
for (String token : entry.getTokens()) {
outputJars.put(token, key);
}
}
}
}
}
return outputJars;
}

private void makeOutputFolder(IPath outputLocation, IPath projectPath) throws CoreException, IOException {
private IPath getRealPath(IPath outputLocation, Map<String, String> outputJars, IFolder outputFolder) {
if (outputLocation == null) {
return null;
}
IFolder projectFolder = getProjectFolder(outputLocation);
for (Entry<String, String> entry : outputJars.entrySet()) {
IFolder jarFolder = projectFolder.getProject().getFolder(entry.getKey());
if (jarFolder.equals(projectFolder)) {
// we have a match!
return outputFolder.getParent()
.getFolder(new org.eclipse.core.runtime.Path(entry.getValue() + "-classes")).getFullPath();
}
}
return outputLocation;
}

private IFolder makeOutputFolder(IPath outputLocation) throws CoreException, IOException {
if (outputLocation != null) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IFolder folder = workspace.getRoot().getFolder(outputLocation);
if (!folder.exists()) {
folder.create(true, true, new NullProgressMonitor());
}
return folder;
}
return null;
}

private IFolder getProjectFolder(IPath path) {
if (path != null) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
return workspace.getRoot().getFolder(path);
}
return null;
}

private void deleteAllProjects() throws CoreException {
Expand Down

0 comments on commit 4678431

Please sign in to comment.