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
51 changes: 21 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@
<!-- test -->
<junit.version>4.12</junit.version>
<hamcrest.version>1.3</hamcrest.version>
<mockito.version>2.20.1</mockito.version>
<mockito.version>2.22.0</mockito.version>
<slf4j.version>1.7.25</slf4j.version>
<logback.version>1.2.3</logback.version>
<maven-invoker.version>3.0.1</maven-invoker.version>

<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>2.20.1</maven-failsafe-plugin.version>
<maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>
<maven-shade-plugin.version>3.2.0</maven-shade-plugin.version>
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.0.1</maven-javadoc-plugin.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
Expand All @@ -90,30 +90,20 @@
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
<license-maven-plugin.version>3.0</license-maven-plugin.version>
<buildnumber-maven-plugin.version>1.4</buildnumber-maven-plugin.version>
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
<jacoco-maven-plugin.version>0.8.2</jacoco-maven-plugin.version>
<coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
</properties>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>LICENSE</include>
<include>README.md</include>
<include>USAGE.md</include>
</includes>
</resource>
</resources>
Expand Down Expand Up @@ -196,18 +186,30 @@
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<executions>
<execution>
<id>prepare-jacoco-agent</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${coveralls-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down Expand Up @@ -335,7 +337,6 @@
</dependency>

<dependency>
<!-- This will probably break after jigsaw becomes mainstream? -->
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>${build.java.version}</version>
Expand Down Expand Up @@ -381,16 +382,6 @@
</dependency>
</dependencies>

<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura-maven-plugin.version}</version>
</plugin>
</plugins>
</reporting>

<repositories>
<repository>
<id>local-lib</id>
Expand Down
54 changes: 40 additions & 14 deletions src/main/java/nl/talsmasoftware/umldoclet/UMLDoclet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 Talsma ICT
* Copyright 2016-2018 Talsma ICT
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,22 +15,38 @@
*/
package nl.talsmasoftware.umldoclet;

import com.sun.javadoc.*;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.DocErrorReporter;
import com.sun.javadoc.LanguageVersion;
import com.sun.javadoc.PackageDoc;
import com.sun.javadoc.RootDoc;
import com.sun.tools.doclets.standard.Standard;
import net.sourceforge.plantuml.version.Version;
import nl.talsmasoftware.umldoclet.config.UMLDocletConfig;
import nl.talsmasoftware.umldoclet.html.HtmlPostprocessor;
import nl.talsmasoftware.umldoclet.logging.GlobalPosition;
import nl.talsmasoftware.umldoclet.logging.LogSupport;
import nl.talsmasoftware.umldoclet.rendering.DiagramRenderer;
import nl.talsmasoftware.umldoclet.rendering.plantuml.PlantumlImageWriter;
import nl.talsmasoftware.umldoclet.rendering.plantuml.PlantumlSupport;

import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

import static java.util.Objects.requireNonNull;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.*;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.debug;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.error;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.info;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.isTraceEnabled;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.trace;

