ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r675585 - in /ant/ivy/core/trunk: CHANGES.txt src/java/org/apache/ivy/core/publish/PublishEngine.java test/java/org/apache/ivy/ant/IvyPublishTest.java test/java/org/apache/ivy/core/publish/PublishEventsTest.java
Date Thu, 10 Jul 2008 14:19:57 GMT
Author: xavier
Date: Thu Jul 10 07:19:56 2008
New Revision: 675585

URL: http://svn.apache.org/viewvc?rev=675585&view=rev
Log:
IMPROVEMENT: Detect missing artifacts on publish asap (IVY-862)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishEngine.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyPublishTest.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/publish/PublishEventsTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=675585&r1=675584&r2=675585&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Thu Jul 10 07:19:56 2008
@@ -77,6 +77,7 @@
 - NEW: Add transitive dependency version and branch override mechanism (IVY-784)
 - NEW: Add new packager resolver (IVY-829) (thanks to Archie Cobbs)
 
+- IMPROVEMENT: Detect missing artifacts on publish asap (IVY-862)
 - IMPROVEMENT: Allow to set the branch at deliver/publish time (IVY-859)
 - IMPROVEMENT: Add defaultconf in publications tag of ivy file (IVY-801)
 - IMPROVEMENT: Support atomic publish with sub directory structure (IVY-856)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishEngine.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishEngine.java?rev=675585&r1=675584&r2=675585&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishEngine.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishEngine.java Thu Jul 10
07:19:56 2008
@@ -28,8 +28,11 @@
 import java.util.Date;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
+import java.util.Map;
 import java.util.Set;
+import java.util.Map.Entry;
 
 import org.apache.ivy.core.IvyContext;
 import org.apache.ivy.core.IvyPatternHelper;
@@ -192,48 +195,61 @@
                         extraArtifacts[i].getQualifiedExtraAttributes()));
             }
         }
