// Path: src/main/java/ch/sbb/maven/plugins/iib/utils/ConfigurationValidator.java
// public static void validateUseClassloaders(Boolean useClassloaders, Log log) throws MojoFailureException
// {
//     if (useClassloaders == null)
//     {
//         logErrorStart(log);
//         String[] messages = { getArgumentMissingString("useClassloaders") };
//         logErrorBaseProblem(log, messages);
// 
//         String tagName = "useClassloaders";
//         String exampleText = "false";
//         String exampleTagString = getExampleTagString(tagName, exampleText);
//         logErrorExample(log, new String[] { exampleTagString });
// 
//         String[] instructions = new String[] {
//                 "'useClassLoaders' indicates whether classloaders are in use with this bar;",
//                 "false adds dependent jars into workspace META-INF dir; true does not; ",
//                 "both true and false will unpack dependent jar resources.",
//                 "This also comes into play in the Bar Override process."
// 
//         };
// 
//         logErrorInstructions(log, instructions);
// 
//         logErrorFinish(log);
// 
//         throw new MojoFailureException(getArgumentMissingString("useClassloaders"));
//     }
// }
// 
// Path: src/main/java/ch/sbb/maven/plugins/iib/utils/ConfigurableProperties.java
// @SuppressWarnings("serial")
// public final class ConfigurableProperties extends TreeMap<String, String> {
// 
//     /**
//      * returns a list of properties where the propName ends with .javaClassLoader
//      * 
//      * @param configurableProperties
//      * @return
//      */
//     public static List<String> getJavaClassLoaderProperties(List<String> configurableProperties) {
//         List<String> clProps = new ArrayList<String>();
//         for (String propEntry : configurableProperties) {
//             if (getPropName(propEntry).endsWith(".javaClassLoader")) {
//                 clProps.add(propEntry);
//             }
//         }
// 
//         return clProps;
//     }
// 
//     public static List<String> getPropNames(List<String> configurableProperties) {
//         List<String> propNames = new ArrayList<String>();
//         for (String confProp : configurableProperties) {
//             // use the value up to an equals sign if present
//             propNames.add(getPropName(confProp));
//         }
//         return propNames;
//     }
// 
//     public static String getPropName(String configurablePropertyEntry) {
//         // use the value up to an equals sign if present
//         return (configurablePropertyEntry.split("=")[0]).trim();
//     }
// 
//     public static String getPropValue(String configurablePropertyEntry) {
//         // use the value up to an equals sign if present
//         if (configurablePropertyEntry.split("=").length == 2) {
//             return (configurablePropertyEntry.split("=")[1]).trim();
//         }
//         return "";
//     }
// 
// 
//     public void load(File file) throws IOException {
// 
//         // empty the existing data
//         this.clear();
// 
//         // read the file line by line, adding it to the existing data
//         LineIterator iterator = FileUtils.lineIterator(file, "UTF-8");
//         try {
//             while (iterator.hasNext()) {
//                 String line = iterator.nextLine();
// 
//                 String key;
//                 String value;
// 
//                 Integer equalsPos = line.indexOf("=");
// 
//                 // if there is no "=", only the key is present
//                 if (equalsPos == -1) {
//                     key = line.trim();
//                     value = "";
//                 } else {
//                     // there is an "=" present, so split out the key & value
//                     key = line.substring(0, equalsPos).trim();
//                     value = line.substring(equalsPos + 1).trim();
//                 }
//                 this.put(key, value);
//             }
//         } finally {
//             LineIterator.closeQuietly(iterator);
//         }
//     }
// 
//     public void save(File file) throws IOException {
// 
//         List<String> lines = new ArrayList<String>();
// 
//         for (Map.Entry<String, String> entry : this.entrySet()) {
//             String line = entry.getKey();
//             String value = entry.getValue();
//             if (value != null && value.length() > 0) {
//                 line = line + " = " + value;
//             }
//             lines.add(line);
//         }
// 
//         FileUtils.writeLines(file, lines);
//     }
// 
// }


import static ch.sbb.maven.plugins.iib.utils.ConfigurationValidator.validateUseClassloaders;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import ch.sbb.maven.plugins.iib.utils.ConfigurableProperties;
package ch.sbb.maven.plugins.iib.mojos;





/**
 * Goal which reads the default.properties file to figure out if the classloader approach for this bar project is consistent. Either all jar nodes in all flows must use a classloader or none of them
 * should.
 */
@Mojo(name = "validate-classloader-approach")
public class ValidateClassloaderApproachMojo extends AbstractMojo {

    /**
     * The name of the default properties file to be generated from the bar file.
     */
    @Parameter(property = "iib.defaultPropertiesFile", defaultValue = "${project.build.directory}/default.properties", required = true)
    protected File defaultPropertiesFile;

    /**
     * Whether or not to fail the build if the classloader approach is invalid.
     */
    @Parameter(property = "iib.failOnInvalidClassloader", defaultValue = "true", required = true)
    protected Boolean failOnInvalidClassloader;

    /**
     * Whether classloaders are in use with this bar
     */
    @Parameter(property = "iib.useClassloaders")
    protected Boolean useClassloaders;

    public void execute() throws MojoFailureException {

// Path: src/main/java/ch/sbb/maven/plugins/iib/utils/ConfigurationValidator.java
// public static void validateUseClassloaders(Boolean useClassloaders, Log log) throws MojoFailureException
// {
//     if (useClassloaders == null)
//     {
//         logErrorStart(log);
//         String[] messages = { getArgumentMissingString("useClassloaders") };
//         logErrorBaseProblem(log, messages);
// 
//         String tagName = "useClassloaders";
//         String exampleText = "false";
//         String exampleTagString = getExampleTagString(tagName, exampleText);
//         logErrorExample(log, new String[] { exampleTagString });
// 
//         String[] instructions = new String[] {
//                 "'useClassLoaders' indicates whether classloaders are in use with this bar;",
//                 "false adds dependent jars into workspace META-INF dir; true does not; ",
//                 "both true and false will unpack dependent jar resources.",
//                 "This also comes into play in the Bar Override process."
// 
//         };
// 
//         logErrorInstructions(log, instructions);
// 
//         logErrorFinish(log);
// 
//         throw new MojoFailureException(getArgumentMissingString("useClassloaders"));
//     }
// }
// 
// Path: src/main/java/ch/sbb/maven/plugins/iib/utils/ConfigurableProperties.java
// @SuppressWarnings("serial")
// public final class ConfigurableProperties extends TreeMap<String, String> {
// 
//     /**
//      * returns a list of properties where the propName ends with .javaClassLoader
//      * 
//      * @param configurableProperties
//      * @return
//      */
//     public static List<String> getJavaClassLoaderProperties(List<String> configurableProperties) {
//         List<String> clProps = new ArrayList<String>();
//         for (String propEntry : configurableProperties) {
//             if (getPropName(propEntry).endsWith(".javaClassLoader")) {
//                 clProps.add(propEntry);
//             }
//         }
// 
//         return clProps;
//     }
// 
//     public static List<String> getPropNames(List<String> configurableProperties) {
//         List<String> propNames = new ArrayList<String>();
//         for (String confProp : configurableProperties) {
//             // use the value up to an equals sign if present
//             propNames.add(getPropName(confProp));
//         }
//         return propNames;
//     }
// 
//     public static String getPropName(String configurablePropertyEntry) {
//         // use the value up to an equals sign if present
//         return (configurablePropertyEntry.split("=")[0]).trim();
//     }
// 
//     public static String getPropValue(String configurablePropertyEntry) {
//         // use the value up to an equals sign if present
//         if (configurablePropertyEntry.split("=").length == 2) {
//             return (configurablePropertyEntry.split("=")[1]).trim();
//         }
//         return "";
//     }
// 
// 
//     public void load(File file) throws IOException {
// 
//         // empty the existing data
//         this.clear();
// 
//         // read the file line by line, adding it to the existing data
//         LineIterator iterator = FileUtils.lineIterator(file, "UTF-8");
//         try {
//             while (iterator.hasNext()) {
//                 String line = iterator.nextLine();
// 
//                 String key;
//                 String value;
// 
//                 Integer equalsPos = line.indexOf("=");
// 
//                 // if there is no "=", only the key is present
//                 if (equalsPos == -1) {
//                     key = line.trim();
//                     value = "";
//                 } else {
//                     // there is an "=" present, so split out the key & value
//                     key = line.substring(0, equalsPos).trim();
//                     value = line.substring(equalsPos + 1).trim();
//                 }
//                 this.put(key, value);
//             }
//         } finally {
//             LineIterator.closeQuietly(iterator);
//         }
//     }
// 
//     public void save(File file) throws IOException {
// 
//         List<String> lines = new ArrayList<String>();
// 
//         for (Map.Entry<String, String> entry : this.entrySet()) {
//             String line = entry.getKey();
//             String value = entry.getValue();
//             if (value != null && value.length() > 0) {
//                 line = line + " = " + value;
//             }
//             lines.add(line);
//         }
// 
//         FileUtils.writeLines(file, lines);
//     }
// 
// }


// Path: src/main/java/ch/sbb/maven/plugins/iib/mojos/ValidateClassloaderApproachMojo.java
import static ch.sbb.maven.plugins.iib.utils.ConfigurationValidator.validateUseClassloaders;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import ch.sbb.maven.plugins.iib.utils.ConfigurableProperties;

package ch.sbb.maven.plugins.iib.mojos;





/**
 * Goal which reads the default.properties file to figure out if the classloader approach for this bar project is consistent. Either all jar nodes in all flows must use a classloader or none of them
 * should.
 */
@Mojo(name = "validate-classloader-approach")
public class ValidateClassloaderApproachMojo extends AbstractMojo {

    /**
     * The name of the default properties file to be generated from the bar file.
     */
    @Parameter(property = "iib.defaultPropertiesFile", defaultValue = "${project.build.directory}/default.properties", required = true)
    protected File defaultPropertiesFile;

    /**
     * Whether or not to fail the build if the classloader approach is invalid.
     */
    @Parameter(property = "iib.failOnInvalidClassloader", defaultValue = "true", required = true)
    protected Boolean failOnInvalidClassloader;

    /**
     * Whether classloaders are in use with this bar
     */
    @Parameter(property = "iib.useClassloaders")
    protected Boolean useClassloaders;

    public void execute() throws MojoFailureException {

        validateUseClassloaders(useClassloaders, getLog());