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.

JDTCompilerAdapter.java 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. ///*******************************************************************************
  2. // * Copyright (c) 2002 International Business Machines Corp. and others.
  3. // * All rights reserved. This program and the accompanying materials
  4. // * are made available under the terms of the Common Public License v0.5
  5. // * which accompanies this distribution, and is available at
  6. // * http://www.eclipse.org/legal/cpl-v05.html
  7. // *
  8. // * Contributors:
  9. // * IBM Corporation - initial API and implementation
  10. // ******************************************************************************/
  11. package org.eclipse.jdt.core;
  12. //
  13. //import java.io.File;
  14. //import java.lang.reflect.Method;
  15. //
  16. //import org.apache.tools.ant.BuildException;
  17. //import org.apache.tools.ant.Project;
  18. //import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter;
  19. //import org.apache.tools.ant.types.Commandline;
  20. //import org.apache.tools.ant.types.FileSet;
  21. //import org.apache.tools.ant.types.Path;
  22. //import org.eclipse.core.runtime.IPath;
  23. //import org.eclipse.jdt.internal.core.Util;
  24. //
  25. ///**
  26. // * Ant compiler adapter for the Eclipse Java compiler. This adapter permits the
  27. // * Eclipse Java compiler to be used with the <code>javac</code> task in Ant scripts. In order
  28. // * to use it, just set the property <code>build.compiler</code> as follows:
  29. // * <p>
  30. // * <code>&lt;property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/&gt;</code>
  31. // * </p>
  32. // * <p>
  33. // * For more information on Ant check out the website at http://jakarta.apache.org/ant/ .
  34. // * </p>
  35. // *
  36. // * @since 2.0
  37. // */
  38. //public class JDTCompilerAdapter extends DefaultCompilerAdapter {
  39. // private static String compilerClass = "org.eclipse.jdt.internal.compiler.batch.Main"; //$NON-NLS-1$
  40. // /**
  41. // * Performs a compile using the JDT batch compiler
  42. // */
  43. // public boolean execute() throws BuildException {
  44. // attributes.log(Util.bind("ant.jdtadapter.info.usingJdtCompiler"), Project.MSG_VERBOSE); //$NON-NLS-1$
  45. // Commandline cmd = setupJavacCommand();
  46. //
  47. // try {
  48. // Class c = Class.forName(compilerClass);
  49. // Method compile = c.getMethod("main", new Class[] { String[].class }); //$NON-NLS-1$
  50. // compile.invoke(null, new Object[] { cmd.getArguments()});
  51. // } catch (ClassNotFoundException cnfe) {
  52. // throw new BuildException(Util.bind("ant.jdtadapter.error.missingJDTCompiler")); //$NON-NLS-1$
  53. // } catch (Exception ex) {
  54. // throw new BuildException(ex);
  55. // }
  56. // return true;
  57. // }
  58. //
  59. //
  60. // protected Commandline setupJavacCommand() throws BuildException {
  61. // Commandline cmd = new Commandline();
  62. //
  63. // /*
  64. // * This option is used to never exit at the end of the ant task.
  65. // */
  66. // cmd.createArgument().setValue("-noExit"); //$NON-NLS-1$
  67. //
  68. // Path classpath = new Path(project);
  69. //
  70. // /*
  71. // * Eclipse compiler doesn't support bootclasspath dir (-bootclasspath).
  72. // * It is emulated using the classpath. We add bootclasspath at the beginning of
  73. // * the classpath.
  74. // */
  75. // if (bootclasspath != null && bootclasspath.size() != 0) {
  76. // classpath.append(bootclasspath);
  77. // } else {
  78. // /*
  79. // * No bootclasspath, we will add one throught the JRE_LIB variable
  80. // */
  81. // IPath jre_lib = JavaCore.getClasspathVariable("JRE_LIB"); //$NON-NLS-1$
  82. // if (jre_lib == null) {
  83. // throw new BuildException(Util.bind("ant.jdtadapter.error.missingJRELIB")); //$NON-NLS-1$
  84. // }
  85. // classpath.addExisting(new Path(null, jre_lib.toOSString()));
  86. // }
  87. //
  88. // /*
  89. // * Eclipse compiler doesn't support -extdirs.
  90. // * It is emulated using the classpath. We add extdirs entries after the
  91. // * bootclasspath.
  92. // */
  93. // addExtdirs(extdirs, classpath);
  94. //
  95. // /*
  96. // * The java runtime is already handled, so we simply want to retrieve the
  97. // * ant runtime and the compile classpath.
  98. // */
  99. // includeJavaRuntime = false;
  100. // classpath.append(getCompileClasspath());
  101. //
  102. // /*
  103. // * Set the classpath for the Eclipse compiler.
  104. // */
  105. // cmd.createArgument().setValue("-classpath"); //$NON-NLS-1$
  106. // cmd.createArgument().setPath(classpath);
  107. //
  108. // /*
  109. // * Handle the nowarn option. If none, then we generate all warnings.
  110. // */
  111. // if (attributes.getNowarn()) {
  112. // cmd.createArgument().setValue("-nowarn"); //$NON-NLS-1$
  113. // } else {
  114. // cmd.createArgument().setValue(
  115. // "-warn:constructorName,packageDefaultMethod,maskedCatchBlocks,deprecation"); //$NON-NLS-1$
  116. // }
  117. //
  118. // /*
  119. // * deprecation option.
  120. // */
  121. // if (deprecation) {
  122. // cmd.createArgument().setValue("-deprecation"); //$NON-NLS-1$
  123. // }
  124. //
  125. // /*
  126. // * destDir option.
  127. // */
  128. // if (destDir != null) {
  129. // cmd.createArgument().setValue("-d"); //$NON-NLS-1$
  130. // cmd.createArgument().setFile(destDir.getAbsoluteFile());
  131. // }
  132. //
  133. // /*
  134. // * target option.
  135. // */
  136. // if (target != null) {
  137. // cmd.createArgument().setValue("-target"); //$NON-NLS-1$
  138. // cmd.createArgument().setValue(target);
  139. // }
  140. //
  141. // /*
  142. // * debug option
  143. // */
  144. // if (debug) {
  145. // cmd.createArgument().setValue("-g"); //$NON-NLS-1$
  146. // }
  147. //
  148. // /*
  149. // * verbose option
  150. // */
  151. // if (verbose) {
  152. // cmd.createArgument().setValue("-verbose"); //$NON-NLS-1$
  153. // /*
  154. // * extra option allowed by the Eclipse compiler
  155. // */
  156. // cmd.createArgument().setValue("-log"); //$NON-NLS-1$
  157. // cmd.createArgument().setValue(destDir.getAbsolutePath() + ".log"); //$NON-NLS-1$
  158. // }
  159. //
  160. // /*
  161. // * failnoerror option
  162. // */
  163. // if (!attributes.getFailonerror()) {
  164. // cmd.createArgument().setValue("-proceedOnError"); //$NON-NLS-1$
  165. // }
  166. //
  167. // /*
  168. // * extra option allowed by the Eclipse compiler
  169. // */
  170. // cmd.createArgument().setValue("-time"); //$NON-NLS-1$
  171. //
  172. // /*
  173. // * extra option allowed by the Eclipse compiler
  174. // */
  175. // cmd.createArgument().setValue("-noImportError"); //$NON-NLS-1$
  176. //
  177. // /*
  178. // * source option
  179. // */
  180. // String source = attributes.getSource();
  181. // if (source != null) {
  182. // cmd.createArgument().setValue("-source"); //$NON-NLS-1$
  183. // cmd.createArgument().setValue(source);
  184. // }
  185. //
  186. // /*
  187. // * encoding option
  188. // */
  189. // if (encoding != null) {
  190. // cmd.createArgument().setValue("-encoding"); //$NON-NLS-1$
  191. // cmd.createArgument().setValue(encoding);
  192. // }
  193. //
  194. // /*
  195. // * Eclipse compiler doesn't have a -sourcepath option. This is
  196. // * handled through the javac task that collects all source files in
  197. // * srcdir option.
  198. // */
  199. // logAndAddFilesToCompile(cmd);
  200. // return cmd;
  201. // }
  202. //
  203. // /**
  204. // * Emulation of extdirs feature in java >= 1.2.
  205. // * This method adds all files in the given
  206. // * directories (but not in sub-directories!) to the classpath,
  207. // * so that you don't have to specify them all one by one.
  208. // * @param extdirs - Path to append files to
  209. // */
  210. // private void addExtdirs(Path extdirs, Path classpath) {
  211. // if (extdirs == null) {
  212. // String extProp = System.getProperty("java.ext.dirs"); //$NON-NLS-1$
  213. // if (extProp != null) {
  214. // extdirs = new Path(classpath.getProject(), extProp);
  215. // } else {
  216. // return;
  217. // }
  218. // }
  219. //
  220. // String[] dirs = extdirs.list();
  221. // for (int i = 0; i < dirs.length; i++) {
  222. // File dir = classpath.getProject().resolveFile(dirs[i]);
  223. // if (dir.exists() && dir.isDirectory()) {
  224. // FileSet fs = new FileSet();
  225. // fs.setDir(dir);
  226. // fs.setIncludes("*"); //$NON-NLS-1$
  227. // classpath.addFileset(fs);
  228. // }
  229. // }
  230. // }
  231. //}