Skip to content

Commit

Permalink
Hacking
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Dec 19, 2020
1 parent 087d20a commit 10ca8f2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
*/
public abstract class GradleBuildWriter {

/**
* Dependency types that are mapped to a jar.
*/
private static final List<String> JAR_DEPENDENCY_TYPES = Arrays.asList("test-jar", "maven-plugin", "ejb",
"ejb-client", "java-source", "javadoc");

/**
* Write a {@linkplain GradleBuild build.gradle} using the specified
* {@linkplain IndentingWriter writer}.
Expand Down Expand Up @@ -138,6 +144,14 @@ private void writeDependencies(IndentingWriter writer, GradleBuild build) {
}
}

protected String determineDependencyType(Dependency dependency) {
String type = dependency.getType();
if (type != null && JAR_DEPENDENCY_TYPES.contains(type)) {
return null;
}
return type;
}

private Predicate<DependencyScope> hasScope(DependencyScope... validScopes) {
return (scope) -> Arrays.asList(validScopes).contains(scope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected void writeDependency(IndentingWriter writer, Dependency dependency) {
String quoteStyle = determineQuoteStyle(dependency.getVersion());
String version = determineVersion(dependency.getVersion());
String classifier = dependency.getClassifier();
String type = dependency.getType();
String type = determineDependencyType(dependency);
boolean hasExclusions = !dependency.getExclusions().isEmpty();
writer.print(configurationForDependency(dependency));
writer.print((hasExclusions) ? "(" : " ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected void writeConfiguration(IndentingWriter writer, GradleConfiguration co
protected void writeDependency(IndentingWriter writer, Dependency dependency) {
String version = determineVersion(dependency.getVersion());
String classifier = dependency.getClassifier();
String type = dependency.getType();
String type = determineDependencyType(dependency);
writer.print(configurationForDependency(dependency) + "(\"" + dependency.getGroupId() + ":"
+ dependency.getArtifactId() + ((version != null) ? ":" + version : "")
+ ((classifier != null) ? ":" + classifier : "") + ((type != null) ? "@" + type : "") + "\")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,15 @@ void gradleBuildWithNonNullArtifactTypeAndClassifierDependency() {
"}");
}

@Test
void gradleBuildWithMavenSpecialJarTypeDependency() {
GradleBuild build = new GradleBuild();
build.dependencies().add("root", Dependency.withCoordinates("com.example", "acme")
.scope(DependencyScope.TEST_COMPILE).classifier("tests").type("test-jar"));
List<String> lines = generateBuild(build);
assertThat(lines).containsSequence("dependencies {", " testImplementation 'com.example:acme:tests'", "}");
}

@Test
void gradleBuildWithOrderedDependencies() {
GradleBuild build = new GradleBuild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,15 @@ void gradleBuildWithClassifierDependency() {
assertThat(lines).containsSequence("dependencies {", " implementation(\"com.example:acme:test-jar\")", "}");
}

@Test
void gradleBuildWithSpecialJarTypeDependency() {
GradleBuild build = new GradleBuild();
build.dependencies().add("root", Dependency.withCoordinates("com.example", "acme")
.scope(DependencyScope.TEST_COMPILE).classifier("tests").type("test-jar"));
List<String> lines = generateBuild(build);
assertThat(lines).containsSequence("dependencies {", " testImplementation(\"com.example:acme:tests\")", "}");
}

@Test
void gradleBuildWithExclusions() {
GradleBuild build = new GradleBuild();
Expand Down

0 comments on commit 10ca8f2

Please sign in to comment.