Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AjBuildConfig.java 16KB

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