Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix forwarded outputs not resolvable in downstream stages
  • Loading branch information
ssadedin committed Aug 2, 2018
1 parent 2bb2419 commit 2f6eda7
Showing 1 changed file with 46 additions and 32 deletions.
78 changes: 46 additions & 32 deletions src/main/groovy/bpipe/PipelineInput.groovy
Expand Up @@ -26,6 +26,7 @@ package bpipe

import java.util.logging.Level;

import groovy.transform.CompileStatic
import groovy.util.logging.Log;

/**
Expand Down Expand Up @@ -279,43 +280,17 @@ class PipelineInput {
def orig = exts
synchronized(stages) {

def reverseOutputs = computeOutputStack()
List<List<String>> reverseOutputs = computeOutputStack()

List missingExts = []
def filesWithExts = [Utils.box(exts),origs].transpose().collect { extsAndOrigs ->
String pattern = extsAndOrigs[0]
String origName = extsAndOrigs[1]

String wholeMatch = '(^|^.*/)' + pattern + '$'

// Special case: treat a leading dot as a literal dot.
// ie: if the user specifies ".xml", they probably mean
// literally ".xml" and not "any character" + "xml"
if(pattern.startsWith("."))
pattern = "\\." + pattern.substring(1)

if(!pattern.startsWith("\\.") )
pattern = "\\." + pattern

pattern = '^.*' + pattern
log.info "Resolving inputs matching pattern $pattern"
for(s in reverseOutputs) {
if(log.isLoggable(Level.FINE))
log.fine("Checking outputs ${s}")

def o = s.find { it?.matches(wholeMatch) }
if(o)
return s.grep { it?.matches(wholeMatch) }

if(!o) {
o = s.find { it?.matches(pattern) }
if(o)
return s.grep { it?.matches(pattern) }
}
// return o
}
missingExts << origName
null
List<String> resolved = resolveInputFromExtension(pattern, origName, reverseOutputs)
if(resolved == null)
missingExts << origName
return resolved
}

if(missingExts && failIfNotFound)
Expand All @@ -326,6 +301,40 @@ class PipelineInput {
}
}


@CompileStatic
List<String> resolveInputFromExtension(String pattern, String origName, List<List<String>> reverseOutputs) {

String wholeMatch = '(^|^.*/)' + pattern + '$'

// Special case: treat a leading dot as a literal dot.
// ie: if the user specifies ".xml", they probably mean
// literally ".xml" and not "any character" + "xml"
if(pattern.startsWith("."))
pattern = "\\." + pattern.substring(1)

if(!pattern.startsWith("\\.") )
pattern = "\\." + pattern

pattern = '^.*' + pattern
log.info "Resolving inputs matching pattern $pattern"
for(s in reverseOutputs) {
if(log.isLoggable(Level.INFO))
log.info("Checking outputs ${s}")

String o = s.find { String p -> p?.matches(wholeMatch) }
if(o)
return s.grep { String p -> p?.matches(wholeMatch) }

if(!o) {
o = s.find { String p -> p?.matches(pattern) }
if(o)
return s.grep { String p -> p?.matches(pattern) }
}
}
return null
}

/**
* Compute a list of outputs from previous stages, in reverse order that they occurred
* in the pipeline, and includes the original inputs as the last stage. This "stack" of inputs
Expand All @@ -351,7 +360,12 @@ class PipelineInput {

// !this.is(it.context.@inputWrapper) && ( this.parent == null || !this.parent.is(it.context.@inputWrapper) )
}.collect { PipelineStage stage ->
Utils.box(stage.context.@output)

List outputs = Utils.box(stage.context.@output)
log.info "Outputs in search from $stage.stageName will be $outputs"
if(outputs.isEmpty() && stage.context.nextInputs != null)
outputs = Utils.box(stage.context.nextInputs)
return outputs
}

// Add a final stage that represents the original inputs (bit of a hack)
Expand Down

0 comments on commit 2f6eda7

Please sign in to comment.