2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-25 08:17:11 -07:00

Added JavacOptions, JavadocOptions and JavaOptions File argument alternatives with Path and String.

Relaxed the requirement to specify mainClass in a project and added support for module.
This commit is contained in:
Geert Bevin 2024-08-25 14:07:36 -04:00
parent 126daecd21
commit 9f9e8a95db
9 changed files with 861 additions and 47 deletions

View file

@ -61,6 +61,13 @@ public class BaseProject extends BuildExecutor {
* @since 1.5
*/
protected String mainClass = null;
/**
* The project's module.
*
* @see #module()
* @since 2.1
*/
protected String module = null;
/**
* The project's repositories for dependency resolution.
@ -1399,12 +1406,18 @@ public class BaseProject extends BuildExecutor {
* @since 1.5
*/
public String mainClass() {
if (mainClass == null) {
throw new IllegalStateException("The mainClass variable has to be set.");
}
return mainClass;
}
/**
* Returns the project's module.
*
* @since 2.1
*/
public String module() {
return module;
}
/**
* Returns the list of repositories for this project.
* <p>
@ -1520,7 +1533,14 @@ public class BaseProject extends BuildExecutor {
* @since 1.5
*/
public String uberJarMainClass() {
return Objects.requireNonNullElseGet(uberJarMainClass, this::mainClass);
if (uberJarMainClass != null) {
return uberJarMainClass;
}
if (mainClass() != null) {
return mainClass();
}
throw new IllegalStateException("The mainClass variable has to be set.");
}
/**

View file

@ -29,6 +29,7 @@ public abstract class AbstractProcessOperation<T extends AbstractProcessOperatio
protected final List<String> classpath_ = new ArrayList<>();
protected final List<String> modulePath_ = new ArrayList<>();
protected String mainClass_;
protected String module_;
protected Function<String, Boolean> outputProcessor_;
protected Function<String, Boolean> errorProcessor_;
protected Process process_;
@ -252,6 +253,18 @@ public abstract class AbstractProcessOperation<T extends AbstractProcessOperatio
return (T) this;
}
/**
* Provides the module to launch with the java tool.
*
* @param name the module to launch
* @return this operation instance
* @since 2.1
*/
public T module(String name) {
module_ = name;
return (T) this;
}
/**
* Provides the processor that will be used to handle the process output.
* <p>
@ -346,6 +359,16 @@ public abstract class AbstractProcessOperation<T extends AbstractProcessOperatio
return mainClass_;
}
/**
* Retrieves the module to launch with the java tool.
*
* @return the module to launch
* @since 2.1
*/
public String module() {
return module_;
}
/**
* Retrieves the processor that is used to handle the process output.
*

View file

@ -4,9 +4,11 @@
*/
package rife.bld.operations;
import rife.tools.FileUtils;
import rife.tools.StringUtils;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@ -38,8 +40,8 @@ public class JavaOptions extends ArrayList<String> {
* @return this list of options
* @since 1.5.18
*/
public JavaOptions modulePath(File... modules) {
return modulePath(List.of(modules));
public JavaOptions modulePath(File... paths) {
return modulePath(List.of(paths));
}
/**
@ -48,9 +50,49 @@ public class JavaOptions extends ArrayList<String> {
* @return this list of options
* @since 1.5.18
*/
public JavaOptions modulePath(List<File> modules) {
public JavaOptions modulePath(List<File> paths) {
return modulePathStrings(paths.stream().map(File::getAbsolutePath).toList());
}
/**
* A list of directories, each directory is a directory of modules.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions modulePath(Path... paths) {
return modulePathPaths(List.of(paths));
}
/**
* A list of directories, each directory is a directory of modules.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions modulePathPaths(List<Path> paths) {
return modulePath(paths.stream().map(Path::toFile).toList());
}
/**
* A list of directories, each directory is a directory of modules.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions modulePath(String... paths) {
return modulePathStrings(List.of(paths));
}
/**
* A list of directories, each directory is a directory of modules.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions modulePathStrings(List<String> paths) {
add("--module-path");
add(StringUtils.join(modules, ":"));
add(FileUtils.joinPaths(paths));
return this;
}
@ -61,8 +103,8 @@ public class JavaOptions extends ArrayList<String> {
* @return this list of options
* @since 1.5.18
*/
public JavaOptions upgradeModulePath(File... modulePath) {
return upgradeModulePath(List.of(modulePath));
public JavaOptions upgradeModulePath(File... paths) {
return upgradeModulePath(List.of(paths));
}
/**
@ -72,9 +114,53 @@ public class JavaOptions extends ArrayList<String> {
* @return this list of options
* @since 1.5.18
*/
public JavaOptions upgradeModulePath(List<File> modulePath) {
public JavaOptions upgradeModulePath(List<File> paths) {
return upgradeModulePathStrings(paths.stream().map(File::getAbsolutePath).toList());
}
/**
* List of directories, each directory is a directory of modules
* that replace upgradeable modules in the runtime image
*
* @return this list of options
* @since 2.1
*/
public JavaOptions upgradeModulePath(Path... paths) {
return upgradeModulePathPaths(List.of(paths));
}
/**
* List of directories, each directory is a directory of modules
* that replace upgradeable modules in the runtime image
*
* @return this list of options
* @since 2.1
*/
public JavaOptions upgradeModulePathPaths(List<Path> paths) {
return upgradeModulePath(paths.stream().map(Path::toFile).toList());
}
/**
* List of directories, each directory is a directory of modules
* that replace upgradeable modules in the runtime image
*
* @return this list of options
* @since 2.1
*/
public JavaOptions upgradeModulePath(String... paths) {
return upgradeModulePathStrings(List.of(paths));
}
/**
* List of directories, each directory is a directory of modules
* that replace upgradeable modules in the runtime image
*
* @return this list of options
* @since 2.1
*/
public JavaOptions upgradeModulePathStrings(List<String> paths) {
add("--upgrade-module-path");
add(StringUtils.join(modulePath, ":"));
add(FileUtils.joinPaths(paths));
return this;
}
@ -256,7 +342,7 @@ public class JavaOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavaOptions agentPath(File pathName) {
return agentPath(pathName, (String)null);
return agentPath(pathName.getAbsolutePath(), (String)null);
}
/**
@ -266,8 +352,7 @@ public class JavaOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavaOptions agentPath(File pathName, String options) {
add("-agentpath:" + pathName + (options == null ? "" : "=" + options));
return this;
return agentPath(pathName.getAbsolutePath(), options);
}
/**
@ -277,7 +362,7 @@ public class JavaOptions extends ArrayList<String> {
* @since 1.7.1
*/
public JavaOptions agentPath(File pathName, String... options) {
return agentPath(pathName, List.of(options));
return agentPath(pathName.getAbsolutePath(), List.of(options));
}
/**
@ -287,6 +372,87 @@ public class JavaOptions extends ArrayList<String> {
* @since 1.7.1
*/
public JavaOptions agentPath(File pathName, List<String> options) {
return agentPath(pathName.getAbsolutePath(), options);
}
/**
* Load native agent library by full pathname.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions agentPath(Path pathName) {
return agentPath(pathName.toFile(), (String)null);
}
/**
* Load native agent library by full pathname.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions agentPath(Path pathName, String options) {
return agentPath(pathName.toFile(), options);
}
/**
* Load native agent library by full pathname.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions agentPath(Path pathName, String... options) {
return agentPath(pathName.toFile(), List.of(options));
}
/**
* Load native agent library by full pathname.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions agentPath(Path pathName, List<String> options) {
return agentPath(pathName.toFile(), options);
}
/**
* Load native agent library by full pathname.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions agentPath(String pathName) {
return agentPath(pathName, (String)null);
}
/**
* Load native agent library by full pathname.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions agentPath(String pathName, String options) {
add("-agentpath:" + pathName + (options == null ? "" : "=" + options));
return this;
}
/**
* Load native agent library by full pathname.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions agentPath(String pathName, String... options) {
return agentPath(pathName, List.of(options));
}
/**
* Load native agent library by full pathname.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions agentPath(String pathName, List<String> options) {
add("-agentpath:" + pathName + (options == null || options.isEmpty() ? "" : "=" + StringUtils.join(options, ",")));
return this;
}
@ -298,7 +464,7 @@ public class JavaOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavaOptions javaAgent(File jarPath) {
return javaAgent(jarPath, (String)null);
return javaAgent(jarPath.getAbsolutePath(), (String)null);
}
/**
@ -308,8 +474,7 @@ public class JavaOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavaOptions javaAgent(File jarPath, String options) {
add("-javaagent:" + jarPath + (options == null ? "" : "=" + options));
return this;
return javaAgent(jarPath.getAbsolutePath(), options);
}
/**
@ -319,7 +484,7 @@ public class JavaOptions extends ArrayList<String> {
* @since 1.7.1
*/
public JavaOptions javaAgent(File jarPath, String... options) {
return javaAgent(jarPath, List.of(options));
return javaAgent(jarPath.getAbsolutePath(), List.of(options));
}
/**
@ -329,6 +494,87 @@ public class JavaOptions extends ArrayList<String> {
* @since 1.7.1
*/
public JavaOptions javaAgent(File jarPath, List<String> options) {
return javaAgent(jarPath.getAbsolutePath(), options);
}
/**
* Load Java programming language agent.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions javaAgent(Path jarPath) {
return javaAgent(jarPath.toFile(), (String)null);
}
/**
* Load Java programming language agent.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions javaAgent(Path jarPath, String options) {
return javaAgent(jarPath.toFile(), options);
}
/**
* Load Java programming language agent.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions javaAgent(Path jarPath, String... options) {
return javaAgent(jarPath.toFile(), List.of(options));
}
/**
* Load Java programming language agent.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions javaAgent(Path jarPath, List<String> options) {
return javaAgent(jarPath.toFile(), options);
}
/**
* Load Java programming language agent.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions javaAgent(String jarPath) {
return javaAgent(jarPath, (String)null);
}
/**
* Load Java programming language agent.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions javaAgent(String jarPath, String options) {
add("-javaagent:" + jarPath + (options == null ? "" : "=" + options));
return this;
}
/**
* Load Java programming language agent.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions javaAgent(String jarPath, String... options) {
return javaAgent(jarPath, List.of(options));
}
/**
* Load Java programming language agent.
*
* @return this list of options
* @since 2.1
*/
public JavaOptions javaAgent(String jarPath, List<String> options) {
add("-javaagent:" + jarPath + (options == null || options.isEmpty() ? "" : "=" + StringUtils.join(options, ",")));
return this;
}

View file

@ -9,10 +9,10 @@ import rife.tools.FileUtils;
import rife.tools.StringUtils;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Options for the standard javac tool.
@ -121,8 +121,48 @@ public class JavacOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavacOptions endorsedDirs(List<File> dirs) {
return endorsedDirsStrings(dirs.stream().map(File::getAbsolutePath).toList());
}
/**
* Override location of endorsed standards path
*
* @return this list of options
* @since 2.1
*/
public JavacOptions endorsedDirs(Path... dirs) {
return endorsedDirsPaths(Arrays.asList(dirs));
}
/**
* Override location of endorsed standards path
*
* @return this list of options
* @since 2.1
*/
public JavacOptions endorsedDirsPaths(List<Path> dirs) {
return endorsedDirs(dirs.stream().map(Path::toFile).toList());
}
/**
* Override location of endorsed standards path
*
* @return this list of options
* @since 2.1
*/
public JavacOptions endorsedDirs(String... dirs) {
return endorsedDirsStrings(Arrays.asList(dirs));
}
/**
* Override location of endorsed standards path
*
* @return this list of options
* @since 2.1
*/
public JavacOptions endorsedDirsStrings(List<String> dirs) {
add("-endorseddirs");
add(dirs.stream().map(File::getAbsolutePath).collect(Collectors.joining(",")));
add(String.join(",", dirs));
return this;
}
@ -143,8 +183,48 @@ public class JavacOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavacOptions extDirs(List<File> dirs) {
return extDirsStrings(dirs.stream().map(File::getAbsolutePath).toList());
}
/**
* Override location of installed extensions
*
* @return this list of options
* @since 2.1
*/
public JavacOptions extDirs(Path... dirs) {
return extDirsPaths(Arrays.asList(dirs));
}
/**
* Override location of installed extensions
*
* @return this list of options
* @since 2.1
*/
public JavacOptions extDirsPaths(List<Path> dirs) {
return extDirs(dirs.stream().map(Path::toFile).toList());
}
/**
* Override location of installed extensions
*
* @return this list of options
* @since 2.1
*/
public JavacOptions extDirs(String... dirs) {
return extDirsStrings(Arrays.asList(dirs));
}
/**
* Override location of installed extensions
*
* @return this list of options
* @since 2.1
*/
public JavacOptions extDirsStrings(List<String> dirs) {
add("-extdirs");
add(dirs.stream().map(File::getAbsolutePath).collect(Collectors.joining(",")));
add(String.join(",", dirs));
return this;
}
@ -193,8 +273,28 @@ public class JavacOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavacOptions nativeHeaders(File path) {
return nativeHeaders(path.getAbsolutePath());
}
/**
* Specify where to place generated native header files
*
* @return this list of options
* @since 2.1
*/
public JavacOptions nativeHeaders(Path path) {
return nativeHeaders(path.toFile());
}
/**
* Specify where to place generated native header files
*
* @return this list of options
* @since 2.1
*/
public JavacOptions nativeHeaders(String path) {
add("-h");
add(path.getAbsolutePath());
add(path);
return this;
}
@ -270,8 +370,48 @@ public class JavacOptions extends ArrayList<String> {
* @since 1.6.2
*/
public JavacOptions modulePath(List<File> paths) {
return modulePathStrings(paths.stream().map(File::getAbsolutePath).toList());
}
/**
* Specify where to find application modules
*
* @return this list of options
* @since 2.1
*/
public JavacOptions modulePath(Path... paths) {
return modulePathPaths(Arrays.asList(paths));
}
/**
* Specify where to find application modules
*
* @return this list of options
* @since 2.1
*/
public JavacOptions modulePathPaths(List<Path> paths) {
return modulePath(paths.stream().map(Path::toFile).toList());
}
/**
* Specify where to find application modules
*
* @return this list of options
* @since 2.1
*/
public JavacOptions modulePath(String... paths) {
return modulePathStrings(Arrays.asList(paths));
}
/**
* Specify where to find application modules
*
* @return this list of options
* @since 2.1
*/
public JavacOptions modulePathStrings(List<String> paths) {
add("--module-path");
add(FileUtils.joinPaths(paths.stream().map(File::getAbsolutePath).toList()));
add(FileUtils.joinPaths(paths));
return this;
}
@ -282,8 +422,28 @@ public class JavacOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavacOptions moduleSourcePath(File path) {
return moduleSourcePath(path.getAbsolutePath());
}
/**
* Specify where to find input source files for multiple modules
*
* @return this list of options
* @since 2.1
*/
public JavacOptions moduleSourcePath(Path path) {
return moduleSourcePath(path.toFile());
}
/**
* Specify where to find input source files for multiple modules
*
* @return this list of options
* @since 2.1
*/
public JavacOptions moduleSourcePath(String path) {
add("--module-source-path");
add(path.getAbsolutePath());
add(path);
return this;
}
@ -361,8 +521,28 @@ public class JavacOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavacOptions processorModulePath(File path) {
return processorModulePath(path.getAbsolutePath());
}
/**
* Specify a module path where to find annotation processors
*
* @return this list of options
* @since 2.1
*/
public JavacOptions processorModulePath(Path path) {
return processorModulePath(path.toFile());
}
/**
* Specify a module path where to find annotation processors
*
* @return this list of options
* @since 2.1
*/
public JavacOptions processorModulePath(String path) {
add("--processor-module-path");
add(path.getAbsolutePath());
add(path);
return this;
}
@ -373,8 +553,28 @@ public class JavacOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavacOptions processorPath(File path) {
return processorPath(path.getAbsolutePath());
}
/**
* Specify where to find annotation processors
*
* @return this list of options
* @since 2.1
*/
public JavacOptions processorPath(Path path) {
return processorPath(path.toFile());
}
/**
* Specify where to find annotation processors
*
* @return this list of options
* @since 2.1
*/
public JavacOptions processorPath(String path) {
add("--processor-path");
add(path.getAbsolutePath());
add(path);
return this;
}
@ -409,8 +609,28 @@ public class JavacOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavacOptions upgradeModulePath(File path) {
return upgradeModulePath(path.getAbsolutePath());
}
/**
* Override location of upgradeable modules
*
* @return this list of options
* @since 2.1
*/
public JavacOptions upgradeModulePath(Path path) {
return upgradeModulePath(path.toFile());
}
/**
* Override location of upgradeable modules
*
* @return this list of options
* @since 2.1
*/
public JavacOptions upgradeModulePath(String path) {
add("--upgrade-module-path");
add(path.getAbsolutePath());
add(path);
return this;
}

View file

@ -9,10 +9,10 @@ import rife.tools.FileUtils;
import rife.tools.StringUtils;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Options for the standard javadoc tool.
@ -178,8 +178,48 @@ public class JavadocOptions extends ArrayList<String> {
* @since 1.5.18
*/
public JavadocOptions extDirs(List<File> dirs) {
return extDirsStrings(dirs.stream().map(File::getAbsolutePath).toList());
}
/**
* Override location of installed extensions
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions extDirs(Path... dirs) {
return extDirsPaths(Arrays.asList(dirs));
}
/**
* Override location of installed extensions
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions extDirsPaths(List<Path> dirs) {
return extDirs(dirs.stream().map(Path::toFile).toList());
}
/**
* Override location of installed extensions
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions extDirs(String... dirs) {
return extDirsStrings(Arrays.asList(dirs));
}
/**
* Override location of installed extensions
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions extDirsStrings(List<String> dirs) {
add("-extdirs");
add(dirs.stream().map(File::getAbsolutePath).collect(Collectors.joining(",")));
add(String.join(",", dirs));
return this;
}
@ -256,8 +296,48 @@ public class JavadocOptions extends ArrayList<String> {
* @since 1.6.3
*/
public JavadocOptions modulePath(List<File> paths) {
return modulePathStrings(paths.stream().map(File::getAbsolutePath).toList());
}
/**
* Specify where to find application modules
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions modulePath(Path... paths) {
return modulePathPaths(Arrays.asList(paths));
}
/**
* Specify where to find application modules
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions modulePathPaths(List<Path> paths) {
return modulePath(paths.stream().map(Path::toFile).toList());
}
/**
* Specify where to find application modules
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions modulePath(String... paths) {
return modulePathStrings(Arrays.asList(paths));
}
/**
* Specify where to find application modules
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions modulePathStrings(List<String> paths) {
add("--module-path");
add(FileUtils.joinPaths(paths.stream().map(File::getAbsolutePath).toList()));
add(FileUtils.joinPaths(paths));
return this;
}
@ -268,8 +348,28 @@ public class JavadocOptions extends ArrayList<String> {
* @since 1.6.3
*/
public JavadocOptions moduleSourcePath(File path) {
return moduleSourcePath(path.getAbsolutePath());
}
/**
* Specify where to find input source files for multiple modules
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions moduleSourcePath(Path path) {
return moduleSourcePath(path.toFile());
}
/**
* Specify where to find input source files for multiple modules
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions moduleSourcePath(String path) {
add("--module-source-path");
add(path.getAbsolutePath());
add(path);
return this;
}
@ -425,9 +525,29 @@ public class JavadocOptions extends ArrayList<String> {
* @return this list of options
* @since 1.5.12
*/
public JavadocOptions addScript(File file) {
public JavadocOptions addScript(File path) {
return addScript(path.getAbsolutePath());
}
/**
* Add a script file to the generated documentation
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions addScript(Path path) {
return addScript(path.toFile());
}
/**
* Add a script file to the generated documentation
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions addScript(String path) {
add("--add-script");
add(file.getAbsolutePath());
add(path);
return this;
}
@ -437,9 +557,29 @@ public class JavadocOptions extends ArrayList<String> {
* @return this list of options
* @since 1.5.12
*/
public JavadocOptions addStylesheet(File file) {
public JavadocOptions addStylesheet(File path) {
return addStylesheet(path.getAbsolutePath());
}
/**
* Add a stylesheet file to the generated documentation
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions addStylesheet(Path path) {
return addStylesheet(path.toFile());
}
/**
* Add a stylesheet file to the generated documentation
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions addStylesheet(String path) {
add("--add-stylesheet");
add(file.getAbsolutePath());
add(path);
return this;
}
@ -578,9 +718,29 @@ public class JavadocOptions extends ArrayList<String> {
* @return this list of options
* @since 1.5.12
*/
public JavadocOptions stylesheet(File file) {
public JavadocOptions stylesheet(File path) {
return stylesheet(path.getAbsolutePath());
}
/**
* File to change style of the generated documentation
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions stylesheet(Path path) {
return stylesheet(path.toFile());
}
/**
* File to change style of the generated documentation
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions stylesheet(String path) {
add("--main-stylesheet");
add(file.getAbsolutePath());
add(path);
return this;
}
@ -735,9 +895,29 @@ public class JavadocOptions extends ArrayList<String> {
* @return this list of options
* @since 1.5.18
*/
public JavadocOptions overview(File htmlFile) {
public JavadocOptions overview(File path) {
return overview(path.getAbsolutePath());
}
/**
* Read overview documentation from HTML file
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions overview(Path path) {
return overview(path.toFile());
}
/**
* Read overview documentation from HTML file
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions overview(String path) {
add("-overview");
add(htmlFile.getAbsolutePath());
add(path);
return this;
}
@ -793,8 +973,28 @@ public class JavadocOptions extends ArrayList<String> {
* @since 1.5.12
*/
public JavadocOptions snippetPath(File path) {
return snippetPath(path.getAbsolutePath());
}
/**
* The path for external snippets
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions snippetPath(Path path) {
return snippetPath(path.toFile());
}
/**
* The path for external snippets
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions snippetPath(String path) {
add("--snippet-path");
add(path.getAbsolutePath());
add(path);
return this;
}
@ -852,8 +1052,28 @@ public class JavadocOptions extends ArrayList<String> {
* @since 1.5.12
*/
public JavadocOptions tagletPath(File path) {
return tagletPath(path.getAbsolutePath());
}
/**
* The path to Taglets
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions tagletPath(Path path) {
return tagletPath(path.toFile());
}
/**
* The path to Taglets
*
* @return this list of options
* @since 2.1
*/
public JavadocOptions tagletPath(String path) {
add("-tagletpath");
add(path.getAbsolutePath());
add(path);
return this;
}

View file

@ -31,16 +31,27 @@ public class RunOperation extends AbstractProcessOperation<RunOperation> {
var args = new ArrayList<String>();
args.add(javaTool());
args.addAll(javaOptions());
if (!classpath().isEmpty()) {
args.add("-cp");
args.add(FileUtils.joinPaths(classpath()));
}
if (!modulePath().isEmpty()) {
args.add("-p");
args.add(FileUtils.joinPaths(modulePath()));
}
if (module() != null && !module().isEmpty()) {
args.add("-m");
args.add(module());
}
else if (mainClass() != null && !mainClass().isEmpty()){
args.add(mainClass());
}
args.addAll(runOptions());
return args;
}
@ -55,7 +66,8 @@ public class RunOperation extends AbstractProcessOperation<RunOperation> {
.javaTool(project.javaTool())
.classpath(project.runClasspath())
.modulePath(project.runModulePath())
.mainClass(project.mainClass());
.mainClass(project.mainClass())
.module(project.module());
if (project.usesRife2Agent()) {
operation.javaOptions().javaAgent(project.getRife2AgentFile());
}

View file

@ -35,7 +35,7 @@ public class TestProject {
assertNull(project.version);
assertThrows(IllegalStateException.class, project::version);
assertNull(project.mainClass);
assertThrows(IllegalStateException.class, project::mainClass);
assertNull(project.module);
assertNotNull(project.repositories);
assertTrue(project.repositories.isEmpty());

View file

@ -33,7 +33,7 @@ public class TestWebProject {
assertNull(project.version);
assertThrows(IllegalStateException.class, project::version);
assertNull(project.mainClass);
assertThrows(IllegalStateException.class, project::mainClass);
assertNull(project.module);
assertNotNull(project.repositories);
assertTrue(project.repositories.isEmpty());

View file

@ -5,12 +5,14 @@
package rife.bld.operations;
import org.junit.jupiter.api.Test;
import rife.bld.NamedFile;
import rife.tools.FileUtils;
import java.io.File;
import java.nio.file.Files;
import java.util.List;
import java.util.function.Function;
import java.util.jar.Attributes;
import static org.junit.jupiter.api.Assertions.*;
@ -26,6 +28,7 @@ public class TestRunOperation {
assertTrue(operation.javaOptions().isEmpty());
assertTrue(operation.classpath().isEmpty());
assertNull(operation.mainClass());
assertNull(operation.module());
assertTrue(operation.runOptions().isEmpty());
assertNull(operation.outputProcessor());
assertNull(operation.errorProcessor());
@ -45,6 +48,7 @@ public class TestRunOperation {
var run_option1 = "runOption1";
var run_option2 = "runOption2";
var main_class = "mainClass";
var module = "module";
Function<String, Boolean> run_output_consumer = (String) -> true;
Function<String, Boolean> run_error_consumer = (String) -> true;
@ -55,6 +59,7 @@ public class TestRunOperation {
.javaOptions(List.of(run_java_option1, run_java_option2))
.classpath(List.of(run_classpath1, run_classpath2))
.mainClass(main_class)
.module(module)
.runOptions(List.of(run_option1, run_option2))
.outputProcessor(run_output_consumer)
.errorProcessor(run_error_consumer);
@ -66,6 +71,7 @@ public class TestRunOperation {
assertTrue(operation1.classpath().contains(run_classpath1));
assertTrue(operation1.classpath().contains(run_classpath2));
assertEquals(main_class, operation1.mainClass());
assertEquals(module, operation1.module());
assertTrue(operation1.runOptions().contains(run_option1));
assertTrue(operation1.runOptions().contains(run_option2));
assertSame(run_output_consumer, operation1.outputProcessor());
@ -79,6 +85,7 @@ public class TestRunOperation {
operation2.classpath().add(run_classpath1);
operation2.classpath().add(run_classpath2);
operation2.mainClass(main_class);
operation2.module(module);
operation2.runOptions().add(run_option1);
operation2.runOptions().add(run_option2);
operation2.outputProcessor(run_output_consumer);
@ -91,6 +98,7 @@ public class TestRunOperation {
assertTrue(operation2.classpath().contains(run_classpath1));
assertTrue(operation2.classpath().contains(run_classpath2));
assertEquals(main_class, operation2.mainClass());
assertEquals(module, operation2.module());
assertTrue(operation2.runOptions().contains(run_option1));
assertTrue(operation2.runOptions().contains(run_option2));
assertSame(run_output_consumer, operation2.outputProcessor());
@ -155,6 +163,71 @@ public class TestRunOperation {
}
}
@Test
void testExecuteModule()
throws Exception {
var tmp = Files.createTempDirectory("test").toFile();
try {
var pkg = new File(tmp, "pkg");
pkg.mkdirs();
var source_file1 = new File(pkg, "Source1.java");
var source_file2 = new File(pkg, "module-info.java");
FileUtils.writeString("""
package pkg;
public class Source1 {
public final String name_;
public Source1() {
name_ = "source1";
}
public static void main(String[] arguments)
throws Exception {
System.out.print(new Source1().name_);
}
}
""", source_file1);
FileUtils.writeString("""
module pkg {
requires java.desktop;
}
""", source_file2);
var build_main = new File(tmp, "buildMain");
var compile_operation = new CompileOperation()
.buildMainDirectory(build_main)
.compileMainClasspath(List.of(build_main.getAbsolutePath()))
.mainSourceFiles(List.of(source_file1, source_file2));
compile_operation.execute();
assertTrue(compile_operation.diagnostics().isEmpty());
var destination_dir = new File(tmp, "destination");
var destination_name = "pkg.jar";
new JarOperation()
.sourceDirectories(List.of(build_main))
.destinationDirectory(destination_dir)
.destinationFileName(destination_name)
.manifestAttribute(Attributes.Name.MAIN_CLASS, "pkg.Source1")
.execute();
var output = new StringBuilder();
var run_operation = new RunOperation()
.module("pkg/pkg.Source1")
.modulePath(new File(destination_dir, destination_name).getAbsolutePath())
.outputProcessor(s -> {
output.append(s);
return true;
});
run_operation.execute();
assertEquals("source1", output.toString());
} finally {
FileUtils.deleteDirectory(tmp);
}
}
@Test
void testFromProject()
throws Exception {