src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java

changeset 930
cb119107aeea
parent 695
3c9b64e55c5d
child 944
83260b3305ac
     1.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Mon Mar 14 11:42:15 2011 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTaskImpl.java	Mon Mar 14 11:48:41 2011 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -129,19 +129,11 @@
    1.11  
    1.12      public Boolean call() {
    1.13          if (!used.getAndSet(true)) {
    1.14 -            beginContext();
    1.15 +            initContext();
    1.16              notYetEntered = new HashMap<JavaFileObject, JCCompilationUnit>();
    1.17 -            try {
    1.18 -                compilerMain.setFatalErrors(true);
    1.19 -                result = compilerMain.compile(args, context, fileObjects, processors);
    1.20 -            } finally {
    1.21 -                endContext();
    1.22 -            }
    1.23 -            compilerMain = null;
    1.24 -            args = null;
    1.25 -            context = null;
    1.26 -            fileObjects = null;
    1.27 -            notYetEntered = null;
    1.28 +            compilerMain.setFatalErrors(true);
    1.29 +            result = compilerMain.compile(args, context, fileObjects, processors);
    1.30 +            cleanup();
    1.31              return result == 0;
    1.32          } else {
    1.33              throw new IllegalStateException("multiple calls to method 'call'");
    1.34 @@ -163,8 +155,11 @@
    1.35      }
    1.36  
    1.37      private void prepareCompiler() throws IOException {
    1.38 -        if (!used.getAndSet(true)) {
    1.39 -            beginContext();
    1.40 +        if (used.getAndSet(true)) {
    1.41 +            if (compiler == null)
    1.42 +                throw new IllegalStateException();
    1.43 +        } else {
    1.44 +            initContext();
    1.45              compilerMain.setOptions(Options.instance(context));
    1.46              compilerMain.filenames = new ListBuffer<File>();
    1.47              List<File> filenames = compilerMain.processArgs(CommandLine.parse(args));
    1.48 @@ -185,13 +180,12 @@
    1.49          }
    1.50      }
    1.51  
    1.52 -    private void beginContext() {
    1.53 +    private void initContext() {
    1.54          context.put(JavacTaskImpl.class, this);
    1.55          if (context.get(TaskListener.class) != null)
    1.56              context.put(TaskListener.class, (TaskListener)null);
    1.57          if (taskListener != null)
    1.58              context.put(TaskListener.class, wrap(taskListener));
    1.59 -        tool.beginContext(context);
    1.60          //initialize compiler's default locale
    1.61          JavacMessages.instance(context).setCurrentLocale(locale);
    1.62      }
    1.63 @@ -218,8 +212,15 @@
    1.64          };
    1.65      }
    1.66  
    1.67 -    private void endContext() {
    1.68 -        tool.endContext();
    1.69 +    void cleanup() {
    1.70 +        if (compiler != null)
    1.71 +            compiler.close();
    1.72 +        compiler = null;
    1.73 +        compilerMain = null;
    1.74 +        args = null;
    1.75 +        context = null;
    1.76 +        fileObjects = null;
    1.77 +        notYetEntered = null;
    1.78      }
    1.79  
    1.80      /**
    1.81 @@ -446,12 +447,12 @@
    1.82              }
    1.83              if (genList.isEmpty()) {
    1.84                  compiler.reportDeferredDiagnostics();
    1.85 -                compiler.log.flush();
    1.86 -                endContext();
    1.87 +                cleanup();
    1.88              }
    1.89          }
    1.90          finally {
    1.91 -            compiler.log.flush();
    1.92 +            if (compiler != null)
    1.93 +                compiler.log.flush();
    1.94          }
    1.95          return results;
    1.96      }

mercurial