From 75cee86c879876f7972a47cb10b5bdb3c21bc750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 31 Oct 2023 18:46:50 +0100 Subject: [PATCH] Support supply a complete folder instead of a singular project file 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. --- .../docbundle/ConvertSchemaToHtmlMojo.java | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/ConvertSchemaToHtmlMojo.java b/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/ConvertSchemaToHtmlMojo.java index 008bb2a332..02261d272c 100644 --- a/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/ConvertSchemaToHtmlMojo.java +++ b/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/ConvertSchemaToHtmlMojo.java @@ -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; @@ -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(); @@ -93,8 +98,30 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } } + List manifestList = getManifestList().stream().flatMap(file -> { + if (file.isDirectory()) { + Builder 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 list = result.errors().toList(); @@ -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 getSearchPaths() { if (additionalSearchPaths == null || additionalSearchPaths.isBlank()) { return List.of();