use of org.commonjava.maven.galley.maven.model.view.RepositoryView in project galley by Commonjava.
the class MavenModelProcessorTest method resolveRepositoriesExpressionFromPropertyInProfile.
@Test
public void resolveRepositoriesExpressionFromPropertyInProfile() throws Exception {
final URI src = new URI("http://nowhere.com/path/to/repo");
final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-pom", "1.0");
final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
lineage.put(childRef, "test-pom-1.0.pom.xml");
final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true, false);
final String base = PROJ_BASE + "resolve-expression-in-a-profile/";
for (final Entry<ProjectVersionRef, String> entry : lineage.entrySet()) {
final ProjectVersionRef ref = entry.getKey();
final String filename = entry.getValue();
final String path = ArtifactPathUtils.formatArtifactPath(ref.asPomArtifact(), fixture.getTypeMapper());
fixture.getTransport().registerDownload(new ConcreteResource(location, path), new TestDownload(base + filename));
}
final Transfer transfer = fixture.getArtifactManager().retrieve(location, childRef.asPomArtifact());
final MavenPomView pomView = fixture.getPomReader().read(childRef, transfer, Collections.singletonList(location));
final List<RepositoryView> rvs = pomView.getAllRepositories();
assertThat(rvs, notNullValue());
assertThat(rvs.size(), equalTo(3));
assertThat(rvs.get(0).getName(), equalTo("repo.one"));
assertThat(rvs.get(0).getUrl(), equalTo("http://repo.one.repository"));
assertThat(rvs.get(1).getName(), equalTo("test.oracle.repo"));
assertThat(rvs.get(1).getUrl(), equalTo("http://test.oracle.repository"));
assertThat(rvs.get(2).getName(), equalTo("test.second.oracle.repo"));
assertThat(rvs.get(2).getUrl(), equalTo("http://another.test.two.oracle.repository"));
}
use of org.commonjava.maven.galley.maven.model.view.RepositoryView in project indy by Commonjava.
the class ImpliedRepositoryDetector method addImpliedRepositories.
private void addImpliedRepositories(final ImplicationsJob job) {
job.implied = new ArrayList<>();
logger.debug("Retrieving repository/pluginRepository declarations from:\n {}", new JoinString("\n ", job.pomView.getDocRefStack()));
final List<List<RepositoryView>> repoLists = Arrays.asList(job.pomView.getNonProfileRepositories(), job.pomView.getAllPluginRepositories());
final ImpliedRepositoryCreator creator = createRepoCreator();
if (creator == null) {
logger.error("Cannot proceed without a valid ImpliedRepositoryCreator instance. Aborting detection.");
return;
}
for (final List<RepositoryView> repos : repoLists) {
if (repos == null || repos.isEmpty()) {
continue;
}
for (final RepositoryView repo : repos) {
final ProjectVersionRef gav = job.pathInfo.getProjectId();
try {
if (config.isBlacklisted(repo.getUrl())) {
logger.debug("Discarding blacklisted repository: {}", repo);
continue;
} else if (!config.isIncludeSnapshotRepos() && !repo.isReleasesEnabled()) {
logger.debug("Discarding snapshot repository: {}", repo);
continue;
}
} catch (final MalformedURLException e) {
logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to check if repository is blacklisted.", repo.getUrl(), gav, job.transfer), e);
}
logger.debug("Detected POM-declared repository: {}", repo);
List<RemoteRepository> rrs = null;
try {
rrs = storeManager.query().getRemoteRepositoryByUrl(MAVEN_PKG_KEY, repo.getUrl());
} catch (IndyDataException e) {
logger.error(String.format("Cannot lookup remote repositories by URL: %s. Reason: %s", e.getMessage()), e);
}
final RemoteRepository ref = creator.createFrom(gav, repo, LoggerFactory.getLogger(creator.getClass()));
if (ref == null) {
logger.warn("ImpliedRepositoryCreator didn't create anything for repo: {}, specified in: {}. Skipping.", repo.getId(), gav);
continue;
}
if (rrs != null && !rrs.isEmpty()) {
rrs = rrs.stream().filter(rr -> rr.isAllowReleases() == ref.isAllowReleases()).filter(rr -> rr.isAllowSnapshots() == ref.isAllowSnapshots()).filter(rr -> (isEmpty(rr.getPathMaskPatterns()) && isEmpty(ref.getPathMaskPatterns())) || rr.getPathMaskPatterns().equals(ref.getPathMaskPatterns())).collect(Collectors.toList());
}
if (rrs == null || rrs.isEmpty()) {
logger.debug("Creating new RemoteRepository for: {}", repo);
final RemoteRepository rr = ref.copyOf();
rr.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
try {
rr.setMetadata(IMPLIED_BY_STORES, mapper.writeValueAsString(new ImpliedRepoMetadataManager.ImpliedRemotesWrapper(Collections.singletonList(job.store.getKey()))));
} catch (JsonProcessingException e) {
logger.error("Failed to set {}", IMPLIED_BY_STORES);
continue;
}
if (!remoteValidator.isValid(rr)) {
logger.warn("Implied repository to: {} is invalid! Repository created was: {}", repo.getUrl(), rr);
continue;
}
final String changelog = String.format("Adding remote repository: %s (url: %s, name: %s), which is implied by the POM: %s (at: %s/%s)", repo.getId(), repo.getUrl(), repo.getName(), gav, job.transfer.getLocation().getUri(), job.transfer.getPath());
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, changelog);
try {
final boolean result = storeManager.storeArtifactStore(rr, summary, true, false, new EventMetadata().set(StoreDataManager.EVENT_ORIGIN, IMPLIED_REPOS_DETECTION).set(IMPLIED_BY_POM_TRANSFER, job.transfer));
logger.debug("Stored new RemoteRepository: {}. (successful? {})", rr, result);
job.implied.add(rr);
} catch (final IndyDataException e) {
logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to store new remote repository.", repo.getUrl(), gav, job.transfer), e);
}
} else {
logger.debug("Found existing RemoteRepositories: {}", rrs);
for (final RemoteRepository rr : rrs) {
rr.setMetadata(METADATA_ORIGIN, IMPLIED_REPO_ORIGIN);
try {
metadataManager.updateImpliedBy(rr, job.store);
} catch (ImpliedReposException e) {
logger.error("Failed to set {}", IMPLIED_BY_STORES);
continue;
}
final String changelog = String.format("Updating the existing remote repository: %s (url: %s, name: %s), which is implied by the POM: %s (at: %s/%s)", repo.getId(), repo.getUrl(), repo.getName(), gav, job.transfer.getLocation().getUri(), job.transfer.getPath());
final ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, changelog);
try {
final boolean result = storeManager.storeArtifactStore(rr, summary, false, false, null);
logger.debug("Updated the RemoteRepository: {}. (successful? {})", rr, result);
job.implied.add(rr);
} catch (final IndyDataException e) {
logger.error(String.format("Cannot add implied remote repo: %s from: %s (transfer: %s). Failed to update the remote repository.", repo.getUrl(), gav, job.transfer), e);
}
}
}
}
}
}
Aggregations