Search in sources :

Example 6 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project spring-cloud-function by spring-cloud.

the class DependencyResolutionModule method dependencies.

public List<Dependency> dependencies(final Resource resource, final Properties properties) {
    initialize();
    try {
        ProjectBuildingRequest request = getProjectBuildingRequest(properties);
        request.setResolveDependencies(true);
        synchronized (DependencyResolver.class) {
            ProjectBuildingResult result = projectBuilder.build(new PropertiesModelSource(properties, resource), request);
            DependencyResolver.globals = null;
            DependencyResolutionResult dependencies = result.getDependencyResolutionResult();
            if (!dependencies.getUnresolvedDependencies().isEmpty()) {
                StringBuilder builder = new StringBuilder();
                for (Dependency dependency : dependencies.getUnresolvedDependencies()) {
                    List<Exception> errors = dependencies.getResolutionErrors(dependency);
                    for (Exception exception : errors) {
                        if (builder.length() > 0) {
                            builder.append("\n");
                        }
                        builder.append(exception.getMessage());
                    }
                }
                throw new RuntimeException(builder.toString());
            }
            return runtime(dependencies.getDependencies());
        }
    } catch (ProjectBuildingException | NoLocalRepositoryManagerException e) {
        throw new IllegalStateException("Cannot build model", e);
    }
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) Dependency(org.eclipse.aether.graph.Dependency) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) NoLocalRepositoryManagerException(org.eclipse.aether.repository.NoLocalRepositoryManagerException) IOException(java.io.IOException) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ProjectBuildingResult(org.apache.maven.project.ProjectBuildingResult) NoLocalRepositoryManagerException(org.eclipse.aether.repository.NoLocalRepositoryManagerException)

Example 7 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project spring-cloud-function by spring-cloud.

the class DependencyResolutionModule method readModel.

public Model readModel(final Resource resource, final Properties properties) {
    initialize();
    try {
        ProjectBuildingRequest request = getProjectBuildingRequest(properties);
        request.setResolveDependencies(false);
        ProjectBuildingResult result = projectBuilder.build(new PropertiesModelSource(properties, resource), request);
        return result.getProject().getModel();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to build model from effective pom", e);
    }
}
Also used : DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ProjectBuildingResult(org.apache.maven.project.ProjectBuildingResult) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) NoLocalRepositoryManagerException(org.eclipse.aether.repository.NoLocalRepositoryManagerException) IOException(java.io.IOException)

Example 8 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project syndesis by syndesisio.

the class ExtractConnectorDescriptorsMojo method execute.

@Override
@SuppressWarnings({ "PMD.EmptyCatchBlock", "PMD.CyclomaticComplexity" })
public void execute() throws MojoExecutionException, MojoFailureException {
    ArrayNode root = new ArrayNode(JsonNodeFactory.instance);
    URLClassLoader classLoader = null;
    try {
        PluginDescriptor desc = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
        List<Artifact> artifacts = desc.getArtifacts();
        ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        buildingRequest.setRemoteRepositories(remoteRepositories);
        for (Artifact artifact : artifacts) {
            ArtifactResult result = artifactResolver.resolveArtifact(buildingRequest, artifact);
            File jar = result.getArtifact().getFile();
            classLoader = createClassLoader(jar);
            if (classLoader == null) {
                throw new IOException("Can not create classloader for " + jar);
            }
            ObjectNode entry = new ObjectNode(JsonNodeFactory.instance);
            addConnectorMeta(entry, classLoader);
            addComponentMeta(entry, classLoader);
            if (entry.size() > 0) {
                addGav(entry, artifact);
                root.add(entry);
            }
        }
        if (root.size() > 0) {
            saveCamelMetaData(root);
        }
    } catch (ArtifactResolverException | IOException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    } finally {
        if (classLoader != null) {
            try {
                classLoader.close();
            } catch (IOException ignored) {
            }
        }
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) URLClassLoader(java.net.URLClassLoader) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) File(java.io.File) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 9 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project sts4 by spring-projects.

the class MavenBridge method readProject.

