Search in sources :

Example 6 with Utils.mvnurlToArtifact

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;
}
Also used : IOException(java.io.IOException) Properties(java.util.Properties) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Artifact(io.fabric8.patch.management.Artifact)

Example 7 with Utils.mvnurlToArtifact

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;
}
Also used : BundleStartLevel(org.osgi.framework.startlevel.BundleStartLevel) Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) Artifact(io.fabric8.patch.management.Artifact)

Example 8 with Utils.mvnurlToArtifact

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;
        }
    };
}
Also used : StreamProvider(io.fabric8.agent.download.StreamProvider) HashMap(java.util.HashMap) DownloadCallback(io.fabric8.agent.download.DownloadCallback) Downloader(io.fabric8.agent.download.Downloader) URI(java.net.URI) MalformedURLException(java.net.MalformedURLException) MultiException(io.fabric8.common.util.MultiException) FileInputStream(java.io.FileInputStream) Artifact(io.fabric8.patch.management.Artifact) Callable(java.util.concurrent.Callable) Repository(io.fabric8.agent.model.Repository) File(java.io.File)

Aggregations

Artifact (io.fabric8.patch.management.Artifact)8 File (java.io.File)5 HashMap (java.util.HashMap)4 Patch (io.fabric8.patch.management.Patch)3 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 Bundle (org.osgi.framework.Bundle)3 Version (org.osgi.framework.Version)3 BundleUpdate (io.fabric8.patch.management.BundleUpdate)2 ManagedPatch (io.fabric8.patch.management.ManagedPatch)2 FileInputStream (java.io.FileInputStream)2 LinkedHashMap (java.util.LinkedHashMap)2 Properties (java.util.Properties)2 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)2 Git (org.eclipse.jgit.api.Git)2 DownloadCallback (io.fabric8.agent.download.DownloadCallback)1 Downloader (io.fabric8.agent.download.Downloader)1 StreamProvider (io.fabric8.agent.download.StreamProvider)1 Repository (io.fabric8.agent.model.Repository)1 MultiException (io.fabric8.common.util.MultiException)1