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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.bridge.IMessage;
  15. import org.aspectj.bridge.Message;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
  17. /**
  18. * The class to be used by tools to drive a build. An AjCompiler is created
  19. * with a unique id (for example the absolute pathname of a project
  20. * or .lst file) along with implementations of ICompilerConfiguration,
  21. * IBuildProgressMonitor and IBuildMessageHandler. Tools then call
  22. * build() or buildFresh() on this AjCompiler.
  23. *
  24. * <p>An AjCompiler is associated with one id, therefore a new one
  25. * needs to be created for a new id (project, .lst file etc.). It is the
  26. * responsibility of the tools to manage the lifecycle of the AjCompiler's.
  27. */
  28. public class AjCompiler {
  29. private ICompilerConfiguration compilerConfig;
  30. private IBuildProgressMonitor monitor;
  31. private IBuildMessageHandler handler;
  32. private String compilerId;
  33. private AjdeCoreBuildManager buildManager;
  34. /**
  35. * Creates a new AjCompiler for the given id, ICompilerConfiguration,
  36. * IBuildProgressMonitor and IBuildMessageHandler. None of the arguments
  37. * can be null.
  38. *
  39. * @param compilerId - Unique String used to identify this AjCompiler
  40. * @param compilerConfig - ICompilerConfiguration implementation
  41. * @param buildProgressMonitor - IBuildProgressMonitor implementation
  42. * @param buildMessageHandler - IBuildMessageHandler implementation
  43. */
  44. public AjCompiler(
  45. String compilerId,
  46. ICompilerConfiguration compilerConfig,
  47. IBuildProgressMonitor buildProgressMonitor,
  48. IBuildMessageHandler buildMessageHandler) {
  49. this.compilerConfig = compilerConfig;
  50. this.monitor = buildProgressMonitor;
  51. this.handler = buildMessageHandler;
  52. this.compilerId = compilerId;
  53. buildManager = new AjdeCoreBuildManager(this);
  54. }
  55. /**
  56. * @return the id for this AjCompiler
  57. */
  58. public String getId() {
  59. return compilerId;
  60. }
  61. /**
  62. * @return the ICompilerConfiguration associated with this AjCompiler
  63. */
  64. public ICompilerConfiguration getCompilerConfiguration() {
  65. return compilerConfig;
  66. }
  67. /**
  68. * @return the IBuildProgressMonitor associated with this AjCompiler
  69. */
  70. public IBuildProgressMonitor getBuildProgressMonitor() {
  71. return monitor;
  72. }
  73. /**
  74. * @return the IBuildMessageHandler associated with this AjCompiler
  75. */
  76. public IBuildMessageHandler getMessageHandler() {
  77. return handler;
  78. }
  79. /**
  80. * Perform an incremental build if possible, otherwise it will
  81. * default to a full build.
  82. */
  83. public void build() {
  84. if (hasValidId()) {
  85. buildManager.doBuild(false);
  86. }
  87. }
  88. /**
  89. * Perform a full build
  90. */
  91. public void buildFresh() {
  92. if (hasValidId()) {
  93. buildManager.doBuild(true);
  94. }
  95. }
  96. /**
  97. * Clear the incremental state associated with this AjCompiler
  98. * from the IncrementalStateManager. This is necessary until AjState
  99. * is reworked and there's an AjState associated with an AjCompiler
  100. * rather than requiring a map of them.
  101. */
  102. public void clearLastState() {
  103. IncrementalStateManager.removeIncrementalStateInformationFor(compilerId);
  104. }
  105. /**
  106. * @return true if the underlying version of the compiler
  107. * is compatible with Java 6, returns false otherwise.
  108. */
  109. public boolean isJava6Compatible() {
  110. return CompilerOptions.versionToJdkLevel(JavaOptions.VERSION_16) != 0;
  111. }
  112. /**
  113. * Ensures that the id associated with this compiler is non-null. If
  114. * it is null then sends an ABORT message to the messageHandler
  115. */
  116. private boolean hasValidId() {
  117. if (compilerId == null) {
  118. Message msg = new Message("compiler didn't have an id associated " +
  119. "with it",IMessage.ABORT,null,null);
  120. handler.handleMessage(msg);
  121. return false;
  122. }
  123. return true;
  124. }
  125. }