-        boolean successfullyPublished = false;
-        try {
-            resolver.beginPublishTransaction(md.getModuleRevisionId(), options.isOverwrite());
-            // for each declared published artifact in this descriptor, do:
-            for (Iterator iter = artifactsSet.iterator(); iter.hasNext();) {
-                Artifact artifact = (Artifact) iter.next();
-                // copy the artifact using src patterns and resolver
-                boolean published = false;
-                for (Iterator iterator = srcArtifactPattern.iterator(); iterator.hasNext()
-                        && !published;) {
+        // now collects artifacts files
+        Map/*<Artifact,File>*/ artifactsFiles = new LinkedHashMap();
+        for (Iterator iter = artifactsSet.iterator(); iter.hasNext();) {
+            Artifact artifact = (Artifact) iter.next();
+            for (Iterator iterator = srcArtifactPattern.iterator(); iterator.hasNext();)
{
+                String pattern = (String) iterator.next();
+                File artifactFile = new File(
+                    IvyPatternHelper.substitute(settings.substitute(pattern), artifact));
+                if (artifactFile.exists()) {
+                    artifactsFiles.put(artifact, artifactFile);
+                    break;
+                }
+            }
+            if (!artifactsFiles.containsKey(artifact)) {
+                Message.info("missing artifact " + artifact + ":");
+                for (Iterator iterator = srcArtifactPattern.iterator(); iterator.hasNext();)
{
                     String pattern = (String) iterator.next();
-                    published = publish(
-                        artifact, settings.substitute(pattern), resolver, options.isOverwrite());
+                    Message.info("\t"
+                            + new File(IvyPatternHelper.substitute(pattern, artifact))
+                            + " file does not exist");
                 }
-                if (!published) {
-                    Message.info("missing artifact " + artifact + ":");
-                    for (Iterator iterator = srcArtifactPattern.iterator(); iterator.hasNext();)
{
-                        String pattern = (String) iterator.next();
-                        Message.info("\t"
-                                + new File(IvyPatternHelper.substitute(pattern, artifact))
-                                + " file does not exist");
-                    }
-                    if (options.isHaltOnMissing()) {
-                        throw new IOException("missing artifact " + artifact);
-                    }
-                    missing.add(artifact);
+                if (options.isHaltOnMissing()) {
+                    throw new IOException("missing artifact " + artifact);
                 }
+                missing.add(artifact);
             }
-            if (options.getSrcIvyPattern() != null) {
-                Artifact artifact = MDArtifact.newIvyArtifact(md);
-                if (!publish(
-                        artifact, options.getSrcIvyPattern(), resolver, options.isOverwrite()))
{
-                    Message.info("missing ivy file for "
-                            + md.getModuleRevisionId()
-                            + ": "
-                            + new File(IvyPatternHelper.substitute(options.getSrcIvyPattern(),
-                                artifact)) + " file does not exist");
-                    if (options.isHaltOnMissing()) {
-                        throw new IOException("missing ivy artifact " + artifact);
-                    }
-                    missing.add(artifact);
+        }
+        if (options.getSrcIvyPattern() != null) {
+            Artifact artifact = MDArtifact.newIvyArtifact(md);
+            File artifactFile = new File(
+                IvyPatternHelper.substitute(options.getSrcIvyPattern(), artifact));
+            if (!artifactFile.exists()) {
+                Message.info("missing ivy file for "
+                        + md.getModuleRevisionId()
+                        + ": "
+                        + artifactFile + " file does not exist");
+                if (options.isHaltOnMissing()) {
+                    throw new IOException("missing ivy artifact " + artifact);
                 }
+                missing.add(artifact);
+            } else {
+                artifactsFiles.put(artifact, artifactFile);
+            }
+        }
+        
+        // and now do actual publishing
+        boolean successfullyPublished = false;
+        try {
+            resolver.beginPublishTransaction(md.getModuleRevisionId(), options.isOverwrite());
+            // for each declared published artifact in this descriptor, do:
+            for (Iterator iter = artifactsFiles.entrySet().iterator(); iter.hasNext();) {
+                Map.Entry entry = (Entry) iter.next();
+                Artifact artifact = (Artifact) entry.getKey();
+                File artifactFile = (File) entry.getValue();
+                publish(artifact, artifactFile, resolver, options.isOverwrite());
             }
             resolver.commitPublishTransaction();
             successfullyPublished = true;
@@ -245,10 +261,8 @@
         return missing;
     }
 
-    private boolean publish(Artifact artifact, String srcArtifactPattern,
+    private void publish(Artifact artifact, File src,
             DependencyResolver resolver, boolean overwrite) throws IOException {
-        File src = new File(IvyPatternHelper.substitute(srcArtifactPattern, artifact));
-        
         IvyContext.getContext().checkInterrupted();
         //notify triggers that an artifact is about to be published
         eventManager.fireIvyEvent(
@@ -259,7 +273,6 @@
                 resolver.publish(artifact, src, overwrite);
                 successful = true;
             }
-            return successful;
         } finally {
             //notify triggers that the publish is finished, successfully or not.
             eventManager.fireIvyEvent(

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyPublishTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyPublishTest.java?rev=675585&r1=675584&r2=675585&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyPublishTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyPublishTest.java Thu Jul 10 07:19:56
2008
@@ -164,6 +164,34 @@
         }
     }
 
+    public void testHaltOnMissing3() throws Exception {
+        project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-publish-multi.xml");
+        IvyResolve res = new IvyResolve();
+        res.setProject(project);
+        res.execute();
+
+        // in this test case one artifact is available, and the other one is missing
+        // this should be detected early and no file should be published at all 
+        File art = new File("build/test/publish/multi1-1.2.jar");
+        FileUtil.copy(new File("test/repositories/1/org1/mod1.1/jars/mod1.1-1.0.jar"), art,
null);
+        publish.setPubrevision("1.2");
+        publish.setResolver("1");
+        publish.setHaltonmissing(true);
+        try {
+            publish.execute();
+            fail("publish with haltonmissing and a missing artifact should raise an exception");
+        } catch (BuildException ex) {
+            assertTrue(ex.getMessage().indexOf("missing") != -1);
+            assertTrue(ex.getMessage().indexOf("multi2.jar") != -1);
+
+            // should have do the ivy delivering
+            assertTrue(new File("build/test/publish/ivy-1.2.xml").exists());
+
+            // should not have published the files with "transactional" resolver
+            assertFalse(new File("test/repositories/1/apache/multi").exists());
+        }
+    }
+
     public void testPublishNotAllConfigs() throws Exception {
         project.setProperty("ivy.dep.file", "test/java/org/apache/ivy/ant/ivy-multiconf.xml");
         IvyResolve res = new IvyResolve();

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/publish/PublishEventsTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/publish/PublishEventsTest.java?rev=675585&r1=675584&r2=675585&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/publish/PublishEventsTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/publish/PublishEventsTest.java Thu Jul
10 07:19:56 2008
@@ -192,7 +192,7 @@
      * Test an attempted publish with an invalid data file path.
      */
     public void testPublishMissingFile() throws IOException {
-        //delete the datafile.  the publish should fail, but all events should still be fired,
+        //delete the datafile.  the publish should fail
         //and the ivy artifact should still publish successfully.
         assertTrue("datafile has been destroyed", dataFile.delete());
         PublishTestCase dataPublish = (PublishTestCase)expectedPublications.get(dataArtifact.getId());
@@ -202,10 +202,10 @@
         assertSameArtifact("missing artifact was returned", dataArtifact, (Artifact)missing.iterator().next());
         
         //if all tests passed, all of our counter variables should have been updated.
-        assertEquals("pre-publish trigger fired and passed all tests", 2, preTriggers);
-        assertEquals("post-publish trigger fired and passed all tests", 2, postTriggers);
+        assertEquals("pre-publish trigger fired and passed all tests", 1, preTriggers);
+        assertEquals("post-publish trigger fired and passed all tests", 1, postTriggers);
         assertEquals("only the ivy file published successfully", 1, publications);
-        assertEquals("publish of all expected artifacts has been attempted", 0, expectedPublications.size());
+        assertEquals("publish of all expected artifacts has been attempted", 1, expectedPublications.size());
     }
 
     /**



Mime
View raw message