/**
* UML doclet that generates <a href="http://plantuml.com">PlantUML</a> class diagrams from your java code just as
Expand Down Expand Up @@ -81,17 +97,15 @@ public static boolean validOptions(String[][] options, DocErrorReporter reporter

public static boolean start(RootDoc rootDoc) {
UMLDoclet umlDoclet = new UMLDoclet(rootDoc);
boolean umlDocletResult = umlDoclet.generateUMLDiagrams();
// Regarding issue #13: I don't understand why the Standard doclet will run on a 'bad' javadoc
// contained in RootDoc somewhere after UMLDoclet has done it's thing, but
// send us a (correct) JavaDoc ERROR if ran on the same rootDoc 'untouched'...
// Think about this; Is there some way to 'clone' it and pass the original rootDoc to the
// Standard doclet??
// TODO re-test this issue with the added 'languageVersion()' method.
if (umlDocletResult && !umlDoclet.config.skipStandardDoclet()) {
return Standard.start(rootDoc);

// First generate Standard HTML documentation
if (!umlDoclet.config.skipStandardDoclet()) {
if (!Standard.start(rootDoc)) return false;
}
return umlDocletResult;

// Then generate UML and postprocess the javadoc HTML files
return umlDoclet.generateUMLDiagrams()
&& umlDoclet.postProcessHtml();
}

public boolean generateUMLDiagrams() {
Expand Down Expand Up @@ -233,4 +247,16 @@ private Writer createWriterForUmlFile(File umlDirectory, String umlBaseName, Fil
throw new IllegalStateException("Error creating: " + umlFile);
}

private boolean postProcessHtml() {
try {

return new HtmlPostprocessor(config).postProcessHtml();

} catch (IOException | RuntimeException ex) {
LogSupport.error("Unanticipated error post-processing HTML: {0}", ex);
ex.printStackTrace(System.err);
return false;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 Talsma ICT
* Copyright 2016-2018 Talsma ICT
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,11 +23,19 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;

import static nl.talsmasoftware.umldoclet.config.UMLDocletConfig.Setting.*;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.*;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.debug;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.error;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.trace;
import static nl.talsmasoftware.umldoclet.logging.LogSupport.warn;
import static nl.talsmasoftware.umldoclet.model.Model.isDeprecated;
import static nl.talsmasoftware.umldoclet.rendering.indent.Indentation.spaces;
import static nl.talsmasoftware.umldoclet.rendering.indent.Indentation.tabs;
Expand Down Expand Up @@ -216,21 +224,54 @@ public String umlFileEncoding() {
// TODO: look for default setting "-docEncoding" as fallback..
String encoding = UML_FILE_ENCODING.value(this);
if (encoding == null) {
encoding = htmlFileEncoding().name();
debug("Setting UML file encoding to evaluated document encoding {0} from standard doclet.", encoding);
this.put(UML_FILE_ENCODING, encoding);
}
return encoding;
}

private Charset _htmlFileEncoding = null;

/**
* The {@code HTML} character set is determined the same way the {@code Standard} doclet uses,
* as we delegate the initial rendering to it:
* <ol>
* <li>use the {@code "-docencoding"} if set,</li>
* <li>otherwise the source encoding ({@code "-encoding"})</li>
* <li>finally, if no encodings are specified at all,
* the {@code default platform encoding} is used as implicit fallback</li>
* </ol>
*
* @return The charset used for Javadoc HTML files
*/
public Charset htmlFileEncoding() {
if (_htmlFileEncoding == null) {
Charset encoding = null;
for (String[] stdOption : standardOptions) {
if (stdOption.length > 1 && "-docEncoding".equalsIgnoreCase(stdOption[0])) {
encoding = stdOption[1];
debug("Setting UML file encoding to \"{0}\" from standard Doclet option \"{1}\", because \"{2}\" was not specified.",
encoding, "-docEncoding", "-" + UML_FILE_ENCODING.delegate.name);
break;
return _htmlFileEncoding = Charset.forName(stdOption[1]);
} else if (stdOption.length > 1 && "-encoding".equalsIgnoreCase(stdOption[0])) {
encoding = Charset.forName(stdOption[1]);
}
}
if (encoding == null) {
encoding = "UTF-8";
debug("Setting UML file encoding to \"{0}\" by default.", encoding);
_htmlFileEncoding = encoding != null ? encoding : Charset.defaultCharset();
}
return _htmlFileEncoding;
}

private String _htmlDestinationDirectory;

public String htmlDestinationDirectory() {
if (_htmlDestinationDirectory == null) {
for (String[] stdOption : standardOptions) {
if (stdOption.length > 1 && "-d".equals(stdOption[0])) {
return _htmlDestinationDirectory = stdOption[1];
}
}
this.put(UML_FILE_ENCODING, encoding);
_htmlDestinationDirectory = basePath();
}
return encoding;
return _htmlDestinationDirectory;
}

public boolean skipStandardDoclet() {
Expand Down
Loading