Skip to content

Commit

Permalink
Support supply a complete folder instead of a singular project file
Browse files Browse the repository at this point in the history
Currently ConvertSchemaToHtmlMojo requires to list each project
individually what can soon become cumbersome.

This now supports specify a folder, this is then scanned and used as an
input to the generator if it has a plugin.xml and is a plugin packaging.
  • Loading branch information
laeubi committed Oct 31, 2023
1 parent 81c1149 commit 75cee86
Showing 1 changed file with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
package org.eclipse.tycho.extras.docbundle;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.Stream.Builder;

import org.apache.maven.model.Repository;
import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -83,7 +88,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// now add all reactor projects,
for (MavenProject reactorProject : reactorProjects) {
if (reactorProject != project) {
if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(reactorProject.getPackaging())) {
if (isValidProject(reactorProject)) {
// due to how the search works we need to add the
// parent (!) directory!
String parent = reactorProject.getBasedir().getParent();
Expand All @@ -93,8 +98,30 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}
}
List<File> manifestList = getManifestList().stream().flatMap(file -> {
if (file.isDirectory()) {
Builder<File> builder = Stream.builder();
File[] files = file.listFiles();
for (File dir : files) {
File pluginXml = new File(dir, "plugin.xml");
if (pluginXml.isFile()) {
MavenProject mp = getReactor(dir);
if (mp != null && isValidProject(mp)) {
try {
pluginXml = pluginXml.getCanonicalFile();
} catch (IOException e) {
}
builder.add(pluginXml);
}
}
}
return builder.build();
} else {
return Stream.of(file);
}
}).toList();
try (EclipseFramework framework = application.startFramework(workspace, List.of())) {
ConvertSchemaToHtmlResult result = framework.execute(new ConvertSchemaToHtmlRunner(getManifestList(),
ConvertSchemaToHtmlResult result = framework.execute(new ConvertSchemaToHtmlRunner(manifestList,
destination, cssURL, searchPaths, project.getBasedir()));
Log log = getLog();
List<String> list = result.errors().toList();
Expand All @@ -113,6 +140,25 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

private boolean isValidProject(MavenProject mp) {

return PackagingType.TYPE_ECLIPSE_PLUGIN.equals(mp.getPackaging());
}

private MavenProject getReactor(File dir) {
Path path = dir.toPath();
for (MavenProject mavenProject : reactorProjects) {
Path project = mavenProject.getBasedir().toPath();
try {
if (Files.isSameFile(path, project)) {
return mavenProject;
}
} catch (IOException e) {
}
}
return null;
}

List<String> getSearchPaths() {
if (additionalSearchPaths == null || additionalSearchPaths.isBlank()) {
return List.of();
Expand Down

0 comments on commit 75cee86

Please sign in to comment.