Skip to content

Commit

Permalink
[MSHARED-1438] Provide protected methods for XRef location construction
Browse files Browse the repository at this point in the history
This closes #56
  • Loading branch information
michael-o committed Oct 12, 2024
1 parent a4d9b2f commit cbe0d84
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 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,56 @@ public boolean canGenerateReport() throws MavenReportException {
* @throws MavenReportException if any
*/
protected abstract void executeReport(Locale locale) throws MavenReportException;

/**
* Returns the (Test) Source XRef location as passthrough if provided, otherwise returns the
* default value.
*
* @param location the XRef location provided via plugin parameter, if any
* @param test whether it is test source
* @return the actual (Test) Source XRef location
*/
protected File getXrefLocation(File location, boolean test) {
return location != null ? location : new File(getReportOutputDirectory(), test ? "xref-test" : "xref");
}

/**
* Contructs the (Test) Source XRef location relative to the {@link #getReportOutputDirectory()}
* with {@link #getXrefLocation(File, boolean)}.
*
* @param location the XRef location provided via plugin parameter, if any
* @param test whether it is test source
* @return the constructed (Test) Source XRef location
*/
protected String constructXrefLocation(File location, boolean test) {
String constructedLocation = null;
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 cbe0d84

Please sign in to comment.