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 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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 String toString() {
  56. StringBuffer sb = new StringBuffer();
  57. sb.append("BuildConfig["+(configFile==null?"null":configFile.getAbsoluteFile().toString())+"] #Files="+files.size());
  58. return sb.toString();
  59. }
  60. public static class BinarySourceFile {
  61. public BinarySourceFile(File dir, File src) {
  62. this.fromInPathDirectory = dir;
  63. this.binSrc = src;
  64. }
  65. public File fromInPathDirectory;
  66. public File binSrc;
  67. public boolean equals(Object obj) {
  68. if ((obj instanceof BinarySourceFile) &&
  69. (obj != null)) {
  70. BinarySourceFile other = (BinarySourceFile)obj;
  71. return(binSrc.equals(other.binSrc));
  72. }
  73. return false;
  74. }
  75. public int hashCode() {
  76. return binSrc != null ? binSrc.hashCode() : 0;
  77. }
  78. }
  79. /**
  80. * Intialises the javaOptions Map to hold the default
  81. * JDT Compiler settings. Added by AMC 01.20.2003 in reponse
  82. * to bug #29768 and enh. 29769.
  83. * The settings here are duplicated from those set in
  84. * org.eclipse.jdt.internal.compiler.batch.Main, but I've elected to
  85. * copy them rather than refactor the JDT class since this keeps
  86. * integration with future JDT releases easier (?).
  87. */
  88. public AjBuildConfig( ) {
  89. options = new AjCompilerOptions();
  90. }
  91. /**
  92. * returned files includes <ul>
  93. * <li>files explicitly listed on command-line</li>
  94. * <li>files listed by reference in argument list files</li>
  95. * <li>files contained in sourceRootDir if that exists</li>
  96. * </ul>
  97. *
  98. * @return all source files that should be compiled.
  99. */
  100. public List/*File*/ getFiles() {
  101. return files;
  102. }
  103. /**
  104. * returned files includes all .class files found in
  105. * a directory on the inpath, but does not include
  106. * .class files contained within jars.
  107. */
  108. public List/*BinarySourceFile*/ getBinaryFiles() {
  109. return binaryFiles;
  110. }
  111. public File getOutputDir() {
  112. return outputDir;
  113. }
  114. public void setFiles(List files) {
  115. this.files = files;
  116. }
  117. public void setOutputDir(File outputDir) {
  118. this.outputDir = outputDir;
  119. }
  120. public AjCompilerOptions getOptions() {
  121. return options;
  122. }
  123. /**
  124. * This does not include -bootclasspath but includes -extdirs and -classpath
  125. */
  126. public List getClasspath() { // XXX setters don't respect javadoc contract...
  127. return classpath;
  128. }
  129. public void setClasspath(List classpath) {
  130. this.classpath = classpath;
  131. }
  132. public List getBootclasspath() {
  133. return bootclasspath;
  134. }
  135. public void setBootclasspath(List bootclasspath) {
  136. this.bootclasspath = bootclasspath;
  137. }
  138. public File getOutputJar() {
  139. return outputJar;
  140. }
  141. public List/*File*/ getInpath() {
  142. // Elements of the list are either archives (jars/zips) or directories
  143. return inPath;
  144. }
  145. public List/*File*/ getInJars() {
  146. return inJars;
  147. }
  148. public Map getSourcePathResources() {
  149. return sourcePathResources;
  150. }
  151. public void setOutputJar(File outputJar) {
  152. this.outputJar = outputJar;
  153. }
  154. public void setInJars(List sourceJars) {
  155. this.inJars = sourceJars;
  156. }
  157. public void setInPath(List dirsOrJars) {
  158. inPath = dirsOrJars;
  159. // remember all the class files in directories on the inpath
  160. binaryFiles = new ArrayList();
  161. FileFilter filter = new FileFilter() {
  162. public boolean accept(File pathname) {
  163. return pathname.getPath().endsWith(".class");
  164. }};
  165. for (Iterator iter = dirsOrJars.iterator(); iter.hasNext();) {
  166. File inpathElement = (File) iter.next();
  167. if (inpathElement.isDirectory()) {
  168. File[] files = FileUtil.listFiles(inpathElement, filter);
  169. for (int i = 0; i < files.length; i++) {
  170. binaryFiles.add(new BinarySourceFile(inpathElement,files[i]));
  171. }
  172. }
  173. }
  174. }
  175. public List getSourceRoots() {
  176. return sourceRoots;
  177. }
  178. public void setSourceRoots(List sourceRootDir) {
  179. this.sourceRoots = sourceRootDir;
  180. }
  181. public File getConfigFile() {
  182. return configFile;
  183. }
  184. public void setConfigFile(File configFile) {
  185. this.configFile = configFile;
  186. }
  187. public void setIncrementalMode(boolean incrementalMode) {
  188. this.incrementalMode = incrementalMode;
  189. }
  190. public boolean isIncrementalMode() {
  191. return incrementalMode;
  192. }
  193. public void setIncrementalFile(File incrementalFile) {
  194. this.incrementalFile = incrementalFile;
  195. }
  196. public boolean isIncrementalFileMode() {
  197. return (null != incrementalFile);
  198. }
  199. /**
  200. * @return List (String) classpath of bootclasspath, injars, inpath, aspectpath
  201. * entries, specified classpath (extdirs, and classpath), and output dir or jar
  202. */
  203. public List getFullClasspath() {
  204. List full = new ArrayList();
  205. full.addAll(getBootclasspath()); // XXX Is it OK that boot classpath overrides inpath/injars/aspectpath?
  206. for (Iterator i = inJars.iterator(); i.hasNext(); ) {
  207. full.add(((File)i.next()).getAbsolutePath());
  208. }
  209. for (Iterator i = inPath.iterator();i.hasNext();) {
  210. full.add(((File)i.next()).getAbsolutePath());
  211. }
  212. for (Iterator i = aspectpath.iterator(); i.hasNext(); ) {
  213. full.add(((File)i.next()).getAbsolutePath());
  214. }
  215. full.addAll(getClasspath());
  216. // if (null != outputDir) {
  217. // full.add(outputDir.getAbsolutePath());
  218. // } else if (null != outputJar) {
  219. // full.add(outputJar.getAbsolutePath());
  220. // }
  221. return full;
  222. }
  223. public File getLintSpecFile() {
  224. return lintSpecFile;
  225. }
  226. public void setLintSpecFile(File lintSpecFile) {
  227. this.lintSpecFile = lintSpecFile;
  228. }
  229. public List getAspectpath() {
  230. return aspectpath;
  231. }
  232. public void setAspectpath(List aspectpath) {
  233. this.aspectpath = aspectpath;
  234. }
  235. /** @return true if any config file, sourceroots, sourcefiles, injars or inpath */
  236. public boolean hasSources() {
  237. return ((null != configFile)
  238. || (0 < sourceRoots.size())
  239. || (0 < files.size())
  240. || (0 < inJars.size())
  241. || (0 < inPath.size())
  242. );
  243. }
  244. // /** @return null if no errors, String errors otherwise */
  245. // public String configErrors() {
  246. // StringBuffer result = new StringBuffer();
  247. // // ok, permit both. sigh.
  248. //// if ((null != outputDir) && (null != outputJar)) {
  249. //// result.append("specified both outputDir and outputJar");
  250. //// }
  251. // // incremental => only sourceroots
  252. // //
  253. // return (0 == result.length() ? null : result.toString());
  254. // }
  255. /**
  256. * Install global values into local config
  257. * unless values conflict:
  258. * <ul>
  259. * <li>Collections are unioned</li>
  260. * <li>values takes local value unless default and global set</li>
  261. * <li>this only sets one of outputDir and outputJar as needed</li>
  262. * <ul>
  263. * This also configures super if javaOptions change.
  264. * @param global the AjBuildConfig to read globals from
  265. */
  266. public void installGlobals(AjBuildConfig global) { // XXX relies on default values
  267. // don't join the options - they already have defaults taken care of.
  268. // Map optionsMap = options.getMap();
  269. // join(optionsMap,global.getOptions().getMap());
  270. // options.set(optionsMap);
  271. join(aspectpath, global.aspectpath);
  272. join(classpath, global.classpath);
  273. if (null == configFile) {
  274. configFile = global.configFile; // XXX correct?
  275. }
  276. if (!isEmacsSymMode() && global.isEmacsSymMode()) {
  277. setEmacsSymMode(true);
  278. }
  279. join(files, global.files);
  280. if (!isGenerateModelMode() && global.isGenerateModelMode()) {
  281. setGenerateModelMode(true);
  282. }
  283. if (null == incrementalFile) {
  284. incrementalFile = global.incrementalFile;
  285. }
  286. if (!incrementalMode && global.incrementalMode) {
  287. incrementalMode = true;
  288. }
  289. join(inJars, global.inJars);
  290. join(inPath, global.inPath);
  291. if ((null == lintMode)
  292. || (AJLINT_DEFAULT.equals(lintMode))) {
  293. setLintMode(global.lintMode);
  294. }
  295. if (null == lintSpecFile) {
  296. lintSpecFile = global.lintSpecFile;
  297. }
  298. if (!isNoWeave() && global.isNoWeave()) {
  299. setNoWeave(true);
  300. }
  301. if ((null == outputDir) && (null == outputJar)) {
  302. if (null != global.outputDir) {
  303. outputDir = global.outputDir;
  304. }
  305. if (null != global.outputJar) {
  306. outputJar = global.outputJar;
  307. }
  308. }
  309. join(sourceRoots, global.sourceRoots);
  310. if (!isXnoInline() && global.isXnoInline()) {
  311. setXnoInline(true);
  312. }
  313. if (!isXserializableAspects() && global.isXserializableAspects()) {
  314. setXserializableAspects(true);
  315. }
  316. if (!isXlazyTjp() && global.isXlazyTjp()) {
  317. setXlazyTjp(true);
  318. }
  319. if (!isXreweavable() && global.isXreweavable()) {
  320. setXreweavable(true);
  321. }
  322. if (!getXreweavableCompressClasses() && global.getXreweavableCompressClasses()) {
  323. setXreweavableCompressClasses(true);
  324. }
  325. }
  326. void join(Collection local, Collection global) {
  327. for (Iterator iter = global.iterator(); iter.hasNext();) {
  328. Object next = iter.next();
  329. if (!local.contains(next)) {
  330. local.add(next);
  331. }
  332. }
  333. }
  334. void join(Map local, Map global) {
  335. for (Iterator iter = global.keySet().iterator(); iter.hasNext();) {
  336. Object key = iter.next();
  337. if (override || (null == local.get(key))) { //
  338. Object value = global.get(key);
  339. if (null != value) {
  340. local.put(key, value);
  341. }
  342. }
  343. }
  344. }
  345. public void setSourcePathResources(Map map) {
  346. sourcePathResources = map;
  347. }
  348. /**
  349. * used to indicate whether to proceed after parsing config
  350. */
  351. public boolean shouldProceed() {
  352. return shouldProceed;
  353. }
  354. public void doNotProceed() {
  355. shouldProceed = false;
  356. }
  357. public String getLintMode() {
  358. return lintMode;
  359. }
  360. // options...
  361. public void setLintMode(String lintMode) {
  362. this.lintMode = lintMode;
  363. String lintValue = null;
  364. if (AJLINT_IGNORE.equals(lintMode)) {
  365. lintValue = AjCompilerOptions.IGNORE;
  366. } else if (AJLINT_WARN.equals(lintMode)) {
  367. lintValue = AjCompilerOptions.WARNING;
  368. } else if (AJLINT_ERROR.equals(lintMode)) {
  369. lintValue = AjCompilerOptions.ERROR;
  370. }
  371. if (lintValue != null) {
  372. Map lintOptions = new HashMap();
  373. lintOptions.put(AjCompilerOptions.OPTION_ReportInvalidAbsoluteTypeName,lintValue);
  374. lintOptions.put(AjCompilerOptions.OPTION_ReportInvalidWildcardTypeName,lintValue);
  375. lintOptions.put(AjCompilerOptions.OPTION_ReportUnresolvableMember,lintValue);
  376. lintOptions.put(AjCompilerOptions.OPTION_ReportTypeNotExposedToWeaver,lintValue);
  377. lintOptions.put(AjCompilerOptions.OPTION_ReportShadowNotInStructure,lintValue);
  378. lintOptions.put(AjCompilerOptions.OPTION_ReportUnmatchedSuperTypeInCall,lintValue);
  379. lintOptions.put(AjCompilerOptions.OPTION_ReportCannotImplementLazyTJP,lintValue);
  380. lintOptions.put(AjCompilerOptions.OPTION_ReportNeedSerialVersionUIDField,lintValue);
  381. lintOptions.put(AjCompilerOptions.OPTION_ReportIncompatibleSerialVersion,lintValue);
  382. options.set(lintOptions);
  383. }
  384. }
  385. public boolean isNoWeave() {
  386. return options.noWeave;
  387. }
  388. public void setNoWeave(boolean noWeave) {
  389. options.noWeave = noWeave;
  390. }
  391. public boolean isXserializableAspects() {
  392. return options.xSerializableAspects;
  393. }
  394. public void setXserializableAspects(boolean xserializableAspects) {
  395. options.xSerializableAspects = xserializableAspects;
  396. }
  397. public boolean isXnoInline() {
  398. return options.xNoInline;
  399. }
  400. public void setXnoInline(boolean xnoInline) {
  401. options.xNoInline = xnoInline;
  402. }
  403. public boolean isXlazyTjp() {
  404. return options.xLazyThisJoinPoint;
  405. }
  406. public void setXlazyTjp(boolean b) {
  407. options.xLazyThisJoinPoint = b;
  408. }
  409. public void setXreweavable(boolean b) {
  410. options.xReweavable = b;
  411. }
  412. public void setXHasMemberSupport(boolean enabled) {
  413. options.xHasMember = enabled;
  414. }
  415. public boolean isXHasMemberEnabled() {
  416. return options.xHasMember;
  417. }
  418. public void setXdevPinpointMode(boolean enabled) {
  419. options.xdevPinpoint = enabled;
  420. }
  421. public boolean isXdevPinpoint() {
  422. return options.xdevPinpoint;
  423. }
  424. public boolean isXreweavable() {
  425. return options.xReweavable;
  426. }
  427. public void setXreweavableCompressClasses(boolean b) {
  428. options.xReweavableCompress = b;
  429. }
  430. public boolean getXreweavableCompressClasses() {
  431. return options.xReweavableCompress;
  432. }
  433. public boolean isGenerateJavadocsInModelMode() {
  434. return options.generateJavaDocsInModel;
  435. }
  436. public void setGenerateJavadocsInModelMode(
  437. boolean generateJavadocsInModelMode) {
  438. options.generateJavaDocsInModel = generateJavadocsInModelMode;
  439. }
  440. public boolean isEmacsSymMode() {
  441. return options.generateEmacsSymFiles;
  442. }
  443. public void setEmacsSymMode(boolean emacsSymMode) {
  444. options.generateEmacsSymFiles = emacsSymMode;
  445. }
  446. public boolean isGenerateModelMode() {
  447. return options.generateModel;
  448. }
  449. public void setGenerateModelMode(boolean structureModelMode) {
  450. options.generateModel = structureModelMode;
  451. }
  452. public boolean isNoAtAspectJAnnotationProcessing() {
  453. return options.noAtAspectJProcessing;
  454. }
  455. public void setNoAtAspectJAnnotationProcessing(boolean noProcess) {
  456. options.noAtAspectJProcessing = noProcess;
  457. }
  458. public void setShowWeavingInformation(boolean b) {
  459. options.showWeavingInformation = true;
  460. }
  461. public boolean getShowWeavingInformation() {
  462. return options.showWeavingInformation;
  463. }
  464. public void setProceedOnError(boolean b) {
  465. options.proceedOnError = b;
  466. }
  467. public boolean getProceedOnError() {
  468. return options.proceedOnError;
  469. }
  470. public void setBehaveInJava5Way(boolean b) {
  471. options.behaveInJava5Way = b;
  472. }
  473. public boolean getBehaveInJava5Way() {
  474. return options.behaveInJava5Way;
  475. }
  476. }