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

com.rimerosolutions.ant.git.tasks.CleanTask Maven / Gradle / Ivy

There is a newer version: 1.3.2
Show newest version
/*
 * Copyright 2013 Rimero Solutions
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.rimerosolutions.ant.git.tasks;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.jgit.api.CleanCommand;

import com.rimerosolutions.ant.git.AbstractGitRepoAwareTask;
import com.rimerosolutions.ant.git.GitBuildException;

/**
 * Git clean.
 *
 * 
{@code
 * 
 * 
 *   
 *   
 * 
 * }
* *

Git documentation about clean

*

JGit CleanCommand

* * @author Yves Zoundi */ public class CleanTask extends AbstractGitRepoAwareTask { private boolean dryRun = false; private boolean cleanDirectories = true; private boolean ignore = true; private Set pathList = new HashSet(); private static final String TASK_NAME = "git-clean"; @Override public String getName() { return TASK_NAME; } /** * If paths are set, only these paths are affected by the cleaning. * * @antdoc.notrequired * @param paths the paths to set */ public void setPaths(String paths) { if (paths != null && paths.trim().length() > 0) { String[] pathArray = paths.split(","); pathList.addAll(Arrays.asList(pathArray)); } } /** * If dirs is set, in addition to files, also clean directories. * * @antdoc.notrequired * @param cleanDirectories whether to clean directories too, or only files. (Default is true) */ public void setCleanDirectories(boolean cleanDirectories) { this.cleanDirectories = cleanDirectories; } /** * If ignore is set, don't report/clean files/directories that are ignored by a .gitignore. otherwise do handle them. * * @antdoc.notrequired * @param ignore whether to respect .gitignore or not. (Default value is true) */ public void setIgnore(boolean ignore) { this.ignore = ignore; } /** * If dryRun is set, the paths in question will not actually be deleted. * * @antdoc.notrequired * @param dryRun (Default value is false) */ public void setDryRun(boolean dryRun) { this.dryRun = dryRun; } @Override public void doExecute() { try { CleanCommand cleanCommand = git.clean(); if (!pathList.isEmpty()) { cleanCommand.setPaths(pathList); } cleanCommand.setDryRun(dryRun). setIgnore(ignore). setCleanDirectories(cleanDirectories). call(); } catch (Exception e) { throw new GitBuildException("Unexpected exception: " + e.getMessage(), e); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy