Commit 9b4df313 authored by liaozan's avatar liaozan 🏀

feat: subModuleNamePrefix

parent 8e53a5ff
......@@ -3,8 +3,10 @@ package com.schbrain.archetype.initializer.listener;
import com.schbrain.archetype.initializer.maven.MavenUtils;
import com.schbrain.archetype.initializer.param.ArchetypeGenerateParam;
import lombok.SneakyThrows;
import org.springframework.boot.cloud.CloudPlatform;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.ConfigurableEnvironment;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
......@@ -20,12 +22,15 @@ public class ProjectWarmUpListener implements ApplicationListener<ApplicationSta
@SneakyThrows
@Override
public void onApplicationEvent(ApplicationStartedEvent event) {
executor.execute(() -> {
ArchetypeGenerateParam mockParam = new ArchetypeGenerateParam();
mockParam.setGroupId("com.schbrain");
mockParam.setArtifactId("schbrain-init");
MavenUtils.generate(mockParam);
});
ConfigurableEnvironment environment = event.getApplicationContext().getEnvironment();
if (CloudPlatform.KUBERNETES.isActive(environment)) {
executor.execute(() -> {
ArchetypeGenerateParam mockParam = new ArchetypeGenerateParam();
mockParam.setGroupId("com.schbrain");
mockParam.setArtifactId("schbrain-init");
MavenUtils.generate(mockParam);
});
}
}
}
\ No newline at end of file
......@@ -10,7 +10,6 @@ import org.apache.maven.settings.Mirror;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.apache.maven.settings.io.DefaultSettingsWriter;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.IOException;
......@@ -101,10 +100,6 @@ public class MavenUtils {
@SuppressWarnings("SpellCheckingInspection")
private static String[] getArchetypeGenerateArgs(ArchetypeGenerateParam param, String settingsFile, String outputDirectory) {
String subModuleNamePrefix = param.getSubModuleNamePrefix();
if (!StringUtils.hasText(subModuleNamePrefix)) {
subModuleNamePrefix = param.getArtifactId();
}
return new String[]{
"-B",
"archetype:generate",
......@@ -115,7 +110,9 @@ public class MavenUtils {
String.format("-DoutputDirectory=%s", outputDirectory),
String.format("-DgroupId=%s", param.getGroupId()),
String.format("-DartifactId=%s", param.getArtifactId()),
String.format("-DsubModuleNamePrefix=%s", subModuleNamePrefix),
String.format("-Dversion=%s", param.getVersion()),
String.format("-Dpackage=%s", param.getPackageName()),
String.format("-DsubModuleNamePrefix=%s", param.getSubModuleNamePrefix()),
};
}
......
......@@ -11,6 +11,8 @@ import javax.validation.constraints.NotBlank;
@Data
public class ArchetypeGenerateParam {
private static final String DELIMITER = "-";
/**
* groupId
*/
......@@ -21,9 +23,35 @@ public class ArchetypeGenerateParam {
*/
@NotBlank
private String artifactId;
/**
* version
*/
private String version = "1.0.0-SNAPSHOT";
/**
* packageName
*/
private String packageName;
/**
* 子模块前缀
*/
private String subModuleNamePrefix;
public String getSubModuleNamePrefix() {
if (this.subModuleNamePrefix == null) {
if (this.artifactId.contains(DELIMITER)) {
this.subModuleNamePrefix = this.artifactId.split(DELIMITER)[1];
} else {
this.subModuleNamePrefix = this.artifactId;
}
}
return this.subModuleNamePrefix;
}
public String getPackageName() {
if (this.packageName == null) {
this.packageName = String.format("%s.%s", this.groupId, this.getSubModuleNamePrefix());
}
return this.packageName;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment