use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.
the class DeprecatedStoreAdminHandler method getAll.
@ApiOperation("Retrieve the definitions of all artifact stores of a given type on the system")
@ApiResponses({ @ApiResponse(code = 200, response = StoreListingDTO.class, message = "The store definitions") })
@GET
@Produces(ApplicationContent.application_json)
public Response getAll(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type) {
String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type).toString();
Consumer<Response.ResponseBuilder> modifier = (rb) -> markDeprecated(rb, altPath);
final StoreType st = StoreType.get(type);
Response response;
try {
final List<ArtifactStore> stores = adminController.getAllOfType(st);
logger.info("Returning listing containing stores:\n\t{}", new JoinString("\n\t", stores));
final StoreListingDTO<ArtifactStore> dto = new StoreListingDTO<>(stores);
response = formatOkResponseWithJsonEntity(dto, objectMapper, modifier);
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e, modifier);
}
return response;
}
use of org.commonjava.maven.atlas.ident.util.JoinString in project indy by Commonjava.
the class IndyLocationExpander method expand.
/**
* For group references, expand into a list of concrete repository locations (hosted or remote). For remote repository references that are
* specified as cache-only locations (see: {@link CacheOnlyLocation}), lookup the corresponding {@link RemoteRepository} and use it to create a
* {@link RepositoryLocation} that contains any relevant SSL, authentication, proxy, etc. attbributes.
*/
@Override
public <T extends Location> List<Location> expand(final Collection<T> locations) throws TransferException {
final List<Location> result = new ArrayList<Location>();
for (final Location location : locations) {
if (location instanceof GroupLocation) {
final GroupLocation gl = (GroupLocation) location;
try {
logger.debug("Expanding group: {}", gl.getKey());
final List<ArtifactStore> members = data.query().packageType(gl.getKey().getPackageType()).getOrderedConcreteStoresInGroup(gl.getKey().getName());
if (members != null) {
for (final ArtifactStore member : members) {
if (!result.contains(member)) {
logger.debug("expansion += {}", member.getKey());
result.add(LocationUtils.toLocation(member));
}
}
logger.debug("Expanded group: {} to:\n {}", gl.getKey(), new JoinString("\n ", result));
}
} catch (final IndyDataException e) {
throw new TransferException("Failed to lookup ordered concrete artifact stores contained in group: {}. Reason: {}", e, gl, e.getMessage());
}
} else if (location instanceof CacheOnlyLocation && !((CacheOnlyLocation) location).isHostedRepository()) {
final StoreKey key = ((KeyedLocation) location).getKey();
try {
final ArtifactStore store = data.getArtifactStore(key);
if (store == null) {
throw new TransferException("Cannot find ArtifactStore to match key: %s.", key);
}
logger.debug("Adding single store: {} for location: {}", store, location);
result.add(LocationUtils.toLocation(store));
} catch (final IndyDataException e) {
throw new TransferException("Failed to lookup store for key: {}. Reason: {}", e, key, e.getMessage());
}
} else {
logger.debug("No expansion available for location: {}", location);
result.add(location);
}
}
return result;
}
use of org.commonjava.maven.atlas.ident.util.JoinString in project galley by Commonjava.
the class MavenModelProcessorTest method resolvePluginDependencyFromManagedInfo.
@Test
public void resolvePluginDependencyFromManagedInfo() throws Exception {
final URI src = new URI("http://nowhere.com/path/to/repo");
final ProjectVersionRef childRef = new SimpleProjectVersionRef("org.test", "test-child", "1.0");
final LinkedHashMap<ProjectVersionRef, String> lineage = new LinkedHashMap<ProjectVersionRef, String>();
lineage.put(childRef, "child.pom.xml");
lineage.put(new SimpleProjectVersionRef("org.test", "test-parent", "1.0"), "parent.pom.xml");
final Location location = new SimpleLocation("test", src.toString(), false, true, true, false, true);
final String base = PROJ_BASE + "dependency-in-managed-parent-plugin/";
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<PluginView> buildPlugins = pomView.getAllBuildPlugins();
assertThat(buildPlugins, notNullValue());
assertThat(buildPlugins.size(), equalTo(1));
final PluginView pv = buildPlugins.get(0);
assertThat(pv, notNullValue());
final List<PluginDependencyView> deps = pv.getLocalPluginDependencies();
assertThat(deps, notNullValue());
assertThat(deps.size(), equalTo(1));
final PluginDependencyView pdv = deps.get(0);
assertThat(pdv, notNullValue());
assertThat(pdv.asArtifactRef().getVersionString(), equalTo("1.0"));
final ModelProcessorConfig discoveryConfig = new ModelProcessorConfig();
discoveryConfig.setIncludeManagedDependencies(true);
discoveryConfig.setIncludeBuildSection(true);
discoveryConfig.setIncludeManagedPlugins(false);
EProjectDirectRelationships result = fixture.getModelProcessor().readRelationships(pomView, src, discoveryConfig);
final Set<ProjectRelationship<?, ?>> rels = result.getExactAllRelationships();
logger.info("Found {} relationships:\n\n {}", rels.size(), new JoinString("\n ", rels));
boolean seen = false;
for (final ProjectRelationship<?, ?> rel : rels) {
if (rel.getType() == RelationshipType.PLUGIN_DEP && !rel.isManaged()) {
if (seen) {
fail("Multiple plugin dependencies found!");
}
seen = true;
assertThat(rel.getTarget().getVersionString(), equalTo("1.0"));
}
}
if (!seen) {
fail("Plugin-dependency relationship not found!");
}
}
use of org.commonjava.maven.atlas.ident.util.JoinString in project galley by Commonjava.
the class MavenMetadataReader method getMetadata.
public MavenMetadataView getMetadata(final ProjectRef ref, final List<? extends Location> locations, final EventMetadata eventMetadata) throws GalleyMavenException {
final List<DocRef<ProjectRef>> docs = new ArrayList<DocRef<ProjectRef>>(locations.size());
final Map<Location, DocRef<ProjectRef>> cached = getAllCached(ref, locations);
final List<? extends Location> toRetrieve = new ArrayList<Location>(locations);
for (final Location loc : locations) {
final DocRef<ProjectRef> dr = cached.get(loc);
if (dr != null) {
docs.add(dr);
toRetrieve.remove(loc);
} else {
docs.add(null);
}
}
List<Transfer> transfers;
try {
transfers = metadataManager.retrieveAll(toRetrieve, ref, eventMetadata);
} catch (final TransferException e) {
throw new GalleyMavenException("Failed to resolve metadata for: {} from: {}. Reason: {}", e, ref, locations, e.getMessage());
}
logger.debug("Resolved {} transfers:\n {}", transfers.size(), new JoinString("\n ", transfers));
if (transfers != null && !transfers.isEmpty()) {
for (final Transfer transfer : transfers) {
final DocRef<ProjectRef> dr = new DocRef<ProjectRef>(ref, transfer.getLocation(), xml.parse(transfer, eventMetadata));
final int idx = locations.indexOf(transfer.getLocation());
//
if (idx > -1) {
docs.set(idx, dr);
} else {
docs.add(dr);
}
}
}
for (final Iterator<DocRef<ProjectRef>> iterator = docs.iterator(); iterator.hasNext(); ) {
final DocRef<ProjectRef> docRef = iterator.next();
if (docRef == null) {
iterator.remove();
}
}
logger.debug("Got {} metadata documents for: {}", docs.size(), ref);
return new MavenMetadataView(docs, xpath, xml);
}
use of org.commonjava.maven.atlas.ident.util.JoinString in project galley by Commonjava.
the class MavenModelProcessor method addPlugins.
private void addPlugins(final List<PluginView> plugins, final ProjectVersionRef projectRef, final Builder builder, final URI source, final boolean managed) {
if (plugins != null) {
for (final PluginView plugin : plugins) {
ProjectVersionRef pluginRef = null;
try {
if (plugin.getVersion() == null) {
logger.error("%s: Cannot find a version for plugin: {}. Skipping.", projectRef, plugin.toXML());
continue;
}
pluginRef = plugin.asProjectVersionRef();
// force the InvalidVersionSpecificationException.
pluginRef.getVersionSpec();
final String profileId = plugin.getProfileId();
final URI location = RelationshipUtils.profileLocation(profileId);
boolean inherited = plugin.getOriginInfo().isInherited();
boolean mixin = plugin.getOriginInfo().isMixin();
builder.withPlugins(new SimplePluginRelationship(source, location, projectRef, pluginRef, builder.getNextPluginDependencyIndex(projectRef, managed, inherited), managed, inherited));
} catch (final GalleyMavenException e) {
logger.error(String.format("%s: plugin is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), plugin.toXML()), e);
continue;
} catch (final InvalidVersionSpecificationException e) {
logger.error(String.format("%s: plugin is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), plugin.toXML()), e);
continue;
} catch (final InvalidRefException e) {
logger.error(String.format("%s: plugin is invalid! Reason: %s. Skipping:\n\n%s\n\n", projectRef, e.getMessage(), plugin.toXML()), e);
continue;
}
List<PluginDependencyView> pluginDependencies = null;
Set<PluginDependencyView> impliedPluginDependencies = null;
try {
pluginDependencies = plugin.getLocalPluginDependencies();
impliedPluginDependencies = plugin.getImpliedPluginDependencies();
} catch (final GalleyMavenException e) {
logger.error(String.format("%s: Cannot retrieve plugin dependencies for: %s. Reason: %s", projectRef, pluginRef, e.getMessage()), e);
} catch (final InvalidVersionSpecificationException e) {
logger.error(String.format("%s: Cannot retrieve plugin dependencies for: %s. Reason: %s", projectRef, pluginRef, e.getMessage()), e);
} catch (final InvalidRefException e) {
logger.error(String.format("%s: Cannot retrieve plugin dependencies for: %s. Reason: %s", projectRef, pluginRef, e.getMessage()), e);
}
addPluginDependencies(pluginDependencies, plugin, pluginRef, projectRef, builder, source, managed);
logger.debug("{}: Adding implied dependencies for: {}\n\n {}", projectRef, pluginRef, impliedPluginDependencies == null ? "-NONE-" : new JoinString("\n ", impliedPluginDependencies));
addPluginDependencies(impliedPluginDependencies, plugin, pluginRef, projectRef, builder, source, managed);
}
}
}
Aggregations