Skip to content

Commit

Permalink
Merge pull request #6 from broadinstitute/ks_impl
Browse files Browse the repository at this point in the history
More impl
  • Loading branch information
kshakir committed Feb 28, 2019
2 parents 2e22ac5 + 718e714 commit 2bf0c0c
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 67 deletions.
15 changes: 2 additions & 13 deletions alfre-v0-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.jupiter.version>5.3.1</junit.jupiter.version>
<slf4j.version>1.7.25</slf4j.version>
</properties>

Expand All @@ -30,18 +29,8 @@
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<artifactId>junit-jupiter</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
12 changes: 1 addition & 11 deletions alfre-v0-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,7 @@
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
8 changes: 4 additions & 4 deletions alfre-v0-cli/src/main/java/alfre/v0/cli/MainRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ private static boolean runLsPath(final LsOptions lsOptions, final Path path) {
final String[] columns = {
String.valueOf(attributes.size()),
String.valueOf(attributes.lastModifiedTime()),
CloudPaths.showAbsolute(path),
CloudPaths.toAbsoluteString(path),
attributes.fileHash() == null ? "" : attributes.fileHash(),
};
System.out.println(String.join("\t", columns));
} else {
System.out.println(CloudPaths.showAbsolute(path));
System.out.println(CloudPaths.toAbsoluteString(path));
}
return false;
} catch (final Exception exception) {
Expand All @@ -102,7 +102,7 @@ private static boolean runCpPath(
System.out.println(
String.format(
"%s -> %s",
CloudPaths.showAbsolute(sourcePath), CloudPaths.showAbsolute(targetPath)));
CloudPaths.toAbsoluteString(sourcePath), CloudPaths.toAbsoluteString(targetPath)));
}
if (cpOptions.isDoModifications()) {
final Path parent = targetPath.getParent();
Expand Down Expand Up @@ -132,7 +132,7 @@ private static boolean runRmFile(final RmOptions rmOptions, final String filePat
private static boolean runRmPath(final RmOptions rmOptions, final Path path) {
try {
if (!rmOptions.isDoModifications() || rmOptions.getVerbosity() == Verbosity.VERBOSE) {
System.out.println(CloudPaths.showAbsolute(path));
System.out.println(CloudPaths.toAbsoluteString(path));
}
if (rmOptions.isDoModifications()) {
Files.deleteIfExists(path);
Expand Down
12 changes: 1 addition & 11 deletions alfre-v0-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,7 @@
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.file.CopyOption;
import java.nio.file.LinkOption;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;

Expand Down Expand Up @@ -45,4 +47,11 @@ WritableByteChannel write(

Optional<CloudRegularFileAttributes> fileAttributes(CloudPath<CloudHostT> cloudPath)
throws Exception;

@SuppressWarnings({"unused", "RedundantThrows"})
default Path toRealPath(
final CloudPath<CloudHostT> cloudPath, final Collection<? extends LinkOption> options)
throws Exception {
return cloudPath.toAbsolutePath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ public <A extends BasicFileAttributes> A readAttributes(
return (A) attributes;
}

final CloudFileSystem<CloudHostT> fileSystem = cloudPath.getFileSystem();
final CloudFileProvider<CloudHostT> fileProvider = fileSystem.getFileProvider();
final CloudRetry retry = fileSystem.getRetry();

if (checkDirectoryExists(cloudPath)) {
return (A) CloudPseudoDirectoryAttributes.INSTANCE;
} else {
try {
final CloudFileSystem<CloudHostT> fileSystem = cloudPath.getFileSystem();
final CloudFileProvider<CloudHostT> fileProvider = fileSystem.getFileProvider();
final CloudRetry retry = fileSystem.getRetry();

return (A)
retry
.runWithRetries(() -> fileProvider.fileAttributes(cloudPath))
Expand All @@ -282,6 +282,25 @@ public void setAttribute(
throw new UnsupportedOperationException();
}

/**
* Returns the <em>real</em> path of an existing file.
*
* @see Path#toRealPath(java.nio.file.LinkOption...)
*/
public Path toRealPath(final CloudPath<CloudHostT> cloudPath, final LinkOption... options)
throws IOException {
try {
final CloudFileSystem<CloudHostT> fileSystem = cloudPath.getFileSystem();
final CloudFileProvider<CloudHostT> fileProvider = fileSystem.getFileProvider();
final CloudRetry retry = fileSystem.getRetry();
final Collection<LinkOption> optionsCollection = Arrays.asList(options);

return retry.runWithRetries(() -> fileProvider.toRealPath(cloudPath, optionsCollection));
} catch (final CloudRetryException cloudRetryException) {
throw cloudRetryException.getCauseIoException();
}
}

private boolean checkDirectoryExists(final CloudPath<CloudHostT> cloudPath) throws IOException {
try {
final CloudFileSystem<CloudHostT> fileSystem = cloudPath.getFileSystem();
Expand Down
5 changes: 3 additions & 2 deletions alfre-v0-spi/src/main/java/alfre/v0/spi/CloudPath.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package alfre.v0.spi;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.LinkOption;
Expand Down Expand Up @@ -234,8 +235,8 @@ public CloudPath<CloudHostT> toAbsolutePath() {
}

@Override
public CloudPath<CloudHostT> toRealPath(final LinkOption... options) {
return toAbsolutePath();
public Path toRealPath(final LinkOption... options) throws IOException {
return this.fileSystem.provider().toRealPath(this, options);
}

@Override
Expand Down
12 changes: 1 addition & 11 deletions alfre-v0-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,7 @@
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion alfre-v0-util/src/main/java/alfre/v0/util/CloudFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Stream<Path> listRegularFiles(final Path path) throws IOException
/** Lists all files under a path. */
public static Stream<PathPair> relativeFiles(final Path sourcePath, final Path targetPath)
throws IOException {
return relativeFiles(sourcePath, targetPath, CloudPaths::showRelative);
return relativeFiles(sourcePath, targetPath, CloudPaths::toRelativeString);
}

/** Returns all regular files under sourcePath mapped relatively to targetPath. */
Expand Down
21 changes: 11 additions & 10 deletions alfre-v0-util/src/main/java/alfre/v0/util/CloudPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
public class CloudPaths {

/**
* Parses a path in a way reciprocal with
* [[cloud.nio.util.CloudNioPaths#showAbsolute(java.nio.file.Path)]].
* Parses a path in a way reciprocal with {@link #toAbsoluteString toAbsoluteString}.
*
* @see alfre.v0.util.CloudPaths#showAbsolute(java.nio.file.Path)
* @see alfre.v0.util.CloudPaths#toAbsoluteString(java.nio.file.Path)
* @see alfre.v0.spi.CloudPath#getUriAsString()
*/
public static Path get(final String filePath) {
Expand All @@ -34,13 +33,13 @@ public static Path get(final String filePath) {
}

/**
* Return a path in a way reciprocal with [[cloud.nio.util.CloudNioPaths#get]].
* Return a path in a way reciprocal with {@link alfre.v0.util.CloudPaths#get get}.
*
* @see alfre.v0.util.CloudPaths#get(java.lang.String)
* @see alfre.v0.util.CloudPaths#showRelative(java.nio.file.Path)
* @see alfre.v0.util.CloudPaths#toRelativeString(java.nio.file.Path)
* @see alfre.v0.spi.CloudPath#getUriAsString()
*/
public static String showAbsolute(final Path path) {
public static String toAbsoluteString(final Path path) {
Objects.requireNonNull(path, "path is null");
if (path instanceof CloudPath<?>) {
final CloudPath<?> cloudPath = (CloudPath<?>) path;
Expand All @@ -51,14 +50,16 @@ public static String showAbsolute(final Path path) {
}

/**
* When the path is relative returns a relative path in a way reciprocal with resolve. If the path
* is absolute then it is returned as relative but including the host/bucket.
* When the path is relative returns a relative path in a way reciprocal with {@link
* java.nio.file.Path#resolve resolve}.
*
* @see alfre.v0.util.CloudPaths#showAbsolute(java.nio.file.Path)
* <p>If the path is absolute then it is returned as relative but including the host/bucket.
*
* @see alfre.v0.util.CloudPaths#toAbsoluteString(java.nio.file.Path)
* @see java.nio.file.Path#resolve(java.nio.file.Path)
* @see alfre.v0.spi.CloudPath#getUriAsString()
*/
public static String showRelative(final Path path) {
public static String toRelativeString(final Path path) {
Objects.requireNonNull(path, "path is null");
if (path instanceof CloudPath<?>) {
final CloudPath<?> cloudPath = (CloudPath<?>) path;
Expand Down

0 comments on commit 2bf0c0c

Please sign in to comment.