ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r893716 - in /ant/sandbox/antlibs/git/trunk: ./ docs/ src/ src/etc/ src/etc/testcases/ src/etc/testcases/antunit/ src/main/ src/main/org/ src/main/org/apache/ src/main/org/apache/ant/ src/main/org/apache/ant/git/ src/tests/ src/tests/junit/...
Date Thu, 24 Dec 2009 09:22:18 GMT
Author: kevj
Date: Thu Dec 24 09:22:15 2009
New Revision: 893716

URL: http://svn.apache.org/viewvc?rev=893716&view=rev
Log: (empty)

Added:
    ant/sandbox/antlibs/git/trunk/NOTICE
    ant/sandbox/antlibs/git/trunk/README
    ant/sandbox/antlibs/git/trunk/contributors.xml   (with props)
    ant/sandbox/antlibs/git/trunk/docs/
    ant/sandbox/antlibs/git/trunk/libraries.properties   (with props)
    ant/sandbox/antlibs/git/trunk/src/
    ant/sandbox/antlibs/git/trunk/src/etc/
    ant/sandbox/antlibs/git/trunk/src/etc/testcases/
    ant/sandbox/antlibs/git/trunk/src/etc/testcases/antunit/
    ant/sandbox/antlibs/git/trunk/src/etc/testcases/antunit/clone-au.xml   (with props)
    ant/sandbox/antlibs/git/trunk/src/etc/testcases/clone.xml   (with props)
    ant/sandbox/antlibs/git/trunk/src/main/
    ant/sandbox/antlibs/git/trunk/src/main/org/
    ant/sandbox/antlibs/git/trunk/src/main/org/apache/
    ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/
    ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/
    ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/AbstractGitTask.java   (with
props)
    ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Clone.java   (with props)
    ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Fetch.java   (with props)
    ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/antlib.xml   (with props)
    ant/sandbox/antlibs/git/trunk/src/tests/
    ant/sandbox/antlibs/git/trunk/src/tests/junit/
    ant/sandbox/antlibs/git/trunk/src/tests/junit/org/
    ant/sandbox/antlibs/git/trunk/src/tests/junit/org/apache/
    ant/sandbox/antlibs/git/trunk/src/tests/junit/org/apache/ant/
    ant/sandbox/antlibs/git/trunk/src/tests/junit/org/apache/ant/git/
    ant/sandbox/antlibs/git/trunk/src/tests/junit/org/apache/ant/git/AbstractGitTaskTest.java
  (with props)

Added: ant/sandbox/antlibs/git/trunk/NOTICE
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/NOTICE?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/NOTICE (added)
+++ ant/sandbox/antlibs/git/trunk/NOTICE Thu Dec 24 09:22:15 2009
@@ -0,0 +1,6 @@
+   Apache Git Ant Library
+   Copyright 2009-2010 The Apache Software Foundation
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+

Added: ant/sandbox/antlibs/git/trunk/README
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/README?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/README (added)
+++ ant/sandbox/antlibs/git/trunk/README Thu Dec 24 09:22:15 2009
@@ -0,0 +1,3 @@
+This library provides Ant task(s) as wrapper(s) over the git command
+line utility.
+

