コード例 #1
0
  public <V> V execute(MavenProject project, ICallable<V> callable, IProgressMonitor monitor)
      throws CoreException {
    Deque<MavenExecutionContext> stack = threadLocal.get();
    if (stack == null) {
      stack = new ArrayDeque<MavenExecutionContext>();
      threadLocal.set(stack);
    }
    final MavenExecutionContext parent = stack.peek();

    if (this == parent) {
      // shortcut the setup logic, this is nested invocation of the same context
      return executeBare(project, callable, monitor);
    }

    // remember original configuration to "pop" the session stack properly
    final MavenExecutionRequest origRequest = request;
    final Map<String, Object> origContext = context;

    if (request == null && parent != null) {
      this.request = parent.request;
      this.context = new HashMap<String, Object>(parent.context);
    } else {
      this.context = new HashMap<String, Object>();
      if (request == null) {
        request = newExecutionRequest();
      }
      maven.populateDefaults(request);
      populateSystemProperties(request);
      setValue(CTX_LOCALREPOSITORY, request.getLocalRepository());
      final FilterRepositorySystemSession repositorySession =
          maven.createRepositorySession(request);
      setValue(CTX_REPOSITORYSESSION, repositorySession);
      if (parent != null) {
        repositorySession.setData(parent.getRepositorySession().getData());
      }
      final MavenExecutionResult result = new DefaultMavenExecutionResult();
      setValue(
          CTX_MAVENSESSION,
          new MavenSession(maven.getPlexusContainer(), repositorySession, request, result));
    }

    final LegacySupport legacySupport = maven.lookup(LegacySupport.class);
    final MavenSession origLegacySession =
        legacySupport.getSession(); // TODO validate == origSession

    stack.push(this);
    legacySupport.setSession(getSession());
    try {
      return executeBare(project, callable, monitor);
    } finally {
      stack.pop();
      if (stack.isEmpty()) {
        threadLocal.set(null); // TODO decide if this is useful
      }
      legacySupport.setSession(origLegacySession);
      request = origRequest;
      context = origContext;
    }
  }
コード例 #2
0
ファイル: JobHelpers.java プロジェクト: GEBIT/m2e-core
 private static boolean flushProcessingQueues(IJobManager jobManager, IProgressMonitor monitor)
     throws InterruptedException, CoreException {
   boolean processed = false;
   for (IBackgroundProcessingQueue queue : getProcessingQueues(jobManager)) {
     queue.join();
     if (!queue.isEmpty()) {
       Deque<MavenExecutionContext> context = MavenExecutionContext.suspend();
       try {
         IStatus status = queue.run(monitor);
         if (!status.isOK()) {
           throw new CoreException(status);
         }
         processed = true;
       } finally {
         MavenExecutionContext.resume(context);
       }
     }
     if (queue.isEmpty()) {
       queue.cancel();
     }
   }
   return processed;
 }