ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r601621 - in /ant/ivy/core/branches/2.0.0-beta1: ./ src/etc/license/ src/java/org/apache/ivy/ant/ src/java/org/apache/ivy/core/cache/ src/java/org/apache/ivy/core/resolve/ src/java/org/apache/ivy/core/settings/ src/java/org/apache/ivy/plugi...
Date Thu, 06 Dec 2007 05:41:39 GMT
Author: xavier
Date: Wed Dec  5 21:41:34 2007
New Revision: 601621

URL: http://svn.apache.org/viewvc?rev=601621&view=rev
Log:
merge bugfix for cache locking + makepom changes; use makepom changes + package crypto in
build-release.xml

Added:
    ant/ivy/core/branches/2.0.0-beta1/src/etc/license/
    ant/ivy/core/branches/2.0.0-beta1/src/etc/license/license-header.xml   (with props)
Modified:
    ant/ivy/core/branches/2.0.0-beta1/build-release.xml
    ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/ant/IvyMakePom.java
    ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/cache/CacheManager.java
    ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java
    ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/resolve/IvyNode.java
    ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/settings/IvySettings.java
    ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java
    ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java

Modified: ant/ivy/core/branches/2.0.0-beta1/build-release.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.0-beta1/build-release.xml?rev=601621&r1=601620&r2=601621&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.0-beta1/build-release.xml (original)
+++ ant/ivy/core/branches/2.0.0-beta1/build-release.xml Wed Dec  5 21:41:34 2007
@@ -64,6 +64,7 @@
 			<zipfileset dir="${doc.build.dir}" prefix="${snapshot.full.name}/doc" excludes="**/reports/coverage/**,**/reports/test/**"/>
 			<zipfileset dir="${src.dir}" prefix="${snapshot.full.name}/src/java"/>
 			<zipfileset dir="${basedir}/src/example" prefix="${snapshot.full.name}/src/example"/>
+			<zipfileset dir="${basedir}/src/etc" prefix="${snapshot.full.name}/src/etc"/>
 			<zipfileset dir="${test.dir}" prefix="${snapshot.full.name}/test/java"/>
 			<zipfileset dir="${basedir}/test/repositories" prefix="${snapshot.full.name}/test/repositories"/>
 			<zipfileset dir="${basedir}/test/buildlist" prefix="${snapshot.full.name}/test/buildlist"/>
@@ -72,6 +73,7 @@
 			<zipfileset dir="${src.dir}/org/apache/ivy/plugins/parser/xml" includes="ivy.xsd" fullpath="${snapshot.full.name}/ivy.xsd"/>
 			<zipfileset dir="${basedir}" includes="MANIFEST.MF" fullpath="${snapshot.full.name}/MANIFEST.MF"/>
 			<zipfileset dir="${basedir}" includes="NOTICE" fullpath="${snapshot.full.name}/NOTICE"/>
+			<zipfileset dir="${basedir}" includes="README" fullpath="${snapshot.full.name}/README"/>
 			<zipfileset dir="${basedir}" includes="LICENSE*" prefix="${snapshot.full.name}"/>
 			<zipfileset dir="${basedir}" includes="CHANGES.txt" fullpath="${snapshot.full.name}/CHANGES.txt"/>
 			<zipfileset dir="${basedir}" includes="RELEASE_NOTES" fullpath="${snapshot.full.name}/RELEASE_NOTES"/>
@@ -93,6 +95,7 @@
 			<zipfileset dir="${doc.build.dir}" prefix="${snapshot.full.name}/doc" excludes="**/reports/coverage/**,**/reports/test/**"/>
 			<zipfileset dir="${basedir}/src/example" prefix="${snapshot.full.name}/src/example"/>
 			<zipfileset dir="${basedir}" includes="NOTICE" fullpath="${snapshot.full.name}/NOTICE"/>
+			<zipfileset dir="${basedir}" includes="README" fullpath="${snapshot.full.name}/README"/>
 			<zipfileset dir="${basedir}" includes="LICENSE*" prefix="${snapshot.full.name}"/>
 			<zipfileset dir="${basedir}" includes="CHANGES.txt" fullpath="${snapshot.full.name}/CHANGES.txt"/>
 			<zipfileset dir="${basedir}" includes="RELEASE_NOTES" fullpath="${snapshot.full.name}/RELEASE_NOTES"/>
@@ -116,6 +119,7 @@
 			<zipfileset dir="${doc.build.dir}" prefix="${snapshot.full.name}/doc" excludes="**/reports/coverage/**,**/reports/test/**"/>
 			<zipfileset dir="${basedir}/src/example" prefix="${snapshot.full.name}/src/example"/>
 			<zipfileset dir="${basedir}" includes="NOTICE" fullpath="${snapshot.full.name}/NOTICE"/>
+			<zipfileset dir="${basedir}" includes="README" fullpath="${snapshot.full.name}/README"/>
 			<zipfileset dir="${basedir}" includes="LICENSE*" prefix="${snapshot.full.name}"/>
 			<zipfileset dir="${basedir}" includes="CHANGES.txt" fullpath="${snapshot.full.name}/CHANGES.txt"/>
 			<zipfileset dir="${basedir}" includes="RELEASE_NOTES" fullpath="${snapshot.full.name}/RELEASE_NOTES"/>
