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.

AjCompiler.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /********************************************************************
  2. * Copyright (c) 2007 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution and is available at
  6. * http://eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initial version (bug 148190)
  10. *******************************************************************/
  11. package org.aspectj.ajde.core;
  12. import org.aspectj.ajde.core.internal.AjdeCoreBuildManager;
  13. import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager;
  14. import org.aspectj.asm.AsmManager;
  15. import org.aspectj.bridge.IMessage;
  16. import org.aspectj.bridge.Message;
  17. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
  18. /**
  19. * The class to be used by tools to drive a build. An AjCompiler is created with a unique id (for example the absolute pathname of a
  20. * project or .lst file) along with implementations of ICompilerConfiguration, IBuildProgressMonitor and IBuildMessageHandler. Tools
  21. * then call build() or buildFresh() on this AjCompiler.
  22. *
  23. * <p>
  24. * An AjCompiler is associated with one id, therefore a new one needs to be created for a new id (project, .lst file etc.). It is
  25. * the responsibility of the tools to manage the lifecycle of the AjCompiler's.
  26. */
  27. public class AjCompiler {
  28. private final String compilerId;
  29. private final ICompilerConfiguration compilerConfig;
  30. private final IBuildProgressMonitor monitor;
  31. private final IBuildMessageHandler handler;
  32. private final AjdeCoreBuildManager buildManager;
  33. /**
  34. * Creates a new AjCompiler for the given id, ICompilerConfiguration, IBuildProgressMonitor and IBuildMessageHandler. None of
  35. * the arguments can be null.
  36. *
  37. * @param compilerId - Unique String used to identify this AjCompiler
  38. * @param compilerConfig - ICompilerConfiguration implementation
  39. * @param buildProgressMonitor - IBuildProgressMonitor implementation
  40. * @param buildMessageHandler - IBuildMessageHandler implementation
  41. */
  42. public AjCompiler(String compilerId, ICompilerConfiguration compilerConfig, IBuildProgressMonitor buildProgressMonitor,
  43. IBuildMessageHandler buildMessageHandler) {
  44. this.compilerConfig = compilerConfig;
  45. this.monitor = buildProgressMonitor;
  46. this.handler = buildMessageHandler;
  47. this.compilerId = compilerId;
  48. this.buildManager = new AjdeCoreBuildManager(this);
  49. }
  50. /**
  51. * @return the id for this AjCompiler
  52. */
  53. public String getId() {
  54. return compilerId;
  55. }
  56. /**
  57. * @return the ICompilerConfiguration associated with this AjCompiler
  58. */
  59. public ICompilerConfiguration getCompilerConfiguration() {
  60. return compilerConfig;
  61. }
  62. /**
  63. * @return the IBuildProgressMonitor associated with this AjCompiler
  64. */
  65. public IBuildProgressMonitor getBuildProgressMonitor() {
  66. return monitor;
  67. }
  68. /**
  69. * @return the IBuildMessageHandler associated with this AjCompiler
  70. */
  71. public IBuildMessageHandler getMessageHandler() {
  72. return handler;
  73. }
  74. /**
  75. * Perform an incremental build if possible, otherwise it will default to a full build.
  76. */
  77. public void build() {
  78. if (hasValidId()) {
  79. buildManager.performBuild(false);
  80. }
  81. }
  82. /**
  83. * Perform a full build.
  84. */
  85. public void buildFresh() {
  86. if (hasValidId()) {
  87. buildManager.performBuild(true);
  88. }
  89. }
  90. /**
  91. * Clear the incremental state associated with this AjCompiler from the IncrementalStateManager. This is necessary until AjState
  92. * is reworked and there's an AjState associated with an AjCompiler rather than requiring a map of them. If the environment is
  93. * not cleaned up then jar locks may be kept.
  94. */
  95. public void clearLastState() {
  96. IncrementalStateManager.removeIncrementalStateInformationFor(compilerId);
  97. buildManager.cleanupEnvironment();
  98. }
  99. /**
  100. * @return true if the underlying version of the compiler is compatible with Java 6, returns false otherwise.
  101. */
  102. public boolean isJava6Compatible() {
  103. return CompilerOptions.versionToJdkLevel(JavaOptions.VERSION_16) != 0;
  104. }
  105. /**
  106. * Ensures that the id associated with this compiler is non-null. If it is null then sends an ABORT message to the
  107. * messageHandler.
  108. */
  109. private boolean hasValidId() {
  110. if (compilerId == null) {
  111. Message msg = new Message("compiler didn't have an id associated with it", IMessage.ABORT, null, null);
  112. handler.handleMessage(msg);
  113. return false;
  114. }
  115. return true;
  116. }
  117. /**
  118. * Set a CustomMungerFactory to the compiler's weaver
  119. *
  120. * The type of factory should be org.aspectj.weaver.CustomMungerFactory but due to dependency problem of project ajde.core, it
  121. * is Object for now.
  122. *
  123. * @param factory
  124. */
  125. public void setCustomMungerFactory(Object factory) {
  126. buildManager.setCustomMungerFactory(factory);
  127. }
  128. /**
  129. * @return the CustomMungerFactory from the compiler's weaver
  130. *
  131. * The return type should be org.aspectj.weaver.CustomMungerFactory but due to dependency problem of project ajde.core,
  132. * it is Object for now.
  133. */
  134. public Object getCustomMungerFactory() {
  135. return buildManager.getCustomMungerFactory();
  136. }
  137. public AsmManager getModel() {
  138. return buildManager.getStructureModel();
  139. }
  140. // public AsmManager getStructureModel() {
  141. // return buildManager.getStructureModel();
  142. // }
  143. }