Search in sources :

Example 11 with BLangCompilerException

use of org.ballerinalang.compiler.BLangCompilerException in project ballerina by ballerina-lang.

the class HomeRepoUtils method createAndGetHomeReposPath.

/**
 * Create and get the home repository path.
 *
 * @return home repository path
 */
public static Path createAndGetHomeReposPath() {
    Path homeRepoPath;
    String homeRepoDir = System.getenv(ProjectDirConstants.HOME_REPO_ENV_KEY);
    if (homeRepoDir == null || homeRepoDir.isEmpty()) {
        String userHomeDir = System.getProperty(USER_HOME);
        if (userHomeDir == null || userHomeDir.isEmpty()) {
            throw new BLangCompilerException("Error creating home repository: unable to get user home directory");
        }
        homeRepoPath = Paths.get(userHomeDir, ProjectDirConstants.HOME_REPO_DEFAULT_DIRNAME);
    } else {
        // User has specified the home repo path with env variable.
        homeRepoPath = Paths.get(homeRepoDir);
    }
    homeRepoPath = homeRepoPath.toAbsolutePath();
    if (Files.exists(homeRepoPath) && !Files.isDirectory(homeRepoPath, LinkOption.NOFOLLOW_LINKS)) {
        throw new BLangCompilerException("Home repository is not a directory: " + homeRepoPath.toString());
    }
    return homeRepoPath;
}
Also used : Path(java.nio.file.Path) BLangCompilerException(org.ballerinalang.compiler.BLangCompilerException)

Aggregations

BLangCompilerException (org.ballerinalang.compiler.BLangCompilerException)11 IOException (java.io.IOException)7 Path (java.nio.file.Path)6 URI (java.net.URI)5 PackageID (org.ballerinalang.model.elements.PackageID)4 RemoteRepo (org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 Manifest (org.ballerinalang.toml.model.Manifest)2 Patten (org.wso2.ballerinalang.compiler.packaging.Patten)2 Name (org.wso2.ballerinalang.compiler.util.Name)2 FileInputStream (java.io.FileInputStream)1 URISyntaxException (java.net.URISyntaxException)1 FileSystem (java.nio.file.FileSystem)1 FileSystemAlreadyExistsException (java.nio.file.FileSystemAlreadyExistsException)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1