Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.maven.project;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  *
  *  http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
  */
 
 import java.io.File;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
 
 @Component( role = ProjectBuilder.class )
 public class DefaultProjectBuilder
     implements ProjectBuilder
 {
 
     @Requirement
     private Logger logger;
 
     @Requirement
     private ModelBuilder modelBuilder;
 
     @Requirement
     private ModelProcessor modelProcessor;
 
     @Requirement
 
     @Requirement
 
     @Requirement
 
     @Requirement
 
     @Requirement
 
     // ----------------------------------------------------------------------
     // MavenProjectBuilder Implementation
    // ----------------------------------------------------------------------
    public ProjectBuildingResult buildFile pomFileProjectBuildingRequest request )
        throws ProjectBuildingException
    {
        return buildpomFilenew FileModelSourcepomFile ), new InternalConfigrequestnull ) );
    }
    public ProjectBuildingResult buildModelSource modelSourceProjectBuildingRequest request )
        throws ProjectBuildingException
    {
        return buildnullmodelSourcenew InternalConfigrequestnull ) );
    }
    private ProjectBuildingResult buildFile pomFileModelSource modelSourceInternalConfig config )
        throws ProjectBuildingException
    {
        ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
        try
        {
            ProjectBuildingRequest configuration = config.request;
            MavenProject project = configuration.getProject();
            List<ModelProblemmodelProblems = null;
            Throwable error = null;
            if ( project == null )
            {
                ModelBuildingRequest request = getModelBuildingRequestconfig );
                project = new MavenProjectthisconfiguration );
                DefaultModelBuildingListener listener =
                    new DefaultModelBuildingListenerprojectconfiguration );
                request.setModelBuildingListenerlistener );
                request.setPomFilepomFile );
                request.setModelSourcemodelSource );
                request.setLocationTrackingtrue );
                ModelBuildingResult result;
                try
                {
                    result = .buildrequest );
                }
                catch ( ModelBuildingException e )
                {
                    result = e.getResult();
                    if ( result == null || result.getEffectiveModel() == null )
                    {
                        throw new ProjectBuildingExceptione.getModelId(), e.getMessage(), pomFilee );
                    }
                    // validation error, continue project building and delay failing to help IDEs
                    error = e;
                }
                modelProblems = result.getProblems();
                initProjectproject, Collections.<StringMavenProjectemptyMap(), result,
                             new HashMap<FileBoolean>() );
            }
            else if ( configuration.isResolveDependencies() )
            {
                .selectProjectRealmproject );
            }
            DependencyResolutionResult resolutionResult = null;
            if ( configuration.isResolveDependencies() )
            {
                resolutionResult = resolveDependenciesprojectconfig.session );
            }
            ProjectBuildingResult result = new DefaultProjectBuildingResultprojectmodelProblemsresolutionResult );
            if ( error != null )
            {
                ProjectBuildingException e = new ProjectBuildingException( Arrays.asListresult ) );
                e.initCauseerror );
                throw e;
            }
            return result;
        }
        finally
        {
            Thread.currentThread().setContextClassLoaderoldContextClassLoader );
        }
    }
    {
        DependencyResolutionResult resolutionResult = null;
        try
        {
            DefaultDependencyResolutionRequest resolution = new DefaultDependencyResolutionRequestprojectsession );
            resolutionResult = .resolveresolution );
        }
        catch ( DependencyResolutionException e )
        {
            resolutionResult = e.getResult();
        }
        Set<Artifactartifacts = new LinkedHashSet<Artifact>();
        if ( resolutionResult.getDependencyGraph() != null )
        {
            RepositoryUtils.toArtifactsartifactsresolutionResult.getDependencyGraph().getChildren(),
                                         Collections.singletonListproject.getArtifact().getId() ), null );
            // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
            LocalRepositoryManager lrm = session.getLocalRepositoryManager();
            for ( Artifact artifact : artifacts )
            {
                if ( !artifact.isResolved() )
                {
                    String path = lrm.getPathForLocalArtifact( RepositoryUtils.toArtifactartifact ) );
                    artifact.setFilenew Filelrm.getRepository().getBasedir(), path ) );
                }
            }
        }
        project.setResolvedArtifactsartifacts );
        project.setArtifactsartifacts );
        return resolutionResult;
    }
    private List<StringgetProfileIdsList<Profileprofiles )
    {
        List<Stringids = new ArrayList<String>( profiles.size() );
        for ( Profile profile : profiles )
        {
            ids.addprofile.getId() );
        }
        return ids;
    }
    {
        ProjectBuildingRequest configuration = config.request;
        ModelBuildingRequest request = new DefaultModelBuildingRequest();
        RequestTrace trace = RequestTrace.newChildnullconfiguration ).newChildrequest );
        ModelResolver resolver =
            new ProjectModelResolverconfig.sessiontraceconfig.repositories,
                                      configuration.getRepositoryMerging(), config.modelPool );
        request.setValidationLevelconfiguration.getValidationLevel() );
        request.setProcessPluginsconfiguration.isProcessPlugins() );
        request.setProfilesconfiguration.getProfiles() );
        request.setActiveProfileIdsconfiguration.getActiveProfileIds() );
        request.setInactiveProfileIdsconfiguration.getInactiveProfileIds() );
        request.setSystemPropertiesconfiguration.getSystemProperties() );
        request.setUserPropertiesconfiguration.getUserProperties() );
        request.setBuildStartTimeconfiguration.getBuildStartTime() );
        request.setModelResolverresolver );
        request.setModelCachenew ReactorModelCache() );
        return request;
    }
    public ProjectBuildingResult buildArtifact artifactProjectBuildingRequest request )
        throws ProjectBuildingException
    {
        return buildartifactfalserequest );
    }
    public ProjectBuildingResult buildArtifact artifactboolean allowStubModelProjectBuildingRequest request )
        throws ProjectBuildingException
    {
        org.eclipse.aether.artifact.Artifact pomArtifact = RepositoryUtils.toArtifactartifact );
        pomArtifact = ArtifactDescriptorUtils.toPomArtifactpomArtifact );
        InternalConfig config = new InternalConfigrequestnull );
        boolean localProject;
        try
        {
            ArtifactRequest pomRequest = new ArtifactRequest();
            pomRequest.setArtifactpomArtifact );
            pomRequest.setRepositoriesconfig.repositories );
            ArtifactResult pomResult = .resolveArtifactconfig.sessionpomRequest );
            pomArtifact = pomResult.getArtifact();
            localProject = pomResult.getRepository() instanceof WorkspaceRepository;
        }
        {
            if ( e.getResults().get( 0 ).isMissing() && allowStubModel )
            {
                return buildnullcreateStubModelSourceartifact ), config );
            }
            throw new ProjectBuildingExceptionartifact.getId(),
                                                "Error resolving project artifact: " + e.getMessage(), e );
        }
        File pomFile = pomArtifact.getFile();
        if ( "pom".equalsartifact.getType() ) )
        {
            artifact.selectVersionpomArtifact.getVersion() );
            artifact.setFilepomFile );
            artifact.setResolvedtrue );
        }
        return buildlocalProject ? pomFile : nullnew FileModelSourcepomFile ), config );
    }
    private ModelSource createStubModelSourceArtifact artifact )
    {
        StringBuilder buffer = new StringBuilder( 1024 );
        buffer.append"<?xml version='1.0'?>" );
        buffer.append"<project>" );
        buffer.append"<modelVersion>4.0.0</modelVersion>" );
        buffer.append"<groupId>" ).appendartifact.getGroupId() ).append"</groupId>" );
        buffer.append"<artifactId>" ).appendartifact.getArtifactId() ).append"</artifactId>" );
        buffer.append"<version>" ).appendartifact.getBaseVersion() ).append"</version>" );
        buffer.append"<packaging>" ).appendartifact.getType() ).append"</packaging>" );
        buffer.append"</project>" );
        return new StringModelSourcebufferartifact.getId() );
    }
    public List<ProjectBuildingResultbuildList<FilepomFilesboolean recursiveProjectBuildingRequest request )
        throws ProjectBuildingException
    {
        List<ProjectBuildingResultresults = new ArrayList<ProjectBuildingResult>();
        List<InterimResultinterimResults = new ArrayList<InterimResult>();
        ReactorModelPool modelPool = new ReactorModelPool();
        InternalConfig config = new InternalConfigrequestmodelPool );
        Map<StringMavenProjectprojectIndex = new HashMap<StringMavenProject>( 256 );
        boolean noErrors =
            buildresultsinterimResultsprojectIndexpomFilesnew LinkedHashSet<File>(), truerecursiveconfig );
        populateReactorModelPoolmodelPoolinterimResults );
        ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
        try
        {
            noErrors =
                buildresultsnew ArrayList<MavenProject>(), projectIndexinterimResultsrequest,
                       new HashMap<FileBoolean>() ) && noErrors;
        }
        finally
        {
            Thread.currentThread().setContextClassLoaderoldContextClassLoader );
        }
        if ( !noErrors )
        {
            throw new ProjectBuildingExceptionresults );
        }
        return results;
    }
    private boolean buildList<ProjectBuildingResultresultsList<InterimResultinterimResults,
                           Map<StringMavenProjectprojectIndexList<FilepomFilesSet<FileaggregatorFiles,
                           boolean isRootboolean recursiveInternalConfig config )
    {
        boolean noErrors = true;
        for ( File pomFile : pomFiles )
        {
            aggregatorFiles.addpomFile );
            if ( !buildresultsinterimResultsprojectIndexpomFileaggregatorFilesisRootrecursiveconfig ) )
            {
                noErrors = false;
            }
            aggregatorFiles.removepomFile );
        }
        return noErrors;
    }
    private boolean buildList<ProjectBuildingResultresultsList<InterimResultinterimResults,
                           Map<StringMavenProjectprojectIndexFile pomFileSet<FileaggregatorFiles,
                           boolean isRootboolean recursiveInternalConfig config )
    {
        boolean noErrors = true;
        ModelBuildingRequest request = getModelBuildingRequestconfig );
        MavenProject project = new MavenProjectthisconfig.request );
        request.setPomFilepomFile );
        request.setTwoPhaseBuildingtrue );
        request.setLocationTrackingtrue );
        DefaultModelBuildingListener listener =
            new DefaultModelBuildingListenerprojectconfig.request );
        request.setModelBuildingListenerlistener );
        try
        {
            ModelBuildingResult result = .buildrequest );
            Model model = result.getEffectiveModel();
            projectIndex.putresult.getModelIds().get( 0 ), project );
            InterimResult interimResult = new InterimResultpomFilerequestresultlistenerisRoot );
            interimResults.addinterimResult );
            if ( recursive && !model.getModules().isEmpty() )
            {
                File basedir = pomFile.getParentFile();
                List<FilemoduleFiles = new ArrayList<File>();
                for ( String module : model.getModules() )
                {
                    if ( StringUtils.isEmptymodule ) )
                    {
                        continue;
                    }
                    module = module.replace'\\'. ).replace'/'. );
                    File moduleFile = new Filebasedirmodule );
                    if ( moduleFile.isDirectory() )
                    {
                        moduleFile = .locatePommoduleFile );
                    }
                    if ( !moduleFile.isFile() )
                    {
                        ModelProblem problem =
                            new DefaultModelProblem"Child module " + moduleFile + " of " + pomFile
                                + " does not exist"....model, -1, -1, null );
                        result.getProblems().addproblem );
                        noErrors = false;
                        continue;
                    }
                    if ( Os.isFamily. ) )
                    {
                        // we don't canonicalize on unix to avoid interfering with symlinks
                        try
                        {
                            moduleFile = moduleFile.getCanonicalFile();
                        }
                        catch ( IOException e )
                        {
                            moduleFile = moduleFile.getAbsoluteFile();
                        }
                    }
                    else
                    {
                        moduleFile = new FilemoduleFile.toURI().normalize() );
                    }
                    if ( aggregatorFiles.containsmoduleFile ) )
                    {
                        StringBuilder buffer = new StringBuilder( 256 );
                        for ( File aggregatorFile : aggregatorFiles )
                        {
                            buffer.appendaggregatorFile ).append" -> " );
                        }
                        buffer.appendmoduleFile );
                        ModelProblem problem =
                            new DefaultModelProblem"Child module " + moduleFile + " of " + pomFile
                                + " forms aggregation cycle " + buffer....model, -1, -1,
                                                     null );
                        result.getProblems().addproblem );
                        noErrors = false;
                        continue;
                    }
                    moduleFiles.addmoduleFile );
                }
                interimResult.modules = new ArrayList<InterimResult>();
                if ( !buildresultsinterimResult.modulesprojectIndexmoduleFilesaggregatorFilesfalse,
                             recursiveconfig ) )
                {
                    noErrors = false;
                }
            }
        }
        catch ( ModelBuildingException e )
        {
            results.addnew DefaultProjectBuildingResulte.getModelId(), pomFilee.getProblems() ) );
            noErrors = false;
        }
        return noErrors;
    }
    static class InterimResult
    {
        File pomFile;
        ModelBuildingResult result;
        boolean root;
        List<InterimResultmodules = Collections.emptyList();
        InterimResultFile pomFileModelBuildingRequest requestModelBuildingResult result,
                       DefaultModelBuildingListener listenerboolean root )
        {
            this. = pomFile;
            this. = request;
            this. = result;
            this. = listener;
            this. = root;
        }
    }
    private void populateReactorModelPoolReactorModelPool reactorModelPoolList<InterimResultinterimResults )
    {
        for ( InterimResult interimResult : interimResults )
        {
            Model model = interimResult.result.getEffectiveModel();
            reactorModelPool.putmodel.getGroupId(), model.getArtifactId(), model.getVersion(), model.getPomFile() );
            populateReactorModelPoolreactorModelPoolinterimResult.modules );
        }
    }
    private boolean buildList<ProjectBuildingResultresultsList<MavenProjectprojects,
                           Map<StringMavenProjectprojectIndexList<InterimResultinterimResults,
                           ProjectBuildingRequest requestMap<FileBooleanprofilesXmls )
    {
        boolean noErrors = true;
        for ( InterimResult interimResult : interimResults )
        {
            try
            {
                ModelBuildingResult result = .buildinterimResult.requestinterimResult.result );
                MavenProject project = interimResult.listener.getProject();
                initProjectprojectprojectIndexresultprofilesXmls );
                List<MavenProjectmodules = new ArrayList<MavenProject>();
                noErrors =
                    buildresultsmodulesprojectIndexinterimResult.modulesrequestprofilesXmls ) && noErrors;
                projects.addAllmodules );
                projects.addproject );
                project.setExecutionRootinterimResult.root );
                project.setCollectedProjectsmodules );
                results.addnew DefaultProjectBuildingResultprojectresult.getProblems(), null ) );
            }
            catch ( ModelBuildingException e )
            {
                results.addnew DefaultProjectBuildingResulte.getModelId(), interimResult.pomFilee.getProblems() ) );
                noErrors = false;
            }
        }
        return noErrors;
    }
    private void initProjectMavenProject projectMap<StringMavenProjectprojectsModelBuildingResult result,
                              Map<FileBooleanprofilesXmls )
    {
        Model model = result.getEffectiveModel();
        project.setModelmodel );
        project.setOriginalModelresult.getRawModel() );
        project.setFilemodel.getPomFile() );
        File parentPomFile = result.getRawModelresult.getModelIds().get( 1 ) ).getPomFile();
        project.setParentFileparentPomFile );
        project.setParentprojects.getresult.getModelIds().get( 1 ) ) );
        Artifact projectArtifact =
            .createArtifactproject.getGroupId(), project.getArtifactId(), project.getVersion(), null,
                                             project.getPackaging() );
        project.setArtifactprojectArtifact );
        if ( project.getFile() != null )
        {
            Build build = project.getBuild();
            project.addScriptSourceRootbuild.getScriptSourceDirectory() );
            project.addCompileSourceRootbuild.getSourceDirectory() );
            project.addTestCompileSourceRootbuild.getTestSourceDirectory() );
        }
        List<ProfileactiveProfiles = new ArrayList<Profile>();
        activeProfiles.addAllresult.getActivePomProfilesresult.getModelIds().get( 0 ) ) );
        activeProfiles.addAllresult.getActiveExternalProfiles() );
        project.setActiveProfilesactiveProfiles );
        project.setInjectedProfileIds"external"getProfileIdsresult.getActiveExternalProfiles() ) );
        for ( String modelId : result.getModelIds() )
        {
            project.setInjectedProfileIdsmodelIdgetProfileIdsresult.getActivePomProfilesmodelId ) ) );
        }
        String modelId = findProfilesXmlresultprofilesXmls );
        if ( modelId != null )
        {
            ModelProblem problem =
                new DefaultModelProblem"Detected profiles.xml alongside " + modelId
                    + ", this file is no longer supported and was ignored" + ", please use the settings.xml instead",
                                         ....model, -1, -1, null );
            result.getProblems().addproblem );
        }
    }
    private String findProfilesXmlModelBuildingResult resultMap<FileBooleanprofilesXmls )
    {
        for ( String modelId : result.getModelIds() )
        {
            Model model = result.getRawModelmodelId );
            File basedir = model.getProjectDirectory();
            if ( basedir == null )
            {
                break;
            }
            Boolean profilesXml = profilesXmls.getbasedir );
            if ( profilesXml == null )
            {
                profilesXml = Boolean.valueOfnew Filebasedir"profiles.xml" ).exists() );
                profilesXmls.putbasedirprofilesXml );
            }
            if ( profilesXml.booleanValue() )
            {
                return modelId;
            }
        }
        return null;
    }
    class InternalConfig
    {
        public final ProjectBuildingRequest request;
        public final RepositorySystemSession session;
        public final List<RemoteRepositoryrepositories;
        public final ReactorModelPool modelPool;
        InternalConfigProjectBuildingRequest requestReactorModelPool modelPool )
        {
            this. = request;
            this. = modelPool;
             =
                LegacyLocalRepositoryManager.overlayrequest.getLocalRepository(), request.getRepositorySession(),
                                                       );
             = RepositoryUtils.toReposrequest.getRemoteRepositories() );
        }
    }
New to GrepCode? Check out our FAQ X