Search in sources :

Example 11 with Repo

use of org.wso2.ballerinalang.compiler.packaging.repo.Repo in project carbon-business-process by wso2.

the class BPMNDeployer method createTenantRepo.

/**
 * @param configurationContext axis2 configurationContext
 * @return                     bpmn repo file
 * @throws BPSFault        repo creation failure will result in this xception
 */
private File createTenantRepo(ConfigurationContext configurationContext) throws BPSFault {
    String axisRepoPath = configurationContext.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(axisRepoPath)) {
        String msg = "URL Repositories are not supported: " + axisRepoPath;
        throw new BPSFault(msg);
    }
    File tenantsRepository = new File(axisRepoPath);
    File bpmnRepo = new File(tenantsRepository, BPMNConstants.BPMN_REPO_NAME);
    if (!bpmnRepo.exists()) {
        boolean status = bpmnRepo.mkdir();
        if (!status) {
            String msg = "Failed to create BPMN repository folder " + bpmnRepo.getAbsolutePath() + ".";
            throw new BPSFault(msg);
        }
    }
    return bpmnRepo;
}
Also used : BPSFault(org.wso2.carbon.bpmn.core.BPSFault) File(java.io.File)

Example 12 with Repo

use of org.wso2.ballerinalang.compiler.packaging.repo.Repo in project carbon-business-process by wso2.

the class HumanTaskUploader method uploadHumanTask.

public void uploadHumanTask(UploadedFileItem[] fileItems) throws AxisFault {
    // First lets filter for jar resources
    ConfigurationContext configurationContext = getConfigContext();
    String repo = configurationContext.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(repo)) {
        throw new AxisFault("URL Repositories are not supported: " + repo);
    }
    // Writting the artifacts to the proper location
    String humantaskDirectory = getHumanTaskLocation(repo);
    String humantaskTemp = CarbonUtils.getCarbonHome() + File.separator + HumanTaskConstants.HUMANTASK_PACKAGE_TEMP_DIRECTORY;
    File humantaskTempDir = new File(humantaskTemp);
    if (!humantaskTempDir.exists() && !humantaskTempDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + humantaskTempDir.getAbsolutePath());
    }
    File humantaskDir = new File(humantaskDirectory);
    if (!humantaskDir.exists() && !humantaskDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + humantaskDir.getAbsolutePath());
    }
    for (UploadedFileItem uploadedFile : fileItems) {
        String fileName = uploadedFile.getFileName();
        if (fileName == null || fileName.equals("")) {
            throw new AxisFault("Invalid file name. File name is not available");
        }
        if (HumanTaskConstants.HUMANTASK_PACKAGE_EXTENSION.equals(uploadedFile.getFileType())) {
            try {
                writeResource(uploadedFile.getDataHandler(), humantaskTemp, fileName, humantaskDir);
            } catch (IOException e) {
                throw new AxisFault("IOError: Writing resource failed.", e);
            }
        } else {
            throw new AxisFault("Invalid file type : " + uploadedFile.getFileType() + " ." + HumanTaskConstants.HUMANTASK_PACKAGE_EXTENSION + " file type is expected");
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) UploadedFileItem(org.wso2.carbon.core.common.UploadedFileItem)

Example 13 with Repo

use of org.wso2.ballerinalang.compiler.packaging.repo.Repo in project carbon-business-process by wso2.

the class BPMNUploader method uploadService.

public void uploadService(UploadedFileItem[] fileItems) throws AxisFault {
    // First lets filter for jar resources
    ConfigurationContext configurationContext = getConfigContext();
    String repo = configurationContext.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(repo)) {
        throw new AxisFault("URL Repositories are not supported: " + repo);
    }
    // Writing the artifacts to the proper location
    String bpmnDirectory = repo + File.separator + BPMNConstants.BPMN_REPO_NAME;
    String bpmnTemp = CarbonUtils.getCarbonHome() + BPMNConstants.BPMN_PACKAGE_TEMP_DIRECTORY;
    File bpmnTempDir = new File(bpmnTemp);
    if (!bpmnTempDir.exists() && !bpmnTempDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + bpmnTempDir.getAbsolutePath());
    }
    File bpmnDir = new File(bpmnDirectory);
    if (!bpmnDir.exists() && !bpmnDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + bpmnDir.getAbsolutePath());
    }
    for (UploadedFileItem uploadedFile : fileItems) {
        String fileName = uploadedFile.getFileName();
        if (fileName == null || fileName.equals("")) {
            throw new AxisFault("Invalid file name. File name is not available");
        }
        if (uploadedFile.getFileType().equals(BPMNConstants.BPMN_PACKAGE_EXTENSION)) {
            try {
                writeResource(uploadedFile.getDataHandler(), bpmnTemp, fileName, bpmnDir);
            } catch (IOException e) {
                throw new AxisFault("IOError: Writing resource failed.", e);
            }
        } else {
            throw new AxisFault("Invalid file type : " + uploadedFile.getFileType() + " ." + BPMNConstants.BPMN_PACKAGE_EXTENSION + " file type is expected");
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) UploadedFileItem(org.wso2.carbon.bpmn.core.mgt.model.UploadedFileItem) IOException(java.io.IOException) File(java.io.File)

Example 14 with Repo

use of org.wso2.ballerinalang.compiler.packaging.repo.Repo in project ballerina by ballerina-lang.

the class PackageLoader method genRepoHierarchy.

private RepoHierarchy genRepoHierarchy(Path sourceRoot) {
    Path balHomeDir = HomeRepoUtils.createAndGetHomeReposPath();
    Path projectHiddenDir = sourceRoot.resolve(".ballerina");
    RepoHierarchyBuilder.RepoNode[] systemArr = loadSystemRepos();
    Converter<Path> converter = sourceDirectory.getConverter();
    Repo remote = new RemoteRepo(URI.create("https://staging.central.ballerina.io:9090/"));
    Repo homeCacheRepo = new CacheRepo(balHomeDir);
    Repo homeRepo = new ZipRepo(balHomeDir);
    Repo projectCacheRepo = new CacheRepo(projectHiddenDir);
    Repo projectRepo = new ZipRepo(projectHiddenDir);
    RepoHierarchyBuilder.RepoNode homeCacheNode;
    if (offline) {
        homeCacheNode = node(homeCacheRepo, systemArr);
    } else {
        homeCacheNode = node(homeCacheRepo, node(remote, systemArr));
    }
    RepoHierarchyBuilder.RepoNode nonLocalRepos = node(projectRepo, node(projectCacheRepo, homeCacheNode), node(homeRepo, homeCacheNode));
    RepoHierarchyBuilder.RepoNode fullRepoGraph;
    if (converter != null) {
        Repo programingSource = new ProgramingSourceRepo(converter);
        Repo projectSource = new ProjectSourceRepo(converter);
        fullRepoGraph = node(programingSource, node(projectSource, nonLocalRepos));
    } else {
        fullRepoGraph = nonLocalRepos;
    }
    return RepoHierarchyBuilder.build(fullRepoGraph);
}
Also used : Path(java.nio.file.Path) ProgramingSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) Repo(org.wso2.ballerinalang.compiler.packaging.repo.Repo) ProgramingSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProgramingSourceRepo) ZipRepo(org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo) CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) RepoHierarchyBuilder(org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder) CacheRepo(org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo) RemoteRepo(org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo) ZipRepo(org.wso2.ballerinalang.compiler.packaging.repo.ZipRepo) ProjectSourceRepo(org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo)

Example 15 with Repo

use of org.wso2.ballerinalang.compiler.packaging.repo.Repo in project ballerina by ballerina-lang.

the class URIConverter method finalize.

public Stream<PackageSourceEntry> finalize(URI u, PackageID packageID) {
    String orgName = packageID.getOrgName().getValue();
    String pkgName = packageID.getName().getValue();
    Path destDirPath = HomeRepoUtils.createAndGetHomeReposPath().resolve(Paths.get("repo", orgName, pkgName));
    createDirectory(destDirPath);
    try {
        String fullPkgPath = orgName + "/" + pkgName;
        executor.execute(pullBalxLocation, u.toString(), destDirPath.toString(), fullPkgPath, File.separator);
        // TODO Simplify using ZipRepo
        Patten pattern = new Patten(Patten.WILDCARD_DIR, Patten.path(pkgName + ".zip"), Patten.path("src"), Patten.WILDCARD_SOURCE);
        return pattern.convertToSources(new ZipConverter(destDirPath), packageID);
    } catch (Exception ignore) {
    }
    return Stream.of();
}
Also used : Path(java.nio.file.Path) Patten(org.wso2.ballerinalang.compiler.packaging.Patten) URISyntaxException(java.net.URISyntaxException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException)

Aggregations

Patten (org.wso2.ballerinalang.compiler.packaging.Patten)7 File (java.io.File)5 PackageID (org.ballerinalang.model.elements.PackageID)5 Repo (org.wso2.ballerinalang.compiler.packaging.repo.Repo)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 AxisFault (org.apache.axis2.AxisFault)4 Test (org.testng.annotations.Test)4 URI (java.net.URI)3 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 BLangCompilerException (org.ballerinalang.compiler.BLangCompilerException)3 RemoteRepo (org.wso2.ballerinalang.compiler.packaging.repo.RemoteRepo)3 PackageSourceEntry (org.ballerinalang.repository.PackageSourceEntry)2 RepoHierarchyBuilder (org.wso2.ballerinalang.compiler.packaging.RepoHierarchyBuilder)2 Converter (org.wso2.ballerinalang.compiler.packaging.converters.Converter)2 CacheRepo (org.wso2.ballerinalang.compiler.packaging.repo.CacheRepo)2 HomeRepo (org.wso2.ballerinalang.compiler.packaging.repo.HomeRepo)2 ObjRepo (org.wso2.ballerinalang.compiler.packaging.repo.ObjRepo)2 ProjectSourceRepo (org.wso2.ballerinalang.compiler.packaging.repo.ProjectSourceRepo)2 Name (org.wso2.ballerinalang.compiler.util.Name)2