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.

AjBuildConfig.java 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * Adrian Colyer added constructor to populate javaOptions with
  12. * default settings - 01.20.2003
  13. * Bugzilla #29768, 29769
  14. * ******************************************************************/
  15. package org.aspectj.ajdt.internal.core.builder;
  16. import java.io.File;
  17. import java.io.FileFilter;
  18. import java.util.ArrayList;
  19. import java.util.Collection;
  20. import java.util.HashMap;
  21. import java.util.Iterator;
  22. import java.util.List;
  23. import java.util.Map;
  24. import org.aspectj.util.FileUtil;
  25. /**
  26. * All configuration information needed to run the AspectJ compiler.
  27. * Compiler options (as opposed to path information) are held in an AjCompilerOptions instance
  28. */
  29. public class AjBuildConfig {
  30. private boolean shouldProceed = true;
  31. public static final String AJLINT_IGNORE = "ignore";
  32. public static final String AJLINT_WARN = "warn";
  33. public static final String AJLINT_ERROR = "error";
  34. public static final String AJLINT_DEFAULT = "default";
  35. private File outputDir;
  36. private File outputJar;
  37. private List/*File*/ sourceRoots = new ArrayList();
  38. private List/*File*/ files = new ArrayList();
  39. private List /*File*/ binaryFiles = new ArrayList(); // .class files in indirs...
  40. private List/*File*/ inJars = new ArrayList();
  41. private List/*File*/ inPath = new ArrayList();
  42. private Map/*String->File*/ sourcePathResources = new HashMap();
  43. private List/*File*/ aspectpath = new ArrayList();
  44. private List/*String*/ classpath = new ArrayList();
  45. private List/*String*/ bootclasspath = new ArrayList();
  46. private File configFile;
  47. private String lintMode = AJLINT_DEFAULT;
  48. private File lintSpecFile = null;
  49. private AjCompilerOptions options;
  50. /** if true, then global values override local when joining */
  51. private boolean override = true;
  52. // incremental variants handled by the compiler client, but parsed here
  53. private boolean incrementalMode;
  54. private File incrementalFile;
  55. public static class BinarySourceFile {
  56. public BinarySourceFile(File dir, File src) {
  57. this.fromInPathDirectory = dir;
  58. this.binSrc = src;
  59. }
  60. public File fromInPathDirectory;
  61. public File binSrc;
  62. public boolean equals(Object obj) {
  63. if ((obj instanceof BinarySourceFile) &&
  64. (obj != null)) {
  65. BinarySourceFile other = (BinarySourceFile)obj;
  66. return(binSrc.equals(other.binSrc));
  67. }
  68. return false;
  69. }
  70. public int hashCode() {
  71. return binSrc != null ? binSrc.hashCode() : 0;
  72. }
  73. }
  74. /**
  75. * Intialises the javaOptions Map to hold the default
  76. * JDT Compiler settings. Added by AMC 01.20.2003 in reponse
  77. * to bug #29768 and enh. 29769.
  78. * The settings here are duplicated from those set in
  79. * org.eclipse.jdt.internal.compiler.batch.Main, but I've elected to
  80. * copy them rather than refactor the JDT class since this keeps
  81. * integration with future JDT releases easier (?).
  82. */
  83. public AjBuildConfig( ) {
  84. options = new AjCompilerOptions();
  85. }
  86. /**
  87. * returned files includes <ul>
  88. * <li>files explicitly listed on command-line</li>
  89. * <li>files listed by reference in argument list files</li>
  90. * <li>files contained in sourceRootDir if that exists</li>
  91. * </ul>
  92. *
  93. * @return all source files that should be compiled.
  94. */
  95. public List/*File*/ getFiles() {
  96. return files;
  97. }
  98. /**
  99. * returned files includes all .class files found in
  100. * a directory on the inpath, but does not include
  101. * .class files contained within jars.
  102. */
  103. public List/*BinarySourceFile*/ getBinaryFiles() {
  104. return binaryFiles;
  105. }
  106. public File getOutputDir() {
  107. return outputDir;
  108. }
  109. public void setFiles(List files) {
  110. this.files = files;
  111. }
  112. public void setOutputDir(File outputDir) {
  113. this.outputDir = outputDir;
  114. }
  115. public AjCompilerOptions getOptions() {
  116. return options;
  117. }
  118. /**
  119. * This does not include -bootclasspath but includes -extdirs and -classpath
  120. */
  121. public List getClasspath() { // XXX setters don't respect javadoc contract...
  122. return classpath;
  123. }
  124. public void setClasspath(List classpath) {
  125. this.classpath = classpath;
  126. }
  127. public List getBootclasspath() {
  128. return bootclasspath;
  129. }
  130. public void setBootclasspath(List bootclasspath) {
  131. this.bootclasspath = bootclasspath;
  132. }
  133. public File getOutputJar() {
  134. return outputJar;
  135. }
  136. public List/*File*/ getInpath() {
  137. // Elements of the list are either archives (jars/zips) or directories
  138. return inPath;
  139. }
  140. public List/*File*/ getInJars() {
  141. return inJars;
  142. }
  143. public Map getSourcePathResources() {
  144. return sourcePathResources;
  145. }
  146. public void setOutputJar(File outputJar) {
  147. this.outputJar = outputJar;
  148. }
  149. public void setInJars(List sourceJars) {
  150. this.inJars = sourceJars;
  151. }
  152. public void setInPath(List dirsOrJars) {
  153. inPath = dirsOrJars;
  154. // remember all the class files in directories on the inpath
  155. binaryFiles = new ArrayList();
  156. FileFilter filter = new FileFilter() {
  157. public boolean accept(File pathname) {
  158. return pathname.getPath().endsWith(".class");
  159. }};
  160. for (Iterator iter = dirsOrJars.iterator(); iter.hasNext();) {
  161. File inpathElement = (File) iter.next();
  162. if (inpathElement.isDirectory()) {
  163. File[] files = FileUtil.listFiles(inpathElement, filter);
  164. for (int i = 0; i < files.length; i++) {
  165. binaryFiles.add(new BinarySourceFile(inpathElement,files[i]));
  166. }
  167. }
  168. }
  169. }
  170. public List getSourceRoots() {
  171. return sourceRoots;
  172. }
  173. public void setSourceRoots(List sourceRootDir) {
  174. this.sourceRoots = sourceRootDir;
  175. }
  176. public File getConfigFile() {
  177. return configFile;
  178. }
  179. public void setConfigFile(File configFile) {
  180. this.configFile = configFile;
  181. }
  182. public void setIncrementalMode(boolean incrementalMode) {
  183. this.incrementalMode = incrementalMode;
  184. }
  185. public boolean isIncrementalMode() {
  186. return incrementalMode;
  187. }
  188. public void setIncrementalFile(File incrementalFile) {
  189. this.incrementalFile = incrementalFile;
  190. }
  191. public boolean isIncrementalFileMode() {
  192. return (null != incrementalFile);
  193. }
  194. /**
  195. * @return List (String) classpath of bootclasspath, injars, inpath, aspectpath
  196. * entries, specified classpath (extdirs, and classpath), and output dir or jar
  197. */
  198. public List getFullClasspath() {
  199. List full = new ArrayList();
  200. full.addAll(getBootclasspath()); // XXX Is it OK that boot classpath overrides inpath/injars/aspectpath?
  201. for (Iterator i = inJars.iterator(); i.hasNext(); ) {
  202. full.add(((File)i.next()).getAbsolutePath());
  203. }
  204. for (Iterator i = inPath.iterator();i.hasNext();) {
  205. full.add(((File)i.next()).getAbsolutePath());
  206. }
  207. for (Iterator i = aspectpath.iterator(); i.hasNext(); ) {
  208. full.add(((File)i.next()).getAbsolutePath());
  209. }
  210. full.addAll(getClasspath());
  211. // if (null != outputDir) {
  212. // full.add(outputDir.getAbsolutePath());
  213. // } else if (null != outputJar) {
  214. // full.add(outputJar.getAbsolutePath());
  215. // }
  216. return full;
  217. }
  218. public File getLintSpecFile() {
  219. return lintSpecFile;
  220. }
  221. public void setLintSpecFile(File lintSpecFile) {
  222. this.lintSpecFile = lintSpecFile;
  223. }
  224. public List getAspectpath() {
  225. return aspectpath;
  226. }
  227. public void setAspectpath(List aspectpath) {
  228. this.aspectpath = aspectpath;
  229. }
  230. /** @return true if any config file, sourceroots, sourcefiles, injars or inpath */
  231. public boolean hasSources() {
  232. return ((null != configFile)
  233. || (0 < sourceRoots.size())
  234. || (0 < files.size())
  235. || (0 < inJars.size())
  236. || (0 < inPath.size())
  237. );
  238. }
  239. // /** @return null if no errors, String errors otherwise */
  240. // public String configErrors() {
  241. // StringBuffer result = new StringBuffer();
  242. // // ok, permit both. sigh.
  243. //// if ((null != outputDir) && (null != outputJar)) {
  244. //// result.append("specified both outputDir and outputJar");
  245. //// }
  246. // // incremental => only sourceroots
  247. // //
  248. // return (0 == result.length() ? null : result.toString());
  249. // }
  250. /**
  251. * Install global values into local config
  252. * unless values conflict:
  253. * <ul>
  254. * <li>Collections are unioned</li>
  255. * <li>values takes local value unless default and global set</li>
  256. * <li>this only sets one of outputDir and outputJar as needed</li>
  257. * <ul>
  258. * This also configures super if javaOptions change.
  259. * @param global the AjBuildConfig to read globals from
  260. */
  261. public void installGlobals(AjBuildConfig global) { // XXX relies on default values
  262. // don't join the options - they already have defaults taken care of.
  263. // Map optionsMap = options.getMap();
  264. // join(optionsMap,global.getOptions().getMap());
  265. // options.set(optionsMap);
  266. join(aspectpath, global.aspectpath);
  267. join(classpath, global.classpath);
  268. if (null == configFile) {
  269. configFile = global.configFile; // XXX correct?
  270. }
  271. if (!isEmacsSymMode() && global.isEmacsSymMode()) {
  272. setEmacsSymMode(true);
  273. }
  274. join(files, global.files);
  275. if (!isGenerateModelMode() && global.isGenerateModelMode()) {
  276. setGenerateModelMode(true);
  277. }
  278. if (null == incrementalFile) {
  279. incrementalFile = global.incrementalFile;
  280. }
  281. if (!incrementalMode && global.incrementalMode) {
  282. incrementalMode = true;
  283. }
  284. join(inJars, global.inJars);
  285. join(inPath, global.inPath);
  286. if ((null == lintMode)
  287. || (AJLINT_DEFAULT.equals(lintMode))) {
  288. setLintMode(global.lintMode);
  289. }
  290. if (null == lintSpecFile) {
  291. lintSpecFile = global.lintSpecFile;
  292. }
  293. if (!isNoWeave() && global.isNoWeave()) {
  294. setNoWeave(true);
  295. }
  296. if ((null == outputDir) && (null == outputJar)) {
  297. if (null != global.outputDir) {
  298. outputDir = global.outputDir;
  299. }
  300. if (null != global.outputJar) {
  301. outputJar = global.outputJar;
  302. }
  303. }
  304. join(sourceRoots, global.sourceRoots);
  305. if (!isXnoInline() && global.isXnoInline()) {
  306. setXnoInline(true);
  307. }
  308. if (!isXserializableAspects() && global.isXserializableAspects()) {
  309. setXserializableAspects(true);
  310. }
  311. if (!isXlazyTjp() && global.isXlazyTjp()) {
  312. setXlazyTjp(true);
  313. }
  314. if (!isXreweavable() && global.isXreweavable()) {
  315. setXreweavable(true);
  316. }
  317. if (!getXreweavableCompressClasses() && global.getXreweavableCompressClasses()) {
  318. setXreweavableCompressClasses(true);
  319. }
  320. }
  321. void join(Collection local, Collection global) {
  322. for (Iterator iter = global.iterator(); iter.hasNext();) {
  323. Object next = iter.next();
  324. if (!local.contains(next)) {
  325. local.add(next);
  326. }
  327. }
  328. }
  329. void join(Map local, Map global) {
  330. for (Iterator iter = global.keySet().iterator(); iter.hasNext();) {
  331. Object key = iter.next();
  332. if (override || (null == local.get(key))) { //
  333. Object value = global.get(key);
  334. if (null != value) {
  335. local.put(key, value);
  336. }
  337. }
  338. }
  339. }
  340. public void setSourcePathResources(Map map) {
  341. sourcePathResources = map;
  342. }
  343. /**
  344. * used to indicate whether to proceed after parsing config
  345. */
  346. public boolean shouldProceed() {
  347. return shouldProceed;
  348. }
  349. public void doNotProceed() {
  350. shouldProceed = false;
  351. }
  352. public String getLintMode() {
  353. return lintMode;
  354. }
  355. // options...
  356. public void setLintMode(String lintMode) {
  357. this.lintMode = lintMode;
  358. options.setLintMode(lintMode);
  359. }
  360. public boolean isNoWeave() {
  361. return options.noWeave;
  362. }
  363. public void setNoWeave(boolean noWeave) {
  364. options.noWeave = noWeave;
  365. }
  366. public boolean isXserializableAspects() {
  367. return options.xSerializableAspects;
  368. }
  369. public void setXserializableAspects(boolean xserializableAspects) {
  370. options.xSerializableAspects = xserializableAspects;
  371. }
  372. public boolean isXnoInline() {
  373. return options.xNoInline;
  374. }
  375. public void setXnoInline(boolean xnoInline) {
  376. options.xNoInline = xnoInline;
  377. }
  378. public boolean isXlazyTjp() {
  379. return options.xLazyThisJoinPoint;
  380. }
  381. public void setXlazyTjp(boolean b) {
  382. options.xLazyThisJoinPoint = b;
  383. }
  384. public void setXreweavable(boolean b) {
  385. options.xReweavable = b;
  386. }
  387. public boolean isXreweavable() {
  388. return options.xReweavable;
  389. }
  390. public void setXreweavableCompressClasses(boolean b) {
  391. options.xReweavableCompress = b;
  392. }
  393. public boolean getXreweavableCompressClasses() {
  394. return options.xReweavableCompress;
  395. }
  396. public boolean isGenerateJavadocsInModelMode() {
  397. return options.generateJavaDocsInModel;
  398. }
  399. public void setGenerateJavadocsInModelMode(
  400. boolean generateJavadocsInModelMode) {
  401. options.generateJavaDocsInModel = generateJavadocsInModelMode;
  402. }
  403. public boolean isEmacsSymMode() {
  404. return options.generateEmacsSymFiles;
  405. }
  406. public void setEmacsSymMode(boolean emacsSymMode) {
  407. options.generateEmacsSymFiles = emacsSymMode;
  408. }
  409. public boolean isGenerateModelMode() {
  410. return options.generateModel;
  411. }
  412. public void setGenerateModelMode(boolean structureModelMode) {
  413. options.generateModel = structureModelMode;
  414. }
  415. public void setShowWeavingInformation(boolean b) {
  416. options.showWeavingInformation = true;
  417. }
  418. public boolean getShowWeavingInformation() {
  419. return options.showWeavingInformation;
  420. }
  421. public void setProceedOnError(boolean b) {
  422. options.proceedOnError = b;
  423. }
  424. public boolean getProceedOnError() {
  425. return options.proceedOnError;
  426. }
  427. public void setBehaveInJava5Way(boolean b) {
  428. options.behaveInJava5Way = b;
  429. }
  430. public boolean getBehaveInJava5Way() {
  431. return options.behaveInJava5Way;
  432. }
  433. }