mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-26 05:32:58 +08:00
Polish "Add support for Maven defaultGoal"
See gh-1134
This commit is contained in:
@@ -47,14 +47,14 @@ public class MavenBuildSettings extends BuildSettings {
|
|||||||
|
|
||||||
private final MavenScm scm;
|
private final MavenScm scm;
|
||||||
|
|
||||||
|
private final String defaultGoal;
|
||||||
|
|
||||||
private final String finalName;
|
private final String finalName;
|
||||||
|
|
||||||
private final String sourceDirectory;
|
private final String sourceDirectory;
|
||||||
|
|
||||||
private final String testSourceDirectory;
|
private final String testSourceDirectory;
|
||||||
|
|
||||||
private final String defaultGoal;
|
|
||||||
|
|
||||||
protected MavenBuildSettings(Builder builder) {
|
protected MavenBuildSettings(Builder builder) {
|
||||||
super(builder);
|
super(builder);
|
||||||
this.parent = builder.parent;
|
this.parent = builder.parent;
|
||||||
@@ -64,10 +64,10 @@ public class MavenBuildSettings extends BuildSettings {
|
|||||||
this.licenses = Collections.unmodifiableList(new ArrayList<>(builder.licenses));
|
this.licenses = Collections.unmodifiableList(new ArrayList<>(builder.licenses));
|
||||||
this.developers = Collections.unmodifiableList(new ArrayList<>(builder.developers));
|
this.developers = Collections.unmodifiableList(new ArrayList<>(builder.developers));
|
||||||
this.scm = builder.scm.build();
|
this.scm = builder.scm.build();
|
||||||
|
this.defaultGoal = builder.defaultGoal;
|
||||||
this.finalName = builder.finalName;
|
this.finalName = builder.finalName;
|
||||||
this.sourceDirectory = builder.sourceDirectory;
|
this.sourceDirectory = builder.sourceDirectory;
|
||||||
this.testSourceDirectory = builder.testSourceDirectory;
|
this.testSourceDirectory = builder.testSourceDirectory;
|
||||||
this.defaultGoal = builder.defaultGoal;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,6 +128,14 @@ public class MavenBuildSettings extends BuildSettings {
|
|||||||
return this.scm;
|
return this.scm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the default goal or phase to execute if none is given.
|
||||||
|
* @return the default goal or {@code null} to use the default
|
||||||
|
*/
|
||||||
|
public String getDefaultGoal() {
|
||||||
|
return this.defaultGoal;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the final name of the artifact.
|
* Return the final name of the artifact.
|
||||||
* @return the final name or {@code null} to use the default
|
* @return the final name or {@code null} to use the default
|
||||||
@@ -154,14 +162,6 @@ public class MavenBuildSettings extends BuildSettings {
|
|||||||
return this.testSourceDirectory;
|
return this.testSourceDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the default goal to execute when none is specified for the project.
|
|
||||||
* @return the default goal or {@code null} to use the default
|
|
||||||
*/
|
|
||||||
public String getDefaultGoal() {
|
|
||||||
return this.defaultGoal;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder for a Maven dependency.
|
* Builder for a Maven dependency.
|
||||||
*
|
*
|
||||||
@@ -183,14 +183,14 @@ public class MavenBuildSettings extends BuildSettings {
|
|||||||
|
|
||||||
private final MavenScm.Builder scm = new MavenScm.Builder();
|
private final MavenScm.Builder scm = new MavenScm.Builder();
|
||||||
|
|
||||||
|
private String defaultGoal;
|
||||||
|
|
||||||
private String finalName;
|
private String finalName;
|
||||||
|
|
||||||
private String sourceDirectory;
|
private String sourceDirectory;
|
||||||
|
|
||||||
private String testSourceDirectory;
|
private String testSourceDirectory;
|
||||||
|
|
||||||
private String defaultGoal;
|
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,6 +287,16 @@ public class MavenBuildSettings extends BuildSettings {
|
|||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default goal or phase to execute if none is given.
|
||||||
|
* @param defaultGoal the default goal or {@code null} to use the default
|
||||||
|
* @return this for method chaining
|
||||||
|
*/
|
||||||
|
public Builder defaultGoal(String defaultGoal) {
|
||||||
|
this.defaultGoal = defaultGoal;
|
||||||
|
return self();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the the location of main source code. Can use Maven properties such as
|
* Set the the location of main source code. Can use Maven properties such as
|
||||||
* {@code ${basedir}}.
|
* {@code ${basedir}}.
|
||||||
@@ -311,16 +321,6 @@ public class MavenBuildSettings extends BuildSettings {
|
|||||||
return self();
|
return self();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the default goal to execute when none is specified for the project.
|
|
||||||
* @param defaultGoal the default goal or {@code null} to use the default
|
|
||||||
* @return this for method chaining
|
|
||||||
*/
|
|
||||||
public Builder defaultGoal(String defaultGoal) {
|
|
||||||
this.defaultGoal = defaultGoal;
|
|
||||||
return self();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MavenBuildSettings build() {
|
public MavenBuildSettings build() {
|
||||||
return new MavenBuildSettings(this);
|
return new MavenBuildSettings(this);
|
||||||
|
|||||||
@@ -304,8 +304,8 @@ public class MavenBuildWriter {
|
|||||||
|
|
||||||
private void writeBuild(IndentingWriter writer, MavenBuild build) {
|
private void writeBuild(IndentingWriter writer, MavenBuild build) {
|
||||||
MavenBuildSettings settings = build.getSettings();
|
MavenBuildSettings settings = build.getSettings();
|
||||||
if (settings.getFinalName() == null && settings.getSourceDirectory() == null
|
if (settings.getDefaultGoal() == null && settings.getFinalName() == null
|
||||||
&& settings.getTestSourceDirectory() == null && settings.getDefaultGoal() == null
|
&& settings.getSourceDirectory() == null && settings.getTestSourceDirectory() == null
|
||||||
&& build.resources().isEmpty() && build.testResources().isEmpty() && build.plugins().isEmpty()) {
|
&& build.resources().isEmpty() && build.testResources().isEmpty() && build.plugins().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,11 +139,4 @@ class MavenBuildTests {
|
|||||||
.hasOnlyOneElementSatisfying((testPlugin) -> assertThat(testPlugin.isExtensions()).isTrue());
|
.hasOnlyOneElementSatisfying((testPlugin) -> assertThat(testPlugin.isExtensions()).isTrue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void mavenDefaultGoalCanBeCustomized() {
|
|
||||||
MavenBuild build = new MavenBuild();
|
|
||||||
build.settings().defaultGoal("clean package");
|
|
||||||
assertThat(build.getSettings().getDefaultGoal()).isEqualTo("clean package");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -672,6 +672,21 @@ class MavenBuildWriterTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pomWithNoDefaultGoal() {
|
||||||
|
MavenBuild build = new MavenBuild();
|
||||||
|
build.settings().coordinates("com.example.demo", "demo").build();
|
||||||
|
generatePom(build, (pom) -> assertThat(pom.nodeAtPath("/project/build/defaultGoal")).isNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void pomWithDefaultGoal() {
|
||||||
|
MavenBuild build = new MavenBuild();
|
||||||
|
build.settings().coordinates("com.example.demo", "demo").defaultGoal("clean package");
|
||||||
|
generatePom(build,
|
||||||
|
(pom) -> assertThat(pom).textAtPath("/project/build/defaultGoal").isEqualTo("clean package"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void pomWithNoFinalName() {
|
void pomWithNoFinalName() {
|
||||||
MavenBuild build = new MavenBuild();
|
MavenBuild build = new MavenBuild();
|
||||||
@@ -802,21 +817,6 @@ class MavenBuildWriterTests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void pomWithNoDefaultGoal() {
|
|
||||||
MavenBuild build = new MavenBuild();
|
|
||||||
build.settings().coordinates("com.example.demo", "demo").build();
|
|
||||||
generatePom(build, (pom) -> assertThat(pom.nodeAtPath("/project/build/defaultGoal")).isNull());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void pomWithDefaultGoal() {
|
|
||||||
MavenBuild build = new MavenBuild();
|
|
||||||
build.settings().coordinates("com.example.demo", "demo").defaultGoal("clean package");
|
|
||||||
generatePom(build,
|
|
||||||
(pom) -> assertThat(pom).textAtPath("/project/build/defaultGoal").isEqualTo("clean package"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generatePom(MavenBuild mavenBuild, Consumer<NodeAssert> consumer) {
|
private void generatePom(MavenBuild mavenBuild, Consumer<NodeAssert> consumer) {
|
||||||
MavenBuildWriter writer = new MavenBuildWriter();
|
MavenBuildWriter writer = new MavenBuildWriter();
|
||||||
StringWriter out = new StringWriter();
|
StringWriter out = new StringWriter();
|
||||||
|
|||||||
Reference in New Issue
Block a user