use switch rather than a chain of if’s

This commit is contained in:
Gintas Grigelionis 2017-12-05 16:38:51 +01:00
parent 14bdf34a9b
commit da461de2db
10 changed files with 410 additions and 307 deletions

View File

@ -290,21 +290,25 @@ public class IvyBuildList extends IvyTask {
}
private void onMissingDescriptor(File buildFile, File ivyFile, List<File> noDescriptor) {
if (OnMissingDescriptor.SKIP.equals(onMissingDescriptor)) {
Message.debug("skipping " + buildFile + ": descriptor " + ivyFile + " doesn't exist");
} else if (OnMissingDescriptor.FAIL.equals(onMissingDescriptor)) {
throw new BuildException(
"a module has no module descriptor and onMissingDescriptor=fail. "
+ "Build file: " + buildFile + ". Expected descriptor: " + ivyFile);
} else {
if (OnMissingDescriptor.WARN.equals(onMissingDescriptor)) {
switch (onMissingDescriptor) {
case OnMissingDescriptor.FAIL:
throw new BuildException("a module has no module descriptor and"
+ " onMissingDescriptor=fail. Build file: " + buildFile
+ ". Expected descriptor: " + ivyFile);
case OnMissingDescriptor.SKIP:
Message.debug("skipping " + buildFile + ": descriptor " + ivyFile
+ " doesn't exist");
break;
case OnMissingDescriptor.WARN:
Message.warn("a module has no module descriptor. " + "Build file: " + buildFile
+ ". Expected descriptor: " + ivyFile);
}
Message.verbose(String.format("no descriptor for %s: descriptor=%s: adding it at the %s of the path",
buildFile, ivyFile, (OnMissingDescriptor.TAIL.equals(onMissingDescriptor) ? "tail" : "head")));
Message.verbose("\t(change onMissingDescriptor if you want to take another action");
noDescriptor.add(buildFile);
// fall through
default:
Message.verbose(String.format("no descriptor for %s: descriptor=%s: adding it at the %s of the path",
buildFile, ivyFile, (OnMissingDescriptor.TAIL.equals(onMissingDescriptor) ? "tail" : "head")));
Message.verbose("\t(change onMissingDescriptor if you want to take another action");
noDescriptor.add(buildFile);
break;
}
}

View File

@ -38,12 +38,13 @@ public class Configuration extends DefaultExtendableItem implements InheritableI
public static final Visibility PRIVATE = new Visibility("private");
public static Visibility getVisibility(String name) {
if ("private".equals(name)) {
return PRIVATE;
} else if ("public".equals(name)) {
return PUBLIC;
} else {
throw new IllegalArgumentException("unknown visibility " + name);
switch (name) {
case "private":
return PRIVATE;
case "public":
return PUBLIC;
default:
throw new IllegalArgumentException("unknown visibility " + name);
}
}
@ -222,14 +223,19 @@ public class Configuration extends DefaultExtendableItem implements InheritableI
Set<String> newExtends = new LinkedHashSet<>();
for (String extend : extendsFrom) {
if ("*".equals(extend)) {
addOther(configs, null, newExtends);
} else if ("*(public)".equals(extend)) {
addOther(configs, Visibility.PUBLIC, newExtends);
} else if ("*(private)".equals(extend)) {
addOther(configs, Visibility.PRIVATE, newExtends);
} else {
newExtends.add(extend);
switch (extend) {
case "*":
addOther(configs, null, newExtends);
break;
case "*(public)":
addOther(configs, Visibility.PUBLIC, newExtends);
break;
case "*(private)":
addOther(configs, Visibility.PRIVATE, newExtends);
break;
default:
newExtends.add(extend);
break;
}
}

View File

@ -31,17 +31,20 @@ public class CapabilityAdapter {
public static void adapt(BundleInfo bundleInfo, Capability capability) throws ParseException {
String name = capability.getName();
if (BundleInfo.PACKAGE_TYPE.equals(name)) {
ExportPackage exportPackage = getExportPackage(bundleInfo, capability);
bundleInfo.addCapability(exportPackage);
} else if (BundleInfo.BUNDLE_TYPE.equals(name)) {
// nothing to do, already handled at the resource tag level
} else if (BundleInfo.SERVICE_TYPE.equals(name)) {
BundleCapability service = getOSGiService(bundleInfo, capability);
bundleInfo.addCapability(service);
} else {
Message.warn("Unsupported capability '" + name + "' on the bundle '"
+ bundleInfo.getSymbolicName() + "'");
switch (name) {
case BundleInfo.PACKAGE_TYPE:
bundleInfo.addCapability(getExportPackage(bundleInfo, capability));
break;
case BundleInfo.BUNDLE_TYPE:
// nothing to do, already handled at the resource tag level
break;
case BundleInfo.SERVICE_TYPE:
bundleInfo.addCapability(getOSGiService(bundleInfo, capability));
break;
default:
Message.warn("Unsupported capability '" + name + "' on the bundle '"
+ bundleInfo.getSymbolicName() + "'");
break;
}
}
@ -52,16 +55,21 @@ public class CapabilityAdapter {
String uses = null;
for (CapabilityProperty property : capability.getProperties()) {
String propName = property.getName();
if ("package".equals(propName)) {
pkgName = property.getValue();
} else if ("version".equals(propName)) {
version = new Version(property.getValue());
} else if ("uses".equals(propName)) {
uses = property.getValue();
} else {
Message.warn("Unsupported property '" + propName
+ "' on the 'package' capability of the bundle '"
+ bundleInfo.getSymbolicName() + "'");
switch (propName) {
case "package":
pkgName = property.getValue();
break;
case "uses":
uses = property.getValue();
break;
case "version":
version = new Version(property.getValue());
break;
default:
Message.warn("Unsupported property '" + propName
+ "' on the 'package' capability of the bundle '"
+ bundleInfo.getSymbolicName() + "'");
break;
}
}
if (pkgName == null) {
@ -83,14 +91,18 @@ public class CapabilityAdapter {
for (CapabilityProperty property : capability.getProperties()) {
String propName = property.getName();
if ("service".equals(propName)) {
name = property.getValue();
} else if ("version".equals(propName)) {
version = new Version(property.getValue());
} else {
Message.warn("Unsupported property '" + propName
+ "' on the 'package' capability of the bundle '"
+ bundleInfo.getSymbolicName() + "'");
switch (propName) {
case "service":
name = property.getValue();
break;
case "version":
version = new Version(property.getValue());
break;
default:
Message.warn("Unsupported property '" + propName
+ "' on the 'package' capability of the bundle '"
+ bundleInfo.getSymbolicName() + "'");
break;
}
}

View File

@ -95,84 +95,98 @@ public class RequirementAdapter {
private void parseCompareFilter(CompareFilter compareFilter, boolean not)
throws UnsupportedFilterException {
String att = compareFilter.getLeftValue();
if (BundleInfo.PACKAGE_TYPE.equals(att) || BundleInfo.BUNDLE_TYPE.equals(att)
|| BundleInfo.EXECUTION_ENVIRONMENT_TYPE.equals(att) || "symbolicname".equals(att)
|| BundleInfo.SERVICE_TYPE.equals(att)) {
if (not) {
throw new UnsupportedFilterException(
"Not filter on requirement comparison is not supported");
}
if (type != null) {
throw new UnsupportedFilterException("Multiple requirement type are not supported");
}
if ("symbolicname".equals(att)) {
type = BundleInfo.BUNDLE_TYPE;
} else {
if ("symbolicname".equals(att)) {
att = BundleInfo.BUNDLE_TYPE;
}
switch (att) {
case BundleInfo.BUNDLE_TYPE:
case BundleInfo.EXECUTION_ENVIRONMENT_TYPE:
case BundleInfo.PACKAGE_TYPE:
case BundleInfo.SERVICE_TYPE:
if (not) {
throw new UnsupportedFilterException(
"Not filter on requirement comparison is not supported");
}
if (compareFilter.getOperator() != Operator.EQUALS) {
throw new UnsupportedFilterException(
"Filtering is only supported with the operator '='");
}
if (type != null) {
throw new UnsupportedFilterException(
"Multiple requirement type are not supported");
}
type = att;
}
if (compareFilter.getOperator() != Operator.EQUALS) {
throw new UnsupportedFilterException(
"Filtering is only supported with the operator '='");
}
name = compareFilter.getRightValue();
} else if ("version".equals(att)) {
String v = compareFilter.getRightValue();
Version version = new Version(v);
Operator operator = compareFilter.getOperator();
if (not) {
if (operator == Operator.EQUALS) {
throw new UnsupportedFilterException(
"Not filter on equals comparison is not supported");
} else if (operator == Operator.GREATER_OR_EQUAL) {
operator = Operator.LOWER_THAN;
} else if (operator == Operator.GREATER_THAN) {
operator = Operator.LOWER_OR_EQUAL;
} else if (operator == Operator.LOWER_OR_EQUAL) {
operator = Operator.GREATER_THAN;
} else if (operator == Operator.LOWER_THAN) {
operator = Operator.GREATER_OR_EQUAL;
name = compareFilter.getRightValue();
break;
case "version":
Version version = new Version(compareFilter.getRightValue());
Operator operator = compareFilter.getOperator();
if (not) {
switch (operator) {
case EQUALS:
throw new UnsupportedFilterException(
"Not filter on equals comparison is not supported");
case GREATER_OR_EQUAL:
operator = Operator.LOWER_THAN;
break;
case GREATER_THAN:
operator = Operator.LOWER_OR_EQUAL;
break;
case LOWER_OR_EQUAL:
operator = Operator.GREATER_THAN;
break;
case LOWER_THAN:
operator = Operator.GREATER_OR_EQUAL;
break;
}
}
}
if (operator == Operator.EQUALS) {
if (startVersion != null || endVersion != null) {
throw new UnsupportedFilterException(
"Multiple version matching is not supported");
switch (operator) {
case EQUALS:
if (startVersion != null || endVersion != null) {
throw new UnsupportedFilterException(
"Multiple version matching is not supported");
}
startVersion = version;
startExclusive = false;
endVersion = version;
endExclusive = false;
break;
case GREATER_OR_EQUAL:
if (startVersion != null) {
throw new UnsupportedFilterException(
"Multiple version matching is not supported");
}
startVersion = version;
startExclusive = false;
break;
case GREATER_THAN:
if (startVersion != null) {
throw new UnsupportedFilterException(
"Multiple version matching is not supported");
}
startVersion = version;
startExclusive = true;
break;
case LOWER_OR_EQUAL:
if (endVersion != null) {
throw new UnsupportedFilterException(
"Multiple version matching is not supported");
}
endVersion = version;
endExclusive = false;
break;
case LOWER_THAN:
if (endVersion != null) {
throw new UnsupportedFilterException(
"Multiple version matching is not supported");
}
endVersion = version;
endExclusive = true;
break;
}
startVersion = version;
startExclusive = false;
endVersion = version;
endExclusive = false;
} else if (operator == Operator.GREATER_OR_EQUAL) {
if (startVersion != null) {
throw new UnsupportedFilterException(
"Multiple version matching is not supported");
}
startVersion = version;
startExclusive = false;
} else if (operator == Operator.GREATER_THAN) {
if (startVersion != null) {
throw new UnsupportedFilterException(
"Multiple version matching is not supported");
}
startVersion = version;
startExclusive = true;
} else if (operator == Operator.LOWER_OR_EQUAL) {
if (endVersion != null) {
throw new UnsupportedFilterException(
"Multiple version matching is not supported");
}
endVersion = version;
endExclusive = false;
} else if (operator == Operator.LOWER_THAN) {
if (endVersion != null) {
throw new UnsupportedFilterException(
"Multiple version matching is not supported");
}
endVersion = version;
endExclusive = true;
}
} else {
throw new UnsupportedFilterException("Unsupported attribute: " + att);
break;
default:
throw new UnsupportedFilterException("Unsupported attribute: " + att);
}
}

View File

@ -745,9 +745,13 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
protected void managerStarted(Attributes attributes, String managerAtt) {
String org = settings.substitute(attributes.getValue("org"));
org = (org == null) ? PatternMatcher.ANY_EXPRESSION : org;
if (org == null) {
org = PatternMatcher.ANY_EXPRESSION;
}
String mod = settings.substitute(attributes.getValue("module"));
mod = (mod == null) ? PatternMatcher.ANY_EXPRESSION : mod;
if (mod == null) {
mod = PatternMatcher.ANY_EXPRESSION;
}
ConflictManager cm;
String name = settings.substitute(attributes.getValue(managerAtt));
String rev = settings.substitute(attributes.getValue("rev"));
@ -764,8 +768,8 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
return;
}
String matcherName = settings.substitute(attributes.getValue("matcher"));
PatternMatcher matcher = matcherName == null ? defaultMatcher : settings
.getMatcher(matcherName);
PatternMatcher matcher = (matcherName == null) ? defaultMatcher
: settings.getMatcher(matcherName);
if (matcher == null) {
addError("unknown matcher: " + matcherName);
return;
@ -775,14 +779,18 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
protected void mediationOverrideStarted(Attributes attributes) {
String org = settings.substitute(attributes.getValue("org"));
org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
if (org == null) {
org = PatternMatcher.ANY_EXPRESSION;
}
String mod = settings.substitute(attributes.getValue("module"));
mod = mod == null ? PatternMatcher.ANY_EXPRESSION : mod;
if (mod == null) {
mod = PatternMatcher.ANY_EXPRESSION;
}
String rev = settings.substitute(attributes.getValue("rev"));
String branch = settings.substitute(attributes.getValue("branch"));
String matcherName = settings.substitute(attributes.getValue("matcher"));
PatternMatcher matcher = matcherName == null ? defaultMatcher : settings
.getMatcher(matcherName);
PatternMatcher matcher = (matcherName == null) ? defaultMatcher
: settings.getMatcher(matcherName);
if (matcher == null) {
addError("unknown matcher: " + matcherName);
return;
@ -805,8 +813,8 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
// the specified file.
Parser parser = new Parser(getModuleDescriptorParser(), settings);
parser.setInput(url);
parser.setMd(new DefaultModuleDescriptor(getModuleDescriptorParser(), new URLResource(
url)));
parser.setMd(new DefaultModuleDescriptor(getModuleDescriptorParser(),
new URLResource(url)));
XMLHelper.parse(url, null, parser);
// add the configurations from this temporary parser to this module descriptor
@ -945,11 +953,17 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
if (state == State.PUB) {
// this is a published artifact
String artName = settings.substitute(attributes.getValue("name"));
artName = artName == null ? getMd().getModuleRevisionId().getName() : artName;
if (artName == null) {
artName = getMd().getModuleRevisionId().getName();
}
String type = settings.substitute(attributes.getValue("type"));
type = type == null ? "jar" : type;
if (type == null) {
type = "jar";
}
String ext = settings.substitute(attributes.getValue("ext"));
ext = ext != null ? ext : type;
if (ext == null) {
ext = type;
}
String url = settings.substitute(attributes.getValue("url"));
artifact = new MDArtifact(getMd(), artName, type, ext, url == null ? null
: new URL(url), ExtendableItemHelper.getExtraAttributes(settings,
@ -1102,35 +1116,52 @@ public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
type = "artifact".equals(tag) ? "jar" : PatternMatcher.ANY_EXPRESSION;
}
String ext = settings.substitute(attributes.getValue("ext"));
ext = ext != null ? ext : type;
if (state == State.DEP_ARTIFACT) {
String url = settings.substitute(attributes.getValue("url"));
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
attributes, Arrays.asList("name", "type", "ext", "url", "conf"));
confAware = new DefaultDependencyArtifactDescriptor(dd, name, type, ext,
url == null ? null : new URL(url), extraAtt);
} else if (state == State.ARTIFACT_INCLUDE) {
PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
String org = settings.substitute(attributes.getValue("org"));
org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
String module = settings.substitute(attributes.getValue("module"));
module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
"conf"));
confAware = new DefaultIncludeRule(aid, matcher, extraAtt);
} else { // _state == ARTIFACT_EXCLUDE || EXCLUDE
PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
String org = settings.substitute(attributes.getValue("org"));
org = org == null ? PatternMatcher.ANY_EXPRESSION : org;
String module = settings.substitute(attributes.getValue("module"));
module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
"conf"));
confAware = new DefaultExcludeRule(aid, matcher, extraAtt);
if (ext == null) {
ext = type;
}
switch (state) {
case State.DEP_ARTIFACT: {
String url = settings.substitute(attributes.getValue("url"));
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
attributes, Arrays.asList("name", "type", "ext", "url", "conf"));
confAware = new DefaultDependencyArtifactDescriptor(dd, name, type, ext,
url == null ? null : new URL(url), extraAtt);
break;
}
case State.ARTIFACT_INCLUDE: {
PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
String org = settings.substitute(attributes.getValue("org"));
if (org == null) {
org = PatternMatcher.ANY_EXPRESSION;
}
String module = settings.substitute(attributes.getValue("module"));
if (module == null) {
module = PatternMatcher.ANY_EXPRESSION;
}
ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
"conf"));
confAware = new DefaultIncludeRule(aid, matcher, extraAtt);
break;
}
default: { // _state == ARTIFACT_EXCLUDE || EXCLUDE
PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
String org = settings.substitute(attributes.getValue("org"));
if (org == null) {
org = PatternMatcher.ANY_EXPRESSION;
}
String module = settings.substitute(attributes.getValue("module"));
if (module == null) {
module = PatternMatcher.ANY_EXPRESSION;
}
ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
"conf"));
confAware = new DefaultExcludeRule(aid, matcher, extraAtt);
break;
}
}
String confs = settings.substitute(attributes.getValue("conf"));
// only add confs if they are specified. if they aren't, endElement will handle this

View File

@ -432,29 +432,34 @@ public final class XmlModuleDescriptorUpdater {
String name = attributes.getQName(i);
String value = null;
if ("revision".equals(name)) {
// replace inline revision with resolved parent revision
ModuleDescriptor merged = options.getMergedDescriptor();
if (merged != null) {
for (ExtendsDescriptor parent : merged.getInheritedDescriptors()) {
ModuleRevisionId resolvedId = parent.getResolvedParentRevisionId();
if (parentId.equals(resolvedId.getModuleId())) {
value = resolvedId.getRevision();
if (value != null) {
break;
switch (name) {
case "revision":
// replace inline revision with resolved parent revision
ModuleDescriptor merged = options.getMergedDescriptor();
if (merged != null) {
for (ExtendsDescriptor parent : merged.getInheritedDescriptors()) {
ModuleRevisionId resolvedId = parent.getResolvedParentRevisionId();
if (parentId.equals(resolvedId.getModuleId())) {
value = resolvedId.getRevision();
if (value != null) {
break;
}
}
}
}
}
if (value == null) {
if (value == null) {
value = substitute(settings, attributes.getValue(i));
}
break;
case "organisation":
value = org;
break;
case "module":
value = module;
break;
default:
value = substitute(settings, attributes.getValue(i));
}
} else if ("organisation".equals(name)) {
value = org;
} else if ("module".equals(name)) {
value = module;
} else {
value = substitute(settings, attributes.getValue(i));
break;
}
write(" " + name + "=\"" + value + "\"");
}
@ -578,50 +583,59 @@ public final class XmlModuleDescriptorUpdater {
for (int i = 0; i < attributes.getLength(); i++) {
String attName = attributes.getQName(i);
if ("rev".equals(attName)) {
String rev = resolvedRevisions.get(systemMrid);
if (rev != null) {
write(" rev=\"" + rev + "\"");
if (attributes.getIndex("branchConstraint") == -1
&& branchConstraint != null) {
write(" branchConstraint=\"" + branchConstraint + "\"");
switch (attName) {
case "rev":
String rev = resolvedRevisions.get(systemMrid);
if (rev == null) {
write(" rev=\"" + systemMrid.getRevision() + "\"");
} else {
write(" rev=\"" + rev + "\"");
if (attributes.getIndex("branchConstraint") == -1
&& branchConstraint != null) {
write(" branchConstraint=\"" + branchConstraint + "\"");
}
if (generateRevConstraint && attributes.getIndex("revConstraint") == -1
&& !rev.equals(systemMrid.getRevision())) {
write(" revConstraint=\"" + systemMrid.getRevision() + "\"");
}
}
if (generateRevConstraint && attributes.getIndex("revConstraint") == -1
&& !rev.equals(systemMrid.getRevision())) {
write(" revConstraint=\"" + systemMrid.getRevision() + "\"");
break;
case "revConstraint":
write(" revConstraint=\"" + revisionConstraint + "\"");
break;
case "org":
write(" org=\"" + systemMrid.getOrganisation() + "\"");
break;
case "name":
write(" name=\"" + systemMrid.getName() + "\"");
break;
case "branch":
if (newBranch != null) {
write(" branch=\"" + newBranch + "\"");
} else if (!resolvedBranches.containsKey(systemMrid)) {
write(" branch=\"" + systemMrid.getBranch() + "\"");
} else {
// if resolvedBranches contains the systemMrid, but the new branch is null,
// the branch attribute will be removed altogether
}
} else {
write(" rev=\"" + systemMrid.getRevision() + "\"");
}
} else if ("revConstraint".equals(attName)) {
write(" revConstraint=\"" + revisionConstraint + "\"");
} else if ("org".equals(attName)) {
write(" org=\"" + systemMrid.getOrganisation() + "\"");
} else if ("name".equals(attName)) {
write(" name=\"" + systemMrid.getName() + "\"");
} else if ("branch".equals(attName)) {
if (newBranch != null) {
write(" branch=\"" + newBranch + "\"");
} else if (!resolvedBranches.containsKey(systemMrid)) {
write(" branch=\"" + systemMrid.getBranch() + "\"");
} else {
// if resolvedBranches contains the systemMrid, but the new branch is null,
// the branch attribute will be removed altogether
}
} else if ("branchConstraint".equals(attName)) {
write(" branchConstraint=\"" + branchConstraint + "\"");
} else if ("conf".equals(attName)) {
String oldMapping = substitute(settings, attributes.getValue("conf"));
if (!oldMapping.isEmpty()) {
String newMapping = removeConfigurationsFromMapping(oldMapping);
if (!newMapping.isEmpty()) {
write(" conf=\"" + newMapping + "\"");
buffers.peek().setPrint(true);
break;
case "branchConstraint":
write(" branchConstraint=\"" + branchConstraint + "\"");
break;
case "conf":
String oldMapping = substitute(settings, attributes.getValue("conf"));
if (!oldMapping.isEmpty()) {
String newMapping = removeConfigurationsFromMapping(oldMapping);
if (!newMapping.isEmpty()) {
write(" conf=\"" + newMapping + "\"");
buffers.peek().setPrint(true);
}
}
}
} else {
write(" " + attName + "=\""
+ substitute(settings, attributes.getValue(attName)) + "\"");
break;
default:
write(" " + attName + "=\""
+ substitute(settings, attributes.getValue(attName)) + "\"");
break;
}
}
@ -642,11 +656,7 @@ public final class XmlModuleDescriptorUpdater {
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 {
if (settings == null) {
// TODO : settings can be null, but I don't why.
// Check if the following code is correct in that case
String fileName = attributes.getValue("file");
@ -656,6 +666,10 @@ public final class XmlModuleDescriptorUpdater {
} else {
url = Checks.checkAbsolute(fileName, "settings.include").toURI().toURL();
}
} else {
url = settings.getRelativeUrlResolver().getURL(relativePathCtx,
settings.substitute(attributes.getValue("file")),
settings.substitute(attributes.getValue("url")));
}
XMLHelper.parse(url, null, new DefaultHandler() {
private boolean insideConfigurations = false;
@ -1147,21 +1161,25 @@ public final class XmlModuleDescriptorUpdater {
String path = getContext();
if (options.isMerge()) {
ModuleDescriptor merged = options.getMergedDescriptor();
if ("ivy-module/info".equals(path)) {
// guarantee that inherited description has been written before
// info element closes.
writeInheritedDescription(merged);
} else if ("ivy-module/configurations".equals(path)) {
// write inherited configurations after all child configurations
writeInheritedConfigurations(merged);
} else if ("ivy-module/dependencies".equals(path)) {
// write inherited dependencies after all child dependencies
writeInheritedDependencies(merged);
} else if ("ivy-module".equals(path)) {
// write any remaining inherited data before we close the
// descriptor.
flushAllMergedElements();
switch (path) {
case "ivy-module/info":
// guarantee that inherited description has been written before
// info element closes.
writeInheritedDescription(merged);
break;
case "ivy-module/configurations":
// write inherited configurations after all child configurations
writeInheritedConfigurations(merged);
break;
case "ivy-module/dependencies":
// write inherited dependencies after all child dependencies
writeInheritedDependencies(merged);
break;
case "ivy-module":
// write any remaining inherited data before we close the
// descriptor.
flushAllMergedElements();
break;
}
}

View File

@ -1095,14 +1095,17 @@ public abstract class BasicResolver extends AbstractResolver {
* the descriptor rule to use with this resolver.
*/
public void setDescriptor(String descriptorRule) {
if (DESCRIPTOR_REQUIRED.equals(descriptorRule)) {
allownomd = false;
} else if (DESCRIPTOR_OPTIONAL.equals(descriptorRule)) {
allownomd = true;
} else {
throw new IllegalArgumentException("unknown descriptor rule '" + descriptorRule
+ "'. Allowed rules are: "
+ Arrays.asList(DESCRIPTOR_REQUIRED, DESCRIPTOR_OPTIONAL));
switch (descriptorRule) {
case DESCRIPTOR_REQUIRED:
allownomd = false;
break;
case DESCRIPTOR_OPTIONAL:
allownomd = true;
break;
default:
throw new IllegalArgumentException("unknown descriptor rule '" + descriptorRule
+ "'. Allowed rules are: "
+ Arrays.asList(DESCRIPTOR_REQUIRED, DESCRIPTOR_OPTIONAL));
}
}

View File

@ -211,14 +211,17 @@ public class DualResolver extends AbstractResolver {
* the descriptor rule to use with this resolver.
*/
public void setDescriptor(String descriptorRule) {
if (DESCRIPTOR_REQUIRED.equals(descriptorRule)) {
allownomd = false;
} else if (DESCRIPTOR_OPTIONAL.equals(descriptorRule)) {
allownomd = true;
} else {
throw new IllegalArgumentException("unknown descriptor rule '" + descriptorRule
+ "'. Allowed rules are: "
+ Arrays.asList(DESCRIPTOR_REQUIRED, DESCRIPTOR_OPTIONAL));
switch (descriptorRule) {
case DESCRIPTOR_REQUIRED:
allownomd = false;
break;
case DESCRIPTOR_OPTIONAL:
allownomd = true;
break;
default:
throw new IllegalArgumentException("unknown descriptor rule '" + descriptorRule
+ "'. Allowed rules are: "
+ Arrays.asList(DESCRIPTOR_REQUIRED, DESCRIPTOR_OPTIONAL));
}
}

View File

@ -154,38 +154,45 @@ public abstract class AbstractURLHandler implements URLHandler {
protected InputStream getDecodingInputStream(String encoding, InputStream in)
throws IOException {
if (encoding == null) {
return in;
}
InputStream result = null;
switch (encoding) {
case "gzip":
case "x-gzip":
result = new GZIPInputStream(in);
break;
case "deflate":
// There seems to be 2 variants of the "deflate"-encoding.
// I couldn't find a way to auto-detect which variant was
// used, so as (a not really good) work-around we try do
// decompress the first 100 bytes using the "zlib"-variant.
BufferedInputStream bStream = new BufferedInputStream(in);
bStream.mark(100);
byte[] bytes = new byte[100];
int nbBytes = bStream.read(bytes);
bStream.reset();
if ("gzip".equals(encoding) || "x-gzip".equals(encoding)) {
result = new GZIPInputStream(in);
} else if ("deflate".equals(encoding)) {
// There seems to be 2 variants of the "deflate"-encoding.
// I couldn't find a way to auto-detect which variant was
// used, so as (a not really good) work-around we try do
// decompress the first 100 bytes using the "zlib"-variant.
BufferedInputStream bStream = new BufferedInputStream(in);
bStream.mark(100);
byte[] bytes = new byte[100];
int nbBytes = bStream.read(bytes);
bStream.reset();
Inflater inflater = new Inflater();
inflater.setInput(bytes, 0, nbBytes);
try {
inflater.inflate(new byte[1000]);
Inflater inflater = new Inflater();
inflater.setInput(bytes, 0, nbBytes);
try {
inflater.inflate(new byte[1000]);
// no error decompressing the first 100 bytes, so we
// assume the "zlib"-variant was used.
result = new InflaterInputStream(bStream);
} catch (DataFormatException e) {
// there was an error decompressing the first 100 bytes,
// so we assume the "gzip/raw"-variant was used.
result = new InflaterInputStream(bStream, new Inflater(true));
} finally {
inflater.end();
}
} else {
result = in;
// no error decompressing the first 100 bytes, so we
// assume the "zlib"-variant was used.
result = new InflaterInputStream(bStream);
} catch (DataFormatException e) {
// there was an error decompressing the first 100 bytes,
// so we assume the "gzip/raw"-variant was used.
result = new InflaterInputStream(bStream, new Inflater(true));
} finally {
inflater.end();
}
break;
default:
result = in;
break;
}
return result;

View File

@ -195,15 +195,20 @@ public class LatestConflictManagerTest {
getResolveOptions());
ConfigurationResolveReport defaultReport = report.getConfigurationReport("default");
for (ModuleRevisionId mrid : defaultReport.getModuleRevisionIds()) {
if (mrid.getName().equals("A")) {
assertEquals("A revision should be 1.0.0", "1.0.0", mrid.getRevision());
} else if (mrid.getName().equals("D")) {
assertEquals("D revision should be 1.0.0", "1.0.0", mrid.getRevision());
} else if (mrid.getName().equals("B")) {
// by transitivity
assertEquals("B revision should be 1.0.0", "1.0.0", mrid.getRevision());
} else if (mrid.getName().equals("C")) {
assertEquals("C revision should be 1.0.2", "1.0.2", mrid.getRevision());
switch (mrid.getName()) {
case "A":
assertEquals("A revision should be 1.0.0", "1.0.0", mrid.getRevision());
break;
case "D":
assertEquals("D revision should be 1.0.0", "1.0.0", mrid.getRevision());
break;
case "B":
// by transitivity
assertEquals("B revision should be 1.0.0", "1.0.0", mrid.getRevision());
break;
case "C":
assertEquals("C revision should be 1.0.2", "1.0.2", mrid.getRevision());
break;
}
}
}