You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-commits@incubator.apache.org by gs...@apache.org on 2007/07/28 19:11:59 UTC
svn commit: r560593 [1/3] - in /incubator/ivy/core/trunk:
src/java/org/apache/ivy/plugins/parser/m2/
src/java/org/apache/ivy/plugins/parser/xml/
src/java/org/apache/ivy/plugins/repository/sftp/
src/java/org/apache/ivy/plugins/repository/ssh/ src/java/o...
Author: gscokart
Date: Sat Jul 28 12:11:58 2007
New Revision: 560593
URL: http://svn.apache.org/viewvc?view=rev&rev=560593
Log:
code cleaning for checkstyle
Modified:
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorWriter.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/sftp/SFTPRepository.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/ssh/SshRepository.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/AbstractSshBasedResolver.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/ChainResolver.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/DualResolver.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/IvyRepResolver.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/RepositoryResolver.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/resolver/SshResolver.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/util/FileUtil.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/util/StringUtils.java
incubator/ivy/core/trunk/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParserTest.java
Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java?view=diff&rev=560593&r1=560592&r2=560593
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java Sat Jul 28 12:11:58 2007
@@ -296,7 +296,8 @@
private void processTextContent() {
if (buffer != null) {
- String txt = IvyPatternHelper.substituteVariables(buffer.toString(), properties).trim();
+ String txt = IvyPatternHelper.substituteVariables(buffer.toString(),
+ properties).trim();
buffer = null;
if (txt.length() == 0) {
Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java?view=diff&rev=560593&r1=560592&r2=560593
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java Sat Jul 28 12:11:58 2007
@@ -67,11 +67,11 @@
* Parses an xml ivy file and output a ModuleDescriptor. For dependency and performance reasons, it
* uses only the SAX API, which makes the parsing code harder to understand.
*/
-public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
+public final class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
static final String[] DEPENDENCY_REGULAR_ATTRIBUTES = new String[] {"org", "name", "branch",
"rev", "force", "transitive", "changing", "conf"};
- private static XmlModuleDescriptorParser INSTANCE = new XmlModuleDescriptorParser();
+ private static final XmlModuleDescriptorParser INSTANCE = new XmlModuleDescriptorParser();
public static XmlModuleDescriptorParser getInstance() {
return INSTANCE;
@@ -139,21 +139,21 @@
private static final List ALLOWED_VERSIONS = Arrays.asList(
new String[] {"1.0", "1.1", "1.2", "1.3", "1.4", "2.0"});
- private DefaultDependencyDescriptor _dd;
+ private DefaultDependencyDescriptor dd;
- private ConfigurationAware _confAware;
+ private ConfigurationAware confAware;
- private MDArtifact _artifact;
+ private MDArtifact artifact;
- private String _conf;
+ private String conf;
- private boolean _validate = true;
+ private boolean validate = true;
- private IvySettings _ivy;
+ private IvySettings ivy;
- private boolean _artifactsDeclared = false;
+ private boolean artifactsDeclared = false;
- private PatternMatcher _defaultMatcher;
+ private PatternMatcher defaultMatcher;
private static final int NONE = 0;
@@ -177,14 +177,15 @@
private static final int DEPS = 10;
- private int _state = NONE;
+ private int state = NONE;
private final URL xmlURL;
- public Parser(ModuleDescriptorParser parser, IvySettings ivySettings, boolean validate, URL xmlURL) {
+ public Parser(ModuleDescriptorParser parser, IvySettings ivySettings, boolean validate,
+ URL xmlURL) {
super(parser);
- _ivy = ivySettings;
- _validate = validate;
+ ivy = ivySettings;
+ this.validate = validate;
this.xmlURL = xmlURL;
}
@@ -196,7 +197,7 @@
XMLHelper.parse(xmlURL, schemaURL, this);
checkConfigurations();
replaceConfigurationWildcards();
- if (!_artifactsDeclared) {
+ if (!artifactsDeclared) {
String[] confs = md.getConfigurationsNames();
for (int i = 0; i < confs.length; i++) {
md.addArtifact(confs[i], new MDArtifact(md, md.getModuleRevisionId()
@@ -225,7 +226,7 @@
XMLHelper.parse(descriptor, schemaURL, this, null);
checkConfigurations();
replaceConfigurationWildcards();
- if (!_artifactsDeclared) {
+ if (!artifactsDeclared) {
String[] confs = md.getConfigurationsNames();
for (int i = 0; i < confs.length; i++) {
md.addArtifact(confs[i], new MDArtifact(md, md.getModuleRevisionId()
@@ -249,285 +250,47 @@
throws SAXException {
try {
if ("ivy-module".equals(qName)) {
- String version = attributes.getValue("version");
- int versionIndex = ALLOWED_VERSIONS.indexOf(version);
- if (versionIndex == -1) {
- addError("invalid version " + version);
- throw new SAXException("invalid version " + version);
- }
- if (versionIndex >= ALLOWED_VERSIONS.indexOf("1.3")) {
- Message.debug("post 1.3 ivy file: using " + PatternMatcher.EXACT
- + " as default matcher");
- _defaultMatcher = _ivy.getMatcher(PatternMatcher.EXACT);
- } else {
- Message.debug("pre 1.3 ivy file: using " + PatternMatcher.EXACT_OR_REGEXP
- + " as default matcher");
- _defaultMatcher = _ivy.getMatcher(PatternMatcher.EXACT_OR_REGEXP);
- }
+ ivyModuleStarted(attributes);
} else if ("info".equals(qName)) {
- _state = INFO;
- String org = _ivy.substitute(attributes.getValue("organisation"));
- String module = _ivy.substitute(attributes.getValue("module"));
- String revision = _ivy.substitute(attributes.getValue("revision"));
- String branch = _ivy.substitute(attributes.getValue("branch"));
- md.setModuleRevisionId(ModuleRevisionId.newInstance(org, module, branch,
- revision, ExtendableItemHelper.getExtraAttributes(attributes, new String[] {
- "organisation", "module", "revision", "status", "publication",
- "namespace", "default", "resolver"})));
-
- String namespace = _ivy.substitute(attributes.getValue("namespace"));
- if (namespace != null) {
- Namespace ns = _ivy.getNamespace(namespace);
- if (ns == null) {
- Message.warn("namespace not found for " + md.getModuleRevisionId()
- + ": " + namespace);
- } else {
- md.setNamespace(ns);
- }
- }
-
- String status = _ivy.substitute(attributes.getValue("status"));
- md.setStatus(status == null ? _ivy.getStatusManager().getDefaultStatus()
- : status);
- md.setDefault(Boolean.valueOf(_ivy.substitute(attributes.getValue("default")))
- .booleanValue());
- String pubDate = _ivy.substitute(attributes.getValue("publication"));
- if (pubDate != null && pubDate.length() > 0) {
- try {
- md.setPublicationDate(Ivy.DATE_FORMAT.parse(pubDate));
- } catch (ParseException e) {
- addError("invalid publication date format: " + pubDate);
- md.setPublicationDate(getDefaultPubDate());
- }
- } else {
- md.setPublicationDate(getDefaultPubDate());
- }
-
+ infoStarted(attributes);
} else if ("license".equals(qName)) {
- md.addLicense(new License(_ivy.substitute(attributes.getValue("name")), _ivy
+ md.addLicense(new License(ivy.substitute(attributes.getValue("name")), ivy
.substitute(attributes.getValue("url"))));
} else if ("description".equals(qName)) {
- md.setHomePage(_ivy.substitute(attributes.getValue("homepage")));
+ md.setHomePage(ivy.substitute(attributes.getValue("homepage")));
} else if ("configurations".equals(qName)) {
- _state = CONF;
- setDefaultConfMapping(_ivy
- .substitute(attributes.getValue("defaultconfmapping")));
- md
- .setMappingOverride(Boolean.valueOf(
- _ivy.substitute(attributes.getValue("confmappingoverride")))
- .booleanValue());
+ configurationStarted(attributes);
} else if ("publications".equals(qName)) {
- _state = PUB;
- _artifactsDeclared = true;
+ state = PUB;
+ artifactsDeclared = true;
checkConfigurations();
} else if ("dependencies".equals(qName)) {
- _state = DEPS;
- String defaultConf = _ivy.substitute(attributes.getValue("defaultconf"));
- if (defaultConf != null) {
- setDefaultConf(defaultConf);
- }
- defaultConf = _ivy.substitute(attributes.getValue("defaultconfmapping"));
- if (defaultConf != null) {
- setDefaultConfMapping(defaultConf);
- }
- String confMappingOverride = _ivy.substitute(attributes
- .getValue("confmappingoverride"));
- if (confMappingOverride != null) {
- md.setMappingOverride(Boolean.valueOf(confMappingOverride).booleanValue());
- }
- checkConfigurations();
+ dependenciesStarted(attributes);
} else if ("conflicts".equals(qName)) {
- _state = CONFLICT;
+ state = CONFLICT;
checkConfigurations();
} else if ("artifact".equals(qName)) {
- if (_state == PUB) {
- // this is a published artifact
- String artName = _ivy.substitute(attributes.getValue("name"));
- artName = artName == null ? md.getModuleRevisionId().getName() : artName;
- String type = _ivy.substitute(attributes.getValue("type"));
- type = type == null ? "jar" : type;
- String ext = _ivy.substitute(attributes.getValue("ext"));
- ext = ext != null ? ext : type;
- String url = _ivy.substitute(attributes.getValue("url"));
- _artifact = new MDArtifact(md, artName, type, ext, url == null ? null
- : new URL(url), ExtendableItemHelper.getExtraAttributes(attributes,
- new String[] {"ext", "type", "name", "conf"}));
- String confs = _ivy.substitute(attributes.getValue("conf"));
- // only add confs if they are specified. if they aren't, endElement will
- // handle this
- // only if there are no conf defined in sub elements
- if (confs != null && confs.length() > 0) {
- String[] conf;
- if ("*".equals(confs)) {
- conf = md.getConfigurationsNames();
- } else {
- conf = confs.split(",");
- }
- for (int i = 0; i < conf.length; i++) {
- _artifact.addConfiguration(conf[i].trim());
- md.addArtifact(conf[i].trim(), _artifact);
- }
- }
- } else if (_state == DEP) {
- // this is an artifact asked for a particular dependency
- addDependencyArtifacts(qName, attributes);
- } else if (_validate) {
- addError("artifact tag found in invalid tag: " + _state);
- }
- } else if ("include".equals(qName) && _state == DEP) {
+ artifactStarted(qName, attributes);
+ } else if ("include".equals(qName) && state == DEP) {
addIncludeRule(qName, attributes);
- } else if ("exclude".equals(qName) && _state == DEP) {
+ } else if ("exclude".equals(qName) && state == DEP) {
addExcludeRule(qName, attributes);
- } else if ("exclude".equals(qName) && _state == DEPS) {
- _state = EXCLUDE;
+ } else if ("exclude".equals(qName) && state == DEPS) {
+ state = EXCLUDE;
parseRule(qName, attributes);
- md.addExcludeRule((ExcludeRule) _confAware);
- } else if ("dependency".equals(qName)) {
- _state = DEP;
- String org = _ivy.substitute(attributes.getValue("org"));
- if (org == null) {
- org = md.getModuleRevisionId().getOrganisation();
- }
- boolean force = Boolean.valueOf(_ivy.substitute(attributes.getValue("force")))
- .booleanValue();
- boolean changing = Boolean.valueOf(
- _ivy.substitute(attributes.getValue("changing"))).booleanValue();
-
- String transitiveValue = _ivy.substitute(attributes.getValue("transitive"));
- boolean transitive = (transitiveValue == null) ? true : Boolean.valueOf(
- attributes.getValue("transitive")).booleanValue();
-
- String name = _ivy.substitute(attributes.getValue("name"));
- String branch = _ivy.substitute(attributes.getValue("branch"));
- String rev = _ivy.substitute(attributes.getValue("rev"));
- _dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(org,
- name, branch, rev, ExtendableItemHelper.getExtraAttributes(attributes,
- DEPENDENCY_REGULAR_ATTRIBUTES)), force, changing, transitive);
- md.addDependency(_dd);
- String confs = _ivy.substitute(attributes.getValue("conf"));
- if (confs != null && confs.length() > 0) {
- parseDepsConfs(confs, _dd);
- }
+ md.addExcludeRule((ExcludeRule) confAware);
+ } else if ("dependency".equals(qName)) {
+ dependencyStarted(attributes);
} else if ("conf".equals(qName)) {
- String conf = _ivy.substitute(attributes.getValue("name"));
- switch (_state) {
- case CONF:
- String visibility = _ivy.substitute(attributes.getValue("visibility"));
- String ext = _ivy.substitute(attributes.getValue("extends"));
- String transitiveValue = attributes.getValue("transitive");
- boolean transitive = (transitiveValue == null) ? true : Boolean
- .valueOf(attributes.getValue("transitive")).booleanValue();
- Configuration configuration = new Configuration(conf,
- Configuration.Visibility
- .getVisibility(visibility == null ? "public"
- : visibility), _ivy.substitute(attributes
- .getValue("description")), ext == null ? null : ext
- .split(","), transitive);
- ExtendableItemHelper.fillExtraAttributes(configuration, attributes,
- new String[] {"name", "visibility", "extends", "transitive",
- "description"});
- md.addConfiguration(configuration);
- break;
- case PUB:
- if ("*".equals(conf)) {
- String[] confs = md.getConfigurationsNames();
- for (int i = 0; i < confs.length; i++) {
- _artifact.addConfiguration(confs[i]);
- md.addArtifact(confs[i], _artifact);
- }
- } else {
- _artifact.addConfiguration(conf);
- md.addArtifact(conf, _artifact);
- }
- break;
- case DEP:
- _conf = conf;
- String mappeds = _ivy.substitute(attributes.getValue("mapped"));
- if (mappeds != null) {
- String[] mapped = mappeds.split(",");
- for (int i = 0; i < mapped.length; i++) {
- _dd.addDependencyConfiguration(_conf, mapped[i].trim());
- }
- }
- break;
- case DEP_ARTIFACT:
- case ARTIFACT_INCLUDE:
- case ARTIFACT_EXCLUDE:
- addConfiguration(conf);
- break;
- default:
- if (_validate) {
- addError("conf tag found in invalid tag: " + _state);
- }
- break;
- }
+ confStarted(attributes);
} else if ("mapped".equals(qName)) {
- _dd.addDependencyConfiguration(_conf, _ivy.substitute(attributes
+ dd.addDependencyConfiguration(conf, ivy.substitute(attributes
.getValue("name")));
- } else if ("manager".equals(qName) && _state == CONFLICT) {
- String org = _ivy.substitute(attributes.getValue("org"));
- org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
- String mod = _ivy.substitute(attributes.getValue("module"));
- mod = mod == null ? PatternMatcher.ANY_EXPRESSION : mod;
- ConflictManager cm;
- String name = _ivy.substitute(attributes.getValue("name"));
- String rev = _ivy.substitute(attributes.getValue("rev"));
- if (rev != null) {
- String[] revs = rev.split(",");
- for (int i = 0; i < revs.length; i++) {
- revs[i] = revs[i].trim();
- }
- cm = new FixedConflictManager(revs);
- } else if (name != null) {
- cm = _ivy.getConflictManager(name);
- if (cm == null) {
- addError("unknown conflict manager: " + name);
- return;
- }
- } else {
- addError("bad conflict manager: no name nor rev");
- return;
- }
- String matcherName = _ivy.substitute(attributes.getValue("matcher"));
- PatternMatcher matcher = matcherName == null ? _defaultMatcher : _ivy
- .getMatcher(matcherName);
- if (matcher == null) {
- addError("unknown matcher: " + matcherName);
- return;
- }
- md.addConflictManager(new ModuleId(org, mod), matcher, cm);
- } else if ("include".equals(qName) && _state == CONF) {
- URL url = _ivy.getRelativeUrlResolver().getURL(xmlURL,
- _ivy.substitute(attributes.getValue("file")),
- _ivy.substitute(attributes.getValue("url")));
-
- if (url == null) {
- throw new SAXException("include tag must have a file or an url attribute");
- }
-
- // create a new temporary parser to read the configurations from
- // the specified file.
- Parser parser = new Parser(getModuleDescriptorParser(), _ivy, false, url);
- parser.md = new DefaultModuleDescriptor(getModuleDescriptorParser(),
- new URLResource(url));
- XMLHelper.parse(url , null, parser);
-
- // add the configurations from this temporary parser to this module descriptor
- Configuration[] configs = parser.getModuleDescriptor().getConfigurations();
- for (int i = 0; i < configs.length; i++) {
- md.addConfiguration(configs[i]);
- }
- if (parser.getDefaultConfMapping() != null) {
- Message.debug("setting default conf from imported configurations file: "
- + parser.getDefaultConfMapping());
- setDefaultConfMapping(parser.getDefaultConfMapping());
- }
- if (parser.md.isMappingOverride()) {
- Message.debug("enabling mapping-override from imported configurations"
- + " file");
- md.setMappingOverride(true);
- }
- } else if (_validate && _state != INFO) {
+ } else if ("manager".equals(qName) && state == CONFLICT) {
+ managerStarted(attributes);
+ } else if ("include".equals(qName) && state == CONF) {
+ includeConfStarted(attributes);
+ } else if (validate && state != INFO) {
addError("unknwon tag " + qName);
}
} catch (Exception ex) {
@@ -539,65 +302,342 @@
}
}
+ private void managerStarted(Attributes attributes) {
+ String org = ivy.substitute(attributes.getValue("org"));
+ org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
+ String mod = ivy.substitute(attributes.getValue("module"));
+ mod = mod == null ? PatternMatcher.ANY_EXPRESSION : mod;
+ ConflictManager cm;
+ String name = ivy.substitute(attributes.getValue("name"));
+ String rev = ivy.substitute(attributes.getValue("rev"));
+ if (rev != null) {
+ String[] revs = rev.split(",");
+ for (int i = 0; i < revs.length; i++) {
+ revs[i] = revs[i].trim();
+ }
+ cm = new FixedConflictManager(revs);
+ } else if (name != null) {
+ cm = ivy.getConflictManager(name);
+ if (cm == null) {
+ addError("unknown conflict manager: " + name);
+ return;
+ }
+ } else {
+ addError("bad conflict manager: no name nor rev");
+ return;
+ }
+ String matcherName = ivy.substitute(attributes.getValue("matcher"));
+ PatternMatcher matcher = matcherName == null ? defaultMatcher : ivy
+ .getMatcher(matcherName);
+ if (matcher == null) {
+ addError("unknown matcher: " + matcherName);
+ return;
+ }
+ md.addConflictManager(new ModuleId(org, mod), matcher, cm);
+ }
+
+ private void includeConfStarted(Attributes attributes)
+ throws SAXException, IOException, ParserConfigurationException, ParseException {
+ URL url = ivy.getRelativeUrlResolver().getURL(xmlURL,
+ ivy.substitute(attributes.getValue("file")),
+ ivy.substitute(attributes.getValue("url")));
+
+ if (url == null) {
+ throw new SAXException("include tag must have a file or an url attribute");
+ }
+
+ // create a new temporary parser to read the configurations from
+ // the specified file.
+ Parser parser = new Parser(getModuleDescriptorParser(), ivy, false, url);
+ parser.md = new DefaultModuleDescriptor(getModuleDescriptorParser(),
+ new URLResource(url));
+ XMLHelper.parse(url , null, parser);
+
+ // add the configurations from this temporary parser to this module descriptor
+ Configuration[] configs = parser.getModuleDescriptor().getConfigurations();
+ for (int i = 0; i < configs.length; i++) {
+ md.addConfiguration(configs[i]);
+ }
+ if (parser.getDefaultConfMapping() != null) {
+ Message.debug("setting default conf from imported configurations file: "
+ + parser.getDefaultConfMapping());
+ setDefaultConfMapping(parser.getDefaultConfMapping());
+ }
+ if (parser.md.isMappingOverride()) {
+ Message.debug("enabling mapping-override from imported configurations"
+ + " file");
+ md.setMappingOverride(true);
+ }
+ }
+
+ private void confStarted(Attributes attributes) {
+ String conf = ivy.substitute(attributes.getValue("name"));
+ switch (state) {
+ case CONF:
+ String visibility = ivy.substitute(attributes.getValue("visibility"));
+ String ext = ivy.substitute(attributes.getValue("extends"));
+ String transitiveValue = attributes.getValue("transitive");
+ boolean transitive = (transitiveValue == null) ? true : Boolean
+ .valueOf(attributes.getValue("transitive")).booleanValue();
+ Configuration configuration = new Configuration(conf,
+ Configuration.Visibility
+ .getVisibility(visibility == null ? "public"
+ : visibility), ivy.substitute(attributes
+ .getValue("description")), ext == null ? null : ext
+ .split(","), transitive);
+ ExtendableItemHelper.fillExtraAttributes(configuration, attributes,
+ new String[] {"name", "visibility", "extends", "transitive",
+ "description"});
+ md.addConfiguration(configuration);
+ break;
+ case PUB:
+ if ("*".equals(conf)) {
+ String[] confs = md.getConfigurationsNames();
+ for (int i = 0; i < confs.length; i++) {
+ artifact.addConfiguration(confs[i]);
+ md.addArtifact(confs[i], artifact);
+ }
+ } else {
+ artifact.addConfiguration(conf);
+ md.addArtifact(conf, artifact);
+ }
+ break;
+ case DEP:
+ this.conf = conf;
+ String mappeds = ivy.substitute(attributes.getValue("mapped"));
+ if (mappeds != null) {
+ String[] mapped = mappeds.split(",");
+ for (int i = 0; i < mapped.length; i++) {
+ dd.addDependencyConfiguration(conf, mapped[i].trim());
+ }
+ }
+ break;
+ case DEP_ARTIFACT:
+ case ARTIFACT_INCLUDE:
+ case ARTIFACT_EXCLUDE:
+ addConfiguration(conf);
+ break;
+ default:
+ if (validate) {
+ addError("conf tag found in invalid tag: " + state);
+ }
+ break;
+ }
+ }
+
+ private void dependencyStarted(Attributes attributes) {
+ state = DEP;
+ String org = ivy.substitute(attributes.getValue("org"));
+ if (org == null) {
+ org = md.getModuleRevisionId().getOrganisation();
+ }
+ boolean force = Boolean.valueOf(ivy.substitute(attributes.getValue("force")))
+ .booleanValue();
+ boolean changing = Boolean.valueOf(
+ ivy.substitute(attributes.getValue("changing"))).booleanValue();
+
+ String transitiveValue = ivy.substitute(attributes.getValue("transitive"));
+ boolean transitive = (transitiveValue == null) ? true : Boolean.valueOf(
+ attributes.getValue("transitive")).booleanValue();
+
+ String name = ivy.substitute(attributes.getValue("name"));
+ String branch = ivy.substitute(attributes.getValue("branch"));
+ String rev = ivy.substitute(attributes.getValue("rev"));
+ dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(org,
+ name, branch, rev, ExtendableItemHelper.getExtraAttributes(attributes,
+ DEPENDENCY_REGULAR_ATTRIBUTES)), force, changing, transitive);
+ md.addDependency(dd);
+ String confs = ivy.substitute(attributes.getValue("conf"));
+ if (confs != null && confs.length() > 0) {
+ parseDepsConfs(confs, dd);
+ }
+ }
+
+ private void artifactStarted(String qName, Attributes attributes)
+ throws MalformedURLException {
+ if (state == PUB) {
+ // this is a published artifact
+ String artName = ivy.substitute(attributes.getValue("name"));
+ artName = artName == null ? md.getModuleRevisionId().getName() : artName;
+ String type = ivy.substitute(attributes.getValue("type"));
+ type = type == null ? "jar" : type;
+ String ext = ivy.substitute(attributes.getValue("ext"));
+ ext = ext != null ? ext : type;
+ String url = ivy.substitute(attributes.getValue("url"));
+ artifact = new MDArtifact(md, artName, type, ext, url == null ? null
+ : new URL(url), ExtendableItemHelper.getExtraAttributes(attributes,
+ new String[] {"ext", "type", "name", "conf"}));
+ String confs = ivy.substitute(attributes.getValue("conf"));
+ // only add confs if they are specified. if they aren't, endElement will
+ // handle this
+ // only if there are no conf defined in sub elements
+ if (confs != null && confs.length() > 0) {
+ String[] conf;
+ if ("*".equals(confs)) {
+ conf = md.getConfigurationsNames();
+ } else {
+ conf = confs.split(",");
+ }
+ for (int i = 0; i < conf.length; i++) {
+ artifact.addConfiguration(conf[i].trim());
+ md.addArtifact(conf[i].trim(), artifact);
+ }
+ }
+ } else if (state == DEP) {
+ // this is an artifact asked for a particular dependency
+ addDependencyArtifacts(qName, attributes);
+ } else if (validate) {
+ addError("artifact tag found in invalid tag: " + state);
+ }
+ }
+
+ private void dependenciesStarted(Attributes attributes) {
+ state = DEPS;
+ String defaultConf = ivy.substitute(attributes.getValue("defaultconf"));
+ if (defaultConf != null) {
+ setDefaultConf(defaultConf);
+ }
+ defaultConf = ivy.substitute(attributes.getValue("defaultconfmapping"));
+ if (defaultConf != null) {
+ setDefaultConfMapping(defaultConf);
+ }
+ String confMappingOverride = ivy.substitute(attributes
+ .getValue("confmappingoverride"));
+ if (confMappingOverride != null) {
+ md.setMappingOverride(Boolean.valueOf(confMappingOverride).booleanValue());
+ }
+ checkConfigurations();
+ }
+
+ private void configurationStarted(Attributes attributes) {
+ state = CONF;
+ setDefaultConfMapping(ivy
+ .substitute(attributes.getValue("defaultconfmapping")));
+ md
+ .setMappingOverride(Boolean.valueOf(
+ ivy.substitute(attributes.getValue("confmappingoverride")))
+ .booleanValue());
+ }
+
+ private void infoStarted(Attributes attributes) {
+ state = INFO;
+ String org = ivy.substitute(attributes.getValue("organisation"));
+ String module = ivy.substitute(attributes.getValue("module"));
+ String revision = ivy.substitute(attributes.getValue("revision"));
+ String branch = ivy.substitute(attributes.getValue("branch"));
+ md.setModuleRevisionId(ModuleRevisionId.newInstance(org, module, branch,
+ revision, ExtendableItemHelper.getExtraAttributes(attributes, new String[] {
+ "organisation", "module", "revision", "status", "publication",
+ "namespace", "default", "resolver"})));
+
+ String namespace = ivy.substitute(attributes.getValue("namespace"));
+ if (namespace != null) {
+ Namespace ns = ivy.getNamespace(namespace);
+ if (ns == null) {
+ Message.warn("namespace not found for " + md.getModuleRevisionId()
+ + ": " + namespace);
+ } else {
+ md.setNamespace(ns);
+ }
+ }
+
+ String status = ivy.substitute(attributes.getValue("status"));
+ md.setStatus(status == null ? ivy.getStatusManager().getDefaultStatus()
+ : status);
+ md.setDefault(Boolean.valueOf(ivy.substitute(attributes.getValue("default")))
+ .booleanValue());
+ String pubDate = ivy.substitute(attributes.getValue("publication"));
+ if (pubDate != null && pubDate.length() > 0) {
+ try {
+ md.setPublicationDate(Ivy.DATE_FORMAT.parse(pubDate));
+ } catch (ParseException e) {
+ addError("invalid publication date format: " + pubDate);
+ md.setPublicationDate(getDefaultPubDate());
+ }
+ } else {
+ md.setPublicationDate(getDefaultPubDate());
+ }
+ }
+
+ private void ivyModuleStarted(Attributes attributes) throws SAXException {
+ String version = attributes.getValue("version");
+ int versionIndex = ALLOWED_VERSIONS.indexOf(version);
+ if (versionIndex == -1) {
+ addError("invalid version " + version);
+ throw new SAXException("invalid version " + version);
+ }
+ if (versionIndex >= ALLOWED_VERSIONS.indexOf("1.3")) {
+ Message.debug("post 1.3 ivy file: using " + PatternMatcher.EXACT
+ + " as default matcher");
+ defaultMatcher = ivy.getMatcher(PatternMatcher.EXACT);
+ } else {
+ Message.debug("pre 1.3 ivy file: using " + PatternMatcher.EXACT_OR_REGEXP
+ + " as default matcher");
+ defaultMatcher = ivy.getMatcher(PatternMatcher.EXACT_OR_REGEXP);
+ }
+ }
+
private void addDependencyArtifacts(String tag, Attributes attributes)
throws MalformedURLException {
- _state = DEP_ARTIFACT;
+ state = DEP_ARTIFACT;
parseRule(tag, attributes);
}
- private void addIncludeRule(String tag, Attributes attributes) throws MalformedURLException {
- _state = ARTIFACT_INCLUDE;
+ private void addIncludeRule(String tag, Attributes attributes)
+ throws MalformedURLException {
+ state = ARTIFACT_INCLUDE;
parseRule(tag, attributes);
}
- private void addExcludeRule(String tag, Attributes attributes) throws MalformedURLException {
- _state = ARTIFACT_EXCLUDE;
+ private void addExcludeRule(String tag, Attributes attributes)
+ throws MalformedURLException {
+ state = ARTIFACT_EXCLUDE;
parseRule(tag, attributes);
}
private void parseRule(String tag, Attributes attributes) throws MalformedURLException {
- String name = _ivy.substitute(attributes.getValue("name"));
+ String name = ivy.substitute(attributes.getValue("name"));
if (name == null) {
- name = _ivy.substitute(attributes.getValue("artifact"));
+ name = ivy.substitute(attributes.getValue("artifact"));
if (name == null) {
- name = "artifact".equals(tag) ? _dd.getDependencyId().getName()
+ name = "artifact".equals(tag) ? dd.getDependencyId().getName()
: PatternMatcher.ANY_EXPRESSION;
}
}
- String type = _ivy.substitute(attributes.getValue("type"));
+ String type = ivy.substitute(attributes.getValue("type"));
if (type == null) {
type = "artifact".equals(tag) ? "jar" : PatternMatcher.ANY_EXPRESSION;
}
- String ext = _ivy.substitute(attributes.getValue("ext"));
+ String ext = ivy.substitute(attributes.getValue("ext"));
ext = ext != null ? ext : type;
- if (_state == DEP_ARTIFACT) {
- String url = _ivy.substitute(attributes.getValue("url"));
+ if (state == DEP_ARTIFACT) {
+ String url = ivy.substitute(attributes.getValue("url"));
Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[] {
"name", "type", "ext", "url", "conf"});
- _confAware = new DefaultDependencyArtifactDescriptor(name, type, ext,
+ confAware = new DefaultDependencyArtifactDescriptor(name, type, ext,
url == null ? null : new URL(url), extraAtt);
- } else if (_state == ARTIFACT_INCLUDE) {
+ } else if (state == ARTIFACT_INCLUDE) {
PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
- String org = _ivy.substitute(attributes.getValue("org"));
+ String org = ivy.substitute(attributes.getValue("org"));
org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
- String module = _ivy.substitute(attributes.getValue("module"));
+ String module = ivy.substitute(attributes.getValue("module"));
module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[] {
"org", "module", "name", "type", "ext", "matcher", "conf"});
- _confAware = new DefaultIncludeRule(aid, matcher, extraAtt);
+ confAware = new DefaultIncludeRule(aid, matcher, extraAtt);
} else { // _state == ARTIFACT_EXCLUDE || EXCLUDE
PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
- String org = _ivy.substitute(attributes.getValue("org"));
+ String org = ivy.substitute(attributes.getValue("org"));
org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
- String module = _ivy.substitute(attributes.getValue("module"));
+ String module = ivy.substitute(attributes.getValue("module"));
module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
Map extraAtt = ExtendableItemHelper.getExtraAttributes(attributes, new String[] {
"org", "module", "name", "type", "ext", "matcher", "conf"});
- _confAware = new DefaultExcludeRule(aid, matcher, extraAtt);
+ confAware = new DefaultExcludeRule(aid, matcher, extraAtt);
}
- String confs = _ivy.substitute(attributes.getValue("conf"));
+ String confs = ivy.substitute(attributes.getValue("conf"));
// only add confs if they are specified. if they aren't, endElement will handle this
// only if there are no conf defined in sub elements
if (confs != null && confs.length() > 0) {
@@ -614,8 +654,8 @@
}
private void addConfiguration(String c) {
- _confAware.addConfiguration(c);
- if (_state == EXCLUDE) {
+ confAware.addConfiguration(c);
+ if (state == EXCLUDE) {
// we are adding a configuration to a module wide exclude rule
// we have nothing special to do here, the rule has already been added to the module
// descriptor
@@ -625,19 +665,19 @@
// of a dependency. This means that we have to add this element to the corresponding
// conf
// of the current dependency descriptor
- if (_confAware instanceof DependencyArtifactDescriptor) {
- _dd.addDependencyArtifact(c, (DependencyArtifactDescriptor) _confAware);
- } else if (_confAware instanceof IncludeRule) {
- _dd.addIncludeRule(c, (IncludeRule) _confAware);
- } else if (_confAware instanceof ExcludeRule) {
- _dd.addExcludeRule(c, (ExcludeRule) _confAware);
+ if (confAware instanceof DependencyArtifactDescriptor) {
+ dd.addDependencyArtifact(c, (DependencyArtifactDescriptor) confAware);
+ } else if (confAware instanceof IncludeRule) {
+ dd.addIncludeRule(c, (IncludeRule) confAware);
+ } else if (confAware instanceof ExcludeRule) {
+ dd.addExcludeRule(c, (ExcludeRule) confAware);
}
}
}
private PatternMatcher getPatternMatcher(String m) {
- String matcherName = _ivy.substitute(m);
- PatternMatcher matcher = matcherName == null ? _defaultMatcher : _ivy
+ String matcherName = ivy.substitute(m);
+ PatternMatcher matcher = matcherName == null ? defaultMatcher : ivy
.getMatcher(matcherName);
if (matcher == null) {
throw new IllegalArgumentException("unknown matcher " + matcherName);
@@ -646,42 +686,42 @@
}
public void endElement(String uri, String localName, String qName) throws SAXException {
- if (_state == PUB && "artifact".equals(qName)
- && _artifact.getConfigurations().length == 0) {
+ if (state == PUB && "artifact".equals(qName)
+ && artifact.getConfigurations().length == 0) {
String[] confs = md.getConfigurationsNames();
for (int i = 0; i < confs.length; i++) {
- _artifact.addConfiguration(confs[i]);
- md.addArtifact(confs[i], _artifact);
+ artifact.addConfiguration(confs[i]);
+ md.addArtifact(confs[i], artifact);
}
} else if ("configurations".equals(qName)) {
checkConfigurations();
- } else if ((_state == DEP_ARTIFACT && "artifact".equals(qName))
- || (_state == ARTIFACT_INCLUDE && "include".equals(qName))
- || (_state == ARTIFACT_EXCLUDE && "exclude".equals(qName))) {
- _state = DEP;
- if (_confAware.getConfigurations().length == 0) {
+ } else if ((state == DEP_ARTIFACT && "artifact".equals(qName))
+ || (state == ARTIFACT_INCLUDE && "include".equals(qName))
+ || (state == ARTIFACT_EXCLUDE && "exclude".equals(qName))) {
+ state = DEP;
+ if (confAware.getConfigurations().length == 0) {
String[] confs = md.getConfigurationsNames();
for (int i = 0; i < confs.length; i++) {
addConfiguration(confs[i]);
}
}
- _confAware = null;
- } else if (_state == EXCLUDE) {
- if (_confAware.getConfigurations().length == 0) {
+ confAware = null;
+ } else if (state == EXCLUDE) {
+ if (confAware.getConfigurations().length == 0) {
String[] confs = md.getConfigurationsNames();
for (int i = 0; i < confs.length; i++) {
addConfiguration(confs[i]);
}
}
- _confAware = null;
- _state = DEPS;
+ confAware = null;
+ state = DEPS;
} else if ("dependency".equals(qName)) {
- if (_dd.getModuleConfigurations().length == 0) {
- parseDepsConfs(getDefaultConf(), _dd);
+ if (dd.getModuleConfigurations().length == 0) {
+ parseDepsConfs(getDefaultConf(), dd);
}
- _state = DEPS;
+ state = DEPS;
} else if ("dependencies".equals(qName)) {
- _state = NONE;
+ state = NONE;
}
}
Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java?view=diff&rev=560593&r1=560592&r2=560593
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java Sat Jul 28 12:11:58 2007
@@ -61,10 +61,16 @@
* Used to update ivy files. Uses ivy file as source and not ModuleDescriptor to preserve as much as
* possible the original syntax
*/
-public class XmlModuleDescriptorUpdater {
+public final class XmlModuleDescriptorUpdater {
private static final int MAX_HEADER_LENGTH = 10000;
+ //CheckStyle:StaticVariableName| OFF
+ //LINE_SEPARATOR is actually a constant, but we have to modify it for the tests
public static String LINE_SEPARATOR = System.getProperty("line.separator");
-
+ //CheckStyle:StaticVariableName| ON
+
+ private XmlModuleDescriptorUpdater() {
+ }
+
/**
* used to copy a module descriptor xml file (also known as ivy file) and update the revisions
* of its dependencies, its status and revision
@@ -211,266 +217,55 @@
// never print *ln* cause \n is found in copied characters stream
// nor do we need do handle indentation, original one is maintained except for attributes
- private String _organisation = null;
+ private String organisation = null;
- private String _defaultConfMapping = null; // defaultConfMapping of imported
+ private String defaultConfMapping = null; // defaultConfMapping of imported
// configurations, if any
- private Boolean _confMappingOverride = null; // confMappingOverride of imported
+ private Boolean confMappingOverride = null; // confMappingOverride of imported
// configurations, if any
- private String _justOpen = null; // used to know if the last open tag was empty, to
+ private String justOpen = null; // used to know if the last open tag was empty, to
// adjust termination with /> instead of ></qName>
- private Stack _context = new Stack();
+ private Stack context = new Stack();
- private Stack _buffers = new Stack();
+ private Stack buffers = new Stack();
- private Stack _confAttributeBuffers = new Stack();
+ private Stack confAttributeBuffers = new Stack();
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
inHeader = false;
- if (_justOpen != null) {
+ if (justOpen != null) {
write(">");
}
- _context.push(qName);
+ context.push(qName);
if ("info".equals(qName)) {
- _organisation = substitute(settings, attributes.getValue("organisation"));
- String module = substitute(settings, attributes.getValue("module"));
- String rev = revision;
- if (rev == null) {
- rev = substitute(settings, attributes.getValue("revision"));
- }
- ModuleRevisionId localMid = ModuleRevisionId.newInstance(_organisation, module, null,
- rev, ExtendableItemHelper.getExtraAttributes(attributes,
- new String[] {"organisation", "module", "revision", "status", "publication", "namespace"}));
- ModuleRevisionId systemMid = ns == null ? localMid : ns.getToSystemTransformer()
- .transform(localMid);
-
- write("<info organisation=\"" + systemMid.getOrganisation() + "\" module=\""
- + systemMid.getName() + "\"");
- if (systemMid.getRevision() != null) {
- write(" revision=\"" + systemMid.getRevision() + "\"");
- }
- if (status != null) {
- write(" status=\"" + status + "\"");
- } else {
- write(" status=\"" + substitute(settings, attributes.getValue("status")) + "\"");
- }
- if (pubdate != null) {
- write(" publication=\"" + Ivy.DATE_FORMAT.format(pubdate) + "\"");
- } else if (attributes.getValue("publication") != null) {
- write(" publication=\""
- + substitute(settings, attributes.getValue("publication")) + "\"");
- }
- Collection stdAtts = Arrays.asList(new String[] {"organisation", "module",
- "revision", "status", "publication", "namespace"});
- if (attributes.getValue("namespace") != null) {
- write(" namespace=\"" + substitute(settings, attributes.getValue("namespace"))
- + "\"");
- }
- for (int i = 0; i < attributes.getLength(); i++) {
- if (!stdAtts.contains(attributes.getQName(i))) {
- write(" " + attributes.getQName(i) + "=\""
- + substitute(settings, attributes.getValue(i)) + "\"");
- }
- }
+ infoStarted(attributes);
} else if (replaceInclude && "include".equals(qName)
- && _context.contains("configurations")) {
+ && context.contains("configurations")) {
//TODO, in the case of !replaceInclude, we should still replace the relative path
//by an absolute path.
- final ExtendedBuffer buffer = new ExtendedBuffer(getContext());
- _buffers.push(buffer);
- try {
- URL url;
- if (settings != null) {
- url = settings.getRelativeUrlResolver().getURL(relativePathCtx,
- settings.substitute(attributes.getValue("file")),
- settings.substitute(attributes.getValue("url")));
- } else {
- //TODO : settings can be null, but I don't why.
- //Check if the next code is correct in that case
- String fileName = attributes.getValue("file");
- if (fileName == null) {
- String urlStr = attributes.getValue("url");
- url = new URL(urlStr);
- } else {
- url = new File(fileName).toURL();
- }
- }
- XMLHelper.parse(url, null, new DefaultHandler() {
- boolean _insideConfigurations = false;
-
- boolean _doIndent = false;
-
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- if ("configurations".equals(qName)) {
- _insideConfigurations = true;
- String defaultconf = substitute(settings, attributes
- .getValue("defaultconfmapping"));
- if (defaultconf != null) {
- _defaultConfMapping = defaultconf;
- }
- String mappingOverride = substitute(settings, attributes
- .getValue("confmappingoverride"));
- if (mappingOverride != null) {
- _confMappingOverride = Boolean.valueOf(mappingOverride);
- }
- } else if ("conf".equals(qName) && _insideConfigurations) {
- String confName = substitute(settings, attributes.getValue("name"));
- if (!confs.contains(confName)) {
- buffer.setPrint(true);
- if (_doIndent) {
- write("/>\n\t\t");
- }
- String extend = substitute(settings, attributes.getValue("extends"));
- if (extend != null) {
- for (StringTokenizer tok = new StringTokenizer(extend, ", "); tok
- .hasMoreTokens();) {
- String current = tok.nextToken();
- if (confs.contains(current)) {
- throw new IllegalArgumentException(
- "Cannot exclude a configuration which is extended.");
- }
- }
-
- }
-
- write("<" + qName);
- for (int i = 0; i < attributes.getLength(); i++) {
- write(" " + attributes.getQName(i) + "=\""
- + substitute(settings, attributes.getValue(i))
- + "\"");
- }
- _doIndent = true;
- }
- }
- }
-
- public void endElement(String uri, String localName, String name)
- throws SAXException {
- if ("configurations".equals(name)) {
- _insideConfigurations = false;
- }
- }
- });
- } catch (Exception e) {
- Message.warn("exception occured while importing configurations: "
- + e.getMessage());
- throw new SAXException(e);
- }
+ includeStarted(attributes);
} else if ("ivy-module/dependencies/dependency".equals(getContext())) {
- ExtendedBuffer buffer = new ExtendedBuffer(getContext());
- _buffers.push(buffer);
- _confAttributeBuffers.push(buffer);
- buffer.setDefaultPrint(attributes.getValue("conf") == null);
- write("<dependency");
- String org = substitute(settings, attributes.getValue("org"));
- org = org == null ? _organisation : org;
- String module = substitute(settings, attributes.getValue("name"));
- String branch = substitute(settings, attributes.getValue("branch"));
- String revision = substitute(settings, attributes.getValue("rev"));
- ModuleRevisionId localMid = ModuleRevisionId.newInstance(org, module, branch,
- revision, ExtendableItemHelper.getExtraAttributes(attributes,
- XmlModuleDescriptorParser.DEPENDENCY_REGULAR_ATTRIBUTES));
- ModuleRevisionId systemMid = ns == null ? localMid : ns.getToSystemTransformer()
- .transform(localMid);
-
- for (int i = 0; i < attributes.getLength(); i++) {
- String attName = attributes.getQName(i);
- if ("rev".equals(attName)) {
- String rev = (String) resolvedRevisions.get(systemMid);
- if (rev != null) {
- write(" rev=\"" + rev + "\"");
- } else {
- write(" rev=\"" + systemMid.getRevision() + "\"");
- }
- } else if ("org".equals(attName)) {
- write(" org=\"" + systemMid.getOrganisation() + "\"");
- } else if ("name".equals(attName)) {
- write(" name=\"" + systemMid.getName() + "\"");
- } else if ("branch".equals(attName)) {
- write(" branch=\"" + systemMid.getBranch() + "\"");
- } else if ("conf".equals(attName)) {
- String oldMapping = substitute(settings, attributes.getValue("conf"));
- if (oldMapping.length() > 0) {
- String newMapping = removeConfigurationsFromMapping(oldMapping, confs);
- if (newMapping.length() > 0) {
- write(" conf=\"" + newMapping + "\"");
- ((ExtendedBuffer) _buffers.peek()).setPrint(true);
- }
- }
- } else {
- write(" " + attName + "=\""
- + substitute(settings, attributes.getValue(attName)) + "\"");
- }
- }
+ startElementInDependency(attributes);
} else if ("dependencies".equals(qName)) {
- // copy
- write("<" + qName);
- for (int i = 0; i < attributes.getLength(); i++) {
- String attName = attributes.getQName(i);
- if ("defaultconfmapping".equals(attName)) {
- String newMapping = removeConfigurationsFromMapping(substitute(settings,
- attributes.getValue("defaultconfmapping")), confs);
- if (newMapping.length() > 0) {
- write(" " + attributes.getQName(i) + "=\"" + newMapping + "\"");
- }
- } else {
- write(" " + attributes.getQName(i) + "=\""
- + substitute(settings, attributes.getValue(i)) + "\"");
- }
- }
- // add default conf mapping if needed
- if (_defaultConfMapping != null
- && attributes.getValue("defaultconfmapping") == null) {
- String newMapping = removeConfigurationsFromMapping(_defaultConfMapping, confs);
- if (newMapping.length() > 0) {
- write(" defaultconfmapping=\"" + newMapping + "\"");
- }
- }
- // add confmappingoverride if needed
- if (_confMappingOverride != null
- && attributes.getValue("confmappingoverride") == null) {
- write(" confmappingoverride=\"" + _confMappingOverride.toString() + "\"");
- }
+ startDependencies(attributes);
} else if ("ivy-module/configurations/conf".equals(getContext())) {
- _buffers.push(new ExtendedBuffer(getContext()));
- String confName = substitute(settings, attributes.getValue("name"));
- if (!confs.contains(confName)) {
- ((ExtendedBuffer) _buffers.peek()).setPrint(true);
- String extend = substitute(settings, attributes.getValue("extends"));
- if (extend != null) {
- for (StringTokenizer tok = new StringTokenizer(extend, ", "); tok
- .hasMoreTokens();) {
- String current = tok.nextToken();
- if (confs.contains(current)) {
- throw new IllegalArgumentException(
- "Cannot exclude a configuration which is extended.");
- }
- }
- }
-
- write("<" + qName);
- for (int i = 0; i < attributes.getLength(); i++) {
- write(" " + attributes.getQName(i) + "=\""
- + substitute(settings, attributes.getValue(i)) + "\"");
- }
- }
+ startElementInConfigurationsConf(qName, attributes);
} else if ("ivy-module/publications/artifact/conf".equals(getContext())
|| "ivy-module/dependencies/dependency/conf".equals(getContext())
|| "ivy-module/dependencies/dependency/artifact/conf".equals(getContext())) {
- _buffers.push(new ExtendedBuffer(getContext()));
- ((ExtendedBuffer) _confAttributeBuffers.peek()).setDefaultPrint(false);
+ buffers.push(new ExtendedBuffer(getContext()));
+ ((ExtendedBuffer) confAttributeBuffers.peek()).setDefaultPrint(false);
String confName = substitute(settings, attributes.getValue("name"));
if (!confs.contains(confName)) {
- ((ExtendedBuffer) _confAttributeBuffers.peek()).setPrint(true);
- ((ExtendedBuffer) _buffers.peek()).setPrint(true);
+ ((ExtendedBuffer) confAttributeBuffers.peek()).setPrint(true);
+ ((ExtendedBuffer) buffers.peek()).setPrint(true);
write("<" + qName);
for (int i = 0; i < attributes.getLength(); i++) {
write(" " + attributes.getQName(i) + "=\""
@@ -480,8 +275,8 @@
} else if ("ivy-module/publications/artifact".equals(getContext())
|| "ivy-module/dependencies/dependency/artifact".equals(getContext())) {
ExtendedBuffer buffer = new ExtendedBuffer(getContext());
- _buffers.push(buffer);
- _confAttributeBuffers.push(buffer);
+ buffers.push(buffer);
+ confAttributeBuffers.push(buffer);
write("<" + qName);
buffer.setDefaultPrint(attributes.getValue("conf") == null);
for (int i = 0; i < attributes.getLength(); i++) {
@@ -491,7 +286,7 @@
String newConf = removeConfigurationsFromList(confName, confs);
if (newConf.length() > 0) {
write(" " + attributes.getQName(i) + "=\"" + newConf + "\"");
- ((ExtendedBuffer) _buffers.peek()).setPrint(true);
+ ((ExtendedBuffer) buffers.peek()).setPrint(true);
}
} else {
write(" " + attributes.getQName(i) + "=\""
@@ -506,22 +301,255 @@
+ substitute(settings, attributes.getValue(i)) + "\"");
}
}
- _justOpen = qName;
+ justOpen = qName;
// indent.append("\t");
}
+ private void startElementInConfigurationsConf(String qName, Attributes attributes) {
+ buffers.push(new ExtendedBuffer(getContext()));
+ String confName = substitute(settings, attributes.getValue("name"));
+ if (!confs.contains(confName)) {
+ ((ExtendedBuffer) buffers.peek()).setPrint(true);
+ String extend = substitute(settings, attributes.getValue("extends"));
+ if (extend != null) {
+ for (StringTokenizer tok = new StringTokenizer(extend, ", "); tok
+ .hasMoreTokens();) {
+ String current = tok.nextToken();
+ if (confs.contains(current)) {
+ throw new IllegalArgumentException(
+ "Cannot exclude a configuration which is extended.");
+ }
+ }
+ }
+
+ write("<" + qName);
+ for (int i = 0; i < attributes.getLength(); i++) {
+ write(" " + attributes.getQName(i) + "=\""
+ + substitute(settings, attributes.getValue(i)) + "\"");
+ }
+ }
+ }
+
+ private void startDependencies(Attributes attributes) {
+ // copy
+ write("<dependencies");
+ for (int i = 0; i < attributes.getLength(); i++) {
+ String attName = attributes.getQName(i);
+ if ("defaultconfmapping".equals(attName)) {
+ String newMapping = removeConfigurationsFromMapping(substitute(settings,
+ attributes.getValue("defaultconfmapping")), confs);
+ if (newMapping.length() > 0) {
+ write(" " + attributes.getQName(i) + "=\"" + newMapping + "\"");
+ }
+ } else {
+ write(" " + attributes.getQName(i) + "=\""
+ + substitute(settings, attributes.getValue(i)) + "\"");
+ }
+ }
+ // add default conf mapping if needed
+ if (defaultConfMapping != null
+ && attributes.getValue("defaultconfmapping") == null) {
+ String newMapping = removeConfigurationsFromMapping(defaultConfMapping, confs);
+ if (newMapping.length() > 0) {
+ write(" defaultconfmapping=\"" + newMapping + "\"");
+ }
+ }
+ // add confmappingoverride if needed
+ if (confMappingOverride != null
+ && attributes.getValue("confmappingoverride") == null) {
+ write(" confmappingoverride=\"" + confMappingOverride.toString() + "\"");
+ }
+ }
+
+ private void startElementInDependency(Attributes attributes) {
+ ExtendedBuffer buffer = new ExtendedBuffer(getContext());
+ buffers.push(buffer);
+ confAttributeBuffers.push(buffer);
+ buffer.setDefaultPrint(attributes.getValue("conf") == null);
+ write("<dependency");
+ String org = substitute(settings, attributes.getValue("org"));
+ org = org == null ? organisation : org;
+ String module = substitute(settings, attributes.getValue("name"));
+ String branch = substitute(settings, attributes.getValue("branch"));
+ String revision = substitute(settings, attributes.getValue("rev"));
+ ModuleRevisionId localMid = ModuleRevisionId.newInstance(org, module, branch,
+ revision, ExtendableItemHelper.getExtraAttributes(attributes,
+ XmlModuleDescriptorParser.DEPENDENCY_REGULAR_ATTRIBUTES));
+ ModuleRevisionId systemMid = ns == null ? localMid : ns.getToSystemTransformer()
+ .transform(localMid);
+
+ for (int i = 0; i < attributes.getLength(); i++) {
+ String attName = attributes.getQName(i);
+ if ("rev".equals(attName)) {
+ String rev = (String) resolvedRevisions.get(systemMid);
+ if (rev != null) {
+ write(" rev=\"" + rev + "\"");
+ } else {
+ write(" rev=\"" + systemMid.getRevision() + "\"");
+ }
+ } else if ("org".equals(attName)) {
+ write(" org=\"" + systemMid.getOrganisation() + "\"");
+ } else if ("name".equals(attName)) {
+ write(" name=\"" + systemMid.getName() + "\"");
+ } else if ("branch".equals(attName)) {
+ write(" branch=\"" + systemMid.getBranch() + "\"");
+ } else if ("conf".equals(attName)) {
+ String oldMapping = substitute(settings, attributes.getValue("conf"));
+ if (oldMapping.length() > 0) {
+ String newMapping = removeConfigurationsFromMapping(oldMapping, confs);
+ if (newMapping.length() > 0) {
+ write(" conf=\"" + newMapping + "\"");
+ ((ExtendedBuffer) buffers.peek()).setPrint(true);
+ }
+ }
+ } else {
+ write(" " + attName + "=\""
+ + substitute(settings, attributes.getValue(attName)) + "\"");
+ }
+ }
+ }
+
+ private void includeStarted(Attributes attributes) throws SAXException {
+ final ExtendedBuffer buffer = new ExtendedBuffer(getContext());
+ buffers.push(buffer);
+ try {
+ URL url;
+ if (settings != null) {
+ url = settings.getRelativeUrlResolver().getURL(relativePathCtx,
+ settings.substitute(attributes.getValue("file")),
+ settings.substitute(attributes.getValue("url")));
+ } else {
+ //TODO : settings can be null, but I don't why.
+ //Check if the next code is correct in that case
+ String fileName = attributes.getValue("file");
+ if (fileName == null) {
+ String urlStr = attributes.getValue("url");
+ url = new URL(urlStr);
+ } else {
+ url = new File(fileName).toURL();
+ }
+ }
+ XMLHelper.parse(url, null, new DefaultHandler() {
+ private boolean insideConfigurations = false;
+
+ private boolean doIndent = false;
+
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+ if ("configurations".equals(qName)) {
+ insideConfigurations = true;
+ String defaultconf = substitute(settings, attributes
+ .getValue("defaultconfmapping"));
+ if (defaultconf != null) {
+ defaultConfMapping = defaultconf;
+ }
+ String mappingOverride = substitute(settings, attributes
+ .getValue("confmappingoverride"));
+ if (mappingOverride != null) {
+ confMappingOverride = Boolean.valueOf(mappingOverride);
+ }
+ } else if ("conf".equals(qName) && insideConfigurations) {
+ String confName = substitute(settings, attributes.getValue("name"));
+ if (!confs.contains(confName)) {
+ buffer.setPrint(true);
+ if (doIndent) {
+ write("/>\n\t\t");
+ }
+ String extend = substitute(settings,
+ attributes.getValue("extends"));
+ if (extend != null) {
+ for (StringTokenizer tok = new StringTokenizer(extend, ", ");
+ tok.hasMoreTokens();) {
+ String current = tok.nextToken();
+ if (confs.contains(current)) {
+ throw new IllegalArgumentException("Cannot exclude a "
+ + "configuration which is extended.");
+ }
+ }
+
+ }
+
+ write("<" + qName);
+ for (int i = 0; i < attributes.getLength(); i++) {
+ write(" " + attributes.getQName(i) + "=\""
+ + substitute(settings, attributes.getValue(i))
+ + "\"");
+ }
+ doIndent = true;
+ }
+ }
+ }
+
+ public void endElement(String uri, String localName, String name)
+ throws SAXException {
+ if ("configurations".equals(name)) {
+ insideConfigurations = false;
+ }
+ }
+ });
+ } catch (Exception e) {
+ Message.warn("exception occured while importing configurations: "
+ + e.getMessage());
+ throw new SAXException(e);
+ }
+ }
+
+ private void infoStarted(Attributes attributes) {
+ organisation = substitute(settings, attributes.getValue("organisation"));
+ String module = substitute(settings, attributes.getValue("module"));
+ String rev = revision;
+ if (rev == null) {
+ rev = substitute(settings, attributes.getValue("revision"));
+ }
+ ModuleRevisionId localMid = ModuleRevisionId.newInstance(organisation, module, null,
+ rev, ExtendableItemHelper.getExtraAttributes(attributes,
+ new String[] {"organisation", "module", "revision", "status", "publication",
+ "namespace"}));
+ ModuleRevisionId systemMid = ns == null ? localMid : ns.getToSystemTransformer()
+ .transform(localMid);
+
+ write("<info organisation=\"" + systemMid.getOrganisation() + "\" module=\""
+ + systemMid.getName() + "\"");
+ if (systemMid.getRevision() != null) {
+ write(" revision=\"" + systemMid.getRevision() + "\"");
+ }
+ if (status != null) {
+ write(" status=\"" + status + "\"");
+ } else {
+ write(" status=\"" + substitute(settings, attributes.getValue("status")) + "\"");
+ }
+ if (pubdate != null) {
+ write(" publication=\"" + Ivy.DATE_FORMAT.format(pubdate) + "\"");
+ } else if (attributes.getValue("publication") != null) {
+ write(" publication=\""
+ + substitute(settings, attributes.getValue("publication")) + "\"");
+ }
+ Collection stdAtts = Arrays.asList(new String[] {"organisation", "module",
+ "revision", "status", "publication", "namespace"});
+ if (attributes.getValue("namespace") != null) {
+ write(" namespace=\"" + substitute(settings, attributes.getValue("namespace"))
+ + "\"");
+ }
+ for (int i = 0; i < attributes.getLength(); i++) {
+ if (!stdAtts.contains(attributes.getQName(i))) {
+ write(" " + attributes.getQName(i) + "=\""
+ + substitute(settings, attributes.getValue(i)) + "\"");
+ }
+ }
+ }
+
private void write(String content) {
- if (_buffers.isEmpty()) {
+ if (buffers.isEmpty()) {
out.print(content);
} else {
- ExtendedBuffer buffer = (ExtendedBuffer) _buffers.peek();
+ ExtendedBuffer buffer = (ExtendedBuffer) buffers.peek();
buffer.getBuffer().append(content);
}
}
private String getContext() {
StringBuffer buf = new StringBuffer();
- for (Iterator iter = _context.iterator(); iter.hasNext();) {
+ for (Iterator iter = context.iterator(); iter.hasNext();) {
String ctx = (String) iter.next();
buf.append(ctx).append("/");
}
@@ -586,39 +614,39 @@
}
public void characters(char[] ch, int start, int length) throws SAXException {
- if (_justOpen != null) {
+ if (justOpen != null) {
write(">");
- _justOpen = null;
+ justOpen = null;
}
write(String.valueOf(ch, start, length));
}
public void endElement(String uri, String localName, String qName) throws SAXException {
- if (qName.equals(_justOpen)) {
+ if (qName.equals(justOpen)) {
write("/>");
} else {
write("</" + qName + ">");
}
- if (!_buffers.isEmpty()) {
- ExtendedBuffer buffer = (ExtendedBuffer) _buffers.peek();
+ if (!buffers.isEmpty()) {
+ ExtendedBuffer buffer = (ExtendedBuffer) buffers.peek();
if (buffer.getContext().equals(getContext())) {
- _buffers.pop();
+ buffers.pop();
if (buffer.isPrint()) {
write(buffer.getBuffer().toString());
}
}
}
- if (!_confAttributeBuffers.isEmpty()) {
- ExtendedBuffer buffer = (ExtendedBuffer) _confAttributeBuffers.peek();
+ if (!confAttributeBuffers.isEmpty()) {
+ ExtendedBuffer buffer = (ExtendedBuffer) confAttributeBuffers.peek();
if (buffer.getContext().equals(getContext())) {
- _confAttributeBuffers.pop();
+ confAttributeBuffers.pop();
}
}
- _justOpen = null;
- _context.pop();
+ justOpen = null;
+ context.pop();
}
public void endDocument() throws SAXException {
@@ -724,39 +752,39 @@
}
private static class ExtendedBuffer {
- private String _context = null;
+ private String context = null;
- private Boolean _print = null;
+ private Boolean print = null;
- private boolean _defaultPrint = false;
+ private boolean defaultPrint = false;
- private StringBuffer _buffer = new StringBuffer();
+ private StringBuffer buffer = new StringBuffer();
ExtendedBuffer(String context) {
- this._context = context;
+ this.context = context;
}
boolean isPrint() {
- if (_print == null) {
- return _defaultPrint;
+ if (print == null) {
+ return defaultPrint;
}
- return _print.booleanValue();
+ return print.booleanValue();
}
void setPrint(boolean print) {
- this._print = Boolean.valueOf(print);
+ this.print = Boolean.valueOf(print);
}
void setDefaultPrint(boolean print) {
- this._defaultPrint = print;
+ this.defaultPrint = print;
}
StringBuffer getBuffer() {
- return _buffer;
+ return buffer;
}
String getContext() {
- return _context;
+ return context;
}
}
}