mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-15 23:13:30 +08:00
Polish "Add support for Maven's finalName"
See gh-1052
This commit is contained in:
parent
0f7196ae02
commit
f7ef31d6f4
@ -47,12 +47,12 @@ public class MavenBuildSettings extends BuildSettings {
|
||||
|
||||
private final MavenScm scm;
|
||||
|
||||
private final String finalName;
|
||||
|
||||
private final String sourceDirectory;
|
||||
|
||||
private final String testSourceDirectory;
|
||||
|
||||
private final String finalName;
|
||||
|
||||
protected MavenBuildSettings(Builder builder) {
|
||||
super(builder);
|
||||
this.parent = builder.parent;
|
||||
@ -62,9 +62,9 @@ public class MavenBuildSettings extends BuildSettings {
|
||||
this.licenses = Collections.unmodifiableList(new ArrayList<>(builder.licenses));
|
||||
this.developers = Collections.unmodifiableList(new ArrayList<>(builder.developers));
|
||||
this.scm = builder.scm.build();
|
||||
this.finalName = builder.finalName;
|
||||
this.sourceDirectory = builder.sourceDirectory;
|
||||
this.testSourceDirectory = builder.testSourceDirectory;
|
||||
this.finalName = builder.finalName;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,6 +125,14 @@ public class MavenBuildSettings extends BuildSettings {
|
||||
return this.scm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the final name of the artifact.
|
||||
* @return the final name or {@code null} to use the default
|
||||
*/
|
||||
public String getFinalName() {
|
||||
return this.finalName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the location of main source code. Can use Maven properties such as
|
||||
* {@code ${basedir}}.
|
||||
@ -143,14 +151,6 @@ public class MavenBuildSettings extends BuildSettings {
|
||||
return this.testSourceDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the final name of the compiled artifact.
|
||||
* @return the final name
|
||||
*/
|
||||
public String getFinalName() {
|
||||
return this.finalName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder for a Maven dependency.
|
||||
*
|
||||
@ -172,12 +172,12 @@ public class MavenBuildSettings extends BuildSettings {
|
||||
|
||||
private final MavenScm.Builder scm = new MavenScm.Builder();
|
||||
|
||||
private String finalName;
|
||||
|
||||
private String sourceDirectory;
|
||||
|
||||
private String testSourceDirectory;
|
||||
|
||||
private String finalName;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
@ -264,6 +264,16 @@ public class MavenBuildSettings extends BuildSettings {
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the bundled project when it is finally built.
|
||||
* @param finalName the final name of the artifact
|
||||
* @return this for method chaining
|
||||
*/
|
||||
public Builder finalName(String finalName) {
|
||||
this.finalName = finalName;
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the the location of main source code. Can use Maven properties such as
|
||||
* {@code ${basedir}}.
|
||||
@ -288,16 +298,6 @@ public class MavenBuildSettings extends BuildSettings {
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the finalName of the artifact as a child tag in the <build> tag.
|
||||
* @param finalName the final name of the artifact after compiling
|
||||
* @return this for method chaining
|
||||
*/
|
||||
public Builder finalName(String finalName) {
|
||||
this.finalName = finalName;
|
||||
return self();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MavenBuildSettings build() {
|
||||
return new MavenBuildSettings(this);
|
||||
|
@ -304,9 +304,9 @@ public class MavenBuildWriter {
|
||||
|
||||
private void writeBuild(IndentingWriter writer, MavenBuild build) {
|
||||
MavenBuildSettings settings = build.getSettings();
|
||||
if (settings.getSourceDirectory() == null && settings.getTestSourceDirectory() == null
|
||||
&& settings.getFinalName() == null && build.resources().isEmpty() && build.testResources().isEmpty()
|
||||
&& build.plugins().isEmpty()) {
|
||||
if (settings.getFinalName() == null && settings.getSourceDirectory() == null
|
||||
&& settings.getTestSourceDirectory() == null && build.resources().isEmpty()
|
||||
&& build.testResources().isEmpty() && build.plugins().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
writer.println();
|
||||
|
@ -672,6 +672,20 @@ class MavenBuildWriterTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithNoFinalName() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo").build();
|
||||
generatePom(build, (pom) -> assertThat(pom.nodeAtPath("/project/build/finalName")).isNull());
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithFinalName() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo").finalName("demo.jar");
|
||||
generatePom(build, (pom) -> assertThat(pom).textAtPath("/project/build/finalName").isEqualTo("demo.jar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithCustomSourceDirectories() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
@ -685,14 +699,6 @@ class MavenBuildWriterTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithFinalName() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
build.settings().coordinates("com.example.demo", "demo").finalName("theArtifact.jar");
|
||||
generatePom(build,
|
||||
(pom) -> assertThat(pom).textAtPath("/project/build/finalName").isEqualTo("theArtifact.jar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pomWithCustomVersion() {
|
||||
MavenBuild build = new MavenBuild();
|
||||
|
Loading…
Reference in New Issue
Block a user