use of org.apache.maven.profiles.ProfileManager in project intellij-community by JetBrains.
the class MavenEmbedder method readProject.
@NotNull
private MavenExecutionResult readProject(@NotNull final MavenExecutionRequest request) {
ProfileManager globalProfileManager = request.getGlobalProfileManager();
globalProfileManager.loadSettingsProfiles(request.getSettings());
MavenProject rootProject = null;
final List<Exception> exceptions = new ArrayList<Exception>();
Object result = null;
try {
final File pomFile = new File(request.getPomFile());
if (!pomFile.exists()) {
throw new FileNotFoundException("File doesn't exist: " + pomFile.getPath());
}
final Method getProjectsMethod = DefaultMaven.class.getDeclaredMethod("getProjects", MavenExecutionRequest.class);
getProjectsMethod.setAccessible(true);
Maven maven = getComponent(Maven.class);
result = getProjectsMethod.invoke(maven, request);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
return handleException(e.getTargetException());
} catch (Exception e) {
return handleException(e);
}
if (result != null) {
MavenProjectBuilder builder = getComponent(MavenProjectBuilder.class);
for (Object p : (List) result) {
MavenProject project = (MavenProject) p;
try {
builder.calculateConcreteState(project, request.getProjectBuilderConfiguration(), false);
} catch (ModelInterpolationException e) {
exceptions.add(e);
}
if (project.isExecutionRoot()) {
rootProject = project;
}
}
if (rootProject == null && exceptions.isEmpty()) {
throw new RuntimeException("Could't build project for unknown reason");
}
}
return new MavenExecutionResult(rootProject, exceptions);
}
use of org.apache.maven.profiles.ProfileManager in project intellij-community by JetBrains.
the class MavenEmbedder method createProfileManager.
private ProfileManager createProfileManager(List<String> activeProfiles, List<String> inactiveProfiles, Properties executionProperties) {
ProfileManager profileManager = new DefaultProfileManager(getContainer(), executionProperties);
profileManager.explicitlyActivate(activeProfiles);
profileManager.explicitlyDeactivate(inactiveProfiles);
return profileManager;
}
use of org.apache.maven.profiles.ProfileManager in project maven-plugins by apache.
the class AbstractProjectInfoTestCase method generateReport.
protected File generateReport(AbstractProjectInfoReport mojo, File pluginXmlFile) throws Exception {
mojo.execute();
MavenProjectBuilder builder = (MavenProjectBuilder) lookup(MavenProjectBuilder.ROLE);
ProfileManager profileManager = new DefaultProfileManager(getContainer(), null, null);
assertNotNull("Local repository", mojo.localRepository);
testMavenProject = builder.buildWithDependencies(pluginXmlFile, mojo.localRepository, profileManager);
File outputDir = mojo.getReportOutputDirectory();
String filename = mojo.getOutputName() + ".html";
return new File(outputDir, filename);
}
use of org.apache.maven.profiles.ProfileManager in project intellij-community by JetBrains.
the class MavenEmbedder method resolveProject.
@NotNull
public MavenExecutionResult resolveProject(@NotNull final File file, @NotNull final List<String> activeProfiles, @NotNull final List<String> inactiveProfiles, List<ResolutionListener> listeners) {
MavenExecutionRequest request = createRequest(file, activeProfiles, inactiveProfiles, Collections.<String>emptyList());
ProjectBuilderConfiguration config = request.getProjectBuilderConfiguration();
request.getGlobalProfileManager().loadSettingsProfiles(mySettings);
ProfileManager globalProfileManager = request.getGlobalProfileManager();
globalProfileManager.loadSettingsProfiles(request.getSettings());
List<Exception> exceptions = new ArrayList<Exception>();
MavenProject project = null;
try {
// copied from DefaultMavenProjectBuilder.buildWithDependencies
MavenProjectBuilder builder = getComponent(MavenProjectBuilder.class);
project = builder.build(new File(file.getPath()), config);
builder.calculateConcreteState(project, config, false);
// copied from DefaultLifecycleExecutor.execute
findExtensions(project);
// end copied from DefaultLifecycleExecutor.execute
Artifact projectArtifact = project.getArtifact();
Map managedVersions = project.getManagedVersionMap();
ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
project.setDependencyArtifacts(project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
ArtifactResolver resolver = getComponent(ArtifactResolver.class);
ArtifactResolutionResult result = resolver.resolveTransitively(project.getDependencyArtifacts(), projectArtifact, managedVersions, myLocalRepository, project.getRemoteArtifactRepositories(), metadataSource, null, listeners);
project.setArtifacts(result.getArtifacts());
// end copied from DefaultMavenProjectBuilder.buildWithDependencies
} catch (Exception e) {
return handleException(e);
}
return new MavenExecutionResult(project, exceptions);
}
Aggregations