From d72b69c30720ce53238cf814dfe0052eacf48f29 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Thu, 12 Dec 2024 18:37:54 +0100 Subject: [PATCH] Strengthen conda naming strategy Signed-off-by: Paolo Di Tommaso --- .../seqera/wave/util/ContainerHelper.groovy | 2 +- .../seqera/wave/util/NameVersionPair.groovy | 31 ++++++++++++++++--- .../wave/util/NameVersionPairTest.groovy | 8 +++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/main/groovy/io/seqera/wave/util/ContainerHelper.groovy b/src/main/groovy/io/seqera/wave/util/ContainerHelper.groovy index d2af92ffc..f56c46445 100644 --- a/src/main/groovy/io/seqera/wave/util/ContainerHelper.groovy +++ b/src/main/groovy/io/seqera/wave/util/ContainerHelper.groovy @@ -225,7 +225,7 @@ class ContainerHelper { return null } catch (Exception e) { - log.warn "Unable to infer conda recipe name - cause: ${e.message}", e + log.warn "Unable to infer conda recipe name - offending content:\n---\n${condaFileContent}", e return null } } diff --git a/src/main/groovy/io/seqera/wave/util/NameVersionPair.groovy b/src/main/groovy/io/seqera/wave/util/NameVersionPair.groovy index b38a5a629..4fb2b987c 100644 --- a/src/main/groovy/io/seqera/wave/util/NameVersionPair.groovy +++ b/src/main/groovy/io/seqera/wave/util/NameVersionPair.groovy @@ -33,8 +33,28 @@ class NameVersionPair { private static final String SUFFIX = 'pruned' private static final int MAX = 5 - Collection names - Collection versions + private Collection names + + private Collection versions + + protected NameVersionPair() { } + + NameVersionPair(Collection names) { + this.names = names + if( names==null ) + throw new IllegalArgumentException("Argument 'names' cannot be null") + if( !names ) + throw new IllegalArgumentException("Argument 'names' cannot be empty") + } + + NameVersionPair(Collection names, Collection versions) { + this(names) + this.versions = versions + } + + Collection getNames() { names } + + Collection getVersions() { versions } private List both() { final result = new ArrayList() @@ -46,8 +66,7 @@ class NameVersionPair { } String friendlyNames(String sep='_') { - if( !names ) - return null + assert names if( names.size()<=MAX ) return names.join(sep) else @@ -63,4 +82,8 @@ class NameVersionPair { else return new ArrayList<>(ret)[0..MAX-2].join(sep) + sep + SUFFIX } + + boolean asBoolean() { + return names + } } diff --git a/src/test/groovy/io/seqera/wave/util/NameVersionPairTest.groovy b/src/test/groovy/io/seqera/wave/util/NameVersionPairTest.groovy index b15244f71..3c5244c70 100644 --- a/src/test/groovy/io/seqera/wave/util/NameVersionPairTest.groovy +++ b/src/test/groovy/io/seqera/wave/util/NameVersionPairTest.groovy @@ -55,4 +55,12 @@ class NameVersionPairTest extends Specification { ['a','b','c','d','e','f'] | ['1','2','3','4','5'] | 'a_b_c_d_pruned' } + def 'should validate truth' () { + expect: + new NameVersionPair(names:['foo']) + and: + !new NameVersionPair(names:null) + !new NameVersionPair(names:[]) + } + }