-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When using the javadoc goal to aggregate documentation using configured source directories there is the problem that also a reference to projects that are mentioned in the source directories is required. This adds a new (configurable) injector that adds the projects mentioned as the source as dependencies of the project.
- Loading branch information
Showing
7 changed files
with
208 additions
and
36 deletions.
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
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
41 changes: 41 additions & 0 deletions
41
...ocument-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/ConfigureMojo.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,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"); | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
...-bundle-plugin/src/main/java/org/eclipse/tycho/extras/docbundle/JavadocBuildListener.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,93 @@ | ||
/******************************************************************************* | ||
* 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.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
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.core.maven.MavenDependencyInjector; | ||
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) { | ||
List<MavenProject> projects = session.getProjects(); | ||
for (MavenProject project : projects) { | ||
if (isJavadocProject(project, session)) { | ||
Configuration configuration = configurationHelper.getConfiguration(GROUP_ID, ARTIFACT_ID, JAVADOC_GOAL, | ||
project, session); | ||
List<MavenProject> additionalProjects = configuration.getString("sourcepath").stream() | ||
.flatMap(sourcepath -> { | ||
return Arrays.stream(sourcepath.split(";|:")); | ||
}).map(s -> s.strip()).map(s -> new File(project.getBasedir(), s).toPath().normalize()) | ||
.map(sourcePath -> getProject(sourcePath, projects)).filter(Objects::nonNull).distinct() | ||
.toList(); | ||
MavenDependencyInjector.injectMavenProjectDependencies(project, additionalProjects); | ||
} | ||
} | ||
|
||
} | ||
|
||
private MavenProject getProject(Path sourcePath, List<MavenProject> projects) { | ||
MavenProject match = null; | ||
int matchNameCount = -1; | ||
for (MavenProject mavenProject : projects) { | ||
Path basePath = mavenProject.getBasedir().toPath(); | ||
if (sourcePath.startsWith(basePath)) { | ||
int nameCount = basePath.getNameCount(); | ||
if (match == null || nameCount > matchNameCount) { | ||
match = mavenProject; | ||
matchNameCount = nameCount; | ||
} | ||
} | ||
} | ||
return match; | ||
} | ||
|
||
private boolean isJavadocProject(MavenProject project, MavenSession mavenSession) { | ||
if (projectHelper.hasPluginExecution(GROUP_ID, ARTIFACT_ID, JAVADOC_GOAL, project, mavenSession)) { | ||
Configuration configuration = configurationHelper.getConfiguration(ConfigureMojo.class, project, | ||
mavenSession); | ||
return configuration.getBoolean(ConfigureMojo.PARAM_INJECT_JAVADOC_DEPENDENCIES).orElse(false); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void buildEnded(MavenSession session) { | ||
// nothing to do... | ||
} | ||
|
||
} |
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
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
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