Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#89: introduced TaskOption class for easier configuration of all task…
… arguments (including JavadocTask)
- Loading branch information
1 parent
8d84487
commit 4014f02
Showing
12 changed files
with
219 additions
and
123 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
12 changes: 12 additions & 0 deletions
12
src/main/java/org/javamodularity/moduleplugin/internal/StreamHelper.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,12 @@ | ||
package org.javamodularity.moduleplugin.internal; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Stream; | ||
|
||
public final class StreamHelper { | ||
|
||
@SafeVarargs | ||
public static <T> Stream<T> concat(Stream<T>... streams) { | ||
return Arrays.stream(streams).reduce(Stream::concat).orElseThrow(IllegalArgumentException::new); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/org/javamodularity/moduleplugin/internal/TaskOption.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,64 @@ | ||
package org.javamodularity.moduleplugin.internal; | ||
|
||
import org.gradle.external.javadoc.CoreJavadocOptions; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Stores a flag and its value that can be used as: compiler args, JVM args, and Javadoc options. | ||
*/ | ||
public final class TaskOption { | ||
|
||
/** | ||
* E.g. {@code --add-modules}. | ||
*/ | ||
private final String flag; | ||
/** | ||
* E.g. {@code java.sql,my.module}. | ||
*/ | ||
private final String value; | ||
|
||
public TaskOption(String flag, String value) { | ||
this.flag = flag; | ||
this.value = value; | ||
this.validate(); | ||
} | ||
|
||
private void validate() { | ||
if (!flag.startsWith("--")) { | ||
throw new IllegalArgumentException("Invalid flag: " + flag); | ||
} | ||
if (value.isBlank() || value.contains(" ")) { | ||
throw new IllegalArgumentException("Invalid value: " + value); | ||
} | ||
} | ||
|
||
public String getFlag() { | ||
return flag; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
/** | ||
* Javadoc takes options without the initial hyphen. | ||
* | ||
* @return the Javadoc flag | ||
* @see org.gradle.external.javadoc.internal.JavadocOptionFileWriterContext#writeOptionHeader(String) | ||
*/ | ||
public String getJavadocFlag() { | ||
return flag.substring(1); | ||
} | ||
|
||
//region MUTATE | ||
public void mutateArgs(List<String> args) { | ||
args.add(flag); | ||
args.add(value); | ||
} | ||
|
||
public void mutateOptions(CoreJavadocOptions options) { | ||
options.addStringOption(getJavadocFlag(), value); | ||
} | ||
//endregion | ||
} |
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
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
Oops, something went wrong.