-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a ClasspathContributor for API tools annotations
Currently it is quite cumbersome to use and discover the PDE own API tools annotations and requires some kind of workarounds. This adds a classpath contributor that makes the annotations available like already done for ds and bundle annotations. Fix #447
- Loading branch information
Showing
4 changed files
with
115 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
....api.tools/src/org/eclipse/pde/api/tools/internal/ApiAnnotationsClasspathContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Christoph Läubrich and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.pde.api.tools.internal; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jdt.core.IClasspathEntry; | ||
import org.eclipse.osgi.service.resolver.BundleDescription; | ||
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin; | ||
import org.eclipse.pde.core.IClasspathContributor; | ||
import org.eclipse.pde.core.plugin.IPluginModelBase; | ||
import org.eclipse.pde.core.plugin.PluginRegistry; | ||
import org.eclipse.pde.internal.core.ClasspathUtilCore; | ||
|
||
public class ApiAnnotationsClasspathContributor implements IClasspathContributor { | ||
|
||
private static final Collection<String> API_TOOLS_ANNOTATIONS = List.of("org.eclipse.pde.api.tools.annotations"); //$NON-NLS-1$ | ||
|
||
@Override | ||
public List<IClasspathEntry> getInitialEntries(BundleDescription project) { | ||
IPluginModelBase model = PluginRegistry.findModel(project); | ||
if (hasApiNature(model)) { | ||
return ClasspathUtilCore.classpathEntries(annotations()).collect(Collectors.toList()); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
|
||
|
||
private boolean hasApiNature(IPluginModelBase model) { | ||
if (model != null) { | ||
IResource resource = model.getUnderlyingResource(); | ||
if (resource != null) { | ||
try { | ||
return resource.getProject().hasNature(ApiPlugin.NATURE_ID); | ||
} catch (CoreException e) { | ||
// assume not compatible project then... | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
|
||
|
||
/** | ||
* @return s stream of all current available annotations in the current plugin | ||
* registry | ||
*/ | ||
public static Stream<IPluginModelBase> annotations() { | ||
return API_TOOLS_ANNOTATIONS.stream().map(PluginRegistry::findModel).filter(Objects::nonNull) | ||
.filter(IPluginModelBase::isEnabled); | ||
} | ||
|
||
@Override | ||
public List<IClasspathEntry> getEntriesForDependency(BundleDescription project, BundleDescription addedDependency) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters