org.apache.maven.dotnet.CleanMojo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-dotnet-plugin Show documentation
Show all versions of maven-dotnet-plugin Show documentation
A plugin that provides general build and test facilities for .Net projects and solutions
/*
* Maven and Sonar plugin for .Net
* Copyright (C) 2010 Jose Chillan and Alexandre Victoor
* mailto: [email protected] or [email protected]
*
* This program 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 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
/*
* Created on Jun 18, 2009
*/
package org.apache.maven.dotnet;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.dotnet.commons.project.ArtifactType;
import org.apache.maven.dotnet.commons.project.VisualStudioProject;
import org.apache.maven.dotnet.commons.project.VisualStudioSolution;
import org.apache.maven.dotnet.commons.project.WebVisualStudioProject;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;
import org.codehaus.plexus.util.FileUtils;
/**
* Cleans the build objects generated for a .Net project or solution
*
* @goal clean
* @phase clean
* @description clean the build object of a .Net project or solution
* @author Jose CHILLAN Apr 9, 2009
*/
public class CleanMojo extends AbstractDotNetBuildMojo {
@Override
protected void executeProject(VisualStudioProject visualProject)
throws MojoExecutionException, MojoFailureException {
// Cannot clean a web project alone
if (visualProject.getType() != ArtifactType.WEB) {
File csprojFile = visualProject.getProjectFile();
launchClean(csprojFile);
}
}
@Override
protected void executeSolution(VisualStudioSolution visualSolution)
throws MojoExecutionException, MojoFailureException {
File solutionFile = visualSolution.getSolutionFile();
launchClean(solutionFile);
}
/**
* Launches the cleaning of a project or solution
*
* @param file
* the project or solution file
* @throws MojoExecutionException
* @throws MojoFailureException
*/
public void launchClean(File file) throws MojoExecutionException,
MojoFailureException {
File executable = getMsBuildCommand();
Log log = getLog();
log.info("Launching the cleaning of " + file);
log.debug(" - Tool Version : " + toolVersion);
log.debug(" - MsBuild exe : " + executable);
// ASP.NET precompiled directory clean-up
List visualStudioProjects = getVisualSolution()
.getProjects();
for (VisualStudioProject visualStudioProject : visualStudioProjects) {
if (visualStudioProject instanceof WebVisualStudioProject) {
WebVisualStudioProject webProject = (WebVisualStudioProject) visualStudioProject;
log.info("Cleaning precompiled asp.net dlls for project " + webProject);
List configurations = getBuildConfigurations();
for (String configuration : configurations) {
File precompilationDirectory = webProject.getWebPrecompilationDirectory(configuration);
try {
if (precompilationDirectory!=null && precompilationDirectory.exists()) {
FileUtils.cleanDirectory(precompilationDirectory);
}
} catch (IOException e) {
throw new MojoExecutionException("error while cleaning web project "
+ visualStudioProject, e);
}
}
}
}
// We clean all configurations
List configurations = getBuildConfigurations();
for (String configuration : configurations) {
// Launches the clean for each configuration
List arguments = new ArrayList();
arguments.add(toCommandPath(file));
arguments.add("/t:Clean");
arguments.add("/p:Configuration=" + configuration);
// We launch the compile command (the logs are put in debug because they
// may be verbose)
launchCommand(executable, arguments, "clean", 0);
}
log.info("Cleaning done!");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy