Search in sources :

Example 11 with RepositorySession

use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.

the class ImportDepVerifyPromotionToSharedImportsTest method extractBuildArtifactsTriggersImportPromotion.

@Test
public void extractBuildArtifactsTriggersImportPromotion() throws Exception {
    String path = "/org/myproj/myproj/1.0/myproj-1.0.pom";
    String content = "This is a test " + System.currentTimeMillis();
    // setup the expectation that the remote repo pointing at this server will request this file...and define its
    // content.
    server.expect(server.formatUrl(STORE, path), 200, content);
    // create a dummy non-chained build execution and repo session based on it
    BuildExecution execution = new TestBuildExecution();
    RepositorySession session = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    // simulate a build resolving an artifact via the Indy remote repository.
    assertThat(download(UrlUtils.buildUrl(session.getConnectionInfo().getDependencyUrl(), path)), equalTo(content));
    // now, extract the build artifacts. This will trigger promotion of imported stuff to shared-imports.
    RepositoryManagerResult result = session.extractBuildArtifacts(true);
    // do some sanity checks while we're here
    List<Artifact> deps = result.getDependencies();
    assertThat(deps.size(), equalTo(1));
    Artifact a = deps.get(0);
    assertThat(a.getFilename(), equalTo(new File(path).getName()));
    // end result: you should be able to download this artifact from shared-imports now.
    StoreKey sharedImportsKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, SHARED_IMPORTS_ID);
    assertThat(download(indy.content().contentUrl(sharedImportsKey, path)), equalTo(content));
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) File(java.io.File) StoreKey(org.commonjava.indy.model.core.StoreKey) Artifact(org.jboss.pnc.model.Artifact) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 12 with RepositorySession

use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.

the class AllSessionUrlsForBuildAreAlikeTest method formatRepositoryURLForSimpleInfo_AllURLsMatch.

@Test
public void formatRepositoryURLForSimpleInfo_AllURLsMatch() throws Exception {
    // create a dummy non-chained build execution and a repo session based on it
    BuildExecution execution = new TestBuildExecution();
    RepositorySession repositoryConfiguration = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    assertThat(repositoryConfiguration, notNullValue());
    RepositoryConnectionInfo connectionInfo = repositoryConfiguration.getConnectionInfo();
    assertThat(connectionInfo, notNullValue());
    // check that all URLs in the connection info are the same (this might be different in another repo driver)
    String expectedUrl = connectionInfo.getDependencyUrl();
    assertThat(connectionInfo.getToolchainUrl(), equalTo(expectedUrl));
// assertThat(connectionInfo.getDeployPath(), equalTo(expectedUrl));
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositoryConnectionInfo(org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 13 with RepositorySession

use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.

the class BuildGroupIncludesConfSetGroupTest method verifyGroupComposition_ProductVersion_WithConfSet.

@Test
public void verifyGroupComposition_ProductVersion_WithConfSet() throws Exception {
    // create a dummy composed (chained) build execution and a repo session based on it
    BuildExecution execution = new TestBuildExecution("build_myproject_67890");
    Indy indy = driver.getIndy(accessToken);
    RepositorySession repositoryConfiguration = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    String repoId = repositoryConfiguration.getBuildRepositoryId();
    assertThat(repoId, equalTo(execution.getBuildContentId()));
    // check that the build group includes:
    // - the build's hosted repo
    // - the build-set's repo group
    // - the product version repo group
    // - the "shared-releases" repo group
    // - the "shared-imports" repo
    // - the public group
    // ...in that order
    Group buildGroup = indy.stores().load(new StoreKey(MAVEN_PKG_KEY, StoreType.group, repoId), Group.class);
    System.out.printf("Constituents:\n  %s\n", join(buildGroup.getConstituents(), "\n  "));
    assertGroupConstituents(buildGroup, new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, execution.getBuildContentId()), new StoreKey(MAVEN_PKG_KEY, StoreType.group, IndyRepositoryConstants.COMMON_BUILD_GROUP_CONSTITUENTS_GROUP));
}
Also used : Group(org.commonjava.indy.model.core.Group) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) Indy(org.commonjava.indy.client.core.Indy) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) StoreKey(org.commonjava.indy.model.core.StoreKey) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Example 14 with RepositorySession

use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.

the class UploadTwoThenVerifyExtractedArtifactsContainThemTest method extractBuildArtifacts_ContainsTwoUploads.

