-
Notifications
You must be signed in to change notification settings - Fork 103
Add the "addScripts" configuration parameter #1281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| invoker.java.version = 18+ | ||
| 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'); |
| 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 |
|---|---|---|
|
|
@@ -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> | ||
| * <addScripts> | ||
| * <addScript>resources/script.js</addScript> | ||
| * </addScripts> | ||
| * </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>. | ||
|
|
@@ -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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hey 👋🏻 , thanks for having a look and for the suggestions!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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/> | ||
|
|
@@ -4761,6 +4815,8 @@ private void addStandardDocletOptions( | |
|
|
||
| addAddStyleSheets(arguments); | ||
|
|
||
| addAddScripts(arguments); | ||
|
|
||
| addArgIfNotEmpty(arguments, "-subpackages", subpackages); | ||
|
|
||
| addArgIfNotEmpty(arguments, "-taglet", JavadocUtil.quotedArgument(taglet)); | ||
|
|
||
There was a problem hiding this comment.
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