All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.ird.observe.maven.plugins.toolbox.GenerateValidatorMojoSupport Maven / Gradle / Ivy

There is a newer version: 4.34
Show newest version
package fr.ird.observe.maven.plugins.toolbox;

/*-
 * #%L
 * ObServe Toolkit :: Maven plugin
 * %%
 * Copyright (C) 2017 - 2020 IRD, Ultreia.io
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * .
 * #L%
 */

import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Optional;

/**
 * Created on 31/08/16.
 *
 * @author Tony Chemit - [email protected]
 */
public abstract class GenerateValidatorMojoSupport extends ToolboxMojoSupport implements ValidatorCacheRequest {

    @Parameter(defaultValue = "${project.build.directory}/generated-sources/java")
    private File generatedSourceRoot;

    @Parameter(defaultValue = "${project.basedir}/src/main/validators/validators.xml", required = true)
    private File validatorsFile;

    private Collection validators;

    @Override
    protected void init() throws Exception {

        if (isSkip()) {
            return;
        }

        super.init();

        validators = ValidatorsCache.get().getValidators(this);
    }

    @Override
    public Optional getExtraSourceRootPath() {
        return generatedSourceRoot.exists() ? Optional.of(generatedSourceRoot.toPath()) : Optional.empty();
    }

    @Override
    protected boolean checkSkip() {
        if (isSkip()) {
            getLog().info("Skipping goal (skip flag is on).");
            return false;
        }
        if (validators.isEmpty()) {
            getLog().info("Skipping goal (no validator detected).");
            return false;
        }

        return super.checkSkip();
    }

    protected abstract Path createOutputFile() throws IOException;

    protected abstract boolean isSkip();

    public Collection getValidators() {
        return validators;
    }

    @Override
    public URLClassLoader getUrlClassLoader() throws MalformedURLException {
        return initClassLoader(getProject(), validatorsFile.getParentFile(), false, true, true, true, true);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy