Skip to content

Commit

Permalink
[MSHARED-1438] Resolve Code Duplication for XRef Link generation
Browse files Browse the repository at this point in the history
This closes #56
  • Loading branch information
michael-o committed Oct 10, 2024
1 parent a4d9b2f commit d402ca8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand All @@ -41,6 +42,8 @@
import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
import org.apache.maven.doxia.tools.SiteTool;
import org.apache.maven.doxia.tools.SiteToolException;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Reporting;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -50,6 +53,7 @@
import org.apache.maven.shared.utils.WriterFactory;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.PathTool;
import org.codehaus.plexus.util.ReaderFactory;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
Expand Down Expand Up @@ -461,4 +465,42 @@ public boolean canGenerateReport() throws MavenReportException {
* @throws MavenReportException if any
*/
protected abstract void executeReport(Locale locale) throws MavenReportException;

protected File getXrefLocation(File location, boolean test) {
return location != null ? location : new File(getReportOutputDirectory(), test ? "xref-test" : "xref");
}

protected String constructXrefLocation(File location, boolean test, boolean link) {
String constructedLocation = null;
if (link) {
File xrefLocation = getXrefLocation(location, test);

String relativePath = PathTool.getRelativePath(
getReportOutputDirectory().getAbsolutePath(), xrefLocation.getAbsolutePath());
if (relativePath == null || relativePath.isEmpty()) {
relativePath = ".";
}
relativePath = relativePath + "/" + xrefLocation.getName();
if (xrefLocation.exists()) {
// XRef was already generated by manual execution of a lifecycle binding
constructedLocation = relativePath;
} else {
// Not yet generated - check if the report is on its way
Reporting reporting = project.getModel().getReporting();
List<ReportPlugin> reportPlugins =
reporting != null ? reporting.getPlugins() : Collections.<ReportPlugin>emptyList();
for (ReportPlugin plugin : reportPlugins) {
String artifactId = plugin.getArtifactId();
if ("maven-jxr-plugin".equals(artifactId)) {
constructedLocation = relativePath;
}
}
}

if (constructedLocation == null) {
getLog().warn("Unable to locate" + (test ? " Test" : "") + " Source XRef to link to - DISABLED");
}
}
return constructedLocation;
}
}

0 comments on commit d402ca8

Please sign in to comment.