%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.ant.FileScannerTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
15 | */ |
|
16 | package org.apache.commons.jelly.tags.ant; |
|
17 | ||
18 | import java.lang.reflect.InvocationTargetException; |
|
19 | ||
20 | import org.apache.commons.beanutils.BeanUtils; |
|
21 | import org.apache.commons.jelly.JellyTagException; |
|
22 | import org.apache.commons.jelly.MissingAttributeException; |
|
23 | import org.apache.commons.jelly.TagSupport; |
|
24 | import org.apache.commons.jelly.XMLOutput; |
|
25 | ||
26 | /** |
|
27 | * A tag which creates a new FileScanner bean instance that can be used to |
|
28 | * iterate over fileSets |
|
29 | * |
|
30 | * @author <a href="mailto:jstrachan@apache.org">James Strachan</a> |
|
31 | * @version $Revision: 1.6 $ |
|
32 | */ |
|
33 | public class FileScannerTag extends TagSupport implements TaskSource { |
|
34 | ||
35 | /** The file walker that gets created */ |
|
36 | private FileScanner fileScanner; |
|
37 | ||
38 | /** the variable exported */ |
|
39 | private String var; |
|
40 | ||
41 | 0 | public FileScannerTag(FileScanner fileScanner) { |
42 | 0 | this.fileScanner = fileScanner; |
43 | 0 | } |
44 | ||
45 | // Tag interface |
|
46 | //------------------------------------------------------------------------- |
|
47 | public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException { |
|
48 | 0 | fileScanner.setProject(AntTagLibrary.getProject(context)); |
49 | ||
50 | 0 | fileScanner.clear(); |
51 | ||
52 | // run the body first to configure the task via nested |
|
53 | 0 | invokeBody(output); |
54 | ||
55 | // output the fileScanner |
|
56 | 0 | if ( var == null ) { |
57 | 0 | throw new MissingAttributeException( "var" ); |
58 | } |
|
59 | 0 | context.setVariable( var, fileScanner ); |
60 | ||
61 | 0 | } |
62 | ||
63 | // TaskSource interface |
|
64 | //------------------------------------------------------------------------- |
|
65 | public Object getTaskObject() { |
|
66 | 0 | return fileScanner; |
67 | } |
|
68 | ||
69 | /** |
|
70 | * Allows nested tags to set a property on the task object of this tag |
|
71 | */ |
|
72 | public void setTaskProperty(String name, Object value) throws JellyTagException { |
|
73 | try { |
|
74 | 0 | BeanUtils.setProperty( fileScanner, name, value ); |
75 | 0 | } |
76 | catch (IllegalAccessException ex) { |
|
77 | 0 | throw new JellyTagException(ex); |
78 | } |
|
79 | catch (InvocationTargetException ex) { |
|
80 | 0 | throw new JellyTagException(ex); |
81 | } |
|
82 | 0 | } |
83 | ||
84 | // Properties |
|
85 | //------------------------------------------------------------------------- |
|
86 | ||
87 | /** |
|
88 | * @return the Ant task |
|
89 | */ |
|
90 | public FileScanner getFileScanner() { |
|
91 | 0 | return fileScanner; |
92 | } |
|
93 | ||
94 | /** Sets the name of the variable exported by this tag */ |
|
95 | public void setVar(String var) { |
|
96 | 0 | this.var = class="keyword">var; |
97 | 0 | } |
98 | ||
99 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |