forked from eclipse-tycho/tycho
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
5 changed files
with
403 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...ndle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/ConvertSchemaToHtmlMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Christoph Läubrich and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.extras.docbundle; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
import org.apache.maven.model.Repository; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugin.logging.Log; | ||
import org.apache.maven.plugins.annotations.Component; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.plugins.annotations.ResolutionScope; | ||
import org.apache.maven.project.MavenProject; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.tycho.MavenRepositoryLocation; | ||
import org.eclipse.tycho.extras.docbundle.runner.ConvertSchemaToHtmlResult; | ||
import org.eclipse.tycho.extras.docbundle.runner.ConvertSchemaToHtmlRunner; | ||
import org.eclipse.tycho.osgi.framework.EclipseApplication; | ||
import org.eclipse.tycho.osgi.framework.EclipseFramework; | ||
import org.eclipse.tycho.osgi.framework.EclipseWorkspace; | ||
import org.eclipse.tycho.osgi.framework.EclipseWorkspaceManager; | ||
import org.osgi.framework.BundleException; | ||
|
||
/** | ||
* This mojo provides the functionality of | ||
* org.eclipse.pde.internal.core.ant.ConvertSchemaToHTML | ||
*/ | ||
@Mojo(name = "schema-to-html", defaultPhase = LifecyclePhase.PREPARE_PACKAGE, threadSafe = true, requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME) | ||
public class ConvertSchemaToHtmlMojo extends AbstractMojo { | ||
|
||
@Parameter() | ||
private Repository pdeToolsRepository; | ||
|
||
@Parameter() | ||
private File manifest; | ||
@Parameter() | ||
private List<File> manifests; | ||
@Parameter() | ||
private File destination; | ||
@Parameter() | ||
private URL cssURL; | ||
@Parameter() | ||
private String additionalSearchPaths; | ||
|
||
@Parameter(property = "project") | ||
private MavenProject project; | ||
|
||
@Component | ||
private EclipseWorkspaceManager workspaceManager; | ||
@Component | ||
private PdeApplicationManager applicationManager; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
MavenRepositoryLocation repository = PdeApplicationManager.getRepository(pdeToolsRepository); | ||
EclipseApplication application = applicationManager.getApplication(repository); | ||
EclipseWorkspace<?> workspace = workspaceManager.getWorkspace(repository.getURL(), this); | ||
try (EclipseFramework framework = application.startFramework(workspace, List.of())) { | ||
ConvertSchemaToHtmlResult result = framework.execute(new ConvertSchemaToHtmlRunner(getManifestList(), | ||
destination, cssURL, additionalSearchPaths, project.getBasedir())); | ||
Log log = getLog(); | ||
result.errors().forEach(log::error); | ||
} catch (BundleException e) { | ||
throw new MojoFailureException("Can't start framework!", e); | ||
} catch (InvocationTargetException e) { | ||
Throwable cause = e.getCause(); | ||
if (cause.getClass().getName().equals(CoreException.class.getName())) { | ||
throw new MojoFailureException(cause.getMessage(), cause); | ||
} | ||
throw new MojoExecutionException(cause); | ||
} | ||
} | ||
|
||
private List<File> getManifestList() { | ||
if (manifests != null && !manifests.isEmpty()) { | ||
return manifests; | ||
} | ||
if (manifest != null) { | ||
return List.of(manifest); | ||
} | ||
return List.of(); | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/PdeApplicationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Christoph Läubrich and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.extras.docbundle; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.apache.maven.model.Repository; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
import org.codehaus.plexus.component.annotations.Requirement; | ||
import org.eclipse.tycho.MavenRepositoryLocation; | ||
import org.eclipse.tycho.TychoConstants; | ||
import org.eclipse.tycho.osgi.framework.EclipseApplication; | ||
import org.eclipse.tycho.osgi.framework.EclipseApplicationFactory; | ||
|
||
@Component(role = PdeApplicationManager.class) | ||
public class PdeApplicationManager { | ||
|
||
static MavenRepositoryLocation getRepository(Repository location) { | ||
if (location == null) { | ||
return new MavenRepositoryLocation(null, URI.create(TychoConstants.ECLIPSE_LATEST)); | ||
} | ||
return new MavenRepositoryLocation(location.getId(), URI.create(location.getUrl())); | ||
} | ||
|
||
private final Map<URI, EclipseApplication> buildIndexCache = new ConcurrentHashMap<>(); | ||
|
||
@Requirement | ||
private EclipseApplicationFactory applicationFactory; | ||
|
||
public EclipseApplication getApplication(MavenRepositoryLocation repository) { | ||
return buildIndexCache.computeIfAbsent(repository.getURL().normalize(), x -> { | ||
EclipseApplication application = applicationFactory.createEclipseApplication(repository, "PDE Tools"); | ||
application.addBundle("org.eclipse.pde.core"); | ||
application.addBundle("org.eclipse.osgi.compatibility.state"); | ||
return application; | ||
}); | ||
|
||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...in/src/main/java/org/eclipse/tycho/extras/docbundle/runner/ConvertSchemaToHtmlResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Christoph Läubrich and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.extras.docbundle.runner; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class ConvertSchemaToHtmlResult implements Serializable { | ||
|
||
private List<String> errors = new ArrayList<>(); | ||
|
||
public void addError(String error) { | ||
errors.add(error); | ||
} | ||
|
||
public Stream<String> errors() { | ||
return errors.stream(); | ||
} | ||
|
||
} |
Oops, something went wrong.