Skip to content

Commit

Permalink
Automatically use all reactor projects for the searchpath
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laeubi committed Oct 31, 2023
1 parent f8e6288 commit 81c1149
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -62,6 +64,9 @@ public class ConvertSchemaToHtmlMojo extends AbstractMojo {
@Parameter(property = "project")
private MavenProject project;

@Parameter(property = "reactorProjects", required = true, readonly = true)
protected List<MavenProject> reactorProjects;

@Component
private EclipseWorkspaceManager workspaceManager;
@Component
Expand All @@ -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<String> 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<String> 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) {
Expand All @@ -88,6 +113,18 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
}

List<String> getSearchPaths() {
if (additionalSearchPaths == null || additionalSearchPaths.isBlank()) {
return List.of();
}
String[] paths = additionalSearchPaths.split(","); //$NON-NLS-1$
List<String> result = new ArrayList<>(paths.length);
for (String pathString : paths) {
result.add(pathString);
}
return result;
}

private List<File> getManifestList() {
if (manifests != null && !manifests.isEmpty()) {
return manifests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,11 +57,11 @@ public class ConvertSchemaToHtmlRunner implements Callable<ConvertSchemaToHtmlRe
private List<File> manifests;
private File destination;
private URL cssURL;
private String additionalSearchPaths;
private List<String> additionalSearchPaths;
private File baseDir;

public ConvertSchemaToHtmlRunner(List<File> manifests, File destination, URL cssURL, String additionalSearchPaths,
File baseDir) {
public ConvertSchemaToHtmlRunner(List<File> manifests, File destination, URL cssURL,
List<String> additionalSearchPaths, File baseDir) {
this.manifests = manifests;
this.destination = destination;
this.cssURL = cssURL;
Expand All @@ -86,8 +85,6 @@ public ConvertSchemaToHtmlResult call() throws Exception {
pluginID = getPluginID(manifest);
}

List<IPath> searchPaths = getSearchPaths();

IPluginExtensionPoint[] extPoints = model.getPluginBase().getExtensionPoints();
for (IPluginExtensionPoint extPoint : extPoints) {
String schemaLocation = extPoint.getSchema();
Expand All @@ -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
Expand Down Expand Up @@ -164,30 +168,6 @@ private String getPluginID(File manifest) {
return null;
}

/**
* @return user specified search paths or <code>null</code>
*/
private List<IPath> getSearchPaths() {
if (this.additionalSearchPaths == null) {
return null;
}
String[] paths = this.additionalSearchPaths.split(","); //$NON-NLS-1$
List<IPath> 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;
Expand Down

0 comments on commit 81c1149

Please sign in to comment.