Skip to content

Commit

Permalink
Code cleanup/refactoring - checkstyle + not using deprecated methods …
Browse files Browse the repository at this point in the history
…+ fix unchecked casts
  • Loading branch information
twogee authored and jaikiran committed Jul 25, 2017
1 parent 497147e commit d4c3cbc
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 129 deletions.
2 changes: 1 addition & 1 deletion src/java/org/apache/ivy/Ivy.java
Expand Up @@ -543,7 +543,7 @@ public ResolveReport install(ModuleRevisionId mrid, String from, String to,
// RETRIEVE
// ///////////////////////////////////////////////////////////////////////

@SuppressWarnings("deprecation")
@Deprecated
public int retrieve(ModuleRevisionId mrid, String destFilePattern, RetrieveOptions options)
throws IOException {
pushContext();
Expand Down
25 changes: 14 additions & 11 deletions src/java/org/apache/ivy/Ivy14.java
Expand Up @@ -378,10 +378,10 @@ public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFi
boolean makeSymlinks) {
try {
return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()),
destFilePattern,
new RetrieveOptions().setConfs(confs).setDestIvyPattern(destIvyPattern)
new RetrieveOptions().setConfs(confs).setDestArtifactPattern(destFilePattern)
.setDestIvyPattern(destIvyPattern)
.setArtifactFilter(artifactFilter).setSync(sync).setUseOrigin(useOrigin)
.setMakeSymlinks(makeSymlinks));
.setMakeSymlinks(makeSymlinks)).getNbrArtifactsCopied();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -392,9 +392,10 @@ public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFi
boolean useOrigin) {
try {
return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()),
destFilePattern,
new RetrieveOptions().setConfs(confs).setDestIvyPattern(destIvyPattern)
.setArtifactFilter(artifactFilter).setSync(sync).setUseOrigin(useOrigin));
new RetrieveOptions().setConfs(confs).setDestArtifactPattern(destFilePattern)
.setDestIvyPattern(destIvyPattern)
.setArtifactFilter(artifactFilter).setSync(sync)
.setUseOrigin(useOrigin)).getNbrArtifactsCopied();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -404,8 +405,9 @@ public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFi
String destIvyPattern, Filter<Artifact> artifactFilter) {
try {
return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()),
destFilePattern, new RetrieveOptions().setConfs(confs)
.setDestIvyPattern(destIvyPattern).setArtifactFilter(artifactFilter));
new RetrieveOptions().setConfs(confs).setDestArtifactPattern(destFilePattern)
.setDestIvyPattern(destIvyPattern)
.setArtifactFilter(artifactFilter)).getNbrArtifactsCopied();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -415,8 +417,8 @@ public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFi
String destIvyPattern) {
try {
return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()),
destFilePattern,
new RetrieveOptions().setConfs(confs).setDestIvyPattern(destIvyPattern));
new RetrieveOptions().setConfs(confs).setDestArtifactPattern(destFilePattern)
.setDestIvyPattern(destIvyPattern)).getNbrArtifactsCopied();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -425,7 +427,8 @@ public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFi
public int retrieve(ModuleId moduleId, String[] confs, File cache, String destFilePattern) {
try {
return ivy.retrieve(new ModuleRevisionId(moduleId, Ivy.getWorkingRevision()),
destFilePattern, new RetrieveOptions().setConfs(confs));
new RetrieveOptions().setConfs(confs)
.setDestArtifactPattern(destFilePattern)).getNbrArtifactsCopied();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/java/org/apache/ivy/Main.java
Expand Up @@ -324,11 +324,11 @@ static void run(CommandLineParser parser, String[] args) throws Exception {
String ivyPattern = settings.substitute(line.getOptionValue("ivypattern"));
ivy.retrieve(
md.getModuleRevisionId(),
retrievePattern,
new RetrieveOptions()
.setConfs(confs)
.setSync(line.hasOption("sync"))
.setUseOrigin(line.hasOption("useOrigin"))
.setDestArtifactPattern(retrievePattern)
.setDestIvyPattern(ivyPattern)
.setArtifactFilter(
FilterHelper.getArtifactTypeFilter(line.getOptionValues("types")))
Expand Down
40 changes: 21 additions & 19 deletions src/java/org/apache/ivy/ant/IvyCacheFileset.java
Expand Up @@ -32,8 +32,8 @@
import org.apache.tools.ant.types.Resource;

/**
* Creates an ant fileset consisting in all artifacts found during a resolve. Note that this task is
* not compatible with the useOrigin mode.
* Creates an ant fileset consisting in all artifacts found during a resolve. Note that this task
* is not compatible with the useOrigin mode.
*/
public class IvyCacheFileset extends IvyCacheTask {
private String setid;
Expand All @@ -50,8 +50,8 @@ public void setUseOrigin(boolean useOrigin) {
if (useOrigin) {
throw new UnsupportedOperationException(
"the cachefileset task does not support the useOrigin mode, since filesets "
+ "require to have only one root directory. Please use the the cachepath "
+ "task instead");
+ "require to have only one root directory. Please use the the "
+ "cachepath task instead");
}
}

Expand Down Expand Up @@ -89,12 +89,13 @@ public void doExecute() throws BuildException {
}

/**
* Returns a common base directory, determined from the {@link ArtifactDownloadReport#getLocalFile() local files} of the
* passed <code>artifactDownloadReports</code>. If no common base directory can be determined, this method throws a
* {@link BuildException}
* Returns a common base directory, determined from the
* {@link ArtifactDownloadReport#getLocalFile() local files} of the passed
* <code>artifactDownloadReports</code>. If no common base directory can be determined, this
* method throws a {@link BuildException}
*
* @param artifactDownloadReports The artifact download reports for which the common base directory of the artifacts
* has to be determined
* @param artifactDownloadReports The artifact download reports for which the common base
* directory of the artifacts has to be determined
* @return File
*/
File requireCommonBaseDir(final List<ArtifactDownloadReport> artifactDownloadReports) {
Expand All @@ -112,15 +113,15 @@ File requireCommonBaseDir(final List<ArtifactDownloadReport> artifactDownloadRep
base = getBaseDir(base, artifactDownloadReport.getLocalFile());
if (base == null) {
// fail fast - we couldn't determine a common base directory, throw an error
throw new BuildException("Cannot find a common base directory, from resolved artifacts, " +
"for generating a cache fileset");
throw new BuildException("Cannot find a common base directory, from resolved "
+ "artifacts, for generating a cache fileset");
}
}
}
if (base == null) {
// finally, we couldn't determine a common base directory, throw an error
throw new BuildException("Cannot find a common base directory, from resolved artifacts, for generating " +
"a cache fileset");
throw new BuildException("Cannot find a common base directory, from resolved "
+ "artifacts, for generating a cache fileset");
}
return base;
}
Expand Down Expand Up @@ -149,19 +150,20 @@ private String getPath(File base, File file) {
}

/**
* Returns the common base directory between the passed <code>file1</code> and <code>file2</code>.
* Returns the common base directory between the passed <code>file1</code> and
* <code>file2</code>.
* <p>
* The returned base directory will be a parent of both the <code>file1</code> and <code>file2</code> or
* it will be <code>null</code>.
* The returned base directory will be a parent of both the <code>file1</code> and
* <code>file2</code> or it will be <code>null</code>.
* </p>
*
* @param file1
* One of the files, for which the common base directory is being sought, may be null.
* @param file2
* The other file for which the common base directory should be returned, may be null.
* @return the common base directory between a <code>file1</code> and <code>file2</code>. Returns null
* if no common base directory could be determined or if either <code>file1</code> or <code>file2</code>
* is null
* @return the common base directory between a <code>file1</code> and <code>file2</code>. Returns
* null if no common base directory could be determined or if either <code>file1</code>
* or <code>file2</code> is null
*/
File getBaseDir(final File file1, final File file2) {
if (file1 == null || file2 == null) {
Expand Down
6 changes: 3 additions & 3 deletions src/java/org/apache/ivy/util/cli/CommandLineParser.java
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
Expand All @@ -45,12 +46,11 @@ public CommandLineParser addCategory(String category) {
return this;
}

@SuppressWarnings("unchecked")
public CommandLineParser addOption(Option option) {
options.put(option.getName(), option);
if (!categories.isEmpty()) {
((List<Option>) categories.values().toArray()[categories.values().size() - 1])
.add(option);
// LinkedHashMap hides its tail...
new LinkedList<>(categories.values()).getLast().add(option);
}
return this;
}
Expand Down
15 changes: 8 additions & 7 deletions test/java/org/apache/ivy/core/deliver/DeliverTest.java
Expand Up @@ -17,12 +17,6 @@
*/
package org.apache.ivy.core.deliver;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;

import org.apache.ivy.TestHelper;
import org.apache.ivy.ant.IvyDeliver;
import org.apache.ivy.ant.IvyResolve;
Expand All @@ -32,6 +26,13 @@
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.URI;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class DeliverTest {
Expand Down Expand Up @@ -81,7 +82,7 @@ public void testIVY1111() throws Exception {
ivyDeliver.doExecute();

String deliverContent = readFile(deliverDir.getAbsolutePath() + "/ivys/ivy-1.0.xml");
assertTrue(!deliverContent.contains("rev=\"latest.integration\""));
assertFalse(deliverContent.contains("rev=\"latest.integration\""));
assertTrue(deliverContent.contains("name=\"b\" rev=\"1.5\""));
}

Expand Down

0 comments on commit d4c3cbc

Please sign in to comment.