Search in sources :

Example 1 with ProfileManager

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);
}
Also used : DefaultProfileManager(org.apache.maven.profiles.DefaultProfileManager) ProfileManager(org.apache.maven.profiles.ProfileManager) DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) FileNotFoundException(java.io.FileNotFoundException) Method(java.lang.reflect.Method) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) FileNotFoundException(java.io.FileNotFoundException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MavenProjectBuilder(org.apache.maven.project.MavenProjectBuilder) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ProfileManager

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;
}
Also used : DefaultProfileManager(org.apache.maven.profiles.DefaultProfileManager) ProfileManager(org.apache.maven.profiles.ProfileManager) DefaultProfileManager(org.apache.maven.profiles.DefaultProfileManager)

Example 3 with 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);
}
Also used : ProfileManager(org.apache.maven.profiles.ProfileManager) DefaultProfileManager(org.apache.maven.profiles.DefaultProfileManager) MavenProjectBuilder(org.apache.maven.project.MavenProjectBuilder) DefaultProfileManager(org.apache.maven.profiles.DefaultProfileManager) File(java.io.File)

Example 4 with ProfileManager

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);
}
Also used : DefaultProfileManager(org.apache.maven.profiles.DefaultProfileManager) ProfileManager(org.apache.maven.profiles.ProfileManager) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) FileNotFoundException(java.io.FileNotFoundException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException) IOException(java.io.IOException) Artifact(org.apache.maven.artifact.Artifact) ProjectBuilderConfiguration(org.apache.maven.project.ProjectBuilderConfiguration) MavenProjectBuilder(org.apache.maven.project.MavenProjectBuilder) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) ArtifactMetadataSource(org.apache.maven.artifact.metadata.ArtifactMetadataSource) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DefaultProfileManager (org.apache.maven.profiles.DefaultProfileManager)4 ProfileManager (org.apache.maven.profiles.ProfileManager)4 File (java.io.File)3 MavenProjectBuilder (org.apache.maven.project.MavenProjectBuilder)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MavenProject (org.apache.maven.project.MavenProject)2 ModelInterpolationException (org.apache.maven.project.interpolation.ModelInterpolationException)2 PlexusContainerException (org.codehaus.plexus.PlexusContainerException)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)2 NotNull (org.jetbrains.annotations.NotNull)2 SecDispatcherException (org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException)2 Method (java.lang.reflect.Method)1 DefaultMaven (org.apache.maven.DefaultMaven)1 Maven (org.apache.maven.Maven)1 Artifact (org.apache.maven.artifact.Artifact)1 ArtifactMetadataSource (org.apache.maven.artifact.metadata.ArtifactMetadataSource)1 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)1