2
0
Fork 0
mirror of https://github.com/ethauvin/rife2.git synced 2025-05-02 11:28:12 -07:00

Added precompile operation tests and javadocs.

Refactoring to all operations.
This commit is contained in:
Geert Bevin 2023-03-16 18:32:04 -04:00
parent 61ce1f795e
commit d3bdbdc533
19 changed files with 328 additions and 166 deletions

View file

@ -30,8 +30,25 @@ public class DependencyScopes extends LinkedHashMap<Scope, DependencySet> {
* @since 1.5 * @since 1.5
*/ */
public DependencyScopes(DependencyScopes other) { public DependencyScopes(DependencyScopes other) {
for (var dep : other.entrySet()) { for (var entry : other.entrySet()) {
put(dep.getKey(), new DependencySet(dep.getValue())); put(entry.getKey(), new DependencySet(entry.getValue()));
}
}
/**
* Includes all the dependencies from another dependency scope map.
*
* @param other the other map to include dependencies from
* @since 1.5
*/
public void include(DependencyScopes other) {
for (var entry : other.entrySet()) {
var dependencies = get(entry.getKey());
if (dependencies == null) {
dependencies = new DependencySet();
put(entry.getKey(), dependencies);
}
dependencies.addAll(entry.getValue());
} }
} }

View file

@ -160,26 +160,6 @@ public class Project extends BuildExecutor {
return StringUtils.join(paths, File.pathSeparator); return StringUtils.join(paths, File.pathSeparator);
} }
@SafeVarargs
public static List<String> combineToAbsolutePaths(List<File>... files) {
var result = new ArrayList<String>();
for (var list : files) {
for (var file : list) {
result.add(file.getAbsolutePath());
}
}
return result;
}
@SafeVarargs
public static <E> List<E> combineLists(List<E>... lists) {
var result = new ArrayList<E>();
for (var list : lists) {
result.addAll(list);
}
return result;
}
/* /*
* Project directories * Project directories
*/ */
@ -454,24 +434,24 @@ public class Project extends BuildExecutor {
} }
public List<String> compileMainClasspath() { public List<String> compileMainClasspath() {
return Project.combineToAbsolutePaths(compileClasspathJars()); return FileUtils.combineToAbsolutePaths(compileClasspathJars());
} }
public List<String> compileTestClasspath() { public List<String> compileTestClasspath() {
var paths = Project.combineToAbsolutePaths(compileClasspathJars(), testClasspathJars()); var paths = FileUtils.combineToAbsolutePaths(compileClasspathJars(), testClasspathJars());
paths.add(buildMainDirectory().getAbsolutePath()); paths.add(buildMainDirectory().getAbsolutePath());
return paths; return paths;
} }
public List<String> runClasspath() { public List<String> runClasspath() {
var paths = Project.combineToAbsolutePaths(compileClasspathJars(), runtimeClasspathJars(), standaloneClasspathJars()); var paths = FileUtils.combineToAbsolutePaths(compileClasspathJars(), runtimeClasspathJars(), standaloneClasspathJars());
paths.add(srcMainResourcesDirectory().getAbsolutePath()); paths.add(srcMainResourcesDirectory().getAbsolutePath());
paths.add(buildMainDirectory().getAbsolutePath()); paths.add(buildMainDirectory().getAbsolutePath());
return paths; return paths;
} }
public List<String> testClasspath() { public List<String> testClasspath() {
var paths = Project.combineToAbsolutePaths(compileClasspathJars(), runtimeClasspathJars(), standaloneClasspathJars(), testClasspathJars()); var paths = FileUtils.combineToAbsolutePaths(compileClasspathJars(), runtimeClasspathJars(), standaloneClasspathJars(), testClasspathJars());
paths.add(srcMainResourcesDirectory().getAbsolutePath()); paths.add(srcMainResourcesDirectory().getAbsolutePath());
paths.add(buildMainDirectory().getAbsolutePath()); paths.add(buildMainDirectory().getAbsolutePath());
paths.add(buildTestDirectory().getAbsolutePath()); paths.add(buildTestDirectory().getAbsolutePath());

View file

@ -18,7 +18,7 @@ import java.util.*;
* @since 1.5 * @since 1.5
*/ */
public class CleanOperation { public class CleanOperation {
private List<File> directories_ = new ArrayList<>(); private final List<File> directories_ = new ArrayList<>();
/** /**
* Performs the clean operation. * Performs the clean operation.
@ -69,7 +69,7 @@ public class CleanOperation {
* @since 1.5 * @since 1.5
*/ */
public CleanOperation directories(List<File> directories) { public CleanOperation directories(List<File> directories) {
directories_ = new ArrayList<>(directories); directories_.addAll(directories);
return this; return this;
} }

View file

@ -20,11 +20,11 @@ import java.util.*;
public class CompileOperation { public class CompileOperation {
private File buildMainDirectory_; private File buildMainDirectory_;
private File buildTestDirectory_; private File buildTestDirectory_;
private List<String> compileMainClasspath_ = new ArrayList<>(); private final List<String> compileMainClasspath_ = new ArrayList<>();
private List<String> compileTestClasspath_ = new ArrayList<>(); private final List<String> compileTestClasspath_ = new ArrayList<>();
private List<File> mainSourceFiles_ = new ArrayList<>(); private final List<File> mainSourceFiles_ = new ArrayList<>();
private List<File> testSourceFiles_ = new ArrayList<>(); private final List<File> testSourceFiles_ = new ArrayList<>();
private List<String> compileOptions_ = new ArrayList<>(); private final List<String> compileOptions_ = new ArrayList<>();
private final List<Diagnostic<? extends JavaFileObject>> diagnostics_ = new ArrayList<>(); private final List<Diagnostic<? extends JavaFileObject>> diagnostics_ = new ArrayList<>();
/** /**
@ -176,7 +176,7 @@ public class CompileOperation {
* @since 1.5 * @since 1.5
*/ */
public CompileOperation compileMainClasspath(List<String> classpath) { public CompileOperation compileMainClasspath(List<String> classpath) {
compileMainClasspath_ = new ArrayList<>(classpath); compileMainClasspath_.addAll(classpath);
return this; return this;
} }
@ -190,7 +190,7 @@ public class CompileOperation {
* @since 1.5 * @since 1.5
*/ */
public CompileOperation compileTestClasspath(List<String> classpath) { public CompileOperation compileTestClasspath(List<String> classpath) {
compileTestClasspath_ = new ArrayList<>(classpath); compileTestClasspath_.addAll(classpath);
return this; return this;
} }
@ -204,7 +204,7 @@ public class CompileOperation {
* @since 1.5 * @since 1.5
*/ */
public CompileOperation mainSourceFiles(List<File> files) { public CompileOperation mainSourceFiles(List<File> files) {
mainSourceFiles_ = new ArrayList<>(files); mainSourceFiles_.addAll(files);
return this; return this;
} }
@ -218,7 +218,7 @@ public class CompileOperation {
* @since 1.5 * @since 1.5
*/ */
public CompileOperation testSourceFiles(List<File> files) { public CompileOperation testSourceFiles(List<File> files) {
testSourceFiles_ = new ArrayList<>(files); testSourceFiles_.addAll(files);
return this; return this;
} }
@ -232,7 +232,7 @@ public class CompileOperation {
* @since 1.5 * @since 1.5
*/ */
public CompileOperation compileOptions(List<String> options) { public CompileOperation compileOptions(List<String> options) {
compileOptions_ = new ArrayList<>(options); compileOptions_.addAll(options);
return this; return this;
} }

View file

@ -22,8 +22,8 @@ import java.util.List;
* @since 1.5 * @since 1.5
*/ */
public class DownloadOperation { public class DownloadOperation {
private List<Repository> repositories_ = new ArrayList<>(); private final List<Repository> repositories_ = new ArrayList<>();
private DependencyScopes dependencies_ = new DependencyScopes(); private final DependencyScopes dependencies_ = new DependencyScopes();
private File libCompileDirectory_; private File libCompileDirectory_;
private File libRuntimeDirectory_; private File libRuntimeDirectory_;
private File libStandaloneDirectory_; private File libStandaloneDirectory_;
@ -140,7 +140,7 @@ public class DownloadOperation {
* @since 1.5 * @since 1.5
*/ */
public DownloadOperation repositories(List<Repository> repositories) { public DownloadOperation repositories(List<Repository> repositories) {
repositories_ = new ArrayList<>(repositories); repositories_.addAll(repositories);
return this; return this;
} }
@ -152,7 +152,7 @@ public class DownloadOperation {
* @since 1.5 * @since 1.5
*/ */
public DownloadOperation dependencies(DependencyScopes dependencies) { public DownloadOperation dependencies(DependencyScopes dependencies) {
dependencies_ = new DependencyScopes(dependencies); dependencies_.include(dependencies);
return this; return this;
} }

View file

@ -20,13 +20,13 @@ import java.util.regex.Pattern;
* @since 1.5 * @since 1.5
*/ */
public class JarOperation { public class JarOperation {
private Map<Attributes.Name, Object> manifestAttributes_ = new HashMap<>(); private final Map<Attributes.Name, Object> manifestAttributes_ = new HashMap<>();
private List<File> sourceDirectories_ = new ArrayList<>(); private final List<File> sourceDirectories_ = new ArrayList<>();
private List<NamedFile> sourceFiles_ = new ArrayList<>(); private final List<NamedFile> sourceFiles_ = new ArrayList<>();
private File destinationDirectory_; private File destinationDirectory_;
private String destinationFileName_; private String destinationFileName_;
private List<Pattern> included_ = new ArrayList<>(); private final List<Pattern> included_ = new ArrayList<>();
private List<Pattern> excluded_ = new ArrayList<>(); private final List<Pattern> excluded_ = new ArrayList<>();
private final byte[] buffer_ = new byte[1024]; private final byte[] buffer_ = new byte[1024];
@ -135,7 +135,7 @@ public class JarOperation {
* @since 1.5 * @since 1.5
*/ */
public JarOperation manifestAttributes(Map<Attributes.Name, Object> attributes) { public JarOperation manifestAttributes(Map<Attributes.Name, Object> attributes) {
manifestAttributes_ = new HashMap<>(attributes); manifestAttributes_.putAll(attributes);
return this; return this;
} }
@ -147,7 +147,7 @@ public class JarOperation {
* @since 1.5 * @since 1.5
*/ */
public JarOperation sourceDirectories(List<File> sources) { public JarOperation sourceDirectories(List<File> sources) {
sourceDirectories_ = new ArrayList<>(sources); sourceDirectories_.addAll(sources);
return this; return this;
} }
@ -159,7 +159,7 @@ public class JarOperation {
* @since 1.5 * @since 1.5
*/ */
public JarOperation sourceFiles(List<NamedFile> sources) { public JarOperation sourceFiles(List<NamedFile> sources) {
sourceFiles_ = new ArrayList<>(sources); sourceFiles_.addAll(sources);
return this; return this;
} }
@ -196,7 +196,7 @@ public class JarOperation {
* @since 1.5 * @since 1.5
*/ */
public JarOperation included(List<Pattern> included) { public JarOperation included(List<Pattern> included) {
included_ = new ArrayList<>(included); included_.addAll(included);
return this; return this;
} }
@ -209,7 +209,7 @@ public class JarOperation {
* @since 1.5 * @since 1.5
*/ */
public JarOperation excluded(List<Pattern> excluded) { public JarOperation excluded(List<Pattern> excluded) {
excluded_ = new ArrayList<>(excluded); excluded_.addAll(excluded);
return this; return this;
} }

View file

@ -7,23 +7,41 @@ package rife.bld.operations;
import rife.bld.Project; import rife.bld.Project;
import rife.template.TemplateDeployer; import rife.template.TemplateDeployer;
import rife.template.TemplateFactory; import rife.template.TemplateFactory;
import rife.tools.FileUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Pre-compiles RIFE2 templates.
*
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
* @since 1.5
*/
public class PrecompileOperation { public class PrecompileOperation {
private List<TemplateType> precompiledTemplateTypes_ = new ArrayList<>(); private final List<TemplateType> templateTypes_ = new ArrayList<>();
private File srcMainResourcesTemplatesDirectory_; private final List<File> sourceDirectories_ = new ArrayList<>();
private File buildTemplatesDirectory_; private File destinationDirectory_;
/**
* Performs the precompile operation.
*
* @since 1.5
*/
public void execute() { public void execute() {
executeCreateTemplateDeployer().execute(); executeCreateTemplateDeployer().execute();
} }
/**
* Part of the {@link #execute} operation, gets the template factories for
* the registered template types.
*
* @since 1.5
*/
public List<TemplateFactory> executeGetTemplateFactories() { public List<TemplateFactory> executeGetTemplateFactories() {
var template_factories = new ArrayList<TemplateFactory>(); var template_factories = new ArrayList<TemplateFactory>();
for (var type : precompiledTemplateTypes()) { for (var type : templateTypes()) {
var factory = TemplateFactory.getFactory(type.identifier()); var factory = TemplateFactory.getFactory(type.identifier());
if (factory == null) { if (factory == null) {
System.err.println("ERROR: unknown template type '" + type.identifier() + "'/"); System.err.println("ERROR: unknown template type '" + type.identifier() + "'/");
@ -35,44 +53,99 @@ public class PrecompileOperation {
return template_factories; return template_factories;
} }
/**
* Part of the {@link #execute} operation, creates the {@code TemplateDeployer}
* that will precompile the templates.
*
* @since 1.5
*/
public TemplateDeployer executeCreateTemplateDeployer() { public TemplateDeployer executeCreateTemplateDeployer() {
return new TemplateDeployer() return new TemplateDeployer()
.verbose(true) .verbose(true)
.directoryPaths(List.of(srcMainResourcesTemplatesDirectory().getAbsolutePath())) .directoryPaths(FileUtils.combineToAbsolutePaths(sourceDirectories()))
.generationPath(buildTemplatesDirectory().getAbsolutePath()) .generationPath(destinationDirectory().getAbsolutePath())
.templateFactories(executeGetTemplateFactories()); .templateFactories(executeGetTemplateFactories());
} }
/**
* Configures a precompile operation from a {@link Project}.
*
* @param project the project to configure the precompile operation from
* @since 1.5
*/
public PrecompileOperation fromProject(Project project) { public PrecompileOperation fromProject(Project project) {
return precompiledTemplateTypes(project.precompiledTemplateTypes()) return templateTypes(project.precompiledTemplateTypes())
.srcMainResourcesTemplatesDirectory(project.srcMainResourcesTemplatesDirectory()) .sourceDirectories(List.of(project.srcMainResourcesTemplatesDirectory()))
.buildTemplatesDirectory(project.buildTemplatesDirectory()); .destinationDirectory(project.buildTemplatesDirectory());
} }
public PrecompileOperation precompiledTemplateTypes(List<TemplateType> types) { /**
precompiledTemplateTypes_ = new ArrayList<>(types); * Provides the template types that will be pre-compiled.
*
* @param types the pre-compiled template types
* @return this operation instance
* @since 1.5
*/
public PrecompileOperation templateTypes(List<TemplateType> types) {
templateTypes_.addAll(types);
return this; return this;
} }
public PrecompileOperation srcMainResourcesTemplatesDirectory(File directory) { /**
srcMainResourcesTemplatesDirectory_ = directory; * Provides the source directories that will be used for the template pre-compilation.
*
* @param sources the source directories
* @return this operation instance
* @since 1.5
*/
public PrecompileOperation sourceDirectories(List<File> sources) {
sourceDirectories_.addAll(sources);
return this; return this;
} }
public PrecompileOperation buildTemplatesDirectory(File directory) { /**
buildTemplatesDirectory_ = directory; * Provides the destination directory in which the pre-compiled templates will be stored.
*
* @param directory the pre-compilation destination directory
* @return this operation instance
* @since 1.5
*/
public PrecompileOperation destinationDirectory(File directory) {
destinationDirectory_ = directory;
return this; return this;
} }
public List<TemplateType> precompiledTemplateTypes() { /**
return precompiledTemplateTypes_; * Retrieves the template types that will be pre-compiled.
* <p>
* This is a modifiable list that can be retrieved and changed.
*
* @return the pre-compiled template types
* @since 1.5
*/
public List<TemplateType> templateTypes() {
return templateTypes_;
} }
public File srcMainResourcesTemplatesDirectory() { /**
return srcMainResourcesTemplatesDirectory_; * Retrieves the source directories that will be used for the template pre-compilation.
* <p>
* This is a modifiable list that can be retrieved and changed.
*
* @return the source directories
* @since 1.5
*/
public List<File> sourceDirectories() {
return sourceDirectories_;
} }
public File buildTemplatesDirectory() { /**
return buildTemplatesDirectory_; * Provides the destination directory in which the pre-compiled templates will be stored.
*
* @return the pre-compilation destination directory
* @since 1.5
*/
public File destinationDirectory() {
return destinationDirectory_;
} }
} }

View file

@ -16,8 +16,8 @@ import java.util.function.Consumer;
public class RunOperation { public class RunOperation {
private File workDirectory_ = new File(System.getProperty("user.dir")); private File workDirectory_ = new File(System.getProperty("user.dir"));
private String javaTool_; private String javaTool_;
private List<String> runJavaOptions_ = new ArrayList<>(); private final List<String> runJavaOptions_ = new ArrayList<>();
private List<String> runClasspath_ = new ArrayList<>(); private final List<String> runClasspath_ = new ArrayList<>();
private String mainClass_; private String mainClass_;
private Consumer<String> runOutputConsumer_; private Consumer<String> runOutputConsumer_;
private Consumer<String> runErrorConsumer_; private Consumer<String> runErrorConsumer_;
@ -97,12 +97,12 @@ public class RunOperation {
} }
public RunOperation runJavaOptions(List<String> options) { public RunOperation runJavaOptions(List<String> options) {
runJavaOptions_ = new ArrayList<>(options); runJavaOptions_.addAll(options);
return this; return this;
} }
public RunOperation runClasspath(List<String> classpath) { public RunOperation runClasspath(List<String> classpath) {
runClasspath_ = new ArrayList<>(classpath); runClasspath_.addAll(classpath);
return this; return this;
} }

View file

@ -13,10 +13,10 @@ import java.util.function.Consumer;
public class TestOperation { public class TestOperation {
private String javaTool_; private String javaTool_;
private List<String> testJavaOptions_ = new ArrayList<>(); private final List<String> testJavaOptions_ = new ArrayList<>();
private List<String> testClasspath_ = new ArrayList<>(); private final List<String> testClasspath_ = new ArrayList<>();
private String testToolMainClass_; private String testToolMainClass_;
private List<String> testToolOptions_ = new ArrayList<>(); private final List<String> testToolOptions_ = new ArrayList<>();
private Consumer<String> testOutputConsumer_; private Consumer<String> testOutputConsumer_;
private Consumer<String> testErrorConsumer_; private Consumer<String> testErrorConsumer_;
private Process process_; private Process process_;
@ -82,12 +82,12 @@ public class TestOperation {
} }
public TestOperation testJavaOptions(List<String> options) { public TestOperation testJavaOptions(List<String> options) {
testJavaOptions_ = new ArrayList<>(options); testJavaOptions_.addAll(options);
return this; return this;
} }
public TestOperation testClasspath(List<String> classpath) { public TestOperation testClasspath(List<String> classpath) {
testClasspath_ = new ArrayList<>(classpath); testClasspath_.addAll(classpath);
return this; return this;
} }
@ -97,7 +97,7 @@ public class TestOperation {
} }
public TestOperation testToolOptions(List<String> options) { public TestOperation testToolOptions(List<String> options) {
testToolOptions_ = new ArrayList<>(options); testToolOptions_.addAll(options);
return this; return this;
} }

View file

@ -14,8 +14,8 @@ import java.util.*;
import java.util.jar.Attributes; import java.util.jar.Attributes;
public class UberJarOperation { public class UberJarOperation {
private List<File> jarSourceFiles_ = new ArrayList<>(); private final List<File> jarSourceFiles_ = new ArrayList<>();
private List<NamedFile> resourceSourceDirectories_ = new ArrayList<>(); private final List<NamedFile> resourceSourceDirectories_ = new ArrayList<>();
private File destinationDirectory_; private File destinationDirectory_;
private String destinationFileName_; private String destinationFileName_;
private String mainClass_; private String mainClass_;
@ -77,7 +77,7 @@ public class UberJarOperation {
} }
public UberJarOperation jarSourceFiles(List<File> files) { public UberJarOperation jarSourceFiles(List<File> files) {
jarSourceFiles_ = new ArrayList<>(files); jarSourceFiles_.addAll(files);
return this; return this;
} }
@ -86,7 +86,7 @@ public class UberJarOperation {
} }
public UberJarOperation resourceSourceDirectories(List<NamedFile> directories) { public UberJarOperation resourceSourceDirectories(List<NamedFile> directories) {
resourceSourceDirectories_ = new ArrayList<>(directories); resourceSourceDirectories_.addAll(directories);
return this; return this;
} }

View file

@ -13,9 +13,9 @@ import java.nio.file.*;
import java.util.*; import java.util.*;
public class WarOperation { public class WarOperation {
private List<File> libSourceDirectories_ = new ArrayList<>(); private final List<File> libSourceDirectories_ = new ArrayList<>();
private List<File> classesSourceDirectories_ = new ArrayList<>(); private final List<File> classesSourceDirectories_ = new ArrayList<>();
private List<NamedFile> jarSourceFiles_ = new ArrayList<>(); private final List<NamedFile> jarSourceFiles_ = new ArrayList<>();
private File webappDirectory_; private File webappDirectory_;
private File webXmlFile_; private File webXmlFile_;
private File destinationDirectory_; private File destinationDirectory_;
@ -105,7 +105,7 @@ public class WarOperation {
} }
public WarOperation libSourceDirectories(List<File> sources) { public WarOperation libSourceDirectories(List<File> sources) {
libSourceDirectories_ = new ArrayList<>(sources); libSourceDirectories_.addAll(sources);
return this; return this;
} }
@ -114,7 +114,7 @@ public class WarOperation {
} }
public WarOperation classesSourceDirectories(List<File> sources) { public WarOperation classesSourceDirectories(List<File> sources) {
classesSourceDirectories_ = new ArrayList<>(sources); classesSourceDirectories_.addAll(sources);
return this; return this;
} }
@ -123,7 +123,7 @@ public class WarOperation {
} }
public WarOperation jarSourceFiles(List<NamedFile> files) { public WarOperation jarSourceFiles(List<NamedFile> files) {
jarSourceFiles_ = new ArrayList<>(files); jarSourceFiles_.addAll(files);
return this; return this;
} }

View file

@ -8,13 +8,13 @@ import rife.tools.exceptions.FileUtilsErrorException;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.net.URLConnection;
import java.nio.file.*; import java.nio.file.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@ -593,4 +593,24 @@ public final class FileUtils {
return ext; return ext;
} }
@SafeVarargs
public static List<String> combineToAbsolutePaths(List<File>... files) {
var result = new ArrayList<String>();
for (var list : files) {
for (var file : list) {
result.add(file.getAbsolutePath());
}
}
return result;
}
public static String generateDirectoryListing(File directory)
throws IOException {
return Files.walk(Path.of(directory.getAbsolutePath()))
.map(path -> path.toAbsolutePath().toString().substring(directory.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining(System.lineSeparator()));
}
} }

View file

@ -10,9 +10,7 @@ import rife.tools.FileUtils;
import java.io.File; import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@ -117,11 +115,7 @@ public class TestCleanOperation {
/src/main/resources/templates /src/main/resources/templates
/src/test /src/test
/src/test/java""", /src/test/java""",
Files.walk(Path.of(tmp.getAbsolutePath())) FileUtils.generateDirectoryListing(tmp));
.map(path -> path.toAbsolutePath().toString().substring(tmp.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining("\n")));
new CleanOperation().fromProject(project).execute(); new CleanOperation().fromProject(project).execute();
assertEquals(""" assertEquals("""
@ -141,11 +135,7 @@ public class TestCleanOperation {
/src/main/resources/templates /src/main/resources/templates
/src/test /src/test
/src/test/java""", /src/test/java""",
Files.walk(Path.of(tmp.getAbsolutePath())) FileUtils.generateDirectoryListing(tmp));
.map(path -> path.toAbsolutePath().toString().substring(tmp.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining("\n")));
} finally { } finally {
FileUtils.deleteDirectory(tmp); FileUtils.deleteDirectory(tmp);
} }

View file

@ -5,17 +5,13 @@
package rife.bld.operations; package rife.bld.operations;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import rife.bld.Project;
import rife.bld.WebProject;
import rife.tools.FileUtils; import rife.tools.FileUtils;
import javax.tools.DiagnosticCollector; import javax.tools.DiagnosticCollector;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import java.io.File; import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;

View file

@ -6,17 +6,10 @@ package rife.bld.operations;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import rife.tools.FileUtils; import rife.tools.FileUtils;
import rife.tools.exceptions.FileUtilsErrorException;
import javax.tools.DiagnosticCollector; import javax.tools.DiagnosticCollector;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import java.io.File;
import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@ -120,11 +113,7 @@ public class TestCreateBlankOperation {
/myapp/src/test/java/com /myapp/src/test/java/com
/myapp/src/test/java/com/example /myapp/src/test/java/com/example
/myapp/src/test/java/com/example/MyappTest.java""", /myapp/src/test/java/com/example/MyappTest.java""",
Files.walk(Path.of(tmp.getAbsolutePath())) FileUtils.generateDirectoryListing(tmp));
.map(path -> path.toAbsolutePath().toString().substring(tmp.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining("\n")));
var compile_operation = new CompileOperation().fromProject(create_operation.project()); var compile_operation = new CompileOperation().fromProject(create_operation.project());
compile_operation.execute(); compile_operation.execute();
@ -188,11 +177,7 @@ public class TestCreateBlankOperation {
/myapp/src/test/java/com /myapp/src/test/java/com
/myapp/src/test/java/com/example /myapp/src/test/java/com/example
/myapp/src/test/java/com/example/MyappTest.java""", /myapp/src/test/java/com/example/MyappTest.java""",
Files.walk(Path.of(tmp.getAbsolutePath())) FileUtils.generateDirectoryListing(tmp));
.map(path -> path.toAbsolutePath().toString().substring(tmp.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining("\n")));
final var run_operation = new RunOperation().fromProject(create_operation.project()); final var run_operation = new RunOperation().fromProject(create_operation.project());
final String[] check_result = new String[1]; final String[] check_result = new String[1];
@ -257,11 +242,7 @@ public class TestCreateBlankOperation {
/yourthing/src/test/java/org /yourthing/src/test/java/org
/yourthing/src/test/java/org/stuff /yourthing/src/test/java/org/stuff
/yourthing/src/test/java/org/stuff/YourthingTest.java""", /yourthing/src/test/java/org/stuff/YourthingTest.java""",
Files.walk(Path.of(tmp.getAbsolutePath())) FileUtils.generateDirectoryListing(tmp));
.map(path -> path.toAbsolutePath().toString().substring(tmp.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining("\n")));
var compile_operation = new CompileOperation() { var compile_operation = new CompileOperation() {
public void executeProcessDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics) { public void executeProcessDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics) {

View file

@ -12,9 +12,8 @@ import javax.tools.DiagnosticCollector;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
import java.net.URL; import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.util.concurrent.Executors;
import java.util.concurrent.*; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@ -137,11 +136,7 @@ public class TestCreateRife2Operation {
/myapp/src/test/java/com /myapp/src/test/java/com
/myapp/src/test/java/com/example /myapp/src/test/java/com/example
/myapp/src/test/java/com/example/MyappTest.java""", /myapp/src/test/java/com/example/MyappTest.java""",
Files.walk(Path.of(tmp.getAbsolutePath())) FileUtils.generateDirectoryListing(tmp));
.map(path -> path.toAbsolutePath().toString().substring(tmp.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining("\n")));
var compile_operation = new CompileOperation().fromProject(create_operation.project()); var compile_operation = new CompileOperation().fromProject(create_operation.project());
compile_operation.execute(); compile_operation.execute();
@ -225,11 +220,7 @@ public class TestCreateRife2Operation {
/myapp/src/test/java/com /myapp/src/test/java/com
/myapp/src/test/java/com/example /myapp/src/test/java/com/example
/myapp/src/test/java/com/example/MyappTest.java""", /myapp/src/test/java/com/example/MyappTest.java""",
Files.walk(Path.of(tmp.getAbsolutePath())) FileUtils.generateDirectoryListing(tmp));
.map(path -> path.toAbsolutePath().toString().substring(tmp.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining("\n")));
final var run_operation = new RunOperation().fromProject(create_operation.project()); final var run_operation = new RunOperation().fromProject(create_operation.project());
final var executor = Executors.newSingleThreadScheduledExecutor(); final var executor = Executors.newSingleThreadScheduledExecutor();
@ -311,11 +302,7 @@ public class TestCreateRife2Operation {
/yourthing/src/test/java/org /yourthing/src/test/java/org
/yourthing/src/test/java/org/stuff /yourthing/src/test/java/org/stuff
/yourthing/src/test/java/org/stuff/YourthingTest.java""", /yourthing/src/test/java/org/stuff/YourthingTest.java""",
Files.walk(Path.of(tmp.getAbsolutePath())) FileUtils.generateDirectoryListing(tmp));
.map(path -> path.toAbsolutePath().toString().substring(tmp.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining("\n")));
var compile_operation = new CompileOperation() { var compile_operation = new CompileOperation() {
public void executeProcessDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics) { public void executeProcessDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics) {

View file

@ -5,15 +5,14 @@
package rife.bld.operations; package rife.bld.operations;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import rife.bld.*; import rife.bld.DependencyScopes;
import rife.bld.WebProject;
import rife.bld.dependencies.*; import rife.bld.dependencies.*;
import rife.tools.FileUtils; import rife.tools.FileUtils;
import java.io.File; import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@ -121,11 +120,7 @@ public class TestDownloadOperation {
/dir4/httpcore5-5.2.jar /dir4/httpcore5-5.2.jar
/dir4/httpcore5-h2-5.2.jar /dir4/httpcore5-h2-5.2.jar
/dir4/slf4j-api-1.7.36.jar""", /dir4/slf4j-api-1.7.36.jar""",
Files.walk(Path.of(tmp.getAbsolutePath())) FileUtils.generateDirectoryListing(tmp));
.map(path -> path.toAbsolutePath().toString().substring(tmp.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining("\n")));
} finally { } finally {
FileUtils.deleteDirectory(tmp); FileUtils.deleteDirectory(tmp);
} }
@ -179,11 +174,7 @@ public class TestDownloadOperation {
/src/main/resources/templates /src/main/resources/templates
/src/test /src/test
/src/test/java""", /src/test/java""",
Files.walk(Path.of(tmp.getAbsolutePath())) FileUtils.generateDirectoryListing(tmp));
.map(path -> path.toAbsolutePath().toString().substring(tmp.getAbsolutePath().length()))
.filter(s -> !s.isEmpty())
.sorted()
.collect(Collectors.joining("\n")));
} finally { } finally {
FileUtils.deleteDirectory(tmp); FileUtils.deleteDirectory(tmp);
} }

View file

@ -10,8 +10,10 @@ import rife.tools.FileUtils;
import java.io.File; import java.io.File;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.*; import java.util.List;
import java.util.jar.*; import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@ -151,7 +153,6 @@ public class TestJarOperation {
} }
} }
@Test @Test
void testFromProject() void testFromProject()
throws Exception { throws Exception {

View file

@ -0,0 +1,126 @@
/*
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.operations;
import org.junit.jupiter.api.Test;
import rife.tools.FileUtils;
import java.io.File;
import java.nio.file.Files;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class TestPrecompileOperation {
@Test
void testInstantiation() {
var operation = new PrecompileOperation();
assertTrue(operation.templateTypes().isEmpty());
assertTrue(operation.sourceDirectories().isEmpty());
assertNull(operation.destinationDirectory());
}
@Test
void testPopulation() {
var source_directory1 = new File("sourceDirectory1");
var source_directory2 = new File("sourceDirectory2");
var destination_directory = new File("destinationDirectory");
var operation1 = new PrecompileOperation()
.templateTypes(List.of(TemplateType.HTML, TemplateType.JSON))
.sourceDirectories(List.of(source_directory1, source_directory2))
.destinationDirectory(destination_directory);
assertTrue(operation1.templateTypes().contains(TemplateType.HTML));
assertTrue(operation1.templateTypes().contains(TemplateType.JSON));
assertTrue(operation1.sourceDirectories().contains(source_directory1));
assertTrue(operation1.sourceDirectories().contains(source_directory2));
assertEquals(destination_directory, operation1.destinationDirectory());
var operation2 = new PrecompileOperation()
.destinationDirectory(destination_directory);
operation2.templateTypes().add(TemplateType.HTML);
operation2.templateTypes().add(TemplateType.JSON);
operation2.sourceDirectories().add(source_directory1);
operation2.sourceDirectories().add(source_directory2);
assertTrue(operation2.templateTypes().contains(TemplateType.HTML));
assertTrue(operation2.templateTypes().contains(TemplateType.JSON));
assertTrue(operation2.sourceDirectories().contains(source_directory1));
assertTrue(operation2.sourceDirectories().contains(source_directory2));
assertEquals(destination_directory, operation2.destinationDirectory());
}
@Test
void testExecute()
throws Exception {
var tmp = Files.createTempDirectory("test").toFile();
try {
var source1 = new File(tmp, "source1");
var source2 = new File(tmp, "source2");
var destination = new File(tmp, "destination");
source1.mkdirs();
source2.mkdirs();
FileUtils.writeString("""
<p><!--v test1a/--></p>
""", new File(source1, "source1a.html"));
FileUtils.writeString("""
{
"test1b": "{{v test1b/}}"
}
""", new File(source1, "source1b.json"));
FileUtils.writeString("""
<div><!--v test2/--></div>
""", new File(source2, "source2.html"));
var precompile_operation = new PrecompileOperation()
.templateTypes(List.of(TemplateType.HTML, TemplateType.JSON))
.sourceDirectories(List.of(source1, source2))
.destinationDirectory(destination);
precompile_operation.execute();
assertEquals("""
/rife
/rife/template
/rife/template/html
/rife/template/html/source1a.class
/rife/template/html/source2.class
/rife/template/json
/rife/template/json/source1b.class""",
FileUtils.generateDirectoryListing(destination));
} finally {
FileUtils.deleteDirectory(tmp);
}
}
@Test
void testFromProject()
throws Exception {
var tmp = Files.createTempDirectory("test").toFile();
try {
var create_operation = new CreateRife2Operation()
.workDirectory(tmp)
.packageName("tst")
.projectName("app")
.downloadDependencies(true);
create_operation.execute();
var precompile_operation = new PrecompileOperation()
.templateTypes(List.of(TemplateType.HTML))
.fromProject(create_operation.project());
precompile_operation.execute();
assertEquals("""
/rife
/rife/template
/rife/template/html
/rife/template/html/hello.class""",
FileUtils.generateDirectoryListing(precompile_operation.destinationDirectory()));
} finally {
FileUtils.deleteDirectory(tmp);
}
}
}