AntProcess.java :  » IDE-Eclipse » ant » org » eclipse » ant » internal » ui » launchConfigurations » Java Open Source

Java Open Source » IDE Eclipse » ant 
ant » org » eclipse » ant » internal » ui » launchConfigurations » AntProcess.java
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ant.internal.ui.launchConfigurations;


import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.PlatformObject;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.core.model.IStreamsProxy;
import org.eclipse.debug.ui.console.IConsole;

public class AntProcess extends PlatformObject implements IProcess, IProgressMonitor {
  
  private AntStreamsProxy fProxy;
  private String fLabel = null;
  private ILaunch fLaunch = null;
  private Map fAttributes = null;
  private boolean fTerminated = false;
  private boolean fCancelled = false;
  private IConsole fConsole = null;
  
  public AntProcess(String label, ILaunch launch, Map attributes) {
    fLabel = label;
    fLaunch = launch;
    if (attributes == null) {
      fAttributes = new HashMap();
    } else {
      fAttributes = attributes;
    }
    String captureOutput= launch.getAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT);
    if(!("false".equals(captureOutput))) { //$NON-NLS-1$
      fProxy= new AntStreamsProxy();
    }
    launch.addProcess(this);
  }

  /**
   * @see org.eclipse.debug.core.model.IProcess#getLabel()
   */
  public String getLabel() {
    return fLabel;
  }

  /**
   * @see org.eclipse.debug.core.model.IProcess#getLaunch()
   */
  public ILaunch getLaunch() {
    return fLaunch;
  }

  /**
   * @see org.eclipse.debug.core.model.IProcess#getStreamsProxy()
   */
  public IStreamsProxy getStreamsProxy() {
    return fProxy;
  }

  /**
   * @see org.eclipse.debug.core.model.IProcess#setAttribute(java.lang.String, java.lang.String)
   */
  public void setAttribute(String key, String value) {
    fAttributes.put(key, value);
  }

  /**
   * @see org.eclipse.debug.core.model.IProcess#getAttribute(java.lang.String)
   */
  public String getAttribute(String key) {
    return (String)fAttributes.get(key);
  }

  /**
   * @see org.eclipse.debug.core.model.IProcess#getExitValue()
   */
  public int getExitValue() {
    return 0;
  }

  /**
   * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
   */
  public boolean canTerminate() {
    return !isCanceled() && !isTerminated();
  }

  /**
   * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
   */
  public boolean isTerminated() {
    return fTerminated;
  }
  
  protected void terminated() {
    if (!fTerminated) {
      fTerminated = true;
      if (DebugPlugin.getDefault() != null) {
        DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {new DebugEvent(this, DebugEvent.TERMINATE)});
      }
    }
  }

  /**
   * @see org.eclipse.debug.core.model.ITerminate#terminate()
   */
  public void terminate() {
    setCanceled(true);
  }

  /**
   * Returns the console associated with this process, or <code>null</code> if
   * none.
   * 
   * @return console, or <code>null</code>
   */
  public IConsole getConsole() {
    return fConsole;
  }
  
  /**
   * Sets the console associated with this process.
   * 
   * @param console
   */
  public void setConsole(IConsole console) {
    fConsole = console;
  }
  
  // IProgressMonitor implemented to support termination.
  
  /**
   * @see org.eclipse.core.runtime.IProgressMonitor#beginTask(java.lang.String, int)
   */
  public void beginTask(String name, int totalWork) {
  }

  /**
   * @see org.eclipse.core.runtime.IProgressMonitor#done()
   */
  public void done() {
  }

  /**
   * @see org.eclipse.core.runtime.IProgressMonitor#internalWorked(double)
   */
  public void internalWorked(double work) {
  }

  /**
   * @see org.eclipse.core.runtime.IProgressMonitor#isCanceled()
   */
  public boolean isCanceled() {
    return fCancelled;
  }

  /**
   * @see org.eclipse.core.runtime.IProgressMonitor#setCanceled(boolean)
   */
  public void setCanceled(boolean value) {
    fCancelled = value;
  }

  /**
   * @see org.eclipse.core.runtime.IProgressMonitor#setTaskName(java.lang.String)
   */
  public void setTaskName(String name) {
  }

  /**
   * @see org.eclipse.core.runtime.IProgressMonitor#subTask(java.lang.String)
   */
  public void subTask(String name) {
  }

  /**
   * @see org.eclipse.core.runtime.IProgressMonitor#worked(int)
   */
  public void worked(int work) {
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.