From 12aeeec70feae05a87a5adfe7b9c2c63744be37f Mon Sep 17 00:00:00 2001 From: Gintas Grigelionis Date: Fri, 8 Dec 2017 07:52:37 +0100 Subject: [PATCH] tidy up the code --- .../org/apache/ivy/ant/AntMessageLogger.java | 2 +- src/java/org/apache/ivy/ant/IvyConfigure.java | 2 +- .../org/apache/ivy/core/IvyPatternHelper.java | 7 ----- .../cache/DefaultRepositoryCacheManager.java | 4 +-- .../DefaultDependencyDescriptor.java | 2 +- .../OverrideDependencyDescriptorMediator.java | 4 +-- .../org/apache/ivy/core/resolve/IvyNode.java | 4 +-- .../settings/IvyVariableContainerImpl.java | 4 +-- .../ivy/osgi/core/ManifestHeaderValue.java | 1 - .../latest/LatestRevisionStrategy.java | 4 ++- .../ivy/plugins/matcher/MapMatcher.java | 2 +- .../parser/m2/PomModuleDescriptorBuilder.java | 9 +++--- .../parser/m2/PomModuleDescriptorWriter.java | 2 +- .../ivy/plugins/parser/m2/PomReader.java | 22 +++++++++----- .../parser/xml/XmlModuleDescriptorParser.java | 10 +++---- .../xml/XmlModuleDescriptorUpdater.java | 30 ++++++++++--------- .../ivy/plugins/repository/TransferEvent.java | 3 -- .../ivy/plugins/repository/ssh/Scp.java | 14 ++++----- .../repository/vsftp/VsftpRepository.java | 11 ++++--- .../AbstractPatternsBasedResolver.java | 6 ++-- .../plugins/resolver/util/ResolverHelper.java | 4 +-- .../OpenPGPSignatureGenerator.java | 5 ++-- .../MavenTimedSnapshotVersionMatcher.java | 4 +-- .../ivy/util/url/AbstractURLHandler.java | 8 ++--- .../apache/ivy/util/url/ApacheURLLister.java | 2 +- .../module/descriptor/IvyMakePomTest.java | 6 ++-- .../ivy/osgi/core/ManifestHeaderTest.java | 2 +- .../conflict/LatestConflictManagerTest.java | 6 ++-- .../util/url/HttpclientURLHandlerTest.java | 1 - 29 files changed, 89 insertions(+), 92 deletions(-) diff --git a/src/java/org/apache/ivy/ant/AntMessageLogger.java b/src/java/org/apache/ivy/ant/AntMessageLogger.java index 2d21f1149..d84df46f8 100644 --- a/src/java/org/apache/ivy/ant/AntMessageLogger.java +++ b/src/java/org/apache/ivy/ant/AntMessageLogger.java @@ -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... diff --git a/src/java/org/apache/ivy/ant/IvyConfigure.java b/src/java/org/apache/ivy/ant/IvyConfigure.java index 3be9a1036..455fd1f03 100644 --- a/src/java/org/apache/ivy/ant/IvyConfigure.java +++ b/src/java/org/apache/ivy/ant/IvyConfigure.java @@ -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 diff --git a/src/java/org/apache/ivy/core/IvyPatternHelper.java b/src/java/org/apache/ivy/core/IvyPatternHelper.java index 92478463a..ef9a16395 100644 --- a/src/java/org/apache/ivy/core/IvyPatternHelper.java +++ b/src/java/org/apache/ivy/core/IvyPatternHelper.java @@ -262,7 +262,6 @@ private static String substituteTokens(String pattern, Map token tokenSeen = false; tokenHadValue = false; break; - case ')': if (!insideOptionalPart || insideToken) { throw new IllegalArgumentException( @@ -275,10 +274,8 @@ private static String substituteTokens(String pattern, Map 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 " @@ -288,7 +285,6 @@ private static String substituteTokens(String pattern, Map token tokenBuffer = new StringBuffer(); insideToken = true; break; - case ']': if (!insideToken) { throw new IllegalArgumentException("invalid end of token at position " + i @@ -298,7 +294,6 @@ private static String substituteTokens(String pattern, Map 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); @@ -308,11 +303,9 @@ private static String substituteTokens(String pattern, Map token } buffer.append(value); } - insideToken = false; tokenSeen = true; break; - default: if (insideToken) { tokenBuffer.append(ch); diff --git a/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java b/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java index 8eda88e80..b85e9a8a3 100644 --- a/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java +++ b/src/java/org/apache/ivy/core/cache/DefaultRepositoryCacheManager.java @@ -1564,7 +1564,7 @@ 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(); @@ -1572,7 +1572,7 @@ public void restore() throws IOException { } public void cleanUp() { - if ((backup != null) && backup.exists()) { + if (backup != null && backup.exists()) { backup.delete(); } } diff --git a/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptor.java b/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptor.java index 66774ad0a..645cbd751 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptor.java +++ b/src/java/org/apache/ivy/core/module/descriptor/DefaultDependencyDescriptor.java @@ -538,7 +538,7 @@ private Set mergeAll(Map> 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)); diff --git a/src/java/org/apache/ivy/core/module/descriptor/OverrideDependencyDescriptorMediator.java b/src/java/org/apache/ivy/core/module/descriptor/OverrideDependencyDescriptorMediator.java index bebdf14a8..a5fbaf84d 100644 --- a/src/java/org/apache/ivy/core/module/descriptor/OverrideDependencyDescriptorMediator.java +++ b/src/java/org/apache/ivy/core/module/descriptor/OverrideDependencyDescriptorMediator.java @@ -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()) diff --git a/src/java/org/apache/ivy/core/resolve/IvyNode.java b/src/java/org/apache/ivy/core/resolve/IvyNode.java index 50f1b0949..82110213d 100644 --- a/src/java/org/apache/ivy/core/resolve/IvyNode.java +++ b/src/java/org/apache/ivy/core/resolve/IvyNode.java @@ -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]; @@ -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))); diff --git a/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java b/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java index 3ba7b8779..096580147 100644 --- a/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java +++ b/src/java/org/apache/ivy/core/settings/IvyVariableContainerImpl.java @@ -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; @@ -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); diff --git a/src/java/org/apache/ivy/osgi/core/ManifestHeaderValue.java b/src/java/org/apache/ivy/osgi/core/ManifestHeaderValue.java index 3819bafe1..3b6eaa1e7 100644 --- a/src/java/org/apache/ivy/osgi/core/ManifestHeaderValue.java +++ b/src/java/org/apache/ivy/osgi/core/ManifestHeaderValue.java @@ -264,7 +264,6 @@ private void parseParameterValue() throws ParseException { switch (readNext()) { case '\0': break; - case ',': case ';': endParameterValue(); diff --git a/src/java/org/apache/ivy/plugins/latest/LatestRevisionStrategy.java b/src/java/org/apache/ivy/plugins/latest/LatestRevisionStrategy.java index 8398868e8..2790ce510 100644 --- a/src/java/org/apache/ivy/plugins/latest/LatestRevisionStrategy.java +++ b/src/java/org/apache/ivy/plugins/latest/LatestRevisionStrategy.java @@ -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) { diff --git a/src/java/org/apache/ivy/plugins/matcher/MapMatcher.java b/src/java/org/apache/ivy/plugins/matcher/MapMatcher.java index cd14a3f48..618ed4623 100644 --- a/src/java/org/apache/ivy/plugins/matcher/MapMatcher.java +++ b/src/java/org/apache/ivy/plugins/matcher/MapMatcher.java @@ -43,7 +43,7 @@ public boolean matches(Map m) { for (Map.Entry 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; } } diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java index de73b24a8..4f1d427b7 100644 --- a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java +++ b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java @@ -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"); @@ -305,8 +305,7 @@ public void addDependency(Resource res, PomDependencyData dep) { ConfMapper mapping = MAVEN2_CONF_MAPPING.get(scope); mapping.addMappingConfs(dd, dep.isOptional()); Map 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(); @@ -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; } @@ -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; diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java index 9fc759c07..e53bda7fa 100644 --- a/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java +++ b/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java @@ -349,7 +349,7 @@ private static DependencyDescriptor[] getDependencies(ModuleDescriptor md, List 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); } } diff --git a/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java b/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java index a82d3feba..4166224cb 100644 --- a/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java +++ b/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java @@ -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")); } @@ -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; } @@ -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); } } @@ -408,7 +414,7 @@ public List 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)); } } @@ -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; diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java index e81ecbde4..9be9ff08d 100644 --- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java +++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java @@ -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) { @@ -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); @@ -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()) { diff --git a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java index f52c132e5..a5ab5931b 100644 --- a/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java +++ b/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorUpdater.java @@ -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(); @@ -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; @@ -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) { @@ -576,7 +578,7 @@ 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); @@ -584,6 +586,12 @@ private void startElementInDependency(Attributes attributes) { 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) { @@ -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 + "\""); diff --git a/src/java/org/apache/ivy/plugins/repository/TransferEvent.java b/src/java/org/apache/ivy/plugins/repository/TransferEvent.java index 64517e7f6..210b20321 100644 --- a/src/java/org/apache/ivy/plugins/repository/TransferEvent.java +++ b/src/java/org/apache/ivy/plugins/repository/TransferEvent.java @@ -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); } diff --git a/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java b/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java index cd278fe12..65d7c0906 100644 --- a/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java +++ b/src/java/org/apache/ivy/plugins/repository/ssh/Scp.java @@ -141,7 +141,7 @@ private void readResponse(InputStream is) throws IOException, RemoteScpException throw new RemoteScpException("Remote scp terminated unexpectedly."); } - if ((c != 1) && (c != 2)) { + if (c != 1 && c != 2) { throw new RemoteScpException("Remote scp sent illegal error code."); } @@ -188,7 +188,7 @@ private void parseCLine(String line, FileInfo fileInfo) throws RemoteScpExceptio "Malformed C line sent by remote SCP binary, line too short."); } - if ((line.charAt(CLINE_SPACE_INDEX1) != ' ') || (line.charAt(CLINE_SPACE_INDEX2) == ' ')) { + if (line.charAt(CLINE_SPACE_INDEX1) != ' ' || line.charAt(CLINE_SPACE_INDEX2) == ' ') { throw new RemoteScpException("Malformed C line sent by remote SCP binary."); } @@ -201,11 +201,11 @@ private void parseCLine(String line, FileInfo fileInfo) throws RemoteScpExceptio String lengthSubstring = line.substring(CLINE_SPACE_INDEX2, lengthNameSep); String nameSubstring = line.substring(lengthNameSep + 1); - if ((lengthSubstring.length() <= 0) || (nameSubstring.length() <= 0)) { + if (lengthSubstring.length() <= 0 || nameSubstring.length() <= 0) { throw new RemoteScpException("Malformed C line sent by remote SCP binary."); } - if ((CLINE_SPACE_INDEX2 + 1 + lengthSubstring.length() + nameSubstring.length()) != line + if (CLINE_SPACE_INDEX2 + 1 + lengthSubstring.length() + nameSubstring.length() != line .length()) { throw new RemoteScpException("Malformed C line sent by remote SCP binary."); } @@ -387,7 +387,7 @@ private FileInfo receiveStream(Channel channel, String file, OutputStream target os.flush(); continue; } - if ((c == 1) || (c == 2)) { + if (c == 1 || c == 2) { throw new RemoteScpException("Remote SCP error: " + line); } @@ -472,7 +472,7 @@ public void put(String localFile, String remoteTargetDir, String remoteTargetNam throws IOException, RemoteScpException { ChannelExec channel = null; - if ((localFile == null) || (remoteTargetName == null)) { + if (localFile == null || remoteTargetName == null) { throw new IllegalArgumentException("Null argument."); } @@ -544,7 +544,7 @@ public void get(String remoteFile, OutputStream localTarget) throws IOException, RemoteScpException { ChannelExec channel = null; - if ((remoteFile == null) || (localTarget == null)) { + if (remoteFile == null || localTarget == null) { throw new IllegalArgumentException("Null argument."); } diff --git a/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java b/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java index d2802edb8..ca771f190 100644 --- a/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java +++ b/src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java @@ -121,7 +121,6 @@ public class VsftpRepository extends AbstractRepository { private Ivy ivy = null; public VsftpRepository() { - } public VsftpRepository(final TimeoutConstraint timeoutConstraint) { @@ -161,9 +160,9 @@ public void get(final String source, File destination) throws IOException { } int index = source.lastIndexOf('/'); - String srcName = index == -1 ? source : source.substring(index + 1); - final File to = destDir == null ? Checks.checkAbsolute(srcName, "source") : new File( - destDir, srcName); + String srcName = (index == -1) ? source : source.substring(index + 1); + final File to = (destDir == null) ? Checks.checkAbsolute(srcName, "source") + : new File(destDir, srcName); final IOException[] ex = new IOException[1]; Thread get = new IvyThread() { @@ -516,8 +515,8 @@ public void run() { sleep(sleep); sleep = reuseConnection - (System.currentTimeMillis() - lastCommand); - if (inCommand) { - sleep = sleep <= 0 ? reuseConnection : sleep; + if (inCommand && sleep <= 0) { + sleep = reuseConnection; } } } catch (InterruptedException e) { diff --git a/src/java/org/apache/ivy/plugins/resolver/AbstractPatternsBasedResolver.java b/src/java/org/apache/ivy/plugins/resolver/AbstractPatternsBasedResolver.java index 0f0d1f111..141be65d8 100644 --- a/src/java/org/apache/ivy/plugins/resolver/AbstractPatternsBasedResolver.java +++ b/src/java/org/apache/ivy/plugins/resolver/AbstractPatternsBasedResolver.java @@ -93,7 +93,7 @@ protected ResolvedResource findResourceUsingPatterns(ModuleRevisionId moduleRevi for (String pattern : patternList) { ResolvedResource rres = findResourceUsingPattern(moduleRevision, pattern, artifact, rmdparser, date); - if ((rres != null) && !foundRevisions.contains(rres.getRevision())) { + if (rres != null && !foundRevisions.contains(rres.getRevision())) { // only add the first found ResolvedResource for each revision foundRevisions.add(rres.getRevision()); resolvedResources.add(rres); @@ -212,7 +212,7 @@ private Set> resolveTokenValues(String[] tokens, String patt String partiallyResolvedPattern = IvyPatternHelper.substituteTokens(pattern, tokenValues); String token = IvyPatternHelper.getFirstToken(partiallyResolvedPattern); - if ((token == null) && exist(partiallyResolvedPattern)) { + if (token == null && exist(partiallyResolvedPattern)) { // no more tokens to resolve result.add(tokenValues); return result; @@ -235,7 +235,7 @@ private Set> resolveTokenValues(String[] tokens, String patt filterNames(valueList); for (String value : valueList) { - if ((matcher != null) && !matcher.matches(value)) { + if (matcher != null && !matcher.matches(value)) { continue; } diff --git a/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java b/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java index bcee92514..6bd891e0c 100644 --- a/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java +++ b/src/java/org/apache/ivy/plugins/resolver/util/ResolverHelper.java @@ -48,7 +48,7 @@ public static String[] listTokenValues(Repository rep, String pattern, String to + ": token not found in pattern"); return null; } - if (((pattern.length() <= index + tokenString.length()) || fileSep.equals(pattern + if ((pattern.length() <= index + tokenString.length() || fileSep.equals(pattern .substring(index + tokenString.length(), index + tokenString.length() + 1))) && (index == 0 || fileSep.equals(pattern.substring(index - 1, index)))) { // the searched token is a whole name @@ -247,7 +247,7 @@ public static String[] listTokenValues(URLLister lister, String pattern, String + ": token not found in pattern"); return null; } - if (((pattern.length() <= index + tokenString.length()) || "/".equals(pattern + if ((pattern.length() <= index + tokenString.length() || "/".equals(pattern .substring(index + tokenString.length(), index + tokenString.length() + 1))) && (index == 0 || "/".equals(pattern.substring(index - 1, index)))) { // the searched token is a whole name diff --git a/src/java/org/apache/ivy/plugins/signer/bouncycastle/OpenPGPSignatureGenerator.java b/src/java/org/apache/ivy/plugins/signer/bouncycastle/OpenPGPSignatureGenerator.java index d800d0e79..9b97d6e4e 100644 --- a/src/java/org/apache/ivy/plugins/signer/bouncycastle/OpenPGPSignatureGenerator.java +++ b/src/java/org/apache/ivy/plugins/signer/bouncycastle/OpenPGPSignatureGenerator.java @@ -156,11 +156,10 @@ private PGPSecretKey readSecretKey(InputStream in) throws IOException, PGPExcept Iterator it2 = kRing.getSecretKeys(); while (key == null && it2.hasNext()) { PGPSecretKey k = it2.next(); - if ((keyId == null) && k.isSigningKey()) { + if (keyId == null && k.isSigningKey()) { key = k; } - if ((keyId != null) - && (Long.valueOf(keyId, 16) == (k.getKeyID() & MASK))) { + if (keyId != null && Long.valueOf(keyId, 16) == (k.getKeyID() & MASK)) { key = k; } } diff --git a/src/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcher.java b/src/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcher.java index bb8e1e99d..489805862 100644 --- a/src/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcher.java +++ b/src/java/org/apache/ivy/plugins/version/MavenTimedSnapshotVersionMatcher.java @@ -137,9 +137,9 @@ public boolean isTimestampedSnapshot() { /** * Returns the "base" revision that this {@link MavenSnapshotRevision} represents. For - * example, for the regular snapshot revision {@link 1.2.3-SNAPSHOT}, the base revision + * example, for the regular snapshot revision {@code 1.2.3-SNAPSHOT}, the base revision * is {@code 1.2.3}. Similarly for timestamped snapshot version - * {@code 1.0.2-20100925.223013-19}, the base revision is {@link 1.0.2} + * {@code 1.0.2-20100925.223013-19}, the base revision is {@code 1.0.2} * * @return String */ diff --git a/src/java/org/apache/ivy/util/url/AbstractURLHandler.java b/src/java/org/apache/ivy/util/url/AbstractURLHandler.java index 3eaa35d99..84a8fea78 100644 --- a/src/java/org/apache/ivy/util/url/AbstractURLHandler.java +++ b/src/java/org/apache/ivy/util/url/AbstractURLHandler.java @@ -159,10 +159,6 @@ protected InputStream getDecodingInputStream(String encoding, InputStream 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 @@ -190,6 +186,10 @@ protected InputStream getDecodingInputStream(String encoding, InputStream in) inflater.end(); } break; + case "gzip": + case "x-gzip": + result = new GZIPInputStream(in); + break; default: result = in; break; diff --git a/src/java/org/apache/ivy/util/url/ApacheURLLister.java b/src/java/org/apache/ivy/util/url/ApacheURLLister.java index 1e4b02244..fed36bb4a 100644 --- a/src/java/org/apache/ivy/util/url/ApacheURLLister.java +++ b/src/java/org/apache/ivy/util/url/ApacheURLLister.java @@ -133,7 +133,7 @@ public List retrieveListing(URL url, boolean includeFiles, boolean includeD String href = matcher.group(1); String text = matcher.group(2); - if ((href == null) || (text == null)) { + if (href == null || text == null) { // the groups were not found (shouldn't happen, really) continue; } diff --git a/test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java b/test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java index fdb869e8a..2374fd785 100644 --- a/test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java +++ b/test/java/org/apache/ivy/core/module/descriptor/IvyMakePomTest.java @@ -168,12 +168,14 @@ static PomDependency parse(final Node dependencyNode) { optional = nextChild.getTextContent(); break; default: - throw new RuntimeException("Unexpected child element " + nextChild.getNodeName() + " under dependency element"); + throw new RuntimeException("Unexpected child element " + + nextChild.getNodeName() + " under dependency element"); } // move to next sibling nextChild = nextChild.getNextSibling(); } - return new PomDependency(groupId, artifactId, version, scope, classifier, optional != null && Boolean.parseBoolean(optional)); + return new PomDependency(groupId, artifactId, version, scope, classifier, + optional != null && Boolean.parseBoolean(optional)); } private static Node skipIfTextNode(final Node node) { diff --git a/test/java/org/apache/ivy/osgi/core/ManifestHeaderTest.java b/test/java/org/apache/ivy/osgi/core/ManifestHeaderTest.java index 3bcc8256b..6464662aa 100644 --- a/test/java/org/apache/ivy/osgi/core/ManifestHeaderTest.java +++ b/test/java/org/apache/ivy/osgi/core/ManifestHeaderTest.java @@ -101,7 +101,7 @@ public static class IllegalOptionTests { @Rule public ExpectedException expExc = ExpectedException.none(); - @Parameterized.Parameters(name = "illegal token at {1} in {0}") + @Parameterized.Parameters(name = "Illegal token at {1} in {0}") public static Collection data() { return Arrays.asList(new Object[][] {{"value1=", 6}, {"value1;version=1;value2", 22}, {"value1;version=", 14}, diff --git a/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java b/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java index 98ab93c82..c74a9a5a3 100644 --- a/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java +++ b/test/java/org/apache/ivy/plugins/conflict/LatestConflictManagerTest.java @@ -199,9 +199,6 @@ public void testLatestTimeTransitivity() throws Exception { 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()); @@ -209,6 +206,9 @@ public void testLatestTimeTransitivity() throws Exception { case "C": assertEquals("C revision should be 1.0.2", "1.0.2", mrid.getRevision()); break; + case "D": + assertEquals("D revision should be 1.0.0", "1.0.0", mrid.getRevision()); + break; } } } diff --git a/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java b/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java index cc406ddfe..b048c68dd 100644 --- a/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java +++ b/test/java/org/apache/ivy/util/url/HttpclientURLHandlerTest.java @@ -42,7 +42,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; /** * Test {@link HttpClientHandler}