You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2021/05/01 11:08:32 UTC

[maven-javadoc-plugin] 01/03: Support for multiple stylesheets

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MJAVADOC-625
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git

commit c84548b9bd5284a5c5d2accb9299d37ce915fb42
Author: Martin Schelldorfer <sc...@gmail.com>
AuthorDate: Thu Oct 17 15:16:28 2019 +0200

    Support for multiple stylesheets
---
 src/it/projects/MJAVADOC-625/invoker.properties    | 19 ++++++++
 src/it/projects/MJAVADOC-625/pom.xml               | 50 ++++++++++++++++++++++
 .../src/main/java/com/example/MJavaDoc625.java     | 28 ++++++++++++
 .../src/main/javadoc/resources/addstylesheet.css   | 23 ++++++++++
 src/it/projects/MJAVADOC-625/verify.groovy         | 24 +++++++++++
 .../maven/plugins/javadoc/AbstractJavadocMojo.java | 42 +++++++++++++++++-
 6 files changed, 184 insertions(+), 2 deletions(-)

diff --git a/src/it/projects/MJAVADOC-625/invoker.properties b/src/it/projects/MJAVADOC-625/invoker.properties
new file mode 100644
index 0000000..1258430
--- /dev/null
+++ b/src/it/projects/MJAVADOC-625/invoker.properties
@@ -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.java.version = 10+
+invoker.goals=compile javadoc:javadoc
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-625/pom.xml b/src/it/projects/MJAVADOC-625/pom.xml
new file mode 100644
index 0000000..6e26644
--- /dev/null
+++ b/src/it/projects/MJAVADOC-625/pom.xml
@@ -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>mjavadoc-625</artifactId>
+  <version>1.0.0-SNAPSHOT</version>
+  
+  <url>https://issues.apache.org/jira/browse/MJAVADOC-625</url>
+
+  <build>
+      <plugins>
+      	<plugin>
+	        <groupId>org.apache.maven.plugins</groupId>
+	        <artifactId>maven-compiler-plugin</artifactId>
+	        <version>3.8.0</version>
+	      </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-javadoc-plugin</artifactId>
+          <version>@project.version@</version>
+          
+          <configuration>
+            <addStylesheet>src/main/javadoc/resources/addstylesheet.css</addStylesheet>
+          </configuration>
+        </plugin>
+      </plugins>
+  </build>
+  
+</project>
diff --git a/src/it/projects/MJAVADOC-625/src/main/java/com/example/MJavaDoc625.java b/src/it/projects/MJAVADOC-625/src/main/java/com/example/MJavaDoc625.java
new file mode 100644
index 0000000..163e444
--- /dev/null
+++ b/src/it/projects/MJAVADOC-625/src/main/java/com/example/MJavaDoc625.java
@@ -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.
+ */
+
+/**
+ * MJAVADOC-625 Support for multiple stylesheets
+ */
+public class MJavaDoc625
+{
+
+}
diff --git a/src/it/projects/MJAVADOC-625/src/main/javadoc/resources/addstylesheet.css b/src/it/projects/MJAVADOC-625/src/main/javadoc/resources/addstylesheet.css
new file mode 100644
index 0000000..02172e1
--- /dev/null
+++ b/src/it/projects/MJAVADOC-625/src/main/javadoc/resources/addstylesheet.css
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+body
+{
+   font-size: 20px;
+}
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-625/verify.groovy b/src/it/projects/MJAVADOC-625/verify.groovy
new file mode 100644
index 0000000..05ca2c5
--- /dev/null
+++ b/src/it/projects/MJAVADOC-625/verify.groovy
@@ -0,0 +1,24 @@
+/*
+ * 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/site/apidocs/com/example/MJavaDoc625.html' );
+
+assert file.exists()
+
+assert 1 == file.text.count('addstylesheet.css')
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index 1409241..6d56a95 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -1423,8 +1423,14 @@ public abstract class AbstractJavadocMojo
      * stylesheetfile</a>.
      */
     @Parameter( property = "stylesheetfile" )
-   private String stylesheetfile;
-
+    private String stylesheetfile;
+    
+    /**
+     * Specifies the path of an additional HTML stylesheet file.
+     */
+    @Parameter
+    private String addStylesheet;
+    
     /**
      * Specifies the class file that starts the taglet used in generating the documentation for that tag.
      * <br/>
@@ -3028,6 +3034,35 @@ public abstract class AbstractJavadocMojo
 
         return getResource( new File( javadocOutputDirectory, DEFAULT_CSS_NAME ), stylesheetfile );
     }
+    
+    private String getAddStylesheet( final File javadocOutputDirectory )
+            throws MavenReportException
+    {
+        if ( StringUtils.isEmpty( addStylesheet ) )
+        {
+            return null;
+        }
+        
+        File addstylesheetfile = new File( addStylesheet );
+        if ( addstylesheetfile.exists() )
+        {
+            String stylesheet = getStylesheetFile( javadocOutputDirectory );
+            if ( stylesheet != null )
+            {
+                File stylesheetfile = new File( stylesheet );
+                if ( stylesheetfile.getName().equals( addstylesheetfile.getName() ) )
+                {
+                    throw new MavenReportException( "additional stylesheet must have a different name "
+                                                        + "than stylesheetfile: " + stylesheetfile.getName() );
+                }
+            }
+            
+            return addstylesheetfile.getAbsolutePath();
+        }
+
+        throw new MavenReportException( "additional stylesheet file does not exist: " 
+                                            + addstylesheetfile.getAbsolutePath() );
+    }
 
     /**
      * Method to get the help file to be used by the Javadoc Tool.
@@ -5507,6 +5542,9 @@ public abstract class AbstractJavadocMojo
 
         addArgIfNotEmpty( arguments, "-stylesheetfile",
                           JavadocUtil.quotedPathArgument( getStylesheetFile( javadocOutputDirectory ) ) );
+        
+        addArgIfNotEmpty( arguments, "--add-stylesheet",
+                          JavadocUtil.quotedPathArgument( getAddStylesheet( javadocOutputDirectory ) ) );
 
         if ( StringUtils.isNotEmpty( sourcepath ) && !isJavaDocVersionAtLeast( SINCE_JAVADOC_1_5 ) )
         {