From 8a70b3c644a5bc9de891de25ffb324af6b19e6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 14 Oct 2023 06:49:38 +0200 Subject: [PATCH] Set the output folder of the imported project to the maven location Currently there could be a mismatch between what eclipse assumes as outputfolder where the class files are located and maven. This ensures that the project info is always updated with the correct location and parts of the code operating on the output location do find the classes (or folders). (cherry picked from commit f0b800c63b3d9d6b40fb0d4cfb0c00072736ba46) --- .../eclipse/tycho/apitools/ApiAnalysis.java | 13 ++++++++++-- .../tycho/apitools/ApiAnalysisMojo.java | 13 ++++++++++-- .../tycho/test/apitools/ApiToolsTest.java | 20 ++++++++++++------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java index 114cce2acb..0493e988b5 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java @@ -83,9 +83,11 @@ public class ApiAnalysis implements Serializable, Callable { private boolean debug; private String apiPreferences; private String binaryArtifact; + private String outputDir; public ApiAnalysis(Collection baselineBundles, Collection dependencyBundles, String baselineName, - Path apiFilterFile, Path apiPreferences, Path projectDir, boolean debug, Path binaryArtifact) { + Path apiFilterFile, Path apiPreferences, Path projectDir, boolean debug, Path binaryArtifact, + Path outputDir) { this.targetBundles = dependencyBundles.stream().map(ApiAnalysis::pathAsString).toList(); this.baselineBundles = baselineBundles.stream().map(ApiAnalysis::pathAsString).toList(); this.baselineName = baselineName; @@ -93,6 +95,7 @@ public ApiAnalysis(Collection baselineBundles, Collection dependency this.apiPreferences = pathAsString(apiPreferences); this.projectDir = pathAsString(projectDir); this.binaryArtifact = pathAsString(binaryArtifact); + this.outputDir = projectDir.relativize(outputDir).toString(); this.debug = debug; } @@ -216,12 +219,18 @@ private BundleComponent importProject() throws CoreException, IOException { } private void createOutputFolder(IProject project, IPath projectPath) throws IOException, CoreException { - // FIXME see bug https://github.com/eclipse-pde/eclipse.pde/issues/791 IJavaProject javaProject = JavaCore.create(project); if (javaProject != null) { + IPath fullPath = project.getFolder(outputDir).getFullPath(); + // FIXME see bug https://github.com/eclipse-pde/eclipse.pde/issues/801 + // it can happen that project output location != maven compiled classes, usually + // eclipse uses output = bin/ while maven uses target/classes if not + // specifically configured to be even + javaProject.setOutputLocation(fullPath, null); makeOutputFolder(javaProject.getOutputLocation(), projectPath); IClasspathEntry[] classpath = javaProject.getRawClasspath(); for (IClasspathEntry entry : classpath) { + // FIXME see bug https://github.com/eclipse-pde/eclipse.pde/issues/791 makeOutputFolder(entry.getOutputLocation(), projectPath); } } 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 f2c64a8834..566e32d9d5 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 @@ -172,9 +172,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { } ApiAnalysisResult analysisResult; try { - analysisResult = eclipseFramework.execute(new ApiAnalysis(baselineBundles, dependencyBundles, + ApiAnalysis analysis = new ApiAnalysis(baselineBundles, dependencyBundles, project.getName(), fileToPath(apiFilter), fileToPath(apiPreferences), - fileToPath(project.getBasedir()), debug, fileToPath(project.getArtifact().getFile()))); + fileToPath(project.getBasedir()), debug, fileToPath(project.getArtifact().getFile()), + stringToPath(project.getBuild().getOutputDirectory())); + analysisResult = eclipseFramework.execute(analysis); } catch (Exception e) { throw new MojoExecutionException("Execute ApiApplication failed", e); } finally { @@ -350,6 +352,13 @@ public boolean equals(Object obj) { } + private static Path stringToPath(String file) { + if (file == null) { + return null; + } + return Path.of(file); + } + private static Path fileToPath(File file) { if (file != null) { return file.toPath(); 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 e484e4cfb5..5f3f8f7db6 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 @@ -60,25 +60,31 @@ public void testVerify() throws Exception { } }); // check summary output - verifier.verifyTextInLog("4 API ERRORS"); + verifier.verifyTextInLog("7 API ERRORS"); verifier.verifyTextInLog("0 API warnings"); // check error output has source references and lines + verifier.verifyTextInLog("File ClassA.java at line 5: The method bundle.ClassA.getString() has been removed"); verifier.verifyTextInLog( - "File ApiInterface.java at line 2: The type bundle.ApiInterface has been removed from api-bundle"); - verifier.verifyTextInLog("File ClassA.java at line 5: The type bundle.ClassA has been removed from api-bundle"); + "File ClassA.java at line 5: The method bundle.ClassA.getCollection() has been removed"); verifier.verifyTextInLog( "File MANIFEST.MF at line 0: The type bundle.InterfaceA has been removed from api-bundle"); + verifier.verifyTextInLog("File ClassA.java at line 7: Missing @since tag on getGreetings()"); + verifier.verifyTextInLog("File ClassA.java at line 11: Missing @since tag on getCollection()"); + verifier.verifyTextInLog("File InterfaceB.java at line 2: Missing @since tag on bundle.InterfaceB"); verifier.verifyTextInLog( "File MANIFEST.MF at line 5: The major version should be incremented in version 0.0.1, since API breakage occurred since version 0.0.1"); // now check for the build error output verifier.verifyTextInLog("on project api-bundle-1: There are API errors:"); + verifier.verifyTextInLog("src/bundle/ClassA.java:5 The method bundle.ClassA.getString() has been removed"); + verifier.verifyTextInLog("src/bundle/ClassA.java:5 The method bundle.ClassA.getCollection() has been removed"); verifier.verifyTextInLog( - "src/bundle/ApiInterface.java:2 The type bundle.ApiInterface has been removed from api-bundle"); - verifier.verifyTextInLog( - "src/bundle/ClassA.java:5 The type bundle.ClassA has been removed from api-bundle-1_0.0.1"); - verifier.verifyTextInLog("META-INF/MANIFEST.MF:0 The type bundle.InterfaceA has been removed from api-bundle"); + "META-INF/MANIFEST.MF:0 The type bundle.InterfaceA has been removed from api-bundle-1_0.0.1"); + verifier.verifyTextInLog("src/bundle/ClassA.java:7 Missing @since tag on getGreetings()"); + verifier.verifyTextInLog("src/bundle/ClassA.java:11 Missing @since tag on getCollection()"); + verifier.verifyTextInLog("src/bundle/InterfaceB.java:2 Missing @since tag on bundle.InterfaceB"); verifier.verifyTextInLog( "META-INF/MANIFEST.MF:5 The major version should be incremented in version 0.0.1, since API breakage occurred since version 0.0.1"); + // TODO: check with api-filter // TODO: check with second plugin with BREE? }