Skip to content

Commit

Permalink
Add warning on publish with a null var
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Apr 10, 2019
1 parent b2cfb66 commit 7d58bfb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,14 @@ class PublishDir {

private String stageInMode

private boolean nullPathWarn

void setPath( Closure obj ) {
setPath( obj.call() as Path )
}

void setPath( String str ) {
nullPathWarn = checkNull(str)
setPath(str as Path)
}

Expand All @@ -108,6 +111,10 @@ class PublishDir {
this.mode = mode
}

@PackageScope boolean checkNull(String str) {
( str =~ /\bnull\b/ ).find()
}

/**
* Object factory method
*
Expand Down Expand Up @@ -154,6 +161,9 @@ class PublishDir {
if( !path )
throw new IllegalStateException("Target path for directive publishDir cannot be null")

if( nullPathWarn )
log.warn "Process `$task.processor.name` publishDir path contains a variable with a null value"

this.processor = task.processor
this.sourceDir = task.targetDir
this.sourceFileSystem = sourceDir.fileSystem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,15 @@ class PublishDirTest extends Specification {
then:
publisher.mode == PublishDir.Mode.COPY
}

def 'should check null path' () {
given:
def pub = new PublishDir()

expect:
!pub.checkNull('ciao')
pub.checkNull('null')
pub.checkNull('null-x')
pub.checkNull(' null')
}
}

0 comments on commit 7d58bfb

Please sign in to comment.