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.

AjBuildManager.java 60KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560
  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 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. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.core.builder;
  13. import java.io.BufferedOutputStream;
  14. import java.io.ByteArrayOutputStream;
  15. import java.io.File;
  16. import java.io.FileFilter;
  17. import java.io.FileInputStream;
  18. import java.io.FileNotFoundException;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import java.io.PrintStream;
  22. import java.util.ArrayList;
  23. import java.util.Collection;
  24. import java.util.Collections;
  25. import java.util.HashMap;
  26. import java.util.List;
  27. import java.util.Locale;
  28. import java.util.Map;
  29. import java.util.Set;
  30. import java.util.jar.Attributes;
  31. import java.util.jar.JarFile;
  32. import java.util.jar.JarInputStream;
  33. import java.util.jar.JarOutputStream;
  34. import java.util.jar.Manifest;
  35. import java.util.zip.ZipEntry;
  36. import org.aspectj.ajdt.ajc.BuildArgParser;
  37. import org.aspectj.ajdt.internal.compiler.AjCompilerAdapter;
  38. import org.aspectj.ajdt.internal.compiler.AjPipeliningCompilerAdapter;
  39. import org.aspectj.ajdt.internal.compiler.CompilationResultDestinationManager;
  40. import org.aspectj.ajdt.internal.compiler.IBinarySourceProvider;
  41. import org.aspectj.ajdt.internal.compiler.ICompilerAdapter;
  42. import org.aspectj.ajdt.internal.compiler.ICompilerAdapterFactory;
  43. import org.aspectj.ajdt.internal.compiler.IIntermediateResultsRequestor;
  44. import org.aspectj.ajdt.internal.compiler.IOutputClassFileNameProvider;
  45. import org.aspectj.ajdt.internal.compiler.InterimCompilationResult;
  46. import org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment;
  47. import org.aspectj.ajdt.internal.compiler.lookup.AnonymousClassPublisher;
  48. import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory;
  49. import org.aspectj.ajdt.internal.compiler.problem.AjProblemReporter;
  50. import org.aspectj.asm.AsmManager;
  51. import org.aspectj.asm.IHierarchy;
  52. import org.aspectj.asm.IProgramElement;
  53. import org.aspectj.asm.internal.ProgramElement;
  54. import org.aspectj.bridge.AbortException;
  55. import org.aspectj.bridge.CountingMessageHandler;
  56. import org.aspectj.bridge.ILifecycleAware;
  57. import org.aspectj.bridge.IMessage;
  58. import org.aspectj.bridge.IMessageHandler;
  59. import org.aspectj.bridge.IProgressListener;
  60. import org.aspectj.bridge.ISourceLocation;
  61. import org.aspectj.bridge.Message;
  62. import org.aspectj.bridge.MessageUtil;
  63. import org.aspectj.bridge.SourceLocation;
  64. import org.aspectj.bridge.Version;
  65. import org.aspectj.bridge.context.CompilationAndWeavingContext;
  66. import org.aspectj.bridge.context.ContextFormatter;
  67. import org.aspectj.bridge.context.ContextToken;
  68. import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation;
  69. import org.aspectj.org.eclipse.jdt.core.compiler.IProblem;
  70. import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile;
  71. import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult;
  72. import org.aspectj.org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
  73. import org.aspectj.org.eclipse.jdt.internal.compiler.ICompilerRequestor;
  74. import org.aspectj.org.eclipse.jdt.internal.compiler.IProblemFactory;
  75. import org.aspectj.org.eclipse.jdt.internal.compiler.batch.ClasspathLocation;
  76. import org.aspectj.org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
  77. import org.aspectj.org.eclipse.jdt.internal.compiler.batch.FileSystem;
  78. import org.aspectj.org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
  79. import org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
  80. import org.aspectj.org.eclipse.jdt.internal.compiler.env.IModule;
  81. import org.aspectj.org.eclipse.jdt.internal.compiler.env.INameEnvironment;
  82. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
  83. import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser;
  84. import org.aspectj.org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
  85. import org.aspectj.org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
  86. import org.aspectj.tools.ajc.Main;
  87. import org.aspectj.util.FileUtil;
  88. import org.aspectj.weaver.CustomMungerFactory;
  89. import org.aspectj.weaver.Dump;
  90. import org.aspectj.weaver.ResolvedType;
  91. import org.aspectj.weaver.World;
  92. import org.aspectj.weaver.bcel.BcelWeaver;
  93. import org.aspectj.weaver.bcel.BcelWorld;
  94. import org.aspectj.weaver.bcel.UnwovenClassFile;
  95. import org.eclipse.core.runtime.OperationCanceledException;
  96. public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySourceProvider, ICompilerAdapterFactory {
  97. private static final String CROSSREFS_FILE_NAME = "build.lst";
  98. private static final String CANT_WRITE_RESULT = "unable to write compilation result";
  99. private static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
  100. public static boolean COPY_INPATH_DIR_RESOURCES = false;
  101. // AJDT doesn't want this check, so Main enables it.
  102. private static boolean DO_RUNTIME_VERSION_CHECK = false;
  103. // If runtime version check fails, warn or fail? (unset?)
  104. static final boolean FAIL_IF_RUNTIME_NOT_FOUND = false;
  105. private static final FileFilter binarySourceFilter = new FileFilter() {
  106. @Override
  107. public boolean accept(File f) {
  108. return f.getName().endsWith(".class");
  109. }
  110. };
  111. /**
  112. * This builder is static so that it can be subclassed and reset. However, note that there is only one builder present, so if
  113. * two extendsion reset it, only the latter will get used.
  114. */
  115. public static AsmHierarchyBuilder asmHierarchyBuilder = new AsmHierarchyBuilder();
  116. static {
  117. // CompilationAndWeavingContext.setMultiThreaded(false);
  118. CompilationAndWeavingContext.registerFormatter(CompilationAndWeavingContext.BATCH_BUILD, new AjBuildContexFormatter());
  119. CompilationAndWeavingContext
  120. .registerFormatter(CompilationAndWeavingContext.INCREMENTAL_BUILD, new AjBuildContexFormatter());
  121. }
  122. private IProgressListener progressListener = null;
  123. private boolean environmentSupportsIncrementalCompilation = false;
  124. private int compiledCount;
  125. private int sourceFileCount;
  126. private JarOutputStream zos;
  127. private boolean batchCompile = true;
  128. private INameEnvironment environment;
  129. private Map<String, List<UnwovenClassFile>> /* String -> List<UCF> */binarySourcesForTheNextCompile = new HashMap<>();
  130. // FIXME asc should this really be in here?
  131. // private AsmManager structureModel;
  132. public AjBuildConfig buildConfig;
  133. private boolean ignoreOutxml;
  134. private boolean wasFullBuild = true; // true if last build was a full build rather than an incremental build
  135. AjState state = new AjState(this);
  136. /**
  137. * Enable check for runtime version, used only by Ant/command-line Main.
  138. *
  139. * @param caller Main unused except to limit to non-null clients.
  140. */
  141. public static void enableRuntimeVersionCheck(Main caller) {
  142. DO_RUNTIME_VERSION_CHECK = null != caller;
  143. }
  144. public BcelWeaver getWeaver() {
  145. return state.getWeaver();
  146. }
  147. public BcelWorld getBcelWorld() {
  148. return state.getBcelWorld();
  149. }
  150. public CountingMessageHandler handler;
  151. private CustomMungerFactory customMungerFactory;
  152. public AjBuildManager(IMessageHandler holder) {
  153. super();
  154. this.handler = CountingMessageHandler.makeCountingMessageHandler(holder);
  155. }
  156. public void environmentSupportsIncrementalCompilation(boolean itDoes) {
  157. this.environmentSupportsIncrementalCompilation = itDoes;
  158. if (itDoes) {
  159. org.aspectj.weaver.loadtime.definition.DocumentParser.deactivateCaching();
  160. }
  161. }
  162. /** @return true if we should generate a model as a side-effect */
  163. public boolean doGenerateModel() {
  164. return buildConfig.isGenerateModelMode();
  165. }
  166. public boolean batchBuild(AjBuildConfig buildConfig, IMessageHandler baseHandler) throws IOException, AbortException {
  167. return performBuild(buildConfig, baseHandler, true);
  168. }
  169. public boolean incrementalBuild(AjBuildConfig buildConfig, IMessageHandler baseHandler) throws IOException, AbortException {
  170. return performBuild(buildConfig, baseHandler, false);
  171. }
  172. /**
  173. * Perform a build.
  174. *
  175. * @return true if the build was successful (ie. no errors)
  176. */
  177. private boolean performBuild(AjBuildConfig buildConfig, IMessageHandler baseHandler, boolean isFullBuild) throws IOException,
  178. AbortException {
  179. boolean ret = true;
  180. batchCompile = isFullBuild;
  181. wasFullBuild = isFullBuild;
  182. if (baseHandler instanceof ILifecycleAware) {
  183. ((ILifecycleAware) baseHandler).buildStarting(!isFullBuild);
  184. }
  185. CompilationAndWeavingContext.reset();
  186. final int phase = isFullBuild ? CompilationAndWeavingContext.BATCH_BUILD : CompilationAndWeavingContext.INCREMENTAL_BUILD;
  187. final ContextToken ct = CompilationAndWeavingContext.enteringPhase(phase, buildConfig);
  188. try {
  189. if (isFullBuild) {
  190. this.state = new AjState(this);
  191. }
  192. this.state.setCouldBeSubsequentIncrementalBuild(this.environmentSupportsIncrementalCompilation);
  193. final boolean canIncremental = state.prepareForNextBuild(buildConfig);
  194. if (!canIncremental && !isFullBuild) { // retry as batch?
  195. CompilationAndWeavingContext.leavingPhase(ct);
  196. if (state.listenerDefined()) {
  197. state.getListener().recordDecision("Falling back to batch compilation");
  198. }
  199. return performBuild(buildConfig, baseHandler, true);
  200. }
  201. this.handler = CountingMessageHandler.makeCountingMessageHandler(baseHandler);
  202. if (buildConfig == null || buildConfig.isCheckRuntimeVersion()) {
  203. if (DO_RUNTIME_VERSION_CHECK) {
  204. final String check = checkRtJar(buildConfig);
  205. if (check != null) {
  206. if (FAIL_IF_RUNTIME_NOT_FOUND) {
  207. MessageUtil.error(handler, check);
  208. CompilationAndWeavingContext.leavingPhase(ct);
  209. return false;
  210. } else {
  211. MessageUtil.warn(handler, check);
  212. }
  213. }
  214. }
  215. }
  216. // if (batch) {
  217. setBuildConfig(buildConfig);
  218. // }
  219. if (isFullBuild || !AsmManager.attemptIncrementalModelRepairs) {
  220. // if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) {
  221. setupModel(buildConfig);
  222. // }
  223. }
  224. if (isFullBuild) {
  225. initBcelWorld(handler);
  226. }
  227. if (handler.hasErrors()) {
  228. CompilationAndWeavingContext.leavingPhase(ct);
  229. return false;
  230. }
  231. if (buildConfig.getOutputJar() != null) {
  232. if (!openOutputStream(buildConfig.getOutputJar())) {
  233. CompilationAndWeavingContext.leavingPhase(ct);
  234. return false;
  235. }
  236. }
  237. if (isFullBuild) {
  238. // System.err.println("XXXX batch: " + buildConfig.getFiles());
  239. if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) {
  240. AsmManager.setLastActiveStructureModel(state.getStructureModel());
  241. getWorld().setModel(state.getStructureModel());
  242. // in incremental build, only get updated model?
  243. }
  244. binarySourcesForTheNextCompile = state.getBinaryFilesToCompile(true);
  245. performCompilation(buildConfig.getFiles());
  246. state.clearBinarySourceFiles(); // we don't want these hanging around...
  247. if (!proceedOnError() && handler.hasErrors()) {
  248. CompilationAndWeavingContext.leavingPhase(ct);
  249. if (AsmManager.isReporting()) {
  250. state.getStructureModel().reportModelInfo("After a batch build");
  251. }
  252. return false;
  253. }
  254. if (AsmManager.isReporting()) {
  255. state.getStructureModel().reportModelInfo("After a batch build");
  256. }
  257. } else {
  258. // done already?
  259. // if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) {
  260. // bcelWorld.setModel(StructureModelManager.INSTANCE.getStructureModel());
  261. // }
  262. // System.err.println("XXXX start inc ");
  263. AsmManager.setLastActiveStructureModel(state.getStructureModel());
  264. binarySourcesForTheNextCompile = state.getBinaryFilesToCompile(true);
  265. Set<File> files = state.getFilesToCompile(true);
  266. if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) {
  267. if (AsmManager.attemptIncrementalModelRepairs) {
  268. state.getStructureModel().resetDeltaProcessing();
  269. state.getStructureModel().processDelta(files, state.getAddedFiles(), state.getDeletedFiles());
  270. }
  271. }
  272. boolean hereWeGoAgain = !(files.isEmpty() && binarySourcesForTheNextCompile.isEmpty());
  273. for (int i = 0; (i < 5) && hereWeGoAgain; i++) {
  274. if (state.listenerDefined()) {
  275. state.getListener()
  276. .recordInformation("Starting incremental compilation loop " + (i + 1) + " of possibly 5");
  277. // System.err.println("XXXX inc: " + files);
  278. }
  279. performCompilation(files);
  280. if ((!proceedOnError() && handler.hasErrors())
  281. || (progressListener != null && progressListener.isCancelledRequested())) {
  282. CompilationAndWeavingContext.leavingPhase(ct);
  283. return false;
  284. }
  285. if (state.requiresFullBatchBuild()) {
  286. if (state.listenerDefined()) {
  287. state.getListener().recordInformation(" Dropping back to full build");
  288. }
  289. return batchBuild(buildConfig, baseHandler);
  290. }
  291. binarySourcesForTheNextCompile = state.getBinaryFilesToCompile(false);
  292. files = state.getFilesToCompile(false);
  293. hereWeGoAgain = !(files.isEmpty() && binarySourcesForTheNextCompile.isEmpty());
  294. // TODO Andy - Needs some thought here...
  295. // I think here we might want to pass empty addedFiles/deletedFiles as they were
  296. // dealt with on the first call to processDelta - we are going through this loop
  297. // again because in compiling something we found something else we needed to
  298. // rebuild. But what case causes this?
  299. if (hereWeGoAgain) {
  300. if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) {
  301. if (AsmManager.attemptIncrementalModelRepairs) {
  302. state.getStructureModel().processDelta(files, state.getAddedFiles(), state.getDeletedFiles());
  303. }
  304. }
  305. }
  306. }
  307. if (!files.isEmpty()) {
  308. CompilationAndWeavingContext.leavingPhase(ct);
  309. return batchBuild(buildConfig, baseHandler);
  310. } else {
  311. if (AsmManager.isReporting()) {
  312. state.getStructureModel().reportModelInfo("After an incremental build");
  313. }
  314. }
  315. }
  316. // XXX not in Mik's incremental
  317. if (buildConfig.isEmacsSymMode()) {
  318. new org.aspectj.ajdt.internal.core.builder.EmacsStructureModelManager().externalizeModel(state.getStructureModel());
  319. }
  320. // for bug 113554: support ajsym file generation for command line builds
  321. if (buildConfig.isGenerateCrossRefsMode()) {
  322. final File configFileProxy = new File(buildConfig.getOutputDir(), CROSSREFS_FILE_NAME);
  323. state.getStructureModel().writeStructureModel(configFileProxy.getAbsolutePath());
  324. }
  325. // have to tell state we succeeded or next is not incremental
  326. state.successfulCompile(buildConfig, isFullBuild);
  327. // For a full compile, copy resources to the destination
  328. // - they should not get deleted on incremental and AJDT
  329. // will handle changes to them that require a recopying
  330. if (isFullBuild) {
  331. copyResourcesToDestination();
  332. }
  333. if (buildConfig.getOutxmlName() != null) {
  334. writeOutxmlFile();
  335. }
  336. /* boolean weaved = */// weaveAndGenerateClassFiles();
  337. // if not weaved, then no-op build, no model changes
  338. // but always returns true
  339. // XXX weaved not in Mik's incremental
  340. if (buildConfig.isGenerateModelMode()) {
  341. state.getStructureModel().fireModelUpdated();
  342. }
  343. CompilationAndWeavingContext.leavingPhase(ct);
  344. } finally {
  345. if (baseHandler instanceof ILifecycleAware) {
  346. ((ILifecycleAware) baseHandler).buildFinished(!isFullBuild);
  347. }
  348. if (zos != null) {
  349. closeOutputStream(buildConfig.getOutputJar());
  350. }
  351. ret = !handler.hasErrors();
  352. if (getBcelWorld() != null) {
  353. final BcelWorld bcelWorld = getBcelWorld();
  354. bcelWorld.reportTimers();
  355. bcelWorld.tidyUp();
  356. }
  357. if (getWeaver() != null) {
  358. getWeaver().tidyUp();
  359. // bug 59895, don't release reference to handler as may be needed by a nested call
  360. // handler = null;
  361. }
  362. }
  363. return ret;
  364. }
  365. /**
  366. * Open an output jar file in which to write the compiler output.
  367. *
  368. * @param outJar the jar file to open
  369. * @return true if successful
  370. */
  371. private boolean openOutputStream(File outJar) {
  372. try {
  373. OutputStream os = FileUtil.makeOutputStream(buildConfig.getOutputJar());
  374. zos = new JarOutputStream(os, getWeaver().getManifest(true));
  375. } catch (IOException ex) {
  376. IMessage message = new Message("Unable to open outjar " + outJar.getPath() + "(" + ex.getMessage() + ")",
  377. new SourceLocation(outJar, 0), true);
  378. handler.handleMessage(message);
  379. return false;
  380. }
  381. return true;
  382. }
  383. private void closeOutputStream(File outJar) {
  384. try {
  385. if (zos != null) {
  386. zos.close();
  387. if (buildConfig.getCompilationResultDestinationManager() != null) {
  388. buildConfig.getCompilationResultDestinationManager().reportFileWrite(outJar.getPath(),
  389. CompilationResultDestinationManager.FILETYPE_OUTJAR);
  390. }
  391. }
  392. zos = null;
  393. /* Ensure we don't write an incomplete JAR bug-71339 */
  394. if (handler.hasErrors()) {
  395. outJar.delete();
  396. if (buildConfig.getCompilationResultDestinationManager() != null) {
  397. buildConfig.getCompilationResultDestinationManager().reportFileRemove(outJar.getPath(),
  398. CompilationResultDestinationManager.FILETYPE_OUTJAR);
  399. }
  400. }
  401. } catch (IOException ex) {
  402. IMessage message = new Message("Unable to write outjar " + outJar.getPath() + "(" + ex.getMessage() + ")",
  403. new SourceLocation(outJar, 0), true);
  404. handler.handleMessage(message);
  405. }
  406. }
  407. private void copyResourcesToDestination() throws IOException {
  408. // resources that we need to copy are contained in the injars and inpath only
  409. for (File inJar : buildConfig.getInJars()) {
  410. copyResourcesFromJarFile(inJar);
  411. }
  412. for (File inPathElement : buildConfig.getInpath()) {
  413. if (inPathElement.isDirectory()) {
  414. copyResourcesFromDirectory(inPathElement);
  415. }
  416. else {
  417. copyResourcesFromJarFile(inPathElement);
  418. }
  419. }
  420. if (buildConfig.getSourcePathResources() != null) {
  421. for (String resource : buildConfig.getSourcePathResources().keySet()) {
  422. File from = buildConfig.getSourcePathResources().get(resource);
  423. copyResourcesFromFile(from, resource, from);
  424. }
  425. }
  426. writeManifest();
  427. }
  428. private void copyResourcesFromJarFile(File jarFile) throws IOException {
  429. try (JarInputStream inStream = new JarInputStream(new FileInputStream(jarFile))) {
  430. while (true) {
  431. ZipEntry entry = inStream.getNextEntry();
  432. if (entry == null) {
  433. break;
  434. }
  435. String filename = entry.getName();
  436. // System.out.println("? copyResourcesFromJarFile() filename='" + filename +"'");
  437. if (entry.isDirectory()) {
  438. writeDirectory(filename, jarFile);
  439. } else if (acceptResource(filename, false)) {
  440. byte[] bytes = FileUtil.readAsByteArray(inStream);
  441. writeResource(filename, bytes, jarFile);
  442. }
  443. inStream.closeEntry();
  444. }
  445. }
  446. }
  447. private void copyResourcesFromDirectory(File dir) throws IOException {
  448. if (!COPY_INPATH_DIR_RESOURCES) {
  449. return;
  450. }
  451. // Get a list of all files (i.e. everything that isnt a directory)
  452. File[] files = FileUtil.listFiles(dir, new FileFilter() {
  453. @Override
  454. public boolean accept(File f) {
  455. boolean accept = !(f.isDirectory() || f.getName().endsWith(".class"));
  456. return accept;
  457. }
  458. });
  459. // For each file, add it either as a real .class file or as a resource
  460. for (File file : files) {
  461. // ASSERT: files[i].getAbsolutePath().startsWith(inFile.getAbsolutePath()
  462. // or we are in trouble...
  463. String filename = file.getAbsolutePath().substring(dir.getAbsolutePath().length() + 1);
  464. copyResourcesFromFile(file, filename, dir);
  465. }
  466. }
  467. private void copyResourcesFromFile(File f, String filename, File src) throws IOException {
  468. if (!acceptResource(filename, true)) {
  469. return;
  470. }
  471. FileInputStream fis = null;
  472. try {
  473. fis = new FileInputStream(f);
  474. byte[] bytes = FileUtil.readAsByteArray(fis);
  475. // String relativePath = files[i].getPath();
  476. writeResource(filename, bytes, src);
  477. } catch (FileNotFoundException fnfe) {
  478. // pr359332: looks like the file moved (refactoring?) just as this copy was starting
  479. // that is OK
  480. } finally {
  481. if (fis != null) {
  482. fis.close();
  483. }
  484. }
  485. }
  486. /**
  487. * Add a directory entry to the output zip file. Don't do anything if not writing out to a zip file. A directory entry is one
  488. * whose filename ends with '/'
  489. *
  490. * @param directory the directory path
  491. * @param srcloc the src of the directory entry, for use when creating a warning message
  492. * @throws IOException if something goes wrong creating the new zip entry
  493. */
  494. private void writeDirectory(String directory, File srcloc) throws IOException {
  495. if (state.hasResource(directory)) {
  496. IMessage msg = new Message("duplicate resource: '" + directory + "'", IMessage.WARNING, null, new SourceLocation(
  497. srcloc, 0));
  498. handler.handleMessage(msg);
  499. return;
  500. }
  501. if (zos != null) {
  502. ZipEntry newEntry = new ZipEntry(directory);
  503. zos.putNextEntry(newEntry);
  504. zos.closeEntry();
  505. state.recordResource(directory, srcloc);
  506. }
  507. // Nothing to do if not writing to a zip file
  508. }
  509. private void writeResource(String filename, byte[] content, File srcLocation) throws IOException {
  510. if (state.hasResource(filename)) {
  511. IMessage msg = new Message("duplicate resource: '" + filename + "'", IMessage.WARNING, null, new SourceLocation(
  512. srcLocation, 0));
  513. handler.handleMessage(msg);
  514. return;
  515. }
  516. if (filename.equals(buildConfig.getOutxmlName())) {
  517. ignoreOutxml = true;
  518. IMessage msg = new Message("-outxml/-outxmlfile option ignored because resource already exists: '" + filename + "'",
  519. IMessage.WARNING, null, new SourceLocation(srcLocation, 0));
  520. handler.handleMessage(msg);
  521. }
  522. if (zos != null) {
  523. ZipEntry newEntry = new ZipEntry(filename); // ??? get compression scheme right
  524. zos.putNextEntry(newEntry);
  525. zos.write(content);
  526. zos.closeEntry();
  527. } else {
  528. File destDir = buildConfig.getOutputDir();
  529. if (buildConfig.getCompilationResultDestinationManager() != null) {
  530. destDir = buildConfig.getCompilationResultDestinationManager().getOutputLocationForResource(srcLocation);
  531. }
  532. try {
  533. File outputLocation = new File(destDir, filename);
  534. OutputStream fos = FileUtil.makeOutputStream(outputLocation);
  535. fos.write(content);
  536. fos.close();
  537. if (buildConfig.getCompilationResultDestinationManager() != null) {
  538. buildConfig.getCompilationResultDestinationManager().reportFileWrite(outputLocation.getPath(),
  539. CompilationResultDestinationManager.FILETYPE_RESOURCE);
  540. }
  541. } catch (FileNotFoundException fnfe) {
  542. IMessage msg = new Message("unable to copy resource to output folder: '" + filename + "' - reason: "
  543. + fnfe.getMessage(), IMessage.ERROR, null, new SourceLocation(srcLocation, 0));
  544. handler.handleMessage(msg);
  545. }
  546. }
  547. state.recordResource(filename, srcLocation);
  548. }
  549. /*
  550. * If we are writing to an output directory copy the manifest but only if we already have one
  551. */
  552. private void writeManifest() throws IOException {
  553. Manifest manifest = getWeaver().getManifest(false);
  554. if (manifest != null && zos == null) {
  555. File outputDir = buildConfig.getOutputDir();
  556. if (buildConfig.getCompilationResultDestinationManager() != null) {
  557. // Manifests are only written if we have a jar on the inpath. Therefore,
  558. // we write the manifest to the defaultOutputLocation because this is
  559. // where we sent the classes that were on the inpath
  560. outputDir = buildConfig.getCompilationResultDestinationManager().getDefaultOutputLocation();
  561. }
  562. if (outputDir == null) {
  563. return;
  564. }
  565. File outputLocation = new File(outputDir, MANIFEST_NAME);
  566. OutputStream fos = FileUtil.makeOutputStream(outputLocation);
  567. manifest.write(fos);
  568. fos.close();
  569. if (buildConfig.getCompilationResultDestinationManager() != null) {
  570. buildConfig.getCompilationResultDestinationManager().reportFileWrite(outputLocation.getPath(),
  571. CompilationResultDestinationManager.FILETYPE_RESOURCE);
  572. }
  573. }
  574. }
  575. private boolean acceptResource(String resourceName, boolean fromFile) {
  576. if ((resourceName.startsWith("CVS/")) || (resourceName.contains("/CVS/")) || (resourceName.endsWith("/CVS"))
  577. || (resourceName.endsWith(".class")) || (resourceName.startsWith(".svn/"))
  578. || (resourceName.contains("/.svn/")) || (resourceName.endsWith("/.svn")) ||
  579. // Do not copy manifests if either they are coming from a jar or we are writing to a jar
  580. (resourceName.toUpperCase().equals(MANIFEST_NAME) && (!fromFile || zos != null))) {
  581. return false;
  582. } else {
  583. return true;
  584. }
  585. }
  586. private void writeOutxmlFile() throws IOException {
  587. if (ignoreOutxml) {
  588. return;
  589. }
  590. String filename = buildConfig.getOutxmlName();
  591. // System.err.println("? AjBuildManager.writeOutxmlFile() outxml=" + filename);
  592. Map<File, List<String>> outputDirsAndAspects = findOutputDirsForAspects();
  593. Set<Map.Entry<File, List<String>>> outputDirs = outputDirsAndAspects.entrySet();
  594. for (Map.Entry<File, List<String>> entry : outputDirs) {
  595. File outputDir = entry.getKey();
  596. List<String> aspects = entry.getValue();
  597. ByteArrayOutputStream baos = getOutxmlContents(aspects);
  598. if (zos != null) {
  599. ZipEntry newEntry = new ZipEntry(filename);
  600. zos.putNextEntry(newEntry);
  601. zos.write(baos.toByteArray());
  602. zos.closeEntry();
  603. }
  604. else {
  605. File outputFile = new File(outputDir, filename);
  606. OutputStream fos = FileUtil.makeOutputStream(outputFile);
  607. fos.write(baos.toByteArray());
  608. fos.close();
  609. if (buildConfig.getCompilationResultDestinationManager() != null) {
  610. buildConfig.getCompilationResultDestinationManager().reportFileWrite(outputFile.getPath(),
  611. CompilationResultDestinationManager.FILETYPE_RESOURCE);
  612. }
  613. }
  614. }
  615. }
  616. private ByteArrayOutputStream getOutxmlContents(List<String> aspectNames) {
  617. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  618. PrintStream ps = new PrintStream(baos);
  619. ps.println("<aspectj>");
  620. ps.println("<aspects>");
  621. if (aspectNames != null) {
  622. for (String name : aspectNames) {
  623. ps.println("<aspect name=\"" + name + "\"/>");
  624. }
  625. }
  626. ps.println("</aspects>");
  627. ps.println("</aspectj>");
  628. ps.println();
  629. ps.close();
  630. return baos;
  631. }
  632. /**
  633. * Returns a map where the keys are File objects corresponding to all the output directories and the values are a list of
  634. * aspects which are sent to that ouptut directory
  635. */
  636. private Map<File, List<String>> findOutputDirsForAspects() {
  637. Map<File, List<String>> outputDirsToAspects = new HashMap<>();
  638. Map<String, char[]> aspectNamesToFileNames = state.getAspectNamesToFileNameMap();
  639. if (buildConfig.getCompilationResultDestinationManager() == null
  640. || buildConfig.getCompilationResultDestinationManager().getAllOutputLocations().size() == 1) {
  641. // we only have one output directory...which simplifies things
  642. File outputDir = buildConfig.getOutputDir();
  643. if (buildConfig.getCompilationResultDestinationManager() != null) {
  644. outputDir = buildConfig.getCompilationResultDestinationManager().getDefaultOutputLocation();
  645. }
  646. List<String> aspectNames = new ArrayList<>();
  647. if (aspectNamesToFileNames != null) {
  648. Set<String> keys = aspectNamesToFileNames.keySet();
  649. for (String name : keys) {
  650. aspectNames.add(name);
  651. }
  652. }
  653. outputDirsToAspects.put(outputDir, aspectNames);
  654. } else {
  655. List<File> outputDirs = buildConfig.getCompilationResultDestinationManager().getAllOutputLocations();
  656. for (File outputDir : outputDirs) {
  657. outputDirsToAspects.put(outputDir, new ArrayList<>());
  658. }
  659. if (aspectNamesToFileNames != null) {
  660. Set<Map.Entry<String, char[]>> entrySet = aspectNamesToFileNames.entrySet();
  661. for (Map.Entry<String, char[]> entry : entrySet) {
  662. String aspectName = entry.getKey();
  663. char[] fileName = entry.getValue();
  664. File outputDir = buildConfig.getCompilationResultDestinationManager().getOutputLocationForClass(
  665. new File(new String(fileName)));
  666. if (!outputDirsToAspects.containsKey(outputDir)) {
  667. outputDirsToAspects.put(outputDir, new ArrayList<>());
  668. }
  669. outputDirsToAspects.get(outputDir).add(aspectName);
  670. }
  671. }
  672. }
  673. return outputDirsToAspects;
  674. }
  675. // public static void dumprels() {
  676. // IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
  677. // int ctr = 1;
  678. // Set entries = irm.getEntries();
  679. // for (Iterator iter = entries.iterator(); iter.hasNext();) {
  680. // String hid = (String) iter.next();
  681. // List rels = irm.get(hid);
  682. // for (Iterator iterator = rels.iterator(); iterator.hasNext();) {
  683. // IRelationship ir = (IRelationship) iterator.next();
  684. // List targets = ir.getTargets();
  685. // for (Iterator iterator2 = targets.iterator();
  686. // iterator2.hasNext();
  687. // ) {
  688. // String thid = (String) iterator2.next();
  689. // System.err.println("Hid:"+(ctr++)+":(targets="+targets.size()+") "+hid+" ("+ir.getName()+") "+thid);
  690. // }
  691. // }
  692. // }
  693. // }
  694. /**
  695. * Responsible for managing the ASM model between builds. Contains the policy for maintaining the persistance of elements in the
  696. * model.
  697. *
  698. * This code is driven before each 'fresh' (batch) build to create a new model.
  699. */
  700. private void setupModel(AjBuildConfig config) {
  701. if (!(config.isEmacsSymMode() || config.isGenerateModelMode())) {
  702. return;
  703. }
  704. // AsmManager.setCreatingModel(config.isEmacsSymMode() || config.isGenerateModelMode());
  705. // if (!AsmManager.isCreatingModel())
  706. // return;
  707. CompilationResultDestinationManager crdm = config.getCompilationResultDestinationManager();
  708. AsmManager structureModel = AsmManager.createNewStructureModel(crdm == null ? Collections.EMPTY_MAP : crdm.getInpathMap());
  709. // AsmManager.getDefault().getRelationshipMap().clear();
  710. IHierarchy model = structureModel.getHierarchy();
  711. String rootLabel = "<root>";
  712. IProgramElement.Kind kind = IProgramElement.Kind.FILE_JAVA;
  713. if (buildConfig.getConfigFile() != null) {
  714. rootLabel = buildConfig.getConfigFile().getName();
  715. model.setConfigFile(buildConfig.getConfigFile().getAbsolutePath());
  716. kind = IProgramElement.Kind.FILE_LST;
  717. }
  718. model.setRoot(new ProgramElement(structureModel, rootLabel, kind, new ArrayList<>()));
  719. model.setFileMap(new HashMap<>());
  720. // setStructureModel(model);
  721. state.setStructureModel(structureModel);
  722. // state.setRelationshipMap(AsmManager.getDefault().getRelationshipMap());
  723. }
  724. //
  725. // private void dumplist(List l) {
  726. // System.err.println("---- "+l.size());
  727. // for (int i =0 ;i<l.size();i++) System.err.println(i+"\t "+l.get(i));
  728. // }
  729. // private void accumulateFileNodes(IProgramElement ipe,List store) {
  730. // if (ipe.getKind()==IProgramElement.Kind.FILE_JAVA ||
  731. // ipe.getKind()==IProgramElement.Kind.FILE_ASPECTJ) {
  732. // if (!ipe.getName().equals("<root>")) {
  733. // store.add(ipe);
  734. // return;
  735. // }
  736. // }
  737. // for (Iterator i = ipe.getChildren().iterator();i.hasNext();) {
  738. // accumulateFileNodes((IProgramElement)i.next(),store);
  739. // }
  740. // }
  741. // LTODO delegate to BcelWeaver?
  742. // XXX hideous, should not be Object
  743. public void setCustomMungerFactory(Object o) {
  744. customMungerFactory = (CustomMungerFactory) o;
  745. }
  746. public Object getCustomMungerFactory() {
  747. return customMungerFactory;
  748. }
  749. /** init only on initial batch compile? no file-specific options */
  750. private void initBcelWorld(IMessageHandler handler) throws IOException {
  751. List<String> cp = buildConfig.getFullClasspath(); // pr145693
  752. // buildConfig.getBootclasspath();
  753. // cp.addAll(buildConfig.getClasspath());
  754. BcelWorld bcelWorld = new BcelWorld(cp, handler, null);
  755. bcelWorld.setBehaveInJava5Way(buildConfig.getBehaveInJava5Way());
  756. bcelWorld.setTiming(buildConfig.isTiming(), false);
  757. bcelWorld.setAddSerialVerUID(buildConfig.isAddSerialVerUID());
  758. bcelWorld.setXmlConfigured(buildConfig.isXmlConfigured());
  759. bcelWorld.setXmlFiles(buildConfig.getXmlFiles());
  760. bcelWorld.performExtraConfiguration(buildConfig.getXconfigurationInfo());
  761. bcelWorld.setTargetAspectjRuntimeLevel(buildConfig.getTargetAspectjRuntimeLevel());
  762. bcelWorld.setOptionalJoinpoints(buildConfig.getXJoinpoints());
  763. bcelWorld.setXnoInline(buildConfig.isXnoInline());
  764. bcelWorld.setXlazyTjp(buildConfig.isXlazyTjp());
  765. bcelWorld.setXHasMemberSupportEnabled(buildConfig.isXHasMemberEnabled());
  766. bcelWorld.setPinpointMode(buildConfig.isXdevPinpoint());
  767. bcelWorld.setErrorAndWarningThreshold(buildConfig.getOptions().errorThreshold.isSet(24), buildConfig.getOptions().warningThreshold.isSet(24));
  768. BcelWeaver bcelWeaver = new BcelWeaver(bcelWorld);
  769. bcelWeaver.setCustomMungerFactory(customMungerFactory);
  770. state.setWorld(bcelWorld);
  771. state.setWeaver(bcelWeaver);
  772. state.clearBinarySourceFiles();
  773. if (buildConfig.getLintMode().equals(AjBuildConfig.AJLINT_DEFAULT)) {
  774. bcelWorld.getLint().loadDefaultProperties();
  775. } else {
  776. bcelWorld.getLint().setAll(buildConfig.getLintMode());
  777. }
  778. if (buildConfig.getLintOptionsMap() != null) {
  779. bcelWorld.getLint().setFromMap(buildConfig.getLintOptionsMap());
  780. }
  781. if (buildConfig.getLintSpecFile() != null) {
  782. bcelWorld.getLint().setFromProperties(buildConfig.getLintSpecFile());
  783. }
  784. for (File f: buildConfig.getAspectpath()) {
  785. if (!f.exists()) {
  786. IMessage message = new Message("invalid aspectpath entry: " + f.getName(), null, true);
  787. handler.handleMessage(message);
  788. } else {
  789. bcelWeaver.addLibraryJarFile(f);
  790. }
  791. }
  792. // String lintMode = buildConfig.getLintMode();
  793. File outputDir = buildConfig.getOutputDir();
  794. if (outputDir == null && buildConfig.getCompilationResultDestinationManager() != null) {
  795. // send all output from injars and inpath to the default output location
  796. // (will also later send the manifest there too)
  797. outputDir = buildConfig.getCompilationResultDestinationManager().getDefaultOutputLocation();
  798. }
  799. // ??? incremental issues
  800. for (File inJar : buildConfig.getInJars()) {
  801. List<UnwovenClassFile> unwovenClasses = bcelWeaver.addJarFile(inJar, outputDir, false);
  802. state.recordBinarySource(inJar.getPath(), unwovenClasses);
  803. }
  804. for (File inPathElement : buildConfig.getInpath()) {
  805. if (!inPathElement.isDirectory()) {
  806. // its a jar file on the inpath
  807. // the weaver method can actually handle dirs, but we don't call it, see next block
  808. List<UnwovenClassFile> unwovenClasses = bcelWeaver.addJarFile(inPathElement, outputDir, true);
  809. state.recordBinarySource(inPathElement.getPath(), unwovenClasses);
  810. } else {
  811. // add each class file in an in-dir individually, this gives us the best error reporting
  812. // (they are like 'source' files then), and enables a cleaner incremental treatment of
  813. // class file changes in indirs.
  814. File[] binSrcs = FileUtil.listFiles(inPathElement, binarySourceFilter);
  815. for (File binSrc : binSrcs) {
  816. UnwovenClassFile ucf = bcelWeaver.addClassFile(binSrc, inPathElement, outputDir);
  817. List<UnwovenClassFile> ucfl = new ArrayList<>();
  818. ucfl.add(ucf);
  819. state.recordBinarySource(binSrc.getPath(), ucfl);
  820. }
  821. }
  822. }
  823. bcelWeaver.setReweavableMode(buildConfig.isXNotReweavable());
  824. // check for org.aspectj.runtime.JoinPoint
  825. ResolvedType joinPoint = bcelWorld.resolve("org.aspectj.lang.JoinPoint");
  826. if (joinPoint.isMissing()) {
  827. IMessage message = new Message(
  828. "classpath error: unable to find org.aspectj.lang.JoinPoint (check that aspectjrt.jar is in your classpath)",
  829. null, true);
  830. handler.handleMessage(message);
  831. }
  832. }
  833. public World getWorld() {
  834. return getBcelWorld();
  835. }
  836. // void addAspectClassFilesToWeaver(List addedClassFiles) throws IOException {
  837. // for (Iterator i = addedClassFiles.iterator(); i.hasNext();) {
  838. // UnwovenClassFile classFile = (UnwovenClassFile) i.next();
  839. // getWeaver().addClassFile(classFile);
  840. // }
  841. // }
  842. public FileSystem getLibraryAccess(String[] classpaths, String[] filenames) {
  843. String defaultEncoding = buildConfig.getOptions().defaultEncoding;
  844. if ("".equals(defaultEncoding)) {//$NON-NLS-1$
  845. defaultEncoding = null;
  846. }
  847. // Bug 46671: We need an array as long as the number of elements in the classpath - *even though* not every
  848. // element of the classpath is likely to be a directory. If we ensure every element of the array is set to
  849. // only look for BINARY, then we make sure that for any classpath element that is a directory, we won't build
  850. // a classpathDirectory object that will attempt to look for source when it can't find binary.
  851. // int[] classpathModes = new int[classpaths.length];
  852. // for (int i =0 ;i<classpaths.length;i++) classpathModes[i]=ClasspathDirectory.BINARY;
  853. FileSystem nameEnvironment = null;
  854. // TODO J9 The compiler likes to work in terms of checked classpath objects - these will be different
  855. // depending on where the code came from (classpath, modulepath). If working with just the raw
  856. // 'classpaths' object it isn't recording where the code came from. This will be an issue later for
  857. // weaving, the distinction will need to be maintained for proper 'module aware/respecting' weaving.
  858. if (buildConfig.getCheckedClasspaths() == null) {
  859. nameEnvironment = new FileSystem(classpaths, filenames, defaultEncoding, ClasspathLocation.BINARY, null);
  860. } else {
  861. nameEnvironment = new FileSystem(buildConfig.getCheckedClasspaths(), filenames, false, null);
  862. }
  863. nameEnvironment.module = buildConfig.getModuleDesc();
  864. return nameEnvironment;
  865. }
  866. public IProblemFactory getProblemFactory() {
  867. return new DefaultProblemFactory(Locale.getDefault());
  868. }
  869. /*
  870. * Build the set of compilation source units
  871. */
  872. public CompilationUnit[] getCompilationUnits(String[] filenames) {
  873. int fileCount = filenames.length;
  874. CompilationUnit[] units = new CompilationUnit[fileCount];
  875. // HashtableOfObject knownFileNames = new HashtableOfObject(fileCount);
  876. String defaultEncoding = buildConfig.getOptions().defaultEncoding;
  877. if ("".equals(defaultEncoding)) {//$NON-NLS-1$
  878. defaultEncoding = null;
  879. }
  880. CompilationUnit moduleCU = null;
  881. // TODO building with multiple module-infos?
  882. int moduleIndex = -1;
  883. IModule moduleDesc = buildConfig.getModuleDesc();
  884. String moduleName = moduleDesc == null? null: new String(moduleDesc.name());
  885. for (int i=0;i<fileCount;i++) {
  886. if (filenames[i].endsWith("module-info.java")) {
  887. moduleIndex = i;
  888. moduleCU = new CompilationUnit(null, filenames[i], defaultEncoding, null, false, moduleName);
  889. }
  890. }
  891. for (int i = 0; i < fileCount; i++) {
  892. // units[i] = new CompilationUnit(null, filenames[i], defaultEncoding);
  893. if (i == moduleIndex) {
  894. units[i] = moduleCU;
  895. } else {
  896. units[i] = new CompilationUnit(null, filenames[i], defaultEncoding, null, false, moduleName);
  897. // With Java 10 changes the modulebinding is fetched from the rootenvironment
  898. // this.moduleBinding = rootEnvironment.getModule(this.module);
  899. // rather than using the moduleCU:
  900. // if (this.modCU != null)
  901. // return this.moduleBinding = this.modCU.module(rootEnvironment);
  902. // units[i].setModule(moduleCU);
  903. }
  904. // new CompilationUnit(null, fileName, encoding, this.destinationPaths[i],
  905. // shouldIgnoreOptionalProblems(this.ignoreOptionalProblemsFromFolders, fileName.toCharArray()),
  906. // this.modNames[i]);
  907. }
  908. return units;
  909. }
  910. public String extractDestinationPathFromSourceFile(CompilationResult result) {
  911. ICompilationUnit compilationUnit = result.compilationUnit;
  912. if (compilationUnit != null) {
  913. char[] fileName = compilationUnit.getFileName();
  914. int lastIndex = CharOperation.lastIndexOf(java.io.File.separatorChar, fileName);
  915. if (lastIndex == -1) {
  916. return System.getProperty("user.dir"); //$NON-NLS-1$
  917. }
  918. return new String(CharOperation.subarray(fileName, 0, lastIndex));
  919. }
  920. return System.getProperty("user.dir"); //$NON-NLS-1$
  921. }
  922. public void performCompilation(Collection<File> files) {
  923. if (progressListener != null) {
  924. compiledCount = 0;
  925. sourceFileCount = files.size();
  926. progressListener.setText("compiling source files");
  927. }
  928. // Translate from strings to File objects
  929. String[] filenames = new String[files.size()];
  930. int idx = 0;
  931. for (File f : files) {
  932. filenames[idx++] = f.getPath();
  933. }
  934. environment = state.getNameEnvironment();
  935. boolean environmentNeedsRebuilding = false;
  936. // Might be a bit too cautious, but let us see how it goes
  937. if (buildConfig.getChanged() != AjBuildConfig.NO_CHANGES) {
  938. environmentNeedsRebuilding = true;
  939. }
  940. if (environment == null || environmentNeedsRebuilding) {
  941. List<String> cps = buildConfig.getFullClasspath();
  942. Dump.saveFullClasspath(cps);
  943. String[] classpaths = new String[cps.size()];
  944. for (int i = 0; i < cps.size(); i++) {
  945. classpaths[i] = cps.get(i);
  946. }
  947. FileSystem fileSystem = getLibraryAccess(classpaths, filenames);
  948. // Use upstream method to generate '--add-reads', '--add-exports' info and copy it into our FileSystem instance.
  949. // See https://github.com/eclipse/org.aspectj/issues/145.
  950. FileSystem fileSystemTemp = buildConfig.getBuildArgParser().getLibraryAccess();
  951. fileSystem.moduleUpdates = fileSystemTemp.moduleUpdates;
  952. fileSystemTemp.cleanup();
  953. environment = new StatefulNameEnvironment(fileSystem, state.getClassNameToFileMap(), state);
  954. state.setFileSystem(fileSystem);
  955. state.setNameEnvironment(environment);
  956. } else {
  957. ((StatefulNameEnvironment) environment).update(state.getClassNameToFileMap(), state.deltaAddedClasses);
  958. state.deltaAddedClasses.clear();
  959. }
  960. org.aspectj.ajdt.internal.compiler.CompilerAdapter.setCompilerAdapterFactory(this);
  961. final Map<String, String> settings = buildConfig.getOptions().getMap();
  962. final BuildArgParser bMain = buildConfig.getBuildArgParser();
  963. final org.aspectj.org.eclipse.jdt.internal.compiler.Compiler compiler = new org.aspectj.org.eclipse.jdt.internal.compiler.Compiler(
  964. environment, DefaultErrorHandlingPolicies.proceedWithAllProblems(), settings,
  965. getBatchRequestor(), getProblemFactory());
  966. bMain.compilerOptions = compiler.options;
  967. bMain.batchCompiler = compiler;
  968. bMain.initializeAnnotationProcessorManager();
  969. compiler.options.produceReferenceInfo = true; // TODO turn off when not needed
  970. if (bMain.compilerOptions.complianceLevel >= ClassFileConstants.JDK1_6
  971. && bMain.compilerOptions.processAnnotations) {
  972. // need this too?
  973. // if (bMain.checkVMVersion(ClassFileConstants.JDK1_6)) {
  974. // initializeAnnotationProcessorManager();
  975. // if (this.classNames != null) {
  976. // this.batchCompiler.setBinaryTypes(processClassNames(this.batchCompiler.lookupEnvironment));
  977. // }
  978. // } else {
  979. // // report a warning
  980. // this.logger.logIncorrectVMVersionForAnnotationProcessing();
  981. // }
  982. if (bMain.checkVMVersion(ClassFileConstants.JDK9)) {
  983. try {
  984. bMain.initRootModules(bMain.batchCompiler.lookupEnvironment, state.getFileSystem());
  985. } catch (IllegalArgumentException iae) {
  986. ISourceLocation location = null;
  987. if (buildConfig.getConfigFile() != null) {
  988. location = new SourceLocation(buildConfig.getConfigFile(), 0);
  989. }
  990. IMessage m = new Message(iae.getMessage(), IMessage.ERROR, null, location);
  991. handler.handleMessage(m);
  992. }
  993. }
  994. }
  995. try {
  996. compiler.compile(getCompilationUnits(filenames));
  997. } catch (OperationCanceledException oce) {
  998. handler.handleMessage(new Message("build cancelled:" + oce.getMessage(), IMessage.WARNING, null, null));
  999. }
  1000. // cleanup
  1001. org.aspectj.ajdt.internal.compiler.CompilerAdapter.setCompilerAdapterFactory(null);
  1002. AnonymousClassPublisher.aspectOf().setAnonymousClassCreationListener(null);
  1003. environment.cleanup();
  1004. // environment = null;
  1005. }
  1006. public void cleanupEnvironment() {
  1007. if (environment != null) {
  1008. environment.cleanup();
  1009. environment = null;
  1010. // le = null;
  1011. }
  1012. }
  1013. /*
  1014. * Answer the component to which will be handed back compilation results from the compiler
  1015. */
  1016. public IIntermediateResultsRequestor getInterimResultRequestor() {
  1017. return new IIntermediateResultsRequestor() {
  1018. @Override
  1019. public void acceptResult(InterimCompilationResult result) {
  1020. if (progressListener != null) {
  1021. compiledCount++;
  1022. progressListener.setProgress((compiledCount / 2.0) / sourceFileCount);
  1023. progressListener.setText("compiled: " + result.fileName());
  1024. }
  1025. state.noteResult(result);
  1026. if (progressListener != null && progressListener.isCancelledRequested()) {
  1027. throw new AbortCompilation(true, new OperationCanceledException("Compilation cancelled as requested"));
  1028. }
  1029. }
  1030. };
  1031. }
  1032. public ICompilerRequestor getBatchRequestor() {
  1033. return new ICompilerRequestor() {
  1034. @Override
  1035. public void acceptResult(CompilationResult unitResult) {
  1036. // end of compile, must now write the results to the output destination
  1037. // this is either a jar file or a file in a directory
  1038. boolean hasErrors = unitResult.hasErrors();
  1039. if (!hasErrors || proceedOnError()) {
  1040. Collection<ClassFile> classFiles = unitResult.compiledTypes.values();
  1041. boolean shouldAddAspectName = (buildConfig.getOutxmlName() != null);
  1042. for (ClassFile classFile : classFiles) {
  1043. String filename = new String(classFile.fileName());
  1044. String classname = filename.replace('/', '.');
  1045. filename = filename.replace('/', File.separatorChar) + ".class";
  1046. try {
  1047. if (buildConfig.getOutputJar() == null) {
  1048. String outfile = writeDirectoryEntry(unitResult, classFile, filename);
  1049. getWorld().classWriteEvent(classFile.getCompoundName());
  1050. if (environmentSupportsIncrementalCompilation) {
  1051. if (!classname.endsWith("$ajcMightHaveAspect")) {
  1052. ResolvedType type = getBcelWorld().resolve(classname);
  1053. if (type.isAspect()) {
  1054. state.recordAspectClassFile(outfile);
  1055. }
  1056. }
  1057. }
  1058. }
  1059. else {
  1060. writeZipEntry(classFile, filename);
  1061. }
  1062. if (shouldAddAspectName && !classname.endsWith("$ajcMightHaveAspect")) {
  1063. addAspectName(classname, unitResult.getFileName());
  1064. }
  1065. } catch (IOException ex) {
  1066. IMessage message = EclipseAdapterUtils.makeErrorMessage(new String(unitResult.fileName),
  1067. CANT_WRITE_RESULT, ex);
  1068. handler.handleMessage(message);
  1069. }
  1070. }
  1071. state.noteNewResult(unitResult);
  1072. unitResult.compiledTypes.clear(); // free up references to AjClassFile instances
  1073. }
  1074. if (unitResult.hasProblems() || unitResult.hasTasks()) {
  1075. IProblem[] problems = unitResult.getAllProblems();
  1076. for (IProblem problem : problems) {
  1077. IMessage message = EclipseAdapterUtils.makeMessage(unitResult.compilationUnit, problem, getBcelWorld(),
  1078. progressListener);
  1079. handler.handleMessage(message);
  1080. }
  1081. }
  1082. }
  1083. private String writeDirectoryEntry(CompilationResult unitResult, ClassFile classFile, String filename)
  1084. throws IOException {
  1085. File destinationPath = buildConfig.getOutputDir();
  1086. if (buildConfig.getCompilationResultDestinationManager() != null) {
  1087. destinationPath = buildConfig.getCompilationResultDestinationManager().getOutputLocationForClass(
  1088. new File(new String(unitResult.fileName)));
  1089. }
  1090. String outFile;
  1091. if (destinationPath == null) {
  1092. outFile = new File(filename).getName();
  1093. outFile = new File(extractDestinationPathFromSourceFile(unitResult), outFile).getPath();
  1094. } else {
  1095. outFile = new File(destinationPath, filename).getPath();
  1096. }
  1097. try {
  1098. BufferedOutputStream os = FileUtil.makeOutputStream(new File(outFile));
  1099. os.write(classFile.getBytes());
  1100. os.close();
  1101. } catch (FileNotFoundException fnfe) {
  1102. IMessage msg = new Message("unable to write out class file: '" + filename + "' - reason: " + fnfe.getMessage(),
  1103. IMessage.ERROR, null, new SourceLocation(new File(outFile), 0));
  1104. handler.handleMessage(msg);
  1105. }
  1106. if (buildConfig.getCompilationResultDestinationManager() != null) {
  1107. buildConfig.getCompilationResultDestinationManager().reportFileWrite(outFile,
  1108. CompilationResultDestinationManager.FILETYPE_CLASS);
  1109. }
  1110. return outFile;
  1111. }
  1112. private void writeZipEntry(ClassFile classFile, String name) throws IOException {
  1113. name = name.replace(File.separatorChar, '/');
  1114. ZipEntry newEntry = new ZipEntry(name); // ??? get compression scheme right
  1115. zos.putNextEntry(newEntry);
  1116. zos.write(classFile.getBytes());
  1117. zos.closeEntry();
  1118. }
  1119. private void addAspectName(String name, char[] fileContainingAspect) {
  1120. BcelWorld world = getBcelWorld();
  1121. ResolvedType type = world.resolve(name);
  1122. // System.err.println("? writeAspectName() type=" + type);
  1123. if (type.isAspect()) {
  1124. if (state.getAspectNamesToFileNameMap() == null) {
  1125. state.initializeAspectNamesToFileNameMap();
  1126. }
  1127. if (!state.getAspectNamesToFileNameMap().containsKey(name)) {
  1128. state.getAspectNamesToFileNameMap().put(name, fileContainingAspect);
  1129. }
  1130. }
  1131. }
  1132. };
  1133. }
  1134. protected boolean proceedOnError() {
  1135. return buildConfig.getProceedOnError();
  1136. }
  1137. // public void noteClassFiles(AjCompiler.InterimResult result) {
  1138. // if (result == null) return;
  1139. // CompilationResult unitResult = result.result;
  1140. // String sourceFileName = result.fileName();
  1141. // if (!(unitResult.hasErrors() && !proceedOnError())) {
  1142. // List unwovenClassFiles = new ArrayList();
  1143. // Enumeration classFiles = unitResult.compiledTypes.elements();
  1144. // while (classFiles.hasMoreElements()) {
  1145. // ClassFile classFile = (ClassFile) classFiles.nextElement();
  1146. // String filename = new String(classFile.fileName());
  1147. // filename = filename.replace('/', File.separatorChar) + ".class";
  1148. //
  1149. // File destinationPath = buildConfig.getOutputDir();
  1150. // if (destinationPath == null) {
  1151. // filename = new File(filename).getName();
  1152. // filename = new File(extractDestinationPathFromSourceFile(unitResult), filename).getPath();
  1153. // } else {
  1154. // filename = new File(destinationPath, filename).getPath();
  1155. // }
  1156. //
  1157. // //System.out.println("classfile: " + filename);
  1158. // unwovenClassFiles.add(new UnwovenClassFile(filename, classFile.getBytes()));
  1159. // }
  1160. // state.noteClassesFromFile(unitResult, sourceFileName, unwovenClassFiles);
  1161. // // System.out.println("file: " + sourceFileName);
  1162. // // for (int i=0; i < unitResult.simpleNameReferences.length; i++) {
  1163. // // System.out.println("simple: " + new String(unitResult.simpleNameReferences[i]));
  1164. // // }
  1165. // // for (int i=0; i < unitResult.qualifiedReferences.length; i++) {
  1166. // // System.out.println("qualified: " +
  1167. // // new String(CharOperation.concatWith(unitResult.qualifiedReferences[i], '/')));
  1168. // // }
  1169. // } else {
  1170. // state.noteClassesFromFile(null, sourceFileName, Collections.EMPTY_LIST);
  1171. // }
  1172. // }
  1173. //
  1174. private void setBuildConfig(AjBuildConfig buildConfig) {
  1175. this.buildConfig = buildConfig;
  1176. if (!this.environmentSupportsIncrementalCompilation) {
  1177. this.environmentSupportsIncrementalCompilation = (buildConfig.isIncrementalMode() || buildConfig
  1178. .isIncrementalFileMode());
  1179. }
  1180. handler.reset();
  1181. }
  1182. String makeClasspathString(AjBuildConfig buildConfig) {
  1183. if (buildConfig == null || buildConfig.getFullClasspath() == null) {
  1184. return "";
  1185. }
  1186. StringBuilder buf = new StringBuilder();
  1187. boolean first = true;
  1188. for (String s : buildConfig.getFullClasspath()) {
  1189. if (first) {
  1190. first = false;
  1191. }
  1192. else {
  1193. buf.append(File.pathSeparator);
  1194. }
  1195. buf.append(s.toString());
  1196. }
  1197. return buf.toString();
  1198. }
  1199. /**
  1200. * This will return null if aspectjrt.jar is present and has the correct version. Otherwise it will return a string message
  1201. * indicating the problem.
  1202. */
  1203. private String checkRtJar(AjBuildConfig buildConfig) {
  1204. // omitting dev info
  1205. if (Version.getText().equals(Version.DEVELOPMENT) || Version.getText().endsWith("-SNAPSHOT")) {
  1206. // in the development version we can't do this test usefully
  1207. // MessageUtil.info(holder, "running development version of aspectj compiler");
  1208. return null;
  1209. }
  1210. if (buildConfig == null || buildConfig.getFullClasspath() == null) {
  1211. return "no classpath specified";
  1212. }
  1213. for (String s: buildConfig.getFullClasspath()) {
  1214. if (s.endsWith("runtime/target/classes") || s.endsWith("runtime\\target\\classes")) {
  1215. // doing an AspectJ build
  1216. return null;
  1217. }
  1218. }
  1219. String ret = null;
  1220. for (String s : buildConfig.getFullClasspath()) {
  1221. File p = new File(s);
  1222. // pr112830, allow variations on aspectjrt.jar of the form aspectjrtXXXXXX.jar
  1223. if (p.isFile() && p.getName().startsWith("aspectjrt") && p.getName().endsWith(".jar")) {
  1224. try {
  1225. String version = null;
  1226. Manifest manifest = new JarFile(p).getManifest();
  1227. if (manifest == null) {
  1228. ret = "no manifest found in " + p.getAbsolutePath() + ", expected " + Version.getText();
  1229. continue;
  1230. }
  1231. Attributes attr = manifest.getAttributes("org/aspectj/lang/");
  1232. if (null != attr) {
  1233. version = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
  1234. if (null != version) {
  1235. version = version.trim();
  1236. }
  1237. }
  1238. // assume that users of development aspectjrt.jar know what they're doing
  1239. if (version != null && (Version.DEVELOPMENT.equals(version) || version.endsWith("-SNAPSHOT"))) {
  1240. // MessageUtil.info(holder,
  1241. // "running with development version of aspectjrt.jar in " +
  1242. // p.getAbsolutePath());
  1243. return null;
  1244. }
  1245. else if (!Version.getText().equals(version)) {
  1246. ret = "bad version number found in " + p.getAbsolutePath() + " expected " + Version.getText() + " found "
  1247. + version;
  1248. continue;
  1249. }
  1250. } catch (IOException ioe) {
  1251. ret = "bad jar file found in " + p.getAbsolutePath() + " error: " + ioe;
  1252. }
  1253. return null; // this is the "OK" return value!
  1254. }
  1255. else if (p.isFile() && p.getName().contains("org.aspectj.runtime")) {
  1256. // likely to be a variant from the springsource bundle repo b272591
  1257. return null;
  1258. }
  1259. else {
  1260. // might want to catch other classpath errors
  1261. }
  1262. }
  1263. if (ret != null) {
  1264. return ret; // last error found in potentially matching jars...
  1265. }
  1266. return "couldn't find aspectjrt.jar on classpath, checked: " + makeClasspathString(buildConfig);
  1267. }
  1268. @Override
  1269. public String toString() {
  1270. StringBuilder buf = new StringBuilder();
  1271. buf.append("AjBuildManager(");
  1272. buf.append(")");
  1273. return buf.toString();
  1274. }
  1275. //
  1276. // public void setStructureModel(IHierarchy structureModel) {
  1277. // this.structureModel = structureModel;
  1278. // }
  1279. /**
  1280. * Returns null if there is no structure model
  1281. */
  1282. public AsmManager getStructureModel() {
  1283. return (state == null ? null : state.getStructureModel());
  1284. }
  1285. public IProgressListener getProgressListener() {
  1286. return progressListener;
  1287. }
  1288. public void setProgressListener(IProgressListener progressListener) {
  1289. this.progressListener = progressListener;
  1290. }
  1291. /*
  1292. * (non-Javadoc)
  1293. *
  1294. * @see org.aspectj.ajdt.internal.compiler.AjCompiler.IOutputClassFileNameProvider#getOutputClassFileName(char[])
  1295. */
  1296. @Override
  1297. public String getOutputClassFileName(char[] eclipseClassFileName, CompilationResult result) {
  1298. String filename = new String(eclipseClassFileName);
  1299. filename = filename.replace('/', File.separatorChar) + ".class";
  1300. File destinationPath = buildConfig.getOutputDir();
  1301. if (buildConfig.getCompilationResultDestinationManager() != null) {
  1302. File f = new File(new String(result.getFileName()));
  1303. destinationPath = buildConfig.getCompilationResultDestinationManager().getOutputLocationForClass(f);
  1304. }
  1305. String outFile;
  1306. if (destinationPath == null) {
  1307. outFile = new File(filename).getName();
  1308. outFile = new File(extractDestinationPathFromSourceFile(result), outFile).getPath();
  1309. } else {
  1310. outFile = new File(destinationPath, filename).getPath();
  1311. }
  1312. return outFile;
  1313. }
  1314. /*
  1315. * (non-Javadoc)
  1316. *
  1317. * @see org.eclipse.jdt.internal.compiler.ICompilerAdapterFactory#getAdapter(org.eclipse.jdt.internal.compiler.Compiler)
  1318. */
  1319. @Override
  1320. public ICompilerAdapter getAdapter(org.aspectj.org.eclipse.jdt.internal.compiler.Compiler forCompiler) {
  1321. // complete compiler config and return a suitable adapter...
  1322. populateCompilerOptionsFromLintSettings(forCompiler);
  1323. AjProblemReporter pr = new AjProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), forCompiler.options,
  1324. getProblemFactory());
  1325. forCompiler.problemReporter = pr;
  1326. AjLookupEnvironment le = new AjLookupEnvironment(forCompiler, forCompiler.options, pr, environment);
  1327. EclipseFactory factory = new EclipseFactory(le, this);
  1328. le.factory = factory;
  1329. pr.factory = factory;
  1330. forCompiler.lookupEnvironment = le;
  1331. forCompiler.parser = new Parser(pr, forCompiler.options.parseLiteralExpressionsAsConstants);
  1332. if (getBcelWorld().shouldPipelineCompilation()) {
  1333. IMessage message = MessageUtil.info("Pipelining compilation");
  1334. handler.handleMessage(message);
  1335. return new AjPipeliningCompilerAdapter(forCompiler, batchCompile, getBcelWorld(), getWeaver(), factory,
  1336. getInterimResultRequestor(), progressListener,
  1337. this, // IOutputFilenameProvider
  1338. this, // IBinarySourceProvider
  1339. state.getBinarySourceMap(), buildConfig.isTerminateAfterCompilation(), buildConfig.getProceedOnError(),
  1340. buildConfig.isNoAtAspectJAnnotationProcessing(), buildConfig.isMakeReflectable(), state);
  1341. } else {
  1342. return new AjCompilerAdapter(forCompiler, batchCompile, getBcelWorld(), getWeaver(), factory,
  1343. getInterimResultRequestor(), progressListener,
  1344. this, // IOutputFilenameProvider
  1345. this, // IBinarySourceProvider
  1346. state.getBinarySourceMap(), buildConfig.isTerminateAfterCompilation(), buildConfig.getProceedOnError(),
  1347. buildConfig.isNoAtAspectJAnnotationProcessing(), buildConfig.isMakeReflectable(), state);
  1348. }
  1349. }
  1350. /**
  1351. * Some AspectJ lint options need to be known about in the compiler. This is how we pass them over...
  1352. *
  1353. * @param forCompiler
  1354. */
  1355. private void populateCompilerOptionsFromLintSettings(org.aspectj.org.eclipse.jdt.internal.compiler.Compiler forCompiler) {
  1356. BcelWorld world = this.state.getBcelWorld();
  1357. IMessage.Kind swallowedExceptionKind = world.getLint().swallowedExceptionInCatchBlock.getKind();
  1358. Map<String, String> optionsMap = new HashMap<>();
  1359. optionsMap.put(CompilerOptions.OPTION_ReportSwallowedExceptionInCatchBlock, swallowedExceptionKind == null ? "ignore"
  1360. : swallowedExceptionKind.toString());
  1361. forCompiler.options.set(optionsMap);
  1362. }
  1363. /*
  1364. * (non-Javadoc)
  1365. *
  1366. * @see org.aspectj.ajdt.internal.compiler.IBinarySourceProvider#getBinarySourcesForThisWeave()
  1367. */
  1368. @Override
  1369. public Map<String, List<UnwovenClassFile>> getBinarySourcesForThisWeave() {
  1370. return binarySourcesForTheNextCompile;
  1371. }
  1372. public static AsmHierarchyBuilder getAsmHierarchyBuilder() {
  1373. return asmHierarchyBuilder;
  1374. }
  1375. /**
  1376. * Override the the default hierarchy builder.
  1377. */
  1378. public static void setAsmHierarchyBuilder(AsmHierarchyBuilder newBuilder) {
  1379. asmHierarchyBuilder = newBuilder;
  1380. }
  1381. public AjState getState() {
  1382. return state;
  1383. }
  1384. public void setState(AjState buildState) {
  1385. state = buildState;
  1386. }
  1387. private static class AjBuildContexFormatter implements ContextFormatter {
  1388. @Override
  1389. public String formatEntry(int phaseId, Object data) {
  1390. StringBuilder sb = new StringBuilder();
  1391. if (phaseId == CompilationAndWeavingContext.BATCH_BUILD) {
  1392. sb.append("batch building ");
  1393. } else {
  1394. sb.append("incrementally building ");
  1395. }
  1396. AjBuildConfig config = (AjBuildConfig) data;
  1397. List<String> classpath = config.getClasspath();
  1398. sb.append("with classpath: ");
  1399. for (Object o : classpath) {
  1400. sb.append(o.toString());
  1401. sb.append(File.pathSeparator);
  1402. }
  1403. return sb.toString();
  1404. }
  1405. }
  1406. public boolean wasFullBuild() {
  1407. return wasFullBuild;
  1408. }
  1409. }