use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class ExcludeInternalRepoByRegexTest method extractBuildArtifacts_ContainsTwoDownloads.
@Test
public void extractBuildArtifacts_ContainsTwoDownloads() throws Exception {
// create a remote repo pointing at our server fixture's 'repo/test' directory.
indy.stores().create(new RemoteRepository(MAVEN_PKG_KEY, INTERNAL, server.formatUrl(INTERNAL)), "Creating internal test remote repo", RemoteRepository.class);
indy.stores().create(new RemoteRepository(MAVEN_PKG_KEY, EXTERNAL, server.formatUrl(EXTERNAL)), "Creating external test remote repo", RemoteRepository.class);
StoreKey publicKey = new StoreKey(MAVEN_PKG_KEY, StoreType.group, PUBLIC_GROUP_ID);
StoreKey internalKey = new StoreKey(MAVEN_PKG_KEY, StoreType.remote, INTERNAL);
StoreKey externalKey = new StoreKey(MAVEN_PKG_KEY, StoreType.remote, EXTERNAL);
Group publicGroup = indy.stores().load(publicKey, Group.class);
if (publicGroup == null) {
publicGroup = new Group(MAVEN_PKG_KEY, PUBLIC_GROUP_ID, internalKey, externalKey);
indy.stores().create(publicGroup, "creating public group", Group.class);
} else {
publicGroup.setConstituents(Arrays.asList(internalKey, externalKey));
indy.stores().update(publicGroup, "adding test remotes to public group");
}
String internalPath = "org/foo/internal/1.0/internal-1.0.pom";
String externalPath = "org/foo/external/1.1/external-1.1.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(INTERNAL, internalPath), 200, content);
server.expect(server.formatUrl(EXTERNAL, externalPath), 200, content);
// 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().getDependencyUrl();
// download the two files via the repo session's dependency URL, which will proxy the test http server
// using the expectations above
assertThat(download(UrlUtils.buildUrl(baseUrl, internalPath)), equalTo(content));
assertThat(download(UrlUtils.buildUrl(baseUrl, externalPath)), equalTo(content));
// extract the build artifacts, which should contain the two imported deps.
// This will also trigger promoting imported artifacts into the shared-imports hosted repo
RepositoryManagerResult repositoryManagerResult = rc.extractBuildArtifacts(true);
List<Artifact> deps = repositoryManagerResult.getDependencies();
System.out.println(deps);
assertThat(deps, notNullValue());
assertThat(deps.size(), equalTo(2));
Indy indy = driver.getIndy(accessToken);
StoreKey sharedImportsKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, SHARED_IMPORTS_ID);
// check that the imports from external locations are available from shared-imports
InputStream stream = indy.content().get(sharedImportsKey, externalPath);
String downloaded = IOUtils.toString(stream, (String) null);
assertThat(downloaded, equalTo(content));
stream.close();
// check that the imports from internal/trusted locations are NOT available from shared-imports
stream = indy.content().get(sharedImportsKey, internalPath);
assertThat(stream, nullValue());
}
use of org.jboss.pnc.model.Artifact 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));
}
use of org.jboss.pnc.model.Artifact 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();
}
use of org.jboss.pnc.model.Artifact 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));
}
use of org.jboss.pnc.model.Artifact in project pnc by project-ncl.
the class VerifyBuildRepoPromotionToUntestedBuildsGroupTest 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 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);
StoreKey hostedKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, buildId);
// simulate a build deploying a file.
indy.module(IndyFoloContentClientModule.class).store(buildId, hostedKey, path, new ByteArrayInputStream(content.getBytes()));
// now, extract the build artifacts. This will trigger promotion of the build hosted repo to the pnc-builds
// group.
RepositoryManagerResult result = session.extractBuildArtifacts(true);
assertThat(result.getCompletionStatus(), equalTo(CompletionStatus.SUCCESS));
// 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 pnc-builds group should contain the build hosted repo.
StoreKey pncBuildsKey = new StoreKey(MAVEN_PKG_KEY, StoreType.hosted, PNC_BUILDS);
assertThat(indy.content().exists(pncBuildsKey, path), equalTo(true));
}
Aggregations