Search in sources :

Example 1 with IoxPlugin

use of ch.interlis.iox_j.plugins.IoxPlugin in project gretl by sogis.

the class IliValidator method validate.

@TaskAction
public void validate() {
    log = LogEnvironment.getLogger(IliValidator.class);
    if (dataFiles == null) {
        return;
    }
    FileCollection dataFilesCollection = null;
    if (dataFiles instanceof FileCollection) {
        dataFilesCollection = (FileCollection) dataFiles;
    } else {
        dataFilesCollection = getProject().files(dataFiles);
    }
    if (dataFilesCollection == null || dataFilesCollection.isEmpty()) {
        return;
    }
    List<String> files = new ArrayList<String>();
    for (java.io.File fileObj : dataFilesCollection) {
        String fileName = fileObj.getPath();
        files.add(fileName);
    }
    Settings settings = new Settings();
    initSettings(settings);
    List<String> userFunctionList = new ArrayList<String>();
    userFunctionList.add("ch.so.agi.ilivalidator.ext.IsHttpResourceIoxPlugin");
    userFunctionList.add("ch.so.agi.ilivalidator.ext.AreaIoxPlugin");
    userFunctionList.add("ch.so.agi.ilivalidator.ext.LengthIoxPlugin");
    userFunctionList.add("ch.so.agi.ilivalidator.ext.IsValidDocumentsCycleIoxPlugin");
    userFunctionList.add("ch.so.agi.ilivalidator.ext.RingSelfIntersectionIoxPlugin");
    userFunctionList.add("ch.so.agi.ilivalidator.ext.TooFewPointsPolylineIoxPlugin");
    // userFunctionList.add("ch.so.agi.ilivalidator.ext.IsHttpResourceFromOerebMultilingualUriIoxPlugin");
    Map<String, Class> userFunctions = new HashMap<String, Class>();
    try {
        for (String userFunction : userFunctionList) {
            Class clazz = Class.forName(userFunction);
            IoxPlugin plugin = (IoxPlugin) clazz.newInstance();
            userFunctions.put(((InterlisFunction) plugin).getQualifiedIliName(), clazz);
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        log.info("Class not found");
    } catch (InstantiationException e) {
        e.printStackTrace();
        log.error("cannot instantiate class", e);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        log.error("Class not accessible", e);
    }
    settings.setTransientObject(ch.interlis.iox_j.validator.Validator.CONFIG_CUSTOM_FUNCTIONS, userFunctions);
    validationOk = new Validator().validate(files.toArray(new String[files.size()]), settings);
    if (!validationOk && failOnError) {
        throw new TaskExecutionException(this, new Exception("validation failed"));
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FileCollection(org.gradle.api.file.FileCollection) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) IoxPlugin(ch.interlis.iox_j.plugins.IoxPlugin) Settings(ch.ehi.basics.settings.Settings) Validator(org.interlis2.validator.Validator) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

Settings (ch.ehi.basics.settings.Settings)1 IoxPlugin (ch.interlis.iox_j.plugins.IoxPlugin)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 FileCollection (org.gradle.api.file.FileCollection)1 TaskAction (org.gradle.api.tasks.TaskAction)1 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)1 Validator (org.interlis2.validator.Validator)1