Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/objectstyle/woproject/ant/FrameworkSet.java


1   /* ====================================================================
2    *
3    * The ObjectStyle Group Software License, Version 1.0
4    *
5    * Copyright (c) 2002 The ObjectStyle Group
6    * and individual authors of the software.  All rights reserved.
7    *
8    * Redistribution and use in source and binary forms, with or without
9    * modification, are permitted provided that the following conditions
10   * are met:
11   *
12   * 1. Redistributions of source code must retain the above copyright
13   *    notice, this list of conditions and the following disclaimer.
14   *
15   * 2. Redistributions in binary form must reproduce the above copyright
16   *    notice, this list of conditions and the following disclaimer in
17   *    the documentation and/or other materials provided with the
18   *    distribution.
19   *
20   * 3. The end-user documentation included with the redistribution, if
21   *    any, must include the following acknowlegement:
22   *       "This product includes software developed by the
23   *        ObjectStyle Group (http://objectstyle.org/)."
24   *    Alternately, this acknowlegement may appear in the software itself,
25   *    if and wherever such third-party acknowlegements normally appear.
26   *
27   * 4. The names "ObjectStyle Group" and "Cayenne"
28   *    must not be used to endorse or promote products derived
29   *    from this software without prior written permission. For written
30   *    permission, please contact andrus@objectstyle.org.
31   *
32   * 5. Products derived from this software may not be called "ObjectStyle"
33   *    nor may "ObjectStyle" appear in their names without prior written
34   *    permission of the ObjectStyle Group.
35   *
36   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39   * DISCLAIMED.  IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
40   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47   * SUCH DAMAGE.
48   * ====================================================================
49   *
50   * This software consists of voluntary contributions made by many
51   * individuals on behalf of the ObjectStyle Group.  For more
52   * information on the ObjectStyle Group, please see
53   * <http://objectstyle.org/>.
54   *
55   */
56  package org.objectstyle.woproject.ant;
57  
58  import java.io.File;
59  import java.io.FilenameFilter;
60  
61  import org.apache.tools.ant.BuildException;
62  import org.apache.tools.ant.Project;
63  import org.apache.tools.ant.ProjectHelper;
64  import org.apache.tools.ant.types.FileSet;
65  
66  /**
67   * Customized subclass of FileSet used to locate frameworks.
68   *
69   * @author Andrei Adamchik
70   */
71  public class FrameworkSet extends FileSet {
72    protected File     aDirectory;
73    protected boolean   embed = false;
74          protected String   ifCondition = "";
75    /** 
76     * Creates new FrameworkSet.
77     */
78    public FrameworkSet() {
79      super();
80    }
81  
82    /** 
83     * Returns a symbolic root prefix that can be used in
84     * classpath files (like CLASSPATH.TXT).
85     */
86  
87    /** 
88     * Overrides parent to discard the value. A warning 
89     * will be printed if log level is high enough.
90     */
91    public void setDir(File dir) throws BuildException {
92      aDirectory = dir;
93          super.setDir(this.aDirectory);
94    }
95  
96    /** 
97     * Sets root directory of this FileSet based on a symbolic name, 
98     * that can be "wo.homeroot", "wo.woroot", "wo.localroot". Throws
99     * BuildException if an invalid root is specified.
100    */
101   public void setRoot(File aRoot) throws BuildException {
102     aDirectory = aRoot;
103     super.setDir(this.aDirectory);
104   }
105 
106   public void setEmbed(boolean flag) {
107     this.embed = flag;
108   }
109 
110   public boolean getEmbed() {
111     return this.embed;
112   }
113 
114         public void setIf(String string) {
115             ifCondition = string == null ? "" : string;
116         }
117 
118         private boolean testIfCondition() {
119             if ("".equals(ifCondition))
120                 return true;
121             String string
122                 = ProjectHelper.replaceProperties(getProject(), ifCondition,
123                                                   getProject().getProperties());
124             return project.getProperty(string) != null;
125         }
126 
127         public File[] findJars(Project project, String frameworkDir) {
128             if(!testIfCondition())
129                 return new File[] {};
130             
131     String jarDirName = frameworkDir
132         + File.separator
133         + "Resources"
134         + File.separator
135         + "Java";
136 
137     File jarDir = new File(getDir(project), jarDirName);
138     if (!jarDir.isDirectory()) {
139       return null;
140     }
141 
142     File[] finalFiles = jarDir.listFiles(new JarFilter());
143     return finalFiles;
144   }
145 
146   class JarFilter implements FilenameFilter {
147     public boolean accept(File dir, String name) {
148       return name.endsWith(".jar");
149     }
150   }
151 }