Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-70261

Using customized class as Enum value fails as groovy script that works in script console fails

XMLWordPrintable

      Trying to use customized class as enum type value, below script works in script console, but hit below runtime error. Works fine when enum value is String array instead of ProductInfo array. 
      groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.vmware.vc.cicd.utils.WCPHelper$ProductInfo(java.lang.String, com.vmware.vc.cicd.utils.WCPHelper$InforType)
      at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1732)
      at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1532)
      at org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:49)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:255)
      // Value type available for Param Type
      enum InfoType

      {   BUILD_WEB,   URL,   STRING }

      // Name and value type available for ProductType
      class ProductInfo {
        String product
        InfoType type
        
        ProductInfo(product, type)

      {     this.product = product     this.type = type   }

      }

      // Product names whose value could be buildweb build or URL or any string type
      enum ProductType {
            AA_BUILD(new ProductInfo('test1', InfoType.BUILD_WEB),
                 new ProductInfo('test2', InfoType.BUILD_WEB)),
          BB_BUILD(new ProductInfo('test3', InfoType.BUILD_WEB)),
          CC_BUILD(new ProductInfo('test4', InfoType.BUILD_WEB),
                       new ProductInfo('test5', InfoType.BUILD_WEB),
                       new ProductInfo('test6', InfoType.URL))
        
          private ProductInfo[] productInfos
          
          ProductType(ProductInfo... productInfos)

      {         this.productInfos = productInfos     }

          
          public ProductInfo[] getProductInfos()

      {         return productInfos     }

      }

      productType = ProductType.CC_BUILD
      ProductInfo[] productInfos = productType.getProductInfos()
      boolean isValidParam = false
      productInfos.eachWithIndex

      { prdInfo, index ->   println prdInfo.type }

      Result

      BUILD_WEB
      BUILD_WEB
      URL
      Result: [LProductInfo;@398b1462

            szandala Tomasz Szandała
            anvivi99 Vivi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: