Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions modules/nextflow/src/main/groovy/nextflow/cli/CmdClone.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,25 @@ class CmdClone extends CmdBase implements HubOptions {
Plugins.init()
// the pipeline name
String pipeline = args[0]
final manager = new AssetManager(pipeline, this)
try (final manager = new AssetManager(pipeline, this)) {
// the target directory is the second parameter
// otherwise default the current pipeline name
def target = new File(args.size()> 1 ? args[1] : manager.getBaseName())
if( target.exists() ) {
if( target.isFile() )
throw new AbortOperationException("A file with the same name already exists: $target")
if( !target.empty() )
throw new AbortOperationException("Clone target directory must be empty: $target")
}
else if( !target.mkdirs() ) {
throw new AbortOperationException("Cannot create clone target directory: $target")
}

// the target directory is the second parameter
// otherwise default the current pipeline name
def target = new File(args.size()> 1 ? args[1] : manager.getBaseName())
if( target.exists() ) {
if( target.isFile() )
throw new AbortOperationException("A file with the same name already exists: $target")
if( !target.empty() )
throw new AbortOperationException("Clone target directory must be empty: $target")
manager.checkValidRemoteRepo()
print "Cloning ${manager.getProjectWithRevision()} ..."
manager.clone(target, revision, deep)
print "\r"
println "${manager.getProjectWithRevision()} cloned to: $target"
}
else if( !target.mkdirs() ) {
throw new AbortOperationException("Cannot create clone target directory: $target")
}

manager.checkValidRemoteRepo()
print "Cloning ${manager.getProjectWithRevision()} ..."
manager.clone(target, revision, deep)
print "\r"
println "${manager.getProjectWithRevision()} cloned to: $target"
}
}
12 changes: 6 additions & 6 deletions modules/nextflow/src/main/groovy/nextflow/cli/CmdConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ class CmdConfig extends CmdBase {
return file.parent ?: Paths.get('/')
}

final manager = new AssetManager(path, revision)
if( revision && manager.isUsingLegacyStrategy() ){
log.warn("The local asset for ${path} does not support multi-revision - 'revision' option is ignored\n" +
"Consider updating the project using 'nextflow pull ${path} -r $revision -migrate'")
try (final manager = new AssetManager(path, revision)) {
if( revision && manager.isUsingLegacyStrategy() ){
log.warn("The local asset for ${path} does not support multi-revision - 'revision' option is ignored\n" +
"Consider updating the project using 'nextflow pull ${path} -r $revision -migrate'")
}
return manager.isLocal() ? manager.localPath.toPath() : manager.configFile?.parent
}
manager.isLocal() ? manager.localPath.toPath() : manager.configFile?.parent

}

}
4 changes: 3 additions & 1 deletion modules/nextflow/src/main/groovy/nextflow/cli/CmdDrop.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class CmdDrop extends CmdBase {
@Override
void run() {
Plugins.init()
new AssetManager(args[0]).drop(revision, force)
try (final manager = new AssetManager(args[0])) {
manager.drop(revision, force)
}
}
}
33 changes: 17 additions & 16 deletions modules/nextflow/src/main/groovy/nextflow/cli/CmdInfo.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,26 @@ class CmdInfo extends CmdBase {
}

Plugins.init()
final manager = new AssetManager(args[0])
if( manager.isNotInitialized() ) {
throw new AbortOperationException("Unknown project `${args[0]}`")
}
try (final manager = new AssetManager(args[0])) {
if( manager.isNotInitialized() ) {
throw new AbortOperationException("Unknown project `${args[0]}`")
}

if( !format || format == 'text' ) {
printText(manager,level)
return
}
if( !format || format == 'text' ) {
printText(manager,level)
return
}

def map = createMap(manager)
if( format == 'json' ) {
printJson(map)
}
else if( format == 'yaml' ) {
printYaml(map)
def map = createMap(manager)
if( format == 'json' ) {
printJson(map)
}
else if( format == 'yaml' ) {
printYaml(map)
}
else
throw new AbortOperationException("Unknown output format: $format");
}
else
throw new AbortOperationException("Unknown output format: $format");

}

