use of org.apache.maven.execution.MavenExecutionRequest in project sts4 by spring-projects.
the class MavenBridge method compileAndGenerateJavadoc.
public MavenExecutionResult compileAndGenerateJavadoc(File pom) throws MavenException {
try {
MavenExecutionRequest request = createExecutionRequest();
lookup(MavenExecutionRequestPopulator.class).populateDefaults(request);
request.setPom(pom);
ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
configuration.setRepositorySession(createRepositorySession(request));
configuration.setResolveDependencies(true);
configuration.setResolveVersionRanges(true);
request.setGoals(Arrays.asList(new String[] { "compile", "javadoc:javadoc" }));
Properties userProperties = (Properties) request.getUserProperties().clone();
userProperties.put("show", "private");
request.setUserProperties(userProperties);
return lookup(Maven.class).execute(request);
} catch (MavenExecutionRequestPopulationException e) {
throw new MavenException(e);
}
}
use of org.apache.maven.execution.MavenExecutionRequest in project sts4 by spring-projects.
the class MavenBridge method getMirror.
public Mirror getMirror(ArtifactRepository repo) throws MavenException {
MavenExecutionRequest request = createExecutionRequest();
populateDefaults(request);
return lookup(RepositorySystem.class).getMirror(repo, request.getMirrors());
}
use of org.apache.maven.execution.MavenExecutionRequest in project sts4 by spring-projects.
the class MavenBridge method createExecutionRequest.
/* package */
@SuppressWarnings("deprecation")
MavenExecutionRequest createExecutionRequest() throws MavenException {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
if (mavenConfiguration.getGlobalSettingsFile() != null) {
request.setGlobalSettingsFile(new File(mavenConfiguration.getGlobalSettingsFile()));
}
File userSettingsFile = SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE;
if (mavenConfiguration.getUserSettingsFile() != null) {
userSettingsFile = new File(mavenConfiguration.getUserSettingsFile());
}
request.setUserSettingsFile(userSettingsFile);
try {
lookup(MavenExecutionRequestPopulator.class).populateFromSettings(request, getSettings());
} catch (MavenExecutionRequestPopulationException ex) {
throw new MavenException(ex);
}
ArtifactRepository localRepository = getLocalRepository();
request.setLocalRepository(localRepository);
request.setLocalRepositoryPath(localRepository.getBasedir());
// request.setOffline(mavenConfiguration.isOffline());
// request.getUserProperties().put("m2e.version",
// MavenPluginActivator.getVersion()); //$NON-NLS-1$
// request.getUserProperties().put(ConfigurationProperties.USER_AGENT,
// MavenPluginActivator.getUserAgent());
EnvironmentUtils.addEnvVars(request.getSystemProperties());
copyProperties(request.getSystemProperties(), System.getProperties());
request.setCacheNotFound(true);
request.setCacheTransferError(true);
// request.setUpdateSnapshots(false);
return request;
}
use of org.apache.maven.execution.MavenExecutionRequest in project sts4 by spring-projects.
the class MavenCore method resolveDependencies.
/**
* Calculates dependency graph for a Maven project provided the scope.
*
* @param project Maven Project descriptor
* @param scope Dependency scope
* @return Set of all dependencies including transient ones
* @throws MavenException
*/
public Set<Artifact> resolveDependencies(MavenProject project, String scope) throws MavenException {
MavenExecutionRequest request = maven.createExecutionRequest();
DefaultRepositorySystemSession session = maven.createRepositorySession(request);
DependencyNode graph = readDependencyTree(maven.lookupComponent(org.eclipse.aether.RepositorySystem.class), session, project, scope);
if (graph != null) {
ArrayList<DependencyNode> dependencyNodes = new ArrayList<>();
graph.accept(new DependencyVisitor() {
public boolean visitEnter(DependencyNode node) {
if (node.getDependency() != null) {
dependencyNodes.add(node);
}
return true;
}
public boolean visitLeave(DependencyNode dependencynode) {
return true;
}
});
LinkedHashSet<Artifact> artifacts = new LinkedHashSet<>();
RepositoryUtils.toArtifacts(artifacts, dependencyNodes, Collections.singletonList(project.getArtifact().getId()), null);
return artifacts.parallelStream().map(artifact -> {
if (!artifact.isResolved()) {
try {
artifact = maven.resolve(artifact, project.getRemoteArtifactRepositories(), request);
} catch (MavenException e) {
Log.log(e);
// Maven 2.x quirk: an artifact always points at the local repo,
// regardless whether resolved or not
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
String path = lrm.getPathForLocalArtifact(RepositoryUtils.toArtifact(artifact));
artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
}
}
return artifact;
}).collect(Collectors.toSet());
}
return Collections.emptySet();
}
use of org.apache.maven.execution.MavenExecutionRequest in project sts4 by spring-projects.
the class MavenCore method localRepositoryFolder.
public File localRepositoryFolder() throws MavenException {
MavenExecutionRequest request = maven.createExecutionRequest();
DefaultRepositorySystemSession session = maven.createRepositorySession(request);
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
return lrm.getRepository().getBasedir();
}
Aggregations