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

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

There is a newer version: 1.3.2
Show newest version
/*
 * Copyright 2014 Antoine Levy-Lambert, 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 org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.resources.Union;
import org.eclipse.jgit.api.RmCommand;
import org.eclipse.jgit.api.errors.GitAPIException;

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

/**
 * Delete files.
 *
 * 
{@code
 *  
 *    
 *      
 * 
 *  }
* *

Git documentation about rm

*

JGit RmCommand

* * @author Antoine Levy-Lambert */ public class RmTask extends AbstractGitRepoAwareTask { private static final String TASK_NAME = "git-rm"; private Union path; @Override public String getName() { return TASK_NAME; } /** * Configure the fileset(s) of files to add to revision control * * @param fileset The fileset to add */ public void addFileset(FileSet fileset) { getPath().add(fileset); } private synchronized Union getPath() { if (path == null) { path = new Union(); path.setProject(getProject()); } return path; } @Override protected void doExecute() { try { RmCommand rmCommand = git.rm(); String prefix = getDirectory().getCanonicalPath(); String[] allFiles = getPath().list(); if (allFiles.length == 0) { return; } for (String file : allFiles) { String addedFile = translateFilePathUsingPrefix(file, prefix); rmCommand.addFilepattern(addedFile); } rmCommand.call(); } catch (GitAPIException e) { throw new GitBuildException(e); } catch (Exception e) { throw new GitBuildException("Unexpected error.", e); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy