Skip to content

Commit

Permalink
Add support for API Tools Annotations to Tycho
Browse files Browse the repository at this point in the history
This adds a similar feature like PDE will offer soon see
eclipse-pde/eclipse.pde#912
  • Loading branch information
laeubi committed Nov 13, 2023
1 parent f1cb4b1 commit b25118a
Show file tree
Hide file tree
Showing 11 changed files with 178 additions and 9 deletions.
10 changes: 10 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

This page describes the noteworthy improvements provided by each release of Eclipse Tycho.

## 4.0.5

### backports:
- support for PDE Api Tools Annotations
- api tools fixes

## 4.0.4

Various bugfixes and backports

## 4.0.3

### new option to filter added repository-references when assembling a p2-repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
Optional<EclipseProject> eclipseProject = projectManager.getEclipseProject(project);
if (eclipseProject.isEmpty()
|| !eclipseProject.get().hasNature("org.eclipse.pde.api.tools.apiAnalysisNature")) {
|| !eclipseProject.get().hasNature(ApiPlugin.NATURE_ID)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* 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.tycho.apitools;

import java.util.Optional;

import javax.inject.Inject;

import org.apache.maven.SessionScoped;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.eclipse.pde.api.tools.internal.provisional.ApiPlugin;
import org.eclipse.tycho.classpath.ClasspathContributor;
import org.eclipse.tycho.core.TychoProjectManager;
import org.eclipse.tycho.core.osgitools.AbstractSpecificationClasspathContributor;
import org.eclipse.tycho.model.project.EclipseProject;
import org.osgi.framework.VersionRange;

@Component(role = ClasspathContributor.class, hint = "apitools-annotations")
@SessionScoped
public class ApiAnnotationsClasspathContributor extends AbstractSpecificationClasspathContributor {

private static final String PACKAGE_NAME = "org.eclipse.pde.api.tools.annotations";
private static final String GROUP_ID = "org.eclipse.pde";
private static final String ARTIFACT_ID = "org.eclipse.pde.api.tools.annotations";
private static final VersionRange VERSION = new VersionRange("[1,2)");
private TychoProjectManager projectManager;

@Inject
public ApiAnnotationsClasspathContributor(MavenSession session, TychoProjectManager projectManager) {
super(session, PACKAGE_NAME, GROUP_ID, ARTIFACT_ID);
this.projectManager = projectManager;
}

@Override
protected VersionRange getSpecificationVersion(MavenProject project) {
return VERSION;
}

@Override
protected boolean isValidProject(MavenProject project) {
Optional<EclipseProject> eclipseProject = projectManager.getEclipseProject(project);
if (eclipseProject.isPresent()) {
return eclipseProject.get().hasNature(ApiPlugin.NATURE_ID);
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,24 @@ protected AbstractSpecificationClasspathContributor(MavenSession session, String

@Override
public final List<ClasspathEntry> getAdditionalClasspathEntries(MavenProject project, String scope) {
VersionRange specificationVersion = getSpecificationVersion(project);
Optional<ResolvedArtifactKey> mavenBundle = findBundle(project, specificationVersion);
if (mavenBundle.isPresent()) {
ResolvedArtifactKey resolved = mavenBundle.get();
logger.debug("Resolved " + packageName + " to " + resolved.getId() + " " + resolved.getVersion() + " @ "
+ resolved.getLocation());
return List.of(new DefaultClasspathEntry(resolved, List.of(accessRule)));
if (isValidProject(project)) {
VersionRange specificationVersion = getSpecificationVersion(project);
Optional<ResolvedArtifactKey> mavenBundle = findBundle(project, specificationVersion);
if (mavenBundle.isPresent()) {
ResolvedArtifactKey resolved = mavenBundle.get();
logger.debug("Resolved " + packageName + " to " + resolved.getId() + " " + resolved.getVersion() + " @ "
+ resolved.getLocation());
return List.of(new DefaultClasspathEntry(resolved, List.of(accessRule)));
}
logger.warn("Cannot resolve specification package " + packageName + ", classpath might be incomplete");
}
logger.warn("Cannot resolve specification package " + packageName + ", classpath might be incomplete");
return Collections.emptyList();
}

protected boolean isValidProject(MavenProject project) {
return true;
}

protected Optional<ResolvedArtifactKey> findBundle(MavenProject project, VersionRange specificationVersion) {
Optional<ResolvedArtifactKey> mavenBundle = mavenBundleResolver.resolveMavenBundle(project, session,
MavenArtifactKey.of(PublisherHelper.CAPABILITY_NS_JAVA_PACKAGE, packageName,
Expand Down
7 changes: 7 additions & 0 deletions tycho-its/projects/api-tools/annotations/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
34 changes: 34 additions & 0 deletions tycho-its/projects/api-tools/annotations/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>api-bundle-2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
</natures>
</projectDescription>
8 changes: 8 additions & 0 deletions tycho-its/projects/api-tools/annotations/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin with API
Bundle-SymbolicName: api-bundle-2
Bundle-Version: 0.0.1.qualifier
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=11))"
Export-Package: bundle
Automatic-Module-Name: bundle
4 changes: 4 additions & 0 deletions tycho-its/projects/api-tools/annotations/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = .,\
META-INF/
23 changes: 23 additions & 0 deletions tycho-its/projects/api-tools/annotations/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.tycho.tycho-its</groupId>
<artifactId>api-bundle-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-apitools-plugin</artifactId>
<version>${tycho-version}</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package bundle;

import org.eclipse.pde.api.tools.annotations.NoExtend;

@NoExtend
public interface ApiInterface2 {

void sayHello();

}
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,11 @@ public void testSingleJar() throws Exception {
verifier.executeGoals(List.of("clean", "verify"));
verifier.verifyErrorFreeLog();
}

@Test
public void testAnnotations() throws Exception {
Verifier verifier = getVerifier("api-tools/annotations", true, true);
verifier.executeGoals(List.of("clean", "verify"));
verifier.verifyErrorFreeLog();
}
}

0 comments on commit b25118a

Please sign in to comment.