Search in sources :

Example 26 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class MavenProxyResolutionTest method releaseIsAvailableInRemoteRepositoryNotUpdatingRelease.

@Test
public void releaseIsAvailableInRemoteRepositoryNotUpdatingRelease() throws IOException, InvalidMavenArtifactRequest {
    File remoteRepository = initFileRepository("rr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.singletonList(remoteRepository)).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 won't be updated for release version", FileUtils.readFileToString(file), equalTo("a"));
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) File(java.io.File) Test(org.junit.Test)

Example 27 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInDefaultRepositoryActingAsRemote.

@Test
public void snapshotIsAvailableInDefaultRepositoryActingAsRemote() throws IOException, InvalidMavenArtifactRequest {
    File differentLocalRepository = initFileRepository("dlr");
    File defaultRepository = initFileRepository("dr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.<File>emptyList()).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER).withDefaultRepositories(Collections.singletonList(defaultRepository)).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    servlet.start();
    mvnDeploy(differentLocalRepository, defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
    // Here's expected state of repository where SNAPSHOT was `mvn deploy`ed
    assertFalse(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata-local.xml").isFile());
    assertTrue(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml").isFile());
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    Metadata metadata = readMetadata(file);
    boolean checked = false;
    assertThat(metadata.getVersioning().getSnapshot().isLocalCopy(), is(false));
    for (SnapshotVersion snapshotVersion : metadata.getVersioning().getSnapshotVersions()) {
        if ("jar".equals(snapshotVersion.getExtension())) {
            assertThat(snapshotVersion.getVersion(), is("0.1.0-20170101.100000-1"));
            checked = true;
        }
    }
    assertTrue("We should find snapshot metadata", checked);
    // download artifact using version from metadata
    file = servlet.download("io/fabric8/test/universalis-api/0.1.0-20170101.100000-1/universalis-api-0.1.0-20170101.100000-1.jar");
    assertThat(FileUtils.readFileToString(file), equalTo("a"));
    mvnDeploy(differentLocalRepository, defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "b");
    file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    metadata = readMetadata(file);
    assertThat("No policy should prevent us from seeing newer snapshot from defaultRepository", metadata.getVersioning().getSnapshotVersions().get(0).getVersion(), is("0.1.0-20170101.110000-2"));
}
Also used : SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Example 28 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInDefaultRepository.

@Test
public void snapshotIsAvailableInDefaultRepository() throws IOException, InvalidMavenArtifactRequest {
    File defaultRepository = initFileRepository("dr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.<File>emptyList()).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER).withDefaultRepositories(Collections.singletonList(defaultRepository)).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    servlet.start();
    mvnInstall(defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
    // Here's expected state of repository where SNAPSHOT was `mvn install`ed
    assertFalse(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml").isFile());
    assertTrue(new File(defaultRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata-local.xml").isFile());
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    Metadata metadata = readMetadata(file);
    boolean checked = false;
    assertThat(metadata.getVersioning().getSnapshot().isLocalCopy(), is(true));
    for (SnapshotVersion snapshotVersion : metadata.getVersioning().getSnapshotVersions()) {
        if ("jar".equals(snapshotVersion.getExtension())) {
            assertThat(snapshotVersion.getVersion(), is("0.1.0-SNAPSHOT"));
            checked = true;
        }
    }
    assertTrue("We should find snapshot metadata", checked);
    // if metadata says it's "0.1.0-SNAPSHOT", we should have no problem downloading this artifact without
    // version transformation
    file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-SNAPSHOT.jar");
    assertThat(FileUtils.readFileToString(file), equalTo("a"));
    mvnInstall(defaultRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "b");
    file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-SNAPSHOT.jar");
    assertThat("No policy should prevent us from seeing newer snapshot from defaultRepository", FileUtils.readFileToString(file), equalTo("b"));
}
Also used : SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Example 29 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInTwoRemoteRepositories.

@Test
public void snapshotIsAvailableInTwoRemoteRepositories() throws IOException, InvalidMavenArtifactRequest {
    File differentLocalRepository = initFileRepository("dlr");
    File remoteRepository1 = initFileRepository("rr1");
    File remoteRepository2 = initFileRepository("rr2");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Arrays.asList(remoteRepository1, remoteRepository2)).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    servlet.start();
    mvnDeploy(differentLocalRepository, remoteRepository1, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "a");
    mvnDeploy(differentLocalRepository, remoteRepository2, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("10:00"), "b");
    mvnDeploy(differentLocalRepository, remoteRepository2, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "c");
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    Metadata metadata = readMetadata(file);
    assertThat("Metadata should aggregate versions from all remote repositories, without duplicates", metadata.getVersioning().getSnapshotVersions().size(), is(4));
    assertThat("Latest version should win", metadata.getVersioning().getLastUpdated(), is("20170101110000"));
    assertThat("Latest version should win", metadata.getVersioning().getSnapshot().getTimestamp(), is("20170101.110000"));
    assertThat("Latest version should win, assume versions are sorted in ascending order", metadata.getVersioning().getSnapshotVersions().get(3).getVersion(), is("0.1.0-20170101.110000-2"));
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Example 30 with Version

use of io.fabric8.api.Version in project fabric8 by jboss-fuse.

the class DummyBatchingProgressMonitor method getVersionFromCacheRW.

private Version getVersionFromCacheRW(String versionId, String profileId) {
    try {
        initialVersionsAvailable.await(15, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
        LOGGER.warn("Waiting for initial versions failed");
    }
    LockHandle writeLock = aquireWriteLock();
    try {
        assertValid();
        String branch = GitHelpers.getProfileBranch(versionId, profileId);
        if (GitHelpers.localBranchExists(getGit(), branch)) {
            return versionCache.get(versionId);
        } else {
            return null;
        }
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    } finally {
        writeLock.unlock();
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) FabricException(io.fabric8.api.FabricException) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException)

Aggregations

Version (io.fabric8.api.Version)74 Profile (io.fabric8.api.Profile)70 File (java.io.File)52 Test (org.junit.Test)46 IOException (java.io.IOException)41 ArrayList (java.util.ArrayList)36 Container (io.fabric8.api.Container)35 HashMap (java.util.HashMap)34 ProfileService (io.fabric8.api.ProfileService)27 Map (java.util.Map)25 Git (org.eclipse.jgit.api.Git)22 FabricService (io.fabric8.api.FabricService)21 Version (org.osgi.framework.Version)21 ProfileBuilder (io.fabric8.api.ProfileBuilder)18 GitVersion (io.fabric8.api.commands.GitVersion)18 PatchException (io.fabric8.patch.management.PatchException)15 HashSet (java.util.HashSet)15 TreeMap (java.util.TreeMap)14 LinkedList (java.util.LinkedList)13 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)12