You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by xa...@apache.org on 2008/04/03 13:26:57 UTC

svn commit: r644267 - in /ant/ivy/core/trunk: CHANGES.txt src/java/org/apache/ivy/ant/IvyBuildList.java src/java/org/apache/ivy/plugins/resolver/BasicResolver.java test/java/org/apache/ivy/core/resolve/ResolveTest.java

Author: xavier
Date: Thu Apr  3 04:26:55 2008
New Revision: 644267

URL: http://svn.apache.org/viewvc?rev=644267&view=rev
Log:
IMPROVEMENT: Change allownomd and skipbuildwithoutivy into a more semantically correct name (IVY-297)

Modified:
    ant/ivy/core/trunk/CHANGES.txt
    ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyBuildList.java
    ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
    ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java

Modified: ant/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/CHANGES.txt?rev=644267&r1=644266&r2=644267&view=diff
==============================================================================
--- ant/ivy/core/trunk/CHANGES.txt (original)
+++ ant/ivy/core/trunk/CHANGES.txt Thu Apr  3 04:26:55 2008
@@ -73,6 +73,7 @@
 - IMPROVEMENT: add branch attribute in ivy:install task (IVY-727)
 - IMPROVEMENT: Parse description information in ivy files (IVY-766)
 - IMPROVEMENT: Parse description and home page from poms (IVY-767)
