You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2009/05/29 21:22:04 UTC
svn commit: r780080 - in
/maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact:
DefaultMavenMetadataCache.java MavenMetadataCache.java
MavenMetadataSource.java
Author: jvanzyl
Date: Fri May 29 19:22:03 2009
New Revision: 780080
URL: http://svn.apache.org/viewvc?rev=780080&view=rev
Log:
o adding a metadata cache
Submitted by: Igor Fedorenko
Added:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java (with props)
maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java (with props)
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
Added: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java?rev=780080&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java (added)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java Fri May 29 19:22:03 2009
@@ -0,0 +1,161 @@
+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.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.codehaus.plexus.component.annotations.Component;
+
+@Component( role = MavenMetadataCache.class )
+public class DefaultMavenMetadataCache
+ implements MavenMetadataCache
+{
+
+ public static class CacheKey
+ {
+ Artifact artifact;
+ List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>();
+
+ CacheKey( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
+ {
+ this.artifact = ArtifactUtils.copyArtifact( artifact );
+ this.repositories.add( localRepository );
+ this.repositories.addAll( remoteRepositories );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int hash = 17;
+ hash = hash * 31 + artifact.hashCode();
+ hash = hash * 31 + repositories.hashCode();
+
+ return hash;
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( o == this )
+ {
+ return true;
+ }
+
+ if ( !(o instanceof CacheKey) )
+ {
+ return false;
+ }
+
+ CacheKey other = (CacheKey) o;
+
+ return artifact.equals( other.artifact ) && repositories.equals( other.repositories );
+ }
+ }
+
+ public class CacheRecord
+ {
+ Artifact pomArtifact;
+ List<Artifact> artifacts;
+ List<ArtifactRepository> remoteRepositories;
+
+ long length;
+ long timestamp;
+
+ CacheRecord(Artifact pomArtifact, Set<Artifact> artifacts, List<ArtifactRepository> remoteRepositories)
+ {
+ this.pomArtifact = ArtifactUtils.copyArtifact( pomArtifact );
+ this.artifacts = copyArtifacts( artifacts );
+ this.remoteRepositories = new ArrayList<ArtifactRepository>( remoteRepositories );
+
+
+ File pomFile = pomArtifact.getFile();
+ if ( pomFile != null && pomFile.canRead() )
+ {
+ this.length = pomFile.length();
+ this.timestamp = pomFile.lastModified();
+ }
+ else
+ {
+ this.length = -1;
+ this.timestamp = -1;
+ }
+ }
+
+ public boolean isStale()
+ {
+ File pomFile = pomArtifact.getFile();
+ if ( pomFile != null && pomFile.canRead() )
+ {
+ return length != pomFile.length() || timestamp != pomFile.lastModified();
+ }
+
+ return length != -1 || timestamp != -1;
+ }
+ }
+
+ private Map<CacheKey, CacheRecord> cache = new HashMap<CacheKey, CacheRecord>();
+
+ public ResolutionGroup get( Artifact artifact, ArtifactRepository localRepository,
+ List<ArtifactRepository> remoteRepositories )
+ {
+ CacheKey cacheKey = new CacheKey( artifact, localRepository, remoteRepositories );
+
+ CacheRecord cacheRecord = cache.get( cacheKey );
+
+ if ( cacheRecord != null && !cacheRecord.isStale() )
+ {
+ Artifact pomArtifact = ArtifactUtils.copyArtifact( cacheRecord.pomArtifact );
+ Set<Artifact> artifacts = new LinkedHashSet<Artifact>( copyArtifacts( cacheRecord.artifacts ) );
+ return new ResolutionGroup( pomArtifact, artifacts , cacheRecord.remoteRepositories );
+ }
+
+ cache.remove( cacheKey );
+
+ return null;
+ }
+
+ public void put( Artifact artifact, ArtifactRepository localRepository,
+ List<ArtifactRepository> remoteRepositories, ResolutionGroup result )
+ {
+ CacheKey cacheKey = new CacheKey( artifact, localRepository, remoteRepositories );
+ CacheRecord cacheRecord = new CacheRecord( result.getPomArtifact(), result.getArtifacts(), result.getResolutionRepositories() );
+
+ cache.put( cacheKey, cacheRecord );
+ }
+
+ public static List<Artifact> copyArtifacts( Collection<Artifact> artifacts )
+ {
+ ArrayList<Artifact> result = new ArrayList<Artifact>();
+ for ( Artifact artifact : artifacts )
+ {
+ result.add( ArtifactUtils.copyArtifact( artifact ) );
+ }
+ return result;
+ }
+
+}
Propchange: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMavenMetadataCache.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java?rev=780080&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java (added)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java Fri May 29 19:22:03 2009
@@ -0,0 +1,34 @@
+package org.apache.maven.project.artifact;
+
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.metadata.ResolutionGroup;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+
+/*
+ * 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.
+ */
+
+
+public interface MavenMetadataCache
+{
+
+ ResolutionGroup get( Artifact artifact, ArtifactRepository localRepository,
+ List<ArtifactRepository> remoteRepositories );
+
+ void put( Artifact artifact, ArtifactRepository localRepository,
+ List<ArtifactRepository> remoteRepositories, ResolutionGroup result );
+
+}
Propchange: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataCache.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java?rev=780080&r1=780079&r2=780080&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java Fri May 29 19:22:03 2009
@@ -71,9 +71,21 @@
@Requirement
private Logger logger;
+ @Requirement
+ private MavenMetadataCache cache;
+
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
throws ArtifactMetadataRetrievalException
{
+ /*
+ ResolutionGroup cached = cache.get( artifact, localRepository, remoteRepositories );
+
+ if ( cached != null )
+ {
+ return cached;
+ }
+ */
+
List<Dependency> dependencies;
Artifact pomArtifact;
@@ -155,7 +167,11 @@
}
}
- return new ResolutionGroup( pomArtifact, artifacts, remoteRepositories );
+ ResolutionGroup result = new ResolutionGroup( pomArtifact, artifacts, remoteRepositories );
+
+ //cache.put( artifact, localRepository, remoteRepositories, result );
+
+ return result;
}
private String getEffectiveScope( String originalScope, String inheritedScope )
Re: svn commit: r780080 - in /maven/components/trunk/maven-core/src/main/java/org/apache/maven/project/artifact: DefaultMavenMetadataCache.java MavenMetadataCache.java MavenMetadataSource.java
Posted by Brett Porter <br...@apache.org>.
On 30/05/2009, at 5:22 AM, jvanzyl@apache.org wrote:
> Author: jvanzyl
> Date: Fri May 29 19:22:03 2009
> New Revision: 780080
>
> URL: http://svn.apache.org/viewvc?rev=780080&view=rev
> Log:
> o adding a metadata cache
> Submitted by: Igor Fedorenko
Can you please handle these contributions via JIRA?
Thanks,
Brett
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org