Groovy web console

subscribe to the feed Subscribe
to this
site

Version Enum

Published 3 months ago by VE
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
class Main {                                    
    static void main(String... args) {          
        println 'Start'
        try{
            //println Languages.valueOf("java2").getLanguage()
            println PipelineVersion.getEnumByVersion("2.0")
        }
        catch(Exception e){
            println e;
        }
    }

    enum Languages {  
       java("java"), dotnet("dotnet");

       public Languages(String language) {
         this.language = language;
       }

       private final String language;

       public String getLanguage() {
         return language;
       }

    }

    enum PipelineVersion{  
       v1_0("1.0"), v2_0("2.0");

       public PipelineVersion(String version) {
         this.version= version;
       }

       private final String version;

       public String getVersion() {
         return version;
       }

       public static String getEnumByVersion(String version){        
            for(PipelineVersion e : PipelineVersion.values()){   
               if(version.equals(e.version)) return e.name();         
            }     
            //return default version or null
            return PipelineVersion.v1_0;     
        }
    }

   
    class ParamStore {  
        private final String language = "java"; // Simulo la stringa letta da config.yaml
        private final def context;
        private Languages l;

         ParamStore(context){
          this.context = context;
         }

         def store(){
            try{
                this.l = Languages.valueOf(language);
            }
            catch(Exception e){
               this.l = Languages.java;
            }
            this.context.env.LANGUAGE = this.l.getLanguage();
        }
    }
}