Search in sources :

Example 1 with Policy

use of io.fabric8.openshift.api.model.Policy 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 2 with Policy

use of io.fabric8.openshift.api.model.Policy 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 3 with Policy

use of io.fabric8.openshift.api.model.Policy in project fabric8 by jboss-fuse.

the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInRemoteRepositoryInNewerVersionUpdateAlways.

@Test
public void snapshotIsAvailableInRemoteRepositoryInNewerVersionUpdateAlways() throws IOException, InvalidMavenArtifactRequest {
    File differentLocalRepository = initFileRepository("dlr");
    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);
    servlet.start();
    mvnDeploy(differentLocalRepository, remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "a");
    // first resolution
    servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-20170101.110000-1.jar");
    mvnDeploy(differentLocalRepository, remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("12:00"), "b");
    // second resolution, subject to update policy
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    Metadata metadata = readMetadata(file);
    assertThat("Policy forces fetching changed metadata", metadata.getVersioning().getSnapshotVersions().get(0).getVersion(), is("0.1.0-20170101.120000-2"));
    assertTrue(new File(localRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.110000-1.jar").isFile());
    assertFalse(new File(localRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.120000-2.jar").isFile());
    assertTrue(new File(remoteRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.110000-1.jar").isFile());
    assertTrue(new File(remoteRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.120000-2.jar").isFile());
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Example 4 with Policy

use of io.fabric8.openshift.api.model.Policy in project fabric8 by jboss-fuse.

the class MavenProxySnapshotResolutionTest method snapshotIsAvailableInRemoteRepositoryInNewerVersion.

@Test
public void snapshotIsAvailableInRemoteRepositoryInNewerVersion() throws IOException, InvalidMavenArtifactRequest {
    File differentLocalRepository = initFileRepository("dlr");
    File remoteRepository = initFileRepository("rr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.singletonList(remoteRepository)).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_DAILY).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    servlet.start();
    mvnDeploy(differentLocalRepository, remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("11:00"), "a");
    // first resolution
    servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-20170101.110000-1.jar");
    mvnDeploy(differentLocalRepository, remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0-SNAPSHOT", at("12:00"), "b");
    // second resolution, subject to update policy
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/maven-metadata.xml");
    Metadata metadata = readMetadata(file);
    assertThat("Policy prevents from fetching changed metadata", metadata.getVersioning().getSnapshotVersions().get(0).getVersion(), is("0.1.0-20170101.110000-1"));
    assertTrue(new File(localRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.110000-1.jar").isFile());
    assertFalse(new File(localRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.120000-2.jar").isFile());
    assertTrue(new File(remoteRepository, "io/fabric8/test/universalis-api/0.1.0-SNAPSHOT/universalis-api-0.1.0-20170101.120000-2.jar").isFile());
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) File(java.io.File) Test(org.junit.Test)

Example 5 with Policy

use of io.fabric8.openshift.api.model.Policy in project fabric8 by jboss-fuse.

the class PushPullPolicyIT method initLocalGitRepositoryAndPushToServletRepository.

@Before
public void initLocalGitRepositoryAndPushToServletRepository() throws Exception {
    dirLocal = new File("target/data-local");
    dirServlet = new File("target/data-servlet");
    FileUtils.deleteDirectory(dirLocal);
    FileUtils.deleteDirectory(dirServlet);
    local = Git.init().setDirectory(dirLocal).setGitDir(new File(dirLocal, ".git")).call();
    servlet = Git.init().setDirectory(dirServlet).setBare(true).call();
    // local -> servlet
    local.getRepository().getConfig().setString("remote", "origin", "url", dirServlet.getCanonicalPath());
    local.getRepository().getConfig().setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    local.getRepository().getConfig().save();
    // master branch - ensemble profiles
    prepareMasterBranch();
    // version 1.0 - created by importing initial profiles
    prepare10Branch();
    prepareBranch("1.0.1", "1.0", 3);
    prepareBranch("1.1", "1.0", 4);
    prepareBranch("1.2", "1.1", 2);
    local.push().setRemote("origin").setPushAll().setPushTags().call();
    policy = new DefaultPullPushPolicy(local, "origin", 42);
}
Also used : DefaultPullPushPolicy(io.fabric8.git.internal.DefaultPullPushPolicy) File(java.io.File) Before(org.junit.Before)

Aggregations

File (java.io.File)5 Test (org.junit.Test)5 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)4 ResourceRequirements (io.fabric8.kubernetes.api.model.ResourceRequirements)4 MavenResolver (io.fabric8.maven.MavenResolver)4 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)4 IOException (java.io.IOException)3 List (java.util.List)3 MapUtils.addToMapSet (io.fabric8.agent.internal.MapUtils.addToMapSet)2 Container (io.fabric8.kubernetes.api.model.Container)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)2 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)2 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2 RestartPolicy (io.fabric8.maven.docker.config.RestartPolicy)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Optional (java.util.Optional)2