Search in sources :

Example 1 with RepositoryManager

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

the class DefaultBuildExecutor method configureRepository.

private RepositorySession configureRepository(DefaultBuildExecutionSession buildExecutionSession) {
    if (buildExecutionSession.isCanceled()) {
        return null;
    }
    ProcessStageUtils.logProcessStageBegin(BuildExecutionStatus.REPO_SETTING_UP.toString(), "Setting up repository...");
    buildExecutionSession.setStatus(BuildExecutionStatus.REPO_SETTING_UP);
    BuildType buildType = buildExecutionSession.getBuildExecutionConfiguration().getBuildType();
    if (buildType == null) {
        throw new BuildProcessException("Missing required value buildExecutionConfiguration.buildType");
    }
    RepositoryType repositoryType = BuildTypeToRepositoryType.getRepositoryType(buildType);
    try {
        RepositoryManager repositoryManager = repositoryManagerFactory.getRepositoryManager(repositoryType);
        BuildExecution buildExecution = buildExecutionSession.getBuildExecutionConfiguration();
        String serviceAccountToken = (serviceClient == null ? null : serviceClient.getAuthToken());
        RepositorySession buildRepository = repositoryManager.createBuildRepositoryWithRetries(buildExecution, buildExecutionSession.getAccessToken(), serviceAccountToken, repositoryType, buildExecutionSession.getBuildExecutionConfiguration().getGenericParameters(), buildExecutionSession.getBuildExecutionConfiguration().isBrewPullActive());
        return buildRepository;
    } catch (Throwable e) {
        throw new BuildProcessException(e);
    } finally {
        ProcessStageUtils.logProcessStageEnd(BuildExecutionStatus.REPO_SETTING_UP.toString(), "Repository setup complete.");
    }
}
Also used : RepositoryType(org.jboss.pnc.enums.RepositoryType) BuildType(org.jboss.pnc.enums.BuildType) BuildExecution(org.jboss.pnc.spi.repositorymanager.BuildExecution) RepositoryManager(org.jboss.pnc.spi.repositorymanager.RepositoryManager) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) BuildProcessException(org.jboss.pnc.executor.exceptions.BuildProcessException)

Example 2 with RepositoryManager

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

the class IndyPromotionValidationTest method testIndyPromotionValidation.

@Test
public /**
 * Test whose purpose is to provide a means for more or less easy debugging of indy validation errors. For it to
 * work it needs a standalone Indy server, with a rule-set definition such as this: { "storeKeyPattern":
 * "group:builds-untested", "ruleNames": [ "no-snapshots.groovy", "parsable-pom.groovy" ], "validationParameters":
 * {} } Provide the base URL to this Indy server as a System parameter such as e.g.
 * -DbaseUrl="http://127.0.0.1:8090"
 */
void testIndyPromotionValidation() {
    String baseUrl = System.getProperty("baseUrl");
    if (StringUtils.isBlank(baseUrl)) {
        fail("No base URL has been specified");
    }
    RepositoryManager driver = null;
    try {
        driver = new RepositoryManagerDriver(new TestConfiguration(baseUrl), new BuildRecordRepositoryMock());
        RepositorySession repositorySession = driver.createBuildRepository(new TestBuildExecution("test"), null, null, RepositoryType.MAVEN, Collections.emptyMap(), false);
        CloseableHttpClient client = HttpClientBuilder.create().build();
        String deployUrl = repositorySession.getConnectionInfo().getDeployUrl();
        // Deploy several 'wrong' artifacts to get a composed error message back
        String pathPom1 = "org/foo/invalid/1/invalid-1.pom";
        String snapshotPom = "<?xml version=\"1.0\"?>\n<project><modelVersion>4.0.0</modelVersion><groupId>org.foo</groupId>" + "<artifactId>invalid</artifactId><version>1</version><dependencies>" + "<dependency><groupId>org.bar</groupId><artifactId>dep</artifactId>" + "<version>1.0-SNAPSHOT</version></dependency></dependencies></project>";
        String url = UrlUtils.buildUrl(deployUrl, pathPom1);
        put(client, url, snapshotPom);
        String pathPom2 = "org/foo/invalid2/1/invalid2-1.pom";
        String snapshotPom2 = "<?xml version=\"1.0\"?>\n<project><modelVersion>4.0.0</modelVersion><groupId>org.foo</groupId>" + "<artifactId>invalid2</artifactId><version>1</version><dependencies>" + "<dependency><groupId>org.bar</groupId><artifactId>dep</artifactId>" + "<version>1.0-SNAPSHOT</version></dependency></dependencies></project>";
        url = UrlUtils.buildUrl(deployUrl, pathPom2);
        put(client, url, snapshotPom2);
        String pathPom3 = "org/foo/nonparseable/1/nonparseable.pom";
        String nonparseablePom = "<?xml version=\"1.0\"?>\n<project><modelVersion>4.0.0</modelVersion><groupId>org.foo</groupId>" + "<artifactId>nonparseable</artifactId><version>1</version><dependencies>" + "<dependency><groupId>org.bar</groupId><artifactId>dep</artifactId>" + "<version>1.0</version></dependency></dependencies></project>";
        url = UrlUtils.buildUrl(deployUrl, pathPom3);
        put(client, url, nonparseablePom);
        RepositoryManagerResult repositoryManagerResult = repositorySession.extractBuildArtifacts(true);
        // Just a dummy check, the point is really to be able to debug this
        assertSame(CompletionStatus.FAILED, repositoryManagerResult.getCompletionStatus());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) BuildRecordRepositoryMock(org.jboss.pnc.mock.repository.BuildRecordRepositoryMock) TestBuildExecution(org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) RepositoryManager(org.jboss.pnc.spi.repositorymanager.RepositoryManager) RepositorySession(org.jboss.pnc.spi.repositorymanager.model.RepositorySession) ConfigurationParseException(org.jboss.pnc.common.json.ConfigurationParseException) IOException(java.io.IOException) DebugTest(org.jboss.pnc.test.category.DebugTest) Test(org.junit.Test)

Aggregations

RepositoryManager (org.jboss.pnc.spi.repositorymanager.RepositoryManager)2 RepositorySession (org.jboss.pnc.spi.repositorymanager.model.RepositorySession)2 IOException (java.io.IOException)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 ConfigurationParseException (org.jboss.pnc.common.json.ConfigurationParseException)1 BuildType (org.jboss.pnc.enums.BuildType)1 RepositoryType (org.jboss.pnc.enums.RepositoryType)1 BuildProcessException (org.jboss.pnc.executor.exceptions.BuildProcessException)1 TestBuildExecution (org.jboss.pnc.indyrepositorymanager.fixture.TestBuildExecution)1 BuildRecordRepositoryMock (org.jboss.pnc.mock.repository.BuildRecordRepositoryMock)1 BuildExecution (org.jboss.pnc.spi.repositorymanager.BuildExecution)1 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)1 DebugTest (org.jboss.pnc.test.category.DebugTest)1 Test (org.junit.Test)1