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

Ajdoc.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. /* *******************************************************************
  2. * Copyright (c) 2000-2001 Xerox Corporation.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * Xerox/PARC initial implementation
  11. * 2006, Arno Schmidmeier, (reactivated the source and removed deprecated calls)
  12. * ******************************************************************/
  13. package org.aspectj.tools.ant.taskdefs;
  14. import java.io.File;
  15. import java.util.ArrayList;
  16. import java.util.Collection;
  17. import java.util.Collections;
  18. import java.util.Enumeration;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;
  22. import java.util.StringJoiner;
  23. import java.util.StringTokenizer;
  24. import java.util.Vector;
  25. import org.apache.tools.ant.BuildException;
  26. import org.apache.tools.ant.DirectoryScanner;
  27. import org.apache.tools.ant.Location;
  28. import org.apache.tools.ant.Project;
  29. import org.apache.tools.ant.taskdefs.MatchingTask;
  30. import org.apache.tools.ant.taskdefs.Javadoc.AccessType;
  31. import org.apache.tools.ant.taskdefs.Javadoc.Html;
  32. import org.apache.tools.ant.types.Commandline;
  33. import org.apache.tools.ant.types.FileSet;
  34. import org.apache.tools.ant.types.Path;
  35. import org.apache.tools.ant.types.Reference;
  36. import org.aspectj.tools.ajdoc.Main;
  37. /**
  38. * A task to run the ajdoc tool.
  39. *
  40. * @author Jeff Palm
  41. */
  42. public class Ajdoc extends MatchingTask {
  43. /** The name of ajdoc class we're using. */
  44. public final static String AJDOC_CLASSNAME = "org.aspectj.tools.ajdoc.Main";
  45. /** If true, ignore fork param and use FORCE_FORK_VALUE */
  46. public final static boolean FORCE_FORK = false;
  47. /** value used as fork when FORCE_FORK is true */
  48. public final static boolean FORCE_FORK_VALUE = true;
  49. protected Commandline cmd;
  50. protected Commandline vmcmd;
  51. private Path sourcepath;
  52. private File destdir;
  53. private Collection<String> sourcefiles;
  54. private Collection<String> packagenames;
  55. private File packageList;
  56. private Path bootclasspath;
  57. private Path extdirs;
  58. private Path classpath;
  59. private Path internalclasspath;
  60. private List<File> argfiles;
  61. private Path docletpath;
  62. private Collection<Link> links;
  63. private Collection<Group> groups;
  64. private Doclet doclet;
  65. private boolean failonerror;
  66. private boolean fork;
  67. private String source;
  68. private Html bottom;
  69. private Vector<FileSet> fileSets = new Vector<>();
  70. /** reset all to initial values - permit gc if Ajdoc is held */
  71. public Ajdoc() {
  72. reset();
  73. }
  74. protected void reset() {
  75. cmd = new Commandline();
  76. vmcmd = new Commandline();
  77. sourcepath = null;
  78. destdir = null ;
  79. sourcefiles = null;
  80. packagenames = null;
  81. packageList = null;
  82. bootclasspath = null;
  83. extdirs = null;
  84. classpath = null;
  85. internalclasspath = null;
  86. argfiles = null;
  87. docletpath = null;
  88. links = new ArrayList<>();
  89. groups = new ArrayList<>();
  90. doclet = null;
  91. failonerror = false;
  92. fork = false;
  93. source = null;
  94. bottom = null;
  95. }
  96. protected final boolean setif(boolean b, String flag) {
  97. if (b) cmd.createArgument().setValue(flag);
  98. return b;
  99. }
  100. protected final void setfile(String flag, String file) {
  101. set(flag, getProject().resolveFile(file).getAbsolutePath());
  102. }
  103. protected final void set(String flag, String val) {
  104. setif(true, flag, val);
  105. }
  106. protected final boolean setif(boolean b, String flag, String val) {
  107. if (setif(b, flag)) cmd.createArgument().setValue(val);
  108. return b;
  109. }
  110. public void setSource(String input) {
  111. source = input;
  112. }
  113. public void setSourcepath(Path path) {
  114. if (sourcepath == null) {
  115. sourcepath = path;
  116. } else {
  117. sourcepath.append(path);
  118. }
  119. }
  120. public Path createSourcepath() {
  121. return sourcepath == null ?
  122. (sourcepath = new Path(getProject())) :
  123. sourcepath.createPath();
  124. }
  125. public void setSourcepathRef(Reference id) {
  126. createSourcepath().setRefid(id);
  127. }
  128. public void setSrcdir(Path path) { setSourcepath(path); }
  129. public Path createSrcdir() { return createSourcepath(); }
  130. public void setSrcdirRef(Reference id) { setSourcepathRef(id); }
  131. public void setDestdir(String destdir) {
  132. this.destdir = getProject().resolveFile(destdir);
  133. }
  134. public void setSourcefiles(String list) {
  135. (sourcefiles == null ?
  136. sourcefiles = new ArrayList<>() :
  137. sourcefiles).addAll(strings(list));
  138. }
  139. public void addFileset(FileSet fs) {
  140. fileSets.addElement(fs);
  141. }
  142. private void addFileSets() {
  143. if(sourcefiles == null)
  144. sourcefiles = new ArrayList<>();
  145. Enumeration<FileSet> e = fileSets.elements();
  146. while (e.hasMoreElements()) {
  147. FileSet fs = e.nextElement();
  148. if (!fs.hasPatterns() && !fs.hasSelectors()) {
  149. fs = (FileSet) fs.clone();
  150. fs.createInclude().setName("**/*.java");
  151. fs.createInclude().setName("**/*.aj");
  152. }
  153. File baseDir = fs.getDir(getProject());
  154. DirectoryScanner ds = fs.getDirectoryScanner(getProject());
  155. String[] files = ds.getIncludedFiles();
  156. for (String file : files) {
  157. sourcefiles.add((new File(baseDir, file)).getAbsolutePath());
  158. }
  159. }
  160. }
  161. public void setPackagenames(String list) {
  162. (packagenames == null ?
  163. packagenames = new ArrayList<>() :
  164. packagenames).addAll(strings(list, true));
  165. }
  166. public void setAccess(AccessType at) {
  167. cmd.createArgument().setValue("-" + at.getValue());
  168. }
  169. public void setPackageList(String packageList) {
  170. this.packageList = getProject().resolveFile(packageList);
  171. }
  172. public void setClasspath(Path path) {
  173. if (classpath == null) {
  174. classpath = path;
  175. } else {
  176. classpath.append(path);
  177. }
  178. }
  179. public Path createClasspath() {
  180. return (classpath == null ?
  181. classpath = new Path(getProject()) :
  182. classpath).createPath();
  183. }
  184. public void setClasspathref(Reference id) {
  185. createClasspath().setRefid(id);
  186. }
  187. public void setBootclasspath(Path path) { // todo: unsupported
  188. if (bootclasspath == null) {
  189. bootclasspath = path;
  190. } else {
  191. bootclasspath.append(path);
  192. }
  193. }
  194. public Path createBootclasspath() { // todo: unsupported
  195. return (bootclasspath == null ?
  196. bootclasspath = new Path(getProject()) :
  197. bootclasspath).createPath();
  198. }
  199. public void setBootclasspathref(Reference bootclasspathref) { // todo: unsupported
  200. createBootclasspath().setRefid(bootclasspathref);
  201. }
  202. public void setInternalclasspath(Path internalclasspath) {
  203. if (this.internalclasspath == null) {
  204. this.internalclasspath = internalclasspath;
  205. } else {
  206. this.internalclasspath.append(internalclasspath);
  207. }
  208. }
  209. public Path createInternalclasspath() {
  210. if (internalclasspath == null) {
  211. internalclasspath = new Path(getProject());
  212. }
  213. return internalclasspath.createPath();
  214. }
  215. public void setInternalclasspathref(Reference internalclasspathref) {
  216. createInternalclasspath().setRefid(internalclasspathref);
  217. }
  218. public void setExtdirs(Path path) {
  219. if (extdirs == null) {
  220. extdirs = path;
  221. } else {
  222. extdirs.append(path);
  223. }
  224. }
  225. public List<File> createArgfiles() {
  226. return (argfiles == null ?
  227. argfiles = new ArrayList<>() :
  228. argfiles);
  229. }
  230. public void setArgfile(String argfile) {
  231. createArgfiles().add(getProject().resolveFile(argfile));
  232. }
  233. public void setArgfiles(String argfiles) {
  234. createArgfiles().addAll(files(argfiles));
  235. }
  236. public void setOverview(String overview) {
  237. setfile("-overview", overview);
  238. }
  239. public void setPublic(boolean b) {
  240. setif(b, "-public");
  241. }
  242. public void setPackage(boolean b) {
  243. setif(b, "-package");
  244. }
  245. public void setProtected(boolean b) {
  246. setif(b, "-protected");
  247. }
  248. public void setPrivate(boolean b) {
  249. setif(b, "-private");
  250. }
  251. public void setOld(boolean old) {
  252. setif(old, "-old");
  253. }
  254. public void setAuthor(boolean author) {
  255. setif(author, "-author");
  256. }
  257. public void setSplitindex(boolean splitindex) {
  258. setif(splitindex, "-splitindex");
  259. }
  260. public void setWindowtitle(String windowtitle) {
  261. set("-windowtitle", windowtitle);
  262. }
  263. public void setDoctitle(String doctitle) {
  264. set("-doctitle", doctitle);
  265. }
  266. public void setHeader(String header) {
  267. set("-header", header);
  268. }
  269. public void setFooter(String footer) {
  270. set("-footer", footer);
  271. }
  272. public void setBottom(String bottom) {
  273. Html html = new Html();
  274. html.addText(bottom);
  275. addBottom(html);
  276. }
  277. public void addBottom(Html text) {
  278. bottom = text;
  279. }
  280. public void setVerbose(boolean b) {
  281. setif(b, "-verbose");
  282. }
  283. public void setVersion(boolean b) {
  284. setif(b, "-version");
  285. }
  286. public void setUse(boolean b) {
  287. setif(b, "-use");
  288. }
  289. public void setStandard(boolean b) {
  290. setif(b, "-standard");
  291. }
  292. public class Link {
  293. protected String href;
  294. protected boolean offline;
  295. protected String packagelistLoc;
  296. public Link() {}
  297. public void setHref(String href) {
  298. this.href = href;
  299. }
  300. public void setOffline(boolean offline) {
  301. this.offline = offline;
  302. }
  303. public void setPackagelistLoc(String packagelistLoc) {
  304. this.packagelistLoc = packagelistLoc;
  305. }
  306. }
  307. public void setLink(String href) {
  308. createLink().setHref(href);
  309. }
  310. public Link createLink() {
  311. Link link = new Link();
  312. links.add(link);
  313. return link;
  314. }
  315. public void setLinkoffline(String linkoffline) {
  316. Link link = createLink();
  317. int ispace = linkoffline.indexOf(" ");
  318. if (ispace == -1) {
  319. throw new BuildException("linkoffline usage: <url> <url2>!", getLocation());
  320. }
  321. link.setHref(linkoffline.substring(0, ispace).trim());
  322. link.setPackagelistLoc(linkoffline.substring(ispace+1).trim());
  323. }
  324. public class Group {
  325. private String title;
  326. private List<String> packages;
  327. public Group() {}
  328. public void setTitle(String title) {
  329. this.title = title;
  330. }
  331. public final void setPackages(String packages) {
  332. setPackagenames(packages);
  333. }
  334. public void setPackagenames(String packages) {
  335. this.packages = strings(packages);
  336. }
  337. }
  338. public void setGroup(String str) {
  339. for (StringTokenizer t = new StringTokenizer(str, ",", false);
  340. t.hasMoreTokens();) {
  341. String s = t.nextToken().trim();
  342. int ispace = s.indexOf(' ');
  343. if (ispace != -1) {
  344. Group group = createGroup();
  345. group.setTitle(s.substring(0, ispace));
  346. group.setPackagenames(s.substring(ispace+1));
  347. } else {
  348. throw new BuildException
  349. ("group usage: group=[<title> <pkglist>]*", getLocation());
  350. }
  351. }
  352. }
  353. public Group createGroup() {
  354. Group group = new Group();
  355. groups.add(group);
  356. return group;
  357. }
  358. public void setNodeprecated(boolean nodeprecated) {
  359. setif(nodeprecated, "-nodeprecated");
  360. }
  361. public void setNodeprecatedlist(boolean nodeprecatedlist) {
  362. setif(nodeprecatedlist, "-nodeprecatedlist");
  363. }
  364. public void setNotree(boolean notree) {
  365. setif(notree, "-notree");
  366. }
  367. public void setNoindex(boolean noindex) {
  368. setif(noindex, "-noindex");
  369. }
  370. public void setNohelp(boolean nohelp) {
  371. setif(nohelp, "-nohelp");
  372. }
  373. public void setNonavbar(boolean nonavbar) {
  374. setif(nonavbar, "-nonavbar");
  375. }
  376. public void setSerialwarn(boolean serialwarn) {
  377. setif(serialwarn, "-serialwarn");
  378. }
  379. public void setHelpfile(String helpfile) {
  380. setfile("-helpfile", helpfile);
  381. }
  382. public void setStylesheetfile(String stylesheetfile) {
  383. setfile("-stylesheetfile", stylesheetfile);
  384. }
  385. public void setCharset(String charset) { set("-charset", charset); }
  386. public void setDocencoding(String docencoding) {
  387. set("-docencoding", docencoding);
  388. }
  389. public void setDoclet(String doclet) {
  390. createDoclet().setName(doclet);
  391. }
  392. public static class Param {
  393. protected String name;
  394. protected String value;
  395. public Param() {}
  396. public void setName(String name) { this.name = name; }
  397. public void setValue(String value) { this.value = value; }
  398. }
  399. public class Doclet {
  400. protected String name;
  401. protected Path path;
  402. protected List<Param> params = new ArrayList<>();
  403. public Doclet() {}
  404. public void setName(String name) {
  405. this.name = name;
  406. }
  407. public void setPath(Path path) {
  408. if (this.path == null) {
  409. this.path = path;
  410. } else {
  411. this.path.append(path);
  412. }
  413. }
  414. public Path createPath() {
  415. return (path == null ?
  416. path = new Path(getProject()) :
  417. path).createPath();
  418. }
  419. public Param createParam() {
  420. Param param = new Param();
  421. params.add(param);
  422. return param;
  423. }
  424. }
  425. public Doclet createDoclet() {
  426. if (doclet != null) {
  427. throw new BuildException("Only one doclet is allowed!");
  428. }
  429. return doclet = new Doclet();
  430. }
  431. public void setDocletpath(Path path) {
  432. (docletpath == null ?
  433. docletpath = path :
  434. docletpath).append(path);
  435. }
  436. public Path createDocletpath() {
  437. return docletpath == null ?
  438. (docletpath = new Path(getProject())) :
  439. docletpath.createPath();
  440. }
  441. public void setDocletpathRef(Reference id) {
  442. createDocletpath().setRefid(id);
  443. }
  444. public void setAdditionalparam(String additionalparam) {
  445. cmd.createArgument().setLine(additionalparam);
  446. }
  447. public void setFailonerror(boolean failonerror) {
  448. this.failonerror = failonerror;
  449. }
  450. public void setFork(boolean fork) {
  451. this.fork = fork;
  452. }
  453. public Commandline.Argument createJvmarg() {
  454. return vmcmd.createArgument();
  455. }
  456. public void setMaxmemory(String max) {
  457. createJvmarg().setValue((Project.getJavaVersion().
  458. startsWith("1.1") ?
  459. "-mx" : "-Xmx") +max);
  460. }
  461. public void execute() throws BuildException {
  462. if (sourcepath == null && argfiles == null && fileSets.size() == 0) {
  463. throw new BuildException("one of sourcepath or argfiles must be set!",
  464. getLocation());
  465. }
  466. if (sourcepath != null) {
  467. cmd.createArgument().setValue("-sourcepath");
  468. cmd.createArgument().setPath(sourcepath);
  469. }
  470. if (destdir != null) {
  471. cmd.createArgument().setValue("-d");
  472. cmd.createArgument().setFile(destdir);
  473. }
  474. if (classpath != null) {
  475. cmd.createArgument().setValue("-classpath");
  476. cmd.createArgument().setPath(classpath);
  477. }
  478. if (bootclasspath != null) {
  479. cmd.createArgument().setValue("-bootclasspath");
  480. cmd.createArgument().setPath(bootclasspath);
  481. }
  482. if (extdirs != null) {
  483. cmd.createArgument().setValue("-extdirs");
  484. cmd.createArgument().setPath(extdirs);
  485. }
  486. if (source != null) {
  487. cmd.createArgument().setValue("-source");
  488. cmd.createArgument().setValue(source);
  489. }
  490. if (bottom != null) {
  491. cmd.createArgument().setValue("-bottom");
  492. cmd.createArgument().setValue(getProject().replaceProperties(bottom.getText()));
  493. }
  494. for (Link link: links) {
  495. if (link.href == null) {
  496. throw new BuildException("Link href cannot be null!", getLocation());
  497. }
  498. if (link.packagelistLoc != null) {
  499. cmd.createArgument().setValue("-linkoffline");
  500. cmd.createArgument().setValue(link.href);
  501. cmd.createArgument().setValue(link.packagelistLoc);
  502. } else {
  503. cmd.createArgument().setValue("-link");
  504. cmd.createArgument().setValue(link.href);
  505. }
  506. }
  507. if (doclet != null) {
  508. if (doclet.name == null) {
  509. throw new BuildException("Doclet name cannot be null!", getLocation());
  510. }
  511. cmd.createArgument().setValue("-doclet");
  512. cmd.createArgument().setValue(doclet.name);
  513. if (doclet.path != null) {
  514. cmd.createArgument().setValue("-docletpath");
  515. cmd.createArgument().setPath(doclet.path);
  516. }
  517. for (Param param : doclet.params) {
  518. if (param.name == null) {
  519. throw new BuildException("Doclet params cannot be null!",
  520. getLocation());
  521. }
  522. cmd.createArgument().setValue(param.name);
  523. if (param.value == null) {
  524. cmd.createArgument().setValue(param.value);
  525. }
  526. }
  527. }
  528. Map<String,List<String>> groupMap = new HashMap<>();
  529. for (Group group: groups) {
  530. if (group.title == null) {
  531. throw new BuildException("Group names cannot be null!",
  532. getLocation());
  533. }
  534. if (group.packages == null) {
  535. throw new BuildException("Group packages cannot be null!",
  536. getLocation());
  537. }
  538. List<String> packages = groupMap.get(group.title);
  539. if (packages == null) {
  540. packages = new ArrayList<>();
  541. }
  542. packages.addAll(group.packages);
  543. groupMap.put(group.title, packages);
  544. }
  545. for (String title: groupMap.keySet()) {
  546. List<String> packages = groupMap.get(title);
  547. StringJoiner pkgstr = new StringJoiner(",");
  548. for (String aPackage : packages) {
  549. pkgstr.add(aPackage);
  550. }
  551. cmd.createArgument().setValue("-group");
  552. cmd.createArgument().setValue(title);
  553. cmd.createArgument().setValue(pkgstr.toString());
  554. }
  555. if (argfiles != null) {
  556. for (File file : argfiles) {
  557. String name = file + "";
  558. File argfile = getProject().resolveFile(name);
  559. if (check(argfile, name, false, getLocation())) {
  560. cmd.createArgument().setValue("-argfile");
  561. cmd.createArgument().setFile(argfile);
  562. }
  563. }
  564. }
  565. if (packageList != null) {
  566. cmd.createArgument().setValue("@" + packageList);
  567. }
  568. if (null != packagenames) {
  569. for (String packagename : packagenames) {
  570. cmd.createArgument().setValue(packagename);
  571. }
  572. }
  573. // support for include parameter as a MatchingTask
  574. int numfiles = 0;
  575. if (sourcepath != null) {
  576. String[] dirs = sourcepath.list();
  577. for (String value : dirs) {
  578. File dir = getProject().resolveFile(value);
  579. check(dir, value, true, getLocation());
  580. String[] files = getDirectoryScanner(dir).getIncludedFiles();
  581. for (String s : files) {
  582. File file = new File(dir, s);
  583. if (file.getName().endsWith(".java")
  584. || file.getName().endsWith(".aj")) {
  585. cmd.createArgument().setFile(file);
  586. numfiles++;
  587. }
  588. }
  589. }
  590. }
  591. addFileSets();
  592. if (sourcefiles != null) {
  593. for (String sourcefile : sourcefiles) {
  594. // let ajdoc resolve sourcefiles relative to sourcepath,
  595. cmd.createArgument().setValue(sourcefile);
  596. }
  597. }
  598. // XXX PR682 weak way to report errors - need to refactor
  599. int result = compile();
  600. if (failonerror && (0 != result)) {
  601. throw new BuildException("Ajdoc failed with code " + result);
  602. }
  603. reset();
  604. }
  605. protected int compile() throws BuildException { // todo: doc that fork is ignored
  606. try {
  607. String[] args = cmd.getArguments();
  608. if (fork) {
  609. log("Warning: fork is ignored ", Project.MSG_WARN);
  610. }
  611. Main.main(args);
  612. if (Main.hasAborted())
  613. return 1;
  614. else
  615. return 0;
  616. } catch (Throwable t) {
  617. throw new BuildException(t);
  618. }
  619. }
  620. protected interface Mapper<T> {
  621. T map(String str);
  622. }
  623. protected final <T> List<T> list(String str, Mapper<T> mapper) {
  624. if (str == null) return Collections.emptyList();
  625. List<T> list = new ArrayList<>();
  626. for (StringTokenizer t = new StringTokenizer(str, ",", false);
  627. t.hasMoreTokens();) {
  628. list.add(mapper.map(t.nextToken().trim()));
  629. }
  630. return list;
  631. }
  632. protected final List<File> files(String str) {
  633. return list(str, new Mapper<File>() {
  634. public File map(String s) {
  635. return getProject().resolveFile(s);
  636. }
  637. });
  638. }
  639. protected final List<String> strings(String str) {
  640. return strings(str, false);
  641. }
  642. protected final List<String> strings(String str, final boolean filterSlashes) {
  643. return list(str, new Mapper<String>() {
  644. public String map(String s) {
  645. return filterSlashes ? filterSlashes(s) : s;
  646. }
  647. });
  648. }
  649. protected final String filterSlashes(String str) {
  650. if (str == null) return null;
  651. return str.
  652. replace('/', '.').
  653. replace('\\', '.').
  654. replace(File.separatorChar, '.');
  655. }
  656. protected final boolean check(File file, String name,
  657. boolean isDir, Location loc) {
  658. loc = loc != null ? loc : getLocation();
  659. if (file == null) {
  660. throw new BuildException(name + " is null!", loc);
  661. }
  662. if (!file.exists()) {
  663. throw new BuildException(file + "doesn't exist!", loc);
  664. }
  665. if (isDir ^ file.isDirectory()) {
  666. throw new BuildException(file + " should" +
  667. (!isDir ? "n't" : "") +
  668. " be a directory!", loc);
  669. }
  670. return true;
  671. }
  672. }