Removing deprecated methods

This commit is contained in:
Joakim Erdfelt 2014-04-15 12:22:53 -07:00
parent 2dc10da3a4
commit dc3362ba3c
5 changed files with 26 additions and 90 deletions

View File

@ -29,21 +29,11 @@ import java.util.Locale;
public class FS public class FS
{ {
public static boolean canReadDirectory(File path)
{
return (path.exists() && path.isDirectory() && path.canRead());
}
public static boolean canReadDirectory(Path path) public static boolean canReadDirectory(Path path)
{ {
return Files.exists(path) && Files.isDirectory(path) && Files.isReadable(path); return Files.exists(path) && Files.isDirectory(path) && Files.isReadable(path);
} }
public static boolean canReadFile(File path)
{
return (path.exists() && path.isFile() && path.canRead());
}
public static boolean canReadFile(Path path) public static boolean canReadFile(Path path)
{ {
return Files.exists(path) && Files.isRegularFile(path) && Files.isReadable(path); return Files.exists(path) && Files.isRegularFile(path) && Files.isReadable(path);
@ -77,22 +67,6 @@ public class FS
return Files.exists(ret); return Files.exists(ret);
} }
/**
* @deprecated use {@link #ensureDirectoryExists(Path)} instead
*/
@Deprecated
public static void ensureDirectoryExists(File dir) throws IOException
{
if (dir.exists())
{
return;
}
if (!dir.mkdirs())
{
throw new IOException("Unable to create directory: " + dir.getAbsolutePath());
}
}
public static void ensureDirectoryExists(Path dir) throws IOException public static void ensureDirectoryExists(Path dir) throws IOException
{ {
if (exists(dir)) if (exists(dir))
@ -103,22 +77,6 @@ public class FS
Files.createDirectories(dir); Files.createDirectories(dir);
} }
/**
* @deprecated use {@link #ensureDirectoryWritable(Path)} instead
*/
@Deprecated
public static void ensureDirectoryWritable(File dir) throws IOException
{
if (!dir.exists())
{
throw new IOException("Directory does not exist: " + dir.getAbsolutePath());
}
if (!dir.canWrite())
{
throw new IOException("Unable to write to directory: " + dir.getAbsolutePath());
}
}
public static void ensureDirectoryWritable(Path dir) throws IOException public static void ensureDirectoryWritable(Path dir) throws IOException
{ {
if (!Files.exists(dir)) if (!Files.exists(dir))
@ -140,15 +98,6 @@ public class FS
return Files.exists(path); return Files.exists(path);
} }
public static boolean isFile(File file)
{
if (file == null)
{
return false;
}
return file.exists() && file.isFile();
}
public static boolean isValidDirectory(Path path) public static boolean isValidDirectory(Path path)
{ {
if (!Files.exists(path)) if (!Files.exists(path))
@ -194,11 +143,6 @@ public class FS
return FileSystems.getDefault().getPath(FS.separators(path)); return FileSystems.getDefault().getPath(FS.separators(path));
} }
public static String toRelativePath(File baseDir, File path)
{
return baseDir.toURI().relativize(path.toURI()).toASCIIString();
}
public static void touch(Path path) throws IOException public static void touch(Path path) throws IOException
{ {
FileTime now = FileTime.fromMillis(System.currentTimeMillis()); FileTime now = FileTime.fromMillis(System.currentTimeMillis());

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.start; package org.eclipse.jetty.start;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
@ -29,16 +28,11 @@ public class StartIni extends TextFile
{ {
private Path basedir; private Path basedir;
public StartIni(File file) throws IOException public StartIni(Path file) throws IOException
{ {
super(file); super(file);
} }
public StartIni(Path path) throws IOException
{
this(path.toFile());
}
@Override @Override
public void addUniqueLine(String line) public void addUniqueLine(String line)
{ {
@ -70,7 +64,7 @@ public class StartIni extends TextFile
@Override @Override
public void init() public void init()
{ {
basedir = getFile().getParentFile().toPath().toAbsolutePath(); basedir = getFile().getParent().toAbsolutePath();
} }
public Path getBaseDir() public Path getBaseDir()

View File

@ -19,10 +19,11 @@
package org.eclipse.jetty.start; package org.eclipse.jetty.start;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -36,40 +37,37 @@ import java.util.regex.Pattern;
*/ */
public class TextFile implements Iterable<String> public class TextFile implements Iterable<String>
{ {
private final File file; private final Path file;
private final List<String> lines = new ArrayList<>(); private final List<String> lines = new ArrayList<>();
public TextFile(File file) throws FileNotFoundException, IOException public TextFile(Path file) throws FileNotFoundException, IOException
{ {
this.file = file; this.file = file;
init(); init();
if (!FS.canReadFile(file)) if (!FS.canReadFile(file))
{ {
StartLog.debug("Skipping read of missing file: %s",file.getAbsolutePath()); StartLog.debug("Skipping read of missing file: %s",file.toAbsolutePath());
return; return;
} }
try (FileReader reader = new FileReader(file)) try (BufferedReader buf = Files.newBufferedReader(file,StandardCharsets.UTF_8))
{ {
try (BufferedReader buf = new BufferedReader(reader)) String line;
while ((line = buf.readLine()) != null)
{ {
String line; if (line.length() == 0)
while ((line = buf.readLine()) != null)
{ {
if (line.length() == 0) continue;
{
continue;
}
if (line.charAt(0) == '#')
{
continue;
}
// TODO - bad form calling derived method from base class constructor
process(line.trim());
} }
if (line.charAt(0) == '#')
{
continue;
}
// TODO - bad form calling derived method from base class constructor
process(line.trim());
} }
} }
} }
@ -84,7 +82,7 @@ public class TextFile implements Iterable<String>
lines.add(line); lines.add(line);
} }
public File getFile() public Path getFile()
{ {
return file; return file;
} }

View File

@ -53,7 +53,7 @@ public class ConfigurationAssert
{ {
File testResourcesDir = MavenTestingUtils.getTestResourcesDir(); File testResourcesDir = MavenTestingUtils.getTestResourcesDir();
File file = MavenTestingUtils.getTestResourceFile(filename); File file = MavenTestingUtils.getTestResourceFile(filename);
TextFile textFile = new TextFile(file); TextFile textFile = new TextFile(file.toPath());
// Validate XMLs (order is important) // Validate XMLs (order is important)
List<String> expectedXmls = new ArrayList<>(); List<String> expectedXmls = new ArrayList<>();

View File

@ -31,21 +31,21 @@ public class FSTest
public void testCanReadDirectory() public void testCanReadDirectory()
{ {
File targetDir = MavenTestingUtils.getTargetDir(); File targetDir = MavenTestingUtils.getTargetDir();
Assert.assertTrue("Can read dir: " + targetDir,FS.canReadDirectory(targetDir)); Assert.assertTrue("Can read dir: " + targetDir,FS.canReadDirectory(targetDir.toPath()));
} }
@Test @Test
public void testCanReadDirectory_NotDir() public void testCanReadDirectory_NotDir()
{ {
File bogusFile = MavenTestingUtils.getTestResourceFile("bogus.xml"); File bogusFile = MavenTestingUtils.getTestResourceFile("bogus.xml");
Assert.assertFalse("Can read dir: " + bogusFile,FS.canReadDirectory(bogusFile)); Assert.assertFalse("Can read dir: " + bogusFile,FS.canReadDirectory(bogusFile.toPath()));
} }
@Test @Test
public void testCanReadFile() public void testCanReadFile()
{ {
File pom = MavenTestingUtils.getProjectFile("pom.xml"); File pom = MavenTestingUtils.getProjectFile("pom.xml");
Assert.assertTrue("Can read file: " + pom,FS.canReadFile(pom)); Assert.assertTrue("Can read file: " + pom,FS.canReadFile(pom.toPath()));
} }
/** /**