From ad0bf7977fd749040d90daa2f195faa783261b3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 31 Oct 2023 16:41:11 +0100 Subject: [PATCH] Automatically use all reactor projects for the searchpath Currently a user has to specify search pathes manually but one obvious choice are other reactor projects. This will add any eclipse-plugin to the search path to make this process much more convenient. --- .../docbundle/ConvertSchemaToHtmlMojo.java | 41 +++++++++++++++++- .../runner/ConvertSchemaToHtmlRunner.java | 42 +++++-------------- 2 files changed, 50 insertions(+), 33 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 67889193e6..008bb2a332 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 @@ -15,6 +15,7 @@ import java.io.File; import java.lang.reflect.InvocationTargetException; import java.net.URL; +import java.util.ArrayList; import java.util.List; import org.apache.maven.model.Repository; @@ -30,6 +31,7 @@ import org.apache.maven.project.MavenProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.tycho.MavenRepositoryLocation; +import org.eclipse.tycho.PackagingType; import org.eclipse.tycho.extras.docbundle.runner.ConvertSchemaToHtmlResult; import org.eclipse.tycho.extras.docbundle.runner.ConvertSchemaToHtmlRunner; import org.eclipse.tycho.osgi.framework.EclipseApplication; @@ -62,6 +64,9 @@ public class ConvertSchemaToHtmlMojo extends AbstractMojo { @Parameter(property = "project") private MavenProject project; + @Parameter(property = "reactorProjects", required = true, readonly = true) + protected List reactorProjects; + @Component private EclipseWorkspaceManager workspaceManager; @Component @@ -72,11 +77,31 @@ public void execute() throws MojoExecutionException, MojoFailureException { MavenRepositoryLocation repository = PdeApplicationManager.getRepository(pdeToolsRepository); EclipseApplication application = applicationManager.getApplication(repository); EclipseWorkspace workspace = workspaceManager.getWorkspace(repository.getURL(), this); + List searchPaths = new ArrayList<>(); + // first add all userpath... + searchPaths.addAll(getSearchPaths()); + // now add all reactor projects, + for (MavenProject reactorProject : reactorProjects) { + if (reactorProject != project) { + if (PackagingType.TYPE_ECLIPSE_PLUGIN.equals(reactorProject.getPackaging())) { + // due to how the search works we need to add the + // parent (!) directory! + String parent = reactorProject.getBasedir().getParent(); + if (!searchPaths.contains(parent)) { + searchPaths.add(parent); + } + } + } + } try (EclipseFramework framework = application.startFramework(workspace, List.of())) { ConvertSchemaToHtmlResult result = framework.execute(new ConvertSchemaToHtmlRunner(getManifestList(), - destination, cssURL, additionalSearchPaths, project.getBasedir())); + destination, cssURL, searchPaths, project.getBasedir())); Log log = getLog(); - result.errors().forEach(log::error); + List list = result.errors().toList(); + if (!list.isEmpty()) { + list.forEach(log::error); + throw new MojoFailureException("There are schema generation errors"); + } } catch (BundleException e) { throw new MojoFailureException("Can't start framework!", e); } catch (InvocationTargetException e) { @@ -88,6 +113,18 @@ public void execute() throws MojoExecutionException, MojoFailureException { } } + List getSearchPaths() { + if (additionalSearchPaths == null || additionalSearchPaths.isBlank()) { + return List.of(); + } + String[] paths = additionalSearchPaths.split(","); //$NON-NLS-1$ + List result = new ArrayList<>(paths.length); + for (String pathString : paths) { + result.add(pathString); + } + return result; + } + private List getManifestList() { if (manifests != null && !manifests.isEmpty()) { return manifests; diff --git a/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/runner/ConvertSchemaToHtmlRunner.java b/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/runner/ConvertSchemaToHtmlRunner.java index b78a38c0cd..8f727ee4fe 100644 --- a/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/runner/ConvertSchemaToHtmlRunner.java +++ b/tycho-extras/tycho-document-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/runner/ConvertSchemaToHtmlRunner.java @@ -25,7 +25,6 @@ import java.io.Serializable; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -58,11 +57,11 @@ public class ConvertSchemaToHtmlRunner implements Callable manifests; private File destination; private URL cssURL; - private String additionalSearchPaths; + private List additionalSearchPaths; private File baseDir; - public ConvertSchemaToHtmlRunner(List manifests, File destination, URL cssURL, String additionalSearchPaths, - File baseDir) { + public ConvertSchemaToHtmlRunner(List manifests, File destination, URL cssURL, + List additionalSearchPaths, File baseDir) { this.manifests = manifests; this.destination = destination; this.cssURL = cssURL; @@ -86,8 +85,6 @@ public ConvertSchemaToHtmlResult call() throws Exception { pluginID = getPluginID(manifest); } - List searchPaths = getSearchPaths(); - IPluginExtensionPoint[] extPoints = model.getPluginBase().getExtensionPoints(); for (IPluginExtensionPoint extPoint : extPoints) { String schemaLocation = extPoint.getSchema(); @@ -103,7 +100,14 @@ public ConvertSchemaToHtmlResult call() throws Exception { .parse(schemaFile, handler); @SuppressWarnings("deprecation") URL url = schemaFile.toURL(); - SchemaDescriptor desc = new SchemaDescriptor(extPoint.getFullId(), url, searchPaths); + SchemaDescriptor desc = new SchemaDescriptor(extPoint.getFullId(), url, + additionalSearchPaths.stream().map(pathString -> { + IPath path = IPath.fromOSString(pathString); + if (!path.isAbsolute()) { + return IPath.fromOSString(baseDir.getPath()).append(path); + } + return path; + }).toList()); schema = (Schema) desc.getSchema(false); // Check that all included schemas are available @@ -164,30 +168,6 @@ private String getPluginID(File manifest) { return null; } - /** - * @return user specified search paths or null - */ - private List getSearchPaths() { - if (this.additionalSearchPaths == null) { - return null; - } - String[] paths = this.additionalSearchPaths.split(","); //$NON-NLS-1$ - List result = new ArrayList<>(paths.length); - for (String pathString : paths) { - IPath path = IPath.fromOSString(pathString); - if (path.isValidPath(pathString)) { - if (!path.isAbsolute()) { - path = IPath.fromOSString(baseDir.getPath()).append(path); - } - result.add(path); - } else { - System.out - .println(NLS.bind(PDECoreMessages.ConvertSchemaToHTML_InvalidAdditionalSearchPath, pathString)); - } - } - return result; - } - private IPluginModelBase readManifestFile(File manifest) throws IOException, CoreException { try (InputStream stream = new BufferedInputStream(new FileInputStream(manifest))) { ExternalPluginModelBase model = null;