use of org.apache.maven.model.building.UrlModelSource in project spring-boot by spring-projects.
the class DependencyManagementBomTransformation method updateDependencyResolutionContext.
private void updateDependencyResolutionContext(List<Map<String, String>> bomDependencies) {
URI[] uris = Grape.getInstance().resolve(null, bomDependencies.toArray(new Map[bomDependencies.size()]));
DefaultModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance();
for (URI uri : uris) {
try {
DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
request.setModelResolver(new GrapeModelResolver());
request.setModelSource(new UrlModelSource(uri.toURL()));
request.setSystemProperties(System.getProperties());
Model model = modelBuilder.build(request).getEffectiveModel();
this.resolutionContext.addDependencyManagement(new MavenModelDependencyManagement(model));
} catch (Exception ex) {
throw new IllegalStateException("Failed to build model for '" + uri + "'. Is it a valid Maven bom?", ex);
}
}
}
use of org.apache.maven.model.building.UrlModelSource in project bazel by bazelbuild.
the class DefaultModelResolver method getModelSource.
// TODO(kchodorow): make this work with local repositories.
private UrlModelSource getModelSource(String url, String groupId, String artifactId, String version) throws UnresolvableModelException {
try {
if (!url.endsWith("/")) {
url += "/";
}
URL urlUrl = new URL(url + groupId.replaceAll("\\.", "/") + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".pom");
if (pomFileExists(urlUrl)) {
UrlModelSource urlModelSource = new UrlModelSource(urlUrl);
ruleNameToModelSource.put(Rule.name(groupId, artifactId), urlModelSource);
return urlModelSource;
}
} catch (MalformedURLException e) {
throw new UnresolvableModelException("Bad URL " + url + ": " + e.getMessage(), groupId, artifactId, version, e);
}
return null;
}
use of org.apache.maven.model.building.UrlModelSource in project bazel by bazelbuild.
the class DefaultModelResolver method resolveModel.
@Override
public ModelSource resolveModel(String groupId, String artifactId, String version) throws UnresolvableModelException {
String ruleName = Rule.name(groupId, artifactId);
if (ruleNameToModelSource.containsKey(ruleName)) {
return ruleNameToModelSource.get(ruleName);
}
for (Repository repository : repositories) {
UrlModelSource modelSource = getModelSource(repository.getUrl(), groupId, artifactId, version);
if (modelSource != null) {
return modelSource;
}
}
// TODO(kchodorow): use Java 8 features to make this a one-liner.
List<String> attemptedUrls = Lists.newArrayList();
for (Repository repository : repositories) {
attemptedUrls.add(repository.getUrl());
}
throw new UnresolvableModelException("Could not find any repositories that knew how to " + "resolve " + groupId + ":" + artifactId + ":" + version + " (checked " + Joiner.on(", ").join(attemptedUrls) + ")", groupId, artifactId, version);
}
Aggregations