From dde1decfa85d7abe47adfb73118a1a2985062202 Mon Sep 17 00:00:00 2001 From: William Riley Date: Sat, 6 Apr 2024 13:14:58 +0100 Subject: [PATCH] Add flag to fail API tools on resolution error Fixes #3570 --- .../tycho/apitools/ApiAnalysisMojo.java | 11 +- .../missing-dependency/.mvn/maven.config | 1 + .../missing-dependency/api-repo/category.xml | 4 + .../missing-dependency/api-repo/pom.xml | 11 + .../missing-dependency/bundle1/.classpath | 7 + .../missing-dependency/bundle1/.project | 40 +++ .../bundle1/META-INF/MANIFEST.MF | 9 + .../bundle1/build.properties | 4 + .../missing-dependency/bundle1/pom.xml | 11 + .../bundle1/src/bundle/ApiInterface.java | 7 + .../bundle1/src/bundle/ClassA.java | 16 + .../bundle1/src/bundle/InterfaceB.java | 5 + .../api-tools/missing-dependency/pom.xml | 63 ++++ .../repositories/api-tools-broken/README | 3 + .../api-tools-incomplete/artifacts.xml | 28 ++ .../api-tools-incomplete/content.xml | 330 ++++++++++++++++++ .../api-tools-incomplete/p2.index | 4 + .../api-bundle-1_0.0.1.202404061530.jar | Bin 0 -> 2776 bytes .../tycho/test/apitools/ApiToolsTest.java | 40 +++ 19 files changed, 592 insertions(+), 2 deletions(-) create mode 100644 tycho-its/projects/api-tools/missing-dependency/.mvn/maven.config create mode 100644 tycho-its/projects/api-tools/missing-dependency/api-repo/category.xml create mode 100644 tycho-its/projects/api-tools/missing-dependency/api-repo/pom.xml create mode 100644 tycho-its/projects/api-tools/missing-dependency/bundle1/.classpath create mode 100644 tycho-its/projects/api-tools/missing-dependency/bundle1/.project create mode 100644 tycho-its/projects/api-tools/missing-dependency/bundle1/META-INF/MANIFEST.MF create mode 100644 tycho-its/projects/api-tools/missing-dependency/bundle1/build.properties create mode 100644 tycho-its/projects/api-tools/missing-dependency/bundle1/pom.xml create mode 100644 tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/ApiInterface.java create mode 100644 tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/ClassA.java create mode 100644 tycho-its/projects/api-tools/missing-dependency/bundle1/src/bundle/InterfaceB.java create mode 100644 tycho-its/projects/api-tools/missing-dependency/pom.xml create mode 100644 tycho-its/repositories/api-tools-broken/README create mode 100644 tycho-its/repositories/api-tools-incomplete/artifacts.xml create mode 100644 tycho-its/repositories/api-tools-incomplete/content.xml create mode 100644 tycho-its/repositories/api-tools-incomplete/p2.index create mode 100644 tycho-its/repositories/api-tools-incomplete/plugins/api-bundle-1_0.0.1.202404061530.jar 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 0000000000000000000000000000000000000000..bca03804176403fa9fbccb1bf3900e64d1f7bcbb GIT binary patch literal 2776 zcmWIWW@h1HVBlb2INjV9!GHuffoxyb5Jz24KR5jVpfVAlG7hk^4f1Z*|A5lvj0_Aw zQG_yIM?X(D*WeI6UpLzc2lJW@1YF*G{A1T{=i=MeuwxOw{K9^}g?aTAuCoRIHmk#XbQyo*6S3o;X*in?zoIlJ9P z_29Y1SvNNB+!)MXWL5q9ddcF3sr_eEjbbk>f1$8=>L=Z-U(N5lx?d$PTwWb6-C9)E zDHmzmoU&18reS~Oq01I`kIb%^y=UF>tMMP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C5;}y0s$Ie$aNdK0q6xV!hmbca04)lV{~KCOGbn-Ei7d_O8wewS!I=eWVKD#z(;&L1 literal 0 HcmV?d00001 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!"); + } }