// Command Task // // Douglas Thrift // // $Id$ /* Copyright 2008 Douglas Thrift * * 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 net.douglasthrift.anttasks; import java.io.File; import org.apache.tools.ant.Task; import org.apache.tools.ant.taskdefs.ExecTask; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; public abstract class CommandTask extends Task { protected ExecTask command_; @Override public void execute() { command_.execute(); } protected void command(String command) { command_ = (ExecTask)getProject().createTask("exec"); command_.setTaskName(getTaskName()); command_.setExecutable(command); command_.setFailonerror(true); } protected void argument(File file) { command_.createArg().setFile(file); } protected void argument(Path path) { command_.createArg().setPath(path); } protected void argument(Reference reference) { command_.createArg().setPathref(reference); } protected void argument(String value) { command_.createArg().setValue(value); } protected void arguments(String line) { command_.createArg().setLine(line); } protected void arguments(Object... objects) { for (Object object : objects) if (object instanceof File) argument((File)object); else if (object instanceof Path) argument((Path)object); else if (object instanceof Reference) argument((Reference)object); else if (object instanceof String) argument((String)object); else assert (false); } }