Author: xavier
Date: Mon Feb 19 08:46:23 2007
New Revision: 509250

URL: http://svn.apache.org/viewvc?view=rev&rev=509250
Log:
REFACTOR: review publish API, introduce PublishOptions

Added:
    
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishOptions.java
Modified:
    incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPublish.java
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyTask.java
    
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java
    
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishEngine.java

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java?view=diff&rev=509250&r1=509249&r2=509250
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy.java Mon Feb 19 
08:46:23 2007
@@ -24,7 +24,6 @@
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Collection;
-import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -36,11 +35,11 @@
 import org.apache.ivy.core.deliver.DeliverOptions;
 import org.apache.ivy.core.event.EventManager;
 import org.apache.ivy.core.install.InstallEngine;
-import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.publish.PublishEngine;
+import org.apache.ivy.core.publish.PublishOptions;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.core.resolve.ResolveEngine;
 import org.apache.ivy.core.resolve.ResolveOptions;
@@ -56,7 +55,6 @@
 import org.apache.ivy.plugins.matcher.PatternMatcher;
 import org.apache.ivy.plugins.repository.TransferEvent;
 import org.apache.ivy.plugins.repository.TransferListener;
-import org.apache.ivy.plugins.resolver.DependencyResolver;
 import org.apache.ivy.plugins.trigger.Trigger;
 import org.apache.ivy.util.HostUtil;
 import org.apache.ivy.util.Message;
@@ -287,26 +285,9 @@
     /////////////////////////////////////////////////////////////////////////
     //                         PUBLISH
     /////////////////////////////////////////////////////////////////////////
-    
-
-    public Collection publish(ModuleDescriptor md, DependencyResolver 
resolver, Collection srcArtifactPattern, String srcIvyPattern, Artifact[] 
extraArtifacts, boolean overwrite, String conf) throws IOException {
-               return _publishEngine.publish(md, resolver, srcArtifactPattern, 
srcIvyPattern, extraArtifacts, overwrite, conf);
-       }
-
-       public Collection publish(ModuleRevisionId mrid, String pubrevision, 
File cache, Collection srcArtifactPattern, String resolverName, String 
srcIvyPattern, String status, Date pubdate, Artifact[] extraArtifacts, boolean 
validate, boolean overwrite, boolean update, String conf) throws IOException {
-               return _publishEngine.publish(mrid, pubrevision, cache, 
srcArtifactPattern, resolverName, srcIvyPattern, status, pubdate, 
extraArtifacts, validate, overwrite, update, conf);
-       }
-
-       public Collection publish(ModuleRevisionId mrid, String pubrevision, 
File cache, String srcArtifactPattern, String resolverName, String 
srcIvyPattern, boolean validate, boolean overwrite) throws IOException {
-               return _publishEngine.publish(mrid, pubrevision, cache, 
srcArtifactPattern, resolverName, srcIvyPattern, validate, overwrite);
-       }
-
-       public Collection publish(ModuleRevisionId mrid, String pubrevision, 
File cache, String srcArtifactPattern, String resolverName, String 
srcIvyPattern, boolean validate) throws IOException {
-               return _publishEngine.publish(mrid, pubrevision, cache, 
srcArtifactPattern, resolverName, srcIvyPattern, validate);
-       }
 
