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

move

上级 a724efdb
......@@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ibizlab-generator-project</artifactId>
<groupId>com.ibizlab</groupId>
<groupId>cn.ibizlab</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
......@@ -30,7 +30,7 @@
<configuration>
<archive>
<manifest>
<mainClass>com.ibizlab.codegen.IbizLabGenerator</mainClass>
<mainClass>cn.ibizlab.codegen.IbizLabGenerator</mainClass>
</manifest>
</archive>
</configuration>
......
......@@ -15,18 +15,17 @@
* limitations under the License.
*/
package com.ibizlab.codegen;
package cn.ibizlab.codegen;
import cn.ibizlab.codegen.cmd.*;
import io.airlift.airline.Cli;
import io.airlift.airline.ParseArgumentsUnexpectedException;
import io.airlift.airline.ParseOptionMissingException;
import io.airlift.airline.ParseOptionMissingValueException;
import com.ibizlab.codegen.cmd.*;
import cn.ibizlab.codegen.cmd.*;
import java.util.Locale;
import static com.ibizlab.codegen.Constants.CLI_NAME;
/**
* User: lanwen Date: 24.03.15 Time: 17:56
* <p>
......@@ -37,7 +36,7 @@ public class IbizLabGenerator {
public static void main(String[] args) {
BuildInfo buildInfo = new BuildInfo();
Cli.CliBuilder<IbizLabGeneratorCommand> builder =
Cli.<IbizLabGeneratorCommand>builder(CLI_NAME)
Cli.<IbizLabGeneratorCommand>builder(Constants.CLI_NAME)
.withDescription(
String.format(
Locale.ROOT,
......@@ -68,7 +67,7 @@ public class IbizLabGenerator {
System.exit(1);
}
} catch (ParseArgumentsUnexpectedException e) {
System.err.printf(Locale.ROOT, "[error] %s%n%nSee '%s help' for usage.%n", e.getMessage(), CLI_NAME);
System.err.printf(Locale.ROOT, "[error] %s%n%nSee '%s help' for usage.%n", e.getMessage(), Constants.CLI_NAME);
System.exit(1);
} catch (ParseOptionMissingException | ParseOptionMissingValueException e) {
System.err.printf(Locale.ROOT, "[error] %s%n", e.getMessage());
......
package com.ibizlab.codegen.cmd;
package cn.ibizlab.codegen.cmd;
import cn.ibizlab.codegen.Constants;
import java.io.IOException;
import java.io.InputStream;
......@@ -9,11 +11,6 @@ import java.time.format.DateTimeParseException;
import java.util.Locale;
import java.util.Properties;
import static com.ibizlab.codegen.Constants.CLI_NAME;
import static com.ibizlab.codegen.Constants.GIT_REPO;
import static com.ibizlab.codegen.Constants.SITE;
/**
* Presents build-time information
*/
......@@ -87,7 +84,7 @@ public class BuildInfo {
* @return Human-readable version display information
*/
public String versionDisplayText() {
StringBuilder sb = new StringBuilder(CLI_NAME);
StringBuilder sb = new StringBuilder(Constants.CLI_NAME);
sb.append(" ").append(this.getVersion()).append(System.lineSeparator());
sb.append(" commit : ").append(this.getSha()).append(System.lineSeparator());
sb.append(" built : ");
......@@ -97,8 +94,8 @@ public class BuildInfo {
sb.append(UNKNOWN);
}
sb.append(System.lineSeparator());
sb.append(" source : ").append(GIT_REPO).append(System.lineSeparator());
sb.append(" docs : ").append(SITE).append(System.lineSeparator());
sb.append(" source : ").append(Constants.GIT_REPO).append(System.lineSeparator());
sb.append(" docs : ").append(Constants.SITE).append(System.lineSeparator());
return sb.toString();
}
}
......@@ -19,7 +19,7 @@
* https://github.com/airlift/airline/blob/fc7a55e34b6361cb97235de5a1b21cba9b508f4b/src/main/java/io/airlift/airline/SuggestCommand.java#L1
* Modifications have been made to fit the needs of OpenAPI Tools CLI.
*/
package com.ibizlab.codegen.cmd;
package cn.ibizlab.codegen.cmd;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
......
......@@ -15,26 +15,23 @@
* limitations under the License.
*/
package com.ibizlab.codegen.cmd;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.spi.FilterAttachable;
import com.ibizlab.codegen.*;
import com.ibizlab.codegen.config.CodegenConfigurator;
import com.ibizlab.codegen.config.CodegenConfiguratorUtils;
package cn.ibizlab.codegen.cmd;
import cn.ibizlab.codegen.CodegenConstants;
import cn.ibizlab.codegen.DefaultGenerator;
import cn.ibizlab.codegen.Generator;
import cn.ibizlab.codegen.GeneratorNotFoundException;
import cn.ibizlab.codegen.config.CodegenConfigurator;
import cn.ibizlab.codegen.config.CodegenConfiguratorUtils;
import cn.ibizlab.codegen.*;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import static com.ibizlab.codegen.config.CodegenConfiguratorUtils.applyAdditionalPropertiesKvpList;
import static com.ibizlab.codegen.config.CodegenConfiguratorUtils.applyGlobalPropertiesKvpList;
import static org.apache.commons.lang3.StringUtils.isNotEmpty;
@SuppressWarnings({"java:S106"})
......@@ -132,11 +129,12 @@ public class Generate extends IbizLabGeneratorCommand {
if (configFile != null && configFile.length() > 0) {
// attempt to load from configFile
configurator = CodegenConfigurator.fromFile(configFile);
} else if (StringUtils.isEmpty(spec)) {
// if user doesn't pass configFile and does not pass spec, we can fail immediately because one of these two is required to run.
System.err.println("[error] Required option '-i' is missing");
System.exit(1);
}
// else if (StringUtils.isEmpty(spec)) {
// // if user doesn't pass configFile and does not pass spec, we can fail immediately because one of these two is required to run.
// System.err.println("[error] Required option '-i' is missing");
// System.exit(1);
// }
// if a config file wasn't specified, or we were unable to read it
if (configurator == null) {
......@@ -202,10 +200,10 @@ public class Generate extends IbizLabGeneratorCommand {
if (globalProperties != null && !globalProperties.isEmpty()) {
applyGlobalPropertiesKvpList(globalProperties, configurator);
CodegenConfiguratorUtils.applyGlobalPropertiesKvpList(globalProperties, configurator);
}
applyAdditionalPropertiesKvpList(additionalProperties, configurator);
CodegenConfiguratorUtils.applyAdditionalPropertiesKvpList(additionalProperties, configurator);
try {
......
package com.ibizlab.codegen.cmd;
package cn.ibizlab.codegen.cmd;
import io.airlift.airline.Command;
import io.airlift.airline.Help;
......
package com.ibizlab.codegen.cmd;
package cn.ibizlab.codegen.cmd;
import io.airlift.airline.Help;
import io.airlift.airline.model.GlobalMetadata;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.cmd;
package cn.ibizlab.codegen.cmd;
import io.airlift.airline.Command;
import io.airlift.airline.Option;
......
......@@ -5,7 +5,7 @@
<parent>
<artifactId>ibizlab-generator-project</artifactId>
<groupId>com.ibizlab</groupId>
<groupId>cn.ibizlab</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
......
......@@ -15,24 +15,28 @@
* limitations under the License.
*/
package com.ibizlab.codegen;
package cn.ibizlab.codegen;
import cn.ibizlab.codegen.config.GlobalSettings;
import cn.ibizlab.codegen.templating.TemplateDefinition;
import cn.ibizlab.codegen.templating.TemplatingEngineAdapter;
import cn.ibizlab.codegen.utils.StringAdvUtils;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.Ticker;
import com.ibizlab.codegen.templating.TemplatingEngineAdapter;
import com.ibizlab.codegen.config.GlobalSettings;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StringUtils;
import java.io.File;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.TimeUnit;
import static com.ibizlab.codegen.utils.StringAdvUtils.*;
import java.util.regex.Pattern;
@Getter
@Setter
......@@ -68,6 +72,30 @@ public class CodegenConfig {
return additionalProperties.getOrDefault(CodegenConstants.IGNORE_FILE_OVERRIDE,"").toString();
}
private List<TemplateDefinition> templateDefinitions;
public List<TemplateDefinition> getTemplateDefinitions()
{
if(templateDefinitions==null&& (!StringUtils.isEmpty(templateDir)))
{
templateDefinitions=new ArrayList<>();
scanTemplate(new File(templateDir),templateDefinitions);
}
return templateDefinitions;
}
private void scanTemplate(File file,List<TemplateDefinition> templateDefinitions)
{
if(file.isDirectory())
{
for(File sub:file.listFiles())
scanTemplate(sub,templateDefinitions);
}
else {
templateDefinitions.add(new TemplateDefinition(Paths.get("/",file.getPath().replace(this.getTemplateDir(),"")).toString()));
}
}
@SuppressWarnings("static-method")
public String sanitizeName(String name) {
return sanitizeName(name, "\\W");
......@@ -78,8 +106,8 @@ public class CodegenConfig {
static {
int cacheSize = Integer.parseInt(GlobalSettings.getProperty(NAME_CACHE_SIZE_PROPERTY, "500"));
int cacheExpiry = Integer.parseInt(GlobalSettings.getProperty(NAME_CACHE_EXPIRY_PROPERTY, "10"));
int cacheSize = Integer.parseInt(GlobalSettings.getProperty(StringAdvUtils.NAME_CACHE_SIZE_PROPERTY, "500"));
int cacheExpiry = Integer.parseInt(GlobalSettings.getProperty(StringAdvUtils.NAME_CACHE_EXPIRY_PROPERTY, "10"));
sanitizedNameCache = Caffeine.newBuilder()
.maximumSize(cacheSize)
.expireAfterAccess(cacheExpiry, TimeUnit.SECONDS)
......@@ -177,7 +205,7 @@ public class CodegenConfig {
* @return Sanitized tag
*/
public String sanitizeTag(String tag) {
tag = camelize(sanitizeName(tag));
tag = StringAdvUtils.camelize(sanitizeName(tag));
// tag starts with numbers
if (tag.matches("^\\d.*")) {
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen;
package cn.ibizlab.codegen;
/**
* A class for storing constants that are used throughout the project.
......
......@@ -15,18 +15,24 @@
* limitations under the License.
*/
package com.ibizlab.codegen;
import com.ibizlab.codegen.templating.TemplatePathLocator;
import com.ibizlab.codegen.templating.TemplateProcessor;
import com.ibizlab.codegen.templating.TemplatingEngineAdapter;
import com.ibizlab.codegen.ignore.CodegenIgnoreProcessor;
import com.ibizlab.codegen.lite.DynamicModelStorage;
import com.ibizlab.codegen.templating.*;
package cn.ibizlab.codegen;
import cn.ibizlab.codegen.ignore.CodegenIgnoreProcessor;
import cn.ibizlab.codegen.lite.DynamicModelStorage;
import cn.ibizlab.codegen.model.CliOption;
import cn.ibizlab.codegen.model.ModelStorage;
import cn.ibizlab.codegen.templating.*;
import cn.ibizlab.codegen.templating.TemplatePathLocator;
import cn.ibizlab.codegen.templating.TemplateProcessor;
import cn.ibizlab.codegen.templating.TemplatingEngineAdapter;
import cn.ibizlab.codegen.templating.*;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
@Slf4j
......@@ -44,6 +50,9 @@ public class DefaultGenerator implements Generator {
private CodegenIgnoreProcessor ignoreProcessor;
protected ModelStorage modelStorage;
protected DynamicModelStorage dynamicModelStorage;
@SuppressWarnings("deprecation")
......@@ -51,7 +60,8 @@ public class DefaultGenerator implements Generator {
public Generator opts(CodegenConfig opts) {
this.config = opts;
DynamicModelStorage.getInstance().modelPath(this.config.getInputSpec());
dynamicModelStorage=DynamicModelStorage.getInstance().modelPath(this.config.getInputSpec());
modelStorage=ModelStorage.getInstance().config(config);
TemplateManagerOptions templateManagerOptions = new TemplateManagerOptions(this.config.isEnableMinimalUpdate(),this.config.isSkipOverwrite());
......@@ -92,6 +102,19 @@ public class DefaultGenerator implements Generator {
@Override
public List<File> generate() {
for(TemplateDefinition templateDefinition:this.config.getTemplateDefinitions())
{
for(CliOption opt:templateDefinition.getTemplateDatas())
{
try {
processTemplateToFile(opt,templateDefinition.getTemplateFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
......@@ -124,35 +147,22 @@ public class DefaultGenerator implements Generator {
return defaultValue;
}
private DefaultMustacheFactory mf = new DefaultMustacheFactory();
protected File processTemplateToFile(Map<String, Object> templateData, String templateName) throws IOException {
// private void generateModel(List<File> files, Map<String, Object> models, String modelName) throws IOException {
// for (String templateName : config.modelTemplateFiles().keySet()) {
// String filename = config.modelFilename(templateName, modelName);
// File written = processTemplateToFile(models, templateName, filename, generateModels, CodegenConstants.MODELS);
// if (written != null) {
// files.add(written);
// if (config.isEnablePostProcessFile() && !dryRun) {
// config.postProcessFile(written, "model");
// }
// }
// }
// }
protected File processTemplateToFile(Map<String, Object> templateData, String templateName, String outputFilename, boolean shouldGenerate, String skippedByOption) throws IOException {
String adjustedOutputFilename = outputFilename.replaceAll("//", "/").replace('/', File.separatorChar);
File target = new File(adjustedOutputFilename);
StringWriter writer = new StringWriter();
Mustache mustache = mf.compile(new StringReader(templateName), "outputFilename");
mustache.execute(writer, templateData);
String outputFilename=writer.toString();
File target = Paths.get(this.config.getOutputDir(),outputFilename).toFile();
if (ignoreProcessor.allowsFile(target)) {
if (shouldGenerate) {
Path outDir = java.nio.file.Paths.get(this.config.getOutputDir()).toAbsolutePath();
Path absoluteTarget = target.toPath().toAbsolutePath();
if (!absoluteTarget.startsWith(outDir)) {
throw new RuntimeException(String.format(Locale.ROOT, "Target files must be generated within the output directory; absoluteTarget=%s outDir=%s", absoluteTarget, outDir));
}
return this.templateProcessor.write(templateData,templateName, target);
} else {
this.templateProcessor.skip(target.toPath(), String.format(Locale.ROOT, "Skipped by %s options supplied by user.", skippedByOption));
return null;
}
} else {
this.templateProcessor.ignore(target.toPath(), "Ignored by rule in ignore file.");
return null;
......
package com.ibizlab.codegen;
package cn.ibizlab.codegen;
import java.io.File;
import java.io.IOException;
import java.util.List;
public interface Generator {
......
......@@ -15,14 +15,17 @@
* limitations under the License.
*/
package com.ibizlab.codegen.config;
package cn.ibizlab.codegen.config;
import cn.ibizlab.codegen.CodegenConfig;
import cn.ibizlab.codegen.CodegenConstants;
import cn.ibizlab.codegen.templating.MustacheEngineAdapter;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.ibizlab.codegen.*;
import com.ibizlab.codegen.templating.TemplatingEngineAdapter;
import com.ibizlab.codegen.templating.TemplatingEngineLoader;
import cn.ibizlab.codegen.*;
import cn.ibizlab.codegen.templating.TemplatingEngineAdapter;
import cn.ibizlab.codegen.templating.TemplatingEngineLoader;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.core.util.Yaml;
import org.apache.commons.io.FilenameUtils;
......@@ -239,15 +242,21 @@ public final class CodegenConfigurator {
TemplatingEngineAdapter templatingEngine = TemplatingEngineLoader.byIdentifier(this.templatingEngineName);
TemplatingEngineAdapter templatingEngine = new MustacheEngineAdapter();
config.setTemplatingEngine(templatingEngine);
if(this.additionalProperties!=null)
config.getAdditionalProperties().putAll(this.additionalProperties);
if(this.globalProperties!=null)
config.getAdditionalProperties().putAll(this.globalProperties);
if(!StringUtils.isEmpty(this.inputSpec))
config.setInputSpec(this.inputSpec);
if(!StringUtils.isEmpty(this.outputDir))
config.setOutputDir(this.outputDir);
if(!StringUtils.isEmpty(this.templateDir))
config.setTemplateDir(this.templateDir);
if(!StringUtils.isEmpty(this.auth))
config.setAuth(this.auth);
return config;
......
......@@ -15,9 +15,9 @@
* limitations under the License.
*/
package com.ibizlab.codegen.config;
package cn.ibizlab.codegen.config;
import com.ibizlab.codegen.utils.OptionUtils;
import cn.ibizlab.codegen.utils.OptionUtils;
import org.apache.commons.lang3.tuple.Pair;
import java.util.*;
......
......@@ -14,13 +14,13 @@
* limitations under the License.
*/
package com.ibizlab.codegen.config;
package cn.ibizlab.codegen.config;
import cn.ibizlab.codegen.model.PojoOption;
import cn.ibizlab.codegen.templating.TemplateFileType;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.reflect.ReflectionObjectHandler;
import com.ibizlab.codegen.templating.TemplateFileType;
import com.ibizlab.codegen.model.PojoOption;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......
package com.ibizlab.codegen.config;
package cn.ibizlab.codegen.config;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonCreator;
......
package com.ibizlab.codegen.config;
package cn.ibizlab.codegen.config;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......
......@@ -15,23 +15,20 @@
* limitations under the License.
*/
package com.ibizlab.codegen.ignore;
package cn.ibizlab.codegen.ignore;
import com.ibizlab.codegen.ignore.rules.DirectoryRule;
import com.ibizlab.codegen.ignore.rules.Rule;
import cn.ibizlab.codegen.ignore.rules.DirectoryRule;
import cn.ibizlab.codegen.ignore.rules.Rule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
/**
* Presents a processing utility for parsing and evaluating files containing common ignore patterns. (.openapi-generator-ignore)
*/
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.ignore.rules;
package cn.ibizlab.codegen.ignore.rules;
import java.nio.file.FileSystems;
import java.nio.file.PathMatcher;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.ignore.rules;
package cn.ibizlab.codegen.ignore.rules;
import java.util.List;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.ignore.rules;
package cn.ibizlab.codegen.ignore.rules;
import java.nio.file.FileSystems;
import java.nio.file.PathMatcher;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.ignore.rules;
package cn.ibizlab.codegen.ignore.rules;
import java.util.ArrayList;
import java.util.List;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.ignore.rules;
package cn.ibizlab.codegen.ignore.rules;
import java.util.List;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.ignore.rules;
package cn.ibizlab.codegen.ignore.rules;
public class ParserException extends Exception {
/**
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.ignore.rules;
package cn.ibizlab.codegen.ignore.rules;
class Part {
private final IgnoreLineParser.Token token;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.ignore.rules;
package cn.ibizlab.codegen.ignore.rules;
import java.util.List;
import java.util.regex.Pattern;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.ignore.rules;
package cn.ibizlab.codegen.ignore.rules;
import java.util.List;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
......@@ -8,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.ibizlab.codegen.utils.DataObject;
import cn.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.JSON;
import com.ibizlab.codegen.utils.Inflector;
import cn.ibizlab.codegen.utils.Inflector;
import net.ibizsys.model.IPSSystem;
import net.ibizsys.model.PSModelServiceImpl;
import net.ibizsys.model.database.IPSDEFDTColumn;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.ibizlab.codegen.utils.DataObject;
import cn.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.ibizlab.codegen.utils.DataObject;
import cn.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
......@@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.ibizlab.codegen.utils.DataObject;
import cn.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
......@@ -6,7 +6,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.ibizlab.codegen.utils.DataObject;
import cn.ibizlab.codegen.utils.DataObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
......
package com.ibizlab.codegen.lite;
package cn.ibizlab.codegen.lite;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ibizlab.codegen.utils.DataObject;
import cn.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......
package com.ibizlab.codegen.model;
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.ibizlab.codegen.CodegenConstants;
import org.springframework.util.StringUtils;
import cn.ibizlab.codegen.CodegenConstants;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
......
package com.ibizlab.codegen.model;
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
......
package com.ibizlab.codegen.model;
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.utils.DataObject;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ibizlab.codegen.utils.DataObject;
import org.springframework.util.ObjectUtils;
import java.math.BigDecimal;
......
package com.ibizlab.codegen.model;
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.ibizlab.codegen.CodegenConfig;
import com.ibizlab.codegen.CodegenConstants;
import com.ibizlab.codegen.lite.DynamicModelStorage;
import com.ibizlab.codegen.lite.EntityModel;
import cn.ibizlab.codegen.lite.DynamicModelStorage;
import cn.ibizlab.codegen.lite.EntityModel;
import cn.ibizlab.codegen.CodegenConfig;
import cn.ibizlab.codegen.CodegenConstants;
import com.ibizlab.codegen.templating.TemplateFileType;
import cn.ibizlab.codegen.templating.TemplateFileType;
import net.ibizsys.model.IPSSystem;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
......@@ -79,11 +71,11 @@ public class ModelStorage {
return schema;
}
private Map<TemplateFileType,List<CliOption>> store=new HashMap<>();
private Map<TemplateFileType,List<CliOption>> templateData=new HashMap<>();
public List<CliOption> getStore(TemplateFileType type)
public List<CliOption> getTemplateData(TemplateFileType type)
{
if(!store.containsKey(type))
if(!templateData.containsKey(type))
{
List<CliOption> rt=new ArrayList();
if(type.equals(TemplateFileType.api))
......@@ -127,9 +119,14 @@ public class ModelStorage {
rt.add(opt);
});
}
store.put(type,rt);
else if(type.equals(TemplateFileType.supportingFiles))
{
CliOption opt=newCliOption();
rt.add(opt);
}
templateData.put(type,rt);
}
return store.get(type);
return templateData.get(type);
}
......
package com.ibizlab.codegen.model;
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.utils.DataObject;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.ibizlab.codegen.utils.DataObject;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
......
package com.ibizlab.codegen.model;
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
......
package com.ibizlab.codegen.model;
package cn.ibizlab.codegen.model;
import com.alibaba.fastjson.JSON;
......@@ -7,14 +7,13 @@ import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.ibizlab.codegen.utils.Inflector;
import cn.ibizlab.codegen.utils.Inflector;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.ibizsys.model.dataentity.IPSDataEntity;
import net.ibizsys.model.dataentity.defield.IPSDEField;
import net.ibizsys.model.dataentity.defield.PSDEFieldImpl;
import org.springframework.util.StringUtils;
import java.io.File;
......
package com.ibizlab.codegen.model;
package cn.ibizlab.codegen.model;
import cn.ibizlab.codegen.lite.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ibizlab.codegen.lite.*;
import cn.ibizlab.codegen.lite.*;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
......
package com.ibizlab.codegen.templating;
package cn.ibizlab.codegen.templating;
import com.ibizlab.codegen.CodegenConfig;
import cn.ibizlab.codegen.CodegenConfig;
import java.io.File;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating;
package cn.ibizlab.codegen.templating;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
......
package com.ibizlab.codegen.templating;
package cn.ibizlab.codegen.templating;
import cn.ibizlab.codegen.model.CliOption;
import cn.ibizlab.codegen.model.ModelStorage;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
@Getter
@Setter
......@@ -12,16 +19,34 @@ import lombok.experimental.Accessors;
@Accessors(chain = true)
public class TemplateDefinition {
private String templateFile;
private String destinationFilename;
protected TemplateFileType templateType;
protected List<CliOption> templateDatas;
public TemplateDefinition(String templateFile) {
if (templateFile == null) throw new IllegalArgumentException("templateFile may not be null.");
if (destinationFilename == null) throw new IllegalArgumentException("destinationFilename may not be null.");
this.templateFile = templateFile;
this.destinationFilename = destinationFilename;
this.templateType = TemplateFileType.supportingFiles;
this.templateType = getType(Paths.get(this.templateFile));
this.templateDatas= ModelStorage.getInstance().getTemplateData(this.templateType);
}
private TemplateFileType getType(Path path)
{
if(path==null)
return TemplateFileType.supportingFiles;
if(StringUtils.isEmpty(path.getFileName()))
return TemplateFileType.supportingFiles;
String fileName=path.getFileName().toString();
for(TemplateFileType type:TemplateFileType.values())
{
if(fileName.indexOf("{{"+type.name()+"}}")>=0
||fileName.indexOf("{{"+type.value()+"}}")>=0)
return type;
}
return getType(path.getParent());
}
}
package com.ibizlab.codegen.templating;
package cn.ibizlab.codegen.templating;
/**
* Provides means for searching for "actual" template location based on relative template file.
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating;
package cn.ibizlab.codegen.templating;
import java.io.FileInputStream;
import java.io.IOException;
......
......@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating;
package cn.ibizlab.codegen.templating;
import java.util.Locale;
......
......@@ -15,16 +15,17 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.ibizlab.codegen.CodegenConfig;
import cn.ibizlab.codegen.utils.StringAdvUtils;
import cn.ibizlab.codegen.CodegenConfig;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import java.io.IOException;
import java.io.Writer;
import static com.ibizlab.codegen.utils.StringAdvUtils.camelize;
import static cn.ibizlab.codegen.utils.StringAdvUtils.camelize;
/**
......@@ -63,7 +64,7 @@ public class CamelCaseLambda implements Mustache.Lambda {
@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
String text = camelize(fragment.execute(), lowercaseFirstLetter);
String text = StringAdvUtils.camelize(fragment.execute(), lowercaseFirstLetter);
if (generator != null) {
text = generator.sanitizeName(text);
......
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.google.common.base.CaseFormat;
import com.ibizlab.codegen.CodegenConfig;
import cn.ibizlab.codegen.CodegenConfig;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
......
......@@ -15,9 +15,9 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.ibizlab.codegen.CodegenConfig;
import cn.ibizlab.codegen.CodegenConfig;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
......
......@@ -15,9 +15,9 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.ibizlab.codegen.CodegenConfig;
import cn.ibizlab.codegen.CodegenConfig;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
......
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template.Fragment;
......
......@@ -14,16 +14,15 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import cn.ibizlab.codegen.utils.StringAdvUtils;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import java.io.IOException;
import java.io.Writer;
import static com.ibizlab.codegen.utils.StringAdvUtils.underscore;
/**
* Converts text in a fragment to snake case.
......@@ -41,6 +40,6 @@ import static com.ibizlab.codegen.utils.StringAdvUtils.underscore;
public class SnakecaseLambda implements Mustache.Lambda {
@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
writer.write(underscore(fragment.execute()));
writer.write(StringAdvUtils.underscore(fragment.execute()));
}
}
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template.Fragment;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template.Fragment;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.templating.mustache;
package cn.ibizlab.codegen.templating.mustache;
import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.utils;
package cn.ibizlab.codegen.utils;
public class ImplementationVersion {
public static String read() {
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.utils;
package cn.ibizlab.codegen.utils;
import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
......
......@@ -15,7 +15,7 @@
* limitations under the License.
*/
package com.ibizlab.codegen.utils;
package cn.ibizlab.codegen.utils;
import org.apache.commons.lang3.tuple.Pair;
......
package com.ibizlab.codegen.utils;
package cn.ibizlab.codegen.utils;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.Ticker;
import com.ibizlab.codegen.config.GlobalSettings;
import cn.ibizlab.codegen.config.GlobalSettings;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
......@@ -17,11 +17,11 @@ public class StringAdvUtils {
/**
* Set the cache size (entry count) of the sanitizedNameCache, camelizedWordsCache and underscoreWordsCache.
*/
public static final String NAME_CACHE_SIZE_PROPERTY = "com.ibizlab.codegen.utils.namecache.cachesize";
public static final String NAME_CACHE_SIZE_PROPERTY = "cn.ibizlab.codegen.utils.namecache.cachesize";
/**
* Set the cache expiry (in seconds) of the sanitizedNameCache, camelizedWordsCache and underscoreWordsCache.
*/
public static final String NAME_CACHE_EXPIRY_PROPERTY = "com.ibizlab.codegen.utils.namecache.expireafter.seconds";
public static final String NAME_CACHE_EXPIRY_PROPERTY = "cn.ibizlab.codegen.utils.namecache.expireafter.seconds";
// A cache of camelized words. The camelize() method is invoked many times with the same
// arguments, this cache is used to optimized performance.
......
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
* Copyright 2018 SmartBear Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ibizlab.codegen;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.parser.util.SchemaTypeUtil;
import java.util.LinkedHashMap;
import java.util.Map;
public class CliOption {
private final String opt;
private String description;
private String type;
private String defaultValue;
private String optValue;
private Map<String, String> enumValues;
public CliOption(String opt, String description) {
this(opt, description, SchemaTypeUtil.STRING_TYPE);
}
public CliOption(String opt, String description, String type) {
this.opt = opt;
this.description = description;
this.type = type;
}
public String getOpt() {
return opt;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getDefault() {
return defaultValue;
}
public void setDefault(String defaultValue) {
this.defaultValue = defaultValue;
}
public CliOption defaultValue(String defaultValue) {
this.defaultValue = defaultValue;
return this;
}
public String getOptValue() {
return this.optValue;
}
public void setOptValue(String optValue) {
if (this.enumValues!=null && this.enumValues.containsKey(optValue)) {
this.optValue = optValue;
} else {
this.optValue = null;
}
}
public CliOption addEnum(String value, String description) {
if (this.enumValues == null) {
this.enumValues = new LinkedHashMap<String, String>();
}
if (!enumValues.containsKey(value)) {
enumValues.put(value, description);
}
return this;
}
public Map<String, String> getEnum() {
return enumValues;
}
public void setEnum(Map<String, String> enumValues) {
this.enumValues = enumValues;
}
/**
* Create new boolean command line option with a default of false
*
* @param opt Option name
* @param description Option description
* @return the CliOption created
*/
public static CliOption newBoolean(String opt, String description) {
return newBoolean(opt, description, false);
}
/**
* Create new boolean command line option with the provided value as default
*
* @param opt Option name
* @param description Option description
* @param defaultValue the default value to use if option not specified
* @return the CliOption created
*/
public static CliOption newBoolean(String opt, String description, boolean defaultValue) {
return new CliOption(opt, description, SchemaTypeUtil.BOOLEAN_TYPE).defaultValue(String.valueOf(defaultValue));
}
public static CliOption newString(String opt, String description) {
return new CliOption(opt, description, SchemaTypeUtil.STRING_TYPE);
}
@JsonIgnore
public String getOptionHelp() {
StringBuilder sb = new StringBuilder(description);
if(defaultValue != null) {
sb.append(" (Default: ").append(defaultValue).append(")");
}
if (enumValues != null) {
for (Map.Entry<String, String> entry : enumValues.entrySet()) {
sb.append("\n ").append(entry.getKey()).append(" - ").append(entry.getValue());
}
}
return sb.toString();
}
}
......@@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ibizlab</groupId>
<groupId>cn.ibizlab</groupId>
<artifactId>ibizlab-generator-project</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册