use of io.fabric8.patch.management.Utils.mvnurlToArtifact in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceImpl method determineVersion.
/**
* Return version of product (Fuse, Fabric8) used, but probably based on different karafHome
* @param home
* @param product
* @return
*/
private String determineVersion(File home, String product) {
if (env != EnvType.FABRIC_CHILD && env != EnvType.STANDALONE_CHILD) {
File versions = new File(home, "fabric/import/fabric/profiles/default.profile/io.fabric8.version.properties");
if (versions.exists() && versions.isFile()) {
Properties props = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream(versions);
props.load(fis);
return props.getProperty(product);
} catch (IOException e) {
Activator.log(LogService.LOG_ERROR, null, e.getMessage(), e, true);
return null;
} finally {
IOUtils.closeQuietly(fis);
}
} else {
Activator.log2(LogService.LOG_ERROR, "Can't find io.fabric8.version.properties file in default profile");
}
} else {
// for child container we have to be more careful and not examine root container's io.fabric8.version.properties!
File startup = new File(home, "etc/startup.properties");
if (startup.exists() && startup.isFile()) {
Properties props = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream(startup);
props.load(fis);
for (String key : props.stringPropertyNames()) {
if (key.startsWith("org/apache/karaf/features/org.apache.karaf.features.core")) {
String url = Utils.pathToMvnurl(key);
Artifact artifact = Utils.mvnurlToArtifact(url, true);
if (artifact != null) {
return artifact.getVersion();
}
}
}
} catch (IOException e) {
Activator.log(LogService.LOG_ERROR, null, e.getMessage(), e, true);
return null;
} finally {
IOUtils.closeQuietly(fis);
}
} else {
Activator.log2(LogService.LOG_ERROR, "Can't find etc/startup.properties file in child container");
}
}
return null;
}
use of io.fabric8.patch.management.Utils.mvnurlToArtifact in project fabric8 by jboss-fuse.
the class ServiceImplTest method bundle.
/**
* Helper method for {@link #bundleUpdatesInPatch()} test
* @param location
* @return
*/
private Bundle bundle(String location) {
BundleStartLevel bsl = createMock(BundleStartLevel.class);
expect(bsl.getStartLevel()).andReturn(42);
replay(bsl);
Bundle b = createMock(Bundle.class);
Artifact a = Utils.mvnurlToArtifact(location, false);
expect(b.getSymbolicName()).andReturn(a.getArtifactId()).anyTimes();
expect(b.getVersion()).andReturn(new Version(a.getVersion())).anyTimes();
expect(b.getLocation()).andReturn(location).anyTimes();
expect(b.adapt(BundleStartLevel.class)).andReturn(bsl);
expect(b.getState()).andReturn(Bundle.ACTIVE);
replay(b);
return b;
}
use of io.fabric8.patch.management.Utils.mvnurlToArtifact 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;
}
};
}
Aggregations