Skip to content

Commit

Permalink
Fix lookup of workspace located annotation providers
Browse files Browse the repository at this point in the history
Currently, if a annotation project is part of the workspace (most
notable (org.eclipse.pde.api.tools.annotations) it currently does not
resolve the binary folders correctly.

This fixes the conversion of plugin models to classpath entries by check
if a build model is available and if found uses the binary folders as
classpath entries instead of the base location.
  • Loading branch information
laeubi committed Jan 21, 2024
1 parent 76e5d1f commit c4c5104
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public class ApiAnnotationsClasspathContributor implements IClasspathContributor

@Override
public List<IClasspathEntry> getInitialEntries(BundleDescription project) {
IPluginModelBase model = PluginRegistry.findModel(project);
if (hasApiNature(model)) {
return ClasspathUtilCore.classpathEntries(annotations()).collect(Collectors.toList());
IPluginModelBase projectModel = PluginRegistry.findModel(project);
if (hasApiNature(projectModel)) {
return ClasspathUtilCore.classpathEntries(annotations().filter(model -> !model.equals(projectModel)))
.collect(Collectors.toList());
}
return Collections.emptyList();
}
Expand Down
24 changes: 8 additions & 16 deletions ui/org.eclipse.pde.core/.settings/.api_filters
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.pde.core" version="2">
<resource path="src/org/eclipse/pde/core/ModelChangedEvent.java" type="org.eclipse.pde.core.ModelChangedEvent">
<filter comment="This is PDEs own implementation" id="576725006">
<message_arguments>
<message_argument value="IModelChangedEvent"/>
<message_argument value="ModelChangedEvent"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/pde/internal/core/project/BundleProjectService.java" type="org.eclipse.pde.internal.core.project.BundleProjectService">
<filter comment="Platform Team allows use of bundle importers for PDE import from source repository" id="640712815">
<message_arguments>
Expand All @@ -9,20 +17,4 @@
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/pde/internal/core/target/ExportTargetJob.java" type="org.eclipse.pde.internal.core.target.ExportTargetJob">
<filter comment="Using IProvidedCapability is the only current available option to export a p2 target correctly" id="640712815">
<message_arguments>
<message_argument value="IProvidedCapability"/>
<message_argument value="ExportTargetJob"/>
<message_argument value="getName()"/>
</message_arguments>
</filter>
<filter comment="Using IProvidedCapability is the only current available option to export a p2 target correctly" id="640712815">
<message_arguments>
<message_argument value="IProvidedCapability"/>
<message_argument value="ExportTargetJob"/>
<message_argument value="getNamespace()"/>
</message_arguments>
</filter>
</resource>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.VersionRange;
Expand Down Expand Up @@ -408,13 +409,16 @@ private static IPluginModelBase[] findModels(String id) {
*/
public static IBuildModel createBuildModel(IPluginModelBase model) throws CoreException {
if (model != null) {
IProject project = model.getUnderlyingResource().getProject();
if (project != null) {
IFile buildFile = PDEProject.getBuildProperties(project);
if (buildFile.exists()) {
IBuildModel buildModel = new WorkspaceBuildModel(buildFile);
buildModel.load();
return buildModel;
IResource resource = model.getUnderlyingResource();
if (resource != null) {
IProject project = resource.getProject();
if (project != null) {
IFile buildFile = PDEProject.getBuildProperties(project);
if (buildFile.exists()) {
IBuildModel buildModel = new WorkspaceBuildModel(buildFile);
buildModel.load();
return buildModel;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.core.resources.IResource;
Expand All @@ -28,6 +31,7 @@
import org.eclipse.jdt.core.IAccessRule;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.pde.core.build.IBuild;
Expand Down Expand Up @@ -82,25 +86,40 @@ private static Collection<ClasspathLibrary> collectLibraryEntries(IPluginModelBa
}

public static Stream<IClasspathEntry> classpathEntries(Stream<IPluginModelBase> models) {
return models.flatMap(model -> {
String location = model.getInstallLocation();
if (location == null) {
return Stream.empty();
}
boolean isJarShape = new File(location).isFile();
IPluginLibrary[] libraries = model.getPluginBase().getLibraries();
if (isJarShape || libraries.length == 0) {
return Stream.of(IPath.fromOSString(location));
Map<Boolean, List<IPluginModelBase>> collect = models.collect(Collectors.partitioningBy(model -> {
IResource resource = model.getUnderlyingResource();
if (resource != null) {
try {
return resource.getProject().hasNature(JavaCore.NATURE_ID);
} catch (CoreException e) {
// nothing we can do then...
}
}
return Arrays.stream(libraries).filter(library -> !IPluginLibrary.RESOURCE.equals(library.getType()))
.map(library -> {
String name = library.getName();
String expandedName = ClasspathUtilCore.expandLibraryName(name);
IPath path = ClasspathUtilCore.getPath(model, expandedName, isJarShape);
return path;
}).filter(Objects::nonNull);
}).map(path -> JavaCore.newLibraryEntry(path, path, IPath.ROOT, new IAccessRule[0], new IClasspathAttribute[0],
false));
return false;
}));
List<IPluginModelBase> javaModels = collect.get(true);
List<IPluginModelBase> externalModels = collect.get(false);
return Stream.concat(
javaModels.stream().map(m -> JavaCore.create(m.getUnderlyingResource().getProject()))
.map(IJavaProject::getPath).map(JavaCore::newProjectEntry),
externalModels.stream().flatMap(model -> {
String location = model.getInstallLocation();
if (location == null) {
return Stream.empty();
}
boolean isJarShape = new File(location).isFile();
IPluginLibrary[] libraries = model.getPluginBase().getLibraries();
if (isJarShape || libraries.length == 0) {
return Stream.of(IPath.fromOSString(location));
}
return Arrays.stream(libraries)
.filter(library -> !IPluginLibrary.RESOURCE.equals(library.getType())).map(library -> {
String name = library.getName();
String expandedName = ClasspathUtilCore.expandLibraryName(name);
return ClasspathUtilCore.getPath(model, expandedName, isJarShape);
}).filter(Objects::nonNull);
}).map(path -> JavaCore.newLibraryEntry(path, path, IPath.ROOT, new IAccessRule[0],
new IClasspathAttribute[0], false)));
}

private static void addLibraryEntry(IPluginLibrary library, Collection<ClasspathLibrary> entries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ public class OSGiAnnotationsClasspathContributor implements IClasspathContributo

@Override
public List<IClasspathEntry> getInitialEntries(BundleDescription project) {
IPluginModelBase model = PluginRegistry.findModel(project);
if (model != null) {
return ClasspathUtilCore.classpathEntries(annotations()).collect(Collectors.toList());
IPluginModelBase projectModel = PluginRegistry.findModel(project);
if (projectModel != null) {
return ClasspathUtilCore
.classpathEntries(annotations().filter(model -> !model.equals(projectModel)))
.collect(Collectors.toList());
}
return Collections.emptyList();
}
Expand Down

0 comments on commit c4c5104

Please sign in to comment.