mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-26 08:37:11 -07:00
First commit of standalone repo
This commit is contained in:
commit
696b23b57a
241 changed files with 28028 additions and 0 deletions
389
src/test/java/rife/bld/TestProject.java
Normal file
389
src/test/java/rife/bld/TestProject.java
Normal file
|
@ -0,0 +1,389 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.dependencies.VersionNumber;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static rife.bld.dependencies.Repository.MAVEN_CENTRAL;
|
||||
import static rife.bld.dependencies.Scope.*;
|
||||
|
||||
public class TestProject {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var project = new Project();
|
||||
|
||||
assertNotNull(project.workDirectory);
|
||||
assertNotNull(project.workDirectory());
|
||||
assertTrue(project.workDirectory().exists());
|
||||
assertTrue(project.workDirectory().isDirectory());
|
||||
assertNull(project.pkg);
|
||||
assertThrows(IllegalStateException.class, project::pkg);
|
||||
assertNull(project.name);
|
||||
assertThrows(IllegalStateException.class, project::name);
|
||||
assertNull(project.version);
|
||||
assertThrows(IllegalStateException.class, project::version);
|
||||
assertNull(project.mainClass);
|
||||
assertThrows(IllegalStateException.class, project::mainClass);
|
||||
|
||||
assertNotNull(project.repositories);
|
||||
assertTrue(project.repositories.isEmpty());
|
||||
assertNotNull(project.dependencies);
|
||||
assertTrue(project.dependencies.isEmpty());
|
||||
|
||||
assertNull(project.javaRelease);
|
||||
assertNull(project.javaTool);
|
||||
assertNotNull(project.javaTool());
|
||||
assertEquals("java", project.javaTool());
|
||||
assertNull(project.archiveBaseName);
|
||||
assertThrows(IllegalStateException.class, project::archiveBaseName);
|
||||
assertNull(project.jarFileName);
|
||||
assertThrows(IllegalStateException.class, project::jarFileName);
|
||||
assertNull(project.sourcesJarFileName);
|
||||
assertThrows(IllegalStateException.class, project::sourcesJarFileName);
|
||||
assertNull(project.javadocJarFileName);
|
||||
assertThrows(IllegalStateException.class, project::javadocJarFileName);
|
||||
assertNull(project.uberJarFileName);
|
||||
assertThrows(IllegalStateException.class, project::uberJarFileName);
|
||||
assertNull(project.uberJarMainClass);
|
||||
assertThrows(IllegalStateException.class, project::uberJarMainClass);
|
||||
|
||||
assertNull(project.srcDirectory);
|
||||
assertNotNull(project.srcDirectory());
|
||||
assertNull(project.srcBldDirectory);
|
||||
assertNotNull(project.srcBldDirectory());
|
||||
assertNull(project.srcBldJavaDirectory);
|
||||
assertNotNull(project.srcBldJavaDirectory());
|
||||
assertNull(project.srcMainDirectory);
|
||||
assertNotNull(project.srcMainDirectory());
|
||||
assertNull(project.srcMainJavaDirectory);
|
||||
assertNotNull(project.srcMainJavaDirectory());
|
||||
assertNull(project.srcMainResourcesDirectory);
|
||||
assertNotNull(project.srcMainResourcesDirectory());
|
||||
assertNull(project.srcMainResourcesTemplatesDirectory);
|
||||
assertNotNull(project.srcMainResourcesTemplatesDirectory());
|
||||
assertNull(project.srcTestDirectory);
|
||||
assertNotNull(project.srcTestDirectory());
|
||||
assertNull(project.srcTestJavaDirectory);
|
||||
assertNotNull(project.srcTestJavaDirectory());
|
||||
assertNotNull(project.libBldDirectory());
|
||||
assertNull(project.libDirectory);
|
||||
assertNotNull(project.libDirectory());
|
||||
assertNull(project.libCompileDirectory);
|
||||
assertNotNull(project.libCompileDirectory());
|
||||
assertNull(project.libRuntimeDirectory);
|
||||
assertNotNull(project.libRuntimeDirectory());
|
||||
assertNull(project.libStandaloneDirectory);
|
||||
assertNull(project.libStandaloneDirectory());
|
||||
assertNull(project.libTestDirectory);
|
||||
assertNotNull(project.libTestDirectory());
|
||||
assertNull(project.buildDirectory);
|
||||
assertNotNull(project.buildDirectory());
|
||||
assertNull(project.buildBldDirectory);
|
||||
assertNotNull(project.buildBldDirectory());
|
||||
assertNull(project.buildDistDirectory);
|
||||
assertNotNull(project.buildDistDirectory());
|
||||
assertNull(project.buildJavadocDirectory);
|
||||
assertNotNull(project.buildJavadocDirectory());
|
||||
assertNull(project.buildMainDirectory);
|
||||
assertNotNull(project.buildMainDirectory());
|
||||
assertNull(project.buildTemplatesDirectory);
|
||||
assertNotNull(project.buildTemplatesDirectory());
|
||||
assertNull(project.buildTestDirectory);
|
||||
assertNotNull(project.buildTestDirectory());
|
||||
|
||||
assertNotNull(project.mainSourceFiles());
|
||||
assertNotNull(project.testSourceFiles());
|
||||
assertNotNull(project.compileClasspathJars());
|
||||
assertNotNull(project.runtimeClasspathJars());
|
||||
assertNotNull(project.standaloneClasspathJars());
|
||||
assertNotNull(project.testClasspathJars());
|
||||
|
||||
assertNotNull(project.compileMainClasspath());
|
||||
assertNotNull(project.compileTestClasspath());
|
||||
assertNotNull(project.runClasspath());
|
||||
assertNotNull(project.testClasspath());
|
||||
}
|
||||
|
||||
static class CustomProject extends Project {
|
||||
StringBuilder result_;
|
||||
|
||||
CustomProject(File tmp, StringBuilder result) {
|
||||
result_ = result;
|
||||
workDirectory = tmp;
|
||||
pkg = "test.pkg";
|
||||
name = "my_project";
|
||||
version = new VersionNumber(0, 0, 1);
|
||||
}
|
||||
|
||||
@BuildCommand
|
||||
public void newcommand() {
|
||||
assertEquals("newcommand", getCurrentCommandName());
|
||||
assertNotNull(getCurrentCommandDefinition());
|
||||
result_.append("newcommand");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomCommand()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var result = new StringBuilder();
|
||||
var project = new CustomProject(tmp, result);
|
||||
|
||||
assertNull(project.getCurrentCommandName());
|
||||
assertNull(project.getCurrentCommandDefinition());
|
||||
|
||||
project.execute(new String[]{"newcommand"});
|
||||
|
||||
assertNull(project.getCurrentCommandName());
|
||||
assertNull(project.getCurrentCommandDefinition());
|
||||
|
||||
assertEquals("newcommand", result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static class CustomProjectInlineHelp extends Project {
|
||||
CustomProjectInlineHelp(File tmp) {
|
||||
workDirectory = tmp;
|
||||
pkg = "test.pkg";
|
||||
name = "my_project";
|
||||
version = new VersionNumber(0, 0, 1);
|
||||
}
|
||||
|
||||
@BuildCommand(summary = "mysummary", description = "mydescription")
|
||||
public void newcommand() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomCommandInlineHelp()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
var orig_err = System.err;
|
||||
try {
|
||||
var out = new ByteArrayOutputStream();
|
||||
System.setErr(new PrintStream(out, true, StandardCharsets.UTF_8));
|
||||
|
||||
var project = new CustomProjectInlineHelp(tmp);
|
||||
project.execute(new String[]{""});
|
||||
|
||||
assertTrue(out.toString(StandardCharsets.UTF_8).contains("newcommand mysummary"));
|
||||
out.reset();
|
||||
|
||||
project.execute(new String[]{"help", "newcommand"});
|
||||
assertTrue(out.toString(StandardCharsets.UTF_8).contains("mydescription"));
|
||||
|
||||
} finally {
|
||||
System.setErr(orig_err);
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static class CustomProjectLambda extends Project {
|
||||
CustomProjectLambda(File tmp, StringBuilder result) {
|
||||
buildCommands().put("newcommand2", () -> {
|
||||
assertEquals("newcommand2", getCurrentCommandName());
|
||||
assertNotNull(getCurrentCommandDefinition());
|
||||
result.append("newcommand2");
|
||||
});
|
||||
workDirectory = tmp;
|
||||
pkg = "test.pkg";
|
||||
name = "my_project";
|
||||
version = new VersionNumber(0, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomCommandLambda()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var result = new StringBuilder();
|
||||
var project = new CustomProjectLambda(tmp, result);
|
||||
|
||||
assertNull(project.getCurrentCommandName());
|
||||
assertNull(project.getCurrentCommandDefinition());
|
||||
|
||||
project.execute(new String[]{"newcommand"});
|
||||
|
||||
assertNull(project.getCurrentCommandName());
|
||||
assertNull(project.getCurrentCommandDefinition());
|
||||
|
||||
assertEquals("newcommand2", result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCommandMatch()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var result = new StringBuilder();
|
||||
var project = new CustomProjectLambda(tmp, result);
|
||||
project.execute(new String[]{"ne2", "nc2", "n2"});
|
||||
assertEquals("newcommand2" +
|
||||
"newcommand2" +
|
||||
"newcommand2", result.toString());
|
||||
|
||||
result = new StringBuilder();
|
||||
project.execute(new String[]{"c"});
|
||||
assertEquals("", result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static class CustomProjectAutoPurge extends Project {
|
||||
CustomProjectAutoPurge(File tmp) {
|
||||
workDirectory = tmp;
|
||||
pkg = "test.pkg";
|
||||
name = "my_project";
|
||||
version = new VersionNumber(0, 0, 1);
|
||||
|
||||
repositories = List.of(MAVEN_CENTRAL);
|
||||
scope(compile)
|
||||
.include(dependency("com.uwyn.rife2", "rife2", version(1, 5, 11)));
|
||||
scope(test)
|
||||
.include(dependency("org.jsoup", "jsoup", version(1, 15, 4)))
|
||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 9, 2)))
|
||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 9, 2)));
|
||||
scope(standalone)
|
||||
.include(dependency("org.eclipse.jetty", "jetty-server", version(11, 0, 14)))
|
||||
.include(dependency("org.eclipse.jetty", "jetty-servlet", version(11, 0, 14)))
|
||||
.include(dependency("org.slf4j", "slf4j-simple", version(2, 0, 7)));
|
||||
}
|
||||
|
||||
public void enableAutoDownloadPurge() {
|
||||
autoDownloadPurge = true;
|
||||
}
|
||||
|
||||
public void increaseRife2Version() {
|
||||
scope(compile).clear();
|
||||
scope(compile)
|
||||
.include(dependency("com.uwyn.rife2", "rife2", version(1, 5, 12)));
|
||||
}
|
||||
|
||||
public void increaseRife2VersionMore() {
|
||||
scope(compile).clear();
|
||||
scope(compile)
|
||||
.include(dependency("com.uwyn.rife2", "rife2", version(1, 5, 15)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAutoDownloadPurge()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var project = new CustomProjectAutoPurge(tmp);
|
||||
project.execute(new String[]{"version"});
|
||||
|
||||
assertEquals("", FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
project = new CustomProjectAutoPurge(tmp);
|
||||
project.enableAutoDownloadPurge();
|
||||
project.execute(new String[]{"version"});
|
||||
|
||||
assertEquals("""
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/bld/bld-build.hash
|
||||
/lib/compile
|
||||
/lib/compile/rife2-1.5.11.jar
|
||||
/lib/runtime
|
||||
/lib/test
|
||||
/lib/test/apiguardian-api-1.1.2.jar
|
||||
/lib/test/jsoup-1.15.4.jar
|
||||
/lib/test/junit-jupiter-5.9.2.jar
|
||||
/lib/test/junit-jupiter-api-5.9.2.jar
|
||||
/lib/test/junit-jupiter-engine-5.9.2.jar
|
||||
/lib/test/junit-jupiter-params-5.9.2.jar
|
||||
/lib/test/junit-platform-commons-1.9.2.jar
|
||||
/lib/test/junit-platform-console-standalone-1.9.2.jar
|
||||
/lib/test/junit-platform-engine-1.9.2.jar
|
||||
/lib/test/opentest4j-1.2.0.jar""", FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
FileUtils.deleteDirectory(new File(tmp, "lib/compile"));
|
||||
FileUtils.deleteDirectory(new File(tmp, "lib/runtime"));
|
||||
FileUtils.deleteDirectory(new File(tmp, "lib/test"));
|
||||
assertEquals("""
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/bld/bld-build.hash""", FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
project = new CustomProjectAutoPurge(tmp);
|
||||
project.enableAutoDownloadPurge();
|
||||
project.execute(new String[]{"version"});
|
||||
assertEquals("""
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/bld/bld-build.hash""", FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
project = new CustomProjectAutoPurge(tmp);
|
||||
project.enableAutoDownloadPurge();
|
||||
project.increaseRife2Version();
|
||||
project.execute(new String[]{"version"});
|
||||
assertEquals("""
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/bld/bld-build.hash
|
||||
/lib/compile
|
||||
/lib/compile/rife2-1.5.12.jar
|
||||
/lib/runtime
|
||||
/lib/test
|
||||
/lib/test/apiguardian-api-1.1.2.jar
|
||||
/lib/test/jsoup-1.15.4.jar
|
||||
/lib/test/junit-jupiter-5.9.2.jar
|
||||
/lib/test/junit-jupiter-api-5.9.2.jar
|
||||
/lib/test/junit-jupiter-engine-5.9.2.jar
|
||||
/lib/test/junit-jupiter-params-5.9.2.jar
|
||||
/lib/test/junit-platform-commons-1.9.2.jar
|
||||
/lib/test/junit-platform-console-standalone-1.9.2.jar
|
||||
/lib/test/junit-platform-engine-1.9.2.jar
|
||||
/lib/test/opentest4j-1.2.0.jar""", FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
project = new CustomProjectAutoPurge(tmp);
|
||||
project.enableAutoDownloadPurge();
|
||||
project.increaseRife2VersionMore();
|
||||
project.execute(new String[]{"version"});
|
||||
assertEquals("""
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/bld/bld-build.hash
|
||||
/lib/compile
|
||||
/lib/compile/rife2-1.5.15.jar
|
||||
/lib/runtime
|
||||
/lib/test
|
||||
/lib/test/apiguardian-api-1.1.2.jar
|
||||
/lib/test/jsoup-1.15.4.jar
|
||||
/lib/test/junit-jupiter-5.9.2.jar
|
||||
/lib/test/junit-jupiter-api-5.9.2.jar
|
||||
/lib/test/junit-jupiter-engine-5.9.2.jar
|
||||
/lib/test/junit-jupiter-params-5.9.2.jar
|
||||
/lib/test/junit-platform-commons-1.9.2.jar
|
||||
/lib/test/junit-platform-console-standalone-1.9.2.jar
|
||||
/lib/test/junit-platform-engine-1.9.2.jar
|
||||
/lib/test/opentest4j-1.2.0.jar""", FileUtils.generateDirectoryListing(tmp));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
152
src/test/java/rife/bld/TestWebProject.java
Normal file
152
src/test/java/rife/bld/TestWebProject.java
Normal file
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.dependencies.VersionNumber;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import java.nio.file.Files;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestWebProject {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var project = new WebProject();
|
||||
|
||||
assertNotNull(project.workDirectory);
|
||||
assertNotNull(project.workDirectory());
|
||||
assertTrue(project.workDirectory().exists());
|
||||
assertTrue(project.workDirectory().isDirectory());
|
||||
assertNull(project.pkg);
|
||||
assertThrows(IllegalStateException.class, project::pkg);
|
||||
assertNull(project.name);
|
||||
assertThrows(IllegalStateException.class, project::name);
|
||||
assertNull(project.version);
|
||||
assertThrows(IllegalStateException.class, project::version);
|
||||
assertNull(project.mainClass);
|
||||
assertThrows(IllegalStateException.class, project::mainClass);
|
||||
|
||||
assertNotNull(project.repositories);
|
||||
assertTrue(project.repositories.isEmpty());
|
||||
assertNotNull(project.dependencies);
|
||||
assertTrue(project.dependencies.isEmpty());
|
||||
|
||||
assertNull(project.javaTool);
|
||||
assertNotNull(project.javaTool());
|
||||
assertEquals("java", project.javaTool());
|
||||
assertNull(project.archiveBaseName);
|
||||
assertThrows(IllegalStateException.class, project::archiveBaseName);
|
||||
assertNull(project.jarFileName);
|
||||
assertThrows(IllegalStateException.class, project::jarFileName);
|
||||
assertNull(project.uberJarFileName);
|
||||
assertThrows(IllegalStateException.class, project::uberJarFileName);
|
||||
assertNull(project.uberJarMainClass);
|
||||
assertThrows(IllegalStateException.class, project::uberJarMainClass);
|
||||
assertNull(project.warFileName);
|
||||
assertThrows(IllegalStateException.class, project::warFileName);
|
||||
|
||||
assertNull(project.srcDirectory);
|
||||
assertNotNull(project.srcDirectory());
|
||||
assertNull(project.srcBldDirectory);
|
||||
assertNotNull(project.srcBldDirectory());
|
||||
assertNull(project.srcBldJavaDirectory);
|
||||
assertNotNull(project.srcBldJavaDirectory());
|
||||
assertNull(project.srcMainDirectory);
|
||||
assertNotNull(project.srcMainDirectory());
|
||||
assertNull(project.srcMainJavaDirectory);
|
||||
assertNotNull(project.srcMainJavaDirectory());
|
||||
assertNull(project.srcMainResourcesDirectory);
|
||||
assertNotNull(project.srcMainResourcesDirectory());
|
||||
assertNull(project.srcMainResourcesTemplatesDirectory);
|
||||
assertNotNull(project.srcMainResourcesTemplatesDirectory());
|
||||
assertNull(project.srcMainWebappDirectory);
|
||||
assertNotNull(project.srcMainWebappDirectory());
|
||||
assertNull(project.srcTestDirectory);
|
||||
assertNotNull(project.srcTestDirectory());
|
||||
assertNull(project.srcTestJavaDirectory);
|
||||
assertNotNull(project.srcTestJavaDirectory());
|
||||
assertNotNull(project.libBldDirectory());
|
||||
assertNull(project.libDirectory);
|
||||
assertNotNull(project.libDirectory());
|
||||
assertNull(project.libCompileDirectory);
|
||||
assertNotNull(project.libCompileDirectory());
|
||||
assertNull(project.libRuntimeDirectory);
|
||||
assertNotNull(project.libRuntimeDirectory());
|
||||
assertNull(project.libStandaloneDirectory);
|
||||
assertNotNull(project.libStandaloneDirectory());
|
||||
assertNull(project.libTestDirectory);
|
||||
assertNotNull(project.libTestDirectory());
|
||||
assertNull(project.buildDirectory);
|
||||
assertNotNull(project.buildDirectory());
|
||||
assertNull(project.buildBldDirectory);
|
||||
assertNotNull(project.buildBldDirectory());
|
||||
assertNull(project.buildDistDirectory);
|
||||
assertNotNull(project.buildDistDirectory());
|
||||
assertNull(project.buildMainDirectory);
|
||||
assertNotNull(project.buildMainDirectory());
|
||||
assertNull(project.buildTemplatesDirectory);
|
||||
assertNotNull(project.buildTemplatesDirectory());
|
||||
assertNull(project.buildTestDirectory);
|
||||
assertNotNull(project.buildTestDirectory());
|
||||
|
||||
assertNotNull(project.mainSourceFiles());
|
||||
assertNotNull(project.testSourceFiles());
|
||||
assertNotNull(project.compileClasspathJars());
|
||||
assertNotNull(project.runtimeClasspathJars());
|
||||
assertNotNull(project.standaloneClasspathJars());
|
||||
assertNotNull(project.testClasspathJars());
|
||||
|
||||
assertNotNull(project.compileMainClasspath());
|
||||
assertNotNull(project.compileTestClasspath());
|
||||
assertNotNull(project.runClasspath());
|
||||
assertNotNull(project.testClasspath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomCommand()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var result = new StringBuilder();
|
||||
var project = new WebProject() {
|
||||
@BuildCommand
|
||||
public void newcommand() {
|
||||
result.append("newcommand");
|
||||
}
|
||||
};
|
||||
project.workDirectory = tmp;
|
||||
project.pkg = "test.pkg";
|
||||
project.name = "my_project";
|
||||
project.version = new VersionNumber(0, 0, 1);
|
||||
|
||||
project.execute(new String[]{"newcommand"});
|
||||
assertEquals("newcommand", result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomCommandLambda()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var result = new StringBuilder();
|
||||
var project = new WebProject();
|
||||
project.buildCommands().put("newcommand", () -> result.append("newcommand"));
|
||||
project.workDirectory = tmp;
|
||||
project.pkg = "test.pkg";
|
||||
project.name = "my_project";
|
||||
project.version = new VersionNumber(0, 0, 1);
|
||||
|
||||
project.execute(new String[]{"newcommand"});
|
||||
assertEquals("newcommand", result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
109
src/test/java/rife/bld/dependencies/TestDependency.java
Normal file
109
src/test/java/rife/bld/dependencies/TestDependency.java
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.dependencies;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestDependency {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var dependency1 = new Dependency("com.uwyn.rife2", "rife2");
|
||||
assertNotNull(dependency1);
|
||||
assertEquals("com.uwyn.rife2", dependency1.groupId());
|
||||
assertEquals("rife2", dependency1.artifactId());
|
||||
assertEquals(VersionNumber.UNKNOWN, dependency1.version());
|
||||
assertEquals("", dependency1.classifier());
|
||||
assertEquals("jar", dependency1.type());
|
||||
|
||||
var dependency2 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0));
|
||||
assertNotNull(dependency2);
|
||||
assertEquals("com.uwyn.rife2", dependency2.groupId());
|
||||
assertEquals("rife2", dependency2.artifactId());
|
||||
assertEquals(new VersionNumber(1, 4, 0), dependency2.version());
|
||||
assertEquals("", dependency2.classifier());
|
||||
assertEquals("jar", dependency2.type());
|
||||
|
||||
var dependency3 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "agent");
|
||||
assertNotNull(dependency3);
|
||||
assertEquals("com.uwyn.rife2", dependency3.groupId());
|
||||
assertEquals("rife2", dependency3.artifactId());
|
||||
assertEquals(new VersionNumber(1, 4, 0), dependency3.version());
|
||||
assertEquals("agent", dependency3.classifier());
|
||||
assertEquals("jar", dependency3.type());
|
||||
|
||||
var dependency4 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "bld", "zip");
|
||||
assertNotNull(dependency4);
|
||||
assertEquals("com.uwyn.rife2", dependency4.groupId());
|
||||
assertEquals("rife2", dependency4.artifactId());
|
||||
assertEquals(new VersionNumber(1, 4, 0), dependency4.version());
|
||||
assertEquals("bld", dependency4.classifier());
|
||||
assertEquals("zip", dependency4.type());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBaseDependency() {
|
||||
var dependency1 = new Dependency("com.uwyn.rife2", "rife2");
|
||||
assertEquals(dependency1, dependency1.baseDependency());
|
||||
|
||||
var dependency2 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0));
|
||||
assertEquals(dependency2, dependency1.baseDependency());
|
||||
|
||||
var dependency3 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "agent");
|
||||
assertNotEquals(dependency3, dependency1.baseDependency());
|
||||
|
||||
var dependency4 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "bld", "zip");
|
||||
assertNotEquals(dependency4, dependency1.baseDependency());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithClassifier() {
|
||||
var dependency1 = new Dependency("com.uwyn.rife2", "rife2");
|
||||
assertEquals(new Dependency("com.uwyn.rife2", "rife2", VersionNumber.UNKNOWN, "sources"), dependency1.withClassifier("sources"));
|
||||
|
||||
var dependency2 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0));
|
||||
assertEquals(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "sources"), dependency2.withClassifier("sources"));
|
||||
|
||||
var dependency3 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "agent");
|
||||
assertEquals(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "sources"), dependency3.withClassifier("sources"));
|
||||
|
||||
var dependency4 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "bld", "zip");
|
||||
assertEquals(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "sources", "zip"), dependency4.withClassifier("sources"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
assertEquals("com.uwyn.rife2:rife2", new Dependency("com.uwyn.rife2", "rife2").toString());
|
||||
assertEquals("com.uwyn.rife2:rife2:1.4.0", new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0)).toString());
|
||||
assertEquals("com.uwyn.rife2:rife2:1.4.0:agent", new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "agent").toString());
|
||||
assertEquals("com.uwyn.rife2:rife2:1.4.0:bld@zip", new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "bld", "zip").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToFileName() {
|
||||
assertEquals("rife2-0.0.0.jar", new Dependency("com.uwyn.rife2", "rife2").toFileName());
|
||||
assertEquals("rife2-1.4.0.jar", new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0)).toFileName());
|
||||
assertEquals("rife2-1.4.0-agent.jar", new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "agent").toFileName());
|
||||
assertEquals("rife2-1.4.0-bld.zip", new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "bld", "zip").toFileName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToParse() {
|
||||
assertEquals("com.uwyn.rife2:rife2", Dependency.parse("com.uwyn.rife2:rife2").toString());
|
||||
assertEquals("com.uwyn.rife2:rife2:1.4.0", Dependency.parse("com.uwyn.rife2:rife2:1.4.0").toString());
|
||||
assertEquals("com.uwyn.rife2:rife2:1.4.0:agent", Dependency.parse("com.uwyn.rife2:rife2:1.4.0:agent").toString());
|
||||
assertEquals("com.uwyn.rife2:rife2:1.4.0:agent@zip", Dependency.parse("com.uwyn.rife2:rife2:1.4.0:agent@zip").toString());
|
||||
assertEquals("com.uwyn.rife2:rife2@zip", Dependency.parse("com.uwyn.rife2:rife2@zip").toString());
|
||||
assertEquals("com.uwyn.rife2:rife2:1.4.0@zip", Dependency.parse("com.uwyn.rife2:rife2:1.4.0@zip").toString());
|
||||
|
||||
assertEquals(new Dependency("com.uwyn.rife2", "rife2").toString(), Dependency.parse("com.uwyn.rife2:rife2").toString());
|
||||
assertEquals(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0)).toString(), Dependency.parse("com.uwyn.rife2:rife2:1.4.0").toString());
|
||||
assertEquals(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "agent").toString(), Dependency.parse("com.uwyn.rife2:rife2:1.4.0:agent").toString());
|
||||
assertEquals(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), "agent", "zip").toString(), Dependency.parse("com.uwyn.rife2:rife2:1.4.0:agent@zip").toString());
|
||||
assertEquals(new Dependency("com.uwyn.rife2", "rife2", null, null, "zip").toString(), Dependency.parse("com.uwyn.rife2:rife2@zip").toString());
|
||||
assertEquals(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0), null, "zip").toString(), Dependency.parse("com.uwyn.rife2:rife2:1.4.0@zip").toString());
|
||||
}
|
||||
}
|
1436
src/test/java/rife/bld/dependencies/TestDependencyResolver.java
Normal file
1436
src/test/java/rife/bld/dependencies/TestDependencyResolver.java
Normal file
File diff suppressed because it is too large
Load diff
375
src/test/java/rife/bld/dependencies/TestDependencySet.java
Normal file
375
src/test/java/rife/bld/dependencies/TestDependencySet.java
Normal file
|
@ -0,0 +1,375 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.dependencies;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.tools.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static rife.bld.dependencies.Repository.*;
|
||||
import static rife.bld.dependencies.Scope.compile;
|
||||
import static rife.bld.dependencies.Scope.runtime;
|
||||
|
||||
public class TestDependencySet {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var set = new DependencySet();
|
||||
assertNotNull(set);
|
||||
assertTrue(set.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var set = new DependencySet();
|
||||
|
||||
var dep1 = new Dependency("com.uwyn.rife2", "rife2");
|
||||
var dep2 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 3, 0));
|
||||
var dep3 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 4, 0));
|
||||
var dep4 = new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 3, 1));
|
||||
|
||||
set.add(dep1);
|
||||
assertEquals(VersionNumber.UNKNOWN, set.get(dep1).version());
|
||||
set.add(dep2);
|
||||
assertEquals(dep2.version(), set.get(dep1).version());
|
||||
set.add(dep3);
|
||||
assertEquals(dep3.version(), set.get(dep2).version());
|
||||
set.add(dep4);
|
||||
assertEquals(dep3.version(), set.get(dep2).version());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddAll() {
|
||||
var set1 = new DependencySet()
|
||||
.include(new Dependency("org.eclipse.jetty", "jetty-server", VersionNumber.parse("11.0.14")))
|
||||
.include(new Dependency("org.eclipse.jetty.toolchain", "jetty-jakarta-servlet-api", VersionNumber.parse("5.0.2")))
|
||||
.include(new Dependency("org.eclipse.jetty", "jetty-http", VersionNumber.parse("11.0.14")))
|
||||
.include(new Dependency("org.eclipse.jetty", "jetty-io", VersionNumber.parse("11.0.14")))
|
||||
.include(new Dependency("org.eclipse.jetty", "jetty-util", VersionNumber.parse("11.0.14")))
|
||||
.include(new Dependency("org.slf4j", "slf4j-api", VersionNumber.parse("2.0.5")));
|
||||
|
||||
var set2 = new DependencySet()
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", VersionNumber.parse("2.0.6")))
|
||||
.include(new Dependency("org.slf4j", "slf4j-api", VersionNumber.parse("2.0.6")));
|
||||
|
||||
var set_union1 = new DependencySet(set1);
|
||||
set_union1.addAll(set2);
|
||||
assertEquals("""
|
||||
org.eclipse.jetty:jetty-server:11.0.14
|
||||
org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api:5.0.2
|
||||
org.eclipse.jetty:jetty-http:11.0.14
|
||||
org.eclipse.jetty:jetty-io:11.0.14
|
||||
org.eclipse.jetty:jetty-util:11.0.14
|
||||
org.slf4j:slf4j-simple:2.0.6
|
||||
org.slf4j:slf4j-api:2.0.6""", StringUtils.join(set_union1, "\n"));
|
||||
|
||||
var set_union2 = new DependencySet(set2);
|
||||
set_union2.addAll(set1);
|
||||
assertEquals("""
|
||||
org.slf4j:slf4j-simple:2.0.6
|
||||
org.slf4j:slf4j-api:2.0.6
|
||||
org.eclipse.jetty:jetty-server:11.0.14
|
||||
org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api:5.0.2
|
||||
org.eclipse.jetty:jetty-http:11.0.14
|
||||
org.eclipse.jetty:jetty-io:11.0.14
|
||||
org.eclipse.jetty:jetty-util:11.0.14""", StringUtils.join(set_union2, "\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateDependencyTreeJettySlf4j() {
|
||||
var dependencies = new DependencySet()
|
||||
.include(new Dependency("org.eclipse.jetty", "jetty-server", new VersionNumber(11, 0, 14)))
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 6)));
|
||||
assertEquals("""
|
||||
├─ org.eclipse.jetty:jetty-server:11.0.14
|
||||
│ ├─ org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api:5.0.2
|
||||
│ ├─ org.eclipse.jetty:jetty-http:11.0.14
|
||||
│ │ └─ org.eclipse.jetty:jetty-util:11.0.14
|
||||
│ └─ org.eclipse.jetty:jetty-io:11.0.14
|
||||
└─ org.slf4j:slf4j-simple:2.0.6
|
||||
└─ org.slf4j:slf4j-api:2.0.6
|
||||
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateDependencyTreeSpringBoot() {
|
||||
var dependencies = new DependencySet()
|
||||
.include(new Dependency("org.springframework.boot", "spring-boot-starter", new VersionNumber(3, 0, 4)));
|
||||
assertEquals("""
|
||||
└─ org.springframework.boot:spring-boot-starter:3.0.4
|
||||
├─ org.springframework.boot:spring-boot:3.0.4
|
||||
│ └─ org.springframework:spring-context:6.0.6
|
||||
│ ├─ org.springframework:spring-aop:6.0.6
|
||||
│ ├─ org.springframework:spring-beans:6.0.6
|
||||
│ └─ org.springframework:spring-expression:6.0.6
|
||||
├─ org.springframework.boot:spring-boot-autoconfigure:3.0.4
|
||||
├─ org.springframework.boot:spring-boot-starter-logging:3.0.4
|
||||
│ ├─ ch.qos.logback:logback-classic:1.4.5
|
||||
│ │ ├─ ch.qos.logback:logback-core:1.4.5
|
||||
│ │ └─ org.slf4j:slf4j-api:2.0.4
|
||||
│ ├─ org.apache.logging.log4j:log4j-to-slf4j:2.19.0
|
||||
│ │ └─ org.apache.logging.log4j:log4j-api:2.19.0
|
||||
│ └─ org.slf4j:jul-to-slf4j:2.0.6
|
||||
├─ jakarta.annotation:jakarta.annotation-api:2.1.1
|
||||
├─ org.springframework:spring-core:6.0.6
|
||||
│ └─ org.springframework:spring-jcl:6.0.6
|
||||
└─ org.yaml:snakeyaml:1.33
|
||||
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateDependencyTreeMaven() {
|
||||
var dependencies = new DependencySet()
|
||||
.include(new Dependency("org.apache.maven", "maven-core", new VersionNumber(3, 9, 0)));
|
||||
assertEquals("""
|
||||
└─ org.apache.maven:maven-core:3.9.0
|
||||
├─ org.apache.maven:maven-model:3.9.0
|
||||
├─ org.apache.maven:maven-settings:3.9.0
|
||||
├─ org.apache.maven:maven-settings-builder:3.9.0
|
||||
│ └─ org.codehaus.plexus:plexus-sec-dispatcher:2.0
|
||||
│ └─ org.codehaus.plexus:plexus-cipher:2.0
|
||||
├─ org.apache.maven:maven-builder-support:3.9.0
|
||||
├─ org.apache.maven:maven-repository-metadata:3.9.0
|
||||
├─ org.apache.maven:maven-artifact:3.9.0
|
||||
├─ org.apache.maven:maven-plugin-api:3.9.0
|
||||
├─ org.apache.maven:maven-model-builder:3.9.0
|
||||
├─ org.apache.maven:maven-resolver-provider:3.9.0
|
||||
├─ org.apache.maven.resolver:maven-resolver-impl:1.9.4
|
||||
│ └─ org.apache.maven.resolver:maven-resolver-named-locks:1.9.4
|
||||
├─ org.apache.maven.resolver:maven-resolver-api:1.9.4
|
||||
├─ org.apache.maven.resolver:maven-resolver-spi:1.9.4
|
||||
├─ org.apache.maven.resolver:maven-resolver-util:1.9.4
|
||||
├─ org.apache.maven.shared:maven-shared-utils:3.3.4
|
||||
├─ org.eclipse.sisu:org.eclipse.sisu.plexus:0.3.5
|
||||
│ └─ javax.annotation:javax.annotation-api:1.2
|
||||
├─ org.eclipse.sisu:org.eclipse.sisu.inject:0.3.5
|
||||
├─ com.google.inject:guice:5.1.0
|
||||
│ └─ aopalliance:aopalliance:1.0
|
||||
├─ com.google.guava:guava:30.1-jre
|
||||
├─ com.google.guava:failureaccess:1.0.1
|
||||
├─ javax.inject:javax.inject:1
|
||||
├─ org.codehaus.plexus:plexus-utils:3.4.2
|
||||
├─ org.codehaus.plexus:plexus-classworlds:2.6.0
|
||||
├─ org.codehaus.plexus:plexus-interpolation:1.26
|
||||
├─ org.codehaus.plexus:plexus-component-annotations:2.1.0
|
||||
├─ org.apache.commons:commons-lang3:3.8.1
|
||||
└─ org.slf4j:slf4j-api:1.7.36
|
||||
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateDependencyTreePlay() {
|
||||
var dependencies = new DependencySet()
|
||||
.include(new Dependency("com.typesafe.play", "play_2.13", new VersionNumber(2, 8, 19)));
|
||||
assertEquals("""
|
||||
└─ com.typesafe.play:play_2.13:2.8.19
|
||||
├─ org.scala-lang:scala-library:2.13.10
|
||||
├─ com.typesafe.play:build-link:2.8.19
|
||||
│ └─ com.typesafe.play:play-exceptions:2.8.19
|
||||
├─ com.typesafe.play:play-streams_2.13:2.8.19
|
||||
│ ├─ org.reactivestreams:reactive-streams:1.0.3
|
||||
│ └─ com.typesafe.akka:akka-stream_2.13:2.6.20
|
||||
│ └─ com.typesafe.akka:akka-protobuf-v3_2.13:2.6.20
|
||||
├─ com.typesafe.play:twirl-api_2.13:1.5.1
|
||||
│ └─ org.scala-lang.modules:scala-xml_2.13:1.2.0
|
||||
├─ org.slf4j:slf4j-api:1.7.36
|
||||
├─ org.slf4j:jul-to-slf4j:1.7.36
|
||||
├─ org.slf4j:jcl-over-slf4j:1.7.36
|
||||
├─ com.typesafe.akka:akka-actor_2.13:2.6.20
|
||||
│ └─ com.typesafe:config:1.4.2
|
||||
├─ com.typesafe.akka:akka-actor-typed_2.13:2.6.20
|
||||
├─ com.typesafe.akka:akka-slf4j_2.13:2.6.20
|
||||
├─ com.typesafe.akka:akka-serialization-jackson_2.13:2.6.20
|
||||
│ ├─ com.fasterxml.jackson.module:jackson-module-parameter-names:2.11.4
|
||||
│ ├─ com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.11.4
|
||||
│ ├─ com.fasterxml.jackson.module:jackson-module-scala_2.13:2.11.4
|
||||
│ │ └─ com.fasterxml.jackson.module:jackson-module-paranamer:2.11.4
|
||||
│ │ └─ com.thoughtworks.paranamer:paranamer:2.8
|
||||
│ └─ org.lz4:lz4-java:1.8.0
|
||||
├─ com.fasterxml.jackson.core:jackson-core:2.11.4
|
||||
├─ com.fasterxml.jackson.core:jackson-annotations:2.11.4
|
||||
├─ com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.4
|
||||
├─ com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.4
|
||||
├─ com.fasterxml.jackson.core:jackson-databind:2.11.4
|
||||
├─ com.typesafe.play:play-json_2.13:2.8.2
|
||||
│ ├─ com.typesafe.play:play-functional_2.13:2.8.2
|
||||
│ ├─ org.scala-lang:scala-reflect:2.13.1
|
||||
│ └─ joda-time:joda-time:2.10.5
|
||||
├─ com.google.guava:guava:30.1.1-jre
|
||||
│ ├─ com.google.guava:failureaccess:1.0.1
|
||||
│ ├─ com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
|
||||
│ ├─ com.google.code.findbugs:jsr305:3.0.2
|
||||
│ ├─ org.checkerframework:checker-qual:3.8.0
|
||||
│ ├─ com.google.errorprone:error_prone_annotations:2.5.1
|
||||
│ └─ com.google.j2objc:j2objc-annotations:1.3
|
||||
├─ io.jsonwebtoken:jjwt:0.9.1
|
||||
├─ jakarta.xml.bind:jakarta.xml.bind-api:2.3.3
|
||||
│ └─ jakarta.activation:jakarta.activation-api:1.2.2
|
||||
├─ jakarta.transaction:jakarta.transaction-api:1.3.3
|
||||
├─ javax.inject:javax.inject:1
|
||||
├─ org.scala-lang.modules:scala-java8-compat_2.13:1.0.2
|
||||
├─ com.typesafe:ssl-config-core_2.13:0.4.3
|
||||
└─ org.scala-lang.modules:scala-parser-combinators_2.13:1.1.2
|
||||
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateDependencyTreeVaadin() {
|
||||
var dependencies = new DependencySet()
|
||||
.include(new Dependency("com.vaadin", "vaadin", new VersionNumber(23, 3, 7)));
|
||||
assertEquals("""
|
||||
└─ com.vaadin:vaadin:23.3.7
|
||||
├─ com.vaadin:vaadin-core:23.3.7
|
||||
│ ├─ com.vaadin:flow-server:23.3.4
|
||||
│ │ ├─ com.vaadin.servletdetector:throw-if-servlet5:1.0.2
|
||||
│ │ ├─ org.slf4j:slf4j-api:1.7.36
|
||||
│ │ ├─ javax.annotation:javax.annotation-api:1.3.2
|
||||
│ │ ├─ com.vaadin.external.gwt:gwt-elemental:2.8.2.vaadin2
|
||||
│ │ ├─ commons-fileupload:commons-fileupload:1.4
|
||||
│ │ ├─ commons-io:commons-io:2.11.0
|
||||
│ │ ├─ com.fasterxml.jackson.core:jackson-core:2.14.1
|
||||
│ │ ├─ org.jsoup:jsoup:1.15.3
|
||||
│ │ ├─ com.helger:ph-css:6.5.0
|
||||
│ │ │ └─ com.helger.commons:ph-commons:10.1.6
|
||||
│ │ │ └─ com.google.code.findbugs:jsr305:3.0.2
|
||||
│ │ ├─ net.bytebuddy:byte-buddy:1.12.20
|
||||
│ │ ├─ com.vaadin.external:gentyref:1.2.0.vaadin1
|
||||
│ │ ├─ org.apache.commons:commons-compress:1.22
|
||||
│ │ ├─ org.apache.httpcomponents:httpclient:4.5.13
|
||||
│ │ │ ├─ org.apache.httpcomponents:httpcore:4.4.13
|
||||
│ │ │ └─ commons-logging:commons-logging:1.2
|
||||
│ │ └─ commons-codec:commons-codec:1.15
|
||||
│ ├─ com.vaadin:vaadin-dev-server:23.3.4
|
||||
│ │ └─ com.vaadin:open:8.5.0
|
||||
│ ├─ com.vaadin:flow-lit-template:23.3.4
|
||||
│ ├─ com.vaadin:flow-polymer-template:23.3.4
|
||||
│ ├─ com.vaadin:flow-push:23.3.4
|
||||
│ │ └─ com.vaadin.external.atmosphere:atmosphere-runtime:2.7.3.slf4jvaadin4
|
||||
│ ├─ com.vaadin:flow-client:23.3.4
|
||||
│ ├─ com.vaadin:flow-html-components:23.3.4
|
||||
│ ├─ com.vaadin:flow-data:23.3.4
|
||||
│ │ └─ javax.validation:validation-api:2.0.1.Final
|
||||
│ ├─ com.vaadin:flow-dnd:23.3.4
|
||||
│ │ ├─ org.webjars.npm:vaadin__vaadin-mobile-drag-drop:1.0.1
|
||||
│ │ └─ org.webjars.npm:mobile-drag-drop:2.3.0-rc.2
|
||||
│ ├─ com.vaadin:vaadin-lumo-theme:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-material-theme:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-accordion-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-avatar-flow:23.3.7
|
||||
│ │ └─ com.vaadin:vaadin-flow-components-base:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-button-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-checkbox-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-combo-box-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-confirm-dialog-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-custom-field-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-date-picker-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-date-time-picker-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-details-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-time-picker-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-select-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-dialog-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-form-layout-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-field-highlighter-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-grid-flow:23.3.7
|
||||
│ │ └─ org.apache.commons:commons-lang3:3.12.0
|
||||
│ ├─ com.vaadin:vaadin-icons-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-iron-list-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-virtual-list-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-list-box-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-login-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-messages-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-ordered-layout-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-progress-bar-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-radio-button-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-renderer-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-split-layout-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-tabs-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-text-field-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-upload-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-notification-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-app-layout-flow:23.3.7
|
||||
│ ├─ com.vaadin:vaadin-context-menu-flow:23.3.7
|
||||
│ └─ com.vaadin:vaadin-menu-bar-flow:23.3.7
|
||||
├─ com.vaadin:vaadin-board-flow:23.3.7
|
||||
├─ com.vaadin:vaadin-charts-flow:23.3.7
|
||||
├─ com.vaadin:vaadin-cookie-consent-flow:23.3.7
|
||||
├─ com.vaadin:vaadin-crud-flow:23.3.7
|
||||
├─ com.vaadin:vaadin-grid-pro-flow:23.3.7
|
||||
├─ com.vaadin:vaadin-map-flow:23.3.7
|
||||
├─ com.vaadin:vaadin-rich-text-editor-flow:23.3.7
|
||||
└─ com.vaadin:collaboration-engine:5.3.0
|
||||
├─ com.fasterxml.jackson.core:jackson-databind:2.14.1
|
||||
│ └─ com.fasterxml.jackson.core:jackson-annotations:2.14.1
|
||||
├─ com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.1
|
||||
└─ com.vaadin:license-checker:1.5.1
|
||||
├─ com.github.oshi:oshi-core:6.1.6
|
||||
│ ├─ net.java.dev.jna:jna:5.11.0
|
||||
│ └─ net.java.dev.jna:jna-platform:5.11.0
|
||||
└─ com.auth0:java-jwt:3.19.2
|
||||
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateDependencyTreeVarious() {
|
||||
var dependencies = new DependencySet()
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1,5,20)))
|
||||
.include(new Dependency("com.stripe", "stripe-java", new VersionNumber(20,136,0)))
|
||||
.include(new Dependency("org.json", "json", new VersionNumber(20230227)))
|
||||
.include(new Dependency("com.itextpdf", "itext7-core", new VersionNumber(7,2,5)))
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2,0,7)))
|
||||
.include(new Dependency("org.apache.thrift", "libthrift", new VersionNumber(0,17,0)))
|
||||
.include(new Dependency("commons-codec", "commons-codec", new VersionNumber(1,15)))
|
||||
.include(new Dependency("org.apache.httpcomponents", "httpcore", new VersionNumber(4,4,16)))
|
||||
.include(new Dependency("com.google.zxing", "javase", new VersionNumber(3,5,1)));
|
||||
assertEquals("""
|
||||
├─ com.uwyn.rife2:rife2:1.5.20
|
||||
├─ com.stripe:stripe-java:20.136.0
|
||||
├─ org.json:json:20230227
|
||||
├─ com.itextpdf:itext7-core:7.2.5
|
||||
│ ├─ com.itextpdf:barcodes:7.2.5
|
||||
│ ├─ com.itextpdf:font-asian:7.2.5
|
||||
│ ├─ com.itextpdf:forms:7.2.5
|
||||
│ ├─ com.itextpdf:hyph:7.2.5
|
||||
│ ├─ com.itextpdf:io:7.2.5
|
||||
│ │ └─ com.itextpdf:commons:7.2.5
|
||||
│ ├─ com.itextpdf:kernel:7.2.5
|
||||
│ │ ├─ org.bouncycastle:bcpkix-jdk15on:1.70
|
||||
│ │ │ └─ org.bouncycastle:bcutil-jdk15on:1.70
|
||||
│ │ └─ org.bouncycastle:bcprov-jdk15on:1.70
|
||||
│ ├─ com.itextpdf:layout:7.2.5
|
||||
│ ├─ com.itextpdf:pdfa:7.2.5
|
||||
│ ├─ com.itextpdf:sign:7.2.5
|
||||
│ ├─ com.itextpdf:styled-xml-parser:7.2.5
|
||||
│ └─ com.itextpdf:svg:7.2.5
|
||||
├─ org.slf4j:slf4j-simple:2.0.7
|
||||
│ └─ org.slf4j:slf4j-api:2.0.7
|
||||
├─ org.apache.thrift:libthrift:0.17.0
|
||||
├─ commons-codec:commons-codec:1.15
|
||||
├─ org.apache.httpcomponents:httpcore:4.4.16
|
||||
└─ com.google.zxing:javase:3.5.1
|
||||
├─ com.google.zxing:core:3.5.1
|
||||
└─ com.beust:jcommander:1.82
|
||||
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL), compile));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateDependencyTreeCompileRuntime() {
|
||||
var dependencies = new DependencySet()
|
||||
.include(new Dependency("net.thauvin.erik", "bitly-shorten", new VersionNumber(0, 9, 4, "SNAPSHOT")));
|
||||
assertEquals("""
|
||||
└─ net.thauvin.erik:bitly-shorten:0.9.4-SNAPSHOT
|
||||
├─ org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.20
|
||||
│ ├─ org.jetbrains.kotlin:kotlin-stdlib:1.8.20
|
||||
│ │ ├─ org.jetbrains.kotlin:kotlin-stdlib-common:1.8.20
|
||||
│ │ └─ org.jetbrains:annotations:13.0
|
||||
│ └─ org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.20
|
||||
├─ com.squareup.okhttp3:okhttp:4.10.0
|
||||
│ └─ com.squareup.okio:okio-jvm:3.0.0
|
||||
├─ com.squareup.okhttp3:logging-interceptor:4.10.0
|
||||
└─ org.json:json:20230227
|
||||
""", dependencies.generateTransitiveDependencyTree(ArtifactRetriever.instance(), List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS_LEGACY), compile, runtime));
|
||||
}
|
||||
}
|
123
src/test/java/rife/bld/dependencies/TestRepository.java
Normal file
123
src/test/java/rife/bld/dependencies/TestRepository.java
Normal file
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.dependencies;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.ioc.HierarchicalProperties;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestRepository {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var repository1 = new Repository("http://my.repo");
|
||||
assertNotNull(repository1);
|
||||
assertEquals("http://my.repo", repository1.location());
|
||||
assertNull(repository1.username());
|
||||
assertNull(repository1.password());
|
||||
|
||||
var repository2 = new Repository("http://your.repo", "user1", "pass1");
|
||||
assertNotNull(repository2);
|
||||
assertEquals("http://your.repo", repository2.location());
|
||||
assertEquals("user1", repository2.username());
|
||||
assertEquals("pass1", repository2.password());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
var repository1 = new Repository("http://my.repo");
|
||||
assertEquals("http://my.repo", repository1.toString());
|
||||
|
||||
var repository2 = new Repository("http://your.repo", null, "pass1");
|
||||
assertEquals("http://your.repo", repository2.toString());
|
||||
|
||||
var repository3 = new Repository("http://your.repo", "user1", null);
|
||||
assertEquals("http://your.repo:24c9e15e52afc47c225b757e7bee1f9d", repository3.toString());
|
||||
|
||||
var repository4 = new Repository("http://your.repo", "user1", "pass1");
|
||||
assertEquals("http://your.repo:24c9e15e52afc47c225b757e7bee1f9d:a722c63db8ec8625af6cf71cb8c2d939", repository4.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithCredentials() {
|
||||
var repository1 = new Repository("http://my.repo");
|
||||
assertNotNull(repository1);
|
||||
assertEquals("http://my.repo", repository1.location());
|
||||
assertNull(repository1.username());
|
||||
assertNull(repository1.password());
|
||||
|
||||
var repository2 = repository1.withCredentials("user1", "pass1");
|
||||
assertNotNull(repository2);
|
||||
assertEquals("http://my.repo", repository2.location());
|
||||
assertEquals("user1", repository2.username());
|
||||
assertEquals("pass1", repository2.password());
|
||||
|
||||
var repository3 = repository1.withCredentials("user2", "pass2");
|
||||
assertNotNull(repository3);
|
||||
assertEquals("http://my.repo", repository3.location());
|
||||
assertEquals("user2", repository3.username());
|
||||
assertEquals("pass2", repository3.password());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArtifactLocation() {
|
||||
var repository1 = new Repository("http://my.repo");
|
||||
assertNotNull(repository1);
|
||||
assertEquals("http://my.repo/groupId1/artifactId1/", repository1.getArtifactLocation("groupId1", "artifactId1"));
|
||||
|
||||
var repository2 = new Repository("file:///local/repo");
|
||||
assertNotNull(repository2);
|
||||
assertEquals("/local/repo/groupId2/artifactId2/", repository2.getArtifactLocation("groupId2", "artifactId2"));
|
||||
|
||||
var repository3 = new Repository("/local/repo");
|
||||
assertNotNull(repository3);
|
||||
assertEquals("/local/repo/groupId3/artifactId3/", repository3.getArtifactLocation("groupId3", "artifactId3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsLocal() {
|
||||
assertFalse(new Repository("http://my.repo").isLocal());
|
||||
assertTrue(new Repository("file:///local/repo").isLocal());
|
||||
assertTrue(new Repository("//local/repo").isLocal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResolveMavenLocal() {
|
||||
var properties = new HierarchicalProperties();
|
||||
|
||||
Repository.MAVEN_LOCAL = null;
|
||||
assertNull(Repository.MAVEN_LOCAL);
|
||||
|
||||
Repository.resolveMavenLocal(properties);
|
||||
assertEquals(Path.of(System.getProperty("user.home"), ".m2", "repository").toString(), Repository.MAVEN_LOCAL.location());
|
||||
|
||||
properties.put("user.home", "/other/home");
|
||||
Repository.resolveMavenLocal(properties);
|
||||
assertEquals(Path.of("/other/home", ".m2", "repository").toString(), Repository.MAVEN_LOCAL.location());
|
||||
|
||||
properties.put("maven.repo.local", "/different/local");
|
||||
Repository.resolveMavenLocal(properties);
|
||||
assertEquals("/different/local", Repository.MAVEN_LOCAL.location());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResolveRepository() {
|
||||
var properties = new HierarchicalProperties();
|
||||
|
||||
assertEquals(new Repository("myrepo"), Repository.resolveRepository(properties, "myrepo"));
|
||||
assertEquals(new Repository("https://some.repo"), Repository.resolveRepository(properties, "https://some.repo"));
|
||||
|
||||
properties.put("bld.repo.therepo", "https://the.repo/is/here");
|
||||
assertEquals(new Repository("https://the.repo/is/here"), Repository.resolveRepository(properties, "therepo"));
|
||||
|
||||
properties.put("bld.repo.therepo.username", "theuser");
|
||||
assertEquals(new Repository("https://the.repo/is/here", "theuser", null), Repository.resolveRepository(properties, "therepo"));
|
||||
|
||||
properties.put("bld.repo.therepo.password", "thepassword");
|
||||
assertEquals(new Repository("https://the.repo/is/here", "theuser", "thepassword"), Repository.resolveRepository(properties, "therepo"));
|
||||
}
|
||||
}
|
148
src/test/java/rife/bld/dependencies/TestVersionNumber.java
Normal file
148
src/test/java/rife/bld/dependencies/TestVersionNumber.java
Normal file
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.dependencies;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestVersionNumber {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var version1 = new VersionNumber(1);
|
||||
var version10 = new VersionNumber(1, 0);
|
||||
var version100 = new VersionNumber(1, 0, 0);
|
||||
var version100s = new VersionNumber(1, 0, 0, "SNAPSHOT");
|
||||
assertEquals("1", version1.toString());
|
||||
assertEquals("1.0", version10.toString());
|
||||
assertEquals("1.0.0", version100.toString());
|
||||
assertEquals("1.0.0-SNAPSHOT", version100s.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testParsing() {
|
||||
assertEquals(VersionNumber.parse("1"), new VersionNumber(1, 0, 0, null));
|
||||
assertEquals(VersionNumber.parse("1.0"), new VersionNumber(1, 0, 0, null));
|
||||
assertEquals(VersionNumber.parse("1.0.0"), new VersionNumber(1, 0, 0, null));
|
||||
|
||||
assertEquals(VersionNumber.parse("1.2"), new VersionNumber(1, 2, 0, null));
|
||||
assertEquals(VersionNumber.parse("1.2.3"), new VersionNumber(1, 2, 3, null));
|
||||
|
||||
assertEquals(VersionNumber.parse("1-rc1-SNAPSHOT"), new VersionNumber(1, 0, 0, "rc1-SNAPSHOT"));
|
||||
assertEquals(VersionNumber.parse("1.2-rc1-SNAPSHOT"), new VersionNumber(1, 2, 0, "rc1-SNAPSHOT"));
|
||||
assertEquals(VersionNumber.parse("1.2.3-rc1-SNAPSHOT"), new VersionNumber(1, 2, 3, "rc1-SNAPSHOT"));
|
||||
|
||||
assertEquals(VersionNumber.parse("11.22"), new VersionNumber(11, 22, 0, null));
|
||||
assertEquals(VersionNumber.parse("11.22.33"), new VersionNumber(11, 22, 33, null));
|
||||
assertEquals(VersionNumber.parse("11.22.33-eap"), new VersionNumber(11, 22, 33, "eap"));
|
||||
|
||||
assertEquals(VersionNumber.parse("11.fortyfour"), new VersionNumber(11, 0, 0, "fortyfour"));
|
||||
|
||||
assertEquals(VersionNumber.parse("1.0.0.0"), new VersionNumber(1, 0, 0, "0"));
|
||||
assertEquals(VersionNumber.parse("1.0.0.0.0.0.0"), new VersionNumber(1, 0, 0, "0.0.0.0"));
|
||||
assertEquals(VersionNumber.parse("1.2.3.4-rc1-SNAPSHOT"), new VersionNumber(1, 2, 3, "4-rc1-SNAPSHOT"));
|
||||
assertEquals(VersionNumber.parse("1.2.3.4.rc1-SNAPSHOT"), new VersionNumber(1, 2, 3, "4.rc1-SNAPSHOT"));
|
||||
|
||||
assertEquals(VersionNumber.parse("1.2.3_4"), new VersionNumber(1, 2, 0, "3_4"));
|
||||
assertEquals(VersionNumber.parse("1.54b"), new VersionNumber(1, 0, 0, "54b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIsSnapshot() {
|
||||
assertFalse(new VersionNumber(1, 0, 0, null).isSnapshot());
|
||||
assertFalse(new VersionNumber(1, 2, 3, null).isSnapshot());
|
||||
assertTrue(new VersionNumber(1, 0, 0, "rc1-SNAPSHOT").isSnapshot());
|
||||
assertTrue(new VersionNumber(1, 2, 0, "rc1-SNAPSHOT").isSnapshot());
|
||||
assertTrue(new VersionNumber(1, 2, 3, "rc1-SNAPSHOT").isSnapshot());
|
||||
assertFalse(new VersionNumber(11, 22, 33, "eap").isSnapshot());
|
||||
assertFalse(new VersionNumber(11, 0, 0, "fortyfour").isSnapshot());
|
||||
assertTrue(new VersionNumber(1, 2, 3, "4-rc1-SNAPSHOT").isSnapshot());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidParsed() {
|
||||
assertEquals(VersionNumber.parse(null), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse(""), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse("foo"), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse("1."), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse("1.2.3-"), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse("."), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse("_"), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse("-"), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse(".1"), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse("a.1"), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse("1_2"), VersionNumber.UNKNOWN);
|
||||
assertEquals(VersionNumber.parse("1_2_2"), VersionNumber.UNKNOWN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAccessors() {
|
||||
var version = new VersionNumber(1, 2, 3, "beta");
|
||||
|
||||
assertEquals(1, version.major());
|
||||
assertEquals(2, version.minor());
|
||||
assertEquals(3, version.revision());
|
||||
assertEquals("beta", version.qualifier());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringRepresentation() {
|
||||
assertEquals(VersionNumber.parse("1.0").toString(), "1.0");
|
||||
assertEquals(VersionNumber.parse("1.2.3").toString(), "1.2.3");
|
||||
assertEquals(VersionNumber.parse("1.2.3-4").toString(), "1.2.3-4");
|
||||
assertEquals(VersionNumber.parse("1.2.3.4").toString(), "1.2.3.4");
|
||||
assertEquals(VersionNumber.parse("1-rc-1").toString(), "1-rc-1");
|
||||
assertEquals(VersionNumber.parse("1.2.3-rc-1").toString(), "1.2.3-rc-1");
|
||||
assertEquals(VersionNumber.parse("1.2.3.rc-1").toString(), "1.2.3.rc-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEquality() {
|
||||
var version = new VersionNumber(1, 1, 1, null);
|
||||
var qualified = new VersionNumber(1, 1, 1, "beta-2");
|
||||
|
||||
assertEquals(new VersionNumber(1, 1, 1, null), version);
|
||||
assertNotEquals(new VersionNumber(2, 1, 1, null), version);
|
||||
assertNotEquals(new VersionNumber(1, 2, 1, null), version);
|
||||
assertNotEquals(new VersionNumber(1, 1, 2, null), version);
|
||||
assertNotEquals(new VersionNumber(1, 1, 1, "rc"), version);
|
||||
assertEquals(new VersionNumber(1, 1, 1, "beta-2"), qualified);
|
||||
assertNotEquals(new VersionNumber(1, 1, 1, "beta-3"), qualified);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComparison() {
|
||||
assertEquals(0, new VersionNumber(1, 1, 1, null).compareTo(new VersionNumber(1, 1, 1, null)));
|
||||
|
||||
assertTrue(new VersionNumber(2, 1, 1, null).compareTo(new VersionNumber(1, 1, 1, null)) > 0);
|
||||
assertTrue(new VersionNumber(1, 2, 1, null).compareTo(new VersionNumber(1, 1, 1, null)) > 0);
|
||||
assertTrue(new VersionNumber(1, 1, 2, null).compareTo(new VersionNumber(1, 1, 1, null)) > 0);
|
||||
|
||||
assertTrue(new VersionNumber(1, 1, 1, "rc").compareTo(new VersionNumber(1, 1, 1, null)) < 0);
|
||||
assertTrue(new VersionNumber(1, 1, 1, "beta").compareTo(new VersionNumber(1, 1, 1, "alpha")) > 0);
|
||||
assertTrue(new VersionNumber(1, 1, 1, "RELEASE").compareTo(new VersionNumber(1, 1, 1, "beta")) > 0);
|
||||
assertTrue(new VersionNumber(1, 1, 1, "SNAPSHOT").compareTo(new VersionNumber(1, 1, 1, null)) < 0);
|
||||
|
||||
assertTrue(new VersionNumber(1, 1, 1, null).compareTo(new VersionNumber(2, 1, 1, null)) < 0);
|
||||
assertTrue(new VersionNumber(1, 1, 1, null).compareTo(new VersionNumber(1, 2, 1, null)) < 0);
|
||||
assertTrue(new VersionNumber(1, 1, 1, null).compareTo(new VersionNumber(1, 1, 2, null)) < 0);
|
||||
assertTrue(new VersionNumber(1, 1, 1, null).compareTo(new VersionNumber(1, 1, 1, "rc")) > 0);
|
||||
assertTrue(new VersionNumber(1, 1, 1, "alpha").compareTo(new VersionNumber(1, 1, 1, "beta")) < 0);
|
||||
assertTrue(new VersionNumber(1, 1, 1, "beta").compareTo(new VersionNumber(1, 1, 1, "RELEASE")) < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBaseVersion() {
|
||||
assertEquals(new VersionNumber(1, 2, 3, null).getBaseVersion(), new VersionNumber(1, 2, 3, null));
|
||||
assertEquals(new VersionNumber(1, 2, 3, "beta").getBaseVersion(), new VersionNumber(1, 2, 3, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWithQualifier() {
|
||||
assertEquals(new VersionNumber(1, 2, 3, null).withQualifier("SNAPSHOT"), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
assertEquals(new VersionNumber(1, 2, 3, "beta").withQualifier("SNAPSHOT"), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
assertEquals(new VersionNumber(1, 2, 4, "beta").withQualifier(null), new VersionNumber(1, 2, 4, null));
|
||||
}
|
||||
}
|
161
src/test/java/rife/bld/operations/TestCleanOperation.java
Normal file
161
src/test/java/rife/bld/operations/TestCleanOperation.java
Normal file
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* 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.bld.WebProject;
|
||||
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 TestCleanOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new CleanOperation();
|
||||
assertTrue(operation.directories().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var dir1 = new File("dir1");
|
||||
var dir2 = new File("dir2");
|
||||
var dir3 = new File("dir3");
|
||||
|
||||
var operation1 = new CleanOperation();
|
||||
operation1.directories(List.of(dir1, dir2, dir3));
|
||||
assertFalse(operation1.directories().isEmpty());
|
||||
assertTrue(operation1.directories().contains(dir1));
|
||||
assertTrue(operation1.directories().contains(dir2));
|
||||
assertTrue(operation1.directories().contains(dir3));
|
||||
|
||||
var operation2 = new CleanOperation();
|
||||
operation2.directories().add(dir1);
|
||||
operation2.directories().add(dir2);
|
||||
operation2.directories().add(dir3);
|
||||
assertFalse(operation2.directories().isEmpty());
|
||||
assertTrue(operation2.directories().contains(dir1));
|
||||
assertTrue(operation2.directories().contains(dir2));
|
||||
assertTrue(operation2.directories().contains(dir3));
|
||||
|
||||
var operation3 = new CleanOperation();
|
||||
operation3.directories(dir1, dir2, dir3);
|
||||
assertFalse(operation3.directories().isEmpty());
|
||||
assertTrue(operation3.directories().contains(dir1));
|
||||
assertTrue(operation3.directories().contains(dir2));
|
||||
assertTrue(operation3.directories().contains(dir3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var dir1 = new File(tmp, "dir1");
|
||||
var dir2 = new File(tmp, "dir2");
|
||||
var dir3 = new File(tmp, "dir3");
|
||||
dir1.mkdirs();
|
||||
dir2.mkdirs();
|
||||
dir3.mkdirs();
|
||||
|
||||
var file1 = new File(dir1, "file1");
|
||||
var file2 = new File(dir2, "file2");
|
||||
var file3 = new File(dir3, "file3");
|
||||
file1.createNewFile();
|
||||
file2.createNewFile();
|
||||
file3.createNewFile();
|
||||
|
||||
FileUtils.writeString("content1", file1);
|
||||
FileUtils.writeString("content2", file2);
|
||||
FileUtils.writeString("content3", file3);
|
||||
|
||||
assertEquals(1, dir1.list().length);
|
||||
assertEquals(1, dir2.list().length);
|
||||
assertEquals(1, dir3.list().length);
|
||||
|
||||
new CleanOperation().directories(List.of(dir1, dir2)).execute();
|
||||
|
||||
assertFalse(dir1.exists());
|
||||
assertFalse(dir2.exists());
|
||||
assertTrue(dir3.exists());
|
||||
|
||||
assertEquals(1, dir3.list().length);
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static class TestProject extends WebProject {
|
||||
public TestProject(File tmp) {
|
||||
workDirectory = tmp;
|
||||
pkg = "test.pkg";
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var project = new TestProject(tmp);
|
||||
|
||||
project.createProjectStructure();
|
||||
project.createBuildStructure();
|
||||
assertEquals("""
|
||||
/build
|
||||
/build/bld
|
||||
/build/dist
|
||||
/build/javadoc
|
||||
/build/main
|
||||
/build/test
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/compile
|
||||
/lib/runtime
|
||||
/lib/standalone
|
||||
/lib/test
|
||||
/src
|
||||
/src/bld
|
||||
/src/bld/java
|
||||
/src/bld/resources
|
||||
/src/main
|
||||
/src/main/java
|
||||
/src/main/resources
|
||||
/src/main/resources/templates
|
||||
/src/test
|
||||
/src/test/java
|
||||
/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
new CleanOperation().fromProject(project).execute();
|
||||
assertEquals("""
|
||||
/build
|
||||
/build/bld
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/compile
|
||||
/lib/runtime
|
||||
/lib/standalone
|
||||
/lib/test
|
||||
/src
|
||||
/src/bld
|
||||
/src/bld/java
|
||||
/src/bld/resources
|
||||
/src/main
|
||||
/src/main/java
|
||||
/src/main/resources
|
||||
/src/main/resources/templates
|
||||
/src/test
|
||||
/src/test/java
|
||||
/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
321
src/test/java/rife/bld/operations/TestCompileOperation.java
Normal file
321
src/test/java/rife/bld/operations/TestCompileOperation.java
Normal file
|
@ -0,0 +1,321 @@
|
|||
/*
|
||||
* 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.bld.operations.exceptions.ExitStatusException;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import javax.tools.DiagnosticCollector;
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestCompileOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new CompileOperation();
|
||||
assertNull(operation.buildMainDirectory());
|
||||
assertNull(operation.buildTestDirectory());
|
||||
assertTrue(operation.compileMainClasspath().isEmpty());
|
||||
assertTrue(operation.compileTestClasspath().isEmpty());
|
||||
assertTrue(operation.mainSourceFiles().isEmpty());
|
||||
assertTrue(operation.testSourceFiles().isEmpty());
|
||||
assertTrue(operation.testSourceDirectories().isEmpty());
|
||||
assertTrue(operation.testSourceDirectories().isEmpty());
|
||||
assertTrue(operation.compileOptions().isEmpty());
|
||||
assertTrue(operation.diagnostics().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var build_main_directory = new File("buildMainDirectory");
|
||||
var build_test_directory = new File("buildTestDirectory");
|
||||
var compile_main_classpath1 = "compileMainClasspath1";
|
||||
var compile_main_classpath2 = "compileMainClasspath2";
|
||||
var compile_test_classpath1 = "compileTestClasspath1";
|
||||
var compile_test_classpath2 = "compileTestClasspath2";
|
||||
var main_source_file1 = new File("mainSourceFile1");
|
||||
var main_source_file2 = new File("mainSourceFile2");
|
||||
var test_source_file1 = new File("testSourceFile1");
|
||||
var test_source_file2 = new File("testSourceFile2");
|
||||
var main_source_directory1 = new File("mainSourceDirectory1");
|
||||
var main_source_directory2 = new File("mainSourceDirectory2");
|
||||
var test_source_directory1 = new File("testSourceDirectory1");
|
||||
var test_source_directory2 = new File("testSourceDirectory2");
|
||||
var compile_option1 = "compileOption1";
|
||||
var compile_option2 = "compileOption2";
|
||||
|
||||
var operation1 = new CompileOperation()
|
||||
.buildMainDirectory(build_main_directory)
|
||||
.buildTestDirectory(build_test_directory)
|
||||
.compileMainClasspath(List.of(compile_main_classpath1, compile_main_classpath2))
|
||||
.compileTestClasspath(List.of(compile_test_classpath1, compile_test_classpath2))
|
||||
.mainSourceFiles(List.of(main_source_file1, main_source_file2))
|
||||
.testSourceFiles(List.of(test_source_file1, test_source_file2))
|
||||
.mainSourceDirectories(List.of(main_source_directory1, main_source_directory2))
|
||||
.testSourceDirectories(List.of(test_source_directory1, test_source_directory2))
|
||||
.compileOptions(List.of(compile_option1, compile_option2));
|
||||
|
||||
assertEquals(build_main_directory, operation1.buildMainDirectory());
|
||||
assertEquals(build_test_directory, operation1.buildTestDirectory());
|
||||
assertTrue(operation1.compileMainClasspath().contains(compile_main_classpath1));
|
||||
assertTrue(operation1.compileMainClasspath().contains(compile_main_classpath2));
|
||||
assertTrue(operation1.compileTestClasspath().contains(compile_test_classpath1));
|
||||
assertTrue(operation1.compileTestClasspath().contains(compile_test_classpath2));
|
||||
assertTrue(operation1.mainSourceFiles().contains(main_source_file1));
|
||||
assertTrue(operation1.mainSourceFiles().contains(main_source_file2));
|
||||
assertTrue(operation1.testSourceFiles().contains(test_source_file1));
|
||||
assertTrue(operation1.testSourceFiles().contains(test_source_file2));
|
||||
assertTrue(operation1.mainSourceDirectories().contains(main_source_directory1));
|
||||
assertTrue(operation1.mainSourceDirectories().contains(main_source_directory2));
|
||||
assertTrue(operation1.testSourceDirectories().contains(test_source_directory1));
|
||||
assertTrue(operation1.testSourceDirectories().contains(test_source_directory2));
|
||||
assertTrue(operation1.compileOptions().contains(compile_option1));
|
||||
assertTrue(operation1.compileOptions().contains(compile_option2));
|
||||
|
||||
var operation2 = new CompileOperation()
|
||||
.buildMainDirectory(build_main_directory)
|
||||
.buildTestDirectory(build_test_directory);
|
||||
operation2.compileMainClasspath().add(compile_main_classpath1);
|
||||
operation2.compileMainClasspath().add(compile_main_classpath2);
|
||||
operation2.compileTestClasspath().add(compile_test_classpath1);
|
||||
operation2.compileTestClasspath().add(compile_test_classpath2);
|
||||
operation2.mainSourceFiles().add(main_source_file1);
|
||||
operation2.mainSourceFiles().add(main_source_file2);
|
||||
operation2.testSourceFiles().add(test_source_file1);
|
||||
operation2.testSourceFiles().add(test_source_file2);
|
||||
operation2.mainSourceDirectories().add(main_source_directory1);
|
||||
operation2.mainSourceDirectories().add(main_source_directory2);
|
||||
operation2.testSourceDirectories().add(test_source_directory1);
|
||||
operation2.testSourceDirectories().add(test_source_directory2);
|
||||
operation2.compileOptions().add(compile_option1);
|
||||
operation2.compileOptions().add(compile_option2);
|
||||
|
||||
assertEquals(build_main_directory, operation2.buildMainDirectory());
|
||||
assertEquals(build_test_directory, operation2.buildTestDirectory());
|
||||
assertTrue(operation2.compileMainClasspath().contains(compile_main_classpath1));
|
||||
assertTrue(operation2.compileMainClasspath().contains(compile_main_classpath2));
|
||||
assertTrue(operation2.compileTestClasspath().contains(compile_test_classpath1));
|
||||
assertTrue(operation2.compileTestClasspath().contains(compile_test_classpath2));
|
||||
assertTrue(operation2.mainSourceFiles().contains(main_source_file1));
|
||||
assertTrue(operation2.mainSourceFiles().contains(main_source_file2));
|
||||
assertTrue(operation2.testSourceFiles().contains(test_source_file1));
|
||||
assertTrue(operation2.testSourceFiles().contains(test_source_file2));
|
||||
assertTrue(operation2.mainSourceDirectories().contains(main_source_directory1));
|
||||
assertTrue(operation2.mainSourceDirectories().contains(main_source_directory2));
|
||||
assertTrue(operation2.testSourceDirectories().contains(test_source_directory1));
|
||||
assertTrue(operation2.testSourceDirectories().contains(test_source_directory2));
|
||||
assertTrue(operation2.compileOptions().contains(compile_option1));
|
||||
assertTrue(operation2.compileOptions().contains(compile_option2));
|
||||
|
||||
var operation3 = new CompileOperation()
|
||||
.buildMainDirectory(build_main_directory)
|
||||
.buildTestDirectory(build_test_directory)
|
||||
.compileMainClasspath(compile_main_classpath1, compile_main_classpath2)
|
||||
.compileTestClasspath(compile_test_classpath1, compile_test_classpath2)
|
||||
.mainSourceFiles(main_source_file1, main_source_file2)
|
||||
.testSourceFiles(test_source_file1, test_source_file2)
|
||||
.mainSourceDirectories(main_source_directory1, main_source_directory2)
|
||||
.testSourceDirectories(test_source_directory1, test_source_directory2)
|
||||
.compileOptions(List.of(compile_option1, compile_option2));
|
||||
|
||||
assertEquals(build_main_directory, operation3.buildMainDirectory());
|
||||
assertEquals(build_test_directory, operation3.buildTestDirectory());
|
||||
assertTrue(operation3.compileMainClasspath().contains(compile_main_classpath1));
|
||||
assertTrue(operation3.compileMainClasspath().contains(compile_main_classpath2));
|
||||
assertTrue(operation3.compileTestClasspath().contains(compile_test_classpath1));
|
||||
assertTrue(operation3.compileTestClasspath().contains(compile_test_classpath2));
|
||||
assertTrue(operation3.mainSourceFiles().contains(main_source_file1));
|
||||
assertTrue(operation3.mainSourceFiles().contains(main_source_file2));
|
||||
assertTrue(operation3.testSourceFiles().contains(test_source_file1));
|
||||
assertTrue(operation3.testSourceFiles().contains(test_source_file2));
|
||||
assertTrue(operation3.mainSourceDirectories().contains(main_source_directory1));
|
||||
assertTrue(operation3.mainSourceDirectories().contains(main_source_directory2));
|
||||
assertTrue(operation3.testSourceDirectories().contains(test_source_directory1));
|
||||
assertTrue(operation3.testSourceDirectories().contains(test_source_directory2));
|
||||
assertTrue(operation3.compileOptions().contains(compile_option1));
|
||||
assertTrue(operation3.compileOptions().contains(compile_option2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var source_file1 = new File(tmp, "Source1.java");
|
||||
var source_file2 = new File(tmp, "Source2.java");
|
||||
var source_file3 = new File(tmp, "Source3.java");
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source1 {
|
||||
public final String name_;
|
||||
public Source1() {
|
||||
name_ = "source1";
|
||||
}
|
||||
}
|
||||
""", source_file1);
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source2 {
|
||||
public final String name_;
|
||||
public Source2(Source1 source1) {
|
||||
name_ = source1.name_;
|
||||
}
|
||||
}
|
||||
""", source_file2);
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source3 {
|
||||
public final String name1_;
|
||||
public final String name2_;
|
||||
public Source3(Source1 source1, Source2 source2) {
|
||||
name1_ = source1.name_;
|
||||
name2_ = source2.name_;
|
||||
}
|
||||
}
|
||||
""", source_file3);
|
||||
var build_main = new File(tmp, "buildMain");
|
||||
var build_test = new File(tmp, "buildTest");
|
||||
var build_main_class1 = new File(build_main, "Source1.class");
|
||||
var build_main_class2 = new File(build_main, "Source2.class");
|
||||
var build_test_class3 = new File(build_test, "Source3.class");
|
||||
|
||||
assertFalse(build_main_class1.exists());
|
||||
assertFalse(build_main_class2.exists());
|
||||
assertFalse(build_test_class3.exists());
|
||||
|
||||
var operation = new CompileOperation()
|
||||
.buildMainDirectory(build_main)
|
||||
.buildTestDirectory(build_test)
|
||||
.compileMainClasspath(List.of(build_main.getAbsolutePath()))
|
||||
.compileTestClasspath(List.of(build_main.getAbsolutePath(), build_test.getAbsolutePath()))
|
||||
.mainSourceFiles(List.of(source_file1, source_file2))
|
||||
.testSourceFiles(List.of(source_file3));
|
||||
operation.execute();
|
||||
assertTrue(operation.diagnostics().isEmpty());
|
||||
|
||||
assertTrue(build_main_class1.exists());
|
||||
assertTrue(build_main_class2.exists());
|
||||
assertTrue(build_test_class3.exists());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("tst")
|
||||
.projectName("app")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
var compile_operation = new CompileOperation()
|
||||
.fromProject(create_operation.project());
|
||||
|
||||
var main_app_class = new File(new File(compile_operation.buildMainDirectory(), "tst"), "AppMain.class");
|
||||
var test_app_class = new File(new File(compile_operation.buildTestDirectory(), "tst"), "AppTest.class");
|
||||
assertFalse(main_app_class.exists());
|
||||
assertFalse(test_app_class.exists());
|
||||
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
|
||||
assertTrue(main_app_class.exists());
|
||||
assertTrue(test_app_class.exists());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteCompilationErrors()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var source_file1 = new File(tmp, "Source1.java");
|
||||
var source_file2 = new File(tmp, "Source2.java");
|
||||
var source_file3 = new File(tmp, "Source3.java");
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source1 {
|
||||
public final String;
|
||||
public Source1() {
|
||||
name_ = "source1";
|
||||
}
|
||||
}
|
||||
""", source_file1);
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source2 {
|
||||
public final String name_;
|
||||
public Source2(Source1B source1) {
|
||||
noName_ = source1.name_;
|
||||
}
|
||||
}
|
||||
""", source_file2);
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source3 {
|
||||
public final String name1_;
|
||||
public final String name2_;
|
||||
public Source3(Source1 source1, Source2 source2) {
|
||||
name_ = source1.name_;
|
||||
name_ = source2.name_;
|
||||
}
|
||||
}
|
||||
""", source_file3);
|
||||
var build_main = new File(tmp, "buildMain");
|
||||
var build_test = new File(tmp, "buildTest");
|
||||
var build_main_class1 = new File(build_main, "Source1.class");
|
||||
var build_main_class2 = new File(build_main, "Source2.class");
|
||||
var build_test_class3 = new File(build_test, "Source3.class");
|
||||
|
||||
assertFalse(build_main_class1.exists());
|
||||
assertFalse(build_main_class2.exists());
|
||||
assertFalse(build_test_class3.exists());
|
||||
|
||||
var operation = new CompileOperation() {
|
||||
public void executeProcessDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics) {
|
||||
// don't output diagnostics
|
||||
}
|
||||
};
|
||||
operation.buildMainDirectory(build_main)
|
||||
.buildTestDirectory(build_test)
|
||||
.compileMainClasspath(List.of(build_main.getAbsolutePath()))
|
||||
.compileTestClasspath(List.of(build_main.getAbsolutePath(), build_test.getAbsolutePath()))
|
||||
.mainSourceFiles(List.of(source_file1, source_file2))
|
||||
.testSourceFiles(List.of(source_file3));
|
||||
assertThrows(ExitStatusException.class, operation::execute);
|
||||
assertEquals(5, operation.diagnostics().size());
|
||||
|
||||
var diagnostic1 = operation.diagnostics().get(0);
|
||||
var diagnostic2 = operation.diagnostics().get(1);
|
||||
var diagnostic3 = operation.diagnostics().get(2);
|
||||
var diagnostic4 = operation.diagnostics().get(3);
|
||||
var diagnostic5 = operation.diagnostics().get(4);
|
||||
|
||||
assertEquals("/Source1.java", diagnostic1.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
|
||||
assertEquals("/Source3.java", diagnostic2.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
|
||||
assertEquals("/Source3.java", diagnostic3.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
|
||||
assertEquals("/Source3.java", diagnostic4.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
|
||||
assertEquals("/Source3.java", diagnostic5.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
|
||||
|
||||
assertFalse(build_main_class1.exists());
|
||||
assertFalse(build_main_class2.exists());
|
||||
assertFalse(build_test_class3.exists());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
332
src/test/java/rife/bld/operations/TestCreateBaseOperation.java
Normal file
332
src/test/java/rife/bld/operations/TestCreateBaseOperation.java
Normal file
|
@ -0,0 +1,332 @@
|
|||
/*
|
||||
* 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.bld.dependencies.LocalDependency;
|
||||
import rife.bld.dependencies.Scope;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import javax.tools.DiagnosticCollector;
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestCreateBaseOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new CreateBaseOperation();
|
||||
assertNotNull(operation.workDirectory());
|
||||
assertTrue(operation.workDirectory().exists());
|
||||
assertTrue(operation.workDirectory().isDirectory());
|
||||
assertTrue(operation.workDirectory().canWrite());
|
||||
assertFalse(operation.downloadDependencies());
|
||||
assertNull(operation.packageName());
|
||||
assertNull(operation.projectName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation()
|
||||
throws Exception {
|
||||
var work_directory = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var download_dependencies = true;
|
||||
var package_name = "packageName";
|
||||
var project_name = "projectName";
|
||||
|
||||
var operation = new CreateBaseOperation();
|
||||
operation
|
||||
.workDirectory(work_directory)
|
||||
.downloadDependencies(download_dependencies)
|
||||
.packageName(package_name)
|
||||
.projectName(project_name);
|
||||
|
||||
assertEquals(work_directory, operation.workDirectory());
|
||||
assertEquals(download_dependencies, operation.downloadDependencies());
|
||||
assertEquals(package_name, operation.packageName());
|
||||
assertEquals(project_name, operation.projectName());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(work_directory);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBaseOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("com.example")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
assertTrue(Pattern.compile("""
|
||||
/myapp
|
||||
/myapp/\\.gitignore
|
||||
/myapp/\\.idea
|
||||
/myapp/\\.idea/app\\.iml
|
||||
/myapp/\\.idea/bld\\.iml
|
||||
/myapp/\\.idea/libraries
|
||||
/myapp/\\.idea/libraries/bld\\.xml
|
||||
/myapp/\\.idea/libraries/compile\\.xml
|
||||
/myapp/\\.idea/libraries/runtime\\.xml
|
||||
/myapp/\\.idea/libraries/test\\.xml
|
||||
/myapp/\\.idea/misc\\.xml
|
||||
/myapp/\\.idea/modules\\.xml
|
||||
/myapp/\\.idea/runConfigurations
|
||||
/myapp/\\.idea/runConfigurations/Run Main\\.xml
|
||||
/myapp/\\.idea/runConfigurations/Run Tests\\.xml
|
||||
/myapp/\\.vscode
|
||||
/myapp/\\.vscode/launch\\.json
|
||||
/myapp/\\.vscode/settings\\.json
|
||||
/myapp/bld
|
||||
/myapp/bld\\.bat
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper\\.jar
|
||||
/myapp/lib/bld/bld-wrapper\\.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/test
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild\\.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappMain\\.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest\\.java
|
||||
/myapp/src/test/resources""").matcher(FileUtils.generateDirectoryListing(tmp)).matches());
|
||||
|
||||
var compile_operation = new CompileOperation().fromProject(create_operation.project());
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
assertTrue(Pattern.compile("""
|
||||
/myapp
|
||||
/myapp/\\.gitignore
|
||||
/myapp/\\.idea
|
||||
/myapp/\\.idea/app\\.iml
|
||||
/myapp/\\.idea/bld\\.iml
|
||||
/myapp/\\.idea/libraries
|
||||
/myapp/\\.idea/libraries/bld\\.xml
|
||||
/myapp/\\.idea/libraries/compile\\.xml
|
||||
/myapp/\\.idea/libraries/runtime\\.xml
|
||||
/myapp/\\.idea/libraries/test\\.xml
|
||||
/myapp/\\.idea/misc\\.xml
|
||||
/myapp/\\.idea/modules\\.xml
|
||||
/myapp/\\.idea/runConfigurations
|
||||
/myapp/\\.idea/runConfigurations/Run Main\\.xml
|
||||
/myapp/\\.idea/runConfigurations/Run Tests\\.xml
|
||||
/myapp/\\.vscode
|
||||
/myapp/\\.vscode/launch\\.json
|
||||
/myapp/\\.vscode/settings\\.json
|
||||
/myapp/bld
|
||||
/myapp/bld\\.bat
|
||||
/myapp/build
|
||||
/myapp/build/main
|
||||
/myapp/build/main/com
|
||||
/myapp/build/main/com/example
|
||||
/myapp/build/main/com/example/MyappMain\\.class
|
||||
/myapp/build/test
|
||||
/myapp/build/test/com
|
||||
/myapp/build/test/com/example
|
||||
/myapp/build/test/com/example/MyappTest\\.class
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper\\.jar
|
||||
/myapp/lib/bld/bld-wrapper\\.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/test
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild\\.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappMain\\.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest\\.java
|
||||
/myapp/src/test/resources""").matcher(FileUtils.generateDirectoryListing(tmp)).matches());
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
new RunOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.outputProcessor(s -> {
|
||||
check_result.append(s);
|
||||
return true;
|
||||
})
|
||||
.execute();
|
||||
assertEquals("Hello World!", check_result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteNoDownload()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBaseOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("org.stuff")
|
||||
.projectName("yourthing");
|
||||
create_operation.execute();
|
||||
|
||||
assertEquals("""
|
||||
/yourthing
|
||||
/yourthing/.gitignore
|
||||
/yourthing/.idea
|
||||
/yourthing/.idea/app.iml
|
||||
/yourthing/.idea/bld.iml
|
||||
/yourthing/.idea/libraries
|
||||
/yourthing/.idea/libraries/bld.xml
|
||||
/yourthing/.idea/libraries/compile.xml
|
||||
/yourthing/.idea/libraries/runtime.xml
|
||||
/yourthing/.idea/libraries/test.xml
|
||||
/yourthing/.idea/misc.xml
|
||||
/yourthing/.idea/modules.xml
|
||||
/yourthing/.idea/runConfigurations
|
||||
/yourthing/.idea/runConfigurations/Run Main.xml
|
||||
/yourthing/.idea/runConfigurations/Run Tests.xml
|
||||
/yourthing/.vscode
|
||||
/yourthing/.vscode/launch.json
|
||||
/yourthing/.vscode/settings.json
|
||||
/yourthing/bld
|
||||
/yourthing/bld.bat
|
||||
/yourthing/lib
|
||||
/yourthing/lib/bld
|
||||
/yourthing/lib/bld/bld-wrapper.jar
|
||||
/yourthing/lib/bld/bld-wrapper.properties
|
||||
/yourthing/lib/compile
|
||||
/yourthing/lib/runtime
|
||||
/yourthing/lib/test
|
||||
/yourthing/src
|
||||
/yourthing/src/bld
|
||||
/yourthing/src/bld/java
|
||||
/yourthing/src/bld/java/org
|
||||
/yourthing/src/bld/java/org/stuff
|
||||
/yourthing/src/bld/java/org/stuff/YourthingBuild.java
|
||||
/yourthing/src/bld/resources
|
||||
/yourthing/src/main
|
||||
/yourthing/src/main/java
|
||||
/yourthing/src/main/java/org
|
||||
/yourthing/src/main/java/org/stuff
|
||||
/yourthing/src/main/java/org/stuff/YourthingMain.java
|
||||
/yourthing/src/main/resources
|
||||
/yourthing/src/main/resources/templates
|
||||
/yourthing/src/test
|
||||
/yourthing/src/test/java
|
||||
/yourthing/src/test/java/org
|
||||
/yourthing/src/test/java/org/stuff
|
||||
/yourthing/src/test/java/org/stuff/YourthingTest.java
|
||||
/yourthing/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
var compile_operation = new CompileOperation().fromProject(create_operation.project());
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
assertEquals("""
|
||||
/yourthing
|
||||
/yourthing/.gitignore
|
||||
/yourthing/.idea
|
||||
/yourthing/.idea/app.iml
|
||||
/yourthing/.idea/bld.iml
|
||||
/yourthing/.idea/libraries
|
||||
/yourthing/.idea/libraries/bld.xml
|
||||
/yourthing/.idea/libraries/compile.xml
|
||||
/yourthing/.idea/libraries/runtime.xml
|
||||
/yourthing/.idea/libraries/test.xml
|
||||
/yourthing/.idea/misc.xml
|
||||
/yourthing/.idea/modules.xml
|
||||
/yourthing/.idea/runConfigurations
|
||||
/yourthing/.idea/runConfigurations/Run Main.xml
|
||||
/yourthing/.idea/runConfigurations/Run Tests.xml
|
||||
/yourthing/.vscode
|
||||
/yourthing/.vscode/launch.json
|
||||
/yourthing/.vscode/settings.json
|
||||
/yourthing/bld
|
||||
/yourthing/bld.bat
|
||||
/yourthing/build
|
||||
/yourthing/build/main
|
||||
/yourthing/build/main/org
|
||||
/yourthing/build/main/org/stuff
|
||||
/yourthing/build/main/org/stuff/YourthingMain.class
|
||||
/yourthing/build/test
|
||||
/yourthing/build/test/org
|
||||
/yourthing/build/test/org/stuff
|
||||
/yourthing/build/test/org/stuff/YourthingTest.class
|
||||
/yourthing/lib
|
||||
/yourthing/lib/bld
|
||||
/yourthing/lib/bld/bld-wrapper.jar
|
||||
/yourthing/lib/bld/bld-wrapper.properties
|
||||
/yourthing/lib/compile
|
||||
/yourthing/lib/runtime
|
||||
/yourthing/lib/test
|
||||
/yourthing/src
|
||||
/yourthing/src/bld
|
||||
/yourthing/src/bld/java
|
||||
/yourthing/src/bld/java/org
|
||||
/yourthing/src/bld/java/org/stuff
|
||||
/yourthing/src/bld/java/org/stuff/YourthingBuild.java
|
||||
/yourthing/src/bld/resources
|
||||
/yourthing/src/main
|
||||
/yourthing/src/main/java
|
||||
/yourthing/src/main/java/org
|
||||
/yourthing/src/main/java/org/stuff
|
||||
/yourthing/src/main/java/org/stuff/YourthingMain.java
|
||||
/yourthing/src/main/resources
|
||||
/yourthing/src/main/resources/templates
|
||||
/yourthing/src/test
|
||||
/yourthing/src/test/java
|
||||
/yourthing/src/test/java/org
|
||||
/yourthing/src/test/java/org/stuff
|
||||
/yourthing/src/test/java/org/stuff/YourthingTest.java
|
||||
/yourthing/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
new RunOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.outputProcessor(s -> {
|
||||
check_result.append(s);
|
||||
return true;
|
||||
})
|
||||
.execute();
|
||||
assertEquals("Hello World!", check_result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
550
src/test/java/rife/bld/operations/TestCreateBlankOperation.java
Normal file
550
src/test/java/rife/bld/operations/TestCreateBlankOperation.java
Normal file
|
@ -0,0 +1,550 @@
|
|||
/*
|
||||
* 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.bld.dependencies.LocalDependency;
|
||||
import rife.bld.dependencies.Scope;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import javax.tools.DiagnosticCollector;
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestCreateBlankOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new CreateBlankOperation();
|
||||
assertNotNull(operation.workDirectory());
|
||||
assertTrue(operation.workDirectory().exists());
|
||||
assertTrue(operation.workDirectory().isDirectory());
|
||||
assertTrue(operation.workDirectory().canWrite());
|
||||
assertFalse(operation.downloadDependencies());
|
||||
assertNull(operation.packageName());
|
||||
assertNull(operation.projectName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation()
|
||||
throws Exception {
|
||||
var work_directory = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var download_dependencies = true;
|
||||
var package_name = "packageName";
|
||||
var project_name = "projectName";
|
||||
|
||||
var operation = new CreateBlankOperation();
|
||||
operation
|
||||
.workDirectory(work_directory)
|
||||
.downloadDependencies(download_dependencies)
|
||||
.packageName(package_name)
|
||||
.projectName(project_name);
|
||||
|
||||
assertEquals(work_directory, operation.workDirectory());
|
||||
assertEquals(download_dependencies, operation.downloadDependencies());
|
||||
assertEquals(package_name, operation.packageName());
|
||||
assertEquals(project_name, operation.projectName());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(work_directory);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("com.example")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
assertTrue(Pattern.compile("""
|
||||
/myapp
|
||||
/myapp/\\.gitignore
|
||||
/myapp/\\.idea
|
||||
/myapp/\\.idea/app\\.iml
|
||||
/myapp/\\.idea/bld\\.iml
|
||||
/myapp/\\.idea/libraries
|
||||
/myapp/\\.idea/libraries/bld\\.xml
|
||||
/myapp/\\.idea/libraries/compile\\.xml
|
||||
/myapp/\\.idea/libraries/runtime\\.xml
|
||||
/myapp/\\.idea/libraries/test\\.xml
|
||||
/myapp/\\.idea/misc\\.xml
|
||||
/myapp/\\.idea/modules\\.xml
|
||||
/myapp/\\.idea/runConfigurations
|
||||
/myapp/\\.idea/runConfigurations/Run Main\\.xml
|
||||
/myapp/\\.idea/runConfigurations/Run Tests\\.xml
|
||||
/myapp/\\.vscode
|
||||
/myapp/\\.vscode/launch\\.json
|
||||
/myapp/\\.vscode/settings\\.json
|
||||
/myapp/bld
|
||||
/myapp/bld\\.bat
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper\\.jar
|
||||
/myapp/lib/bld/bld-wrapper\\.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/test
|
||||
/myapp/lib/test/apiguardian-api-1\\.1\\.2-sources\\.jar
|
||||
/myapp/lib/test/apiguardian-api-1\\.1\\.2\\.jar
|
||||
/myapp/lib/test/junit-jupiter-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-api-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-api-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-engine-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-engine-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-params-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-params-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-commons-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-commons-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-console-standalone-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-console-standalone-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-engine-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-engine-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/opentest4j-1\\.2\\.0-sources\\.jar
|
||||
/myapp/lib/test/opentest4j-1\\.2\\.0\\.jar
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild\\.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappMain\\.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest\\.java
|
||||
/myapp/src/test/resources""").matcher(FileUtils.generateDirectoryListing(tmp)).matches());
|
||||
|
||||
var compile_operation = new CompileOperation().fromProject(create_operation.project());
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
assertTrue(Pattern.compile("""
|
||||
/myapp
|
||||
/myapp/\\.gitignore
|
||||
/myapp/\\.idea
|
||||
/myapp/\\.idea/app\\.iml
|
||||
/myapp/\\.idea/bld\\.iml
|
||||
/myapp/\\.idea/libraries
|
||||
/myapp/\\.idea/libraries/bld\\.xml
|
||||
/myapp/\\.idea/libraries/compile\\.xml
|
||||
/myapp/\\.idea/libraries/runtime\\.xml
|
||||
/myapp/\\.idea/libraries/test\\.xml
|
||||
/myapp/\\.idea/misc\\.xml
|
||||
/myapp/\\.idea/modules\\.xml
|
||||
/myapp/\\.idea/runConfigurations
|
||||
/myapp/\\.idea/runConfigurations/Run Main\\.xml
|
||||
/myapp/\\.idea/runConfigurations/Run Tests\\.xml
|
||||
/myapp/\\.vscode
|
||||
/myapp/\\.vscode/launch\\.json
|
||||
/myapp/\\.vscode/settings\\.json
|
||||
/myapp/bld
|
||||
/myapp/bld\\.bat
|
||||
/myapp/build
|
||||
/myapp/build/main
|
||||
/myapp/build/main/com
|
||||
/myapp/build/main/com/example
|
||||
/myapp/build/main/com/example/MyappMain\\.class
|
||||
/myapp/build/test
|
||||
/myapp/build/test/com
|
||||
/myapp/build/test/com/example
|
||||
/myapp/build/test/com/example/MyappTest\\.class
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper\\.jar
|
||||
/myapp/lib/bld/bld-wrapper\\.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/test
|
||||
/myapp/lib/test/apiguardian-api-1\\.1\\.2-sources\\.jar
|
||||
/myapp/lib/test/apiguardian-api-1\\.1\\.2\\.jar
|
||||
/myapp/lib/test/junit-jupiter-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-api-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-api-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-engine-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-engine-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-params-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-params-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-commons-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-commons-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-console-standalone-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-console-standalone-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-engine-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-engine-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/opentest4j-1\\.2\\.0-sources\\.jar
|
||||
/myapp/lib/test/opentest4j-1\\.2\\.0\\.jar
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild\\.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappMain\\.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest\\.java
|
||||
/myapp/src/test/resources""").matcher(FileUtils.generateDirectoryListing(tmp)).matches());
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
new RunOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.outputProcessor(s -> {
|
||||
check_result.append(s);
|
||||
return true;
|
||||
})
|
||||
.execute();
|
||||
assertEquals("Hello World!", check_result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteNoDownload()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("org.stuff")
|
||||
.projectName("yourthing");
|
||||
create_operation.execute();
|
||||
|
||||
assertEquals("""
|
||||
/yourthing
|
||||
/yourthing/.gitignore
|
||||
/yourthing/.idea
|
||||
/yourthing/.idea/app.iml
|
||||
/yourthing/.idea/bld.iml
|
||||
/yourthing/.idea/libraries
|
||||
/yourthing/.idea/libraries/bld.xml
|
||||
/yourthing/.idea/libraries/compile.xml
|
||||
/yourthing/.idea/libraries/runtime.xml
|
||||
/yourthing/.idea/libraries/test.xml
|
||||
/yourthing/.idea/misc.xml
|
||||
/yourthing/.idea/modules.xml
|
||||
/yourthing/.idea/runConfigurations
|
||||
/yourthing/.idea/runConfigurations/Run Main.xml
|
||||
/yourthing/.idea/runConfigurations/Run Tests.xml
|
||||
/yourthing/.vscode
|
||||
/yourthing/.vscode/launch.json
|
||||
/yourthing/.vscode/settings.json
|
||||
/yourthing/bld
|
||||
/yourthing/bld.bat
|
||||
/yourthing/lib
|
||||
/yourthing/lib/bld
|
||||
/yourthing/lib/bld/bld-wrapper.jar
|
||||
/yourthing/lib/bld/bld-wrapper.properties
|
||||
/yourthing/lib/compile
|
||||
/yourthing/lib/runtime
|
||||
/yourthing/lib/test
|
||||
/yourthing/src
|
||||
/yourthing/src/bld
|
||||
/yourthing/src/bld/java
|
||||
/yourthing/src/bld/java/org
|
||||
/yourthing/src/bld/java/org/stuff
|
||||
/yourthing/src/bld/java/org/stuff/YourthingBuild.java
|
||||
/yourthing/src/bld/resources
|
||||
/yourthing/src/main
|
||||
/yourthing/src/main/java
|
||||
/yourthing/src/main/java/org
|
||||
/yourthing/src/main/java/org/stuff
|
||||
/yourthing/src/main/java/org/stuff/YourthingMain.java
|
||||
/yourthing/src/main/resources
|
||||
/yourthing/src/main/resources/templates
|
||||
/yourthing/src/test
|
||||
/yourthing/src/test/java
|
||||
/yourthing/src/test/java/org
|
||||
/yourthing/src/test/java/org/stuff
|
||||
/yourthing/src/test/java/org/stuff/YourthingTest.java
|
||||
/yourthing/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
var compile_operation = new CompileOperation() {
|
||||
public void executeProcessDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics) {
|
||||
// don't output errors
|
||||
}
|
||||
};
|
||||
compile_operation.fromProject(create_operation.project());
|
||||
assertThrows(ExitStatusException.class, compile_operation::execute);
|
||||
var diagnostics = compile_operation.diagnostics();
|
||||
assertEquals(4, diagnostics.size());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteLocalDependencies()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("com.example")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
var project = create_operation.project();
|
||||
var lib_local = new File(project.libDirectory(), "local");
|
||||
lib_local.mkdirs();
|
||||
for (var lib : FileUtils.getFileList(project.libCompileDirectory())) {
|
||||
if (!lib.endsWith("-sources.jar")) {
|
||||
project.dependencies().scope(Scope.compile).include(new LocalDependency(Path.of("lib", "local", lib).toString()));
|
||||
}
|
||||
new File(project.libCompileDirectory(), lib).renameTo(new File(lib_local, lib));
|
||||
}
|
||||
for (var lib : FileUtils.getFileList(project.libTestDirectory())) {
|
||||
if (!lib.endsWith("-sources.jar")) {
|
||||
project.dependencies().scope(Scope.test).include(new LocalDependency(Path.of("lib", "local", lib).toString()));
|
||||
}
|
||||
new File(project.libTestDirectory(), lib).renameTo(new File(lib_local, lib));
|
||||
}
|
||||
|
||||
var compile_operation = new CompileOperation().fromProject(create_operation.project());
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
System.out.println(FileUtils.generateDirectoryListing(tmp));
|
||||
assertTrue(Pattern.compile("""
|
||||
/myapp
|
||||
/myapp/\\.gitignore
|
||||
/myapp/\\.idea
|
||||
/myapp/\\.idea/app\\.iml
|
||||
/myapp/\\.idea/bld\\.iml
|
||||
/myapp/\\.idea/libraries
|
||||
/myapp/\\.idea/libraries/bld\\.xml
|
||||
/myapp/\\.idea/libraries/compile\\.xml
|
||||
/myapp/\\.idea/libraries/runtime\\.xml
|
||||
/myapp/\\.idea/libraries/test\\.xml
|
||||
/myapp/\\.idea/misc\\.xml
|
||||
/myapp/\\.idea/modules\\.xml
|
||||
/myapp/\\.idea/runConfigurations
|
||||
/myapp/\\.idea/runConfigurations/Run Main\\.xml
|
||||
/myapp/\\.idea/runConfigurations/Run Tests\\.xml
|
||||
/myapp/\\.vscode
|
||||
/myapp/\\.vscode/launch\\.json
|
||||
/myapp/\\.vscode/settings\\.json
|
||||
/myapp/bld
|
||||
/myapp/bld\\.bat
|
||||
/myapp/build
|
||||
/myapp/build/main
|
||||
/myapp/build/main/com
|
||||
/myapp/build/main/com/example
|
||||
/myapp/build/main/com/example/MyappMain\\.class
|
||||
/myapp/build/test
|
||||
/myapp/build/test/com
|
||||
/myapp/build/test/com/example
|
||||
/myapp/build/test/com/example/MyappTest\\.class
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper\\.jar
|
||||
/myapp/lib/bld/bld-wrapper\\.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/local
|
||||
/myapp/lib/local/apiguardian-api-1\\.1\\.2-sources\\.jar
|
||||
/myapp/lib/local/apiguardian-api-1\\.1\\.2\\.jar
|
||||
/myapp/lib/local/junit-jupiter-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-jupiter-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-jupiter-api-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-jupiter-api-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-jupiter-engine-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-jupiter-engine-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-jupiter-params-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-jupiter-params-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-platform-commons-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-platform-commons-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-platform-console-standalone-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-platform-console-standalone-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-platform-engine-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-platform-engine-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local/opentest4j-1\\.2\\.0-sources\\.jar
|
||||
/myapp/lib/local/opentest4j-1\\.2\\.0\\.jar
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/test
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild\\.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappMain\\.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest\\.java
|
||||
/myapp/src/test/resources""").matcher(FileUtils.generateDirectoryListing(tmp)).matches());
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
new RunOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.outputProcessor(s -> {
|
||||
check_result.append(s);
|
||||
return true;
|
||||
})
|
||||
.execute();
|
||||
assertEquals("Hello World!", check_result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteLocalDependenciesFolders()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("com.example")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
var project = create_operation.project();
|
||||
var lib_local_compile = new File(project.libDirectory(), "local_compile");
|
||||
lib_local_compile.mkdirs();
|
||||
project.dependencies().scope(Scope.compile).include(new LocalDependency(Path.of("lib", "local_compile").toString()));
|
||||
for (var lib : FileUtils.getFileList(project.libCompileDirectory())) {
|
||||
new File(project.libCompileDirectory(), lib).renameTo(new File(lib_local_compile, lib));
|
||||
}
|
||||
var lib_local_test = new File(project.libDirectory(), "local_test");
|
||||
lib_local_test.mkdirs();
|
||||
project.dependencies().scope(Scope.test).include(new LocalDependency(Path.of("lib", "local_test").toString()));
|
||||
for (var lib : FileUtils.getFileList(project.libTestDirectory())) {
|
||||
new File(project.libTestDirectory(), lib).renameTo(new File(lib_local_test, lib));
|
||||
}
|
||||
|
||||
var compile_operation = new CompileOperation().fromProject(create_operation.project());
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
assertTrue(Pattern.compile("""
|
||||
/myapp
|
||||
/myapp/\\.gitignore
|
||||
/myapp/\\.idea
|
||||
/myapp/\\.idea/app\\.iml
|
||||
/myapp/\\.idea/bld\\.iml
|
||||
/myapp/\\.idea/libraries
|
||||
/myapp/\\.idea/libraries/bld\\.xml
|
||||
/myapp/\\.idea/libraries/compile\\.xml
|
||||
/myapp/\\.idea/libraries/runtime\\.xml
|
||||
/myapp/\\.idea/libraries/test\\.xml
|
||||
/myapp/\\.idea/misc\\.xml
|
||||
/myapp/\\.idea/modules\\.xml
|
||||
/myapp/\\.idea/runConfigurations
|
||||
/myapp/\\.idea/runConfigurations/Run Main\\.xml
|
||||
/myapp/\\.idea/runConfigurations/Run Tests\\.xml
|
||||
/myapp/\\.vscode
|
||||
/myapp/\\.vscode/launch\\.json
|
||||
/myapp/\\.vscode/settings\\.json
|
||||
/myapp/bld
|
||||
/myapp/bld\\.bat
|
||||
/myapp/build
|
||||
/myapp/build/main
|
||||
/myapp/build/main/com
|
||||
/myapp/build/main/com/example
|
||||
/myapp/build/main/com/example/MyappMain\\.class
|
||||
/myapp/build/test
|
||||
/myapp/build/test/com
|
||||
/myapp/build/test/com/example
|
||||
/myapp/build/test/com/example/MyappTest\\.class
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper\\.jar
|
||||
/myapp/lib/bld/bld-wrapper\\.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/local_compile
|
||||
/myapp/lib/local_test
|
||||
/myapp/lib/local_test/apiguardian-api-1\\.1\\.2-sources\\.jar
|
||||
/myapp/lib/local_test/apiguardian-api-1\\.1\\.2\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-api-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-api-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-engine-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-engine-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-params-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-params-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-platform-commons-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-platform-commons-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-platform-console-standalone-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-platform-console-standalone-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-platform-engine-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-platform-engine-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/opentest4j-1\\.2\\.0-sources\\.jar
|
||||
/myapp/lib/local_test/opentest4j-1\\.2\\.0\\.jar
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/test
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild\\.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappMain\\.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest\\.java
|
||||
/myapp/src/test/resources""").matcher(FileUtils.generateDirectoryListing(tmp)).matches());
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
new RunOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.outputProcessor(s -> {
|
||||
check_result.append(s);
|
||||
return true;
|
||||
})
|
||||
.execute();
|
||||
assertEquals("Hello World!", check_result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
327
src/test/java/rife/bld/operations/TestCreateLibOperation.java
Normal file
327
src/test/java/rife/bld/operations/TestCreateLibOperation.java
Normal file
|
@ -0,0 +1,327 @@
|
|||
/*
|
||||
* 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.bld.dependencies.LocalDependency;
|
||||
import rife.bld.dependencies.Scope;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestCreateLibOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new CreateLibOperation();
|
||||
assertNotNull(operation.workDirectory());
|
||||
assertTrue(operation.workDirectory().exists());
|
||||
assertTrue(operation.workDirectory().isDirectory());
|
||||
assertTrue(operation.workDirectory().canWrite());
|
||||
assertFalse(operation.downloadDependencies());
|
||||
assertNull(operation.packageName());
|
||||
assertNull(operation.projectName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation()
|
||||
throws Exception {
|
||||
var work_directory = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var download_dependencies = true;
|
||||
var package_name = "packageName";
|
||||
var project_name = "projectName";
|
||||
|
||||
var operation = new CreateLibOperation();
|
||||
operation
|
||||
.workDirectory(work_directory)
|
||||
.downloadDependencies(download_dependencies)
|
||||
.packageName(package_name)
|
||||
.projectName(project_name);
|
||||
|
||||
assertEquals(work_directory, operation.workDirectory());
|
||||
assertEquals(download_dependencies, operation.downloadDependencies());
|
||||
assertEquals(package_name, operation.packageName());
|
||||
assertEquals(project_name, operation.projectName());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(work_directory);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateLibOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("com.example")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
assertEquals("""
|
||||
/myapp
|
||||
/myapp/.gitignore
|
||||
/myapp/.idea
|
||||
/myapp/.idea/app.iml
|
||||
/myapp/.idea/bld.iml
|
||||
/myapp/.idea/libraries
|
||||
/myapp/.idea/libraries/bld.xml
|
||||
/myapp/.idea/libraries/compile.xml
|
||||
/myapp/.idea/libraries/runtime.xml
|
||||
/myapp/.idea/libraries/test.xml
|
||||
/myapp/.idea/misc.xml
|
||||
/myapp/.idea/modules.xml
|
||||
/myapp/.idea/runConfigurations
|
||||
/myapp/.idea/runConfigurations/Run Tests.xml
|
||||
/myapp/.vscode
|
||||
/myapp/.vscode/launch.json
|
||||
/myapp/.vscode/settings.json
|
||||
/myapp/bld
|
||||
/myapp/bld.bat
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper.jar
|
||||
/myapp/lib/bld/bld-wrapper.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/test
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappLib.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest.java
|
||||
/myapp/src/test/resources""", FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
var compile_operation = new CompileOperation().fromProject(create_operation.project());
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
assertEquals("""
|
||||
/myapp
|
||||
/myapp/.gitignore
|
||||
/myapp/.idea
|
||||
/myapp/.idea/app.iml
|
||||
/myapp/.idea/bld.iml
|
||||
/myapp/.idea/libraries
|
||||
/myapp/.idea/libraries/bld.xml
|
||||
/myapp/.idea/libraries/compile.xml
|
||||
/myapp/.idea/libraries/runtime.xml
|
||||
/myapp/.idea/libraries/test.xml
|
||||
/myapp/.idea/misc.xml
|
||||
/myapp/.idea/modules.xml
|
||||
/myapp/.idea/runConfigurations
|
||||
/myapp/.idea/runConfigurations/Run Tests.xml
|
||||
/myapp/.vscode
|
||||
/myapp/.vscode/launch.json
|
||||
/myapp/.vscode/settings.json
|
||||
/myapp/bld
|
||||
/myapp/bld.bat
|
||||
/myapp/build
|
||||
/myapp/build/main
|
||||
/myapp/build/main/com
|
||||
/myapp/build/main/com/example
|
||||
/myapp/build/main/com/example/MyappLib.class
|
||||
/myapp/build/test
|
||||
/myapp/build/test/com
|
||||
/myapp/build/test/com/example
|
||||
/myapp/build/test/com/example/MyappTest.class
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper.jar
|
||||
/myapp/lib/bld/bld-wrapper.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/test
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappLib.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest.java
|
||||
/myapp/src/test/resources""", FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
new TestOperation<>()
|
||||
.fromProject(create_operation.project())
|
||||
.outputProcessor(s -> {
|
||||
check_result.append(s);
|
||||
return true;
|
||||
})
|
||||
.mainClass("com.example.MyappTest")
|
||||
.execute();
|
||||
assertEquals("Succeeded", check_result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteNoDownload()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateLibOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("org.stuff")
|
||||
.projectName("yourthing");
|
||||
create_operation.execute();
|
||||
|
||||
assertEquals("""
|
||||
/yourthing
|
||||
/yourthing/.gitignore
|
||||
/yourthing/.idea
|
||||
/yourthing/.idea/app.iml
|
||||
/yourthing/.idea/bld.iml
|
||||
/yourthing/.idea/libraries
|
||||
/yourthing/.idea/libraries/bld.xml
|
||||
/yourthing/.idea/libraries/compile.xml
|
||||
/yourthing/.idea/libraries/runtime.xml
|
||||
/yourthing/.idea/libraries/test.xml
|
||||
/yourthing/.idea/misc.xml
|
||||
/yourthing/.idea/modules.xml
|
||||
/yourthing/.idea/runConfigurations
|
||||
/yourthing/.idea/runConfigurations/Run Tests.xml
|
||||
/yourthing/.vscode
|
||||
/yourthing/.vscode/launch.json
|
||||
/yourthing/.vscode/settings.json
|
||||
/yourthing/bld
|
||||
/yourthing/bld.bat
|
||||
/yourthing/lib
|
||||
/yourthing/lib/bld
|
||||
/yourthing/lib/bld/bld-wrapper.jar
|
||||
/yourthing/lib/bld/bld-wrapper.properties
|
||||
/yourthing/lib/compile
|
||||
/yourthing/lib/runtime
|
||||
/yourthing/lib/test
|
||||
/yourthing/src
|
||||
/yourthing/src/bld
|
||||
/yourthing/src/bld/java
|
||||
/yourthing/src/bld/java/org
|
||||
/yourthing/src/bld/java/org/stuff
|
||||
/yourthing/src/bld/java/org/stuff/YourthingBuild.java
|
||||
/yourthing/src/bld/resources
|
||||
/yourthing/src/main
|
||||
/yourthing/src/main/java
|
||||
/yourthing/src/main/java/org
|
||||
/yourthing/src/main/java/org/stuff
|
||||
/yourthing/src/main/java/org/stuff/YourthingLib.java
|
||||
/yourthing/src/main/resources
|
||||
/yourthing/src/main/resources/templates
|
||||
/yourthing/src/test
|
||||
/yourthing/src/test/java
|
||||
/yourthing/src/test/java/org
|
||||
/yourthing/src/test/java/org/stuff
|
||||
/yourthing/src/test/java/org/stuff/YourthingTest.java
|
||||
/yourthing/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
var compile_operation = new CompileOperation().fromProject(create_operation.project());
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
assertEquals("""
|
||||
/yourthing
|
||||
/yourthing/.gitignore
|
||||
/yourthing/.idea
|
||||
/yourthing/.idea/app.iml
|
||||
/yourthing/.idea/bld.iml
|
||||
/yourthing/.idea/libraries
|
||||
/yourthing/.idea/libraries/bld.xml
|
||||
/yourthing/.idea/libraries/compile.xml
|
||||
/yourthing/.idea/libraries/runtime.xml
|
||||
/yourthing/.idea/libraries/test.xml
|
||||
/yourthing/.idea/misc.xml
|
||||
/yourthing/.idea/modules.xml
|
||||
/yourthing/.idea/runConfigurations
|
||||
/yourthing/.idea/runConfigurations/Run Tests.xml
|
||||
/yourthing/.vscode
|
||||
/yourthing/.vscode/launch.json
|
||||
/yourthing/.vscode/settings.json
|
||||
/yourthing/bld
|
||||
/yourthing/bld.bat
|
||||
/yourthing/build
|
||||
/yourthing/build/main
|
||||
/yourthing/build/main/org
|
||||
/yourthing/build/main/org/stuff
|
||||
/yourthing/build/main/org/stuff/YourthingLib.class
|
||||
/yourthing/build/test
|
||||
/yourthing/build/test/org
|
||||
/yourthing/build/test/org/stuff
|
||||
/yourthing/build/test/org/stuff/YourthingTest.class
|
||||
/yourthing/lib
|
||||
/yourthing/lib/bld
|
||||
/yourthing/lib/bld/bld-wrapper.jar
|
||||
/yourthing/lib/bld/bld-wrapper.properties
|
||||
/yourthing/lib/compile
|
||||
/yourthing/lib/runtime
|
||||
/yourthing/lib/test
|
||||
/yourthing/src
|
||||
/yourthing/src/bld
|
||||
/yourthing/src/bld/java
|
||||
/yourthing/src/bld/java/org
|
||||
/yourthing/src/bld/java/org/stuff
|
||||
/yourthing/src/bld/java/org/stuff/YourthingBuild.java
|
||||
/yourthing/src/bld/resources
|
||||
/yourthing/src/main
|
||||
/yourthing/src/main/java
|
||||
/yourthing/src/main/java/org
|
||||
/yourthing/src/main/java/org/stuff
|
||||
/yourthing/src/main/java/org/stuff/YourthingLib.java
|
||||
/yourthing/src/main/resources
|
||||
/yourthing/src/main/resources/templates
|
||||
/yourthing/src/test
|
||||
/yourthing/src/test/java
|
||||
/yourthing/src/test/java/org
|
||||
/yourthing/src/test/java/org/stuff
|
||||
/yourthing/src/test/java/org/stuff/YourthingTest.java
|
||||
/yourthing/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
new TestOperation<>()
|
||||
.fromProject(create_operation.project())
|
||||
.outputProcessor(s -> {
|
||||
check_result.append(s);
|
||||
return true;
|
||||
})
|
||||
.mainClass("org.stuff.YourthingTest")
|
||||
.execute();
|
||||
assertEquals("Succeeded", check_result.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
720
src/test/java/rife/bld/operations/TestCreateRife2Operation.java
Normal file
720
src/test/java/rife/bld/operations/TestCreateRife2Operation.java
Normal file
|
@ -0,0 +1,720 @@
|
|||
/*
|
||||
* 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.bld.dependencies.LocalDependency;
|
||||
import rife.bld.dependencies.Scope;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
import rife.tools.FileUtils;
|
||||
import rife.tools.exceptions.FileUtilsErrorException;
|
||||
|
||||
import javax.tools.DiagnosticCollector;
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestCreateRife2Operation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new CreateRife2Operation();
|
||||
assertNotNull(operation.workDirectory());
|
||||
assertTrue(operation.workDirectory().exists());
|
||||
assertTrue(operation.workDirectory().isDirectory());
|
||||
assertTrue(operation.workDirectory().canWrite());
|
||||
assertFalse(operation.downloadDependencies());
|
||||
assertNull(operation.packageName());
|
||||
assertNull(operation.projectName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation()
|
||||
throws Exception {
|
||||
var work_directory = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var download_dependencies = true;
|
||||
var package_name = "packageName";
|
||||
var project_name = "projectName";
|
||||
|
||||
var operation = new CreateRife2Operation();
|
||||
operation
|
||||
.workDirectory(work_directory)
|
||||
.downloadDependencies(download_dependencies)
|
||||
.packageName(package_name)
|
||||
.projectName(project_name);
|
||||
|
||||
assertEquals(work_directory, operation.workDirectory());
|
||||
assertEquals(download_dependencies, operation.downloadDependencies());
|
||||
assertEquals(package_name, operation.packageName());
|
||||
assertEquals(project_name, operation.projectName());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(work_directory);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateRife2Operation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("com.example")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
assertTrue(Pattern.compile("""
|
||||
/myapp
|
||||
/myapp/\\.gitignore
|
||||
/myapp/\\.idea
|
||||
/myapp/\\.idea/app\\.iml
|
||||
/myapp/\\.idea/bld\\.iml
|
||||
/myapp/\\.idea/libraries
|
||||
/myapp/\\.idea/libraries/bld\\.xml
|
||||
/myapp/\\.idea/libraries/compile\\.xml
|
||||
/myapp/\\.idea/libraries/runtime\\.xml
|
||||
/myapp/\\.idea/libraries/standalone\\.xml
|
||||
/myapp/\\.idea/libraries/test\\.xml
|
||||
/myapp/\\.idea/misc\\.xml
|
||||
/myapp/\\.idea/modules\\.xml
|
||||
/myapp/\\.idea/runConfigurations
|
||||
/myapp/\\.idea/runConfigurations/Run Main\\.xml
|
||||
/myapp/\\.idea/runConfigurations/Run Tests\\.xml
|
||||
/myapp/\\.vscode
|
||||
/myapp/\\.vscode/launch\\.json
|
||||
/myapp/\\.vscode/settings\\.json
|
||||
/myapp/bld
|
||||
/myapp/bld\\.bat
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper\\.jar
|
||||
/myapp/lib/bld/bld-wrapper\\.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/compile/rife2-.+-sources\\.jar
|
||||
/myapp/lib/compile/rife2-.+\\.jar
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/standalone
|
||||
/myapp/lib/standalone/jetty-http-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-http-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/jetty-io-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-io-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/jetty-jakarta-servlet-api-5\\.0\\.2-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-jakarta-servlet-api-5\\.0\\.2\\.jar
|
||||
/myapp/lib/standalone/jetty-security-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-security-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/jetty-server-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-server-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/jetty-servlet-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-servlet-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/jetty-util-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-util-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/slf4j-api-2\\.0\\.7-sources\\.jar
|
||||
/myapp/lib/standalone/slf4j-api-2\\.0\\.7\\.jar
|
||||
/myapp/lib/standalone/slf4j-simple-2\\.0\\.7-sources\\.jar
|
||||
/myapp/lib/standalone/slf4j-simple-2\\.0\\.7\\.jar
|
||||
/myapp/lib/test
|
||||
/myapp/lib/test/apiguardian-api-1\\.1\\.2-sources\\.jar
|
||||
/myapp/lib/test/apiguardian-api-1\\.1\\.2\\.jar
|
||||
/myapp/lib/test/jsoup-1\\.16\\.1-sources\\.jar
|
||||
/myapp/lib/test/jsoup-1\\.16\\.1\\.jar
|
||||
/myapp/lib/test/junit-jupiter-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-api-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-api-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-engine-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-engine-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-params-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-params-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-commons-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-commons-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-console-standalone-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-console-standalone-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-engine-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-engine-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/opentest4j-1\\.2\\.0-sources\\.jar
|
||||
/myapp/lib/test/opentest4j-1\\.2\\.0\\.jar
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild\\.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappSite\\.java
|
||||
/myapp/src/main/java/com/example/MyappSiteUber\\.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/main/resources/templates/hello\\.html
|
||||
/myapp/src/main/webapp
|
||||
/myapp/src/main/webapp/WEB-INF
|
||||
/myapp/src/main/webapp/WEB-INF/web\\.xml
|
||||
/myapp/src/main/webapp/css
|
||||
/myapp/src/main/webapp/css/style\\.css
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest\\.java
|
||||
/myapp/src/test/resources""").matcher(FileUtils.generateDirectoryListing(tmp)).matches());
|
||||
|
||||
var compile_operation = new CompileOperation().fromProject(create_operation.project());
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
assertTrue(Pattern.compile("""
|
||||
/myapp
|
||||
/myapp/\\.gitignore
|
||||
/myapp/\\.idea
|
||||
/myapp/\\.idea/app\\.iml
|
||||
/myapp/\\.idea/bld\\.iml
|
||||
/myapp/\\.idea/libraries
|
||||
/myapp/\\.idea/libraries/bld\\.xml
|
||||
/myapp/\\.idea/libraries/compile\\.xml
|
||||
/myapp/\\.idea/libraries/runtime\\.xml
|
||||
/myapp/\\.idea/libraries/standalone\\.xml
|
||||
/myapp/\\.idea/libraries/test\\.xml
|
||||
/myapp/\\.idea/misc\\.xml
|
||||
/myapp/\\.idea/modules\\.xml
|
||||
/myapp/\\.idea/runConfigurations
|
||||
/myapp/\\.idea/runConfigurations/Run Main\\.xml
|
||||
/myapp/\\.idea/runConfigurations/Run Tests\\.xml
|
||||
/myapp/\\.vscode
|
||||
/myapp/\\.vscode/launch\\.json
|
||||
/myapp/\\.vscode/settings\\.json
|
||||
/myapp/bld
|
||||
/myapp/bld\\.bat
|
||||
/myapp/build
|
||||
/myapp/build/main
|
||||
/myapp/build/main/com
|
||||
/myapp/build/main/com/example
|
||||
/myapp/build/main/com/example/MyappSite\\.class
|
||||
/myapp/build/main/com/example/MyappSiteUber\\.class
|
||||
/myapp/build/test
|
||||
/myapp/build/test/com
|
||||
/myapp/build/test/com/example
|
||||
/myapp/build/test/com/example/MyappTest\\.class
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper\\.jar
|
||||
/myapp/lib/bld/bld-wrapper\\.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/compile/rife2-.+-sources\\.jar
|
||||
/myapp/lib/compile/rife2-.+\\.jar
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/standalone
|
||||
/myapp/lib/standalone/jetty-http-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-http-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/jetty-io-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-io-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/jetty-jakarta-servlet-api-5\\.0\\.2-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-jakarta-servlet-api-5\\.0\\.2\\.jar
|
||||
/myapp/lib/standalone/jetty-security-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-security-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/jetty-server-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-server-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/jetty-servlet-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-servlet-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/jetty-util-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/standalone/jetty-util-11\\.0\\.15\\.jar
|
||||
/myapp/lib/standalone/slf4j-api-2\\.0\\.7-sources\\.jar
|
||||
/myapp/lib/standalone/slf4j-api-2\\.0\\.7\\.jar
|
||||
/myapp/lib/standalone/slf4j-simple-2\\.0\\.7-sources\\.jar
|
||||
/myapp/lib/standalone/slf4j-simple-2\\.0\\.7\\.jar
|
||||
/myapp/lib/test
|
||||
/myapp/lib/test/apiguardian-api-1\\.1\\.2-sources\\.jar
|
||||
/myapp/lib/test/apiguardian-api-1\\.1\\.2\\.jar
|
||||
/myapp/lib/test/jsoup-1\\.16\\.1-sources\\.jar
|
||||
/myapp/lib/test/jsoup-1\\.16\\.1\\.jar
|
||||
/myapp/lib/test/junit-jupiter-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-api-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-api-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-engine-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-engine-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-jupiter-params-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-jupiter-params-5\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-commons-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-commons-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-console-standalone-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-console-standalone-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/junit-platform-engine-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/test/junit-platform-engine-1\\.9\\.3\\.jar
|
||||
/myapp/lib/test/opentest4j-1\\.2\\.0-sources\\.jar
|
||||
/myapp/lib/test/opentest4j-1\\.2\\.0\\.jar
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild\\.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappSite\\.java
|
||||
/myapp/src/main/java/com/example/MyappSiteUber\\.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/main/resources/templates/hello\\.html
|
||||
/myapp/src/main/webapp
|
||||
/myapp/src/main/webapp/WEB-INF
|
||||
/myapp/src/main/webapp/WEB-INF/web\\.xml
|
||||
/myapp/src/main/webapp/css
|
||||
/myapp/src/main/webapp/css/style\\.css
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest\\.java
|
||||
/myapp/src/test/resources""").matcher(FileUtils.generateDirectoryListing(tmp)).matches());
|
||||
|
||||
var run_operation = new RunOperation().fromProject(create_operation.project());
|
||||
var executor = Executors.newSingleThreadScheduledExecutor();
|
||||
var checked_url = new URL("http://localhost:8080");
|
||||
var check_result = new StringBuilder();
|
||||
executor.schedule(() -> {
|
||||
try {
|
||||
check_result.append(FileUtils.readString(checked_url));
|
||||
} catch (FileUtilsErrorException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
executor.schedule(() -> run_operation.process().destroy(), 2, TimeUnit.SECONDS);
|
||||
assertThrows(ExitStatusException.class, run_operation::execute);
|
||||
|
||||
assertTrue(check_result.toString().contains("<p>Hello World Myapp</p>"));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteNoDownload()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateRife2Operation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("org.stuff")
|
||||
.projectName("yourthing");
|
||||
create_operation.execute();
|
||||
|
||||
assertEquals("""
|
||||
/yourthing
|
||||
/yourthing/.gitignore
|
||||
/yourthing/.idea
|
||||
/yourthing/.idea/app.iml
|
||||
/yourthing/.idea/bld.iml
|
||||
/yourthing/.idea/libraries
|
||||
/yourthing/.idea/libraries/bld.xml
|
||||
/yourthing/.idea/libraries/compile.xml
|
||||
/yourthing/.idea/libraries/runtime.xml
|
||||
/yourthing/.idea/libraries/standalone.xml
|
||||
/yourthing/.idea/libraries/test.xml
|
||||
/yourthing/.idea/misc.xml
|
||||
/yourthing/.idea/modules.xml
|
||||
/yourthing/.idea/runConfigurations
|
||||
/yourthing/.idea/runConfigurations/Run Main.xml
|
||||
/yourthing/.idea/runConfigurations/Run Tests.xml
|
||||
/yourthing/.vscode
|
||||
/yourthing/.vscode/launch.json
|
||||
/yourthing/.vscode/settings.json
|
||||
/yourthing/bld
|
||||
/yourthing/bld.bat
|
||||
/yourthing/lib
|
||||
/yourthing/lib/bld
|
||||
/yourthing/lib/bld/bld-wrapper.jar
|
||||
/yourthing/lib/bld/bld-wrapper.properties
|
||||
/yourthing/lib/compile
|
||||
/yourthing/lib/runtime
|
||||
/yourthing/lib/standalone
|
||||
/yourthing/lib/test
|
||||
/yourthing/src
|
||||
/yourthing/src/bld
|
||||
/yourthing/src/bld/java
|
||||
/yourthing/src/bld/java/org
|
||||
/yourthing/src/bld/java/org/stuff
|
||||
/yourthing/src/bld/java/org/stuff/YourthingBuild.java
|
||||
/yourthing/src/bld/resources
|
||||
/yourthing/src/main
|
||||
/yourthing/src/main/java
|
||||
/yourthing/src/main/java/org
|
||||
/yourthing/src/main/java/org/stuff
|
||||
/yourthing/src/main/java/org/stuff/YourthingSite.java
|
||||
/yourthing/src/main/java/org/stuff/YourthingSiteUber.java
|
||||
/yourthing/src/main/resources
|
||||
/yourthing/src/main/resources/templates
|
||||
/yourthing/src/main/resources/templates/hello.html
|
||||
/yourthing/src/main/webapp
|
||||
/yourthing/src/main/webapp/WEB-INF
|
||||
/yourthing/src/main/webapp/WEB-INF/web.xml
|
||||
/yourthing/src/main/webapp/css
|
||||
/yourthing/src/main/webapp/css/style.css
|
||||
/yourthing/src/test
|
||||
/yourthing/src/test/java
|
||||
/yourthing/src/test/java/org
|
||||
/yourthing/src/test/java/org/stuff
|
||||
/yourthing/src/test/java/org/stuff/YourthingTest.java
|
||||
/yourthing/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
var compile_operation = new CompileOperation() {
|
||||
public void executeProcessDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics) {
|
||||
// don't output errors
|
||||
}
|
||||
};
|
||||
compile_operation.fromProject(create_operation.project());
|
||||
assertThrows(ExitStatusException.class, compile_operation::execute);
|
||||
var diagnostics = compile_operation.diagnostics();
|
||||
assertEquals(16, diagnostics.size());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteLocalDependencies()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateRife2Operation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("com.example")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
var project = create_operation.project();
|
||||
var lib_local = new File(project.libDirectory(), "local");
|
||||
lib_local.mkdirs();
|
||||
for (var lib : FileUtils.getFileList(project.libCompileDirectory())) {
|
||||
if (!lib.endsWith("-sources.jar")) {
|
||||
project.dependencies().scope(Scope.compile).include(new LocalDependency(Path.of("lib", "local", lib).toString()));
|
||||
}
|
||||
new File(project.libCompileDirectory(), lib).renameTo(new File(lib_local, lib));
|
||||
}
|
||||
for (var lib : FileUtils.getFileList(project.libStandaloneDirectory())) {
|
||||
if (!lib.endsWith("-sources.jar")) {
|
||||
project.dependencies().scope(Scope.standalone).include(new LocalDependency(Path.of("lib", "local", lib).toString()));
|
||||
}
|
||||
new File(project.libStandaloneDirectory(), lib).renameTo(new File(lib_local, lib));
|
||||
}
|
||||
for (var lib : FileUtils.getFileList(project.libTestDirectory())) {
|
||||
if (!lib.endsWith("-sources.jar")) {
|
||||
project.dependencies().scope(Scope.test).include(new LocalDependency(Path.of("lib", "local", lib).toString()));
|
||||
}
|
||||
new File(project.libTestDirectory(), lib).renameTo(new File(lib_local, lib));
|
||||
}
|
||||
|
||||
var compile_operation = new CompileOperation().fromProject(create_operation.project());
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
assertTrue(Pattern.compile("""
|
||||
/myapp
|
||||
/myapp/\\.gitignore
|
||||
/myapp/\\.idea
|
||||
/myapp/\\.idea/app\\.iml
|
||||
/myapp/\\.idea/bld\\.iml
|
||||
/myapp/\\.idea/libraries
|
||||
/myapp/\\.idea/libraries/bld\\.xml
|
||||
/myapp/\\.idea/libraries/compile\\.xml
|
||||
/myapp/\\.idea/libraries/runtime\\.xml
|
||||
/myapp/\\.idea/libraries/standalone\\.xml
|
||||
/myapp/\\.idea/libraries/test\\.xml
|
||||
/myapp/\\.idea/misc\\.xml
|
||||
/myapp/\\.idea/modules\\.xml
|
||||
/myapp/\\.idea/runConfigurations
|
||||
/myapp/\\.idea/runConfigurations/Run Main\\.xml
|
||||
/myapp/\\.idea/runConfigurations/Run Tests\\.xml
|
||||
/myapp/\\.vscode
|
||||
/myapp/\\.vscode/launch\\.json
|
||||
/myapp/\\.vscode/settings\\.json
|
||||
/myapp/bld
|
||||
/myapp/bld\\.bat
|
||||
/myapp/build
|
||||
/myapp/build/main
|
||||
/myapp/build/main/com
|
||||
/myapp/build/main/com/example
|
||||
/myapp/build/main/com/example/MyappSite\\.class
|
||||
/myapp/build/main/com/example/MyappSiteUber\\.class
|
||||
/myapp/build/test
|
||||
/myapp/build/test/com
|
||||
/myapp/build/test/com/example
|
||||
/myapp/build/test/com/example/MyappTest\\.class
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper\\.jar
|
||||
/myapp/lib/bld/bld-wrapper\\.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/local
|
||||
/myapp/lib/local/apiguardian-api-1\\.1\\.2-sources\\.jar
|
||||
/myapp/lib/local/apiguardian-api-1\\.1\\.2\\.jar
|
||||
/myapp/lib/local/jetty-http-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local/jetty-http-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local/jetty-io-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local/jetty-io-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local/jetty-jakarta-servlet-api-5\\.0\\.2-sources\\.jar
|
||||
/myapp/lib/local/jetty-jakarta-servlet-api-5\\.0\\.2\\.jar
|
||||
/myapp/lib/local/jetty-security-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local/jetty-security-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local/jetty-server-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local/jetty-server-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local/jetty-servlet-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local/jetty-servlet-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local/jetty-util-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local/jetty-util-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local/jsoup-1\\.16\\.1-sources\\.jar
|
||||
/myapp/lib/local/jsoup-1\\.16\\.1\\.jar
|
||||
/myapp/lib/local/junit-jupiter-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-jupiter-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-jupiter-api-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-jupiter-api-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-jupiter-engine-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-jupiter-engine-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-jupiter-params-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-jupiter-params-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-platform-commons-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-platform-commons-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-platform-console-standalone-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-platform-console-standalone-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local/junit-platform-engine-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local/junit-platform-engine-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local/opentest4j-1\\.2\\.0-sources\\.jar
|
||||
/myapp/lib/local/opentest4j-1\\.2\\.0\\.jar
|
||||
/myapp/lib/local/rife2-.*-sources\\.jar
|
||||
/myapp/lib/local/rife2-.*\\.jar
|
||||
/myapp/lib/local/slf4j-api-2\\.0\\.7-sources\\.jar
|
||||
/myapp/lib/local/slf4j-api-2\\.0\\.7\\.jar
|
||||
/myapp/lib/local/slf4j-simple-2\\.0\\.7-sources\\.jar
|
||||
/myapp/lib/local/slf4j-simple-2\\.0\\.7\\.jar
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/standalone
|
||||
/myapp/lib/test
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild\\.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappSite\\.java
|
||||
/myapp/src/main/java/com/example/MyappSiteUber\\.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/main/resources/templates/hello\\.html
|
||||
/myapp/src/main/webapp
|
||||
/myapp/src/main/webapp/WEB-INF
|
||||
/myapp/src/main/webapp/WEB-INF/web\\.xml
|
||||
/myapp/src/main/webapp/css
|
||||
/myapp/src/main/webapp/css/style\\.css
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest\\.java
|
||||
/myapp/src/test/resources""").matcher(FileUtils.generateDirectoryListing(tmp)).matches());
|
||||
|
||||
var run_operation = new RunOperation().fromProject(create_operation.project());
|
||||
var executor = Executors.newSingleThreadScheduledExecutor();
|
||||
var checked_url = new URL("http://localhost:8080");
|
||||
var check_result = new StringBuilder();
|
||||
executor.schedule(() -> {
|
||||
try {
|
||||
check_result.append(FileUtils.readString(checked_url));
|
||||
} catch (FileUtilsErrorException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
executor.schedule(() -> run_operation.process().destroy(), 2, TimeUnit.SECONDS);
|
||||
assertThrows(ExitStatusException.class, run_operation::execute);
|
||||
|
||||
assertTrue(check_result.toString().contains("<p>Hello World Myapp</p>"));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteLocalDependenciesFolders()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateRife2Operation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("com.example")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
var project = create_operation.project();
|
||||
var lib_local_compile = new File(project.libDirectory(), "local_compile");
|
||||
lib_local_compile.mkdirs();
|
||||
project.dependencies().scope(Scope.compile).include(new LocalDependency(Path.of("lib", "local_compile").toString()));
|
||||
for (var lib : FileUtils.getFileList(project.libCompileDirectory())) {
|
||||
new File(project.libCompileDirectory(), lib).renameTo(new File(lib_local_compile, lib));
|
||||
}
|
||||
var lib_local_standalone = new File(project.libDirectory(), "local_standalone");
|
||||
lib_local_standalone.mkdirs();
|
||||
project.dependencies().scope(Scope.standalone).include(new LocalDependency(Path.of("lib", "local_standalone").toString()));
|
||||
for (var lib : FileUtils.getFileList(project.libStandaloneDirectory())) {
|
||||
new File(project.libStandaloneDirectory(), lib).renameTo(new File(lib_local_standalone, lib));
|
||||
}
|
||||
var lib_local_test = new File(project.libDirectory(), "local_test");
|
||||
lib_local_test.mkdirs();
|
||||
project.dependencies().scope(Scope.test).include(new LocalDependency(Path.of("lib", "local_test").toString()));
|
||||
for (var lib : FileUtils.getFileList(project.libTestDirectory())) {
|
||||
new File(project.libTestDirectory(), lib).renameTo(new File(lib_local_test, lib));
|
||||
}
|
||||
|
||||
var compile_operation = new CompileOperation().fromProject(create_operation.project());
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
assertTrue(Pattern.compile("""
|
||||
/myapp
|
||||
/myapp/\\.gitignore
|
||||
/myapp/\\.idea
|
||||
/myapp/\\.idea/app\\.iml
|
||||
/myapp/\\.idea/bld\\.iml
|
||||
/myapp/\\.idea/libraries
|
||||
/myapp/\\.idea/libraries/bld\\.xml
|
||||
/myapp/\\.idea/libraries/compile\\.xml
|
||||
/myapp/\\.idea/libraries/runtime\\.xml
|
||||
/myapp/\\.idea/libraries/standalone\\.xml
|
||||
/myapp/\\.idea/libraries/test\\.xml
|
||||
/myapp/\\.idea/misc\\.xml
|
||||
/myapp/\\.idea/modules\\.xml
|
||||
/myapp/\\.idea/runConfigurations
|
||||
/myapp/\\.idea/runConfigurations/Run Main\\.xml
|
||||
/myapp/\\.idea/runConfigurations/Run Tests\\.xml
|
||||
/myapp/\\.vscode
|
||||
/myapp/\\.vscode/launch\\.json
|
||||
/myapp/\\.vscode/settings\\.json
|
||||
/myapp/bld
|
||||
/myapp/bld\\.bat
|
||||
/myapp/build
|
||||
/myapp/build/main
|
||||
/myapp/build/main/com
|
||||
/myapp/build/main/com/example
|
||||
/myapp/build/main/com/example/MyappSite\\.class
|
||||
/myapp/build/main/com/example/MyappSiteUber\\.class
|
||||
/myapp/build/test
|
||||
/myapp/build/test/com
|
||||
/myapp/build/test/com/example
|
||||
/myapp/build/test/com/example/MyappTest\\.class
|
||||
/myapp/lib
|
||||
/myapp/lib/bld
|
||||
/myapp/lib/bld/bld-wrapper\\.jar
|
||||
/myapp/lib/bld/bld-wrapper\\.properties
|
||||
/myapp/lib/compile
|
||||
/myapp/lib/local_compile
|
||||
/myapp/lib/local_compile/rife2-.*-sources\\.jar
|
||||
/myapp/lib/local_compile/rife2-.*\\.jar
|
||||
/myapp/lib/local_standalone
|
||||
/myapp/lib/local_standalone/jetty-http-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local_standalone/jetty-http-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local_standalone/jetty-io-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local_standalone/jetty-io-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local_standalone/jetty-jakarta-servlet-api-5\\.0\\.2-sources\\.jar
|
||||
/myapp/lib/local_standalone/jetty-jakarta-servlet-api-5\\.0\\.2\\.jar
|
||||
/myapp/lib/local_standalone/jetty-security-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local_standalone/jetty-security-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local_standalone/jetty-server-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local_standalone/jetty-server-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local_standalone/jetty-servlet-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local_standalone/jetty-servlet-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local_standalone/jetty-util-11\\.0\\.15-sources\\.jar
|
||||
/myapp/lib/local_standalone/jetty-util-11\\.0\\.15\\.jar
|
||||
/myapp/lib/local_standalone/slf4j-api-2\\.0\\.7-sources\\.jar
|
||||
/myapp/lib/local_standalone/slf4j-api-2\\.0\\.7\\.jar
|
||||
/myapp/lib/local_standalone/slf4j-simple-2\\.0\\.7-sources\\.jar
|
||||
/myapp/lib/local_standalone/slf4j-simple-2\\.0\\.7\\.jar
|
||||
/myapp/lib/local_test
|
||||
/myapp/lib/local_test/apiguardian-api-1\\.1\\.2-sources\\.jar
|
||||
/myapp/lib/local_test/apiguardian-api-1\\.1\\.2\\.jar
|
||||
/myapp/lib/local_test/jsoup-1\\.16\\.1-sources\\.jar
|
||||
/myapp/lib/local_test/jsoup-1\\.16\\.1\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-api-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-api-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-engine-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-engine-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-params-5\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-jupiter-params-5\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-platform-commons-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-platform-commons-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-platform-console-standalone-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-platform-console-standalone-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/junit-platform-engine-1\\.9\\.3-sources\\.jar
|
||||
/myapp/lib/local_test/junit-platform-engine-1\\.9\\.3\\.jar
|
||||
/myapp/lib/local_test/opentest4j-1\\.2\\.0-sources\\.jar
|
||||
/myapp/lib/local_test/opentest4j-1\\.2\\.0\\.jar
|
||||
/myapp/lib/runtime
|
||||
/myapp/lib/standalone
|
||||
/myapp/lib/test
|
||||
/myapp/src
|
||||
/myapp/src/bld
|
||||
/myapp/src/bld/java
|
||||
/myapp/src/bld/java/com
|
||||
/myapp/src/bld/java/com/example
|
||||
/myapp/src/bld/java/com/example/MyappBuild\\.java
|
||||
/myapp/src/bld/resources
|
||||
/myapp/src/main
|
||||
/myapp/src/main/java
|
||||
/myapp/src/main/java/com
|
||||
/myapp/src/main/java/com/example
|
||||
/myapp/src/main/java/com/example/MyappSite\\.java
|
||||
/myapp/src/main/java/com/example/MyappSiteUber\\.java
|
||||
/myapp/src/main/resources
|
||||
/myapp/src/main/resources/templates
|
||||
/myapp/src/main/resources/templates/hello\\.html
|
||||
/myapp/src/main/webapp
|
||||
/myapp/src/main/webapp/WEB-INF
|
||||
/myapp/src/main/webapp/WEB-INF/web\\.xml
|
||||
/myapp/src/main/webapp/css
|
||||
/myapp/src/main/webapp/css/style\\.css
|
||||
/myapp/src/test
|
||||
/myapp/src/test/java
|
||||
/myapp/src/test/java/com
|
||||
/myapp/src/test/java/com/example
|
||||
/myapp/src/test/java/com/example/MyappTest\\.java
|
||||
/myapp/src/test/resources""").matcher(FileUtils.generateDirectoryListing(tmp)).matches());
|
||||
|
||||
var run_operation = new RunOperation().fromProject(create_operation.project());
|
||||
var executor = Executors.newSingleThreadScheduledExecutor();
|
||||
var checked_url = new URL("http://localhost:8080");
|
||||
var check_result = new StringBuilder();
|
||||
executor.schedule(() -> {
|
||||
try {
|
||||
check_result.append(FileUtils.readString(checked_url));
|
||||
} catch (FileUtilsErrorException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
executor.schedule(() -> run_operation.process().destroy(), 2, TimeUnit.SECONDS);
|
||||
assertThrows(ExitStatusException.class, run_operation::execute);
|
||||
|
||||
assertTrue(check_result.toString().contains("<p>Hello World Myapp</p>"));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,197 @@
|
|||
/*
|
||||
* 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.bld.WebProject;
|
||||
import rife.bld.dependencies.*;
|
||||
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 TestDependencyTreeOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new DependencyTreeOperation();
|
||||
assertTrue(operation.dependencies().isEmpty());
|
||||
assertTrue(operation.repositories().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var repository1 = new Repository("repository1");
|
||||
var repository2 = new Repository("repository2");
|
||||
var dependency1 = new Dependency("group1", "artifact1");
|
||||
var dependency2 = new Dependency("group2", "artifact2");
|
||||
|
||||
var operation1 = new DependencyTreeOperation()
|
||||
.repositories(List.of(repository1, repository2));
|
||||
var dependency_scopes = new DependencyScopes();
|
||||
dependency_scopes.scope(Scope.compile).include(dependency1).include(dependency2);
|
||||
operation1.dependencies(dependency_scopes);
|
||||
assertTrue(operation1.repositories().contains(repository1));
|
||||
assertTrue(operation1.repositories().contains(repository2));
|
||||
assertTrue(operation1.dependencies().scope(Scope.compile).contains(dependency1));
|
||||
assertTrue(operation1.dependencies().scope(Scope.compile).contains(dependency2));
|
||||
|
||||
var operation2 = new DependencyTreeOperation();
|
||||
operation2.repositories().add(repository1);
|
||||
operation2.repositories().add(repository2);
|
||||
operation2.dependencies().scope(Scope.compile).include(dependency1).include(dependency2);
|
||||
operation2.dependencies(dependency_scopes);
|
||||
assertTrue(operation2.repositories().contains(repository1));
|
||||
assertTrue(operation2.repositories().contains(repository2));
|
||||
assertTrue(operation2.dependencies().scope(Scope.compile).contains(dependency1));
|
||||
assertTrue(operation2.dependencies().scope(Scope.compile).contains(dependency2));
|
||||
|
||||
var operation3 = new DependencyTreeOperation()
|
||||
.repositories(repository1, repository2);
|
||||
assertTrue(operation3.repositories().contains(repository1));
|
||||
assertTrue(operation3.repositories().contains(repository2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecution()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var operation = new DependencyTreeOperation()
|
||||
.repositories(List.of(Repository.MAVEN_CENTRAL));
|
||||
operation.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1,5,20)))
|
||||
.include(new Dependency("com.stripe", "stripe-java", new VersionNumber(20,136,0)))
|
||||
.include(new Dependency("org.json", "json", new VersionNumber(20230227)))
|
||||
.include(new Dependency("com.itextpdf", "itext7-core", new VersionNumber(7,2,5)))
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2,0,7)))
|
||||
.include(new Dependency("org.apache.thrift", "libthrift", new VersionNumber(0,17,0)))
|
||||
.include(new Dependency("commons-codec", "commons-codec", new VersionNumber(1,15)))
|
||||
.include(new Dependency("org.apache.httpcomponents", "httpcore", new VersionNumber(4,4,16)))
|
||||
.include(new Dependency("com.google.zxing", "javase", new VersionNumber(3,5,1)));
|
||||
operation.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.postgresql", "postgresql", new VersionNumber(42,6,0)));
|
||||
|
||||
operation.execute();
|
||||
|
||||
var tree = operation.dependencyTree();
|
||||
|
||||
assertEquals("""
|
||||
compile:
|
||||
├─ com.uwyn.rife2:rife2:1.5.20
|
||||
├─ com.stripe:stripe-java:20.136.0
|
||||
├─ org.json:json:20230227
|
||||
├─ com.itextpdf:itext7-core:7.2.5
|
||||
│ ├─ com.itextpdf:barcodes:7.2.5
|
||||
│ ├─ com.itextpdf:font-asian:7.2.5
|
||||
│ ├─ com.itextpdf:forms:7.2.5
|
||||
│ ├─ com.itextpdf:hyph:7.2.5
|
||||
│ ├─ com.itextpdf:io:7.2.5
|
||||
│ │ └─ com.itextpdf:commons:7.2.5
|
||||
│ ├─ com.itextpdf:kernel:7.2.5
|
||||
│ │ ├─ org.bouncycastle:bcpkix-jdk15on:1.70
|
||||
│ │ │ └─ org.bouncycastle:bcutil-jdk15on:1.70
|
||||
│ │ └─ org.bouncycastle:bcprov-jdk15on:1.70
|
||||
│ ├─ com.itextpdf:layout:7.2.5
|
||||
│ ├─ com.itextpdf:pdfa:7.2.5
|
||||
│ ├─ com.itextpdf:sign:7.2.5
|
||||
│ ├─ com.itextpdf:styled-xml-parser:7.2.5
|
||||
│ └─ com.itextpdf:svg:7.2.5
|
||||
├─ org.slf4j:slf4j-simple:2.0.7
|
||||
│ └─ org.slf4j:slf4j-api:2.0.7
|
||||
├─ org.apache.thrift:libthrift:0.17.0
|
||||
├─ commons-codec:commons-codec:1.15
|
||||
├─ org.apache.httpcomponents:httpcore:4.4.16
|
||||
└─ com.google.zxing:javase:3.5.1
|
||||
├─ com.google.zxing:core:3.5.1
|
||||
└─ com.beust:jcommander:1.82
|
||||
|
||||
runtime:
|
||||
└─ org.postgresql:postgresql:42.6.0
|
||||
└─ org.checkerframework:checker-qual:3.31.0
|
||||
|
||||
""", tree);
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static class TestProject extends WebProject {
|
||||
public TestProject(File tmp) {
|
||||
workDirectory = tmp;
|
||||
pkg = "test.pkg";
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var project = new TestProject(tmp);
|
||||
project.createProjectStructure();
|
||||
project.repositories().add(Repository.MAVEN_CENTRAL);
|
||||
project.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1,5,20)))
|
||||
.include(new Dependency("com.stripe", "stripe-java", new VersionNumber(20,136,0)))
|
||||
.include(new Dependency("org.json", "json", new VersionNumber(20230227)))
|
||||
.include(new Dependency("com.itextpdf", "itext7-core", new VersionNumber(7,2,5)))
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2,0,7)))
|
||||
.include(new Dependency("org.apache.thrift", "libthrift", new VersionNumber(0,17,0)))
|
||||
.include(new Dependency("commons-codec", "commons-codec", new VersionNumber(1,15)))
|
||||
.include(new Dependency("org.apache.httpcomponents", "httpcore", new VersionNumber(4,4,16)))
|
||||
.include(new Dependency("com.google.zxing", "javase", new VersionNumber(3,5,1)));
|
||||
project.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.postgresql", "postgresql", new VersionNumber(42,6,0)));
|
||||
|
||||
var operation = new DependencyTreeOperation()
|
||||
.fromProject(project);
|
||||
|
||||
operation.execute();
|
||||
|
||||
var tree = operation.dependencyTree();
|
||||
|
||||
assertEquals("""
|
||||
compile:
|
||||
├─ com.uwyn.rife2:rife2:1.5.20
|
||||
├─ com.stripe:stripe-java:20.136.0
|
||||
├─ org.json:json:20230227
|
||||
├─ com.itextpdf:itext7-core:7.2.5
|
||||
│ ├─ com.itextpdf:barcodes:7.2.5
|
||||
│ ├─ com.itextpdf:font-asian:7.2.5
|
||||
│ ├─ com.itextpdf:forms:7.2.5
|
||||
│ ├─ com.itextpdf:hyph:7.2.5
|
||||
│ ├─ com.itextpdf:io:7.2.5
|
||||
│ │ └─ com.itextpdf:commons:7.2.5
|
||||
│ ├─ com.itextpdf:kernel:7.2.5
|
||||
│ │ ├─ org.bouncycastle:bcpkix-jdk15on:1.70
|
||||
│ │ │ └─ org.bouncycastle:bcutil-jdk15on:1.70
|
||||
│ │ └─ org.bouncycastle:bcprov-jdk15on:1.70
|
||||
│ ├─ com.itextpdf:layout:7.2.5
|
||||
│ ├─ com.itextpdf:pdfa:7.2.5
|
||||
│ ├─ com.itextpdf:sign:7.2.5
|
||||
│ ├─ com.itextpdf:styled-xml-parser:7.2.5
|
||||
│ └─ com.itextpdf:svg:7.2.5
|
||||
├─ org.slf4j:slf4j-simple:2.0.7
|
||||
│ └─ org.slf4j:slf4j-api:2.0.7
|
||||
├─ org.apache.thrift:libthrift:0.17.0
|
||||
├─ commons-codec:commons-codec:1.15
|
||||
├─ org.apache.httpcomponents:httpcore:4.4.16
|
||||
└─ com.google.zxing:javase:3.5.1
|
||||
├─ com.google.zxing:core:3.5.1
|
||||
└─ com.beust:jcommander:1.82
|
||||
|
||||
runtime:
|
||||
└─ org.postgresql:postgresql:42.6.0
|
||||
└─ org.checkerframework:checker-qual:3.31.0
|
||||
|
||||
""", tree);
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
314
src/test/java/rife/bld/operations/TestDownloadOperation.java
Normal file
314
src/test/java/rife/bld/operations/TestDownloadOperation.java
Normal file
|
@ -0,0 +1,314 @@
|
|||
/*
|
||||
* 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.bld.WebProject;
|
||||
import rife.bld.dependencies.*;
|
||||
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 TestDownloadOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new DownloadOperation();
|
||||
assertTrue(operation.dependencies().isEmpty());
|
||||
assertTrue(operation.repositories().isEmpty());
|
||||
assertNull(operation.libCompileDirectory());
|
||||
assertNull(operation.libRuntimeDirectory());
|
||||
assertNull(operation.libStandaloneDirectory());
|
||||
assertNull(operation.libTestDirectory());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var repository1 = new Repository("repository1");
|
||||
var repository2 = new Repository("repository2");
|
||||
var dependency1 = new Dependency("group1", "artifact1");
|
||||
var dependency2 = new Dependency("group2", "artifact2");
|
||||
var dir1 = new File("dir1");
|
||||
var dir2 = new File("dir2");
|
||||
var dir3 = new File("dir3");
|
||||
var dir4 = new File("dir4");
|
||||
|
||||
var operation1 = new DownloadOperation()
|
||||
.repositories(List.of(repository1, repository2))
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4);
|
||||
var dependency_scopes = new DependencyScopes();
|
||||
dependency_scopes.scope(Scope.compile).include(dependency1).include(dependency2);
|
||||
operation1.dependencies(dependency_scopes);
|
||||
assertTrue(operation1.repositories().contains(repository1));
|
||||
assertTrue(operation1.repositories().contains(repository2));
|
||||
assertTrue(operation1.dependencies().scope(Scope.compile).contains(dependency1));
|
||||
assertTrue(operation1.dependencies().scope(Scope.compile).contains(dependency2));
|
||||
assertEquals(dir1, operation1.libCompileDirectory());
|
||||
assertEquals(dir2, operation1.libRuntimeDirectory());
|
||||
assertEquals(dir3, operation1.libStandaloneDirectory());
|
||||
assertEquals(dir4, operation1.libTestDirectory());
|
||||
|
||||
var operation2 = new DownloadOperation()
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4);
|
||||
operation2.repositories().add(repository1);
|
||||
operation2.repositories().add(repository2);
|
||||
operation2.dependencies().scope(Scope.compile).include(dependency1).include(dependency2);
|
||||
operation2.dependencies(dependency_scopes);
|
||||
assertTrue(operation2.repositories().contains(repository1));
|
||||
assertTrue(operation2.repositories().contains(repository2));
|
||||
assertTrue(operation2.dependencies().scope(Scope.compile).contains(dependency1));
|
||||
assertTrue(operation2.dependencies().scope(Scope.compile).contains(dependency2));
|
||||
assertEquals(dir1, operation2.libCompileDirectory());
|
||||
assertEquals(dir2, operation2.libRuntimeDirectory());
|
||||
assertEquals(dir3, operation2.libStandaloneDirectory());
|
||||
assertEquals(dir4, operation2.libTestDirectory());
|
||||
|
||||
var operation3 = new DownloadOperation()
|
||||
.repositories(repository1, repository2);
|
||||
assertTrue(operation3.repositories().contains(repository1));
|
||||
assertTrue(operation3.repositories().contains(repository2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecution()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var dir1 = new File(tmp, "dir1");
|
||||
var dir2 = new File(tmp, "dir2");
|
||||
var dir3 = new File(tmp, "dir3");
|
||||
var dir4 = new File(tmp, "dir4");
|
||||
dir1.mkdirs();
|
||||
dir2.mkdirs();
|
||||
dir3.mkdirs();
|
||||
dir4.mkdirs();
|
||||
|
||||
var operation = new DownloadOperation()
|
||||
.repositories(List.of(Repository.MAVEN_CENTRAL))
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4);
|
||||
operation.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 12, 0)));
|
||||
operation.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 4)));
|
||||
operation.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 6)));
|
||||
operation.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 2, 1)));
|
||||
|
||||
operation.execute();
|
||||
|
||||
assertEquals("""
|
||||
/dir1
|
||||
/dir1/commons-lang3-3.12.0.jar
|
||||
/dir2
|
||||
/dir2/commons-collections4-4.4.jar
|
||||
/dir3
|
||||
/dir3/slf4j-api-2.0.6.jar
|
||||
/dir3/slf4j-simple-2.0.6.jar
|
||||
/dir4
|
||||
/dir4/httpclient5-5.2.1.jar
|
||||
/dir4/httpcore5-5.2.jar
|
||||
/dir4/httpcore5-h2-5.2.jar
|
||||
/dir4/slf4j-api-1.7.36.jar""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecutionAdditionalSourcesJavadoc()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var dir1 = new File(tmp, "dir1");
|
||||
var dir2 = new File(tmp, "dir2");
|
||||
var dir3 = new File(tmp, "dir3");
|
||||
var dir4 = new File(tmp, "dir4");
|
||||
dir1.mkdirs();
|
||||
dir2.mkdirs();
|
||||
dir3.mkdirs();
|
||||
dir4.mkdirs();
|
||||
|
||||
var operation = new DownloadOperation()
|
||||
.repositories(List.of(Repository.MAVEN_CENTRAL))
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4)
|
||||
.downloadJavadoc(true)
|
||||
.downloadSources(true);
|
||||
operation.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 12, 0)));
|
||||
operation.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 4)));
|
||||
operation.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 6)));
|
||||
operation.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 2, 1)));
|
||||
|
||||
operation.execute();
|
||||
|
||||
assertEquals("""
|
||||
/dir1
|
||||
/dir1/commons-lang3-3.12.0-javadoc.jar
|
||||
/dir1/commons-lang3-3.12.0-sources.jar
|
||||
/dir1/commons-lang3-3.12.0.jar
|
||||
/dir2
|
||||
/dir2/commons-collections4-4.4-javadoc.jar
|
||||
/dir2/commons-collections4-4.4-sources.jar
|
||||
/dir2/commons-collections4-4.4.jar
|
||||
/dir3
|
||||
/dir3/slf4j-api-2.0.6-javadoc.jar
|
||||
/dir3/slf4j-api-2.0.6-sources.jar
|
||||
/dir3/slf4j-api-2.0.6.jar
|
||||
/dir3/slf4j-simple-2.0.6-javadoc.jar
|
||||
/dir3/slf4j-simple-2.0.6-sources.jar
|
||||
/dir3/slf4j-simple-2.0.6.jar
|
||||
/dir4
|
||||
/dir4/httpclient5-5.2.1-javadoc.jar
|
||||
/dir4/httpclient5-5.2.1-sources.jar
|
||||
/dir4/httpclient5-5.2.1.jar
|
||||
/dir4/httpcore5-5.2-javadoc.jar
|
||||
/dir4/httpcore5-5.2-sources.jar
|
||||
/dir4/httpcore5-5.2.jar
|
||||
/dir4/httpcore5-h2-5.2-javadoc.jar
|
||||
/dir4/httpcore5-h2-5.2-sources.jar
|
||||
/dir4/httpcore5-h2-5.2.jar
|
||||
/dir4/slf4j-api-1.7.36-javadoc.jar
|
||||
/dir4/slf4j-api-1.7.36-sources.jar
|
||||
/dir4/slf4j-api-1.7.36.jar""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static class TestProject extends WebProject {
|
||||
public TestProject(File tmp) {
|
||||
workDirectory = tmp;
|
||||
pkg = "test.pkg";
|
||||
downloadSources = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var project = new TestProject(tmp);
|
||||
project.createProjectStructure();
|
||||
project.repositories().add(Repository.MAVEN_CENTRAL);
|
||||
project.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 12, 0)));
|
||||
project.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 4)));
|
||||
project.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 6)));
|
||||
project.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 2, 1)));
|
||||
|
||||
var operation = new DownloadOperation()
|
||||
.fromProject(project);
|
||||
|
||||
operation.execute();
|
||||
|
||||
assertEquals("""
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/compile
|
||||
/lib/compile/commons-lang3-3.12.0-sources.jar
|
||||
/lib/compile/commons-lang3-3.12.0.jar
|
||||
/lib/runtime
|
||||
/lib/runtime/commons-collections4-4.4-sources.jar
|
||||
/lib/runtime/commons-collections4-4.4.jar
|
||||
/lib/standalone
|
||||
/lib/standalone/slf4j-api-2.0.6-sources.jar
|
||||
/lib/standalone/slf4j-api-2.0.6.jar
|
||||
/lib/standalone/slf4j-simple-2.0.6-sources.jar
|
||||
/lib/standalone/slf4j-simple-2.0.6.jar
|
||||
/lib/test
|
||||
/lib/test/httpclient5-5.2.1-sources.jar
|
||||
/lib/test/httpclient5-5.2.1.jar
|
||||
/lib/test/httpcore5-5.2-sources.jar
|
||||
/lib/test/httpcore5-5.2.jar
|
||||
/lib/test/httpcore5-h2-5.2-sources.jar
|
||||
/lib/test/httpcore5-h2-5.2.jar
|
||||
/lib/test/slf4j-api-1.7.36-sources.jar
|
||||
/lib/test/slf4j-api-1.7.36.jar
|
||||
/src
|
||||
/src/bld
|
||||
/src/bld/java
|
||||
/src/bld/resources
|
||||
/src/main
|
||||
/src/main/java
|
||||
/src/main/resources
|
||||
/src/main/resources/templates
|
||||
/src/test
|
||||
/src/test/java
|
||||
/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject2()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var project = new TestProject(tmp);
|
||||
project.createProjectStructure();
|
||||
project.repositories().add(Repository.MAVEN_CENTRAL);
|
||||
project.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("com.stripe", "stripe-java", new VersionNumber(20,136,0)));
|
||||
|
||||
var operation = new DownloadOperation()
|
||||
.fromProject(project);
|
||||
|
||||
operation.execute();
|
||||
|
||||
assertEquals("""
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/compile
|
||||
/lib/compile/stripe-java-20.136.0-sources.jar
|
||||
/lib/compile/stripe-java-20.136.0.jar
|
||||
/lib/runtime
|
||||
/lib/runtime/gson-2.9.0-sources.jar
|
||||
/lib/runtime/gson-2.9.0.jar
|
||||
/lib/standalone
|
||||
/lib/test
|
||||
/src
|
||||
/src/bld
|
||||
/src/bld/java
|
||||
/src/bld/resources
|
||||
/src/main
|
||||
/src/main/java
|
||||
/src/main/resources
|
||||
/src/main/resources/templates
|
||||
/src/test
|
||||
/src/test/java
|
||||
/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
213
src/test/java/rife/bld/operations/TestJUnitOperation.java
Normal file
213
src/test/java/rife/bld/operations/TestJUnitOperation.java
Normal file
|
@ -0,0 +1,213 @@
|
|||
/*
|
||||
* 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 java.util.function.Function;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class TestJUnitOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new JUnitOperation();
|
||||
assertNotNull(operation.workDirectory());
|
||||
assertTrue(operation.workDirectory().exists());
|
||||
assertTrue(operation.workDirectory().isDirectory());
|
||||
assertTrue(operation.workDirectory().canWrite());
|
||||
assertEquals("java", operation.javaTool());
|
||||
assertTrue(operation.javaOptions().isEmpty());
|
||||
assertTrue(operation.classpath().isEmpty());
|
||||
assertNull(operation.mainClass());
|
||||
assertNull(operation.outputProcessor());
|
||||
assertNull(operation.errorProcessor());
|
||||
assertNull(operation.process());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation()
|
||||
throws Exception {
|
||||
var work_directory = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var java_tool = "javatool";
|
||||
var test_java_option1 = "testJavaOption1";
|
||||
var test_java_option2 = "testJavaOption2";
|
||||
var test_classpath1 = "testClasspath1";
|
||||
var test_classpath2 = "testClasspath2";
|
||||
var test_tool_main_class = "testToolMainClass";
|
||||
var test_tool_option1 = "testToolOption1";
|
||||
var test_tool_option2 = "testToolOption2";
|
||||
Function<String, Boolean> test_output_consumer = (String) -> true;
|
||||
Function<String, Boolean> test_error_consumer = (String) -> true;
|
||||
|
||||
var operation1 = new JUnitOperation();
|
||||
operation1
|
||||
.workDirectory(work_directory)
|
||||
.javaTool(java_tool)
|
||||
.javaOptions(List.of(test_java_option1, test_java_option2))
|
||||
.testToolOptions(List.of(test_tool_option1, test_tool_option2))
|
||||
.classpath(List.of(test_classpath1, test_classpath2))
|
||||
.mainClass(test_tool_main_class)
|
||||
.outputProcessor(test_output_consumer)
|
||||
.errorProcessor(test_error_consumer);
|
||||
|
||||
assertEquals(work_directory, operation1.workDirectory());
|
||||
assertEquals(java_tool, operation1.javaTool());
|
||||
assertTrue(operation1.javaOptions().contains(test_java_option1));
|
||||
assertTrue(operation1.javaOptions().contains(test_java_option2));
|
||||
assertTrue(operation1.testToolOptions().contains(test_tool_option1));
|
||||
assertTrue(operation1.testToolOptions().contains(test_tool_option2));
|
||||
assertTrue(operation1.classpath().contains(test_classpath1));
|
||||
assertTrue(operation1.classpath().contains(test_classpath2));
|
||||
assertEquals(test_tool_main_class, operation1.mainClass());
|
||||
assertSame(test_output_consumer, operation1.outputProcessor());
|
||||
assertSame(test_error_consumer, operation1.errorProcessor());
|
||||
|
||||
var operation2 = new JUnitOperation();
|
||||
operation2.workDirectory(work_directory);
|
||||
operation2.javaTool(java_tool);
|
||||
operation2.javaOptions().add(test_java_option1);
|
||||
operation2.javaOptions().add(test_java_option2);
|
||||
operation2.testToolOptions().add(test_tool_option1);
|
||||
operation2.testToolOptions().add(test_tool_option2);
|
||||
operation2.classpath().add(test_classpath1);
|
||||
operation2.classpath().add(test_classpath2);
|
||||
operation2.mainClass(test_tool_main_class);
|
||||
operation2.outputProcessor(test_output_consumer);
|
||||
operation2.errorProcessor(test_error_consumer);
|
||||
|
||||
assertEquals(work_directory, operation2.workDirectory());
|
||||
assertEquals(java_tool, operation2.javaTool());
|
||||
assertTrue(operation2.javaOptions().contains(test_java_option1));
|
||||
assertTrue(operation2.javaOptions().contains(test_java_option2));
|
||||
assertTrue(operation2.testToolOptions().contains(test_tool_option1));
|
||||
assertTrue(operation2.testToolOptions().contains(test_tool_option2));
|
||||
assertTrue(operation2.classpath().contains(test_classpath1));
|
||||
assertTrue(operation2.classpath().contains(test_classpath2));
|
||||
assertEquals(test_tool_main_class, operation2.mainClass());
|
||||
assertSame(test_output_consumer, operation2.outputProcessor());
|
||||
assertSame(test_error_consumer, operation2.errorProcessor());
|
||||
|
||||
var operation3 = new JUnitOperation();
|
||||
operation3
|
||||
.classpath(test_classpath1, test_classpath2)
|
||||
.testToolOptions(test_tool_option1, test_tool_option2);
|
||||
|
||||
assertTrue(operation3.classpath().contains(test_classpath1));
|
||||
assertTrue(operation3.classpath().contains(test_classpath2));
|
||||
assertTrue(operation3.testToolOptions().contains(test_tool_option1));
|
||||
assertTrue(operation3.testToolOptions().contains(test_tool_option2));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(work_directory);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var source_file1 = new File(tmp, "Source1.java");
|
||||
var source_file2 = new File(tmp, "Source2.java");
|
||||
|
||||
FileUtils.writeString("""
|
||||
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("""
|
||||
public class Source2 {
|
||||
public static void main(String[] arguments)
|
||||
throws Exception {
|
||||
System.out.print(new Source1().name_.equals("source1"));
|
||||
}
|
||||
}
|
||||
""", source_file2);
|
||||
var build_main = new File(tmp, "buildMain");
|
||||
var build_test = new File(tmp, "buildTest");
|
||||
|
||||
var compile_operation = new CompileOperation()
|
||||
.buildMainDirectory(build_main)
|
||||
.buildTestDirectory(build_test)
|
||||
.compileMainClasspath(List.of(build_main.getAbsolutePath()))
|
||||
.compileTestClasspath(List.of(build_main.getAbsolutePath(), build_test.getAbsolutePath()))
|
||||
.mainSourceFiles(List.of(source_file1))
|
||||
.testSourceFiles(List.of(source_file2));
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
|
||||
var output = new StringBuilder();
|
||||
var test_operation = new JUnitOperation()
|
||||
.mainClass("Source2")
|
||||
.classpath(List.of(build_main.getAbsolutePath(), build_test.getAbsolutePath()))
|
||||
.outputProcessor(s -> {
|
||||
output.append(s);
|
||||
return true;
|
||||
});
|
||||
test_operation.execute();
|
||||
|
||||
assertEquals("true", output.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("com.example")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation.project()).execute();
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
new JUnitOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.outputProcessor(s -> {
|
||||
check_result.append(s).append(System.lineSeparator());
|
||||
return true;
|
||||
})
|
||||
.execute();
|
||||
assertTrue(check_result.toString().contains("""
|
||||
[ 2 containers found ]
|
||||
[ 0 containers skipped ]
|
||||
[ 2 containers started ]
|
||||
[ 0 containers aborted ]
|
||||
[ 2 containers successful ]
|
||||
[ 0 containers failed ]
|
||||
[ 1 tests found ]
|
||||
[ 0 tests skipped ]
|
||||
[ 1 tests started ]
|
||||
[ 0 tests aborted ]
|
||||
[ 1 tests successful ]
|
||||
[ 0 tests failed ]
|
||||
"""));
|
||||
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
218
src/test/java/rife/bld/operations/TestJarOperation.java
Normal file
218
src/test/java/rife/bld/operations/TestJarOperation.java
Normal file
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
* 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.bld.NamedFile;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestJarOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new JarOperation();
|
||||
assertTrue(operation.manifestAttributes().isEmpty());
|
||||
assertTrue(operation.sourceDirectories().isEmpty());
|
||||
assertTrue(operation.sourceFiles().isEmpty());
|
||||
assertNull(operation.destinationDirectory());
|
||||
assertNull(operation.destinationFileName());
|
||||
assertTrue(operation.included().isEmpty());
|
||||
assertTrue(operation.excluded().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var manifest_attribute_1a = Attributes.Name.MANIFEST_VERSION;
|
||||
var manifest_attribute_1b = "manifestAttribute1";
|
||||
var manifest_attribute_2a = Attributes.Name.MAIN_CLASS;
|
||||
var manifest_Attribute_2b = "manifestAttribute2";
|
||||
var source_directory1 = new File("sourceDirectory1");
|
||||
var source_directory2 = new File("sourceDirectory2");
|
||||
var source_file1 = new NamedFile("sourceFile1", new File("sourceFile1"));
|
||||
var source_file2 = new NamedFile("sourceFile2", new File("sourceFile2"));
|
||||
var destination_directory = new File("destinationDirectory");
|
||||
var destination_fileName = "destinationFileName";
|
||||
var included1 = Pattern.compile("included1");
|
||||
var included2 = Pattern.compile("included2");
|
||||
var excluded1 = Pattern.compile("excluded1");
|
||||
var excluded2 = Pattern.compile("excluded2");
|
||||
|
||||
var operation1 = new JarOperation()
|
||||
.manifestAttributes(Map.of(manifest_attribute_1a, manifest_attribute_1b, manifest_attribute_2a, manifest_Attribute_2b))
|
||||
.sourceDirectories(List.of(source_directory1, source_directory2))
|
||||
.sourceFiles(List.of(source_file1, source_file2))
|
||||
.destinationDirectory(destination_directory)
|
||||
.destinationFileName(destination_fileName)
|
||||
.included(List.of(included1, included2))
|
||||
.excluded(List.of(excluded1, excluded2));
|
||||
|
||||
assertEquals(manifest_attribute_1b, operation1.manifestAttributes().get(manifest_attribute_1a));
|
||||
assertEquals(manifest_Attribute_2b, operation1.manifestAttributes().get(manifest_attribute_2a));
|
||||
assertTrue(operation1.sourceDirectories().contains(source_directory1));
|
||||
assertTrue(operation1.sourceDirectories().contains(source_directory2));
|
||||
assertTrue(operation1.sourceFiles().contains(source_file1));
|
||||
assertTrue(operation1.sourceFiles().contains(source_file2));
|
||||
assertEquals(destination_directory, operation1.destinationDirectory());
|
||||
assertEquals(destination_fileName, operation1.destinationFileName());
|
||||
assertEquals(new File(destination_directory, destination_fileName), operation1.destinationFile());
|
||||
assertTrue(operation1.included().contains(included1));
|
||||
assertTrue(operation1.included().contains(included2));
|
||||
assertTrue(operation1.excluded().contains(excluded1));
|
||||
assertTrue(operation1.excluded().contains(excluded2));
|
||||
|
||||
var operation2 = new JarOperation()
|
||||
.destinationDirectory(destination_directory)
|
||||
.destinationFileName(destination_fileName);
|
||||
operation2.manifestAttributes().put(manifest_attribute_1a, manifest_attribute_1b);
|
||||
operation2.manifestAttributes().put(manifest_attribute_2a, manifest_Attribute_2b);
|
||||
operation2.sourceDirectories().add(source_directory1);
|
||||
operation2.sourceDirectories().add(source_directory2);
|
||||
operation2.sourceFiles().add(source_file1);
|
||||
operation2.sourceFiles().add(source_file2);
|
||||
operation2.included().add(included1);
|
||||
operation2.included().add(included2);
|
||||
operation2.excluded().add(excluded1);
|
||||
operation2.excluded().add(excluded2);
|
||||
|
||||
assertEquals(manifest_attribute_1b, operation2.manifestAttributes().get(manifest_attribute_1a));
|
||||
assertEquals(manifest_Attribute_2b, operation2.manifestAttributes().get(manifest_attribute_2a));
|
||||
assertTrue(operation2.sourceDirectories().contains(source_directory1));
|
||||
assertTrue(operation2.sourceDirectories().contains(source_directory2));
|
||||
assertTrue(operation2.sourceFiles().contains(source_file1));
|
||||
assertTrue(operation2.sourceFiles().contains(source_file2));
|
||||
assertEquals(destination_directory, operation2.destinationDirectory());
|
||||
assertEquals(destination_fileName, operation2.destinationFileName());
|
||||
assertTrue(operation2.included().contains(included1));
|
||||
assertTrue(operation2.included().contains(included2));
|
||||
assertTrue(operation2.excluded().contains(excluded1));
|
||||
assertTrue(operation2.excluded().contains(excluded2));
|
||||
|
||||
var operation3 = new JarOperation()
|
||||
.manifestAttribute(manifest_attribute_1a, manifest_attribute_1b)
|
||||
.manifestAttribute(manifest_attribute_2a, manifest_Attribute_2b)
|
||||
.sourceDirectories(source_directory1, source_directory2)
|
||||
.sourceFiles(source_file1, source_file2)
|
||||
.destinationDirectory(destination_directory)
|
||||
.destinationFileName(destination_fileName)
|
||||
.included(included1, included2)
|
||||
.excluded(excluded1, excluded2);
|
||||
|
||||
assertEquals(manifest_attribute_1b, operation3.manifestAttributes().get(manifest_attribute_1a));
|
||||
assertEquals(manifest_Attribute_2b, operation3.manifestAttributes().get(manifest_attribute_2a));
|
||||
assertTrue(operation3.sourceDirectories().contains(source_directory1));
|
||||
assertTrue(operation3.sourceDirectories().contains(source_directory2));
|
||||
assertTrue(operation3.sourceFiles().contains(source_file1));
|
||||
assertTrue(operation3.sourceFiles().contains(source_file2));
|
||||
assertEquals(destination_directory, operation3.destinationDirectory());
|
||||
assertEquals(destination_fileName, operation3.destinationFileName());
|
||||
assertTrue(operation3.included().contains(included1));
|
||||
assertTrue(operation3.included().contains(included2));
|
||||
assertTrue(operation3.excluded().contains(excluded1));
|
||||
assertTrue(operation3.excluded().contains(excluded2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var source_dir = new File(tmp, "source");
|
||||
var destination_dir = new File(tmp, "destination");
|
||||
var destination_name = "archive.jar";
|
||||
|
||||
source_dir.mkdirs();
|
||||
FileUtils.writeString("source1", new File(source_dir, "source1.text"));
|
||||
FileUtils.writeString("source2", new File(source_dir, "source2.text"));
|
||||
FileUtils.writeString("source3", new File(source_dir, "source3.text"));
|
||||
FileUtils.writeString("source4", new File(source_dir, "source4.txt"));
|
||||
var source5 = new File(tmp, "source5.text");
|
||||
var source6 = new File(tmp, "source6.text");
|
||||
FileUtils.writeString("source5", source5);
|
||||
FileUtils.writeString("source6", source6);
|
||||
|
||||
new JarOperation()
|
||||
.sourceDirectories(List.of(source_dir))
|
||||
.sourceFiles(List.of(
|
||||
new NamedFile("src5.txt", source5),
|
||||
new NamedFile("src6.txt", source6)))
|
||||
.destinationDirectory(destination_dir)
|
||||
.destinationFileName(destination_name)
|
||||
.included("source.*\\.text")
|
||||
.excluded("source5.*")
|
||||
.execute();
|
||||
|
||||
var jar_archive = new File(destination_dir, destination_name);
|
||||
assertTrue(jar_archive.exists());
|
||||
|
||||
var content = new StringBuilder();
|
||||
try (var jar = new JarFile(jar_archive)) {
|
||||
var e = jar.entries();
|
||||
while (e.hasMoreElements()) {
|
||||
var jar_entry = e.nextElement();
|
||||
content.append(jar_entry.getName());
|
||||
content.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("""
|
||||
META-INF/MANIFEST.MF
|
||||
source1.text
|
||||
source2.text
|
||||
source3.text
|
||||
src6.txt
|
||||
""", content.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("tst")
|
||||
.projectName("app")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.execute();
|
||||
|
||||
var jar_operation = new JarOperation()
|
||||
.fromProject(create_operation.project());
|
||||
jar_operation.execute();
|
||||
|
||||
var content = new StringBuilder();
|
||||
try (var jar = new JarFile(new File(jar_operation.destinationDirectory(), jar_operation.destinationFileName()))) {
|
||||
var e = jar.entries();
|
||||
while (e.hasMoreElements()) {
|
||||
var jar_entry = e.nextElement();
|
||||
content.append(jar_entry.getName());
|
||||
content.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("""
|
||||
META-INF/MANIFEST.MF
|
||||
tst/AppMain.class
|
||||
""", content.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
368
src/test/java/rife/bld/operations/TestJavadocOperation.java
Normal file
368
src/test/java/rife/bld/operations/TestJavadocOperation.java
Normal file
|
@ -0,0 +1,368 @@
|
|||
/*
|
||||
* 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.bld.operations.exceptions.ExitStatusException;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import javax.tools.DiagnosticCollector;
|
||||
import javax.tools.JavaFileObject;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestJavadocOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new JavadocOperation();
|
||||
assertNull(operation.buildDirectory());
|
||||
assertTrue(operation.classpath().isEmpty());
|
||||
assertTrue(operation.sourceFiles().isEmpty());
|
||||
assertTrue(operation.javadocOptions().isEmpty());
|
||||
assertTrue(operation.diagnostics().isEmpty());
|
||||
assertTrue(operation.included().isEmpty());
|
||||
assertTrue(operation.excluded().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var build_directory = new File("buildDirectory");
|
||||
var classpath1 = "classpath1";
|
||||
var classpath2 = "classpath2";
|
||||
var source_file1 = new File("sourceFile1");
|
||||
var source_file2 = new File("sourceFile2");
|
||||
var source_dir1 = new File("sourceDir1");
|
||||
var source_dir2 = new File("sourceDir2");
|
||||
var javadoc_option1 = "javadocOption1";
|
||||
var javadoc_option2 = "javadocOption2";
|
||||
var included1 = Pattern.compile("included1");
|
||||
var included2 = Pattern.compile("included2");
|
||||
var excluded1 = Pattern.compile("excluded1");
|
||||
var excluded2 = Pattern.compile("excluded2");
|
||||
|
||||
var operation1 = new JavadocOperation()
|
||||
.buildDirectory(build_directory)
|
||||
.classpath(List.of(classpath1, classpath2))
|
||||
.sourceFiles(List.of(source_file1, source_file2))
|
||||
.sourceDirectories(List.of(source_dir1, source_dir2))
|
||||
.javadocOptions(List.of(javadoc_option1, javadoc_option2))
|
||||
.included(List.of(included1, included2))
|
||||
.excluded(List.of(excluded1, excluded2));
|
||||
|
||||
assertEquals(build_directory, operation1.buildDirectory());
|
||||
assertTrue(operation1.classpath().contains(classpath1));
|
||||
assertTrue(operation1.classpath().contains(classpath2));
|
||||
assertTrue(operation1.sourceFiles().contains(source_file1));
|
||||
assertTrue(operation1.sourceFiles().contains(source_file2));
|
||||
assertTrue(operation1.sourceDirectories().contains(source_dir1));
|
||||
assertTrue(operation1.sourceDirectories().contains(source_dir2));
|
||||
assertTrue(operation1.javadocOptions().contains(javadoc_option1));
|
||||
assertTrue(operation1.javadocOptions().contains(javadoc_option2));
|
||||
assertTrue(operation1.included().contains(included1));
|
||||
assertTrue(operation1.included().contains(included2));
|
||||
assertTrue(operation1.excluded().contains(excluded1));
|
||||
assertTrue(operation1.excluded().contains(excluded2));
|
||||
|
||||
var operation2 = new JavadocOperation()
|
||||
.buildDirectory(build_directory);
|
||||
operation2.classpath().add(classpath1);
|
||||
operation2.classpath().add(classpath2);
|
||||
operation2.sourceFiles().add(source_file1);
|
||||
operation2.sourceFiles().add(source_file2);
|
||||
operation2.sourceDirectories().add(source_dir1);
|
||||
operation2.sourceDirectories().add(source_dir2);
|
||||
operation2.javadocOptions().add(javadoc_option1);
|
||||
operation2.javadocOptions().add(javadoc_option2);
|
||||
operation2.included().add(included1);
|
||||
operation2.included().add(included2);
|
||||
operation2.excluded().add(excluded1);
|
||||
operation2.excluded().add(excluded2);
|
||||
|
||||
assertEquals(build_directory, operation2.buildDirectory());
|
||||
assertTrue(operation2.classpath().contains(classpath1));
|
||||
assertTrue(operation2.classpath().contains(classpath2));
|
||||
assertTrue(operation2.sourceFiles().contains(source_file1));
|
||||
assertTrue(operation2.sourceFiles().contains(source_file2));
|
||||
assertTrue(operation2.sourceDirectories().contains(source_dir1));
|
||||
assertTrue(operation2.sourceDirectories().contains(source_dir2));
|
||||
assertTrue(operation2.javadocOptions().contains(javadoc_option1));
|
||||
assertTrue(operation2.javadocOptions().contains(javadoc_option2));
|
||||
assertTrue(operation2.included().contains(included1));
|
||||
assertTrue(operation2.included().contains(included2));
|
||||
assertTrue(operation2.excluded().contains(excluded1));
|
||||
assertTrue(operation2.excluded().contains(excluded2));
|
||||
|
||||
var operation3 = new JavadocOperation()
|
||||
.buildDirectory(build_directory)
|
||||
.classpath(classpath1, classpath2)
|
||||
.sourceFiles(source_file1, source_file2)
|
||||
.sourceDirectories(source_dir1, source_dir2)
|
||||
.javadocOptions(List.of(javadoc_option1, javadoc_option2))
|
||||
.included(included1, included2)
|
||||
.excluded(excluded1, excluded2);
|
||||
|
||||
assertEquals(build_directory, operation3.buildDirectory());
|
||||
assertTrue(operation3.classpath().contains(classpath1));
|
||||
assertTrue(operation3.classpath().contains(classpath2));
|
||||
assertTrue(operation3.sourceFiles().contains(source_file1));
|
||||
assertTrue(operation3.sourceFiles().contains(source_file2));
|
||||
assertTrue(operation3.sourceDirectories().contains(source_dir1));
|
||||
assertTrue(operation3.sourceDirectories().contains(source_dir2));
|
||||
assertTrue(operation3.javadocOptions().contains(javadoc_option1));
|
||||
assertTrue(operation3.javadocOptions().contains(javadoc_option2));
|
||||
assertTrue(operation3.included().contains(included1));
|
||||
assertTrue(operation3.included().contains(included2));
|
||||
assertTrue(operation3.excluded().contains(excluded1));
|
||||
assertTrue(operation3.excluded().contains(excluded2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var source_file1 = new File(tmp, "Source1.java");
|
||||
var source_file2 = new File(tmp, "Source2.java");
|
||||
var source_file3 = new File(tmp, "Source3.java");
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source1 {
|
||||
public final String name_;
|
||||
public Source1() {
|
||||
name_ = "source1";
|
||||
}
|
||||
}
|
||||
""", source_file1);
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source2 {
|
||||
public final String name_;
|
||||
public Source2(Source1 source1) {
|
||||
name_ = source1.name_;
|
||||
}
|
||||
}
|
||||
""", source_file2);
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source3 {
|
||||
public final String name1_;
|
||||
public final String name2_;
|
||||
public Source3(Source1 source1, Source2 source2) {
|
||||
name1_ = source1.name_;
|
||||
name2_ = source2.name_;
|
||||
}
|
||||
}
|
||||
""", source_file3);
|
||||
var build = new File(tmp, "build");
|
||||
var build_html1 = new File(build, "Source1.html");
|
||||
var build_html2 = new File(build, "Source2.html");
|
||||
var build_html3 = new File(build, "Source3.html");
|
||||
var build_index_html = new File(build, "index.html");
|
||||
var build_index_all_html = new File(build, "index-all.html");
|
||||
|
||||
assertFalse(build_html1.exists());
|
||||
assertFalse(build_html2.exists());
|
||||
assertFalse(build_html3.exists());
|
||||
assertFalse(build_index_html.exists());
|
||||
assertFalse(build_index_all_html.exists());
|
||||
|
||||
var operation = new JavadocOperation()
|
||||
.buildDirectory(build)
|
||||
.classpath(List.of(build.getAbsolutePath()))
|
||||
.sourceFiles(List.of(source_file1, source_file2, source_file3));
|
||||
operation.execute();
|
||||
assertTrue(operation.diagnostics().isEmpty());
|
||||
|
||||
assertTrue(build_html1.exists());
|
||||
assertTrue(build_html2.exists());
|
||||
assertTrue(build_html3.exists());
|
||||
assertTrue(build_index_html.exists());
|
||||
assertTrue(build_index_all_html.exists());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIncludeExclude()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var source_file1 = new File(tmp, "Source1.java");
|
||||
var source_file2 = new File(tmp, "Source2.java");
|
||||
var source_file3 = new File(tmp, "Source3.java");
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source1 {
|
||||
public final String name_;
|
||||
public Source1() {
|
||||
name_ = "source1";
|
||||
}
|
||||
}
|
||||
""", source_file1);
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source2 {
|
||||
public final String name_;
|
||||
public Source2(String name) {
|
||||
name_ = name;
|
||||
}
|
||||
}
|
||||
""", source_file2);
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source3 {
|
||||
public final String name1_;
|
||||
public final String name2_;
|
||||
public Source3(Source1 source1, Source2 source2) {
|
||||
name1_ = source1.name_;
|
||||
name2_ = source2.name_;
|
||||
}
|
||||
}
|
||||
""", source_file3);
|
||||
var build = new File(tmp, "build");
|
||||
var build_html1 = new File(build, "Source1.html");
|
||||
var build_html2 = new File(build, "Source2.html");
|
||||
var build_html3 = new File(build, "Source3.html");
|
||||
var build_index_html = new File(build, "index.html");
|
||||
var build_index_all_html = new File(build, "index-all.html");
|
||||
|
||||
assertFalse(build_html1.exists());
|
||||
assertFalse(build_html2.exists());
|
||||
assertFalse(build_html3.exists());
|
||||
assertFalse(build_index_html.exists());
|
||||
assertFalse(build_index_all_html.exists());
|
||||
|
||||
var operation = new JavadocOperation()
|
||||
.buildDirectory(build)
|
||||
.classpath(List.of(build.getAbsolutePath()))
|
||||
.sourceFiles(List.of(source_file1, source_file2, source_file3))
|
||||
.included("Source([12])")
|
||||
.excluded("Source1");
|
||||
operation.execute();
|
||||
assertTrue(operation.diagnostics().isEmpty());
|
||||
|
||||
assertFalse(build_html1.exists());
|
||||
assertTrue(build_html2.exists());
|
||||
assertFalse(build_html3.exists());
|
||||
assertTrue(build_index_html.exists());
|
||||
assertTrue(build_index_all_html.exists());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("tst")
|
||||
.projectName("app")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
var javadoc_operation = new JavadocOperation()
|
||||
.fromProject(create_operation.project());
|
||||
|
||||
var main_app_html = new File(new File(javadoc_operation.buildDirectory(), "tst"), "AppMain.html");
|
||||
var index_html = new File(javadoc_operation.buildDirectory(), "index.html");
|
||||
var index_all_html = new File(javadoc_operation.buildDirectory(), "index-all.html");
|
||||
assertFalse(main_app_html.exists());
|
||||
assertFalse(index_html.exists());
|
||||
assertFalse(index_all_html.exists());
|
||||
|
||||
javadoc_operation.execute();
|
||||
assertTrue(javadoc_operation.diagnostics().isEmpty());
|
||||
|
||||
assertTrue(main_app_html.exists());
|
||||
assertTrue(index_html.exists());
|
||||
assertTrue(index_all_html.exists());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecuteGenerationErrors()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var source_file1 = new File(tmp, "Source1.java");
|
||||
var source_file2 = new File(tmp, "Source2.java");
|
||||
var source_file3 = new File(tmp, "Source3.java");
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source1 {
|
||||
public final String;
|
||||
public Source1() {
|
||||
name_ = "source1";
|
||||
}
|
||||
}
|
||||
""", source_file1);
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source2 {
|
||||
public final String name_;
|
||||
public Source2(Source1B source1) {
|
||||
noName_ = source1.name_;
|
||||
}
|
||||
}
|
||||
""", source_file2);
|
||||
|
||||
FileUtils.writeString("""
|
||||
public class Source3 {
|
||||
public final String name1_;
|
||||
public final String name2_;
|
||||
public Source3(Source1 source1, Source2 source2) {
|
||||
name_ = source1.name_;
|
||||
name_ = source2.name_;
|
||||
}
|
||||
}
|
||||
""", source_file3);
|
||||
var build = new File(tmp, "build");
|
||||
var build_html1 = new File(build, "Source1.html");
|
||||
var build_html2 = new File(build, "Source2.html");
|
||||
var build_html3 = new File(build, "Source3.html");
|
||||
var build_index_html = new File(build, "index.html");
|
||||
var build_index_all_html = new File(build, "index-all.html");
|
||||
|
||||
assertFalse(build_html1.exists());
|
||||
assertFalse(build_html2.exists());
|
||||
assertFalse(build_html3.exists());
|
||||
assertFalse(build_index_html.exists());
|
||||
assertFalse(build_index_all_html.exists());
|
||||
|
||||
var operation = new JavadocOperation() {
|
||||
public void executeProcessDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics) {
|
||||
// don't output diagnostics
|
||||
}
|
||||
};
|
||||
operation.buildDirectory(build)
|
||||
.classpath(List.of(build.getAbsolutePath()))
|
||||
.sourceFiles(List.of(source_file1, source_file2, source_file3));
|
||||
assertThrows(ExitStatusException.class, operation::execute);
|
||||
assertEquals(2, operation.diagnostics().size());
|
||||
|
||||
var diagnostic1 = operation.diagnostics().get(0);
|
||||
|
||||
assertEquals("/Source1.java", diagnostic1.getSource().toUri().getPath().substring(tmp.getAbsolutePath().length()));
|
||||
|
||||
assertFalse(build_html1.exists());
|
||||
assertFalse(build_html2.exists());
|
||||
assertFalse(build_html3.exists());
|
||||
assertFalse(build_index_html.exists());
|
||||
assertFalse(build_index_all_html.exists());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
137
src/test/java/rife/bld/operations/TestPrecompileOperation.java
Normal file
137
src/test/java/rife/bld/operations/TestPrecompileOperation.java
Normal file
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* 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());
|
||||
|
||||
var operation3 = new PrecompileOperation()
|
||||
.templateTypes(TemplateType.HTML, TemplateType.JSON)
|
||||
.sourceDirectories(source_directory1, source_directory2)
|
||||
.destinationDirectory(destination_directory);
|
||||
|
||||
assertTrue(operation3.templateTypes().contains(TemplateType.HTML));
|
||||
assertTrue(operation3.templateTypes().contains(TemplateType.JSON));
|
||||
assertTrue(operation3.sourceDirectories().contains(source_directory1));
|
||||
assertTrue(operation3.sourceDirectories().contains(source_directory2));
|
||||
assertEquals(destination_directory, operation3.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);
|
||||
}
|
||||
}
|
||||
}
|
689
src/test/java/rife/bld/operations/TestPublishOperation.java
Normal file
689
src/test/java/rife/bld/operations/TestPublishOperation.java
Normal file
|
@ -0,0 +1,689 @@
|
|||
/*
|
||||
* 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.json.JSONObject;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.Project;
|
||||
import rife.bld.blueprints.BlankProjectBlueprint;
|
||||
import rife.bld.dependencies.*;
|
||||
import rife.bld.publish.PublishArtifact;
|
||||
import rife.tools.FileUtils;
|
||||
import rife.tools.exceptions.FileUtilsErrorException;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestPublishOperation {
|
||||
static File reposiliteJar_ = null;
|
||||
|
||||
@BeforeAll
|
||||
static void downloadReposilite()
|
||||
throws Exception {
|
||||
reposiliteJar_ = File.createTempFile("reposilite", "jar");
|
||||
reposiliteJar_.deleteOnExit();
|
||||
System.out.print("Downloading: https://maven.reposilite.com/releases/com/reposilite/reposilite/3.4.0/reposilite-3.4.0-all.jar ...");
|
||||
System.out.flush();
|
||||
FileUtils.copy(new URL("https://maven.reposilite.com/releases/com/reposilite/reposilite/3.4.0/reposilite-3.4.0-all.jar").openStream(), reposiliteJar_);
|
||||
System.out.println("done");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void deleteReposilite()
|
||||
throws Exception {
|
||||
if (reposiliteJar_ != null) {
|
||||
reposiliteJar_.delete();
|
||||
reposiliteJar_ = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new PublishOperation();
|
||||
assertTrue(operation.repositories().isEmpty());
|
||||
assertNull(operation.moment());
|
||||
assertTrue(operation.dependencies().isEmpty());
|
||||
assertNotNull(operation.info());
|
||||
assertNull(operation.info().groupId());
|
||||
assertNull(operation.info().artifactId());
|
||||
assertNull(operation.info().version());
|
||||
assertNull(operation.info().name());
|
||||
assertNull(operation.info().description());
|
||||
assertNull(operation.info().url());
|
||||
assertTrue(operation.info().licenses().isEmpty());
|
||||
assertTrue(operation.info().developers().isEmpty());
|
||||
assertNull(operation.info().scm());
|
||||
assertTrue(operation.artifacts().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var repository1 = new Repository("repository1");
|
||||
var repository2 = new Repository("repository2");
|
||||
var moment = ZonedDateTime.now();
|
||||
|
||||
var artifact1 = new PublishArtifact(new File("file1"), "classifier1", "type1");
|
||||
var artifact2 = new PublishArtifact(new File("file2"), "classifier2", "type2");
|
||||
|
||||
var operation1 = new PublishOperation()
|
||||
.repositories(repository1, repository2)
|
||||
.moment(moment)
|
||||
.artifacts(List.of(artifact1, artifact2));
|
||||
assertTrue(operation1.repositories().contains(repository1));
|
||||
assertTrue(operation1.repositories().contains(repository2));
|
||||
assertEquals(moment, operation1.moment());
|
||||
assertTrue(operation1.artifacts().contains(artifact1));
|
||||
assertTrue(operation1.artifacts().contains(artifact2));
|
||||
|
||||
var operation2 = new PublishOperation()
|
||||
.moment(moment);
|
||||
operation2.repositories().add(repository1);
|
||||
operation2.repositories().add(repository2);
|
||||
operation2.artifacts().add(artifact1);
|
||||
operation2.artifacts().add(artifact2);
|
||||
assertTrue(operation2.repositories().contains(repository1));
|
||||
assertTrue(operation2.repositories().contains(repository2));
|
||||
assertEquals(moment, operation2.moment());
|
||||
assertTrue(operation2.artifacts().contains(artifact1));
|
||||
assertTrue(operation2.artifacts().contains(artifact2));
|
||||
|
||||
var operation3 = new PublishOperation()
|
||||
.repository(repository1)
|
||||
.repository(repository2)
|
||||
.moment(moment)
|
||||
.artifacts(List.of(artifact1, artifact2));
|
||||
assertTrue(operation3.repositories().contains(repository1));
|
||||
assertTrue(operation3.repositories().contains(repository2));
|
||||
assertEquals(moment, operation3.moment());
|
||||
assertTrue(operation3.artifacts().contains(artifact1));
|
||||
assertTrue(operation3.artifacts().contains(artifact2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPublishRelease()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
var tmp_reposilite = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var process_builder = new ProcessBuilder(
|
||||
"java", "-jar", reposiliteJar_.getAbsolutePath(),
|
||||
"-wd", tmp_reposilite.getAbsolutePath(),
|
||||
"-p", "8081",
|
||||
"--token", "manager:passwd");
|
||||
process_builder.directory(tmp_reposilite);
|
||||
var process = process_builder.start();
|
||||
|
||||
// wait for full startup
|
||||
Thread.sleep(4000);
|
||||
|
||||
// verify the version doesn't exist
|
||||
assertThrows(FileUtilsErrorException.class, () -> FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
|
||||
assertThrows(FileUtilsErrorException.class, () -> FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/0.0.1")));
|
||||
|
||||
// create a first publication
|
||||
var create_operation1 = new CreateBlankOperation()
|
||||
.workDirectory(tmp1)
|
||||
.packageName("test.pkg")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation1.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation1.project())
|
||||
.execute();
|
||||
|
||||
var jar_operation1 = new JarOperation()
|
||||
.fromProject(create_operation1.project());
|
||||
jar_operation1.execute();
|
||||
|
||||
var publish_operation1 = new PublishOperation()
|
||||
.fromProject(create_operation1.project())
|
||||
.repositories(new Repository("http://localhost:8081/releases", "manager", "passwd"));
|
||||
publish_operation1.execute();
|
||||
|
||||
var dir_json1 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
|
||||
assertEquals("myapp", dir_json1.get("name"));
|
||||
var dir_files_json1 = dir_json1.getJSONArray("files");
|
||||
assertEquals(6, dir_files_json1.length());
|
||||
assertEquals("0.0.1", dir_files_json1.getJSONObject(0).get("name"));
|
||||
assertEquals("maven-metadata.xml.md5", dir_files_json1.getJSONObject(1).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha1", dir_files_json1.getJSONObject(2).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha256", dir_files_json1.getJSONObject(3).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha512", dir_files_json1.getJSONObject(4).get("name"));
|
||||
assertEquals("maven-metadata.xml", dir_files_json1.getJSONObject(5).get("name"));
|
||||
|
||||
var maven_metadata1 = new Xml2MavenMetadata();
|
||||
maven_metadata1.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/maven-metadata.xml")));
|
||||
assertEquals(create_operation1.project().version(), maven_metadata1.getLatest());
|
||||
assertEquals(create_operation1.project().version(), maven_metadata1.getRelease());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_metadata1.getSnapshot());
|
||||
assertNull(maven_metadata1.getSnapshotTimestamp());
|
||||
assertNull(maven_metadata1.getSnapshotBuildNumber());
|
||||
assertEquals(1, maven_metadata1.getVersions().size());
|
||||
assertTrue(maven_metadata1.getVersions().contains(create_operation1.project().version()));
|
||||
|
||||
var version_json1 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/0.0.1")));
|
||||
assertEquals("0.0.1", version_json1.get("name"));
|
||||
var version_files_json1 = version_json1.getJSONArray("files");
|
||||
assertEquals(10, version_files_json1.length());
|
||||
assertEquals("myapp-0.0.1.jar.md5", version_files_json1.getJSONObject(0).get("name"));
|
||||
assertEquals("myapp-0.0.1.jar.sha1", version_files_json1.getJSONObject(1).get("name"));
|
||||
assertEquals("myapp-0.0.1.jar.sha256", version_files_json1.getJSONObject(2).get("name"));
|
||||
assertEquals("myapp-0.0.1.jar.sha512", version_files_json1.getJSONObject(3).get("name"));
|
||||
assertEquals("myapp-0.0.1.jar", version_files_json1.getJSONObject(4).get("name"));
|
||||
assertEquals("myapp-0.0.1.pom.md5", version_files_json1.getJSONObject(5).get("name"));
|
||||
assertEquals("myapp-0.0.1.pom.sha1", version_files_json1.getJSONObject(6).get("name"));
|
||||
assertEquals("myapp-0.0.1.pom.sha256", version_files_json1.getJSONObject(7).get("name"));
|
||||
assertEquals("myapp-0.0.1.pom.sha512", version_files_json1.getJSONObject(8).get("name"));
|
||||
assertEquals("myapp-0.0.1.pom", version_files_json1.getJSONObject(9).get("name"));
|
||||
|
||||
// created an updated publication
|
||||
var create_operation2 = new CreateBlankOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new BlankProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 0, 0));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp2)
|
||||
.packageName("test.pkg")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation2.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation2.project())
|
||||
.execute();
|
||||
|
||||
var jar_operation2 = new JarOperation()
|
||||
.fromProject(create_operation2.project());
|
||||
jar_operation2.execute();
|
||||
|
||||
var publish_operation2 = new PublishOperation()
|
||||
.fromProject(create_operation2.project())
|
||||
.repositories(new Repository("http://localhost:8081/releases", "manager", "passwd"));
|
||||
publish_operation2.execute();
|
||||
|
||||
var dir_json2 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
|
||||
assertEquals("myapp", dir_json2.get("name"));
|
||||
var dir_files_json2 = dir_json2.getJSONArray("files");
|
||||
assertEquals(7, dir_files_json2.length());
|
||||
assertEquals("0.0.1", dir_files_json2.getJSONObject(0).get("name"));
|
||||
assertEquals("1.0.0", dir_files_json2.getJSONObject(1).get("name"));
|
||||
assertEquals("maven-metadata.xml.md5", dir_files_json2.getJSONObject(2).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha1", dir_files_json2.getJSONObject(3).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha256", dir_files_json2.getJSONObject(4).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha512", dir_files_json2.getJSONObject(5).get("name"));
|
||||
assertEquals("maven-metadata.xml", dir_files_json2.getJSONObject(6).get("name"));
|
||||
|
||||
var maven_metadata2 = new Xml2MavenMetadata();
|
||||
maven_metadata2.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/maven-metadata.xml")));
|
||||
assertEquals(create_operation2.project().version(), maven_metadata2.getLatest());
|
||||
assertEquals(create_operation2.project().version(), maven_metadata2.getRelease());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_metadata2.getSnapshot());
|
||||
assertNull(maven_metadata2.getSnapshotTimestamp());
|
||||
assertNull(maven_metadata2.getSnapshotBuildNumber());
|
||||
assertEquals(2, maven_metadata2.getVersions().size());
|
||||
assertTrue(maven_metadata2.getVersions().contains(create_operation1.project().version()));
|
||||
assertTrue(maven_metadata2.getVersions().contains(create_operation2.project().version()));
|
||||
|
||||
var version_json1b = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/0.0.1")));
|
||||
assertEquals("0.0.1", version_json1b.get("name"));
|
||||
var version_files_json1b = version_json1b.getJSONArray("files");
|
||||
assertEquals(10, version_files_json1b.length());
|
||||
assertEquals("myapp-0.0.1.jar.md5", version_files_json1b.getJSONObject(0).get("name"));
|
||||
assertEquals("myapp-0.0.1.jar.sha1", version_files_json1b.getJSONObject(1).get("name"));
|
||||
assertEquals("myapp-0.0.1.jar.sha256", version_files_json1b.getJSONObject(2).get("name"));
|
||||
assertEquals("myapp-0.0.1.jar.sha512", version_files_json1b.getJSONObject(3).get("name"));
|
||||
assertEquals("myapp-0.0.1.jar", version_files_json1b.getJSONObject(4).get("name"));
|
||||
assertEquals("myapp-0.0.1.pom.md5", version_files_json1b.getJSONObject(5).get("name"));
|
||||
assertEquals("myapp-0.0.1.pom.sha1", version_files_json1b.getJSONObject(6).get("name"));
|
||||
assertEquals("myapp-0.0.1.pom.sha256", version_files_json1b.getJSONObject(7).get("name"));
|
||||
assertEquals("myapp-0.0.1.pom.sha512", version_files_json1b.getJSONObject(8).get("name"));
|
||||
assertEquals("myapp-0.0.1.pom", version_files_json1b.getJSONObject(9).get("name"));
|
||||
|
||||
var version_json2 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/1.0.0")));
|
||||
assertEquals("1.0.0", version_json2.get("name"));
|
||||
var version_files_json2 = version_json2.getJSONArray("files");
|
||||
assertEquals(10, version_files_json2.length());
|
||||
assertEquals("myapp-1.0.0.jar.md5", version_files_json2.getJSONObject(0).get("name"));
|
||||
assertEquals("myapp-1.0.0.jar.sha1", version_files_json2.getJSONObject(1).get("name"));
|
||||
assertEquals("myapp-1.0.0.jar.sha256", version_files_json2.getJSONObject(2).get("name"));
|
||||
assertEquals("myapp-1.0.0.jar.sha512", version_files_json2.getJSONObject(3).get("name"));
|
||||
assertEquals("myapp-1.0.0.jar", version_files_json2.getJSONObject(4).get("name"));
|
||||
assertEquals("myapp-1.0.0.pom.md5", version_files_json2.getJSONObject(5).get("name"));
|
||||
assertEquals("myapp-1.0.0.pom.sha1", version_files_json2.getJSONObject(6).get("name"));
|
||||
assertEquals("myapp-1.0.0.pom.sha256", version_files_json2.getJSONObject(7).get("name"));
|
||||
assertEquals("myapp-1.0.0.pom.sha512", version_files_json2.getJSONObject(8).get("name"));
|
||||
assertEquals("myapp-1.0.0.pom", version_files_json2.getJSONObject(9).get("name"));
|
||||
|
||||
process.destroy();
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp_reposilite);
|
||||
FileUtils.deleteDirectory(tmp2);
|
||||
FileUtils.deleteDirectory(tmp1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPublishReleaseLocal()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
var tmp_local = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
// create a first publication
|
||||
var create_operation1 = new CreateBlankOperation()
|
||||
.workDirectory(tmp1)
|
||||
.packageName("test.pkg")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation1.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation1.project())
|
||||
.execute();
|
||||
|
||||
var jar_operation1 = new JarOperation()
|
||||
.fromProject(create_operation1.project());
|
||||
jar_operation1.execute();
|
||||
|
||||
var publish_operation1 = new PublishOperation()
|
||||
.fromProject(create_operation1.project())
|
||||
.repositories(new Repository(tmp_local.getAbsolutePath()));
|
||||
publish_operation1.execute();
|
||||
|
||||
assertEquals("""
|
||||
/test
|
||||
/test/pkg
|
||||
/test/pkg/myapp
|
||||
/test/pkg/myapp/0.0.1
|
||||
/test/pkg/myapp/0.0.1/myapp-0.0.1.jar
|
||||
/test/pkg/myapp/0.0.1/myapp-0.0.1.pom
|
||||
/test/pkg/myapp/maven-metadata-local.xml""", FileUtils.generateDirectoryListing(tmp_local));
|
||||
|
||||
var maven_metadata1 = new Xml2MavenMetadata();
|
||||
maven_metadata1.processXml(FileUtils.readString(Path.of(tmp_local.getAbsolutePath(), "test", "pkg", "myapp", "maven-metadata-local.xml").toFile()));
|
||||
assertEquals(create_operation1.project().version(), maven_metadata1.getLatest());
|
||||
assertEquals(create_operation1.project().version(), maven_metadata1.getRelease());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_metadata1.getSnapshot());
|
||||
assertNull(maven_metadata1.getSnapshotTimestamp());
|
||||
assertNull(maven_metadata1.getSnapshotBuildNumber());
|
||||
assertEquals(1, maven_metadata1.getVersions().size());
|
||||
assertTrue(maven_metadata1.getVersions().contains(create_operation1.project().version()));
|
||||
|
||||
// created an updated publication
|
||||
var create_operation2 = new CreateBlankOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new BlankProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 0, 0));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp2)
|
||||
.packageName("test.pkg")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation2.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation2.project())
|
||||
.execute();
|
||||
|
||||
var jar_operation2 = new JarOperation()
|
||||
.fromProject(create_operation2.project());
|
||||
jar_operation2.execute();
|
||||
|
||||
var publish_operation2 = new PublishOperation()
|
||||
.fromProject(create_operation2.project())
|
||||
.repositories(new Repository(tmp_local.getAbsolutePath()));
|
||||
publish_operation2.execute();
|
||||
|
||||
assertEquals("""
|
||||
/test
|
||||
/test/pkg
|
||||
/test/pkg/myapp
|
||||
/test/pkg/myapp/0.0.1
|
||||
/test/pkg/myapp/0.0.1/myapp-0.0.1.jar
|
||||
/test/pkg/myapp/0.0.1/myapp-0.0.1.pom
|
||||
/test/pkg/myapp/1.0.0
|
||||
/test/pkg/myapp/1.0.0/myapp-1.0.0.jar
|
||||
/test/pkg/myapp/1.0.0/myapp-1.0.0.pom
|
||||
/test/pkg/myapp/maven-metadata-local.xml""", FileUtils.generateDirectoryListing(tmp_local));
|
||||
|
||||
var maven_metadata2 = new Xml2MavenMetadata();
|
||||
maven_metadata2.processXml(FileUtils.readString(Path.of(tmp_local.getAbsolutePath(), "test", "pkg", "myapp", "maven-metadata-local.xml").toFile()));
|
||||
assertEquals(create_operation2.project().version(), maven_metadata2.getLatest());
|
||||
assertEquals(create_operation2.project().version(), maven_metadata2.getRelease());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_metadata2.getSnapshot());
|
||||
assertNull(maven_metadata2.getSnapshotTimestamp());
|
||||
assertNull(maven_metadata2.getSnapshotBuildNumber());
|
||||
assertEquals(2, maven_metadata2.getVersions().size());
|
||||
assertTrue(maven_metadata2.getVersions().contains(create_operation1.project().version()));
|
||||
assertTrue(maven_metadata2.getVersions().contains(create_operation2.project().version()));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp_local);
|
||||
FileUtils.deleteDirectory(tmp2);
|
||||
FileUtils.deleteDirectory(tmp1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPublishSnapshot()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
var tmp_reposilite = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var process_builder = new ProcessBuilder(
|
||||
"java", "-jar", reposiliteJar_.getAbsolutePath(),
|
||||
"-wd", tmp_reposilite.getAbsolutePath(),
|
||||
"-p", "8081",
|
||||
"--token", "manager:passwd");
|
||||
process_builder.directory(tmp_reposilite);
|
||||
var process = process_builder.start();
|
||||
|
||||
// wait for full startup
|
||||
Thread.sleep(4000);
|
||||
|
||||
// verify the version doesn't exist
|
||||
assertThrows(FileUtilsErrorException.class, () -> FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
|
||||
assertThrows(FileUtilsErrorException.class, () -> FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/1.2.3-SNAPSHOT")));
|
||||
|
||||
// create a first publication
|
||||
var create_operation1 = new CreateBlankOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new BlankProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp1)
|
||||
.packageName("test.pkg")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation1.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation1.project())
|
||||
.execute();
|
||||
|
||||
var jar_operation1 = new JarOperation()
|
||||
.fromProject(create_operation1.project());
|
||||
jar_operation1.execute();
|
||||
|
||||
var publish_operation1 = new PublishOperation()
|
||||
.fromProject(create_operation1.project())
|
||||
.moment(ZonedDateTime.of(2023, 3, 29, 18, 54, 32, 909, ZoneId.of("America/New_York")))
|
||||
.repositories(new Repository("http://localhost:8081/releases", "manager", "passwd"));
|
||||
publish_operation1.execute();
|
||||
|
||||
var dir_json1 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
|
||||
assertEquals("myapp", dir_json1.get("name"));
|
||||
var dir_files_json1 = dir_json1.getJSONArray("files");
|
||||
assertEquals(6, dir_files_json1.length());
|
||||
assertEquals("1.2.3-SNAPSHOT", dir_files_json1.getJSONObject(0).get("name"));
|
||||
assertEquals("maven-metadata.xml.md5", dir_files_json1.getJSONObject(1).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha1", dir_files_json1.getJSONObject(2).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha256", dir_files_json1.getJSONObject(3).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha512", dir_files_json1.getJSONObject(4).get("name"));
|
||||
assertEquals("maven-metadata.xml", dir_files_json1.getJSONObject(5).get("name"));
|
||||
|
||||
var maven_metadata1 = new Xml2MavenMetadata();
|
||||
maven_metadata1.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/maven-metadata.xml")));
|
||||
assertEquals(create_operation1.project().version(), maven_metadata1.getLatest());
|
||||
assertEquals(create_operation1.project().version(), maven_metadata1.getRelease());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_metadata1.getSnapshot());
|
||||
assertNull(maven_metadata1.getSnapshotTimestamp());
|
||||
assertNull(maven_metadata1.getSnapshotBuildNumber());
|
||||
assertEquals(1, maven_metadata1.getVersions().size());
|
||||
assertTrue(maven_metadata1.getVersions().contains(create_operation1.project().version()));
|
||||
|
||||
var version_json1 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/1.2.3-SNAPSHOT")));
|
||||
assertEquals("1.2.3-SNAPSHOT", version_json1.get("name"));
|
||||
var version_files_json1 = version_json1.getJSONArray("files");
|
||||
assertEquals(15, version_files_json1.length());
|
||||
assertEquals("maven-metadata.xml.md5", version_files_json1.getJSONObject(0).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha1", version_files_json1.getJSONObject(1).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha256", version_files_json1.getJSONObject(2).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha512", version_files_json1.getJSONObject(3).get("name"));
|
||||
assertEquals("maven-metadata.xml", version_files_json1.getJSONObject(4).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230329.225432-1.jar.md5", version_files_json1.getJSONObject(5).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230329.225432-1.jar.sha1", version_files_json1.getJSONObject(6).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230329.225432-1.jar.sha256", version_files_json1.getJSONObject(7).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230329.225432-1.jar.sha512", version_files_json1.getJSONObject(8).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230329.225432-1.jar", version_files_json1.getJSONObject(9).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230329.225432-1.pom.md5", version_files_json1.getJSONObject(10).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230329.225432-1.pom.sha1", version_files_json1.getJSONObject(11).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230329.225432-1.pom.sha256", version_files_json1.getJSONObject(12).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230329.225432-1.pom.sha512", version_files_json1.getJSONObject(13).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230329.225432-1.pom", version_files_json1.getJSONObject(14).get("name"));
|
||||
|
||||
var maven_snapshot_metadata1 = new Xml2MavenMetadata();
|
||||
maven_snapshot_metadata1.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/1.2.3-SNAPSHOT/maven-metadata.xml")));
|
||||
assertEquals(create_operation1.project().version(), maven_snapshot_metadata1.getLatest());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_snapshot_metadata1.getRelease());
|
||||
assertEquals(new VersionNumber(1, 2, 3, "20230329.225432-1"), maven_snapshot_metadata1.getSnapshot());
|
||||
assertEquals("20230329.225432", maven_snapshot_metadata1.getSnapshotTimestamp());
|
||||
assertEquals(1, maven_snapshot_metadata1.getSnapshotBuildNumber());
|
||||
assertEquals(1, maven_snapshot_metadata1.getVersions().size());
|
||||
assertTrue(maven_snapshot_metadata1.getVersions().contains(create_operation1.project().version()));
|
||||
|
||||
// created an updated publication
|
||||
var create_operation2 = new CreateBlankOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new BlankProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp2)
|
||||
.packageName("test.pkg")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation2.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation2.project())
|
||||
.execute();
|
||||
|
||||
var jar_operation2 = new JarOperation()
|
||||
.fromProject(create_operation2.project());
|
||||
jar_operation2.execute();
|
||||
|
||||
var publish_operation2 = new PublishOperation()
|
||||
.fromProject(create_operation2.project())
|
||||
.moment(ZonedDateTime.of(2023, 3, 30, 13, 17, 29, 89, ZoneId.of("America/New_York")))
|
||||
.repositories(new Repository("http://localhost:8081/releases", "manager", "passwd"));
|
||||
publish_operation2.execute();
|
||||
|
||||
var dir_json2 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
|
||||
assertEquals("myapp", dir_json2.get("name"));
|
||||
var dir_files_json2 = dir_json2.getJSONArray("files");
|
||||
assertEquals(6, dir_files_json2.length());
|
||||
assertEquals("1.2.3-SNAPSHOT", dir_files_json2.getJSONObject(0).get("name"));
|
||||
assertEquals("maven-metadata.xml.md5", dir_files_json2.getJSONObject(1).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha1", dir_files_json2.getJSONObject(2).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha256", dir_files_json2.getJSONObject(3).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha512", dir_files_json2.getJSONObject(4).get("name"));
|
||||
assertEquals("maven-metadata.xml", dir_files_json2.getJSONObject(5).get("name"));
|
||||
|
||||
var maven_metadata2 = new Xml2MavenMetadata();
|
||||
maven_metadata2.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/maven-metadata.xml")));
|
||||
assertEquals(create_operation2.project().version(), maven_metadata2.getLatest());
|
||||
assertEquals(create_operation2.project().version(), maven_metadata2.getRelease());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_metadata2.getSnapshot());
|
||||
assertNull(maven_metadata2.getSnapshotTimestamp());
|
||||
assertNull(maven_metadata2.getSnapshotBuildNumber());
|
||||
assertEquals(1, maven_metadata2.getVersions().size());
|
||||
assertTrue(maven_metadata2.getVersions().contains(create_operation1.project().version()));
|
||||
assertTrue(maven_metadata2.getVersions().contains(create_operation2.project().version()));
|
||||
|
||||
var version_json2 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/1.2.3-SNAPSHOT")));
|
||||
assertEquals("1.2.3-SNAPSHOT", version_json2.get("name"));
|
||||
var version_files_json2 = version_json2.getJSONArray("files");
|
||||
assertEquals(15, version_files_json2.length());
|
||||
assertEquals("maven-metadata.xml.md5", version_files_json2.getJSONObject(0).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha1", version_files_json2.getJSONObject(1).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha256", version_files_json2.getJSONObject(2).get("name"));
|
||||
assertEquals("maven-metadata.xml.sha512", version_files_json2.getJSONObject(3).get("name"));
|
||||
assertEquals("maven-metadata.xml", version_files_json2.getJSONObject(4).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230330.171729-2.jar.md5", version_files_json2.getJSONObject(5).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230330.171729-2.jar.sha1", version_files_json2.getJSONObject(6).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230330.171729-2.jar.sha256", version_files_json2.getJSONObject(7).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230330.171729-2.jar.sha512", version_files_json2.getJSONObject(8).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230330.171729-2.jar", version_files_json2.getJSONObject(9).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230330.171729-2.pom.md5", version_files_json2.getJSONObject(10).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230330.171729-2.pom.sha1", version_files_json2.getJSONObject(11).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230330.171729-2.pom.sha256", version_files_json2.getJSONObject(12).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230330.171729-2.pom.sha512", version_files_json2.getJSONObject(13).get("name"));
|
||||
assertEquals("myapp-1.2.3-20230330.171729-2.pom", version_files_json2.getJSONObject(14).get("name"));
|
||||
|
||||
var maven_snapshot_metadata2 = new Xml2MavenMetadata();
|
||||
maven_snapshot_metadata2.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/1.2.3-SNAPSHOT/maven-metadata.xml")));
|
||||
assertEquals(create_operation2.project().version(), maven_snapshot_metadata2.getLatest());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_snapshot_metadata2.getRelease());
|
||||
assertEquals(new VersionNumber(1, 2, 3, "20230330.171729-2"), maven_snapshot_metadata2.getSnapshot());
|
||||
assertEquals("20230330.171729", maven_snapshot_metadata2.getSnapshotTimestamp());
|
||||
assertEquals(2, maven_snapshot_metadata2.getSnapshotBuildNumber());
|
||||
assertEquals(1, maven_snapshot_metadata2.getVersions().size());
|
||||
assertTrue(maven_snapshot_metadata2.getVersions().contains(create_operation2.project().version()));
|
||||
|
||||
process.destroy();
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp_reposilite);
|
||||
FileUtils.deleteDirectory(tmp2);
|
||||
FileUtils.deleteDirectory(tmp1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPublishSnapshotLocal()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
var tmp_local = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
// create a first publication
|
||||
var create_operation1 = new CreateBlankOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new BlankProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp1)
|
||||
.packageName("test.pkg")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation1.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation1.project())
|
||||
.execute();
|
||||
|
||||
var jar_operation1 = new JarOperation()
|
||||
.fromProject(create_operation1.project());
|
||||
jar_operation1.execute();
|
||||
|
||||
var publish_operation1 = new PublishOperation()
|
||||
.fromProject(create_operation1.project())
|
||||
.moment(ZonedDateTime.of(2023, 3, 29, 18, 54, 32, 909, ZoneId.of("America/New_York")))
|
||||
.repositories(new Repository(tmp_local.getAbsolutePath()));
|
||||
publish_operation1.execute();
|
||||
|
||||
assertEquals("""
|
||||
/test
|
||||
/test/pkg
|
||||
/test/pkg/myapp
|
||||
/test/pkg/myapp/1.2.3-SNAPSHOT
|
||||
/test/pkg/myapp/1.2.3-SNAPSHOT/maven-metadata-local.xml
|
||||
/test/pkg/myapp/1.2.3-SNAPSHOT/myapp-1.2.3-SNAPSHOT.jar
|
||||
/test/pkg/myapp/1.2.3-SNAPSHOT/myapp-1.2.3-SNAPSHOT.pom
|
||||
/test/pkg/myapp/maven-metadata-local.xml""", FileUtils.generateDirectoryListing(tmp_local));
|
||||
|
||||
var maven_metadata1 = new Xml2MavenMetadata();
|
||||
maven_metadata1.processXml(FileUtils.readString(Path.of(tmp_local.getAbsolutePath(), "test", "pkg", "myapp", "maven-metadata-local.xml").toFile()));
|
||||
assertEquals(create_operation1.project().version(), maven_metadata1.getLatest());
|
||||
assertEquals(create_operation1.project().version(), maven_metadata1.getRelease());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_metadata1.getSnapshot());
|
||||
assertNull(maven_metadata1.getSnapshotTimestamp());
|
||||
assertNull(maven_metadata1.getSnapshotBuildNumber());
|
||||
assertEquals(1, maven_metadata1.getVersions().size());
|
||||
assertTrue(maven_metadata1.getVersions().contains(create_operation1.project().version()));
|
||||
|
||||
var maven_snapshot_metadata1 = new Xml2MavenMetadata();
|
||||
maven_snapshot_metadata1.processXml(FileUtils.readString(Path.of(tmp_local.getAbsolutePath(), "test", "pkg", "myapp", "1.2.3-SNAPSHOT", "maven-metadata-local.xml").toFile()));
|
||||
assertEquals(create_operation1.project().version(), maven_snapshot_metadata1.getLatest());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_snapshot_metadata1.getRelease());
|
||||
assertEquals(new VersionNumber(1, 2, 3, "SNAPSHOT"), maven_snapshot_metadata1.getSnapshot());
|
||||
assertNull(maven_snapshot_metadata1.getSnapshotTimestamp());
|
||||
assertNull(maven_snapshot_metadata1.getSnapshotBuildNumber());
|
||||
assertEquals(1, maven_snapshot_metadata1.getVersions().size());
|
||||
assertTrue(maven_snapshot_metadata1.getVersions().contains(create_operation1.project().version()));
|
||||
|
||||
// created an updated publication
|
||||
var create_operation2 = new CreateBlankOperation() {
|
||||
protected Project createProjectBlueprint() {
|
||||
return new BlankProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1, 2, 3, "SNAPSHOT"));
|
||||
}
|
||||
}
|
||||
.workDirectory(tmp2)
|
||||
.packageName("test.pkg")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation2.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation2.project())
|
||||
.execute();
|
||||
|
||||
var jar_operation2 = new JarOperation()
|
||||
.fromProject(create_operation2.project());
|
||||
jar_operation2.execute();
|
||||
|
||||
var publish_operation2 = new PublishOperation()
|
||||
.fromProject(create_operation2.project())
|
||||
.moment(ZonedDateTime.of(2023, 3, 30, 13, 17, 29, 89, ZoneId.of("America/New_York")))
|
||||
.repositories(new Repository(tmp_local.getAbsolutePath()));
|
||||
publish_operation2.execute();
|
||||
|
||||
assertEquals("""
|
||||
/test
|
||||
/test/pkg
|
||||
/test/pkg/myapp
|
||||
/test/pkg/myapp/1.2.3-SNAPSHOT
|
||||
/test/pkg/myapp/1.2.3-SNAPSHOT/maven-metadata-local.xml
|
||||
/test/pkg/myapp/1.2.3-SNAPSHOT/myapp-1.2.3-SNAPSHOT.jar
|
||||
/test/pkg/myapp/1.2.3-SNAPSHOT/myapp-1.2.3-SNAPSHOT.pom
|
||||
/test/pkg/myapp/maven-metadata-local.xml""", FileUtils.generateDirectoryListing(tmp_local));
|
||||
|
||||
var maven_metadata2 = new Xml2MavenMetadata();
|
||||
maven_metadata2.processXml(FileUtils.readString(Path.of(tmp_local.getAbsolutePath(), "test", "pkg", "myapp", "maven-metadata-local.xml").toFile()));
|
||||
assertEquals(create_operation2.project().version(), maven_metadata2.getLatest());
|
||||
assertEquals(create_operation2.project().version(), maven_metadata2.getRelease());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_metadata2.getSnapshot());
|
||||
assertNull(maven_metadata2.getSnapshotTimestamp());
|
||||
assertNull(maven_metadata2.getSnapshotBuildNumber());
|
||||
assertEquals(1, maven_metadata2.getVersions().size());
|
||||
assertTrue(maven_metadata2.getVersions().contains(create_operation1.project().version()));
|
||||
assertTrue(maven_metadata2.getVersions().contains(create_operation2.project().version()));
|
||||
|
||||
var maven_snapshot_metadata2 = new Xml2MavenMetadata();
|
||||
maven_snapshot_metadata2.processXml(FileUtils.readString(Path.of(tmp_local.getAbsolutePath(), "test", "pkg", "myapp", "1.2.3-SNAPSHOT", "maven-metadata-local.xml").toFile()));
|
||||
assertEquals(create_operation2.project().version(), maven_snapshot_metadata2.getLatest());
|
||||
assertEquals(VersionNumber.UNKNOWN, maven_snapshot_metadata2.getRelease());
|
||||
assertEquals(new VersionNumber(1, 2, 3, "SNAPSHOT"), maven_snapshot_metadata2.getSnapshot());
|
||||
assertNull(maven_snapshot_metadata2.getSnapshotTimestamp());
|
||||
assertNull(maven_snapshot_metadata2.getSnapshotBuildNumber());
|
||||
assertEquals(1, maven_snapshot_metadata2.getVersions().size());
|
||||
assertTrue(maven_snapshot_metadata2.getVersions().contains(create_operation2.project().version()));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp_local);
|
||||
FileUtils.deleteDirectory(tmp2);
|
||||
FileUtils.deleteDirectory(tmp1);
|
||||
}
|
||||
}
|
||||
}
|
541
src/test/java/rife/bld/operations/TestPurgeOperation.java
Normal file
541
src/test/java/rife/bld/operations/TestPurgeOperation.java
Normal file
|
@ -0,0 +1,541 @@
|
|||
/*
|
||||
* 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.bld.WebProject;
|
||||
import rife.bld.dependencies.*;
|
||||
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 TestPurgeOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new PurgeOperation();
|
||||
assertTrue(operation.dependencies().isEmpty());
|
||||
assertTrue(operation.repositories().isEmpty());
|
||||
assertNull(operation.libCompileDirectory());
|
||||
assertNull(operation.libRuntimeDirectory());
|
||||
assertNull(operation.libStandaloneDirectory());
|
||||
assertNull(operation.libTestDirectory());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var repository1 = new Repository("repository1");
|
||||
var repository2 = new Repository("repository2");
|
||||
var dependency1 = new Dependency("group1", "artifact1");
|
||||
var dependency2 = new Dependency("group2", "artifact2");
|
||||
var dir1 = new File("dir1");
|
||||
var dir2 = new File("dir2");
|
||||
var dir3 = new File("dir3");
|
||||
var dir4 = new File("dir4");
|
||||
|
||||
var operation1 = new PurgeOperation()
|
||||
.repositories(List.of(repository1, repository2))
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4);
|
||||
var dependency_scopes = new DependencyScopes();
|
||||
dependency_scopes.scope(Scope.compile).include(dependency1).include(dependency2);
|
||||
operation1.dependencies(dependency_scopes);
|
||||
assertTrue(operation1.repositories().contains(repository1));
|
||||
assertTrue(operation1.repositories().contains(repository2));
|
||||
assertTrue(operation1.dependencies().scope(Scope.compile).contains(dependency1));
|
||||
assertTrue(operation1.dependencies().scope(Scope.compile).contains(dependency2));
|
||||
assertEquals(dir1, operation1.libCompileDirectory());
|
||||
assertEquals(dir2, operation1.libRuntimeDirectory());
|
||||
assertEquals(dir3, operation1.libStandaloneDirectory());
|
||||
assertEquals(dir4, operation1.libTestDirectory());
|
||||
|
||||
var operation2 = new PurgeOperation()
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4);
|
||||
operation2.repositories().add(repository1);
|
||||
operation2.repositories().add(repository2);
|
||||
operation2.dependencies().scope(Scope.compile).include(dependency1).include(dependency2);
|
||||
operation2.dependencies(dependency_scopes);
|
||||
assertTrue(operation2.repositories().contains(repository1));
|
||||
assertTrue(operation2.repositories().contains(repository2));
|
||||
assertTrue(operation2.dependencies().scope(Scope.compile).contains(dependency1));
|
||||
assertTrue(operation2.dependencies().scope(Scope.compile).contains(dependency2));
|
||||
assertEquals(dir1, operation2.libCompileDirectory());
|
||||
assertEquals(dir2, operation2.libRuntimeDirectory());
|
||||
assertEquals(dir3, operation2.libStandaloneDirectory());
|
||||
assertEquals(dir4, operation2.libTestDirectory());
|
||||
|
||||
var operation3 = new PurgeOperation()
|
||||
.repositories(repository1, repository2);
|
||||
assertTrue(operation3.repositories().contains(repository1));
|
||||
assertTrue(operation3.repositories().contains(repository2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecution()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var dir1 = new File(tmp, "dir1");
|
||||
var dir2 = new File(tmp, "dir2");
|
||||
var dir3 = new File(tmp, "dir3");
|
||||
var dir4 = new File(tmp, "dir4");
|
||||
dir1.mkdirs();
|
||||
dir2.mkdirs();
|
||||
dir3.mkdirs();
|
||||
dir4.mkdirs();
|
||||
|
||||
var operation_download1 = new DownloadOperation()
|
||||
.repositories(List.of(Repository.MAVEN_CENTRAL))
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4);
|
||||
operation_download1.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 1)));
|
||||
operation_download1.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 3)));
|
||||
operation_download1.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 0)));
|
||||
operation_download1.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 0)));
|
||||
|
||||
operation_download1.execute();
|
||||
|
||||
var operation_download2 = new DownloadOperation()
|
||||
.repositories(List.of(Repository.MAVEN_CENTRAL))
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4);
|
||||
operation_download2.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 12, 0)));
|
||||
operation_download2.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 4)));
|
||||
operation_download2.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 6)));
|
||||
operation_download2.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 2, 1)));
|
||||
|
||||
operation_download2.execute();
|
||||
|
||||
assertEquals("""
|
||||
/dir1
|
||||
/dir1/commons-lang3-3.1.jar
|
||||
/dir1/commons-lang3-3.12.0.jar
|
||||
/dir2
|
||||
/dir2/commons-collections4-4.3.jar
|
||||
/dir2/commons-collections4-4.4.jar
|
||||
/dir3
|
||||
/dir3/slf4j-api-2.0.0.jar
|
||||
/dir3/slf4j-api-2.0.6.jar
|
||||
/dir3/slf4j-simple-2.0.0.jar
|
||||
/dir3/slf4j-simple-2.0.6.jar
|
||||
/dir4
|
||||
/dir4/commons-codec-1.13.jar
|
||||
/dir4/httpclient5-5.0.jar
|
||||
/dir4/httpclient5-5.2.1.jar
|
||||
/dir4/httpcore5-5.0.jar
|
||||
/dir4/httpcore5-5.2.jar
|
||||
/dir4/httpcore5-h2-5.0.jar
|
||||
/dir4/httpcore5-h2-5.2.jar
|
||||
/dir4/slf4j-api-1.7.25.jar
|
||||
/dir4/slf4j-api-1.7.36.jar""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
var operation_purge = new PurgeOperation()
|
||||
.repositories(List.of(Repository.MAVEN_CENTRAL))
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4);
|
||||
operation_purge.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 12, 0)));
|
||||
operation_purge.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 4)));
|
||||
operation_purge.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 6)));
|
||||
operation_purge.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 2, 1)));
|
||||
|
||||
operation_purge.execute();
|
||||
|
||||
assertEquals("""
|
||||
/dir1
|
||||
/dir1/commons-lang3-3.12.0.jar
|
||||
/dir2
|
||||
/dir2/commons-collections4-4.4.jar
|
||||
/dir3
|
||||
/dir3/slf4j-api-2.0.6.jar
|
||||
/dir3/slf4j-simple-2.0.6.jar
|
||||
/dir4
|
||||
/dir4/httpclient5-5.2.1.jar
|
||||
/dir4/httpcore5-5.2.jar
|
||||
/dir4/httpcore5-h2-5.2.jar
|
||||
/dir4/slf4j-api-1.7.36.jar""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecutionAdditionalSourcesJavadoc()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var dir1 = new File(tmp, "dir1");
|
||||
var dir2 = new File(tmp, "dir2");
|
||||
var dir3 = new File(tmp, "dir3");
|
||||
var dir4 = new File(tmp, "dir4");
|
||||
dir1.mkdirs();
|
||||
dir2.mkdirs();
|
||||
dir3.mkdirs();
|
||||
dir4.mkdirs();
|
||||
|
||||
var operation_download1 = new DownloadOperation()
|
||||
.repositories(List.of(Repository.MAVEN_CENTRAL))
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4)
|
||||
.downloadJavadoc(true)
|
||||
.downloadSources(true);
|
||||
operation_download1.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 1)));
|
||||
operation_download1.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 3)));
|
||||
operation_download1.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 0)));
|
||||
operation_download1.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 0)));
|
||||
|
||||
operation_download1.execute();
|
||||
|
||||
var operation_download2 = new DownloadOperation()
|
||||
.repositories(List.of(Repository.MAVEN_CENTRAL))
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4)
|
||||
.downloadJavadoc(true)
|
||||
.downloadSources(true);
|
||||
operation_download2.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 12, 0)));
|
||||
operation_download2.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 4)));
|
||||
operation_download2.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 6)));
|
||||
operation_download2.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 2, 1)));
|
||||
|
||||
operation_download2.execute();
|
||||
|
||||
assertEquals("""
|
||||
/dir1
|
||||
/dir1/commons-lang3-3.1-javadoc.jar
|
||||
/dir1/commons-lang3-3.1-sources.jar
|
||||
/dir1/commons-lang3-3.1.jar
|
||||
/dir1/commons-lang3-3.12.0-javadoc.jar
|
||||
/dir1/commons-lang3-3.12.0-sources.jar
|
||||
/dir1/commons-lang3-3.12.0.jar
|
||||
/dir2
|
||||
/dir2/commons-collections4-4.3-javadoc.jar
|
||||
/dir2/commons-collections4-4.3-sources.jar
|
||||
/dir2/commons-collections4-4.3.jar
|
||||
/dir2/commons-collections4-4.4-javadoc.jar
|
||||
/dir2/commons-collections4-4.4-sources.jar
|
||||
/dir2/commons-collections4-4.4.jar
|
||||
/dir3
|
||||
/dir3/slf4j-api-2.0.0-javadoc.jar
|
||||
/dir3/slf4j-api-2.0.0-sources.jar
|
||||
/dir3/slf4j-api-2.0.0.jar
|
||||
/dir3/slf4j-api-2.0.6-javadoc.jar
|
||||
/dir3/slf4j-api-2.0.6-sources.jar
|
||||
/dir3/slf4j-api-2.0.6.jar
|
||||
/dir3/slf4j-simple-2.0.0-javadoc.jar
|
||||
/dir3/slf4j-simple-2.0.0-sources.jar
|
||||
/dir3/slf4j-simple-2.0.0.jar
|
||||
/dir3/slf4j-simple-2.0.6-javadoc.jar
|
||||
/dir3/slf4j-simple-2.0.6-sources.jar
|
||||
/dir3/slf4j-simple-2.0.6.jar
|
||||
/dir4
|
||||
/dir4/commons-codec-1.13-javadoc.jar
|
||||
/dir4/commons-codec-1.13-sources.jar
|
||||
/dir4/commons-codec-1.13.jar
|
||||
/dir4/httpclient5-5.0-javadoc.jar
|
||||
/dir4/httpclient5-5.0-sources.jar
|
||||
/dir4/httpclient5-5.0.jar
|
||||
/dir4/httpclient5-5.2.1-javadoc.jar
|
||||
/dir4/httpclient5-5.2.1-sources.jar
|
||||
/dir4/httpclient5-5.2.1.jar
|
||||
/dir4/httpcore5-5.0-javadoc.jar
|
||||
/dir4/httpcore5-5.0-sources.jar
|
||||
/dir4/httpcore5-5.0.jar
|
||||
/dir4/httpcore5-5.2-javadoc.jar
|
||||
/dir4/httpcore5-5.2-sources.jar
|
||||
/dir4/httpcore5-5.2.jar
|
||||
/dir4/httpcore5-h2-5.0-javadoc.jar
|
||||
/dir4/httpcore5-h2-5.0-sources.jar
|
||||
/dir4/httpcore5-h2-5.0.jar
|
||||
/dir4/httpcore5-h2-5.2-javadoc.jar
|
||||
/dir4/httpcore5-h2-5.2-sources.jar
|
||||
/dir4/httpcore5-h2-5.2.jar
|
||||
/dir4/slf4j-api-1.7.25-javadoc.jar
|
||||
/dir4/slf4j-api-1.7.25-sources.jar
|
||||
/dir4/slf4j-api-1.7.25.jar
|
||||
/dir4/slf4j-api-1.7.36-javadoc.jar
|
||||
/dir4/slf4j-api-1.7.36-sources.jar
|
||||
/dir4/slf4j-api-1.7.36.jar""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
var operation_purge = new PurgeOperation()
|
||||
.repositories(List.of(Repository.MAVEN_CENTRAL))
|
||||
.libCompileDirectory(dir1)
|
||||
.libRuntimeDirectory(dir2)
|
||||
.libStandaloneDirectory(dir3)
|
||||
.libTestDirectory(dir4)
|
||||
.preserveSources(true)
|
||||
.preserveJavadoc(true);
|
||||
operation_purge.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 12, 0)));
|
||||
operation_purge.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 4)));
|
||||
operation_purge.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 6)));
|
||||
operation_purge.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 2, 1)));
|
||||
|
||||
operation_purge.execute();
|
||||
|
||||
assertEquals("""
|
||||
/dir1
|
||||
/dir1/commons-lang3-3.12.0-javadoc.jar
|
||||
/dir1/commons-lang3-3.12.0-sources.jar
|
||||
/dir1/commons-lang3-3.12.0.jar
|
||||
/dir2
|
||||
/dir2/commons-collections4-4.4-javadoc.jar
|
||||
/dir2/commons-collections4-4.4-sources.jar
|
||||
/dir2/commons-collections4-4.4.jar
|
||||
/dir3
|
||||
/dir3/slf4j-api-2.0.6-javadoc.jar
|
||||
/dir3/slf4j-api-2.0.6-sources.jar
|
||||
/dir3/slf4j-api-2.0.6.jar
|
||||
/dir3/slf4j-simple-2.0.6-javadoc.jar
|
||||
/dir3/slf4j-simple-2.0.6-sources.jar
|
||||
/dir3/slf4j-simple-2.0.6.jar
|
||||
/dir4
|
||||
/dir4/httpclient5-5.2.1-javadoc.jar
|
||||
/dir4/httpclient5-5.2.1-sources.jar
|
||||
/dir4/httpclient5-5.2.1.jar
|
||||
/dir4/httpcore5-5.2-javadoc.jar
|
||||
/dir4/httpcore5-5.2-sources.jar
|
||||
/dir4/httpcore5-5.2.jar
|
||||
/dir4/httpcore5-h2-5.2-javadoc.jar
|
||||
/dir4/httpcore5-h2-5.2-sources.jar
|
||||
/dir4/httpcore5-h2-5.2.jar
|
||||
/dir4/slf4j-api-1.7.36-javadoc.jar
|
||||
/dir4/slf4j-api-1.7.36-sources.jar
|
||||
/dir4/slf4j-api-1.7.36.jar""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
operation_purge
|
||||
.preserveJavadoc(false).execute();
|
||||
|
||||
assertEquals("""
|
||||
/dir1
|
||||
/dir1/commons-lang3-3.12.0-sources.jar
|
||||
/dir1/commons-lang3-3.12.0.jar
|
||||
/dir2
|
||||
/dir2/commons-collections4-4.4-sources.jar
|
||||
/dir2/commons-collections4-4.4.jar
|
||||
/dir3
|
||||
/dir3/slf4j-api-2.0.6-sources.jar
|
||||
/dir3/slf4j-api-2.0.6.jar
|
||||
/dir3/slf4j-simple-2.0.6-sources.jar
|
||||
/dir3/slf4j-simple-2.0.6.jar
|
||||
/dir4
|
||||
/dir4/httpclient5-5.2.1-sources.jar
|
||||
/dir4/httpclient5-5.2.1.jar
|
||||
/dir4/httpcore5-5.2-sources.jar
|
||||
/dir4/httpcore5-5.2.jar
|
||||
/dir4/httpcore5-h2-5.2-sources.jar
|
||||
/dir4/httpcore5-h2-5.2.jar
|
||||
/dir4/slf4j-api-1.7.36-sources.jar
|
||||
/dir4/slf4j-api-1.7.36.jar""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
operation_purge
|
||||
.preserveSources(false).execute();
|
||||
|
||||
assertEquals("""
|
||||
/dir1
|
||||
/dir1/commons-lang3-3.12.0.jar
|
||||
/dir2
|
||||
/dir2/commons-collections4-4.4.jar
|
||||
/dir3
|
||||
/dir3/slf4j-api-2.0.6.jar
|
||||
/dir3/slf4j-simple-2.0.6.jar
|
||||
/dir4
|
||||
/dir4/httpclient5-5.2.1.jar
|
||||
/dir4/httpcore5-5.2.jar
|
||||
/dir4/httpcore5-h2-5.2.jar
|
||||
/dir4/slf4j-api-1.7.36.jar""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static class TestProject extends WebProject {
|
||||
public TestProject(File tmp) {
|
||||
workDirectory = tmp;
|
||||
pkg = "test.pkg";
|
||||
downloadSources = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var project1 = new TestProject(tmp);
|
||||
project1.createProjectStructure();
|
||||
project1.repositories().add(Repository.MAVEN_CENTRAL);
|
||||
project1.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 1)));
|
||||
project1.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 3)));
|
||||
project1.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 0)));
|
||||
project1.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 0)));
|
||||
|
||||
var project2 = new TestProject(tmp);
|
||||
project2.createProjectStructure();
|
||||
project2.repositories().add(Repository.MAVEN_CENTRAL);
|
||||
project2.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 12, 0)));
|
||||
project2.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 4)));
|
||||
project2.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(2, 0, 6)));
|
||||
project2.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 2, 1)));
|
||||
|
||||
new DownloadOperation()
|
||||
.fromProject(project1)
|
||||
.execute();
|
||||
new DownloadOperation()
|
||||
.fromProject(project2)
|
||||
.execute();
|
||||
|
||||
assertEquals("""
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/compile
|
||||
/lib/compile/commons-lang3-3.1-sources.jar
|
||||
/lib/compile/commons-lang3-3.1.jar
|
||||
/lib/compile/commons-lang3-3.12.0-sources.jar
|
||||
/lib/compile/commons-lang3-3.12.0.jar
|
||||
/lib/runtime
|
||||
/lib/runtime/commons-collections4-4.3-sources.jar
|
||||
/lib/runtime/commons-collections4-4.3.jar
|
||||
/lib/runtime/commons-collections4-4.4-sources.jar
|
||||
/lib/runtime/commons-collections4-4.4.jar
|
||||
/lib/standalone
|
||||
/lib/standalone/slf4j-api-2.0.0-sources.jar
|
||||
/lib/standalone/slf4j-api-2.0.0.jar
|
||||
/lib/standalone/slf4j-api-2.0.6-sources.jar
|
||||
/lib/standalone/slf4j-api-2.0.6.jar
|
||||
/lib/standalone/slf4j-simple-2.0.0-sources.jar
|
||||
/lib/standalone/slf4j-simple-2.0.0.jar
|
||||
/lib/standalone/slf4j-simple-2.0.6-sources.jar
|
||||
/lib/standalone/slf4j-simple-2.0.6.jar
|
||||
/lib/test
|
||||
/lib/test/commons-codec-1.13-sources.jar
|
||||
/lib/test/commons-codec-1.13.jar
|
||||
/lib/test/httpclient5-5.0-sources.jar
|
||||
/lib/test/httpclient5-5.0.jar
|
||||
/lib/test/httpclient5-5.2.1-sources.jar
|
||||
/lib/test/httpclient5-5.2.1.jar
|
||||
/lib/test/httpcore5-5.0-sources.jar
|
||||
/lib/test/httpcore5-5.0.jar
|
||||
/lib/test/httpcore5-5.2-sources.jar
|
||||
/lib/test/httpcore5-5.2.jar
|
||||
/lib/test/httpcore5-h2-5.0-sources.jar
|
||||
/lib/test/httpcore5-h2-5.0.jar
|
||||
/lib/test/httpcore5-h2-5.2-sources.jar
|
||||
/lib/test/httpcore5-h2-5.2.jar
|
||||
/lib/test/slf4j-api-1.7.25-sources.jar
|
||||
/lib/test/slf4j-api-1.7.25.jar
|
||||
/lib/test/slf4j-api-1.7.36-sources.jar
|
||||
/lib/test/slf4j-api-1.7.36.jar
|
||||
/src
|
||||
/src/bld
|
||||
/src/bld/java
|
||||
/src/bld/resources
|
||||
/src/main
|
||||
/src/main/java
|
||||
/src/main/resources
|
||||
/src/main/resources/templates
|
||||
/src/test
|
||||
/src/test/java
|
||||
/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
|
||||
new PurgeOperation()
|
||||
.fromProject(project2)
|
||||
.execute();
|
||||
|
||||
assertEquals("""
|
||||
/lib
|
||||
/lib/bld
|
||||
/lib/compile
|
||||
/lib/compile/commons-lang3-3.12.0-sources.jar
|
||||
/lib/compile/commons-lang3-3.12.0.jar
|
||||
/lib/runtime
|
||||
/lib/runtime/commons-collections4-4.4-sources.jar
|
||||
/lib/runtime/commons-collections4-4.4.jar
|
||||
/lib/standalone
|
||||
/lib/standalone/slf4j-api-2.0.6-sources.jar
|
||||
/lib/standalone/slf4j-api-2.0.6.jar
|
||||
/lib/standalone/slf4j-simple-2.0.6-sources.jar
|
||||
/lib/standalone/slf4j-simple-2.0.6.jar
|
||||
/lib/test
|
||||
/lib/test/httpclient5-5.2.1-sources.jar
|
||||
/lib/test/httpclient5-5.2.1.jar
|
||||
/lib/test/httpcore5-5.2-sources.jar
|
||||
/lib/test/httpcore5-5.2.jar
|
||||
/lib/test/httpcore5-h2-5.2-sources.jar
|
||||
/lib/test/httpcore5-h2-5.2.jar
|
||||
/lib/test/slf4j-api-1.7.36-sources.jar
|
||||
/lib/test/slf4j-api-1.7.36.jar
|
||||
/src
|
||||
/src/bld
|
||||
/src/bld/java
|
||||
/src/bld/resources
|
||||
/src/main
|
||||
/src/main/java
|
||||
/src/main/resources
|
||||
/src/main/resources/templates
|
||||
/src/test
|
||||
/src/test/java
|
||||
/src/test/resources""",
|
||||
FileUtils.generateDirectoryListing(tmp));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
187
src/test/java/rife/bld/operations/TestRunOperation.java
Normal file
187
src/test/java/rife/bld/operations/TestRunOperation.java
Normal file
|
@ -0,0 +1,187 @@
|
|||
/*
|
||||
* 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 java.util.function.Function;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestRunOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new RunOperation();
|
||||
assertNotNull(operation.workDirectory());
|
||||
assertTrue(operation.workDirectory().exists());
|
||||
assertTrue(operation.workDirectory().isDirectory());
|
||||
assertTrue(operation.workDirectory().canWrite());
|
||||
assertEquals("java", operation.javaTool());
|
||||
assertTrue(operation.javaOptions().isEmpty());
|
||||
assertTrue(operation.classpath().isEmpty());
|
||||
assertNull(operation.mainClass());
|
||||
assertTrue(operation.runOptions().isEmpty());
|
||||
assertNull(operation.outputProcessor());
|
||||
assertNull(operation.errorProcessor());
|
||||
assertNull(operation.process());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation()
|
||||
throws Exception {
|
||||
var work_directory = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var java_tool = "javatool";
|
||||
var run_java_option1 = "runJavaOption1";
|
||||
var run_java_option2 = "runJavaOption2";
|
||||
var run_classpath1 = "runClasspath1";
|
||||
var run_classpath2 = "runClasspath2";
|
||||
var run_option1 = "runOption1";
|
||||
var run_option2 = "runOption2";
|
||||
var main_class = "mainClass";
|
||||
Function<String, Boolean> run_output_consumer = (String) -> true;
|
||||
Function<String, Boolean> run_error_consumer = (String) -> true;
|
||||
|
||||
var operation1 = new RunOperation();
|
||||
operation1
|
||||
.workDirectory(work_directory)
|
||||
.javaTool(java_tool)
|
||||
.javaOptions(List.of(run_java_option1, run_java_option2))
|
||||
.classpath(List.of(run_classpath1, run_classpath2))
|
||||
.mainClass(main_class)
|
||||
.runOptions(List.of(run_option1, run_option2))
|
||||
.outputProcessor(run_output_consumer)
|
||||
.errorProcessor(run_error_consumer);
|
||||
|
||||
assertEquals(work_directory, operation1.workDirectory());
|
||||
assertEquals(java_tool, operation1.javaTool());
|
||||
assertTrue(operation1.javaOptions().contains(run_java_option1));
|
||||
assertTrue(operation1.javaOptions().contains(run_java_option2));
|
||||
assertTrue(operation1.classpath().contains(run_classpath1));
|
||||
assertTrue(operation1.classpath().contains(run_classpath2));
|
||||
assertEquals(main_class, operation1.mainClass());
|
||||
assertTrue(operation1.runOptions().contains(run_option1));
|
||||
assertTrue(operation1.runOptions().contains(run_option2));
|
||||
assertSame(run_output_consumer, operation1.outputProcessor());
|
||||
assertSame(run_error_consumer, operation1.errorProcessor());
|
||||
|
||||
var operation2 = new RunOperation();
|
||||
operation2.workDirectory(work_directory);
|
||||
operation2.javaTool(java_tool);
|
||||
operation2.javaOptions().add(run_java_option1);
|
||||
operation2.javaOptions().add(run_java_option2);
|
||||
operation2.classpath().add(run_classpath1);
|
||||
operation2.classpath().add(run_classpath2);
|
||||
operation2.mainClass(main_class);
|
||||
operation2.runOptions().add(run_option1);
|
||||
operation2.runOptions().add(run_option2);
|
||||
operation2.outputProcessor(run_output_consumer);
|
||||
operation2.errorProcessor(run_error_consumer);
|
||||
|
||||
assertEquals(work_directory, operation2.workDirectory());
|
||||
assertEquals(java_tool, operation2.javaTool());
|
||||
assertTrue(operation2.javaOptions().contains(run_java_option1));
|
||||
assertTrue(operation2.javaOptions().contains(run_java_option2));
|
||||
assertTrue(operation2.classpath().contains(run_classpath1));
|
||||
assertTrue(operation2.classpath().contains(run_classpath2));
|
||||
assertEquals(main_class, operation2.mainClass());
|
||||
assertTrue(operation2.runOptions().contains(run_option1));
|
||||
assertTrue(operation2.runOptions().contains(run_option2));
|
||||
assertSame(run_output_consumer, operation2.outputProcessor());
|
||||
assertSame(run_error_consumer, operation2.errorProcessor());
|
||||
|
||||
var operation3 = new RunOperation();
|
||||
operation3
|
||||
.classpath(run_classpath1, run_classpath2)
|
||||
.runOptions(run_option1, run_option2);
|
||||
|
||||
assertTrue(operation3.classpath().contains(run_classpath1));
|
||||
assertTrue(operation3.classpath().contains(run_classpath2));
|
||||
assertTrue(operation3.runOptions().contains(run_option1));
|
||||
assertTrue(operation3.runOptions().contains(run_option2));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(work_directory);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var source_file1 = new File(tmp, "Source1.java");
|
||||
|
||||
FileUtils.writeString("""
|
||||
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);
|
||||
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));
|
||||
compile_operation.execute();
|
||||
assertTrue(compile_operation.diagnostics().isEmpty());
|
||||
|
||||
var output = new StringBuilder();
|
||||
var run_operation = new RunOperation()
|
||||
.mainClass("Source1")
|
||||
.classpath(List.of(build_main.getAbsolutePath()))
|
||||
.outputProcessor(s -> {
|
||||
output.append(s);
|
||||
return true;
|
||||
});
|
||||
run_operation.execute();
|
||||
|
||||
assertEquals("source1", output.toString());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("com.example")
|
||||
.projectName("myapp")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation.project()).execute();
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
new RunOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.outputProcessor(s -> {
|
||||
check_result.append(s);
|
||||
return true;
|
||||
})
|
||||
.execute();
|
||||
assertEquals("Hello World!", check_result.toString());
|
||||
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
182
src/test/java/rife/bld/operations/TestUberJarOperation.java
Normal file
182
src/test/java/rife/bld/operations/TestUberJarOperation.java
Normal file
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
* 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.bld.NamedFile;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
import rife.tools.FileUtils;
|
||||
import rife.tools.exceptions.FileUtilsErrorException;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestUberJarOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new UberJarOperation();
|
||||
assertTrue(operation.jarSourceFiles().isEmpty());
|
||||
assertTrue(operation.sourceDirectories().isEmpty());
|
||||
assertNull(operation.destinationDirectory());
|
||||
assertNull(operation.destinationFileName());
|
||||
assertNull(operation.mainClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var jar_source_file1 = new File("jarSourceFile1");
|
||||
var jar_source_file2 = new File("jarSourceFile2");
|
||||
var resource_source_directory1 = new NamedFile("resourceSourceDirectory1", new File("resourceSourceDirectory1"));
|
||||
var resource_source_directory2 = new NamedFile("resourceSourceDirectory2", new File("resourceSourceDirectory2"));
|
||||
var destination_directory = new File("destinationDirectory");
|
||||
var destination_fileName = "destinationFileName";
|
||||
var main_class = "mainClass";
|
||||
|
||||
var operation1 = new UberJarOperation()
|
||||
.jarSourceFiles(List.of(jar_source_file1, jar_source_file2))
|
||||
.sourceDirectories(List.of(resource_source_directory1, resource_source_directory2))
|
||||
.destinationDirectory(destination_directory)
|
||||
.destinationFileName(destination_fileName)
|
||||
.mainClass(main_class);
|
||||
|
||||
assertTrue(operation1.jarSourceFiles().contains(jar_source_file1));
|
||||
assertTrue(operation1.jarSourceFiles().contains(jar_source_file2));
|
||||
assertTrue(operation1.sourceDirectories().contains(resource_source_directory1));
|
||||
assertTrue(operation1.sourceDirectories().contains(resource_source_directory2));
|
||||
assertEquals(destination_directory, operation1.destinationDirectory());
|
||||
assertEquals(destination_fileName, operation1.destinationFileName());
|
||||
assertEquals(main_class, operation1.mainClass());
|
||||
|
||||
var operation2 = new UberJarOperation()
|
||||
.destinationDirectory(destination_directory)
|
||||
.destinationFileName(destination_fileName)
|
||||
.mainClass(main_class);
|
||||
operation2.jarSourceFiles().add(jar_source_file1);
|
||||
operation2.jarSourceFiles().add(jar_source_file2);
|
||||
operation2.sourceDirectories().add(resource_source_directory1);
|
||||
operation2.sourceDirectories().add(resource_source_directory2);
|
||||
assertEquals(main_class, operation1.mainClass());
|
||||
|
||||
assertTrue(operation2.jarSourceFiles().contains(jar_source_file1));
|
||||
assertTrue(operation2.jarSourceFiles().contains(jar_source_file2));
|
||||
assertTrue(operation2.sourceDirectories().contains(resource_source_directory1));
|
||||
assertTrue(operation2.sourceDirectories().contains(resource_source_directory2));
|
||||
assertEquals(destination_directory, operation2.destinationDirectory());
|
||||
assertEquals(destination_fileName, operation2.destinationFileName());
|
||||
|
||||
var operation3 = new UberJarOperation()
|
||||
.jarSourceFiles(jar_source_file1, jar_source_file2)
|
||||
.sourceDirectories(resource_source_directory1, resource_source_directory2)
|
||||
.destinationDirectory(destination_directory)
|
||||
.destinationFileName(destination_fileName)
|
||||
.mainClass(main_class);
|
||||
|
||||
assertTrue(operation3.jarSourceFiles().contains(jar_source_file1));
|
||||
assertTrue(operation3.jarSourceFiles().contains(jar_source_file2));
|
||||
assertTrue(operation3.sourceDirectories().contains(resource_source_directory1));
|
||||
assertTrue(operation3.sourceDirectories().contains(resource_source_directory2));
|
||||
assertEquals(destination_directory, operation3.destinationDirectory());
|
||||
assertEquals(destination_fileName, operation3.destinationFileName());
|
||||
assertEquals(main_class, operation3.mainClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProjectBlank()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var create_operation = new CreateBlankOperation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("tst")
|
||||
.projectName("app")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.execute();
|
||||
|
||||
new JarOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.execute();
|
||||
|
||||
var uberjar_operation = new UberJarOperation()
|
||||
.fromProject(create_operation.project());
|
||||
uberjar_operation.execute();
|
||||
|
||||
var uberjar_file = new File(uberjar_operation.destinationDirectory(), uberjar_operation.destinationFileName());
|
||||
try (var jar = new JarFile(uberjar_file)) {
|
||||
assertEquals(2, jar.size());
|
||||
}
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
new RunOperation()
|
||||
.javaOptions(List.of("-jar"))
|
||||
.mainClass(uberjar_file.getAbsolutePath())
|
||||
.outputProcessor(s -> {
|
||||
check_result.append(s);
|
||||
return true;
|
||||
})
|
||||
.execute();
|
||||
assertEquals("Hello World!", check_result.toString());
|
||||
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProjectWeb()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("web").toFile();
|
||||
try {
|
||||
var create_operation = new CreateRife2Operation()
|
||||
.workDirectory(tmp)
|
||||
.packageName("tst")
|
||||
.projectName("app")
|
||||
.downloadDependencies(true);
|
||||
create_operation.execute();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.execute();
|
||||
|
||||
create_operation.project().uberjar();
|
||||
|
||||
var uberjar_file = new File(create_operation.project().buildDistDirectory(), create_operation.project().uberJarFileName());
|
||||
try (var jar = new JarFile(uberjar_file)) {
|
||||
assertTrue(jar.size() > 1300);
|
||||
}
|
||||
|
||||
var check_result = new StringBuilder();
|
||||
var run_operation = new RunOperation()
|
||||
.javaOptions(List.of("-jar"))
|
||||
.mainClass(uberjar_file.getAbsolutePath());
|
||||
var executor = Executors.newSingleThreadScheduledExecutor();
|
||||
var checked_url = new URL("http://localhost:8080");
|
||||
executor.schedule(() -> {
|
||||
try {
|
||||
check_result.append(FileUtils.readString(checked_url));
|
||||
} catch (FileUtilsErrorException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}, 1, TimeUnit.SECONDS);
|
||||
executor.schedule(() -> run_operation.process().destroy(), 2, TimeUnit.SECONDS);
|
||||
assertThrows(ExitStatusException.class, run_operation::execute);
|
||||
|
||||
assertTrue(check_result.toString().contains("<p>Hello World App</p>"));
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
172
src/test/java/rife/bld/operations/TestUpdatesOperation.java
Normal file
172
src/test/java/rife/bld/operations/TestUpdatesOperation.java
Normal file
|
@ -0,0 +1,172 @@
|
|||
/*
|
||||
* 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.bld.dependencies.DependencyScopes;
|
||||
import rife.bld.WebProject;
|
||||
import rife.bld.dependencies.*;
|
||||
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 TestUpdatesOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new UpdatesOperation();
|
||||
assertTrue(operation.dependencies().isEmpty());
|
||||
assertTrue(operation.repositories().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var repository1 = new Repository("repository1");
|
||||
var repository2 = new Repository("repository2");
|
||||
var dependency1 = new Dependency("group1", "artifact1");
|
||||
var dependency2 = new Dependency("group2", "artifact2");
|
||||
|
||||
var operation1 = new UpdatesOperation()
|
||||
.repositories(List.of(repository1, repository2));
|
||||
var dependency_scopes = new DependencyScopes();
|
||||
dependency_scopes.scope(Scope.compile).include(dependency1).include(dependency2);
|
||||
operation1.dependencies(dependency_scopes);
|
||||
assertTrue(operation1.repositories().contains(repository1));
|
||||
assertTrue(operation1.repositories().contains(repository2));
|
||||
assertTrue(operation1.dependencies().scope(Scope.compile).contains(dependency1));
|
||||
assertTrue(operation1.dependencies().scope(Scope.compile).contains(dependency2));
|
||||
|
||||
var operation2 = new UpdatesOperation();
|
||||
operation2.repositories().add(repository1);
|
||||
operation2.repositories().add(repository2);
|
||||
operation2.dependencies().scope(Scope.compile).include(dependency1).include(dependency2);
|
||||
operation2.dependencies(dependency_scopes);
|
||||
assertTrue(operation2.repositories().contains(repository1));
|
||||
assertTrue(operation2.repositories().contains(repository2));
|
||||
assertTrue(operation2.dependencies().scope(Scope.compile).contains(dependency1));
|
||||
assertTrue(operation2.dependencies().scope(Scope.compile).contains(dependency2));
|
||||
|
||||
var operation3 = new UpdatesOperation()
|
||||
.repositories(repository1, repository2);
|
||||
assertTrue(operation3.repositories().contains(repository1));
|
||||
assertTrue(operation3.repositories().contains(repository2));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecution()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var operation = new UpdatesOperation()
|
||||
.repositories(List.of(Repository.MAVEN_CENTRAL));
|
||||
operation.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 10, 0)));
|
||||
operation.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 0)));
|
||||
operation.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(1, 0, 6)));
|
||||
operation.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 0, 1)));
|
||||
|
||||
operation.execute();
|
||||
|
||||
var results = operation.updates();
|
||||
assertFalse(results.isEmpty());
|
||||
|
||||
assertEquals(1, results.get(Scope.compile).size());
|
||||
assertEquals(1, results.get(Scope.runtime).size());
|
||||
assertEquals(1, results.get(Scope.standalone).size());
|
||||
assertEquals(1, results.get(Scope.test).size());
|
||||
results.get(Scope.compile).forEach(dependency -> {
|
||||
assertEquals("org.apache.commons", dependency.groupId());
|
||||
assertEquals("commons-lang3", dependency.artifactId());
|
||||
assertNotEquals(new VersionNumber(3, 10, 0), dependency.version());
|
||||
});
|
||||
results.get(Scope.runtime).forEach(dependency -> {
|
||||
assertEquals("org.apache.commons", dependency.groupId());
|
||||
assertEquals("commons-collections4", dependency.artifactId());
|
||||
assertNotEquals(new VersionNumber(4, 0), dependency.version());
|
||||
});
|
||||
results.get(Scope.standalone).forEach(dependency -> {
|
||||
assertEquals("org.slf4j", dependency.groupId());
|
||||
assertEquals("slf4j-simple", dependency.artifactId());
|
||||
assertNotEquals(new VersionNumber(1, 0, 6), dependency.version());
|
||||
});
|
||||
results.get(Scope.test).forEach(dependency -> {
|
||||
assertEquals("org.apache.httpcomponents.client5", dependency.groupId());
|
||||
assertEquals("httpclient5", dependency.artifactId());
|
||||
assertNotEquals(new VersionNumber(5, 0, 1), dependency.version());
|
||||
});
|
||||
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
static class TestProject extends WebProject {
|
||||
public TestProject(File tmp) {
|
||||
workDirectory = tmp;
|
||||
pkg = "test.pkg";
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromProject()
|
||||
throws Exception {
|
||||
var tmp = Files.createTempDirectory("test").toFile();
|
||||
try {
|
||||
var project = new TestProject(tmp);
|
||||
project.createProjectStructure();
|
||||
project.repositories().add(Repository.MAVEN_CENTRAL);
|
||||
project.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("org.apache.commons", "commons-lang3", new VersionNumber(3, 10, 0)));
|
||||
project.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("org.apache.commons", "commons-collections4", new VersionNumber(4, 0)));
|
||||
project.dependencies().scope(Scope.standalone)
|
||||
.include(new Dependency("org.slf4j", "slf4j-simple", new VersionNumber(1, 0, 6)));
|
||||
project.dependencies().scope(Scope.test)
|
||||
.include(new Dependency("org.apache.httpcomponents.client5", "httpclient5", new VersionNumber(5, 0, 1)));
|
||||
|
||||
var operation = new UpdatesOperation()
|
||||
.fromProject(project);
|
||||
|
||||
operation.execute();
|
||||
|
||||
var results = operation.updates();
|
||||
assertFalse(results.isEmpty());
|
||||
|
||||
assertEquals(1, results.get(Scope.compile).size());
|
||||
assertEquals(1, results.get(Scope.runtime).size());
|
||||
assertEquals(1, results.get(Scope.standalone).size());
|
||||
assertEquals(1, results.get(Scope.test).size());
|
||||
results.get(Scope.compile).forEach(dependency -> {
|
||||
assertEquals("org.apache.commons", dependency.groupId());
|
||||
assertEquals("commons-lang3", dependency.artifactId());
|
||||
assertNotEquals(new VersionNumber(3, 10, 0), dependency.version());
|
||||
});
|
||||
results.get(Scope.runtime).forEach(dependency -> {
|
||||
assertEquals("org.apache.commons", dependency.groupId());
|
||||
assertEquals("commons-collections4", dependency.artifactId());
|
||||
assertNotEquals(new VersionNumber(4, 0), dependency.version());
|
||||
});
|
||||
results.get(Scope.standalone).forEach(dependency -> {
|
||||
assertEquals("org.slf4j", dependency.groupId());
|
||||
assertEquals("slf4j-simple", dependency.artifactId());
|
||||
assertNotEquals(new VersionNumber(1, 0, 6), dependency.version());
|
||||
});
|
||||
results.get(Scope.test).forEach(dependency -> {
|
||||
assertEquals("org.apache.httpcomponents.client5", dependency.groupId());
|
||||
assertEquals("httpclient5", dependency.artifactId());
|
||||
assertNotEquals(new VersionNumber(5, 0, 1), dependency.version());
|
||||
});
|
||||
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
156
src/test/java/rife/bld/operations/TestWarOperation.java
Normal file
156
src/test/java/rife/bld/operations/TestWarOperation.java
Normal file
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* 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.bld.NamedFile;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestWarOperation {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var operation = new WarOperation();
|
||||
assertTrue(operation.libSourceDirectories().isEmpty());
|
||||
assertTrue(operation.classesSourceDirectories().isEmpty());
|
||||
assertTrue(operation.jarSourceFiles().isEmpty());
|
||||
assertNull(operation.webappDirectory());
|
||||
assertNull(operation.webXmlFile());
|
||||
assertNull(operation.destinationDirectory());
|
||||
assertNull(operation.destinationFileName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulation() {
|
||||
var lib_source_directory1 = new File("libSourceDirectory1");
|
||||
var lib_source_directory2 = new File("libSourceDirectory2");
|
||||
var classes_source_directory1 = new File("classesSourceDirectory1");
|
||||
var classes_source_directory2 = new File("classesSourceDirectory2");
|
||||
var jar_source_file1 = new NamedFile("jarSourceFile1", new File("jarSourceFile1"));
|
||||
var jar_source_file2 = new NamedFile("jarSourceFile2", new File("jarSourceFile2"));
|
||||
var webapp_directory = new File("webappDirectory");
|
||||
var web_xml_file = new File("webXmlFile");
|
||||
var destination_directory = new File("destinationDirectory");
|
||||
var destination_fileName = "destinationFileName";
|
||||
|
||||
var operation1 = new WarOperation()
|
||||
.libSourceDirectories(List.of(lib_source_directory1, lib_source_directory2))
|
||||
.classesSourceDirectories(List.of(classes_source_directory1, classes_source_directory2))
|
||||
.jarSourceFiles(List.of(jar_source_file1, jar_source_file2))
|
||||
.webappDirectory(webapp_directory)
|
||||
.webXmlFile(web_xml_file)
|
||||
.destinationDirectory(destination_directory)
|
||||
.destinationFileName(destination_fileName);
|
||||
|
||||
assertTrue(operation1.libSourceDirectories().contains(lib_source_directory1));
|
||||
assertTrue(operation1.libSourceDirectories().contains(lib_source_directory2));
|
||||
assertTrue(operation1.classesSourceDirectories().contains(classes_source_directory1));
|
||||
assertTrue(operation1.classesSourceDirectories().contains(classes_source_directory2));
|
||||
assertTrue(operation1.jarSourceFiles().contains(jar_source_file1));
|
||||
assertTrue(operation1.jarSourceFiles().contains(jar_source_file2));
|
||||
assertEquals(webapp_directory, operation1.webappDirectory());
|
||||
assertEquals(web_xml_file, operation1.webXmlFile());
|
||||
assertEquals(destination_directory, operation1.destinationDirectory());
|
||||
assertEquals(destination_fileName, operation1.destinationFileName());
|
||||
|
||||
var operation2 = new WarOperation()
|
||||
.webappDirectory(webapp_directory)
|
||||
.webXmlFile(web_xml_file)
|
||||
.destinationDirectory(destination_directory)
|
||||
.destinationFileName(destination_fileName);
|
||||
operation2.libSourceDirectories().add(lib_source_directory1);
|
||||
operation2.libSourceDirectories().add(lib_source_directory2);
|
||||
operation2.classesSourceDirectories().add(classes_source_directory1);
|
||||
operation2.classesSourceDirectories().add(classes_source_directory2);
|
||||
operation2.jarSourceFiles().add(jar_source_file1);
|
||||
operation2.jarSourceFiles().add(jar_source_file2);
|
||||
|
||||
assertTrue(operation2.libSourceDirectories().contains(lib_source_directory1));
|
||||
assertTrue(operation2.libSourceDirectories().contains(lib_source_directory2));
|
||||
assertTrue(operation2.classesSourceDirectories().contains(classes_source_directory1));
|
||||
assertTrue(operation2.classesSourceDirectories().contains(classes_source_directory2));
|
||||
assertTrue(operation2.jarSourceFiles().contains(jar_source_file1));
|
||||
assertTrue(operation2.jarSourceFiles().contains(jar_source_file2));
|
||||
assertEquals(webapp_directory, operation2.webappDirectory());
|
||||
assertEquals(web_xml_file, operation2.webXmlFile());
|
||||
assertEquals(destination_directory, operation2.destinationDirectory());
|
||||
assertEquals(destination_fileName, operation2.destinationFileName());
|
||||
|
||||
var operation3 = new WarOperation()
|
||||
.libSourceDirectories(lib_source_directory1, lib_source_directory2)
|
||||
.classesSourceDirectories(classes_source_directory1, classes_source_directory2)
|
||||
.jarSourceFiles(jar_source_file1, jar_source_file2)
|
||||
.webappDirectory(webapp_directory)
|
||||
.webXmlFile(web_xml_file)
|
||||
.destinationDirectory(destination_directory)
|
||||
.destinationFileName(destination_fileName);
|
||||
|
||||
assertTrue(operation3.libSourceDirectories().contains(lib_source_directory1));
|
||||
assertTrue(operation3.libSourceDirectories().contains(lib_source_directory2));
|
||||
assertTrue(operation3.classesSourceDirectories().contains(classes_source_directory1));
|
||||
assertTrue(operation3.classesSourceDirectories().contains(classes_source_directory2));
|
||||
assertTrue(operation3.jarSourceFiles().contains(jar_source_file1));
|
||||
assertTrue(operation3.jarSourceFiles().contains(jar_source_file2));
|
||||
assertEquals(webapp_directory, operation3.webappDirectory());
|
||||
assertEquals(web_xml_file, operation3.webXmlFile());
|
||||
assertEquals(destination_directory, operation3.destinationDirectory());
|
||||
assertEquals(destination_fileName, operation3.destinationFileName());
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
new CompileOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.execute();
|
||||
|
||||
new JarOperation()
|
||||
.fromProject(create_operation.project())
|
||||
.execute();
|
||||
|
||||
var war_operation = new WarOperation()
|
||||
.fromProject(create_operation.project());
|
||||
war_operation.execute();
|
||||
|
||||
var war_file = new File(war_operation.destinationDirectory(), war_operation.destinationFileName());
|
||||
var content = new StringBuilder();
|
||||
try (var jar = new JarFile(war_file)) {
|
||||
var e = jar.entries();
|
||||
while (e.hasMoreElements()) {
|
||||
var jar_entry = e.nextElement();
|
||||
content.append(jar_entry.getName());
|
||||
content.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(Pattern.compile("""
|
||||
META-INF/MANIFEST\\.MF
|
||||
WEB-INF/lib/app-0\\.0\\.1\\.jar
|
||||
WEB-INF/lib/rife2-.+\\.jar
|
||||
WEB-INF/web\\.xml
|
||||
css/style\\.css
|
||||
""").matcher(content.toString()).matches());
|
||||
} finally {
|
||||
FileUtils.deleteDirectory(tmp);
|
||||
}
|
||||
}
|
||||
}
|
250
src/test/java/rife/bld/publish/TestMetadataBuilder.java
Normal file
250
src/test/java/rife/bld/publish/TestMetadataBuilder.java
Normal file
|
@ -0,0 +1,250 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.publish;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.dependencies.*;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestMetadataBuilder {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var builder = new MetadataBuilder();
|
||||
assertNull(builder.info());
|
||||
assertNull(builder.updated());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyBuild() {
|
||||
var builder = new MetadataBuilder();
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata modelVersion="1.1.0">
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<versioning>
|
||||
</versioning>
|
||||
</metadata>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMainInfoBuild() {
|
||||
var builder = new MetadataBuilder()
|
||||
.info(new PublishInfo()
|
||||
.groupId("com.example")
|
||||
.artifactId("myapp")
|
||||
.version(VersionNumber.parse("1.2.3-SNAPSHOT")));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata modelVersion="1.1.0">
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>myapp</artifactId>
|
||||
<versioning>
|
||||
<latest>1.2.3-SNAPSHOT</latest>
|
||||
<release>1.2.3-SNAPSHOT</release>
|
||||
<versions>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
</versions>
|
||||
</versioning>
|
||||
</metadata>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdatedBuild() {
|
||||
var builder = new MetadataBuilder()
|
||||
.updated(ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York")));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata modelVersion="1.1.0">
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<versioning>
|
||||
<lastUpdated>20230327125617</lastUpdated>
|
||||
</versioning>
|
||||
</metadata>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOtherVersionsBuild() {
|
||||
var builder = new MetadataBuilder()
|
||||
.otherVersions(List.of(new VersionNumber(6,0,1), new VersionNumber(3,0,2), new VersionNumber(1,0,3), new VersionNumber(3,0,2)));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata modelVersion="1.1.0">
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<versioning>
|
||||
<versions>
|
||||
<version>1.0.3</version>
|
||||
<version>3.0.2</version>
|
||||
<version>6.0.1</version>
|
||||
</versions>
|
||||
</versioning>
|
||||
</metadata>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCompleteBuild() {
|
||||
var builder = new MetadataBuilder()
|
||||
.info(new PublishInfo()
|
||||
.groupId("com.example")
|
||||
.artifactId("myapp")
|
||||
.version(VersionNumber.parse("1.2.3-SNAPSHOT")))
|
||||
.otherVersions(List.of(new VersionNumber(6,0,1), new VersionNumber(3,0,2), new VersionNumber(1,0,3), new VersionNumber(3,0,2)))
|
||||
.updated(ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York")));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata modelVersion="1.1.0">
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>myapp</artifactId>
|
||||
<versioning>
|
||||
<latest>1.2.3-SNAPSHOT</latest>
|
||||
<release>1.2.3-SNAPSHOT</release>
|
||||
<versions>
|
||||
<version>1.0.3</version>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<version>3.0.2</version>
|
||||
<version>6.0.1</version>
|
||||
</versions>
|
||||
<lastUpdated>20230327125617</lastUpdated>
|
||||
</versioning>
|
||||
</metadata>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSnapshot() {
|
||||
var builder = new MetadataBuilder()
|
||||
.info(new PublishInfo()
|
||||
.groupId("com.example")
|
||||
.artifactId("myapp")
|
||||
.version(VersionNumber.parse("1.2.3-SNAPSHOT")))
|
||||
.snapshot(ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York")), 5);
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata modelVersion="1.1.0">
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>myapp</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<versioning>
|
||||
<snapshot>
|
||||
<timestamp>20230327.125617</timestamp>
|
||||
<buildNumber>5</buildNumber>
|
||||
</snapshot>
|
||||
</versioning>
|
||||
</metadata>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSnapshotVersions() {
|
||||
var moment = ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York"));
|
||||
var moment2 = ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York"));
|
||||
var moment3 = ZonedDateTime.of(2023, 5, 27, 8, 56, 17, 123, ZoneId.of("America/New_York"));
|
||||
var builder = new MetadataBuilder()
|
||||
.info(new PublishInfo()
|
||||
.groupId("com.example")
|
||||
.artifactId("myapp")
|
||||
.version(VersionNumber.parse("1.2.3-SNAPSHOT")))
|
||||
.snapshot(moment, 5)
|
||||
.snapshotVersions(List.of(
|
||||
new SnapshotVersion("classifier1", "ext1", "123", moment2),
|
||||
new SnapshotVersion("classifier2", "ext2", "456", moment3),
|
||||
new SnapshotVersion("classifier3", "ext3", "789", moment2)));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata modelVersion="1.1.0">
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>myapp</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<versioning>
|
||||
<snapshot>
|
||||
<timestamp>20230327.125617</timestamp>
|
||||
<buildNumber>5</buildNumber>
|
||||
</snapshot>
|
||||
<snapshotVersions>
|
||||
<snapshotVersion>
|
||||
<classifier>classifier1</classifier>
|
||||
<extension>ext1</extension>
|
||||
<value>123</value>
|
||||
<updated>20230327125617</updated>
|
||||
</snapshotVersion>
|
||||
<snapshotVersion>
|
||||
<classifier>classifier2</classifier>
|
||||
<extension>ext2</extension>
|
||||
<value>456</value>
|
||||
<updated>20230527125617</updated>
|
||||
</snapshotVersion>
|
||||
<snapshotVersion>
|
||||
<classifier>classifier3</classifier>
|
||||
<extension>ext3</extension>
|
||||
<value>789</value>
|
||||
<updated>20230327125617</updated>
|
||||
</snapshotVersion>
|
||||
</snapshotVersions>
|
||||
</versioning>
|
||||
</metadata>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLocalSnapshotVersions() {
|
||||
var moment = ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York"));
|
||||
var moment2 = ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York"));
|
||||
var moment3 = ZonedDateTime.of(2023, 5, 27, 8, 56, 17, 123, ZoneId.of("America/New_York"));
|
||||
var builder = new MetadataBuilder()
|
||||
.info(new PublishInfo()
|
||||
.groupId("com.example")
|
||||
.artifactId("myapp")
|
||||
.version(VersionNumber.parse("1.2.3-SNAPSHOT")))
|
||||
.snapshotLocal()
|
||||
.snapshotVersions(List.of(
|
||||
new SnapshotVersion("classifier1", "ext1", "123", moment2),
|
||||
new SnapshotVersion("classifier2", "ext2", "456", moment3),
|
||||
new SnapshotVersion("classifier3", "ext3", "789", moment2)));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata modelVersion="1.1.0">
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>myapp</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<versioning>
|
||||
<snapshot>
|
||||
<localCopy>true</localCopy>
|
||||
</snapshot>
|
||||
<snapshotVersions>
|
||||
<snapshotVersion>
|
||||
<classifier>classifier1</classifier>
|
||||
<extension>ext1</extension>
|
||||
<value>123</value>
|
||||
<updated>20230327125617</updated>
|
||||
</snapshotVersion>
|
||||
<snapshotVersion>
|
||||
<classifier>classifier2</classifier>
|
||||
<extension>ext2</extension>
|
||||
<value>456</value>
|
||||
<updated>20230527125617</updated>
|
||||
</snapshotVersion>
|
||||
<snapshotVersion>
|
||||
<classifier>classifier3</classifier>
|
||||
<extension>ext3</extension>
|
||||
<value>789</value>
|
||||
<updated>20230327125617</updated>
|
||||
</snapshotVersion>
|
||||
</snapshotVersions>
|
||||
</versioning>
|
||||
</metadata>
|
||||
""", builder.build());
|
||||
}
|
||||
}
|
558
src/test/java/rife/bld/publish/TestPomBuilder.java
Normal file
558
src/test/java/rife/bld/publish/TestPomBuilder.java
Normal file
|
@ -0,0 +1,558 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.publish;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.dependencies.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestPomBuilder {
|
||||
@Test
|
||||
void testInstantiation() {
|
||||
var builder = new PomBuilder();
|
||||
assertNull(builder.info());
|
||||
assertTrue(builder.dependencies().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEmptyBuild() {
|
||||
var builder = new PomBuilder();
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<version></version>
|
||||
<name></name>
|
||||
<description></description>
|
||||
<url></url>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMainInfoBuild() {
|
||||
var builder = new PomBuilder()
|
||||
.info(new PublishInfo()
|
||||
.groupId("com.example")
|
||||
.artifactId("myapp")
|
||||
.version(VersionNumber.parse("1.2.3-SNAPSHOT"))
|
||||
.name("the thing")
|
||||
.description("the thing but longer")
|
||||
.url("https://the.thing"));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>myapp</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<name>the thing</name>
|
||||
<description>the thing but longer</description>
|
||||
<url>https://the.thing</url>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLicensesInfoBuild() {
|
||||
var builder = new PomBuilder()
|
||||
.info(new PublishInfo()
|
||||
.license(new PublishLicense().name("license1").url("https://license1.com"))
|
||||
.license(new PublishLicense().name("license2").url("https://license2.com")));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<version></version>
|
||||
<name></name>
|
||||
<description></description>
|
||||
<url></url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>license1</name>
|
||||
<url>https://license1.com</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>license2</name>
|
||||
<url>https://license2.com</url>
|
||||
</license>
|
||||
</licenses>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDevelopersInfoBuild() {
|
||||
var builder = new PomBuilder()
|
||||
.info(new PublishInfo()
|
||||
.developer(new PublishDeveloper().id("id1").name("name1").email("email1").url("url1"))
|
||||
.developer(new PublishDeveloper().id("id2").name("name2"))
|
||||
.developer(new PublishDeveloper().id("id3").name("name3").url("url3")));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<version></version>
|
||||
<name></name>
|
||||
<description></description>
|
||||
<url></url>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>id1</id>
|
||||
<name>name1</name>
|
||||
<email>email1</email>
|
||||
<url>url1</url>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>id2</id>
|
||||
<name>name2</name>
|
||||
<email></email>
|
||||
<url></url>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>id3</id>
|
||||
<name>name3</name>
|
||||
<email></email>
|
||||
<url>url3</url>
|
||||
</developer>
|
||||
</developers>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testScmInfoBuild() {
|
||||
var builder = new PomBuilder()
|
||||
.info(new PublishInfo()
|
||||
.scm(new PublishScm().connection("conn1").developerConnection("devconn1").url("url1")));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<version></version>
|
||||
<name></name>
|
||||
<description></description>
|
||||
<url></url>
|
||||
<scm>
|
||||
<connection>conn1</connection>
|
||||
<developerConnection>devconn1</developerConnection>
|
||||
<url>url1</url>
|
||||
</scm>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFullInfoBuild() {
|
||||
var builder = new PomBuilder()
|
||||
.info(new PublishInfo()
|
||||
.groupId("com.example")
|
||||
.artifactId("myapp")
|
||||
.version(VersionNumber.parse("1.2.3-SNAPSHOT"))
|
||||
.name("the thing")
|
||||
.description("the thing but longer")
|
||||
.url("https://the.thing")
|
||||
.license(new PublishLicense().name("license1").url("https://license1.com"))
|
||||
.license(new PublishLicense().name("license2").url("https://license2.com"))
|
||||
.developer(new PublishDeveloper().id("id1").name("name1").email("email1").url("url1"))
|
||||
.developer(new PublishDeveloper().id("id2").name("name2"))
|
||||
.developer(new PublishDeveloper().id("id3").name("name3").url("url3"))
|
||||
.scm(new PublishScm().connection("conn1").developerConnection("devconn1").url("url1")));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>myapp</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<name>the thing</name>
|
||||
<description>the thing but longer</description>
|
||||
<url>https://the.thing</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>license1</name>
|
||||
<url>https://license1.com</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>license2</name>
|
||||
<url>https://license2.com</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>id1</id>
|
||||
<name>name1</name>
|
||||
<email>email1</email>
|
||||
<url>url1</url>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>id2</id>
|
||||
<name>name2</name>
|
||||
<email></email>
|
||||
<url></url>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>id3</id>
|
||||
<name>name3</name>
|
||||
<email></email>
|
||||
<url>url3</url>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>conn1</connection>
|
||||
<developerConnection>devconn1</developerConnection>
|
||||
<url>url1</url>
|
||||
</scm>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDependenciesCompile() {
|
||||
var builder = new PomBuilder();
|
||||
builder.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2"))
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", VersionNumber.UNKNOWN, "agent"))
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 5, 5), "bld", "zip"))
|
||||
.include(new Dependency("org.eclipse.jetty", "jetty-server", new VersionNumber(11, 0, 14))
|
||||
.exclude("*", "*").exclude("groupId", "artifactId"))
|
||||
.include(new Dependency("org.springframework.boot", "spring-boot-starter", new VersionNumber(3, 0, 4))
|
||||
.exclude("*", "artifactId"));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<version></version>
|
||||
<name></name>
|
||||
<description></description>
|
||||
<url></url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<classifier>agent</classifier>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<type>zip</type>
|
||||
<classifier>bld</classifier>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>11.0.14</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>*</groupId>
|
||||
<artifactId>*</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>groupId</groupId>
|
||||
<artifactId>artifactId</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>3.0.4</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>*</groupId>
|
||||
<artifactId>artifactId</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDependenciesRuntime() {
|
||||
var builder = new PomBuilder();
|
||||
builder.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2"))
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", VersionNumber.UNKNOWN, "agent"))
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 5, 5), "bld", "zip"))
|
||||
.include(new Dependency("org.eclipse.jetty", "jetty-server", new VersionNumber(11, 0, 14)))
|
||||
.include(new Dependency("org.springframework.boot", "spring-boot-starter", new VersionNumber(3, 0, 4)));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<version></version>
|
||||
<name></name>
|
||||
<description></description>
|
||||
<url></url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<classifier>agent</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<type>zip</type>
|
||||
<classifier>bld</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>11.0.14</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>3.0.4</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDependencies() {
|
||||
var builder = new PomBuilder();
|
||||
builder.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2"))
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 5, 5), "bld", "zip"))
|
||||
.include(new Dependency("org.springframework.boot", "spring-boot-starter", new VersionNumber(3, 0, 4))
|
||||
.exclude("*", "artifactId"));
|
||||
builder.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", VersionNumber.UNKNOWN, "agent"))
|
||||
.include(new Dependency("org.eclipse.jetty", "jetty-server", new VersionNumber(11, 0, 14))
|
||||
.exclude("*", "*").exclude("groupId", "artifactId"));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId></groupId>
|
||||
<artifactId></artifactId>
|
||||
<version></version>
|
||||
<name></name>
|
||||
<description></description>
|
||||
<url></url>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<type>zip</type>
|
||||
<classifier>bld</classifier>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>3.0.4</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>*</groupId>
|
||||
<artifactId>artifactId</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<classifier>agent</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>11.0.14</version>
|
||||
<scope>runtime</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>*</groupId>
|
||||
<artifactId>*</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>groupId</groupId>
|
||||
<artifactId>artifactId</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComplete() {
|
||||
var builder = new PomBuilder()
|
||||
.info(new PublishInfo()
|
||||
.groupId("com.example")
|
||||
.artifactId("myapp")
|
||||
.version(VersionNumber.parse("1.2.3-SNAPSHOT"))
|
||||
.name("the thing")
|
||||
.description("the thing but longer")
|
||||
.url("https://the.thing")
|
||||
.license(new PublishLicense().name("license1").url("https://license1.com"))
|
||||
.license(new PublishLicense().name("license2").url("https://license2.com"))
|
||||
.developer(new PublishDeveloper().id("id1").name("name1").email("email1").url("url1"))
|
||||
.developer(new PublishDeveloper().id("id2").name("name2"))
|
||||
.developer(new PublishDeveloper().id("id3").name("name3").url("url3"))
|
||||
.scm(new PublishScm().connection("conn1").developerConnection("devconn1").url("url1")));
|
||||
builder.dependencies().scope(Scope.compile)
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2"))
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", new VersionNumber(1, 5, 5), "bld", "zip"))
|
||||
.include(new Dependency("org.springframework.boot", "spring-boot-starter", new VersionNumber(3, 0, 4))
|
||||
.exclude("*", "artifactId"));
|
||||
builder.dependencies().scope(Scope.runtime)
|
||||
.include(new Dependency("com.uwyn.rife2", "rife2", VersionNumber.UNKNOWN, "agent"))
|
||||
.include(new Dependency("org.eclipse.jetty", "jetty-server", new VersionNumber(11, 0, 14))
|
||||
.exclude("*", "*").exclude("groupId", "artifactId"));
|
||||
assertEquals("""
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>myapp</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<name>the thing</name>
|
||||
<description>the thing but longer</description>
|
||||
<url>https://the.thing</url>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>license1</name>
|
||||
<url>https://license1.com</url>
|
||||
</license>
|
||||
<license>
|
||||
<name>license2</name>
|
||||
<url>https://license2.com</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<version>1.5.5</version>
|
||||
<type>zip</type>
|
||||
<classifier>bld</classifier>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>3.0.4</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>*</groupId>
|
||||
<artifactId>artifactId</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.uwyn.rife2</groupId>
|
||||
<artifactId>rife2</artifactId>
|
||||
<classifier>agent</classifier>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>11.0.14</version>
|
||||
<scope>runtime</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>*</groupId>
|
||||
<artifactId>*</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>groupId</groupId>
|
||||
<artifactId>artifactId</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>id1</id>
|
||||
<name>name1</name>
|
||||
<email>email1</email>
|
||||
<url>url1</url>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>id2</id>
|
||||
<name>name2</name>
|
||||
<email></email>
|
||||
<url></url>
|
||||
</developer>
|
||||
<developer>
|
||||
<id>id3</id>
|
||||
<name>name3</name>
|
||||
<email></email>
|
||||
<url>url3</url>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>conn1</connection>
|
||||
<developerConnection>devconn1</developerConnection>
|
||||
<url>url1</url>
|
||||
</scm>
|
||||
</project>
|
||||
""", builder.build());
|
||||
}
|
||||
}
|
566
src/test/java/rife/bld/wrapper/TestWrapperExtensionResolver.java
Normal file
566
src/test/java/rife/bld/wrapper/TestWrapperExtensionResolver.java
Normal file
|
@ -0,0 +1,566 @@
|
|||
/*
|
||||
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||
*/
|
||||
package rife.bld.wrapper;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.BldVersion;
|
||||
import rife.tools.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static rife.bld.wrapper.Wrapper.MAVEN_CENTRAL;
|
||||
|
||||
public class TestWrapperExtensionResolver {
|
||||
@Test
|
||||
void testNoExtensions()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var resolver = new WrapperExtensionResolver(tmp1, hash_file, tmp2, Collections.emptySet(), Collections.emptySet(), false, false);
|
||||
resolver.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files2));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateExtensions()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var resolver = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1"), false, false);
|
||||
resolver.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(9, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
ST4-4.3.4.jar
|
||||
antlr-runtime-3.5.3.jar
|
||||
antlr4-4.11.1.jar
|
||||
antlr4-runtime-4.11.1.jar
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
icu4j-71.1.jar
|
||||
javax.json-1.1.4.jar
|
||||
org.abego.treelayout.core-1.0.3.jar""", String.join("\n", files2));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateExtensionsSources()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var resolver = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1"), true, false);
|
||||
resolver.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(16, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
ST4-4.3.4-sources.jar
|
||||
ST4-4.3.4.jar
|
||||
antlr-runtime-3.5.3-sources.jar
|
||||
antlr-runtime-3.5.3.jar
|
||||
antlr4-4.11.1-sources.jar
|
||||
antlr4-4.11.1.jar
|
||||
antlr4-runtime-4.11.1-sources.jar
|
||||
antlr4-runtime-4.11.1.jar
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
icu4j-71.1-sources.jar
|
||||
icu4j-71.1.jar
|
||||
javax.json-1.1.4-sources.jar
|
||||
javax.json-1.1.4.jar
|
||||
org.abego.treelayout.core-1.0.3-sources.jar
|
||||
org.abego.treelayout.core-1.0.3.jar""", String.join("\n", files2));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateExtensionsJavadoc()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var resolver = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1"), false, true);
|
||||
resolver.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(16, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
ST4-4.3.4-javadoc.jar
|
||||
ST4-4.3.4.jar
|
||||
antlr-runtime-3.5.3-javadoc.jar
|
||||
antlr-runtime-3.5.3.jar
|
||||
antlr4-4.11.1-javadoc.jar
|
||||
antlr4-4.11.1.jar
|
||||
antlr4-runtime-4.11.1-javadoc.jar
|
||||
antlr4-runtime-4.11.1.jar
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
icu4j-71.1-javadoc.jar
|
||||
icu4j-71.1.jar
|
||||
javax.json-1.1.4-javadoc.jar
|
||||
javax.json-1.1.4.jar
|
||||
org.abego.treelayout.core-1.0.3-javadoc.jar
|
||||
org.abego.treelayout.core-1.0.3.jar""", String.join("\n", files2));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateExtensionsBoth()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var resolver = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1"), true, true);
|
||||
resolver.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(23, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
ST4-4.3.4-javadoc.jar
|
||||
ST4-4.3.4-sources.jar
|
||||
ST4-4.3.4.jar
|
||||
antlr-runtime-3.5.3-javadoc.jar
|
||||
antlr-runtime-3.5.3-sources.jar
|
||||
antlr-runtime-3.5.3.jar
|
||||
antlr4-4.11.1-javadoc.jar
|
||||
antlr4-4.11.1-sources.jar
|
||||
antlr4-4.11.1.jar
|
||||
antlr4-runtime-4.11.1-javadoc.jar
|
||||
antlr4-runtime-4.11.1-sources.jar
|
||||
antlr4-runtime-4.11.1.jar
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
icu4j-71.1-javadoc.jar
|
||||
icu4j-71.1-sources.jar
|
||||
icu4j-71.1.jar
|
||||
javax.json-1.1.4-javadoc.jar
|
||||
javax.json-1.1.4-sources.jar
|
||||
javax.json-1.1.4.jar
|
||||
org.abego.treelayout.core-1.0.3-javadoc.jar
|
||||
org.abego.treelayout.core-1.0.3-sources.jar
|
||||
org.abego.treelayout.core-1.0.3.jar""", String.join("\n", files2));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResolvedRepository()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var properties = new File(tmp1, "local.properties");
|
||||
FileUtils.writeString("bld.repo.testrepo=" + MAVEN_CENTRAL, properties);
|
||||
|
||||
var resolver = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of("testrepo"), List.of("org.antlr:antlr4:4.11.1"), false, false);
|
||||
resolver.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(9, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
ST4-4.3.4.jar
|
||||
antlr-runtime-3.5.3.jar
|
||||
antlr4-4.11.1.jar
|
||||
antlr4-runtime-4.11.1.jar
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
icu4j-71.1.jar
|
||||
javax.json-1.1.4.jar
|
||||
org.abego.treelayout.core-1.0.3.jar""", String.join("\n", files2));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckHash()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var resolver = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1"), false, false);
|
||||
resolver.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files = tmp2.listFiles();
|
||||
assertEquals(9, files.length);
|
||||
Arrays.stream(files).forEach(file -> {
|
||||
if (!file.getName().startsWith(Wrapper.WRAPPER_PREFIX)) {
|
||||
file.delete();
|
||||
}
|
||||
});
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files2));
|
||||
|
||||
resolver.updateExtensions();
|
||||
var files3 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files3.size());
|
||||
Collections.sort(files3);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files3));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteHash()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var resolver = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1"), false, false);
|
||||
resolver.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files = tmp2.listFiles();
|
||||
assertEquals(9, files.length);
|
||||
Arrays.stream(files).forEach(file -> {
|
||||
if (!file.getName().startsWith(Wrapper.WRAPPER_PREFIX)) {
|
||||
file.delete();
|
||||
}
|
||||
});
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files2));
|
||||
|
||||
resolver.updateExtensions();
|
||||
var files3 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files3.size());
|
||||
Collections.sort(files3);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files3));
|
||||
hash_file.delete();
|
||||
|
||||
resolver.updateExtensions();
|
||||
var files4 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(9, files4.size());
|
||||
Collections.sort(files4);
|
||||
assertEquals("""
|
||||
ST4-4.3.4.jar
|
||||
antlr-runtime-3.5.3.jar
|
||||
antlr4-4.11.1.jar
|
||||
antlr4-runtime-4.11.1.jar
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
icu4j-71.1.jar
|
||||
javax.json-1.1.4.jar
|
||||
org.abego.treelayout.core-1.0.3.jar""", String.join("\n", files4));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateHash()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var resolver = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1"), false, false);
|
||||
resolver.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files = tmp2.listFiles();
|
||||
assertEquals(9, files.length);
|
||||
Arrays.stream(files).forEach(file -> {
|
||||
if (!file.getName().startsWith(Wrapper.WRAPPER_PREFIX)) {
|
||||
file.delete();
|
||||
}
|
||||
});
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files2));
|
||||
|
||||
resolver.updateExtensions();
|
||||
var files3 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files3.size());
|
||||
Collections.sort(files3);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files3));
|
||||
FileUtils.writeString("updated", hash_file);
|
||||
|
||||
resolver.updateExtensions();
|
||||
var files4 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(9, files4.size());
|
||||
Collections.sort(files4);
|
||||
assertEquals("""
|
||||
ST4-4.3.4.jar
|
||||
antlr-runtime-3.5.3.jar
|
||||
antlr4-4.11.1.jar
|
||||
antlr4-runtime-4.11.1.jar
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
icu4j-71.1.jar
|
||||
javax.json-1.1.4.jar
|
||||
org.abego.treelayout.core-1.0.3.jar""", String.join("\n", files4));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddExtension()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var resolver1 = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1"), false, false);
|
||||
resolver1.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(9, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
ST4-4.3.4.jar
|
||||
antlr-runtime-3.5.3.jar
|
||||
antlr4-4.11.1.jar
|
||||
antlr4-runtime-4.11.1.jar
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
icu4j-71.1.jar
|
||||
javax.json-1.1.4.jar
|
||||
org.abego.treelayout.core-1.0.3.jar""", String.join("\n", files2));
|
||||
|
||||
var resolver2 = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1", "org.jsoup:jsoup:1.15.4"), false, false);
|
||||
resolver2.updateExtensions();
|
||||
var files3 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(10, files3.size());
|
||||
Collections.sort(files3);
|
||||
assertEquals("""
|
||||
ST4-4.3.4.jar
|
||||
antlr-runtime-3.5.3.jar
|
||||
antlr4-4.11.1.jar
|
||||
antlr4-runtime-4.11.1.jar
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
icu4j-71.1.jar
|
||||
javax.json-1.1.4.jar
|
||||
jsoup-1.15.4.jar
|
||||
org.abego.treelayout.core-1.0.3.jar""", String.join("\n", files3));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveExtension()
|
||||
throws Exception {
|
||||
var tmp1 = Files.createTempDirectory("test1").toFile();
|
||||
var tmp2 = Files.createTempDirectory("test2").toFile();
|
||||
try {
|
||||
new Wrapper().createWrapperFiles(tmp2, BldVersion.getVersion());
|
||||
|
||||
var hash_file = new File(tmp1, "wrapper.hash");
|
||||
assertFalse(hash_file.exists());
|
||||
var files1 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(2, files1.size());
|
||||
Collections.sort(files1);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties""", String.join("\n", files1));
|
||||
|
||||
var resolver1 = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.antlr:antlr4:4.11.1", "org.jsoup:jsoup:1.15.4"), false, false);
|
||||
resolver1.updateExtensions();
|
||||
|
||||
assertTrue(hash_file.exists());
|
||||
var files2 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(10, files2.size());
|
||||
Collections.sort(files2);
|
||||
assertEquals("""
|
||||
ST4-4.3.4.jar
|
||||
antlr-runtime-3.5.3.jar
|
||||
antlr4-4.11.1.jar
|
||||
antlr4-runtime-4.11.1.jar
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
icu4j-71.1.jar
|
||||
javax.json-1.1.4.jar
|
||||
jsoup-1.15.4.jar
|
||||
org.abego.treelayout.core-1.0.3.jar""", String.join("\n", files2));
|
||||
|
||||
var resolver2 = new WrapperExtensionResolver(tmp1, hash_file, tmp2, List.of(MAVEN_CENTRAL), List.of("org.jsoup:jsoup:1.15.4"), false, false);
|
||||
resolver2.updateExtensions();
|
||||
var files3 = FileUtils.getFileList(tmp2);
|
||||
assertEquals(3, files3.size());
|
||||
Collections.sort(files3);
|
||||
assertEquals("""
|
||||
bld-wrapper.jar
|
||||
bld-wrapper.properties
|
||||
jsoup-1.15.4.jar""", String.join("\n", files3));
|
||||
} finally {
|
||||
tmp2.delete();
|
||||
tmp1.delete();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue