]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/DistributerMap.java
Initial import.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / DistributerMap.java
CommitLineData
878ddf1f 1/*\r
2 *\r
3 * Copyright 2004 The Ant-Contrib project\r
4 *\r
5 * Licensed under the Apache License, Version 2.0 (the "License");\r
6 * you may not use this file except in compliance with the License.\r
7 * You may obtain a copy of the License at\r
8 *\r
9 * http://www.apache.org/licenses/LICENSE-2.0\r
10 *\r
11 * Unless required by applicable law or agreed to in writing, software\r
12 * distributed under the License is distributed on an "AS IS" BASIS,\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 * See the License for the specific language governing permissions and\r
15 * limitations under the License.\r
16 */\r
17package net.sf.antcontrib.cpptasks;\r
18\r
19import java.io.File;\r
20import java.io.IOException;\r
21\r
22import org.apache.tools.ant.BuildException;\r
23import org.apache.tools.ant.types.DataType;\r
24\r
25/**\r
26 * Local to remote filename mapping (Experimental).\r
27 *\r
28 */\r
29public final class DistributerMap\r
30 extends DataType {\r
31 /**\r
32 * if property.\r
33 */\r
34 private String ifCond;\r
35\r
36 /**\r
37 * unless property.\r
38 */\r
39 private String unlessCond;\r
40\r
41 /**\r
42 * local directory name.\r
43 *\r
44 */\r
45 private File localName;\r
46\r
47 /**\r
48 * Canonical local file name.\r
49 */\r
50 private String canonicalPath;\r
51\r
52 /**\r
53 * remote name.\r
54 *\r
55 */\r
56 private String remoteName;\r
57\r
58 /**\r
59 * Separator (/ or \) character on remote system.\r
60 */\r
61 private char remoteSeparator = File.separatorChar;\r
62\r
63 /**\r
64 * hosts that for which this map is valid.\r
65 *\r
66 */\r
67 private String hosts;\r
68\r
69 /**\r
70 * Constructor.\r
71 *\r
72 */\r
73 public DistributerMap() {\r
74 }\r
75\r
76 /**\r
77 * Required by documentation generator.\r
78 */\r
79 public void execute() {\r
80 throw new org.apache.tools.ant.BuildException(\r
81 "Not an actual task, but looks like one for documentation purposes");\r
82 }\r
83\r
84 /**\r
85 * Returns true if the if and unless conditions (if any) are\r
86 * satisfied.\r
87 *\r
88 * @return true if this object is active.\r
89 */\r
90 public boolean isActive() {\r
91 return CUtil.isActive(getProject(), ifCond, unlessCond);\r
92 }\r
93\r
94 /**\r
95 * Sets the property name for the 'if' condition.\r
96 *\r
97 * This object will be ignored unless the property is defined.\r
98 *\r
99 * The value of the property is insignificant, but values that would imply\r
100 * misinterpretation ("false", "no") will throw an exception when\r
101 * evaluated.\r
102 *\r
103 * @param propName\r
104 * property name\r
105 */\r
106 public void setIf(final String propName) {\r
107 ifCond = propName;\r
108 }\r
109\r
110 /**\r
111 * Set the property name for the 'unless' condition.\r
112 *\r
113 * If named property is set, the define will be ignored.\r
114 *\r
115 * The value of the property is insignificant, but values that would imply\r
116 * misinterpretation ("false", "no") of the behavior will throw an\r
117 * exception when evaluated.\r
118 *\r
119 * @param propName\r
120 * name of property\r
121 */\r
122 public void setUnless(final String propName) {\r
123 unlessCond = propName;\r
124 }\r
125\r
126 /**\r
127 * Gets local directory.\r
128 * @return local directory, may be null.\r
129 *\r
130 */\r
131 public File getLocal() {\r
132 return localName;\r
133 }\r
134\r
135 /**\r
136 * Gets remote name for directory.\r
137 * @return remote name, may be null.\r
138 *\r
139 */\r
140 public String getRemote() {\r
141 return remoteName;\r
142 }\r
143\r
144 /**\r
145 * Converts the local file name to the remote name for the same file.\r
146 *\r
147 * @param host host\r
148 * @param localFile local file\r
149 * @return remote name for local file, null if unknown.\r
150 */\r
151 public String toRemote(final String host, final File localFile) {\r
152 if (remoteName != null\r
153 && (hosts == null || hosts.indexOf(host) >= 0)) {\r
154 try {\r
155 String canonical = localFile.getCanonicalPath();\r
156 if (canonical.startsWith(canonicalPath)) {\r
157 if (isActive()) {\r
158 return remoteName\r
159 + canonical.substring(canonicalPath.length()).replace(File.\r
160 separatorChar, remoteSeparator);\r
161 }\r
162 }\r
163 } catch (IOException ex) {\r
164 return null;\r
165 }\r
166 }\r
167 return null;\r
168 }\r
169\r
170 /**\r
171 * Sets local directory for base of mapping.\r
172 *\r
173 * @param value value\r
174 */\r
175 public void setLocal(final File value) {\r
176 if (value == null) {\r
177 throw new NullPointerException("value");\r
178 }\r
179 if (value.exists() && !value.isDirectory()) {\r
180 throw new BuildException("local should be a directory");\r
181 }\r
182 localName = value;\r
183 try {\r
184 canonicalPath = localName.getCanonicalPath();\r
185 } catch (IOException ex) {\r
186 throw new BuildException(ex);\r
187 }\r
188 }\r
189\r
190 /**\r
191 * Sets remote name for directory.\r
192 * @param value remote name for directory\r
193 */\r
194 public void setRemote(final String value) {\r
195 remoteName = value;\r
196 }\r
197\r
198 /**\r
199 * Sets the separator character (/ or \) for the remote system.\r
200 * @param value separator character\r
201 */\r
202 public void setRemoteSeparator(final String value) {\r
203 if (value != null && value.length() != 1) {\r
204 throw new BuildException("remote separator must be a single character");\r
205 }\r
206 remoteSeparator = value.charAt(0);\r
207 }\r
208\r
209 /**\r
210 * Sets hosts for which this mapping is valid.\r
211 *\r
212 * @param value hosts\r
213 */\r
214 public void setHosts(final String value) {\r
215 hosts = value;\r
216 }\r
217\r
218}\r