use of org.ops4j.pax.url.mvn.MavenResolver in project karaf by apache.
the class FeaturesServiceImpl method doProvision.
private // all requirements
void doProvision(// all requirements
Map<String, Set<String>> requirements, // features state changes
Map<String, Map<String, FeatureState>> stateChanges, // current state
State state, // installation options
EnumSet<Option> options, // file to store the resolution or null
String outputFile) throws Exception {
Dictionary<String, String> props = getMavenConfig();
MavenResolver resolver = MavenResolvers.createMavenResolver(props, "org.ops4j.pax.url.mvn");
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(cfg.downloadThreads);
executor.setMaximumPoolSize(cfg.downloadThreads);
DownloadManager manager = DownloadManagers.createDownloadManager(resolver, executor, cfg.scheduleDelay, cfg.scheduleMaxRun);
try {
Set<String> prereqs = new HashSet<>();
while (true) {
try {
Deployer.DeploymentState dstate = getDeploymentState(state);
Deployer.DeploymentRequest request = getDeploymentRequest(requirements, stateChanges, options, outputFile);
new Deployer(manager, this.resolver, this.installSupport, this).deploy(dstate, request);
break;
} catch (Deployer.PartialDeploymentException e) {
if (!prereqs.containsAll(e.getMissing())) {
prereqs.addAll(e.getMissing());
state = copyState();
} else {
throw new Exception("Deployment aborted due to loop in missing prerequisites: " + e.getMissing());
}
}
}
} finally {
executor.shutdown();
}
}
use of org.ops4j.pax.url.mvn.MavenResolver in project opennms by OpenNMS.
the class KarafExtender method init.
public void init() throws InterruptedException {
Objects.requireNonNull(m_configurationAdmin, "configurationAdmin");
Objects.requireNonNull(m_mavenResolver, "mavenResolver");
Objects.requireNonNull(m_featuresService, "featuresService");
List<Repository> repositories;
try {
repositories = getRepositories();
} catch (IOException e) {
LOG.error("Failed to retrieve the list of repositories. Aborting.", e);
return;
}
// Prepend the featuresBoot from the repository definitions
List<Feature> featuresBoot = repositories.stream().flatMap(r -> r.getFeaturesBoot().stream()).collect(Collectors.toList());
try {
featuresBoot.addAll(getFeaturesBoot());
} catch (IOException e) {
LOG.error("Failed to retrieve the list of features to boot. Aborting.", e);
return;
}
// Filter the list of features
filterFeatures(featuresBoot);
// Build a comma separated list of our Maven repositories
final StringBuilder mavenReposSb = new StringBuilder();
for (Repository repository : repositories) {
if (mavenReposSb.length() != 0) {
mavenReposSb.append(",");
}
mavenReposSb.append(repository.toMavenUri());
}
final String mavenRepos = mavenReposSb.toString();
LOG.info("Updating Maven repositories to include: {}", mavenRepos);
try {
final Configuration config = m_configurationAdmin.getConfiguration(PAX_MVN_PID);
if (config == null) {
throw new IOException("The OSGi configuration (admin) registry was found for pid " + PAX_MVN_PID + ", but a configuration could not be located/generated. This shouldn't happen.");
}
final Dictionary<String, Object> props = config.getProperties();
if (!mavenRepos.equals(props.get(PAX_MVN_REPOSITORIES))) {
props.put(PAX_MVN_REPOSITORIES, mavenRepos);
config.update(props);
}
} catch (IOException e) {
LOG.error("Failed to update the list of Maven repositories to '{}'. Aborting.", mavenRepos, e);
return;
}
// The configuration update is async, we need to wait for the feature URLs to be resolvable before we use them
LOG.info("Waiting up-to 30 seconds for the Maven repositories to be updated...");
// Attempting to resolve a missing features writes an exception to the log
// We sleep fix a fixed amount of time before our first try in order to help minimize the logged
// exceptions, even if we catch them
Thread.sleep(2000);
for (int i = 28; i > 0 && !canResolveAllFeatureUris(repositories); i--) {
Thread.sleep(1000);
}
for (Repository repository : repositories) {
for (URI featureUri : repository.getFeatureUris()) {
try {
LOG.info("Adding feature repository: {}", featureUri);
m_featuresService.addRepository(featureUri);
} catch (Exception e) {
LOG.error("Failed to add feature repository '{}'. Skipping.", featureUri, e);
}
}
}
final Set<String> featuresToInstall = featuresBoot.stream().map(f -> f.getVersion() != null ? f.getName() + "/" + f.getVersion() : f.getName()).collect(Collectors.toCollection(LinkedHashSet::new));
// Because of the fix for the following issue, we need to call the
// feature installation in another thread since this method is invoked
// during a feature installation itself and feature installations are
// now single-threaded.
//
// https://issues.apache.org/jira/browse/KARAF-3798
// https://github.com/apache/karaf/pull/138
//
CompletableFuture.runAsync(new Runnable() {
@Override
public void run() {
try {
LOG.info("Installing features: {}", featuresToInstall);
m_featuresService.installFeatures(featuresToInstall, EnumSet.noneOf(Option.class));
} catch (Exception e) {
LOG.error("Failed to install one or more features.", e);
}
}
});
}
use of org.ops4j.pax.url.mvn.MavenResolver in project components by Talend.
the class JarRuntimeInfoTest method testExtracDependencyFromStream.
/**
* Test method for
* {@link org.talend.components.api.component.runtime.DependenciesReader#extractDependenciesFromStream(org.talend.components.api.component.runtime.DependenciesReader, java.lang.String, java.util.jar.JarInputStream)}
* .
*
* @throws IOException
* @throws MalformedURLException
*/
@Ignore("we can't use components-api-full-example here because it brings cyclic dependency. Should be fixed by using another test module")
@Test
public void testExtracDependencyFromStream() throws MalformedURLException, IOException {
MavenResolver mavenResolver = MavenResolvers.createMavenResolver(null, "foo");
File jarWithDeps = mavenResolver.resolve("mvn:org.talend.components/components-api-full-example/0.1.0");
try (JarInputStream jis = new JarInputStream(new FileInputStream(jarWithDeps))) {
List<URL> dependencyFromStream = DependenciesReader.extractDependencies(new DependenciesReader(null), DependenciesReader.computeDependenciesFilePath("org.talend.components", "components-full-example"), jis);
checkFullExampleDependencies(dependencyFromStream);
}
}
use of org.ops4j.pax.url.mvn.MavenResolver in project karaf by apache.
the class FeaturesServiceImpl method createDownloadManager.
protected DownloadManager createDownloadManager() throws IOException {
Dictionary<String, String> props = getMavenConfig();
MavenResolver resolver = MavenResolvers.createMavenResolver(props, "org.ops4j.pax.url.mvn");
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(cfg.downloadThreads, ThreadUtils.namedThreadFactory("downloader"));
executor.setMaximumPoolSize(cfg.downloadThreads);
return DownloadManagers.createDownloadManager(resolver, executor, cfg.scheduleDelay, cfg.scheduleMaxRun);
}
use of org.ops4j.pax.url.mvn.MavenResolver in project karaf by apache.
the class Builder method createMavenResolver.
private MavenResolver createMavenResolver() {
Dictionary<String, String> props = new Hashtable<>();
if (offline) {
props.put(ORG_OPS4J_PAX_URL_MVN_PID + "offline", "true");
}
if (localRepository != null) {
props.put(ORG_OPS4J_PAX_URL_MVN_PID + ".localRepository", localRepository);
}
if (mavenRepositories != null) {
props.put(ORG_OPS4J_PAX_URL_MVN_PID + ".repositories", mavenRepositories);
}
MavenResolver resolver = MavenResolvers.createMavenResolver(props, ORG_OPS4J_PAX_URL_MVN_PID);
return resolverWrapper.apply(resolver);
}
Aggregations