use of org.graalvm.component.installer.remote.RemotePropertiesStorage in project graal by oracle.
the class GraalChannel method loadStorage.
@Override
protected ComponentStorage loadStorage() throws IOException {
FileDownloader dn = new FileDownloader(fb.l10n("OLDS_ReleaseFile"), getIndexURL(), fb);
dn.download();
Path storagePath = dn.getLocalFile().toPath();
List<ReleaseEntry> releases = loadReleasesIndex(storagePath);
if (releases.isEmpty()) {
return throwEmptyStorage();
}
MergeStorage store = new MergeStorage(localRegistry, fb);
store.setAcceptAllSources(true);
for (ReleaseEntry en : releases) {
URL catURL = en.getCatalogURL();
Version v = Version.fromString(en.getVersion().displayString());
SoftwareChannelSource src = new SoftwareChannelSource(catURL.toString(), en.getLabel());
WebCatalog cata = new WebCatalog(src.getLocationURL(), src) {
@Override
protected RemotePropertiesStorage createPropertiesStorage(Feedback aFeedback, ComponentRegistry aLocal, Properties props, String selector, URL baseURL) {
return new RemotePropertiesStorage(aFeedback, aLocal, props, selector, v, baseURL);
}
};
cata.init(localRegistry, fb);
cata.setMatchVersion(en.getVersion().match(Version.Match.Type.EXACT));
cata.setRemoteProcessor((i) -> configureLicense(i, en));
store.addChannel(src, cata);
}
return store;
}
use of org.graalvm.component.installer.remote.RemotePropertiesStorage in project graal by oracle.
the class CatalogContentsTest method initVersion.
private Version initVersion(String s) throws IOException {
Version v = Version.fromString(s);
storage.graalInfo.put(BundleConstants.GRAAL_VERSION, s);
Path catalogPath = dataFile("../repo/catalog.properties");
Properties props = new Properties();
try (InputStream is = Files.newInputStream(catalogPath)) {
props.load(is);
}
remstorage = new RemotePropertiesStorage(this, getLocalRegistry(), props, "linux_amd64", v, catalogPath.toUri().toURL());
coll = new CatalogContents(this, remstorage, getLocalRegistry());
return v;
}
use of org.graalvm.component.installer.remote.RemotePropertiesStorage in project graal by oracle.
the class MergedCatalogContentsTest method initVersion.
private Version initVersion(String s) throws IOException {
Version v = Version.fromString(s);
storage.graalInfo.put(BundleConstants.GRAAL_VERSION, s);
Path catalogPath = dataFile("catalog-deps.properties");
Properties props = new Properties();
try (InputStream is = Files.newInputStream(catalogPath)) {
props.load(is);
}
remstorage = new RemotePropertiesStorage(this, getLocalRegistry(), props, "linux_amd64", v, catalogPath.toUri().toURL());
coll = new CatalogContents(this, remstorage, getLocalRegistry());
return v;
}
use of org.graalvm.component.installer.remote.RemotePropertiesStorage in project graal by oracle.
the class WebCatalog method getStorage.
@Override
public ComponentStorage getStorage() {
if (this.storage != null) {
return this.storage;
}
Map<String, String> graalCaps = local.getGraalCapabilities();
StringBuilder sb = new StringBuilder();
sb.append(SystemUtils.patternOsName(graalCaps.get(CommonConstants.CAP_OS_NAME)).toLowerCase());
sb.append("_");
sb.append(SystemUtils.patternOsArch(graalCaps.get(CommonConstants.CAP_OS_ARCH).toLowerCase()));
try {
catalogURL = new URL(urlString);
} catch (MalformedURLException ex) {
throw feedback.failure("REMOTE_InvalidURL", ex, catalogURL, ex.getLocalizedMessage());
}
Properties props = new Properties();
// create the storage. If the init fails, but process will not terminate, the storage will
// serve no components on the next call.
RemotePropertiesStorage newStorage = createPropertiesStorage(feedback, local, props, sb.toString(), catalogURL);
if (remoteProcessor != null) {
newStorage.setRemoteProcessor(remoteProcessor);
}
Properties loadProps = new Properties();
FileDownloader dn;
try {
// avoid duplicate (failed) downloads
if (savedException != null) {
throw savedException;
}
catalogURL = new URL(urlString);
String l = source.getLabel();
dn = new FileDownloader(feedback.l10n(l == null || l.isEmpty() ? "REMOTE_CatalogLabel2" : "REMOTE_CatalogLabel", l), catalogURL, feedback);
dn.download();
} catch (NoRouteToHostException | ConnectException ex) {
throw savedException = feedback.failure("REMOTE_ErrorDownloadCatalogProxy", ex, catalogURL, ex.getLocalizedMessage());
} catch (FileNotFoundException ex) {
// treat missing resources as non-fatal errors, print warning
feedback.error("REMOTE_WarningErrorDownloadCatalogNotFoundSkip", ex, catalogURL);
this.storage = newStorage;
return storage;
} catch (IOException ex) {
throw savedException = feedback.failure("REMOTE_ErrorDownloadCatalog", ex, catalogURL, ex.getLocalizedMessage());
}
// download is successful; if the processing fails after download, next call will report an
// empty catalog.
this.storage = newStorage;
StringBuilder oldGraalPref = new StringBuilder("^" + BundleConstants.GRAAL_COMPONENT_ID);
oldGraalPref.append('.');
String graalVersionString;
Version normalizedVersion;
if (matchVersion != null) {
graalVersionString = matchVersion.getVersion().displayString();
normalizedVersion = matchVersion.getVersion().installVersion();
} else {
// read from the release file
graalVersionString = graalCaps.get(CommonConstants.CAP_GRAALVM_VERSION).toLowerCase();
normalizedVersion = local.getGraalVersion().installVersion();
}
StringBuilder graalPref = new StringBuilder(oldGraalPref);
oldGraalPref.append(Pattern.quote(graalVersionString));
oldGraalPref.append('_').append(sb);
graalPref.append(sb).append('/');
// NOI18N
graalPref.append("(?<ver>[^/]+)$");
try (FileInputStream fis = new FileInputStream(dn.getLocalFile())) {
loadProps.load(fis);
} catch (IllegalArgumentException | IOException ex) {
throw feedback.failure("REMOTE_CorruptedCatalogFile", ex, catalogURL);
}
Pattern oldPrefixPattern = Pattern.compile(oldGraalPref.toString(), Pattern.CASE_INSENSITIVE);
Pattern newPrefixPattern = Pattern.compile(graalPref.toString(), Pattern.CASE_INSENSITIVE);
Stream<String> propNames = loadProps.stringPropertyNames().stream();
boolean foundPrefix = propNames.anyMatch(p -> {
if (oldPrefixPattern.matcher(p).matches()) {
return true;
}
Matcher m = newPrefixPattern.matcher(p);
if (!m.find() || m.start() > 0) {
return false;
}
try {
// NOI18N
Version v = Version.fromString(m.group("ver"));
return normalizedVersion.match(Version.Match.Type.INSTALLABLE).test(v);
} catch (IllegalArgumentException ex) {
return false;
}
});
if (!foundPrefix) {
boolean graalPrefixFound = false;
boolean componentFound = false;
for (String s : loadProps.stringPropertyNames()) {
if (s.startsWith(BundleConstants.GRAAL_COMPONENT_ID)) {
graalPrefixFound = true;
}
if (s.startsWith("Component.")) {
componentFound = true;
}
}
if (!componentFound) {
// no graal prefix, no components
feedback.verboseOutput("REMOTE_CatalogDoesNotContainComponents", catalogURL);
return newStorage;
} else if (!graalPrefixFound) {
// strange thing, no graal declaration, but components are there ?
throw feedback.failure("REMOTE_CorruptedCatalogFile", null, catalogURL);
} else {
throw new IncompatibleException(feedback.l10n("REMOTE_UnsupportedGraalVersion", graalCaps.get(CommonConstants.CAP_GRAALVM_VERSION), graalCaps.get(CommonConstants.CAP_OS_NAME), graalCaps.get(CommonConstants.CAP_OS_ARCH)), null);
}
}
props.putAll(loadProps);
return newStorage;
}
use of org.graalvm.component.installer.remote.RemotePropertiesStorage in project graal by oracle.
the class ListTest method initRemoteStorage.
private void initRemoteStorage() throws MalformedURLException {
this.remoteStorage = new RemotePropertiesStorage(this, getLocalRegistry(), catalogContents, "linux_amd64", Version.fromString("1.0.0-rc3-dev"), new URL("http://go.to/graalvm"));
this.registry = new CatalogContents(this, remoteStorage, localRegistry);
}
Aggregations