package com.boissinot.jenkins.csvexporter.service;

/**
 * @author Gregory Boissinot
 */
public class FunctionalJobTypeRetriever {

    public static enum JOB_TYPE {

        CPP("CPP", "BUILD"),
        CPP_RELEASE("CPP", "RELEASE"),
        CPP_REPORT("CPP", "REPORT"),
        JAR("JAR", "BUILD"),
        JAR_RELEASE("JAR", "RELEASE"),
        TEMPLATE("GENERIC", "TEMPLATE"),
        PKG("ANY", "PACKAGING"),
        MAVEN_PLUGIN("JAVA", "PLUGIN"),
        OTHER("GENERIC", "NOT DETERMINED");

        private String language;

        private String type;

        private JOB_TYPE(String language, String type) {
            this.language = language;
            this.type = type;
        }

        public String getLanguage() {
            return language;
        }

        public String getType() {
            return type;
        }
    }

    public JOB_TYPE getJobType(String jobName) {
        if (jobName == null) {
            return null;
        }

        if (jobName.contains("template")) {
            return JOB_TYPE.TEMPLATE;
        }

        if (jobName.contains("PKG") || jobName.contains("packaging")) {
            return JOB_TYPE.PKG;
        }

        if (jobName.contains("plugin")) {
            return JOB_TYPE.MAVEN_PLUGIN;
        }

        if (jobName.contains("NAR_RELEASE_REPORT")) {
            return JOB_TYPE.CPP_REPORT;
        }

        if (jobName.contains("NAR_RELEASE")) {
            return JOB_TYPE.CPP_RELEASE;
        }

        if (jobName.contains("NAR")) {
            return JOB_TYPE.CPP;
        }

        if (jobName.contains("JAR_RELEASE")) {
            return JOB_TYPE.JAR_RELEASE;
        }

        if (jobName.contains("JAR")) {
            return JOB_TYPE.JAR;
        }

        return JOB_TYPE.OTHER;
    }


}

@@ -45,16 +45,85 @@
 rvice;%0A%0A
+import com.boissinot.jenkins.csvexporter.exception.ExportException;%0A%0A
 /**%0A * @
@@ -394,32 +394,100 @@
 R%22, %22RELEASE%22),%0A
+        WAR(%22WAR%22, %22BUILD%22),%0A        WAR_RELEASE(%22WAR%22, %22RELEASE%22),%0A
         TEMPLATE
@@ -552,22 +552,16 @@
         
-MAVEN_
 PLUGIN(%22
@@ -1022,24 +1022,25 @@
  jobName) %7B%0A
+%0A
         if (
@@ -1074,19 +1074,194 @@
     
-return null
+throw new ExportException(%22You must give a non empty job name.%22);%0A        %7D%0A%0A        if (jobName.isEmpty()) %7B%0A            throw new ExportException(%22You must give a non empty job name.%22)
 ;%0A  
@@ -1309,16 +1309,48 @@
 mplate%22)
+ %7C%7C jobName.contains(%22TEMPLATE%22)
 ) %7B%0A    
@@ -1548,16 +1548,46 @@
 plugin%22)
+ %7C%7C jobName.contains(%22PLUGIN%22)
 ) %7B%0A    
@@ -1614,20 +1614,111 @@
 YPE.
-MAVEN_
 PLUGIN
+;%0A        %7D%0A%0A        if (jobName.contains(%22NAR_REPORT%22)) %7B%0A            return JOB_TYPE.CPP_REPORT
 ;%0A  
@@ -2187,32 +2187,214 @@
 JAR;%0A        %7D%0A%0A
+        if (jobName.contains(%22WAR_RELEASE%22)) %7B%0A            return JOB_TYPE.WAR_RELEASE;%0A        %7D%0A%0A        if (jobName.contains(%22WAR%22)) %7B%0A            return JOB_TYPE.WAR;%0A        %7D%0A%0A
         return J

Fix Job Type