1 package net.sourceforge.phpdt.externaltools.variable;
3 /**********************************************************************
4 Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
10 **********************************************************************/
12 import org.eclipse.core.resources.IProject;
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.resources.IncrementalProjectBuilder;
15 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
18 * Represents the context the external tool is running in
19 * that a variable uses to expand itself.
21 public final class ExpandVariableContext {
22 public static final ExpandVariableContext EMPTY_CONTEXT = new ExpandVariableContext(null);
24 private IProject project = null;
25 private IResource selectedResource = null;
26 private String buildType = IExternalToolConstants.BUILD_TYPE_NONE;
29 * Create a context for an external tool running
30 * as a builder on the given project.
32 * @param project the <code>IProject</code> being built.
33 * @param buildKind the kind of build being performed
34 * (see <code>IncrementalProjectBuilder</code>).
36 public ExpandVariableContext(IProject project, int buildKind) {
38 this.project = project;
40 case IncrementalProjectBuilder.INCREMENTAL_BUILD :
41 this.buildType = IExternalToolConstants.BUILD_TYPE_INCREMENTAL;
43 case IncrementalProjectBuilder.FULL_BUILD :
44 this.buildType = IExternalToolConstants.BUILD_TYPE_FULL;
46 case IncrementalProjectBuilder.AUTO_BUILD :
47 this.buildType = IExternalToolConstants.BUILD_TYPE_AUTO;
50 this.buildType = IExternalToolConstants.BUILD_TYPE_NONE;
56 * Create a context for an external tool running
57 * with the given resource selected.
59 * @param selectedResource the <code>IResource</code> selected
60 * or <code>null</code> if none.
62 public ExpandVariableContext(IResource selectedResource) {
64 if (selectedResource != null) {
65 this.selectedResource = selectedResource;
66 this.project = selectedResource.getProject();
71 * Returns the build type being performed if the
72 * external tool is being run as a project builder.
74 * @return one of the <code>IExternalToolConstants.BUILD_TYPE_*</code> constants.
76 public String getBuildType() {
81 * Returns the project which the variable can use. This
82 * will the the project being built if the tool is being
83 * run as a builder. Otherwise, it is the project of the
84 * selected resource, or <code>null</code> if none.
86 * @return the <code>IProject</code> or <code>null</code> if none
88 public IProject getProject() {
93 * Returns the resource selected at the time the tool
94 * is run, or <code>null</code> if none selected.
96 * @return the <code>IResource</code> selected, or <code>null</code> if none
98 public IResource getSelectedResource() {
99 return selectedResource;