public MavenProject readProject(final File pomFile, MavenExecutionRequest request, boolean resolveDependencies) throws MavenException {
    try {
        lookup(MavenExecutionRequestPopulator.class).populateDefaults(request);
        ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
        configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
        configuration.setRepositorySession(createRepositorySession(request));
        configuration.setResolveDependencies(resolveDependencies);
        return lookup(ProjectBuilder.class).build(pomFile, configuration).getProject();
    } catch (ProjectBuildingException ex) {
        throw new MavenException(ex);
    } catch (MavenExecutionRequestPopulationException ex) {
        throw new MavenException(ex);
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenExecutionRequestPopulationException(org.apache.maven.execution.MavenExecutionRequestPopulationException) MavenExecutionRequestPopulator(org.apache.maven.execution.MavenExecutionRequestPopulator)

Example 10 with ProjectBuildingRequest

use of org.apache.maven.project.ProjectBuildingRequest in project maven-archetype by apache.

the class DefaultArchetypeGenerationConfigurator2Test method setUp.

public void setUp() throws Exception {
    super.setUp();
    configurator = (DefaultArchetypeGenerationConfigurator) lookup(ArchetypeGenerationConfigurator.ROLE);
    ProjectBuildingRequest buildingRequest = null;
    // MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
    // repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( localRepository.getBasedir() ) );
    // buildingRequest.setRepositorySession( repositorySession );
    // request.setProjectBuildingRequest( buildingRequest );
    MockControl control = MockControl.createControl(ArchetypeArtifactManager.class);
    control.setDefaultMatcher(MockControl.ALWAYS_MATCHER);
    ArchetypeArtifactManager manager = (ArchetypeArtifactManager) control.getMock();
    manager.exists("archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, null, buildingRequest);
    control.setReturnValue(true);
    manager.isFileSetArchetype("archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, null, buildingRequest);
    control.setReturnValue(true);
    manager.isOldArchetype("archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, null, buildingRequest);
    control.setReturnValue(false);
    manager.getFileSetArchetypeDescriptor("archetypeGroupId", "archetypeArtifactId", "archetypeVersion", null, null, null, buildingRequest);
    ArchetypeDescriptor descriptor = new ArchetypeDescriptor();
    RequiredProperty groupId = new RequiredProperty();
    groupId.setKey("groupId");
    groupId.setDefaultValue("com.example.${groupName}");
    RequiredProperty artifactId = new RequiredProperty();
    artifactId.setKey("artifactId");
    artifactId.setDefaultValue("${serviceName}");
    RequiredProperty thePackage = new RequiredProperty();
    thePackage.setKey("package");
    thePackage.setDefaultValue("com.example.${groupName}");
    RequiredProperty groupName = new RequiredProperty();
    groupName.setKey("groupName");
    groupName.setDefaultValue(null);
    RequiredProperty serviceName = new RequiredProperty();
    serviceName.setKey("serviceName");
    serviceName.setDefaultValue(null);
    descriptor.addRequiredProperty(groupId);
    descriptor.addRequiredProperty(artifactId);
    descriptor.addRequiredProperty(thePackage);
    descriptor.addRequiredProperty(groupName);
    descriptor.addRequiredProperty(serviceName);
    control.setReturnValue(descriptor);
    control.replay();
    configurator.setArchetypeArtifactManager(manager);
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) MockControl(org.easymock.MockControl) RequiredProperty(org.apache.maven.archetype.metadata.RequiredProperty) ArchetypeDescriptor(org.apache.maven.archetype.metadata.ArchetypeDescriptor) ArchetypeArtifactManager(org.apache.maven.archetype.common.ArchetypeArtifactManager)

Aggregations

ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)81 File (java.io.File)40 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)37 MavenRepositorySystemSession (org.apache.maven.repository.internal.MavenRepositorySystemSession)28 SimpleLocalRepositoryManager (org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager)28 Artifact (org.apache.maven.artifact.Artifact)25 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)22 MavenProject (org.apache.maven.project.MavenProject)22 MavenSession (org.apache.maven.execution.MavenSession)17 IOException (java.io.IOException)14 LegacySupport (org.apache.maven.plugin.LegacySupport)13 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)12 ArrayList (java.util.ArrayList)9 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)8 MavenArtifactRepository (org.apache.maven.artifact.repository.MavenArtifactRepository)8 ArchetypeGenerationRequest (org.apache.maven.archetype.ArchetypeGenerationRequest)7 ArchetypeManager (org.apache.maven.archetype.ArchetypeManager)7 ArchetypeCatalog (org.apache.maven.archetype.catalog.ArchetypeCatalog)7 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)7 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)7