Skip to content
Open
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
19 changes: 19 additions & 0 deletions src/it/projects/addscript/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

invoker.goals=compile javadoc:javadoc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if available only since jdk 18, you need add something such

invoker.java.version = 18+

invoker.java.version = 18+
50 changes: 50 additions & 0 deletions src/it/projects/addscript/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. The ASF licenses this file to
you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins.javadoc.it</groupId>
<artifactId>addscript</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>@maven.compiler.source@</maven.compiler.source>
<maven.compiler.target>@maven.compiler.target@</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>@compilerPluginVersion@</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<addScripts>
<addScript>resources/custom-script.js</addScript>
<addScript>resources/custom-script1.js</addScript>
<addScript>resources/custom-script2.js</addScript>
</addScripts>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.example;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
* Support for multiple extra scripts
*/
public class AddScriptJavaDoc
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

console.log('script');
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

console.log('script1');
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

console.log('script2');
26 changes: 26 additions & 0 deletions src/it/projects/addscript/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

def file = new File( basedir, 'target/reports/apidocs/com/example/AddScriptJavaDoc.html' );

assert file.exists()

assert 1 == file.text.count('custom-script.js')
assert 1 == file.text.count('custom-script1.js')
assert 1 == file.text.count('custom-script2.js')
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,22 @@ public AbstractJavadocMojo(
@Parameter
private String[] addStylesheets;

/**
* Specifies the path of an additional script file relative to the {@code javadocDirectory}
* Example:
* <pre>
* &lt;addScripts&gt;
* &lt;addScript&gt;resources/script.js&lt;/addScript&gt;
* &lt;/addScripts&gt;
* </pre>
* <p>
* These script files are passed to the Javadoc tool via the {@code --add-script} parameter.
* This option is available since JDK 18.
* @since 3.13.0
*/
@Parameter
private String[] addScripts;

/**
* Specifies the class file that starts the taglet used in generating the documentation for that tag.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option taglet</a>.
Expand Down Expand Up @@ -2789,6 +2805,44 @@ private Optional<File> getAddStylesheet(final File javadocOutputDirectory, final
"additional stylesheet file does not exist: " + addstylesheetfile.getAbsolutePath());
}

private void addAddScripts(List<String> arguments) throws MavenReportException {
if (addScripts == null) {
return;
}

JavaVersion requiredJavaVersionForScripts = JavaVersion.parse("18");
if (!isJavaDocVersionAtLeast(requiredJavaVersionForScripts)) {
throw new MavenReportException(
"the javadoc tool option to add scripts (--add-scripts) is available only since JDK 18");
}

for (String addScript : addScripts) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe check if the jdk is at least 18, if not throw a proper error message

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey 👋🏻 , thanks for having a look and for the suggestions!
I'll try to address these soon 🙂.

Copy link
Author

@marko-bekhta marko-bekhta Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addArgIfNotEmpty( had that check to produce a warning, but as you've suggested... I added a check and exception just above ^.
thanks 🙂

Optional<File> script = getAddScript(getJavadocDirectory(), addScript);

if (script.isPresent()) {
addArgIfNotEmpty(
arguments,
"--add-script",
JavadocUtil.quotedPathArgument(script.get().getAbsolutePath()),
requiredJavaVersionForScripts);
}
}
}

private Optional<File> getAddScript(final File javadocOutputDirectory, final String script)
throws MavenReportException {
if (script == null || script.isEmpty()) {
return Optional.empty();
}

File scriptFile = new File(getJavadocDirectory(), script);
if (scriptFile.exists()) {
return Optional.of(scriptFile);
}

throw new MavenReportException("script file does not exist: " + scriptFile.getAbsolutePath());
}

/**
* Method to get the help file to be used by the Javadoc Tool.
* <br/>
Expand Down Expand Up @@ -4761,6 +4815,8 @@ private void addStandardDocletOptions(

addAddStyleSheets(arguments);

addAddScripts(arguments);

addArgIfNotEmpty(arguments, "-subpackages", subpackages);

addArgIfNotEmpty(arguments, "-taglet", JavadocUtil.quotedArgument(taglet));
Expand Down