Added: ant/sandbox/antlibs/git/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/contributors.xml?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/contributors.xml (added)
+++ ant/sandbox/antlibs/git/trunk/contributors.xml Thu Dec 24 09:22:15 2009
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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.
+-->
+<!DOCTYPE contributors
+[
+<!ELEMENT name (first?, middle?, last)>
+<!ELEMENT contributors (introduction, name+)>
+<!ELEMENT first (#PCDATA)>
+<!ELEMENT introduction (#PCDATA)>
+<!ELEMENT middle (#PCDATA)>
+<!ELEMENT last (#PCDATA)>
+]
+>
+
+<contributors>
+  <introduction>
+  These are some of the many people who have helped with this Ant Library.
+  </introduction>
+  <name>
+    <first>Kevin</first>
+    <last>Jackson</last>
+  </name>
+</contributors>

Propchange: ant/sandbox/antlibs/git/trunk/contributors.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/sandbox/antlibs/git/trunk/libraries.properties
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/libraries.properties?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/libraries.properties (added)
+++ ant/sandbox/antlibs/git/trunk/libraries.properties Thu Dec 24 09:22:15 2009
@@ -0,0 +1,15 @@
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You 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.
+artifact.version=1.0-beta-SNAPSHOT
\ No newline at end of file

Propchange: ant/sandbox/antlibs/git/trunk/libraries.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/sandbox/antlibs/git/trunk/src/etc/testcases/antunit/clone-au.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/src/etc/testcases/antunit/clone-au.xml?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/src/etc/testcases/antunit/clone-au.xml (added)
+++ ant/sandbox/antlibs/git/trunk/src/etc/testcases/antunit/clone-au.xml Thu Dec 24 09:22:15
2009
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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.
+-->
+
+<project name="clone-test" basedir="../../../" 
+         default="all" xmlns:git="antlib:org.apache.ant.git" 
+         xmlns:au="antlib:org.apache.ant.antunit">
+
+  <property name="tmpdir" value="tmpdir"/>
+  <property name="file" value="build.xml"/>
+
+  <target name="setup">
+    <mkdir dir="${tmpdir}"/>
+  </target>
+
+  <target name="all" depends="setup">
+    <git:clone
+      gitRepo="git://github.com/apache/ant.git" dest="${tmpdir}"/>
+    <au:assertFileExists file="${tmpdir}/${file}"/>
+  </target>
+
+  <target name="cleanup">
+    <delete dir="${tmpdir}" />
+  </target>
+</project>

Propchange: ant/sandbox/antlibs/git/trunk/src/etc/testcases/antunit/clone-au.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/sandbox/antlibs/git/trunk/src/etc/testcases/clone.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/src/etc/testcases/clone.xml?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/src/etc/testcases/clone.xml (added)
+++ ant/sandbox/antlibs/git/trunk/src/etc/testcases/clone.xml Thu Dec 24 09:22:15 2009
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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.
+-->
+
+<project name="clone-test" basedir="../../../" 
+         default="all" xmlns:git="antlib:org.apache.ant.git">
+
+  <property name="tmpdir" value="tmpdir"/>
+  <property name="trunkdir" value="${tmpdir}/trunk"/>
+  <property name="file" value="build.xml"/>
+
+  <target name="setup">
+    <mkdir dir="${tmpdir}"/>
+  </target>
+
+  <target name="all" depends="setup">
+    <git:clone
+      gitRepo="git://github.com/apache/ant.git" dest="${tmpdir}"/>
+  </target>
+
+  <target name="cleanup">
+    <delete dir="${tmpdir}" />
+  </target>
+</project>

Propchange: ant/sandbox/antlibs/git/trunk/src/etc/testcases/clone.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/AbstractGitTask.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/AbstractGitTask.java?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/AbstractGitTask.java (added)
+++ ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/AbstractGitTask.java Thu Dec
24 09:22:15 2009
@@ -0,0 +1,556 @@
+package org.apache.ant.git;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.util.Vector;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
+import org.apache.tools.ant.taskdefs.LogOutputStream;
+import org.apache.tools.ant.taskdefs.PumpStreamHandler;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.Environment;
+import org.apache.tools.ant.util.StringUtils;
+
+public abstract class AbstractGitTask extends Task {
+	
+	private Commandline cmd = new Commandline();
+
+    /** list of Commandline children */
+    private Vector vecCommandlines = new Vector();
+    
+    /**
+     * Defaults to true
+     */
+    private boolean failOnError = true;
+   
+    private String gitRepo;
+
+    /**
+     * the revision
+     */
+    private String revision;
+    
+    /**
+     * the directory where the checked out files should be placed.
+     */
+    private File dest;
+    
+    /**
+     * suppress information messages.
+     */
+    private boolean quiet = false;
+
+    /**
+     * be verbose
+     */
+    private boolean verbose = false;
+
+    /**
+     * report only, don't change any files.
+     */
+    private boolean dryrun = false;
+
+    /** whether or not to append stdout/stderr to existing files */
+    private boolean append = false;
+
+    /**
+     * the file to direct standard output from the command.
+     */
+    private File output;
+
+    /**
+     * the file to direct standard error from the command.
+     */
+    private File error;
+    
+    /**
+     * 
+     */
+    private boolean recursive;
+    
+    private boolean force;
+    
+    
+    /**
+     * Create accessors for the following, to allow different handling of
+     * the output.
+     */
+    private ExecuteStreamHandler executeStreamHandler;
+    private OutputStream outputStream;
+    private OutputStream errorStream;
+    
+    public AbstractGitTask() {
+    	//no-op
+    }
+    
+    /**
+     * sets the handler
+     * @param handler a handler able of processing the output and error streams from the
svn exe
+     */
+    public void setExecuteStreamHandler(ExecuteStreamHandler handler) {
+        this.executeStreamHandler = handler;
+    }
+
+    /**
+     * find the handler and instantiate it if it does not exist yet
+     * @return handler for output and error streams
+     */
+    protected ExecuteStreamHandler getExecuteStreamHandler() {
+
+        if (this.executeStreamHandler == null) {
+            setExecuteStreamHandler(new PumpStreamHandler(getOutputStream(),
+                                                          getErrorStream()));
+        }
+
+        return this.executeStreamHandler;
+    }
+
+    /**
+     * sets a stream to which the output from the git executable should be sent
+     * @param outputStream stream to which the stdout from git should go
+     */
+    protected void setOutputStream(OutputStream outputStream) {
+
+        this.outputStream = outputStream;
+    }
+
+    /**
+     * access the stream to which the stdout from git should go
+     * if this stream has already been set, it will be returned
+     * if the stream has not yet been set, if the attribute output
+     * has been set, the output stream will go to the output file
+     * otherwise the output will go to ant's logging system
+     * @return output stream to which git's stdout should go to
+     */
+    protected OutputStream getOutputStream() {
+
+        if (this.outputStream == null) {
+
+            if (output != null) {
+                try {
+                    setOutputStream(new PrintStream(
+                                        new BufferedOutputStream(
+                                            new FileOutputStream(output
+                                                                 .getPath(),
+                                                                 append))));
+                } catch (IOException e) {
+                    throw new BuildException(e, getLocation());
+                }
+            } else {
+                setOutputStream(new LogOutputStream(this, Project.MSG_INFO));
+            }
+        }
+
+        return this.outputStream;
+    }
+
+    /**
+     * sets a stream to which the stderr from the svn exe should go
+     * @param errorStream an output stream willing to process stderr
+     */
+    protected void setErrorStream(OutputStream errorStream) {
+        this.errorStream = errorStream;
+    }
+
+    /**
+     * access the stream to which the stderr from git should go
+     * if this stream has already been set, it will be returned
+     * if the stream has not yet been set, if the attribute error
+     * has been set, the output stream will go to the file denoted by the error attribute
+     * otherwise the stderr output will go to ant's logging system
+     * @return output stream to which git's stderr should go to
+     */
+    protected OutputStream getErrorStream() {
+
+        if (this.errorStream == null) {
+
+            if (error != null) {
+
+                try {
+                    setErrorStream(new PrintStream(
+                                       new BufferedOutputStream(
+                                           new FileOutputStream(error.getPath(),
+                                                                append))));
+                } catch (IOException e) {
+                    throw new BuildException(e, getLocation());
+                }
+            } else {
+                setErrorStream(new LogOutputStream(this, Project.MSG_WARN));
+            }
+        }
+
+        return this.errorStream;
+    }
+    
+    /**
+     * Sets up the environment for toExecute and then runs it.
+     * @param toExecute the command line to execute
+     * @throws BuildException if failonError is set to true and the git command fails
+     */
+    protected void runCommand(Commandline toExecute) throws BuildException {
+        Environment env = new Environment();
+
+        //
+        // Just call the getExecuteStreamHandler() and let it handle
+        //     the semantics of instantiation or retrieval.
+        //
+        Execute exe = new Execute(getExecuteStreamHandler(), null);
+
+        exe.setAntRun(getProject());
+        if (dest == null) {
+            dest = getProject().getBaseDir();
+        }
+
+        if (!dest.exists()) {
+            dest.mkdirs();
+        }
+
+        exe.setWorkingDirectory(dest);
+        exe.setCommandline(toExecute.getCommandline());
+        exe.setEnvironment(env.getVariables());
+
+        try {
+            String actualCommandLine = executeToString(exe);
+            log(actualCommandLine, Project.MSG_VERBOSE);
+            int retCode = exe.execute();
+            log("retCode=" + retCode, Project.MSG_DEBUG);
+            if (failOnError && Execute.isFailure(retCode)) {
+                throw new BuildException("git exited with error code "
+                                         + retCode
+                                         + StringUtils.LINE_SEP
+                                         + "Command line was ["
+                                         + actualCommandLine + "]", getLocation());
+            }
+        } catch (IOException e) {
+            if (failOnError) {
+                throw new BuildException(e, getLocation());
+            } else {
+                log("Caught exception: " + e.getMessage(), Project.MSG_WARN);
+            }
+        } catch (BuildException e) {
+            if (failOnError) {
+                throw(e);
+            } else {
+                Throwable t = e.getException();
+                if (t == null) {
+                    t = e;
+                }
+                log("Caught exception: " + t.getMessage(), Project.MSG_WARN);
+            }
+        } catch (Exception e) {
+            if (failOnError) {
+                throw new BuildException(e, getLocation());
+            } else {
+                log("Caught exception: " + e.getMessage(), Project.MSG_WARN);
+            }
+        }
+    }
+
+    /**
+     * do the work
+     * @throws BuildException if failonerror is set to true and the git command fails.
+     */
+    public void execute() throws BuildException {
+
+        try {
+            for (int i = 0; i < vecCommandlines.size(); i++) {
+                this.runCommand((Commandline) vecCommandlines.elementAt(i));
+            }
+        } finally {
+            if (outputStream != null) {
+                try {
+                    outputStream.close();
+                } catch (IOException e) {
+                    //ignore
+                }
+            }
+            if (errorStream != null) {
+                try {
+                    errorStream.close();
+                } catch (IOException e) {
+                    //ignore
+                }
+            }
+        }
+    }
+    
+    private String executeToString(Execute execute) {
+
+        StringBuffer stringBuffer =
+            new StringBuffer(Commandline.describeCommand(execute
+                                                         .getCommandline()));
+
+        String newLine = StringUtils.LINE_SEP;
+        String[] variableArray = execute.getEnvironment();
+
+        if (variableArray != null) {
+            stringBuffer.append(newLine);
+            stringBuffer.append(newLine);
+            stringBuffer.append("environment:");
+            stringBuffer.append(newLine);
+            for (int z = 0; z < variableArray.length; z++) {
+                stringBuffer.append(newLine);
+                stringBuffer.append("\t");
+                stringBuffer.append(variableArray[z]);
+            }
+        }
+
+        return stringBuffer.toString();
+    }
+
+    /**
+     * The URL the subcommand should apply to.
+     *
+     * @param url the URL the subcommand should apply to.
+     */
+
+    public void setGitRepo(String url) {
+        if (url != null) {
+            if (url.trim().equals("")) {
+                url = null;
+            }
+        }
+        this.gitRepo = url;
+    }
+
+    /**
+     * access the repoURL variable
+     * @return repoURL
+     */
+    public String getGitRepo() {
+        return this.gitRepo;
+    }
+
+    /**
+     * revision
+     * @return revision
+     */
+    public String getRevision() {
+        return revision;
+    }
+
+    /**
+     * The revision to operate upon.
+     * @param p revision
+     */
+
+    public void setRevision(String p) {
+        // Check if not real revision => set it to null
+        if (p != null && p.trim().length() > 0) {
+            revision = p;
+            addSubCommandArgument("--revision");
+            addSubCommandArgument(p);
+        }
+    }
+
+    /**
+     * Forces a particular command or operation to run.
+     */
+    public void setForce(boolean force) {
+        this.force = force;
+    }
+
+    /**
+     * Forces a particular command or operation to run.
+     */
+    public boolean getForce() {
+        return force;
+    }
+    
+    /**
+     * Makes a subcommand recurse into subdirectories. Most
+     * subcommands recurse by default.
+     */
+    public void setRecursive(boolean recursive) {
+        this.recursive = recursive;
+    }
+
+    /**
+     * Makes a subcommand recurse into subdirectories. Most
+     * subcommands recurse by default.
+     */
+    public boolean getRecursive() {
+        return recursive;
+    }
+
+    /**
+     * This needs to be public to allow configuration
+     *      of commands externally.
+     * @param arg command argument
+     */
+    public void addSubCommandArgument(String arg) {
+        this.addSubCommandArgument(cmd, arg);
+    }
+
+    /**
+     * This method adds a command line argument to an external subcommand.
+     *
+     * @param c  command line to which one argument should be added
+     * @param arg argument to add
+     */
+    protected void addSubCommandArgument(Commandline c, String arg) {
+        c.createArgument().setValue(arg);
+    }
+
+    /**
+     * If true, suppress informational messages.
+     * @param q  if true, suppress informational messages
+     */
+    public void setQuiet(boolean q) {
+        quiet = q;
+    }
+
+    /**
+     * If true, be verbose.
+     * @param q  if true, be verbose.
+     */
+    public void setVerbose(boolean v) {
+        verbose = v;
+    }
+
+    /**
+     * The file to direct standard output from the command.
+     * @param output a file to which stdout should go
+     */
+    public void setOutput(File output) {
+        this.output = output;
+    }
+
+    /**
+     * The file to direct standard error from the command.
+     *
+     * @param error a file to which stderr should go
+     */
+    public void setError(File error) {
+        this.error = error;
+    }
+
+    /**
+     * Whether to append output/error when redirecting to a file.
+     * @param value true indicated you want to append
+     */
+    public void setAppend(boolean value) {
+        this.append = value;
+    }
+
+    /**
+     * Stop the build process if the command exits with
+     * a return code other than 0.
+     * Defaults to false.
+     * @param failOnError stop the build process if the command exits with
+     * a return code other than 0
+     */
+    public void setFailOnError(boolean failOnError) {
+        this.failOnError = failOnError;
+    }
+
+    /**
+     * Configure a commandline element for things like quiet, etc.
+     * @param c the command line which will be configured
+     * if the commandline is initially null, the function is a noop
+     * otherwise the function append to the commandline arguments concerning
+     * <ul>
+     * <li>
+     * quiet
+     * </li>
+     * <li>
+     * verbose
+     * </li>
+     * </ul>
+     */
+    protected void configureCommandline(Commandline c) {
+        if (c == null) {
+            return;
+        }
+        c.setExecutable("git");
+        if (quiet) {
+            c.createArgument(true).setValue("--quiet");
+        }
+        if (verbose) {
+            c.createArgument(true).setValue("--verbose");
+        }
+    }
+
+    /**
+     * remove a particular command from a vector of command lines
+     * @param c command line which should be removed
+     */
+    protected void removeCommandline(Commandline c) {
+        vecCommandlines.removeElement(c);
+    }
+    
+    /**
+     * Adds direct command-line to execute.
+     * @param c command line to execute
+     */
+    public void addConfiguredCommandline(Commandline c) {
+        this.addConfiguredCommandline(c, false);
+    }
+    
+    /**
+     * Configures and adds the given Commandline.
+     * @param c commandline to insert
+     * @param insertAtStart If true, c is
+     * inserted at the beginning of the vector of command lines
+     */
+    public void addConfiguredCommandline(Commandline c, boolean insertAtStart) {
+        if (c == null) {
+            return;
+        }
+        this.configureCommandline(c);
+        if (insertAtStart) {
+            vecCommandlines.insertElementAt(c, 0);
+        } else {
+            vecCommandlines.addElement(c);
+        }
+    }
+    
+    public boolean isDryrun() {
+		return dryrun;
+	}
+
+	public void setDryrun(boolean dryrun) {
+		this.dryrun = dryrun;
+	}
+
+	public File getDest() {
+		return dest;
+	}
+
+	public void setDest(File dest) {
+		this.dest = dest;
+	}
+
+	public boolean isQuiet() {
+		return quiet;
+	}
+
+	public boolean isVerbose() {
+		return verbose;
+	}
+
+	protected boolean validGitRepo() {
+    	// simply check the transport and ensure that it ends with .git
+    	if(this.gitRepo.startsWith("rsync://") ||
+    			this.gitRepo.startsWith("http://") ||
+    			this.gitRepo.startsWith("https://") ||
+    			this.gitRepo.startsWith("git://") ||
+    			this.gitRepo.startsWith("ssh://") ||
+    			this.gitRepo.startsWith("file://") ||
+    			this.gitRepo.startsWith("rsync") ||
+    			this.gitRepo.startsWith("/")) {
+    		if(this.gitRepo.endsWith(".git")) {
+    			return true;
+    		}
+    	} 
+    	return false;
+    }
+}

Propchange: ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/AbstractGitTask.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Clone.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Clone.java?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Clone.java (added)
+++ ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Clone.java Thu Dec 24 09:22:15
2009
@@ -0,0 +1,54 @@
+package org.apache.ant.git;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Commandline;
+
+public class Clone extends AbstractGitTask {
+
+	private boolean noCheckout;
+	private boolean bare;
+	
+	public void execute() throws BuildException {
+		validate();
+        Commandline c = new Commandline();
+        c.setExecutable("git");
+        c.createArgument(true).setValue("clone");
+        if(isNoCheckout()) {
+        	c.createArgument(false).setValue("--no-checkout");
+        }
+        if(isBare()) {
+        	c.createArgument(false).setValue("--bare");
+        }
+        c.createArgument(false).setValue(getGitRepo());
+        if (null != getDest()) {
+        	c.createArgument(false).setValue(getDest().getAbsolutePath());
+        }
+        this.addConfiguredCommandline(c);
+        super.execute();
+	}
+	
+	private void validate() throws BuildException {
+		if(null == getGitRepo()) {
+			throw new BuildException("You must specify a gitRepo value");
+		}
+		if(!validGitRepo()) {
+			throw new BuildException("The repository [ "+ getGitRepo()+ " ] specified is not recognised");
+		}
+	}
+	
+	public boolean isNoCheckout() {
+		return noCheckout;
+	}
+
+	public void setNoCheckout(boolean noCheckout) {
+		this.noCheckout = noCheckout;
+	}
+
+	public boolean isBare() {
+		return bare;
+	}
+
+	public void setBare(boolean bare) {
+		this.bare = bare;
+	}
+}

Propchange: ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Clone.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Fetch.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Fetch.java?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Fetch.java (added)
+++ ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Fetch.java Thu Dec 24 09:22:15
2009
@@ -0,0 +1,55 @@
+package org.apache.ant.git;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Commandline;
+
+public class Fetch extends AbstractGitTask {
+
+	private boolean prune = false;
+	private boolean noTags = false;
+	
+	public void execute() throws BuildException {
+		validate();
+        Commandline c = new Commandline();
+        c.setExecutable("git");
+        c.createArgument(true).setValue("fetch");
+        if(isDryrun()) {
+        	c.createArgument(false).setValue("--no-checkout");
+        }
+        if(isPrune()) {
+        	c.createArgument(false).setValue("--prune");
+        }
+        if(isNoTags()) {
+        	c.createArgument(false).setValue("--no-tags");
+        }
+        c.createArgument(false).setValue(getGitRepo());
+        this.addConfiguredCommandline(c);
+        super.execute();
+	}
+	
+	private void validate() throws BuildException {
+		if(null == getGitRepo()) {
+			throw new BuildException("You must specify a gitRepo value");
+		}
+		if(!validGitRepo()) {
+			throw new BuildException("The repository [ "+ getGitRepo()+ " ] specified is not recognised");
+		}
+	}
+
+	public boolean isPrune() {
+		return prune;
+	}
+
+	public void setPrune(boolean prune) {
+		this.prune = prune;
+	}
+
+	public boolean isNoTags() {
+		return noTags;
+	}
+
+	public void setNoTags(boolean noTags) {
+		this.noTags = noTags;
+	}
+	
+}

Propchange: ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/Fetch.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/antlib.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/antlib.xml?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/antlib.xml (added)
+++ ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/antlib.xml Thu Dec 24 09:22:15
2009
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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.
+-->
+<antlib>
+  <taskdef
+    name="clone"
+    classname="org.apache.ant.git.Clone"
+    />
+  <taskdef
+    name="fetch"
+    classname="org.apache.ant.git.Fetch"
+    />
+</antlib>

Propchange: ant/sandbox/antlibs/git/trunk/src/main/org/apache/ant/git/antlib.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ant/sandbox/antlibs/git/trunk/src/tests/junit/org/apache/ant/git/AbstractGitTaskTest.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/git/trunk/src/tests/junit/org/apache/ant/git/AbstractGitTaskTest.java?rev=893716&view=auto
==============================================================================
--- ant/sandbox/antlibs/git/trunk/src/tests/junit/org/apache/ant/git/AbstractGitTaskTest.java
(added)
+++ ant/sandbox/antlibs/git/trunk/src/tests/junit/org/apache/ant/git/AbstractGitTaskTest.java
Thu Dec 24 09:22:15 2009
@@ -0,0 +1,33 @@
+package org.apache.ant.git;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class AbstractGitTaskTest extends TestCase {
+	
+	//TODO - need to consider special cases like 'origin'
+	// or check .git/config for any short names
+	public void testValidGitRepo() {
+		String[] validRepos = {
+				"rsync://host.xz/path/to/repo.git",
+				"http://host.xz[:port]/path/to/repo.git",
+				"https://host.xz[:port]/path/to/repo.git",
+				"git://host.xz[:port]/path/to/repo.git",
+				"git://host.xz[:port]/~user/path/to/repo.git",
+				"ssh://[user@]host.xz[:port]/path/to/repo.git",
+				"ssh://[user@]host.xz/path/to/repo.git",
+				"ssh://[user@]host.xz/~user/path/to/repo.git",
+				"ssh://[user@]host.xz/~/path/to/repo.git"
+		};
+		TestGitTask t = new TestGitTask();
+		for(int i=0; i<validRepos.length;i++) {
+			t.setGitRepo(validRepos[i]);
+			Assert.assertTrue(t.validGitRepo());
+		}
+	}
+	
+	private class TestGitTask extends AbstractGitTask {
+		
+	}
+
+}

Propchange: ant/sandbox/antlibs/git/trunk/src/tests/junit/org/apache/ant/git/AbstractGitTaskTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message