use of org.ballerinalang.BLangProgramArchiveBuilder in project carbon-apimgt by wso2.
the class GenerateArchives method execute.
/**
* Generate archives
*
* @param type type of the bal file
* @param packagePath package path to the bal
* @param targetName target file name
*/
public void execute(String type, String srcDir, String packagePath, String targetName) {
Path sourcePath = Paths.get(packagePath);
try {
Path realPath = Paths.get(srcDir + File.separator + packagePath).toRealPath(LinkOption.NOFOLLOW_LINKS);
if (!Files.isDirectory(realPath, LinkOption.NOFOLLOW_LINKS) && !realPath.toString().endsWith(BLangPrograms.BSOURCE_FILE_EXT)) {
log.error("invalid file or package '" + sourcePath + "'");
throw new IllegalArgumentException("invalid file or package '" + sourcePath + "'");
}
} catch (IOException e) {
log.error("error reading from file: " + sourcePath + " reason: " + e.getMessage(), e);
throw new RuntimeException("error reading from file: " + sourcePath + " reason: " + e.getMessage(), e);
}
Path programDirPath = Paths.get(srcDir);
BLangProgram bLangProgram = null;
if (MAIN_TYPE.equals(type)) {
bLangProgram = new BLangProgramLoader().loadMain(programDirPath, sourcePath);
} else if (SERVICE_TYPE.equals(type)) {
bLangProgram = new BLangProgramLoader().loadService(programDirPath, sourcePath);
} else {
log.error("source type '" + type + "' not supported");
throw new RuntimeException("source type '" + type + "' not supported");
}
new BLangProgramArchiveBuilder().build(bLangProgram, targetName.trim());
}
Aggregations