You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Project.java 72 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992
  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "Ant" and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. */
  54. package org.apache.tools.ant;
  55. import java.io.File;
  56. import java.io.IOException;
  57. import java.io.EOFException;
  58. import java.io.InputStream;
  59. import java.lang.reflect.Method;
  60. import java.lang.reflect.Modifier;
  61. import java.util.Enumeration;
  62. import java.util.Hashtable;
  63. import java.util.Properties;
  64. import java.util.Stack;
  65. import java.util.Vector;
  66. import org.apache.tools.ant.input.DefaultInputHandler;
  67. import org.apache.tools.ant.input.InputHandler;
  68. import org.apache.tools.ant.types.FilterSet;
  69. import org.apache.tools.ant.types.FilterSetCollection;
  70. import org.apache.tools.ant.types.Description;
  71. import org.apache.tools.ant.types.Path;
  72. import org.apache.tools.ant.util.FileUtils;
  73. import org.apache.tools.ant.util.JavaEnvUtils;
  74. import org.apache.tools.ant.util.WeakishReference;
  75. import org.apache.tools.ant.util.LazyHashtable;
  76. /**
  77. * Central representation of an Ant project. This class defines an
  78. * Ant project with all of its targets, tasks and various other
  79. * properties. It also provides the mechanism to kick off a build using
  80. * a particular target name.
  81. * <p>
  82. * This class also encapsulates methods which allow files to be referred
  83. * to using abstract path names which are translated to native system
  84. * file paths at runtime.
  85. *
  86. * @author duncan@x180.com
  87. *
  88. * @version $Revision$
  89. */
  90. public class Project {
  91. /** Message priority of "error". */
  92. public static final int MSG_ERR = 0;
  93. /** Message priority of "warning". */
  94. public static final int MSG_WARN = 1;
  95. /** Message priority of "information". */
  96. public static final int MSG_INFO = 2;
  97. /** Message priority of "verbose". */
  98. public static final int MSG_VERBOSE = 3;
  99. /** Message priority of "debug". */
  100. public static final int MSG_DEBUG = 4;
  101. /**
  102. * Constant for the "visiting" state, used when
  103. * traversing a DFS of target dependencies.
  104. */
  105. private static final String VISITING = "VISITING";
  106. /**
  107. * Constant for the "visited" state, used when
  108. * traversing a DFS of target dependencies.
  109. */
  110. private static final String VISITED = "VISITED";
  111. /**
  112. * The class name of the Ant class loader to use for
  113. * JDK 1.2 and above
  114. */
  115. private static final String ANTCLASSLOADER_JDK12
  116. = "org.apache.tools.ant.loader.AntClassLoader2";
  117. /**
  118. * Version constant for Java 1.0
  119. *
  120. * @deprecated use org.apache.tools.ant.util.JavaEnvUtils instead
  121. */
  122. public static final String JAVA_1_0 = JavaEnvUtils.JAVA_1_0;
  123. /**
  124. * Version constant for Java 1.1
  125. *
  126. * @deprecated use org.apache.tools.ant.util.JavaEnvUtils instead
  127. */
  128. public static final String JAVA_1_1 = JavaEnvUtils.JAVA_1_1;
  129. /**
  130. * Version constant for Java 1.2
  131. *
  132. * @deprecated use org.apache.tools.ant.util.JavaEnvUtils instead
  133. */
  134. public static final String JAVA_1_2 = JavaEnvUtils.JAVA_1_2;
  135. /**
  136. * Version constant for Java 1.3
  137. *
  138. * @deprecated use org.apache.tools.ant.util.JavaEnvUtils instead
  139. */
  140. public static final String JAVA_1_3 = JavaEnvUtils.JAVA_1_3;
  141. /**
  142. * Version constant for Java 1.4
  143. *
  144. * @deprecated use org.apache.tools.ant.util.JavaEnvUtils instead
  145. */
  146. public static final String JAVA_1_4 = JavaEnvUtils.JAVA_1_4;
  147. /** Default filter start token. */
  148. public static final String TOKEN_START = FilterSet.DEFAULT_TOKEN_START;
  149. /** Default filter end token. */
  150. public static final String TOKEN_END = FilterSet.DEFAULT_TOKEN_END;
  151. /** Name of this project. */
  152. private String name;
  153. /** Description for this project (if any). */
  154. private String description;
  155. /** Map of references within the project (paths etc) (String to Object). */
  156. private Hashtable references = new AntRefTable(this);
  157. /** Name of the project's default target. */
  158. private String defaultTarget;
  159. /** Map from target names to targets (String to Target). */
  160. private Hashtable targets = new Hashtable();
  161. /** Set of global filters. */
  162. private FilterSet globalFilterSet = new FilterSet();
  163. /**
  164. * Wrapper around globalFilterSet. This collection only ever
  165. * contains one FilterSet, but the wrapper is needed in order to
  166. * make it easier to use the FileUtils interface.
  167. */
  168. private FilterSetCollection globalFilters
  169. = new FilterSetCollection(globalFilterSet);
  170. /** Project base directory. */
  171. private File baseDir;
  172. /** List of listeners to notify of build events. */
  173. private Vector listeners = new Vector();
  174. /**
  175. * The Ant core classloader - may be <code>null</code> if using
  176. * parent classloader.
  177. */
  178. private ClassLoader coreLoader = null;
  179. /** Records the latest task to be executed on a thread (Thread to Task). */
  180. private Hashtable threadTasks = new Hashtable();
  181. /** Records the latest task to be executed on a thread Group. */
  182. private Hashtable threadGroupTasks = new Hashtable();
  183. /**
  184. * Called to handle any input requests.
  185. */
  186. private InputHandler inputHandler = null;
  187. /**
  188. * The default input stream used to read any input
  189. */
  190. private InputStream defaultInputStream = null;
  191. /**
  192. * Sets the input handler
  193. *
  194. * @param handler the InputHandler instance to use for gathering input.
  195. */
  196. public void setInputHandler(InputHandler handler) {
  197. inputHandler = handler;
  198. }
  199. /**
  200. * Set the default System input stream. Normally this stream is set to
  201. * System.in. This inputStream is used when no task inptu redirection is
  202. * being performed.
  203. *
  204. * @param defaultInputStream the default input stream to use when input
  205. * is reuested.
  206. * @since Ant 1.6
  207. */
  208. public void setDefaultInputStream(InputStream defaultInputStream) {
  209. this.defaultInputStream = defaultInputStream;
  210. }
  211. /**
  212. * Get this project's input stream
  213. *
  214. * @return the InputStream instance in use by this Porject instance to
  215. * read input
  216. */
  217. public InputStream getDefaultInputStream() {
  218. return defaultInputStream;
  219. }
  220. /**
  221. * Retrieves the current input handler.
  222. *
  223. * @return the InputHandler instance currently in place for the project
  224. * instance.
  225. */
  226. public InputHandler getInputHandler() {
  227. return inputHandler;
  228. }
  229. /** Instance of a utility class to use for file operations. */
  230. private FileUtils fileUtils;
  231. /**
  232. * Flag which catches Listeners which try to use System.out or System.err
  233. */
  234. private boolean loggingMessage = false;
  235. /**
  236. * Creates a new Ant project.
  237. */
  238. public Project() {
  239. fileUtils = FileUtils.newFileUtils();
  240. inputHandler = new DefaultInputHandler();
  241. }
  242. /**
  243. * Initialises the project.
  244. *
  245. * This involves setting the default task definitions and loading the
  246. * system properties.
  247. *
  248. * @exception BuildException if the default task list cannot be loaded
  249. */
  250. public void init() throws BuildException {
  251. setJavaVersionProperty();
  252. ComponentHelper.getComponentHelper(this).initDefaultDefinitions();
  253. setSystemProperties();
  254. }
  255. /**
  256. * Factory method to create a class loader for loading classes
  257. *
  258. * @return an appropriate classloader
  259. */
  260. private AntClassLoader createClassLoader() {
  261. AntClassLoader loader = null;
  262. if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
  263. try {
  264. // 1.2+ - create advanced helper dynamically
  265. Class loaderClass
  266. = Class.forName(ANTCLASSLOADER_JDK12);
  267. loader = (AntClassLoader) loaderClass.newInstance();
  268. } catch (Exception e) {
  269. log("Unable to create Class Loader: "
  270. + e.getMessage(), Project.MSG_DEBUG);
  271. }
  272. }
  273. if (loader == null) {
  274. loader = new AntClassLoader();
  275. }
  276. loader.setProject(this);
  277. return loader;
  278. }
  279. /**
  280. * Factory method to create a class loader for loading classes from
  281. * a given path
  282. *
  283. * @param path the path from whcih clases are to be loaded.
  284. *
  285. * @return an appropriate classloader
  286. */
  287. public AntClassLoader createClassLoader(Path path) {
  288. AntClassLoader loader = createClassLoader();
  289. loader.setClassPath(path);
  290. return loader;
  291. }
  292. /**
  293. * Sets the core classloader for the project. If a <code>null</code>
  294. * classloader is specified, the parent classloader should be used.
  295. *
  296. * @param coreLoader The classloader to use for the project.
  297. * May be <code>null</code>.
  298. */
  299. public void setCoreLoader(ClassLoader coreLoader) {
  300. this.coreLoader = coreLoader;
  301. }
  302. /**
  303. * Returns the core classloader to use for this project.
  304. * This may be <code>null</code>, indicating that
  305. * the parent classloader should be used.
  306. *
  307. * @return the core classloader to use for this project.
  308. *
  309. */
  310. public ClassLoader getCoreLoader() {
  311. return coreLoader;
  312. }
  313. /**
  314. * Adds a build listener to the list. This listener will
  315. * be notified of build events for this project.
  316. *
  317. * @param listener The listener to add to the list.
  318. * Must not be <code>null</code>.
  319. */
  320. public void addBuildListener(BuildListener listener) {
  321. listeners.addElement(listener);
  322. }
  323. /**
  324. * Removes a build listener from the list. This listener
  325. * will no longer be notified of build events for this project.
  326. *
  327. * @param listener The listener to remove from the list.
  328. * Should not be <code>null</code>.
  329. */
  330. public void removeBuildListener(BuildListener listener) {
  331. listeners.removeElement(listener);
  332. }
  333. /**
  334. * Returns a list of build listeners for the project.
  335. *
  336. * @return a list of build listeners for the project
  337. */
  338. public Vector getBuildListeners() {
  339. return (Vector) listeners.clone();
  340. }
  341. /**
  342. * Writes a message to the log with the default log level
  343. * of MSG_INFO
  344. * @param message The text to log. Should not be <code>null</code>.
  345. */
  346. public void log(String message) {
  347. log(message, MSG_INFO);
  348. }
  349. /**
  350. * Writes a project level message to the log with the given log level.
  351. * @param message The text to log. Should not be <code>null</code>.
  352. * @param msgLevel The priority level to log at.
  353. */
  354. public void log(String message, int msgLevel) {
  355. fireMessageLogged(this, message, msgLevel);
  356. }
  357. /**
  358. * Writes a task level message to the log with the given log level.
  359. * @param task The task to use in the log. Must not be <code>null</code>.
  360. * @param message The text to log. Should not be <code>null</code>.
  361. * @param msgLevel The priority level to log at.
  362. */
  363. public void log(Task task, String message, int msgLevel) {
  364. fireMessageLogged(task, message, msgLevel);
  365. }
  366. /**
  367. * Writes a target level message to the log with the given log level.
  368. * @param target The target to use in the log.
  369. * Must not be <code>null</code>.
  370. * @param message The text to log. Should not be <code>null</code>.
  371. * @param msgLevel The priority level to log at.
  372. */
  373. public void log(Target target, String message, int msgLevel) {
  374. fireMessageLogged(target, message, msgLevel);
  375. }
  376. /**
  377. * Returns the set of global filters.
  378. *
  379. * @return the set of global filters
  380. */
  381. public FilterSet getGlobalFilterSet() {
  382. return globalFilterSet;
  383. }
  384. /**
  385. * Sets a property. Any existing property of the same name
  386. * is overwritten, unless it is a user property.
  387. * @param name The name of property to set.
  388. * Must not be <code>null</code>.
  389. * @param value The new value of the property.
  390. * Must not be <code>null</code>.
  391. */
  392. public synchronized void setProperty(String name, String value) {
  393. PropertyHelper.getPropertyHelper(this).
  394. setProperty(null, name, value, true);
  395. }
  396. /**
  397. * Sets a property if no value currently exists. If the property
  398. * exists already, a message is logged and the method returns with
  399. * no other effect.
  400. *
  401. * @param name The name of property to set.
  402. * Must not be <code>null</code>.
  403. * @param value The new value of the property.
  404. * Must not be <code>null</code>.
  405. * @since 1.5
  406. */
  407. public synchronized void setNewProperty(String name, String value) {
  408. PropertyHelper.getPropertyHelper(this).setNewProperty(null, name,
  409. value);
  410. }
  411. /**
  412. * Sets a user property, which cannot be overwritten by
  413. * set/unset property calls. Any previous value is overwritten.
  414. * @param name The name of property to set.
  415. * Must not be <code>null</code>.
  416. * @param value The new value of the property.
  417. * Must not be <code>null</code>.
  418. * @see #setProperty(String,String)
  419. */
  420. public synchronized void setUserProperty(String name, String value) {
  421. PropertyHelper.getPropertyHelper(this).setUserProperty(null, name,
  422. value);
  423. }
  424. /**
  425. * Sets a user property, which cannot be overwritten by set/unset
  426. * property calls. Any previous value is overwritten. Also marks
  427. * these properties as properties that have not come from the
  428. * command line.
  429. *
  430. * @param name The name of property to set.
  431. * Must not be <code>null</code>.
  432. * @param value The new value of the property.
  433. * Must not be <code>null</code>.
  434. * @see #setProperty(String,String)
  435. */
  436. public synchronized void setInheritedProperty(String name, String value) {
  437. PropertyHelper ph = PropertyHelper.getPropertyHelper(this);
  438. ph.setInheritedProperty(null, name, value);
  439. }
  440. /**
  441. * Sets a property unless it is already defined as a user property
  442. * (in which case the method returns silently).
  443. *
  444. * @param name The name of the property.
  445. * Must not be <code>null</code>.
  446. * @param value The property value. Must not be <code>null</code>.
  447. */
  448. private void setPropertyInternal(String name, String value) {
  449. PropertyHelper ph = PropertyHelper.getPropertyHelper(this);
  450. ph.setProperty(null, name, value, false);
  451. }
  452. /**
  453. * Returns the value of a property, if it is set.
  454. *
  455. * @param name The name of the property.
  456. * May be <code>null</code>, in which case
  457. * the return value is also <code>null</code>.
  458. * @return the property value, or <code>null</code> for no match
  459. * or if a <code>null</code> name is provided.
  460. */
  461. public String getProperty(String name) {
  462. PropertyHelper ph = PropertyHelper.getPropertyHelper(this);
  463. return (String) ph.getProperty(null, name);
  464. }
  465. /**
  466. * Replaces ${} style constructions in the given value with the
  467. * string value of the corresponding data types.
  468. *
  469. * @param value The string to be scanned for property references.
  470. * May be <code>null</code>.
  471. *
  472. * @return the given string with embedded property names replaced
  473. * by values, or <code>null</code> if the given string is
  474. * <code>null</code>.
  475. *
  476. * @exception BuildException if the given value has an unclosed
  477. * property name, e.g. <code>${xxx</code>
  478. */
  479. public String replaceProperties(String value)
  480. throws BuildException {
  481. PropertyHelper ph = PropertyHelper.getPropertyHelper(this);
  482. return ph.replaceProperties(null, value, null);
  483. }
  484. /**
  485. * Returns the value of a user property, if it is set.
  486. *
  487. * @param name The name of the property.
  488. * May be <code>null</code>, in which case
  489. * the return value is also <code>null</code>.
  490. * @return the property value, or <code>null</code> for no match
  491. * or if a <code>null</code> name is provided.
  492. */
  493. public String getUserProperty(String name) {
  494. PropertyHelper ph = PropertyHelper.getPropertyHelper(this);
  495. return (String) ph.getUserProperty(null, name);
  496. }
  497. /**
  498. * Returns a copy of the properties table.
  499. * @return a hashtable containing all properties
  500. * (including user properties).
  501. */
  502. public Hashtable getProperties() {
  503. PropertyHelper ph = PropertyHelper.getPropertyHelper(this);
  504. return ph.getProperties();
  505. }
  506. /**
  507. * Returns a copy of the user property hashtable
  508. * @return a hashtable containing just the user properties
  509. */
  510. public Hashtable getUserProperties() {
  511. PropertyHelper ph = PropertyHelper.getPropertyHelper(this);
  512. return ph.getUserProperties();
  513. }
  514. /**
  515. * Copies all user properties that have been set on the command
  516. * line or a GUI tool from this instance to the Project instance
  517. * given as the argument.
  518. *
  519. * <p>To copy all "user" properties, you will also have to call
  520. * {@link #copyInheritedProperties copyInheritedProperties}.</p>
  521. *
  522. * @param other the project to copy the properties to. Must not be null.
  523. *
  524. * @since Ant 1.5
  525. */
  526. public void copyUserProperties(Project other) {
  527. PropertyHelper ph = PropertyHelper.getPropertyHelper(this);
  528. ph.copyUserProperties(other);
  529. }
  530. /**
  531. * Copies all user properties that have not been set on the
  532. * command line or a GUI tool from this instance to the Project
  533. * instance given as the argument.
  534. *
  535. * <p>To copy all "user" properties, you will also have to call
  536. * {@link #copyUserProperties copyUserProperties}.</p>
  537. *
  538. * @param other the project to copy the properties to. Must not be null.
  539. *
  540. * @since Ant 1.5
  541. */
  542. public void copyInheritedProperties(Project other) {
  543. PropertyHelper ph = PropertyHelper.getPropertyHelper(this);
  544. ph.copyInheritedProperties(other);
  545. }
  546. /**
  547. * Sets the default target of the project.
  548. *
  549. * @param defaultTarget The name of the default target for this project.
  550. * May be <code>null</code>, indicating that there is
  551. * no default target.
  552. *
  553. * @deprecated use setDefault
  554. * @see #setDefault(String)
  555. */
  556. public void setDefaultTarget(String defaultTarget) {
  557. this.defaultTarget = defaultTarget;
  558. }
  559. /**
  560. * Returns the name of the default target of the project.
  561. * @return name of the default target or
  562. * <code>null</code> if no default has been set.
  563. */
  564. public String getDefaultTarget() {
  565. return defaultTarget;
  566. }
  567. /**
  568. * Sets the default target of the project.
  569. *
  570. * @param defaultTarget The name of the default target for this project.
  571. * May be <code>null</code>, indicating that there is
  572. * no default target.
  573. */
  574. public void setDefault(String defaultTarget) {
  575. this.defaultTarget = defaultTarget;
  576. }
  577. /**
  578. * Sets the name of the project, also setting the user
  579. * property <code>ant.project.name</code>.
  580. *
  581. * @param name The name of the project.
  582. * Must not be <code>null</code>.
  583. */
  584. public void setName(String name) {
  585. setUserProperty("ant.project.name", name);
  586. this.name = name;
  587. }
  588. /**
  589. * Returns the project name, if one has been set.
  590. *
  591. * @return the project name, or <code>null</code> if it hasn't been set.
  592. */
  593. public String getName() {
  594. return name;
  595. }
  596. /**
  597. * Sets the project description.
  598. *
  599. * @param description The description of the project.
  600. * May be <code>null</code>.
  601. */
  602. public void setDescription(String description) {
  603. this.description = description;
  604. }
  605. /**
  606. * Returns the project description, if one has been set.
  607. *
  608. * @return the project description, or <code>null</code> if it hasn't
  609. * been set.
  610. */
  611. public String getDescription() {
  612. if (description == null) {
  613. description = Description.getDescription(this);
  614. }
  615. return description;
  616. }
  617. /**
  618. * Adds a filter to the set of global filters.
  619. *
  620. * @param token The token to filter.
  621. * Must not be <code>null</code>.
  622. * @param value The replacement value.
  623. * Must not be <code>null</code>.
  624. * @deprecated Use getGlobalFilterSet().addFilter(token,value)
  625. *
  626. * @see #getGlobalFilterSet()
  627. * @see FilterSet#addFilter(String,String)
  628. */
  629. public void addFilter(String token, String value) {
  630. if (token == null) {
  631. return;
  632. }
  633. globalFilterSet.addFilter(new FilterSet.Filter(token, value));
  634. }
  635. /**
  636. * Returns a hashtable of global filters, mapping tokens to values.
  637. *
  638. * @return a hashtable of global filters, mapping tokens to values
  639. * (String to String).
  640. *
  641. * @deprecated Use getGlobalFilterSet().getFilterHash()
  642. *
  643. * @see #getGlobalFilterSet()
  644. * @see FilterSet#getFilterHash()
  645. */
  646. public Hashtable getFilters() {
  647. // we need to build the hashtable dynamically
  648. return globalFilterSet.getFilterHash();
  649. }
  650. /**
  651. * Sets the base directory for the project, checking that
  652. * the given filename exists and is a directory.
  653. *
  654. * @param baseD The project base directory.
  655. * Must not be <code>null</code>.
  656. *
  657. * @exception BuildException if the directory if invalid
  658. */
  659. public void setBasedir(String baseD) throws BuildException {
  660. setBaseDir(new File(baseD));
  661. }
  662. /**
  663. * Sets the base directory for the project, checking that
  664. * the given file exists and is a directory.
  665. *
  666. * @param baseDir The project base directory.
  667. * Must not be <code>null</code>.
  668. * @exception BuildException if the specified file doesn't exist or
  669. * isn't a directory
  670. */
  671. public void setBaseDir(File baseDir) throws BuildException {
  672. baseDir = fileUtils.normalize(baseDir.getAbsolutePath());
  673. if (!baseDir.exists()) {
  674. throw new BuildException("Basedir " + baseDir.getAbsolutePath()
  675. + " does not exist");
  676. }
  677. if (!baseDir.isDirectory()) {
  678. throw new BuildException("Basedir " + baseDir.getAbsolutePath()
  679. + " is not a directory");
  680. }
  681. this.baseDir = baseDir;
  682. setPropertyInternal("basedir", this.baseDir.getPath());
  683. String msg = "Project base dir set to: " + this.baseDir;
  684. log(msg, MSG_VERBOSE);
  685. }
  686. /**
  687. * Returns the base directory of the project as a file object.
  688. *
  689. * @return the project base directory, or <code>null</code> if the
  690. * base directory has not been successfully set to a valid value.
  691. */
  692. public File getBaseDir() {
  693. if (baseDir == null) {
  694. try {
  695. setBasedir(".");
  696. } catch (BuildException ex) {
  697. ex.printStackTrace();
  698. }
  699. }
  700. return baseDir;
  701. }
  702. /**
  703. * Returns the version of Java this class is running under.
  704. * @return the version of Java as a String, e.g. "1.1"
  705. * @see org.apache.tools.ant.util.JavaEnvUtils#getJavaVersion
  706. * @deprecated use org.apache.tools.ant.util.JavaEnvUtils instead
  707. */
  708. public static String getJavaVersion() {
  709. return JavaEnvUtils.getJavaVersion();
  710. }
  711. /**
  712. * Sets the <code>ant.java.version</code> property and tests for
  713. * unsupported JVM versions. If the version is supported,
  714. * verbose log messages are generated to record the Java version
  715. * and operating system name.
  716. *
  717. * @exception BuildException if this Java version is not supported
  718. *
  719. * @see org.apache.tools.ant.util.JavaEnvUtils#getJavaVersion
  720. */
  721. public void setJavaVersionProperty() throws BuildException {
  722. String javaVersion = JavaEnvUtils.getJavaVersion();
  723. setPropertyInternal("ant.java.version", javaVersion);
  724. // sanity check
  725. if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_0)) {
  726. throw new BuildException("Ant cannot work on Java 1.0");
  727. }
  728. log("Detected Java version: " + javaVersion + " in: "
  729. + System.getProperty("java.home"), MSG_VERBOSE);
  730. log("Detected OS: " + System.getProperty("os.name"), MSG_VERBOSE);
  731. }
  732. /**
  733. * Adds all system properties which aren't already defined as
  734. * user properties to the project properties.
  735. */
  736. public void setSystemProperties() {
  737. Properties systemP = System.getProperties();
  738. Enumeration e = systemP.keys();
  739. while (e.hasMoreElements()) {
  740. Object name = e.nextElement();
  741. String value = systemP.get(name).toString();
  742. this.setPropertyInternal(name.toString(), value);
  743. }
  744. }
  745. /**
  746. * Adds a new task definition to the project.
  747. * Attempting to override an existing definition with an
  748. * equivalent one (i.e. with the same classname) results in
  749. * a verbose log message. Attempting to override an existing definition
  750. * with a different one results in a warning log message and
  751. * invalidates any tasks which have already been created with the
  752. * old definition.
  753. *
  754. * @param taskName The name of the task to add.
  755. * Must not be <code>null</code>.
  756. * @param taskClass The full name of the class implementing the task.
  757. * Must not be <code>null</code>.
  758. *
  759. * @exception BuildException if the class is unsuitable for being an Ant
  760. * task. An error level message is logged before
  761. * this exception is thrown.
  762. *
  763. * @see #checkTaskClass(Class)
  764. */
  765. public void addTaskDefinition(String taskName, Class taskClass)
  766. throws BuildException {
  767. ComponentHelper.getComponentHelper(this).addTaskDefinition(taskName,
  768. taskClass);
  769. }
  770. /**
  771. * Checks whether or not a class is suitable for serving as Ant task.
  772. * Ant task implementation classes must be public, concrete, and have
  773. * a no-arg constructor.
  774. *
  775. * @param taskClass The class to be checked.
  776. * Must not be <code>null</code>.
  777. *
  778. * @exception BuildException if the class is unsuitable for being an Ant
  779. * task. An error level message is logged before
  780. * this exception is thrown.
  781. */
  782. public void checkTaskClass(final Class taskClass) throws BuildException {
  783. ComponentHelper.getComponentHelper(this).checkTaskClass(taskClass);
  784. if (!Modifier.isPublic(taskClass.getModifiers())) {
  785. final String message = taskClass + " is not public";
  786. log(message, Project.MSG_ERR);
  787. throw new BuildException(message);
  788. }
  789. if (Modifier.isAbstract(taskClass.getModifiers())) {
  790. final String message = taskClass + " is abstract";
  791. log(message, Project.MSG_ERR);
  792. throw new BuildException(message);
  793. }
  794. try {
  795. taskClass.getConstructor(null);
  796. // don't have to check for public, since
  797. // getConstructor finds public constructors only.
  798. } catch (NoSuchMethodException e) {
  799. final String message = "No public no-arg constructor in "
  800. + taskClass;
  801. log(message, Project.MSG_ERR);
  802. throw new BuildException(message);
  803. }
  804. if (!Task.class.isAssignableFrom(taskClass)) {
  805. TaskAdapter.checkTaskClass(taskClass, this);
  806. }
  807. }
  808. /**
  809. * Returns the current task definition hashtable. The returned hashtable is
  810. * "live" and so should not be modified.
  811. *
  812. * @return a map of from task name to implementing class
  813. * (String to Class).
  814. */
  815. public Hashtable getTaskDefinitions() {
  816. return ComponentHelper.getComponentHelper(this).getTaskDefinitions();
  817. }
  818. /**
  819. * Adds a new datatype definition.
  820. * Attempting to override an existing definition with an
  821. * equivalent one (i.e. with the same classname) results in
  822. * a verbose log message. Attempting to override an existing definition
  823. * with a different one results in a warning log message, but the
  824. * definition is changed.
  825. *
  826. * @param typeName The name of the datatype.
  827. * Must not be <code>null</code>.
  828. * @param typeClass The full name of the class implementing the datatype.
  829. * Must not be <code>null</code>.
  830. */
  831. public void addDataTypeDefinition(String typeName, Class typeClass) {
  832. ComponentHelper.getComponentHelper(this).addDataTypeDefinition(typeName,
  833. typeClass);
  834. }
  835. /**
  836. * Returns the current datatype definition hashtable. The returned
  837. * hashtable is "live" and so should not be modified.
  838. *
  839. * @return a map of from datatype name to implementing class
  840. * (String to Class).
  841. */
  842. public Hashtable getDataTypeDefinitions() {
  843. return ComponentHelper.getComponentHelper(this).getDataTypeDefinitions();
  844. }
  845. /**
  846. * Adds a <em>new</em> target to the project.
  847. *
  848. * @param target The target to be added to the project.
  849. * Must not be <code>null</code>.
  850. *
  851. * @exception BuildException if the target already exists in the project
  852. *
  853. * @see Project#addOrReplaceTarget
  854. */
  855. public void addTarget(Target target) throws BuildException {
  856. String name = target.getName();
  857. if (targets.get(name) != null) {
  858. throw new BuildException("Duplicate target: `" + name + "'");
  859. }
  860. addOrReplaceTarget(name, target);
  861. }
  862. /**
  863. * Adds a <em>new</em> target to the project.
  864. *
  865. * @param targetName The name to use for the target.
  866. * Must not be <code>null</code>.
  867. * @param target The target to be added to the project.
  868. * Must not be <code>null</code>.
  869. *
  870. * @exception BuildException if the target already exists in the project
  871. *
  872. * @see Project#addOrReplaceTarget
  873. */
  874. public void addTarget(String targetName, Target target)
  875. throws BuildException {
  876. if (targets.get(targetName) != null) {
  877. throw new BuildException("Duplicate target: `" + targetName + "'");
  878. }
  879. addOrReplaceTarget(targetName, target);
  880. }
  881. /**
  882. * Adds a target to the project, or replaces one with the same
  883. * name.
  884. *
  885. * @param target The target to be added or replaced in the project.
  886. * Must not be <code>null</code>.
  887. */
  888. public void addOrReplaceTarget(Target target) {
  889. addOrReplaceTarget(target.getName(), target);
  890. }
  891. /**
  892. * Adds a target to the project, or replaces one with the same
  893. * name.
  894. *
  895. * @param targetName The name to use for the target.
  896. * Must not be <code>null</code>.
  897. * @param target The target to be added or replaced in the project.
  898. * Must not be <code>null</code>.
  899. */
  900. public void addOrReplaceTarget(String targetName, Target target) {
  901. String msg = " +Target: " + targetName;
  902. log(msg, MSG_DEBUG);
  903. target.setProject(this);
  904. targets.put(targetName, target);
  905. }
  906. /**
  907. * Returns the hashtable of targets. The returned hashtable
  908. * is "live" and so should not be modified.
  909. * @return a map from name to target (String to Target).
  910. */
  911. public Hashtable getTargets() {
  912. return targets;
  913. }
  914. /**
  915. * Creates a new instance of a task, adding it to a list of
  916. * created tasks for later invalidation. This causes all tasks
  917. * to be remembered until the containing project is removed
  918. * @param taskType The name of the task to create an instance of.
  919. * Must not be <code>null</code>.
  920. *
  921. * @return an instance of the specified task, or <code>null</code> if
  922. * the task name is not recognised.
  923. *
  924. * @exception BuildException if the task name is recognised but task
  925. * creation fails.
  926. */
  927. public Task createTask(String taskType) throws BuildException {
  928. return ComponentHelper.getComponentHelper(this).createTask(taskType);
  929. }
  930. /**
  931. * Creates a new instance of a data type.
  932. *
  933. * @param typeName The name of the data type to create an instance of.
  934. * Must not be <code>null</code>.
  935. *
  936. * @return an instance of the specified data type, or <code>null</code> if
  937. * the data type name is not recognised.
  938. *
  939. * @exception BuildException if the data type name is recognised but
  940. * instance creation fails.
  941. */
  942. public Object createDataType(String typeName) throws BuildException {
  943. return ComponentHelper.getComponentHelper(this).createDataType(typeName);
  944. }
  945. /**
  946. * Execute the specified sequence of targets, and the targets
  947. * they depend on.
  948. *
  949. * @param targetNames A vector of target name strings to execute.
  950. * Must not be <code>null</code>.
  951. *
  952. * @exception BuildException if the build failed
  953. */
  954. public void executeTargets(Vector targetNames) throws BuildException {
  955. for (int i = 0; i < targetNames.size(); i++) {
  956. executeTarget((String) targetNames.elementAt(i));
  957. }
  958. }
  959. /**
  960. * Demultiplexes output so that each task receives the appropriate
  961. * messages. If the current thread is not currently executing a task,
  962. * the message is logged directly.
  963. *
  964. * @param line Message to handle. Should not be <code>null</code>.
  965. * @param isError Whether the text represents an error (<code>true</code>)
  966. * or information (<code>false</code>).
  967. */
  968. public void demuxOutput(String line, boolean isError) {
  969. Task task = getThreadTask(Thread.currentThread());
  970. if (task == null) {
  971. fireMessageLogged(this, line, isError ? MSG_ERR : MSG_INFO);
  972. } else {
  973. if (isError) {
  974. task.handleErrorOutput(line);
  975. } else {
  976. task.handleOutput(line);
  977. }
  978. }
  979. }
  980. /**
  981. * Read data from the default input stream. If no default has been
  982. * specified, System.in is used.
  983. *
  984. * @param buffer the buffer into which data is to be read.
  985. * @param offset the offset into the buffer at which data is stored.
  986. * @param length the amount of data to read
  987. *
  988. * @return the number of bytes read
  989. *
  990. * @exception IOException if the data cannot be read
  991. * @since Ant 1.6
  992. */
  993. public int defaultInput(byte[] buffer, int offset, int length)
  994. throws IOException {
  995. if (defaultInputStream != null) {
  996. return defaultInputStream.read(buffer, offset, length);
  997. } else {
  998. throw new EOFException("No input provided for project");
  999. }
  1000. }
  1001. /**
  1002. * Demux an input request to the correct task.
  1003. *
  1004. * @param buffer the buffer into which data is to be read.
  1005. * @param offset the offset into the buffer at which data is stored.
  1006. * @param length the amount of data to read
  1007. *
  1008. * @return the number of bytes read
  1009. *
  1010. * @exception IOException if the data cannot be read
  1011. * @since Ant 1.6
  1012. */
  1013. public int demuxInput(byte[] buffer, int offset, int length)
  1014. throws IOException {
  1015. Task task = getThreadTask(Thread.currentThread());
  1016. if (task == null) {
  1017. return defaultInput(buffer, offset, length);
  1018. } else {
  1019. return task.handleInput(buffer, offset, length);
  1020. }
  1021. }
  1022. /**
  1023. * Demultiplexes flush operation so that each task receives the appropriate
  1024. * messages. If the current thread is not currently executing a task,
  1025. * the message is logged directly.
  1026. *
  1027. * @since Ant 1.5.2
  1028. *
  1029. * @param line Message to handle. Should not be <code>null</code>.
  1030. * @param isError Whether the text represents an error (<code>true</code>)
  1031. * or information (<code>false</code>).
  1032. */
  1033. public void demuxFlush(String line, boolean isError) {
  1034. Task task = getThreadTask(Thread.currentThread());
  1035. if (task == null) {
  1036. fireMessageLogged(this, line, isError ? MSG_ERR : MSG_INFO);
  1037. } else {
  1038. if (isError) {
  1039. task.handleErrorFlush(line);
  1040. } else {
  1041. task.handleFlush(line);
  1042. }
  1043. }
  1044. }
  1045. /**
  1046. * Executes the specified target and any targets it depends on.
  1047. *
  1048. * @param targetName The name of the target to execute.
  1049. * Must not be <code>null</code>.
  1050. *
  1051. * @exception BuildException if the build failed
  1052. */
  1053. public void executeTarget(String targetName) throws BuildException {
  1054. // sanity check ourselves, if we've been asked to build nothing
  1055. // then we should complain
  1056. if (targetName == null) {
  1057. String msg = "No target specified";
  1058. throw new BuildException(msg);
  1059. }
  1060. // Sort the dependency tree, and run everything from the
  1061. // beginning until we hit our targetName.
  1062. // Sorting checks if all the targets (and dependencies)
  1063. // exist, and if there is any cycle in the dependency
  1064. // graph.
  1065. Vector sortedTargets = topoSort(targetName, targets);
  1066. int curidx = 0;
  1067. Target curtarget;
  1068. do {
  1069. curtarget = (Target) sortedTargets.elementAt(curidx++);
  1070. curtarget.performTasks();
  1071. } while (!curtarget.getName().equals(targetName));
  1072. }
  1073. /**
  1074. * Returns the canonical form of a filename.
  1075. * <p>
  1076. * If the specified file name is relative it is resolved
  1077. * with respect to the given root directory.
  1078. *
  1079. * @param fileName The name of the file to resolve.
  1080. * Must not be <code>null</code>.
  1081. *
  1082. * @param rootDir The directory to resolve relative file names with
  1083. * respect to. May be <code>null</code>, in which case
  1084. * the current directory is used.
  1085. *
  1086. * @return the resolved File.
  1087. *
  1088. * @deprecated
  1089. */
  1090. public File resolveFile(String fileName, File rootDir) {
  1091. return fileUtils.resolveFile(rootDir, fileName);
  1092. }
  1093. /**
  1094. * Returns the canonical form of a filename.
  1095. * <p>
  1096. * If the specified file name is relative it is resolved
  1097. * with respect to the project's base directory.
  1098. *
  1099. * @param fileName The name of the file to resolve.
  1100. * Must not be <code>null</code>.
  1101. *
  1102. * @return the resolved File.
  1103. *
  1104. */
  1105. public File resolveFile(String fileName) {
  1106. return fileUtils.resolveFile(baseDir, fileName);
  1107. }
  1108. /**
  1109. * Translates a path into its native (platform specific) format.
  1110. * <p>
  1111. * This method uses PathTokenizer to separate the input path
  1112. * into its components. This handles DOS style paths in a relatively
  1113. * sensible way. The file separators are then converted to their platform
  1114. * specific versions.
  1115. *
  1116. * @param toProcess The path to be translated.
  1117. * May be <code>null</code>.
  1118. *
  1119. * @return the native version of the specified path or
  1120. * an empty string if the path is <code>null</code> or empty.
  1121. *
  1122. * @see PathTokenizer
  1123. */
  1124. public static String translatePath(String toProcess) {
  1125. if (toProcess == null || toProcess.length() == 0) {
  1126. return "";
  1127. }
  1128. StringBuffer path = new StringBuffer(toProcess.length() + 50);
  1129. PathTokenizer tokenizer = new PathTokenizer(toProcess);
  1130. while (tokenizer.hasMoreTokens()) {
  1131. String pathComponent = tokenizer.nextToken();
  1132. pathComponent = pathComponent.replace('/', File.separatorChar);
  1133. pathComponent = pathComponent.replace('\\', File.separatorChar);
  1134. if (path.length() != 0) {
  1135. path.append(File.pathSeparatorChar);
  1136. }
  1137. path.append(pathComponent);
  1138. }
  1139. return path.toString();
  1140. }
  1141. /**
  1142. * Convenience method to copy a file from a source to a destination.
  1143. * No filtering is performed.
  1144. *
  1145. * @param sourceFile Name of file to copy from.
  1146. * Must not be <code>null</code>.
  1147. * @param destFile Name of file to copy to.
  1148. * Must not be <code>null</code>.
  1149. *
  1150. * @exception IOException if the copying fails
  1151. *
  1152. * @deprecated
  1153. */
  1154. public void copyFile(String sourceFile, String destFile)
  1155. throws IOException {
  1156. fileUtils.copyFile(sourceFile, destFile);
  1157. }
  1158. /**
  1159. * Convenience method to copy a file from a source to a destination
  1160. * specifying if token filtering should be used.
  1161. *
  1162. * @param sourceFile Name of file to copy from.
  1163. * Must not be <code>null</code>.
  1164. * @param destFile Name of file to copy to.
  1165. * Must not be <code>null</code>.
  1166. * @param filtering Whether or not token filtering should be used during
  1167. * the copy.
  1168. *
  1169. * @exception IOException if the copying fails
  1170. *
  1171. * @deprecated
  1172. */
  1173. public void copyFile(String sourceFile, String destFile, boolean filtering)
  1174. throws IOException {
  1175. fileUtils.copyFile(sourceFile, destFile,
  1176. filtering ? globalFilters : null);
  1177. }
  1178. /**
  1179. * Convenience method to copy a file from a source to a
  1180. * destination specifying if token filtering should be used and if
  1181. * source files may overwrite newer destination files.
  1182. *
  1183. * @param sourceFile Name of file to copy from.
  1184. * Must not be <code>null</code>.
  1185. * @param destFile Name of file to copy to.
  1186. * Must not be <code>null</code>.
  1187. * @param filtering Whether or not token filtering should be used during
  1188. * the copy.
  1189. * @param overwrite Whether or not the destination file should be
  1190. * overwritten if it already exists.
  1191. *
  1192. * @exception IOException if the copying fails
  1193. *
  1194. * @deprecated
  1195. */
  1196. public void copyFile(String sourceFile, String destFile, boolean filtering,
  1197. boolean overwrite) throws IOException {
  1198. fileUtils.copyFile(sourceFile, destFile,
  1199. filtering ? globalFilters : null, overwrite);
  1200. }
  1201. /**
  1202. * Convenience method to copy a file from a source to a
  1203. * destination specifying if token filtering should be used, if
  1204. * source files may overwrite newer destination files, and if the
  1205. * last modified time of the resulting file should be set to
  1206. * that of the source file.
  1207. *
  1208. * @param sourceFile Name of file to copy from.
  1209. * Must not be <code>null</code>.
  1210. * @param destFile Name of file to copy to.
  1211. * Must not be <code>null</code>.
  1212. * @param filtering Whether or not token filtering should be used during
  1213. * the copy.
  1214. * @param overwrite Whether or not the destination file should be
  1215. * overwritten if it already exists.
  1216. * @param preserveLastModified Whether or not the last modified time of
  1217. * the resulting file should be set to that
  1218. * of the source file.
  1219. *
  1220. * @exception IOException if the copying fails
  1221. *
  1222. * @deprecated
  1223. */
  1224. public void copyFile(String sourceFile, String destFile, boolean filtering,
  1225. boolean overwrite, boolean preserveLastModified)
  1226. throws IOException {
  1227. fileUtils.copyFile(sourceFile, destFile,
  1228. filtering ? globalFilters : null, overwrite, preserveLastModified);
  1229. }
  1230. /**
  1231. * Convenience method to copy a file from a source to a destination.
  1232. * No filtering is performed.
  1233. *
  1234. * @param sourceFile File to copy from.
  1235. * Must not be <code>null</code>.
  1236. * @param destFile File to copy to.
  1237. * Must not be <code>null</code>.
  1238. *
  1239. * @exception IOException if the copying fails
  1240. *
  1241. * @deprecated
  1242. */
  1243. public void copyFile(File sourceFile, File destFile) throws IOException {
  1244. fileUtils.copyFile(sourceFile, destFile);
  1245. }
  1246. /**
  1247. * Convenience method to copy a file from a source to a destination
  1248. * specifying if token filtering should be used.
  1249. *
  1250. * @param sourceFile File to copy from.
  1251. * Must not be <code>null</code>.
  1252. * @param destFile File to copy to.
  1253. * Must not be <code>null</code>.
  1254. * @param filtering Whether or not token filtering should be used during
  1255. * the copy.
  1256. *
  1257. * @exception IOException if the copying fails
  1258. *
  1259. * @deprecated
  1260. */
  1261. public void copyFile(File sourceFile, File destFile, boolean filtering)
  1262. throws IOException {
  1263. fileUtils.copyFile(sourceFile, destFile,
  1264. filtering ? globalFilters : null);
  1265. }
  1266. /**
  1267. * Convenience method to copy a file from a source to a
  1268. * destination specifying if token filtering should be used and if
  1269. * source files may overwrite newer destination files.
  1270. *
  1271. * @param sourceFile File to copy from.
  1272. * Must not be <code>null</code>.
  1273. * @param destFile File to copy to.
  1274. * Must not be <code>null</code>.
  1275. * @param filtering Whether or not token filtering should be used during
  1276. * the copy.
  1277. * @param overwrite Whether or not the destination file should be
  1278. * overwritten if it already exists.
  1279. *
  1280. * @exception IOException if the file cannot be copied.
  1281. *
  1282. * @deprecated
  1283. */
  1284. public void copyFile(File sourceFile, File destFile, boolean filtering,
  1285. boolean overwrite) throws IOException {
  1286. fileUtils.copyFile(sourceFile, destFile,
  1287. filtering ? globalFilters : null, overwrite);
  1288. }
  1289. /**
  1290. * Convenience method to copy a file from a source to a
  1291. * destination specifying if token filtering should be used, if
  1292. * source files may overwrite newer destination files, and if the
  1293. * last modified time of the resulting file should be set to
  1294. * that of the source file.
  1295. *
  1296. * @param sourceFile File to copy from.
  1297. * Must not be <code>null</code>.
  1298. * @param destFile File to copy to.
  1299. * Must not be <code>null</code>.
  1300. * @param filtering Whether or not token filtering should be used during
  1301. * the copy.
  1302. * @param overwrite Whether or not the destination file should be
  1303. * overwritten if it already exists.
  1304. * @param preserveLastModified Whether or not the last modified time of
  1305. * the resulting file should be set to that
  1306. * of the source file.
  1307. *
  1308. * @exception IOException if the file cannot be copied.
  1309. *
  1310. * @deprecated
  1311. */
  1312. public void copyFile(File sourceFile, File destFile, boolean filtering,
  1313. boolean overwrite, boolean preserveLastModified)
  1314. throws IOException {
  1315. fileUtils.copyFile(sourceFile, destFile,
  1316. filtering ? globalFilters : null, overwrite, preserveLastModified);
  1317. }
  1318. /**
  1319. * Calls File.setLastModified(long time) on Java above 1.1, and logs
  1320. * a warning on Java 1.1.
  1321. *
  1322. * @param file The file to set the last modified time on.
  1323. * Must not be <code>null</code>.
  1324. *
  1325. * @param time the required modification time.
  1326. *
  1327. * @deprecated
  1328. *
  1329. * @exception BuildException if the last modified time cannot be set
  1330. * despite running on a platform with a version
  1331. * above 1.1.
  1332. */
  1333. public void setFileLastModified(File file, long time)
  1334. throws BuildException {
  1335. if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
  1336. log("Cannot change the modification time of " + file
  1337. + " in JDK 1.1", Project.MSG_WARN);
  1338. return;
  1339. }
  1340. fileUtils.setFileLastModified(file, time);
  1341. log("Setting modification time for " + file, MSG_VERBOSE);
  1342. }
  1343. /**
  1344. * Returns the boolean equivalent of a string, which is considered
  1345. * <code>true</code> if either <code>"on"</code>, <code>"true"</code>,
  1346. * or <code>"yes"</code> is found, ignoring case.
  1347. *
  1348. * @param s The string to convert to a boolean value.
  1349. * Must not be <code>null</code>.
  1350. *
  1351. * @return <code>true</code> if the given string is <code>"on"</code>,
  1352. * <code>"true"</code> or <code>"yes"</code>, or
  1353. * <code>false</code> otherwise.
  1354. */
  1355. public static boolean toBoolean(String s) {
  1356. return (s.equalsIgnoreCase("on") ||
  1357. s.equalsIgnoreCase("true") ||
  1358. s.equalsIgnoreCase("yes"));
  1359. }
  1360. /**
  1361. * Topologically sorts a set of targets.
  1362. *
  1363. * @param root The name of the root target. The sort is created in such
  1364. * a way that the sequence of Targets up to the root
  1365. * target is the minimum possible such sequence.
  1366. * Must not be <code>null</code>.
  1367. * @param targets A map of names to targets (String to Target).
  1368. * Must not be <code>null</code>.
  1369. * @return a vector of strings with the names of the targets in
  1370. * sorted order.
  1371. * @exception BuildException if there is a cyclic dependency among the
  1372. * targets, or if a named target does not exist.
  1373. */
  1374. public final Vector topoSort(String root, Hashtable targets)
  1375. throws BuildException {
  1376. Vector ret = new Vector();
  1377. Hashtable state = new Hashtable();
  1378. Stack visiting = new Stack();
  1379. // We first run a DFS based sort using the root as the starting node.
  1380. // This creates the minimum sequence of Targets to the root node.
  1381. // We then do a sort on any remaining unVISITED targets.
  1382. // This is unnecessary for doing our build, but it catches
  1383. // circular dependencies or missing Targets on the entire
  1384. // dependency tree, not just on the Targets that depend on the
  1385. // build Target.
  1386. tsort(root, targets, state, visiting, ret);
  1387. log("Build sequence for target `" + root + "' is " + ret, MSG_VERBOSE);
  1388. for (Enumeration en = targets.keys(); en.hasMoreElements();) {
  1389. String curTarget = (String) en.nextElement();
  1390. String st = (String) state.get(curTarget);
  1391. if (st == null) {
  1392. tsort(curTarget, targets, state, visiting, ret);
  1393. } else if (st == VISITING) {
  1394. throw new RuntimeException("Unexpected node in visiting state: "
  1395. + curTarget);
  1396. }
  1397. }
  1398. log("Complete build sequence is " + ret, MSG_VERBOSE);
  1399. return ret;
  1400. }
  1401. /**
  1402. * Performs a single step in a recursive depth-first-search traversal of
  1403. * the target dependency tree.
  1404. * <p>
  1405. * The current target is first set to the "visiting" state, and pushed
  1406. * onto the "visiting" stack.
  1407. * <p>
  1408. * An exception is then thrown if any child of the current node is in the
  1409. * visiting state, as that implies a circular dependency. The exception
  1410. * contains details of the cycle, using elements of the "visiting" stack.
  1411. * <p>
  1412. * If any child has not already been "visited", this method is called
  1413. * recursively on it.
  1414. * <p>
  1415. * The current target is then added to the ordered list of targets. Note
  1416. * that this is performed after the children have been visited in order
  1417. * to get the correct order. The current target is set to the "visited"
  1418. * state.
  1419. * <p>
  1420. * By the time this method returns, the ordered list contains the sequence
  1421. * of targets up to and including the current target.
  1422. *
  1423. * @param root The current target to inspect.
  1424. * Must not be <code>null</code>.
  1425. * @param targets A mapping from names to targets (String to Target).
  1426. * Must not be <code>null</code>.
  1427. * @param state A mapping from target names to states
  1428. * (String to String).
  1429. * The states in question are "VISITING" and "VISITED".
  1430. * Must not be <code>null</code>.
  1431. * @param visiting A stack of targets which are currently being visited.
  1432. * Must not be <code>null</code>.
  1433. * @param ret The list to add target names to. This will end up
  1434. * containing the complete list of depenencies in
  1435. * dependency order.
  1436. * Must not be <code>null</code>.
  1437. *
  1438. * @exception BuildException if a non-existent target is specified or if
  1439. * a circular dependency is detected.
  1440. */
  1441. private final void tsort(String root, Hashtable targets,
  1442. Hashtable state, Stack visiting,
  1443. Vector ret)
  1444. throws BuildException {
  1445. state.put(root, VISITING);
  1446. visiting.push(root);
  1447. Target target = (Target) targets.get(root);
  1448. // Make sure we exist
  1449. if (target == null) {
  1450. StringBuffer sb = new StringBuffer("Target `");
  1451. sb.append(root);
  1452. sb.append("' does not exist in this project. ");
  1453. visiting.pop();
  1454. if (!visiting.empty()) {
  1455. String parent = (String) visiting.peek();
  1456. sb.append("It is used from target `");
  1457. sb.append(parent);
  1458. sb.append("'.");
  1459. }
  1460. throw new BuildException(new String(sb));
  1461. }
  1462. for (Enumeration en = target.getDependencies(); en.hasMoreElements();) {
  1463. String cur = (String) en.nextElement();
  1464. String m = (String) state.get(cur);
  1465. if (m == null) {
  1466. // Not been visited
  1467. tsort(cur, targets, state, visiting, ret);
  1468. } else if (m == VISITING) {
  1469. // Currently visiting this node, so have a cycle
  1470. throw makeCircularException(cur, visiting);
  1471. }
  1472. }
  1473. String p = (String) visiting.pop();
  1474. if (root != p) {
  1475. throw new RuntimeException("Unexpected internal error: expected to "
  1476. + "pop " + root + " but got " + p);
  1477. }
  1478. state.put(root, VISITED);
  1479. ret.addElement(target);
  1480. }
  1481. /**
  1482. * Builds an appropriate exception detailing a specified circular
  1483. * dependency.
  1484. *
  1485. * @param end The dependency to stop at. Must not be <code>null</code>.
  1486. * @param stk A stack of dependencies. Must not be <code>null</code>.
  1487. *
  1488. * @return a BuildException detailing the specified circular dependency.
  1489. */
  1490. private static BuildException makeCircularException(String end, Stack stk) {
  1491. StringBuffer sb = new StringBuffer("Circular dependency: ");
  1492. sb.append(end);
  1493. String c;
  1494. do {
  1495. c = (String) stk.pop();
  1496. sb.append(" <- ");
  1497. sb.append(c);
  1498. } while (!c.equals(end));
  1499. return new BuildException(new String(sb));
  1500. }
  1501. /**
  1502. * Adds a reference to the project.
  1503. *
  1504. * @param name The name of the reference. Must not be <code>null</code>.
  1505. * @param value The value of the reference. Must not be <code>null</code>.
  1506. */
  1507. public void addReference(String name, Object value) {
  1508. synchronized (references) {
  1509. Object old = ((AntRefTable) references).getReal(name);
  1510. if (old == value) {
  1511. // no warning, this is not changing anything
  1512. return;
  1513. }
  1514. if (old != null && !(old instanceof UnknownElement)) {
  1515. log("Overriding previous definition of reference to " + name,
  1516. MSG_WARN);
  1517. }
  1518. String valueAsString = "";
  1519. try {
  1520. valueAsString = value.toString();
  1521. } catch (Throwable t) {
  1522. log("Caught exception (" + t.getClass().getName() + ")"
  1523. + " while expanding " + name + ": " + t.getMessage(),
  1524. MSG_WARN);
  1525. }
  1526. log("Adding reference: " + name + " -> " + valueAsString,
  1527. MSG_DEBUG);
  1528. references.put(name, value);
  1529. }
  1530. }
  1531. /**
  1532. * Returns a map of the references in the project (String to Object).
  1533. * The returned hashtable is "live" and so must not be modified.
  1534. *
  1535. * @return a map of the references in the project (String to Object).
  1536. */
  1537. public Hashtable getReferences() {
  1538. return references;
  1539. }
  1540. /**
  1541. * Looks up a reference by its key (ID).
  1542. *
  1543. * @param key The key for the desired reference.
  1544. * Must not be <code>null</code>.
  1545. *
  1546. * @return the reference with the specified ID, or <code>null</code> if
  1547. * there is no such reference in the project.
  1548. */
  1549. public Object getReference(String key) {
  1550. return references.get(key);
  1551. }
  1552. /**
  1553. * Returns a description of the type of the given element, with
  1554. * special handling for instances of tasks and data types.
  1555. * <p>
  1556. * This is useful for logging purposes.
  1557. *
  1558. * @param element The element to describe.
  1559. * Must not be <code>null</code>.
  1560. *
  1561. * @return a description of the element type
  1562. *
  1563. * @since 1.95, Ant 1.5
  1564. */
  1565. public String getElementName(Object element) {
  1566. return ComponentHelper.getComponentHelper(this).getElementName(element);
  1567. }
  1568. /**
  1569. * Sends a "build started" event to the build listeners for this project.
  1570. */
  1571. public void fireBuildStarted() {
  1572. BuildEvent event = new BuildEvent(this);
  1573. Vector listeners = getBuildListeners();
  1574. int size = listeners.size();
  1575. for (int i = 0; i < size; i++) {
  1576. BuildListener listener = (BuildListener) listeners.elementAt(i);
  1577. listener.buildStarted(event);
  1578. }
  1579. }
  1580. /**
  1581. * Sends a "build finished" event to the build listeners for this project.
  1582. * @param exception an exception indicating a reason for a build
  1583. * failure. May be <code>null</code>, indicating
  1584. * a successful build.
  1585. */
  1586. public void fireBuildFinished(Throwable exception) {
  1587. BuildEvent event = new BuildEvent(this);
  1588. event.setException(exception);
  1589. Vector listeners = getBuildListeners();
  1590. int size = listeners.size();
  1591. for (int i = 0; i < size; i++) {
  1592. BuildListener listener = (BuildListener) listeners.elementAt(i);
  1593. listener.buildFinished(event);
  1594. }
  1595. }
  1596. /**
  1597. * Sends a "target started" event to the build listeners for this project.
  1598. *
  1599. * @param target The target which is starting to build.
  1600. * Must not be <code>null</code>.
  1601. */
  1602. protected void fireTargetStarted(Target target) {
  1603. BuildEvent event = new BuildEvent(target);
  1604. Vector listeners = getBuildListeners();
  1605. int size = listeners.size();
  1606. for (int i = 0; i < size; i++) {
  1607. BuildListener listener = (BuildListener) listeners.elementAt(i);
  1608. listener.targetStarted(event);
  1609. }
  1610. }
  1611. /**
  1612. * Sends a "target finished" event to the build listeners for this
  1613. * project.
  1614. *
  1615. * @param target The target which has finished building.
  1616. * Must not be <code>null</code>.
  1617. * @param exception an exception indicating a reason for a build
  1618. * failure. May be <code>null</code>, indicating
  1619. * a successful build.
  1620. */
  1621. protected void fireTargetFinished(Target target, Throwable exception) {
  1622. BuildEvent event = new BuildEvent(target);
  1623. event.setException(exception);
  1624. Vector listeners = getBuildListeners();
  1625. int size = listeners.size();
  1626. for (int i = 0; i < size; i++) {
  1627. BuildListener listener = (BuildListener) listeners.elementAt(i);
  1628. listener.targetFinished(event);
  1629. }
  1630. }
  1631. /**
  1632. * Sends a "task started" event to the build listeners for this project.
  1633. *
  1634. * @param task The target which is starting to execute.
  1635. * Must not be <code>null</code>.
  1636. */
  1637. protected void fireTaskStarted(Task task) {
  1638. // register this as the current task on the current thread.
  1639. registerThreadTask(Thread.currentThread(), task);
  1640. BuildEvent event = new BuildEvent(task);
  1641. Vector listeners = getBuildListeners();
  1642. int size = listeners.size();
  1643. for (int i = 0; i < size; i++) {
  1644. BuildListener listener = (BuildListener) listeners.elementAt(i);
  1645. listener.taskStarted(event);
  1646. }
  1647. }
  1648. /**
  1649. * Sends a "task finished" event to the build listeners for this
  1650. * project.
  1651. *
  1652. * @param task The task which has finished executing.
  1653. * Must not be <code>null</code>.
  1654. * @param exception an exception indicating a reason for a build
  1655. * failure. May be <code>null</code>, indicating
  1656. * a successful build.
  1657. */
  1658. protected void fireTaskFinished(Task task, Throwable exception) {
  1659. registerThreadTask(Thread.currentThread(), null);
  1660. System.out.flush();
  1661. System.err.flush();
  1662. BuildEvent event = new BuildEvent(task);
  1663. event.setException(exception);
  1664. Vector listeners = getBuildListeners();
  1665. int size = listeners.size();
  1666. for (int i = 0; i < size; i++) {
  1667. BuildListener listener = (BuildListener) listeners.elementAt(i);
  1668. listener.taskFinished(event);
  1669. }
  1670. }
  1671. /**
  1672. * Sends a "message logged" event to the build listeners for this project.
  1673. *
  1674. * @param event The event to send. This should be built up with the
  1675. * appropriate task/target/project by the caller, so that
  1676. * this method can set the message and priority, then send
  1677. * the event. Must not be <code>null</code>.
  1678. * @param message The message to send. Should not be <code>null</code>.
  1679. * @param priority The priority of the message.
  1680. */
  1681. private void fireMessageLoggedEvent(BuildEvent event, String message,
  1682. int priority) {
  1683. event.setMessage(message, priority);
  1684. Vector listeners = getBuildListeners();
  1685. synchronized (this) {
  1686. if (loggingMessage) {
  1687. throw new BuildException("Listener attempted to access "
  1688. + (priority == MSG_ERR ? "System.err" : "System.out")
  1689. + " - infinite loop terminated");
  1690. }
  1691. loggingMessage = true;
  1692. int size = listeners.size();
  1693. for (int i = 0; i < size; i++) {
  1694. BuildListener listener = (BuildListener) listeners.elementAt(i);
  1695. listener.messageLogged(event);
  1696. }
  1697. loggingMessage = false;
  1698. }
  1699. }
  1700. /**
  1701. * Sends a "message logged" project level event to the build listeners for
  1702. * this project.
  1703. *
  1704. * @param project The project generating the event.
  1705. * Should not be <code>null</code>.
  1706. * @param message The message to send. Should not be <code>null</code>.
  1707. * @param priority The priority of the message.
  1708. */
  1709. protected void fireMessageLogged(Project project, String message,
  1710. int priority) {
  1711. BuildEvent event = new BuildEvent(project);
  1712. fireMessageLoggedEvent(event, message, priority);
  1713. }
  1714. /**
  1715. * Sends a "message logged" target level event to the build listeners for
  1716. * this project.
  1717. *
  1718. * @param target The target generating the event.
  1719. * Must not be <code>null</code>.
  1720. * @param message The message to send. Should not be <code>null</code>.
  1721. * @param priority The priority of the message.
  1722. */
  1723. protected void fireMessageLogged(Target target, String message,
  1724. int priority) {
  1725. BuildEvent event = new BuildEvent(target);
  1726. fireMessageLoggedEvent(event, message, priority);
  1727. }
  1728. /**
  1729. * Sends a "message logged" task level event to the build listeners for
  1730. * this project.
  1731. *
  1732. * @param task The task generating the event.
  1733. * Must not be <code>null</code>.
  1734. * @param message The message to send. Should not be <code>null</code>.
  1735. * @param priority The priority of the message.
  1736. */
  1737. protected void fireMessageLogged(Task task, String message, int priority) {
  1738. BuildEvent event = new BuildEvent(task);
  1739. fireMessageLoggedEvent(event, message, priority);
  1740. }
  1741. /**
  1742. * Register a task as the current task for a thread.
  1743. * If the task is null, the thread's entry is removed.
  1744. *
  1745. * @param thread the thread on which the task is registered.
  1746. * @param task the task to be registered.
  1747. * @since Ant 1.5
  1748. */
  1749. public synchronized void registerThreadTask(Thread thread, Task task) {
  1750. if (task != null) {
  1751. threadTasks.put(thread, task);
  1752. threadGroupTasks.put(thread.getThreadGroup(), task);
  1753. } else {
  1754. threadTasks.remove(thread);
  1755. threadGroupTasks.remove(thread.getThreadGroup());
  1756. }
  1757. }
  1758. /**
  1759. * Get the current task assopciated with a thread, if any
  1760. *
  1761. * @param thread the thread for which the task is required.
  1762. * @return the task which is currently registered for the given thread or
  1763. * null if no task is registered.
  1764. */
  1765. public Task getThreadTask(Thread thread) {
  1766. Task task = (Task) threadTasks.get(thread);
  1767. if (task == null) {
  1768. ThreadGroup group = thread.getThreadGroup();
  1769. while (task == null && group != null) {
  1770. task = (Task) threadGroupTasks.get(group);
  1771. group = group.getParent();
  1772. }
  1773. }
  1774. return task;
  1775. }
  1776. // Should move to a separate public class - and have API to add
  1777. // listeners, etc.
  1778. private static class AntRefTable extends Hashtable {
  1779. Project project;
  1780. public AntRefTable(Project project) {
  1781. super();
  1782. this.project = project;
  1783. }
  1784. /** Returns the unmodified original object.
  1785. * This method should be called internally to
  1786. * get the 'real' object.
  1787. * The normal get method will do the replacement
  1788. * of UnknownElement ( this is similar with the JDNI
  1789. * refs behavior )
  1790. */
  1791. public Object getReal(Object key) {
  1792. return super.get(key);
  1793. }
  1794. /** Get method for the reference table.
  1795. * It can be used to hook dynamic references and to modify
  1796. * some references on the fly - for example for delayed
  1797. * evaluation.
  1798. *
  1799. * It is important to make sure that the processing that is
  1800. * done inside is not calling get indirectly.
  1801. *
  1802. * @param key
  1803. * @return
  1804. */
  1805. public Object get(Object key) {
  1806. //System.out.println("AntRefTable.get " + key);
  1807. Object o = super.get(key);
  1808. if (o instanceof UnknownElement) {
  1809. // Make sure that
  1810. ((UnknownElement) o).maybeConfigure();
  1811. o = ((UnknownElement) o).getTask();
  1812. }
  1813. return o;
  1814. }
  1815. }
  1816. /**
  1817. * Set a reference to this Project on the parameterized object.
  1818. * Need to set the project before other set/add elements
  1819. * are called
  1820. * @param obj the object to invoke setProject(this) on
  1821. */
  1822. public final void setProjectReference( final Object obj ) {
  1823. if ( obj instanceof ProjectComponent ) {
  1824. ( (ProjectComponent) obj ).setProject( this );
  1825. return;
  1826. }
  1827. try {
  1828. Method method =
  1829. obj.getClass().getMethod(
  1830. "setProject", new Class[] {Project.class} );
  1831. if ( method != null ) {
  1832. method.invoke( obj, new Object[] { this } );
  1833. }
  1834. } catch (Throwable e) {
  1835. // ignore this if the object does not have
  1836. // a set project method or the method
  1837. // is private/protected.
  1838. }
  1839. }
  1840. }