From 3382ce4caf006cd12e6fc146d1386c2d491e9697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sat, 9 Mar 2024 19:17:15 +0100 Subject: [PATCH] Add option to include all configured sources in ApiFileGenerationMojo Currently APIFileGenerator scans all folders from the root, but one can configured folders that are relative to the project, this is then not discovered. This adds a new option that when used automatically adds all configured source folders as extraSourceLocations. (cherry picked from commit 517ea22ed036acd7d00db48a8ed97b0e22edd795) --- .../tycho/apitools/ApiFileGenerationMojo.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiFileGenerationMojo.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiFileGenerationMojo.java index cb97ab5d6c..90dbaba52a 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiFileGenerationMojo.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiFileGenerationMojo.java @@ -13,7 +13,10 @@ package org.eclipse.tycho.apitools; import java.io.File; +import java.io.IOException; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.jar.JarFile; import java.util.stream.Collectors; @@ -27,7 +30,9 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.eclipse.pde.api.tools.internal.APIFileGenerator; +import org.eclipse.tycho.BuildPropertiesParser; import org.eclipse.tycho.core.TychoProjectManager; +import org.eclipse.tycho.core.osgitools.DefaultReactorProject; import org.eclipse.tycho.model.project.EclipseProject; /** @@ -84,9 +89,20 @@ public class ApiFileGenerationMojo extends AbstractMojo { @Parameter(defaultValue = "false", property = "tycho.apitools.generate.skip") private boolean skip; + /** + * If set to + * true all configured source folders in build.properties + * will be added as {@link #extraSourceLocations} + */ + @Parameter(defaultValue = "false") + private boolean addSourceFolders; + @Component private TychoProjectManager projectManager; + @Component + private BuildPropertiesParser buildPropertiesParser; + @Override public void execute() throws MojoExecutionException, MojoFailureException { Optional eclipseProject = projectManager.getEclipseProject(project); @@ -110,13 +126,32 @@ public void execute() throws MojoExecutionException, MojoFailureException { generator.encoding = encoding; generator.debug = debug; generator.manifests = join(extraManifests); - generator.sourceLocations = join(extraSourceLocations); + if (addSourceFolders) { + List list = new ArrayList<>(extraSourceLocations); + for (Map.Entry> entry : buildPropertiesParser + .parse(DefaultReactorProject.adapt(project)).getJarToSourceFolderMap().entrySet()) { + for (String sourceFolder : entry.getValue()) { + list.add(canonicalFile(new File(project.getBasedir(), sourceFolder))); + } + } + generator.sourceLocations = join(list); + } else { + generator.sourceLocations = join(extraSourceLocations); + } generator.generateAPIFile(); } } } - private String join(List list) { + private static File canonicalFile(File file) { + try { + return file.getCanonicalFile(); + } catch (IOException e) { + } + return file; + } + + private static String join(List list) { return list.isEmpty() ? null // join the elements so that the APIFileGenerator splits it correspondingly : list.stream().map(File::toString).collect(Collectors.joining(File.pathSeparator)); }