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

[tycho-4.0.x] Add option to include all configured sources in ApiFileGenerationMojo #3563

Merged
merged 1 commit into from
Mar 9, 2024
Merged
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 @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -84,9 +89,20 @@ public class ApiFileGenerationMojo extends AbstractMojo {
@Parameter(defaultValue = "false", property = "tycho.apitools.generate.skip")
private boolean skip;

/**
* If set to
* <code>true</true> all configured source folders in <code>build.properties</code>
* 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> eclipseProject = projectManager.getEclipseProject(project);
Expand All @@ -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<File> list = new ArrayList<>(extraSourceLocations);
for (Map.Entry<String, List<String>> 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<File> list) {
private static File canonicalFile(File file) {
try {
return file.getCanonicalFile();
} catch (IOException e) {
}
return file;
}

private static String join(List<File> 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));
}
Expand Down
Loading