-       public Collection publish(ModuleRevisionId mrid, String pubrevision, 
File cache, String srcArtifactPattern, String resolverName, String 
srcIvyPattern, String status, Date pubdate, Artifact[] extraArtifacts, boolean 
validate, boolean overwrite, boolean update, String conf) throws IOException {
-               return _publishEngine.publish(mrid, pubrevision, cache, 
srcArtifactPattern, resolverName, srcIvyPattern, status, pubdate, 
extraArtifacts, validate, overwrite, update, conf);
+       public Collection publish(ModuleRevisionId mrid, Collection 
srcArtifactPattern, String resolverName, PublishOptions options) throws 
IOException {
+               return _publishEngine.publish(mrid, srcArtifactPattern, 
resolverName, options);
        }
 
     /////////////////////////////////////////////////////////////////////////

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java?view=diff&rev=509250&r1=509249&r2=509250
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/Ivy14.java Mon Feb 19 
08:46:23 2007
@@ -23,6 +23,7 @@
 import java.net.URL;
 import java.text.ParseException;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
@@ -34,6 +35,7 @@
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.publish.PublishOptions;
 import org.apache.ivy.core.report.ArtifactDownloadReport;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.core.resolve.IvyNode;
@@ -204,23 +206,65 @@
        }
 
        public Collection publish(ModuleDescriptor md, DependencyResolver 
resolver, Collection srcArtifactPattern, String srcIvyPattern, Artifact[] 
extraArtifacts, boolean overwrite, String conf) throws IOException {
-               return _ivy.publish(md, resolver, srcArtifactPattern, 
srcIvyPattern, extraArtifacts, overwrite, conf);
+               return _ivy.getPublishEngine().publish(md, srcArtifactPattern, 
resolver, 
+                               new PublishOptions()
+                                       .setSrcIvyPattern(srcIvyPattern)
+                                       .setExtraArtifacts(extraArtifacts)
+                                       .setOverwrite(overwrite)
+                                       .setConfs(splitConfs(conf)));
        }
 
        public Collection publish(ModuleRevisionId mrid, String pubrevision, 
File cache, Collection srcArtifactPattern, String resolverName, String 
srcIvyPattern, String status, Date pubdate, Artifact[] extraArtifacts, boolean 
validate, boolean overwrite, boolean update, String conf) throws IOException {
-               return _ivy.publish(mrid, pubrevision, cache, 
srcArtifactPattern, resolverName, srcIvyPattern, status, pubdate, 
extraArtifacts, validate, overwrite, update, conf);
+               return _ivy.publish(mrid, srcArtifactPattern, resolverName, 
+                               new PublishOptions()
+                                       .setCache(_ivy.getCacheManager(cache == 
null?_ivy.getSettings().getDefaultCache():cache))
+                                       .setStatus(status)
+                                       .setPubdate(pubdate)
+                                       .setPubrevision(pubrevision)
+                                       .setSrcIvyPattern(srcIvyPattern)
+                                       .setExtraArtifacts(extraArtifacts)
+                                       .setUpdate(update)
+                                       .setValidate(validate)
+                                       .setOverwrite(overwrite)
+                                       .setConfs(splitConfs(conf))
+                               );
        }
 
        public Collection publish(ModuleRevisionId mrid, String pubrevision, 
File cache, String srcArtifactPattern, String resolverName, String 
srcIvyPattern, boolean validate, boolean overwrite) throws IOException {
-               return _ivy.publish(mrid, pubrevision, cache, 
srcArtifactPattern, resolverName, srcIvyPattern, validate, overwrite);
+               return _ivy.publish(mrid, 
Collections.singleton(srcArtifactPattern), resolverName, 
+                               new PublishOptions()
+                                       .setCache(_ivy.getCacheManager(cache == 
null?_ivy.getSettings().getDefaultCache():cache))
+                                       .setPubrevision(pubrevision)
+                                       .setSrcIvyPattern(srcIvyPattern)
+                                       .setValidate(validate)
+                                       .setOverwrite(overwrite)
+                               );
        }
 
        public Collection publish(ModuleRevisionId mrid, String pubrevision, 
File cache, String srcArtifactPattern, String resolverName, String 
srcIvyPattern, boolean validate) throws IOException {
-               return _ivy.publish(mrid, pubrevision, cache, 
srcArtifactPattern, resolverName, srcIvyPattern, validate);
+               return _ivy.publish(mrid, 
Collections.singleton(srcArtifactPattern), resolverName, 
+                               new PublishOptions()
+                                       .setCache(_ivy.getCacheManager(cache == 
null?_ivy.getSettings().getDefaultCache():cache))
+                                       .setPubrevision(pubrevision)
+                                       .setSrcIvyPattern(srcIvyPattern)
+                                       .setValidate(validate)
+                               );
        }
 
        public Collection publish(ModuleRevisionId mrid, String pubrevision, 
File cache, String srcArtifactPattern, String resolverName, String 
srcIvyPattern, String status, Date pubdate, Artifact[] extraArtifacts, boolean 
validate, boolean overwrite, boolean update, String conf) throws IOException {
-               return _ivy.publish(mrid, pubrevision, cache, 
srcArtifactPattern, resolverName, srcIvyPattern, status, pubdate, 
extraArtifacts, validate, overwrite, update, conf);
+               return _ivy.publish(mrid, 
Collections.singleton(srcArtifactPattern), resolverName, 
+                               new PublishOptions()
+                                       .setCache(_ivy.getCacheManager(cache == 
null?_ivy.getSettings().getDefaultCache():cache))
+                                       .setStatus(status)
+                                       .setPubdate(pubdate)
+                                       .setPubrevision(pubrevision)
+                                       .setSrcIvyPattern(srcIvyPattern)
+                                       .setExtraArtifacts(extraArtifacts)
+                                       .setUpdate(update)
+                                       .setValidate(validate)
+                                       .setOverwrite(overwrite)
+                                       .setConfs(splitConfs(conf))
+                               );
        }
 
        public ResolveReport resolve(File ivySource) throws ParseException, 
