use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.
the class AgentUtils method downloadRepositories.
public static Callable<Map<String, Repository>> downloadRepositories(DownloadManager manager, Set<String> uris) throws MultiException, InterruptedException, MalformedURLException {
final Map<String, Repository> repositories = new HashMap<>();
final Downloader downloader = manager.createDownloader();
final File targetLocation = getDefaultKarafRepository();
for (String uri : uris) {
downloader.download(uri, new DownloadCallback() {
@Override
public void downloaded(StreamProvider provider) throws Exception {
String uri = provider.getUrl();
Repository repository = new Repository(URI.create(uri));
repository.load(new FileInputStream(provider.getFile()), true);
synchronized (repositories) {
repositories.put(uri, repository);
}
for (URI repo : repository.getRepositories()) {
downloader.download(repo.toASCIIString(), this);
}
Artifact artifact = Utils.mvnurlToArtifact(uri, true);
if (artifact == null || artifact.getVersion() == null || !artifact.getVersion().endsWith("-SNAPSHOT")) {
// we need a feature repository to be available in ${karaf.home}/${karaf.default.repository}
// it makes patching much easier
// ENTESB-6931: don't store SNAPSHOT feature repositories in ${karaf.home}/${karaf.default.repository}
storeInDefaultKarafRepository(targetLocation, provider.getFile(), uri);
}
}
});
}
return new Callable<Map<String, Repository>>() {
@Override
public Map<String, Repository> call() throws Exception {
downloader.await();
return repositories;
}
};
}
use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.
the class AgentUtils method getProfileArtifacts.
/**
* Returns the location and parser map (i.e. the location and the parsed maven coordinates and artifact locations) of each bundle and feature
*/
public static Map<String, Parser> getProfileArtifacts(FabricService fabricService, Profile profile, Iterable<String> bundles, Iterable<Feature> features, Callback<String> nonMavenLocationCallback) {
Set<String> locations = new HashSet<>();
for (Feature feature : features) {
List<BundleInfo> bundleList = feature.getBundles();
if (bundleList == null) {
LOGGER.warn("No bundles for feature " + feature);
} else {
for (BundleInfo bundle : bundleList) {
locations.add(bundle.getLocation());
}
}
}
for (String bundle : bundles) {
locations.add(bundle);
}
Map<String, Parser> artifacts = new HashMap<>();
for (String location : locations) {
try {
if (location.contains("$")) {
ProfileService profileService = fabricService.adapt(ProfileService.class);
Profile overlay = profileService.getOverlayProfile(profile);
location = VersionPropertyPointerResolver.replaceVersions(fabricService, overlay.getConfigurations(), location);
}
if (location.startsWith("mvn:") || location.contains(":mvn:")) {
Parser parser = Parser.parsePathWithSchemePrefix(location);
artifacts.put(location, parser);
} else {
if (nonMavenLocationCallback != null) {
nonMavenLocationCallback.call(location);
}
}
} catch (MalformedURLException e) {
LOGGER.error("Failed to parse bundle URL: " + location + ". " + e, e);
}
}
return artifacts;
}
use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.
the class AgentUtils method expandFeature.
public static Set<Feature> expandFeature(Feature feature, Map<String, Repository> repositories) {
Set<Feature> features = new HashSet<>();
for (Dependency f : feature.getDependencies()) {
Feature loaded = FeatureUtils.search(f.getName(), repositories.values());
features.addAll(expandFeature(loaded, repositories));
}
features.add(feature);
return features;
}
use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.
the class FeatureUtils method search.
public static Feature search(String name, String version, Collection<Repository> repositories) {
VersionRange range = new VersionRange(version, false, true);
Feature bestFeature = null;
Version bestVersion = null;
for (Repository repo : repositories) {
Feature[] features;
try {
features = repo.getFeatures();
} catch (Exception e) {
// This should not happen as the repository has been loaded already
throw new IllegalStateException(e);
}
for (Feature feature : features) {
if (name.equals(feature.getName())) {
Version v = new Version(VersionCleaner.clean(feature.getVersion()));
if (range.contains(v)) {
if (bestVersion == null || bestVersion.compareTo(v) < 0) {
bestFeature = feature;
bestVersion = v;
}
}
}
}
}
return bestFeature;
}
use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.
the class DeploymentAgentTest method testResolveOptionalImports.
@Test
@SuppressWarnings("unchecked")
public void testResolveOptionalImports() throws Exception {
CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
CommandSupport.executeCommand("fabric:profile-create --parent default test-profile");
CommandSupport.executeCommand("fabric:profile-edit --pid io.fabric8.agent/resolve.optional.imports=true test-profile");
CommandSupport.executeCommand("fabric:profile-edit --feature spring-struts test-profile");
BundleContext moduleContext = ServiceLocator.getSystemContext();
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
Set<Container> containers = ContainerBuilder.create().withName("smoke_cnt_b").withProfiles("test-profile").assertProvisioningResult().build(fabricService);
try {
String command = "fabric:container-connect -u admin -p admin " + containers.iterator().next().getId() + " osgi:list -t 0 -s | grep org.apache.servicemix.bundles.struts";
String result = CommandSupport.executeCommand(command);
assertTrue("Result contains struts, but was: " + result, result.contains("org.apache.servicemix.bundles.struts"));
} finally {
ContainerBuilder.stop(fabricService, containers);
}
} finally {
fabricProxy.close();
}
}
Aggregations