use of org.wso2.ballerinalang.compiler.SourceDirectory in project carbon-apimgt by wso2.
the class APIFileUtils method archiveDirectory.
/**
* Creates a zip archive from of a directory
*
* @param sourceDirectory directory to create zip archive from
* @param archiveLocation path to the archive location, excluding archive name
* @param archiveName name of the archive to create
* @throws APIMgtDAOException if an error occurs while creating the archive
*/
public static void archiveDirectory(String sourceDirectory, String archiveLocation, String archiveName) throws APIMgtDAOException {
File directoryToZip = new File(sourceDirectory);
List<File> fileList = new ArrayList<>();
getAllFiles(directoryToZip, fileList);
try {
writeArchiveFile(directoryToZip, fileList, archiveLocation, archiveName);
} catch (IOException e) {
String errorMsg = "Error while writing archive file " + directoryToZip.getPath() + " to archive " + archiveLocation;
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
if (log.isDebugEnabled()) {
log.debug("Archived API generated successfully" + archiveName);
}
}
use of org.wso2.ballerinalang.compiler.SourceDirectory in project carbon-apimgt by wso2.
the class FileBasedApplicationImportExportManager method createArchiveFromExportedAppArtifacts.
/**
* Creates an archive of the contained application details.
*
* @param sourceDirectory Directory which contains source file
* @param archiveLocation Directory to generate the zip archive
* @param archiveName Name of the zip archive
* @return path to the created archive file
* @throws APIMgtEntityImportExportException
*/
public String createArchiveFromExportedAppArtifacts(String sourceDirectory, String archiveLocation, String archiveName) throws APIMgtEntityImportExportException {
String archivedFilePath = null;
try {
APIFileUtils.archiveDirectory(sourceDirectory, archiveLocation, archiveName);
} catch (APIManagementException e) {
// cleanup the archive root directory
try {
FileUtils.deleteDirectory(new File(path));
} catch (IOException e1) {
log.warn("Unable to remove directory " + path);
}
String errorMsg = "Error while archiving directory " + sourceDirectory;
throw new APIMgtEntityImportExportException(errorMsg, e, ExceptionCodes.APPLICATION_EXPORT_ERROR);
}
archivedFilePath = archiveLocation + File.separator + archiveName + ".zip";
return archivedFilePath;
}
use of org.wso2.ballerinalang.compiler.SourceDirectory in project ballerina by ballerina-lang.
the class BCompileUtil method compile.
public static CompileResult compile(String sourceRoot, String packageName, CompilerPhase compilerPhase, SourceDirectory sourceDirectory) {
CompilerContext context = new CompilerContext();
CompilerOptions options = CompilerOptions.getInstance(context);
options.put(PROJECT_DIR, sourceRoot);
options.put(COMPILER_PHASE, compilerPhase.toString());
options.put(PRESERVE_WHITESPACE, "false");
context.put(SourceDirectory.class, sourceDirectory);
CompileResult comResult = new CompileResult();
// catch errors
DiagnosticListener listener = comResult::addDiagnostic;
context.put(DiagnosticListener.class, listener);
// compile
Compiler compiler = Compiler.getInstance(context);
BLangPackage packageNode = compiler.compile(packageName);
comResult.setAST(packageNode);
CompiledBinaryFile.ProgramFile programFile = compiler.getExecutableProgram(packageNode);
if (programFile != null) {
comResult.setProgFile(LauncherUtils.getExecutableProgram(programFile));
}
return comResult;
}
use of org.wso2.ballerinalang.compiler.SourceDirectory in project ballerina by ballerina-lang.
the class TestCmd method execute.
public void execute() {
if (helpFlag) {
printCommandUsageInfo(parentCmdParser, "test");
return;
}
if (sourceFileList == null || sourceFileList.isEmpty()) {
Path userDir = Paths.get(System.getProperty("user.dir"));
SourceDirectory srcDirectory = new FileSystemProjectDirectory(userDir);
sourceFileList = srcDirectory.getSourcePackageNames();
}
if (groupList != null && disableGroupList != null) {
throw LauncherUtils.createUsageException("Cannot specify both --groups and --disable-groups flags at the same time");
}
Path sourceRootPath = LauncherUtils.getSourceRootPath(sourceRoot);
Path ballerinaConfPath = sourceRootPath.resolve("ballerina.conf");
try {
ConfigRegistry.getInstance().initRegistry(configRuntimeParams, null, ballerinaConfPath);
((BLogManager) LogManager.getLogManager()).loadUserProvidedLogConfiguration();
} catch (IOException e) {
throw new RuntimeException("failed to read the specified configuration file: " + ballerinaConfPath.toString(), e);
}
Path[] paths = sourceFileList.stream().map(Paths::get).toArray(Path[]::new);
BTestRunner testRunner = new BTestRunner();
if (disableGroupList != null) {
testRunner.runTest(sourceRoot, paths, disableGroupList, false);
} else {
testRunner.runTest(sourceRoot, paths, groupList, true);
}
if (testRunner.getTesterinaReport().isFailure()) {
Runtime.getRuntime().exit(1);
}
Runtime.getRuntime().exit(0);
}
use of org.wso2.ballerinalang.compiler.SourceDirectory in project carbon-apimgt by wso2.
the class FileBasedServicesImportExportManager method createArchiveFromExportedServices.
/**
* Creates an archive of the contained service details.
*
* @param sourceDirectory Directory which contains source file
* @param archiveLocation Directory to generate the zip archive
* @param archiveName Name of the zip archive
* @return path to the created archive file
* @throws APIManagementException if an error occurs while creating an archive from app details
*/
public ExportArchive createArchiveFromExportedServices(String sourceDirectory, String archiveLocation, String archiveName) throws APIManagementException {
String archivedFilePath;
ExportArchive exportArchive = new ExportArchive();
try {
archiveDirectory(sourceDirectory, archiveLocation, archiveName);
} catch (IOException e) {
// cleanup the archive root directory
try {
FileUtils.deleteDirectory(new File(path));
} catch (IOException e1) {
log.warn("Unable to remove directory " + path);
}
String errorMsg = "Error while archiving directory " + sourceDirectory;
throw new APIManagementException(errorMsg);
}
archivedFilePath = archiveLocation + File.separator + archiveName + APIConstants.ZIP_FILE_EXTENSION;
exportArchive.setArchiveName(archivedFilePath);
return exportArchive;
}
Aggregations