use of org.ballerinalang.compiler.BLangCompilerException in project ballerina by ballerina-lang.
the class ZipUtils method addFileToArchive.
/**
* Add file to archive.
*
* @param filesToBeArchived files to be archived
* @param zipFS Zip file system
* @param outFileName output archive name
*/
private static void addFileToArchive(Stream<Path> filesToBeArchived, FileSystem zipFS, String outFileName) {
filesToBeArchived.forEach((path) -> {
Path root = zipFS.getPath(SRC_DIR);
String fileName = path.getFileName().toString();
Path dest = zipFS.getPath(root.toString(), fileName);
if (path.getFileName().toString().equals("Ballerina.md")) {
dest = zipFS.getPath(File.separator, fileName);
}
try {
if (Files.exists(path)) {
copyFileToArchive(new FileInputStream(path.toString()), dest);
}
} catch (IOException e) {
throw new BLangCompilerException("error generating artifact " + outFileName);
}
});
}
use of org.ballerinalang.compiler.BLangCompilerException in project ballerina by ballerina-lang.
the class ZipUtils method createArchive.
/**
* Create archive when creating the balo.
*
* @param filesToBeArchived files to be archived
* @param outFileName output archive name
*/
private static void createArchive(Stream<Path> filesToBeArchived, String outFileName) {
Map<String, String> zipFSEnv = new HashMap<>();
zipFSEnv.put("create", "true");
URI filepath = Paths.get(outFileName).toUri();
URI zipFileURI;
try {
zipFileURI = new URI("jar:" + filepath.getScheme(), filepath.getUserInfo(), filepath.getHost(), filepath.getPort(), filepath.getPath() + "!/", filepath.getQuery(), filepath.getFragment());
} catch (URISyntaxException ignore) {
throw new BLangCompilerException("error creating artifact" + outFileName);
}
try (FileSystem zipFS = FileSystems.newFileSystem(zipFileURI, zipFSEnv)) {
addFileToArchive(filesToBeArchived, zipFS, outFileName);
} catch (IOException e) {
throw new BLangCompilerException("error creating artifact" + outFileName);
}
}
use of org.ballerinalang.compiler.BLangCompilerException in project ballerina by ballerina-lang.
the class ZipUtils method generateBalo.
/**
* Generates the balo/zip of the package.
*
* @param bLangPackage bLangPackage node
* @param projectPath project path
* @param paths paths of bal files inside the package
*/
static void generateBalo(BLangPackage bLangPackage, String projectPath, Stream<Path> paths) {
PackageID packageID = bLangPackage.packageID;
Path destPath = Paths.get(projectPath).resolve(".ballerina").resolve("repo").resolve(packageID.getOrgName().getValue()).resolve(packageID.getName().getValue()).resolve(packageID.getPackageVersion().getValue());
if (!Files.exists(destPath)) {
try {
Files.createDirectories(destPath);
} catch (IOException e) {
throw new BLangCompilerException("Error occurred when creating directories in " + "./ballerina/repo/ to save the generated balo");
}
}
String fileName = packageID.getName() + ".zip";
String baloDirPath = destPath.resolve(fileName).toString();
createArchive(paths, baloDirPath);
}
use of org.ballerinalang.compiler.BLangCompilerException in project ballerina by ballerina-lang.
the class ZipConverter method initFS.
private static void initFS(URI uri) {
Map<String, String> env = new HashMap<>();
env.put("create", "true");
try {
FileSystems.newFileSystem(uri, env);
} catch (FileSystemAlreadyExistsException ignore) {
} catch (IOException e) {
throw new BLangCompilerException("Error loading balo " + uri.getPath(), e);
}
}
use of org.ballerinalang.compiler.BLangCompilerException in project ballerina by ballerina-lang.
the class PushUtils method resolvePkgPathInRemoteRepo.
/**
* Get URI of the package from the remote repo.
*
* @param packageID packageID object
* @return full URI path of the package relative to the remote repo
*/
private static String resolvePkgPathInRemoteRepo(PackageID packageID) {
Repo<URI> remoteRepo = new RemoteRepo(URI.create("https://staging.central.ballerina.io:9090/"));
Patten patten = remoteRepo.calculate(packageID);
if (patten == Patten.NULL) {
throw new BLangCompilerException("Couldn't find package " + packageID.toString());
}
Converter<URI> converter = remoteRepo.getConverterInstance();
List<URI> uris = patten.convert(converter).collect(Collectors.toList());
if (uris.isEmpty()) {
throw new BLangCompilerException("Couldn't find package " + packageID.toString());
}
return uris.get(0).toString();
}
Aggregations