Skip to content

Commit

Permalink
Set the output folder of the imported project to the maven location
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
laeubi committed Oct 14, 2023
1 parent 6876ab6 commit ae7bca9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,19 @@ public class ApiAnalysis implements Serializable, Callable<ApiAnalysisResult> {
private boolean debug;
private String apiPreferences;
private String binaryArtifact;
private String outputDir;

public ApiAnalysis(Collection<Path> baselineBundles, Collection<Path> 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;
this.apiFilterFile = pathAsString(apiFilterFile);
this.apiPreferences = pathAsString(apiPreferences);
this.projectDir = pathAsString(projectDir);
this.binaryArtifact = pathAsString(binaryArtifact);
this.outputDir = projectDir.relativize(outputDir).toString();
this.debug = debug;
}

Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
Expand Down

0 comments on commit ae7bca9

Please sign in to comment.