@@ -151,7 +155,8 @@
 	<target name="snapshot-maven2" depends="init-snapshot, snapshot-metadata, jar, sources,
javadoc">
 		<property name="m2.distrib.dir" value="${distrib.dir}/maven2/${build.version}" />
 		<ivy:makepom ivyfile="${distrib.dir}/ivy.xml" 
-	                 pomfile="${m2.distrib.dir}/ivy-${build.version}.pom">
+	                 pomfile="${m2.distrib.dir}/ivy-${build.version}.pom"
+                     headerfile="${basedir}/src/etc/license/license-header.xml">
 			<mapping conf="core" scope="compile"/>
 			<mapping conf="test" scope="test"/>
 		</ivy:makepom>

Added: ant/ivy/core/branches/2.0.0-beta1/src/etc/license/license-header.xml
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.0-beta1/src/etc/license/license-header.xml?rev=601621&view=auto
==============================================================================
--- ant/ivy/core/branches/2.0.0-beta1/src/etc/license/license-header.xml (added)
+++ ant/ivy/core/branches/2.0.0-beta1/src/etc/license/license-header.xml Wed Dec  5 21:41:34
2007
@@ -0,0 +1,18 @@
+<!--
+   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.    
+-->

Propchange: ant/ivy/core/branches/2.0.0-beta1/src/etc/license/license-header.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/ant/IvyMakePom.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/ant/IvyMakePom.java?rev=601621&r1=601620&r2=601621&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/ant/IvyMakePom.java (original)
+++ ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/ant/IvyMakePom.java Wed Dec
 5 21:41:34 2007
@@ -30,8 +30,10 @@
 import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorWriter;
 import org.apache.ivy.plugins.parser.m2.PomModuleDescriptorWriter.ConfigurationScopeMapping;
 import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorParser;
+import org.apache.ivy.util.FileUtil;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  * Convert an ivy file to a pom
@@ -56,6 +58,8 @@
 
     private File pomFile = null;
 
+    private File headerFile = null;
+
     private File ivyFile = null;
 
     private Collection mappings = new ArrayList();
@@ -75,6 +79,14 @@
     public void setIvyFile(File ivyFile) {
         this.ivyFile = ivyFile;
     }
+
+    public File getHeaderFile() {
+        return headerFile;
+    }
+
+    public void setHeaderFile(File headerFile) {
+        this.headerFile = headerFile;
+    }
     
     public Mapping createMapping() {
         Mapping mapping = new Mapping();
@@ -92,7 +104,8 @@
             }
             ModuleDescriptor md = XmlModuleDescriptorParser.getInstance().parseDescriptor(
                 getSettings(), ivyFile.toURL(), false);
-            PomModuleDescriptorWriter.write(md, 
+            PomModuleDescriptorWriter.write(md,
+                headerFile == null ? null : FileUtil.readEntirely(getHeaderFile()),
                 mappings.isEmpty() 
                     ? PomModuleDescriptorWriter.DEFAULT_MAPPING
                     : new ConfigurationScopeMapping(getMappingsMap()), pomFile);

Modified: ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/cache/CacheManager.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/cache/CacheManager.java?rev=601621&r1=601620&r2=601621&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/cache/CacheManager.java
(original)
+++ ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/cache/CacheManager.java
Wed Dec  5 21:41:34 2007
@@ -164,7 +164,8 @@
      * @param name
      *            resolver name
      */
-    public void saveResolver(ModuleDescriptor md, String name) {
+    private void saveResolver(ModuleDescriptor md, String name) {
+        // should always be called with a lock on module metadata artifact
         PropertiesFile cdf = getCachedDataFile(md);
         cdf.setProperty("resolver", name);
         cdf.save();
@@ -179,38 +180,72 @@
      * @param name
      *            artifact resolver name
      */
-    public void saveArtResolver(ModuleDescriptor md, String name) {
+    public void saveResolvers(
+            ModuleDescriptor md, String metadataResolverName, String artifactResolverName)
{
+        ModuleRevisionId mrid = md.getResolvedModuleRevisionId();
+        if (!lockMetadataArtifact(mrid)) {
+            Message.error("impossible to acquire lock for " + mrid);
+            return;
+        }
+        try {
+            PropertiesFile cdf = getCachedDataFile(md);
+            cdf.setProperty("resolver", metadataResolverName);
+            cdf.setProperty("artifact.resolver", artifactResolverName);
+            cdf.save();
+        } finally {
+            unlockMetadataArtifact(mrid);
+        }
+    }
+
+    private String getSavedResolverName(ModuleDescriptor md) {
+        // should always be called with a lock on module metadata artifact
         PropertiesFile cdf = getCachedDataFile(md);
-        cdf.setProperty("artifact.resolver", name);
-        cdf.save();
+        return cdf.getProperty("resolver");
+    }
+
+    private String getSavedArtResolverName(ModuleDescriptor md) {
+        // should always be called with a lock on module metadata artifact
+        PropertiesFile cdf = getCachedDataFile(md);
+        return cdf.getProperty("artifact.resolver");
     }
 
-    public void saveArtifactOrigin(Artifact artifact, ArtifactOrigin origin) {
+    void saveArtifactOrigin(Artifact artifact, ArtifactOrigin origin) {
+        // should always be called with a lock on module metadata artifact
         PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId());
         cdf.setProperty(getIsLocalKey(artifact), String.valueOf(origin.isLocal()));
         cdf.setProperty(getLocationKey(artifact), origin.getLocation());
         cdf.save();
     }
 
-    public ArtifactOrigin getSavedArtifactOrigin(Artifact artifact) {
+    private void removeSavedArtifactOrigin(Artifact artifact) {
+        // should always be called with a lock on module metadata artifact
         PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId());
-        String location = cdf.getProperty(getLocationKey(artifact));
-        String local = cdf.getProperty(getIsLocalKey(artifact));
-        boolean isLocal = Boolean.valueOf(local).booleanValue();
+        cdf.remove(getLocationKey(artifact));
+        cdf.remove(getIsLocalKey(artifact));
+        cdf.save();
+    }
 
-        if (location == null) {
-            // origin has not been specified, return null
+    public ArtifactOrigin getSavedArtifactOrigin(Artifact artifact) {
+        ModuleRevisionId mrid = artifact.getModuleRevisionId();
+        if (!lockMetadataArtifact(mrid)) {
+            Message.error("impossible to acquire lock for " + mrid);
             return null;
         }
+        try {
+            PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId());
+            String location = cdf.getProperty(getLocationKey(artifact));
+            String local = cdf.getProperty(getIsLocalKey(artifact));
+            boolean isLocal = Boolean.valueOf(local).booleanValue();
+
+            if (location == null) {
+                // origin has not been specified, return null
+                return null;
+            }
 
-        return new ArtifactOrigin(isLocal, location);
-    }
-
-    public void removeSavedArtifactOrigin(Artifact artifact) {
-        PropertiesFile cdf = getCachedDataFile(artifact.getModuleRevisionId());
-        cdf.remove(getLocationKey(artifact));
-        cdf.remove(getIsLocalKey(artifact));
-        cdf.save();
+            return new ArtifactOrigin(isLocal, location);
+        } finally {
+            unlockMetadataArtifact(mrid);
+        }
     }
 
     /**
@@ -252,16 +287,6 @@
         return prefix + ".is-local";
     }
 
-    private String getSavedResolverName(ModuleDescriptor md) {
-        PropertiesFile cdf = getCachedDataFile(md);
-        return cdf.getProperty("resolver");
-    }
-
-    private String getSavedArtResolverName(ModuleDescriptor md) {
-        PropertiesFile cdf = getCachedDataFile(md);
-        return cdf.getProperty("artifact.resolver");
-    }
-
     private PropertiesFile getCachedDataFile(ModuleDescriptor md) {
         return getCachedDataFile(md.getResolvedModuleRevisionId());
     }
@@ -274,58 +299,66 @@
 
     public ResolvedModuleRevision findModuleInCache(
             ModuleRevisionId mrid, boolean validate, String expectedResolver) {
-        // first, check if it is in cache
         if (!settings.getVersionMatcher().isDynamic(mrid)) {
-            File ivyFile = getIvyFileInCache(mrid);
-            if (ivyFile.exists()) {
-                // found in cache !
-                try {
-                    ModuleDescriptor depMD = XmlModuleDescriptorParser.getInstance()
-                            .parseDescriptor(settings, ivyFile.toURL(), validate);
-                    String resolverName = getSavedResolverName(depMD);
-                    String artResolverName = getSavedArtResolverName(depMD);
-                    DependencyResolver resolver = settings.getResolver(resolverName);
-                    if (resolver == null) {
-                        Message.debug("\tresolver not found: " + resolverName
+            if (!lockMetadataArtifact(mrid)) {
+                Message.error("impossible to acquire lock for " + mrid);
+                return null;
+            }
+            try {
+                // first, check if it is in cache
+                File ivyFile = getIvyFileInCache(mrid);
+                if (ivyFile.exists()) {
+                    // found in cache !
+                    try {
+                        ModuleDescriptor depMD = XmlModuleDescriptorParser.getInstance()
+                        .parseDescriptor(settings, ivyFile.toURL(), validate);
+                        String resolverName = getSavedResolverName(depMD);
+                        String artResolverName = getSavedArtResolverName(depMD);
+                        DependencyResolver resolver = settings.getResolver(resolverName);
+                        if (resolver == null) {
+                            Message.debug("\tresolver not found: " + resolverName
                                 + " => trying to use the one configured for " + mrid);
-                        resolver = settings.getResolver(depMD.getResolvedModuleRevisionId()
+                            resolver = settings.getResolver(depMD.getResolvedModuleRevisionId()
                                 .getModuleId());
-                        if (resolver != null) {
-                            Message.debug("\tconfigured resolver found for "
+                            if (resolver != null) {
+                                Message.debug("\tconfigured resolver found for "
                                     + depMD.getResolvedModuleRevisionId() + ": "
                                     + resolver.getName() + ": saving this data");
-                            saveResolver(depMD, resolver.getName());
+                                saveResolver(depMD, resolver.getName());
+                            }
                         }
-                    }
-                    DependencyResolver artResolver = settings.getResolver(artResolverName);
-                    if (artResolver == null) {
-                        artResolver = resolver;
-                    }
-                    if (resolver != null) {
-                        Message.debug("\tfound ivy file in cache for " + mrid + " (resolved
by "
+                        DependencyResolver artResolver = settings.getResolver(artResolverName);
+                        if (artResolver == null) {
+                            artResolver = resolver;
+                        }
+                        if (resolver != null) {
+                            Message.debug("\tfound ivy file in cache for " + mrid + " (resolved
by "
                                 + resolver.getName() + "): " + ivyFile);
-                        if (expectedResolver != null 
-                                && expectedResolver.equals(resolver.getName())) {
-                            return new DefaultModuleRevision(
-                                resolver, artResolver, depMD, false, false);
+                            if (expectedResolver != null 
+                                    && expectedResolver.equals(resolver.getName()))
{
+                                return new DefaultModuleRevision(
+                                    resolver, artResolver, depMD, false, false);
+                            } else {
+                                Message.debug(
+                                    "found module in cache but with a different resolver:
"
+                                    + "discarding: " + mrid 
+                                    + "; expected resolver=" + expectedResolver 
+                                    + "; resolver=" + resolver.getName());
+                            }
                         } else {
-                            Message.debug(
-                                "found module in cache but with a different resolver: "
-                                + "discarding: " + mrid 
-                                + "; expected resolver=" + expectedResolver 
-                                + "; resolver=" + resolver.getName());                  
         
-                        }
-                    } else {
-                        Message.debug("\tresolver not found: " + resolverName
+                            Message.debug("\tresolver not found: " + resolverName
                                 + " => cannot use cached ivy file for " + mrid);
-                    }
-                } catch (Exception e) {
-                    // will try with resolver
-                    Message.debug("\tproblem while parsing cached ivy file for: " + mrid
+ ": "
+                        }
+                    } catch (Exception e) {
+                        // will try with resolver
+                        Message.debug("\tproblem while parsing cached ivy file for: " + mrid
+ ": "
                             + e.getMessage());
+                    }
+                } else {
+                    Message.debug("\tno ivy file in cache for " + mrid + ": tried " + ivyFile);
                 }
-            } else {
-                Message.debug("\tno ivy file in cache for " + mrid + ": tried " + ivyFile);
+            } finally {
+                unlockMetadataArtifact(mrid);
             }
         }
         return null;
@@ -362,11 +395,14 @@
         final ArtifactDownloadReport adr = new ArtifactDownloadReport(artifact);
         boolean useOrigin = options.isUseOrigin();
         
-        LockStrategy lockStrategy = getLockStrategy();
-        
-        if (!lockArtifact(artifact)) {
+        // TODO: see if we could lock on the artifact to download only, instead of the module
+        // metadata artifact. We'd need to store artifact origin and is local in artifact
specific
+        // file to do so, or lock the metadata artifact only to update artifact origin, which
would
+        // mean acquiring nested locks, which can be a dangerous thing
+        ModuleRevisionId mrid = artifact.getModuleRevisionId();
+        if (!lockMetadataArtifact(mrid)) {
             adr.setDownloadStatus(DownloadStatus.FAILED);
-            adr.setDownloadDetails("impossible to get artifact lock with " + lockStrategy);
+            adr.setDownloadDetails("impossible to get lock for " + mrid);
             return adr;
         }
         try {
@@ -438,23 +474,10 @@
             }
             return adr;
         } finally {
-            unlockArtifact(artifact);
-        }
-    }
-    
-    private boolean lockArtifact(Artifact artifact) {
-        try {
-            return getLockStrategy().lockArtifact(artifact, getArchiveFileInCache(artifact,
null));
-        } catch (InterruptedException e) {
-            Thread.currentThread().interrupt(); // reset interrupt status 
-            throw new RuntimeException("operation interrupted");
+            unlockMetadataArtifact(mrid);
         }
     }
     
-    private void unlockArtifact(Artifact artifact) {
-        getLockStrategy().unlockArtifact(artifact, getArchiveFileInCache(artifact, null));
-    }
-    
     public void originalToCachedModuleDescriptor(
             DependencyResolver resolver, ResolvedResource orginalMetadataRef,
             Artifact requestedMetadataArtifact,
@@ -462,8 +485,9 @@
         Artifact originalMetadataArtifact = getOriginalMetadataArtifact(requestedMetadataArtifact);
         File mdFileInCache = getIvyFileInCache(md.getResolvedModuleRevisionId());
 
-        if (!lockArtifact(originalMetadataArtifact)) {
-            Message.warn("impossible to get artifact lock for: " + requestedMetadataArtifact);
+        ModuleRevisionId mrid = requestedMetadataArtifact.getModuleRevisionId();
+        if (!lockMetadataArtifact(mrid)) {
+            Message.warn("impossible to acquire lock for: " + mrid);
             return;
         }
         try {
@@ -471,8 +495,7 @@
                 getArchiveFileInCache(originalMetadataArtifact), 
                 mdFileInCache);
 
-            saveResolver(md, resolver.getName());
-            saveArtResolver(md, resolver.getName());
+            saveResolvers(md, resolver.getName(), resolver.getName());
         } catch (RuntimeException e) {
             throw e;
         } catch (Exception e) {
@@ -482,10 +505,10 @@
                         : String.valueOf(orginalMetadataRef))
                 + ". " + e.getClass().getName() + ": " + e.getMessage());
         } finally {
-            unlockArtifact(originalMetadataArtifact);
+            unlockMetadataArtifact(mrid);
         }
     }
-    
+
     public ResolvedModuleRevision cacheModuleDescriptor(
             DependencyResolver resolver, final ResolvedResource mdRef, Artifact moduleArtifact,

             ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException
{
@@ -495,116 +518,164 @@
         ArtifactDownloadReport report;
         ModuleRevisionId mrid = moduleArtifact.getModuleRevisionId();
         Artifact originalMetadataArtifact = getOriginalMetadataArtifact(moduleArtifact);
-        if (!lockArtifact(originalMetadataArtifact)) {
-            Message.error("impossible to acquire lock for " + originalMetadataArtifact);
+        if (!lockMetadataArtifact(mrid)) {
+            Message.error("impossible to acquire lock for " + mrid);
             return null;
         }
         try {
-        // now let's see if we can find it in cache and if it is up to date
-        ResolvedModuleRevision rmr = findModuleInCache(
-            mrid, options.isValidate(), resolver.getName());
-        if (rmr != null) {
-            if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this) {
-                Message.verbose("\t" + getName() + ": found revision in cache: " + mrid
+            // now let's see if we can find it in cache and if it is up to date
+            ResolvedModuleRevision rmr = findModuleInCache(
+                mrid, options.isValidate(), resolver.getName());
+            if (rmr != null) {
+                if (rmr.getDescriptor().isDefault() && rmr.getResolver() != this)
{
+                    Message.verbose("\t" + getName() + ": found revision in cache: " + mrid
                         + " (resolved by " + rmr.getResolver().getName()
                         + "): but it's a default one, maybe we can find a better one");
-            } else {
-                if (!options.isCheckmodified() && !options.isChanging()) {
-                    Message.verbose("\t" + getName() + ": revision in cache: " + mrid);
-                    return DefaultModuleRevision.searchedRmr(rmr);
-                }
-                long repLastModified = mdRef.getLastModified();
-                long cacheLastModified = rmr.getDescriptor().getLastModified();
-                if (!rmr.getDescriptor().isDefault() && repLastModified <= cacheLastModified)
{
-                    Message.verbose("\t" + getName() + ": revision in cache (not updated):
"
-                            + mrid);
-                    return DefaultModuleRevision.searchedRmr(rmr);
                 } else {
-                    Message.verbose("\t" + getName() + ": revision in cache is not up to
date: "
+                    if (!options.isCheckmodified() && !options.isChanging()) {
+                        Message.verbose("\t" + getName() + ": revision in cache: " + mrid);
+                        return DefaultModuleRevision.searchedRmr(rmr);
+                    }
+                    long repLastModified = mdRef.getLastModified();
+                    long cacheLastModified = rmr.getDescriptor().getLastModified();
+                    if (!rmr.getDescriptor().isDefault() && repLastModified <=
cacheLastModified) {
+                        Message.verbose("\t" + getName() + ": revision in cache (not updated):
"
                             + mrid);
-                    if (options.isChanging()) {
-                        // ivy file has been updated, we should see if it has a new publication
date
-                        // to see if a new download is required (in case the dependency is
a
-                        // changing one)
-                        cachedPublicationDate = rmr.getDescriptor().getResolvedPublicationDate();
+                        return DefaultModuleRevision.searchedRmr(rmr);
+                    } else {
+                        Message.verbose("\t" + getName() + ": revision in cache is not up
to date: "
+                            + mrid);
+                        if (options.isChanging()) {
+                            // ivy file has been updated, we should see if it has a new publication
+                            // date to see if a new download is required (in case the dependency
is
+                            // a changing one)
+                            cachedPublicationDate = 
+                                rmr.getDescriptor().getResolvedPublicationDate();
+                        }
                     }
                 }
             }
-        }
 
-        // now download module descriptor and parse it
-        report = download(
-            originalMetadataArtifact, 
-            new ArtifactResourceResolver() {
-                public ResolvedResource resolve(Artifact artifact) {
-                    return mdRef;
-                }
-            }, downloader, 
-            new CacheDownloadOptions().setListener(options.getListener()).setForce(true));
-        Message.verbose("\t" + report); 
-        } finally {
-            unlockArtifact(originalMetadataArtifact);
-        }
-
-        if (report.getDownloadStatus() == DownloadStatus.FAILED) {
-            Message.warn("problem while downloading module descriptor: " + mdRef.getResource()

-                + ": " + report.getDownloadDetails() 
-                + " (" + report.getDownloadTimeMillis() + "ms)");
-            return null;
-        }
+            // now download module descriptor and parse it
+            report = download(
+                originalMetadataArtifact, 
+                new ArtifactResourceResolver() {
+                    public ResolvedResource resolve(Artifact artifact) {
+                        return mdRef;
+                    }
+                }, downloader, 
+                new CacheDownloadOptions().setListener(options.getListener()).setForce(true));
+            Message.verbose("\t" + report); 
+
+            if (report.getDownloadStatus() == DownloadStatus.FAILED) {
+                Message.warn("problem while downloading module descriptor: " + mdRef.getResource()

+                    + ": " + report.getDownloadDetails() 
+                    + " (" + report.getDownloadTimeMillis() + "ms)");
+                return null;
+            }
 
-        URL cachedMDURL = null;
-        try {
-            cachedMDURL = report.getDownloadedFile().toURL();
-        } catch (MalformedURLException ex) {
-            Message.warn("malformed url exception for original in cache file: " 
-                + report.getDownloadedFile() + ": " + ex.getMessage());
-            return null;
-        }
-        try {
-            ModuleDescriptor md = parser.parseDescriptor(
-                settings, cachedMDURL, mdRef.getResource(), options.isValidate());
-            Message.debug("\t" + getName() + ": parsed downloaded md file for " + mrid 
-                + "; parsed=" + md.getModuleRevisionId());
-
-            // check if we should delete old artifacts
-            boolean deleteOldArtifacts = false;
-            if (cachedPublicationDate != null
-                    && !cachedPublicationDate.equals(md.getResolvedPublicationDate()))
{
-                // artifacts have changed, they should be downloaded again
-                Message.verbose(mrid + " has changed: deleting old artifacts");
-                deleteOldArtifacts = true;
+            URL cachedMDURL = null;
+            try {
+                cachedMDURL = report.getDownloadedFile().toURL();
+            } catch (MalformedURLException ex) {
+                Message.warn("malformed url exception for original in cache file: " 
+                    + report.getDownloadedFile() + ": " + ex.getMessage());
+                return null;
             }
-            if (deleteOldArtifacts) {
-                String[] confs = md.getConfigurationsNames();
-                for (int i = 0; i < confs.length; i++) {
-                    Artifact[] arts = md.getArtifacts(confs[i]);
-                    for (int j = 0; j < arts.length; j++) {
-                        Artifact transformedArtifact = NameSpaceHelper.transform(
-                            arts[j], options.getNamespace().getToSystemTransformer());
-                        ArtifactOrigin origin = getSavedArtifactOrigin(
-                            transformedArtifact);
-                        File artFile = getArchiveFileInCache(
-                            transformedArtifact, origin, false);
-                        if (artFile.exists()) {
-                            Message.debug("deleting " + artFile);
-                            artFile.delete();
+            try {
+                ModuleDescriptor md = parser.parseDescriptor(
+                    settings, cachedMDURL, mdRef.getResource(), options.isValidate());
+                Message.debug("\t" + getName() + ": parsed downloaded md file for " + mrid

+                    + "; parsed=" + md.getModuleRevisionId());
+
+                // check if we should delete old artifacts
+                boolean deleteOldArtifacts = false;
+                if (cachedPublicationDate != null
+                        && !cachedPublicationDate.equals(md.getResolvedPublicationDate()))
{
+                    // artifacts have changed, they should be downloaded again
+                    Message.verbose(mrid + " has changed: deleting old artifacts");
+                    deleteOldArtifacts = true;
+                }
+                if (deleteOldArtifacts) {
+                    String[] confs = md.getConfigurationsNames();
+                    for (int i = 0; i < confs.length; i++) {
+                        Artifact[] arts = md.getArtifacts(confs[i]);
+                        for (int j = 0; j < arts.length; j++) {
+                            Artifact transformedArtifact = NameSpaceHelper.transform(
+                                arts[j], options.getNamespace().getToSystemTransformer());
+                            ArtifactOrigin origin = getSavedArtifactOrigin(
+                                transformedArtifact);
+                            File artFile = getArchiveFileInCache(
+                                transformedArtifact, origin, false);
+                            if (artFile.exists()) {
+                                Message.debug("deleting " + artFile);
+                                artFile.delete();
+                            }
+                            removeSavedArtifactOrigin(transformedArtifact);
                         }
-                        removeSavedArtifactOrigin(transformedArtifact);
                     }
-                }
-            } else if (options.isChanging()) {
-                Message.verbose(mrid
+                } else if (options.isChanging()) {
+                    Message.verbose(mrid
                         + " is changing, but has not changed: will trust cached artifacts
if any");
-            }
-            return new DefaultModuleRevision(resolver, resolver, md, true, true);
-        } catch (IOException ex) {
-            Message.warn("io problem while parsing ivy file: " + mdRef.getResource() + ":
"
+                }
+                return new DefaultModuleRevision(resolver, resolver, md, true, true);
+            } catch (IOException ex) {
+                Message.warn("io problem while parsing ivy file: " + mdRef.getResource()
+ ": "
                     + ex.getMessage());
-            return null;
+                return null;
+            }
+        } finally {
+            unlockMetadataArtifact(mrid);
         }
         
     }
+
+    // lock used to lock all metadata related information access
+    private boolean lockMetadataArtifact(ModuleRevisionId mrid) {
+        Artifact artifact = getDefaultMetadataArtifact(mrid);
+        try {
+            // we need to provide an artifact origin to be sure we do not end up in a stack
overflow
+            // if the cache pattern is using original name, and the substitution thus trying
to get
+            // the saved artifact origin value which in turns calls this method
+            return getLockStrategy().lockArtifact(artifact, 
+                getArchiveFileInCache(artifact, getDefaultMetadataArtifactOrigin(mrid)));
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt(); // reset interrupt status 
+            throw new RuntimeException("operation interrupted");
+        }
+    }
+
+    private void unlockMetadataArtifact(ModuleRevisionId mrid) {
+        Artifact artifact = getDefaultMetadataArtifact(mrid);
+        getLockStrategy().unlockArtifact(artifact, 
+            getArchiveFileInCache(artifact, getDefaultMetadataArtifactOrigin(mrid)));
+    }
+    
+    
+    private ArtifactOrigin getDefaultMetadataArtifactOrigin(ModuleRevisionId mrid) {
+        // it's important to say the origin is not local to make sure it won't ever be used
for
+        // anything else than original token
+        return new ArtifactOrigin(false, getIvyFileInCache(mrid).getPath());
+    }
+    
+    private Artifact getDefaultMetadataArtifact(ModuleRevisionId mrid) {
+        return new DefaultArtifact(mrid, new Date(), "metadata", "metadata", "ivy", true);
+    }
+
+    // not used any more, but maybe useful for finer grain locking when downloading artifacts
+//    private boolean lockArtifact(Artifact artifact) {
+//        try {
+//            return getLockStrategy().lockArtifact(artifact, 
+//                getArchiveFileInCache(artifact, null));
+//        } catch (InterruptedException e) {
+//            Thread.currentThread().interrupt(); // reset interrupt status 
+//            throw new RuntimeException("operation interrupted");
+//        }
+//    }
+//    
+//    private void unlockArtifact(Artifact artifact) {
+//        getLockStrategy().unlockArtifact(artifact, getArchiveFileInCache(artifact, null));
+//    }
     
     public Artifact getOriginalMetadataArtifact(Artifact moduleArtifact) {
         return DefaultArtifact.cloneWithAnotherName(moduleArtifact, 

Modified: ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java?rev=601621&r1=601620&r2=601621&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java
(original)
+++ ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/cache/RepositoryCacheManager.java
Wed Dec  5 21:41:34 2007
@@ -63,33 +63,22 @@
     public abstract String getArchivePathInCache(Artifact artifact, ArtifactOrigin origin);
 
     /**
-     * Saves the information of which resolver was used to resolve a md, so that this info
can be
-     * retrieve later (even after a jvm restart) by getSavedResolverName(ModuleDescriptor
md)
+     * Saves the information of which resolvers were used to resolve a module (both for metadata
and
+     * artifact), so that this info can be loaded later (even after a jvm restart) for the
use of
+     * {@link #findModuleInCache(ModuleRevisionId, boolean, String)}.
      * 
      * @param md
      *            the module descriptor resolved
-     * @param name
-     *            resolver name
-     */
-    public abstract void saveResolver(ModuleDescriptor md, String name);
-
-    /**
-     * Saves the information of which resolver was used to resolve a md, so that this info
can be
-     * retrieve later (even after a jvm restart) by getSavedArtResolverName(ModuleDescriptor
md)
-     * 
-     * @param md
-     *            the module descriptor resolved
-     * @param name
+     * @param metadataResolverName
+     *            metadata resolver name
+     * @param artifactResolverName
      *            artifact resolver name
      */
-    public abstract void saveArtResolver(ModuleDescriptor md, String name);
-
-    public abstract void saveArtifactOrigin(Artifact artifact, ArtifactOrigin origin);
+    public abstract void saveResolvers(
+            ModuleDescriptor descriptor, String metadataResolverName, String artifactResolverName);
 
     public abstract ArtifactOrigin getSavedArtifactOrigin(Artifact artifact);
 
-    public abstract void removeSavedArtifactOrigin(Artifact artifact);
-
     /**
      * Search a module descriptor in cache for a mrid
      * 
@@ -130,8 +119,6 @@
             DependencyResolver resolver, ResolvedResource orginalMetadataRef, 
             Artifact requestedMetadataArtifact, 
             ResourceDownloader downloader, CacheMetadataOptions options) throws ParseException;
-
-    public Artifact getOriginalMetadataArtifact(Artifact moduleArtifact);
 
     public void originalToCachedModuleDescriptor(
             DependencyResolver resolver, ResolvedResource orginalMetadataRef, 

Modified: ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/resolve/IvyNode.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/resolve/IvyNode.java?rev=601621&r1=601620&r2=601621&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/resolve/IvyNode.java (original)
+++ ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/resolve/IvyNode.java Wed
Dec  5 21:41:34 2007
@@ -225,9 +225,8 @@
                         new EndResolveDependencyEvent(resolver, dependencyDescriptor, module,
                             System.currentTimeMillis() - start));
                     if (module != null) {
-                        data.getCacheManager().saveResolver(module.getDescriptor(),
-                            module.getResolver().getName());
-                        data.getCacheManager().saveArtResolver(module.getDescriptor(),
+                        data.getCacheManager().saveResolvers(module.getDescriptor(),
+                            module.getResolver().getName(),
                             module.getArtifactResolver().getName());
                         if (settings.logModuleWhenFound()) {
                             Message.info("\tfound " + module.getId() + " in "

Modified: ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/settings/IvySettings.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/settings/IvySettings.java?rev=601621&r1=601620&r2=601621&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/settings/IvySettings.java
(original)
+++ ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/core/settings/IvySettings.java
Wed Dec  5 21:41:34 2007
@@ -243,7 +243,7 @@
         addLatestStrategy("latest-time", latestTimeStrategy);
         
         addLockStrategy("no-lock", new NoLockStrategy());
-        addLockStrategy("artifact-lock", new ArtifactLockStrategy());
+        addLockStrategy("artifact-lock", new ArtifactLockStrategy(debugLocking()));
 
         addConflictManager("latest-revision", new LatestConflictManager("latest-revision",
             latestRevisionStrategy));
@@ -1154,7 +1154,7 @@
         return debugConflictResolution.booleanValue();
     }
 
-    public boolean debugLocking() {
+    public final boolean debugLocking() {
         if (debugLocking == null) {
             String var = getVariable("ivy.log.locking");
             debugLocking = Boolean.valueOf(var != null

Modified: ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java?rev=601621&r1=601620&r2=601621&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java
(original)
+++ ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/plugins/lock/FileBasedLockStrategy.java
Wed Dec  5 21:41:34 2007
@@ -61,23 +61,28 @@
         
     protected boolean acquireLock(File file) throws InterruptedException {
         if (isDebugLocking()) {
-            Message.info("acquiring lock on " + file);
+            debugLocking("acquiring lock on " + file);
         }
         long start = System.currentTimeMillis();
-        synchronized (this) {
-            if (hasLock(file)) {
-                incrementLock(file);
-                return true;
-            }
-        }
         do {
-            if (locker.tryLock(file)) {
-                if (isDebugLocking()) {
-                    Message.info("lock acquired on " + file 
-                        + " in " + (System.currentTimeMillis() - start) + "ms");
+            synchronized (this) {
+                if (hasLock(file)) {
+                    int holdLocks = incrementLock(file);
+                    if (isDebugLocking()) {
+                        debugLocking("reentrant lock acquired on " + file 
+                            + " in " + (System.currentTimeMillis() - start) + "ms"
+                            + " - hold locks = " + holdLocks);
+                    }
+                    return true;
+                }
+                if (locker.tryLock(file)) {
+                    if (isDebugLocking()) {
+                        debugLocking("lock acquired on " + file 
+                            + " in " + (System.currentTimeMillis() - start) + "ms");
+                    }
+                    incrementLock(file);
+                    return true;
                 }
-                incrementLock(file);
-                return true;
             }
             Thread.sleep(SLEEP_TIME);
         } while (System.currentTimeMillis() - start < timeout);
@@ -85,26 +90,40 @@
     }
 
     protected void releaseLock(File file) {
-        if (decrementLock(file) == 0) {
-            locker.unlock(file);
-            if (isDebugLocking()) {
-                Message.info("lock released on " + file);
+        synchronized (this) {
+            int holdLocks = decrementLock(file);
+            if (holdLocks == 0) {
+                locker.unlock(file);
+                if (isDebugLocking()) {
+                    debugLocking("lock released on " + file);
+                }
+            } else {
+                if (isDebugLocking()) {
+                    debugLocking("reentrant lock released on " + file 
+                        + " - hold locks = " + holdLocks);
+                }                
             }
         }
     }
 
     
-    private synchronized boolean hasLock(File file) {
+    private static void debugLocking(String msg) {
+        Message.info(Thread.currentThread() + " " + System.currentTimeMillis() + " " + msg);
+    }
+
+    private boolean hasLock(File file) {
         Integer c = (Integer) currentLockCounters.get(file);
         return c != null && c.intValue() > 0;
     }
     
-    private synchronized void incrementLock(File file) {
+    private int incrementLock(File file) {
         Integer c = (Integer) currentLockCounters.get(file);
-        currentLockCounters.put(file, new Integer(c == null ? 1 : c.intValue() + 1));
+        int holdLocks = c == null ? 1 : c.intValue() + 1;
+        currentLockCounters.put(file, new Integer(holdLocks));
+        return holdLocks;
     }
 
-    private synchronized int decrementLock(File file) {
+    private int decrementLock(File file) {
         Integer c = (Integer) currentLockCounters.get(file);
         int dc = c == null ? 0 : c.intValue() - 1;
         currentLockCounters.put(file, new Integer(dc));
@@ -134,7 +153,7 @@
                         return true;
                     } else {
                         if (debugLocking) {
-                            Message.info("file creation failed " + file);
+                            debugLocking("file creation failed " + file);
                         }
                     }
                 }
@@ -177,7 +196,7 @@
                             return true;
                         } else {
                             if (debugLocking) {
-                                Message.info("failed to acquire lock on " + file);
+                                debugLocking("failed to acquire lock on " + file);
                             }
                         }
                     } finally {

Modified: ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java?rev=601621&r1=601620&r2=601621&view=diff
==============================================================================
--- ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
(original)
+++ ant/ivy/core/branches/2.0.0-beta1/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
Wed Dec  5 21:41:34 2007
@@ -109,7 +109,7 @@
                     out.println("      <scope>" + scope + "</scope>");
                 }
                 if (mapping.isOptional(dds[i].getModuleConfigurations())) {
-                    out.println("      <optional/>");
+                    out.println("      <optional>true</optional>");
                 }
                 out.println("    </dependency>");
             }



Mime
View raw message