Search in sources :

Example 1 with UrlModelSource

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);
        }
    }
}
Also used : DefaultModelBuilderFactory(org.apache.maven.model.building.DefaultModelBuilderFactory) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) MavenModelDependencyManagement(org.springframework.boot.cli.compiler.dependencies.MavenModelDependencyManagement) Model(org.apache.maven.model.Model) HashMap(java.util.HashMap) Map(java.util.Map) URI(java.net.URI) DefaultModelBuilder(org.apache.maven.model.building.DefaultModelBuilder) UrlModelSource(org.apache.maven.model.building.UrlModelSource) InvalidRepositoryException(org.apache.maven.model.resolution.InvalidRepositoryException) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) MalformedURLException(java.net.MalformedURLException) SyntaxException(org.codehaus.groovy.syntax.SyntaxException)

Example 2 with UrlModelSource

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) UrlModelSource(org.apache.maven.model.building.UrlModelSource) URL(java.net.URL)

Example 3 with UrlModelSource

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);
}
Also used : Repository(org.apache.maven.model.Repository) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) UrlModelSource(org.apache.maven.model.building.UrlModelSource)

Aggregations

UrlModelSource (org.apache.maven.model.building.UrlModelSource)3 UnresolvableModelException (org.apache.maven.model.resolution.UnresolvableModelException)3 MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Model (org.apache.maven.model.Model)1 Repository (org.apache.maven.model.Repository)1 DefaultModelBuilder (org.apache.maven.model.building.DefaultModelBuilder)1 DefaultModelBuilderFactory (org.apache.maven.model.building.DefaultModelBuilderFactory)1 DefaultModelBuildingRequest (org.apache.maven.model.building.DefaultModelBuildingRequest)1 InvalidRepositoryException (org.apache.maven.model.resolution.InvalidRepositoryException)1 SyntaxException (org.codehaus.groovy.syntax.SyntaxException)1 MavenModelDependencyManagement (org.springframework.boot.cli.compiler.dependencies.MavenModelDependencyManagement)1