IOException {
@@ -387,5 +431,16 @@
                return _ivy.substitute(str);
        }
     
+
+       private String[] splitConfs(String conf) {
+               if (conf == null || "".equals(conf)) {
+                       return null;
+               }
+        String[] confs = conf.split(",");
+        for (int i = 0; i < confs.length; i++) {
+            confs[i] = confs[i].trim();
+        }
+        return confs;
+       }
        
 }

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java?view=diff&rev=509250&r1=509249&r2=509250
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/Main.java Mon Feb 19 
08:46:23 2007
@@ -27,6 +27,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -46,9 +47,11 @@
 import org.apache.ivy.core.module.descriptor.DefaultModuleDescriptor;
 import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.publish.PublishOptions;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.core.resolve.ResolveOptions;
 import org.apache.ivy.core.retrieve.RetrieveOptions;
+import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
 import org.apache.ivy.plugins.report.XmlReportParser;
 import org.apache.ivy.util.DefaultMessageImpl;
@@ -210,9 +213,10 @@
             boolean validate = line.hasOption("novalidate")?false:true;
             
             Ivy ivy = Ivy.newInstance();
-            ivy.getSettings().addAllVariables(System.getProperties());
+            IvySettings settings = ivy.getSettings();
+                       settings.addAllVariables(System.getProperties());
             if (line.hasOption("m2compatible")) {
-                
ivy.getSettings().setVariable("ivy.default.configuration.m2compatible", "true");
+                settings.setVariable("ivy.default.configuration.m2compatible", 
"true");
             }
 
             configureURLHandler(
@@ -234,13 +238,13 @@
                 ivy.configure(conffile);
             }
             
-            File cache = new 
File(ivy.getSettings().substitute(line.getOptionValue("cache", 
ivy.getSettings().getDefaultCache().getAbsolutePath())));
+            File cache = new 
File(settings.substitute(line.getOptionValue("cache", 
settings.getDefaultCache().getAbsolutePath())));
             if (!cache.exists()) {
                 cache.mkdirs();
             } else if (!cache.isDirectory()) {
                 error(options, cache+" is not a directory");
             }
