fr.ird.observe.maven.plugins.toolbox.GenerateValidatorMojoSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolbox-maven-plugin Show documentation
Show all versions of toolbox-maven-plugin Show documentation
ObServe Toolbox Maven plugin module
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();
loadValidators();
}
protected void loadValidators() throws IOException {
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);
}
}