Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the output folder of the imported project to the maven location #2922

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading