1 package org.apache.maven.hibernate.beans;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import java.io.File;
21 import java.util.ArrayList;
22 import java.util.LinkedList;
23 import java.util.List;
24 import java.util.StringTokenizer;
25
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.tools.ant.DirectoryScanner;
30
31 /**
32 *
33 * @author <a href="as851@columbia.edu">Alex Shneyderman</a>
34 * @since $Id: CommonOperationsBean.java 170200 2005-05-15 06:24:19Z brett $
35 */
36 public class CommonOperationsBean {
37
38 private String includes = null;
39 private String excludes = null;
40 private String basedir = null;
41
42 private static final Log LOG = LogFactory.getLog(CommonOperationsBean.class);
43
44 public String getBasedir()
45 {
46 return basedir;
47 }
48
49 public void setBasedir(String basedir)
50 {
51 this.basedir = basedir;
52 }
53
54 public String getExcludes()
55 {
56 return excludes;
57 }
58
59 public void setExcludes(String excludes)
60 {
61 this.excludes = excludes;
62 }
63
64 public String getIncludes()
65 {
66 return includes;
67 }
68
69 public void setIncludes(String includes)
70 {
71 this.includes = includes;
72 }
73
74 protected String[] getBaseDirNames()
75 {
76 LOG.debug("Bases string: " + getBasedir());
77 StringTokenizer st = new StringTokenizer(getBasedir(), ",");
78 String r[] = new String[st.countTokens()];
79 for(int i = 0; st.hasMoreTokens(); i++)
80 r[i] = st.nextToken();
81
82 return r;
83 }
84
85 protected File[] getBaseDirs()
86 {
87 String bases[] = getBaseDirNames();
88 List l = new ArrayList();
89 for(int i = 0; i < bases.length; i++)
90 {
91 File t = new File(bases[i]);
92 if(t.isDirectory())
93 {
94 l.add(t);
95 LOG.info(" Adding base dir: " + t.getAbsolutePath());
96 }
97 }
98
99 return (File[])l.toArray(new File[0]);
100 }
101
102 protected String[] getFileNames()
103 {
104 List files = new LinkedList();
105 File dirs[] = getBaseDirs();
106 for(int i = 0; i < dirs.length; i++)
107 {
108 DirectoryScanner directoryScanner = new DirectoryScanner();
109 directoryScanner.setBasedir(dirs[i]);
110 LOG.debug("Base dir:" + dirs[i].getAbsolutePath());
111 LOG.debug("Excludes:" + getExcludes());
112 LOG.debug("Includes:" + getIncludes());
113 directoryScanner.setExcludes(StringUtils.split(getExcludes(), ","));
114 directoryScanner.setIncludes(StringUtils.split(getIncludes(), ","));
115 directoryScanner.scan();
116 String includesFiles[] = directoryScanner.getIncludedFiles();
117 for(int j = 0; j < includesFiles.length; j++)
118 {
119 File file = new File(includesFiles[j]);
120 if(!file.isFile())
121 file = new File(directoryScanner.getBasedir(), includesFiles[j]);
122 files.add(file.getAbsolutePath());
123 LOG.debug("work with file:" + file.getAbsolutePath());
124 }
125
126 }
127
128 return (String[])files.toArray(new String[0]);
129 }
130
131 protected File[] getFileDescriptors()
132 {
133 String names[] = getFileNames();
134 List files = new ArrayList();
135 for(int i = 0; i < names.length; i++)
136 {
137 File t = new File(names[i]);
138 if(t.isFile())
139 files.add(t);
140 }
141
142 return (File[])files.toArray(new File[0]);
143 }
144
145
146
147
148 }