-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4581eb
commit a0fe6cf
Showing
13 changed files
with
339 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
builder/src/main/java/dev/sashimono/builder/documenter/DocumentationResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package dev.sashimono.builder.documenter; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* The results of documenting, basically just a temp directory with javadoc files | ||
* | ||
* @param documentationDirectory | ||
*/ | ||
public record DocumentationResult(Path documentationDirectory) { | ||
} |
68 changes: 68 additions & 0 deletions
68
builder/src/main/java/dev/sashimono/builder/documenter/JavaDocumenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package dev.sashimono.builder.documenter; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import javax.tools.DiagnosticCollector; | ||
import javax.tools.DocumentationTool; | ||
import javax.tools.JavaFileObject; | ||
import javax.tools.StandardJavaFileManager; | ||
import javax.tools.ToolProvider; | ||
|
||
import dev.sashimono.builder.compiler.JavaCompiler; | ||
import dev.sashimono.builder.tool.AbstractJavaTool; | ||
import dev.sashimono.builder.util.Log; | ||
|
||
public class JavaDocumenter extends AbstractJavaTool { | ||
|
||
private static final Log log = Log.of(JavaCompiler.class); | ||
|
||
public JavaDocumenter(final javax.tools.DocumentationTool documenter, final List<String> flags, | ||
final List<Path> dependencies, final List<Path> sourceDirectories) { | ||
super(documenter, flags, dependencies, sourceDirectories); | ||
if (documenter == null) { | ||
throw new RuntimeException("No system java documenter provided"); | ||
} | ||
} | ||
|
||
@Override | ||
protected Log getLogger() { | ||
return log; | ||
} | ||
|
||
public static JavaDocumenter build(final List<Path> dependencies, final List<Path> sourceDirectories) { | ||
// '-notimestamp' prevents timestamp from being written to .html files, ensures that hashes are identical between builds | ||
return new JavaDocumenter(ToolProvider.getSystemDocumentationTool(), List.of("-notimestamp"), dependencies, | ||
sourceDirectories); | ||
} | ||
|
||
@Override | ||
public Path process() { | ||
final javax.tools.DocumentationTool documenter = (DocumentationTool) tool; | ||
final StandardJavaFileManager fileManager = documenter.getStandardFileManager(null, null, | ||
StandardCharsets.UTF_8); | ||
final List<File> sourceFiles = collectSourceFiles(); | ||
try { | ||
final Path output = configureFileManager(fileManager, DocumentationTool.Location.DOCUMENTATION_OUTPUT); | ||
final DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<>(); | ||
final Iterable<? extends JavaFileObject> sources = fileManager | ||
.getJavaFileObjectsFromFiles(sourceFiles); | ||
final DocumentationTool.DocumentationTask task = documenter.getTask(null, fileManager, | ||
diagnosticsCollector, | ||
null, this.flags, sources); | ||
final boolean documentationTaskSucceeded = task.call(); | ||
processDiagnostics(diagnosticsCollector); | ||
if (!documentationTaskSucceeded) { | ||
throw new RuntimeException("documenting failed"); | ||
} | ||
log.infof("Documented classes to %s", output); | ||
return output; | ||
} catch (final IOException e) { | ||
throw new RuntimeException("Cannot initialize file manager", e); | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
builder/src/main/java/dev/sashimono/builder/documenter/JavaDocumenterTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.sashimono.builder.documenter; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import dev.sashimono.builder.dependencies.ResolvedDependency; | ||
import dev.sashimono.builder.tool.AbstractJavaToolTask; | ||
import dev.sashimono.builder.util.TaskMap; | ||
|
||
public class JavaDocumenterTask extends AbstractJavaToolTask implements Function<TaskMap, DocumentationResult> { | ||
|
||
public JavaDocumenterTask(final List<Path> sourceDirectories) { | ||
super(sourceDirectories); | ||
} | ||
|
||
@Override | ||
public DocumentationResult apply(final TaskMap taskMap) { | ||
//grab both the downloaded and compiled dependencies | ||
final List<Path> deps = taskMap.results(ResolvedDependency.class).stream().map(ResolvedDependency::path).toList(); | ||
final JavaDocumenter documenter = JavaDocumenter.build(deps, sourceDirectories); | ||
|
||
return new DocumentationResult(documenter.process()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.