diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java index 5f3fd7cc80..0915f8b3c9 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java @@ -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; @@ -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 dependencyBundles; try { diff --git a/tycho-its/projects/api-tools/missing-dependency/.mvn/maven.config b/tycho-its/projects/api-tools/missing-dependency/.mvn/maven.config new file mode 100644 index 0000000000..70ac38db10 --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/.mvn/maven.config @@ -0,0 +1 @@ +-Dtycho-version=4.0.0-SNAPSHOT diff --git a/tycho-its/projects/api-tools/missing-dependency/api-repo/category.xml b/tycho-its/projects/api-tools/missing-dependency/api-repo/category.xml new file mode 100644 index 0000000000..94d970e064 --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/api-repo/category.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tycho-its/projects/api-tools/missing-dependency/api-repo/pom.xml b/tycho-its/projects/api-tools/missing-dependency/api-repo/pom.xml new file mode 100644 index 0000000000..3c720caede --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/api-repo/pom.xml @@ -0,0 +1,11 @@ + + + 4.0.0 + + org.eclipse.tycho.tycho-its + apitools-parent + 0.0.1-SNAPSHOT + + api-repo + eclipse-repository + diff --git a/tycho-its/projects/api-tools/missing-dependency/bundle1/.classpath b/tycho-its/projects/api-tools/missing-dependency/bundle1/.classpath new file mode 100644 index 0000000000..edc8895124 --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/bundle1/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tycho-its/projects/api-tools/missing-dependency/bundle1/.project b/tycho-its/projects/api-tools/missing-dependency/bundle1/.project new file mode 100644 index 0000000000..5056fa5fae --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/bundle1/.project @@ -0,0 +1,40 @@ + + + api-bundle-1 + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + org.eclipse.pde.api.tools.apiAnalysisNature + + diff --git a/tycho-its/projects/api-tools/missing-dependency/bundle1/META-INF/MANIFEST.MF b/tycho-its/projects/api-tools/missing-dependency/bundle1/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..7c58159dc8 --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/bundle1/META-INF/MANIFEST.MF @@ -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 diff --git a/tycho-its/projects/api-tools/missing-dependency/bundle1/build.properties b/tycho-its/projects/api-tools/missing-dependency/bundle1/build.properties new file mode 100644 index 0000000000..12b49e3215 --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/bundle1/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = .,\ + META-INF/ diff --git a/tycho-its/projects/api-tools/missing-dependency/bundle1/pom.xml b/tycho-its/projects/api-tools/missing-dependency/bundle1/pom.xml new file mode 100644 index 0000000000..1929259cf4 --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/bundle1/pom.xml @@ -0,0 +1,11 @@ + + + 4.0.0 + + org.eclipse.tycho.tycho-its + apitools-parent + 0.0.1-SNAPSHOT + + api-bundle-1 + eclipse-plugin + diff --git a/tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/ApiInterface.java b/tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/ApiInterface.java new file mode 100644 index 0000000000..f4668e5f5c --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/ApiInterface.java @@ -0,0 +1,7 @@ +package bundle; + +public interface ApiInterface { + + void sayHello(); + +} diff --git a/tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/ClassA.java b/tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/ClassA.java new file mode 100644 index 0000000000..471fe279f0 --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/ClassA.java @@ -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 getCollection() { // originally returned List + return List.of(); + } + +} diff --git a/tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/InterfaceB.java b/tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/InterfaceB.java new file mode 100644 index 0000000000..d376c17b7f --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/InterfaceB.java @@ -0,0 +1,5 @@ +package bundle; + +public interface InterfaceB { // originally named 'InterfaceA' + +} diff --git a/tycho-its/projects/api-tools/missing-dependency/pom.xml b/tycho-its/projects/api-tools/missing-dependency/pom.xml new file mode 100644 index 0000000000..9523f83393 --- /dev/null +++ b/tycho-its/projects/api-tools/missing-dependency/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + org.eclipse.tycho.tycho-its + apitools-parent + 0.0.1-SNAPSHOT + pom + + + + bundle1 + api-repo + + + false + https://download.eclipse.org/releases/2023-09/ + + + + platform + ${target-platform} + p2 + + + + + + org.eclipse.tycho + tycho-maven-plugin + ${tycho-version} + true + + + org.eclipse.tycho + tycho-apitools-plugin + ${tycho-version} + + + + baseline + ${baselineRepo} + + + ${failResolutionError} + + + + generate + + generate + + + + analyse + + verify + + + + + + + \ No newline at end of file diff --git a/tycho-its/repositories/api-tools-broken/README b/tycho-its/repositories/api-tools-broken/README new file mode 100644 index 0000000000..b16c1ce3b7 --- /dev/null +++ b/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 diff --git a/tycho-its/repositories/api-tools-incomplete/artifacts.xml b/tycho-its/repositories/api-tools-incomplete/artifacts.xml new file mode 100644 index 0000000000..8084145007 --- /dev/null +++ b/tycho-its/repositories/api-tools-incomplete/artifacts.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tycho-its/repositories/api-tools-incomplete/content.xml b/tycho-its/repositories/api-tools-incomplete/content.xml new file mode 100644 index 0000000000..11e6723470 --- /dev/null +++ b/tycho-its/repositories/api-tools-incomplete/content.xml @@ -0,0 +1,330 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + api-bundle-1 + + + + + (org.eclipse.update.install.sources=true) + + + + + + + + + + + Bundle-SymbolicName: api-bundle-1 Bundle-Version: 0.0.1.202404061530 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tycho-its/repositories/api-tools-incomplete/p2.index b/tycho-its/repositories/api-tools-incomplete/p2.index new file mode 100644 index 0000000000..0e7d423d02 --- /dev/null +++ b/tycho-its/repositories/api-tools-incomplete/p2.index @@ -0,0 +1,4 @@ +#Sat Sep 24 09:53:44 CEST 2022 +artifact.repository.factory.order=artifacts.xml,\! +version=1 +metadata.repository.factory.order=content.xml,\! diff --git a/tycho-its/repositories/api-tools-incomplete/plugins/api-bundle-1_0.0.1.202404061530.jar b/tycho-its/repositories/api-tools-incomplete/plugins/api-bundle-1_0.0.1.202404061530.jar new file mode 100644 index 0000000000..bca0380417 Binary files /dev/null and b/tycho-its/repositories/api-tools-incomplete/plugins/api-bundle-1_0.0.1.202404061530.jar differ diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/apitools/ApiToolsTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/apitools/ApiToolsTest.java index 3b8f936e33..4d155cd6d7 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/apitools/ApiToolsTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/apitools/ApiToolsTest.java @@ -149,4 +149,44 @@ public void testAnnotations() throws Exception { verifier.executeGoals(List.of("clean", "verify")); verifier.verifyErrorFreeLog(); } + + @Test + public void testInvalidRepo() throws Exception { + Verifier verifier = getVerifier("api-tools/single-jar", true, true); + File repo = ResourceUtil.resolveTestResource("repositories/api-tools-broken"); + verifier.addCliOption("-DbaselineRepo=" + repo.toURI()); + + assertThrows(VerificationException.class, () -> verifier.executeGoals(List.of("clean", "verify")), "Did not error on missing repo"); + } + + @Test + public void testBaselineResolutonFailure_Error() throws Exception { + Verifier verifier = getVerifier("api-tools/missing-dependency", true, true); + File repo = ResourceUtil.resolveTestResource("repositories/api-tools-incomplete"); + verifier.addCliOption("-DbaselineRepo=" + repo.toURI()); + verifier.addCliOption("-DfailResolutionError=true"); + + assertThrows(VerificationException.class, () -> verifier.executeGoals(List.of("clean", "verify")), "Did not error on resolution failure"); + verifier.verifyTextInLog("Can't resolve API baseline!"); + } + + @Test + public void testBaselineResolutonFailure_Warn() throws Exception { + Verifier verifier = getVerifier("api-tools/missing-dependency", true, true); + File repo = ResourceUtil.resolveTestResource("repositories/api-tools-incomplete"); + verifier.addCliOption("-DbaselineRepo=" + repo.toURI()); + + verifier.executeGoals(List.of("clean", "verify")); + verifier.verifyTextInLog("Can't resolve API baseline, API baseline check is skipped!"); + } + + @Test + public void testBaselineResolutonFailure_Default() throws Exception { + Verifier verifier = getVerifier("api-tools/single-jar", true, true); + File repo = ResourceUtil.resolveTestResource("repositories/api-tools-incomplete"); + verifier.addCliOption("-DbaselineRepo=" + repo.toURI()); + + verifier.executeGoals(List.of("clean", "verify")); + verifier.verifyTextInLog("Can't resolve API baseline, API baseline check is skipped!"); + } }