Skip to content

Commit

Permalink
tidy up the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Gintas Grigelionis committed Dec 8, 2017
1 parent 1b84f2e commit 12aeeec
Show file tree
Hide file tree
Showing 29 changed files with 89 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/java/org/apache/ivy/ant/AntMessageLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void register(ProjectComponent task, final Ivy ivy) {
&& ((AntMessageLogger) current).task instanceof Task) {
Task currentTask = (Task) ((AntMessageLogger) current).task;

if ((currentTask.getTaskName() != null)
if (currentTask.getTaskName() != null
&& currentTask.getTaskName().equals(((Task) task).getTaskName())) {
// The current AntMessageLogger already logs with the same
// prefix as the given task. So we shouldn't do anything...
Expand Down
2 changes: 1 addition & 1 deletion src/java/org/apache/ivy/ant/IvyConfigure.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void execute() throws BuildException {
String settingsId = settings.getId();
Object otherRef = getProject().getReference(settingsId);

if ((otherRef != null) && OVERRIDE_NOT_ALLOWED.equals(override)) {
if (otherRef != null && OVERRIDE_NOT_ALLOWED.equals(override)) {
throw new BuildException(
"Overriding a previous definition of ivy:settings with the id '" + settingsId
+ "' is not allowed when using override='" + OVERRIDE_NOT_ALLOWED
Expand Down
7 changes: 0 additions & 7 deletions src/java/org/apache/ivy/core/IvyPatternHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ private static String substituteTokens(String pattern, Map<String, Object> token
tokenSeen = false;
tokenHadValue = false;
break;

case ')':
if (!insideOptionalPart || insideToken) {
throw new IllegalArgumentException(
Expand All @@ -275,10 +274,8 @@ private static String substituteTokens(String pattern, Map<String, Object> token
} else if (!tokenSeen) {
buffer.append('(').append(optionalPart.toString()).append(')');
}

insideOptionalPart = false;
break;

case '[':
if (insideToken) {
throw new IllegalArgumentException("invalid start of token at position "
Expand All @@ -288,7 +285,6 @@ private static String substituteTokens(String pattern, Map<String, Object> token
tokenBuffer = new StringBuffer();
insideToken = true;
break;

case ']':
if (!insideToken) {
throw new IllegalArgumentException("invalid end of token at position " + i
Expand All @@ -298,7 +294,6 @@ private static String substituteTokens(String pattern, Map<String, Object> token
String token = tokenBuffer.toString();
Object tokenValue = tokensCopy.get(token);
String value = (tokenValue == null) ? null : tokenValue.toString();

if (insideOptionalPart) {
tokenHadValue = !isNullOrEmpty(value);
optionalPart.append(value);
Expand All @@ -308,11 +303,9 @@ private static String substituteTokens(String pattern, Map<String, Object> token
}
buffer.append(value);
}

insideToken = false;
tokenSeen = true;
break;

default:
if (insideToken) {
tokenBuffer.append(ch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1564,15 +1564,15 @@ public void download(Artifact artifact, Resource resource, File dest) throws IOE
}

public void restore() throws IOException {
if ((backup != null) && backup.exists()) {
if (backup != null && backup.exists()) {
File original = new File(originalPath);
FileUtil.copy(backup, original, null, true);
backup.delete();
}
}

public void cleanUp() {
if ((backup != null) && backup.exists()) {
if (backup != null && backup.exists()) {
backup.delete();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ private <T> Set<T> mergeAll(Map<String, Collection<T>> artifactsMap) {
}

public void addDependencyConfiguration(String masterConf, String depConf) {
if ((md != null) && !"*".equals(masterConf) && !"%".equals(masterConf)) {
if (md != null && !"*".equals(masterConf) && !"%".equals(masterConf)) {
Configuration config;
if (masterConf.startsWith("!")) {
config = md.getConfiguration(masterConf.substring(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public DependencyDescriptor mediate(DependencyDescriptor dd) {
return dd;
}

String version = this.version == null ? mrid.getRevision() : this.version;
String branch = this.branch == null ? mrid.getBranch() : this.branch;
String version = (this.version == null) ? mrid.getRevision() : this.version;
String branch = (this.branch == null) ? mrid.getBranch() : this.branch;

// if this is a noop, do not construct any new object
if (version.equals(dd.getDependencyRevisionId().getRevision())
Expand Down
4 changes: 2 additions & 2 deletions src/java/org/apache/ivy/core/resolve/IvyNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ public String[] getRealConfs(String conf) {
}
String defaultConf = getDefaultConf(conf);
conf = getMainConf(conf);
if ((md.getConfiguration(conf) == null)
if (md.getConfiguration(conf) == null
|| PRIVATE.equals(md.getConfiguration(conf).getVisibility())) {
if ("".equals(defaultConf)) {
return new String[0];
Expand Down Expand Up @@ -821,7 +821,7 @@ public Artifact[] getArtifacts(String rootModuleConf) {
}

if ((dependencyArtifacts == null || dependencyArtifacts.isEmpty())
&& (includes.isEmpty())) {
&& includes.isEmpty()) {
// no artifacts / includes: we get all artifacts as defined by the descriptor
for (String conf : confs) {
artifacts.addAll(Arrays.asList(md.getArtifacts(conf)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void setVariable(String varName, String value, boolean overwrite) {
}

public void setEnvironmentPrefix(String prefix) {
if ((prefix != null) && !prefix.endsWith(".")) {
if (prefix != null && !prefix.endsWith(".")) {
this.envPrefix = prefix + ".";
} else {
this.envPrefix = prefix;
Expand All @@ -79,7 +79,7 @@ protected String getEnvironmentPrefix() {
*/
public String getVariable(String name) {
String val = null;
if ((envPrefix != null) && name.startsWith(envPrefix)) {
if (envPrefix != null && name.startsWith(envPrefix)) {
val = System.getenv(name.substring(envPrefix.length()));
} else {
val = variables.get(name);
Expand Down
1 change: 0 additions & 1 deletion src/java/org/apache/ivy/osgi/core/ManifestHeaderValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ private void parseParameterValue() throws ParseException {
switch (readNext()) {
case '\0':
break;

case ',':
case ';':
endParameterValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public int compare(ModuleRevisionId o1, ModuleRevisionId o2) {
Integer sm1 = specialMeanings.get(parts1[i].toLowerCase(Locale.US));
Integer sm2 = specialMeanings.get(parts2[i].toLowerCase(Locale.US));
if (sm1 != null) {
sm2 = sm2 == null ? new Integer(0) : sm2;
if (sm2 == null) {
sm2 = new Integer(0);
}
return sm1.compareTo(sm2);
}
if (sm2 != null) {
Expand Down
2 changes: 1 addition & 1 deletion src/java/org/apache/ivy/plugins/matcher/MapMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public boolean matches(Map<String, String> m) {
for (Map.Entry<String, Matcher> entry : matchers.entrySet()) {
Matcher matcher = entry.getValue();
String value = m.get(entry.getKey());
if ((value == null) || !matcher.matches(value)) {
if (value == null || !matcher.matches(value)) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void setModuleRevId(String groupId, String artifactId, String version) {
mrid = ModuleRevisionId.newInstance(groupId, artifactId, version);
ivyModuleDescriptor.setModuleRevisionId(mrid);

if ((version == null) || version.endsWith("SNAPSHOT")) {
if (version == null || version.endsWith("SNAPSHOT")) {
ivyModuleDescriptor.setStatus("integration");
} else {
ivyModuleDescriptor.setStatus("release");
Expand Down Expand Up @@ -305,8 +305,7 @@ public void addDependency(Resource res, PomDependencyData dep) {
ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
mapping.addMappingConfs(dd, dep.isOptional());
Map<String, String> extraAtt = new HashMap<>();
if ((dep.getClassifier() != null)
|| (dep.getType() != null && !"jar".equals(dep.getType()))) {
if (dep.getClassifier() != null || dep.getType() != null && !"jar".equals(dep.getType())) {
String type = "jar";
if (dep.getType() != null) {
type = dep.getType();
Expand Down Expand Up @@ -373,7 +372,7 @@ public void addDependency(DependencyDescriptor descriptor) {
// https://repo1.maven.org/maven2/com/atomikos/atomikos-util/3.6.4/atomikos-util-3.6.4.pom
ModuleId dependencyId = descriptor.getDependencyId();
ModuleRevisionId mRevId = ivyModuleDescriptor.getModuleRevisionId();
if ((mRevId != null) && mRevId.getModuleId().equals(dependencyId)) {
if (mRevId != null && mRevId.getModuleId().equals(dependencyId)) {
return;
}

Expand Down Expand Up @@ -494,7 +493,7 @@ private String getDefaultScope(PomDependencyData dep) {
String key = getDependencyMgtExtraInfoKeyForScope(dep.getGroupId(), dep.getArtifactId());
result = ivyModuleDescriptor.getExtraInfoContentByTagName(key);
}
if ((result == null) || !MAVEN2_CONF_MAPPING.containsKey(result)) {
if (result == null || !MAVEN2_CONF_MAPPING.containsKey(result)) {
result = "compile";
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private static DependencyDescriptor[] getDependencies(ModuleDescriptor md,
List<DependencyDescriptor> result = new ArrayList<>();
for (DependencyDescriptor dd : md.getDependencies()) {
String[] depConfs = dd.getDependencyConfigurations(confs);
if ((depConfs != null) && (depConfs.length > 0)) {
if (depConfs != null && depConfs.length > 0) {
result.add(dd);
}
}
Expand Down
22 changes: 14 additions & 8 deletions src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public PomReader(final URL descriptorURL, final Resource res) throws IOException
Document pomDomDoc = XMLHelper.parseToDom(source, new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
if ((systemId != null) && systemId.endsWith("m2-entities.ent")) {
if (systemId != null && systemId.endsWith("m2-entities.ent")) {
return new InputSource(
PomReader.class.getResourceAsStream("m2-entities.ent"));
}
Expand Down Expand Up @@ -264,7 +264,7 @@ public License[] getLicenses() {
String name = getFirstChildText(license, LICENSE_NAME);
String url = getFirstChildText(license, LICENSE_URL);

if ((name == null) && (url == null)) {
if (name == null && url == null) {
// move to next license
continue;
}
Expand All @@ -287,11 +287,17 @@ public ModuleRevisionId getRelocation() {
return null;
} else {
String relocGroupId = getFirstChildText(relocation, GROUP_ID);
if (relocGroupId == null) {
relocGroupId = getGroupId();
}
String relocArtId = getFirstChildText(relocation, ARTIFACT_ID);
if (relocArtId == null) {
relocArtId = getArtifactId();
}
String relocVersion = getFirstChildText(relocation, VERSION);
relocGroupId = relocGroupId == null ? getGroupId() : relocGroupId;
relocArtId = relocArtId == null ? getArtifactId() : relocArtId;
relocVersion = relocVersion == null ? getVersion() : relocVersion;
if (relocVersion == null) {
relocVersion = getVersion();
}
return ModuleRevisionId.newInstance(relocGroupId, relocArtId, relocVersion);
}
}
Expand Down Expand Up @@ -408,7 +414,7 @@ public List<ModuleId> getExcludedModules() {
if (node instanceof Element && EXCLUSION.equals(node.getNodeName())) {
String groupId = getFirstChildText((Element) node, GROUP_ID);
String artifactId = getFirstChildText((Element) node, ARTIFACT_ID);
if ((groupId != null) && (artifactId != null)) {
if (groupId != null && artifactId != null) {
exclusions.add(ModuleId.newInstance(groupId, artifactId));
}
}
Expand Down Expand Up @@ -719,8 +725,8 @@ public int read() throws IOException {
public int read(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)
|| ((off + len) < 0)) {
} else if (off < 0 || off > b.length || len < 0 || (off + len) > b.length
|| (off + len) < 0) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ && isOtherNamespace(qName)) {
} else if ("mapped".equals(qName)) {
dd.addDependencyConfiguration(conf,
settings.substitute(attributes.getValue("name")));
} else if (("conflict".equals(qName) && state == State.DEPS)
} else if ("conflict".equals(qName) && state == State.DEPS
|| "manager".equals(qName) && state == State.CONFLICT) {
managerStarted(attributes, state == State.CONFLICT ? "name" : "manager");
} else if ("override".equals(qName) && state == State.DEPS) {
Expand Down Expand Up @@ -922,7 +922,7 @@ protected void dependencyStarted(Attributes attributes) {
ModuleRevisionId revId = ModuleRevisionId.newInstance(org, name, branch, rev,
extraAttributes);
ModuleRevisionId dynamicId = null;
if ((revConstraint == null) && (branchConstraint == null)) {
if (revConstraint == null && branchConstraint == null) {
// no dynamic constraints defined, so dynamicId equals revId
dynamicId = ModuleRevisionId.newInstance(org, name, branch, rev, extraAttributes,
false);
Expand Down Expand Up @@ -1223,9 +1223,9 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
}
} else if ("configurations".equals(qName)) {
checkConfigurations();
} else if ((state == State.DEP_ARTIFACT && "artifact".equals(qName))
|| (state == State.ARTIFACT_INCLUDE && "include".equals(qName))
|| (state == State.ARTIFACT_EXCLUDE && "exclude".equals(qName))) {
} else if (state == State.DEP_ARTIFACT && "artifact".equals(qName)
|| state == State.ARTIFACT_INCLUDE && "include".equals(qName)
|| state == State.ARTIFACT_EXCLUDE && "exclude".equals(qName)) {
state = State.DEP;
if (confAware.getConfigurations().length == 0) {
for (String config : getMd().getConfigurationsNames()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ private void startExtends(Attributes attributes) {
String value = null;

switch (name) {
case "organisation":
value = org;
break;
case "module":
value = module;
break;
case "revision":
// replace inline revision with resolved parent revision
ModuleDescriptor merged = options.getMergedDescriptor();
Expand All @@ -451,12 +457,6 @@ private void startExtends(Attributes attributes) {
value = substitute(settings, attributes.getValue(i));
}
break;
case "organisation":
value = org;
break;
case "module":
value = module;
break;
default:
value = substitute(settings, attributes.getValue(i));
break;
Expand Down Expand Up @@ -554,7 +554,9 @@ private void startElementInDependency(Attributes attributes) {
String module = substitute(settings, attributes.getValue("name"));
String branch = substitute(settings, attributes.getValue("branch"));
String branchConstraint = substitute(settings, attributes.getValue("branchConstraint"));
branchConstraint = branchConstraint == null ? branch : branchConstraint;
if (branchConstraint == null) {
branchConstraint = branch;
}

// look for the branch used in resolved revisions
if (branch == null) {
Expand All @@ -576,14 +578,20 @@ private void startElementInDependency(Attributes attributes) {
XmlModuleDescriptorParser.DEPENDENCY_REGULAR_ATTRIBUTES);
ModuleRevisionId localMrid = ModuleRevisionId.newInstance(org, module, branch,
revision, extraAttributes);
ModuleRevisionId systemMrid = ns == null ? localMrid : ns.getToSystemTransformer()
ModuleRevisionId systemMrid = (ns == null) ? localMrid : ns.getToSystemTransformer()
.transform(localMrid);

String newBranch = resolvedBranches.get(systemMrid);

for (int i = 0; i < attributes.getLength(); i++) {
String attName = attributes.getQName(i);
switch (attName) {
case "org":
write(" org=\"" + systemMrid.getOrganisation() + "\"");
break;
case "name":
write(" name=\"" + systemMrid.getName() + "\"");
break;
case "rev":
String rev = resolvedRevisions.get(systemMrid);
if (rev == null) {
Expand All @@ -603,12 +611,6 @@ private void startElementInDependency(Attributes attributes) {
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 + "\"");
Expand Down
3 changes: 0 additions & 3 deletions src/java/org/apache/ivy/plugins/repository/TransferEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,9 @@ public int getRequestType() {
*/
protected void setRequestType(final int requestType) {
switch (requestType) {

case REQUEST_PUT:
break;
case REQUEST_GET:
break;

default:
throw new IllegalArgumentException("Illegal request type: " + requestType);
}
Expand Down
Loading

0 comments on commit 12aeeec

Please sign in to comment.