+- IMPROVEMENT: Change allownomd and skipbuildwithoutivy into a more semantically correct name (IVY-297)
 - IMPROVEMENT: Smarter determination if an expression is exact or not for RegexpPatternMatcher and GlobPatternMatcher
 
 - FIX: SFTPRepository.list(String) hides exceptions (IVY-751)

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyBuildList.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyBuildList.java?rev=644267&r1=644266&r2=644267&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyBuildList.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyBuildList.java Thu Apr  3 04:26:55 2008
@@ -49,13 +49,26 @@
  * declared in ivy files.
  */
 public class IvyBuildList extends IvyTask {
+    public static final class OnMissingDescriptor {
+        public static final String HEAD = "head";
+        public static final String TAIL = "tail";
+        public static final String SKIP = "skip";
+        public static final String FAIL = "fail";
+        public static final String WARN = "warn";
+        
+        private OnMissingDescriptor() {
+        }
+    }
+
+    public static final String DESCRIPTOR_REQUIRED = "required";
+    
     private List buildFileSets = new ArrayList(); // List (FileSet)
 
     private String reference;
 
     private boolean haltOnError = true;
 
-    private boolean skipBuildWithoutIvy = false;
+    private String onMissingDescriptor = OnMissingDescriptor.HEAD;
 
     private boolean reverse = false;
 
@@ -154,6 +167,7 @@
 
         Map buildFiles = new HashMap(); // Map (ModuleDescriptor -> File buildFile)
         List independent = new ArrayList();
+        List noDescriptor = new ArrayList();
         Collection mds = new ArrayList();
 
         Set rootModuleNames = new LinkedHashSet();
@@ -187,16 +201,7 @@
                 File buildFile = new File(ds.getBasedir(), builds[i]);
                 File ivyFile = getIvyFileFor(buildFile);
                 if (!ivyFile.exists()) {
-                    if (skipBuildWithoutIvy) {
-                        Message.debug("skipping " + buildFile + ": ivy file " + ivyFile
-                                + " doesn't exist");
-                    } else {
-                        Message.verbose("no ivy file for " + buildFile + ": ivyfile=" + ivyFile
-                                + ": adding it at the beginning of the path");
-                        Message.verbose("\t(set skipbuildwithoutivy to true if you don't want this"
-                                + " file to be added to the path)");
-                        independent.add(buildFile);
-                    }
+                    onMissingDescriptor(buildFile, ivyFile, noDescriptor);
                 } else {
                     try {
                         ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance()
@@ -239,6 +244,12 @@
             new WarningNonMatchingVersionReporter();
         List sortedModules = ivy.sortModuleDescriptors(mds, nonMatchingVersionReporter);
 
+        if (onMissingDescriptor != OnMissingDescriptor.TAIL) {
+            for (ListIterator iter = noDescriptor.listIterator(); iter.hasNext();) {
+                File buildFile = (File) iter.next();
+                addBuildFile(path, buildFile);
+            }            
+        }
         for (ListIterator iter = independent.listIterator(); iter.hasNext();) {
             File buildFile = (File) iter.next();
             addBuildFile(path, buildFile);
@@ -275,10 +286,40 @@
             File buildFile = (File) buildFiles.get(md);
             addBuildFile(path, buildFile);
         }
+        if (onMissingDescriptor == OnMissingDescriptor.TAIL) {
+            for (ListIterator iter = noDescriptor.listIterator(); iter.hasNext();) {
+                File buildFile = (File) iter.next();
+                addBuildFile(path, buildFile);
+            }            
+        }
 
         getProject().addReference(getReference(), path);
         getProject().setProperty("ivy.sorted.modules", order.toString());
     }
+
+    private void onMissingDescriptor(File buildFile, File ivyFile, List noDescriptor) {
+        if (onMissingDescriptor == OnMissingDescriptor.SKIP) {
+            Message.debug("skipping " + buildFile + ": descriptor " + ivyFile
+                    + " doesn't exist");
+        } else if (onMissingDescriptor == OnMissingDescriptor.FAIL) {
+            throw new BuildException(
+                "a module has no module descriptor and onMissingDescriptor=fail. "
+                + "Build file: " + buildFile + ". Expected descriptor: " + ivyFile);
+        } else {
+            if (onMissingDescriptor == OnMissingDescriptor.WARN) {
+                Message.warn(
+                    "a module has no module descriptor. "
+                    + "Build file: " + buildFile + ". Expected descriptor: " + ivyFile);
+            }
+            Message.verbose("no descriptor for " + buildFile + ": descriptor=" + ivyFile
+                    + ": adding it at the " 
+                    + onMissingDescriptor == OnMissingDescriptor.TAIL 
+                    ? "tail" : "head" + " of the path");
+            Message.verbose(
+                "\t(change onMissingDescriptor if you want to take another action");
+            noDescriptor.add(buildFile);
+        }
+    }
     
     private List convertModuleNamesToModuleDescriptors(
             Collection mds, Set moduleNames, String kind) {
@@ -483,12 +524,29 @@
         this.ivyFilePath = ivyFilePath;
     }
 
+    public String getOnMissingDescriptor() {
+        return onMissingDescriptor;
+    }
+    
+    public void setOnMissingDescriptor(String onMissingDescriptor) {
+        this.onMissingDescriptor = onMissingDescriptor;
+    }
+    
+    /**
+     * @deprecated use {@link #getOnMissingDescriptor()} instead. 
+     */
     public boolean isSkipbuildwithoutivy() {
-        return skipBuildWithoutIvy;
+        return onMissingDescriptor == OnMissingDescriptor.SKIP;
     }
 
+    /**
+     * @deprecated use {@link #setOnMissingDescriptor(String)} instead. 
+     */
     public void setSkipbuildwithoutivy(boolean skipBuildFilesWithoutIvy) {
-        this.skipBuildWithoutIvy = skipBuildFilesWithoutIvy;
+        Message.deprecated("skipbuildwithoutivy is deprecated, use onMissingDescriptor instead.");
+        this.onMissingDescriptor = skipBuildFilesWithoutIvy
+            ? OnMissingDescriptor.SKIP
+                    : OnMissingDescriptor.FAIL;
     }
 
     public boolean isReverse() {

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java?rev=644267&r1=644266&r2=644267&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java Thu Apr  3 04:26:55 2008
@@ -24,6 +24,7 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
@@ -74,6 +75,10 @@
  *
  */
 public abstract class BasicResolver extends AbstractResolver {
+    public static final String DESCRIPTOR_OPTIONAL = "optional";
+
+    public static final String DESCRIPTOR_REQUIRED = "required";
+    
     /**
      * Exception thrown internally in getDependency to indicate a dependency is unresolved.
      * <p>
@@ -831,7 +836,29 @@
     }
 
     public void setAllownomd(boolean b) {
+        Message.deprecated(
+            "allownomd is deprecated, please use descriptor=\"" 
+            + (b ? DESCRIPTOR_OPTIONAL : DESCRIPTOR_REQUIRED) + "\" instead");
         allownomd = b;
+    }
+    
+    /**
+     * Sets the module descriptor presence rule.
+     * Should be one of {@link #DESCRIPTOR_REQUIRED} or {@link #DESCRIPTOR_OPTIONAL}.
+     *  
+     * @param descriptorRule the descriptor rule to use with this resolver.
+     */
+    public void setDescriptor(String descriptorRule) {
+        if (DESCRIPTOR_REQUIRED.equals(descriptorRule)) {
+          allownomd = false;  
+        } else if (DESCRIPTOR_OPTIONAL.equals(descriptorRule)) {
+          allownomd = true;  
+        } else {
+            throw new IllegalArgumentException(
+                "unknown descriptor rule '" + descriptorRule 
+                + "'. Allowed rules are: " 
+                + Arrays.asList(new String[] {DESCRIPTOR_REQUIRED, DESCRIPTOR_OPTIONAL}));
+        }
     }
 
     public String[] getChecksumAlgorithms() {

Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java?rev=644267&r1=644266&r2=644267&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/core/resolve/ResolveTest.java Thu Apr  3 04:26:55 2008
@@ -311,11 +311,12 @@
                 .exists());
     }
 
-    public void testResolveRequiresIvyFile() throws Exception {
+    public void testResolveRequiresDescriptor() throws Exception {
         // mod1.1 depends on mod1.2, mod1.2 has no ivy file
         Ivy ivy = new Ivy();
         ivy.configure(new File("test/repositories/ivysettings.xml"));
-        ((FileSystemResolver) ivy.getSettings().getResolver("1")).setAllownomd(false);
+        ((FileSystemResolver) ivy.getSettings().getResolver("1"))
+            .setDescriptor(FileSystemResolver.DESCRIPTOR_REQUIRED);
         ResolveReport report = ivy.resolve(new File(
                 "test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
             getResolveOptions(new String[] {"*"}));