// Path: src/main/java/org/jenkinsci/plugins/SemanticVersioning/columnDisplay/AbstractColumnDisplayStrategy.java
// public abstract class AbstractColumnDisplayStrategy extends ExtensionPoint implements ColumnDisplayStrategy {
//     public static ExtensionList<ColumnDisplayStrategy> getStrategies() {
//         return Jenkins.getActiveInstance().getExtensionList(ColumnDisplayStrategy.class);
//     }
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/SemanticVersioning/columnDisplay/ColumnDisplayStrategy.java
// public interface ColumnDisplayStrategy extends Describable<ColumnDisplayStrategy> {
//     String getDisplayString(Job job);
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/SemanticVersioning/columnDisplay/LastSuccessfulBuildStrategy.java
// @Extension
// public class LastSuccessfulBuildStrategy extends AbstractColumnDisplayStrategy {
// 
//     private static Logger logger = Logger.getLogger(String.valueOf(AppVersion.class));
// 
//     public String getDisplayString(Job job) {
//         String semanticVersion = null;
//         Run run = job.getLastSuccessfulBuild();
//         if (run == null) {
//             logger.info("LastSuccessfulBuildStrategy::getDisplayString -> last successful build not found.");
//             semanticVersion = Messages.UNKNOWN_VERSION;
//         } else {
//             String filename = run.getRootDir() + "/" + Messages.SEMANTIC_VERSION_FILENAME;
//             logger.info("LastSuccessfulBuildStrategy::getDisplayString -> last successful build found. Filename -> " + filename);
//             File file = new File(filename);
//             if (file.exists()) {
//                 try {
//                     semanticVersion = FileUtils.readFileToString(file);
//                     logger.info("LastSuccessfulBuildStrategy::getDisplayString -> read semantic version from file -> " + semanticVersion);
//                 } catch (IOException e) {
//                     logger.severe(e.toString());
//                 }
//             } else {
//                 logger.info("LastSuccessfulBuildStrategy::getDisplayString -> semanticVersion file not found.");
//                 semanticVersion = Messages.UNKNOWN_VERSION;
//             }
//         }
// 
//         return semanticVersion;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public Descriptor<ColumnDisplayStrategy> getDescriptor() {
//         return new AbstractDisplayStrategyDescription() {
//             @Override
//             public String getDisplayName() {
//                 return Messages.ColumnDisplayStrategies.LAST_SUCCESSFUL_BUILD_VERSION_STRATEGY;
//             }
//         };
//     }
// }


