亲棋牌手机版

Home » apache-ivyde-sources-2.0.0.final-200907011148-RELEASE » org.apache.ivyde.common.ivyfile » [javadoc | source]
    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    *
   17    */
   18   package org.apache.ivyde.common.ivyfile;
   19   
   20   import java.text.ParseException;
   21   import java.util.ArrayList;
   22   import java.util.Arrays;
   23   import java.util.Date;
   24   import java.util.List;
   25   import java.util.Map;
   26   
   27   import org.apache.ivy.Ivy;
   28   import org.apache.ivy.core.IvyPatternHelper;
   29   import org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor;
   30   import org.apache.ivy.core.module.id.ModuleRevisionId;
   31   import org.apache.ivy.core.resolve.ResolveData;
   32   import org.apache.ivy.core.resolve.ResolveOptions;
   33   import org.apache.ivy.core.resolve.ResolvedModuleRevision;
   34   import org.apache.ivy.plugins.resolver.DependencyResolver;
   35   import org.apache.ivyde.common.model.IValueProvider;
   36   import org.apache.ivyde.common.model.IvyBooleanTagAttribute;
   37   import org.apache.ivyde.common.model.IvyFile;
   38   import org.apache.ivyde.common.model.IvyModel;
   39   import org.apache.ivyde.common.model.IvyModelSettings;
   40   import org.apache.ivyde.common.model.IvyTag;
   41   import org.apache.ivyde.common.model.IvyTagAttribute;
   42   import org.apache.ivyde.common.model.ListValueProvider;
   43   
   44   public class IvyModuleDescriptorModel extends IvyModel {
   45       public IvyModuleDescriptorModel(IvyModelSettings settings) {
   46           super(settings);
   47   
   48           // ivy-module
   49           IvyTag ivyTag = new IvyTag("ivy-module", "root tag of ivy file");
   50           ivyTag.setDoc("Root tag of any ivy-file.");
   51           ivyTag.addAttribute(new IvyTagAttribute("version",
   52                   "The version of the ivy file specification \n"
   53                           + "should be '2.0' with current version of ivy", true));
   54           addTag(ivyTag);
   55   
   56           IValueProvider defaultOrganizationProvider = new IValueProvider() {
   57               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
   58                   return new String[] {getSettings().getDefaultOrganization()};
   59               }
   60           };
   61           IValueProvider defaultOrganizationURLProvider = new IValueProvider() {
   62               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
   63                   return new String[] {getSettings().getDefaultOrganizationURL()};
   64               }
   65           };
   66   
   67           // info
   68           IvyTagAttribute orgTagAttribute = new IvyTagAttribute("organisation",
   69                   "the name of the organisation that is the owner of this module.", true);
   70           orgTagAttribute.setValueProvider(defaultOrganizationProvider);
   71           IvyTagAttribute statusTagAttribute = new IvyTagAttribute("status",
   72                   "the status of this module.");
   73           statusTagAttribute.setValueProvider(new ListValueProvider(getDefault("status")));
   74           IvyTagAttribute pubTagAttribute = new IvyTagAttribute("publication",
   75                   "the date of publication of this module. \n"
   76                           + "It should be given in this format: yyyyMMddHHmmss");
   77           pubTagAttribute.setValueProvider(new IValueProvider() {
   78               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
   79                   return new String[] {Ivy.DATE_FORMAT.format(new Date())};
   80               }
   81           });
   82           IvyTagAttribute moduleTagAttribute = new IvyTagAttribute("module",
   83                   "the name of the module described by this ivy file.", true);
   84           IValueProvider projectNameValueProvider = new IValueProvider() {
   85               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
   86                   return new String[] {ivyFile.getProjectName()};
   87               }
   88           };
   89           moduleTagAttribute.setValueProvider(projectNameValueProvider);
   90           IvyTag info = new IvyTag("info", "gives general information about the described module",
   91                   new IvyTagAttribute[] {orgTagAttribute, moduleTagAttribute,
   92                           new IvyTagAttribute("branch", "the branch of this module."),
   93                           new IvyTagAttribute("revision", "the revision of this module."),
   94                           statusTagAttribute, pubTagAttribute});
   95           addTag(info);
   96           IvyTag child = new IvyTag("license",
   97                   "gives information about the licenses of the described module");
   98           child.addAttribute(new IvyTagAttribute("name", "the name of the license. \n"
   99                   + "Try to respect spelling when using a classical license.", true,
  100                   new ListValueProvider(getDefault("license"))));
  101           child
  102                   .addAttribute(new IvyTagAttribute("url", "an url pointing to the license text.",
  103                           false));
  104           addTag(child);
  105           info.addChildIvyTag(child);
  106           child = new IvyTag("ivyauthor", "describes who has contributed to write the ivy file");
  107           child.addAttribute(new IvyTagAttribute("name",
  108                   "the name of the author, as a person or a company.", true,
  109                   defaultOrganizationProvider));
  110           child.addAttribute(new IvyTagAttribute("url",
  111                   "an url pointing to where the author can be reached.", false,
  112                   defaultOrganizationURLProvider));
  113           addTag(child);
  114           info.addChildIvyTag(child);
  115           child = new IvyTag("repository",
  116                   "describes on which public repositories this module can be found");
  117           child.addAttribute(new IvyTagAttribute("name", "the name of the repository. \n"
  118                   + "Try to respect spelling for common repositories (ibiblio, ivyrep, ...)", true,
  119                   new IValueProvider() {
  120                       public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  121                           return new String[] {"ibiblio", "ivyrep"};
  122                       }
  123                   }));
  124           child.addAttribute(new IvyTagAttribute("url", "an url pointing to the repository.", true,
  125                   new IValueProvider() {
  126                       public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  127                           Map allAttsValues = ivyFile.getAllAttsValues();
  128                           if (allAttsValues != null) {
  129                               String name = (String) allAttsValues.get("name");
  130                               if ("ibiblio".equals(name)) {
  131                                   return new String[] {"http://www.ibiblio.org/maven/"};
  132                               } else if ("ivyrep".equals(name)) {
  133                                   return new String[] {"http://www.jayasoft.fr/org/ivyrep/"};
  134                               }
  135                           }
  136                           return null;
  137                       }
  138   
  139                   }));
  140           IvyTagAttribute reppatternTagAttribute = new IvyTagAttribute("pattern",
  141                   "an ivy pattern to find modules on this repository", false);
  142           reppatternTagAttribute.setValueProvider(new IValueProvider() {
  143               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  144                   Map allAttsValues = ivyFile.getAllAttsValues();
  145                   if (allAttsValues != null) {
  146                       String name = (String) allAttsValues.get("name");
  147                       if ("ibiblio".equals(name)) {
  148                           return new String[] {"[module]/[type]s/[artifact]-[revision].[ext]"};
  149                       } else if ("ivyrep".equals(name)) {
  150                           return new String[] {"[organisation]/[module]/[artifact]-[revision].[ext]"};
  151                       }
  152                   }
  153                   return null;
  154               }
  155           });
  156           child.addAttribute(reppatternTagAttribute);
  157           child.addAttribute(new IvyBooleanTagAttribute("ivys",
  158                   "true if ivy file can be found on this repository", false));
  159           child.addAttribute(new IvyBooleanTagAttribute("artifacts",
  160                   "true if module artifacts can be found on this repository", false));
  161           addTag(child);
  162           info.addChildIvyTag(child);
  163           child = new IvyTag("description", "gives general description about the module");
  164           child.addAttribute(new IvyTagAttribute("homepage", "the url of the homepage of the module",
  165                   false, defaultOrganizationURLProvider));
  166           addTag(child);
  167           info.addChildIvyTag(child);
  168           ivyTag.addChildIvyTag(info);
  169   
  170           // configurations
  171           IvyTag configurations = new IvyTag("configurations", "container for configuration elements");
  172           IvyTag conf = new IvyTag("conf", "declares a configuration of this module");
  173           conf.addAttribute(new IvyTagAttribute("name", "the name of the declared configuration",
  174                   true));
  175           conf.addAttribute(new IvyTagAttribute("description",
  176                   "a short description for the declared configuration", false));
  177           IvyTagAttribute visibilityTagAttribute = new IvyTagAttribute("visibility",
  178                   "the visibility of the declared configuration.\n"
  179                           + "'public' means that this configuration can be used by other modules, \n"
  180                           + "while 'private' means that this configuration is used only in the\n"
  181                           + "module itself, and is not exposed to other modules", false);
  182           visibilityTagAttribute.setValueProvider(new IValueProvider() {
  183               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  184                   return new String[] {"public", "private"};
  185               }
  186           });
  187           conf.addAttribute(visibilityTagAttribute);
  188           IvyTagAttribute confExtTagAttribute = new IvyTagAttribute("extends",
  189                   "a comma separated list of configurations of this module \n"
  190                           + "that the current configuration extends", false);
  191           IValueProvider masterConfsValueProvider = new IValueProvider() {
  192               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  193                   StringBuffer base = new StringBuffer();
  194                   String qualifier = ivyFile.getAttributeValueQualifier();
  195                   int comma = qualifier.lastIndexOf(",") + 1;
  196                   base.append(qualifier.substring(0, comma));
  197                   qualifier = qualifier.substring(comma);
  198                   while (qualifier.length() > 0 && qualifier.charAt(0) == ' ') {
  199                       base.append(' ');
  200                       qualifier = qualifier.substring(1);
  201                   }
  202                   String[] confs = ((IvyModuleDescriptorFile) ivyFile).getConfigurationNames();
  203                   for (int i = 0; i < confs.length; i++) {
  204                       confs[i] = base + confs[i];
  205                   }
  206                   return confs;
  207               }
  208           };
  209           IValueProvider masterConfValueProvider = new IValueProvider() {
  210               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  211                   return ((IvyModuleDescriptorFile) ivyFile).getConfigurationNames();
  212               }
  213           };
  214           confExtTagAttribute.setValueProvider(masterConfsValueProvider);
  215           conf.addAttribute(confExtTagAttribute);
  216           IvyTagAttribute deprecatedTagAttribute = new IvyTagAttribute("deprecated",
  217                   "indicates that this conf has been deprecated \n"
  218                           + "by giving the date of the deprecation. \n"
  219                           + "It should be given in this format: yyyyMMddHHmmss", false);
  220           deprecatedTagAttribute.setValueProvider(new IValueProvider() {
  221               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  222                   return new String[] {Ivy.DATE_FORMAT.format(new Date())};
  223               }
  224           });
  225           conf.addAttribute(deprecatedTagAttribute);
  226           configurations.addChildIvyTag(conf);
  227           List allConf = new ArrayList();
  228           allConf.add(conf);
  229           addTag(conf.getName(), allConf);
  230           ivyTag.addChildIvyTag(configurations);
  231           addTag(configurations);
  232   
  233           // configurations
  234           IvyTag publications = new IvyTag("publications",
  235                   "container for published artifact elements");
  236           IvyTag artifact = new IvyTag("artifact", "declares a published artifact for this module");
  237           artifact.addAttribute(new IvyTagAttribute("name",
  238                   "the name of the published artifact. This name must not include revision.", true,
  239                   projectNameValueProvider));
  240           artifact.addAttribute(new IvyTagAttribute("type", "the type of the published artifact. \n"
  241                   + "It's usually its extension, but not necessarily. \n"
  242                   + "For instance, ivy files are of type 'ivy' but have 'xml' extension", true,
  243                   new ListValueProvider(getDefault("type"))));
  244           artifact.addAttribute(new IvyTagAttribute("ext", "the extension of the published artifact",
  245                   false, new ListValueProvider(getDefault("ext"))));
  246           artifact.addAttribute(new IvyTagAttribute("conf",
  247                   "comma separated list of public configurations in which this artifact\n"
  248                           + "is published. '*' wildcard can be used to designate all public\n"
  249                           + "configurations of this module", false, masterConfsValueProvider));
  250           IvyTag conf2 = new IvyTag("conf",
  251                   "indicates a public configuration in which this artifact is published");
  252           conf2.addAttribute(new IvyTagAttribute("name",
  253                   "the name of a module public configuration in which this artifact\n"
  254                           + "is published. '*' wildcard can be used to designate all\n"
  255                           + "public configurations of this module", true, masterConfValueProvider));
  256           allConf.add(conf2);
  257           artifact.addChildIvyTag(conf2);
  258           publications.addChildIvyTag(artifact);
  259           addTag(publications);
  260           addTag(artifact);
  261           ivyTag.addChildIvyTag(publications);
  262   
  263           // dependencies
  264           IvyTag dependencies = new IvyTag("dependencies", "container for dependency elements");
  265           // dependency
  266           IvyTag dependency = new IvyTag("dependency", "declares a dependency for this module") {
  267               public String[] getPossibleValuesForAttribute(String att, IvyFile ivyfile) {
  268                   String[] r = super.getPossibleValuesForAttribute(att, ivyfile);
  269                   if (r == null) { // listing can be used even for extra attributes
  270                       List ret = listDependencyTokenValues(att, ivyfile);
  271                       return (String[]) ret.toArray(new String[ret.size()]);
  272                   } else {
  273                       return r;
  274                   }
  275               }
  276           };
  277           IvyTagAttribute orgAtt = new IvyTagAttribute("org",
  278                   "the name of the organisation of the dependency.", false);
  279           orgAtt.setValueProvider(new IValueProvider() {
  280               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  281                   List ret = listDependencyTokenValues(att.getName(), ivyFile);
  282                   ret.add(getSettings().getDefaultOrganization());
  283                   String org = ((IvyModuleDescriptorFile) ivyFile).getOrganisation();
  284                   if (org != null) {
  285                       ret.add(org);
  286                   }
  287                   return (String[]) ret.toArray(new String[ret.size()]);
  288               }
  289   
  290           });
  291           dependency.addAttribute(orgAtt);
  292           IvyTagAttribute module = new IvyTagAttribute("name", "the module name of the dependency",
  293                   true);
  294           module.setValueProvider(new IValueProvider() {
  295               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  296                   List ret = listDependencyTokenValues(att.getName(), ivyFile);
  297                   return (String[]) ret.toArray(new String[ret.size()]);
  298               }
  299           });
  300           dependency.addAttribute(module);
  301           IvyTagAttribute branch = new IvyTagAttribute("branch",
  302                   "the branch of the dependency. \nDo not set if not needed.", false);
  303           branch.setValueProvider(new IValueProvider() {
  304               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  305                   List ret = listDependencyTokenValues(att.getName(), ivyFile);
  306                   return (String[]) ret.toArray(new String[ret.size()]);
  307               }
  308           });
  309           dependency.addAttribute(branch);
  310           IvyTagAttribute rev = new IvyTagAttribute("rev", "the revision of the dependency. \n"
  311                   + "Use 'latest.integration' to get the latest version of the dependency. \n"
  312                   + "You can also end the revision asked with a '+' to get the latest"
  313                   + " matching revision.", true);
  314           rev.setValueProvider(new IValueProvider() {
  315               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  316                   List ret = listDependencyTokenValues(att.getName(), ivyFile);
  317                   ret.add("latest.integration");
  318                   return (String[]) ret.toArray(new String[ret.size()]);
  319               }
  320           });
  321           dependency.addAttribute(rev);
  322           dependency.addAttribute(new IvyBooleanTagAttribute("force",
  323                   "a boolean to give an indication to conflict manager \n"
  324                           + "that this dependency should be forced to this revision", false));
  325           dependency.addAttribute(new IvyBooleanTagAttribute("transitive",
  326                   "a boolean indicating if this dependency should be resolved transitively or not",
  327                   false));
  328           IvyTagAttribute confAtt = new IvyTagAttribute("conf",
  329                   "an inline mapping configuration spec", false);
  330           dependency.addAttribute(confAtt);
  331           confAtt.setValueProvider(new IValueProvider() {
  332               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  333                   String qualifier = ivyFile.getAttributeValueQualifier();
  334                   int index = qualifier.lastIndexOf(';') + 1;
  335                   StringBuffer base = new StringBuffer(qualifier.substring(0, index));
  336                   qualifier = qualifier.substring(index);
  337                   int arrowIndex = qualifier.indexOf("->");
  338                   if (arrowIndex > -1) {
  339                       // we are looking for a dep conf
  340                       String org = ((IvyModuleDescriptorFile) ivyFile).getDependencyOrganisation();
  341                       Map otherAttValues = ivyFile.getAllAttsValues();
  342                       if (org != null && otherAttValues != null && otherAttValues.get("name") != null
  343                               && otherAttValues.get("rev") != null) {
  344                           otherAttValues.remove("org");
  345                           String branch = (String) otherAttValues.remove("branch");
  346                           otherAttValues.remove("conf");
  347                           otherAttValues.remove("force");
  348                           otherAttValues.remove("transitive");
  349                           otherAttValues.remove("changing");
  350                           return getDependencyConfs(org, (String) otherAttValues.remove("name"),
  351                               branch, (String) otherAttValues.remove("rev"), otherAttValues,
  352                               qualifier, base, arrowIndex);
  353                       }
  354   
  355                   } else {
  356                       // we are looking for a master conf
  357                       return getMasterConfs(ivyFile, qualifier, base, arrowIndex);
  358                   }
  359   
  360                   return null;
  361               }
  362   
  363               private String[] getMasterConfs(IvyFile ivyFile, String qualifier, StringBuffer base,
  364                       int arrowIndex) {
  365                   // search for word after last comma
  366                   int comma = qualifier.lastIndexOf(",") + 1;
  367                   base.append(qualifier.substring(0, comma));
  368                   qualifier = qualifier.substring(comma);
  369                   while (qualifier.length() > 0 && qualifier.charAt(0) == ' ') {
  370                       base.append(' ');
  371                       qualifier = qualifier.substring(1);
  372                   }
  373                   String[] confs = ((IvyModuleDescriptorFile) ivyFile).getConfigurationNames();
  374                   for (int i = 0; i < confs.length; i++) {
  375                       confs[i] = base + confs[i];
  376                   }
  377                   List ret = new ArrayList(Arrays.asList(confs));
  378                   ret.add("*");
  379                   return (String[]) ret.toArray(new String[ret.size()]);
  380               }
  381   
  382               private String[] getDependencyConfs(String org, String name, String branch, String rev,
  383                       Map otherAtts, String qualifier, StringBuffer base, int arrowIndex) {
  384                   Ivy ivy = getIvy();
  385                   if (ivy == null) {
  386                       return null;
  387                   }
  388                   base.append(qualifier.substring(0, arrowIndex + 2));
  389                   qualifier = qualifier.substring(arrowIndex + 2);
  390                   // search for word after last comma
  391                   int comma = qualifier.lastIndexOf(",") + 1;
  392                   base.append(qualifier.substring(0, comma));
  393                   qualifier = qualifier.substring(comma);
  394                   while (qualifier.length() > 0 && qualifier.charAt(0) == ' ') {
  395                       base.append(' ');
  396                       qualifier = qualifier.substring(1);
  397                   }
  398                   ResolveData data = new ResolveData(ivy.getResolveEngine(), new ResolveOptions());
  399                   ModuleRevisionId mrid = ModuleRevisionId.newInstance(org, name, branch, rev,
  400                       otherAtts);
  401                   DefaultDependencyDescriptor ddd = new DefaultDependencyDescriptor(mrid, false);
  402                   try {
  403                       DependencyResolver resolver = ivy.getSettings().getResolver(mrid);
  404                       if (resolver == null) {
  405                           return null;
  406                       }
  407                       ResolvedModuleRevision dep = resolver.getDependency(ddd, data);
  408                       if (dep == null) {
  409                           return null;
  410                       }
  411                       String[] confs = dep.getDescriptor().getConfigurationsNames();
  412                       for (int i = 0; i < confs.length; i++) {
  413                           confs[i] = base + confs[i];
  414                       }
  415                       List ret = new ArrayList(Arrays.asList(confs));
  416                       ret.add("*");
  417                       return (String[]) ret.toArray(new String[ret.size()]);
  418                   } catch (ParseException e) {
  419                       getSettings().logError("The dependencies of " + mrid + " could not be parsed",
  420                           e);
  421                       return null;
  422                   }
  423               }
  424   
  425           });
  426           IvyTag conf3 = new IvyTag("conf", "defines configuration mapping has sub element");
  427           conf3
  428                   .addAttribute(new IvyTagAttribute(
  429                           "name",
  430                           "the name of the master configuration to map. \n"
  431                                   + "'*' wildcard can be used to designate all configurations of this module",
  432                           true, masterConfValueProvider));
  433           conf3.addAttribute(new IvyTagAttribute("mapped",
  434                   "a comma separated list of dependency configurations \n"
  435                           + "to which this master configuration should be mapped", false,
  436                   new IValueProvider() {
  437                       public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  438                           Ivy ivy = getIvy();
  439                           int[] indexes = ivyFile.getParentTagIndex();
  440                           if (indexes != null && ivy != null) {
  441                               Map otherAttValues = ivyFile.getAllAttsValues(indexes[0] + 1);
  442                               String org = ((IvyModuleDescriptorFile) ivyFile)
  443                                       .getDependencyOrganisation(otherAttValues);
  444                               if (org != null && otherAttValues != null
  445                                       && otherAttValues.get("name") != null
  446                                       && otherAttValues.get("rev") != null) {
  447                                   StringBuffer base = new StringBuffer();
  448                                   String qualifier = ivyFile.getAttributeValueQualifier();
  449                                   // search for word after last comma
  450                                   int comma = qualifier.lastIndexOf(",") + 1;
  451                                   base.append(qualifier.substring(0, comma));
  452                                   qualifier = qualifier.substring(comma);
  453                                   while (qualifier.length() > 0 && qualifier.charAt(0) == ' ') {
  454                                       base.append(' ');
  455                                       qualifier = qualifier.substring(1);
  456                                   }
  457                                   ResolveData data = new ResolveData(ivy.getResolveEngine(),
  458                                           new ResolveOptions());
  459                                   ModuleRevisionId mrid = ModuleRevisionId.newInstance(org,
  460                                       (String) otherAttValues.get("name"), (String) otherAttValues
  461                                               .get("rev"));
  462                                   DefaultDependencyDescriptor ddd = new DefaultDependencyDescriptor(
  463                                           mrid, false);
  464                                   try {
  465                                       String[] confs = ivy.getSettings().getResolver(mrid)
  466                                               .getDependency(ddd, data).getDescriptor()
  467                                               .getConfigurationsNames();
  468                                       for (int i = 0; i < confs.length; i++) {
  469                                           confs[i] = base + confs[i];
  470                                       }
  471                                       List ret = new ArrayList(Arrays.asList(confs));
  472                                       ret.add("*");
  473                                       return (String[]) ret.toArray(new String[ret.size()]);
  474                                   } catch (ParseException e) {
  475                                       getSettings().logError(
  476                                           "The dependencies of " + mrid + " could not be parsed", e);
  477                                       return new String[] {"*"};
  478                                   }
  479                               }
  480                           }
  481                           return new String[] {"*"};
  482                       }
  483   
  484                   }));
  485           allConf.add(conf3);
  486           IvyTag mapped = new IvyTag("mapped",
  487                   "map dependency configurations for this master configuration");
  488           mapped
  489                   .addAttribute(new IvyTagAttribute(
  490                           "name",
  491                           "the name of the dependency configuration mapped. \n"
  492                                   + "'*' wildcard can be used to designate all configurations of this module",
  493                           true, new IValueProvider() {
  494                               public String[] getValuesfor(IvyTagAttribute att, IvyFile ivyFile) {
  495                                   Ivy ivy = getIvy();
  496                                   int[] indexes = ivyFile.getParentTagIndex();
  497                                   if (indexes != null && ivy != null) {
  498                                       indexes = ivyFile.getParentTagIndex(indexes[0]);
  499                                       if (indexes != null) {
  500                                           Map otherAttValues = ivyFile
  501                                                   .getAllAttsValues(indexes[0] + 1);
  502                                           String org = ((IvyModuleDescriptorFile) ivyFile)
  503                                                   .getDependencyOrganisation(otherAttValues);
  504                                           if (org != null && otherAttValues != null
  505                                                   && otherAttValues.get("name") != null
  506                                                   && otherAttValues.get("rev") != null) {
  507                                               ResolveData data = new ResolveData(ivy
  508                                                       .getResolveEngine(), new ResolveOptions());
  509                                               ModuleRevisionId mrid = ModuleRevisionId.newInstance(
  510                                                   org, (String) otherAttValues.get("name"),
  511                                                   (String) otherAttValues.get("rev"));
  512                                               DefaultDependencyDescriptor ddd = new DefaultDependencyDescriptor(
  513                                                       mrid, false);
  514                                               try {
  515                                                   String[] confs = ivy.getSettings()
  516                                                           .getResolver(mrid).getDependency(ddd, data)
  517                                                           .getDescriptor().getConfigurationsNames();
  518                                                   List ret = new ArrayList(Arrays.asList(confs));
  519                                                   ret.add("*");
  520                                                   return (String[]) ret
  521                                                           .toArray(new String[ret.size()]);
  522                                               } catch (ParseException e) {
  523                                                   getSettings().logError(
  524                                                       "The dependencies of " + mrid
  525                                                               + " could not be parsed", e);
  526                                                   return new String[] {"*"};
  527                                               }
  528                                           }
  529                                       }
  530                                   }
  531                                   return new String[] {"*"};
  532                               }
  533   
  534                           }));
  535           conf3.addChildIvyTag(mapped);
  536           addTag(mapped);
  537   
  538           String[] matcherNames = new String[0];
  539           Ivy ivy = getIvy();
  540           if (ivy != null) {
  541               matcherNames = (String[]) ivy.getSettings().getMatcherNames().toArray(new String[0]);
  542           }
  543           ListValueProvider matcherNamesProvider = new ListValueProvider(matcherNames);
  544   
  545           IvyTag artifact2 = new IvyTag("artifact", "defines artifacts restriction \n"
  546                   + "use only if you do not control dependency ivy file");
  547           artifact2.addAttribute(new IvyTagAttribute("name", "the name of an artifact of the \n"
  548                   + "dependency module to add to the include list, \n"
  549                   + "or a regexp matching this name", false));
  550           artifact2.addAttribute(new IvyTagAttribute("type", "the type of the artifact of the \n"
  551                   + "dependency module to add to the include list, \n"
  552                   + "or a regexp matching this name", false,
  553                   new ListValueProvider(getDefault("type"))));
  554           artifact2
  555                   .addAttribute(new IvyTagAttribute("ext", "the extension of the artifact of the \n"
  556                           + "dependency module to add to the include list, \n"
  557                           + "or a regexp matching this name", false, new ListValueProvider(
  558                           getDefault("ext"))));
  559           artifact2.addAttribute(new IvyTagAttribute("url",
  560                   "an url where this artifact can be found \n"
  561                           + "if it isn't present at the standard \n" + "location in the repository",
  562                   false));
  563           artifact2
  564                   .addAttribute(new IvyTagAttribute(
  565                           "conf",
  566                           "comma separated list of the master configurations \n"
  567                                   + "in which this artifact should be included. \n"
  568                                   + "'*' wildcard can be used to designate all configurations of this module",
  569                           false, masterConfsValueProvider));
  570           IvyTag conf4 = new IvyTag("conf", "configuration in which the artifact should be included");
  571           conf4.addAttribute(new IvyTagAttribute("name",
  572                   "the name of the master configuration in which \n"
  573                           + "the enclosing artifact should be included", true,
  574                   masterConfValueProvider));
  575           allConf.add(conf4);
  576           artifact2.addChildIvyTag(conf4);
  577           addTag(artifact2);
  578           IvyTag include = new IvyTag("include", "defines artifacts restriction \n"
  579                   + "use only if you do not control dependency ivy file");
  580           include.addAttribute(new IvyTagAttribute("name", "the name of an artifact of the \n"
  581                   + "dependency module to add to the include list, \n"
  582                   + "or a regexp matching this name", false));
  583           include.addAttribute(new IvyTagAttribute("type", "the type of the artifact of the \n"
  584                   + "dependency module to add to the include list, \n"
  585                   + "or a regexp matching this name", false,
  586                   new ListValueProvider(getDefault("type"))));
  587           include
  588                   .addAttribute(new IvyTagAttribute("ext", "the extension of the artifact of the \n"
  589                           + "dependency module to add to the include list, \n"
  590                           + "or a regexp matching this name", false, new ListValueProvider(
  591                           getDefault("ext"))));
  592           include.addAttribute(new IvyTagAttribute("matcher",
  593                   "the matcher to use to match the modules to include", false, matcherNamesProvider));
  594           include
  595                   .addAttribute(new IvyTagAttribute(
  596                           "conf",
  597                           "comma separated list of the master configurations \n"
  598                                   + "in which this artifact should be included. \n"
  599                                   + "'*' wildcard can be used to designate all configurations of this module",
  600                           false, masterConfsValueProvider));
  601           IvyTag conf5 = new IvyTag("conf", "configuration in which the artifact should be included");
  602           conf5.addAttribute(new IvyTagAttribute("name",
  603                   "the name of the master configuration in which \n"
  604                           + "the enclosing artifact should be included", true,
  605                   masterConfValueProvider));
  606           include.addChildIvyTag(conf5);
  607           addTag(include);
  608           allConf.add(conf5);
  609           IvyTag exclude = new IvyTag("exclude", "defines artifacts restriction \n"
  610                   + "use only if you do not control dependency ivy file");
  611           exclude.addAttribute(new IvyTagAttribute("org", "the organisation of the dependency \n"
  612                   + "module or artifact to exclude, \n" + "or a pattern matching this organisation",
  613                   false));
  614           exclude.addAttribute(new IvyTagAttribute("module", "the name of the dependency \n"
  615                   + "module or the artifact to exclude, \n"
  616                   + "or a pattern matching this module name", false));
  617           exclude.addAttribute(new IvyTagAttribute("name", "the name of an artifact of the \n"
  618                   + "dependency module to add to the exclude list, \n"
  619                   + "or a pattern matching this name", false));
  620           exclude.addAttribute(new IvyTagAttribute("type", "the type of the artifact of the \n"
  621                   + "dependency module to add to the exclude list, \n"
  622                   + "or a pattern matching this name", false, new ListValueProvider(
  623                   getDefault("type"))));
  624           exclude.addAttribute(new IvyTagAttribute("ext", "the extension of the artifact of the \n"
  625                   + "dependency module to add to the exclude list, \n"
  626                   + "or a pattern matching this name", false,
  627                   new ListValueProvider(getDefault("ext"))));
  628           exclude.addAttribute(new IvyTagAttribute("matcher",
  629                   "the matcher to use to match the modules to include", false, matcherNamesProvider));
  630           exclude
  631                   .addAttribute(new IvyTagAttribute(
  632                           "conf",
  633                           "comma separated list of the master configurations \n"
  634                                   + "in which this artifact should be excluded. \n"
  635                                   + "'*' wildcard can be used to designate all configurations of this module",
  636                           false, masterConfsValueProvider));
  637           IvyTag conf6 = new IvyTag("conf", "configuration in which the artifact should be excluded");
  638           conf6.addAttribute(new IvyTagAttribute("name",
  639                   "the name of the master configuration in which \n"
  640                           + "the enclosing artifact should be excluded", true,
  641                   masterConfValueProvider));
  642           allConf.add(conf6);
  643           exclude.addChildIvyTag(conf6);
  644           addTag(exclude);
  645           dependency.addChildIvyTag(conf3);
  646           dependency.addChildIvyTag(artifact2);
  647           dependency.addChildIvyTag(include);
  648           dependency.addChildIvyTag(exclude);
  649           dependencies.addChildIvyTag(dependency);
  650           ivyTag.addChildIvyTag(dependencies);
  651           addTag(dependency);
  652           addTag(dependencies);
  653   
  654           // dependencies
  655   
  656           IvyTag conflicts = new IvyTag("conflicts", "conflicts managers definition section");
  657           IvyTag manager = new IvyTag("manager", "declares a conflict manager for this module");
  658           manager.addAttribute(new IvyTagAttribute("org",
  659                   "the name, or a regexp matching the name of organisation \n"
  660                           + "to which this conflict manager should apply", false));
  661           manager.addAttribute(new IvyTagAttribute("module",
  662                   "the name, or a regexp matching the name of module \n"
  663                           + "to which this conflict manager should apply", false));
  664           manager.addAttribute(new IvyTagAttribute("name", "the name of the conflict manager to use",
  665                   false));
  666           manager.addAttribute(new IvyTagAttribute("rev",
  667                   "a comma separated list of revisions this conflict manager should select", false));
  668           manager.addAttribute(new IvyTagAttribute("matcher",
  669                   "the matcher to use to match the modules for which \n"
  670                           + "the conflict manager should be used", false));
  671           conflicts.addChildIvyTag(manager);
  672           ivyTag.addChildIvyTag(conflicts);
  673           addTag(conflicts);
  674           addTag(manager);
  675       }
  676   
  677       protected String getRootIvyTagName() {
  678           return "ivy-module";
  679       }
  680   
  681       List listDependencyTokenValues(String att, IvyFile ivyfile) {
  682           Map allAttsValues = ivyfile.getAllAttsValues();
  683           String org = ((IvyModuleDescriptorFile) ivyfile).getOrganisation();
  684           if (org != null && !allAttsValues.containsKey("org")) {
  685               allAttsValues.put("org", org);
  686           }
  687           return listDependencyTokenValues(att, allAttsValues);
  688       }
  689   
  690       private List listDependencyTokenValues(String att, Map otherAttValues) {
  691           List ret = new ArrayList();
  692           Ivy ivy = getIvy();
  693           if (ivy != null) {
  694               replaceToken(otherAttValues, "org", IvyPatternHelper.ORGANISATION_KEY);
  695               replaceToken(otherAttValues, "name", IvyPatternHelper.MODULE_KEY);
  696               replaceToken(otherAttValues, "rev", IvyPatternHelper.REVISION_KEY);
  697   
  698               if (!otherAttValues.containsKey(IvyPatternHelper.BRANCH_KEY)) {
  699                   otherAttValues.put(IvyPatternHelper.BRANCH_KEY, ivy.getSettings()
  700                           .getDefaultBranch());
  701               }
  702   
  703               String stdAtt = standardiseDependencyAttribute(att);
  704               otherAttValues.remove(stdAtt);
  705               String[] revs = ivy.listTokenValues(stdAtt, otherAttValues);
  706               if (revs != null) {
  707                   ret.addAll(Arrays.asList(revs));
  708               }
  709           }
  710           return ret;
  711       }
  712   
  713       private void replaceToken(Map otherAttValues, String oldToken, String newToken) {
  714           String val = (String) otherAttValues.remove(oldToken);
  715           if (val != null) {
  716               otherAttValues.put(newToken, val);
  717           }
  718       }
  719   
  720       private String standardiseDependencyAttribute(String att) {
  721           if ("org".equals(att)) {
  722               return IvyPatternHelper.ORGANISATION_KEY;
  723           }
  724           if ("name".equals(att)) {
  725               return IvyPatternHelper.MODULE_KEY;
  726           }
  727           if ("rev".equals(att)) {
  728               return IvyPatternHelper.REVISION_KEY;
  729           }
  730           return att;
  731       }
  732   
  733       public IvyFile newIvyFile(String name, String content, int documentOffset) {
  734           return new IvyModuleDescriptorFile(getSettings(), name, content, documentOffset);
  735       }
  736   
  737   }

Home » apache-ivyde-sources-2.0.0.final-200907011148-RELEASE » org.apache.ivyde.common.ivyfile » [javadoc | source]
乐优彩票天天红单下载 乐博现金lb377775 乐优彩票登入,备用,官方网址 乐优彩票网址是多少 乐优炫彩app 乐博28app下载 乐优炫彩app下载 乐优炫彩app天天红单 乐优炫彩天天红单 乐优炫彩官网