@Test
public void extractBuildArtifacts_ContainsTwoUploads() throws Exception {
    // create a dummy non-chained build execution and repo session based on it
    BuildExecution execution = new TestBuildExecution();
    RepositorySession rc = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    assertThat(rc, notNullValue());
    String baseUrl = rc.getConnectionInfo().getDeployUrl();
    String pomPath = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.pom";
    String jarPath = "org/commonjava/indy/indy-core/0.17.0/indy-core-0.17.0.jar";
    CloseableHttpClient client = HttpClientBuilder.create().build();
    // this simulates a build deploying one jar and its associated POM
    for (String path : new String[] { pomPath, jarPath }) {
        final String url = UrlUtils.buildUrl(baseUrl, path);
        assertThat("Failed to upload: " + url, ArtifactUploadUtils.put(client, url, "This is a test"), equalTo(true));
    }
    // extract the "built" artifacts we uploaded above.
    RepositoryManagerResult repositoryManagerResult = rc.extractBuildArtifacts(true);
    // check that both files are present in extracted result
    List<Artifact> artifacts = repositoryManagerResult.getBuiltArtifacts();
    System.out.println(artifacts);
    assertThat(artifacts, notNullValue());
    assertThat(artifacts.size(), equalTo(2));
    ProjectVersionRef pvr = new SimpleProjectVersionRef("org.commonjava.indy", "indy-core", "0.17.0");
    Set<String> refs = new HashSet<>();
    refs.add(new SimpleArtifactRef(pvr, "pom", null).toString());
    refs.add(new SimpleArtifactRef(pvr, "jar", null).toString());
    // check that the artifact getIdentifier() stores GAVT[C] information in the standard Maven rendering
    for (Artifact artifact : artifacts) {
        assertThat(artifact + " is not in the expected list of built artifacts: " + refs, refs.contains(artifact.getIdentifier()), equalTo(true));
    }
    // check that we can download the two files from the build repository
    for (String path : new String[] { pomPath, jarPath }) {
        StoreKey hostedKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, rc.getBuildRepositoryId());
        final String url = indy.content().contentUrl(hostedKey, path);
        boolean downloaded = client.execute(new HttpGet(url), response -> {
            try {
                return response.getStatusLine().getStatusCode() == 200;
            } finally {
                if (response instanceof CloseableHttpResponse) {
                    IOUtils.closeQuietly((CloseableHttpResponse) response);
                }
            }
        });
        assertThat("Failed to download: " + url, downloaded, equalTo(true));
    }
    client.close();
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) HttpGet(org.apache.http.client.methods.HttpGet) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) SimpleProjectVersionRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) StoreKey(org.commonjava.indy.model.core.StoreKey) Artifact(org.jboss.pnc.model.Artifact) ProjectVersionRef(org.commonjava.atlas.maven.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HashSet(java.util.HashSet) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Example 15 with RepositorySession

use of org.jboss.pnc.spi.repositorymanager.model.RepositorySession in project pnc by project-ncl.

the class VerifyBuildGroupRemovedAfterArtifactExtractionTest method extractBuildArtifactsTriggersBuildRepoPromotionToChainGroup.

@Test
public void extractBuildArtifactsTriggersBuildRepoPromotionToChainGroup() throws Exception {
    String path = "/org/myproj/myproj/1.0/myproj-1.0.pom";
    String content = "This is a test " + System.currentTimeMillis();
    String buildId = "build";
    // create a dummy composed (chained) build execution, and a repo session based on it
    BuildExecution execution = new TestBuildExecution(buildId);
    RepositorySession session = driver.createBuildRepository(execution, accessToken, accessToken, RepositoryType.MAVEN, Collections.emptyMap(), false);
    // simulate a build deploying a file.
    indy.module(IndyFoloContentClientModule.class).store(buildId, new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, buildId), path, new ByteArrayInputStream(content.getBytes()));
    // now, extract the build artifacts. This will trigger promotion of the build hosted repo to the chain group.
    RepositoryManagerResult result = session.extractBuildArtifacts(true);
    // do some sanity checks while we're here
    List<Artifact> deps = result.getBuiltArtifacts();
    assertThat(deps.size(), equalTo(1));
    Artifact a = deps.get(0);
    assertThat(a.getFilename(), equalTo(new File(path).getName()));
    // end result: the build aggregation group should have been garbage collected
    StoreKey groupKey = new StoreKey(MAVEN_PKG_KEY, StoreType.group, buildId);
    boolean buildGroupExists = indy.stores().exists(groupKey);
    assertThat(buildGroupExists, equalTo(false));
}
Also used : TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) IndyFoloContentClientModule(org.commonjava.indy.folo.client.IndyFoloContentClientModule) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) StoreKey(org.commonjava.indy.model.core.StoreKey) File(java.io.File) Artifact(org.jboss.pnc.model.Artifact) Test(org.junit.Test) ContainerTest(org.jboss.pnc.test.category.ContainerTest)

Aggregations

RepositorySession (org.jboss.pnc.spi.repositorymanager.model.RepositorySession)26 TestBuildExecution (org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution)20 BuildExecution (org.jboss.pnc.spi.repositorymanager.BuildExecution)20 Test (org.junit.Test)19 ContainerTest (org.jboss.pnc.test.category.ContainerTest)18 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)13 StoreKey (org.commonjava.indy.model.core.StoreKey)12 Artifact (org.jboss.pnc.model.Artifact)11 Indy (org.commonjava.indy.client.core.Indy)8 Group (org.commonjava.indy.model.core.Group)7 File (java.io.File)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ProjectVersionRef (org.commonjava.atlas.maven.ident.ref.ProjectVersionRef)4 SimpleArtifactRef (org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef)4 SimpleProjectVersionRef (org.commonjava.atlas.maven.ident.ref.SimpleProjectVersionRef)4 IndyFoloContentClientModule (org.commonjava.indy.folo.client.IndyFoloContentClientModule)4 RunningEnvironment (org.jboss.pnc.spi.environment.RunningEnvironment)4 RepositoryConnectionInfo (org.jboss.pnc.spi.repositorymanager.model.RepositoryConnectionInfo)4 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 BuildProcessException (org.jboss.pnc.executor.exceptions.BuildProcessException)3