Skip to content

Commit

Permalink
Add flag to fail API tools on resolution error
Browse files Browse the repository at this point in the history
Fixes #3570

(cherry picked from commit dde1dec)
  • Loading branch information
Kummallinen committed Apr 14, 2024
1 parent eb19275 commit 350c1a1
Show file tree
Hide file tree
Showing 19 changed files with 592 additions and 2 deletions.
Expand Up @@ -120,6 +120,9 @@ public class ApiAnalysisMojo extends AbstractMojo {
@Parameter(defaultValue = "true")
private boolean printSummary;

@Parameter(defaultValue = "false")
private boolean failOnResolutionError;

@Parameter(defaultValue = "true")
private boolean failOnError;

Expand Down Expand Up @@ -162,8 +165,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
try {
baselineBundles = getBaselineBundles();
} catch (DependencyResolutionException e) {
log.warn("Can't resolve API baseline, API baseline check is skipped!");
return;
if (failOnResolutionError) {
throw new MojoFailureException("Can't resolve API baseline!", e);
} else {
log.warn("Can't resolve API baseline, API baseline check is skipped!");
return;
}
}
Collection<Path> dependencyBundles;
try {
Expand Down
@@ -0,0 +1 @@
-Dtycho-version=4.0.0-SNAPSHOT
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<site>
<bundle id="api-bundle-1"/>
</site>
11 changes: 11 additions & 0 deletions tycho-its/projects/api-tools/missing-dependency/api-repo/pom.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.tycho.tycho-its</groupId>
<artifactId>apitools-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>api-repo</artifactId>
<packaging>eclipse-repository</packaging>
</project>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="bin"/>
</classpath>
40 changes: 40 additions & 0 deletions tycho-its/projects/api-tools/missing-dependency/bundle1/.project
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>api-bundle-1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<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.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,9 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin with API
Bundle-SymbolicName: api-bundle-1
Bundle-Version: 0.0.1.qualifier
Require-Bundle: org.eclipse.core.runtime
Bundle-RequiredExecutionEnvironment: JavaSE-11
Export-Package: bundle
Automatic-Module-Name: bundle
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = .,\
META-INF/
11 changes: 11 additions & 0 deletions tycho-its/projects/api-tools/missing-dependency/bundle1/pom.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.tycho.tycho-its</groupId>
<artifactId>apitools-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>api-bundle-1</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
@@ -0,0 +1,7 @@
package bundle;

public interface ApiInterface {

void sayHello();

}
@@ -0,0 +1,16 @@
package bundle;

import java.util.Collection;
import java.util.List;

public class ClassA {

public String getGreetings() { // originally getString()
return "Hello World";
}

public Collection<String> getCollection() { // originally returned List
return List.of();
}

}
@@ -0,0 +1,5 @@
package bundle;

public interface InterfaceB { // originally named 'InterfaceA'

}
63 changes: 63 additions & 0 deletions tycho-its/projects/api-tools/missing-dependency/pom.xml
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.tycho.tycho-its</groupId>
<artifactId>apitools-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<!--module>api-repo</module-->
<!-- Used to build the baseline repo -->
<module>bundle1</module>
<module>api-repo</module>
</modules>
<properties>
<failResolutionError>false</failResolutionError>
<target-platform>https://download.eclipse.org/releases/2023-09/</target-platform>
</properties>
<repositories>
<repository>
<id>platform</id>
<url>${target-platform}</url>
<layout>p2</layout>
</repository>
</repositories>
<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>
<configuration>
<baselines>
<repository>
<id>baseline</id>
<url>${baselineRepo}</url>
</repository>
</baselines>
<failOnResolutionError>${failResolutionError}</failOnResolutionError>
</configuration>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
<execution>
<id>analyse</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3 changes: 3 additions & 0 deletions tycho-its/repositories/api-tools-broken/README
@@ -0,0 +1,3 @@
This is debliberatly not a p2 repository.

It is used to test API Tools behaviour when baseline resolution fails
28 changes: 28 additions & 0 deletions tycho-its/repositories/api-tools-incomplete/artifacts.xml
@@ -0,0 +1,28 @@
<?xml version='1.0' encoding='UTF-8'?>
<?artifactRepository version='1.1.0'?>
<repository name='api-repo' type='org.eclipse.equinox.p2.artifact.repository.simpleRepository' version='1'>
<properties size='2'>
<property name='p2.timestamp' value='1712417422899'/>
<property name='p2.compressed' value='true'/>
</properties>
<mappings size='3'>
<rule filter='(&amp; (classifier=osgi.bundle))' output='${repoUrl}/plugins/${id}_${version}.jar'/>
<rule filter='(&amp; (classifier=binary))' output='${repoUrl}/binary/${id}_${version}'/>
<rule filter='(&amp; (classifier=org.eclipse.update.feature))' output='${repoUrl}/features/${id}_${version}.jar'/>
</mappings>
<artifacts size='1'>
<artifact classifier='osgi.bundle' id='api-bundle-1' version='0.0.1.202404061530'>
<properties size='9'>
<property name='artifact.size' value='2776'/>
<property name='download.size' value='2776'/>
<property name='download.checksum.sha-512' value='602076046fe598cdfc5577d821073ea232e7763eb6da2d8a24a76ba03cfd1ad697923f18b46b70fabb6ade9962fe17aa764abd55b2986c9df29c6e82d79398fa'/>
<property name='download.checksum.sha-1' value='ec8fba619a385c2aff447db1af4ae7bee746c26d'/>
<property name='download.checksum.sha-256' value='48b87b31b78a2f85cbc6b7192309b0c3a0aee51f2ada598fd0c04487988029a0'/>
<property name='maven-groupId' value='org.eclipse.tycho.tycho-its'/>
<property name='maven-artifactId' value='api-bundle-1'/>
<property name='maven-version' value='0.0.1-SNAPSHOT'/>
<property name='maven-type' value='eclipse-plugin'/>
</properties>
</artifact>
</artifacts>
</repository>

0 comments on commit 350c1a1

Please sign in to comment.