Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schema-to-html mojo as a replacement for ant ConvertSchemaToHTML #2969

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tycho-extras/tycho-document-bundle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
- Contributors:
- IBH SYSTEMS GmbH - initial API and implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand Down Expand Up @@ -60,6 +61,11 @@
<artifactId>org.eclipse.help.base</artifactId>
<version>4.4.100</version>
</dependency>
<dependency>
<groupId>org.eclipse.pde</groupId>
<artifactId>org.eclipse.pde.core</artifactId>
<version>3.17.100</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
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();
}

}
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;
});

}
}
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();
}

}
Loading
Loading