Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
drernie committed Nov 13, 2024
1 parent 0e0cff2 commit ddc3da0
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ class QuiltObserverFactory implements TraceObserverFactory {
@Override
Collection<TraceObserver> create(Session session) {
//log.debug("`create` ${this}")
return (Collection<TraceObserver>) [new QuiltObserver()]
Collection<QuiltObserver> quiltObservers = new ArrayList<>()
quiltObservers.add(new QuiltObserver())

return quiltObservers as Collection<TraceObserver>
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class QuiltPathify {
Files.copy(source, dest)
}
catch (Exception e) {
log.error("writeString: cannot write `$source` to `$dest` in `${destRoot}`")
log.error("writeString: cannot write `$source` to `$dest` in `${destRoot}`\n$e")
}
}

Expand Down
6 changes: 3 additions & 3 deletions plugins/nf-quilt/src/main/nextflow/quilt/QuiltProduct.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ ${nextflow}
Files.write(path, text.bytes)
}
catch (Exception e) {
log.error("writeString: cannot write `$text` to `$path` for `${pkg}`")
log.error("writeString: cannot write `$text` to `$path` for `${pkg}`\n$e")
}
}

Expand All @@ -121,7 +121,7 @@ ${nextflow}
Files.copy(source, dest)
}
catch (Exception e) {
log.error("writeString: cannot write `$source` to `$dest` in `${destRoot}`")
log.error("writeString: cannot write `$source` to `$dest` in `${destRoot}`\n$e.message()")
}
}

Expand Down Expand Up @@ -182,7 +182,7 @@ ${nextflow}
Map<String, Object> cf_meta = quilt_cf.navigate(KEY_META) as Map<String, Object> ?: [:]
quilt_cf.remove(KEY_META)
// println("getMetadata.cf_meta: ${cf_meta}")
Map pkg_meta = pkg.meta
Map pkg_meta = pkg.getMetadata()
updateFlags(pkg_meta, quilt_cf)

Map params = session.getParams()
Expand Down
3 changes: 0 additions & 3 deletions plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltID.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package nextflow.quilt.jep

/* groovylint-disable-next-line ImportFromSamePackage */
import nextflow.quilt.jep.QuiltParser

