KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cpmake > PatternRule


1 /*
2  * Copyright (c) 2004, Brian Hawkins
3  * brianhks@activeclickweb.com
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation; either version 2 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */

20  
21
22
23 package cpmake;
24
25 import java.util.regex.*;
26 import java.io.*;
27
28 class PatternRule implements Rule
29     {
30     private Pattern m_pattern;
31     private String JavaDoc m_strPattern;
32     //private String m_repRegex;
33
private String JavaDoc m_replacement;
34     private String JavaDoc m_scriptCall;
35     private CPMake m_make;
36     private boolean m_verify;
37     
38     public PatternRule(CPMake make, String JavaDoc pattern, String JavaDoc replacement,
39             String JavaDoc scriptCall, boolean verify)
40         {
41         m_make = make;
42         m_strPattern = pattern;
43         //m_pattern = Pattern.compile(m_strPattern.replaceAll("%", ".*"));
44
m_pattern = Pattern.compile(pattern);
45         //m_repRegex = repRegex;
46
m_replacement = replacement;
47         m_scriptCall = scriptCall;
48         m_verify = verify;
49         }
50         
51     public boolean matchTarget(String JavaDoc target)
52         {
53         return (m_pattern.matcher(target.replace('\\', '/')).matches());
54         }
55         
56     public String JavaDoc[] getPrerequisites(String JavaDoc target)
57         {
58         target = target.replace('\\', '/');
59         String JavaDoc[] s = new String JavaDoc[1];
60         /*String[] pattern = m_strPattern.split("%");
61         String subStr = target.replaceFirst(pattern[0], "");
62         subStr = subStr.replaceFirst(pattern[1], "");*/

63         File f;
64         
65         s[0] = target.replaceFirst(m_strPattern, m_replacement);
66         if ((f = m_make.locateFile(s[0])) != null)
67             {
68             s[0] = m_make.getPath(f);
69             }
70         
71         return (s);
72         }
73         
74     public String JavaDoc getScriptCall()
75         {
76         return (m_scriptCall);
77         }
78         
79     public boolean hasAction()
80         {
81         return (m_scriptCall != null);
82         }
83         
84     public boolean verify()
85         {
86         return (m_verify);
87         }
88         
89     public void callAction(String JavaDoc target) {}
90     }
91
Popular Tags