/** * Copyright (C) 2010-2017 Gordon Fraser, Andrea Arcuri and EvoSuite * contributors * * This file is part of EvoSuite. * * EvoSuite is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published * by the Free Software Foundation, either version 3.0 of the License, or * (at your option) any later version. * * EvoSuite 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 * Lesser Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with EvoSuite. If not, see <http://www.gnu.org/licenses/>. */ package org.evosuite.maven; import java.util.ArrayList; import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilder; import org.eclipse.aether.RepositorySystemSession; import org.evosuite.maven.util.EvoSuiteRunner; /** * Remove all local files created by EvoSuite so far */ @Mojo( name = "clean") public class CleanMojo extends AbstractMojo{ @Parameter(defaultValue = "${plugin.artifacts}", required = true, readonly = true) private List<Artifact> artifacts; @Component private ProjectBuilder projectBuilder; @Parameter(defaultValue="${repositorySystemSession}", required = true, readonly = true) private RepositorySystemSession repoSession; @Parameter(defaultValue = "${project}", required = true, readonly = true) private MavenProject project; @Override public void execute() throws MojoExecutionException,MojoFailureException{ getLog().info("Going to clean all EvoSuite data"); List<String> params = new ArrayList<>(); params.add("-continuous"); params.add("clean"); EvoSuiteRunner runner = new EvoSuiteRunner(getLog(),artifacts,projectBuilder,repoSession); runner.registerShutDownHook(); boolean ok = runner.runEvoSuite(project.getBasedir().toString(),params); if(!ok){ throw new MojoFailureException("Failed to correctly execute EvoSuite"); } } }