< prev index next >
functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/Source.java
Print this page
*** 26,44 ****
private String packageName;
private String simpleName;
private String fileContent;
private String jarName;
! private Map<String, String> replacementsInSrcCode;
/*
* JDK 9 Parameters
*/
private String moduleName;
private String moduleInfoContent;
! private Map<String, String> classNameToTemplateMap = new HashMap<>();
! private Map<String, Map<String, String>> classNameToReplacementsInSrcMap = new HashMap<>();
private boolean isModule;
private boolean mainModule;
/*
* Jar Source
--- 26,43 ----
private String packageName;
private String simpleName;
private String fileContent;
private String jarName;
! private Map<String, String> replacementsInSourceCode;
/*
* JDK 9 Parameters
*/
private String moduleName;
private String moduleInfoContent;
! private Map<String, String> templateToClassNameMap = new HashMap<>();
private boolean isModule;
private boolean mainModule;
/*
* Jar Source
*** 49,63 ****
this.fileContent = readFileAsString(templateFileName, replacements);
this.isModule = false;
}
/*
* Module Source
*/
public Source(String moduleName, String moduleInfoFileName,
! Map<String, String> classNameToTemplateMap, String fullName,
String jar, Map<String, String> replacementsInSourceCode)
throws IOException {
init(fullName, jar);
if (moduleName == null) {
throw new NullPointerException("Module Name cannot be null");
--- 48,75 ----
this.fileContent = readFileAsString(templateFileName, replacements);
this.isModule = false;
}
/*
+ * Jar Source
+ */
+
+ public Source(String fullName, String jar,
+ Map<String, String> templateToClassNameMap,
+ Map<String, Map<String, String>> templateToSourceCodeReplacementsMap)
+ throws IOException {
+ init(fullName, jar);
+ this.isModule = false;
+ this.templateToClassNameMap = templateToClassNameMap;
+ }
+
+ /*
* Module Source
*/
public Source(String moduleName, String moduleInfoFileName,
! Map<String, String> templateToClassNameMap, String fullName,
String jar, Map<String, String> replacementsInSourceCode)
throws IOException {
init(fullName, jar);
if (moduleName == null) {
throw new NullPointerException("Module Name cannot be null");
*** 66,119 ****
if (moduleInfoFileName == null) {
throw new NullPointerException(
"Module Info File Name cannot be null");
}
this.isModule = true;
! this.replacementsInSrcCode = replacementsInSourceCode;
this.moduleInfoContent = readFileAsString(moduleInfoFileName,
! this.replacementsInSrcCode);
! this.classNameToTemplateMap = classNameToTemplateMap;
}
/*
* Module Source
*/
public Source(String moduleName, String moduleInfoFileName,
! Map<String, String> classNameToTemplateMap,
! String mainClassfullyQualifiedName, String jar,
! Map<String, String> replacementsInSrcCode, boolean mainModule)
! throws IOException {
! this(moduleName, moduleInfoFileName, classNameToTemplateMap,
! mainClassfullyQualifiedName, jar, replacementsInSrcCode);
this.mainModule = mainModule;
}
- /*
- * Module Source
- */
- public Source(String moduleName, String moduleInfoFileName,
- Map<String, String> classNameToTemplateMap,
- String mainClassfullyQualifiedName,
- Map<String, Map<String, String>> classNameToReplacementsInSrcMap,
- String jar) throws IOException {
- init(mainClassfullyQualifiedName, jar);
- if (moduleName == null) {
- throw new NullPointerException("Module Name cannot be null");
- }
- this.moduleName = moduleName;
- if (moduleInfoFileName == null) {
- throw new NullPointerException(
- "Module Info File Name cannot be null");
- }
- this.classNameToReplacementsInSrcMap = classNameToReplacementsInSrcMap;
- this.classNameToTemplateMap = classNameToTemplateMap;
- this.moduleInfoContent = readFileAsString(moduleInfoFileName,
- this.classNameToReplacementsInSrcMap.get(Constants.MODULE_INFO_DOT_JAVA));
- this.isModule = true;
- }
-
private void init(String fullName, String jarName) {
int lastDot = fullName.lastIndexOf(".");
this.packageName = fullName.substring(0, lastDot);
this.simpleName = fullName.substring(lastDot + 1);
this.jarName = jarName;
--- 78,106 ----
if (moduleInfoFileName == null) {
throw new NullPointerException(
"Module Info File Name cannot be null");
}
this.isModule = true;
! this.replacementsInSourceCode = replacementsInSourceCode;
this.moduleInfoContent = readFileAsString(moduleInfoFileName,
! this.replacementsInSourceCode);
! this.templateToClassNameMap = templateToClassNameMap;
}
/*
* Module Source
*/
public Source(String moduleName, String moduleInfoFileName,
! Map<String, String> templateToClassNameMap, String fullName,
! String jar, Map<String, String> replacementsInSourceCode,
! boolean mainModule) throws IOException {
! this(moduleName, moduleInfoFileName, templateToClassNameMap, fullName,
! jar, replacementsInSourceCode);
this.mainModule = mainModule;
}
private void init(String fullName, String jarName) {
int lastDot = fullName.lastIndexOf(".");
this.packageName = fullName.substring(0, lastDot);
this.simpleName = fullName.substring(lastDot + 1);
this.jarName = jarName;
*** 172,235 ****
}
void generateSourceForModule(Path srcDir) throws IOException {
Path moduleDir = srcDir.resolve(moduleName);
Utils.createDir(moduleDir);
! Path moduleInfoPath = moduleDir.resolve(Constants.MODULE_INFO_DOT_JAVA);
write(moduleInfoPath, moduleInfoContent.getBytes());
! Set<Entry<String, String>> entrySet = this.classNameToTemplateMap
! .entrySet();
! Iterator<Entry<String, String>> classNameToTemplateItr = entrySet
! .iterator();
! while (classNameToTemplateItr.hasNext()) {
! Entry<String, String> next = classNameToTemplateItr.next();
! String className = next.getKey();
! String templateName = next.getValue();
! if (this.replacementsInSrcCode != null) {
! writeJavaSourceFilesToDir(moduleDir, className, templateName,
! this.replacementsInSrcCode);
! } else {
! writeJavaSourceFilesToDir(moduleDir, className, templateName,
! this.classNameToReplacementsInSrcMap.get(className
! .substring(className.lastIndexOf('.') + 1)));
! }
! }
}
private String readFileAsString(String templateFileName,
! Map<String, String> replacementsInSrcCode) throws IOException {
String content = Files
.lines(CONFIG_INSTANCE.getResourceFilePath(templateFileName))
.collect(joining(System.lineSeparator()));
! for (Map.Entry<String, String> entry : replacementsInSrcCode
! .entrySet()) {
content = content.replace(entry.getKey(), entry.getValue());
}
return content;
}
! private void writeJavaSourceFilesToDir(Path moduleDir,
! String fullyQualifiedJavaClassName, String templatename,
! Map<String, String> replacementsInSrcCode) throws IOException {
! int lastIndex = fullyQualifiedJavaClassName.lastIndexOf('.');
! String appNameDir = fullyQualifiedJavaClassName.substring(0, lastIndex);
String replaceAll = appNameDir.replaceAll(Pattern.quote("."),
Matcher.quoteReplacement(File.separator));
File file = new File(
moduleDir.toString() + File.separator + replaceAll);
file.mkdirs();
! String fileContent = readFileAsString(templatename,
! replacementsInSrcCode);
! String fileName = fullyQualifiedJavaClassName.substring(
! fullyQualifiedJavaClassName.lastIndexOf('.') + 1) + ".java";
write(Paths.get(moduleDir.toString() + File.separator + replaceAll)
.resolve(fileName), fileContent.getBytes());
}
! public boolean isMainModule() {
! return this.mainModule;
}
! public void setMainModule(boolean mainModule) {
! this.mainModule = mainModule;
}
}
--- 159,211 ----
}
void generateSourceForModule(Path srcDir) throws IOException {
Path moduleDir = srcDir.resolve(moduleName);
Utils.createDir(moduleDir);
! Path moduleInfoPath = moduleDir.resolve("module-info.java");
write(moduleInfoPath, moduleInfoContent.getBytes());
! writeJavaSourceFilesToDir(moduleDir);
}
private String readFileAsString(String templateFileName,
! Map<String, String> replacements) throws IOException {
String content = Files
.lines(CONFIG_INSTANCE.getResourceFilePath(templateFileName))
.collect(joining(System.lineSeparator()));
! for (Map.Entry<String, String> entry : replacements.entrySet()) {
content = content.replace(entry.getKey(), entry.getValue());
}
return content;
}
! private void writeJavaSourceFilesToDir(Path moduleDir) throws IOException {
! Set<Entry<String, String>> entrySet = this.templateToClassNameMap
! .entrySet();
! Iterator<Entry<String, String>> iterator = entrySet.iterator();
! while (iterator.hasNext()) {
! Map.Entry<java.lang.String, java.lang.String> entry = iterator
! .next();
! String fileNameInFullPath = entry.getValue();
! int lastIndexOf = fileNameInFullPath.lastIndexOf('.');
! String appNameDir = fileNameInFullPath.substring(0, lastIndexOf);
String replaceAll = appNameDir.replaceAll(Pattern.quote("."),
Matcher.quoteReplacement(File.separator));
File file = new File(
moduleDir.toString() + File.separator + replaceAll);
file.mkdirs();
! String fileContent = readFileAsString(entry.getKey(),
! replacementsInSourceCode);
! String fileName = fileNameInFullPath.substring(
! fileNameInFullPath.lastIndexOf('.') + 1) + ".java";
write(Paths.get(moduleDir.toString() + File.separator + replaceAll)
.resolve(fileName), fileContent.getBytes());
}
+ }
! public Map<String, String> getReplacementsInSourceCode() {
! return this.replacementsInSourceCode;
}
! public boolean isMainModule() {
! return this.mainModule;
}
}
< prev index next >