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

com.rimerosolutions.ant.git.tasks.AddTask 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 org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.resources.Union;
import org.eclipse.jgit.api.AddCommand;
import org.eclipse.jgit.api.errors.GitAPIException;

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

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

Git documentation about add

*

JGit AddCommand

* * @author Yves Zoundi */ public class AddTask extends AbstractGitRepoAwareTask { private static final String TASK_NAME = "git-patch"; private boolean update; private Union path; /** * If set to true, the command only matches filepattern against already tracked files in the index rather than the working tree. * * @antdoc.notrequired * @param update Default is false; */ public void setUpdate(boolean update) { this.update = update; } @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 { AddCommand addCommand = git.add().setUpdate(update); String prefix = getDirectory().getCanonicalPath(); String[] allFiles = getPath().list(); if (allFiles.length == 0) { return; } for (String file : allFiles) { String addedFile = translateFilePathUsingPrefix(file, prefix); addCommand.addFilepattern(addedFile); } addCommand.call(); } catch (GitAPIException e) { throw new GitBuildException(e); } catch (Exception e) { throw new GitBuildException("Unexpected error.", e); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy