use of org.wso2.ballerinalang.compiler.packaging.repo.Repo in project ballerina by ballerina-lang.
the class JarIntegrationTest method balInsideJar.
@Test
public void balInsideJar() throws IOException {
Patten balPatten = new Patten(path("very"), Patten.WILDCARD_SOURCE);
JarRepo repo = new JarRepo(tempJar.toUri());
Converter<Path> subject = repo.getConverterInstance();
List<PackageSourceEntry> sources = balPatten.convertToSources(subject, null).collect(Collectors.toList());
Assert.assertEquals(sources.size(), 1);
Assert.assertEquals(sources.get(0).getCode(), BAL_CONTENT);
}
use of org.wso2.ballerinalang.compiler.packaging.repo.Repo in project core-util by WSO2Telco.
the class OAuthApplicationDataStubFactory method generateStub.
/**
* This is used to create a stub which will be triggered through object pool factory, which will create an
* instance of it.
*
* @return OAuth2TokenValidationServiceStub stub that is used to call an external service.
* @throws PCRException will be thrown when initialization failed.
*/
private OAuthAdminServiceStub generateStub() throws PCRException {
OAuthAdminServiceStub stub;
try {
URL hostURL = new URL(config.getHostUrl());
// ConfigurationContext myConfigContext =
// ConfigurationContextFactory.createConfigurationContextFromFileSystem(
// "repo", CarbonUtils.getCarbonConfigDirPath() + File.separator + "axis2" + File.separator +
// "axis2.xml");
stub = new OAuthAdminServiceStub(null, hostURL.toString());
ServiceClient client = stub._getServiceClient();
client.getServiceContext().getConfigurationContext().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setPreemptiveAuthentication(true);
String username = config.getUsername();
String password = config.getPassword();
auth.setUsername(username);
auth.setPassword(password);
Options options = client.getOptions();
options.setProperty(HTTPConstants.AUTHENTICATE, auth);
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);
client.setOptions(options);
} catch (AxisFault axisFault) {
log.error("Error occurred while creating the OAuth2TokenValidationServiceStub.");
throw new PCRException("Error occurred while creating the OAuth2TokenValidationServiceStub.", axisFault);
} catch (MalformedURLException e) {
log.error("Malformed URL error");
throw new PCRException("Malformed URL error", e);
}
return stub;
}
use of org.wso2.ballerinalang.compiler.packaging.repo.Repo in project ballerina by ballerina-lang.
the class PushUtils method pushPackages.
/**
* Push/Uploads packages to the central repository.
*
* @param packageName path of the package folder to be pushed
* @param installToRepo if it should be pushed to central or home
*/
public static void pushPackages(String packageName, String installToRepo) {
String accessToken = getAccessTokenOfCLI();
Manifest manifest = readManifestConfigurations();
if (manifest.getName() == null && manifest.getVersion() == null) {
throw new BLangCompilerException("An org-name and package version is required when pushing. " + "This is not specified in Ballerina.toml inside the project");
}
String orgName = manifest.getName();
String version = manifest.getVersion();
PackageID packageID = new PackageID(new Name(orgName), new Name(packageName), new Name(version));
Path prjDirPath = Paths.get(".").toAbsolutePath().normalize().resolve(ProjectDirConstants.DOT_BALLERINA_DIR_NAME);
// Get package path from project directory path
Path pkgPathFromPrjtDir = Paths.get(prjDirPath.toString(), "repo", Names.ANON_ORG.getValue(), packageName, Names.DEFAULT_VERSION.getValue(), packageName + ".zip");
if (installToRepo == null) {
if (accessToken == null) {
// TODO: get bal home location dynamically
throw new BLangCompilerException("Access token is missing in ~/ballerina_home/Settings.toml file.\n" + "Please visit https://central.ballerina.io/cli-token");
}
// Push package to central
String resourcePath = resolvePkgPathInRemoteRepo(packageID);
URI balxPath = URI.create(String.valueOf(PushUtils.class.getClassLoader().getResource("ballerina.push.balx")));
String msg = orgName + "/" + packageName + ":" + version + " [project repo -> central]";
ExecutorUtils.execute(balxPath, accessToken, resourcePath, pkgPathFromPrjtDir.toString(), msg);
} else {
if (!installToRepo.equals("home")) {
throw new BLangCompilerException("Unknown repository provided to push the package");
}
Path balHomeDir = HomeRepoUtils.createAndGetHomeReposPath();
Path targetDirectoryPath = Paths.get(balHomeDir.toString(), "repo", orgName, packageName, version, packageName + ".zip");
if (Files.exists(targetDirectoryPath)) {
throw new BLangCompilerException("Ballerina package exists in the home repository");
} else {
try {
Files.createDirectories(targetDirectoryPath);
Files.copy(pkgPathFromPrjtDir, targetDirectoryPath, StandardCopyOption.REPLACE_EXISTING);
outStream.println(orgName + "/" + packageName + ":" + version + " [project repo -> home repo]");
} catch (IOException e) {
throw new BLangCompilerException("Error occurred when creating directories in the home repository");
}
}
}
}
use of org.wso2.ballerinalang.compiler.packaging.repo.Repo in project ballerina by ballerina-lang.
the class PullCommand method execute.
@Override
public void execute() {
if (helpFlag) {
String commandUsageInfo = BLauncherCmd.getCommandUsageInfo(parentCmdParser, "pull");
outStream.println(commandUsageInfo);
return;
}
if (argList == null || argList.size() == 0) {
throw new BLangCompilerException("no package given");
}
if (argList.size() > 1) {
throw new BLangCompilerException("too many arguments");
}
// Enable remote debugging
if (null != debugPort) {
System.setProperty(SYSTEM_PROP_BAL_DEBUG, debugPort);
}
String resourceName = argList.get(0);
String orgName;
String packageName;
String version;
// Get org-name
int orgNameIndex = resourceName.indexOf("/");
if (orgNameIndex != -1) {
orgName = resourceName.substring(0, orgNameIndex);
} else {
throw new BLangCompilerException("no package-name provided");
}
// Get package name
int packageNameIndex = resourceName.indexOf(":");
if (packageNameIndex != -1) {
// version is provided
packageName = resourceName.substring(orgNameIndex + 1, packageNameIndex);
version = resourceName.substring(packageNameIndex + 1, resourceName.length());
} else {
packageName = resourceName.substring(orgNameIndex + 1, resourceName.length());
version = "*";
}
URI baseURI = URI.create("https://staging.central.ballerina.io:9090/");
Repo remoteRepo = new RemoteRepo(baseURI);
PackageID packageID = new PackageID(new Name(orgName), new Name(packageName), new Name(version));
Patten patten = remoteRepo.calculate(packageID);
if (patten != Patten.NULL) {
Converter converter = remoteRepo.getConverterInstance();
patten.convertToSources(converter, packageID).collect(Collectors.toList());
} else {
outStream.println("couldn't find package " + patten);
}
Runtime.getRuntime().exit(0);
}
use of org.wso2.ballerinalang.compiler.packaging.repo.Repo in project ballerina by ballerina-lang.
the class RepoHierarchy method resolve.
public Resolution resolve(PackageID pkg) {
log1(pkg);
for (int i = 0; i < repos.length; i++) {
Repo repo = repos[i];
Patten patten = repo.calculate(pkg);
if (patten != Patten.NULL) {
Converter converter = repo.getConverterInstance();
List<PackageSourceEntry> paths = patten.convertToSources(converter, pkg).collect(Collectors.toList());
log2(repo, patten, paths);
if (!paths.isEmpty()) {
return new Resolution(getChildHierarchyForRepo(i), paths);
}
} else {
log3(repo);
}
}
log4();
return Resolution.NOT_FOUND;
}
Aggregations