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);
}
}
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);
}
}
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) {
}
}
}
}
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);
}
}
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);
}
Aggregations