import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class QuiltPackage {
private static final String INSTALL_PREFIX = 'QuiltPackage'
static final Path INSTALL_ROOT = Files.createTempDirectory(INSTALL_PREFIX)

public final String packageName
private final String bucket
private final String packageName
private final QuiltParser parsed
private final String hash
private final Path folder
Expand Down Expand Up @@ -220,6 +220,10 @@ class QuiltPackage {
return folder
}

Map getMetadata() {
return this.meta
}

/*
* Package methods
*/
Expand Down
11 changes: 6 additions & 5 deletions plugins/nf-quilt/src/main/nextflow/quilt/jep/QuiltParser.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,21 @@ class QuiltParser {
static Map<String, Object> parseQuery(String query) {
if (!query) { return [:] } // skip for urls without query params
def params = query.split('&')
def result = [:]
Map<String,List<String>> result = [:]
params.each { param ->
def keyValue = param.split('=')
if (keyValue.size() == 2) {
String key = decode(keyValue[0])
String value = decode(keyValue[1])
if (result.containsKey(key)) {
if (result[key] instanceof List) {
result[key] += value
List<String> listVal = result[key]
if (listVal instanceof List) {
listVal << value
} else {
result[key] = [result[key], value]
result[key] = [listVal, value] as List<String>
}
} else {
result[key] = value
result[key] = value as List<String>
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class QuiltFileAttributesView implements BasicFileAttributeView {

/**
* This API is implemented is not supported but instead of throwing an exception just do nothing
* to not break the method {@link java.nio.file.CopyMoveHelper#copyToForeignTarget(...)}
* to not break the method {@link java.nio.file.CopyMoveHelper copyToForeignTarget(...)}
*
* @param lastModifiedTime
* @param lastAccessTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ final class QuiltFileSystem extends FileSystem implements Closeable {
return quiltIDS
}

void copy(QuiltPath source, QuiltPath target) {
static void copy(QuiltPath source, QuiltPath target) {
throw new UnsupportedOperationException("NOT Implemented 'QuiltFileSystem.copy' `$source` -> `$target`")
}

void delete(QuiltPath path) {
static void delete(QuiltPath path) {
//log.debug("QuiltFileSystem.delete: $path")
path.deinstall()
//throw new UnsupportedOperationException("Operation 'delete' is not supported by QuiltFileSystem")
Expand Down Expand Up @@ -93,7 +93,7 @@ final class QuiltFileSystem extends FileSystem implements Closeable {
return QuiltParser.SEP
}

QuiltFileAttributesView getFileAttributeView(QuiltPath path) {
static QuiltFileAttributesView getFileAttributeView(QuiltPath path) {
//log.debug("QuiltFileAttributesView QuiltFileSystem.getFileAttributeView($path)")
String pathString = path.toUriString()
try {
Expand All @@ -105,20 +105,20 @@ final class QuiltFileSystem extends FileSystem implements Closeable {
}
}

QuiltFileAttributes readAttributes(QuiltPath path) {
static QuiltFileAttributes readAttributes(QuiltPath path) {
log.debug("QuiltFileAttributes QuiltFileSystem.readAttributes($path)")
Path installedPath = path.localPath()
try {
BasicFileAttributes attrs = Files.readAttributes(installedPath, BasicFileAttributes)
return new QuiltFileAttributes(path, path.toString(), attrs)
}
catch (NoSuchFileException e) {
log.debug("No attributes yet for: ${installedPath}")
log.debug("No attributes yet for: ${installedPath}\n$e")
}
return null
}

boolean exists(QuiltPath path) {
static boolean exists(QuiltPath path) {
return path.pkg().isInstalled()
}

Expand All @@ -145,15 +145,15 @@ final class QuiltFileSystem extends FileSystem implements Closeable {
return new QuiltPath(this, p)
}

String toUriString(Path path) {
static String toUriString(Path path) {
return path in QuiltPath ? ((QuiltPath)path).toUriString() : null
}

String getBashLib(Path path) {
static String getBashLib(Path path) {
return path in QuiltPath ? QuiltBashLib.script() : null
}

String getUploadCmd(String source, Path target) {
static String getUploadCmd(String source, Path target) {
return target in QuiltPath ? QuiltFileCopyStrategy.uploadCmd(source, target) : null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import java.nio.file.NoSuchFileException
import java.nio.file.OpenOption
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.StandardOpenOption
import java.nio.file.attribute.BasicFileAttributeView
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.attribute.FileAttribute
Expand Down Expand Up @@ -94,12 +93,12 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr

boolean canUpload(Path source, Path target) {
log.debug "QuiltFileSystemProvider.canUpload: ${source} -> ${target}"
return FileSystems.getDefault().equals(source.getFileSystem()) && target instanceof QuiltPath
return FileSystems.getDefault() == source.getFileSystem() && target instanceof QuiltPath
}

boolean canDownload(Path source, Path target) {
log.debug "QuiltFileSystemProvider.canDownload: ${source} -> ${target}"
return source instanceof QuiltPath && FileSystems.getDefault().equals(target.getFileSystem())
return source instanceof QuiltPath && FileSystems.getDefault() == target.getFileSystem()
}

void download(Path remoteFile, Path localDestination, CopyOption... options) throws IOException {
Expand Down Expand Up @@ -161,7 +160,7 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr
return QuiltParser.SCHEME
}

String getQuiltIDS(URI uri) {
static String getQuiltIDS(URI uri) {
assert uri
QuiltParser parsed = QuiltParser.forURI(uri)
return parsed.quiltID().toString()
Expand Down Expand Up @@ -213,6 +212,7 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr

/* groovylint-disable-next-line UnusedMethodParameter */
QuiltFileSystem newFileSystem(String quiltIDS, Map<String, ?> env) throws IOException {
log.debug("newFileSystem $env")
final fs = new QuiltFileSystem(quiltIDS, this)
fileSystems[quiltIDS] = fs
return fs
Expand Down Expand Up @@ -301,7 +301,7 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr
return new QuiltPath(fs, parsed)
}

void checkRoot(Path path) {
static void checkRoot(Path path) {
if (path == Paths.get('/')) {
throw new UnsupportedOperationException("Operation 'checkRoot' not supported on root path")
}
Expand All @@ -316,7 +316,7 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr
* @return
* @throws IOException
*/
void notifyFilePublish(QuiltPath destination) { //, Path source=null) {
static void notifyFilePublish(QuiltPath destination) { //, Path source=null) {
final sess = Global.session
/* groovylint-disable-next-line Instanceof */
if (sess instanceof Session) {
Expand Down Expand Up @@ -345,12 +345,13 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr
FileChannel channel = FileChannel.open(installedPath, options)
return channel
}
catch (java.nio.file.NoSuchFileException e) {
log.error("Failed `FileChannel.open`: ${installedPath} <- ${options}")
catch (NoSuchFileException e) {
log.error("Failed `FileChannel.open`: ${installedPath} <- ${options}\n$e")
}
return null
}

DirectoryStream<Path> emptyStream() throws IOException {
static DirectoryStream<Path> emptyStream() throws IOException {
return new DirectoryStream<Path>() {

@Override
Expand Down Expand Up @@ -450,32 +451,32 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr
}

@Override
def <V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
<V extends FileAttributeView> V getFileAttributeView(Path path, Class<V> type, LinkOption... options) {
// log.debug("Calling `getFileAttributeView`: ${path}")
checkRoot(path)
if (type == BasicFileAttributeView || type == QuiltFileAttributesView) {
QuiltPath qPath = asQuiltPath(path)
QuiltFileSystem fs = qPath.filesystem
QuiltFileSystem fs = qPath.getFileSystem() as QuiltFileSystem
return (V)fs.getFileAttributeView(qPath)
}
throw new UnsupportedOperationException("Operation 'getFileAttributeView' is not supported for type $type")
}

@Override
def <A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options)
<A extends BasicFileAttributes> A readAttributes(Path path, Class<A> type, LinkOption... options)
throws IOException {
log.debug '<A>BasicFileAttributes QuiltFileSystemProvider.readAttributes()'
def attr = attributesCache.get(path)
if (attr) {
return attr
return attr as A
}
if (type == BasicFileAttributes || type == QuiltFileAttributes) {
QuiltPath qPath = asQuiltPath(path)
QuiltFileSystem fs = qPath.filesystem
QuiltFileSystem fs = qPath.getFileSystem() as QuiltFileSystem
def result = (A)fs.readAttributes(qPath)
if (result) {
attributesCache[path] = result
return result
return result as A
}
log.debug("readAttributes: File ${qPath.localPath()} not found")
if (!qPath.isNull()) {
Expand All @@ -484,7 +485,7 @@ class QuiltFileSystemProvider extends FileSystemProvider implements FileSystemTr
log.warn("readAttributes: Ignore ${qPath} for null bucket")
}
throw new UnsupportedOperationException("Not a valid Quilt Storage file attribute type: $type")
}
}

@Override
Map<String, Object> readAttributes(Path path, String attributes, LinkOption... options) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import nextflow.quilt.jep.QuiltParser
import java.nio.file.Files
import java.nio.file.FileSystem
import java.nio.file.LinkOption
import java.nio.file.NoSuchFileException
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.ProviderMismatchException
Expand Down Expand Up @@ -112,10 +113,11 @@ final class QuiltPath implements Path, Comparable {
log.debug("QuiltPath.deinstall: $path")
try {
Files.delete(path)
} catch (java.nio.file.NoSuchFileException e) {
} catch (NoSuchFileException e) {
// Handle the exception here
log.error("Failed to delete path: $path", e)
}
return false
}

@Override
Expand Down

0 comments on commit ddc3da0

Please sign in to comment.