Skip to content
2 changes: 1 addition & 1 deletion src/example/multi-project/projects/find/src/find/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void main(String[] args) throws Exception {
CommandLineParser parser = new GnuParser();

CommandLine line = parser.parse(options, args);
File dir = new File(line.getOptionValue("dir", "."));
File dir = FileUtil.newFile(line.getOptionValue("dir", "."));
String name = line.getOptionValue("name", "jar");
Collection files = FindFile.find(dir, name);
System.out.println("listing files in " + dir + " containing " + name);
Expand Down
2 changes: 1 addition & 1 deletion src/example/multi-project/projects/list/src/list/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void main(String[] args) throws Exception {
CommandLineParser parser = new GnuParser();

CommandLine line = parser.parse(options, args);
File dir = new File(line.getOptionValue("dir", "."));
File dir = FileUtil.newFile(line.getOptionValue("dir", "."));
Collection files = ListFile.list(dir);
System.out.println("listing files in " + dir);
for (Iterator it = files.iterator(); it.hasNext();) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void main(String[] args) throws Exception {
CommandLineParser parser = new GnuParser();

CommandLine line = parser.parse(options, args);
File dir = new File(line.getOptionValue("dir", "."));
File dir = FileUtil.newFile(line.getOptionValue("dir", "."));
String name = line.getOptionValue("name", "jar");
System.out.println("total size of files in " + dir
+ " containing " + name + ": " + SizeWhere.totalSize(dir, name));
Expand Down
11 changes: 6 additions & 5 deletions src/java/org/apache/ivy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
import org.apache.ivy.plugins.report.XmlReportParser;
import org.apache.ivy.util.DefaultMessageLogger;
import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.Message;
import org.apache.ivy.util.cli.CommandLine;
import org.apache.ivy.util.cli.CommandLineParser;
Expand Down Expand Up @@ -247,7 +248,7 @@ static void run(CommandLineParser parser, String[] args) throws Exception {
IvySettings settings = initSettings(line, ivy);
ivy.pushContext();

File cache = new File(settings.substitute(line.getOptionValue("cache", settings
File cache = FileUtil.newFile(settings.substitute(line.getOptionValue("cache", settings
.getDefaultCache().getAbsolutePath())));

if (line.hasOption("cache")) {
Expand Down Expand Up @@ -285,7 +286,7 @@ static void run(CommandLineParser parser, String[] args) throws Exception {
XmlModuleDescriptorWriter.write(md, ivyfile);
confs = new String[] {"default"};
} else {
ivyfile = new File(settings.substitute(line.getOptionValue("ivy", "ivy.xml")));
ivyfile = FileUtil.newFile(settings.substitute(line.getOptionValue("ivy", "ivy.xml")));
if (!ivyfile.exists()) {
error("ivy file not found: " + ivyfile);
} else if (ivyfile.isDirectory()) {
Expand Down Expand Up @@ -409,7 +410,7 @@ static void run(CommandLineParser parser, String[] args) throws Exception {
System.getProperty("path.separator"));
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
File file = new File(token);
File file = FileUtil.newFile(token);
if (file.exists()) {
fileList.add(file);
} else {
Expand Down Expand Up @@ -443,7 +444,7 @@ private static IvySettings initSettings(CommandLine line, Ivy ivy)
if ("".equals(settingsPath)) {
ivy.configureDefault();
} else {
File conffile = new File(settingsPath);
File conffile = FileUtil.newFile(settingsPath);
if (!conffile.exists()) {
error("ivy configuration file not found: " + conffile);
} else if (conffile.isDirectory()) {
Expand Down Expand Up @@ -491,7 +492,7 @@ private static void outputCachePath(Ivy ivy, File cache, ModuleDescriptor md, St
}
}

PrintWriter writer = new PrintWriter(new FileOutputStream(outFile));
PrintWriter writer = new PrintWriter(FileUtil.newOutputStream(outFile));
if (buf.length() > 0) {
writer.println(buf.substring(0, buf.length() - pathSeparator.length()));
}
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/apache/ivy/ant/BuildOBRTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.ivy.osgi.repo.ResolverManifestIterable;
import org.apache.ivy.plugins.resolver.BasicResolver;
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.Message;
import org.apache.tools.ant.BuildException;
import org.xml.sax.ContentHandler;
Expand Down Expand Up @@ -169,7 +170,7 @@ public void doExecute() throws BuildException {

OutputStream out;
try {
out = new FileOutputStream(file);
out = FileUtil.newOutputStream(file);
} catch (FileNotFoundException e) {
throw new BuildException(file + " was not found", e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/apache/ivy/ant/ConvertManifestTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.ivy.osgi.core.ManifestParser;
import org.apache.ivy.osgi.core.OSGiManifestParser;
import org.apache.ivy.plugins.parser.xml.XmlModuleDescriptorWriter;
import org.apache.ivy.util.FileUtil;
import org.apache.tools.ant.BuildException;

public class ConvertManifestTask extends IvyTask {
Expand Down Expand Up @@ -70,7 +71,7 @@ public void doExecute() throws BuildException {

Manifest m;
try {
m = new Manifest(new FileInputStream(manifest));
m = new Manifest(FileUtil.newInputStream(manifest));
} catch (FileNotFoundException e) {
throw new BuildException("the manifest file '" + manifest + "' was not found", e);
} catch (IOException e) {
Expand Down
7 changes: 4 additions & 3 deletions src/java/org/apache/ivy/ant/IvyAntSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.ivy.Ivy;
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.core.settings.IvyVariableContainer;
import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.Message;
import org.apache.ivy.util.url.CredentialsStore;
import org.apache.ivy.util.url.URLHandler;
Expand Down Expand Up @@ -344,9 +345,9 @@ private void defineDefaultSettingFile(IvyVariableContainer variableContainer,
settingsFileName = variableContainer.getVariable("ivy.settings.file");
}
File[] settingsLocations = new File[] {
new File(getProject().getBaseDir(), settingsFileName),
new File(getProject().getBaseDir(), "ivyconf.xml"), new File(settingsFileName),
new File("ivyconf.xml")};
FileUtil.newFile(getProject().getBaseDir(), settingsFileName),
FileUtil.newFile(getProject().getBaseDir(), "ivyconf.xml"), FileUtil.newFile(settingsFileName),
FileUtil.newFile("ivyconf.xml")};
for (int i = 0; i < settingsLocations.length; i++) {
file = settingsLocations[i];
task.log("searching settings file: trying " + file, Project.MSG_VERBOSE);
Expand Down
8 changes: 5 additions & 3 deletions src/java/org/apache/ivy/ant/IvyArtifactReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -44,6 +45,7 @@
import org.apache.ivy.core.resolve.ResolveOptions;
import org.apache.ivy.core.resolve.ResolvedModuleRevision;
import org.apache.ivy.core.retrieve.RetrieveOptions;
import org.apache.ivy.util.FileUtil;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.xml.sax.SAXException;
Expand Down Expand Up @@ -126,7 +128,7 @@ public void doExecute() throws BuildException {
private void generateXml(IvyNode[] dependencies, Map moduleRevToArtifactsMap,
Map artifactsToCopy) {
try {
FileOutputStream fileOuputStream = new FileOutputStream(tofile);
OutputStream fileOuputStream = FileUtil.newOutputStream(tofile);
try {
TransformerHandler saxHandler = createTransformerHandler(fileOuputStream);

Expand Down Expand Up @@ -180,7 +182,7 @@ private void generateXml(IvyNode[] dependencies, Map moduleRevToArtifactsMap,
}
}

private TransformerHandler createTransformerHandler(FileOutputStream fileOuputStream)
private TransformerHandler createTransformerHandler(OutputStream fileOuputStream)
throws TransformerFactoryConfigurationError, TransformerConfigurationException,
SAXException {
SAXTransformerFactory transformerFact = (SAXTransformerFactory) SAXTransformerFactory
Expand Down Expand Up @@ -253,7 +255,7 @@ private void writeCacheLocationIfPresent(RepositoryCacheManager cache,

private void writeRetrieveLocation(TransformerHandler saxHandler, String artifactDestPath)
throws SAXException {
artifactDestPath = removeLeadingPath(getProject().getBaseDir(), new File(artifactDestPath));
artifactDestPath = removeLeadingPath(getProject().getBaseDir(), FileUtil.newFile(artifactDestPath));

saxHandler.startElement(null, "retrieve-location", "retrieve-location",
new AttributesImpl());
Expand Down
5 changes: 3 additions & 2 deletions src/java/org/apache/ivy/ant/IvyBuildList.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.core.sort.SortOptions;
import org.apache.ivy.plugins.parser.ModuleDescriptorParserRegistry;
import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.Message;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
Expand Down Expand Up @@ -201,7 +202,7 @@ public void doExecute() throws BuildException {
DirectoryScanner ds = fs.getDirectoryScanner(getProject());
String[] builds = ds.getIncludedFiles();
for (int i = 0; i < builds.length; i++) {
File buildFile = new File(ds.getBasedir(), builds[i]);
File buildFile = FileUtil.newFile(ds.getBasedir(), builds[i]);
File ivyFile = getIvyFileFor(buildFile);
if (!ivyFile.exists()) {
onMissingDescriptor(buildFile, ivyFile, noDescriptor);
Expand Down Expand Up @@ -505,7 +506,7 @@ private void addBuildFile(Path path, File buildFile) {
}

private File getIvyFileFor(File buildFile) {
return new File(buildFile.getParentFile(), ivyFilePath);
return FileUtil.newFile(buildFile.getParentFile(), ivyFilePath);
}

public boolean isHaltonerror() {
Expand Down
5 changes: 3 additions & 2 deletions src/java/org/apache/ivy/ant/IvyCachePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.ivy.core.report.ArtifactDownloadReport;
import org.apache.ivy.osgi.core.BundleInfo;
import org.apache.ivy.osgi.core.ManifestParser;
import org.apache.ivy.util.FileUtil;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.Path;
Expand Down Expand Up @@ -92,7 +93,7 @@ protected void addToPath(Path path, File f) throws Exception {
path.createPathElement().setLocation(f);
return;
}
File manifest = new File(f, "META-INF/MANIFEST.MF");
File manifest = FileUtil.newFile(f, "META-INF/MANIFEST.MF");
if (!manifest.exists()) {
path.createPathElement().setLocation(f);
return;
Expand All @@ -108,7 +109,7 @@ protected void addToPath(Path path, File f) throws Exception {
if (p.equals(".")) {
path.createPathElement().setLocation(f);
} else {
path.createPathElement().setLocation(new File(f, p));
path.createPathElement().setLocation(FileUtil.newFile(f, p));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/apache/ivy/ant/IvyCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;

import org.apache.ivy.Ivy;
import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.Message;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
Expand Down Expand Up @@ -84,7 +85,7 @@ public void doExecute() throws BuildException {

String[] srcFiles = ds.getIncludedFiles();
for (int j = 0; j < srcFiles.length; j++) {
File file = new File(fromDir, srcFiles[j]);
File file = FileUtil.newFile(fromDir, srcFiles[j]);
if (ivy.check(file.toURI().toURL(), resolvername)) {
Message.verbose("checked " + file + ": OK");
}
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/apache/ivy/ant/IvyDeliver.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.ivy.core.module.status.StatusManager;
import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.util.DateUtil;
import org.apache.ivy.util.FileUtil;
import org.apache.ivy.util.Message;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.CallTarget;
Expand Down Expand Up @@ -350,7 +351,7 @@ public void doExecute() throws BuildException {
if (deliveryList == null) {
String deliveryListPath = getProperty(settings, "ivy.delivery.list.file");
if (deliveryListPath == null) {
deliveryList = new File(System.getProperty("java.io.tmpdir")
deliveryList = FileUtil.newFile(System.getProperty("java.io.tmpdir")
+ "/delivery.properties");
} else {
deliveryList = getProject().resolveFile(settings.substitute(deliveryListPath));
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/apache/ivy/ant/IvyExtractFromSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Set;

import org.apache.ivy.core.module.id.ModuleRevisionId;
import org.apache.ivy.util.FileUtil;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
Expand Down Expand Up @@ -142,7 +143,7 @@ public void execute() throws BuildException {
}
}
try {
PrintWriter writer = new PrintWriter(new FileOutputStream(to));
PrintWriter writer = new PrintWriter(FileUtil.newOutputStream(to));
writer.println("<ivy-module version=\"1.0\">");
writer.println("\t<info organisation=\"" + organisation + "\"");
writer.println("\t module=\"" + module + "\"");
Expand Down
16 changes: 8 additions & 8 deletions src/java/org/apache/ivy/ant/IvyReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void genxml(String[] confs) throws IOException {

File out;
if (todir != null) {
out = new File(todir, getOutputPattern(confs[i], "xml"));
out = FileUtil.newFile(todir, getOutputPattern(confs[i], "xml"));
} else {
out = getProject().resolveFile(getOutputPattern(confs[i], "xml"));
}
Expand All @@ -244,7 +244,7 @@ private void genreport(String[] confs) throws IOException {
if (xslFile == null) {
File css;
if (todir != null) {
css = new File(todir, "ivy-report.css");
css = FileUtil.newFile(todir, "ivy-report.css");
} else {
css = getProject().resolveFile("ivy-report.css");
}
Expand All @@ -264,7 +264,7 @@ private File getReportStylePath() throws IOException {
// style should be a file (and not an url)
// so we have to copy it from classpath to cache
ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
File style = new File(cacheMgr.getResolutionCacheRoot(), "ivy-report.xsl");
File style = FileUtil.newFile(cacheMgr.getResolutionCacheRoot(), "ivy-report.xsl");
if (!style.exists()) {
Message.debug("copying ivy-report.xsl to " + style.getAbsolutePath());
FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report.xsl"), style,
Expand Down Expand Up @@ -310,7 +310,7 @@ private void genStyled(String[] confs, File style, String ext) throws IOExceptio
InputStream xsltStream = null;
try {
// create stream to stylesheet
xsltStream = new BufferedInputStream(new FileInputStream(style));
xsltStream = new BufferedInputStream(FileUtil.newInputStream(style));
Source xsltSource = new StreamSource(xsltStream, JAXPUtils.getSystemId(style));

// create transformer
Expand All @@ -331,7 +331,7 @@ private void genStyled(String[] confs, File style, String ext) throws IOExceptio
for (int i = 0; i < confs.length; i++) {
File reportFile = cacheMgr
.getConfigurationResolveReportInCache(resolveId, confs[i]);
File outFile = new File(out, getOutputPattern(confs[i], ext));
File outFile = FileUtil.newFile(out, getOutputPattern(confs[i], ext));

log("Processing " + reportFile + " to " + outFile);

Expand All @@ -347,8 +347,8 @@ private void genStyled(String[] confs, File style, String ext) throws IOExceptio
InputStream inStream = null;
OutputStream outStream = null;
try {
inStream = new BufferedInputStream(new FileInputStream(reportFile));
outStream = new BufferedOutputStream(new FileOutputStream(outFile));
inStream = new BufferedInputStream(FileUtil.newInputStream(reportFile));
outStream = new BufferedOutputStream(FileUtil.newOutputStream(outFile));
StreamResult res = new StreamResult(outStream);
Source src = new StreamSource(inStream, JAXPUtils.getSystemId(style));
transformer.transform(src, res);
Expand Down Expand Up @@ -388,7 +388,7 @@ private File getStylePath(String styleResourceName) throws IOException {
// style should be a file (and not an url)
// so we have to copy it from classpath to cache
ResolutionCacheManager cacheMgr = getIvyInstance().getResolutionCacheManager();
File style = new File(cacheMgr.getResolutionCacheRoot(), styleResourceName);
File style = FileUtil.newFile(cacheMgr.getResolutionCacheRoot(), styleResourceName);
FileUtil.copy(XmlReportOutputter.class.getResourceAsStream(styleResourceName), style, null);
return style;
}
Expand Down
10 changes: 5 additions & 5 deletions src/java/org/apache/ivy/ant/IvyRepositoryReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void doExecute() throws BuildException {
if (xml) {

FileUtil.copy(cacheMgr.getConfigurationResolveReportInCache(resolveId, "default"),
new File(getTodir(), outputname + ".xml"), null);
FileUtil.newFile(getTodir(), outputname + ".xml"), null);
}
if (xsl) {
genreport(cacheMgr, md.getModuleRevisionId().getOrganisation(), md
Expand All @@ -146,7 +146,7 @@ private void genreport(ResolutionCacheManager cache, String organisation, String

String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module));
xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default"));
xslt.setOut(new File(getTodir(), outputname + "." + xslext));
xslt.setOut(FileUtil.newFile(getTodir(), outputname + "." + xslext));

xslt.setStyle(xslFile);

Expand Down Expand Up @@ -174,7 +174,7 @@ private void gengraph(ResolutionCacheManager cache, String organisation, String
private String getGraphStylePath(File cache) throws IOException {
// style should be a file (and not an url)
// so we have to copy it from classpath to cache
File style = new File(cache, "ivy-report-graph-all.xsl");
File style = FileUtil.newFile(cache, "ivy-report-graph-all.xsl");
FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report-graph-all.xsl"),
style, null);
return style.getAbsolutePath();
Expand All @@ -188,7 +188,7 @@ private void gendot(ResolutionCacheManager cache, String organisation, String mo
private String getDotStylePath(File cache) throws IOException {
// style should be a file (and not an url)
// so we have to copy it from classpath to cache
File style = new File(cache, "ivy-report-dot-all.xsl");
File style = FileUtil.newFile(cache, "ivy-report-dot-all.xsl");
FileUtil.copy(XmlReportOutputter.class.getResourceAsStream("ivy-report-dot-all.xsl"),
style, null);
return style.getAbsolutePath();
Expand All @@ -203,7 +203,7 @@ private void gen(ResolutionCacheManager cache, String organisation, String modul

String resolveId = ResolveOptions.getDefaultResolveId(new ModuleId(organisation, module));
xslt.setIn(cache.getConfigurationResolveReportInCache(resolveId, "default"));
xslt.setOut(new File(getTodir(), outputname + "." + ext));
xslt.setOut(FileUtil.newFile(getTodir(), outputname + "." + ext));
xslt.setBasedir(cache.getResolutionCacheRoot());
xslt.setStyle(style);
xslt.execute();
Expand Down
Loading