Skip to content

Commit

Permalink
Add a javadoc dependency injector
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Nov 11, 2023
1 parent bce5c53 commit a6a2b44
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
log.info("Tycho Builder: "
+ session.getUserProperties().getProperty(TychoConstants.SESSION_PROPERTY_TYCHO_BUILDER, "maven"));
if (disableLifecycleParticipation(session)) {
buildListeners.notifyBuildStart(session);
return;
}
buildListeners.notifyBuildStart(session);
List<MavenProject> projects = session.getProjects();
try {
validate(projects);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*******************************************************************************
* 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 org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
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;

/**
* This mojo is only there
*/
@Mojo(name = "configure-document-bundle-plugin", defaultPhase = LifecyclePhase.INITIALIZE, requiresDependencyResolution = ResolutionScope.NONE, threadSafe = true)
public class ConfigureMojo extends AbstractMojo {

/**
* name of the parameter to inject javadoc source dependencies
*/
public static final String PARAM_INJECT_JAVADOC_DEPENDENCIES = "injectJavadocDependencies";
@Parameter(name = PARAM_INJECT_JAVADOC_DEPENDENCIES)
private boolean dummyBoolean;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
throw new MojoFailureException("This mojo is not intended to be ever called");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
* 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.util.Arrays;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.eclipse.tycho.build.BuildListener;
import org.eclipse.tycho.helper.PluginConfigurationHelper;
import org.eclipse.tycho.helper.PluginConfigurationHelper.Configuration;
import org.eclipse.tycho.helper.ProjectHelper;

@Component(role = BuildListener.class, hint = "javadoc")
public class JavadocBuildListener implements BuildListener {

private static final String JAVADOC_GOAL = "javadoc";
private static final String ARTIFACT_ID = "maven-javadoc-plugin";
private static final String GROUP_ID = "org.apache.maven.plugins";

@Requirement
private ProjectHelper projectHelper;

@Requirement
private PluginConfigurationHelper configurationHelper;

@Override
public void buildStarted(MavenSession session) {
for (MavenProject project : session.getProjects()) {
if (isJavadocProject(project, session)) {
Configuration configuration = configurationHelper.getConfiguration(GROUP_ID, ARTIFACT_ID, JAVADOC_GOAL,
project, session);
configuration.getString("sourcepath").ifPresent(sourcepath -> {
System.out.println("project " + project + " has sourcepath=" + sourcepath);
String[] pathString = sourcepath.split(";|:");
System.out.println(Arrays.toString(pathString));
});
}
}

}

private boolean isJavadocProject(MavenProject project, MavenSession mavenSession) {
return projectHelper.hasPluginExecution(GROUP_ID, ARTIFACT_ID, JAVADOC_GOAL, project, mavenSession);
}

@Override
public void buildEnded(MavenSession session) {
// nothing to do...
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.InterpolationFilterReader;
Expand Down Expand Up @@ -58,6 +60,12 @@ public Configuration getConfiguration(Xpp3Dom configuration) {
return new Configuration(configuration);
}

public Configuration getConfiguration(String pluginGroupId, String pluginArtifactId, String goal,
MavenProject project, MavenSession mavenSession) {
return new Configuration(
projectHelper.getPluginConfiguration(pluginGroupId, pluginArtifactId, goal, project, mavenSession));
}

public <M extends Mojo> Configuration getConfiguration(Class<M> mojo) {
URL resource = mojo.getResource("/META-INF/maven/plugin.xml");
if (resource == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public List<Plugin> getPlugins(MavenProject project, MavenSession mavenSession)
* @param goal
* @param project
* @param mavenSession
* @return <code>true</code> if an execution was found or <code>false</code> otherwhise.
* @return <code>true</code> if an execution was found or <code>false</code> otherwise.
*/
public boolean hasPluginExecution(String pluginGroupId, String pluginArtifactId, String goal, MavenProject project,
MavenSession mavenSession) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.eclipse.tycho.versions.pom.PomFile;
import org.osgi.framework.Version;

@Component(role = BuildListener.class)
@Component(role = BuildListener.class, hint = "version-bump")
public class VersionBumpBuildListener implements BuildListener {

@Requirement
Expand Down Expand Up @@ -79,10 +79,10 @@ public void buildEnded(MavenSession session) {
String newVersion = suggestedVersion.map(String::valueOf)
.orElseGet(() -> Versions.incrementVersion(currentVersion,
VersionBumpMojo.getIncrement(session, project, projectHelper)));
boolean isSnapshot = currentVersion.endsWith(TychoConstants.SUFFIX_SNAPSHOT);
if (isSnapshot) {
newVersion += TychoConstants.SUFFIX_SNAPSHOT;
}
boolean isSnapshot = currentVersion.endsWith(TychoConstants.SUFFIX_SNAPSHOT);
if (isSnapshot) {
newVersion += TychoConstants.SUFFIX_SNAPSHOT;
}
logger.info(project.getId() + " requires a version bump from " + currentVersion + " => "
+ newVersion);
engine.setProjects(metadataReader.getProjects());
Expand Down

0 comments on commit a6a2b44

Please sign in to comment.