Skip to content

Commit 12aeeec

Browse files
author
Gintas Grigelionis
committed
tidy up the code
1 parent 1b84f2e commit 12aeeec

29 files changed

+89
-92
lines changed

src/java/org/apache/ivy/ant/AntMessageLogger.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static void register(ProjectComponent task, final Ivy ivy) {
5151
&& ((AntMessageLogger) current).task instanceof Task) {
5252
Task currentTask = (Task) ((AntMessageLogger) current).task;
5353

54-
if ((currentTask.getTaskName() != null)
54+
if (currentTask.getTaskName() != null
5555
&& currentTask.getTaskName().equals(((Task) task).getTaskName())) {
5656
// The current AntMessageLogger already logs with the same
5757
// prefix as the given task. So we shouldn't do anything...

src/java/org/apache/ivy/ant/IvyConfigure.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void execute() throws BuildException {
139139
String settingsId = settings.getId();
140140
Object otherRef = getProject().getReference(settingsId);
141141

142-
if ((otherRef != null) && OVERRIDE_NOT_ALLOWED.equals(override)) {
142+
if (otherRef != null && OVERRIDE_NOT_ALLOWED.equals(override)) {
143143
throw new BuildException(
144144
"Overriding a previous definition of ivy:settings with the id '" + settingsId
145145
+ "' is not allowed when using override='" + OVERRIDE_NOT_ALLOWED

src/java/org/apache/ivy/core/IvyPatternHelper.java

-7
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ private static String substituteTokens(String pattern, Map<String, Object> token
262262
tokenSeen = false;
263263
tokenHadValue = false;
264264
break;
265-
266265
case ')':
267266
if (!insideOptionalPart || insideToken) {
268267
throw new IllegalArgumentException(
@@ -275,10 +274,8 @@ private static String substituteTokens(String pattern, Map<String, Object> token
275274
} else if (!tokenSeen) {
276275
buffer.append('(').append(optionalPart.toString()).append(')');
277276
}
278-
279277
insideOptionalPart = false;
280278
break;
281-
282279
case '[':
283280
if (insideToken) {
284281
throw new IllegalArgumentException("invalid start of token at position "
@@ -288,7 +285,6 @@ private static String substituteTokens(String pattern, Map<String, Object> token
288285
tokenBuffer = new StringBuffer();
289286
insideToken = true;
290287
break;
291-
292288
case ']':
293289
if (!insideToken) {
294290
throw new IllegalArgumentException("invalid end of token at position " + i
@@ -298,7 +294,6 @@ private static String substituteTokens(String pattern, Map<String, Object> token
298294
String token = tokenBuffer.toString();
299295
Object tokenValue = tokensCopy.get(token);
300296
String value = (tokenValue == null) ? null : tokenValue.toString();
301-
302297
if (insideOptionalPart) {
303298
tokenHadValue = !isNullOrEmpty(value);
304299
optionalPart.append(value);
@@ -308,11 +303,9 @@ private static String substituteTokens(String pattern, Map<String, Object> token
308303
}
309304
buffer.append(value);
310305
}
311-
312306
insideToken = false;
313307
tokenSeen = true;
314308
break;
315-
316309
default:
317310
if (insideToken) {
318311
tokenBuffer.append(ch);

src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1564,15 +1564,15 @@ public void download(Artifact artifact, Resource resource, File dest) throws IOE
15641564
}
15651565

15661566
public void restore() throws IOException {
1567-
if ((backup != null) && backup.exists()) {
1567+
if (backup != null && backup.exists()) {
15681568
File original = new File(originalPath);
15691569
FileUtil.copy(backup, original, null, true);
15701570
backup.delete();
15711571
}
15721572
}
15731573

15741574
public void cleanUp() {
1575-
if ((backup != null) && backup.exists()) {
1575+
if (backup != null && backup.exists()) {
15761576
backup.delete();
15771577
}
15781578
}

src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ private <T> Set<T> mergeAll(Map<String, Collection<T>> artifactsMap) {
538538
}
539539

540540
public void addDependencyConfiguration(String masterConf, String depConf) {
541-
if ((md != null) && !"*".equals(masterConf) && !"%".equals(masterConf)) {
541+
if (md != null && !"*".equals(masterConf) && !"%".equals(masterConf)) {
542542
Configuration config;
543543
if (masterConf.startsWith("!")) {
544544
config = md.getConfiguration(masterConf.substring(1));

src/java/org/apache/ivy/core/module/descriptor/OverrideDependencyDescriptorMediator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public DependencyDescriptor mediate(DependencyDescriptor dd) {
7070
return dd;
7171
}
7272

73-
String version = this.version == null ? mrid.getRevision() : this.version;
74-
String branch = this.branch == null ? mrid.getBranch() : this.branch;
73+
String version = (this.version == null) ? mrid.getRevision() : this.version;
74+
String branch = (this.branch == null) ? mrid.getBranch() : this.branch;
7575

7676
// if this is a noop, do not construct any new object
7777
if (version.equals(dd.getDependencyRevisionId().getRevision())

src/java/org/apache/ivy/core/resolve/IvyNode.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ public String[] getRealConfs(String conf) {
662662
}
663663
String defaultConf = getDefaultConf(conf);
664664
conf = getMainConf(conf);
665-
if ((md.getConfiguration(conf) == null)
665+
if (md.getConfiguration(conf) == null
666666
|| PRIVATE.equals(md.getConfiguration(conf).getVisibility())) {
667667
if ("".equals(defaultConf)) {
668668
return new String[0];
@@ -821,7 +821,7 @@ public Artifact[] getArtifacts(String rootModuleConf) {
821821
}
822822

823823
if ((dependencyArtifacts == null || dependencyArtifacts.isEmpty())
824-
&& (includes.isEmpty())) {
824+
&& includes.isEmpty()) {
825825
// no artifacts / includes: we get all artifacts as defined by the descriptor
826826
for (String conf : confs) {
827827
artifacts.addAll(Arrays.asList(md.getArtifacts(conf)));

src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void setVariable(String varName, String value, boolean overwrite) {
5353
}
5454

5555
public void setEnvironmentPrefix(String prefix) {
56-
if ((prefix != null) && !prefix.endsWith(".")) {
56+
if (prefix != null && !prefix.endsWith(".")) {
5757
this.envPrefix = prefix + ".";
5858
} else {
5959
this.envPrefix = prefix;
@@ -79,7 +79,7 @@ protected String getEnvironmentPrefix() {
7979
*/
8080
public String getVariable(String name) {
8181
String val = null;
82-
if ((envPrefix != null) && name.startsWith(envPrefix)) {
82+
if (envPrefix != null && name.startsWith(envPrefix)) {
8383
val = System.getenv(name.substring(envPrefix.length()));
8484
} else {
8585
val = variables.get(name);

src/java/org/apache/ivy/osgi/core/ManifestHeaderValue.java

-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ private void parseParameterValue() throws ParseException {
264264
switch (readNext()) {
265265
case '\0':
266266
break;
267-
268267
case ',':
269268
case ';':
270269
endParameterValue();

src/java/org/apache/ivy/plugins/latest/LatestRevisionStrategy.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ public int compare(ModuleRevisionId o1, ModuleRevisionId o2) {
6565
Integer sm1 = specialMeanings.get(parts1[i].toLowerCase(Locale.US));
6666
Integer sm2 = specialMeanings.get(parts2[i].toLowerCase(Locale.US));
6767
if (sm1 != null) {
68-
sm2 = sm2 == null ? new Integer(0) : sm2;
68+
if (sm2 == null) {
69+
sm2 = new Integer(0);
70+
}
6971
return sm1.compareTo(sm2);
7072
}
7173
if (sm2 != null) {

src/java/org/apache/ivy/plugins/matcher/MapMatcher.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public boolean matches(Map<String, String> m) {
4343
for (Map.Entry<String, Matcher> entry : matchers.entrySet()) {
4444
Matcher matcher = entry.getValue();
4545
String value = m.get(entry.getKey());
46-
if ((value == null) || !matcher.matches(value)) {
46+
if (value == null || !matcher.matches(value)) {
4747
return false;
4848
}
4949
}

src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void setModuleRevId(String groupId, String artifactId, String version) {
211211
mrid = ModuleRevisionId.newInstance(groupId, artifactId, version);
212212
ivyModuleDescriptor.setModuleRevisionId(mrid);
213213

214-
if ((version == null) || version.endsWith("SNAPSHOT")) {
214+
if (version == null || version.endsWith("SNAPSHOT")) {
215215
ivyModuleDescriptor.setStatus("integration");
216216
} else {
217217
ivyModuleDescriptor.setStatus("release");
@@ -305,8 +305,7 @@ public void addDependency(Resource res, PomDependencyData dep) {
305305
ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope);
306306
mapping.addMappingConfs(dd, dep.isOptional());
307307
Map<String, String> extraAtt = new HashMap<>();
308-
if ((dep.getClassifier() != null)
309-
|| (dep.getType() != null && !"jar".equals(dep.getType()))) {
308+
if (dep.getClassifier() != null || dep.getType() != null && !"jar".equals(dep.getType())) {
310309
String type = "jar";
311310
if (dep.getType() != null) {
312311
type = dep.getType();
@@ -373,7 +372,7 @@ public void addDependency(DependencyDescriptor descriptor) {
373372
// https://repo1.maven.org/maven2/com/atomikos/atomikos-util/3.6.4/atomikos-util-3.6.4.pom
374373
ModuleId dependencyId = descriptor.getDependencyId();
375374
ModuleRevisionId mRevId = ivyModuleDescriptor.getModuleRevisionId();
376-
if ((mRevId != null) && mRevId.getModuleId().equals(dependencyId)) {
375+
if (mRevId != null && mRevId.getModuleId().equals(dependencyId)) {
377376
return;
378377
}
379378

@@ -494,7 +493,7 @@ private String getDefaultScope(PomDependencyData dep) {
494493
String key = getDependencyMgtExtraInfoKeyForScope(dep.getGroupId(), dep.getArtifactId());
495494
result = ivyModuleDescriptor.getExtraInfoContentByTagName(key);
496495
}
497-
if ((result == null) || !MAVEN2_CONF_MAPPING.containsKey(result)) {
496+
if (result == null || !MAVEN2_CONF_MAPPING.containsKey(result)) {
498497
result = "compile";
499498
}
500499
return result;

src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ private static DependencyDescriptor[] getDependencies(ModuleDescriptor md,
349349
List<DependencyDescriptor> result = new ArrayList<>();
350350
for (DependencyDescriptor dd : md.getDependencies()) {
351351
String[] depConfs = dd.getDependencyConfigurations(confs);
352-
if ((depConfs != null) && (depConfs.length > 0)) {
352+
if (depConfs != null && depConfs.length > 0) {
353353
result.add(dd);
354354
}
355355
}

src/java/org/apache/ivy/plugins/parser/m2/PomReader.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public PomReader(final URL descriptorURL, final Resource res) throws IOException
126126
Document pomDomDoc = XMLHelper.parseToDom(source, new EntityResolver() {
127127
public InputSource resolveEntity(String publicId, String systemId)
128128
throws SAXException, IOException {
129-
if ((systemId != null) && systemId.endsWith("m2-entities.ent")) {
129+
if (systemId != null && systemId.endsWith("m2-entities.ent")) {
130130
return new InputSource(
131131
PomReader.class.getResourceAsStream("m2-entities.ent"));
132132
}
@@ -264,7 +264,7 @@ public License[] getLicenses() {
264264
String name = getFirstChildText(license, LICENSE_NAME);
265265
String url = getFirstChildText(license, LICENSE_URL);
266266

267-
if ((name == null) && (url == null)) {
267+
if (name == null && url == null) {
268268
// move to next license
269269
continue;
270270
}
@@ -287,11 +287,17 @@ public ModuleRevisionId getRelocation() {
287287
return null;
288288
} else {
289289
String relocGroupId = getFirstChildText(relocation, GROUP_ID);
290+
if (relocGroupId == null) {
291+
relocGroupId = getGroupId();
292+
}
290293
String relocArtId = getFirstChildText(relocation, ARTIFACT_ID);
294+
if (relocArtId == null) {
295+
relocArtId = getArtifactId();
296+
}
291297
String relocVersion = getFirstChildText(relocation, VERSION);
292-
relocGroupId = relocGroupId == null ? getGroupId() : relocGroupId;
293-
relocArtId = relocArtId == null ? getArtifactId() : relocArtId;
294-
relocVersion = relocVersion == null ? getVersion() : relocVersion;
298+
if (relocVersion == null) {
299+
relocVersion = getVersion();
300+
}
295301
return ModuleRevisionId.newInstance(relocGroupId, relocArtId, relocVersion);
296302
}
297303
}
@@ -408,7 +414,7 @@ public List<ModuleId> getExcludedModules() {
408414
if (node instanceof Element && EXCLUSION.equals(node.getNodeName())) {
409415
String groupId = getFirstChildText((Element) node, GROUP_ID);
410416
String artifactId = getFirstChildText((Element) node, ARTIFACT_ID);
411-
if ((groupId != null) && (artifactId != null)) {
417+
if (groupId != null && artifactId != null) {
412418
exclusions.add(ModuleId.newInstance(groupId, artifactId));
413419
}
414420
}
@@ -719,8 +725,8 @@ public int read() throws IOException {
719725
public int read(byte[] b, int off, int len) throws IOException {
720726
if (b == null) {
721727
throw new NullPointerException();
722-
} else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)
723-
|| ((off + len) < 0)) {
728+
} else if (off < 0 || off > b.length || len < 0 || (off + len) > b.length
729+
|| (off + len) < 0) {
724730
throw new IndexOutOfBoundsException();
725731
} else if (len == 0) {
726732
return 0;

src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ && isOtherNamespace(qName)) {
371371
} else if ("mapped".equals(qName)) {
372372
dd.addDependencyConfiguration(conf,
373373
settings.substitute(attributes.getValue("name")));
374-
} else if (("conflict".equals(qName) && state == State.DEPS)
374+
} else if ("conflict".equals(qName) && state == State.DEPS
375375
|| "manager".equals(qName) && state == State.CONFLICT) {
376376
managerStarted(attributes, state == State.CONFLICT ? "name" : "manager");
377377
} else if ("override".equals(qName) && state == State.DEPS) {
@@ -922,7 +922,7 @@ protected void dependencyStarted(Attributes attributes) {
922922
ModuleRevisionId revId = ModuleRevisionId.newInstance(org, name, branch, rev,
923923
extraAttributes);
924924
ModuleRevisionId dynamicId = null;
925-
if ((revConstraint == null) && (branchConstraint == null)) {
925+
if (revConstraint == null && branchConstraint == null) {
926926
// no dynamic constraints defined, so dynamicId equals revId
927927
dynamicId = ModuleRevisionId.newInstance(org, name, branch, rev, extraAttributes,
928928
false);
@@ -1223,9 +1223,9 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
12231223
}
12241224
} else if ("configurations".equals(qName)) {
12251225
checkConfigurations();
1226-
} else if ((state == State.DEP_ARTIFACT && "artifact".equals(qName))
1227-
|| (state == State.ARTIFACT_INCLUDE && "include".equals(qName))
1228-
|| (state == State.ARTIFACT_EXCLUDE && "exclude".equals(qName))) {
1226+
} else if (state == State.DEP_ARTIFACT && "artifact".equals(qName)
1227+
|| state == State.ARTIFACT_INCLUDE && "include".equals(qName)
1228+
|| state == State.ARTIFACT_EXCLUDE && "exclude".equals(qName)) {
12291229
state = State.DEP;
12301230
if (confAware.getConfigurations().length == 0) {
12311231
for (String config : getMd().getConfigurationsNames()) {

src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ private void startExtends(Attributes attributes) {
433433
String value = null;
434434

435435
switch (name) {
436+
case "organisation":
437+
value = org;
438+
break;
439+
case "module":
440+
value = module;
441+
break;
436442
case "revision":
437443
// replace inline revision with resolved parent revision
438444
ModuleDescriptor merged = options.getMergedDescriptor();
@@ -451,12 +457,6 @@ private void startExtends(Attributes attributes) {
451457
value = substitute(settings, attributes.getValue(i));
452458
}
453459
break;
454-
case "organisation":
455-
value = org;
456-
break;
457-
case "module":
458-
value = module;
459-
break;
460460
default:
461461
value = substitute(settings, attributes.getValue(i));
462462
break;
@@ -554,7 +554,9 @@ private void startElementInDependency(Attributes attributes) {
554554
String module = substitute(settings, attributes.getValue("name"));
555555
String branch = substitute(settings, attributes.getValue("branch"));
556556
String branchConstraint = substitute(settings, attributes.getValue("branchConstraint"));
557-
branchConstraint = branchConstraint == null ? branch : branchConstraint;
557+
if (branchConstraint == null) {
558+
branchConstraint = branch;
559+
}
558560

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

582584
String newBranch = resolvedBranches.get(systemMrid);
583585

584586
for (int i = 0; i < attributes.getLength(); i++) {
585587
String attName = attributes.getQName(i);
586588
switch (attName) {
589+
case "org":
590+
write(" org=\"" + systemMrid.getOrganisation() + "\"");
591+
break;
592+
case "name":
593+
write(" name=\"" + systemMrid.getName() + "\"");
594+
break;
587595
case "rev":
588596
String rev = resolvedRevisions.get(systemMrid);
589597
if (rev == null) {
@@ -603,12 +611,6 @@ private void startElementInDependency(Attributes attributes) {
603611
case "revConstraint":
604612
write(" revConstraint=\"" + revisionConstraint + "\"");
605613
break;
606-
case "org":
607-
write(" org=\"" + systemMrid.getOrganisation() + "\"");
608-
break;
609-
case "name":
610-
write(" name=\"" + systemMrid.getName() + "\"");
611-
break;
612614
case "branch":
613615
if (newBranch != null) {
614616
write(" branch=\"" + newBranch + "\"");

src/java/org/apache/ivy/plugins/repository/TransferEvent.java

-3
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,9 @@ public int getRequestType() {
203203
*/
204204
protected void setRequestType(final int requestType) {
205205
switch (requestType) {
206-
207206
case REQUEST_PUT:
208-
break;
209207
case REQUEST_GET:
210208
break;
211-
212209
default:
213210
throw new IllegalArgumentException("Illegal request type: " + requestType);
214211
}

0 commit comments

Comments
 (0)