import hudson.views.ListViewColumnDescriptor;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.SemanticVersioning.columnDisplay.AbstractColumnDisplayStrategy;
import org.jenkinsci.plugins.SemanticVersioning.columnDisplay.ColumnDisplayStrategy;
import org.jenkinsci.plugins.SemanticVersioning.columnDisplay.LastSuccessfulBuildStrategy;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import java.io.IOException;
import java.util.logging.Logger;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.model.Descriptor;
import hudson.model.Job;
import hudson.util.ListBoxModel;
import hudson.views.ListViewColumn;
    public String getSemanticVersion(Job job) throws IOException, InterruptedException {
        ColumnDisplayStrategy strategy;
        if(job==null || job.getLastBuild()==null || job.getLastBuild().getResult()==null) {
        	return "-";
        }
        if(job.getLastBuild().getResult().ordinal == 0) {
            strategy = new LastSuccessfulBuildStrategy();
        } else {
            strategy = this.displayStrategy;
        }
        return strategy.getDisplayString(job);
    }

    @Extension(ordinal = 1.5)
    public static class SemanticVersionColumnDescriptor extends ListViewColumnDescriptor {
        @Override
        public boolean shownByDefault() {
            return false;
        }


        @Override
        public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
            String strategy = formData == null ? null : formData.optString("displayStrategy");
            return new SemanticVersionColumn(StringUtils.defaultIfBlank(strategy,
                    LastSuccessfulBuildStrategy.class.getCanonicalName()));
        }

        public ListBoxModel doFillDisplayStrategyItems() {
            ListBoxModel columnDisplayStrategies = new ListBoxModel();
// Path: src/main/java/org/jenkinsci/plugins/SemanticVersioning/columnDisplay/AbstractColumnDisplayStrategy.java
// public abstract class AbstractColumnDisplayStrategy extends ExtensionPoint implements ColumnDisplayStrategy {
//     public static ExtensionList<ColumnDisplayStrategy> getStrategies() {
//         return Jenkins.getActiveInstance().getExtensionList(ColumnDisplayStrategy.class);
//     }
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/SemanticVersioning/columnDisplay/ColumnDisplayStrategy.java
// public interface ColumnDisplayStrategy extends Describable<ColumnDisplayStrategy> {
//     String getDisplayString(Job job);
// }
// 
// Path: src/main/java/org/jenkinsci/plugins/SemanticVersioning/columnDisplay/LastSuccessfulBuildStrategy.java
// @Extension
// public class LastSuccessfulBuildStrategy extends AbstractColumnDisplayStrategy {
// 
//     private static Logger logger = Logger.getLogger(String.valueOf(AppVersion.class));
// 
//     public String getDisplayString(Job job) {
//         String semanticVersion = null;
//         Run run = job.getLastSuccessfulBuild();
//         if (run == null) {
//             logger.info("LastSuccessfulBuildStrategy::getDisplayString -> last successful build not found.");
//             semanticVersion = Messages.UNKNOWN_VERSION;
//         } else {
//             String filename = run.getRootDir() + "/" + Messages.SEMANTIC_VERSION_FILENAME;
//             logger.info("LastSuccessfulBuildStrategy::getDisplayString -> last successful build found. Filename -> " + filename);
//             File file = new File(filename);
//             if (file.exists()) {
//                 try {
//                     semanticVersion = FileUtils.readFileToString(file);
//                     logger.info("LastSuccessfulBuildStrategy::getDisplayString -> read semantic version from file -> " + semanticVersion);
//                 } catch (IOException e) {
//                     logger.severe(e.toString());
//                 }
//             } else {
//                 logger.info("LastSuccessfulBuildStrategy::getDisplayString -> semanticVersion file not found.");
//                 semanticVersion = Messages.UNKNOWN_VERSION;
//             }
//         }
// 
//         return semanticVersion;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public Descriptor<ColumnDisplayStrategy> getDescriptor() {
//         return new AbstractDisplayStrategyDescription() {
//             @Override
//             public String getDisplayName() {
//                 return Messages.ColumnDisplayStrategies.LAST_SUCCESSFUL_BUILD_VERSION_STRATEGY;
//             }
//         };
//     }
// }


// Path: src/main/java/org/jenkinsci/plugins/SemanticVersioning/SemanticVersionColumn.java
import hudson.views.ListViewColumnDescriptor;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.SemanticVersioning.columnDisplay.AbstractColumnDisplayStrategy;
import org.jenkinsci.plugins.SemanticVersioning.columnDisplay.ColumnDisplayStrategy;
import org.jenkinsci.plugins.SemanticVersioning.columnDisplay.LastSuccessfulBuildStrategy;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import java.io.IOException;
import java.util.logging.Logger;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.model.Descriptor;
import hudson.model.Job;
import hudson.util.ListBoxModel;
import hudson.views.ListViewColumn;

    public String getSemanticVersion(Job job) throws IOException, InterruptedException {
        ColumnDisplayStrategy strategy;
        if(job==null || job.getLastBuild()==null || job.getLastBuild().getResult()==null) {
        	return "-";
        }
        if(job.getLastBuild().getResult().ordinal == 0) {
            strategy = new LastSuccessfulBuildStrategy();
        } else {
            strategy = this.displayStrategy;
        }
        return strategy.getDisplayString(job);
    }

    @Extension(ordinal = 1.5)
    public static class SemanticVersionColumnDescriptor extends ListViewColumnDescriptor {
        @Override
        public boolean shownByDefault() {
            return false;
        }


        @Override
        public ListViewColumn newInstance(StaplerRequest req, JSONObject formData) throws FormException {
            String strategy = formData == null ? null : formData.optString("displayStrategy");
            return new SemanticVersionColumn(StringUtils.defaultIfBlank(strategy,
                    LastSuccessfulBuildStrategy.class.getCanonicalName()));
        }

        public ListBoxModel doFillDisplayStrategyItems() {
            ListBoxModel columnDisplayStrategies = new ListBoxModel();
            ExtensionList<ColumnDisplayStrategy> extensionList = AbstractColumnDisplayStrategy.getStrategies();