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

minicode

上级 d8c90b4b
......@@ -14,7 +14,11 @@
<groupId>cn.ibizlab</groupId>
<artifactId>ibizlab-generator-core</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
......
......@@ -61,6 +61,10 @@ public class TemplateManager implements TemplatingExecutor, TemplateProcessor {
return readTemplate(getFullTemplateFile(name));
}
public Reader getFullTemplateReader(String name) {
return getTemplateReader(getFullTemplateFile(name));
}
/**
* Returns the path of a template, allowing access to the template where consuming literal contents aren't desirable or possible.
*
......@@ -102,9 +106,17 @@ public class TemplateManager implements TemplatingExecutor, TemplateProcessor {
if (reader == null) {
throw new RuntimeException("no file found");
}
try (Scanner s = new Scanner(reader).useDelimiter("\\A")) {
return s.hasNext() ? s.next() : "";
}
// try (Scanner s = new Scanner(reader).useDelimiter("\\A")) {
// return s.hasNext() ? s.next() : "";
// }
BufferedReader br = new BufferedReader(reader);
String line;
List<String> list=new ArrayList<>();
while ( (line = br.readLine()) != null )
{
list.add(line);
} return String.join(System.lineSeparator(),list);
} catch (Exception e) {
LOGGER.error("{}", e.getMessage(), e);
}
......@@ -153,14 +165,14 @@ public class TemplateManager implements TemplatingExecutor, TemplateProcessor {
File dir=target.getParentFile();
if(!dir.exists())
dir.mkdirs();
Path srcPath=this.getFullTemplatePath(template);
if(srcPath.toFile().exists()) {
Files.copy(srcPath, Paths.get(target.getPath()), StandardCopyOption.REPLACE_EXISTING);
return target;
}
else
templateContent=getFullTemplateContents(template);
if(StringUtils.isEmpty(templateContent))
{
templateContent=getFullTemplateContents(template);
Path srcPath=this.getFullTemplatePath(template);
if(srcPath.toFile().exists()) {
Files.copy(srcPath, Paths.get(target.getPath()), StandardCopyOption.REPLACE_EXISTING);
return target;
}
}
}
else
......@@ -170,6 +182,7 @@ public class TemplateManager implements TemplatingExecutor, TemplateProcessor {
return writeToFile(target.getPath(), templateContent);
}
@Override
public String targetPath(Map<String, Object> data, String template) throws IOException {
template=template.replace("{{packageName}}","{{packagePath}}");
......@@ -196,6 +209,7 @@ public class TemplateManager implements TemplatingExecutor, TemplateProcessor {
* @throws IOException If file cannot be written.
*/
public File writeToFile(String filename, String contents) throws IOException {
return writeToFile(filename, contents.getBytes(StandardCharsets.UTF_8));
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册