-            CacheManager cacheManager = 
CacheManager.getInstance(ivy.getSettings(), cache);
+            CacheManager cacheManager = CacheManager.getInstance(settings, 
cache);
             
             String[] confs;
             if (line.hasOption("confs")) {
@@ -266,7 +270,7 @@
                 XmlModuleDescriptorWriter.write(md, ivyfile);
                 confs = new String[] {"default"};
             } else {
-                ivyfile = new 
File(ivy.getSettings().substitute(line.getOptionValue("ivy", "ivy.xml")));
+                ivyfile = new 
File(settings.substitute(line.getOptionValue("ivy", "ivy.xml")));
                 if (!ivyfile.exists()) {
                     error(options, "ivy file not found: "+ivyfile);
                 } else if (ivyfile.isDirectory()) {
@@ -292,7 +296,7 @@
                 confs = md.getConfigurationsNames();
             }
             if (line.hasOption("retrieve")) {
-                String retrievePattern = 
ivy.getSettings().substitute(line.getOptionValue("retrieve"));
+                String retrievePattern = 
settings.substitute(line.getOptionValue("retrieve"));
                 if (retrievePattern.indexOf("[") == -1) {
                     retrievePattern = retrievePattern + 
"/lib/[conf]/[artifact].[ext]";
                 }
@@ -312,23 +316,23 @@
             if (line.hasOption("revision")) {
                                ivy.deliver(
                     md.getResolvedModuleRevisionId(),
-                    
ivy.getSettings().substitute(line.getOptionValue("revision")),
-                    
ivy.getSettings().substitute(line.getOptionValue("deliverto", 
"ivy-[revision].xml")),
-                    DeliverOptions.newInstance(ivy.getSettings())
-                       
.setStatus(ivy.getSettings().substitute(line.getOptionValue("status", 
"release")))
+                    settings.substitute(line.getOptionValue("revision")),
+                    settings.substitute(line.getOptionValue("deliverto", 
"ivy-[revision].xml")),
+                    DeliverOptions.newInstance(settings)
+                       
.setStatus(settings.substitute(line.getOptionValue("status", "release")))
                        .setValidate(validate)
                        .setCache(cacheManager)
                     );
                 if (line.hasOption("publish")) {
                     ivy.publish(
                             md.getResolvedModuleRevisionId(), 
-                            
ivy.getSettings().substitute(line.getOptionValue("revision")), 
-                            cache, 
-                            
ivy.getSettings().substitute(line.getOptionValue("publishpattern", 
"distrib/[type]s/[artifact]-[revision].[ext]")), 
+                            
Collections.singleton(settings.substitute(line.getOptionValue("publishpattern", 
"distrib/[type]s/[artifact]-[revision].[ext]"))), 
                             line.getOptionValue("publish"), 
-                            
ivy.getSettings().substitute(line.getOptionValue("deliverto", 
"ivy-[revision].xml")), 
-                            validate);
-                    
+                            new PublishOptions()
+                               .setCache(cacheManager)
+                               
.setPubrevision(settings.substitute(line.getOptionValue("revision")))
+                               .setValidate(validate)
+                               
.setSrcIvyPattern(settings.substitute(line.getOptionValue("deliverto", 
"ivy-[revision].xml"))));
                 }
             }
             if (line.hasOption("main")) {

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPublish.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPublish.java?view=diff&rev=509250&r1=509249&r2=509250
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPublish.java 
(original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyPublish.java Mon 
Feb 19 08:46:23 2007
@@ -29,9 +29,11 @@
 
 import org.apache.ivy.Ivy;
 import org.apache.ivy.core.IvyPatternHelper;
+import org.apache.ivy.core.cache.CacheManager;
 import org.apache.ivy.core.module.descriptor.Artifact;
 import org.apache.ivy.core.module.id.ArtifactRevisionId;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
+import org.apache.ivy.core.publish.PublishOptions;
 import org.apache.ivy.core.settings.IvySettings;
 import org.apache.ivy.util.Message;
 import org.apache.tools.ant.BuildException;
@@ -244,17 +246,19 @@
             
             Collection missing = ivy.publish(
                        mrid, 
-                       _pubRevision, 
-                       _cache, 
                        _artifactspattern, 
-                       _publishResolverName, 
-                       _publishivy?_srcivypattern:null, 
-                       getStatus(), 
-                       pubdate, 
-                       (Artifact[]) _artifacts.toArray(new 
Artifact[_artifacts.size()]), doValidate(settings), 
-                       _overwrite, 
-                       _update,
-                       _conf);
+                       _publishResolverName,
+                       new PublishOptions()
+                               .setPubrevision(getPubrevision())
+                               .setCache(CacheManager.getInstance(settings, 
_cache))
+                               
.setSrcIvyPattern(_publishivy?_srcivypattern:null)
+                               .setStatus(getStatus())
+                               .setPubdate(pubdate)
+                               .setExtraArtifacts((Artifact[]) 
_artifacts.toArray(new Artifact[_artifacts.size()]))
+                               .setValidate(doValidate(settings))
+                               .setOverwrite(_overwrite)
+                               .setUpdate(_update)
+                               .setConfs(splitConfs(_conf)));
             if (_warnonmissing) {
                 for (Iterator iter = missing.iterator(); iter.hasNext();) {
                     Artifact artifact = (Artifact)iter.next();

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyTask.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyTask.java?view=diff&rev=509250&r1=509249&r2=509250
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyTask.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyTask.java Mon Feb 
19 08:46:23 2007
@@ -227,6 +227,9 @@
     }
 
     protected String[] splitConfs(String conf) {
+       if (conf == null) {
+               return null;
+       }
         String[] confs = conf.split(",");
         for (int i = 0; i < confs.length; i++) {
             confs[i] = confs[i].trim();

Modified: 
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java?view=diff&rev=509250&r1=509249&r2=509250
==============================================================================
--- 
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java
 (original)
+++ 
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/install/InstallEngine.java
 Mon Feb 19 08:46:23 2007
@@ -33,6 +33,7 @@
 import org.apache.ivy.core.module.id.ModuleId;
 import org.apache.ivy.core.module.id.ModuleRevisionId;
 import org.apache.ivy.core.publish.PublishEngine;
+import org.apache.ivy.core.publish.PublishOptions;
 import org.apache.ivy.core.report.ResolveReport;
 import org.apache.ivy.core.resolve.IvyNode;
 import org.apache.ivy.core.resolve.ResolveEngine;
@@ -130,13 +131,13 @@
                 ModuleDescriptor depmd = dependencies[i].getDescriptor();
                 if (depmd != null) {
                     Message.verbose("installing "+depmd.getModuleRevisionId());
-                    _publishEngine.publish(depmd, 
+                    _publishEngine.publish(
+                               depmd, 
+                            
Collections.singleton(cache.getAbsolutePath()+"/"+_settings.getCacheArtifactPattern()),
                             toResolver, 
-                            
Collections.singleton(cache.getAbsolutePath()+"/"+_settings.getCacheArtifactPattern()),
 
-                            
cache.getAbsolutePath()+"/"+_settings.getCacheIvyPattern(), 
-                            null,
-                            overwrite,
-                            null);
+                            new PublishOptions()
+                                       
.setSrcIvyPattern(cache.getAbsolutePath()+"/"+_settings.getCacheIvyPattern())
+                                       .setOverwrite(overwrite));
                 }
             }
 

Modified: 
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishEngine.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishEngine.java?view=diff&rev=509250&r1=509249&r2=509250
==============================================================================
--- 
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishEngine.java
 (original)
+++ 
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishEngine.java
 Mon Feb 19 08:46:23 2007
@@ -24,13 +24,11 @@
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
-import java.util.StringTokenizer;
 
 import org.apache.ivy.core.IvyContext;
 import org.apache.ivy.core.IvyPatternHelper;
@@ -53,33 +51,6 @@
     public PublishEngine(IvySettings settings) {
                _settings = settings;
        }
-       /**
-     * 
-     * @param pubrevision 
-     * @param resolverName the name of a resolver to use for publication
-     * @param srcArtifactPattern a pattern to find artifacts to publish with 
the given resolver
-     * @param srcIvyPattern a pattern to find ivy file to publish, null if ivy 
file should not be published
-     * @return a collection of missing artifacts (those that are not published)
-     * @throws ParseException
-     */
-    public Collection publish(ModuleRevisionId mrid, String pubrevision, File 
cache, String srcArtifactPattern, String resolverName, String srcIvyPattern, 
boolean validate) throws IOException {
-        return publish(mrid, pubrevision, cache, srcArtifactPattern, 
resolverName, srcIvyPattern, validate, false);
-    }
-    /**
-     * 
-     * @param pubrevision 
-     * @param resolverName the name of a resolver to use for publication
-     * @param srcArtifactPattern a pattern to find artifacts to publish with 
the given resolver
-     * @param srcIvyPattern a pattern to find ivy file to publish, null if ivy 
file should not be published
-     * @return a collection of missing artifacts (those that are not published)
-     * @throws ParseException
-     */
-    public Collection publish(ModuleRevisionId mrid, String pubrevision, File 
cache, String srcArtifactPattern, String resolverName, String srcIvyPattern, 
boolean validate, boolean overwrite) throws IOException {
-       return publish(mrid, pubrevision, cache, srcArtifactPattern, 
resolverName, srcIvyPattern, null, null, null, validate, overwrite, false, 
null);
-    }
-    public Collection publish(ModuleRevisionId mrid, String pubrevision, File 
cache, String srcArtifactPattern, String resolverName, String srcIvyPattern, 
String status, Date pubdate, Artifact[] extraArtifacts, boolean validate, 
boolean overwrite, boolean update, String conf) throws IOException {
-       return publish(mrid, pubrevision, cache, 
Collections.singleton(srcArtifactPattern), resolverName, srcIvyPattern, status, 
pubdate, extraArtifacts, validate, overwrite, update, conf);
-    }
     /**
      * Publishes a module to the repository.
      * 
@@ -94,62 +65,62 @@
      * The extra artifacts array can be null (= no extra artifacts), and if 
non null only the name, type, ext url 
      * and extra attributes of the artifacts are really used. Other methods 
can return null safely. 
      * 
-     * @param mrid
-     * @param pubrevision
-     * @param cache
-     * @param srcArtifactPattern
-     * @param resolverName
-     * @param srcIvyPattern
-     * @param status
-     * @param pubdate
-     * @param validate
-     * @param overwrite
-     * @param update
-     * @return
-     * @throws IOException
      */
-    public Collection publish(ModuleRevisionId mrid, String pubrevision, File 
cache, Collection srcArtifactPattern, String resolverName, String 
srcIvyPattern, String status, Date pubdate, Artifact[] extraArtifacts, boolean 
validate, boolean overwrite, boolean update, String conf) throws IOException {
+    public Collection publish(ModuleRevisionId mrid, Collection 
srcArtifactPattern, String resolverName, PublishOptions options) throws 
IOException {
         Message.info(":: publishing :: "+mrid.getModuleId());
-        Message.verbose("\tvalidate = "+validate);
+        Message.verbose("\tvalidate = "+options.isValidate());
         long start = System.currentTimeMillis();
-        srcIvyPattern = _settings.substitute(srcIvyPattern);
-        CacheManager cacheManager = getCacheManager(cache);
-        // 1) find the resolved module descriptor
-        ModuleRevisionId pubmrid = ModuleRevisionId.newInstance(mrid, 
pubrevision);
+        
+        
options.setSrcIvyPattern(_settings.substitute(options.getSrcIvyPattern()));
+        if (options.getPubrevision() == null) {
+               options.setPubrevision(mrid.getRevision());
+        }
+        ModuleRevisionId pubmrid = ModuleRevisionId.newInstance(mrid, 
options.getPubrevision());
         File ivyFile;
-        if (srcIvyPattern != null) {
-               ivyFile = new File(IvyPatternHelper.substitute(srcIvyPattern, 
DefaultArtifact.newIvyArtifact(pubmrid, new Date())));
+        if (options.getSrcIvyPattern() != null) {
+               ivyFile = new 
File(IvyPatternHelper.substitute(options.getSrcIvyPattern(), 
DefaultArtifact.newIvyArtifact(pubmrid, new Date())));
                if (!ivyFile.exists()) {
                        throw new IllegalArgumentException("ivy file to publish 
not found for "+mrid+": call deliver before ("+ivyFile+")");
                }
         } else {
+               CacheManager cacheManager = getCacheManager(options);
                ivyFile = cacheManager.getResolvedIvyFileInCache(mrid);
                if (!ivyFile.exists()) {
                        throw new IllegalStateException("ivy file not found in 
cache for "+mrid+": please resolve dependencies before publishing 
("+ivyFile+")");
                }
         }
         
+        // let's find the resolved module descriptor
         ModuleDescriptor md = null;
         URL ivyFileURL = null;
         try {
                ivyFileURL = ivyFile.toURL();
                md = 
XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, ivyFileURL, 
false);
-               if (srcIvyPattern != null) {
-               if 
(!pubrevision.equals(md.getModuleRevisionId().getRevision())) {
-                       if (update) {
+               if (options.getSrcIvyPattern() != null) {
+               if 
(!options.getPubrevision().equals(md.getModuleRevisionId().getRevision())) {
+                       if (options.isUpdate()) {
                                File tmp = File.createTempFile("ivy", ".xml");
                                tmp.deleteOnExit();
                                try {
-                                                       
XmlModuleDescriptorUpdater.update(_settings, ivyFileURL, tmp, new HashMap(), 
status==null?md.getStatus():status, pubrevision, pubdate==null?new 
Date():pubdate, null, true);
+                                                       
XmlModuleDescriptorUpdater.update(
+                                                                       
_settings, 
+                                                                       
ivyFileURL, 
+                                                                       tmp, 
+                                                                       new 
HashMap(), 
+                                                                       
options.getStatus()==null?md.getStatus():options.getStatus(), 
+                                                                       
options.getPubrevision(), 
+                                                                       
options.getPubdate()==null?new Date():options.getPubdate(), 
+                                                                       null, 
+                                                                       true);
                                                        ivyFile = tmp;
                                                        // we parse the new 
file to get updated module descriptor
                                                        md = 
XmlModuleDescriptorParser.getInstance().parseDescriptor(_settings, 
ivyFile.toURL(), false);
-                                                       srcIvyPattern = 
ivyFile.getAbsolutePath();
+                                                       
options.setSrcIvyPattern(ivyFile.getAbsolutePath());
                                                } catch (SAXException e) {
                                                throw new 
IllegalStateException("bad ivy file for "+mrid+": "+ivyFile+": "+e);
                                                }
                        } else {
-                               throw new IllegalArgumentException("cannot 
publish "+ivyFile+" as "+pubrevision+": bad revision found in ivy file. Use 
deliver before.");
+                               throw new IllegalArgumentException("cannot 
publish "+ivyFile+" as "+options.getPubrevision()+": bad revision found in ivy 
file (Revision: "+md.getModuleRevisionId().getRevision()+"). Use forcedeliver 
or update.");
                        }
                }
                } else {
@@ -167,25 +138,17 @@
         }
         
         // collect all declared artifacts of this module
-        Collection missing = publish(md, resolver, srcArtifactPattern, 
srcIvyPattern, extraArtifacts, overwrite, conf);
+        Collection missing = publish(md, srcArtifactPattern, resolver, 
options);
         Message.verbose("\tpublish done 
("+(System.currentTimeMillis()-start)+"ms)");
         return missing;
     }
 
-    public Collection publish(ModuleDescriptor md, DependencyResolver 
resolver, Collection srcArtifactPattern, String srcIvyPattern, Artifact[] 
extraArtifacts, boolean overwrite, String conf) throws IOException {
+    public Collection publish(ModuleDescriptor md, Collection 
srcArtifactPattern, DependencyResolver resolver, PublishOptions options) throws 
IOException {
         Collection missing = new ArrayList();
         Set artifactsSet = new HashSet();
-               String[] confs;
-               if (null == conf || "".equals(conf)) {
+               String[] confs = options.getConfs();
+               if (confs == null || (confs.length == 1 && 
"*".equals(confs[0]))) {
                        confs = md.getConfigurationsNames();
-               } else {
-                       StringTokenizer st = new StringTokenizer(conf, ",");
-                       confs = new String[st.countTokens()];
-                       int counter = 0;
-                       while (st.hasMoreTokens()) {
-                               confs[counter] = st.nextToken().trim();
-                               counter++;
-                       }
                }
 
                for (int i = 0; i < confs.length; i++) {
@@ -194,6 +157,7 @@
                 artifactsSet.add(artifacts[j]);
             }
         }
+               Artifact[] extraArtifacts = options.getExtraArtifacts();
         if (extraArtifacts != null) {
                for (int i = 0; i < extraArtifacts.length; i++) {
                                artifactsSet.add(new MDArtifact(md, 
extraArtifacts[i].getName(), extraArtifacts[i].getType(), 
extraArtifacts[i].getExt(), extraArtifacts[i].getUrl(), 
extraArtifacts[i].getExtraAttributes()));
@@ -206,7 +170,7 @@
             boolean published = false;
             for (Iterator iterator = srcArtifactPattern.iterator(); 
iterator.hasNext() && !published;) {
                                String pattern = (String) iterator.next();
-                               published = publish(artifact, 
_settings.substitute(pattern), resolver, overwrite);
+                               published = publish(artifact, 
_settings.substitute(pattern), resolver, options.isOverwrite());
                        }
             if (!published) {
                Message.info("missing artifact "+artifact+":");
@@ -217,10 +181,12 @@
                 missing.add(artifact);
             }
         }
-        if (srcIvyPattern != null) {
+        if (options.getSrcIvyPattern() != null) {
             Artifact artifact = MDArtifact.newIvyArtifact(md);
-            if (!publish(artifact, srcIvyPattern, resolver, overwrite)) {
-                Message.info("missing ivy file for 
"+md.getModuleRevisionId()+": "+new 
File(IvyPatternHelper.substitute(srcIvyPattern, artifact))+" file does not 
exist");
+            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");
                 missing.add(artifact);
             }
         }
@@ -238,11 +204,15 @@
         }
     }
 
-       private CacheManager getCacheManager(File cache) {
-               //TODO : reuse instance
-               CacheManager cacheManager = new CacheManager(_settings, cache);
+
+       private CacheManager getCacheManager(PublishOptions options) {
+               CacheManager cacheManager = options.getCache();
+        if (cacheManager == null) {  // ensure that a cache is configured
+               cacheManager = IvyContext.getContext().getCacheManager();
+               options.setCache(cacheManager);
+        } else {
+               IvyContext.getContext().setCache(cacheManager.getCache());
+        }
                return cacheManager;
        }
-
-
 }

Added: 
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishOptions.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishOptions.java?view=auto&rev=509250
==============================================================================
--- 
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishOptions.java
 (added)
+++ 
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/publish/PublishOptions.java
 Mon Feb 19 08:46:23 2007
@@ -0,0 +1,148 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.ivy.core.publish;
+
+import java.util.Date;
+
+import org.apache.ivy.core.cache.CacheManager;
+import org.apache.ivy.core.module.descriptor.Artifact;
+
+/**
+ * A set of options used during publish related tasks
+ * 
+ * The publish can update the ivy file to publish if update is set to true. In 
this case it will use
+ * the given pubrevision, pubdate and status. If pudate is null it will 
default to the current date.
+ * If status is null it will default to the current ivy file status (which 
itself defaults to integration if none is found).
+ * If update is false, then if the revision is not the same in the ivy file 
than the one expected (given as parameter),
+ * this method will fail with an  IllegalArgumentException.
+ * pubdate and status are not used if update is false.
+ * extra artifacts can be used to publish more artifacts than actually 
declared in the ivy file.
+ * This can be useful to publish additional metadata or reports.
+ * The extra artifacts array can be null (= no extra artifacts), and if non 
null only the name, type, ext url 
+ * and extra attributes of the artifacts are really used. Other methods (on 
the artifacts) can return null safely.
+ *  
+ * @see PublishEngine
+ * @author Xavier Hanin
+ */
+public class PublishOptions {
+       private CacheManager cache;
+       private String srcIvyPattern;
+       
+       private String pubrevision;
+       private String status;
+       private Date pubdate;
+       
+       private Artifact[] extraArtifacts;
+       private boolean validate;
+       private boolean overwrite;
+       private boolean update;
+       
+       private String[] confs;
+
+       public CacheManager getCache() {
+               return cache;
+       }
+
+       public PublishOptions setCache(CacheManager cache) {
+               this.cache = cache;
+               return this;
+       }
+
+       public String[] getConfs() {
+               return confs;
+       }
+
+       public PublishOptions setConfs(String[] confs) {
+               this.confs = confs;
+               return this;
+       }
+
+       public Artifact[] getExtraArtifacts() {
+               return extraArtifacts;
+       }
+
+       public PublishOptions setExtraArtifacts(Artifact[] extraArtifacts) {
+               this.extraArtifacts = extraArtifacts;
+               return this;
+       }
+
+       public boolean isOverwrite() {
+               return overwrite;
+       }
+
+       public PublishOptions setOverwrite(boolean overwrite) {
+               this.overwrite = overwrite;
+               return this;
+       }
+
+       public Date getPubdate() {
+               return pubdate;
+       }
+
+       public PublishOptions setPubdate(Date pubdate) {
+               this.pubdate = pubdate;
+               return this;
+       }
+
+       public String getPubrevision() {
+               return pubrevision;
+       }
+
+       public PublishOptions setPubrevision(String pubrevision) {
+               this.pubrevision = pubrevision;
+               return this;
+       }
+
+       public String getSrcIvyPattern() {
+               return srcIvyPattern;
+       }
+
+       public PublishOptions setSrcIvyPattern(String srcIvyPattern) {
+               this.srcIvyPattern = srcIvyPattern;
+               return this;
+       }
+
+       public String getStatus() {
+               return status;
+       }
+
+       public PublishOptions setStatus(String status) {
+               this.status = status;
+               return this;
+       }
+
+       public boolean isUpdate() {
+               return update;
+       }
+
+       public PublishOptions setUpdate(boolean update) {
+               this.update = update;
+               return this;
+       }
+
+       public boolean isValidate() {
+               return validate;
+       }
+
+       public PublishOptions setValidate(boolean validate) {
+               this.validate = validate;
+               return this;
+       }
+       
+       
+}


Reply via email to