org.openwebtop.maven.plugins.precheck.EnvironmentCheckerMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-precheck-plugin Show documentation
Show all versions of maven-precheck-plugin Show documentation
Webwork configuration & Prohibit text pre-check plugin
/**
* Copyright (C) 2010 Jaehyeon Nam ([email protected])
*
* 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 .
*/
package org.openwebtop.maven.plugins.precheck;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.DirectoryScanner;
import org.openwebtop.maven.plugins.precheck.environment.EnvironmentChecker;
import org.openwebtop.maven.plugins.precheck.environment.model.Environment;
import org.openwebtop.maven.plugins.precheck.environment.model.EnvironmentError;
import org.openwebtop.maven.plugins.precheck.environment.model.EnvironmentFiles;
/**
* Environment Checker
*
* @author Jaehyeon Nam
* @since 2010. 10. 8.
* @goal environment
* @phase process-resources
*/
public class EnvironmentCheckerMojo extends AbstractPrecheckMojo {
private final static String GOAL_NAME = "enviroment";
/**
* Environment checker configuration
*
* @parameter
*/
private Environment[] environments;
@Override
public String getGoalName() {
return GOAL_NAME;
}
@Override
public void onExecute() throws MojoExecutionException, MojoFailureException {
if (ArrayUtils.isEmpty(environments)) {
printInfoLog("There is no configuration for checking environment. skipping...");
return;
}
final List environmentErrors = new ArrayList();
for (Environment environment : environments) {
final EnvironmentChecker environmentChecker = new EnvironmentChecker();
environmentChecker.setExtractRegExp(environment.getExtractRegExp());
environmentChecker.setCheckTargetFiles(getFilelist(environment.getCheckTarget()));
environmentChecker.setCheckSourceFiles(getFilelist(environment.getCheckSource()));
try {
environmentErrors.addAll(environmentChecker.check());
} catch (IOException e) {
throw new MojoFailureException("Cannot scan some files!");
}
}
if (CollectionUtils.isNotEmpty(environmentErrors)) {
for (EnvironmentError environmentError : environmentErrors) {
printInfoLog(environmentError.toString());
}
throw new MojoFailureException(String.format("%d files have been detected!", environmentErrors.size()));
}
}
private File[] getFilelist(EnvironmentFiles environmentFiles) {
final DirectoryScanner directoryScanner = new DirectoryScanner();
directoryScanner.setBasedir(environmentFiles.getBasedir());
directoryScanner.setIncludes(environmentFiles.getIncludes());
directoryScanner.setExcludes(environmentFiles.getExcludes());
directoryScanner.scan();
final String[] filelist = directoryScanner.getIncludedFiles();
final List files = new ArrayList();
for (String filename : filelist) {
files.add(new File(environmentFiles.getBasedir() + File.separator + filename));
}
return files.toArray(new File[0]);
}
public void setEnvironments(Environment[] environments) {
this.environments = environments;
}
}