Polish "Add dependency classifier support"

See gh-1049
This commit is contained in:
Stephane Nicoll
2020-03-17 05:31:23 +01:00
parent a81e4ef77b
commit 835f69986c
14 changed files with 108 additions and 115 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,10 +87,10 @@ public class Dependency extends MetadataElement implements Describable {
private String version;
private String type;
private String classifier;
private String type;
private List<Mapping> mappings = new ArrayList<>();
private String scope = SCOPE_COMPILE;
@@ -132,6 +132,7 @@ public class Dependency extends MetadataElement implements Describable {
this.groupId = dependency.groupId;
this.artifactId = dependency.artifactId;
this.version = dependency.version;
this.classifier = dependency.classifier;
this.type = dependency.type;
this.mappings.addAll(dependency.mappings);
this.scope = dependency.scope;
@@ -145,7 +146,6 @@ public class Dependency extends MetadataElement implements Describable {
this.starter = dependency.starter;
this.keywords.addAll(dependency.keywords);
this.links.addAll(dependency.links);
this.classifier = dependency.classifier;
}
public void setScope(String scope) {
@@ -328,6 +328,11 @@ public class Dependency extends MetadataElement implements Describable {
this.version = version;
}
/**
* Return the classifier, can be {@code null} to indicate that no classifier is
* available.
* @return the classifier or {@code null}
*/
public String getClassifier() {
return this.classifier;
}
@@ -469,18 +474,12 @@ public class Dependency extends MetadataElement implements Describable {
}
public static Dependency withId(String id, String groupId, String artifactId, String version, String scope) {
return withId(id, groupId, artifactId, version, scope, null);
}
public static Dependency withId(String id, String groupId, String artifactId, String version, String scope,
String classifier) {
Dependency dependency = new Dependency();
dependency.setId(id);
dependency.groupId = groupId;
dependency.artifactId = artifactId;
dependency.version = version;
dependency.scope = (scope != null) ? scope : SCOPE_COMPILE;
dependency.classifier = classifier;
return dependency;
}
@@ -527,8 +526,6 @@ public class Dependency extends MetadataElement implements Describable {
*/
private String version;
private String classifier;
/**
* The starter setting to use for the mapping or {@code null} to use the default.
*/
@@ -561,14 +558,6 @@ public class Dependency extends MetadataElement implements Describable {
this.version = version;
}
public String getClassifier() {
return this.classifier;
}
public void setClassifier(String classifier) {
this.classifier = classifier;
}
public Boolean getStarter() {
return this.starter;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,8 +46,8 @@ public final class MetadataBuildItemMapper {
? VersionReference.ofValue(dependency.getVersion()) : null;
return io.spring.initializr.generator.buildsystem.Dependency
.withCoordinates(dependency.getGroupId(), dependency.getArtifactId()).version(versionReference)
.scope(toDependencyScope(dependency.getScope())).type(dependency.getType())
.classifier(dependency.getClassifier()).build();
.scope(toDependencyScope(dependency.getScope())).classifier(dependency.getClassifier())
.type(dependency.getType()).build();
}
private static DependencyScope toDependencyScope(String scope) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,9 @@ class MetadataBuildItemResolverTests {
void resoleDependencyWithMatchingEntry() {
InitializrMetadata metadata = new InitializrMetadata();
DependencyGroup group = DependencyGroup.create("test");
group.getContent().add(Dependency.withId("test-dep", "com.example", "test", "1.0.0", "runtime", "classifier"));
Dependency target = Dependency.withId("test-dep", "com.example", "test", "1.0.0", "runtime");
target.setClassifier("test-jar");
group.getContent().add(target);
metadata.getDependencies().getContent().add(group);
metadata.validate();
MetadataBuildItemResolver resolver = new MetadataBuildItemResolver(metadata, VERSION_2_0_0);
@@ -53,7 +55,7 @@ class MetadataBuildItemResolverTests {
assertThat(dependency.getGroupId()).isEqualTo("com.example");
assertThat(dependency.getArtifactId()).isEqualTo("test");
assertThat(dependency.getVersion()).hasToString("1.0.0");
assertThat(dependency.getClassifier()).hasToString("classifier");
assertThat(dependency.getClassifier()).hasToString("test-jar");
assertThat(dependency.getScope()).isEqualTo(DependencyScope.RUNTIME);
}