Search in sources :

Example 86 with Repository

use of io.fabric8.agent.model.Repository 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)

Example 87 with Repository

use of io.fabric8.agent.model.Repository 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;
}
Also used : Dependency(io.fabric8.agent.model.Dependency) Feature(io.fabric8.agent.model.Feature) HashSet(java.util.HashSet)

Example 88 with Repository

use of io.fabric8.agent.model.Repository 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;
}
Also used : Repository(io.fabric8.agent.model.Repository) Version(org.osgi.framework.Version) VersionRange(org.apache.felix.utils.version.VersionRange) Feature(io.fabric8.agent.model.Feature)

Example 89 with Repository

use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.

the class MavenProxyResolutionTest method releaseIsAvailableInRemoteRepositoryUpdatingRelease.

@Test
public void releaseIsAvailableInRemoteRepositoryUpdatingRelease() throws IOException, InvalidMavenArtifactRequest {
    File remoteRepository = initFileRepository("rr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.singletonList(remoteRepository)).withReleaseUpdates().withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    mvnInstall(remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0", at("10:00"), "a");
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0/universalis-api-0.1.0.jar");
    // first resolution
    assertThat(FileUtils.readFileToString(file), equalTo("a"));
    // don't do that, it's not proper use of maven. But sometimes we just have another deployment to public repository...
    mvnInstall(remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0", at("11:00"), "b");
    // second resolution
    file = servlet.download("io/fabric8/test/universalis-api/0.1.0/universalis-api-0.1.0.jar");
    assertThat("Artifact will be updated though it's not proper usage of Maven", FileUtils.readFileToString(file), equalTo("b"));
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) File(java.io.File) Test(org.junit.Test)

Example 90 with Repository

use of io.fabric8.agent.model.Repository in project fabric8 by jboss-fuse.

the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInTwoDefaultRepositories.

@Test
public void snapshotIsAvailableInTwoDefaultRepositories() throws IOException, InvalidMavenArtifactRequest {
    File defaultRepository1 = initFileRepository("dr1");
    File defaultRepository2 = initFileRepository("dr2");
    MavenResolver resolver = new ResolverBuilder().withDefaultRepositories(Arrays.asList(defaultRepository1, defaultRepository2)).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    servlet.start();
    mvnInstall(defaultRepository1, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
    mvnInstall(defaultRepository2, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "b");
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    Metadata metadata = readMetadata(file);
    assertThat("Resolution done in first default repository, even if second one has newer artifact", metadata.getVersioning().getSnapshotVersions().get(0).getUpdated(), is("20170101100000"));
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)49 Test (org.junit.Test)32 Git (org.eclipse.jgit.api.Git)30 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)27 IOException (java.io.IOException)24 GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)20 HashMap (java.util.HashMap)15 ObjectId (org.eclipse.jgit.lib.ObjectId)13 MalformedURLException (java.net.MalformedURLException)11 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 PatchException (io.fabric8.patch.management.PatchException)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 Bundle (org.osgi.framework.Bundle)8 Version (org.osgi.framework.Version)8 MavenResolver (io.fabric8.maven.MavenResolver)7 HashSet (java.util.HashSet)7 Repository (io.fabric8.agent.model.Repository)6 BundleContext (org.osgi.framework.BundleContext)6 Feature (io.fabric8.agent.model.Feature)5