Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class GroovyDocConfiguration implements Serializable {
private String header;
private boolean displayAuthor;
private String languageLevel;
private String preLanguage;

public GroovyDocConfiguration(FileSet[] sourceDirectories, List<?> classpath, File outputDirectory) {
this.sourceDirectories = sourceDirectories;
Expand Down Expand Up @@ -225,4 +226,12 @@ public String getLanguageLevel() {
public void setLanguageLevel(String languageLevel) {
this.languageLevel = languageLevel;
}

public String getPreLanguage() {
return preLanguage;
}

public void setPreLanguage(String preLanguage) {
this.preLanguage = preLanguage;
}
}
165 changes: 158 additions & 7 deletions src/main/java/org/codehaus/gmavenplus/mojo/AbstractGroovyDocMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,118 @@ public abstract class AbstractGroovyDocMojo extends AbstractGroovySourcesMojo {
@Parameter(defaultValue = "false")
protected boolean attachGroovyDocAnnotation;

/**
* The syntax highlighter to use.
*
* @since 1.11.0
*/
@Parameter
protected String syntaxHighlighter;

/**
* The theme to use.
*
* @since 1.11.0
*/
@Parameter
protected String theme;

/**
* Whether to show internal classes.
*
* @since 1.11.0
*/
@Parameter(defaultValue = "false")
protected boolean showInternal;

/**
* Whether to generate an index.
*
* @since 1.11.0
*/
@Parameter(defaultValue = "false")
protected boolean noIndex;

/**
* Whether to generate a deprecated list.
*
* @since 1.11.0
*/
@Parameter(defaultValue = "false")
protected boolean noDeprecatedList;

/**
* Whether to generate a help page.
*
* @since 1.11.0
*/
@Parameter(defaultValue = "false")
protected boolean noHelp;

/**
* Whether to include a timestamp.
*
* @since 1.11.0
*/
@Parameter(defaultValue = "false")
protected boolean noTimestamp;

/**
* Whether to include a version stamp.
*
* @since 1.11.0
*/
@Parameter(defaultValue = "false")
protected boolean noVersionStamp;

/**
* Whether to process scripts.
*
* @since 1.11.0
*/
@Parameter(defaultValue = "true")
protected boolean processScripts = true;

/**
* Whether to include main for scripts.
*
* @since 1.11.0
*/
@Parameter(defaultValue = "true")
protected boolean includeMainForScripts = true;

/**
* The charset to use.
*
* @since 1.11.0
*/
@Parameter
protected String charset;

/**
* The file encoding to use.
*
* @since 1.11.0
*/
@Parameter
protected String fileEncoding;

/**
* Additional stylesheets to include.
*
* @since 1.11.0
*/
@Parameter
protected List<File> addStylesheet;

/**
* The pre-language to use.
*
* @since 1.11.0
*/
@Parameter
protected String preLanguage;

/**
* The Maven ToolchainManager.
*/
Expand Down Expand Up @@ -286,6 +398,7 @@ protected synchronized void doGroovyDocGeneration(final FileSet[] sourceDirector
configuration.setLanguageLevel(languageLevel != null ? languageLevel.toString() : null);

configuration.setScope(scope);
configuration.setPreLanguage(preLanguage);

org.apache.maven.toolchain.Toolchain toolchain = toolchainManager.getToolchainFromBuildContext("jdk", session);
if (toolchain != null) {
Expand All @@ -298,7 +411,13 @@ protected synchronized void doGroovyDocGeneration(final FileSet[] sourceDirector

// overwrite stylesheet.css with provided stylesheet (if configured)
if (stylesheetFile != null) {
copyStylesheet(outputDirectory);
copyStylesheet(stylesheetFile, outputDirectory, "stylesheet.css");
}
// copy additional stylesheets
if (addStylesheet != null && !addStylesheet.isEmpty()) {
for (File file : addStylesheet) {
copyStylesheet(file, outputDirectory, file.getName());
}
}
}

Expand Down Expand Up @@ -392,6 +511,36 @@ protected Properties setupProperties() {
properties.setProperty("header", header);
properties.setProperty("author", Boolean.toString(displayAuthor));
properties.setProperty("overviewFile", overviewFile != null ? overviewFile.getAbsolutePath() : "");
if (syntaxHighlighter != null) {
properties.setProperty("syntaxHighlighter", syntaxHighlighter);
}
if (theme != null) {
properties.setProperty("theme", theme);
}
properties.setProperty("showInternal", Boolean.toString(showInternal));
properties.setProperty("noIndex", Boolean.toString(noIndex));
properties.setProperty("noDeprecatedList", Boolean.toString(noDeprecatedList));
properties.setProperty("noHelp", Boolean.toString(noHelp));
properties.setProperty("timestamp", Boolean.toString(!noTimestamp));
properties.setProperty("versionStamp", Boolean.toString(!noVersionStamp));
properties.setProperty("processScripts", Boolean.toString(processScripts));
properties.setProperty("includeMainForScripts", Boolean.toString(includeMainForScripts));
if (charset != null) {
properties.setProperty("charset", charset);
}
if (fileEncoding != null) {
properties.setProperty("fileEncoding", fileEncoding);
}
if (addStylesheet != null && !addStylesheet.isEmpty()) {
StringBuilder basenames = new StringBuilder();
for (int i = 0; i < addStylesheet.size(); i++) {
basenames.append(addStylesheet.get(i).getName());
if (i < addStylesheet.size() - 1) {
basenames.append(",");
}
}
properties.setProperty("additionalStylesheets", basenames.toString());
}
try {
Scopes scopeVal = Scopes.valueOf(scope.toUpperCase());
if (scopeVal.equals(Scopes.PUBLIC)) {
Expand All @@ -414,25 +563,27 @@ protected Properties setupProperties() {
/**
* Copies the stylesheet to the specified output directory.
*
* @param file The stylesheet file to copy
* @param outputDirectory The output directory to copy the stylesheet to
* @param outputName The name of the output file
*/
protected void copyStylesheet(final File outputDirectory) {
getLog().info("Using stylesheet from " + stylesheetFile.getAbsolutePath() + ".");
protected void copyStylesheet(final File file, final File outputDirectory, final String outputName) {
getLog().info("Using stylesheet from " + file.getAbsolutePath() + ".");
try {
BufferedReader bufferedReader = null;
BufferedWriter bufferedWriter = null;
try {
if (stylesheetEncoding != null) {
bufferedReader = new BufferedReader(new InputStreamReader(Files.newInputStream(stylesheetFile.toPath()), stylesheetEncoding));
bufferedReader = new BufferedReader(new InputStreamReader(Files.newInputStream(file.toPath()), stylesheetEncoding));
} else {
bufferedReader = new BufferedReader(new InputStreamReader(Files.newInputStream(stylesheetFile.toPath())));
bufferedReader = new BufferedReader(new InputStreamReader(Files.newInputStream(file.toPath())));
}
StringBuilder css = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
css.append(line).append("\n");
}
File outfile = new File(outputDirectory, "stylesheet.css");
File outfile = new File(outputDirectory, outputName);
if (stylesheetEncoding != null) {
bufferedWriter = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(outfile.toPath()), stylesheetEncoding));
} else {
Expand All @@ -444,7 +595,7 @@ protected void copyStylesheet(final File outputDirectory) {
FileUtils.closeQuietly(bufferedWriter);
}
} catch (IOException e) {
getLog().warn("Unable to copy specified stylesheet (" + stylesheetFile.getAbsolutePath() + ").");
getLog().warn("Unable to copy specified stylesheet (" + file.getAbsolutePath() + ").");
}
}

Expand Down
44 changes: 44 additions & 0 deletions src/main/java/org/codehaus/gmavenplus/util/GroovyCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
*/
public class GroovyCompiler {

/**
* Groovy 6.0.0-alpha-1 version.
*/
protected static final Version GROOVY_6_0_0_ALPHA1 = new Version(6, 0, 0, "alpha-1");

/**
* Groovy 5.0.0-beta-1 version.
*/
Expand Down Expand Up @@ -349,6 +354,26 @@ public void generateGroovyDoc(GroovyDocConfiguration configuration) throws Class
log.warn("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support GroovyDoc documentation properties (docTitle, footer, header, displayAuthor, overviewFile, and scope). You need Groovy 1.6-RC-2 or newer to support this. Ignoring properties.");
}

if (ClassWrangler.groovyOlderThan(classWrangler.getGroovyVersion(), GROOVY_6_0_0_ALPHA1) && configuration.getDocProperties() != null) {
Properties props = configuration.getDocProperties();
boolean usesGroovy6Props = props.getProperty("syntaxHighlighter") != null ||
props.getProperty("theme") != null ||
"true".equals(props.getProperty("showInternal")) ||
"true".equals(props.getProperty("noIndex")) ||
"true".equals(props.getProperty("noDeprecatedList")) ||
"true".equals(props.getProperty("noHelp")) ||
"false".equals(props.getProperty("timestamp")) ||
"false".equals(props.getProperty("versionStamp")) ||
"false".equals(props.getProperty("processScripts")) ||
"false".equals(props.getProperty("includeMainForScripts")) ||
props.getProperty("charset") != null ||
props.getProperty("fileEncoding") != null ||
props.getProperty("additionalStylesheets") != null;
if (usesGroovy6Props) {
log.warn("Your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support Groovy 6 GroovyDoc properties (syntaxHighlighter, theme, showInternal, noIndex, noDeprecatedList, noHelp, noTimestamp, noVersionStamp, processScripts, includeMainForScripts, charset, fileEncoding, and addStylesheet). You need Groovy 6.0.0-alpha-1 or newer to support this. Ignoring properties.");
}
}

// prevent Java stubs from overwriting GroovyDoc
List<String> groovyDocSources = setupGroovyDocSources(configuration.getSourceDirectories(), fileSetManager);

Expand All @@ -357,6 +382,25 @@ public void generateGroovyDoc(GroovyDocConfiguration configuration) throws Class

// generate GroovyDoc
performGroovyDocGeneration(configuration.getOutputDirectory(), groovyDocToolClass, outputToolClass, fileOutputTool, groovyDocSources, groovyDocTool);

// Invoke PreLanguageRewriter if preLanguage is configured (Groovy 6+ only)
if (configuration.getPreLanguage() != null && !configuration.getPreLanguage().isEmpty()) {
if (ClassWrangler.groovyAtLeast(classWrangler.getGroovyVersion(), GROOVY_6_0_0_ALPHA1)) {
try {
Class<?> preLanguageRewriterClass = classWrangler.getClass("org.codehaus.groovy.tools.groovydoc.PreLanguageRewriter");
if (preLanguageRewriterClass != null) {
Method rewriteDirectoryMethod = findMethod(preLanguageRewriterClass, "rewriteDirectory", String.class, String.class);
invokeStaticMethod(rewriteDirectoryMethod, configuration.getOutputDirectory().getAbsolutePath(), configuration.getPreLanguage());
}
} catch (ClassNotFoundException e) {
log.warn("Unable to load PreLanguageRewriter class.", e);
} catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
log.warn("Unable to invoke PreLanguageRewriter.rewriteDirectory().", e);
}
} else {
log.warn("Requested to use preLanguage, but your Groovy version (" + classWrangler.getGroovyVersionString() + ") doesn't support it (must be " + GROOVY_6_0_0_ALPHA1 + " or newer). Ignoring preLanguage parameter.");
}
}
}

protected List<?> setupLinks(GroovyDocConfiguration configuration) throws ClassNotFoundException, InvocationTargetException, IllegalAccessException, InstantiationException {
Expand Down
Loading
Loading