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.util.List;
 import java.util.Map;
 import java.util.Set;
 
Assists the project builder. Warning: This is an internal utility class that is only public for technical reasons, it is not part of the public API. In particular, this class can be changed or deleted without prior notice.

Author(s):
Benjamin Bentmann
 
 @Component( role = ProjectBuildingHelper.class )
     implements ProjectBuildingHelper
 {
 
     @Requirement
     private Logger logger;
 
     @Requirement
     private PlexusContainer container;
 
     @Requirement
 
     @Requirement
 
     @Requirement
 
     @Requirement
 
     @Requirement
 
     @Requirement
 
     @Requirement
                                                                List<ArtifactRepositoryexternalRepositories,
                                                                ProjectBuildingRequest request )
        throws InvalidRepositoryException
    {
        List<ArtifactRepositoryinternalRepositories = new ArrayList<ArtifactRepository>();
        for ( Repository repository : pomRepositories )
        {
            internalRepositories.add.buildArtifactRepositoryrepository ) );
        }
        .injectMirrorrequest.getRepositorySession(), internalRepositories );
        .injectProxyrequest.getRepositorySession(), internalRepositories );
        .injectAuthenticationrequest.getRepositorySession(), internalRepositories );
        List<ArtifactRepositorydominantRepositories;
        List<ArtifactRepositoryrecessiveRepositories;
        {
            dominantRepositories = externalRepositories;
            recessiveRepositories = internalRepositories;
        }
        else
        {
            dominantRepositories = internalRepositories;
            recessiveRepositories = externalRepositories;
        }
        List<ArtifactRepositoryartifactRepositories = new ArrayList<ArtifactRepository>();
        Collection<StringrepoIds = new HashSet<String>();
        if ( dominantRepositories != null )
        {
            for ( ArtifactRepository repository : dominantRepositories )
            {
                repoIds.addrepository.getId() );
                artifactRepositories.addrepository );
            }
        }
        if ( recessiveRepositories != null )
        {
            for ( ArtifactRepository repository : recessiveRepositories )
            {
                if ( repoIds.addrepository.getId() ) )
                {
                    artifactRepositories.addrepository );
                }
            }
        }
        artifactRepositories = .getEffectiveRepositoriesartifactRepositories );
        return artifactRepositories;
    }
    public synchronized ProjectRealmCache.CacheRecord createProjectRealmMavenProject projectModel model,
                                                                          ProjectBuildingRequest request )
    {
        ClassRealm projectRealm = null;
        List<PluginextensionPlugins = new ArrayList<Plugin>();
        Build build = model.getBuild();
        if ( build != null )
        {
            for ( Extension extension : build.getExtensions() )
            {
                Plugin plugin = new Plugin();
                plugin.setGroupIdextension.getGroupId() );
                plugin.setArtifactIdextension.getArtifactId() );
                plugin.setVersionextension.getVersion() );
                extensionPlugins.addplugin );
            }
            for ( Plugin plugin : build.getPlugins() )
            {
                if ( plugin.isExtensions() )
                {
                    extensionPlugins.addplugin );
                }
            }
        }
        if ( extensionPlugins.isEmpty() )
        {
            if ( .isDebugEnabled() )
            {
                .debug"Extension realms for project " + model.getId() + ": (none)" );
            }
            return new ProjectRealmCache.CacheRecordnullnull );
        }
        List<ClassRealmextensionRealms = new ArrayList<ClassRealm>();
        Map<ClassRealmList<String>> exportedPackages = new HashMap<ClassRealmList<String>>();
        Map<ClassRealmList<String>> exportedArtifacts = new HashMap<ClassRealmList<String>>();
        List<ArtifactpublicArtifacts = new ArrayList<Artifact>();
        for ( Plugin plugin : extensionPlugins )
        {
            if ( plugin.getVersion() == null )
            {
                PluginVersionRequest versionRequest =
                    new DefaultPluginVersionRequestpluginrequest.getRepositorySession(),
                                                     project.getRemotePluginRepositories() );
                plugin.setVersion.resolveversionRequest ).getVersion() );
            }
            List<Artifactartifacts;
            PluginArtifactsCache.Key cacheKey =
                .createKeypluginnullproject.getRemotePluginRepositories(),
                                                request.getRepositorySession() );
            PluginArtifactsCache.CacheRecord recordArtifacts = .getcacheKey );
            if ( recordArtifacts != null )
            {
                artifacts = recordArtifacts.artifacts;
            }
            else
            {
                try
                {
                    artifacts = resolveExtensionArtifactspluginproject.getRemotePluginRepositories(), request );
                    recordArtifacts = .putcacheKeyartifacts );
                }
                catch ( PluginResolutionException e )
                {
                    .putcacheKeye );
                    .registerprojectrecordArtifacts );
                    throw e;
                }
            }
            .registerprojectrecordArtifacts );
            ClassRealm extensionRealm;
            ExtensionDescriptor extensionDescriptor = null;
            ExtensionRealmCache.CacheRecord recordRealm = .getartifacts );
            if ( recordRealm != null )
            {
                extensionRealm = recordRealm.realm;
                extensionDescriptor = recordRealm.desciptor;
            }
            else
            {
                extensionRealm = .createExtensionRealmpluginartifacts );
                try
                {
                    .discoverComponentsextensionRealm );
                }
                catch ( Exception e )
                {
                    throw new IllegalStateException"Failed to discover components in extension realm "
                        + extensionRealm.getId(), e );
                }
                Artifact extensionArtifact = artifacts.get( 0 );
                try
                {
                    extensionDescriptor = .buildextensionArtifact.getFile() );
                }
                catch ( IOException e )
                {
                    String message = "Invalid extension descriptor for " + plugin.getId() + ": " + e.getMessage();
                    if ( .isDebugEnabled() )
                    {
                        .errormessagee );
                    }
                    else
                    {
                        .errormessage );
                    }
                }
                recordRealm = .putartifactsextensionRealmextensionDescriptor );
            }
            .registerprojectrecordRealm );
            extensionRealms.addextensionRealm );
            if ( extensionDescriptor != null )
            {
                exportedPackages.putextensionRealmextensionDescriptor.getExportedPackages() );
                exportedArtifacts.putextensionRealmextensionDescriptor.getExportedArtifacts() );
            }
            if ( !plugin.isExtensions() && artifacts.size() == 2 && artifacts.get( 0 ).getFile() != null
                && "plexus-utils".equalsartifacts.get( 1 ).getArtifactId() ) )
            {
                /*
                 * This is purely for backward-compat with 2.x where <extensions> consisting of a single artifact where
                 * loaded into the core and hence available to plugins, in contrast to bigger extensions that were
                 * loaded into a dedicated realm which is invisible to plugins (MNG-2749).
                 */
                publicArtifacts.addartifacts.get( 0 ) );
            }
        }
        if ( .isDebugEnabled() )
        {
            .debug"Extension realms for project " + model.getId() + ": " + extensionRealms );
        }
        ProjectRealmCache.CacheRecord record = .getextensionRealms );
        if ( record == null )
        {
            projectRealm = .createProjectRealmmodelpublicArtifacts );
            Set<Stringexclusions = new LinkedHashSet<String>();
            for ( ClassRealm extensionRealm : extensionRealms )
            {
                List<Stringexcludes = exportedArtifacts.getextensionRealm );
                if ( excludes != null )
                {
                    exclusions.addAllexcludes );
                }
                List<Stringexports = exportedPackages.getextensionRealm );
                if ( exports == null || exports.isEmpty() )
                {
                    /*
                     * Most existing extensions don't define exported packages, i.e. no classes are to be exposed to
                     * plugins, yet the components provided by the extension (e.g. artifact handlers) must be
                     * accessible, i.e. we still must import the extension realm into the project realm.
                     */
                    exports = Arrays.asListextensionRealm.getId() );
                }
                for ( String export : exports )
                {
                    projectRealm.importFromextensionRealmexport );
                }
            }
            DependencyFilter extensionArtifactFilter = null;
            if ( !exclusions.isEmpty() )
            {
                extensionArtifactFilter = new ExclusionsDependencyFilterexclusions );
            }
            record = .putextensionRealmsprojectRealmextensionArtifactFilter );
        }
        .registerprojectrecord );
        return record;
    }
    private List<ArtifactresolveExtensionArtifactsPlugin extensionPluginList<RemoteRepositoryrepositories,
                                                      ProjectBuildingRequest request )
        throws PluginResolutionException
    {
        DependencyNode root =
            .resolveextensionPluginnullnullrepositories,
                                                request.getRepositorySession() );
        root.acceptnlg );
        return nlg.getArtifactsfalse );
    }
    public void selectProjectRealmMavenProject project )
    {
        ClassLoader projectRealm = project.getClassRealm();
        if ( projectRealm == null )
        {
            projectRealm = .getCoreRealm();
        }
        Thread.currentThread().setContextClassLoaderprojectRealm );
    }
New to GrepCode? Check out our FAQ X