Skip to content

Commit

Permalink
test: added bunch of tests for ProjectBuilder
Browse files Browse the repository at this point in the history
These tests the main ways a project can be built: from a source file,
from a JAR or from a GAV. In all three cases we also test their options
being overridden by aliases.
  • Loading branch information
quintesse committed Sep 28, 2023
1 parent 2292fa3 commit 79caf95
Show file tree
Hide file tree
Showing 5 changed files with 426 additions and 2 deletions.
28 changes: 28 additions & 0 deletions itests/alltags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

//REPOS dummy=http://dummy
//DEPS dummy.org:dummy:1.2.3

//SOURCES Two.java
//SOURCES nested/*.java

//FILES res/resource.properties renamed.properties=res/resource.properties
//FILES META-INF/application.properties=res/resource.properties

//COMPILE_OPTIONS --enable-preview --verbose
//RUNTIME_OPTIONS --add-opens java.base/java.net=ALL-UNNAMED
//NATIVE_OPTIONS -O1 -d

//JAVA 11+
//MAIN mainclass
//MODULE mymodule
//DESCRIPTION some description
//GAV example.org:alltags:1.2.3
//CDS
//PREVIEW
//MANIFEST one=1 two=2 three=3
//JAVAAGENT

public class alltags {
public static void main(String... args) {
}
}
81 changes: 81 additions & 0 deletions itests/jbang-catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,87 @@
},
"resource": {
"script-ref": "res/resource.java"
},
"alltags": {
"script-ref": "alltags.java",
"description": "twodesc",
"arguments": ["2"],
"runtime-options": ["--two"],
"sources": ["helloworld.java"],
"files": ["res/test.properties"],
"dependencies": ["twodep"],
"repositories": ["tworepo"],
"classpaths": ["twocp"],
"properties": {"two":"2"},
"java": "twojava",
"main": "twomain",
"module": "twomodule",
"compile-options": ["--ctwo"],
"native-image": true,
"native-options": ["--ntwo"],
"jfr": "twojfr",
"debug": {"twod":"2"},
"cds": true,
"interactive": true,
"enable-preview": true,
"enable-assertions": true,
"enable-system-assertions": true,
"manifest-options": {"twom":"2"},
"java-agents": [{"agent-ref":"twojag","options":"twoopts"}]
},
"hellojar": {
"script-ref": "hellojar.jar",
"description": "twodesc",
"arguments": ["2"],
"runtime-options": ["--two"],
"sources": ["helloworld.java"],
"files": ["res/test.properties"],
"dependencies": ["twodep"],
"repositories": ["tworepo"],
"classpaths": ["twocp"],
"properties": {"two":"2"},
"java": "twojava",
"main": "twomain",
"module": "twomodule",
"compile-options": ["--ctwo"],
"native-image": true,
"native-options": ["--ntwo"],
"jfr": "twojfr",
"debug": {"twod":"2"},
"cds": true,
"interactive": true,
"enable-preview": true,
"enable-assertions": true,
"enable-system-assertions": true,
"manifest-options": {"twom":"2"},
"java-agents": [{"agent-ref":"twojag","options":"twoopts"}]
},
"pgmgav": {
"script-ref": "org.eclipse.jgit:org.eclipse.jgit.pgm:5.9.0.202009080501-r",
"description": "twodesc",
"arguments": ["2"],
"runtime-options": ["--two"],
"sources": ["helloworld.java"],
"files": ["res/test.properties"],
"dependencies": ["info.picocli:picocli:4.6.3"],
"repositories": ["mavencentral", "tworepo"],
"classpaths": ["twocp"],
"properties": {"two":"2"},
"java": "twojava",
"main": "twomain",
"module": "twomodule",
"compile-options": ["--ctwo"],
"native-image": true,
"native-options": ["--ntwo"],
"jfr": "twojfr",
"debug": {"twod":"2"},
"cds": true,
"interactive": true,
"enable-preview": true,
"enable-assertions": true,
"enable-system-assertions": true,
"manifest-options": {"twom":"2"},
"java-agents": [{"agent-ref":"twojag","options":"twoopts"}]
}
},
"templates": {},
Expand Down
33 changes: 32 additions & 1 deletion src/main/java/dev/jbang/source/RefTarget.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Objects;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import dev.jbang.cli.ExitException;
import dev.jbang.util.Util;
Expand All @@ -16,19 +20,23 @@
* //FILES target=source directives in scripts and templates.
*/
public class RefTarget {
@Nonnull
protected final ResourceRef source;
@Nullable
protected final Path target;

protected RefTarget(ResourceRef source, Path target) {
protected RefTarget(@Nonnull ResourceRef source, @Nullable Path target) {
assert (source != null);
this.source = source;
this.target = target;
}

@Nonnull
public ResourceRef getSource() {
return source;
}

@Nullable
public Path getTarget() {
return target;
}
Expand All @@ -52,6 +60,29 @@ public void copy(Path destroot) {
}
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
RefTarget refTarget = (RefTarget) o;
return source.equals(refTarget.source) && Objects.equals(target, refTarget.target);
}

@Override
public int hashCode() {
return Objects.hash(source, target);
}

@Override
public String toString() {
return "RefTarget{" +
"source=" + source +
", target=" + target +
'}';
}

public static RefTarget create(String ref, Path dest, ResourceResolver siblingResolver) {
return new RefTarget(siblingResolver.resolve(ref), dest);
}
Expand Down
1 change: 0 additions & 1 deletion src/test/java/dev/jbang/cli/TestAlias.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ void testAddWithDefaultCatalogFile2() throws IOException {
assertThat(alias.classpaths, contains("cps"));
assertThat(alias.properties, aMapWithSize(1));
assertThat(alias.properties, hasEntry("prop", "val"));
assertThat(alias.arguments, iterableWithSize(3));
assertThat(alias.mainClass, is("mainclass"));
assertThat(alias.compileOptions, iterableWithSize(1));
assertThat(alias.compileOptions, contains("copts"));
Expand Down
Loading

0 comments on commit 79caf95

Please sign in to comment.