Expand Down
44 changes: 23 additions & 21 deletions modules/nextflow/src/main/groovy/nextflow/cli/CmdPull.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -83,39 +83,41 @@ class CmdPull extends CmdBase implements HubOptions {

for( String proj : list ) {
if( all ) {
def branches = new AssetManager(proj).getBranchesAndTags(false).pulled as List<String>
branches.each { rev -> pullProjectRevision(proj, rev) }
try (def mgr = new AssetManager(proj)) {
def branches = mgr.getBranchesAndTags(false).pulled as List<String>
branches.each { rev -> pullProjectRevision(proj, rev) }
}
} else {
pullProjectRevision(proj, revision)
}
}
}

private pullProjectRevision(String project, String revision) {
final manager = new AssetManager(project, this)

if( manager.isUsingLegacyStrategy() ) {
if( migrate ) {
log.info "Migrating ${project} revision ${revision} to multi-revision strategy"
manager.setStrategyType(AssetManager.RepositoryStrategyType.MULTI_REVISION)
} else {
log.warn "The local asset for ${project} does not support multi-revision - Pulling with legacy strategy\n" +
"Consider updating the project ${project} using '-migrate' option"
try (final manager = new AssetManager(project, this)) {
if( manager.isUsingLegacyStrategy() ) {
if( migrate ) {
log.info "Migrating ${project} revision ${revision} to multi-revision strategy"
manager.setStrategyType(AssetManager.RepositoryStrategyType.MULTI_REVISION)
} else {
log.warn "The local asset for ${project} does not support multi-revision - Pulling with legacy strategy\n" +
"Consider updating the project ${project} using '-migrate' option"
}
}
}

if( revision )
manager.setRevision(revision)
if( revision )
manager.setRevision(revision)

log.info "Checking ${manager.getProjectWithRevision()} ..."
log.info "Checking ${manager.getProjectWithRevision()} ..."

def result = manager.download(revision, deep)
manager.updateModules()
def result = manager.download(revision, deep)
manager.updateModules()

def scriptFile = manager.getScriptFile()
String message = !result ? " done" : " $result"
message += " - revision: ${scriptFile.revisionInfo}"
log.info message
def scriptFile = manager.getScriptFile()
String message = !result ? " done" : " $result"
message += " - revision: ${scriptFile.revisionInfo}"
log.info message
}
}

}
71 changes: 36 additions & 35 deletions modules/nextflow/src/main/groovy/nextflow/cli/CmdRun.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -599,41 +599,42 @@ class CmdRun extends CmdBase implements HubOptions {
/*
* try to look for a pipeline in the repository
*/
def manager = new AssetManager(pipelineName, this)
if( revision )
manager.setRevision(revision)
def repo = manager.getProjectWithRevision()

boolean checkForUpdate = true
if( !manager.isRunnable() || latest ) {
if( offline )
throw new AbortOperationException("Unknown project `$repo` -- NOTE: automatic download from remote repositories is disabled")
log.info "Pulling $repo ..."
def result = manager.download(revision,deep)
if( result )
log.info " $result"
checkForUpdate = false
}
// Warn if using legacy
if( manager.isUsingLegacyStrategy() ){
log.warn1 "This Nextflow version supports a new Multi-revision strategy for managing the SCM repositories, " +
"but '${repo}' is single-revision legacy strategy - Please consider to update the repository with the 'nextflow pull -migrate' command."
}
// post download operations
try {
manager.checkout(revision)
manager.updateModules()
final scriptFile = manager.getScriptFile(mainScript)
if( checkForUpdate && !offline )
manager.checkRemoteStatus(scriptFile.revisionInfo)
// return the script file
return scriptFile
}
catch( AbortOperationException e ) {
throw e
}
catch( Exception e ) {
throw new AbortOperationException("Unknown error accessing project `$repo` -- Repository may be corrupted: ${manager.localPath}", e)
try (def manager = new AssetManager(pipelineName, this)) {
if( revision )
manager.setRevision(revision)
def repo = manager.getProjectWithRevision()

boolean checkForUpdate = true
if( !manager.isRunnable() || latest ) {
if( offline )
throw new AbortOperationException("Unknown project `$repo` -- NOTE: automatic download from remote repositories is disabled")
log.info "Pulling $repo ..."
def result = manager.download(revision,deep)
if( result )
log.info " $result"
checkForUpdate = false
}
// Warn if using legacy
if( manager.isUsingLegacyStrategy() ){
log.warn1 "This Nextflow version supports a new Multi-revision strategy for managing the SCM repositories, " +
"but '${repo}' is single-revision legacy strategy - Please consider to update the repository with the 'nextflow pull -migrate' command."
}
// post download operations
try {
manager.checkout(revision)
manager.updateModules()
final scriptFile = manager.getScriptFile(mainScript)
if( checkForUpdate && !offline )
manager.checkRemoteStatus(scriptFile.revisionInfo)
// return the script file
return scriptFile
}
catch( AbortOperationException e ) {
throw e
}
catch( Exception e ) {
throw new AbortOperationException("Unknown error accessing project `$repo` -- Repository may be corrupted: ${manager.localPath}", e)
}
}

}
Expand Down
48 changes: 24 additions & 24 deletions modules/nextflow/src/main/groovy/nextflow/cli/CmdView.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,35 @@ class CmdView extends CmdBase {
@Override
void run() {
Plugins.init()
final manager = new AssetManager(args[0], revision)
if( !manager.isLocal() )
throw new AbortOperationException("Unknown project `${manager.getProjectWithRevision()}`")
if( revision && manager.isUsingLegacyStrategy()){
log.warn("The local asset ${args[0]} does not support multi-revision - 'revision' option is ignored\n" +
"Consider updating the asset using 'nextflow pull ${args[0]} -r $revision -migrate'")
}
if( all ) {
if( !quiet )
println "== content of path: ${manager.localPath}"
try (final manager = new AssetManager(args[0], revision)) {
if( !manager.isLocal() )
throw new AbortOperationException("Unknown project `${manager.getProjectWithRevision()}`")
if( revision && manager.isUsingLegacyStrategy()){
log.warn("The local asset ${args[0]} does not support multi-revision - 'revision' option is ignored\n" +
"Consider updating the asset using 'nextflow pull ${args[0]} -r $revision -migrate'")
}
if( all ) {
if( !quiet )
println "== content of path: ${manager.localPath}"

manager.localPath.eachFile { File it ->
println it.name
manager.localPath.eachFile { File it ->
println it.name
}
}
}

else {
/*
* prints the script main file
*/
final script = manager.getMainScriptFile()
if( !script.exists() )
throw new AbortOperationException("Missing script file: '${script}'")
else {
/*
* prints the script main file
*/
final script = manager.getMainScriptFile()
if( !script.exists() )
throw new AbortOperationException("Missing script file: '${script}'")

if( !quiet )
println "== content of file: $script"
if( !quiet )
println "== content of file: $script"

script.readLines().each { println it }
script.readLines().each { println it }
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import org.eclipse.jgit.merge.MergeStrategy

@Slf4j
@CompileStatic
class AssetManager {
class AssetManager implements Closeable {

/**
* The folder all pipelines scripts are installed
Expand Down Expand Up @@ -782,7 +782,7 @@ class AssetManager {
clone.setBranch(revision)
if( deep )
clone.setDepth(deep)
clone.call()
clone.call().close()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class LegacyRepositoryStrategy extends AbstractRepositoryStrategy {
.setCloneSubmodules(manifest.recurseSubmodules)
if( deep )
clone.setDepth(deep)
clone.call()
clone.call().close()

// git cli would automatically create a 'refs/remotes/origin/HEAD' symbolic ref pointing at the remote's
// default branch. jgit doesn't do this, but since it automatically checked out the default branch on clone
Expand Down
Loading
Loading