Skip to content

Commit

Permalink
Convert parameters from String to File whenever applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Jun 18, 2024
1 parent 2d5a306 commit af8e211
Show file tree
Hide file tree
Showing 7 changed files with 424 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .idea/copyright/Apache_License.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 97 additions & 24 deletions src/main/java/rife/bld/extension/DokkaOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
* Builds documentation (javadoc, HTML, etc.) using Dokka.
Expand All @@ -37,6 +38,7 @@
*/
@SuppressWarnings("PMD.AvoidThrowingRawExceptionTypes")
public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
public static final String SEMICOLON = ";";
private final static String GFM_PLUGIN_REGEXP =
"^.*(dokka-base|analysis-kotlin-descriptors|gfm-plugin|freemarker).*\\.jar$";
private final static String HTML_PLUGIN_REGEXP =
Expand All @@ -49,8 +51,8 @@ public class DokkaOperation extends AbstractProcessOperation<DokkaOperation> {
private final Map<String, String> globalLinks_ = new ConcurrentHashMap<>();
private final Collection<String> globalPackageOptions_ = new ArrayList<>();
private final Collection<String> globalSrcLinks_ = new ArrayList<>();
private final Collection<String> includes_ = new ArrayList<>();
private final Collection<String> pluginsClasspath_ = new ArrayList<>();
private final Collection<File> includes_ = new ArrayList<>();
private final Collection<File> pluginsClasspath_ = new ArrayList<>();
private final Map<String, String> pluginsConfiguration_ = new ConcurrentHashMap<>();
private boolean delayTemplateSubstitution_;
private boolean failOnWarning_;
Expand Down Expand Up @@ -81,16 +83,16 @@ private static String encodeJson(final String json) {
* @param regex the regular expression to match
* @return the list of JARs
*/
public static List<String> getJarList(File directory, String regex) {
var jars = new ArrayList<String>();
public static List<File> getJarList(File directory, String regex) {
var jars = new ArrayList<File>();

if (directory.isDirectory()) {
var files = directory.listFiles();
if (files != null) {
for (var f : files) {
if (!f.getName().endsWith("-sources.jar") && (!f.getName().endsWith("-javadoc.jar")) &&
f.getName().matches(regex)) {
jars.add(f.getAbsolutePath());
jars.add(f);
}
}
}
Expand Down Expand Up @@ -146,12 +148,12 @@ protected List<String> executeConstructProcessCommandList() {

// -jar dokka-cli
args.add("-jar");
args.add(cli.get(0));
args.add(cli.get(0).getAbsolutePath());

// -pluginClasspath
if (!pluginsClasspath_.isEmpty()) {
args.add("-pluginsClasspath");
args.add(String.join(";", pluginsClasspath_));
args.add(pluginsClasspath_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}

// -sourceSet
Expand Down Expand Up @@ -195,19 +197,19 @@ protected List<String> executeConstructProcessCommandList() {
// -globalPackageOptions
if (!globalPackageOptions_.isEmpty()) {
args.add("-globalPackageOptions");
args.add(String.join(";", globalPackageOptions_));
args.add(String.join(SEMICOLON, globalPackageOptions_));
}

// -globalSrcLinks
if (!globalSrcLinks_.isEmpty()) {
args.add("-globalSrcLinks_");
args.add(String.join(";", globalSrcLinks_));
args.add(String.join(SEMICOLON, globalSrcLinks_));
}

// -includes
if (!includes_.isEmpty()) {
args.add("-includes");
args.add(String.join(";", includes_));
args.add(includes_.stream().map(File::getAbsolutePath).collect(Collectors.joining(SEMICOLON)));
}

// -loggingLevel
Expand Down Expand Up @@ -268,15 +270,15 @@ protected List<String> executeConstructProcessCommandList() {
* Configures the operation from a {@link BaseProject}.
* <p>
* Sets the {@link #sourceSet sourceSet}, {@link SourceSet#jdkVersion jdkVersion}, {@link #moduleName moduleName}
* and {@link SourceSet#classpath(String...) classpath} from the project.
* and {@link SourceSet#classpath(File...) classpath} from the project.
*
* @param project the project to configure the operation from
*/
@Override
public DokkaOperation fromProject(BaseProject project) {
project_ = project;
sourceSet_ = new SourceSet()
.src(new File(project.srcMainDirectory(), "kotlin").getAbsolutePath())
.src(new File(project.srcMainDirectory(), "kotlin"))
.classpath(project.compileClasspathJars())
.classpath(project.providedClasspathJars());
if (project.javaRelease() != null) {
Expand All @@ -302,6 +304,15 @@ public DokkaOperation failOnWarning(Boolean failOnWarning) {
return this;
}

/**
* Retrieves the global external documentation links.
*
* @return the documentation links
*/
public Map<String, String> globalLinks() {
return globalLinks_;
}

/**
* Set the global external documentation links.
*
Expand Down Expand Up @@ -348,6 +359,15 @@ public DokkaOperation globalPackageOptions(String... options) {
return this;
}

/**
* Retrieves the global list of package configurations.
*
* @return the package configurations
*/
public Collection<String> globalPackageOptions() {
return globalPackageOptions_;
}

/**
* Sets the global list of package configurations.
* <p>
Expand Down Expand Up @@ -381,6 +401,15 @@ public DokkaOperation globalSrcLink(String... links) {
return this;
}

/**
* Retrieves the global source links
*
* @return the source links
*/
public Collection<String> globalSrcLink() {
return globalSrcLinks_;
}

/**
* Sets the global mapping between a source directory and a Web service for browsing the code.
*
Expand All @@ -402,11 +431,37 @@ public DokkaOperation globalSrcLink(Collection<String> links) {
* @param files one or more files
* @return this operation instance
*/
public DokkaOperation includes(String... files) {
public DokkaOperation includes(File... files) {
Collections.addAll(includes_, files);
return this;
}

/**
* Sets the Markdown files that contain module and package documentation.
* <p>
* The contents of specified files are parsed and embedded into documentation as module and package descriptions.
* <p>
* This can be configured on per-package basis.
*
* @param files one or more files
* @return this operation instance
*/
public DokkaOperation includes(String... files) {
Collections.addAll(includes_, Arrays.stream(files)
.map(File::new)
.toArray(File[]::new));
return this;
}

/**
* Retrieves the markdown files that contain the module and package documentation.
*
* @return the markdown files
*/
public Collection<File> includes() {
return includes_;
}

/**
* Sets the Markdown files that contain module and package documentation.
* <p>
Expand All @@ -417,7 +472,7 @@ public DokkaOperation includes(String... files) {
* @param files the list of files
* @return this operation instance
*/
public DokkaOperation includes(Collection<String> files) {
public DokkaOperation includes(Collection<File> files) {
includes_.addAll(files);
return this;
}
Expand Down Expand Up @@ -583,38 +638,56 @@ public DokkaOperation pluginConfigurations(Map<String, String> pluginConfigurati
return this;
}

/**
* Retrieves the plugin configurations.
*
* @return the plugin configurations.
*/
public Map<String, String> pluginConfigurations() {
return pluginsConfiguration_;
}

/**
* Sets the list of jars with Dokka plugins and their dependencies.
*
* @param jars one or more jars
* @return this operation instance
*/
public DokkaOperation pluginsClasspath(String... jars) {
public DokkaOperation pluginsClasspath(File... jars) {
Collections.addAll(pluginsClasspath_, jars);
return this;
}

/**
* Sets the list of jars with Dokka plugins and their dependencies.
*
* @param jars the list of jars
* @param jars one or more jars
* @return this operation instance
*/
public DokkaOperation pluginsClasspath(Collection<String> jars) {
pluginsClasspath_.addAll(jars);
public DokkaOperation pluginsClasspath(String... jars) {
Collections.addAll(pluginsClasspath_, Arrays.stream(jars)
.map(File::new)
.toArray(File[]::new));
return this;
}

/**
* Clears the list of Dokka plugins.
* Retrieves the plugins classpath.
*
* @param clear set to clear the list
* @return the classpath
*/
public Collection<File> pluginsClasspath() {
return pluginsClasspath_;
}

/**
* Sets the list of jars with Dokka plugins and their dependencies.
*
* @param jars the list of jars
* @return this operation instance
*/
public DokkaOperation pluginsClasspath(boolean clear) {
if (clear) {
pluginsClasspath_.clear();
}
public DokkaOperation pluginsClasspath(Collection<File> jars) {
pluginsClasspath_.addAll(jars);
return this;
}

Expand Down
Loading

0 comments on commit af8e211

Please sign in to comment.