Save This Page
Home » j2ssh-0.2.9-src » com.sshtools.ant » [javadoc | source]
    1   /*
    2    *  SSHTools - Java SSH2 API
    3    *
    4    *  Copyright (C) 2002-2003 Lee David Painter and Contributors.
    5    *
    6    *  Contributions made by:
    7    *
    8    *  Brett Smith
    9    *  Richard Pernavas
   10    *  Erwin Bolwidt
   11    *
   12    *  This program is free software; you can redistribute it and/or
   13    *  modify it under the terms of the GNU General Public License
   14    *  as published by the Free Software Foundation; either version 2
   15    *  of the License, or (at your option) any later version.
   16    *
   17    *  This program is distributed in the hope that it will be useful,
   18    *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   19    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20    *  GNU General Public License for more details.
   21    *
   22    *  You should have received a copy of the GNU General Public License
   23    *  along with this program; if not, write to the Free Software
   24    *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   25    */
   26   package com.sshtools.ant;
   27   
   28   import org.apache.tools.ant;
   29   
   30   import java.io;
   31   
   32   import java.util;
   33   
   34   
   35   public class ConditionalTasks extends Task implements TaskContainer {
   36       private ArrayList tasks = new ArrayList();
   37       private String dirs;
   38       private String files;
   39       private String name;
   40       private String family;
   41   
   42       public ConditionalTasks() {
   43       }
   44   
   45       public void setFamily(String family) {
   46           this.family = family;
   47       }
   48   
   49       public void setDirs(String dirs) {
   50           this.dirs = dirs;
   51       }
   52   
   53       public void setFiles(String files) {
   54           this.files = files;
   55       }
   56   
   57       public void setName(String name) {
   58           this.name = name;
   59       }
   60   
   61       public void addTask(Task task) {
   62           tasks.add(tasks.size(), task);
   63       }
   64   
   65       public void execute() {
   66           if ((dirs == null) && (files == null)) {
   67               throw new BuildException(
   68                   "ConditionalTasks: You must supply at least one of either the files or dirs properties");
   69           }
   70   
   71           if (name == null) {
   72               throw new BuildException(
   73                   "ConditionalTasks: You must supply a name for these conditional tasks!");
   74           }
   75   
   76           log("Verifying conditions for " + name);
   77   
   78           if (family != null) {
   79               StringTokenizer tokenizer = new StringTokenizer(dirs, ",");
   80               boolean familyMatch = false;
   81   
   82               while (tokenizer.hasMoreElements() && !familyMatch) {
   83                   String condition = (String) tokenizer.nextElement();
   84   
   85                   if (condition.equals(family)) {
   86                       familyMatch = true;
   87                   }
   88               }
   89   
   90               if (!familyMatch) {
   91                   log("ConditionalTasks: OS Family '" + family +
   92                       "' does not match; " + name + " will not be performed");
   93   
   94                   return;
   95               }
   96           }
   97   
   98           File basedir = getProject().getBaseDir();
   99   
  100           if (dirs != null) {
  101               StringTokenizer tokenizer = new StringTokenizer(dirs, ",");
  102               File f;
  103   
  104               while (tokenizer.hasMoreElements()) {
  105                   String condition = (String) tokenizer.nextElement();
  106                   f = new File(basedir, condition);
  107   
  108                   if (!f.exists()) {
  109                       f = new File(condition);
  110   
  111                       if (!f.exists()) {
  112                           log("ConditionalTasks: Directory '" + condition +
  113                               "' does not exist; " + name +
  114                               " will not be performed");
  115   
  116                           return;
  117                       }
  118                   }
  119               }
  120           }
  121   
  122           if (files != null) {
  123               StringTokenizer tokenizer = new StringTokenizer(files, ",");
  124               File f;
  125   
  126               while (tokenizer.hasMoreElements()) {
  127                   String condition = (String) tokenizer.nextElement();
  128                   f = new File(basedir, condition);
  129   
  130                   if (!f.exists()) {
  131                       log("ConditionalTasks: File '" + condition +
  132                           "' does not exist; " + name + " will not be performed");
  133   
  134                       return;
  135                   }
  136               }
  137           }
  138   
  139           System.out.println("Executing Conditional Tasks");
  140   
  141           Iterator it = tasks.iterator();
  142           Task task;
  143   
  144           while (it.hasNext()) {
  145               task = (Task) it.next();
  146               task.setProject(getProject());
  147               task.setOwningTarget(getOwningTarget());
  148               task.setLocation(getLocation());
  149               task.perform();
  150           }
  151       }
  152   }

Save This Page
Home » j2ssh-0.2.9-src » com.sshtools.ant » [javadoc | source]