Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.maven.project.artifact;
  
  /*
   * 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 = MavenMetadataCache.class )
     implements MavenMetadataCache
 {
 
     protected final Map<CacheKeyCacheRecordcache = new ConcurrentHashMap<CacheKeyCacheRecord>();
 
     public static class CacheKey
     {
         private final Artifact artifact;
         private final long pomHash;
         private final boolean resolveManagedVersions;
         private final List<ArtifactRepositoryrepositories = new ArrayList<ArtifactRepository>();
         private final int hashCode;
 
         public CacheKeyArtifact artifactboolean resolveManagedVersionsArtifactRepository localRepository,
                          List<ArtifactRepositoryremoteRepositories )
         {
             File file = artifact.getFile();
             this. = ArtifactUtils.copyArtifactartifact );
             if ( "pom".equalsartifact.getType() ) && file != null )
             {
                  = file.getPath().hashCode() + file.lastModified();
             }
             else
             {
                  = 0;
             }
             this. = resolveManagedVersions;
             this..addlocalRepository );
             this..addAllremoteRepositories );
 
             int hash = 17;
             hash = hash * 31 + artifactHashCodeartifact );
             hash = hash * 31 + ( resolveManagedVersions ? 1 : 2 );
             hash = hash * 31 + repositoriesHashCode );
             this. = hash;
         }
 
         @Override
         public int hashCode()
         {
             return ;
         }
 
         @Override
         public boolean equalsObject o )
         {
             if ( o == this )
             {
                 return true;
             }
 
             if ( !( o instanceof CacheKey ) )
             {
                 return false;
             }
 
             CacheKey other = (CacheKeyo;
 
             return  == other.pomHash && artifactEqualsother.artifact )
                &&  == other.resolveManagedVersions
                && repositoriesEqualsother.repositories );
        }
    }
    private static int artifactHashCodeArtifact a )
    {
        int result = 17;
        result = 31 * result + a.getGroupId().hashCode();
        result = 31 * result + a.getArtifactId().hashCode();
        result = 31 * result + a.getType().hashCode();
        if ( a.getVersion() != null )
        {
            result = 31 * result + a.getVersion().hashCode();
        }
        result = 31 * result + ( a.getClassifier() != null ? a.getClassifier().hashCode() : 0 );
        result = 31 * result + ( a.getScope() != null ? a.getScope().hashCode() : 0 );
        result = 31 * result + ( a.getDependencyFilter() != null ? a.getDependencyFilter().hashCode() : 0 );
        result = 31 * result + ( a.isOptional() ? 1 : 0 );
        return result;
    }
    private static boolean artifactEqualsArtifact a1Artifact a2 )
    {
        if ( a1 == a2 )
        {
            return true;
        }
        return eqa1.getGroupId(), a2.getGroupId() )
            && eqa1.getArtifactId(), a2.getArtifactId() )
            && eqa1.getType(), a2.getType() )
            && eqa1.getVersion(), a2.getVersion() )
            && eqa1.getClassifier(), a2.getClassifier() )
            && eqa1.getScope(), a2.getScope() )
            && eqa1.getDependencyFilter(), a2.getDependencyFilter() )
            && a1.isOptional() == a2.isOptional();
    }
    private static int repositoryHashCodeArtifactRepository repository )
    {
        int result = 17;
        result = 31 * result + ( repository.getId() != null ? repository.getId().hashCode() : 0 );
        return result;
    }
    private static int repositoriesHashCodeList<ArtifactRepositoryrepositories )
    {
        int result = 17;
        for ( ArtifactRepository repository : repositories )
        {
            result = 31 * result + repositoryHashCoderepository );
        }
        return result;
    }
    private static boolean repositoryEqualsArtifactRepository r1ArtifactRepository r2 )
    {
        if ( r1 == r2 )
        {
            return true;
        }
        return eqr1.getId(), r2.getId() ) && eqr1.getUrl(), r2.getUrl() )
            && repositoryPolicyEqualsr1.getReleases(), r2.getReleases() )
            && repositoryPolicyEqualsr1.getSnapshots(), r2.getSnapshots() );
    }
    private static boolean repositoryPolicyEqualsArtifactRepositoryPolicy p1ArtifactRepositoryPolicy p2 )
    {
        if ( p1 == p2 )
        {
            return true;
        }
        return p1.isEnabled() == p2.isEnabled() && eqp1.getUpdatePolicy(), p2.getUpdatePolicy() );
    }
    private static boolean repositoriesEqualsList<ArtifactRepositoryr1List<ArtifactRepositoryr2 )
    {
        if ( r1.size() != r2.size() )
        {
            return false;
        }
        for ( Iterator<ArtifactRepositoryit1 = r1.iterator(), it2 = r2.iterator(); it1.hasNext(); )
        {
            if ( !repositoryEqualsit1.next(), it2.next() ) )
            {
                return false;
            }
        }
        return true;
    }
    private static <T> boolean eq( T s1, T s2 )
    {
        return s1 != null ? s1.equalss2 ) : s2 == null;
    }
    public class CacheRecord
    {
        private Artifact pomArtifact;
        private Artifact relocatedArtifact;
        private List<Artifactartifacts;
        private Map<StringArtifactmanagedVersions;
        private List<ArtifactRepositoryremoteRepositories;
        private long length;
        private long timestamp;
        CacheRecordArtifact pomArtifactArtifact relocatedArtifactSet<Artifactartifacts,
                     Map<StringArtifactmanagedVersionsList<ArtifactRepositoryremoteRepositories )
        {
            this. = ArtifactUtils.copyArtifactpomArtifact );
            this. = ArtifactUtils.copyArtifactSaferelocatedArtifact );
            this. = ArtifactUtils.copyArtifactsartifactsnew ArrayList<Artifact>() );
            this. = new ArrayList<ArtifactRepository>( remoteRepositories );
            this. = managedVersions;
            if ( managedVersions != null )
            {
                this. =
                    ArtifactUtils.copyArtifactsmanagedVersionsnew LinkedHashMap<StringArtifact>() );
            }
            File pomFile = pomArtifact.getFile();
            if ( pomFile != null && pomFile.canRead() )
            {
                this. = pomFile.length();
                this. = pomFile.lastModified();
            }
            else
            {
                this. = -1;
                this. = -1;
            }
        }
        public Artifact getArtifact()
        {
            return ;
        }
        public Artifact getRelocatedArtifact()
        {
            return ;
        }
        public List<ArtifactgetArtifacts()
        {
            return ;
        }
        public Map<StringArtifactgetManagedVersions()
        {
            return ;
        }
        {
            return ;
        }
        public boolean isStale()
        {
            File pomFile = .getFile();
            if ( pomFile != null )
            {
                if ( pomFile.canRead() )
                {
                    return  != pomFile.length() ||  != pomFile.lastModified();
                }
                else
                {
                    // if the POM didn't exist, retry if any repo is configured to always update
                    boolean snapshot = .isSnapshot();
                    for ( ArtifactRepository repository :  )
                    {
                        ArtifactRepositoryPolicy policy =
                            snapshot ? repository.getSnapshots() : repository.getReleases();
                        if ( ..equalspolicy.getUpdatePolicy() ) )
                        {
                            return true;
                        }
                    }
                }
            }
            return  != -1 ||  != -1;
        }
    }
    public ResolutionGroup getArtifact artifactboolean resolveManagedVersionsArtifactRepository localRepository,
                                List<ArtifactRepositoryremoteRepositories )
    {
        CacheKey cacheKey = newCacheKeyartifactresolveManagedVersionslocalRepositoryremoteRepositories );
        CacheRecord cacheRecord = .getcacheKey );
        if ( cacheRecord != null && !cacheRecord.isStale() )
        {
            Artifact pomArtifact = ArtifactUtils.copyArtifactcacheRecord.getArtifact() );
            Artifact relocatedArtifact = ArtifactUtils.copyArtifactSafecacheRecord.getRelocatedArtifact() );
            Set<Artifactartifacts =
                ArtifactUtils.copyArtifactscacheRecord.getArtifacts(), new LinkedHashSet<Artifact>() );
            Map<StringArtifactmanagedVersions = cacheRecord.getManagedVersions();
            if ( managedVersions != null )
            {
                managedVersions = ArtifactUtils.copyArtifactsmanagedVersionsnew LinkedHashMap<StringArtifact>() );
            }
            return new ResolutionGrouppomArtifactrelocatedArtifactartifactsmanagedVersions,
                                        cacheRecord.getRemoteRepositories() );
        }
        .removecacheKey );
        return null;
    }
    public void putArtifact artifactboolean resolveManagedVersionsArtifactRepository localRepository,
                     List<ArtifactRepositoryremoteRepositoriesResolutionGroup result )
    {
        putnewCacheKeyartifactresolveManagedVersionslocalRepositoryremoteRepositories ), result );
    }
    protected CacheKey newCacheKeyArtifact artifactboolean resolveManagedVersions,
                                    ArtifactRepository localRepositoryList<ArtifactRepositoryremoteRepositories )
    {
        return new CacheKeyartifactresolveManagedVersionslocalRepositoryremoteRepositories );
    }
    protected void putCacheKey cacheKeyResolutionGroup result )
    {
        CacheRecord cacheRecord =
            new CacheRecordresult.getPomArtifact(), result.getRelocatedArtifact(), result.getArtifacts(),
                             result.getManagedVersions(), result.getResolutionRepositories() );
        .putcacheKeycacheRecord );
    }
    public void flush()
    {
        .clear();
    }
New to GrepCode? Check out our FAQ X