PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/maven-amps-plugin/src/main/java/com/atlassian/maven/plugins/amps/util/ant/DefaultAntTaskFactory.java

https://bitbucket.org/mmeinhold/amps
Java | 102 lines | 38 code | 8 blank | 56 comment | 2 complexity | f6d64cb634f4dbe703b84d8d8384db85 MD5 | raw file
  1/*
  2 * ========================================================================
  3 *
  4 * Copyright 2003-2004 The Apache Software Foundation. Code from this file
  5 * was originally imported from the Jakarta Cactus project.
  6 *
  7 * Codehaus CARGO, copyright 2004-2010 Vincent Massol.
  8 *
  9 * Licensed under the Apache License, Version 2.0 (the "License");
 10 * you may not use this file except in compliance with the License.
 11 * You may obtain a copy of the License at
 12 *
 13 *   http://www.apache.org/licenses/LICENSE-2.0
 14 *
 15 * Unless required by applicable law or agreed to in writing, software
 16 * distributed under the License is distributed on an "AS IS" BASIS,
 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 18 * See the License for the specific language governing permissions and
 19 * limitations under the License.
 20 *
 21 * ========================================================================
 22 */
 23package com.atlassian.maven.plugins.amps.util.ant;
 24
 25import org.apache.tools.ant.Location;
 26import org.apache.tools.ant.Project;
 27import org.apache.tools.ant.Target;
 28import org.apache.tools.ant.Task;
 29
 30/**
 31 * Default {@link AntTaskFactory} for creating Ant tasks.
 32 *
 33 * @version $Id$
 34 */
 35public class DefaultAntTaskFactory implements AntTaskFactory
 36{
 37    /**
 38     * The current {@link org.apache.tools.ant.Project} being executed.
 39     */
 40    private Project currentProject;
 41
 42    /**
 43     * The current Ant task being executed.
 44     */
 45    private String currentTaskName;
 46
 47    /**
 48     * The current {@link org.apache.tools.ant.Location} of the Task being executed.
 49     */
 50    private Location currentLocation;
 51
 52    /**
 53     * The current {@link org.apache.tools.ant.Target} being executed.
 54     */
 55    private Target currentOwningTarget;
 56
 57    /**
 58     * Constructor using default values for the current task name, current location and current
 59     * target.
 60     *
 61     * @param project the Ant project used when creating Ant tasks
 62     */
 63    public DefaultAntTaskFactory(Project project)
 64    {
 65        this.currentProject = project;
 66        this.currentTaskName = "cargo";
 67        this.currentLocation = new Location("in cargo code");
 68        this.currentOwningTarget = new Target();
 69    }
 70
 71    /**
 72     * @param project the Ant project used when creating Ant tasks
 73     * @param currentTaskName the current Ant task being executed
 74     * @param currentLocation the current {@link org.apache.tools.ant.Location} of the Task being
 75     *        executed.
 76     * @param currentTarget the current {@link org.apache.tools.ant.Target} being executed
 77     */
 78    public DefaultAntTaskFactory(Project project, String currentTaskName, Location currentLocation,
 79        Target currentTarget)
 80    {
 81        this.currentProject = project;
 82        this.currentTaskName = currentTaskName;
 83        this.currentLocation = currentLocation;
 84        this.currentOwningTarget = currentTarget;
 85    }
 86
 87    /**
 88     * {@inheritDoc}
 89     * @see AntTaskFactory#createTask(String)
 90     */
 91    public Task createTask(String theName)
 92    {
 93        Task retVal = this.currentProject.createTask(theName);
 94        if (retVal != null)
 95        {
 96            retVal.setTaskName(this.currentTaskName);
 97            retVal.setLocation(this.currentLocation);
 98            retVal.setOwningTarget(this.currentOwningTarget);
 99        }
100        return retVal;
101    }
102}