提交 ff40a4b9 编写于 作者: sq3536's avatar sq3536

整改cmd

上级 ac294684
package cn.ibizlab.codegen.cmd;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class ExecuteResult {
private int exitCode;
private String executeOut;
private String errorOut;
public ExecuteResult(int exitCode, String executeOut) {
this.exitCode = exitCode;
this.executeOut = executeOut;
}
}
\ No newline at end of file
package cn.ibizlab.codegen.cmd;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.util.concurrent.*;
public class LocalCommandExecutor {
static final Logger logger = LoggerFactory.getLogger(LocalCommandExecutor.class);
static ExecutorService pool = new ThreadPoolExecutor(0, 50, 3L, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>());
private static LocalCommandExecutor instance;
static {
instance = new LocalCommandExecutor();
}
public static LocalCommandExecutor getInstance() {
return instance;
}
private void closeQuietly(Closeable c) {
try {
if (c != null) {
c.close();
}
} catch (IOException e) {
logger.error("exception", e);
}
}
public ExecuteResult executeCommand(String command, long timeout) {
Future<ExecuteResult> executeFuture = null;
try {
logger.info(command);
// create a Callable for the command's Process which can be called by an Executor
Callable<ExecuteResult> call = new Callable<ExecuteResult>() {
public ExecuteResult call() throws Exception {
ProcessBuilder processBuilder = null;
Process process = null;
InputStream pIn = null;
StreamGobbler outputGobbler = null;
try
{
processBuilder=new ProcessBuilder(new String[]{"sh","-c",command});
processBuilder.redirectErrorStream(true);
process=processBuilder.start();
logger.debug(command+ " started()");
// close process's output stream.
process.getOutputStream().close();
pIn = process.getInputStream();
outputGobbler = new StreamGobbler(pIn, "OUTPUT");
outputGobbler.start();
System.out.println(Thread.currentThread().getName() + " is running");
process.waitFor();
return new ExecuteResult(process.exitValue(), outputGobbler.getContent());
}
catch (Exception ex)
{
String errorMessage = "The command [" + command + "] execute failed.";
logger.error(errorMessage, ex);
return new ExecuteResult(-1, "");
}
finally {
if (pIn != null) {
closeQuietly(pIn);
if (outputGobbler != null && !outputGobbler.isInterrupted()) {
outputGobbler.interrupt();
}
}
if ( process != null) {
process.destroy();
}
}
}
};
// submit the command's call and get the result from a
executeFuture = pool.submit(call);
return executeFuture.get(timeout, TimeUnit.MILLISECONDS);
} catch (TimeoutException ex) {
String errorMessage = "The command [" + command + "] timed out.";
logger.error(errorMessage, ex);
return new ExecuteResult(-1, "");
} catch (ExecutionException ex) {
String errorMessage = "The command [" + command + "] did not complete due to an execution error.";
logger.error(errorMessage, ex);
return new ExecuteResult(-1, "");
} catch (InterruptedException ex) {
String errorMessage = "The command [" + command + "] did not complete due to an interrupted error.";
logger.error(errorMessage, ex);
return new ExecuteResult(-1, "");
} finally {
if (executeFuture != null) {
try {
executeFuture.cancel(true);
} catch (Exception ignore) {
ignore.printStackTrace();
}
}
}
}
}
\ No newline at end of file
package cn.ibizlab.codegen.cmd;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StreamGobbler extends Thread {
private static Logger logger = LoggerFactory.getLogger(StreamGobbler.class);
private InputStream inputStream;
private String streamType;
private StringBuilder buf;
private volatile boolean isStopped = false;
/**
* @param inputStream the InputStream to be consumed
* @param streamType the stream type (should be OUTPUT or ERROR)
*/
public StreamGobbler(final InputStream inputStream, final String streamType) {
this.inputStream = inputStream;
this.streamType = streamType;
this.buf = new StringBuilder();
this.isStopped = false;
}
/**
* Consumes the output from the input stream and displays the lines consumed
* if configured to do so.
*/
@Override
public void run() {
try {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
this.buf.append(line + "\n");
System.out.println(line);
}
} catch (IOException ex) {
logger.trace("Failed to successfully consume and display the input stream of type " + streamType + ".", ex);
} finally {
this.isStopped = true;
synchronized (this) {
notify();
}
}
}
public String getContent() {
if (!this.isStopped) {
synchronized (this) {
try {
wait();
} catch (InterruptedException ignore) {
ignore.printStackTrace();
}
}
}
return this.buf.toString();
}
public String getText() {
return this.buf.toString();
}
}
\ No newline at end of file
package cn.ibizlab.codegen;
import cn.ibizlab.codegen.config.EmbedTemplate;
import cn.ibizlab.codegen.config.GlobalSettings;
import cn.ibizlab.codegen.model.CliFilter;
import cn.ibizlab.codegen.templating.*;
......@@ -42,7 +43,7 @@ public class CodegenConfig {
private List<String> templateDirs;
private String embedTemplate;
private List<EmbedTemplate> embedTemplates;
private String auth;
......@@ -172,8 +173,7 @@ public class CodegenConfig {
public CommonTemplateContentLocator getCommonTemplateContentLocator() {
if(commonTemplateContentLocator==null) {
String path="templ";
if(!StringUtils.isEmpty(embedTemplate))
path=Paths.get("templ" , embedTemplate).toString();
String loc = TemplateManager.getCPResourcePath(path);
URL url = this.getClass().getClassLoader().getResource(loc);
if (url != null) {
......@@ -197,6 +197,7 @@ public class CodegenConfig {
this.getTemplateDirs().forEach(templateDir->{
list.add(new GeneratorTemplateContentLocator(templateDir));
});
}
if(getCommonTemplateContentLocator()!=null) {
list.add(commonTemplateContentLocator);
}
......@@ -205,7 +206,7 @@ public class CodegenConfig {
templatingEngine,
list
);
}
}
return templateProcessor;
......
......@@ -41,7 +41,8 @@ public final class CodegenConfigurator {
private String outputDir;
private List<String> filters;
private List<String> templateDirs;
private String embedTemplate;
private List<EmbedTemplate> embedTemplates;
private List<Volume> volumes;
private List<String> templatePaths;
private List<String> templateFilters;
private String auth;
......@@ -52,7 +53,6 @@ public final class CodegenConfigurator {
private Map<String, Object> additionalProperties = new HashMap<>();
private GeneratorSettings generatorSettings=new GeneratorSettings();
public CodegenConfigurator() {
......@@ -60,24 +60,36 @@ public final class CodegenConfigurator {
}
@SuppressWarnings("DuplicatedCode")
public static CodegenConfigurator fromFile(String configFile, Module... modules) {
public static List<CodegenConfigurator> fromFile(String configFile, Module... modules) {
if (isNotEmpty(configFile)) {
DynamicSettings settings = readDynamicSettings(configFile, modules);
DynamicSettings dynamicSettings = readDynamicSettings(configFile, modules);
if(!ObjectUtils.isEmpty(dynamicSettings))
{
List<CodegenConfigurator> list = new ArrayList<>();
dynamicSettings.values().forEach(settings->{
CodegenConfigurator configurator = new CodegenConfigurator();
GeneratorSettings generatorSettings = settings.getGeneratorSettings();
configurator.setAuth(settings.getAuth());
configurator.setOutputDir(settings.getOutput());
configurator.setInputSpec(settings.getInputSpec());
configurator.setFilters(settings.getInputSpecFilters());
configurator.setTemplateDirs(settings.getTemplateDirs());
configurator.setTemplatePaths(settings.getTemplatePaths());
configurator.setTemplateFilters(settings.getInputSpecFilters());
configurator.setEmbedTemplates(settings.getEmbedTemplates());
configurator.setPackageName(settings.getPackageName());
configurator.setVolumes(settings.getVolumes());
configurator.setProjectName(settings.getProjectName());
if(generatorSettings.getAdditionalProperties() != null) {
configurator.additionalProperties.putAll(generatorSettings.getAdditionalProperties());
if(settings.getAdditionalProperties() != null) {
configurator.additionalProperties.putAll(settings.getAdditionalProperties());
}
list.add(configurator);
});
return list;
}
return configurator;
}
return null;
}
......@@ -108,7 +120,6 @@ public final class CodegenConfigurator {
public CodegenConfigurator addAdditionalProperty(String key, Object value) {
this.additionalProperties.put(key, value);
generatorSettings.getAdditionalProperties().put(key, value);
return this;
}
......@@ -121,7 +132,6 @@ public final class CodegenConfigurator {
public CodegenConfigurator setAdditionalProperties(Map<String, Object> additionalProperties) {
this.additionalProperties = additionalProperties;
generatorSettings.setAdditionalProperties(additionalProperties);
return this;
}
......@@ -137,7 +147,6 @@ public final class CodegenConfigurator {
if (StringUtils.isNotEmpty(projectName)) {
addAdditionalProperty(CodegenConstants.PROJECT_NAME, projectName);
}
generatorSettings.setProjectName(projectName);
return this;
}
......@@ -146,62 +155,55 @@ public final class CodegenConfigurator {
if (StringUtils.isNotEmpty(packageName)) {
addAdditionalProperty(CodegenConstants.PACKAGE_NAME, packageName);
}
generatorSettings.setPackageName(packageName);
return this;
}
public CodegenConfigurator setGitRepoId(String gitRepoId) {
if (StringUtils.isNotEmpty(gitRepoId)) {
addAdditionalProperty(CodegenConstants.GIT_REPO_ID, gitRepoId);
}
generatorSettings.setGitRepoId(gitRepoId);
return this;
}
public CodegenConfigurator setGitHost(String gitHost) {
if (StringUtils.isNotEmpty(gitHost)) {
addAdditionalProperty(CodegenConstants.GIT_HOST, gitHost);
public CodegenConfigurator setAuth(String auth) {
// do not cache this in additional properties.
this.auth = auth;
if (StringUtils.isNotEmpty(auth)) {
addAdditionalProperty("auth", auth);
}
generatorSettings.setGitHost(gitHost);
return this;
}
public CodegenConfigurator setGitUserId(String gitUserId) {
if (StringUtils.isNotEmpty(gitUserId)) {
addAdditionalProperty(CodegenConstants.GIT_USER_ID, gitUserId);
}
generatorSettings.setGitUserId(gitUserId);
public CodegenConfigurator setInputSpec(String inputSpec) {
this.inputSpec = inputSpec;
return this;
}
public CodegenConfigurator setReleaseNote(String releaseNote) {
if (StringUtils.isNotEmpty(releaseNote)) {
addAdditionalProperty(CodegenConstants.RELEASE_NOTE, releaseNote);
public String getInputSpec() {
return this.inputSpec;
}
generatorSettings.setReleaseNote(releaseNote);
return this;
public String getOutputDir() {
return outputDir;
}
public CodegenConfigurator setHttpUserAgent(String httpUserAgent) {
if (StringUtils.isNotEmpty(httpUserAgent)) {
addAdditionalProperty(CodegenConstants.HTTP_USER_AGENT, httpUserAgent);
public List<String> getFilters() {
return filters;
}
generatorSettings.setHttpUserAgent(httpUserAgent);
return this;
public List<String> getTemplateDirs() {
return templateDirs;
}
public List<String> getTemplatePaths() {
return templatePaths;
}
public List<String> getTemplateFilters() {
return templateFilters;
}
public CodegenConfigurator setAuth(String auth) {
// do not cache this in additional properties.
this.auth = auth;
return this;
public String getAuth() {
return auth;
}
public CodegenConfigurator setInputSpec(String inputSpec) {
this.inputSpec = inputSpec;
return this;
public Map<String, Object> getAdditionalProperties() {
return additionalProperties;
}
public CodegenConfigurator setOutputDir(String outputDir) {
......@@ -214,11 +216,26 @@ public final class CodegenConfigurator {
return this;
}
public CodegenConfigurator setEmbedTemplate(String embedTemplate) {
this.embedTemplate = embedTemplate;
public CodegenConfigurator setEmbedTemplates(List<EmbedTemplate> embedTemplates) {
this.embedTemplates = embedTemplates;
return this;
}
public List<EmbedTemplate> getEmbedTemplates() {
return embedTemplates;
}
public CodegenConfigurator setVolumes(List<Volume> volumes) {
this.volumes = volumes;
return this;
}
public List<Volume> getVolumes() {
return volumes;
}
public CodegenConfigurator setTemplatePaths(List<String> templatePaths) {
this.templatePaths = templatePaths;
return this;
......@@ -264,8 +281,8 @@ public final class CodegenConfigurator {
config.setTemplateDirs(this.templateDirs);
}
if(!StringUtils.isEmpty(embedTemplate)) {
config.setEmbedTemplate(this.embedTemplate);
if(!ObjectUtils.isEmpty(embedTemplates)) {
config.setEmbedTemplates(this.embedTemplates);
}
if(!ObjectUtils.isEmpty(templatePaths)) {
......
......@@ -35,35 +35,4 @@ public class Context<TSpecDocument> {
}
}
public static void main(String[] args) throws IOException {
Path path= Paths.get("/122/33/abc.java");
System.out.println(path.getParent().getFileName());
System.out.println(TemplateFileType.entity.toString());
System.out.println(TemplateFileType.entity.value());
HashMap<String, Object> scopes = new HashMap<String, Object>();
scopes.put("name", "Mustache");
GeneratorSettings generatorSettings=new GeneratorSettings().setGitHost("host");
generatorSettings.getAdditionalProperties().put("sub",new GeneratorSettings().setGitHost("son"));
scopes.put("feature",generatorSettings );
List<String> list=new ArrayList<>();
list.add("a");
list.add("b");
scopes.put("list",list);
Map map=new HashMap();
map.put("01","a01");
map.put("02","a02");
scopes.put("map1",map);
scopes.put("opt",new PojoOption().set("system_name","ab").set("persistent",false));
scopes.put("type",TemplateFileType.entity);
Writer writer = new OutputStreamWriter(System.out);
DefaultMustacheFactory mf = new DefaultMustacheFactory();
mf.setObjectHandler(new MapMethodReflectionHandler());
Mustache mustache = mf.compile(new StringReader("{{type}},{{type.value}},{{name}},{{opt.system}},{{opt.physicalField}}, {{map1.entrySet}}{{#map1.entrySet}}{{key}}{{/map1.entrySet}}!"), "example");
mustache.execute(writer, scopes);
writer.flush();
}
}
package cn.ibizlab.codegen.config;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.lang.reflect.Field;
import java.util.*;
public class DynamicSettings {
@JsonAnySetter
private Map<String, Object> dynamicProperties = new HashMap<>();
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class DynamicSettings extends LinkedHashMap<String,GeneratorSettings>{
@JsonUnwrapped
@JsonDeserialize(builder = GeneratorSettings.Builder.class)
private GeneratorSettings generatorSettings;
public GeneratorSettings getGeneratorSettings() {
excludeSettingsFromDynamicProperties();
GeneratorSettings.Builder builder = GeneratorSettings.newBuilder(generatorSettings);
// This allows us to put any unknown top-level properties into additionalProperties of the generator object.
for (Map.Entry<String, Object> entry : dynamicProperties.entrySet()) {
builder.withAdditionalProperty(entry.getKey(), entry.getValue());
}
return builder.build();
}
/**
* <p>Constructor for DynamicSettings.</p>
*/
@JsonCreator
public DynamicSettings() { }
/**
* Gets all "custom" properties included in the config object.
*
* @return All user-specified custom properties.
*/
public Map<String, Object> getDynamicProperties() {
return dynamicProperties;
}
private void excludeSettingsFromDynamicProperties(){
Set<String> fieldNames = new HashSet<>();
for (Field field : GeneratorSettings.class.getDeclaredFields()) {
fieldNames.add(field.getName());
}
dynamicProperties.keySet().removeAll(fieldNames);
}
}
package cn.ibizlab.codegen.config;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.ObjectUtils;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class EmbedTemplate {
private String name;
private String version;
@JsonCreator
public static EmbedTemplate from(String tag) {
if(ObjectUtils.isEmpty(tag))
return null;
EmbedTemplate template=new EmbedTemplate();
String tags[]=tag.split(":");
template.setName(tags[0]);
if(tags.length>1)
template.setVersion(tags[1]);
else
template.setVersion("1.0-SNAPSHOT");
return template;
}
}
package cn.ibizlab.codegen.config;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......@@ -14,221 +16,48 @@ import java.util.*;
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class GeneratorSettings implements Serializable {
private static final Logger LOGGER = LoggerFactory.getLogger(GeneratorSettings.class);
private static final String DEFAULT_GIT_HOST = "github.com";
private static final String DEFAULT_GIT_USER_ID = "GIT_USER_ID";
private static final String DEFAULT_GIT_REPO_ID = "GIT_REPO_ID";
private static final String DEFAULT_RELEASE_NOTE = "Minor update";
private String projectName;
private String packageName;
private Map<String, Object> additionalProperties = new LinkedHashMap<>();
private String gitHost;
private String gitUserId;
private String gitRepoId;
private String releaseNote;
private String httpUserAgent;
private Map<String, String> typeMappings;
public String getHost()
{
return gitHost+"abc";
}
private GeneratorSettings(Builder builder) {
projectName = builder.projectName;
packageName = builder.packageName;
typeMappings = Collections.unmodifiableMap(builder.typeMappings);
gitHost = builder.gitHost;
gitUserId = builder.gitUserId;
gitRepoId = builder.gitRepoId;
releaseNote = builder.releaseNote;
httpUserAgent = builder.httpUserAgent;
Map<String, Object> additional = new HashMap<>(builder.additionalProperties);
additionalProperties = Collections.unmodifiableMap(additional);
}
public static Builder newBuilder(GeneratorSettings copy) {
Builder builder = new Builder();
builder.projectName = copy.projectName;
builder.packageName = copy.packageName;
builder.typeMappings = Collections.unmodifiableMap(copy.typeMappings);
builder.gitHost = copy.gitHost;
builder.gitUserId = copy.gitUserId;
builder.gitRepoId = copy.gitRepoId;
builder.releaseNote = copy.releaseNote;
builder.httpUserAgent = copy.httpUserAgent;
Map<String, Object> additional = new HashMap<>(copy.additionalProperties);
builder.additionalProperties = Collections.unmodifiableMap(additional);
return builder;
}
public static final class Builder {
private String projectName;
private String packageName;
private String gitHost;
private String gitUserId;
private String gitRepoId;
private String releaseNote;
private String httpUserAgent;
private Map<String, String> typeMappings;
private Map<String, Object> additionalProperties;
/**
* Instantiates a new Builder.
*/
public Builder() {
typeMappings = new HashMap<>();
additionalProperties = new HashMap<>();
gitHost = DEFAULT_GIT_HOST;
gitUserId = DEFAULT_GIT_USER_ID;
gitRepoId = DEFAULT_GIT_REPO_ID;
releaseNote = DEFAULT_RELEASE_NOTE;
}
public Builder withProjectName(String projectName) {
this.projectName = projectName;
return this;
}
/**
* Sets the {@code packageName} and returns a reference to this Builder so that the methods can be chained together.
*
* @param packageName the {@code packageName} to set
* @return a reference to this Builder
*/
public Builder withPackageName(String packageName) {
this.packageName = packageName;
return this;
}
@JsonIgnore
private Map<String, Object> additionalProperties = new LinkedHashMap<>();
private String output ;
/**
* Sets the {@code typeMappings} and returns a reference to this Builder so that the methods can be chained together.
*
* @param typeMappings the {@code typeMappings} to set
* @return a reference to this Builder
*/
public Builder withTypeMappings(Map<String, String> typeMappings) {
this.typeMappings = typeMappings;
return this;
}
private String inputSpec;
public Builder withTypeMapping(String key, String value) {
if (this.typeMappings == null) {
this.typeMappings = new HashMap<>();
}
this.typeMappings.put(key, value);
return this;
}
/**
* Sets the {@code additionalProperties} and returns a reference to this Builder so that the methods can be chained together.
*
* @param additionalProperties the {@code additionalProperties} to set
* @return a reference to this Builder
*/
public Builder withAdditionalProperties(Map<String, Object> additionalProperties) {
this.additionalProperties = additionalProperties;
return this;
}
private List<String> inputSpecFilters;
/**
* Sets the {@code additionalProperties} and returns a reference to this Builder so that the methods can be chained together.
*
* @param key A key for some additional property
* @param value The value of some additional property
* @return a reference to this Builder
*/
public Builder withAdditionalProperty(String key, Object value) {
if (this.additionalProperties == null) {
this.additionalProperties = new HashMap<>();
}
this.additionalProperties.put(key, value);
return this;
}
private List<String> templateDirs;
private List<String> templatePaths;
/**
* Sets the {@code gitHost} and returns a reference to this Builder so that the methods can be chained together.
*
* @param gitHost the {@code gitHost} to set
* @return a reference to this Builder
*/
public Builder withGitHost(String gitHost) {
this.gitHost = gitHost;
return this;
}
private List<String> templateFilters;
/**
* Sets the {@code gitUserId} and returns a reference to this Builder so that the methods can be chained together.
*
* @param gitUserId the {@code gitUserId} to set
* @return a reference to this Builder
*/
public Builder withGitUserId(String gitUserId) {
this.gitUserId = gitUserId;
return this;
}
private List<Volume> volumes;
/**
* Sets the {@code gitRepoId} and returns a reference to this Builder so that the methods can be chained together.
*
* @param gitRepoId the {@code gitRepoId} to set
* @return a reference to this Builder
*/
public Builder withGitRepoId(String gitRepoId) {
this.gitRepoId = gitRepoId;
return this;
}
private String auth;
/**
* Sets the {@code releaseNote} and returns a reference to this Builder so that the methods can be chained together.
*
* @param releaseNote the {@code releaseNote} to set
* @return a reference to this Builder
*/
public Builder withReleaseNote(String releaseNote) {
this.releaseNote = releaseNote;
return this;
}
private List<EmbedTemplate> embedTemplates;
/**
* Sets the {@code httpUserAgent} and returns a reference to this Builder so that the methods can be chained together.
*
* @param httpUserAgent the {@code httpUserAgent} to set
* @return a reference to this Builder
*/
public Builder withHttpUserAgent(String httpUserAgent) {
this.httpUserAgent = httpUserAgent;
return this;
@JsonAnyGetter
public Map<String , Object> any() {
return additionalProperties;
}
/**
* Returns a {@code GeneratorSettings} built from the parameters previously set.
*
* @return a {@code GeneratorSettings} built with parameters of this {@code GeneratorSettings.Builder}
*/
public GeneratorSettings build() {
GeneratorSettings instance = new GeneratorSettings(this);
//noinspection PlaceholderCountMatchesArgumentCount
LOGGER.debug("GeneratorSettings#build: %s", instance.toString());
return instance;
}
@JsonAnySetter
public void set(String field, Object value) {
this.additionalProperties.put(field ,value);
}
}
package cn.ibizlab.codegen.config;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.ObjectUtils;
import java.nio.file.Path;
import java.nio.file.Paths;
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Volume {
private String source;
private String target;
public void setSource(String source) {
this.source = source.replace("\\", "/");
}
public void setTarget(String target) {
this.target = target.replace("\\", "/");
}
public Path getSourcePath() {
return Paths.get(source);
}
@JsonCreator
public static Volume from(String tag) {
if(ObjectUtils.isEmpty(tag))
return null;
Volume volume=new Volume();
String tags[]=tag.split(":");
volume.setSource(tags[0]);
if(tags.length>1)
volume.setTarget(tags[1]);
else
volume.setTarget(tags[0]);
return volume;
}
}
......@@ -9,6 +9,7 @@ import cn.ibizlab.codegen.utils.StringAdvUtils;
import net.ibizsys.model.IPSSystem;
import net.ibizsys.model.PSModelServiceImpl;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.nio.file.Files;
......@@ -86,6 +87,8 @@ public class ModelStorage {
opt.setProjectDesc(systemModel.getProjectDesc());
opt.setPackageName(systemModel.getPackageName());
opt.set("system", systemModel);
if(!ObjectUtils.isEmpty(config.getEmbedTemplates()))
opt.set("embedTemplates",config.getEmbedTemplates());
return opt;
}
......
*volumes
*target
.settings
*node_modules
*bin
*.project
*.classpath
*.factorypath
.history
.vscode
.idea
**.iml
*.jar
*.log
.DS_Store
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
......@@ -103,6 +103,17 @@
${project.artifactId}
</name>
</configuration>
{{#if embedTemplates}}
<dependencies>
{{#each embedTemplates}}
<dependency>
<groupId>cn.ibizlab</groupId>
<artifactId>{{name}}</artifactId>
<version>{{version}}</version>
</dependency>
{{/each}}
</dependencies>
{{/if}}
</plugin>
</plugins>
</build>
......
......@@ -2,6 +2,7 @@ package cn.ibizlab.codegen;
import cn.ibizlab.codegen.config.CodegenConfigurator;
import cn.ibizlab.codegen.config.CodegenConfiguratorUtils;
import cn.ibizlab.codegen.config.EmbedTemplate;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.AbstractMojo;
......@@ -41,8 +42,6 @@ public class GenerateMojo extends AbstractMojo {
@Parameter
private String[] templateDirs;
@Parameter
private String embedTemplate;
@Parameter
private String[] templatePaths;
......@@ -57,8 +56,6 @@ public class GenerateMojo extends AbstractMojo {
@Parameter
private String[] globalProperties ;
@Parameter
private String configFile;
@Parameter
private String name;
......@@ -74,20 +71,6 @@ public class GenerateMojo extends AbstractMojo {
@Parameter
private String gitHost;
@Parameter
private String gitUserId;
@Parameter
private String gitRepoId;
@Parameter
private String releaseNote;
@Parameter
private String httpUserAgent;
/**
......@@ -136,10 +119,6 @@ public class GenerateMojo extends AbstractMojo {
configurator.setTemplateDirs(Arrays.asList(templateDirs));
}
if(!StringUtils.isEmpty(embedTemplate)) {
configurator.setEmbedTemplate(this.embedTemplate);
}
if (!ObjectUtils.isEmpty(templatePaths)) {
configurator.setTemplatePaths(Arrays.asList(templatePaths));
}
......@@ -161,26 +140,6 @@ public class GenerateMojo extends AbstractMojo {
}
if (isNotEmpty(gitHost)) {
configurator.setGitHost(gitHost);
}
if (isNotEmpty(gitUserId)) {
configurator.setGitUserId(gitUserId);
}
if (isNotEmpty(gitRepoId)) {
configurator.setGitRepoId(gitRepoId);
}
if (isNotEmpty(releaseNote)) {
configurator.setReleaseNote(releaseNote);
}
if (isNotEmpty(httpUserAgent)) {
configurator.setHttpUserAgent(httpUserAgent);
}
if (!ObjectUtils.isEmpty(globalProperties)) {
......
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
**.ibizlab-generator-ignore
**.DS_Store
**/node_modules/**
**/target/**
**@macro/**
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册