Skip to content

Commit abd0cd0

Browse files
committed
Add schema-to-html mojo as a replacement for ant ConvertSchemaToHTML
Currently platform build contains ant targets to run ConvertSchemaToHTML for documentation purpose. This adds as a first step a new mojo tycho-document-bundle-plugin:schema-to-html that offers the same functionality and should act as a base to further improve the brittle manually maintained references the current process requires and already allows to move things from the ant build to the maven build files.
1 parent 9f95dc0 commit abd0cd0

5 files changed

Lines changed: 403 additions & 1 deletion

File tree

tycho-extras/tycho-document-bundle-plugin/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
- Contributors:
1010
- IBH SYSTEMS GmbH - initial API and implementation
1111
-->
12-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12+
<project xmlns="http://maven.apache.org/POM/4.0.0"
13+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1314
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
1415
<modelVersion>4.0.0</modelVersion>
1516
<parent>
@@ -60,6 +61,11 @@
6061
<artifactId>org.eclipse.help.base</artifactId>
6162
<version>4.4.100</version>
6263
</dependency>
64+
<dependency>
65+
<groupId>org.eclipse.pde</groupId>
66+
<artifactId>org.eclipse.pde.core</artifactId>
67+
<version>3.17.100</version>
68+
</dependency>
6369
</dependencies>
6470
<build>
6571
<plugins>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Christoph Läubrich and others.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.tycho.extras.docbundle;
14+
15+
import java.io.File;
16+
import java.lang.reflect.InvocationTargetException;
17+
import java.net.URL;
18+
import java.util.List;
19+
20+
import org.apache.maven.model.Repository;
21+
import org.apache.maven.plugin.AbstractMojo;
22+
import org.apache.maven.plugin.MojoExecutionException;
23+
import org.apache.maven.plugin.MojoFailureException;
24+
import org.apache.maven.plugin.logging.Log;
25+
import org.apache.maven.plugins.annotations.Component;
26+
import org.apache.maven.plugins.annotations.LifecyclePhase;
27+
import org.apache.maven.plugins.annotations.Mojo;
28+
import org.apache.maven.plugins.annotations.Parameter;
29+
import org.apache.maven.plugins.annotations.ResolutionScope;
30+
import org.apache.maven.project.MavenProject;
31+
import org.eclipse.core.runtime.CoreException;
32+
import org.eclipse.tycho.MavenRepositoryLocation;
33+
import org.eclipse.tycho.extras.docbundle.runner.ConvertSchemaToHtmlResult;
34+
import org.eclipse.tycho.extras.docbundle.runner.ConvertSchemaToHtmlRunner;
35+
import org.eclipse.tycho.osgi.framework.EclipseApplication;
36+
import org.eclipse.tycho.osgi.framework.EclipseFramework;
37+
import org.eclipse.tycho.osgi.framework.EclipseWorkspace;
38+
import org.eclipse.tycho.osgi.framework.EclipseWorkspaceManager;
39+
import org.osgi.framework.BundleException;
40+
41+
/**
42+
* This mojo provides the functionality of
43+
* org.eclipse.pde.internal.core.ant.ConvertSchemaToHTML
44+
*/
45+
@Mojo(name = "schema-to-html", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, threadSafe = true, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
46+
public class ConvertSchemaToHtmlMojo extends AbstractMojo {
47+
48+
@Parameter()
49+
private Repository pdeToolsRepository;
50+
51+
@Parameter()
52+
private File manifest;
53+
@Parameter()
54+
private List<File> manifests;
55+
@Parameter()
56+
private File destination;
57+
@Parameter()
58+
private URL cssURL;
59+
@Parameter()
60+
private String additionalSearchPaths;
61+
62+
@Parameter(property = "project")
63+
private MavenProject project;
64+
65+
@Component
66+
private EclipseWorkspaceManager workspaceManager;
67+
@Component
68+
private PdeApplicationManager applicationManager;
69+
70+
@Override
71+
public void execute() throws MojoExecutionException, MojoFailureException {
72+
MavenRepositoryLocation repository = PdeApplicationManager.getRepository(pdeToolsRepository);
73+
EclipseApplication application = applicationManager.getApplication(repository);
74+
EclipseWorkspace<?> workspace = workspaceManager.getWorkspace(repository.getURL(), this);
75+
try (EclipseFramework framework = application.startFramework(workspace, List.of())) {
76+
ConvertSchemaToHtmlResult result = framework.execute(new ConvertSchemaToHtmlRunner(getManifestList(),
77+
destination, cssURL, additionalSearchPaths, project.getBasedir()));
78+
Log log = getLog();
79+
result.errors().forEach(log::error);
80+
} catch (BundleException e) {
81+
throw new MojoFailureException("Can't start framework!", e);
82+
} catch (InvocationTargetException e) {
83+
Throwable cause = e.getCause();
84+
if (cause.getClass().getName().equals(CoreException.class.getName())) {
85+
throw new MojoFailureException(cause.getMessage(), cause);
86+
}
87+
throw new MojoExecutionException(cause);
88+
}
89+
}
90+
91+
private List<File> getManifestList() {
92+
if (manifests != null && !manifests.isEmpty()) {
93+
return manifests;
94+
}
95+
if (manifest != null) {
96+
return List.of(manifest);
97+
}
98+
return List.of();
99+
}
100+
101+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Christoph Läubrich and others.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.tycho.extras.docbundle;
14+
15+
import java.net.URI;
16+
import java.util.Map;
17+
import java.util.concurrent.ConcurrentHashMap;
18+
19+
import org.apache.maven.model.Repository;
20+
import org.codehaus.plexus.component.annotations.Component;
21+
import org.codehaus.plexus.component.annotations.Requirement;
22+
import org.eclipse.tycho.MavenRepositoryLocation;
23+
import org.eclipse.tycho.TychoConstants;
24+
import org.eclipse.tycho.osgi.framework.EclipseApplication;
25+
import org.eclipse.tycho.osgi.framework.EclipseApplicationFactory;
26+
27+
@Component(role = PdeApplicationManager.class)
28+
public class PdeApplicationManager {
29+
30+
static MavenRepositoryLocation getRepository(Repository location) {
31+
if (location == null) {
32+
return new MavenRepositoryLocation(null, URI.create(TychoConstants.ECLIPSE_LATEST));
33+
}
34+
return new MavenRepositoryLocation(location.getId(), URI.create(location.getUrl()));
35+
}
36+
37+
private final Map<URI, EclipseApplication> buildIndexCache = new ConcurrentHashMap<>();
38+
39+
@Requirement
40+
private EclipseApplicationFactory applicationFactory;
41+
42+
public EclipseApplication getApplication(MavenRepositoryLocation repository) {
43+
return buildIndexCache.computeIfAbsent(repository.getURL().normalize(), x -> {
44+
EclipseApplication application = applicationFactory.createEclipseApplication(repository, "PDE Tools");
45+
application.addBundle("org.eclipse.pde.core");
46+
application.addBundle("org.eclipse.osgi.compatibility.state");
47+
return application;
48+
});
49+
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Christoph Läubrich and others.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License 2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.tycho.extras.docbundle.runner;
14+
15+
import java.io.Serializable;
16+
import java.util.ArrayList;
17+
import java.util.List;
18+
import java.util.stream.Stream;
19+
20+
public class ConvertSchemaToHtmlResult implements Serializable {
21+
22+
private List<String> errors = new ArrayList<>();
23+
24+
public void addError(String error) {
25+
errors.add(error);
26+
}
27+
28+
public Stream<String> errors() {
29+
return errors.stream();
30+
}
31+
32+
}

0 commit comments

Comments
 (0)