Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 264338 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +1 lines)
Lines 7-13 Link Here
7
Bundle-Vendor: %providerName
7
Bundle-Vendor: %providerName
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Export-Package: org.eclipse.ant.core,
9
Export-Package: org.eclipse.ant.core,
10
 org.eclipse.ant.internal.core;x-friends:="org.eclipse.ant.ui",
10
 org.eclipse.ant.internal.core;x-friends:="org.eclipse.ant.ui,org.eclipse.ant.launching",
11
 org.eclipse.ant.internal.core.contentDescriber;x-internal:=true
11
 org.eclipse.ant.internal.core.contentDescriber;x-internal:=true
12
Require-Bundle: org.eclipse.core.variables;bundle-version="[3.1.0,4.0.0)",
12
Require-Bundle: org.eclipse.core.variables;bundle-version="[3.1.0,4.0.0)",
13
 org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)"
13
 org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)"
(-).classpath (+3 lines)
Lines 3-7 Link Here
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="src" output="loggers_bin" path="loggers"/>
7
	<classpathentry kind="src" output="common_bin" path="common"/>
8
	<classpathentry kind="src" output="remote_bin" path="remote"/>
6
	<classpathentry kind="output" path="bin"/>
9
	<classpathentry kind="output" path="bin"/>
7
</classpath>
10
</classpath>
(-).cvsignore (-1 / +5 lines)
Line 1 Link Here
1
bin
1
bin
2
lib
3
temp.folder
4
loggers_bin
5
common_bin
(-).externalToolBuilders/build (+21 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
3
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
4
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
5
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;launchConfigurationWorkingSet editPageId=&quot;org.eclipse.ui.resourceWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; id=&quot;1254539808328_112&quot; label=&quot;working set&quot; name=&quot;working set&quot;&gt;&#13;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.ant.launching/lib&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;/launchConfigurationWorkingSet&gt;}"/>
6
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
7
<listEntry value="/org.eclipse.ant.launching/buildfiles/buildCommonDebug.xml"/>
8
</listAttribute>
9
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
10
<listEntry value="1"/>
11
</listAttribute>
12
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
13
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
14
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.ant.launching"/>
15
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
16
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;launchConfigurationWorkingSet editPageId=&quot;org.eclipse.ui.resourceWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; id=&quot;1254539834953_113&quot; label=&quot;workingSet&quot; name=&quot;workingSet&quot;&gt;&#13;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.ant.launching/common&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;/launchConfigurationWorkingSet&gt;}"/>
17
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.ant.launching/buildfiles/buildCommonDebug.xml}"/>
18
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
19
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
20
<stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/>
21
</launchConfiguration>
(-).externalToolBuilders/build (+22 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
3
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
4
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
5
<booleanAttribute key="org.eclipse.ant.uiSET_INPUTHANDLER" value="false"/>
6
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;launchConfigurationWorkingSet editPageId=&quot;org.eclipse.ui.resourceWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; id=&quot;1254539604968_29&quot; label=&quot;working set&quot; name=&quot;working set&quot;&gt;&#13;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.ant.launching/lib&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;/launchConfigurationWorkingSet&gt;}"/>
7
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
8
<listEntry value="/org.eclipse.ant.launching/buildfiles/buildLoggers.xml"/>
9
</listAttribute>
10
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
11
<listEntry value="1"/>
12
</listAttribute>
13
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
14
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
15
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.ant.launching"/>
16
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
17
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;launchConfigurationWorkingSet editPageId=&quot;org.eclipse.ui.resourceWorkingSetPage&quot; factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; id=&quot;1254539671875_56&quot; label=&quot;workingSet&quot; name=&quot;workingSet&quot;&gt;&#13;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.ant.launching/loggers&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;/launchConfigurationWorkingSet&gt;}"/>
18
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.ant.launching/buildfiles/buildLoggers.xml}"/>
19
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
20
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
21
<stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/>
22
</launchConfiguration>
(-).externalToolBuilders/build (+21 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
3
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
4
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
5
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;launchConfigurationWorkingSet factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; id=&quot;1254617191468_44&quot; label=&quot;working set&quot; name=&quot;working set&quot;&gt;&#13;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.ant.launching/lib&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;/launchConfigurationWorkingSet&gt;}"/>
6
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
7
<listEntry value="/org.eclipse.ant.launching/buildfiles/buildRemote.xml"/>
8
</listAttribute>
9
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
10
<listEntry value="1"/>
11
</listAttribute>
12
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
13
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
14
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.ant.launching"/>
15
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
16
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_BUILD_SCOPE" value="${working_set:&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;launchConfigurationWorkingSet factoryID=&quot;org.eclipse.ui.internal.WorkingSetFactory&quot; id=&quot;1254617206453_45&quot; label=&quot;workingSet&quot; name=&quot;workingSet&quot;&gt;&#13;&#10;&lt;item factoryID=&quot;org.eclipse.ui.internal.model.ResourceFactory&quot; path=&quot;/org.eclipse.ant.launching/remote&quot; type=&quot;2&quot;/&gt;&#13;&#10;&lt;/launchConfigurationWorkingSet&gt;}"/>
17
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.ant.launching/buildfiles/buildRemote.xml}"/>
18
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,auto,"/>
19
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
20
<stringAttribute key="process_factory_id" value="org.eclipse.ant.ui.remoteAntProcessFactory"/>
21
</launchConfiguration>
(-).project (+30 lines)
Lines 25-30 Link Here
25
			<arguments>
25
			<arguments>
26
			</arguments>
26
			</arguments>
27
		</buildCommand>
27
		</buildCommand>
28
		<buildCommand>
29
			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
30
			<triggers>auto,full,incremental,</triggers>
31
			<arguments>
32
				<dictionary>
33
					<key>LaunchConfigHandle</key>
34
					<value>&lt;project&gt;/.externalToolBuilders/build loggers [Builder].launch</value>
35
				</dictionary>
36
			</arguments>
37
		</buildCommand>
38
		<buildCommand>
39
			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
40
			<triggers>auto,full,incremental,</triggers>
41
			<arguments>
42
				<dictionary>
43
					<key>LaunchConfigHandle</key>
44
					<value>&lt;project&gt;/.externalToolBuilders/build common debug [Builder].launch</value>
45
				</dictionary>
46
			</arguments>
47
		</buildCommand>
48
		<buildCommand>
49
			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
50
			<triggers>auto,full,incremental,</triggers>
51
			<arguments>
52
				<dictionary>
53
					<key>LaunchConfigHandle</key>
54
					<value>&lt;project&gt;/.externalToolBuilders/build remote support [Builder].launch</value>
55
				</dictionary>
56
			</arguments>
57
		</buildCommand>
28
	</buildSpec>
58
	</buildSpec>
29
	<natures>
59
	<natures>
30
		<nature>org.eclipse.pde.PluginNature</nature>
60
		<nature>org.eclipse.pde.PluginNature</nature>
(-)build.properties (-2 / +29 lines)
Lines 1-4 Link Here
1
source.. = src/
1
###############################################################################
2
# Copyright (c) 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
# 
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
source.. = src/                           
2
output.. = bin/
12
output.. = bin/
3
bin.includes = META-INF/,\
13
bin.includes = META-INF/,\
4
               .
14
               .,\
15
               plugin.xml,\
16
               plugin.properties,\
17
               lib/antdebug.jar,\
18
               lib/loggers.jar,\
19
               lib/remote.jar
20
21
jars.compile.order = .,\
22
                     lib/loggers.jar,\
23
                     lib/antdebug.jar,\
24
                     lib/remote.jar
25
source.lib/loggers.jar = loggers/
26
output.lib/loggers.jar = loggers_bin/
27
source.lib/antdebug.jar = common/
28
output.lib/antdebug.jar = common_bin/
29
source.lib/remote.jar = remote/
30
output.lib/remote.jar = remote_bin
31
src.includes = about.html
(-).settings/org.eclipse.jdt.core.prefs (-2 / +2 lines)
Lines 1-6 Link Here
1
#Wed Sep 16 09:44:05 CDT 2009
1
#Sun Sep 20 13:08:07 CEST 2009
2
eclipse.preferences.version=1
2
eclipse.preferences.version=1
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6
org.eclipse.jdt.core.compiler.compliance=1.4
6
org.eclipse.jdt.core.compiler.compliance=1.4
(-)META-INF/MANIFEST.MF (-4 / +16 lines)
Lines 1-16 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.ant.launching
4
Bundle-SymbolicName: org.eclipse.ant.launching;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-Activator: org.eclipse.ant.internal.launching.AntLaunching
6
Bundle-Activator: org.eclipse.ant.internal.launching.AntLaunching
7
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
7
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
8
 org.eclipse.debug.core;bundle-version="[3.6.0,4.0.0)",
8
 org.eclipse.debug.core;bundle-version="[3.5.0,4.0.0)",
9
 org.eclipse.jdt.launching;bundle-version="[3.5.0,4.0.0)",
9
 org.eclipse.jdt.launching;bundle-version="[3.5.0,4.0.0)",
10
 org.eclipse.core.variables;bundle-version="[3.2.0,4.0.0)",
10
 org.eclipse.core.variables;bundle-version="[3.2.0,4.0.0)",
11
 org.eclipse.ant.core;bundle-version="[3.2.0,4.0.0)",
11
 org.eclipse.ant.core;bundle-version="[3.2.0,4.0.0)",
12
 org.apache.ant;bundle-version="1.7.1"
12
 org.apache.ant;bundle-version="1.7.1",
13
 org.eclipse.jdt.core;bundle-version="3.5.0",
14
 org.eclipse.core.commands;bundle-version="3.5.0",
15
 org.eclipse.core.externaltools;bundle-version="1.0.0"
13
Bundle-RequiredExecutionEnvironment: J2SE-1.4
16
Bundle-RequiredExecutionEnvironment: J2SE-1.4
14
Bundle-ActivationPolicy: lazy
17
Bundle-ActivationPolicy: lazy
15
Bundle-Vendor: %providerName
18
Bundle-Vendor: %providerName
16
Export-Package: org.eclipse.ant.internal.launching;x-internal:=true
19
Export-Package: org.eclipse.ant.internal.launching;x-friends:="org.eclipse.ant.ui,org.eclipse.ant.core",
20
 org.eclipse.ant.internal.launching.debug;x-friends:="org.eclipse.ant.ui",
21
 org.eclipse.ant.internal.launching.debug.model;x-friends:="org.eclipse.ant.ui",
22
 org.eclipse.ant.internal.launching.launchConfigurations;x-friends:="org.eclipse.ant.ui",
23
 org.eclipse.ant.launching
24
Import-Package: com.ibm.icu.text,
25
 org.eclipse.ant.internal.launching.launchConfigurations,
26
 org.eclipse.core.filebuffers,
27
 org.eclipse.jface.preference,
28
 org.eclipse.jface.text
(-)buildfiles/buildCommonDebug.xml (+39 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
     Copyright (c) 2005, 2009 IBM Corporation and others.
4
     All rights reserved. This program and the accompanying materials
5
     are made available under the terms of the Eclipse Public License v1.0
6
     which accompanies this distribution, and is available at
7
     http://www.eclipse.org/legal/epl-v10.html
8
    
9
     Contributors:
10
         IBM Corporation - initial API and implementation
11
 -->
12
13
<project name="Build Ant common debug support JAR" default="build" basedir="..">
14
	
15
	<target name="build" description="Cleans, builds and refreshes" depends="clean, lib/antdebuglib.jar"/>
16
17
	<target name="init">
18
		<property name="temp.folder" value="${basedir}/temp.folder"/>
19
		<property name="build.result.folder" value="${basedir}"/>
20
	</target>
21
	
22
	<target name="lib/antdebuglib.jar" description= "Creates the antdebug.jar" depends="init">
23
		<property name="destdir" value="${temp.folder}/lib/antdebug.jar.bin"/>
24
		<delete dir="${destdir}"/>
25
		<mkdir dir="${destdir}"/>
26
		<!-- copy necessary class files resources -->
27
		<copy todir="${destdir}">
28
			<fileset dir="${basedir}/common_bin"/>
29
		</copy>
30
		<mkdir dir="${build.result.folder}/lib"/>
31
		<jar destfile="${build.result.folder}/lib/antdebug.jar" basedir="${destdir}"/>
32
		<delete dir="${temp.folder}"/>
33
	</target>
34
35
	<target name="clean" description="Deletes previous build remnants" depends="init">
36
		<delete file="${build.result.folder}/lib/antdebug.jar"/>
37
		<delete dir="${temp.folder}"/>
38
	</target>
39
</project>
(-)buildfiles/buildLoggers.xml (+39 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
     Copyright (c) 2005, 2009 IBM Corporation and others.
4
     All rights reserved. This program and the accompanying materials
5
     are made available under the terms of the Eclipse Public License v1.0
6
     which accompanies this distribution, and is available at
7
     http://www.eclipse.org/legal/epl-v10.html
8
    
9
     Contributors:
10
         IBM Corporation - initial API and implementation
11
 -->
12
13
<project name="Build Ant loggers support JAR" default="build" basedir="..">
14
	
15
	<target name="build" description="Cleans, builds and refreshes" depends="clean, lib/loggerslib.jar"/>
16
17
	<target name="init">
18
		<property name="temp.folder" value="${basedir}/temp.folder"/>
19
		<property name="build.result.folder" value="${basedir}"/>
20
	</target>
21
22
	<target name="lib/loggerslib.jar" description= "Creates the loggers.jar" depends="init">
23
		<property name="destdir" value="${temp.folder}/lib/loggers.jar.bin"/>
24
		<delete dir="${destdir}"/>
25
		<mkdir dir="${destdir}"/>
26
		<!-- copy necessary class files resources -->
27
		<copy todir="${destdir}">
28
			<fileset dir="${basedir}/loggers_bin/"/>
29
		</copy>
30
		<mkdir dir="${build.result.folder}/lib"/>
31
		<jar destfile="${build.result.folder}/lib/loggers.jar" basedir="${destdir}"/>
32
		<delete dir="${temp.folder}"/>
33
	</target>
34
35
	<target name="clean" description="Deletes previous build remnants" depends="init">
36
		<delete file="${build.result.folder}/lib/loggers.jar"/>
37
		<delete dir="${temp.folder}"/>
38
	</target>
39
</project>
(-)buildfiles/buildRemote.xml (+39 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
     Copyright (c) 2005, 2009 IBM Corporation and others.
4
     All rights reserved. This program and the accompanying materials
5
     are made available under the terms of the Eclipse Public License v1.0
6
     which accompanies this distribution, and is available at
7
     http://www.eclipse.org/legal/epl-v10.html
8
    
9
     Contributors:
10
         IBM Corporation - initial API and implementation
11
 -->
12
13
<project name="Build Ant remote support JAR" default="build" basedir="..">
14
	
15
	<target name="build" description="Cleans, builds and refreshes" depends="clean, lib/remotelib.jar"/>
16
17
	<target name="init">
18
		<property name="temp.folder" value="${basedir}/temp.folder"/>
19
		<property name="build.result.folder" value="${basedir}"/>
20
	</target>
21
	
22
	<target name="lib/remotelib.jar" description= "Creates the remote.jar" depends="init">
23
		<property name="destdir" value="${temp.folder}/lib/remote.jar.bin"/>
24
		<delete dir="${destdir}"/>
25
		<mkdir dir="${destdir}"/>
26
		<!-- copy necessary class files resources -->
27
		<copy todir="${destdir}">
28
			<fileset dir="${basedir}/remote_bin"/>
29
		</copy>
30
		<mkdir dir="${build.result.folder}/lib"/>
31
		<jar destfile="${build.result.folder}/lib/remote.jar" basedir="${destdir}"/>
32
		<delete dir="${temp.folder}"/>
33
	</target>
34
35
	<target name="clean" description="Deletes previous build remnants" depends="init">
36
		<delete file="${build.result.folder}/lib/remote.jar"/>
37
		<delete dir="${temp.folder}"/>
38
	</target>
39
</project>
(-)common/META-INF/eclipse.inf (+1 lines)
Added Link Here
1
jarprocessor.exclude.sign=true
(-)common/org/eclipse/ant/internal/launching/debug/AntDebugState.java (+529 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.launching.debug;
13
14
import java.util.HashMap;
15
import java.util.Hashtable;
16
import java.util.Iterator;
17
import java.util.Map;
18
import java.util.Stack;
19
import java.util.Vector;
20
21
import org.apache.tools.ant.BuildEvent;
22
import org.apache.tools.ant.Location;
23
import org.apache.tools.ant.Project;
24
import org.apache.tools.ant.Target;
25
import org.apache.tools.ant.Task;
26
import org.apache.tools.ant.taskdefs.MacroInstance;
27
28
public class AntDebugState {
29
    
30
    private static final String fgAntTaskName= "ant"; //$NON-NLS-1$
31
    private static final String fgAntCallTaskName= "antcall"; //$NON-NLS-1$
32
    
33
	private IDebugBuildLogger fLogger;
34
	private Stack fTasks= new Stack();
35
	private Map fTaskToProxies= new HashMap();
36
	private Task fCurrentTask;
37
	private Task fStepOverTask;
38
	private Task fStepIntoTask;
39
	private Task fLastTaskFinished;
40
    
41
	//properties set before execution
42
    private Map fInitialProperties= null;
43
	private Map fProperties= null;
44
    
45
    private Map fProjectToTargetNames= null;
46
    private Map fProjectToMapOfTargetToBuildSequence= null;
47
    private Stack fTargetsToExecute= new Stack();
48
    private Stack fTargetsExecuting= new Stack();
49
	
50
	private boolean fConsiderTargetBreakpoints= false;
51
	private boolean fShouldSuspend;
52
	private boolean fClientSuspend= false;
53
	private boolean fStepIntoSuspend= false;
54
	private boolean fIsAfterTaskEvent= false;
55
	
56
	
57
	public AntDebugState(IDebugBuildLogger logger) {
58
		fLogger= logger;
59
	}
60
61
	public void waitIfSuspended() {
62
		fLogger.waitIfSuspended();
63
	}
64
65
	public Task getLastTaskFinished() {
66
		return fLastTaskFinished;
67
	}
68
69
	private void setLastTaskFinished(Task lastTaskFinished) {
70
		fLastTaskFinished= lastTaskFinished;
71
72
	}
73
74
	public Task getCurrentTask() {
75
		return fCurrentTask;
76
	}
77
78
	public void setCurrentTask(Task currentTask) {
79
		fCurrentTask= currentTask;
80
81
	}
82
83
	private Map getInitialProperties() {
84
		return fInitialProperties;
85
	}
86
87
	public Task getStepOverTask() {
88
		return fStepOverTask;
89
	}
90
91
	public void setStepOverTask(Task stepOverTask) {
92
		fStepOverTask= stepOverTask;
93
94
	}
95
96
	private boolean considerTargetBreakpoints() {
97
		return fConsiderTargetBreakpoints;
98
	}
99
100
	private void setConsiderTargetBreakpoints(boolean considerTargetBreakpoints) {
101
		fConsiderTargetBreakpoints= considerTargetBreakpoints;
102
	}
103
104
	private Stack getTasks() {
105
		return fTasks;
106
	}
107
	
108
	public void setShouldSuspend(boolean shouldSuspend) {
109
		fShouldSuspend= shouldSuspend;
110
	}
111
112
	public boolean shouldSuspend() {
113
		return fShouldSuspend;
114
	}
115
116
	private Map getTargetToBuildSequence(Project project) {
117
		return (Map) fProjectToMapOfTargetToBuildSequence.get(project);
118
	}
119
120
	public void setTargetToExecute(Target target) {
121
        if (target == null) {
122
            fTargetsToExecute.pop();
123
        } else {
124
            fTargetsToExecute.push(target);
125
        }
126
	}
127
128
	public void setTargetExecuting(Target target) {
129
        if (target == null) {
130
            fTargetsExecuting.pop();
131
        } else {
132
            fTargetsExecuting.push(target);
133
        }
134
	}
135
136
	private Target getTargetToExecute() {
137
	    if (fTargetsToExecute.isEmpty()) {
138
            return null;
139
        }
140
		return (Target) fTargetsToExecute.peek();
141
	}
142
	
143
	private Target getTargetExecuting() {
144
        if (fTargetsExecuting.isEmpty()) {
145
            return null;
146
        }
147
		return (Target) fTargetsExecuting.peek();
148
	}
149
150
	public boolean isStepIntoSuspend() {
151
		return isAfterTaskEvent() && fStepIntoSuspend;
152
	}
153
154
	public void setStepIntoSuspend(boolean stepIntoSuspend) {
155
		fStepIntoSuspend = stepIntoSuspend;
156
	}
157
158
	public boolean isClientSuspend() {
159
		return fClientSuspend;
160
	}
161
162
	public void setClientSuspend(boolean clientSuspend) {
163
		fClientSuspend = clientSuspend;
164
	}
165
166
	public Task getStepIntoTask() {
167
		return fStepIntoTask;
168
	}
169
170
	public void setStepIntoTask(Task stepIntoTask) {
171
		fStepIntoTask = stepIntoTask;
172
	}
173
	
174
	public void resume() {
175
		fLogger.notifyAll();
176
	}
177
178
	public Map getProperties() {
179
		return fProperties;
180
	}
181
	
182
	public Location getBreakpointLocation() {
183
		if (isAfterTaskEvent() && getCurrentTask() != null) {
184
			return getCurrentTask().getLocation();
185
		}
186
		if (considerTargetBreakpoints()) {
187
	        Target targetExecuting= getTargetExecuting();
188
	        if (targetExecuting != null) {
189
                return getLocation(targetExecuting);      
190
            }
191
		}
192
		return null;
193
	}
194
195
	private boolean isAfterTaskEvent() {
196
		return fIsAfterTaskEvent;
197
	}
198
199
	private void setAfterTaskEvent(boolean isAfterTaskEvent) {
200
		fIsAfterTaskEvent = isAfterTaskEvent;
201
	}
202
	
203
	public void taskStarted(BuildEvent event) {
204
		setAfterTaskEvent(true);
205
		if (getInitialProperties() == null) {//implicit or top level target does not fire targetStarted()
206
			fInitialProperties= event.getProject().getProperties();
207
		}
208
		
209
		setCurrentTask(event.getTask());
210
		setConsiderTargetBreakpoints(false);
211
		if (!getTasks().isEmpty()) {
212
			//cache the parent task proxy as when that task is started or finished the
213
			//proxy is not yet available or is nulled out
214
			Task parentTask = (Task) getTasks().peek();
215
			Object proxy = parentTask.getRuntimeConfigurableWrapper().getProxy();
216
			if (proxy != null) {
217
				fTaskToProxies.put(parentTask, proxy);
218
			}
219
		}
220
		getTasks().push(getCurrentTask());
221
		waitIfSuspended();
222
	}
223
	
224
225
    public void taskFinished() {
226
    	Task lastTask= (Task)getTasks().pop();
227
        setLastTaskFinished(lastTask);
228
        setCurrentTask(null);
229
        String taskName= lastTask.getTaskName();
230
       
231
        if (getStepOverTask() != null) {
232
        	if ((fgAntCallTaskName.equals(taskName) || fgAntTaskName.equals(taskName)) && (!fgAntCallTaskName.equals(getStepOverTask().getTaskName()) && !fgAntTaskName.equals(getStepOverTask().getTaskName()))) {
233
        		setShouldSuspend(true);
234
        	} else if (fTaskToProxies.remove(lastTask) instanceof MacroInstance) {
235
        		setShouldSuspend(true);
236
        	}
237
        }
238
        waitIfSuspended();
239
    }
240
241
    public void stepOver() {
242
       setStepOverTask(getCurrentTask());
243
        if (getCurrentTask() == null) {
244
            //stepping over target breakpoint
245
           setShouldSuspend(true);
246
        }
247
        resume();
248
    }
249
250
    public void targetStarted(BuildEvent event) {
251
		setAfterTaskEvent(false);
252
        Project eventProject = event.getProject();
253
        if (getInitialProperties() == null) {
254
            fInitialProperties= eventProject.getProperties();
255
        }
256
        if (fProjectToTargetNames.get(eventProject) == null) {
257
            Object ref= eventProject.getReference("eclipse.ant.targetVector"); //$NON-NLS-1$
258
            if (ref != null) {
259
                fProjectToTargetNames.put(eventProject, ref);
260
                Map targetToBuildSequence= new HashMap();
261
                setTargetToExecute(initializeBuildSequenceInformation(event, targetToBuildSequence));
262
                fProjectToMapOfTargetToBuildSequence.put(eventProject, targetToBuildSequence);
263
            }
264
        }
265
        
266
        setTargetExecuting(event.getTarget());
267
        if (event.getTarget().equals(getTargetToExecute())) {
268
            //the dependencies of the target to execute have been met
269
            //prepare for the next target
270
            Vector targets= (Vector) fProjectToTargetNames.get(eventProject);
271
            if (!targets.isEmpty()) {
272
                setTargetToExecute((Target) eventProject.getTargets().get(targets.remove(0)));
273
            } else {
274
                setTargetToExecute(null);
275
            }
276
        }
277
        setConsiderTargetBreakpoints(true);
278
    }
279
280
	public int getLineNumber(Location location) {
281
	    try { //succeeds with Ant newer than 1.6
282
	        return location.getLineNumber();
283
	    } catch (NoSuchMethodError e) {
284
	        //Ant before 1.6
285
	        String locationString= location.toString();
286
	        if (locationString.length() == 0) {
287
	            return 0;
288
	        }
289
	        //filename: lineNumber: ("c:\buildfile.xml: 12: ")
290
	        int lastIndex= locationString.lastIndexOf(':');
291
	        int index =locationString.lastIndexOf(':', lastIndex - 1);
292
	        if (index != -1) {
293
	            try {
294
	                return Integer.parseInt(locationString.substring(index+1, lastIndex));
295
	            } catch (NumberFormatException nfe) {
296
	                return 0;
297
	            }
298
	        }
299
	        return 0;
300
	    }
301
	}
302
303
	public static Location getLocation(Target target) {
304
	    try {//succeeds with Ant newer than 1.6.2
305
	        return target.getLocation();
306
	    } catch (NoSuchMethodError e) {
307
	        return Location.UNKNOWN_LOCATION;
308
	    }
309
	}
310
311
	public String getFileName(Location location) {
312
	    try {//succeeds with Ant newer than 1.6
313
	        return location.getFileName();
314
	    } catch (NoSuchMethodError e) {
315
	        //Ant before 1.6
316
	        String locationString= location.toString();
317
	        if (locationString.length() == 0) {
318
	            return null;
319
	        }
320
	        //filename: lineNumber: ("c:\buildfile.xml: 12: ")          
321
	        int lastIndex= locationString.lastIndexOf(':');
322
	        int index =locationString.lastIndexOf(':', lastIndex-1);
323
	        if (index == -1) {
324
	            index= lastIndex; //only the filename is known
325
	        }
326
	        if (index != -1) {
327
	        //bug 84403
328
	            //if (locationString.startsWith("file:")) {
329
	              //  return FileUtils.newFileUtils().fromURI(locationString);
330
	            //}
331
	            //remove file:
332
	            return locationString.substring(5, index);
333
	        }
334
	        return null;
335
	    }
336
	}
337
338
	private void appendToStack(StringBuffer stackRepresentation, String targetName, String taskName, Location location) {
339
	    stackRepresentation.append(targetName);
340
	    stackRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
341
	    stackRepresentation.append(taskName);
342
	    stackRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
343
	    
344
	    stackRepresentation.append(getFileName(location));
345
	    stackRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
346
	    stackRepresentation.append(getLineNumber(location));
347
	    stackRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
348
	}
349
350
	public void marshalStack(StringBuffer stackRepresentation) {
351
		Stack tasks= getTasks();
352
		
353
	    stackRepresentation.append(DebugMessageIds.STACK);
354
	    stackRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
355
	    
356
		Target targetToExecute= getTargetToExecute();
357
		Target targetExecuting= getTargetExecuting();
358
      
359
        Project projectExecuting= null;
360
        if (targetExecuting != null) {
361
            projectExecuting= targetExecuting.getProject();
362
        } else { //no target...must be a task
363
            Task task= (Task) tasks.peek();
364
            projectExecuting= task.getProject();
365
        }
366
        
367
		if (!isAfterTaskEvent()) {
368
			appendToStack(stackRepresentation, targetExecuting.getName(), "", getLocation(targetExecuting)); //$NON-NLS-1$
369
		}
370
		for (int i = tasks.size() - 1; i >= 0 ; i--) {
371
			Task task= (Task) tasks.get(i);
372
            if (task.getProject() == projectExecuting) {
373
                appendToStack(stackRepresentation, task.getOwningTarget().getName(), task.getTaskName(), task.getLocation());
374
            } else {
375
                //sub build target dependencies
376
                String targetName= task.getOwningTarget().getName();
377
                if (targetName != null && targetName.length() != 0) { //skip for implicit target
378
                    Iterator itr= fTargetsToExecute.iterator();
379
                    while (itr.hasNext()) {
380
                        Target target= (Target) itr.next();
381
                        if (target.getProject() != projectExecuting) {
382
                        	targetToExecute= target;
383
                            continue;
384
                        }
385
                        marshalTargetDependancyStack(stackRepresentation, target, targetExecuting);
386
                    }
387
                }
388
                projectExecuting= task.getProject();
389
                targetExecuting= task.getOwningTarget();
390
                appendToStack(stackRepresentation, targetExecuting.getName(), task.getTaskName(), task.getLocation());
391
            }
392
		}
393
394
		//target dependency stack 
395
		marshalTargetDependancyStack(stackRepresentation, targetToExecute, targetExecuting);
396
	}
397
398
    private void marshalTargetDependancyStack(StringBuffer stackRepresentation, Target targetToExecute, Target targetExecuting) {
399
        if (targetToExecute != null) {
400
	     	Vector buildSequence= (Vector) getTargetToBuildSequence(targetToExecute.getProject()).get(targetToExecute);
401
	     	int startIndex= buildSequence.indexOf(targetExecuting) + 1;
402
	     	int dependancyStackDepth= buildSequence.indexOf(targetToExecute);
403
	     	
404
	     	Target stackTarget;
405
	     	for (int i = startIndex; i <= dependancyStackDepth; i++) {
406
	     		stackTarget= (Target) buildSequence.get(i);
407
	            if (stackTarget.dependsOn(targetExecuting.getName())) {
408
	     		    appendToStack(stackRepresentation, stackTarget.getName(), "", getLocation(stackTarget)); //$NON-NLS-1$
409
	            }
410
	     	}
411
	     }
412
    }
413
414
	public void marshallProperties(StringBuffer propertiesRepresentation, boolean escapeLineSep) {
415
		if (getTasks().isEmpty()) {
416
			return;
417
		}
418
	    propertiesRepresentation.append(DebugMessageIds.PROPERTIES);
419
	    propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
420
		
421
		Project project= ((Task)getTasks().peek()).getProject();
422
		Map lastProperties= getProperties(); 
423
		
424
	    Map currentProperties= project.getProperties();
425
	    if (lastProperties != null && currentProperties.size() == lastProperties.size()) {
426
	        //no new properties
427
	        return;
428
	    }
429
	    
430
		Map initialProperties= getInitialProperties();
431
	    Map currentUserProperties= project.getUserProperties();
432
	    Iterator iter= currentProperties.keySet().iterator();
433
	    String propertyName;
434
		String originalPropertyName;
435
	    String propertyValue;
436
	    while (iter.hasNext()) {
437
	        propertyName = (String) iter.next();
438
			originalPropertyName= propertyName;
439
	        if (lastProperties == null || lastProperties.get(propertyName) == null) { //new property
440
				if (escapeLineSep) {
441
					propertyName= escapeLineSeparator(propertyName);
442
				}
443
	            propertiesRepresentation.append(propertyName.length());
444
	            propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
445
	            propertiesRepresentation.append(propertyName);
446
	            propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
447
	            propertyValue= (String) currentProperties.get(originalPropertyName);
448
				if (escapeLineSep) {
449
					propertyValue= escapeLineSeparator(propertyValue);
450
				}
451
	            propertiesRepresentation.append(propertyValue.length());
452
	            propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
453
				propertiesRepresentation.append(propertyValue);
454
	            propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
455
	            propertiesRepresentation.append(getPropertyType(initialProperties, currentUserProperties, originalPropertyName));
456
	            propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
457
	        }
458
	    }
459
	    
460
	    propertiesRepresentation.deleteCharAt(propertiesRepresentation.length() - 1);
461
		fProperties= currentProperties;
462
	}
463
464
	private int getPropertyType(Map initialProperties, Map currentUserProperties, String propertyName) {
465
		if (initialProperties.get(propertyName) != null) { //properties set before the start of the build
466
		    if (currentUserProperties.get(propertyName) == null) {
467
		        return DebugMessageIds.PROPERTY_SYSTEM;
468
		    } 
469
			return DebugMessageIds.PROPERTY_USER;
470
		} else if (currentUserProperties.get(propertyName) == null){
471
		    return DebugMessageIds.PROPERTY_RUNTIME;
472
		} else {
473
		    return DebugMessageIds.PROPERTY_USER;
474
		}
475
	}
476
477
	private String escapeLineSeparator(String stringToEscape) {
478
		if (!(stringToEscape.indexOf('\r') != -1 || stringToEscape.indexOf('\n') != -1 || stringToEscape.indexOf("\\r") != -1 || stringToEscape.indexOf("\\n") != -1)) { //$NON-NLS-1$ //$NON-NLS-2$
479
			return stringToEscape;
480
		}
481
		StringBuffer escapedValue= new StringBuffer(stringToEscape);		
482
		for (int i= 0; i < escapedValue.length(); i++) {
483
			switch (escapedValue.charAt(i)) {
484
			case '\r':
485
				escapedValue.replace(i, i+1, "\\r"); //$NON-NLS-1$
486
				i++;
487
				break;
488
			case '\n':
489
				escapedValue.replace(i, i+1, "\\n"); //$NON-NLS-1$
490
				i++;
491
				break;
492
			case '\\':
493
				if (escapedValue.charAt(i + 1) == 'r' || escapedValue.charAt(i + 1) == 'n') {
494
					escapedValue.replace(i, i+1, "\\\\"); //$NON-NLS-1$
495
					i++;
496
				}
497
				break;
498
			default:
499
				break;
500
			}
501
		}
502
503
		return escapedValue.toString();
504
	}
505
506
	private Target initializeBuildSequenceInformation(BuildEvent event, Map targetToBuildSequence) {
507
	    Project antProject= event.getProject();
508
	    Vector targets= (Vector) antProject.getReference("eclipse.ant.targetVector"); //$NON-NLS-1$
509
        if (targets == null) {
510
            return null;
511
        }
512
	    Iterator itr= targets.iterator();
513
	    Hashtable allTargets= antProject.getTargets();
514
	    String targetName;
515
	    Vector sortedTargets;
516
	    while (itr.hasNext()) {
517
	        targetName= (String) itr.next();
518
	        sortedTargets= antProject.topoSort(targetName, allTargets);
519
	        targetToBuildSequence.put(allTargets.get(targetName), sortedTargets);
520
	    }
521
	    //the target to execute
522
	    return (Target) allTargets.get(targets.remove(0));
523
	}
524
    
525
    public void buildStarted() {
526
        fProjectToTargetNames= new HashMap();
527
        fProjectToMapOfTargetToBuildSequence= new HashMap();
528
    }
529
}
(-)common/org/eclipse/ant/internal/launching/debug/DebugMessageIds.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug;
12
13
14
public class DebugMessageIds {
15
	
16
	public final static String MESSAGE_DELIMITER= ","; //$NON-NLS-1$
17
	
18
	public final static String BUILD_STARTED=   "build_started"; //$NON-NLS-1$
19
	public final static String TARGET_STARTED= "target_started"; //$NON-NLS-1$
20
	public final static String TARGET_FINISHED= "target_finished"; //$NON-NLS-1$
21
	public final static String TASK_STARTED= "task_started"; //$NON-NLS-1$
22
	public final static String TASK_FINISHED= "task_finished"; //$NON-NLS-1$
23
	
24
	public final static String STEP= "step"; //$NON-NLS-1$
25
	public final static String STEP_OVER= "step_over"; //$NON-NLS-1$
26
	public final static String STEP_INTO= "step_into"; //$NON-NLS-1$
27
	
28
	public final static String TERMINATE= "terminate"; //$NON-NLS-1$
29
	public final static String TERMINATED= "terminated"; //$NON-NLS-1$
30
	public final static String SUSPEND= "suspend"; //$NON-NLS-1$
31
	public final static String SUSPENDED= "suspended"; //$NON-NLS-1$
32
	public final static String RESUME= "resume"; //$NON-NLS-1$
33
	
34
	public final static String STACK= "stack"; //$NON-NLS-1$
35
	
36
	public final static String ADD_BREAKPOINT= "add"; //$NON-NLS-1$
37
	public final static String REMOVE_BREAKPOINT= "remove"; //$NON-NLS-1$
38
	
39
	public final static String CLIENT_REQUEST= "client"; //$NON-NLS-1$
40
	public final static String BREAKPOINT= "breakpoint"; //$NON-NLS-1$
41
	
42
	public final static String PROPERTIES= "prop"; //$NON-NLS-1$
43
	public final static String PROPERTY_VALUE= "value"; //$NON-NLS-1$
44
	public final static int PROPERTY_USER= 0;
45
	public final static int PROPERTY_SYSTEM= 1;
46
	public final static int PROPERTY_RUNTIME= 2;
47
}
(-)common/org/eclipse/ant/internal/launching/debug/IDebugBuildLogger.java (+21 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug;
12
13
14
public interface IDebugBuildLogger {
15
16
	/**
17
	 * Requests to suspend the build if the current debug state
18
	 * indicates that suspension is required.
19
	 */
20
    public abstract void waitIfSuspended();
21
}
(-)loggers/META-INF/eclipse.inf (+1 lines)
Added Link Here
1
jarprocessor.exclude.sign=true
(-)loggers/org/eclipse/ant/internal/launching/runtime/logger/AntProcessBuildLogger.java (+306 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Matt Conway - Patch for Bug 28052
11
 *******************************************************************************/
12
13
package org.eclipse.ant.internal.launching.runtime.logger;
14
15
import java.io.BufferedReader;
16
import java.io.IOException;
17
import java.io.StringReader;
18
19
import org.apache.tools.ant.BuildEvent;
20
import org.apache.tools.ant.Location;
21
import org.apache.tools.ant.Project;
22
import org.apache.tools.ant.Target;
23
import org.eclipse.ant.internal.core.AbstractEclipseBuildLogger;
24
import org.eclipse.ant.internal.launching.AntLaunch;
25
import org.eclipse.ant.internal.launching.AntLaunching;
26
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
27
import org.eclipse.ant.internal.launching.debug.AntDebugState;
28
import org.eclipse.ant.internal.launching.launchConfigurations.AntProcess;
29
import org.eclipse.ant.internal.launching.launchConfigurations.AntStreamMonitor;
30
import org.eclipse.ant.internal.launching.launchConfigurations.AntStreamsProxy;
31
import org.eclipse.core.runtime.OperationCanceledException;
32
import org.eclipse.debug.core.DebugPlugin;
33
import org.eclipse.debug.core.model.IProcess;
34
import org.eclipse.jface.text.IRegion;
35
import org.eclipse.jface.text.Region;
36
37
public class AntProcessBuildLogger extends NullBuildLogger {
38
39
	private long fStartTime;
40
41
	/**
42
	 * Associated process - discovered as needed to log messages
43
	 */
44
	private AntProcess fProcess = null;
45
	
46
	protected void logMessage(String message, BuildEvent event, int overridePriority) {
47
		int priority= overridePriority;
48
		if (priority == -1) {
49
			priority= event.getPriority();
50
		} 
51
		
52
		if (priority > getMessageOutputLevel()) {
53
			return;
54
		}
55
		AntProcess antProcess = getAntProcess(fProcessId);
56
		if (antProcess == null) {
57
			return;
58
		}
59
		
60
		StringBuffer fullMessage= new StringBuffer();
61
		 if (!loggingToLogFile()) {
62
			fullMessage.append(System.getProperty("line.separator")); //$NON-NLS-1$
63
		}
64
		if (event.getException() == null && event.getTask() != null && !fEmacsMode) {
65
			adornMessage(event, fullMessage);
66
		} else {
67
			fullMessage.append(message);
68
		}
69
		message= fullMessage.toString();
70
		
71
		if (loggingToLogFile()) {
72
			logMessageToLogFile(message, priority);
73
		} else {
74
			AntStreamMonitor monitor = getMonitor(priority);
75
			monitor.append(message);
76
		}
77
	}
78
79
	/**
80
	 * Builds a right justified task prefix for the given build event, placing it
81
	 * in the given string buffer. Creates the hyperlinks for the task prefix. 
82
	 *  
83
	 * @param event build event
84
	 * @param fullMessage buffer to place task prefix in
85
	 */
86
	private void adornMessage(BuildEvent event, StringBuffer fullMessage) {
87
		String name = event.getTask().getTaskName();
88
		if (name == null) {
89
			name = "null"; //$NON-NLS-1$
90
		}
91
		Location location = event.getTask().getLocation();
92
		StringBuffer column= new StringBuffer();
93
		int size = AntLaunching.LEFT_COLUMN_SIZE - (name.length() + 3);
94
		for (int i = 0; i < size; i++) {
95
			column.append(' ');
96
		}
97
		StringBuffer labelBuff= new StringBuffer();
98
		labelBuff.append('[');
99
		labelBuff.append(name);
100
		labelBuff.append("] "); //$NON-NLS-1$
101
		
102
		int offset = Math.max(size, 0) + 1;
103
		String label= labelBuff.toString();
104
		if (event.getMessage() == null) {
105
			return;
106
		}
107
		try {
108
			BufferedReader r = new BufferedReader(new StringReader(event.getMessage()));
109
			String line = r.readLine();
110
			fullMessage.append(column);
111
			appendAndLink(fullMessage, location, label, offset, line);
112
			line = r.readLine();
113
			while (line != null) {
114
				fullMessage.append(System.getProperty("line.separator")); //$NON-NLS-1$
115
				fullMessage.append(column);
116
				appendAndLink(fullMessage, location, label, offset, line);
117
				line = r.readLine();
118
			}
119
		} catch (IOException e) {
120
			if (event.getMessage() != null) {
121
				fullMessage.append(label).append(event.getMessage());
122
			}
123
		}
124
	}
125
	
126
	private void appendAndLink(StringBuffer fullMessage, Location location, String label, int offset, String line) {
127
		fullMessage.append(label);
128
		fullMessage.append(line);
129
		if (location != null) {
130
			String newLine= (label + line).trim();
131
			IRegion region= new Region(offset, label.length() - 3); // only
132
			// want
133
			// the
134
			// name
135
			// length
136
			// "[name] "
137
			AntProcess antProcess = getAntProcess(fProcessId);
138
			AntLaunch antLaunch = (AntLaunch)antProcess.getLaunch();
139
			antLaunch.addLinkDescriptor(newLine, location.getFileName(), location.getLineNumber(), region.getOffset(), region.getLength());
140
		}
141
	}
142
143
	private AntStreamMonitor getMonitor(int priority) {
144
		AntStreamsProxy proxy = (AntStreamsProxy)fProcess.getStreamsProxy();
145
		AntStreamMonitor monitor = null;
146
		switch (priority) {
147
			case Project.MSG_INFO:
148
				monitor = (AntStreamMonitor)proxy.getOutputStreamMonitor();
149
				break;
150
			case Project.MSG_ERR:
151
				monitor = (AntStreamMonitor)proxy.getErrorStreamMonitor();
152
				break;
153
			case Project.MSG_DEBUG:
154
				monitor = (AntStreamMonitor)proxy.getDebugStreamMonitor();
155
				break;
156
			case Project.MSG_WARN:
157
				monitor = (AntStreamMonitor)proxy.getWarningStreamMonitor();
158
				break;
159
			case Project.MSG_VERBOSE:
160
				monitor = (AntStreamMonitor)proxy.getVerboseStreamMonitor();
161
				break;
162
		}
163
		return monitor;
164
	}
165
166
	private void logMessageToLogFile(String message, int priority) {
167
		if (priority == Project.MSG_ERR) {
168
			getErrorPrintStream().println(message);
169
		} else {
170
			getOutputPrintStream().println(message);
171
		}
172
	}
173
	
174
	/**
175
	 * Returns the associated Ant process, finding it if necessary, if not
176
	 * already found.
177
	 */
178
	protected AntProcess getAntProcess(String processId) {
179
		if (fProcess == null && processId != null) {
180
			IProcess[] all = DebugPlugin.getDefault().getLaunchManager().getProcesses();
181
			for (int i = 0; i < all.length; i++) {
182
				IProcess process = all[i];
183
				if (process instanceof AntProcess && processId.equals(process.getAttribute(AbstractEclipseBuildLogger.ANT_PROCESS_ID))) {
184
					fProcess = (AntProcess)process;
185
					break;
186
				}
187
			}
188
		}
189
		return fProcess;
190
	}
191
192
	/* (non-Javadoc)
193
	 * Set the start time.
194
	 * 
195
	 * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
196
	 */
197
	public void buildStarted(BuildEvent event) {
198
		fStartTime= System.currentTimeMillis();
199
	}
200
	
201
	/* (non-Javadoc)
202
	 * @see org.apache.tools.ant.BuildListener#buildFinished(org.apache.tools.ant.BuildEvent)
203
	 */
204
	public void buildFinished(BuildEvent event) {
205
        String message= handleException(event);
206
        if (message != null) {
207
        	try {
208
    			BufferedReader r = new BufferedReader(new StringReader(message));
209
    			String line = r.readLine();
210
    			logMessage(line, event, Project.MSG_ERR);
211
    			line = r.readLine();
212
    			AntProcess antProcess = getAntProcess(fProcessId);
213
    			while (line != null) {
214
    				logMessage(line, event, Project.MSG_ERR);
215
    				if (!message.startsWith("Total time:")) { //$NON-NLS-1$
216
						AntLaunchingUtil.linkBuildFailedMessage(line, antProcess);
217
    				}
218
    				line = r.readLine();
219
    			}
220
    			logMessage("", event, Project.MSG_ERR); //$NON-NLS-1$
221
    		} catch (IOException e) {
222
    		}
223
        }
224
		fHandledException= null;
225
		if (!(event.getException() instanceof OperationCanceledException)) {
226
			logMessage(getTimeString(System.currentTimeMillis() - fStartTime), event, fMessageOutputLevel);
227
		}
228
		fProcess= null;
229
		event.getProject().removeBuildListener(this);
230
	}
231
	
232
	private String getTimeString(long milliseconds) {
233
			long seconds = milliseconds / 1000;
234
			long minutes = seconds / 60;
235
			seconds= seconds % 60;
236
		
237
			StringBuffer result= new StringBuffer(RuntimeMessages.AntProcessBuildLogger_Total_time);
238
			if (minutes > 0) {
239
				result.append(minutes);
240
				if (minutes > 1) {
241
					result.append(RuntimeMessages.AntProcessBuildLogger__minutes_2);
242
				} else {
243
					result.append(RuntimeMessages.AntProcessBuildLogger__minute_3);
244
				}
245
			}
246
			if (seconds > 0) {
247
				if (minutes > 0) {
248
					result.append(' ');
249
				}
250
				result.append(seconds);
251
			
252
				if (seconds > 1) {
253
					result.append(RuntimeMessages.AntProcessBuildLogger__seconds_4);
254
				} else {
255
					result.append(RuntimeMessages.AntProcessBuildLogger__second_5);
256
				} 
257
			}
258
			if (seconds == 0 && minutes == 0) {
259
				result.append(milliseconds);
260
				result.append(RuntimeMessages.AntProcessBuildLogger__milliseconds_6);
261
			}
262
			
263
			result.append(System.getProperty("line.separator")); //$NON-NLS-1$
264
			return result.toString();
265
		}
266
	
267
	/* (non-Javadoc)
268
	 * @see org.apache.tools.ant.BuildListener#messageLogged(org.apache.tools.ant.BuildEvent)
269
	 */
270
	public void messageLogged(BuildEvent event) {
271
		if (event.getPriority() > getMessageOutputLevel()) {
272
			return;
273
		}
274
		if (event.getMessage() != null && event.getMessage().length() > 0) {
275
			logMessage(event.getMessage(), event, -1);
276
		}
277
	}
278
279
	/* (non-Javadoc)
280
	 * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
281
	 */
282
	public void targetStarted(BuildEvent event) {
283
		if (Project.MSG_INFO > getMessageOutputLevel()) {
284
			return;
285
		}
286
		Target target= event.getTarget();
287
		StringBuffer msg= new StringBuffer(System.getProperty("line.separator")); //$NON-NLS-1$
288
		String targetName= target.getName();
289
		msg.append(targetName);
290
		msg.append(':');
291
		String message= msg.toString();
292
		Location location= AntDebugState.getLocation(target);
293
		if (location != null && location != Location.UNKNOWN_LOCATION) {
294
			IRegion region = new Region(0, targetName.length());
295
			AntProcess antProcess = getAntProcess(fProcessId);
296
			AntLaunch antLaunch = (AntLaunch)antProcess.getLaunch();
297
			antLaunch.addLinkDescriptor(message, location.getFileName(), location.getLineNumber(), region.getOffset(), region.getLength());
298
		}
299
		logMessage(message, event, Project.MSG_INFO);
300
	}
301
	
302
	private boolean loggingToLogFile() {
303
		//check if user has designated to log to a log file
304
		return getErrorPrintStream() != null && getErrorPrintStream() != System.err;
305
	}
306
}
(-)loggers/org/eclipse/ant/internal/launching/runtime/logger/AntProcessDebugBuildLogger.java (+246 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.runtime.logger;
12
13
import java.io.File;
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.apache.tools.ant.BuildEvent;
18
import org.apache.tools.ant.Location;
19
import org.eclipse.ant.internal.launching.debug.AntDebugState;
20
import org.eclipse.ant.internal.launching.debug.IAntDebugController;
21
import org.eclipse.ant.internal.launching.debug.IDebugBuildLogger;
22
import org.eclipse.ant.internal.launching.debug.model.AntDebugTarget;
23
import org.eclipse.ant.internal.launching.debug.model.AntThread;
24
import org.eclipse.ant.internal.launching.launchConfigurations.AntProcess;
25
import org.eclipse.core.resources.IFile;
26
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.OperationCanceledException;
28
import org.eclipse.debug.core.DebugEvent;
29
import org.eclipse.debug.core.ILaunch;
30
import org.eclipse.debug.core.model.IBreakpoint;
31
import org.eclipse.debug.core.model.ILineBreakpoint;
32
import org.eclipse.debug.core.model.IProcess;
33
34
public class AntProcessDebugBuildLogger extends AntProcessBuildLogger implements IAntDebugController, IDebugBuildLogger {
35
	
36
	private AntDebugState fDebugState= null;
37
	
38
	private List fBreakpoints= null;
39
    
40
	private AntDebugTarget fAntDebugTarget;
41
	private boolean fResumed= false;
42
	
43
	/* (non-Javadoc)
44
	 * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
45
	 */
46
	public void buildStarted(BuildEvent event) {
47
		fDebugState= new AntDebugState(this);
48
		super.buildStarted(event);
49
		IProcess process= getAntProcess(fProcessId);
50
		ILaunch launch= process.getLaunch();
51
		fAntDebugTarget= new AntDebugTarget(launch, process, this);
52
		launch.addDebugTarget(fAntDebugTarget);
53
        
54
        fAntDebugTarget.buildStarted();
55
        fDebugState.buildStarted();
56
	}
57
58
	/* (non-Javadoc)
59
	 * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent)
60
	 */
61
	public void taskFinished(BuildEvent event) {
62
		super.taskFinished(event);
63
		fDebugState.taskFinished();
64
	}
65
	
66
	/* (non-Javadoc)
67
	 * @see org.apache.tools.ant.BuildListener#taskStarted(org.apache.tools.ant.BuildEvent)
68
	 */
69
	public void taskStarted(BuildEvent event) {
70
        super.taskStarted(event);
71
		fDebugState.taskStarted(event);
72
	}
73
	
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.ant.internal.ui.antsupport.logger.util.IDebugBuildLogger#waitIfSuspended()
76
	 */
77
	public synchronized void waitIfSuspended() {
78
		fResumed= false;
79
		IBreakpoint breakpoint= breakpointAtLineNumber(fDebugState.getBreakpointLocation());
80
		if (breakpoint != null) {
81
			 fAntDebugTarget.breakpointHit(breakpoint);
82
			 try {
83
				 while (!fResumed) {
84
					 wait(500);
85
					 checkCancelled();
86
				 }
87
			 } catch (InterruptedException e) {
88
			 }
89
		} else if (fDebugState.getCurrentTask() != null) {
90
			int detail= -1;
91
	        boolean shouldSuspend= true;
92
	        if (fDebugState.isStepIntoSuspend()) {
93
	            detail= DebugEvent.STEP_END;
94
	            fDebugState.setStepIntoSuspend(false);               
95
	        } else if ((fDebugState.getLastTaskFinished() != null && fDebugState.getLastTaskFinished() == fDebugState.getStepOverTask()) || fDebugState.shouldSuspend()) {
96
				detail= DebugEvent.STEP_END;
97
				fDebugState.setShouldSuspend(false);
98
				fDebugState.setStepOverTask(null);
99
	        } else if (fDebugState.isClientSuspend()) {
100
	            detail= DebugEvent.CLIENT_REQUEST;
101
	            fDebugState.setClientSuspend(false);
102
	        } else {
103
	            shouldSuspend= false;
104
	        }
105
	        if (shouldSuspend) {
106
                fAntDebugTarget.suspended(detail);
107
	            try {
108
	            	while (!fResumed) {
109
	            		wait(500);
110
	            		checkCancelled();
111
	            	}
112
	            } catch (InterruptedException e) {
113
	            }
114
	        }
115
	    }
116
	}
117
118
	private void checkCancelled() {
119
		AntProcess process= getAntProcess(fProcessId);
120
		if (process != null && process.isCanceled()) {
121
			throw new OperationCanceledException(RuntimeMessages.AntProcessDebugBuildLogger_1);
122
		}
123
	}
124
125
	/* (non-Javadoc)
126
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#resume()
127
	 */
128
	public synchronized void resume() {
129
		fResumed= true;
130
        notifyAll();
131
	}
132
133
	/* (non-Javadoc)
134
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#suspend()
135
	 */
136
	public synchronized void suspend() {
137
		fDebugState.setClientSuspend(true);
138
	}
139
140
	/* (non-Javadoc)
141
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#stepInto()
142
	 */
143
	public synchronized void stepInto() {
144
		fDebugState.setStepIntoSuspend(true);
145
		fResumed= true;
146
		notifyAll();
147
	}
148
149
	/* (non-Javadoc)
150
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#stepOver()
151
	 */
152
	public synchronized void stepOver() {
153
		fResumed= true;
154
		fDebugState.stepOver();
155
	}
156
157
	/* (non-Javadoc)
158
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#handleBreakpoint(org.eclipse.debug.core.model.IBreakpoint, boolean)
159
	 */
160
	public void handleBreakpoint(IBreakpoint breakpoint, boolean added) {
161
		if (added) {
162
			if (fBreakpoints == null) {
163
				fBreakpoints= new ArrayList();
164
			}
165
			if (!fBreakpoints.contains(breakpoint)) {
166
				fBreakpoints.add(breakpoint);
167
			}
168
		} else {
169
			if (fBreakpoints != null) {
170
				fBreakpoints.remove(breakpoint);
171
			}
172
		}
173
	}
174
175
	/* (non-Javadoc)
176
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#getProperties()
177
	 */
178
	public void getProperties() {
179
		if (!fAntDebugTarget.isSuspended()) {
180
			return;
181
		}
182
	    StringBuffer propertiesRepresentation= new StringBuffer();
183
		fDebugState.marshallProperties(propertiesRepresentation, false);
184
		if (fAntDebugTarget.getThreads().length > 0) {
185
			((AntThread) fAntDebugTarget.getThreads()[0]).newProperties(propertiesRepresentation.toString());
186
		}
187
	}
188
189
	/* (non-Javadoc)
190
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#getStackFrames()
191
	 */
192
	public void getStackFrames() {
193
		StringBuffer stackRepresentation= new StringBuffer();
194
		fDebugState.marshalStack(stackRepresentation);
195
		((AntThread) fAntDebugTarget.getThreads()[0]).buildStack(stackRepresentation.toString());
196
	}
197
    
198
    private IBreakpoint breakpointAtLineNumber(Location location) {
199
        if (fBreakpoints == null || location == null || location == Location.UNKNOWN_LOCATION) {
200
            return null;
201
        }
202
        int lineNumber= fDebugState.getLineNumber(location);
203
        File locationFile= new File(fDebugState.getFileName(location));
204
        for (int i = 0; i < fBreakpoints.size(); i++) {
205
            ILineBreakpoint breakpoint = (ILineBreakpoint) fBreakpoints.get(i);
206
            int breakpointLineNumber;
207
            try {
208
            	if (!breakpoint.isEnabled()) {
209
                	continue;
210
                }
211
            	breakpointLineNumber = breakpoint.getLineNumber();
212
            } catch (CoreException e) {
213
               return null;
214
            }
215
            IFile resource= (IFile) breakpoint.getMarker().getResource();
216
            if (breakpointLineNumber == lineNumber && resource.getLocation().toFile().equals(locationFile)) {
217
                return breakpoint;
218
            }
219
        }
220
        return null;
221
    }
222
    
223
    /* (non-Javadoc)
224
     * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
225
     */
226
    public void targetStarted(BuildEvent event) {
227
		fDebugState.targetStarted(event);
228
		waitIfSuspended();
229
		super.targetStarted(event);
230
    }
231
	
232
	/* (non-Javadoc)
233
	 * @see org.apache.tools.ant.BuildListener#targetFinished(org.apache.tools.ant.BuildEvent)
234
	 */
235
	public void targetFinished(BuildEvent event) {
236
		super.targetFinished(event);
237
		fDebugState.setTargetExecuting(null);
238
	}
239
240
	/* (non-Javadoc)
241
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#unescapeString(java.lang.StringBuffer)
242
	 */
243
	public StringBuffer unescapeString(StringBuffer propertyValue) {
244
		return propertyValue;
245
	}
246
}
(-)loggers/org/eclipse/ant/internal/launching/runtime/logger/NullBuildLogger.java (+179 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.runtime.logger;
12
13
14
import java.io.PrintStream;
15
16
import org.apache.tools.ant.BuildEvent;
17
import org.apache.tools.ant.BuildException;
18
import org.apache.tools.ant.BuildLogger;
19
import org.apache.tools.ant.Project;
20
import org.apache.tools.ant.util.StringUtils;
21
import org.eclipse.ant.core.AntSecurityException;
22
import org.eclipse.ant.internal.core.AbstractEclipseBuildLogger;
23
import org.eclipse.core.runtime.OperationCanceledException;
24
25
public class NullBuildLogger extends AbstractEclipseBuildLogger implements BuildLogger{
26
27
	protected int fMessageOutputLevel = Project.MSG_INFO;
28
	private PrintStream fErr= null;
29
	private PrintStream fOut= null;
30
	protected boolean fEmacsMode= false;
31
	
32
	/**
33
	 * An exception that has already been logged.
34
	 */
35
	protected Throwable fHandledException= null;
36
	
37
	/**
38
	 * @see org.apache.tools.ant.BuildLogger#setMessageOutputLevel(int)
39
	 */
40
	public void setMessageOutputLevel(int level) {
41
		fMessageOutputLevel= level;
42
	}
43
	
44
	protected int getMessageOutputLevel() {
45
		return fMessageOutputLevel;
46
	}
47
48
	/**
49
	 * @see org.apache.tools.ant.BuildLogger#setEmacsMode(boolean)
50
	 */
51
	public void setEmacsMode(boolean emacsMode) {
52
		fEmacsMode= emacsMode;
53
	}
54
55
	/**
56
	 * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
57
	 */
58
	public void buildStarted(BuildEvent event) {
59
	}
60
61
	/**
62
	 * @see org.apache.tools.ant.BuildListener#buildFinished(org.apache.tools.ant.BuildEvent)
63
	 */
64
	public void buildFinished(BuildEvent event) {
65
		String message= handleException(event);
66
        if (message != null) {
67
            logMessage(message, getMessageOutputLevel());
68
        }
69
		fHandledException= null;
70
	}
71
72
	/**
73
	 * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
74
	 */
75
	public void targetStarted(BuildEvent event) {
76
	}
77
78
	/**
79
	 * @see org.apache.tools.ant.BuildListener#targetFinished(org.apache.tools.ant.BuildEvent)
80
	 */
81
	public void targetFinished(BuildEvent event) {
82
	}
83
84
	/**
85
	 * @see org.apache.tools.ant.BuildListener#taskStarted(org.apache.tools.ant.BuildEvent)
86
	 */
87
	public void taskStarted(BuildEvent event) {
88
	}
89
90
	/**
91
	 * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent)
92
	 */
93
	public void taskFinished(BuildEvent event) {
94
	}
95
96
	/* (non-Javadoc)
97
	 * @see org.apache.tools.ant.BuildListener#messageLogged(org.apache.tools.ant.BuildEvent)
98
	 */
99
	public void messageLogged(BuildEvent event) {
100
		logMessage(event.getMessage(), event.getPriority());
101
	}
102
103
	protected PrintStream getErrorPrintStream() {
104
		return fErr;
105
	}
106
	
107
	protected PrintStream getOutputPrintStream() {
108
		return fOut;
109
	}
110
	
111
	/**
112
	 * @see org.apache.tools.ant.BuildLogger#setErrorPrintStream(java.io.PrintStream)
113
	 */
114
	public void setErrorPrintStream(PrintStream err) {
115
		//this build logger logs to "null" unless
116
		//the user has explicitly set a logfile to use
117
		if (err == System.err) {
118
			fErr= null;
119
		} else {
120
			fErr= err;
121
		}
122
	}
123
124
	/**
125
	 * @see org.apache.tools.ant.BuildLogger#setOutputPrintStream(java.io.PrintStream)
126
	 */
127
	public void setOutputPrintStream(PrintStream output) {
128
		//this build logger logs to "null" unless
129
		//the user has explicitly set a logfile to use
130
		if (output == System.out) {
131
			fOut= null;
132
		} else {
133
			fOut= output;
134
		}
135
	}
136
	
137
	protected void logMessage(String message, int priority) {
138
		if (priority > getMessageOutputLevel()) {
139
			return;
140
		}
141
		
142
		if (priority == Project.MSG_ERR) {
143
			if (getErrorPrintStream() != null && getErrorPrintStream() != System.err) {
144
				//user has designated to log to a logfile
145
				getErrorPrintStream().println(message);
146
			}
147
		} else {
148
			if (getOutputPrintStream() != null && getOutputPrintStream() != System.out) {
149
				//user has designated to log to a logfile
150
				getOutputPrintStream().println(message);
151
			} 
152
		}
153
	}
154
	
155
	protected String handleException(BuildEvent event) {
156
		Throwable exception = event.getException();
157
		if (exception == null || exception == fHandledException
158
		|| exception instanceof OperationCanceledException
159
		|| exception instanceof AntSecurityException) {
160
			return null;
161
		}
162
		fHandledException= exception;
163
        StringBuffer message= new StringBuffer();
164
        message.append(StringUtils.LINE_SEP);
165
        message.append(RuntimeMessages.NullBuildLogger_1);
166
        message.append(StringUtils.LINE_SEP);
167
        if (Project.MSG_VERBOSE <= fMessageOutputLevel || !(exception instanceof BuildException)) {
168
            message.append(StringUtils.getStackTrace(exception));
169
        } else {
170
            if (exception instanceof BuildException) {
171
                message.append(exception.toString()).append(StringUtils.LINE_SEP);
172
            } else {
173
                message.append(exception.getMessage()).append(StringUtils.LINE_SEP);
174
            }
175
        }
176
        
177
		return message.toString();	
178
	}
179
}
(-)loggers/org/eclipse/ant/internal/launching/runtime/logger/RuntimeMessages.java (+31 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.ant.internal.launching.runtime.logger;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class RuntimeMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.ant.internal.launching.runtime.logger.RuntimeMessages";//$NON-NLS-1$
16
17
	public static String NullBuildLogger_1;
18
	public static String AntProcessBuildLogger_Total_time;
19
	public static String AntProcessBuildLogger__minutes_2;
20
	public static String AntProcessBuildLogger__minute_3;
21
	public static String AntProcessBuildLogger__seconds_4;
22
	public static String AntProcessBuildLogger__second_5;
23
	public static String AntProcessBuildLogger__milliseconds_6;
24
	
25
	public static String AntProcessDebugBuildLogger_1;
26
27
	static {
28
		// load message values from bundle file
29
		NLS.initializeMessages(BUNDLE_NAME, RuntimeMessages.class);
30
	}
31
}
(-)loggers/org/eclipse/ant/internal/launching/runtime/logger/RuntimeMessages.properties (+20 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
NullBuildLogger_1=BUILD FAILED
13
AntProcessBuildLogger_Total_time=Total time: 
14
AntProcessBuildLogger__minutes_2=\ minutes
15
AntProcessBuildLogger__minute_3=\ minute
16
AntProcessBuildLogger__seconds_4=\ seconds
17
AntProcessBuildLogger__second_5=\ second
18
AntProcessBuildLogger__milliseconds_6=\ milliseconds
19
20
AntProcessDebugBuildLogger_1=Build cancelled.
(-)plugin.properties (-1 / +169 lines)
Lines 10-13 Link Here
10
###############################################################################
10
###############################################################################
11
11
12
pluginName=Ant Launching Support
12
pluginName=Ant Launching Support
13
providerName=Eclipse.org
13
providerName=Eclipse.org
14
15
AntBuild=Ant Build
16
AntBuilder.name=Ant Builder
17
AntLaunchShortcut.label=Ant Build
18
AntLaunchShortcutWithDialog.label=Ant Build...
19
antLaunchConfigurationTabGroup.description=Run an Ant build file.
20
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
21
22
AntLaunchDelegate.name=Eclipse Ant Launcher
23
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
24
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
25
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
26
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
27
AntBuildShortcut.description=Launches an Ant build with default settings
28
29
AntBuild=Ant Build
30
AntBuilder.name=Ant Builder
31
AntLaunchShortcut.label=Ant Build
32
AntLaunchShortcutWithDialog.label=Ant Build...
33
antLaunchConfigurationTabGroup.description=Run an Ant build file.
34
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
35
36
AntLaunchDelegate.name=Eclipse Ant Launcher
37
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
38
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
39
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
40
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
41
AntBuildShortcut.description=Launches an Ant build with default settings
42
43
AntBuild=Ant Build
44
AntBuilder.name=Ant Builder
45
AntLaunchShortcut.label=Ant Build
46
AntLaunchShortcutWithDialog.label=Ant Build...
47
antLaunchConfigurationTabGroup.description=Run an Ant build file.
48
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
49
50
AntLaunchDelegate.name=Eclipse Ant Launcher
51
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
52
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
53
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
54
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
55
AntBuildShortcut.description=Launches an Ant build with default settings
56
57
AntBuild=Ant Build
58
AntBuilder.name=Ant Builder
59
AntLaunchShortcut.label=Ant Build
60
AntLaunchShortcutWithDialog.label=Ant Build...
61
antLaunchConfigurationTabGroup.description=Run an Ant build file.
62
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
63
64
AntLaunchDelegate.name=Eclipse Ant Launcher
65
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
66
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
67
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
68
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
69
AntBuildShortcut.description=Launches an Ant build with default settings
70
71
AntBuild=Ant Build
72
AntBuilder.name=Ant Builder
73
AntLaunchShortcut.label=Ant Build
74
AntLaunchShortcutWithDialog.label=Ant Build...
75
antLaunchConfigurationTabGroup.description=Run an Ant build file.
76
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
77
78
AntLaunchDelegate.name=Eclipse Ant Launcher
79
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
80
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
81
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
82
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
83
AntBuildShortcut.description=Launches an Ant build with default settings
84
85
AntBuild=Ant Build
86
AntBuilder.name=Ant Builder
87
AntLaunchShortcut.label=Ant Build
88
AntLaunchShortcutWithDialog.label=Ant Build...
89
antLaunchConfigurationTabGroup.description=Run an Ant build file.
90
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
91
92
AntLaunchDelegate.name=Eclipse Ant Launcher
93
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
94
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
95
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
96
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
97
AntBuildShortcut.description=Launches an Ant build with default settings
98
99
AntBuild=Ant Build
100
AntBuilder.name=Ant Builder
101
AntLaunchShortcut.label=Ant Build
102
AntLaunchShortcutWithDialog.label=Ant Build...
103
antLaunchConfigurationTabGroup.description=Run an Ant build file.
104
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
105
106
AntLaunchDelegate.name=Eclipse Ant Launcher
107
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
108
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
109
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
110
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
111
AntBuildShortcut.description=Launches an Ant build with default settings
112
113
AntBuild=Ant Build
114
AntBuilder.name=Ant Builder
115
AntLaunchShortcut.label=Ant Build
116
AntLaunchShortcutWithDialog.label=Ant Build...
117
antLaunchConfigurationTabGroup.description=Run an Ant build file.
118
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
119
120
AntLaunchDelegate.name=Eclipse Ant Launcher
121
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
122
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
123
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
124
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
125
AntBuildShortcut.description=Launches an Ant build with default settings
126
127
AntBuild=Ant Build
128
AntBuilder.name=Ant Builder
129
AntLaunchShortcut.label=Ant Build
130
AntLaunchShortcutWithDialog.label=Ant Build...
131
antLaunchConfigurationTabGroup.description=Run an Ant build file.
132
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
133
134
AntLaunchDelegate.name=Eclipse Ant Launcher
135
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
136
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
137
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
138
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
139
AntBuildShortcut.description=Launches an Ant build with default settings
140
141
AntBuild=Ant Build
142
AntBuilder.name=Ant Builder
143
AntLaunchShortcut.label=Ant Build
144
AntLaunchShortcutWithDialog.label=Ant Build...
145
antLaunchConfigurationTabGroup.description=Run an Ant build file.
146
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
147
148
AntLaunchDelegate.name=Eclipse Ant Launcher
149
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
150
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
151
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
152
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
153
AntBuildShortcut.description=Launches an Ant build with default settings
154
155
AntBuild=Ant Build
156
AntBuilder.name=Ant Builder
157
AntLaunchShortcut.label=Ant Build
158
AntLaunchShortcutWithDialog.label=Ant Build...
159
antLaunchConfigurationTabGroup.description=Run an Ant build file.
160
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
161
162
AntLaunchDelegate.name=Eclipse Ant Launcher
163
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
164
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
165
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
166
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
167
AntBuildShortcut.description=Launches an Ant build with default settings
168
169
AntBuild=Ant Build
170
AntBuilder.name=Ant Builder
171
AntLaunchShortcut.label=Ant Build
172
AntLaunchShortcutWithDialog.label=Ant Build...
173
antLaunchConfigurationTabGroup.description=Run an Ant build file.
174
antBuilderLaunchConfigurationTabGroup.description=Create a configuration that will run an Ant build file during a build.
175
176
AntLaunchDelegate.name=Eclipse Ant Launcher
177
AntLaunchDelegate.description=The Eclipse Ant Launcher supports running and debugging Ant build files.
178
AntBuilderLaunchDelegate.name= Eclipse Ant Builder Launcher
179
AntBuilderLaunchDelegate.description=The Eclipse Ant Builder Launcher supports running Ant build files.
180
AntBuild...Shortcut.description=Launches an Ant build and allows it to be configured 
181
AntBuildShortcut.description=Launches an Ant build with default settings
(-)plugin.xml (+76 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
   <extension
5
         point="org.eclipse.debug.core.launchConfigurationTypes">
6
      <launchConfigurationType
7
            category="org.eclipse.ui.externaltools"
8
            delegate="org.eclipse.ant.internal.launching.launchConfigurations.AntLaunchDelegate"
9
            delegateDescription="%AntLaunchDelegate.description"
10
            delegateName="%AntLaunchDelegate.name"
11
            id="org.eclipse.ant.AntLaunchConfigurationType"
12
            migrationDelegate="org.eclipse.ant.internal.launching.launchConfigurations.AntMigrationDelegate"
13
            modes="run, debug"
14
            name="%AntBuild"
15
            sourceLocatorId="org.eclipse.ant.ui.debug.sourceLookupDirector"
16
            sourcePathComputerId="org.eclipse.ant.ui.debug.sourcePathComputer">
17
      </launchConfigurationType>
18
      <launchConfigurationType
19
            category="org.eclipse.ui.externaltools.builder"
20
            delegate="org.eclipse.ant.internal.launching.launchConfigurations.AntLaunchDelegate"
21
            delegateDescription="%AntBuilderLaunchDelegate.description"
22
            delegateName="%AntBuilderLaunchDelegate.name"
23
            id="org.eclipse.ant.AntBuilderLaunchConfigurationType"
24
            modes="run"
25
            name="%AntBuilder.name">
26
      </launchConfigurationType>
27
   </extension>
28
   <extension point="org.eclipse.core.runtime.preferences">
29
		<initializer class="org.eclipse.ant.internal.launching.AntLaunchingPreferenceInitializer"/>
30
	</extension>
31
  <extension
32
         point="org.eclipse.jdt.launching.runtimeClasspathEntries">
33
      <runtimeClasspathEntry
34
            class="org.eclipse.ant.internal.launching.launchConfigurations.AntHomeClasspathEntry"
35
            id="org.eclipse.antui.classpathentry.antHome">
36
      </runtimeClasspathEntry>
37
      <runtimeClasspathEntry
38
            class="org.eclipse.ant.internal.launching.launchConfigurations.ContributedClasspathEntriesEntry"
39
            id="org.eclipse.ant.ui.classpathentry.extraClasspathEntries">
40
      </runtimeClasspathEntry>
41
   </extension>
42
   <extension
43
         point="org.eclipse.jdt.launching.classpathProviders">
44
      <classpathProvider
45
            class="org.eclipse.ant.internal.launching.launchConfigurations.AntClasspathProvider"
46
            id="org.eclipse.ant.ui.AntClasspathProvider">
47
      </classpathProvider>
48
   </extension>
49
   <extension
50
         point="org.eclipse.debug.core.processFactories">
51
      <processFactory
52
            class="org.eclipse.ant.internal.launching.launchConfigurations.RemoteAntProcessFactory"
53
            id="org.eclipse.ant.ui.remoteAntProcessFactory">
54
      </processFactory>
55
   </extension>
56
   <extension point="org.eclipse.core.runtime.preferences">
57
		<initializer class="org.eclipse.ant.internal.launching.AntLaunchingPreferenceInitializer"/>
58
	</extension>
59
   <extension
60
         point="org.eclipse.ant.core.extraClasspathEntries">
61
      <extraClasspathEntry
62
            headless="true"
63
            library="lib/loggers.jar">
64
      </extraClasspathEntry>
65
      <extraClasspathEntry
66
            eclipseRuntime="false"
67
            headless="true"
68
            library="lib/antdebug.jar">
69
      </extraClasspathEntry>
70
      <extraClasspathEntry
71
            eclipseRuntime="false"
72
            headless="true"
73
            library="lib/remote.jar">
74
      </extraClasspathEntry>
75
   </extension>
76
</plugin>
(-)remote/META-INF/eclipse.inf (+1 lines)
Added Link Here
1
jarprocessor.exclude.sign=true
(-)remote/org/eclipse/ant/internal/launching/remote/AntSecurityException.java (+23 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote;
12
13
/**
14
 * A security exception that is thrown by the AntSecurityManager if
15
 * an Ant task in some way attempts to halt or exit the Java Virtual Machine.
16
 * 
17
 * @since 2.1
18
 */
19
public class AntSecurityException extends SecurityException {
20
21
	private static final long serialVersionUID = 1L;
22
23
}
(-)remote/org/eclipse/ant/internal/launching/remote/AntSecurityManager.java (+371 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote;
12
13
14
import java.io.FileDescriptor;
15
import java.net.InetAddress;
16
import java.net.SocketPermission;
17
import java.security.Permission;
18
import java.util.PropertyPermission;
19
20
/**
21
 * A security manager that always throws an <code>AntSecurityException</code>
22
 * if the calling thread attempts to cause the Java Virtual Machine to 
23
 * exit/halt or if the restricted thread attempts to set a System property.
24
 * Otherwise this manager just delegates to the pre-existing manager
25
 * passed in the constructor or mimics the default security manager behavior
26
 */
27
public class AntSecurityManager extends SecurityManager {
28
29
	private SecurityManager fSecurityManager= null;
30
	private Thread fRestrictedThread= null;
31
	//ensure that the PropertyPermission class is loaded before we 
32
	//start checking permissions: bug 85908
33
	private static final PropertyPermission fgPropertyPermission= new PropertyPermission("*", "write"); //$NON-NLS-1$ //$NON-NLS-2$
34
	
35
	private boolean fAllowSettingSystemProperties= true;
36
	
37
	public AntSecurityManager(SecurityManager securityManager, Thread restrictedThread, boolean allowSettingProperties) {
38
		fSecurityManager= securityManager;
39
		fRestrictedThread= restrictedThread;
40
		fAllowSettingSystemProperties= allowSettingProperties;
41
	}
42
	
43
	public AntSecurityManager(SecurityManager securityManager, Thread restrictedThread) {
44
		this(securityManager, restrictedThread, true);
45
	}
46
	
47
	/* (non-Javadoc)
48
	 * @see java.lang.SecurityManager#checkExit(int)
49
	 */
50
	public void checkExit(int status) {
51
		//no exit allowed from the restricted thread...System.exit is being called
52
		//by some ant task...disallow the exit
53
		if (Thread.currentThread() == fRestrictedThread) {
54
			throw new AntSecurityException();
55
		}
56
		if (fSecurityManager != null) {
57
			fSecurityManager.checkExit(status);
58
		}
59
	}
60
	/* (non-Javadoc)
61
	 * @see java.lang.SecurityManager#checkAccept(java.lang.String, int)
62
	 */
63
	public void checkAccept(String host, int port) {
64
		if (fSecurityManager != null) {
65
			fSecurityManager.checkAccept(host, port);
66
		}
67
	}
68
69
	/* (non-Javadoc)
70
	 * @see java.lang.SecurityManager#checkAccess(java.lang.Thread)
71
	 */
72
	public void checkAccess(Thread t) {
73
		if (fSecurityManager != null) {
74
			fSecurityManager.checkAccess(t);
75
		}
76
	}
77
78
	/* (non-Javadoc)
79
	 * @see java.lang.SecurityManager#checkAccess(java.lang.ThreadGroup)
80
	 */
81
	public void checkAccess(ThreadGroup g) {
82
		if (fSecurityManager != null) {
83
			fSecurityManager.checkAccess(g);
84
		}
85
	}
86
87
	/* (non-Javadoc)
88
	 * @see java.lang.SecurityManager#checkAwtEventQueueAccess()
89
	 */
90
	public void checkAwtEventQueueAccess() {
91
		if (fSecurityManager != null) {
92
			fSecurityManager.checkAwtEventQueueAccess();
93
		}
94
	}
95
96
	/* (non-Javadoc)
97
	 * @see java.lang.SecurityManager#checkConnect(java.lang.String, int, java.lang.Object)
98
	 */
99
	public void checkConnect(String host, int port, Object context) {
100
		if (fSecurityManager != null) {
101
			fSecurityManager.checkConnect(host, port, context);
102
		}
103
	}
104
105
	/* (non-Javadoc)
106
	 * @see java.lang.SecurityManager#checkConnect(java.lang.String, int)
107
	 */
108
	public void checkConnect(String host, int port) {
109
		if (fSecurityManager != null) {
110
			fSecurityManager.checkConnect(host, port);
111
		}
112
	}
113
114
	/* (non-Javadoc)
115
	 * @see java.lang.SecurityManager#checkCreateClassLoader()
116
	 */
117
	public void checkCreateClassLoader() {
118
		if (fSecurityManager != null) {
119
			fSecurityManager.checkCreateClassLoader();
120
		}
121
	}
122
123
	/* (non-Javadoc)
124
	 * @see java.lang.SecurityManager#checkDelete(java.lang.String)
125
	 */
126
	public void checkDelete(String file) {
127
		if (fSecurityManager != null) {
128
			fSecurityManager.checkDelete(file);
129
		}
130
	}
131
132
	/* (non-Javadoc)
133
	 * @see java.lang.SecurityManager#checkExec(java.lang.String)
134
	 */
135
	public void checkExec(String cmd) {
136
		if (fSecurityManager != null) {
137
			fSecurityManager.checkExec(cmd);
138
		}
139
	}
140
141
	/* (non-Javadoc)
142
	 * @see java.lang.SecurityManager#checkLink(java.lang.String)
143
	 */
144
	public void checkLink(String lib) {
145
		if (fSecurityManager != null) {
146
			fSecurityManager.checkLink(lib);
147
		}
148
	}
149
150
	/* (non-Javadoc)
151
	 * @see java.lang.SecurityManager#checkListen(int)
152
	 */
153
	public void checkListen(int port) {
154
		if (fSecurityManager != null) {
155
			fSecurityManager.checkListen(port);
156
		}
157
	}
158
159
	/* (non-Javadoc)
160
	 * @see java.lang.SecurityManager#checkMemberAccess(java.lang.Class, int)
161
	 */
162
	public void checkMemberAccess(Class clazz, int which) {
163
		if (fSecurityManager != null) {
164
			fSecurityManager.checkMemberAccess(clazz, which);
165
		}
166
	}
167
168
	/**
169
	 * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress, byte)
170
	 * @deprecated
171
	 */
172
	public void checkMulticast(InetAddress maddr, byte ttl) {
173
		if (fSecurityManager != null) {
174
			String host = maddr.getHostAddress();
175
			if (!host.startsWith("[") && host.indexOf(':') != -1) { //$NON-NLS-1$
176
	   			host = "[" + host + "]"; //$NON-NLS-1$ //$NON-NLS-2$
177
			}
178
	    	checkPermission(new SocketPermission(host, "accept,connect")); //$NON-NLS-1$
179
		}
180
	}
181
182
	/* (non-Javadoc)
183
	 * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress)
184
	 */
185
	public void checkMulticast(InetAddress maddr) {
186
		if (fSecurityManager != null) {
187
			fSecurityManager.checkMulticast(maddr);
188
		}
189
	}
190
191
	/* (non-Javadoc)
192
	 * @see java.lang.SecurityManager#checkPackageAccess(java.lang.String)
193
	 */
194
	public void checkPackageAccess(String pkg) {
195
		if (fSecurityManager != null) {
196
			fSecurityManager.checkPackageAccess(pkg);
197
		}
198
	}
199
200
	/* (non-Javadoc)
201
	 * @see java.lang.SecurityManager#checkPackageDefinition(java.lang.String)
202
	 */
203
	public void checkPackageDefinition(String pkg) {
204
		if (fSecurityManager != null) {
205
			fSecurityManager.checkPackageDefinition(pkg);
206
		}
207
	}
208
209
	/* (non-Javadoc)
210
	 * @see java.lang.SecurityManager#checkPermission(java.security.Permission, java.lang.Object)
211
	 */
212
	public void checkPermission(Permission perm, Object context) {
213
		if (fSecurityManager != null) {
214
			fSecurityManager.checkPermission(perm, context);
215
		}
216
	}
217
218
	/* (non-Javadoc)
219
	 * @see java.lang.SecurityManager#checkPermission(java.security.Permission)
220
	 */
221
	public void checkPermission(Permission perm) {
222
		if (!fAllowSettingSystemProperties && fgPropertyPermission.implies(perm) && fRestrictedThread == Thread.currentThread()) {
223
			//attempting to write a system property
224
			throw new AntSecurityException();
225
		}
226
		if (fSecurityManager != null) {
227
			fSecurityManager.checkPermission(perm);
228
		}
229
	}
230
231
	/* (non-Javadoc)
232
	 * @see java.lang.SecurityManager#checkPrintJobAccess()
233
	 */
234
	public void checkPrintJobAccess() {
235
		if (fSecurityManager != null) {
236
			fSecurityManager.checkPrintJobAccess();
237
		}
238
	}
239
240
	/* (non-Javadoc)
241
	 * @see java.lang.SecurityManager#checkPropertiesAccess()
242
	 */
243
	public void checkPropertiesAccess() {
244
		if (fSecurityManager != null) {
245
			fSecurityManager.checkPropertiesAccess();
246
		}
247
		super.checkPropertiesAccess();
248
	}
249
250
	/* (non-Javadoc)
251
	 * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
252
	 */
253
	public void checkPropertyAccess(String key) {
254
		if (fSecurityManager != null) {
255
			fSecurityManager.checkPropertyAccess(key);
256
		}
257
	}
258
259
	/* (non-Javadoc)
260
	 * @see java.lang.SecurityManager#checkRead(java.io.FileDescriptor)
261
	 */
262
	public void checkRead(FileDescriptor fd) {
263
		if (fSecurityManager != null) {
264
			fSecurityManager.checkRead(fd);
265
		}
266
	}
267
268
	/* (non-Javadoc)
269
	 * @see java.lang.SecurityManager#checkRead(java.lang.String, java.lang.Object)
270
	 */
271
	public void checkRead(String file, Object context) {
272
		if (fSecurityManager != null) {
273
			fSecurityManager.checkRead(file, context);
274
		}
275
	}
276
277
	/* (non-Javadoc)
278
	 * @see java.lang.SecurityManager#checkRead(java.lang.String)
279
	 */
280
	public void checkRead(String file) {
281
		if (fSecurityManager != null) {
282
			fSecurityManager.checkRead(file);
283
		}
284
	}
285
286
	/* (non-Javadoc)
287
	 * @see java.lang.SecurityManager#checkSecurityAccess(java.lang.String)
288
	 */
289
	public void checkSecurityAccess(String target) {
290
		if (fSecurityManager != null) {
291
			fSecurityManager.checkSecurityAccess(target);
292
		}
293
	}
294
295
	/* (non-Javadoc)
296
	 * @see java.lang.SecurityManager#checkSetFactory()
297
	 */
298
	public void checkSetFactory() {
299
		if (fSecurityManager != null) {
300
			fSecurityManager.checkSetFactory();
301
		}
302
	}
303
304
	/* (non-Javadoc)
305
	 * @see java.lang.SecurityManager#checkSystemClipboardAccess()
306
	 */
307
	public void checkSystemClipboardAccess() {
308
		if (fSecurityManager != null) {
309
			fSecurityManager.checkSystemClipboardAccess();
310
		}
311
	}
312
313
	/* (non-Javadoc)
314
	 * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object)
315
	 */
316
	public boolean checkTopLevelWindow(Object window) {
317
		if (fSecurityManager != null) {
318
			return fSecurityManager.checkTopLevelWindow(window);
319
		}
320
		return super.checkTopLevelWindow(window);
321
	}
322
323
	/* (non-Javadoc)
324
	 * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor)
325
	 */
326
	public void checkWrite(FileDescriptor fd) {
327
		if (fSecurityManager != null) {
328
			fSecurityManager.checkWrite(fd);
329
		}
330
	}
331
332
	/* (non-Javadoc)
333
	 * @see java.lang.SecurityManager#checkWrite(java.lang.String)
334
	 */
335
	public void checkWrite(String file) {
336
		if (fSecurityManager != null) {
337
			fSecurityManager.checkWrite(file);
338
		}
339
	}
340
341
	/**
342
	 * @see java.lang.SecurityManager#getInCheck()
343
	 * @deprecated
344
	 */
345
	public boolean getInCheck() {
346
		if (fSecurityManager != null) {
347
			return fSecurityManager.getInCheck();
348
		}
349
		return super.getInCheck();
350
	}
351
352
	/* (non-Javadoc)
353
	 * @see java.lang.SecurityManager#getSecurityContext()
354
	 */
355
	public Object getSecurityContext() {
356
		if (fSecurityManager != null) {
357
			return fSecurityManager.getSecurityContext();
358
		}
359
		return super.getSecurityContext();
360
	}
361
362
	/* (non-Javadoc)
363
	 * @see java.lang.SecurityManager#getThreadGroup()
364
	 */
365
	public ThreadGroup getThreadGroup() {
366
		if (fSecurityManager != null) {
367
			fSecurityManager.getThreadGroup();
368
		}
369
		return super.getThreadGroup();
370
	}
371
}
(-)remote/org/eclipse/ant/internal/launching/remote/DemuxInputStreamSetter.java (+26 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote;
12
13
14
import org.apache.tools.ant.DemuxInputStream;
15
import org.apache.tools.ant.Project;
16
17
/**
18
 * This class exists so that the Ant integration has backwards compatibility
19
 * with Ant releases previous to 1.6. DemuxInputStream is a new class to Ant 1.6.
20
 */
21
class DemuxInputStreamSetter {
22
23
	protected void remapSystemIn(Project project) {
24
		System.setIn(new DemuxInputStream(project));
25
	}
26
}
(-)remote/org/eclipse/ant/internal/launching/remote/EclipseDefaultExecutor.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote;
12
13
import java.util.Arrays;
14
import java.util.Vector;
15
16
import org.apache.tools.ant.BuildException;
17
import org.apache.tools.ant.Executor;
18
import org.apache.tools.ant.Project;
19
import org.apache.tools.ant.helper.DefaultExecutor;
20
21
public class EclipseDefaultExecutor extends DefaultExecutor {
22
23
    private static final EclipseSingleCheckExecutor SUB_EXECUTOR = new EclipseSingleCheckExecutor();
24
    
25
    /* (non-Javadoc)
26
     * @see org.apache.tools.ant.Executor#executeTargets(org.apache.tools.ant.Project, java.lang.String[])
27
     */
28
    public void executeTargets(Project project, String[] targetNames) throws BuildException {
29
        Vector v= new Vector();
30
        v.addAll(Arrays.asList(targetNames));
31
        project.addReference("eclipse.ant.targetVector", v); //$NON-NLS-1$
32
        super.executeTargets(project, targetNames);
33
    }
34
    
35
    /* (non-Javadoc)
36
     * @see org.apache.tools.ant.Executor#getSubProjectExecutor()
37
     */
38
    public Executor getSubProjectExecutor() {
39
       return SUB_EXECUTOR;
40
    }
41
}
(-)remote/org/eclipse/ant/internal/launching/remote/EclipseSingleCheckExecutor.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote;
12
13
import java.util.Arrays;
14
import java.util.Vector;
15
16
import org.apache.tools.ant.BuildException;
17
import org.apache.tools.ant.Executor;
18
import org.apache.tools.ant.Project;
19
import org.apache.tools.ant.helper.SingleCheckExecutor;
20
21
public class EclipseSingleCheckExecutor extends SingleCheckExecutor {
22
23
    /* (non-Javadoc)
24
     * @see org.apache.tools.ant.Executor#executeTargets(org.apache.tools.ant.Project, java.lang.String[])
25
     */
26
    public void executeTargets(Project project, String[] targetNames) throws BuildException {
27
        Vector v= new Vector();
28
        v.addAll(Arrays.asList(targetNames));
29
        project.addReference("eclipse.ant.targetVector", v); //$NON-NLS-1$
30
        super.executeTargets(project, targetNames);
31
    }
32
    
33
    /* (non-Javadoc)
34
     * @see org.apache.tools.ant.Executor#getSubProjectExecutor()
35
     */
36
    public Executor getSubProjectExecutor() {
37
        return this;
38
    }
39
}
(-)remote/org/eclipse/ant/internal/launching/remote/ExecutorSetter.java (+26 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote;
12
13
import org.apache.tools.ant.Executor;
14
import org.apache.tools.ant.Project;
15
16
/**
17
 * This class exists so that the Ant integration has backwards compatibility
18
 * with Ant releases previous to 1.6.3. Executors are a new feature of Ant 1.6.3.
19
 */
20
public class ExecutorSetter {
21
22
    protected void setExecutor(Project project) {
23
        Executor executor= new EclipseDefaultExecutor();
24
        project.setExecutor(executor);
25
    }
26
}
(-)remote/org/eclipse/ant/internal/launching/remote/InputHandlerSetter.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote;
12
13
14
import java.text.MessageFormat; // can't use ICU, used by ant
15
16
import org.apache.tools.ant.BuildException;
17
import org.apache.tools.ant.Project;
18
import org.apache.tools.ant.input.DefaultInputHandler;
19
import org.apache.tools.ant.input.InputHandler;
20
21
/**
22
 * This class exists so that the Ant integration has backwards compatibility
23
 * with Ant releases previous to 1.5. InputHandlers are a new feature of Ant 1.5.
24
 */
25
class InputHandlerSetter {
26
27
	protected void setInputHandler(Project project, String inputHandlerClassname) {
28
		InputHandler handler = null;
29
		if (inputHandlerClassname == null) {
30
			handler = new DefaultInputHandler();
31
		} else {
32
			try {
33
				handler = (InputHandler)(Class.forName(inputHandlerClassname).newInstance());
34
			} catch (ClassCastException e) {
35
				String msg = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.The_specified_input_handler_class_{0}_does_not_implement_the_org.apache.tools.ant.input.InputHandler_interface_5"), new String[]{inputHandlerClassname}); //$NON-NLS-1$
36
				throw new BuildException(msg, e);
37
			} catch (Exception e) {
38
				String msg = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unable_to_instantiate_specified_input_handler_class_{0}___{1}_6"), new String[]{inputHandlerClassname, e.getClass().getName()}); //$NON-NLS-1$
39
				throw new BuildException(msg, e);
40
			}
41
		}
42
		project.setInputHandler(handler);
43
	}
44
}
(-)remote/org/eclipse/ant/internal/launching/remote/InternalAntRunner.java (+1231 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * Portions Copyright  2000-2005 The Apache Software Foundation
4
 * All rights reserved. This program and the accompanying materials are made 
5
 * available under the terms of the Apache Software License v2.0 which 
6
 * accompanies this distribution and is available at 
7
 * http://www.apache.org/licenses/LICENSE-2.0.
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - derived implementation
11
 *******************************************************************************/
12
13
package org.eclipse.ant.internal.launching.remote;
14
15
import java.io.File;
16
import java.io.FileInputStream;
17
import java.io.FileNotFoundException;
18
import java.io.FileOutputStream;
19
import java.io.IOException;
20
import java.io.InputStream;
21
import java.io.PrintStream;
22
import java.text.MessageFormat;
23
import java.util.ArrayList;
24
import java.util.Collections;
25
import java.util.Enumeration;
26
import java.util.HashMap;
27
import java.util.Iterator;
28
import java.util.List;
29
import java.util.Map;
30
import java.util.Properties;
31
import java.util.Vector;
32
33
import org.apache.tools.ant.AntTypeDefinition;
34
import org.apache.tools.ant.BuildEvent;
35
import org.apache.tools.ant.BuildException;
36
import org.apache.tools.ant.BuildListener;
37
import org.apache.tools.ant.BuildLogger;
38
import org.apache.tools.ant.ComponentHelper;
39
import org.apache.tools.ant.DefaultLogger;
40
import org.apache.tools.ant.DemuxOutputStream;
41
import org.apache.tools.ant.Diagnostics;
42
import org.apache.tools.ant.Main;
43
import org.apache.tools.ant.Project;
44
import org.apache.tools.ant.ProjectHelper;
45
import org.apache.tools.ant.Target;
46
import org.apache.tools.ant.Task;
47
import org.apache.tools.ant.TaskAdapter;
48
import org.apache.tools.ant.util.FileUtils;
49
import org.eclipse.ant.internal.launching.remote.logger.RemoteAntBuildLogger;
50
51
/**
52
 * Eclipse application entry point into Ant in a separate VM. Derived from the original Ant Main class
53
 * to ensure that the functionality is equivalent when running in the platform.
54
 */
55
public class InternalAntRunner {
56
57
	/**
58
	 *  Message priority for project help messages. 
59
	 */
60
	public static final int MSG_PROJECT_HELP= Project.MSG_DEBUG + 1;
61
	
62
	private List buildListeners;
63
64
	private String buildFileLocation;
65
66
	/** 
67
	 * Targets we want to run.
68
	 */
69
	private Vector targets;
70
71
	private Map userProperties;
72
	
73
	private Project currentProject;
74
	
75
	private BuildLogger buildLogger= null;
76
	
77
	private Map eclipseSpecifiedTasks;
78
	private Map eclipseSpecifiedTypes;
79
	
80
	/**
81
	 * Cache of the Ant version number when it has been loaded
82
	 */
83
	private String antVersionNumber= null;
84
85
	/** Our current message output status. Follows Project.MSG_XXX */
86
	private int messageOutputLevel = Project.MSG_INFO;
87
88
	/** Indicates whether output to the log is to be unadorned. */
89
	private boolean emacsMode = false;
90
91
	/** Indicates we should only parse and display the project help information */
92
	private boolean projectHelp = false;
93
94
	/** Stream that we are using for logging */
95
	private PrintStream out = System.out;
96
97
	/** Stream that we are using for logging error messages */
98
	private PrintStream err = System.err;
99
100
	/**
101
	 * The Ant logger class. There may be only one logger. It will have the
102
	 * right to use the 'out' PrintStream. The class must implement the BuildLogger
103
	 * interface.  An empty String indicates that no logger is to be used.  A <code>null</code>
104
	 * name indicates that the <code>org.apache.tools.ant.DefaultLogger</code> will be used.
105
	 */
106
	private String loggerClassname = null;
107
108
	/** Extra arguments to be parsed as command line arguments. */
109
	private String[] extraArguments = null;
110
	
111
	private boolean scriptExecuted= false;
112
	
113
	private List propertyFiles= new ArrayList();
114
	
115
	/**
116
     * The Ant InputHandler class. There may be only one input handler.
117
     */
118
    private String inputHandlerClassname = null;
119
    
120
    /** 
121
     * Indicates whether to execute all targets that 
122
     * do not depend on failed targets
123
     * @since Ant 1.6.0
124
     */
125
    private boolean keepGoing= false;
126
127
    /** 
128
     * Indicates whether this build is to support interactive input 
129
     * @since Ant 1.6.0
130
     */
131
    private boolean allowInput = true;
132
    
133
    private String fEarlyErrorMessage= null;
134
    
135
    public static void main(String[] args) {
136
    	try {
137
    		new InternalAntRunner().run(getArrayList(args));
138
    	} catch (Throwable t) {
139
    	    t.printStackTrace();
140
    		System.exit(1);
141
    	}
142
		System.exit(0);
143
	}
144
145
	private void addBuildListeners(Project project) {
146
		String className= null;
147
		try {
148
			BuildLogger logger= createLogger();
149
			if (logger != null) {
150
				project.addBuildListener(logger);
151
			}
152
			if (buildListeners != null) {
153
				for (Iterator iterator = buildListeners.iterator(); iterator.hasNext();) {
154
					className = (String) iterator.next();
155
					Class listener = Class.forName(className);
156
					project.addBuildListener((BuildListener) listener.newInstance());
157
				}
158
			}
159
		} catch (ClassCastException e) {
160
			String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.{0}_which_was_specified_to_be_a_build_listener_is_not_an_instance_of_org.apache.tools.ant.BuildListener._1"), new String[]{className}); //$NON-NLS-1$
161
			logMessage(null, message, Project.MSG_ERR);
162
			throw new BuildException(message, e);
163
		} catch (BuildException e) {
164
			throw e;
165
		} catch (Exception e) {
166
			throw new BuildException(e);
167
		}
168
	}
169
170
	/**
171
	 * Parses the build file and adds necessary information into
172
	 * the given project.
173
	 * @param project The project to configure
174
	 */
175
	private void parseBuildFile(Project project) {
176
		File buildFile = new File(getBuildFileLocation());
177
		if (!buildFile.exists()) {
178
			throw new BuildException(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Buildfile__{0}_does_not_exist_!_1"), //$NON-NLS-1$
179
						 new String[]{buildFile.getAbsolutePath()}));
180
		}
181
		if (!buildFile.isFile()) {
182
			throw new BuildException(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Buildfile__{0}_is_not_a_file_1"), //$NON-NLS-1$
183
							new String[]{buildFile.getAbsolutePath()}));
184
		}
185
		
186
        if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
187
            parseBuildFile(project, buildFile);
188
        } else {
189
            ProjectHelper helper = ProjectHelper.getProjectHelper();
190
            project.addReference("ant.projectHelper", helper); //$NON-NLS-1$
191
            helper.parse(project, buildFile);
192
        }
193
    }
194
    
195
    /**
196
     * @deprecated support for Ant older than 1.5
197
     */
198
    private void parseBuildFile(Project project, File buildFile) {
199
        ProjectHelper.configureProject(project, buildFile);   
200
    }
201
202
	private void printArguments(Project project) {
203
		if ((messageOutputLevel != Project.MSG_DEBUG) && (messageOutputLevel != Project.MSG_VERBOSE)) {
204
			return;
205
		}
206
		StringBuffer sb = new StringBuffer();
207
		for (int i = 0; i < extraArguments.length; i++) {
208
			sb.append(extraArguments[i]);
209
			sb.append(' ');
210
		}
211
		project.log(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Arguments__{0}_2"), new String[]{sb.toString().trim()})); //$NON-NLS-1$
212
	}
213
214
215
	/**
216
	 * Logs a message with the client that lists the targets
217
	 * in a project
218
	 * 
219
	 * @param project the project to list targets from
220
	 */
221
	private void printTargets(Project project) {
222
		//notify the logger that project help message are coming
223
		//since there is no buildstarted or targetstarted to 
224
		//to be used to establish the connection
225
		logMessage(project, "", MSG_PROJECT_HELP); //$NON-NLS-1$
226
		// find the target with the longest name
227
		int maxLength = 0;
228
		Enumeration ptargets = project.getTargets().elements();
229
		String targetName;
230
		String targetDescription;
231
		Target currentTarget;
232
		// split the targets in top-level and sub-targets depending
233
		// on the presence of a description
234
		List topNames = new ArrayList();
235
		List topDescriptions = new ArrayList();
236
		List subNames = new ArrayList();
237
238
		while (ptargets.hasMoreElements()) {
239
			currentTarget = (Target) ptargets.nextElement();
240
			targetName = currentTarget.getName();
241
			targetDescription = currentTarget.getDescription();
242
			if (targetDescription == null) {
243
				subNames.add(targetName);
244
			} else {
245
				topNames.add(targetName);
246
				topDescriptions.add(targetDescription);
247
				if (targetName.length() > maxLength) {
248
					maxLength = targetName.length();
249
				}
250
			}
251
		}
252
253
		Collections.sort(subNames);
254
		Collections.sort(topNames);
255
		Collections.sort(topDescriptions);
256
		
257
		String defaultTargetName = project.getDefaultTarget();
258
		if (defaultTargetName != null && !"".equals(defaultTargetName)) { // shouldn't need to check but... //$NON-NLS-1$
259
			List defaultName = new ArrayList(1);
260
			List defaultDesc = null;
261
			defaultName.add(defaultTargetName);
262
263
			int indexOfDefDesc = topNames.indexOf(defaultTargetName);
264
			if (indexOfDefDesc >= 0) {
265
				defaultDesc = new ArrayList(1);
266
				defaultDesc.add(topDescriptions.get(indexOfDefDesc));
267
			}
268
			printTargets(project, defaultName, defaultDesc, RemoteAntMessages.getString("InternalAntRunner.Default_target__3"), maxLength); //$NON-NLS-1$
269
270
		}
271
272
		printTargets(project, topNames, topDescriptions, RemoteAntMessages.getString("InternalAntRunner.Main_targets__4"), maxLength); //$NON-NLS-1$
273
		printTargets(project, subNames, null, RemoteAntMessages.getString("InternalAntRunner.Subtargets__5"), 0); //$NON-NLS-1$
274
	}
275
276
	/**
277
	 * Logs a message with the client that lists the target names and optional descriptions
278
	 * 
279
	 * @param project the enclosing target
280
	 * @param names the targets names
281
	 * @param descriptions the corresponding descriptions
282
	 * @param heading the message heading
283
	 * @param maxlen maximum length that can be allocated for a name
284
	 */
285
	private void printTargets(Project project, List names, List descriptions, String heading, int maxlen) {
286
		// now, start printing the targets and their descriptions
287
		String lSep = System.getProperty("line.separator"); //$NON-NLS-1$
288
		
289
		String spaces = "    "; //$NON-NLS-1$
290
		while (spaces.length() < maxlen) {
291
			spaces += spaces;
292
		}
293
		StringBuffer msg = new StringBuffer();
294
		msg.append(heading + lSep + lSep);
295
		for (int i = 0; i < names.size(); i++) {
296
			msg.append(' ');
297
			msg.append(names.get(i));
298
			if (descriptions != null) {
299
				msg.append(spaces.substring(0, maxlen - ((String) names.get(i)).length() + 2));
300
				msg.append(descriptions.get(i));
301
			}
302
			msg.append(lSep);
303
		}
304
		logMessage(project, msg.toString(), Project.MSG_INFO);
305
	}
306
307
	/*
308
	 * Note that the list passed to this method must support
309
	 * List#remove(Object)
310
	 */
311
	private void run(List argList) {
312
		setCurrentProject(new Project());
313
         if (isVersionCompatible("1.6.3")) { //$NON-NLS-1$
314
               new ExecutorSetter().setExecutor(getCurrentProject());
315
            }
316
		Throwable error = null;
317
		PrintStream originalErr = System.err;
318
		PrintStream originalOut = System.out;
319
		InputStream originalIn= System.in;
320
		
321
		SecurityManager originalSM= System.getSecurityManager();
322
		scriptExecuted= true;
323
		try {
324
			if (argList != null && (argList.remove("-projecthelp") || argList.remove("-p"))) { //$NON-NLS-1$ //$NON-NLS-2$
325
				projectHelp = true;
326
			}
327
			getCurrentProject().init();
328
			if (argList != null) {
329
				scriptExecuted= preprocessCommandLine(argList);
330
			
331
				if (!scriptExecuted) {
332
					return;
333
				}
334
			}
335
			
336
            boolean exceptionState= processProperties(argList);
337
            
338
			addBuildListeners(getCurrentProject());
339
            
340
			addInputHandler(getCurrentProject());
341
			
342
			remapSystemIn();
343
			System.setOut(new PrintStream(new DemuxOutputStream(getCurrentProject(), false)));
344
			System.setErr(new PrintStream(new DemuxOutputStream(getCurrentProject(), true)));
345
			
346
			if (!projectHelp) {
347
				fireBuildStarted(getCurrentProject());
348
			}
349
            
350
            if (fEarlyErrorMessage != null) {
351
                //an error occurred processing the properties
352
                //build started has fired and we have
353
                //listeners/loggers to report the error
354
                logMessage(getCurrentProject(), fEarlyErrorMessage, Project.MSG_ERR);
355
                if (exceptionState) {
356
                    throw new BuildException(fEarlyErrorMessage);
357
                }
358
            }
359
            
360
            //properties can only be set after buildStarted as some listeners/loggers
361
            //depend on this (e.g. XMLLogger)
362
            setProperties(getCurrentProject());
363
			
364
			if (argList != null && !argList.isEmpty()) {
365
				try {
366
					scriptExecuted= processCommandLine(argList);
367
				} catch (BuildException e) {
368
					scriptExecuted= false;
369
					throw e;
370
				}
371
			}
372
			if (!scriptExecuted) {
373
				return;
374
			}
375
			
376
            //needs to occur after processCommandLine(List)
377
			if (allowInput && (inputHandlerClassname != null && inputHandlerClassname.length() > 0)) {
378
				if (isVersionCompatible("1.6")) { //$NON-NLS-1$
379
					getCurrentProject().setDefaultInputStream(originalIn);
380
				}
381
			} else {
382
				//set the system property that any input handler
383
				//can check to see if handling input is allowed
384
				System.setProperty("eclipse.ant.noInput", "true");  //$NON-NLS-1$//$NON-NLS-2$
385
				if (isVersionCompatible("1.5") && (inputHandlerClassname == null || inputHandlerClassname.length() == 0)) { //$NON-NLS-1$
386
					InputHandlerSetter setter= new InputHandlerSetter();
387
					setter.setInputHandler(getCurrentProject(), "org.eclipse.ant.internal.ui.antsupport.inputhandler.FailInputHandler"); //$NON-NLS-1$
388
				}
389
			}
390
			
391
			getCurrentProject().log(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Build_file__{0}_1"), new String[]{getBuildFileLocation()})); //$NON-NLS-1$
392
			
393
			setTasks();
394
			setTypes();
395
			
396
			if (isVersionCompatible("1.6")) { //$NON-NLS-1$
397
				getCurrentProject().setKeepGoingMode(keepGoing);
398
			}
399
			
400
			parseBuildFile(getCurrentProject());
401
			
402
			if (projectHelp) {
403
				printHelp(getCurrentProject());
404
				scriptExecuted= false;
405
				return;
406
			}
407
			
408
			if (extraArguments != null) {
409
				printArguments(getCurrentProject());
410
			}
411
			
412
			System.setSecurityManager(new AntSecurityManager(originalSM, Thread.currentThread()));
413
			
414
			if (targets == null) {
415
                targets= new Vector(1);
416
            }
417
            if (targets.isEmpty() && getCurrentProject().getDefaultTarget() != null) {
418
                targets.add(getCurrentProject().getDefaultTarget());
419
            }
420
			if (!isVersionCompatible("1.6.3")) {  //$NON-NLS-1$
421
	            getCurrentProject().addReference("eclipse.ant.targetVector", targets); //$NON-NLS-1$
422
			}
423
			getCurrentProject().executeTargets(targets);
424
		} catch (AntSecurityException e) {
425
			//expected
426
		} catch (Throwable e) {
427
			error = e;
428
		} finally {
429
			System.setErr(originalErr);
430
			System.setOut(originalOut);
431
			System.setIn(originalIn);
432
			if (System.getSecurityManager() instanceof AntSecurityManager) {
433
				System.setSecurityManager(originalSM);
434
			}
435
			
436
			if (!projectHelp) {				
437
				fireBuildFinished(getCurrentProject(), error);
438
			}
439
						
440
			//close any user specified build log
441
			if (err != originalErr) {
442
				err.close();
443
			}
444
			if (out != originalOut) {
445
				out.close();
446
			}
447
		}
448
	}
449
	
450
	private void setTasks() {
451
		if (eclipseSpecifiedTasks != null) {
452
			Iterator itr= eclipseSpecifiedTasks.keySet().iterator();
453
			String taskName;
454
			String taskClassName;
455
			while (itr.hasNext()) {
456
				taskName= (String) itr.next();
457
				taskClassName= (String) eclipseSpecifiedTasks.get(taskName);
458
				
459
				if (isVersionCompatible("1.6")) { //$NON-NLS-1$
460
					AntTypeDefinition def= new AntTypeDefinition();
461
					def.setName(taskName);
462
		            def.setClassName(taskClassName);
463
		            def.setClassLoader(this.getClass().getClassLoader());
464
		            def.setAdaptToClass(Task.class);
465
		            def.setAdapterClass(TaskAdapter.class);
466
		            ComponentHelper.getComponentHelper(getCurrentProject()).addDataTypeDefinition(def);
467
				} else {
468
					try {
469
						Class taskClass = Class.forName(taskClassName);
470
						getCurrentProject().addTaskDefinition(taskName, taskClass);
471
					} catch (ClassNotFoundException e) {
472
						String message= MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.161"), new String[]{taskClassName, taskName}); //$NON-NLS-1$
473
						getCurrentProject().log(message, Project.MSG_WARN);
474
					}	
475
				}
476
			}
477
		}
478
	}
479
480
	private void setTypes() {
481
		if (eclipseSpecifiedTypes != null) {
482
			Iterator itr= eclipseSpecifiedTypes.keySet().iterator();
483
			String typeName;
484
			String typeClassName;
485
			while (itr.hasNext()) {
486
				typeName = (String) itr.next();
487
				typeClassName= (String) eclipseSpecifiedTypes.get(typeName);
488
				if (isVersionCompatible("1.6")) { //$NON-NLS-1$
489
					AntTypeDefinition def = new AntTypeDefinition();
490
	                def.setName(typeName);
491
	                def.setClassName(typeClassName);
492
	                def.setClassLoader(this.getClass().getClassLoader());
493
	                ComponentHelper.getComponentHelper(getCurrentProject()).addDataTypeDefinition(def);
494
				} else {
495
					try {
496
						Class typeClass = Class.forName(typeClassName);
497
						getCurrentProject().addDataTypeDefinition(typeName, typeClass);
498
					} catch (ClassNotFoundException e) {
499
						String message= MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.162"), new String[]{typeClassName, typeName}); //$NON-NLS-1$
500
						getCurrentProject().log(message, Project.MSG_WARN);
501
					}	
502
				}
503
			}
504
		}
505
	}
506
507
	private void remapSystemIn() {
508
		if (!isVersionCompatible("1.6")) { //$NON-NLS-1$
509
			return;
510
		}
511
		DemuxInputStreamSetter setter= new DemuxInputStreamSetter();
512
		setter.remapSystemIn(getCurrentProject());
513
	}
514
	
515
	/**
516
	 * Creates and returns the default build logger for logging build events to the ant log.
517
	 * 
518
	 * @return the default build logger for logging build events to the ant log
519
	 * 			can return <code>null</code> if no logging is to occur
520
	 */
521
	private BuildLogger createLogger() {
522
		if (loggerClassname == null) {
523
			buildLogger= new DefaultLogger();
524
		} else if (!"".equals(loggerClassname)) { //$NON-NLS-1$
525
			try {
526
				buildLogger = (BuildLogger) (Class.forName(loggerClassname).newInstance());
527
			} catch (ClassCastException e) {
528
				String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.{0}_which_was_specified_to_perform_logging_is_not_an_instance_of_org.apache.tools.ant.BuildLogger._2"), new String[]{loggerClassname}); //$NON-NLS-1$
529
				logMessage(null, message, Project.MSG_ERR);
530
				throw new BuildException(message, e);
531
			} catch (Exception e) {
532
				String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unable_to_instantiate_logger__{0}_6"), new String[]{loggerClassname}); //$NON-NLS-1$
533
				logMessage(null, message, Project.MSG_ERR);
534
				throw new BuildException(message, e);
535
			}
536
		} 
537
		
538
		if (buildLogger != null) {
539
			buildLogger.setMessageOutputLevel(messageOutputLevel);
540
			buildLogger.setOutputPrintStream(out);
541
			buildLogger.setErrorPrintStream(err);
542
			buildLogger.setEmacsMode(emacsMode);
543
            if (buildLogger instanceof RemoteAntBuildLogger) {
544
                ((RemoteAntBuildLogger) buildLogger).configure(userProperties);
545
            }
546
		}
547
548
		return buildLogger;
549
    }
550
    
551
    /**
552
     * Project.fireBuildStarted is protected in Ant earlier than 1.5.*.
553
     * Provides backwards compatibility with old Ant installs.
554
     */
555
    private void fireBuildStarted(Project project) {
556
        if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
557
            BuildEvent event = new BuildEvent(project);
558
            for (Iterator iterator = project.getBuildListeners().iterator(); iterator.hasNext();) {
559
                BuildListener listener = (BuildListener) iterator.next();
560
                listener.buildStarted(event);
561
            }
562
        } else {
563
            project.fireBuildStarted();
564
        }
565
    }
566
567
	private void fireBuildFinished(Project project, Throwable error) {
568
		if (error == null && scriptExecuted) {
569
			logMessage(project, RemoteAntMessages.getString("InternalAntRunner.BUILD_SUCCESSFUL_1"), messageOutputLevel); //$NON-NLS-1$
570
		}
571
        if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
572
            BuildEvent event = new BuildEvent(project);
573
            event.setException(error);
574
            Iterator iter = project.getBuildListeners().iterator();
575
            while (iter.hasNext()) {
576
                BuildListener listener = (BuildListener) iter.next();
577
                listener.buildFinished(event);
578
            }   
579
        } else {
580
            project.fireBuildFinished(error);
581
        }
582
	}
583
584
	private void logMessage(Project project, String message, int priority) {
585
		if (project != null) {
586
			project.log(message, priority);	
587
		} else {
588
			if (buildListeners != null) {
589
				project = new Project();
590
				BuildEvent event = new BuildEvent(project);
591
				event.setMessage(message, priority);
592
				//notify the build listeners that are not registered as
593
				//no project existed
594
				for (Iterator iterator = buildListeners.iterator(); iterator.hasNext();) {
595
					try {
596
						BuildListener listener = (BuildListener) iterator.next();
597
						listener.messageLogged(event);
598
					} catch (ClassCastException e) {
599
						//ignore we could be trying to log that a build listener is the
600
						//wrong type of class
601
					}
602
				}
603
			}
604
		}
605
	}
606
607
	/**
608
	 * Sets the buildFileLocation.
609
	 * 
610
	 * @param buildFileLocation the file system location of the build file
611
	 */
612
	private void setBuildFileLocation(String buildFileLocation) {
613
		this.buildFileLocation = buildFileLocation;
614
		if (getCurrentProject() != null) {
615
			getCurrentProject().setUserProperty("ant.file", buildFileLocation); //$NON-NLS-1$
616
		}
617
	}
618
619
	private String getBuildFileLocation() {
620
		if (buildFileLocation == null) {
621
			buildFileLocation = new File("build.xml").getAbsolutePath(); //$NON-NLS-1$
622
		}
623
		return buildFileLocation;
624
	}
625
626
	/**
627
	 * Sets the message output level. Use -1 for none.
628
	 * @param level The message output level
629
	 */
630
	private void setMessageOutputLevel(int level) {
631
		messageOutputLevel = level;
632
		if (buildLogger != null) {
633
			buildLogger.setMessageOutputLevel(level);
634
		}
635
	}
636
	
637
	/*
638
	 * Returns a String representation of the Ant version number as specified
639
	 * in the version.txt file.
640
	 */
641
	private String getAntVersionNumber() throws BuildException {
642
		if (antVersionNumber == null) {
643
			try {
644
				Properties props = new Properties();
645
				InputStream in = Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt"); //$NON-NLS-1$
646
				props.load(in);
647
				in.close();
648
				String versionNumber= props.getProperty("VERSION");  //$NON-NLS-1$
649
				antVersionNumber= versionNumber;
650
			} catch (IOException ioe) {
651
				throw new BuildException(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_the_version_information._{0}_9"), new String[]{ioe.getMessage()})); //$NON-NLS-1$
652
			} catch (NullPointerException npe) {
653
				throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_the_version_information._10")); //$NON-NLS-1$
654
			}
655
		}
656
		return antVersionNumber;
657
	}
658
	
659
	/*
660
	 * Returns whether the given version is compatible with the
661
	 * current Ant version. A version is compatible if it is less
662
	 * than or equal to the current version. 
663
	 */
664
	private boolean isVersionCompatible(String comparison) {
665
		String version= getAntVersionNumber();
666
		return version.compareTo(comparison) >= 0;
667
	}
668
	
669
	private boolean preprocessCommandLine(List commands) {
670
		
671
		String arg = getArgument(commands, "-listener"); //$NON-NLS-1$
672
		while (arg != null) {
673
			if (arg.length() == 0) {
674
				throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.You_must_specify_a_classname_when_using_the_-listener_argument_1")); //$NON-NLS-1$
675
			} 
676
			if (buildListeners == null) {
677
				buildListeners= new ArrayList(1);
678
			}
679
			buildListeners.add(arg);
680
			arg = getArgument(commands, "-listener"); //$NON-NLS-1$
681
		}
682
683
		arg = getArgument(commands, "-logger"); //$NON-NLS-1$
684
		if (arg != null) {
685
			//allow empty string to mean no logger
686
			loggerClassname = arg;
687
		}
688
		arg = getArgument(commands, "-logger"); //$NON-NLS-1$
689
		if (arg != null) {
690
			throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.Only_one_logger_class_may_be_specified_1")); //$NON-NLS-1$
691
		}
692
		
693
		arg = getArgument(commands, "-inputhandler"); //$NON-NLS-1$
694
		if (arg != null) {
695
			if (arg.length() == 0) {
696
				throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.You_must_specify_a_classname_when_using_the_-inputhandler_argument_1")); //$NON-NLS-1$
697
			} 
698
			inputHandlerClassname = arg;
699
		}
700
		arg = getArgument(commands, "-inputhandler"); //$NON-NLS-1$
701
		if (arg != null) {
702
			throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.Only_one_input_handler_class_may_be_specified._2")); //$NON-NLS-1$
703
		}
704
		return true;
705
	}
706
	
707
	/*
708
	 * Looks for interesting command line arguments. 
709
	 * Returns whether it is OK to run the script.
710
	 */
711
	private boolean processCommandLine(List commands) {
712
		
713
		if (commands.remove("-help") || commands.remove("-h")) { //$NON-NLS-1$ //$NON-NLS-2$
714
			printUsage();
715
			return false;
716
		}
717
		
718
		if (commands.remove("-version")) { //$NON-NLS-1$
719
			printVersion();
720
			return false;
721
		}
722
		
723
		if (commands.remove("-verbose") || commands.remove("-v")) { //$NON-NLS-1$ //$NON-NLS-2$
724
			printVersion();
725
			setMessageOutputLevel(Project.MSG_VERBOSE);
726
		}
727
		
728
		if (commands.remove("-debug") || commands.remove("-d")) { //$NON-NLS-1$ //$NON-NLS-2$
729
			printVersion();
730
			setMessageOutputLevel(Project.MSG_DEBUG);
731
		}
732
		
733
		if (commands.remove("-quiet") || commands.remove("-q")) { //$NON-NLS-1$ //$NON-NLS-2$
734
			setMessageOutputLevel(Project.MSG_WARN);
735
		}
736
737
		if (commands.remove("-emacs") || commands.remove("-e")) { //$NON-NLS-1$ //$NON-NLS-2$
738
			emacsMode = true;
739
			if (buildLogger != null) {
740
				buildLogger.setEmacsMode(true);
741
			}
742
		}
743
		
744
		if (commands.remove("-diagnostics")) { //$NON-NLS-1$
745
			if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
746
				throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.The_diagnositics_options_is_an_Ant_1.5.*_feature._Please_update_your_Ant_classpath_to_include_an_Ant_version_greater_than_this._4")); //$NON-NLS-1$
747
			}
748
			try {
749
				Diagnostics.doReport(System.out);
750
			} catch (NullPointerException e) {
751
				logMessage(getCurrentProject(), RemoteAntMessages.getString("InternalAntRunner.ANT_HOME_must_be_set_to_use_Ant_diagnostics_2"), Project.MSG_ERR); //$NON-NLS-1$
752
			}
753
			return false;
754
		}
755
		
756
		String arg = getArgument(commands, "-logfile"); //$NON-NLS-1$
757
		if (arg == null) {
758
			arg = getArgument(commands, "-l"); //$NON-NLS-1$
759
		}
760
		if (arg != null) {
761
			if (arg.length() == 0) {
762
				String message= RemoteAntMessages.getString("InternalAntRunner.You_must_specify_a_log_file_when_using_the_-log_argument_3"); //$NON-NLS-1$
763
				logMessage(currentProject, message, Project.MSG_ERR); 
764
				throw new BuildException(message);
765
			} 
766
			try {
767
				createLogFile(arg);
768
			} catch (IOException e) {
769
				// just log message and ignore exception
770
				logMessage(getCurrentProject(), MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_write_to_the_specified_log_file__{0}._Make_sure_the_path_exists_and_you_have_write_permissions._2"), new String[]{arg}), Project.MSG_ERR); //$NON-NLS-1$
771
				return false;
772
			}
773
		
774
		}
775
		
776
		arg = getArgument(commands, "-buildfile"); //$NON-NLS-1$
777
		if (arg == null) {
778
			arg = getArgument(commands, "-file"); //$NON-NLS-1$
779
			if (arg == null) {
780
				arg = getArgument(commands, "-f"); //$NON-NLS-1$
781
			}
782
		}
783
		
784
		if (arg != null) {
785
			if (arg.length() == 0) {
786
				String message= RemoteAntMessages.getString("InternalAntRunner.You_must_specify_a_buildfile_when_using_the_-buildfile_argument_4"); //$NON-NLS-1$
787
				logMessage(currentProject, message, Project.MSG_ERR); 
788
				throw new BuildException(message);
789
			} 
790
			setBuildFileLocation(arg);
791
		}
792
		
793
		if (isVersionCompatible("1.6")) { //$NON-NLS-1$
794
			if (commands.remove("-k") || commands.remove("-keep-going")) { //$NON-NLS-1$ //$NON-NLS-2$
795
				keepGoing= true;
796
			}
797
			if (commands.remove("-noinput")) { //$NON-NLS-1$
798
				allowInput= false;
799
			}
800
			arg= getArgument(commands, "-lib"); //$NON-NLS-1$
801
			if (arg != null) {
802
				logMessage(currentProject, RemoteAntMessages.getString("InternalAntRunner.157"), Project.MSG_ERR); //$NON-NLS-1$
803
				return false;
804
			}
805
		}
806
		
807
		arg= getArgument(commands, "-find"); //$NON-NLS-1$
808
		if (arg == null) {
809
			arg= getArgument(commands, "-s"); //$NON-NLS-1$
810
		}
811
		if (arg != null) {
812
			logMessage(currentProject, RemoteAntMessages.getString("InternalAntRunner.-find_not_supported"), Project.MSG_ERR); //$NON-NLS-1$
813
			return false;
814
		}
815
		
816
		processTasksAndTypes(commands);
817
		
818
		if (!commands.isEmpty()) {
819
			processUnrecognizedCommands(commands);
820
		}
821
822
		if (!commands.isEmpty()) {
823
			processTargets(commands);
824
		}
825
		
826
		return true;
827
	}
828
	
829
	private void processTasksAndTypes(List commands) {
830
		String arg = getArgument(commands, "-eclipseTask"); //$NON-NLS-1$
831
		while (arg != null) {
832
			if (eclipseSpecifiedTasks == null) {
833
				eclipseSpecifiedTasks= new HashMap();
834
			}
835
			int index= arg.indexOf(',');
836
			if (index != -1) {
837
				String name= arg.substring(0, index);
838
				String className= arg.substring(index + 1);
839
				eclipseSpecifiedTasks.put(name, className);
840
			}
841
			arg = getArgument(commands, "-eclipseTask"); //$NON-NLS-1$
842
		}
843
		
844
		arg = getArgument(commands, "-eclipseType"); //$NON-NLS-1$
845
		while (arg != null) {
846
			if (eclipseSpecifiedTypes == null) {
847
				eclipseSpecifiedTypes= new HashMap();
848
			}
849
			int index= arg.indexOf(',');
850
			if (index != -1) {	
851
				String name= arg.substring(0, index);
852
				String className= arg.substring(index + 1);
853
				eclipseSpecifiedTypes.put(name, className);
854
			}
855
			arg = getArgument(commands, "-eclipseType"); //$NON-NLS-1$
856
		}
857
	}
858
859
	/*
860
	 * Checks for unrecognized arguments on the command line.
861
	 * Since there is no syntactic way to distingush between
862
	 * ant -foo target1 target2
863
	 * ant -foo fooarg target
864
	 * we remove everything up to the last argument that
865
	 * begins with a '-'.  In the latter case, above, that
866
	 * means that there will be an extra target, 'fooarg',
867
	 * left lying around.
868
	 */
869
	private void processUnrecognizedCommands(List commands) {
870
		int p = -1;
871
872
		// find the last arg that begins with '-'
873
		for (int i = commands.size() - 1; i >= 0; i--) {
874
			if (((String) commands.get(0)).startsWith("-")) { //$NON-NLS-1$
875
				p = i;
876
				break;
877
			}
878
		}
879
		if (p < 0) { return; }
880
881
		// remove everything preceding that last '-arg'
882
		String s = ""; //$NON-NLS-1$
883
		for (int i = 0; i <= p; i++) {
884
			s += " " + ((String) commands.get(0)); //$NON-NLS-1$
885
			commands.remove(0);
886
		}
887
		
888
		// warn of ignored commands
889
		String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unknown_argument__{0}_2"), new Object[]{ s.substring(1) }); //$NON-NLS-1$
890
		logMessage(currentProject, message, Project.MSG_WARN); 
891
	}
892
	
893
894
	/*
895
	 * Checks for targets specified at the command line.
896
	 */
897
	private void processTargets(List commands) {
898
		if (targets == null) {
899
			targets = new Vector(commands.size());
900
		}
901
		for (Iterator iter = commands.iterator(); iter.hasNext();) {
902
			targets.add(iter.next());
903
		}
904
	}
905
906
	/*
907
	 * Creates the log file with the name specified by the user.
908
	 * If the fileName is not absolute, the file will be created in the
909
	 * working directory if specified or in the same directory as the location
910
	 * of the build file.
911
	 */
912
	private void createLogFile(String fileName) throws FileNotFoundException, IOException {
913
		File logFile = getFileRelativeToBaseDir(fileName);
914
		
915
		//this stream is closed in the finally block of run(list)
916
		out = new PrintStream(new FileOutputStream(logFile));
917
		err = out;
918
		logMessage(getCurrentProject(), MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Using_{0}_file_as_build_log._1"), new String[]{logFile.getCanonicalPath()}), Project.MSG_INFO); //$NON-NLS-1$
919
		if (buildLogger != null) {
920
			buildLogger.setErrorPrintStream(err);
921
			buildLogger.setOutputPrintStream(out);
922
		}
923
	}
924
925
	private File getFileRelativeToBaseDir(String fileName) {
926
		File parentFile= null;
927
		
928
		String base= getCurrentProject().getUserProperty("basedir"); //$NON-NLS-1$
929
		if (base != null) {
930
			parentFile= new File(base);
931
		} else {
932
			//relative to the build file location
933
			parentFile= new File(getBuildFileLocation()).getParentFile();
934
		}
935
		
936
		//remain backwards compatible for older Ant usage
937
		return FileUtils.newFileUtils().resolveFile(parentFile, fileName);
938
	}
939
940
	/*
941
	 * Processes cmd line properties and adds the user properties
942
	 * Any user properties that have been explicitly set are set as well.
943
	 * Ensures that -D properties take precedence.
944
	 */
945
	private boolean processProperties(List commands) {
946
        boolean exceptionToBeThrown= false;
947
		//MULTIPLE property files are allowed
948
		String arg= getArgument(commands, "-propertyfile"); //$NON-NLS-1$
949
		while (arg != null) {
950
			if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
951
				fEarlyErrorMessage= RemoteAntMessages.getString("InternalAntRunner.Specifying_property_files_is_a_Ant_1.5.*_feature._Please_update_your_Ant_classpath._6"); //$NON-NLS-1$
952
				break;
953
			}
954
			if (arg.length() == 0) {
955
                fEarlyErrorMessage= RemoteAntMessages.getString("InternalAntRunner.You_must_specify_a_property_filename_when_using_the_-propertyfile_argument_3"); //$NON-NLS-1$
956
                exceptionToBeThrown= true;
957
                break;
958
			} 
959
			
960
			propertyFiles.add(arg);
961
			arg= getArgument(commands, "-propertyfile"); //$NON-NLS-1$
962
		}
963
        
964
        if (propertyFiles != null && !propertyFiles.isEmpty()) {
965
            loadPropertyFiles();
966
        }
967
        
968
        if (commands != null) {
969
            processMinusDProperties(commands);
970
        }
971
        return exceptionToBeThrown;
972
	}
973
974
	private void processMinusDProperties(List commands) {
975
		String[] args = (String[]) commands.toArray(new String[commands.size()]);
976
		for (int i = 0; i < args.length; i++) {
977
			String arg = args[i];
978
			if (arg.startsWith("-D")) { //$NON-NLS-1$
979
				String name = arg.substring(2, arg.length());
980
				String value = null;
981
				int posEq = name.indexOf("="); //$NON-NLS-1$
982
				if (posEq == 0) {
983
					value= name.substring(1);
984
					name= ""; //$NON-NLS-1$
985
				} else if (posEq > 0 && posEq != name.length() - 1) {
986
					value = name.substring(posEq + 1).trim();
987
					name = name.substring(0, posEq);
988
				}
989
				
990
				if (value == null) {
991
					//the user has specified something like "-Debug"
992
					continue;
993
				}
994
				if (userProperties == null) {
995
					userProperties= new HashMap();
996
				}
997
				userProperties.put(name, value);
998
				commands.remove(args[i]);
999
			}
1000
		}
1001
	}
1002
	
1003
	private void setProperties(Project project) {
1004
		setBuiltInProperties(project);
1005
		if (userProperties != null) {
1006
			for (Iterator iterator = userProperties.entrySet().iterator(); iterator.hasNext();) {
1007
				Map.Entry entry = (Map.Entry) iterator.next();
1008
				project.setUserProperty((String) entry.getKey(), (String) entry.getValue());
1009
			}
1010
		} 
1011
	}
1012
1013
	private void setBuiltInProperties(Project project) {
1014
		project.setUserProperty("ant.file", getBuildFileLocation()); //$NON-NLS-1$
1015
		project.setUserProperty("ant.version", Main.getAntVersion()); //$NON-NLS-1$
1016
	}
1017
1018
	/*
1019
	 * Print the project description, if any
1020
	 */
1021
	private void printHelp(Project project) {
1022
		if (project.getDescription() != null) {
1023
			logMessage(project, project.getDescription(), Project.MSG_INFO);
1024
		}
1025
		printTargets(project);
1026
	}
1027
1028
	/*
1029
	 * Logs a message with the client indicating the version of <b>Ant</b> that this class
1030
	 * fronts.
1031
	 */
1032
	private void printVersion() {
1033
		logMessage(getCurrentProject(), Main.getAntVersion(), Project.MSG_INFO);
1034
	}
1035
1036
	/*
1037
	 * Logs a message with the client outlining the usage of <b>Ant</b>.
1038
	 */
1039
	private void printUsage() {
1040
		String lSep = System.getProperty("line.separator"); //$NON-NLS-1$
1041
		StringBuffer msg = new StringBuffer();
1042
		msg.append("ant ["); //$NON-NLS-1$
1043
		msg.append(RemoteAntMessages.getString("InternalAntRunner.options_13")); //$NON-NLS-1$
1044
		msg.append("] ["); //$NON-NLS-1$
1045
		msg.append(RemoteAntMessages.getString("InternalAntRunner.target_15")); //$NON-NLS-1$
1046
		msg.append(" ["); //$NON-NLS-1$
1047
		msg.append(RemoteAntMessages.getString("InternalAntRunner.target_15")); //$NON-NLS-1$
1048
		msg.append("2 ["); //$NON-NLS-1$
1049
		msg.append(RemoteAntMessages.getString("InternalAntRunner.target_15")); //$NON-NLS-1$
1050
		msg.append("3] ...]]"); //$NON-NLS-1$
1051
		msg.append(lSep);
1052
		msg.append(RemoteAntMessages.getString("InternalAntRunner.Options___21")); //$NON-NLS-1$
1053
		msg.append(lSep);
1054
		msg.append("\t-help, -h\t\t\t\t"); //$NON-NLS-1$
1055
		msg.append(RemoteAntMessages.getString("InternalAntRunner.print_this_message_23")); //$NON-NLS-1$
1056
		msg.append(lSep);
1057
		msg.append("\t-projecthelp, -p\t\t"); //$NON-NLS-1$
1058
		msg.append(RemoteAntMessages.getString("InternalAntRunner.print_project_help_information_25")); //$NON-NLS-1$
1059
		msg.append(lSep);
1060
		msg.append("\t-version\t\t\t\t"); //$NON-NLS-1$
1061
		msg.append(RemoteAntMessages.getString("InternalAntRunner.print_the_version_information_and_exit_27")); //$NON-NLS-1$
1062
		msg.append(lSep); 
1063
		msg.append("\t-diagnostics\t\t\t"); //$NON-NLS-1$
1064
		msg.append(RemoteAntMessages.getString("InternalAntRunner.12")); //$NON-NLS-1$
1065
		msg.append(lSep);
1066
		msg.append(RemoteAntMessages.getString("InternalAntRunner.13")); //$NON-NLS-1$
1067
		msg.append(lSep);
1068
		msg.append("\t-quiet, -q\t\t\t"); //$NON-NLS-1$
1069
		msg.append(RemoteAntMessages.getString("InternalAntRunner.be_extra_quiet_29")); //$NON-NLS-1$
1070
		msg.append(lSep);
1071
		msg.append("\t-verbose, -v\t\t\t"); //$NON-NLS-1$
1072
		msg.append(RemoteAntMessages.getString("InternalAntRunner.be_extra_verbose_31")); //$NON-NLS-1$
1073
		msg.append(lSep);
1074
		msg.append("\t-debug, -d\t\t\t"); //$NON-NLS-1$
1075
		msg.append(RemoteAntMessages.getString("InternalAntRunner.print_debugging_information_33")); //$NON-NLS-1$
1076
		msg.append(lSep);
1077
		msg.append("\t-emacs, -e\t\t\t"); //$NON-NLS-1$
1078
		msg.append(RemoteAntMessages.getString("InternalAntRunner.produce_logging_information_without_adornments_35")); //$NON-NLS-1$
1079
		msg.append(lSep);
1080
		msg.append("\t-logfile\t<file>\t\t"); //$NON-NLS-1$
1081
		msg.append(RemoteAntMessages.getString("InternalAntRunner.use_given_file_for_log_37")); //$NON-NLS-1$
1082
		msg.append(lSep);
1083
		msg.append("\t\t-l\t<file>"); //$NON-NLS-1$
1084
		msg.append(RemoteAntMessages.getString("InternalAntRunner.1")); //$NON-NLS-1$
1085
		msg.append(lSep);  
1086
		msg.append("\t-logger <classname>\t\t"); //$NON-NLS-1$
1087
		msg.append(RemoteAntMessages.getString("InternalAntRunner.the_class_which_is_to_perform_logging_39")); //$NON-NLS-1$
1088
		msg.append(lSep);  
1089
		msg.append("\t-listener <classname>\t"); //$NON-NLS-1$
1090
		msg.append(RemoteAntMessages.getString("InternalAntRunner.add_an_instance_of_class_as_a_project_listener_41")); //$NON-NLS-1$
1091
		msg.append(lSep);
1092
		msg.append("\t-noinput\t"); //$NON-NLS-1$
1093
		msg.append(RemoteAntMessages.getString("InternalAntRunner.158")); //$NON-NLS-1$
1094
		msg.append(lSep); 
1095
		msg.append("\t-buildfile\t<file>\t"); //$NON-NLS-1$
1096
		msg.append(RemoteAntMessages.getString("InternalAntRunner.use_given_buildfile_43")); //$NON-NLS-1$
1097
		msg.append(lSep); 
1098
		msg.append("\t\t-file\t<file>"); //$NON-NLS-1$
1099
		msg.append(RemoteAntMessages.getString("InternalAntRunner.1")); //$NON-NLS-1$
1100
		msg.append(lSep);
1101
		msg.append("\t\t-f\t\t<file>"); //$NON-NLS-1$
1102
		msg.append(RemoteAntMessages.getString("InternalAntRunner.1")); //$NON-NLS-1$
1103
		msg.append(lSep);
1104
		msg.append("\t-D<property>=<value>\t"); //$NON-NLS-1$
1105
		msg.append(RemoteAntMessages.getString("InternalAntRunner.use_value_for_given_property_45")); //$NON-NLS-1$
1106
		msg.append(lSep);
1107
		msg.append("\t-keep-going, -k"); //$NON-NLS-1$
1108
		msg.append(RemoteAntMessages.getString("InternalAntRunner.159")); //$NON-NLS-1$
1109
		msg.append(lSep);
1110
		msg.append(RemoteAntMessages.getString("InternalAntRunner.160")); //$NON-NLS-1$
1111
		msg.append(lSep); 
1112
		msg.append("\t-propertyfile <name>\t"); //$NON-NLS-1$
1113
		msg.append(RemoteAntMessages.getString("InternalAntRunner.19")); //$NON-NLS-1$
1114
		msg.append(lSep);
1115
		msg.append(RemoteAntMessages.getString("InternalAntRunner.20")); //$NON-NLS-1$
1116
		msg.append(lSep);
1117
		msg.append("\t-inputhandler <class>\t"); //$NON-NLS-1$
1118
		msg.append(RemoteAntMessages.getString("InternalAntRunner.22")); //$NON-NLS-1$
1119
		msg.append(lSep);
1120
1121
		logMessage(getCurrentProject(), msg.toString(), Project.MSG_INFO);
1122
	}
1123
1124
	/*
1125
	 * From a command line list, return the argument for the given parameter.
1126
	 * The parameter and its argument are removed from the list.
1127
	 * 
1128
	 * @return <code>null</code> if the parameter is not found 
1129
	 * 			or an empty String if no arguments are found
1130
	 */
1131
	private String getArgument(List commands, String param) {
1132
		if (commands == null) {
1133
			return null;
1134
		}
1135
		int index = commands.indexOf(param);
1136
		if (index == -1) {
1137
			return null;
1138
		}
1139
		commands.remove(index);
1140
		if (index == commands.size()) {// if this is the last command
1141
			return ""; //$NON-NLS-1$
1142
		}
1143
		
1144
		String command = (String) commands.get(index);
1145
		if (command.startsWith("-")) { //new parameter //$NON-NLS-1$
1146
			return ""; //$NON-NLS-1$
1147
		}
1148
		
1149
		commands.remove(index);
1150
		return command;
1151
	}
1152
1153
	/*
1154
	 * Helper method to ensure an array is converted into an ArrayList.
1155
	 */
1156
	private static ArrayList getArrayList(String[] args) {
1157
		if (args == null) {
1158
			return null;
1159
		}
1160
		// We could be using Arrays.asList() here, but it does not specify
1161
		// what kind of list it will return. We need a list that
1162
		// implements the method List.remove(Object) and ArrayList does.
1163
		ArrayList result = new ArrayList(args.length);
1164
		for (int i = 0; i < args.length; i++) {
1165
			result.add(args[i]);
1166
		}
1167
		return result;
1168
	}
1169
1170
	private Project getCurrentProject() {
1171
		return currentProject;
1172
	}
1173
1174
	private void setCurrentProject(Project currentProject) {
1175
		this.currentProject = currentProject;
1176
	}
1177
	
1178
	/**
1179
	 * Load all properties from the files 
1180
	 * specified by -propertyfile.
1181
	 */
1182
	private void loadPropertyFiles() {
1183
		Iterator itr= propertyFiles.iterator();
1184
        while (itr.hasNext()) {
1185
            String filename= (String) itr.next();
1186
           	File file= getFileRelativeToBaseDir(filename);
1187
            Properties props = new Properties();
1188
            FileInputStream fis = null;
1189
            try {
1190
                fis = new FileInputStream(file);
1191
                props.load(fis);
1192
            } catch (IOException e) {
1193
            	fEarlyErrorMessage= MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_property_file_{0}__{1}_4"), new String[]{filename, e.getMessage()}); //$NON-NLS-1$
1194
            } finally {
1195
                if (fis != null) {
1196
                    try {
1197
                        fis.close();
1198
                    } catch (IOException e){
1199
                    }
1200
                }
1201
            }
1202
1203
            if (userProperties == null) {
1204
            	userProperties= new HashMap();
1205
            }
1206
            Enumeration propertyNames = props.propertyNames();
1207
            while (propertyNames.hasMoreElements()) {
1208
                String name = (String) propertyNames.nextElement();
1209
                //most specific to global
1210
                //do not overwrite specific with a global property
1211
                if (userProperties.get(name) == null) {
1212
            		userProperties.put(name, props.getProperty(name));
1213
                }
1214
            }
1215
        }
1216
	}
1217
	
1218
	/*
1219
     * Creates the InputHandler and adds it to the project.
1220
     *
1221
     * @exception BuildException if a specified InputHandler
1222
     *                           implementation could not be loaded.
1223
     */
1224
    private void addInputHandler(Project project) {
1225
    	if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
1226
			return;
1227
		}
1228
		InputHandlerSetter setter= new InputHandlerSetter();
1229
		setter.setInputHandler(project, inputHandlerClassname);
1230
    }
1231
}
(-)remote/org/eclipse/ant/internal/launching/remote/RemoteAntMessages.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote;
12
13
14
import java.util.MissingResourceException;
15
import java.util.ResourceBundle;
16
17
public class RemoteAntMessages {
18
19
	private static final String BUNDLE_NAME = "org.eclipse.ant.internal.launching.remote.RemoteAntMessages"; //$NON-NLS-1$
20
21
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
22
23
	private RemoteAntMessages() {
24
	}
25
26
	public static String getString(String key) {
27
		try {
28
			return RESOURCE_BUNDLE.getString(key);
29
		} catch (MissingResourceException e) {
30
			return '!' + key + '!';
31
		}
32
	}
33
}
(-)remote/org/eclipse/ant/internal/launching/remote/RemoteAntMessages.properties (+76 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
InternalAntRunner.Build_file__{0}_1=Buildfile: {0}
13
InternalAntRunner.Arguments__{0}_2=Arguments: {0}
14
InternalAntRunner.Default_target__3=Default target:
15
InternalAntRunner.Main_targets__4=Main targets:
16
InternalAntRunner.Subtargets__5=Subtargets:
17
InternalAntRunner.Unable_to_instantiate_logger__{0}_6=Unable to instantiate logger: {0}
18
InternalAntRunner.Could_not_load_the_version_information._{0}_9=Could not load the version information. {0}
19
InternalAntRunner.Could_not_load_the_version_information._10=Could not load the version information.
20
InternalAntRunner.options_13=options
21
InternalAntRunner.target_15=target
22
InternalAntRunner.Options___21=Options: 
23
InternalAntRunner.print_this_message_23=print this message
24
InternalAntRunner.print_project_help_information_25=print project help information
25
InternalAntRunner.print_the_version_information_and_exit_27=print the version information and exit
26
InternalAntRunner.be_extra_quiet_29=be extra quiet
27
InternalAntRunner.be_extra_verbose_31=be extra verbose
28
InternalAntRunner.print_debugging_information_33=print debugging information
29
InternalAntRunner.produce_logging_information_without_adornments_35=produce logging information without adornments
30
InternalAntRunner.use_given_file_for_log_37=use given file for log
31
InternalAntRunner.the_class_which_is_to_perform_logging_39=the class which is to perform logging
32
InternalAntRunner.add_an_instance_of_class_as_a_project_listener_41=add an instance of class as a project listener
33
InternalAntRunner.use_given_buildfile_43=use given buildfile
34
InternalAntRunner.use_value_for_given_property_45=use value for given property
35
InternalAntRunner.Using_{0}_file_as_build_log._1=Using {0} file as build log.
36
InternalAntRunner.Could_not_write_to_the_specified_log_file__{0}._Make_sure_the_path_exists_and_you_have_write_permissions._2=Cannot write on the specified log file: {0}. Make sure the path exists and you have write permissions.
37
InternalAntRunner.BUILD_SUCCESSFUL_1=BUILD SUCCESSFUL
38
InternalAntRunner.Unknown_argument__{0}_2=Unknown argument: {0}
39
InternalAntRunner.Buildfile__{0}_does_not_exist_!_1=Buildfile: {0} does not exist
40
InternalAntRunner.{0}_which_was_specified_to_be_a_build_listener_is_not_an_instance_of_org.apache.tools.ant.BuildListener._1={0} which was specified to be a build listener is not an instance of org.apache.tools.ant.BuildListener.
41
InternalAntRunner.{0}_which_was_specified_to_perform_logging_is_not_an_instance_of_org.apache.tools.ant.BuildLogger._2={0} which was specified to perform logging is not an instance of org.apache.tools.ant.BuildLogger.
42
InternalAntRunner.You_must_specify_a_classname_when_using_the_-listener_argument_1=You must specify a classname when using the -listener argument
43
InternalAntRunner.You_must_specify_a_log_file_when_using_the_-log_argument_3=You must specify a log file when using the -log argument
44
InternalAntRunner.You_must_specify_a_buildfile_when_using_the_-buildfile_argument_4=You must specify a buildfile when using the -buildfile argument
45
InternalAntRunner.12=print information that might be helpful to
46
InternalAntRunner.13=\t\t\t\t\t\t\tdiagnose or report problems.
47
InternalAntRunner.19=load all properties from file with -D
48
InternalAntRunner.20=\t\t\t\t\t\t\tproperties taking precedence
49
InternalAntRunner.22=the class which will handle input requests
50
InternalAntRunner.1=\t\t\t\t\'
51
InternalAntRunner.Only_one_logger_class_may_be_specified_1=Only one logger class may be specified
52
InternalAntRunner.You_must_specify_a_classname_when_using_the_-inputhandler_argument_1=You must specify a classname when using the -inputhandler argument
53
InternalAntRunner.Only_one_input_handler_class_may_be_specified._2=Only one input handler class may be specified.
54
InternalAntRunner.You_must_specify_a_property_filename_when_using_the_-propertyfile_argument_3=You must specify a property filename when using the -propertyfile argument
55
InternalAntRunner.Could_not_load_property_file_{0}__{1}_4=Could not load property file {0}: {1}
56
InternalAntRunner.The_specified_input_handler_class_{0}_does_not_implement_the_org.apache.tools.ant.input.InputHandler_interface_5=The specified input handler class {0} does not implement the org.apache.tools.ant.input.InputHandler interface
57
InternalAntRunner.Unable_to_instantiate_specified_input_handler_class_{0}___{1}_6=Unable to instantiate specified input handler class {0} : {1}
58
InternalAntRunner.The_diagnositics_options_is_an_Ant_1.5.*_feature._Please_update_your_Ant_classpath_to_include_an_Ant_version_greater_than_this._4=The diagnostics options is an Ant 1.5.* feature. Please update your Ant classpath to include an Ant version greater than this.
59
InternalAntRunner.Specifying_property_files_is_a_Ant_1.5.*_feature._Please_update_your_Ant_classpath._6=Specifying property files is a Ant 1.5.* feature. Please update your Ant classpath to include an Ant version greater than this.
60
InternalAntRunner.ANT_HOME_must_be_set_to_use_Ant_diagnostics_2=ANT_HOME must be set to use Ant diagnostics
61
InternalAntRunner.Buildfile__{0}_is_not_a_file_1=Buildfile: {0} is not a file
62
InternalAntRunner.-find_not_supported=-find not supported.\nCan be emulated using Run As > Ant Build located\nin the Run > External Tools menu
63
InternalAntRunner.157=-lib not supported\nConfigure the Ant runtime classpath using either the\nglobal Ant runtime classpath or the Ant runtime classpath\n for this particular build
64
InternalAntRunner.158=\t\t\tdo not allow interactive input
65
InternalAntRunner.159=\t\texecute all targets that do not depend
66
InternalAntRunner.160=\t\t\t\t\t\ton failed target(s)
67
InternalAntRunner.161=Class {0} not found for task {1}
68
InternalAntRunner.162=Class {0} not found for type {1}
69
70
RemoteAntBuildLogger.1=BUILD FAILED
71
RemoteAntBuildLogger.Total_time=Total time: 
72
RemoteAntBuildLogger._minutes_2=\ minutes
73
RemoteAntBuildLogger._minute_3=\ minute
74
RemoteAntBuildLogger._seconds_4=\ seconds
75
RemoteAntBuildLogger._second_5=\ second
76
RemoteAntBuildLogger._milliseconds_6=\ milliseconds
(-)remote/org/eclipse/ant/internal/launching/remote/inputhandler/FailInputHandler.java (+29 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.launching.remote.inputhandler;
13
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import org.apache.tools.ant.input.DefaultInputHandler;
18
19
public class FailInputHandler extends DefaultInputHandler {
20
	
21
	protected InputStream getInputStream() {
22
		//ensure any attempts to read input fail
23
		return new InputStream(){
24
			public int read() throws IOException {
25
				throw new IOException();
26
			}
27
		};
28
	}
29
}
(-)remote/org/eclipse/ant/internal/launching/remote/logger/MessageIds.java (+21 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote.logger;
12
13
14
public class MessageIds {
15
16
	public final static String PROCESS_ID=   "processID"; //$NON-NLS-1$
17
	public final static String BUILD_CANCELLED= "cancelled"; //$NON-NLS-1$
18
    //constants need to start greater than the Project.MSG_* constants
19
	public final static String TASK= "6"; //$NON-NLS-1$
20
	public final static String TARGET= "7"; //$NON-NLS-1$
21
}
(-)remote/org/eclipse/ant/internal/launching/remote/logger/RemoteAntBreakpoint.java (+74 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote.logger;
12
13
import java.io.File;
14
15
import org.eclipse.ant.internal.launching.debug.DebugMessageIds;
16
17
public class RemoteAntBreakpoint {
18
	
19
    private File fFile;
20
	private int fLineNumber;
21
	private String fFileName;
22
	
23
	public RemoteAntBreakpoint(String breakpointRepresentation) {
24
		String[] data= breakpointRepresentation.split(DebugMessageIds.MESSAGE_DELIMITER);
25
		String fileName= data[1];
26
		String lineNumber= data[2];
27
		fFileName= fileName;
28
		fFile= new File(fileName);
29
		fLineNumber= Integer.parseInt(lineNumber);
30
	}
31
32
	public boolean isAt(String fileName, int lineNumber) {
33
		return fLineNumber == lineNumber && fileName != null && fFile.equals(new File(fileName));
34
	}
35
	
36
	public String toMarshallString() {
37
		StringBuffer buffer= new StringBuffer(DebugMessageIds.BREAKPOINT);
38
		buffer.append(DebugMessageIds.MESSAGE_DELIMITER);
39
		buffer.append(fFileName);
40
		buffer.append(DebugMessageIds.MESSAGE_DELIMITER);
41
		buffer.append(fLineNumber);
42
		return buffer.toString();
43
	}
44
	
45
	/* (non-Javadoc)
46
	 * @see java.lang.Object#equals(java.lang.Object)
47
	 */
48
	public boolean equals(Object obj) {
49
		if (!(obj instanceof RemoteAntBreakpoint)) {
50
			return false;
51
		}
52
		RemoteAntBreakpoint other= (RemoteAntBreakpoint) obj;
53
		return other.getLineNumber() == fLineNumber && other.getFile().equals(fFile);
54
	}
55
	
56
	/* (non-Javadoc)
57
	 * @see java.lang.Object#hashCode()
58
	 */
59
	public int hashCode() {
60
		return fFileName.hashCode() + fLineNumber;
61
	}
62
	
63
	public int getLineNumber() {
64
		return fLineNumber;
65
	}
66
67
	public String getFileName() {
68
		return fFileName;
69
	}
70
	
71
	public File getFile() {
72
	    return fFile;
73
	}
74
}
(-)remote/org/eclipse/ant/internal/launching/remote/logger/RemoteAntBuildLogger.java (+396 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote.logger;
12
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.PrintStream;
17
import java.io.PrintWriter;
18
import java.io.StringReader;
19
import java.net.Socket;
20
import java.util.ArrayList;
21
import java.util.Iterator;
22
import java.util.List;
23
import java.util.Map;
24
25
import org.apache.tools.ant.BuildEvent;
26
import org.apache.tools.ant.BuildException;
27
import org.apache.tools.ant.DefaultLogger;
28
import org.apache.tools.ant.Location;
29
import org.apache.tools.ant.Project;
30
import org.apache.tools.ant.Target;
31
import org.apache.tools.ant.util.StringUtils;
32
import org.eclipse.ant.internal.launching.debug.AntDebugState;
33
import org.eclipse.ant.internal.launching.remote.AntSecurityException;
34
import org.eclipse.ant.internal.launching.remote.InternalAntRunner;
35
import org.eclipse.ant.internal.launching.remote.RemoteAntMessages;
36
37
/**
38
 * Parts adapted from org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
39
 * A build logger that reports via a socket connection.
40
 * See MessageIds for more information about the protocol.
41
 */
42
public class RemoteAntBuildLogger extends DefaultLogger {
43
44
    /** Time of the start of the build */
45
    private long fStartTime = System.currentTimeMillis();
46
47
    /**
48
     * The client socket.
49
     */
50
    private Socket fEventSocket;
51
    /**
52
     * Print writer for sending messages
53
     */
54
    private PrintWriter fWriter;
55
    /**
56
     * Host to connect to, default is the localhost
57
     */
58
    protected String fHost= ""; //$NON-NLS-1$
59
    /**
60
     * Port to connect to.
61
     */
62
    private int fEventPort= -1;
63
    
64
    private String fProcessId= null;
65
    
66
    /**
67
     * Is the debug mode enabled?
68
     */
69
    protected boolean fDebugMode= false;    
70
    
71
    protected boolean fSentProcessId= false;
72
    
73
    private List fEventQueue;
74
    
75
    private String fLastFileName= null;
76
    private String fLastTaskName= null;
77
    
78
    /* (non-Javadoc)
79
     * @see org.apache.tools.ant.DefaultLogger#printMessage(java.lang.String, java.io.PrintStream, int)
80
     */
81
    protected void printMessage(String message, PrintStream stream, int priority) {
82
        marshalMessage(priority, message);
83
    }
84
    
85
    /**
86
     * Connect to the remote Ant build listener.
87
     */
88
    protected void connect() {
89
        if (fDebugMode) {
90
            System.out.println("RemoteAntBuildLogger: trying to connect" + fHost + ":" + fEventPort); //$NON-NLS-1$ //$NON-NLS-2$
91
        }
92
        
93
        for (int i= 1; i < 5; i++) {
94
            try{
95
                fEventSocket= new Socket(fHost, fEventPort);
96
                fWriter= new PrintWriter(fEventSocket.getOutputStream(), true);
97
                return;
98
            } catch(IOException e){
99
            }
100
            try {
101
                Thread.sleep(500);
102
            } catch(InterruptedException e) {
103
            }
104
        }
105
        shutDown();
106
    }
107
108
    /**
109
     * Shutdown the connection to the remote build listener.
110
     */
111
    protected void shutDown() {
112
        if (fEventQueue != null) {
113
            fEventQueue.clear();
114
        }
115
        if (fWriter != null) {
116
            fWriter.close();
117
            fWriter= null;
118
        }
119
        
120
        try {
121
            if (fEventSocket != null) {
122
                fEventSocket.close();
123
                fEventSocket= null;
124
            }
125
        } catch(IOException e) {
126
        }
127
    }
128
129
    private void sendMessage(String msg) {
130
        if (fWriter == null) {
131
            return;
132
        }
133
        
134
        fWriter.println(msg);
135
    }
136
    
137
    /* (non-Javadoc)
138
     * @see org.apache.tools.ant.BuildListener#buildFinished(org.apache.tools.ant.BuildEvent)
139
     */
140
    public void buildFinished(BuildEvent event) {
141
        if (!fSentProcessId) {
142
            establishConnection();
143
        }
144
        handleException(event);
145
        printMessage( getTimeString(System.currentTimeMillis() - fStartTime), out, Project.MSG_INFO); 
146
        shutDown();
147
    }
148
    
149
    protected void handleException(BuildEvent event) {
150
        Throwable exception = event.getException();
151
        if (exception == null || exception instanceof AntSecurityException) {
152
            return;
153
        }
154
        
155
         StringBuffer message= new StringBuffer();
156
         message.append(StringUtils.LINE_SEP);
157
         message.append(RemoteAntMessages.getString("RemoteAntBuildLogger.1")); //$NON-NLS-1$
158
         message.append(StringUtils.LINE_SEP);
159
         if (Project.MSG_VERBOSE <= this.msgOutputLevel || !(exception instanceof BuildException)) {
160
             message.append(StringUtils.getStackTrace(exception));
161
         } else {
162
             if (exception instanceof BuildException) {
163
                 message.append(exception.toString()).append(StringUtils.LINE_SEP);
164
             } else {
165
                 message.append(exception.getMessage()).append(StringUtils.LINE_SEP);
166
             }
167
         }
168
        message.append(StringUtils.LINE_SEP);
169
        printMessage(message.toString(), out, Project.MSG_ERR); 
170
    }
171
    
172
    private String getTimeString(long milliseconds) {
173
        long seconds = milliseconds / 1000;
174
        long minutes = seconds / 60;
175
        seconds= seconds % 60;
176
177
        StringBuffer result= new StringBuffer(RemoteAntMessages.getString("RemoteAntBuildLogger.Total_time")); //$NON-NLS-1$
178
        if (minutes > 0) {
179
            result.append(minutes);
180
            if (minutes > 1) {
181
                result.append(RemoteAntMessages.getString("RemoteAntBuildLogger._minutes_2")); //$NON-NLS-1$
182
            } else {
183
                result.append(RemoteAntMessages.getString("RemoteAntBuildLogger._minute_3")); //$NON-NLS-1$
184
            }
185
        }
186
        if (seconds > 0) {
187
            if (minutes > 0) {
188
                result.append(' ');
189
            }
190
            result.append(seconds);
191
    
192
            if (seconds > 1) {
193
                result.append(RemoteAntMessages.getString("RemoteAntBuildLogger._seconds_4")); //$NON-NLS-1$
194
            } else {
195
                result.append(RemoteAntMessages.getString("RemoteAntBuildLogger._second_5")); //$NON-NLS-1$
196
            } 
197
        }
198
        if (seconds == 0 && minutes == 0) {
199
            result.append(milliseconds);
200
            result.append(RemoteAntMessages.getString("RemoteAntBuildLogger._milliseconds_6"));      //$NON-NLS-1$
201
        }
202
        return result.toString();
203
    }
204
            
205
206
    /* (non-Javadoc)
207
     * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
208
     */
209
    public void targetStarted(BuildEvent event) {
210
        if (!fSentProcessId) {
211
            establishConnection();
212
        }
213
214
        if (Project.MSG_INFO <= msgOutputLevel) {
215
            marshalTargetMessage(event);
216
        }
217
    }
218
219
    protected void establishConnection() {
220
        if (fEventPort != -1) {
221
            connect();
222
        } else {
223
            shutDown();
224
            return;
225
        }
226
        
227
        fSentProcessId= true;
228
        StringBuffer message= new StringBuffer(MessageIds.PROCESS_ID);
229
        message.append(fProcessId);
230
        sendMessage(message.toString());
231
        if (fEventQueue != null) {
232
            for (Iterator iter = fEventQueue.iterator(); iter.hasNext();) {
233
                processEvent((BuildEvent)iter.next());
234
            }
235
            fEventQueue= null;
236
        }
237
    }
238
239
    /* (non-Javadoc)
240
     * @see org.apache.tools.ant.BuildListener#messageLogged(org.apache.tools.ant.BuildEvent)
241
     */
242
    public void messageLogged(BuildEvent event) {
243
        if (event.getPriority() > msgOutputLevel && event.getPriority() != InternalAntRunner.MSG_PROJECT_HELP) {
244
            return;
245
        }
246
        
247
        if (!fSentProcessId) {
248
            if (event.getPriority() == InternalAntRunner.MSG_PROJECT_HELP) {
249
                if (Project.MSG_INFO > msgOutputLevel) {
250
                    return;
251
                }
252
                //no buildstarted or project started for project help option
253
                establishConnection();
254
                return;
255
            }
256
            if (fEventQueue == null){
257
                fEventQueue= new ArrayList(10);
258
            }
259
            fEventQueue.add(event);
260
            return;
261
        }
262
        
263
        processEvent(event);
264
    }
265
266
    private void processEvent(BuildEvent event) {
267
        if (event.getTask() != null & !emacsMode) {
268
            try {
269
                marshalTaskMessage(event);
270
            } catch (IOException e) {
271
            }
272
        } else {
273
            marshalMessage(event);
274
        }
275
    }
276
    
277
    private void marshalMessage(BuildEvent event) {
278
        String eventMessage= event.getMessage();
279
        if (eventMessage.length() == 0) {
280
            return;
281
        }
282
        marshalMessage(event.getPriority(), eventMessage);
283
    }
284
285
    protected void marshalMessage(int priority, String message) {
286
        try {
287
            BufferedReader r = new BufferedReader(new StringReader(message));
288
            String line = r.readLine();
289
            StringBuffer messageLine;
290
            while (line != null) {
291
                messageLine= new StringBuffer();
292
                if (priority != -1) {
293
                    messageLine.append(priority);
294
                    messageLine.append(',');
295
                }
296
                messageLine.append(line);
297
                sendMessage(messageLine.toString());
298
                line = r.readLine();
299
            }
300
        } catch (IOException e) {
301
        }
302
    }
303
304
    private void marshalTaskMessage(BuildEvent event) throws IOException {
305
        String eventMessage= event.getMessage();
306
        if (eventMessage.length() == 0) {
307
            return;
308
        }
309
        BufferedReader r = new BufferedReader(new StringReader(eventMessage));
310
        String line = r.readLine();
311
        StringBuffer message;
312
        String taskName= event.getTask().getTaskName();
313
        if (taskName != null && taskName.equals(fLastTaskName)) {
314
            taskName= ""; //$NON-NLS-1$
315
        } else {
316
            fLastTaskName= taskName;
317
        }
318
        Location location= event.getTask().getLocation();
319
        String fileName= null;
320
        int lineNumber= -1;
321
        try {
322
            fileName= location.getFileName();
323
            lineNumber= location.getLineNumber();
324
        } catch (NoSuchMethodError e) {
325
            //older Ant
326
            fileName= location.toString();
327
        }
328
        if (location.equals(Location.UNKNOWN_LOCATION)) {
329
            fileName= location.toString();
330
            lineNumber= -1;
331
        }
332
        int priority= event.getPriority();
333
        while (line != null) {
334
            message= new StringBuffer(MessageIds.TASK);
335
            message.append(priority);
336
            message.append(',');
337
            message.append(taskName);
338
            message.append(',');
339
            message.append(line.length());
340
            message.append(',');
341
            message.append(line);
342
            message.append(',');
343
            if (!fileName.equals(fLastFileName)) {
344
            	message.append(fileName.length());
345
            	message.append(',');
346
                message.append(fileName);
347
            } 
348
            message.append(',');
349
            message.append(lineNumber);
350
            sendMessage(message.toString());
351
            fLastFileName= fileName;
352
            line= r.readLine();
353
        }
354
    }
355
    
356
    private void marshalTargetMessage(BuildEvent event) {
357
        Target target= event.getTarget();
358
        Location location= AntDebugState.getLocation(target);
359
        
360
        StringBuffer message= new StringBuffer();
361
        message.append(MessageIds.TARGET);
362
        message.append(',');
363
        message.append(target.getName());
364
        message.append(':');
365
        message.append(',');
366
        if (location != null && location != Location.UNKNOWN_LOCATION) {
367
            //if a target has a valid location then we are on an Ant that is 
368
            //new enough to have the accessor methods on Location
369
        	String fileName= location.getFileName();
370
        	message.append(fileName.length());
371
        	message.append(',');
372
            message.append(fileName);
373
            message.append(',');
374
            message.append(location.getLineNumber());
375
        }
376
        sendMessage(message.toString());
377
    }
378
379
    /* (non-Javadoc)
380
     * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
381
     */
382
    public void buildStarted(BuildEvent event) {
383
        establishConnection();
384
        super.buildStarted(event);
385
    }
386
    
387
    public void configure(Map userProperties) {
388
        String portProperty= (String) userProperties.remove("eclipse.connect.port"); //$NON-NLS-1$
389
        
390
        if (portProperty != null) {
391
            fEventPort= Integer.parseInt(portProperty);
392
        }
393
        
394
        fProcessId= (String) userProperties.remove("org.eclipse.ant.core.ANT_PROCESS_ID"); //$NON-NLS-1$
395
    } 
396
}
(-)remote/org/eclipse/ant/internal/launching/remote/logger/RemoteAntDebugBuildLogger.java (+353 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.remote.logger;
12
13
import java.io.BufferedReader;
14
import java.io.IOException;
15
import java.io.InputStreamReader;
16
import java.io.PrintWriter;
17
import java.net.ServerSocket;
18
import java.net.Socket;
19
import java.net.SocketTimeoutException;
20
import java.util.ArrayList;
21
import java.util.Iterator;
22
import java.util.List;
23
import java.util.Map;
24
25
import org.apache.tools.ant.BuildEvent;
26
import org.apache.tools.ant.Location;
27
import org.apache.tools.ant.Task;
28
import org.eclipse.ant.internal.launching.debug.AntDebugState;
29
import org.eclipse.ant.internal.launching.debug.DebugMessageIds;
30
import org.eclipse.ant.internal.launching.debug.IDebugBuildLogger;
31
32
/**
33
 * Parts adapted from org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
34
 * A build logger that reports via a socket connection.
35
 * See DebugMessageIds and MessageIds for more information about the protocol.
36
 */
37
public class RemoteAntDebugBuildLogger extends RemoteAntBuildLogger implements IDebugBuildLogger {
38
	
39
	private ServerSocket fServerSocket;
40
	private static final int fgServerSocketTimeout= 5000;
41
	private Socket fRequestSocket;
42
	
43
	private PrintWriter fRequestWriter;
44
	
45
	private BufferedReader fRequestReader;
46
	
47
    private boolean fBuildStartedSuspend= true;
48
	
49
	private Task fStepOverTaskInterrupted;
50
	
51
	private List fBreakpoints= null;
52
	
53
	/**
54
	 * Request port to connect to.
55
	 * Used for debug connections
56
	 */
57
	private int fRequestPort= -1;
58
	private AntDebugState fDebugState;
59
60
	/**
61
	 * Reader thread that processes requests from the debug client.
62
	 */
63
	private class ReaderThread extends Thread {
64
		public ReaderThread() {
65
			super("ReaderThread"); //$NON-NLS-1$
66
			setDaemon(true);
67
		}
68
69
		public void run(){
70
			try { 
71
				String message= null; 
72
				while (fRequestReader != null) { 
73
					if ((message= fRequestReader.readLine()) != null) {
74
						
75
						if (message.startsWith(DebugMessageIds.STEP_INTO)){
76
							synchronized(RemoteAntDebugBuildLogger.this) {
77
								fDebugState.setStepIntoSuspend(true);
78
								fDebugState.setStepIntoTask(fDebugState.getCurrentTask());
79
								RemoteAntDebugBuildLogger.this.notifyAll();
80
							}
81
						} if (message.startsWith(DebugMessageIds.STEP_OVER)){
82
							synchronized(RemoteAntDebugBuildLogger.this) {
83
								fDebugState.stepOver();
84
							}
85
						} else if (message.startsWith(DebugMessageIds.SUSPEND)) {
86
							synchronized(RemoteAntDebugBuildLogger.this) {
87
								fDebugState.setStepIntoTask(null);
88
								fDebugState.setStepOverTask(null);
89
								fStepOverTaskInterrupted= null;
90
								fDebugState.setClientSuspend(true);
91
							}
92
						} else if (message.startsWith(DebugMessageIds.RESUME)) {
93
							synchronized(RemoteAntDebugBuildLogger.this) {
94
								fDebugState.setStepIntoTask(null);
95
								fDebugState.setStepOverTask(null);
96
								fStepOverTaskInterrupted= null;
97
								RemoteAntDebugBuildLogger.this.notifyAll();
98
							}
99
						} else if (message.startsWith(DebugMessageIds.TERMINATE)) {
100
						    sendRequestResponse(DebugMessageIds.TERMINATED);
101
							shutDown();
102
						} else if (message.startsWith(DebugMessageIds.STACK)) {
103
							marshallStack();
104
						} else if (message.startsWith(DebugMessageIds.ADD_BREAKPOINT)) {
105
							addBreakpoint(message);
106
						} else if (message.startsWith(DebugMessageIds.REMOVE_BREAKPOINT)) {
107
							removeBreakpoint(message);
108
						}  else if (message.startsWith(DebugMessageIds.PROPERTIES)) {
109
							marshallProperties();
110
						}
111
					}
112
				} 
113
			} catch (Exception e) {
114
				RemoteAntDebugBuildLogger.this.shutDown();
115
			}
116
		}
117
	}
118
	
119
	private void requestConnect() {
120
		if (fDebugMode) {
121
			System.out.println("RemoteAntDebugBuildLogger: trying to connect" + fHost + ":" + fRequestPort); //$NON-NLS-1$ //$NON-NLS-2$
122
		}
123
		
124
		try{
125
			fServerSocket.setSoTimeout(fgServerSocketTimeout);
126
			fRequestSocket= fServerSocket.accept();
127
			fRequestWriter= new PrintWriter(fRequestSocket.getOutputStream(), true);
128
			fRequestReader = new BufferedReader(new InputStreamReader(fRequestSocket.getInputStream()));
129
			
130
			ReaderThread readerThread= new ReaderThread();
131
			readerThread.setDaemon(true);
132
			readerThread.start();
133
			return;
134
		} catch(SocketTimeoutException e){
135
		} catch(IOException e) {
136
		}
137
		shutDown();
138
	}
139
	
140
	/* (non-Javadoc)
141
	 * @see org.eclipse.ant.internal.ui.antsupport.logger.RemoteAntBuildLogger#shutDown()
142
	 */
143
	protected void shutDown() {
144
		if (fRequestWriter != null) {
145
			fRequestWriter.close();
146
			fRequestWriter= null;
147
		}
148
		
149
		if (fRequestReader != null) {
150
			try {
151
				fRequestReader.close();
152
			} catch (IOException e) {
153
			}
154
			fRequestReader= null;
155
		}
156
		
157
		if (fRequestSocket != null) {
158
			try {
159
				fRequestSocket.close();	
160
			} catch(IOException e) {
161
			}
162
		}
163
		fRequestSocket= null;
164
		
165
		super.shutDown();
166
	}
167
	
168
	/* (non-Javadoc)
169
	 * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
170
	 */
171
	public synchronized void buildStarted(BuildEvent event) {
172
		fDebugState= new AntDebugState(this);
173
		super.buildStarted(event);
174
		marshalMessage(-1, DebugMessageIds.BUILD_STARTED);
175
		if (fRequestPort != -1) {
176
			try {
177
				fServerSocket= new ServerSocket(fRequestPort);
178
			} catch (IOException ioe) {
179
				shutDown();
180
			}
181
			requestConnect();
182
		} else {
183
			shutDown();
184
		}
185
        fDebugState.buildStarted();
186
		fDebugState.setShouldSuspend(true);
187
		waitIfSuspended();
188
	}
189
190
	/* (non-Javadoc)
191
	 * @see org.apache.tools.ant.BuildListener#taskStarted(org.apache.tools.ant.BuildEvent)
192
	 */
193
	public void taskStarted(BuildEvent event) {
194
        super.taskStarted(event);
195
		fDebugState.taskStarted(event);
196
	}
197
	
198
	/* (non-Javadoc)
199
	 * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent)
200
	 */
201
	public synchronized void taskFinished(BuildEvent event) {
202
		super.taskFinished(event);
203
		fDebugState.taskFinished();
204
	}
205
	
206
	/* (non-Javadoc)
207
	 * @see org.eclipse.ant.internal.ui.antsupport.logger.util.IDebugBuildLogger#waitIfSuspended()
208
	 */
209
	public synchronized void waitIfSuspended() {
210
		String detail= null;
211
		boolean shouldSuspend= true;
212
		RemoteAntBreakpoint breakpoint= breakpointAtLineNumber(fDebugState.getBreakpointLocation());
213
		if (breakpoint != null) {
214
			detail= breakpoint.toMarshallString();
215
			fDebugState.setShouldSuspend(false);
216
			if (fDebugState.getStepOverTask() != null) {
217
				fStepOverTaskInterrupted= fDebugState.getStepOverTask();
218
				fDebugState.setStepOverTask(null);
219
			}
220
		} else if (fDebugState.getCurrentTask() != null) {
221
	        if (fDebugState.isStepIntoSuspend()) {
222
	            detail= DebugMessageIds.STEP;
223
				fDebugState.setStepIntoSuspend(false);
224
	        } else if ((fDebugState.getLastTaskFinished() != null && fDebugState.getLastTaskFinished() == fDebugState.getStepOverTask()) || fDebugState.shouldSuspend()) {
225
	        	//suspend as a step over has finished
226
	        	detail= DebugMessageIds.STEP;
227
				fDebugState.setStepOverTask(null);
228
				fDebugState.setShouldSuspend(false);
229
	        } else if (fDebugState.getLastTaskFinished() != null && fDebugState.getLastTaskFinished() == fDebugState.getStepIntoTask()) {
230
	        	//suspend as a task that was stepped into has finally completed
231
	        	 detail= DebugMessageIds.STEP;
232
	        	 fDebugState.setStepIntoTask(null);
233
	        } else if (fDebugState.getLastTaskFinished() != null && fDebugState.getLastTaskFinished() == fStepOverTaskInterrupted) {
234
	        	//suspend as a task that was stepped over but hit a breakpoint has finally completed
235
	        	 detail= DebugMessageIds.STEP;
236
	        	 fStepOverTaskInterrupted= null;
237
	        } else if (fDebugState.isClientSuspend()) {
238
	            detail= DebugMessageIds.CLIENT_REQUEST;
239
				fDebugState.setClientSuspend(false);
240
	        } else {
241
	            shouldSuspend= false;
242
	        }
243
	    } else if (fDebugState.shouldSuspend() && fBuildStartedSuspend) {
244
            fBuildStartedSuspend= false;
245
			fDebugState.setShouldSuspend(false);
246
	    } else {
247
			shouldSuspend= false;
248
	    }
249
		
250
		if (shouldSuspend) {
251
			if (detail != null) {
252
				StringBuffer message= new StringBuffer(DebugMessageIds.SUSPENDED);
253
				message.append(detail);
254
				sendRequestResponse(message.toString());
255
			}
256
			 try {
257
				 wait();
258
                 shouldSuspend= false;
259
			 } catch (InterruptedException e) {
260
			 }
261
		}
262
	}
263
264
	private RemoteAntBreakpoint breakpointAtLineNumber(Location location) {
265
		if (fBreakpoints == null || location == null || location == Location.UNKNOWN_LOCATION) {
266
			return null;
267
		}
268
		String fileName= fDebugState.getFileName(location);
269
		int lineNumber= fDebugState.getLineNumber(location);
270
		for (int i = 0; i < fBreakpoints.size(); i++) {
271
			RemoteAntBreakpoint breakpoint = (RemoteAntBreakpoint) fBreakpoints.get(i);
272
			if (breakpoint.isAt(fileName, lineNumber)) {
273
				return breakpoint;
274
			}
275
		}
276
		return null;
277
	}
278
279
	private void sendRequestResponse(String message) {
280
		if (fRequestWriter == null) {
281
			return;
282
		}
283
		
284
		fRequestWriter.println(message);
285
	}
286
	
287
	protected void marshallStack() {
288
	    StringBuffer stackRepresentation= new StringBuffer();
289
	    fDebugState.marshalStack(stackRepresentation);
290
	    sendRequestResponse(stackRepresentation.toString());
291
	}
292
	
293
	protected void marshallProperties() {
294
	    StringBuffer propertiesRepresentation= new StringBuffer();
295
		fDebugState.marshallProperties(propertiesRepresentation, true);
296
	    sendRequestResponse(propertiesRepresentation.toString());
297
	}
298
	
299
	protected void addBreakpoint(String breakpointRepresentation) {
300
		if (fBreakpoints == null) {
301
			fBreakpoints= new ArrayList();
302
		}
303
		RemoteAntBreakpoint newBreakpoint= new RemoteAntBreakpoint(breakpointRepresentation);
304
		if (!fBreakpoints.contains(newBreakpoint)) {
305
			fBreakpoints.add(newBreakpoint);	
306
		}
307
	}
308
	
309
	protected void removeBreakpoint(String breakpointRepresentation) {
310
		if (fBreakpoints == null) {
311
			return;
312
		} 
313
		RemoteAntBreakpoint equivalentBreakpoint= new RemoteAntBreakpoint(breakpointRepresentation);
314
		for (Iterator iter = fBreakpoints.iterator(); iter.hasNext(); ) {
315
			RemoteAntBreakpoint breakpoint = (RemoteAntBreakpoint) iter.next();
316
			if (breakpoint.equals(equivalentBreakpoint)) {
317
				iter.remove();
318
				return;
319
			}
320
		}
321
	}
322
323
	/* (non-Javadoc)
324
	 * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
325
	 */
326
	public void targetStarted(BuildEvent event) {
327
		fDebugState.targetStarted(event);
328
		if (!fSentProcessId) {
329
			establishConnection();
330
		}
331
		waitIfSuspended();
332
		super.targetStarted(event);
333
	}
334
    
335
    /* (non-Javadoc)
336
     * @see org.apache.tools.ant.BuildListener#targetFinished(org.apache.tools.ant.BuildEvent)
337
     */
338
    public void targetFinished(BuildEvent event) {
339
        super.targetFinished(event);
340
		fDebugState.setTargetExecuting(null);
341
    }   
342
    
343
    /* (non-Javadoc)
344
     * @see org.eclipse.ant.internal.ui.antsupport.logger.RemoteAntBuildLogger#configure(java.util.Map)
345
     */
346
    public void configure(Map userProperties) {
347
       super.configure(userProperties);
348
       String requestPortProperty= (String) userProperties.remove("eclipse.connect.request_port"); //$NON-NLS-1$
349
        if (requestPortProperty != null) {
350
            fRequestPort= Integer.parseInt(requestPortProperty);
351
        }
352
    }
353
}
(-)src/org/eclipse/ant/internal/launching/AntLaunch.java (+53 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.debug.core.ILaunchConfiguration;
17
import org.eclipse.debug.core.Launch;
18
import org.eclipse.debug.core.model.ISourceLocator;
19
20
/**
21
 * Stores link descriptors for Launch for further use of TaskLinkManager
22
 */
23
public class AntLaunch extends Launch {
24
	List linkDescriptors;
25
26
	public AntLaunch(ILaunchConfiguration launchConfiguration, String mode,
27
			ISourceLocator locator) {
28
		super(launchConfiguration, mode, locator);
29
		linkDescriptors = new ArrayList();
30
31
	}
32
33
	public void addLinkDescriptor(String line, String fileName, int lineNumber,
34
			int offset, int length) {
35
		if (fileName!= null && fileName.trim().length() > 0) {
36
			linkDescriptors.add(new LinkDescriptor(line, fileName, lineNumber,
37
					offset, length));
38
		}
39
	}
40
41
	public void removeLinkDescriptor(LinkDescriptor ld) {
42
		linkDescriptors.remove(ld);
43
	}
44
45
	public List getLinkDescriptors() {
46
		return linkDescriptors;
47
	}
48
49
	public void clearLinkDescriptors() {
50
		linkDescriptors.clear();
51
	}
52
53
}
(-)src/org/eclipse/ant/internal/launching/AntLaunching.java (+106 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching;
11
package org.eclipse.ant.internal.launching;
12
12
13
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
14
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.core.runtime.Plugin;
15
import org.eclipse.core.runtime.Plugin;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
14
import org.osgi.framework.BundleContext;
18
import org.osgi.framework.BundleContext;
15
19
16
/**
20
/**
Lines 20-25 Link Here
20
24
21
	// The plug-in ID
25
	// The plug-in ID
22
	public static final String PLUGIN_ID = "org.eclipse.ant.launching"; //$NON-NLS-1$
26
	public static final String PLUGIN_ID = "org.eclipse.ant.launching"; //$NON-NLS-1$
27
	
28
	private static final String EMPTY_STRING= ""; //$NON-NLS-1$
29
	
30
	/**
31
	 * Boolean attribute indicating if an input handler should be supplied for
32
	 * the build Default value is <code>true</code>.
33
	 */
34
	public static final String SET_INPUTHANDLER = "org.eclipse.ant.ui.SET_INPUTHANDLER"; //$NON-NLS-1$
35
36
	/**
37
	 * int preference identifier constant which specifies the length of time to
38
	 * wait to connect with the socket that communicates with the separate JRE
39
	 * to capture the output
40
	 */
41
	public static final String ANT_COMMUNICATION_TIMEOUT = "timeout"; //$NON-NLS-1$
42
43
	/**
44
	 * Size of left-hand column for right-justified task name. Used for Ant
45
	 * Build logging.
46
	 * 
47
	 * @see org.eclipse.ant.internal.ui.antsupport.logger.AntProcessBuildLogger
48
	 * @see org.eclipse.ant.internal.launching.launchConfigurations.RemoteAntBuildListener
49
	 */
50
	public static final int LEFT_COLUMN_SIZE = 15;
51
	
52
	/**
53
	 * String attribute indicating the custom runtime classpath to use for an
54
	 * Ant build. Default value is <code>null</code> which indicates that the
55
	 * global classpath is to be used. Format is a comma separated listing of
56
	 * URLs.
57
	 * 
58
	 * @deprecated no longer supported: use
59
	 *             {@link IJavaLaunchConfigurationConstants#ATTR_CLASSPATH_PROVIDER}
60
	 * @see IJavaLaunchConfigurationConstants#ATTR_DEFAULT_CLASSPATH
61
	 */
62
	public static final String ATTR_ANT_CUSTOM_CLASSPATH = IExternalToolConstants.UI_PLUGIN_ID
63
			+ ".ATTR_ANT_CUSTOM_CLASSPATH"; //$NON-NLS-1$
64
	/**
65
	 * String attribute indicating the custom Ant home to use for an Ant build.
66
	 * Default value is <code>null</code> which indicates that no Ant home is to
67
	 * be set
68
	 * 
69
	 * @deprecated no longer supported: use
70
	 *             {@link IJavaLaunchConfigurationConstants#ATTR_CLASSPATH_PROVIDER}
71
	 * @see IJavaLaunchConfigurationConstants#ATTR_DEFAULT_CLASSPATH
72
	 */
73
	public static final String ATTR_ANT_HOME = IExternalToolConstants.UI_PLUGIN_ID
74
			+ ".ATTR_ANT_HOME"; //$NON-NLS-1$
75
	
76
	
77
	/**
78
	 * Status code indicating an unexpected internal error.
79
	 * @since 2.1
80
	 */
81
	public static final int INTERNAL_ERROR = 120;	
23
82
24
	// The shared instance
83
	// The shared instance
25
	private static AntLaunching plugin;
84
	private static AntLaunching plugin;
Lines 56-60 Link Here
56
	public static AntLaunching getDefault() {
115
	public static AntLaunching getDefault() {
57
		return plugin;
116
		return plugin;
58
	}
117
	}
118
	
119
	public static String getUniqueIdentifier() {
120
		return PLUGIN_ID;
121
	}
122
	
123
	/**
124
	 * Logs the specified throwable with this plug-in's log.
125
	 * 
126
	 * @param t throwable to log 
127
	 */
128
	public static void log(Throwable t) {
129
		IStatus status= new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, "Error logged from Ant UI: ", t); //$NON-NLS-1$
130
		log(status);
131
	}
132
	
133
	/**
134
	 * Logs the specified status with this plug-in's log.
135
	 * 
136
	 * @param status status 
137
	 */
138
	public static void log(IStatus status) {
139
		getDefault().getLog().log(status);
140
	}
141
	
142
	/**
143
	 * Writes the message to the plug-in's log
144
	 * 
145
	 * @param message the text to write to the log
146
	 */
147
	public static void log(String message, Throwable exception) {
148
		IStatus status = newErrorStatus(message, exception);
149
		log(status);
150
	}
151
	
152
	/**
153
	 * Returns a new <code>IStatus</code> for this plug-in
154
	 */
155
	public static IStatus newErrorStatus(String message, Throwable exception) {
156
		if (message == null) {
157
			message= EMPTY_STRING; 
158
		}		
159
		return new Status(IStatus.ERROR, PLUGIN_ID, 0, message, exception);
160
	}
161
	
162
	public static AntLaunching getPlugin() {
163
		return plugin;
164
	}
59
165
60
}
166
}
(-)src/org/eclipse/ant/internal/launching/AntLaunchingPreferenceInitializer.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching;
12
13
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
14
import org.eclipse.core.runtime.preferences.DefaultScope;
15
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
16
17
public class AntLaunchingPreferenceInitializer extends
18
		AbstractPreferenceInitializer {
19
20
	public AntLaunchingPreferenceInitializer() {
21
		super();
22
	}
23
24
	/*
25
	 * (non-Javadoc)
26
	 * 
27
	 * @seeorg.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#
28
	 * initializeDefaultPreferences()
29
	 */
30
	public void initializeDefaultPreferences() {
31
32
		IEclipsePreferences node = new DefaultScope()
33
				.getNode("org.eclipse.ant.launching"); //$NON-NLS-1$
34
		node.put(IAntLaunchingPreferenceConstants.ANT_COMMUNICATION_TIMEOUT,
35
				"20000"); //$NON-NLS-1$
36
	}
37
}
(-)src/org/eclipse/ant/internal/launching/AntLaunchingUtil.java (+525 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching;
12
13
import java.io.File;
14
import java.io.IOException;
15
import java.net.MalformedURLException;
16
import java.net.URL;
17
import java.util.ArrayList;
18
import java.util.List;
19
import java.util.Map;
20
import java.util.StringTokenizer;
21
22
import org.apache.tools.ant.BuildException;
23
import org.apache.tools.ant.util.FileUtils;
24
import org.eclipse.ant.internal.launching.launchConfigurations.AntCoreModelMessages;
25
import org.eclipse.ant.internal.launching.launchConfigurations.AntHomeClasspathEntry;
26
import org.eclipse.ant.internal.launching.launchConfigurations.AntProcess;
27
import org.eclipse.ant.internal.launching.launchConfigurations.RemoteAntRuntimeProcess;
28
import org.eclipse.ant.launching.IAntLaunchConstants;
29
import org.eclipse.core.internal.externaltools.model.ExternalToolBuilder;
30
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
31
import org.eclipse.core.resources.IFile;
32
import org.eclipse.core.resources.IWorkspaceRoot;
33
import org.eclipse.core.resources.ResourcesPlugin;
34
import org.eclipse.core.runtime.CoreException;
35
import org.eclipse.core.runtime.IPath;
36
import org.eclipse.core.runtime.IStatus;
37
import org.eclipse.core.runtime.Path;
38
import org.eclipse.core.runtime.Status;
39
import org.eclipse.core.variables.VariablesPlugin;
40
import org.eclipse.debug.core.ILaunch;
41
import org.eclipse.debug.core.ILaunchConfiguration;
42
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
43
import org.eclipse.debug.core.model.IProcess;
44
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
45
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
46
import org.eclipse.jdt.launching.IRuntimeClasspathEntry2;
47
import org.eclipse.jdt.launching.JavaRuntime;
48
49
import com.ibm.icu.text.MessageFormat;
50
51
/**
52
 * General utility class dealing with Ant build files
53
 */
54
public final class AntLaunchingUtil {
55
	public static final String ATTRIBUTE_SEPARATOR = ","; //$NON-NLS-1$;
56
	public static final char ANT_CLASSPATH_DELIMITER = '*';
57
	public static final String ANT_HOME_CLASSPATH_PLACEHOLDER = "G"; //$NON-NLS-1$
58
	public static final String ANT_GLOBAL_USER_CLASSPATH_PLACEHOLDER = "UG"; //$NON-NLS-1$
59
	
60
	/**
61
	 * No instances allowed
62
	 */
63
	private AntLaunchingUtil() {
64
		super();
65
	}
66
67
	/**
68
	 * Returns a single-string of the strings for storage.
69
	 * 
70
	 * @param strings
71
	 *            the array of strings
72
	 * @return a single-string representation of the strings or
73
	 *         <code>null</code> if the array is empty.
74
	 */
75
	public static String combineStrings(String[] strings) {
76
		if (strings.length == 0)
77
			return null;
78
79
		if (strings.length == 1)
80
			return strings[0];
81
82
		StringBuffer buf = new StringBuffer();
83
		for (int i = 0; i < strings.length - 1; i++) {
84
			buf.append(strings[i]);
85
			buf.append(ATTRIBUTE_SEPARATOR);
86
		}
87
		buf.append(strings[strings.length - 1]);
88
		return buf.toString();
89
	}
90
91
	/**
92
	 * Returns an array of targets to be run, or <code>null</code> if none are
93
	 * specified (indicating the default target or implicit target should be
94
	 * run).
95
	 * 
96
	 * @param configuration
97
	 *            launch configuration
98
	 * @return array of target names, or <code>null</code>
99
	 * @throws CoreException
100
	 *             if unable to access the associated attribute
101
	 */
102
	public static String[] getTargetNames(ILaunchConfiguration configuration)
103
			throws CoreException {
104
		String attribute = null;
105
		if (IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE
106
				.equals(configuration.getType().getIdentifier())) {
107
			attribute = getTargetNamesForAntBuilder(configuration);
108
		}
109
		if (attribute == null) {
110
			attribute = configuration.getAttribute(
111
					IAntLaunchConstants.ATTR_ANT_TARGETS,
112
					(String) null);
113
			if (attribute == null) {
114
				return null;
115
			}
116
		}
117
118
		return AntLaunchingUtil.parseRunTargets(attribute);
119
	}
120
121
	private static String getTargetNamesForAntBuilder(
122
			ILaunchConfiguration configuration) throws CoreException {
123
		String buildType = ExternalToolBuilder.getBuildType();
124
		String targets = null;
125
		if (IExternalToolConstants.BUILD_TYPE_AUTO.equals(buildType)) {
126
			targets = configuration.getAttribute(
127
					IAntLaunchConstants.ATTR_ANT_AUTO_TARGETS,
128
					(String) null);
129
		} else if (IExternalToolConstants.BUILD_TYPE_CLEAN.equals(buildType)) {
130
			targets = configuration.getAttribute(
131
					IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS,
132
					(String) null);
133
		} else if (IExternalToolConstants.BUILD_TYPE_FULL.equals(buildType)) {
134
			targets = configuration
135
					.getAttribute(
136
							IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS,
137
							(String) null);
138
		} else if (IExternalToolConstants.BUILD_TYPE_INCREMENTAL
139
				.equals(buildType)) {
140
			targets = configuration.getAttribute(
141
					IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS,
142
					(String) null);
143
		}
144
145
		return targets;
146
	}
147
148
	/**
149
	 * Returns a map of properties to be defined for the build, or
150
	 * <code>null</code> if none are specified (indicating no additional
151
	 * properties specified for the build).
152
	 * 
153
	 * @param configuration
154
	 *            launch configuration
155
	 * @return map of properties (name --> value), or <code>null</code>
156
	 * @throws CoreException
157
	 *             if unable to access the associated attribute
158
	 */
159
	public static Map getProperties(ILaunchConfiguration configuration)
160
			throws CoreException {
161
		Map map = configuration.getAttribute(
162
				IAntLaunchConstants.ATTR_ANT_PROPERTIES,
163
				(Map) null);
164
		return map;
165
	}
166
167
	/**
168
	 * Returns a String specifying the Ant home to use for the build.
169
	 * 
170
	 * @param configuration
171
	 *            launch configuration
172
	 * @return String specifying Ant home to use or <code>null</code>
173
	 * @throws CoreException
174
	 *             if unable to access the associated attribute
175
	 */
176
	public static String getAntHome(ILaunchConfiguration configuration)
177
			throws CoreException {
178
		IRuntimeClasspathEntry[] entries = JavaRuntime
179
				.computeUnresolvedRuntimeClasspath(configuration);
180
		for (int i = 0; i < entries.length; i++) {
181
			IRuntimeClasspathEntry entry = entries[i];
182
			if (entry.getType() == IRuntimeClasspathEntry.OTHER) {
183
				IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2) entry;
184
				if (entry2.getTypeId().equals(AntHomeClasspathEntry.TYPE_ID)) {
185
					return ((AntHomeClasspathEntry) entry2).getAntHome();
186
				}
187
			}
188
		}
189
		return null;
190
	}
191
192
	/**
193
	 * Returns an array of property files to be used for the build, or
194
	 * <code>null</code> if none are specified (indicating no additional
195
	 * property files specified for the build).
196
	 * 
197
	 * @param configuration
198
	 *            launch configuration
199
	 * @return array of property file names, or <code>null</code>
200
	 * @throws CoreException
201
	 *             if unable to access the associated attribute
202
	 */
203
	public static String[] getPropertyFiles(ILaunchConfiguration configuration)
204
			throws CoreException {
205
		String attribute = configuration.getAttribute(
206
				IAntLaunchConstants.ATTR_ANT_PROPERTY_FILES,
207
				(String) null);
208
		if (attribute == null) {
209
			return null;
210
		}
211
		String[] propertyFiles = AntLaunchingUtil.parseString(attribute, ","); //$NON-NLS-1$
212
		for (int i = 0; i < propertyFiles.length; i++) {
213
			String propertyFile = propertyFiles[i];
214
			propertyFile = expandVariableString(propertyFile,
215
					AntCoreModelMessages.AntUtil_6);
216
			propertyFiles[i] = propertyFile;
217
		}
218
		return propertyFiles;
219
	}
220
221
	/**
222
	 * Returns the list of URLs that define the custom classpath for the Ant
223
	 * build, or <code>null</code> if the global classpath is to be used.
224
	 * 
225
	 * @param config
226
	 *            launch configuration
227
	 * @return a list of <code>URL</code>
228
	 * 
229
	 * @throws CoreException
230
	 *             if file does not exist, IO problems, or invalid format.
231
	 */
232
	public static URL[] getCustomClasspath(ILaunchConfiguration config)
233
			throws CoreException {
234
		boolean useDefault = config.getAttribute(
235
				IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
236
		if (useDefault) {
237
			return null;
238
		}
239
		IRuntimeClasspathEntry[] unresolved = JavaRuntime
240
				.computeUnresolvedRuntimeClasspath(config);
241
		// don't consider bootpath entries
242
		List userEntries = new ArrayList(unresolved.length);
243
		for (int i = 0; i < unresolved.length; i++) {
244
			IRuntimeClasspathEntry entry = unresolved[i];
245
			if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {
246
				userEntries.add(entry);
247
			}
248
		}
249
		IRuntimeClasspathEntry[] entries = JavaRuntime
250
				.resolveRuntimeClasspath(
251
						(IRuntimeClasspathEntry[]) userEntries
252
								.toArray(new IRuntimeClasspathEntry[userEntries
253
										.size()]), config);
254
		URL[] urls = new URL[entries.length];
255
		for (int i = 0; i < entries.length; i++) {
256
			IRuntimeClasspathEntry entry = entries[i];
257
			try {
258
				urls[i] = new URL("file:" + entry.getLocation()); //$NON-NLS-1$
259
			} catch (MalformedURLException e) {
260
				throw new CoreException(new Status(IStatus.ERROR, AntLaunching
261
						.getUniqueIdentifier(), AntLaunching.INTERNAL_ERROR,
262
						AntCoreModelMessages.AntUtil_7, e));
263
			}
264
		}
265
		return urls;
266
	}
267
268
	private static String expandVariableString(String variableString,
269
			String invalidMessage) throws CoreException {
270
		String expandedString = VariablesPlugin.getDefault()
271
				.getStringVariableManager().performStringSubstitution(
272
						variableString);
273
		if (expandedString == null || expandedString.length() == 0) {
274
			String msg = MessageFormat.format(invalidMessage,
275
					new String[] { variableString });
276
			throw new CoreException(new Status(IStatus.ERROR,
277
					AntLaunching.PLUGIN_ID, 0, msg, null));
278
		}
279
280
		return expandedString;
281
	}
282
283
	/**
284
	 * Returns the list of target names to run
285
	 * 
286
	 * @param extraAttibuteValue
287
	 *            the external tool's extra attribute value for the run targets
288
	 *            key.
289
	 * @return a list of target names
290
	 */
291
	public static String[] parseRunTargets(String extraAttibuteValue) {
292
		return parseString(extraAttibuteValue, ATTRIBUTE_SEPARATOR);
293
	}
294
295
	/**
296
	 * Returns the list of Strings that were delimiter separated.
297
	 * 
298
	 * @param delimString
299
	 *            the String to be tokenized based on the delimiter
300
	 * @return a list of Strings
301
	 */
302
	public static String[] parseString(String delimString, String delim) {
303
		if (delimString == null) {
304
			return new String[0];
305
		}
306
307
		// Need to handle case where separator character is
308
		// actually part of the target name!
309
		StringTokenizer tokenizer = new StringTokenizer(delimString, delim);
310
		String[] results = new String[tokenizer.countTokens()];
311
		for (int i = 0; i < results.length; i++) {
312
			results[i] = tokenizer.nextToken();
313
		}
314
315
		return results;
316
	}
317
318
	/**
319
	 * Returns an IFile with the given fully qualified path (relative to the
320
	 * workspace root). The returned IFile may or may not exist.
321
	 */
322
	public static IFile getFile(String fullPath) {
323
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
324
		return root.getFile(new Path(fullPath));
325
	}
326
327
	/**
328
	 * Returns the workspace file associated with the given path in the local
329
	 * file system, or <code>null</code> if none. If the path happens to be a
330
	 * relative path, then the path is interpreted as relative to the specified
331
	 * parent file.
332
	 * 
333
	 * Attempts to handle linked files; the first found linked file with the
334
	 * correct path is returned.
335
	 * 
336
	 * @param path
337
	 * @param buildFileParent
338
	 * @return file or <code>null</code>
339
	 * @see org.eclipse.core.resources.IWorkspaceRoot#findFilesForLocation(IPath)
340
	 */
341
	public static IFile getFileForLocation(String path, File buildFileParent) {
342
		if (path == null) {
343
			return null;
344
		}
345
		IPath filePath = new Path(path);
346
		IFile file = null;
347
		IFile[] files = ResourcesPlugin.getWorkspace().getRoot()
348
				.findFilesForLocation(filePath);
349
		if (files.length > 0) {
350
			file = files[0];
351
		}
352
		if (file == null) {
353
			// relative path
354
			File relativeFile = null;
355
			try {
356
				// this call is ok if buildFileParent is null
357
				relativeFile = FileUtils.getFileUtils().resolveFile(
358
						buildFileParent, path);
359
				filePath = new Path(relativeFile.getAbsolutePath());
360
				files = ResourcesPlugin.getWorkspace().getRoot()
361
						.findFilesForLocation(filePath);
362
				if (files.length > 0) {
363
					file = files[0];
364
				} else {
365
					return null;
366
				}
367
			} catch (BuildException be) {
368
				return null;
369
			}
370
		}
371
372
		if (file.exists()) {
373
			return file;
374
		}
375
		File ioFile = file.getLocation().toFile();
376
		if (ioFile.exists()) {// needs to handle case insensitivity on WINOS
377
			try {
378
				files = ResourcesPlugin.getWorkspace().getRoot()
379
						.findFilesForLocation(
380
								new Path(ioFile.getCanonicalPath()));
381
				if (files.length > 0) {
382
					return files[0];
383
				}
384
			} catch (IOException e) {
385
			}
386
		}
387
388
		return null;
389
	}
390
391
	/**
392
	 * Migrates the classpath in the given configuration from the old format to
393
	 * the new format. The old format is not preserved. Instead, the default
394
	 * classpath will be used. However, ANT_HOME settings are preserved.
395
	 * 
396
	 * @param configuration
397
	 *            a configuration to migrate
398
	 * @throws CoreException
399
	 *             if unable to migrate
400
	 * @since 3.0
401
	 */
402
	public static void migrateToNewClasspathFormat(
403
			ILaunchConfiguration configuration) throws CoreException {
404
		String oldClasspath = configuration.getAttribute(
405
				AntLaunching.ATTR_ANT_CUSTOM_CLASSPATH,
406
				(String) null);
407
		String oldAntHome = configuration.getAttribute(
408
				AntLaunching.ATTR_ANT_HOME, (String) null);
409
		String provider = configuration.getAttribute(
410
				IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
411
				(String) null);
412
		if (oldClasspath != null || oldAntHome != null || provider == null) {
413
			ILaunchConfigurationWorkingCopy workingCopy = null;
414
			if (configuration.isWorkingCopy()) {
415
				workingCopy = (ILaunchConfigurationWorkingCopy) configuration;
416
			} else {
417
				workingCopy = configuration.getWorkingCopy();
418
			}
419
			workingCopy
420
					.setAttribute(
421
							AntLaunching.ATTR_ANT_CUSTOM_CLASSPATH,
422
							(String) null);
423
			workingCopy
424
					.setAttribute(
425
							AntLaunching.ATTR_ANT_HOME,
426
							(String) null);
427
			workingCopy.setAttribute(
428
					IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER,
429
					"org.eclipse.ant.ui.AntClasspathProvider"); //$NON-NLS-1$
430
			workingCopy.setAttribute(
431
					IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
432
					true);
433
			if (oldAntHome != null) {
434
				IRuntimeClasspathEntry[] entries = JavaRuntime
435
						.computeUnresolvedRuntimeClasspath(workingCopy);
436
				List mementos = new ArrayList(entries.length);
437
				for (int i = 0; i < entries.length; i++) {
438
					IRuntimeClasspathEntry entry = entries[i];
439
					if (entry.getType() == IRuntimeClasspathEntry.OTHER) {
440
						IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2) entry;
441
						if (entry2.getTypeId().equals(
442
								AntHomeClasspathEntry.TYPE_ID)) {
443
							AntHomeClasspathEntry homeEntry = new AntHomeClasspathEntry(
444
									oldAntHome);
445
							mementos.add(homeEntry.getMemento());
446
							continue;
447
						}
448
					}
449
					mementos.add(entry.getMemento());
450
				}
451
				workingCopy
452
						.setAttribute(
453
								IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH,
454
								false);
455
				workingCopy.setAttribute(
456
						IJavaLaunchConfigurationConstants.ATTR_CLASSPATH,
457
						mementos);
458
			}
459
			workingCopy.doSave();
460
		}
461
	}
462
463
	public static boolean isSeparateJREAntBuild(
464
			ILaunchConfiguration configuration) {
465
		boolean separateJRE = true;
466
		try {
467
			// always null for same JRE
468
			separateJRE = configuration.getAttribute(
469
					IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
470
					(String) null) != null;
471
		} catch (CoreException e) {
472
			AntLaunching.log(AntCoreModelMessages.AntUtil_2, e);
473
		}
474
475
		return separateJRE;
476
	}
477
478
	public static void linkBuildFailedMessage(String message, IProcess process) {
479
		String fileName = null;
480
		String lineNumber = ""; //$NON-NLS-1$
481
		int fileStart = 0;
482
		int index = message.indexOf("xml"); //$NON-NLS-1$
483
		if (index > 0) {
484
			int numberStart = index + 4;
485
			int numberEnd = message.indexOf(':', numberStart);
486
			int fileEnd = index + 3;
487
			if (numberStart > 0 && fileEnd > 0) {
488
				fileName = message.substring(fileStart, fileEnd).trim();
489
				if (numberEnd > 0) {
490
					lineNumber = message.substring(numberStart, numberEnd)
491
							.trim();
492
				}
493
			}
494
		}
495
496
		if (fileName != null) {
497
			int num = -1;
498
			try {
499
				num = Integer.parseInt(lineNumber);
500
			} catch (NumberFormatException e) {
501
			}
502
			IFile[] files = ResourcesPlugin.getWorkspace().getRoot()
503
					.findFilesForLocation(new Path(fileName));
504
			IFile file = null;
505
			if (files.length > 0) {
506
				file = files[0];
507
			}
508
			if (file != null && file.exists()) {
509
				if (process != null) {
510
					ILaunch launch = null;
511
					if (process instanceof RemoteAntRuntimeProcess) {
512
						launch = ((RemoteAntRuntimeProcess) process)
513
								.getLaunch();
514
					} else if (process instanceof AntProcess) {
515
						launch = ((AntProcess) process).getLaunch();
516
					}
517
					if (launch != null) {
518
						((AntLaunch) launch).addLinkDescriptor(message,
519
								fileName, num, 0, message.length());
520
					}
521
				}
522
			}
523
		}
524
	}
525
}
(-)src/org/eclipse/ant/internal/launching/IAntLaunchingPreferenceConstants.java (+23 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching;
12
13
/**
14
 * Constants used to identify user preferences.
15
 */
16
public interface IAntLaunchingPreferenceConstants {
17
18
	 /**
19
     * int preference identifier constant which specifies the length of time to wait
20
     * to connect with the socket that communicates with the separate JRE to capture the output
21
     */
22
    public static final String ANT_COMMUNICATION_TIMEOUT= "timeout"; //$NON-NLS-1$
23
}
(-)src/org/eclipse/ant/internal/launching/LinkDescriptor.java (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching;
12
13
/**
14
 * Stores detailed data of Link. Used to create linked messages.
15
 */
16
public class LinkDescriptor {
17
	String line;
18
	String fileName;
19
	int lineNumber;
20
	int offset;
21
	int length;
22
23
	public LinkDescriptor(String line, String fileName, int lineNumber,
24
			int offset, int length) {
25
		super();
26
		this.line = line;
27
		this.fileName = fileName;
28
		this.lineNumber = lineNumber;
29
		this.offset = offset;
30
		this.length = length;
31
	}
32
33
	public String getLine() {
34
		return line;
35
	}
36
37
	public void setLine(String line) {
38
		this.line = line;
39
	}
40
41
	public String getFileName() {
42
		return fileName;
43
	}
44
45
	public void setFileName(String fileName) {
46
		this.fileName = fileName;
47
	}
48
49
	public int getLineNumber() {
50
		return lineNumber;
51
	}
52
53
	public void setLineNumber(int lineNumber) {
54
		this.lineNumber = lineNumber;
55
	}
56
57
	public int getOffset() {
58
		return offset;
59
	}
60
61
	public void setOffset(int offset) {
62
		this.offset = offset;
63
	}
64
65
	public int getLength() {
66
		return length;
67
	}
68
69
	public void setLength(int length) {
70
		this.length = length;
71
	}
72
73
}
(-)src/org/eclipse/ant/internal/launching/debug/AntDebugMessages.java (+23 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.ant.internal.launching.debug;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class AntDebugMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.ant.internal.ui.debug.AntDebugMessages";//$NON-NLS-1$
16
    
17
	public static String AntSourceContainer_0;
18
19
	static {
20
		// load message values from bundle file
21
		NLS.initializeMessages(BUNDLE_NAME, AntDebugMessages.class);
22
	}
23
}
(-)src/org/eclipse/ant/internal/launching/debug/AntDebugMessages.properties (+12 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2005, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
AntSourceContainer_0=Ant Source Container
(-)src/org/eclipse/ant/internal/launching/debug/AntSourceContainer.java (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.launching.debug;
13
14
import java.io.File;
15
import java.io.IOException;
16
import java.util.ArrayList;
17
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IWorkspaceRoot;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
25
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer;
26
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
27
28
public class AntSourceContainer extends AbstractSourceContainer {
29
30
	private IWorkspaceRoot fRoot;
31
32
	public AntSourceContainer() {
33
		fRoot = ResourcesPlugin.getWorkspace().getRoot();
34
	}
35
36
	/* (non-Javadoc)
37
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String)
38
	 */
39
	public Object[] findSourceElements(String path) throws CoreException {
40
		ArrayList sources = new ArrayList();
41
		File osFile = new File(path);
42
		if (osFile.exists()) {
43
			try {
44
				IPath canonicalPath = new Path(osFile.getCanonicalPath());
45
				IFile[] files = fRoot.findFilesForLocation(canonicalPath);
46
				if (files.length > 0) {
47
					for (int i = 0; i < files.length; i++) {
48
						sources.add(files[i]);
49
					}
50
				} else {
51
					sources.add(new LocalFileStorage(osFile));
52
				}
53
			} catch (IOException e) {
54
			}
55
		}
56
		return sources.toArray();
57
	}
58
59
	/* (non-Javadoc)
60
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
61
	 */
62
	public String getName() {
63
		return AntDebugMessages.AntSourceContainer_0;
64
	}
65
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
68
     * Not persisted via the launch configuration
69
	 */
70
	public ISourceContainerType getType() {
71
		return null;
72
	}
73
}
(-)src/org/eclipse/ant/internal/launching/debug/AntSourceLookupDirector.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
15
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
16
17
/**
18
 * Ant source lookup director. For Ant source lookup there is one source
19
 * lookup participant. 
20
 */
21
public class AntSourceLookupDirector extends AbstractSourceLookupDirector {
22
	
23
	/* (non-Javadoc)
24
	 * @see org.eclipse.debug.core.sourcelookup.ISourceLookupDirector#initializeParticipants()
25
	 */
26
	public void initializeParticipants() {
27
		addParticipants(new ISourceLookupParticipant[]{new AntSourceLookupParticipant()});
28
	}
29
30
    /* (non-Javadoc)
31
     * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
32
     */
33
    public String getMemento() throws CoreException {
34
        return null;
35
    }
36
}
(-)src/org/eclipse/ant/internal/launching/debug/AntSourceLookupParticipant.java (+36 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug;
12
13
import org.eclipse.ant.internal.launching.debug.model.AntStackFrame;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
16
17
/**
18
 * The Ant source lookup participant knows how to translate a 
19
 * Ant stack frame into a source file name 
20
 */
21
public class AntSourceLookupParticipant extends AbstractSourceLookupParticipant {
22
	
23
	/* (non-Javadoc)
24
	 * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#getSourceName(java.lang.Object)
25
	 */
26
	public String getSourceName(Object object) throws CoreException {
27
		if (object instanceof AntStackFrame) {
28
			return ((AntStackFrame)object).getFilePath();
29
		}
30
        if (object instanceof String) {
31
            // assume it's a file name
32
            return (String)object;
33
        }
34
		return null;
35
	}
36
}
(-)src/org/eclipse/ant/internal/launching/debug/AntSourcePathComputerDelegate.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.debug.core.ILaunchConfiguration;
16
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
17
import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate;
18
19
/**
20
 * Computes the default source lookup path for an Ant launch configuration.
21
 * The default source lookup is a container that knows how to map the 
22
 * fully qualified file system paths to either the <code>IFile</code> within the workspace or
23
 * a <code>LocalFileStorage</code> for buildfiles not in the workspace.
24
 */
25
public class AntSourcePathComputerDelegate implements ISourcePathComputerDelegate {
26
	
27
	/* (non-Javadoc)
28
	 * @see org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor)
29
	 */
30
	public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
31
		return new ISourceContainer[] {new AntSourceContainer()};
32
	}
33
}
(-)src/org/eclipse/ant/internal/launching/debug/IAntDebugConstants.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.launching.debug;
13
14
public interface IAntDebugConstants {
15
	
16
	/**
17
	 * Unique identifier for the Ant debug model (value 
18
	 * <code>org.eclipse.ant.ui.debug</code>).
19
	 */
20
	public static final String ID_ANT_DEBUG_MODEL = "org.eclipse.ant.ui.debug"; //$NON-NLS-1$
21
	
22
	/**
23
	 * Unique identifier for the Ant line breakpoint markers 
24
	 * (value <code>org.eclipse.ant.ui.antLineBreakpointMarker</code>).
25
	 */
26
	public static final String ID_ANT_LINE_BREAKPOINT_MARKER= "org.eclipse.ant.ui.antLineBreakpointMarker"; //$NON-NLS-1$
27
    
28
    /**
29
     * Unique identifier for the Ant run to line breakpoints 
30
     * (value <code>org.eclipse.ant.ui.runToLineBreakpoint</code>).
31
     */
32
    public static final String ANT_RUN_TO_LINE= "org.eclipse.ant.ui.runToLineBreakpoint"; //$NON-NLS-1$
33
}
(-)src/org/eclipse/ant/internal/launching/debug/IAntDebugController.java (+66 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug;
12
13
import org.eclipse.debug.core.model.IBreakpoint;
14
15
public interface IAntDebugController {
16
	
17
    /**
18
     * Resume the Ant build
19
     */
20
	public void resume();
21
    
22
    /**
23
     * Suspend the Ant build
24
     */
25
	public void suspend();
26
    
27
     /**
28
     * Step into the current Ant task
29
     */
30
	public void stepInto();
31
    
32
     /**
33
     * Step over the current Ant task
34
     */
35
	public void stepOver();
36
    
37
    /**
38
     * The provided breakpoint has been added or removed depending on the <code>added</code> parameter.
39
     * Updates the controller for this change.
40
     * 
41
     * @param breakpoint the breakpoint that has been added or removed
42
     * @param added whether or not the breakpoint has been added 
43
     */
44
	public void handleBreakpoint(IBreakpoint breakpoint, boolean added);
45
    
46
     /**
47
     * Retrieve the properties of the Ant build.
48
     * May occur asynchronously depending on implementation.
49
     */
50
	public void getProperties();
51
    
52
    /**
53
     * Retrieve the stack frames of the Ant build.
54
     * May occur asynchronously depending on implementation.
55
     */
56
	public void getStackFrames();
57
58
	/**
59
	 * Some strings are escaped when marshalled for socket communication.
60
	 * The Ant debug controller will properly unescape these Strings if required.
61
	 * 
62
	 * @param value The buffer of the string to unescape
63
	 * @return The unescaped string
64
	 */
65
	public StringBuffer unescapeString(StringBuffer value);
66
}
(-)src/org/eclipse/ant/internal/launching/debug/model/AntDebugElement.java (+55 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug.model;
12
13
14
import org.eclipse.ant.internal.launching.AntLaunching;
15
import org.eclipse.ant.internal.launching.debug.IAntDebugConstants;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.debug.core.DebugException;
19
import org.eclipse.debug.core.model.DebugElement;
20
21
/**
22
 * Common function of Ant debug model elements
23
 */
24
public abstract class AntDebugElement extends DebugElement {
25
	
26
	/**
27
	 * Constructs a new debug element contained in the given
28
	 * debug target.
29
	 * 
30
	 * @param target debug target
31
	 */
32
	public AntDebugElement(AntDebugTarget target) {
33
		super(target);
34
	}
35
	
36
	/* (non-Javadoc)
37
	 * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
38
	 */
39
	public String getModelIdentifier() {
40
		return IAntDebugConstants.ID_ANT_DEBUG_MODEL;
41
	}
42
    
43
	/**
44
     * Throws a debug exception with the given message, error code, and underlying
45
     * exception.
46
     */
47
    protected void throwDebugException(String message) throws DebugException {
48
        throw new DebugException(new Status(IStatus.ERROR, AntLaunching.getUniqueIdentifier(),
49
            DebugException.TARGET_REQUEST_FAILED, message, null));
50
    }
51
    
52
    protected AntDebugTarget getAntDebugTarget() {
53
        return (AntDebugTarget)super.getDebugTarget();
54
    }
55
}
(-)src/org/eclipse/ant/internal/launching/debug/model/AntDebugTarget.java (+464 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug.model;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.ant.internal.launching.debug.DebugMessageIds;
18
import org.eclipse.ant.internal.launching.debug.IAntDebugConstants;
19
import org.eclipse.ant.internal.launching.debug.IAntDebugController;
20
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
21
import org.eclipse.core.resources.IMarkerDelta;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.variables.VariablesPlugin;
24
import org.eclipse.debug.core.DebugEvent;
25
import org.eclipse.debug.core.DebugException;
26
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.debug.core.IBreakpointManager;
28
import org.eclipse.debug.core.IBreakpointManagerListener;
29
import org.eclipse.debug.core.IDebugEventSetListener;
30
import org.eclipse.debug.core.ILaunch;
31
import org.eclipse.debug.core.model.IBreakpoint;
32
import org.eclipse.debug.core.model.IDebugTarget;
33
import org.eclipse.debug.core.model.ILineBreakpoint;
34
import org.eclipse.debug.core.model.IMemoryBlock;
35
import org.eclipse.debug.core.model.IProcess;
36
import org.eclipse.debug.core.model.IThread;
37
38
/**
39
 * Ant Debug Target
40
 */
41
public class AntDebugTarget extends AntDebugElement implements IDebugTarget, IDebugEventSetListener, IBreakpointManagerListener {
42
	
43
	// associated system process (Ant Build)
44
	private IProcess fProcess;
45
	
46
	// containing launch object
47
	private ILaunch fLaunch;
48
	
49
	// Build file name
50
	private String fName;
51
52
	// suspend state
53
	private boolean fSuspended= false;
54
	
55
	// terminated state
56
	private boolean fTerminated= false;
57
	
58
	// threads
59
	private AntThread fThread;
60
	private IThread[] fThreads;
61
	
62
	private IAntDebugController fController;
63
    
64
    private List fRunToLineBreakpoints;
65
66
	/**
67
	 * Constructs a new debug target in the given launch for the 
68
	 * associated Ant build process.
69
	 * 
70
	 * @param launch containing launch
71
	 * @param process Ant build process
72
	 * @param controller the controller to communicate to the Ant build
73
	 */
74
	public AntDebugTarget(ILaunch launch, IProcess process, IAntDebugController controller) {
75
		super(null);
76
		fLaunch = launch;
77
		fProcess = process;
78
		
79
		fController= controller;
80
		
81
		fThread = new AntThread(this);
82
		fThreads = new IThread[] {fThread};
83
        
84
        DebugPlugin.getDefault().getBreakpointManager().addBreakpointManagerListener(this);
85
		DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
86
        DebugPlugin.getDefault().addDebugEventListener(this);
87
	}
88
	
89
	/* (non-Javadoc)
90
	 * @see org.eclipse.debug.core.model.IDebugTarget#getProcess()
91
	 */
92
	public IProcess getProcess() {
93
		return fProcess;
94
	}
95
	
96
	/* (non-Javadoc)
97
	 * @see org.eclipse.debug.core.model.IDebugTarget#getThreads()
98
	 */
99
	public IThread[] getThreads() {
100
		return fThreads;
101
	}
102
	
103
	/* (non-Javadoc)
104
	 * @see org.eclipse.debug.core.model.IDebugTarget#hasThreads()
105
	 */
106
	public boolean hasThreads() throws DebugException {
107
		return !fTerminated && fThreads.length > 0;
108
	}
109
	
110
	/* (non-Javadoc)
111
	 * @see org.eclipse.debug.core.model.IDebugTarget#getName()
112
	 */
113
	public String getName() throws DebugException {
114
		if (fName == null) {
115
			try {
116
				fName= getLaunch().getLaunchConfiguration().getAttribute(IExternalToolConstants.ATTR_LOCATION, DebugModelMessages.AntDebugTarget_0);
117
				fName= VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(fName);
118
			} catch (CoreException e) {
119
				fName = DebugModelMessages.AntDebugTarget_0;
120
			}
121
		}
122
		return fName;
123
	}
124
	
125
	/* (non-Javadoc)
126
	 * @see org.eclipse.debug.core.model.IDebugTarget#supportsBreakpoint(org.eclipse.debug.core.model.IBreakpoint)
127
	 */
128
	public boolean supportsBreakpoint(IBreakpoint breakpoint) {
129
		if (breakpoint.getModelIdentifier().equals(IAntDebugConstants.ID_ANT_DEBUG_MODEL)) {
130
		    //need to consider all breakpoints as no way to tell which set
131
		    //of buildfiles will be executed (ant task)
132
		    return true;
133
		}
134
		return false;
135
	}
136
	
137
	/* (non-Javadoc)
138
	 * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
139
	 */
140
	public IDebugTarget getDebugTarget() {
141
		return this;
142
	}
143
	
144
	/* (non-Javadoc)
145
	 * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
146
	 */
147
	public ILaunch getLaunch() {
148
		return fLaunch;
149
	}
150
	
151
	/* (non-Javadoc)
152
	 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
153
	 */
154
	public boolean canTerminate() {
155
		return !fTerminated;
156
	}
157
	
158
	/* (non-Javadoc)
159
	 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
160
	 */
161
	public boolean isTerminated() {
162
		return fTerminated;
163
	}
164
	
165
	/* (non-Javadoc)
166
	 * @see org.eclipse.debug.core.model.ITerminate#terminate()
167
	 */
168
	public void terminate() throws DebugException {
169
	    terminated();
170
	}
171
	
172
	/* (non-Javadoc)
173
	 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
174
	 */
175
	public boolean canResume() {
176
		return !isTerminated() && isSuspended();
177
	}
178
	
179
	/* (non-Javadoc)
180
	 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
181
	 */
182
	public boolean canSuspend() {
183
		return !isTerminated() && !isSuspended();
184
	}
185
	
186
	/* (non-Javadoc)
187
	 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
188
	 */
189
	public boolean isSuspended() {
190
		return fSuspended;
191
	}
192
	
193
	/* (non-Javadoc)
194
	 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
195
	 */
196
	public void resume() throws DebugException {
197
	    fSuspended= false;
198
	    fController.resume();
199
	}
200
	
201
	/**
202
	 * Notification the target has suspended for the given reason
203
	 * 
204
	 * @param detail reason for the suspend
205
	 */
206
	public void suspended(int detail) {
207
		fSuspended = true;
208
		fThread.setStepping(false);
209
		fThread.fireSuspendEvent(detail);
210
	}	
211
	
212
	/* (non-Javadoc)
213
	 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
214
	 */
215
	public void suspend() throws DebugException {
216
		fController.suspend();
217
	}
218
	
219
	/* (non-Javadoc)
220
	 * @see org.eclipse.debug.core.IBreakpointListener#breakpointAdded(org.eclipse.debug.core.model.IBreakpoint)
221
	 */
222
	public void breakpointAdded(IBreakpoint breakpoint) {
223
		fController.handleBreakpoint(breakpoint, true);
224
        if (breakpoint instanceof AntLineBreakpoint) {
225
            if (((AntLineBreakpoint) breakpoint).isRunToLine()) {
226
                if (fRunToLineBreakpoints == null) {
227
                    fRunToLineBreakpoints= new ArrayList();
228
                }
229
                fRunToLineBreakpoints.add(breakpoint);
230
            }
231
        }
232
	}
233
234
    /* (non-Javadoc)
235
	 * @see org.eclipse.debug.core.IBreakpointListener#breakpointRemoved(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
236
	 */
237
	public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
238
		fController.handleBreakpoint(breakpoint, false);
239
        if (fRunToLineBreakpoints != null) {
240
            if (fRunToLineBreakpoints.remove(breakpoint) && fRunToLineBreakpoints.isEmpty()) {
241
                fRunToLineBreakpoints= null;
242
            }
243
        }
244
	}
245
	
246
	/* (non-Javadoc)
247
	 * @see org.eclipse.debug.core.IBreakpointListener#breakpointChanged(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
248
	 */
249
	public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
250
		if (supportsBreakpoint(breakpoint)) {
251
			try {
252
				if (breakpoint.isEnabled() && DebugPlugin.getDefault().getBreakpointManager().isEnabled()) {
253
					breakpointAdded(breakpoint);
254
				} else {
255
					breakpointRemoved(breakpoint, null);
256
				}
257
			} catch (CoreException e) {
258
			}
259
		}
260
	}
261
	
262
	/* (non-Javadoc)
263
	 * @see org.eclipse.debug.core.model.IDisconnect#canDisconnect()
264
	 */
265
	public boolean canDisconnect() {
266
		return false;
267
	}
268
	
269
	/* (non-Javadoc)
270
	 * @see org.eclipse.debug.core.model.IDisconnect#disconnect()
271
	 */
272
	public void disconnect() throws DebugException {
273
	}
274
	
275
	/* (non-Javadoc)
276
	 * @see org.eclipse.debug.core.model.IDisconnect#isDisconnected()
277
	 */
278
	public boolean isDisconnected() {
279
		return false;
280
	}
281
	
282
	/* (non-Javadoc)
283
	 * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#supportsStorageRetrieval()
284
	 */
285
	public boolean supportsStorageRetrieval() {
286
		return false;
287
	}
288
	
289
	/* (non-Javadoc)
290
	 * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#getMemoryBlock(long, long)
291
	 */
292
	public IMemoryBlock getMemoryBlock(long startAddress, long length) throws DebugException {
293
		return null;
294
	}
295
296
	/**
297
	 * Notification we have connected to the Ant build logger and it has started.
298
	 * Resume the build.
299
	 */
300
	public void buildStarted() {
301
		fireCreationEvent();
302
		installDeferredBreakpoints();
303
		try {
304
			resume();
305
		} catch (DebugException e) {
306
		}
307
	}
308
	
309
	/**
310
	 * Install breakpoints that are already registered with the breakpoint
311
	 * manager if the breakpoint manager is enabled and the breakpoint is enabled.
312
	 */
313
	private void installDeferredBreakpoints() {
314
		IBreakpointManager manager= DebugPlugin.getDefault().getBreakpointManager();
315
		if (!manager.isEnabled()) {
316
			return;
317
		}
318
		IBreakpoint[] breakpoints = manager.getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
319
		for (int i = 0; i < breakpoints.length; i++) {
320
            IBreakpoint breakpoint= breakpoints[i];
321
            try {
322
                if (breakpoint.isEnabled()) {
323
                    breakpointAdded(breakpoints[i]);
324
                }
325
            } catch (CoreException e) {
326
            }
327
		}
328
	}
329
	
330
	/**
331
	 * Called when this debug target terminates.
332
	 */
333
	public void terminated() {
334
		fThreads= new IThread[0];
335
		fTerminated = true;
336
		fSuspended = false;
337
		if (DebugPlugin.getDefault() != null) {
338
			DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this);
339
			DebugPlugin.getDefault().removeDebugEventListener(this);
340
			DebugPlugin.getDefault().getBreakpointManager().removeBreakpointManagerListener(this);
341
		}
342
		if (!getProcess().isTerminated()) {
343
		    try {
344
                fProcess.terminate();
345
                resume();
346
		    } catch (DebugException e) {       
347
		    }
348
		}
349
		if (DebugPlugin.getDefault() != null) {
350
			fireTerminateEvent();
351
		}
352
	}
353
	
354
	/**
355
	 * Single step the Ant build.
356
	 * 
357
	 * @throws DebugException if the request fails
358
	 */
359
	public void stepOver() {
360
	    fSuspended= false;
361
		fController.stepOver();
362
	}
363
	
364
	/**
365
	 * Step-into the Ant build.
366
	 * 
367
	 * @throws DebugException if the request fails
368
	 */
369
	public void stepInto() {
370
	    fSuspended= false;
371
	    fController.stepInto();
372
	}
373
	
374
	/**
375
	 * Notification a breakpoint was encountered. Determine
376
	 * which breakpoint was hit and fire a suspend event.
377
	 * 
378
	 * @param event debug event
379
	 */
380
	public void breakpointHit(String event) {
381
		// determine which breakpoint was hit, and set the thread's breakpoint
382
		String[] datum= event.split(DebugMessageIds.MESSAGE_DELIMITER);
383
		String fileName= datum[1];
384
		int lineNumber = Integer.parseInt(datum[2]);
385
		IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
386
        boolean found= false;
387
		for (int i = 0; i < breakpoints.length; i++) {
388
           ILineBreakpoint lineBreakpoint = (ILineBreakpoint)breakpoints[i];
389
           if (setThreadBreakpoint(lineBreakpoint, lineNumber, fileName)) {
390
               found= true;
391
               break;
392
           }
393
		}
394
        if (!found && fRunToLineBreakpoints != null) {
395
            Iterator iter= fRunToLineBreakpoints.iterator();
396
            while (iter.hasNext()) {
397
                ILineBreakpoint lineBreakpoint = (ILineBreakpoint) iter.next();
398
                if (setThreadBreakpoint(lineBreakpoint, lineNumber, fileName)) {
399
                    break;
400
                }
401
            }
402
        }
403
		suspended(DebugEvent.BREAKPOINT);
404
	}	
405
    
406
    private boolean setThreadBreakpoint(ILineBreakpoint lineBreakpoint, int lineNumber, String fileName) {
407
        try {
408
            if (lineBreakpoint.getLineNumber() == lineNumber && 
409
                    fileName.equals(lineBreakpoint.getMarker().getResource().getLocation().toOSString())) {
410
                fThread.setBreakpoints(new IBreakpoint[]{lineBreakpoint});
411
                return true;
412
            }
413
        } catch (CoreException e) {
414
        }
415
        return false;
416
    }
417
	
418
    public void breakpointHit (IBreakpoint breakpoint) {
419
        fThread.setBreakpoints(new IBreakpoint[]{breakpoint});
420
        suspended(DebugEvent.BREAKPOINT);
421
    }
422
    
423
	public void getStackFrames() {
424
		fController.getStackFrames();
425
	}
426
	
427
	public void getProperties() {
428
		fController.getProperties();
429
	}
430
431
    /* (non-Javadoc)
432
     * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
433
     */
434
    public void handleDebugEvents(DebugEvent[] events) {
435
        for (int i = 0; i < events.length; i++) {
436
            DebugEvent event = events[i];
437
            if (event.getKind() == DebugEvent.TERMINATE && event.getSource().equals(fProcess)) {
438
                terminated();
439
            }
440
        }
441
    }
442
    
443
    /**
444
     * When the breakpoint manager disables, remove all registered breakpoints
445
     * requests from the VM. When it enables, reinstall them.
446
     *
447
     * @see org.eclipse.debug.core.IBreakpointManagerListener#breakpointManagerEnablementChanged(boolean)
448
     */
449
    public void breakpointManagerEnablementChanged(boolean enabled) {
450
        IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
451
        for (int i = 0; i < breakpoints.length; i++) {
452
            IBreakpoint breakpoint = breakpoints[i];
453
            if (enabled) {
454
                breakpointAdded(breakpoint);
455
            } else {
456
                breakpointRemoved(breakpoint, null);
457
            }
458
        }
459
    }
460
461
	public IAntDebugController getAntDebugController() {
462
		return fController;
463
	}   
464
}
(-)src/org/eclipse/ant/internal/launching/debug/model/AntLineBreakpoint.java (+112 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug.model;
12
13
import com.ibm.icu.text.MessageFormat;
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.ant.internal.launching.debug.IAntDebugConstants;
18
import org.eclipse.core.resources.IMarker;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IWorkspaceRunnable;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.debug.core.DebugException;
24
import org.eclipse.debug.core.DebugPlugin;
25
import org.eclipse.debug.core.model.IBreakpoint;
26
import org.eclipse.debug.core.model.LineBreakpoint;
27
28
/**
29
 * Ant line breakpoint
30
 */
31
public class AntLineBreakpoint extends LineBreakpoint {
32
	
33
	/**
34
	 * Default constructor is required for the breakpoint manager
35
	 * to re-create persisted breakpoints. After instantiating a breakpoint,
36
	 * the <code>setMarker(...)</code> method is called to restore
37
	 * this breakpoint's attributes.
38
	 */
39
	public AntLineBreakpoint() {
40
	}
41
	
42
	/**
43
	 * Constructs a line breakpoint on the given resource at the given
44
	 * line number. The line number is 1-based (i.e. the first line of a
45
	 * file is line number 1).
46
	 * 
47
	 * @param resource file on which to set the breakpoint
48
	 * @param lineNumber 1-based line number of the breakpoint
49
	 * @throws CoreException if unable to create the breakpoint
50
	 */
51
	public AntLineBreakpoint(IResource resource, int lineNumber) throws CoreException {
52
	    this(resource, lineNumber, new HashMap(), true);
53
	}
54
	
55
	/**
56
	 * Constructs a line breakpoint on the given resource at the given
57
	 * line number. The line number is 1-based (i.e. the first line of a
58
	 * file is line number 1).
59
	 * 
60
	 * @param resource file on which to set the breakpoint
61
	 * @param lineNumber 1-based line number of the breakpoint
62
	 * @param attributes the marker attributes to set
63
	 * @param register whether to add this breakpoint to the breakpoint manager
64
	 * @throws CoreException if unable to create the breakpoint
65
	 */
66
	public AntLineBreakpoint(final IResource resource, final int lineNumber, final Map attributes, final boolean register) throws CoreException {
67
	    IWorkspaceRunnable wr= new IWorkspaceRunnable() {
68
			public void run(IProgressMonitor monitor) throws CoreException {
69
			    IMarker marker = resource.createMarker(IAntDebugConstants.ID_ANT_LINE_BREAKPOINT_MARKER);
70
			    setMarker(marker);
71
			    attributes.put(IBreakpoint.ENABLED, Boolean.TRUE);
72
			    attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
73
			    attributes.put(IBreakpoint.ID, IAntDebugConstants.ID_ANT_DEBUG_MODEL);
74
                attributes.put(IMarker.MESSAGE, MessageFormat.format(DebugModelMessages.AntLineBreakpoint_0, new String[] {Integer.toString(lineNumber)}));
75
			    ensureMarker().setAttributes(attributes);
76
                
77
                register(register);
78
			}
79
	    };
80
	    run(getMarkerRule(resource), wr);
81
	}
82
	
83
	/* (non-Javadoc)
84
	 * @see org.eclipse.debug.core.model.IBreakpoint#getModelIdentifier()
85
	 */
86
	public String getModelIdentifier() {
87
		return IAntDebugConstants.ID_ANT_DEBUG_MODEL;
88
	}
89
90
    /**
91
     * @return whether this breakpoint is a run to line breakpoint
92
     */
93
    public boolean isRunToLine() {
94
        try {
95
            return ensureMarker().getAttribute(IAntDebugConstants.ANT_RUN_TO_LINE, false);
96
        } catch (DebugException e) {
97
           return false;
98
        }
99
    }
100
    
101
    /**
102
     * Add this breakpoint to the breakpoint manager,
103
     * or sets it as unregistered.
104
     */
105
    private void register(boolean register) throws CoreException {
106
        if (register) {
107
            DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(this);
108
        } else {
109
            setRegistered(false);
110
        }
111
    }
112
}
(-)src/org/eclipse/ant/internal/launching/debug/model/AntProperties.java (+109 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug.model;
12
13
import org.eclipse.debug.core.DebugException;
14
import org.eclipse.debug.core.model.IValue;
15
import org.eclipse.debug.core.model.IVariable;
16
17
public class AntProperties extends AntDebugElement implements IVariable {
18
	
19
	private IValue fValue;
20
	private String fName;
21
    private boolean fValid= true;
22
23
	public AntProperties(AntDebugTarget target, String name) {
24
		super(target);
25
		fName= name;
26
	}
27
28
	/* (non-Javadoc)
29
	 * @see org.eclipse.debug.core.model.IVariable#getValue()
30
	 */
31
	public synchronized IValue getValue() throws DebugException {
32
        int attempts= 0;
33
        while (!fValid && !getDebugTarget().isTerminated()) {
34
            try {
35
                wait(50);
36
            } catch (InterruptedException e) {
37
            }
38
            if (attempts == 20 && !fValid && !getDebugTarget().isTerminated()) {
39
                throwDebugException(DebugModelMessages.AntProperties_1);
40
            }
41
            attempts++;
42
        }
43
 		return fValue;
44
	}
45
    
46
    public IValue getLastValue() {
47
        return fValue;
48
    }
49
50
	/* (non-Javadoc)
51
	 * @see org.eclipse.debug.core.model.IVariable#getName()
52
	 */
53
	public String getName() {
54
		return fName;
55
	}
56
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
59
	 */
60
	public String getReferenceTypeName() {
61
		return ""; //$NON-NLS-1$
62
	}
63
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
66
	 */
67
	public boolean hasValueChanged() {
68
		return false;
69
	}
70
71
	/* (non-Javadoc)
72
	 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
73
	 */
74
	public void setValue(String expression) {
75
	}
76
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
79
	 */
80
	public void setValue(IValue value) {
81
		fValue= value;
82
	}
83
84
	/* (non-Javadoc)
85
	 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
86
	 */
87
	public boolean supportsValueModification() {
88
		return false;
89
	}
90
91
	/* (non-Javadoc)
92
	 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
93
	 */
94
	public boolean verifyValue(String expression) {
95
		return false;
96
	}
97
98
	/* (non-Javadoc)
99
	 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
100
	 */
101
	public boolean verifyValue(IValue value) {
102
		return false;
103
	}
104
105
    public synchronized void setValid(boolean valid) {
106
        fValid= valid;        
107
        notifyAll();
108
    }
109
}
(-)src/org/eclipse/ant/internal/launching/debug/model/AntPropertiesValue.java (+71 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Brock Janiczak (brockj@tpg.com.au) - bug 154907
11
 *******************************************************************************/
12
package org.eclipse.ant.internal.launching.debug.model;
13
14
import java.util.ArrayList;
15
import java.util.Collections;
16
import java.util.List;
17
import org.eclipse.debug.core.model.IValue;
18
import org.eclipse.debug.core.model.IVariable;
19
20
public class AntPropertiesValue extends AntDebugElement implements IValue {
21
	
22
	private List fProperties= new ArrayList();
23
	
24
	public AntPropertiesValue(AntDebugTarget target) {
25
		super(target);
26
	}
27
	
28
	/* (non-Javadoc)
29
	 * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
30
	 */
31
	public String getReferenceTypeName() {
32
		return ""; //$NON-NLS-1$
33
	}
34
	
35
	/* (non-Javadoc)
36
	 * @see org.eclipse.debug.core.model.IValue#getValueString()
37
	 */
38
	public String getValueString() {
39
		return ""; //$NON-NLS-1$
40
	}
41
	
42
	/* (non-Javadoc)
43
	 * @see org.eclipse.debug.core.model.IValue#isAllocated()
44
	 */
45
	public boolean isAllocated() {
46
		return true;
47
	}
48
	
49
	/* (non-Javadoc)
50
	 * @see org.eclipse.debug.core.model.IValue#getVariables()
51
	 */
52
	public IVariable[] getVariables() {
53
		Collections.sort(fProperties);
54
		return (IVariable[])fProperties.toArray(new IVariable[fProperties.size()]);
55
	}
56
	
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.debug.core.model.IValue#hasVariables()
59
	 */
60
	public boolean hasVariables() {
61
		return true;
62
	}
63
	
64
	protected void addProperties(List properties) {
65
		fProperties.addAll(properties);
66
	}
67
68
	public List getProperties() {
69
		return fProperties;
70
	}
71
}
(-)src/org/eclipse/ant/internal/launching/debug/model/AntProperty.java (+121 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Brock Janiczak (brockj@tpg.com.au) - bug 154907
11
 *******************************************************************************/
12
package org.eclipse.ant.internal.launching.debug.model;
13
14
import org.eclipse.debug.core.model.IValue;
15
import org.eclipse.debug.core.model.IVariable;
16
17
/**
18
 * A property in an Ant build.
19
 */
20
public class AntProperty extends AntDebugElement implements IVariable, Comparable {
21
22
	private String fName;
23
	private AntValue fValue;
24
    private String fLabel;
25
	
26
	/**
27
	 * Constructs a variable associated with the debug target
28
	 * with the given name and value.
29
	 * 
30
	 * @param target the debug target
31
	 * @param name property name
32
	 * @param value property value
33
	 */
34
	public AntProperty(AntDebugTarget target, String name, String value) {
35
		super(target);
36
		fName = name;
37
		fValue= new AntValue(target, value);
38
	}
39
	
40
	/*
41
	 * @see org.eclipse.debug.core.model.IVariable#getValue()
42
	 */
43
	public IValue getValue() {
44
		return fValue;
45
	}
46
	
47
	/*
48
	 * @see org.eclipse.debug.core.model.IVariable#getName()
49
	 */
50
	public String getName() {
51
		return fName;
52
	}
53
	
54
	/*
55
	 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
56
	 */
57
	public String getReferenceTypeName() {
58
		return ""; //$NON-NLS-1$
59
	}
60
	
61
	/*
62
	 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
63
	 */
64
	public boolean hasValueChanged() {
65
		return false;
66
	}
67
	
68
	/*
69
	 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
70
	 */
71
	public void setValue(String expression) {
72
	}
73
	
74
	/*
75
	 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
76
	 */
77
	public void setValue(IValue value) {
78
	}
79
	
80
	/*
81
	 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
82
	 */
83
	public boolean supportsValueModification() {
84
		return false;
85
	}
86
	
87
	/*
88
	 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
89
	 */
90
	public boolean verifyValue(String expression) {
91
		return false;
92
	}
93
	
94
	/*
95
	 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
96
	 */
97
	public boolean verifyValue(IValue value) {
98
		return false;
99
	}
100
101
    /**
102
     * @return the text used to render this property
103
     */
104
    public String getText() {
105
        if (fLabel == null) {
106
            StringBuffer buffer= new StringBuffer(getName());
107
            buffer.append("= "); //$NON-NLS-1$
108
            buffer.append(fValue.getValueString());          
109
            fLabel=  buffer.toString();
110
        } 
111
        return fLabel;
112
    }
113
    
114
    /*
115
     * @see java.lang.Comparable#compareTo(java.lang.Object)
116
     */
117
    public int compareTo(Object other) {
118
    	AntProperty otherProperty = (AntProperty) other;
119
    	return fName.compareToIgnoreCase(otherProperty.getName());
120
    }
121
}
(-)src/org/eclipse/ant/internal/launching/debug/model/AntStackFrame.java (+314 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug.model;
12
13
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.runtime.Path;
16
import org.eclipse.debug.core.DebugException;
17
import org.eclipse.debug.core.model.IRegisterGroup;
18
import org.eclipse.debug.core.model.IStackFrame;
19
import org.eclipse.debug.core.model.IThread;
20
import org.eclipse.debug.core.model.IVariable;
21
22
/**
23
 * Ant stack frame.
24
 */
25
public class AntStackFrame extends AntDebugElement implements IStackFrame {
26
	
27
	private AntThread fThread;
28
	private String fName;
29
	private int fLineNumber;
30
	private String fFilePath;
31
	private int fId;
32
    private String fFullPath;
33
	
34
	/**
35
	 * Constructs a stack frame in the given thread with the given id.
36
	 * 
37
	 * @param antThread
38
	 * @param id stack frame id (0 is the top of the stack)
39
	 */
40
	public AntStackFrame(AntThread antThread, int id, String name, String fullPath, int lineNumber) {
41
		super((AntDebugTarget) antThread.getDebugTarget());
42
		fId = id;
43
		fThread = antThread;
44
		fLineNumber= lineNumber;
45
		fName= name;
46
		setFilePath(fullPath);
47
	}
48
	
49
	public void setId(int id) {
50
		fId= id;
51
	}
52
	
53
	/* (non-Javadoc)
54
	 * @see org.eclipse.debug.core.model.IStackFrame#getThread()
55
	 */
56
	public IThread getThread() {
57
		return fThread;
58
	}
59
	
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.debug.core.model.IStackFrame#getVariables()
62
	 */
63
	public IVariable[] getVariables() throws DebugException {
64
	   return fThread.getVariables();
65
	}
66
67
    /* (non-Javadoc)
68
	 * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
69
	 */
70
	public boolean hasVariables() {
71
		return isSuspended();
72
	}
73
	
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
76
	 */
77
	public int getLineNumber() {
78
		return fLineNumber;
79
	}
80
	
81
	public void setLineNumber(int lineNumber) {
82
		fLineNumber= lineNumber;
83
	}
84
	
85
	public void setFilePath(String fullPath) {
86
        fFullPath= fullPath;
87
        IFile file= AntLaunchingUtil.getFileForLocation(fullPath, null);
88
        if (file != null) {
89
            fFilePath= file.getProjectRelativePath().toString();
90
        } else {
91
            fFilePath= new Path(fullPath).lastSegment();
92
        }
93
	}
94
	
95
	public String getFilePath() {
96
		return fFullPath;
97
	}
98
	
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
101
	 */
102
	public int getCharStart() {
103
		return -1;
104
	}
105
	
106
	/* (non-Javadoc)
107
	 * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
108
	 */
109
	public int getCharEnd() {
110
		return -1;
111
	}
112
	
113
	/* (non-Javadoc)
114
	 * @see org.eclipse.debug.core.model.IStackFrame#getName()
115
	 */
116
	public String getName() {
117
		return fName;
118
	}
119
	
120
	public void setName(String name) {
121
		fName= name;
122
	}
123
	
124
	/* (non-Javadoc)
125
	 * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
126
	 */
127
	public IRegisterGroup[] getRegisterGroups() {
128
		return null;
129
	}
130
	
131
	/* (non-Javadoc)
132
	 * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
133
	 */
134
	public boolean hasRegisterGroups() {
135
		return false;
136
	}
137
	
138
	/* (non-Javadoc)
139
	 * @see org.eclipse.debug.core.model.IStep#canStepInto()
140
	 */
141
	public boolean canStepInto() {
142
		return getThread().canStepInto();
143
	}
144
	
145
	/* (non-Javadoc)
146
	 * @see org.eclipse.debug.core.model.IStep#canStepOver()
147
	 */
148
	public boolean canStepOver() {
149
		return getThread().canStepOver();
150
	}
151
	
152
	/* (non-Javadoc)
153
	 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
154
	 */
155
	public boolean canStepReturn() {
156
		return getThread().canStepReturn();
157
	}
158
	
159
	/* (non-Javadoc)
160
	 * @see org.eclipse.debug.core.model.IStep#isStepping()
161
	 */
162
	public boolean isStepping() {
163
		return getThread().isStepping();
164
	}
165
	
166
	/* (non-Javadoc)
167
	 * @see org.eclipse.debug.core.model.IStep#stepInto()
168
	 */
169
	public void stepInto() throws DebugException {
170
		getThread().stepInto();
171
	}
172
	
173
	/* (non-Javadoc)
174
	 * @see org.eclipse.debug.core.model.IStep#stepOver()
175
	 */
176
	public void stepOver() throws DebugException {
177
		getThread().stepOver();
178
	}
179
	
180
	/* (non-Javadoc)
181
	 * @see org.eclipse.debug.core.model.IStep#stepReturn()
182
	 */
183
	public void stepReturn() throws DebugException {
184
		getThread().stepReturn();
185
	}
186
	
187
	/* (non-Javadoc)
188
	 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
189
	 */
190
	public boolean canResume() {
191
		return getThread().canResume();
192
	}
193
	
194
	/* (non-Javadoc)
195
	 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
196
	 */
197
	public boolean canSuspend() {
198
		return getThread().canSuspend();
199
	}
200
	
201
	/* (non-Javadoc)
202
	 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
203
	 */
204
	public boolean isSuspended() {
205
		return getThread().isSuspended();
206
	}
207
	
208
	/* (non-Javadoc)
209
	 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
210
	 */
211
	public void resume() throws DebugException {
212
		getThread().resume();
213
	}
214
	
215
	/* (non-Javadoc)
216
	 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
217
	 */
218
	public void suspend() throws DebugException {
219
		getThread().suspend();
220
	}
221
	
222
	/* (non-Javadoc)
223
	 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
224
	 */
225
	public boolean canTerminate() {
226
		return getThread().canTerminate();
227
	}
228
	
229
	/* (non-Javadoc)
230
	 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
231
	 */
232
	public boolean isTerminated() {
233
		return getThread().isTerminated();
234
	}
235
	
236
	/* (non-Javadoc)
237
	 * @see org.eclipse.debug.core.model.ITerminate#terminate()
238
	 */
239
	public void terminate() throws DebugException {
240
		getThread().terminate();
241
	}
242
	
243
	/**
244
	 * Returns the name of the buildfile this stack frame is associated
245
	 * with.
246
	 * 
247
	 * @return the name of the buildfile this stack frame is associated
248
	 * with
249
	 */
250
	public String getSourceName() {
251
		return fFilePath;
252
	}
253
	
254
	/* (non-Javadoc)
255
	 * @see java.lang.Object#equals(java.lang.Object)
256
	 */
257
	public boolean equals(Object obj) {
258
		if (obj instanceof AntStackFrame) {
259
			AntStackFrame sf = (AntStackFrame)obj;
260
			if (getSourceName() != null) {
261
				return getSourceName().equals(sf.getSourceName()) &&
262
					sf.getLineNumber() == getLineNumber() &&
263
					sf.fId == fId;
264
			} 
265
			return sf.fId == fId;
266
		}
267
		return false;
268
	}
269
	
270
	/* (non-Javadoc)
271
	 * @see java.lang.Object#hashCode()
272
	 */
273
	public int hashCode() {
274
	    if (getSourceName() == null) {
275
	        return fId;
276
	    }
277
	    return getSourceName().hashCode() + fId;
278
	}
279
	
280
	/**
281
	 * Returns this stack frame's unique identifier within its thread
282
	 * 
283
	 * @return this stack frame's unique identifier within its thread
284
	 */
285
	protected int getIdentifier() {
286
		return fId;
287
	}
288
    
289
    /**
290
     * Returns the system, user or runtime property
291
     * name, or <code>null</code> if unable to resolve a property with the name.
292
     *
293
     * @param propertyName the name of the variable to search for
294
     * @return a property, or <code>null</code> if none
295
     */
296
    public AntProperty findProperty(String propertyName) {
297
        try {
298
            IVariable[] groups= getVariables();
299
            for (int i = 0; i < groups.length; i++) {
300
                AntProperties propertiesGrouping = (AntProperties) groups[i];
301
                AntPropertiesValue value= (AntPropertiesValue) propertiesGrouping.getValue();
302
                IVariable[] properties= value.getVariables();
303
                for (int j = 0; j < properties.length; j++) {
304
                    AntProperty property = (AntProperty) properties[j];
305
                    if (property.getName().equals(propertyName)) {
306
                        return property;
307
                    }
308
                }
309
            }
310
        } catch (DebugException e) {
311
        }
312
        return null;
313
    } 
314
}
(-)src/org/eclipse/ant/internal/launching/debug/model/AntThread.java (+480 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug.model;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.ant.internal.launching.debug.DebugMessageIds;
17
import org.eclipse.debug.core.DebugEvent;
18
import org.eclipse.debug.core.DebugException;
19
import org.eclipse.debug.core.model.IBreakpoint;
20
import org.eclipse.debug.core.model.IStackFrame;
21
import org.eclipse.debug.core.model.IThread;
22
import org.eclipse.debug.core.model.IVariable;
23
24
/**
25
 * An Ant build thread.
26
 */
27
public class AntThread extends AntDebugElement implements IThread {
28
	
29
	/**
30
	 * Breakpoints this thread is suspended at or <code>null</code>
31
	 * if none.
32
	 */
33
	private IBreakpoint[] fBreakpoints;
34
	
35
	/**
36
	 * The stackframes associated with this thread
37
	 */
38
	private List fFrames= new ArrayList(1);
39
	
40
	/**
41
	 * The stackframes to be reused on suspension
42
	 */
43
	private List fOldFrames;
44
	
45
	/**
46
	 * Whether this thread is stepping
47
	 */
48
	private boolean fStepping = false;
49
	
50
	private boolean fRefreshProperties= true;
51
	
52
	/**
53
	 * The user properties associated with this thread
54
	 */
55
	private AntProperties fUserProperties;
56
	
57
	/**
58
	 * The system properties associated with this thread
59
	 */
60
	private AntProperties fSystemProperties;
61
	
62
	/**
63
	 * The properties set during the build associated with this thread
64
	 */
65
	private AntProperties fRuntimeProperties;
66
    
67
    private Object fPropertiesLock= new Object();
68
	
69
	/**
70
	 * Constructs a new thread for the given target
71
	 * 
72
	 * @param target the Ant Build
73
	 */
74
	public AntThread(AntDebugTarget target) {
75
		super(target);
76
	}
77
	
78
	/* (non-Javadoc)
79
	 * @see org.eclipse.debug.core.model.IThread#getStackFrames()
80
	 */
81
	public synchronized IStackFrame[] getStackFrames() throws DebugException {
82
		if (isSuspended()) {
83
			if (fFrames.size() == 0) {
84
				getStackFrames0();
85
			}
86
		} 
87
		
88
		return (IStackFrame[]) fFrames.toArray(new IStackFrame[fFrames.size()]);
89
	}
90
	
91
	/**
92
	 * Retrieves the current stack frames in the thread
93
	 * possibly waiting until the frames are populated
94
     * 
95
	 */
96
	private void getStackFrames0() throws DebugException {
97
        synchronized (fFrames) {
98
    		getAntDebugTarget().getStackFrames();
99
            if (fFrames.size() > 0) {
100
                //frames set..no need to wait
101
                return;
102
            }
103
            int attempts= 0;
104
    		try {
105
                while (fFrames.size() == 0 && !isTerminated()) {
106
                    fFrames.wait(50);
107
                    if (attempts == 20 && fFrames.size() == 0 && !isTerminated()) {
108
                        throwDebugException(DebugModelMessages.AntThread_3);
109
                    }
110
                    attempts++;
111
                }
112
    		} catch (InterruptedException e) {
113
    		}
114
        }
115
	}
116
	
117
	/* (non-Javadoc)
118
	 * @see org.eclipse.debug.core.model.IThread#hasStackFrames()
119
	 */
120
	public boolean hasStackFrames() throws DebugException {
121
		return isSuspended();
122
	}
123
	
124
	/* (non-Javadoc)
125
	 * @see org.eclipse.debug.core.model.IThread#getPriority()
126
	 */
127
	public int getPriority() throws DebugException {
128
		return 0;
129
	}
130
	
131
	/* (non-Javadoc)
132
	 * @see org.eclipse.debug.core.model.IThread#getTopStackFrame()
133
	 */
134
	public synchronized IStackFrame getTopStackFrame() throws DebugException {
135
		if (isSuspended()) {
136
			if (fFrames.size() == 0) {
137
				getStackFrames0();
138
			}
139
			if (fFrames.size() > 0) {
140
				return (IStackFrame)fFrames.get(0);
141
			}
142
		} 
143
		return null;
144
	}
145
	
146
	/* (non-Javadoc)
147
	 * @see org.eclipse.debug.core.model.IThread#getName()
148
	 */
149
	public String getName() {
150
		return "Thread [Ant Build]"; //$NON-NLS-1$
151
	}
152
	
153
	/* (non-Javadoc)
154
	 * @see org.eclipse.debug.core.model.IThread#getBreakpoints()
155
	 */
156
	public IBreakpoint[] getBreakpoints() {
157
		if (fBreakpoints == null) {
158
			return new IBreakpoint[0];
159
		}
160
		return fBreakpoints;
161
	}
162
	
163
	/**
164
	 * Sets the breakpoints this thread is suspended at, or <code>null</code>
165
	 * if none.
166
	 * 
167
	 * @param breakpoints the breakpoints this thread is suspended at, or <code>null</code>
168
	 * if none
169
	 */
170
	protected void setBreakpoints(IBreakpoint[] breakpoints) {
171
		fBreakpoints = breakpoints;
172
	}
173
	
174
	/* (non-Javadoc)
175
	 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
176
	 */
177
	public boolean canResume() {
178
		return isSuspended();
179
	}
180
	
181
	/* (non-Javadoc)
182
	 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
183
	 */
184
	public boolean canSuspend() {
185
		return !isSuspended();
186
	}
187
	
188
	/* (non-Javadoc)
189
	 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
190
	 */
191
	public boolean isSuspended() {
192
		return getDebugTarget().isSuspended();
193
	}
194
	
195
	/* (non-Javadoc)
196
	 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
197
	 */
198
	public synchronized void resume() throws DebugException {
199
		aboutToResume(DebugEvent.CLIENT_REQUEST, false);
200
		getDebugTarget().resume();
201
	}
202
	
203
	/* (non-Javadoc)
204
	 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
205
	 */
206
	public synchronized void suspend() throws DebugException {
207
		getDebugTarget().suspend();
208
	}
209
	
210
	/* (non-Javadoc)
211
	 * @see org.eclipse.debug.core.model.IStep#canStepInto()
212
	 */
213
	public boolean canStepInto() {
214
	    return isSuspended();
215
	}
216
	
217
	/* (non-Javadoc)
218
	 * @see org.eclipse.debug.core.model.IStep#canStepOver()
219
	 */
220
	public boolean canStepOver() {
221
		return isSuspended();
222
	}
223
	
224
	/* (non-Javadoc)
225
	 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
226
	 */
227
	public boolean canStepReturn() {
228
		return false;
229
	}
230
	
231
	/* (non-Javadoc)
232
	 * @see org.eclipse.debug.core.model.IStep#isStepping()
233
	 */
234
	public boolean isStepping() {
235
		return fStepping;
236
	}
237
	
238
	/* (non-Javadoc)
239
	 * @see org.eclipse.debug.core.model.IStep#stepInto()
240
	 */
241
	public synchronized void stepInto() throws DebugException {
242
	    aboutToResume(DebugEvent.STEP_INTO, true);
243
		((AntDebugTarget)getDebugTarget()).stepInto();
244
	}
245
	
246
	private void aboutToResume(int detail, boolean stepping) {
247
	    fRefreshProperties= true;
248
	    fOldFrames= new ArrayList(fFrames);
249
        fFrames.clear();
250
        setPropertiesValid(false);
251
	    setStepping(stepping);
252
	    setBreakpoints(null);
253
		fireResumeEvent(detail);
254
    }
255
256
    private void setPropertiesValid(boolean valid) {
257
        if (fUserProperties != null) {
258
            fUserProperties.setValid(valid);
259
            fSystemProperties.setValid(valid);
260
            fRuntimeProperties.setValid(valid);
261
        }
262
    }
263
264
    /* (non-Javadoc)
265
	 * @see org.eclipse.debug.core.model.IStep#stepOver()
266
	 */
267
	public synchronized void stepOver() throws DebugException {
268
	    aboutToResume(DebugEvent.STEP_OVER, true);
269
		((AntDebugTarget)getDebugTarget()).stepOver();
270
	}
271
	
272
	/* (non-Javadoc)
273
	 * @see org.eclipse.debug.core.model.IStep#stepReturn()
274
	 */
275
	public synchronized void stepReturn() throws DebugException {
276
	}
277
	
278
	/* (non-Javadoc)
279
	 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
280
	 */
281
	public boolean canTerminate() {
282
		return !isTerminated();
283
	}
284
	
285
	/* (non-Javadoc)
286
	 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
287
	 */
288
	public boolean isTerminated() {
289
		return getDebugTarget().isTerminated();
290
	}
291
	
292
	/* (non-Javadoc)
293
	 * @see org.eclipse.debug.core.model.ITerminate#terminate()
294
	 */
295
	public void terminate() throws DebugException {
296
		fFrames.clear();
297
		getDebugTarget().terminate();
298
	}
299
	
300
	/**
301
	 * Sets whether this thread is stepping
302
	 * 
303
	 * @param stepping whether stepping
304
	 */
305
	protected void setStepping(boolean stepping) {
306
		fStepping = stepping;
307
	}
308
309
    public void buildStack(String data) { 
310
        synchronized (fFrames) {
311
            String[] strings= data.split(DebugMessageIds.MESSAGE_DELIMITER);
312
            //0 STACK message
313
            //1 targetName
314
            //2 taskName
315
            //3 filePath
316
            //4 lineNumber
317
            //5 ...
318
            if (fOldFrames != null && (strings.length - 1)/ 4 != fOldFrames.size()) {
319
                fOldFrames= null; //stack size changed..do not preserve
320
            }
321
            StringBuffer name;
322
            String filePath;
323
            int lineNumber;
324
            int stackFrameId= 0;
325
            String taskName;
326
            for (int i = 1; i < strings.length; i++) {
327
                if (strings[i].length() > 0) {
328
                    name= new StringBuffer(strings[i]);
329
                    taskName= strings[++i];
330
                    if (taskName.length() > 0) {
331
                        name.append(": "); //$NON-NLS-1$
332
                        name.append(taskName);
333
                    }
334
                } else {
335
                    name= new StringBuffer(strings[++i]);
336
                }
337
                filePath= strings[++i];
338
                lineNumber= Integer.parseInt(strings[++i]);
339
                addFrame(stackFrameId++, name.toString(), filePath, lineNumber);
340
            }
341
            //wake up the call from getStackFrames
342
            fFrames.notifyAll();
343
        }
344
    }
345
    
346
    private void addFrame(int stackFrameId, String name, String filePath, int lineNumber) {
347
    	AntStackFrame frame= getOldFrame();
348
    	
349
    	if (frame == null || !frame.getFilePath().equals(filePath)) {
350
    		frame= new AntStackFrame(this, stackFrameId, name, filePath, lineNumber);
351
    	} else {
352
    		frame.setFilePath(filePath);
353
    		frame.setId(stackFrameId);
354
    		frame.setLineNumber(lineNumber);
355
    		frame.setName(name);
356
    	}
357
		fFrames.add(frame);
358
    }
359
    
360
    private AntStackFrame getOldFrame() {
361
    	if (fOldFrames == null) {
362
    		return null;
363
    	}
364
    	AntStackFrame frame= (AntStackFrame) fOldFrames.remove(0);
365
    	if (fOldFrames.isEmpty()) {
366
    		fOldFrames= null;
367
    	}
368
    	return frame;
369
    }
370
    
371
    public void newProperties(String data) {
372
        synchronized (fPropertiesLock) {
373
            try {
374
                String[] datum= data.split(DebugMessageIds.MESSAGE_DELIMITER);
375
                if (fUserProperties == null) {
376
                    initializePropertyGroups();
377
                }
378
379
                List userProperties= ((AntPropertiesValue)fUserProperties.getLastValue()).getProperties();
380
                List systemProperties= ((AntPropertiesValue)fSystemProperties.getLastValue()).getProperties();
381
                List runtimeProperties= ((AntPropertiesValue)fRuntimeProperties.getLastValue()).getProperties();
382
                //0 PROPERTIES message
383
                //1 propertyName length
384
                //2 propertyName
385
                //3 propertyValue length
386
                //3 propertyValue
387
                //4 propertyType
388
                //5 ...
389
                if (datum.length > 1) { //new properties
390
                    StringBuffer propertyName;
391
                    StringBuffer propertyValue;
392
                    int propertyNameLength;
393
                    int propertyValueLength;
394
                    for (int i = 1; i < datum.length; i++) {
395
                        propertyNameLength= Integer.parseInt(datum[i]);
396
                        propertyName= new StringBuffer(datum[++i]);
397
                        while (propertyName.length() != propertyNameLength) {
398
                            propertyName.append(DebugMessageIds.MESSAGE_DELIMITER);
399
                            propertyName.append(datum[++i]);
400
                        }
401
402
                        propertyName= getAntDebugTarget().getAntDebugController().unescapeString(propertyName);
403
404
                        propertyValueLength= Integer.parseInt(datum[++i]);
405
                        if (propertyValueLength == 0 && i + 1 == datum.length) { //bug 81299
406
                            propertyValue= new StringBuffer(""); //$NON-NLS-1$
407
                        } else {
408
                            propertyValue= new StringBuffer(datum[++i]);
409
                        }
410
                        while (propertyValue.length() != propertyValueLength) {
411
                            propertyValue.append(DebugMessageIds.MESSAGE_DELIMITER);
412
                            propertyValue.append(datum[++i]);
413
                        }
414
415
                        propertyValue= getAntDebugTarget().getAntDebugController().unescapeString(propertyValue);
416
417
                        int propertyType= Integer.parseInt(datum[++i]);
418
                        addProperty(userProperties, systemProperties, runtimeProperties, propertyName.toString(), propertyValue.toString(), propertyType);
419
                    }
420
                }
421
            } finally {
422
                fRefreshProperties= false;
423
                setPropertiesValid(true);
424
                //wake up the call from getVariables
425
                fPropertiesLock.notifyAll();
426
            }
427
        }
428
	}
429
430
	private void addProperty(List userProperties, List systemProperties, List runtimeProperties, String propertyName, String propertyValue, int propertyType) {
431
		AntProperty property= new AntProperty((AntDebugTarget) getDebugTarget(), propertyName, propertyValue);
432
		switch (propertyType) {
433
			case DebugMessageIds.PROPERTY_SYSTEM:
434
				systemProperties.add(property);
435
				break;
436
			case DebugMessageIds.PROPERTY_USER:
437
				userProperties.add(property);
438
				break;
439
			case DebugMessageIds.PROPERTY_RUNTIME:
440
				runtimeProperties.add(property);
441
				break;
442
		}
443
	}
444
445
	private void initializePropertyGroups() {
446
        AntDebugTarget target= getAntDebugTarget();
447
		fUserProperties= new AntProperties(target, DebugModelMessages.AntThread_0);
448
		fUserProperties.setValue(new AntPropertiesValue(target));
449
		fSystemProperties= new AntProperties(target, DebugModelMessages.AntThread_1);
450
		fSystemProperties.setValue(new AntPropertiesValue(target));
451
		fRuntimeProperties= new AntProperties(target, DebugModelMessages.AntThread_2);
452
		fRuntimeProperties.setValue(new AntPropertiesValue(target));
453
	}
454
    
455
    protected IVariable[] getVariables() throws DebugException {
456
        synchronized (fPropertiesLock) {
457
            if (fRefreshProperties) {
458
                getAntDebugTarget().getProperties();
459
                if (fRefreshProperties) { 
460
                    //properties have not been set; need to wait
461
                    try {
462
                        int attempts= 0;
463
                        while (fRefreshProperties && !isTerminated()) {
464
                            fPropertiesLock.wait(50);
465
                            if (attempts == 20 && fRefreshProperties && !isTerminated()) {
466
                                throwDebugException(DebugModelMessages.AntThread_4);
467
                            }
468
                            attempts++;
469
                        }
470
                    } catch (InterruptedException ie) {
471
                    }
472
                }
473
            }
474
            if (fSystemProperties == null) {
475
                return new IVariable[0];
476
            }
477
            return new IVariable[]{fSystemProperties, fUserProperties, fRuntimeProperties};
478
        }
479
    }
480
}
(-)src/org/eclipse/ant/internal/launching/debug/model/AntValue.java (+71 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.debug.model;
12
13
import org.eclipse.ant.internal.launching.debug.IAntDebugConstants;
14
import org.eclipse.debug.core.model.IValue;
15
import org.eclipse.debug.core.model.IVariable;
16
17
public class AntValue extends AntDebugElement implements IValue  {
18
19
    private String fValueString;
20
    protected static final IVariable[] EMPTY = new IVariable[0];
21
    
22
    /**
23
     * @param target
24
     */
25
    public AntValue(AntDebugTarget target, String value) {
26
        super(target);
27
        fValueString= value;
28
    }
29
30
    /* (non-Javadoc)
31
     * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
32
     */
33
    public String getReferenceTypeName() {
34
        return ""; //$NON-NLS-1$
35
    }
36
37
    /* (non-Javadoc)
38
     * @see org.eclipse.debug.core.model.IValue#getValueString()
39
     */
40
    public String getValueString() {
41
        return fValueString;
42
    }
43
44
    /* (non-Javadoc)
45
     * @see org.eclipse.debug.core.model.IValue#isAllocated()
46
     */
47
    public boolean isAllocated() {
48
        return true;
49
    }
50
51
    /* (non-Javadoc)
52
     * @see org.eclipse.debug.core.model.IValue#getVariables()
53
     */
54
    public IVariable[] getVariables() {
55
        return EMPTY;
56
    }
57
58
    /* (non-Javadoc)
59
     * @see org.eclipse.debug.core.model.IValue#hasVariables()
60
     */
61
    public boolean hasVariables() {
62
        return false;
63
    }
64
65
    /* (non-Javadoc)
66
     * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
67
     */
68
    public String getModelIdentifier() {
69
        return IAntDebugConstants.ID_ANT_DEBUG_MODEL;
70
    }
71
}
(-)src/org/eclipse/ant/internal/launching/debug/model/DebugModelMessages.java (+39 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2004, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.ant.internal.launching.debug.model;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class DebugModelMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.ant.internal.ui.debug.model.DebugModelMessages";//$NON-NLS-1$
16
17
	public static String AntDebugTarget_0;
18
19
	public static String AntDebugModelPresentation_0;
20
	public static String AntDebugModelPresentation_1;
21
	public static String AntDebugModelPresentation_2;
22
	public static String AntDebugModelPresentation_3;
23
	public static String AntDebugModelPresentation_4;
24
	public static String AntDebugModelPresentation_5;
25
26
	public static String AntLineBreakpoint_0;
27
	public static String AntThread_0;
28
	public static String AntThread_1;
29
	public static String AntThread_2;
30
    public static String AntThread_3;
31
    public static String AntThread_4;
32
    
33
    public static String AntProperties_1;
34
    
35
	static {
36
		// load message values from bundle file
37
		NLS.initializeMessages(BUNDLE_NAME, DebugModelMessages.class);
38
	}
39
}
(-)src/org/eclipse/ant/internal/launching/debug/model/DebugModelMessages.properties (+28 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2004, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
AntDebugTarget_0=Ant Build
13
14
AntDebugModelPresentation_0=<not available>
15
AntDebugModelPresentation_1=\ line: {0}
16
AntDebugModelPresentation_2=(breakpoint at line {0} in {1})
17
AntDebugModelPresentation_3=\ (Suspended {0})
18
AntDebugModelPresentation_4=\ (Suspended)
19
AntDebugModelPresentation_5=(run to line {0} in {1})
20
21
AntLineBreakpoint_0=Ant breakpoint [line: {0}]
22
AntThread_0=User Properties
23
AntThread_1=System Properties
24
AntThread_2=Runtime Properties
25
AntThread_3=Request to retrieve Ant stack frames failed
26
AntThread_4=Request to retrieve Ant properties failed
27
28
AntProperties_1=Request to Ant properties value failed
(-)src/org/eclipse/ant/internal/launching/debug/model/RemoteAntDebugBuildListener.java (+322 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.launching.debug.model;
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.InputStreamReader;
17
import java.io.PrintWriter;
18
import java.net.Socket;
19
import java.net.UnknownHostException;
20
21
import org.eclipse.ant.internal.launching.AntLaunching;
22
import org.eclipse.ant.internal.launching.debug.DebugMessageIds;
23
import org.eclipse.ant.internal.launching.debug.IAntDebugController;
24
import org.eclipse.ant.internal.launching.launchConfigurations.RemoteAntBuildListener;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.debug.core.DebugEvent;
27
import org.eclipse.debug.core.DebugPlugin;
28
import org.eclipse.debug.core.ILaunch;
29
import org.eclipse.debug.core.model.IBreakpoint;
30
import org.eclipse.debug.core.model.ILineBreakpoint;
31
import org.eclipse.debug.core.model.IProcess;
32
33
public class RemoteAntDebugBuildListener extends RemoteAntBuildListener implements IAntDebugController {
34
	
35
	// sockets to communicate with the remote Ant debug build logger
36
	private Socket fRequestSocket;
37
	private PrintWriter fRequestWriter;
38
	private BufferedReader fResponseReader;
39
	
40
	private int fRequestPort= -1;
41
	private Thread fReaderThread;
42
	
43
	private AntDebugTarget fTarget;
44
	
45
	/**
46
	 * Reader thread that processes request responses from the remote Ant debug build logger
47
	 */
48
	private class ReaderThread extends Thread {
49
		public ReaderThread() {
50
			super("Ant Request Response Reader Thread"); //$NON-NLS-1$
51
			setDaemon(true);
52
		}
53
54
		public void run(){
55
			try { 
56
				String message= null; 
57
				while (fResponseReader != null) { 
58
				    synchronized (RemoteAntDebugBuildListener.this) {
59
				        if (fResponseReader != null && (message= fResponseReader.readLine()) != null) {
60
				            receiveMessage(message);
61
				        }
62
				    }
63
				} 
64
			} catch (IOException ie) { //the other end has shutdown
65
				RemoteAntDebugBuildListener.this.shutDown();
66
			} catch (Exception e) {
67
				AntLaunching.log("Internal error processing remote response", e); //$NON-NLS-1$
68
				RemoteAntDebugBuildListener.this.shutDown();
69
			}
70
		}
71
	}	
72
	
73
	public RemoteAntDebugBuildListener(ILaunch launch) {
74
		super(launch);
75
		//fDebug= true;
76
	}
77
	
78
	protected void receiveMessage(String message) {
79
		if (message.startsWith(DebugMessageIds.BUILD_STARTED)) {
80
			buildStarted();
81
		} else if (message.startsWith(DebugMessageIds.SUSPENDED)){
82
			handleSuspendMessage(message);
83
		} else if (message.startsWith(DebugMessageIds.TERMINATED)){
84
			fTarget.terminated();
85
		} else if (message.startsWith(DebugMessageIds.STACK)){
86
			AntThread thread= (AntThread) fTarget.getThreads()[0];
87
			thread.buildStack(message);
88
		} else if (message.startsWith(DebugMessageIds.PROPERTIES)){
89
		    AntThread thread= (AntThread) fTarget.getThreads()[0];
90
		    thread.newProperties(message);
91
		} else {
92
			super.receiveMessage(message);
93
		}
94
	}
95
96
    private void handleSuspendMessage(String message) {
97
        if (message.endsWith(DebugMessageIds.CLIENT_REQUEST)) {
98
        	fTarget.suspended(DebugEvent.CLIENT_REQUEST);
99
        } else if (message.endsWith(DebugMessageIds.STEP)) {
100
        	fTarget.suspended(DebugEvent.STEP_END);
101
        } else if (message.indexOf(DebugMessageIds.BREAKPOINT) >= 0) {
102
        	fTarget.breakpointHit(message);
103
        }
104
    }
105
106
    private void buildStarted() {
107
        IProcess process= getProcess();
108
        while(process == null) {
109
        	try {
110
        		synchronized (this) {
111
        			wait(400);
112
        		}
113
        		process= getProcess();
114
        	} catch (InterruptedException ie) {
115
        	}
116
        }
117
        fTarget= new AntDebugTarget(fLaunch, process, this);
118
        fLaunch.addDebugTarget(fTarget);
119
        
120
        if (!connectRequest()) {
121
			RemoteAntDebugBuildListener.this.shutDown();
122
			return;
123
        }
124
        
125
        fTarget.buildStarted();
126
    }
127
128
    private boolean connectRequest() {
129
    	Exception exception= null;
130
    	for (int i= 1; i < 20; i++) {
131
    		try {
132
    			fRequestSocket = new Socket("localhost", fRequestPort); //$NON-NLS-1$
133
    			fRequestWriter = new PrintWriter(fRequestSocket.getOutputStream(), true);
134
    			fResponseReader = new BufferedReader(new InputStreamReader(fRequestSocket.getInputStream()));
135
    			
136
    			fReaderThread= new ReaderThread();
137
    			fReaderThread.start();
138
    			return true;
139
    		} catch (UnknownHostException e) {
140
    			exception= e;
141
    			break;
142
    		} catch (IOException e) {
143
    			exception= e;
144
    		}
145
    		try {
146
				Thread.sleep(500);
147
			} catch(InterruptedException e) {
148
			}
149
    	}
150
    	AntLaunching.log("Internal error attempting to connect to debug target", exception); //$NON-NLS-1$
151
    	return false;
152
	}
153
154
	/**
155
	 * Start listening to an Ant build. Start a server connection that
156
	 * the RemoteAntDebugBuildLogger can connect to.
157
	 * 
158
	 * @param eventPort The port number to create the server connection on
159
     * @param requestPort The port number to use for sending requests to the remote logger
160
	 */
161
	public synchronized void startListening(int eventPort, int requestPort) {
162
		super.startListening(eventPort);
163
		fRequestPort= requestPort;
164
	}
165
	
166
	/**
167
	 * Sends a request to the Ant build
168
	 * 
169
	 * @param request debug command
170
	 */
171
	protected void sendRequest(String request) {
172
		if (fRequestSocket == null) {
173
			return;
174
		}
175
		synchronized (fRequestSocket) {
176
			fRequestWriter.println(request);
177
		}		
178
	}
179
	
180
	protected synchronized void shutDown() {
181
        if (fTarget != null) {
182
            fTarget.terminated();
183
            fTarget= null;
184
        }
185
		fLaunch= null;
186
		if (DebugPlugin.getDefault() != null) {
187
			DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
188
		}
189
		try {
190
			if (fReaderThread != null)   {
191
				// interrupt reader thread so that we don't block on close
192
				// on a lock held by the BufferedReader
193
				// see bug: 38955
194
				fReaderThread.interrupt();
195
			}
196
			if (fResponseReader != null) {
197
				fResponseReader.close();
198
				fResponseReader= null;
199
			}
200
		} catch(IOException e) {
201
		}	
202
		if (fRequestWriter != null) {
203
			fRequestWriter.close();
204
			fRequestWriter= null;
205
		}
206
		try{
207
			if(fRequestSocket != null) {
208
				fRequestSocket.close();
209
				fRequestSocket= null;
210
			}
211
		} catch(IOException e) {
212
		}
213
		super.shutDown();
214
	}
215
216
	/* (non-Javadoc)
217
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#resume()
218
	 */
219
	public void resume() {
220
		sendRequest(DebugMessageIds.RESUME);
221
	}
222
223
	/* (non-Javadoc)
224
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#suspend()
225
	 */
226
	public void suspend() {
227
		sendRequest(DebugMessageIds.SUSPEND);
228
	}
229
230
	/* (non-Javadoc)
231
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#stepInto()
232
	 */
233
	public void stepInto() {
234
		sendRequest(DebugMessageIds.STEP_INTO);
235
	}
236
237
	/* (non-Javadoc)
238
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#stepOver()
239
	 */
240
	public void stepOver() {
241
		sendRequest(DebugMessageIds.STEP_OVER);
242
	}
243
244
	/* (non-Javadoc)
245
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#handleBreakpoint(IBreakpoint, boolean)
246
	 */
247
	public void handleBreakpoint(IBreakpoint breakpoint, boolean add) {
248
		if (fTarget == null || !fTarget.supportsBreakpoint(breakpoint)) {
249
			return;
250
		}
251
		StringBuffer message= new StringBuffer();
252
		if (add) {
253
			try {
254
				if (!breakpoint.isEnabled()) {
255
					return;
256
				}
257
			} catch (CoreException e) {
258
				AntLaunching.log(e);
259
				return;
260
			}
261
			message.append(DebugMessageIds.ADD_BREAKPOINT);
262
		} else {
263
			message.append(DebugMessageIds.REMOVE_BREAKPOINT);
264
		}
265
		message.append(DebugMessageIds.MESSAGE_DELIMITER);
266
		message.append(breakpoint.getMarker().getResource().getLocation().toOSString());
267
		message.append(DebugMessageIds.MESSAGE_DELIMITER);
268
		try {
269
			message.append(((ILineBreakpoint)breakpoint).getLineNumber());
270
			sendRequest(message.toString());
271
		} catch (CoreException ce) {
272
			AntLaunching.log(ce);
273
		}
274
	}
275
276
	/* (non-Javadoc)
277
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#getProperties()
278
	 */
279
	public void getProperties() {
280
		sendRequest(DebugMessageIds.PROPERTIES);
281
	}
282
283
	/* (non-Javadoc)
284
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#getStackFrames()
285
	 */
286
	public void getStackFrames() {
287
		sendRequest(DebugMessageIds.STACK);
288
	}
289
290
	/* (non-Javadoc)
291
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#unescapeString(java.lang.StringBuffer)
292
	 */
293
	public StringBuffer unescapeString(StringBuffer property) {
294
		if (property.indexOf("\\r") == -1 && property.indexOf("\\n") == -1) { //$NON-NLS-1$ //$NON-NLS-2$
295
			return property;
296
		}
297
		for (int i= 0; i < property.length(); i++) {
298
			if ('\\' == property.charAt(i)) {
299
				String newString= ""; //$NON-NLS-1$
300
				if ('r' == property.charAt(i + 1)) {
301
					if (i-1 > - 1 && '\\' == property.charAt(i-1)) {
302
						newString= "r"; //$NON-NLS-1$
303
					} else {
304
						newString+= '\r';
305
					}
306
				} else if ('n' == property.charAt(i + 1)) {
307
					if (i-1 > - 1 && '\\' == property.charAt(i-1)) {
308
						newString= "n"; //$NON-NLS-1$
309
					} else {
310
						newString+= '\n';
311
					}
312
					
313
				}
314
				if (newString.length() > 0) {
315
					property.replace(i, i + 2, newString);
316
				}
317
			}
318
		}
319
320
		return property;
321
	}
322
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntClasspathProvider.java (+50 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.launching.launchConfigurations;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.debug.core.ILaunchConfiguration;
19
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
20
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
21
import org.eclipse.jdt.launching.JavaRuntime;
22
import org.eclipse.jdt.launching.StandardClasspathProvider;
23
24
public class AntClasspathProvider extends StandardClasspathProvider {
25
26
	/* (non-Javadoc)
27
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathProvider#computeUnresolvedClasspath(org.eclipse.debug.core.ILaunchConfiguration)
28
	 */
29
	public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException {
30
		boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
31
		if (useDefault) {
32
			List rtes = new ArrayList(10);
33
			IRuntimeClasspathEntry jreEntry = null;
34
			try {
35
				jreEntry = JavaRuntime.computeJREEntry(configuration);
36
			} catch (CoreException e) {
37
				// not a java project
38
			}
39
			if (jreEntry == null) {
40
				jreEntry = JavaRuntime.newRuntimeContainerClasspathEntry(
41
						JavaRuntime.newDefaultJREContainerPath(), IRuntimeClasspathEntry.STANDARD_CLASSES);
42
			}
43
			rtes.add(jreEntry);
44
			rtes.add(new AntHomeClasspathEntry());
45
			rtes.add(new ContributedClasspathEntriesEntry());
46
			return (IRuntimeClasspathEntry[]) rtes.toArray(new IRuntimeClasspathEntry[rtes.size()]);
47
		}
48
		return super.computeUnresolvedClasspath(configuration);
49
	}
50
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntCoreModelMessages.java (+25 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.ant.internal.launching.launchConfigurations;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class AntCoreModelMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.ant.internal.launching.launchConfigurations.AntCoreModelMessages";//$NON-NLS-1$
16
	
17
	public static String AntUtil_6;
18
	public static String AntUtil_7;
19
	public static String AntUtil_2;
20
21
	static {
22
		// load message values from bundle file
23
		NLS.initializeMessages(BUNDLE_NAME, AntCoreModelMessages.class);
24
	}
25
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntCoreModelMessages.properties (+14 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
AntUtil_6=Invalid property file entry: {0}
13
AntUtil_7=Unable to generate Ant classpath
14
AntUtil_2=Error reading launch configuration
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntHomeClasspathEntry.java (+210 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.launchConfigurations;
12
13
import java.io.File;
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.ant.core.AntCorePlugin;
18
import org.eclipse.ant.core.AntCorePreferences;
19
import org.eclipse.ant.core.IAntClasspathEntry;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IPath;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.debug.core.ILaunchConfiguration;
24
import org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry;
25
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
26
import org.eclipse.jdt.launching.JavaRuntime;
27
import org.w3c.dom.Document;
28
import org.w3c.dom.Element;
29
30
import com.ibm.icu.text.MessageFormat;
31
32
/**
33
 * A classpath entry that contains a set of archives for a particular
34
 * ANT_HOME.
35
 * 
36
 * @since 3.0 
37
 */
38
public class AntHomeClasspathEntry extends AbstractRuntimeClasspathEntry {
39
	
40
	public static final String TYPE_ID = "org.eclipse.ant.ui.classpathentry.antHome"; //$NON-NLS-1$
41
	
42
	/**
43
	 * Local path on disk where Ant Home is located or <code>null</code>
44
	 * to indicate the use of the default Ant Home.
45
	 */
46
	private String antHomeLocation = null;
47
	
48
	/**
49
	 * Creates an AntHome entry for the default AntHome installation.
50
	 */
51
	public AntHomeClasspathEntry() {
52
		antHomeLocation = null;
53
	}
54
	
55
	/**
56
	 * Constructs an AntHome entry for the Ant installed at the specified
57
	 * root directory.
58
	 * 
59
	 * @param antHome path in the local file system to an Ant installation
60
	 */
61
	public AntHomeClasspathEntry(String antHome) {
62
		antHomeLocation = antHome;
63
	}
64
		
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry#buildMemento(org.w3c.dom.Document, org.w3c.dom.Element)
67
	 */
68
	protected void buildMemento(Document document, Element memento) throws CoreException {
69
		if (antHomeLocation == null) {
70
			memento.setAttribute("default", "true");  //$NON-NLS-1$//$NON-NLS-2$
71
		} else {
72
			memento.setAttribute("antHome", new Path(antHomeLocation).toString()); //$NON-NLS-1$
73
		}
74
	}
75
	/* (non-Javadoc)
76
	 * @see org.eclipse.jdt.internal.launching.IRuntimeClasspathEntry2#initializeFrom(org.w3c.dom.Element)
77
	 */
78
	public void initializeFrom(Element memento) throws CoreException {
79
		String antHome = memento.getAttribute("antHome"); //$NON-NLS-1$
80
		if (antHome != null && (antHome.length() > 0)) {
81
			IPath path = new Path(antHome);
82
			antHomeLocation = path.toOSString();
83
		} else {
84
			antHomeLocation = null;
85
		}
86
	}
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getTypeId()
89
	 */
90
	public String getTypeId() {
91
		return TYPE_ID;
92
	}
93
	/* (non-Javadoc)
94
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getRuntimeClasspathEntries(org.eclipse.debug.core.ILaunchConfiguration)
95
	 */
96
	public IRuntimeClasspathEntry[] getRuntimeClasspathEntries(ILaunchConfiguration configuration) throws CoreException {
97
		List libs = new ArrayList(40);
98
		AntCorePreferences preferences = AntCorePlugin.getPlugin().getPreferences();
99
		if (antHomeLocation == null) {
100
			IAntClasspathEntry[] entries = preferences.getAntHomeClasspathEntries();
101
			for (int i = 0; i < entries.length; i++) {
102
				IAntClasspathEntry entry = entries[i];
103
				libs.add(JavaRuntime.newStringVariableClasspathEntry(entry.getLabel()));
104
			}
105
		} else {
106
			File lib= resolveAntHome();
107
			IPath libDir = new Path(antHomeLocation).append("lib"); //$NON-NLS-1$
108
			String[] fileNames = lib.list();
109
			for (int i = 0; i < fileNames.length; i++) {
110
				String name = fileNames[i];
111
				IPath path = new Path(name);
112
				String fileExtension = path.getFileExtension();
113
				if ("jar".equalsIgnoreCase(fileExtension)) { //$NON-NLS-1$
114
					libs.add(JavaRuntime.newArchiveRuntimeClasspathEntry(libDir.append(path)));
115
				}
116
			}
117
		}
118
		return (IRuntimeClasspathEntry[]) libs.toArray(new IRuntimeClasspathEntry[libs.size()]);
119
	}
120
	
121
	public File resolveAntHome() throws CoreException {
122
		if (antHomeLocation == null) { //using the default ant home
123
			return null;
124
		}
125
		IPath libDir= new Path(antHomeLocation).append("lib"); //$NON-NLS-1$
126
		File lib= libDir.toFile();
127
		File parentDir= lib.getParentFile();
128
		if (parentDir == null || !parentDir.exists()) {
129
			abort(MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_10, new String[] {antHomeLocation}), null);
130
		}
131
		if (!lib.exists() || !lib.isDirectory()) {
132
			abort(MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_11, new String[] {antHomeLocation}), null);
133
		}
134
		return lib;
135
	}
136
	
137
	/* (non-Javadoc)
138
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getName()
139
	 */
140
	public String getName() {
141
		if (antHomeLocation == null) {
142
			return AntLaunchConfigurationMessages.AntHomeClasspathEntry_8;
143
		}
144
		return MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_9, new String[]{antHomeLocation});
145
	}
146
	
147
	/* (non-Javadoc)
148
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getType()
149
	 */
150
	public int getType() {
151
		return IRuntimeClasspathEntry.OTHER;
152
	}
153
	
154
	/* (non-Javadoc)
155
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#isComposite()
156
	 */
157
	public boolean isComposite() {
158
		return true;
159
	}
160
	
161
	/* (non-Javadoc)
162
	 * @see java.lang.Object#equals(java.lang.Object)
163
	 */
164
	public boolean equals(Object obj) {
165
		return obj instanceof AntHomeClasspathEntry &&
166
		  equalsOrNull(antHomeLocation, ((AntHomeClasspathEntry)obj).antHomeLocation);
167
	}
168
	
169
	/**
170
	 * Return whether s1 is equivalent to s2.
171
	 * 
172
	 * @param s1
173
	 * @param s2
174
	 * @return whether s1 is equivalent to s2
175
	 */
176
	private boolean equalsOrNull(String s1, String s2) {
177
		if (s1 == null || s2 == null) {
178
			return s1 == s2;
179
		} 
180
		return s1.equalsIgnoreCase(s2);
181
	}
182
183
	/* (non-Javadoc)
184
	 * @see java.lang.Object#hashCode()
185
	 */
186
	public int hashCode() {
187
		return getClass().hashCode();
188
	}	
189
	
190
	/**
191
	 * Sets the ant home to use.
192
	 * 
193
	 * @param path path to toor of an ant home installation
194
	 */
195
	public void setAntHome(String path) {
196
		antHomeLocation = path;
197
	}
198
	
199
	/**
200
	 * Returns the ant home location
201
	 * 
202
	 * @return path to root ant installation directory
203
	 */
204
	public String getAntHome() {
205
		if (antHomeLocation == null) {
206
			return AntCorePlugin.getPlugin().getPreferences().getAntHome();
207
		}
208
		return antHomeLocation;
209
	}
210
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntJavaLaunchDelegate.java (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.launchConfigurations;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.debug.core.ILaunchConfiguration;
16
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
17
import org.eclipse.jdt.launching.JavaLaunchDelegate;
18
19
/**
20
 * Used by the AntLaunchDelegate for Ant builds in a separate VM
21
 * The subclassing is needed to be able to launch an Ant build from a non-Java project
22
 */
23
public class AntJavaLaunchDelegate extends JavaLaunchDelegate {
24
	/* (non-Javadoc)
25
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate2#preLaunchCheck(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
26
	 */
27
	public boolean preLaunchCheck(ILaunchConfiguration configuration,String mode, IProgressMonitor monitor) throws CoreException {
28
		try {
29
			return super.preLaunchCheck(configuration, mode, monitor);
30
		} catch (CoreException ce) {
31
			//likely dealing with a non-Java project
32
		}
33
		//no need to check for breakpoints as always in run mode
34
		return true;
35
	}
36
	
37
	/* (non-Javadoc)
38
	 * @see org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate#getProgramArguments(org.eclipse.debug.core.ILaunchConfiguration)
39
	 */
40
	public String getProgramArguments(ILaunchConfiguration configuration) throws CoreException {
41
		try {
42
			return super.getProgramArguments(configuration);
43
		} catch (CoreException ce) {
44
		}
45
		return configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, ""); //$NON-NLS-1$
46
	}
47
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntLaunchConfigurationMessages.java (+37 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 * dakshinamurthy.karra@gmail.com - bug 165371
10
 **********************************************************************/
11
package org.eclipse.ant.internal.launching.launchConfigurations;
12
13
import org.eclipse.osgi.util.NLS;
14
15
public class AntLaunchConfigurationMessages extends NLS {
16
	private static final String BUNDLE_NAME = "org.eclipse.ant.internal.launching.launchConfigurations.AntLaunchConfigurationMessages";//$NON-NLS-1$
17
18
	public static String AntLaunchDelegate_Launching__0__1;
19
	public static String AntLaunchDelegate_Running__0__2;
20
	public static String AntLaunchDelegate_Build_In_Progress;
21
	public static String AntLaunchDelegate_Failure;
22
	public static String AntLaunchDelegate_22;
23
	public static String AntLaunchDelegate_23;
24
	public static String AntLaunchDelegate_28;
25
26
	public static String AntHomeClasspathEntry_8;
27
	public static String AntHomeClasspathEntry_9;
28
	public static String AntHomeClasspathEntry_10;
29
	public static String AntHomeClasspathEntry_11;
30
31
	public static String ContributedClasspathEntriesEntry_1;
32
33
	static {
34
		// load message values from bundle file
35
		NLS.initializeMessages(BUNDLE_NAME, AntLaunchConfigurationMessages.class);
36
	}
37
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntLaunchConfigurationMessages.properties (+26 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
#     dakshinamurthy.karra@gmail.com - bug 165371
11
###############################################################################
12
13
AntLaunchDelegate_Launching__0__1=Launching {0}
14
AntLaunchDelegate_Running__0__2=Running {0}
15
AntLaunchDelegate_Build_In_Progress=Ant build {0} already in progress. Concurrent Ant builds are possible if you specify to build in a separate JRE.
16
AntLaunchDelegate_Failure=Failure of Background Ant Build
17
AntLaunchDelegate_22=&Do not show error dialog when Ant build fails
18
AntLaunchDelegate_23=Ant Build Failed
19
AntLaunchDelegate_28=Waiting for virtual machine to exit...
20
21
AntHomeClasspathEntry_8=Ant Home (Default)
22
AntHomeClasspathEntry_9=Ant Home ({0})
23
AntHomeClasspathEntry_10=Ant Home {0} does not exist
24
AntHomeClasspathEntry_11=Ant Home {0} does not contain a "lib" directory
25
26
ContributedClasspathEntriesEntry_1=Additional Tasks & Support
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntLaunchDelegate.java (+892 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Juan A. Hernandez - bug 89926
11
 *     dakshinamurthy.karra@gmail.com - bug 165371
12
 *******************************************************************************/
13
package org.eclipse.ant.internal.launching.launchConfigurations;
14
15
import java.io.File;
16
import java.io.IOException;
17
import java.net.URL;
18
import java.util.HashMap;
19
import java.util.Iterator;
20
import java.util.List;
21
import java.util.Map;
22
23
import org.apache.tools.ant.ProjectHelper;
24
import org.eclipse.ant.core.AntCorePlugin;
25
import org.eclipse.ant.core.AntCorePreferences;
26
import org.eclipse.ant.core.AntRunner;
27
import org.eclipse.ant.core.Property;
28
import org.eclipse.ant.core.Task;
29
import org.eclipse.ant.core.Type;
30
import org.eclipse.ant.internal.core.AbstractEclipseBuildLogger;
31
import org.eclipse.ant.internal.launching.AntLaunch;
32
import org.eclipse.ant.internal.launching.AntLaunching;
33
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
34
import org.eclipse.ant.internal.launching.debug.IAntDebugConstants;
35
import org.eclipse.ant.internal.launching.debug.model.RemoteAntDebugBuildListener;
36
import org.eclipse.ant.launching.IAntLaunchConstants;
37
import org.eclipse.core.internal.externaltools.launchConfigurations.BackgroundResourceRefresher;
38
import org.eclipse.core.internal.externaltools.launchConfigurations.ExternalToolsCoreUtil;
39
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
40
import org.eclipse.core.resources.IProject;
41
import org.eclipse.core.runtime.CoreException;
42
import org.eclipse.core.runtime.FileLocator;
43
import org.eclipse.core.runtime.IPath;
44
import org.eclipse.core.runtime.IProgressMonitor;
45
import org.eclipse.core.runtime.IStatus;
46
import org.eclipse.core.runtime.Path;
47
import org.eclipse.core.runtime.Platform;
48
import org.eclipse.core.runtime.Status;
49
import org.eclipse.core.runtime.SubProgressMonitor;
50
import org.eclipse.core.variables.VariablesPlugin;
51
import org.eclipse.debug.core.DebugEvent;
52
import org.eclipse.debug.core.DebugPlugin;
53
import org.eclipse.debug.core.IBreakpointManager;
54
import org.eclipse.debug.core.IDebugEventSetListener;
55
import org.eclipse.debug.core.ILaunch;
56
import org.eclipse.debug.core.ILaunchConfiguration;
57
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
58
import org.eclipse.debug.core.ILaunchManager;
59
import org.eclipse.debug.core.model.IBreakpoint;
60
import org.eclipse.debug.core.model.IProcess;
61
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
62
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
63
import org.eclipse.jdt.launching.IVMInstall;
64
import org.eclipse.jdt.launching.JavaRuntime;
65
import org.eclipse.jdt.launching.SocketUtil;
66
import org.eclipse.osgi.service.resolver.BundleDescription;
67
import org.osgi.framework.Bundle;
68
69
import com.ibm.icu.text.MessageFormat;
70
71
/**
72
 * Launch delegate for Ant builds
73
 */
74
public class AntLaunchDelegate extends LaunchConfigurationDelegate {
75
76
	private static final String ANT_LOGGER_CLASS = "org.eclipse.ant.internal.launching.runtime.logger.AntProcessBuildLogger"; //$NON-NLS-1$
77
	private static final String ANT_DEBUG_LOGGER_CLASS = "org.eclipse.ant.internal.launching.runtime.logger.AntProcessDebugBuildLogger"; //$NON-NLS-1$
78
	private static final String NULL_LOGGER_CLASS = "org.eclipse.ant.internal.launching.runtime.logger.NullBuildLogger"; //$NON-NLS-1$
79
	private static final String REMOTE_ANT_LOGGER_CLASS = "org.eclipse.ant.internal.launching.remote.logger.RemoteAntBuildLogger"; //$NON-NLS-1$
80
	private static final String REMOTE_ANT_DEBUG_LOGGER_CLASS = "org.eclipse.ant.internal.launching.remote.logger.RemoteAntDebugBuildLogger"; //$NON-NLS-1$
81
	private static final String BASE_DIR_PREFIX = "-Dbasedir="; //$NON-NLS-1$
82
	private static final String INPUT_HANDLER_CLASS = "org.eclipse.ant.internal.ui.antsupport.inputhandler.AntInputHandler"; //$NON-NLS-1$
83
	private static final String REMOTE_INPUT_HANDLER_CLASS = "org.eclipse.ant.internal.ui.antsupport.inputhandler.ProxyInputHandler"; //$NON-NLS-1$
84
85
	private static final IProject[] NO_PROJECTS = new IProject[0];
86
87
	/**
88
	 * String attribute identifying the build scope for a launch configuration.
89
	 * <code>null</code> indicates the default workspace build.
90
	 */
91
	private static final String ATTR_BUILD_SCOPE = AntLaunching
92
			.getUniqueIdentifier()
93
			+ ".ATTR_BUILD_SCOPE"; //$NON-NLS-1$
94
95
	/**
96
	 * Attribute identifier specifying whether referenced projects should be
97
	 * considered when computing the projects to build. Default value is
98
	 * <code>true</code>.
99
	 */
100
	private static final String ATTR_INCLUDE_REFERENCED_PROJECTS = AntLaunching
101
			.getUniqueIdentifier()
102
			+ ".ATTR_INCLUDE_REFERENCED_PROJECTS"; //$NON-NLS-1$
103
104
	private static String fgSWTLibraryLocation;
105
106
	private String fMode;
107
	ILaunchManager launchManager;
108
109
	private boolean fUserSpecifiedLogger = false;
110
111
	private String getProgramArguments(ILaunchConfiguration configuration)
112
			throws CoreException {
113
		String arguments = configuration.getAttribute(
114
				IExternalToolConstants.ATTR_TOOL_ARGUMENTS, ""); //$NON-NLS-1$
115
		return VariablesPlugin.getDefault().getStringVariableManager()
116
				.performStringSubstitution(arguments);
117
	}
118
119
	/**
120
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration,
121
	 *      java.lang.String, org.eclipse.debug.core.ILaunch,
122
	 *      org.eclipse.core.runtime.IProgressMonitor)
123
	 */
124
	public void launch(ILaunchConfiguration configuration, String mode,
125
			ILaunch launch, IProgressMonitor monitor) throws CoreException {
126
		if (monitor.isCanceled()) {
127
			return;
128
		}
129
		fUserSpecifiedLogger = false;
130
		fMode = mode;
131
		launchManager = DebugPlugin.getDefault().getLaunchManager();
132
133
		// migrate the config to the new classpath format if required
134
		AntLaunchingUtil.migrateToNewClasspathFormat(configuration);
135
136
		boolean isSeparateJRE = AntLaunchingUtil
137
				.isSeparateJREAntBuild(configuration);
138
139
		if (launchManager.isLaunchInBackground(configuration)) {
140
			monitor
141
					.beginTask(
142
							MessageFormat
143
									.format(
144
											AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__1,
145
											new String[] { configuration
146
													.getName() }), 10);
147
		} else {
148
			monitor
149
					.beginTask(
150
							MessageFormat
151
									.format(
152
											AntLaunchConfigurationMessages.AntLaunchDelegate_Running__0__2,
153
											new String[] { configuration
154
													.getName() }), 100);
155
		}
156
157
		// resolve location
158
		IPath location = ExternalToolsCoreUtil.getLocation(configuration);
159
		monitor.worked(1);
160
161
		if (monitor.isCanceled()) {
162
			return;
163
		}
164
165
		if (!isSeparateJRE && AntRunner.isBuildRunning()) {
166
			IStatus status = new Status(
167
					IStatus.ERROR,
168
					AntLaunching.PLUGIN_ID,
169
					1,
170
					MessageFormat
171
							.format(
172
									AntLaunchConfigurationMessages.AntLaunchDelegate_Build_In_Progress,
173
									new String[] { location.toOSString() }),
174
					null);
175
			throw new CoreException(status);
176
		}
177
178
		// resolve working directory
179
		IPath workingDirectory = ExternalToolsCoreUtil
180
				.getWorkingDirectory(configuration);
181
		String basedir = null;
182
		if (workingDirectory != null) {
183
			basedir = workingDirectory.toOSString();
184
		}
185
		monitor.worked(1);
186
187
		if (monitor.isCanceled()) {
188
			return;
189
		}
190
191
		// link the process to its build logger via a timestamp
192
		long timeStamp = System.currentTimeMillis();
193
		String idStamp = Long.toString(timeStamp);
194
		StringBuffer idProperty = new StringBuffer("-D"); //$NON-NLS-1$
195
		idProperty.append(AbstractEclipseBuildLogger.ANT_PROCESS_ID);
196
		idProperty.append('=');
197
		idProperty.append(idStamp);
198
199
		// resolve arguments
200
		String[] arguments = null;
201
		if (isSeparateJRE) {
202
			arguments = new String[] { getProgramArguments(configuration) };
203
		} else {
204
			arguments = ExternalToolsCoreUtil.getArguments(configuration);
205
		}
206
207
		Map userProperties = AntLaunchingUtil.getProperties(configuration);
208
		if (userProperties != null) {// create a copy so as to not affect the
209
			// configuration with transient
210
			// properties
211
			userProperties = new HashMap(userProperties);
212
		}
213
		String[] propertyFiles = AntLaunchingUtil
214
				.getPropertyFiles(configuration);
215
		String[] targets = AntLaunchingUtil.getTargetNames(configuration);
216
		URL[] customClasspath = AntLaunchingUtil
217
				.getCustomClasspath(configuration);
218
		String antHome = AntLaunchingUtil.getAntHome(configuration);
219
220
		boolean setInputHandler = true;
221
		try {
222
			// check if set specify inputhandler
223
			setInputHandler = configuration.getAttribute(
224
					AntLaunching.SET_INPUTHANDLER, true);
225
		} catch (CoreException ce) {
226
			AntLaunching.log(ce);
227
		}
228
229
		AntRunner runner = null;
230
		if (!isSeparateJRE) {
231
			runner = configureAntRunner(configuration, location, basedir,
232
					idProperty, arguments, userProperties, propertyFiles,
233
					targets, customClasspath, antHome, setInputHandler);
234
		}
235
236
		monitor.worked(1);
237
238
		if (monitor.isCanceled()) {
239
			return;
240
		}
241
		boolean captureOutput = ExternalToolsCoreUtil
242
				.getCaptureOutput(configuration);
243
		int port = -1;
244
		int requestPort = -1;
245
		if (isSeparateJRE && captureOutput) {
246
			if (userProperties == null) {
247
				userProperties = new HashMap();
248
			}
249
			port = SocketUtil.findFreePort();
250
			userProperties.put(AbstractEclipseBuildLogger.ANT_PROCESS_ID,
251
					idStamp);
252
			userProperties.put("eclipse.connect.port", Integer.toString(port)); //$NON-NLS-1$
253
			if (fMode.equals(ILaunchManager.DEBUG_MODE)) {
254
				requestPort = SocketUtil.findFreePort();
255
				userProperties
256
						.put(
257
								"eclipse.connect.request_port", Integer.toString(requestPort)); //$NON-NLS-1$
258
			}
259
		}
260
261
		StringBuffer commandLine = generateCommandLine(location, arguments,
262
				userProperties, propertyFiles, targets, antHome, basedir,
263
				isSeparateJRE, captureOutput, setInputHandler);
264
265
		if (isSeparateJRE) {
266
			monitor
267
					.beginTask(
268
							MessageFormat
269
									.format(
270
											AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__1,
271
											new String[] { configuration
272
													.getName() }), 10);
273
			runInSeparateVM(configuration, launch, monitor, idStamp, antHome,
274
					port, requestPort, commandLine, captureOutput,
275
					setInputHandler);
276
		} else {
277
			runInSameVM(configuration, launch, monitor, location, idStamp,
278
					runner, commandLine);
279
		}
280
281
		monitor.done();
282
	}
283
284
	private void runInSameVM(ILaunchConfiguration configuration,
285
			ILaunch launch, IProgressMonitor monitor, IPath location,
286
			String idStamp, AntRunner runner, StringBuffer commandLine) throws CoreException {
287
		Map attributes = new HashMap(2);
288
		attributes.put(IProcess.ATTR_PROCESS_TYPE,
289
				IAntLaunchConstants.ID_ANT_PROCESS_TYPE);
290
		attributes.put(AbstractEclipseBuildLogger.ANT_PROCESS_ID, idStamp);
291
292
		final AntProcess process = new AntProcess(location.toOSString(),
293
				launch, attributes);
294
		setProcessAttributes(process, idStamp, commandLine);
295
		boolean debug = fMode.equals(ILaunchManager.DEBUG_MODE);
296
		if (debug || launchManager.isLaunchInBackground(configuration)) {
297
			final AntRunner finalRunner = runner;
298
			Runnable r = new Runnable() {
299
				public void run() {
300
					try {
301
						finalRunner.run(process);
302
					} catch (CoreException e) {
303
						handleException(
304
								e,
305
								AntLaunchConfigurationMessages.AntLaunchDelegate_Failure);
306
					}
307
					process.terminated();
308
				}
309
			};
310
			Thread background = new Thread(r);
311
			background.setDaemon(true);
312
			background.start();
313
			monitor.worked(1);
314
			// refresh resources after process finishes
315
			if (configuration.getAttribute(ILaunchManager.ATTR_REFRESH_SCOPE, (String)null) != null) {
316
				BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(
317
						configuration, process);
318
				refresher.startBackgroundRefresh();
319
			}
320
		} else {
321
			// execute the build
322
			try {
323
				runner.run(monitor);
324
			} catch (CoreException e) {
325
				process.terminated();
326
				monitor.done();
327
				handleException(e,
328
						AntLaunchConfigurationMessages.AntLaunchDelegate_23);
329
				return;
330
			}
331
			process.terminated();
332
333
			// refresh resources
334
			launchManager.refreshResources(configuration, monitor);
335
		}
336
	}
337
338
	private AntRunner configureAntRunner(ILaunchConfiguration configuration,
339
			IPath location, String baseDir, StringBuffer idProperty,
340
			String[] arguments, Map userProperties, String[] propertyFiles,
341
			String[] targets, URL[] customClasspath, String antHome,
342
			boolean setInputHandler) throws CoreException {
343
		int argLength = 1; // at least one user property - timestamp
344
		if (arguments != null) {
345
			argLength += arguments.length;
346
		}
347
		if (baseDir != null && baseDir.length() > 0) {
348
			argLength++;
349
		}
350
		String[] runnerArgs = new String[argLength];
351
		if (arguments != null) {
352
			System.arraycopy(arguments, 0, runnerArgs, 0, arguments.length);
353
		}
354
		if (baseDir != null && baseDir.length() > 0) {
355
			runnerArgs[runnerArgs.length - 2] = BASE_DIR_PREFIX + baseDir;
356
		}
357
		runnerArgs[runnerArgs.length - 1] = idProperty.toString();
358
359
		AntRunner runner = new AntRunner();
360
		runner.setBuildFileLocation(location.toOSString());
361
		boolean captureOutput = ExternalToolsCoreUtil
362
				.getCaptureOutput(configuration);
363
		if (captureOutput) {
364
			if (fMode.equals(ILaunchManager.DEBUG_MODE)) {
365
				runner.addBuildLogger(ANT_DEBUG_LOGGER_CLASS);
366
			} else {
367
				runner.addBuildLogger(ANT_LOGGER_CLASS);
368
			}
369
		} else {
370
			runner.addBuildLogger(NULL_LOGGER_CLASS);
371
		}
372
		if (setInputHandler) {
373
			runner.setInputHandler(INPUT_HANDLER_CLASS);
374
		} else {
375
			runner.setInputHandler(""); //$NON-NLS-1$
376
		}
377
		runner.setArguments(runnerArgs);
378
		if (userProperties != null) {
379
			runner.addUserProperties(userProperties);
380
		}
381
382
		if (propertyFiles != null) {
383
			runner.setPropertyFiles(propertyFiles);
384
		}
385
386
		if (targets != null) {
387
			runner.setExecutionTargets(targets);
388
		}
389
390
		if (customClasspath != null) {
391
			runner.setCustomClasspath(customClasspath);
392
		}
393
394
		if (antHome != null) {
395
			runner.setAntHome(antHome);
396
		}
397
		return runner;
398
	}
399
400
	private void handleException(final CoreException e, final String title) {
401
		AntLaunching.log(title, e);
402
	}
403
404
	private void setProcessAttributes(IProcess process, String idStamp,
405
			StringBuffer commandLine) {
406
		// link the process to the Eclipse build logger via a timestamp
407
		if (!fUserSpecifiedLogger) {
408
			process.setAttribute(AbstractEclipseBuildLogger.ANT_PROCESS_ID,
409
					idStamp);
410
		}
411
412
		// create "fake" command line for the process
413
		if (commandLine != null) {
414
			process.setAttribute(IProcess.ATTR_CMDLINE, commandLine.toString());
415
		}
416
	}
417
418
	private StringBuffer generateCommandLine(IPath location,
419
			String[] arguments, Map userProperties, String[] propertyFiles,
420
			String[] targets, String antHome, String basedir,
421
			boolean separateVM, boolean captureOutput, boolean setInputHandler) {
422
		StringBuffer commandLine = new StringBuffer();
423
424
		if (!separateVM) {
425
			commandLine.append("ant"); //$NON-NLS-1$
426
		}
427
428
		if (arguments != null) {
429
			for (int i = 0; i < arguments.length; i++) {
430
				commandLine.append(' ');
431
				commandLine.append(arguments[i]);
432
			}
433
		}
434
435
		AntCorePreferences prefs = AntCorePlugin.getPlugin().getPreferences();
436
		if (propertyFiles == null) { // global
437
			String[] files = prefs.getCustomPropertyFiles();
438
			for (int i = 0; i < files.length; i++) {
439
				String path = files[i];
440
				commandLine.append(" -propertyfile \""); //$NON-NLS-1$
441
				commandLine.append(path);
442
				commandLine.append('\"');
443
			}
444
		} else {// "local" configuration
445
			for (int i = 0; i < propertyFiles.length; i++) {
446
				String path = propertyFiles[i];
447
				commandLine.append(" -propertyfile \""); //$NON-NLS-1$
448
				commandLine.append(path);
449
				commandLine.append('\"');
450
			}
451
		}
452
		// "local" configuration
453
		if (userProperties != null) {
454
			Iterator keys = userProperties.keySet().iterator();
455
			String key;
456
			while (keys.hasNext()) {
457
				key = (String) keys.next();
458
				appendProperty(commandLine, key, (String) userProperties
459
						.get(key));
460
			}
461
		}
462
463
		// global
464
		List properties = null;
465
		if (!separateVM) {
466
			properties = prefs.getProperties();
467
		} else {
468
			properties = prefs.getRemoteAntProperties();
469
		}
470
471
		// if we have user properties this means that the user has chosen to
472
		// override the global properties
473
		// if in a separate VM and have only two (or three if debug) user
474
		// properties these are really only Eclipse generated properties
475
		// and the user is still using the global properties
476
		int numberOfEclipseProperties = 2;
477
		if (userProperties != null
478
				&& userProperties.get("eclipse.connect.request_port") != null) { //$NON-NLS-1$
479
			numberOfEclipseProperties = 3; // debug mode
480
		}
481
		boolean useGlobalProperties = userProperties == null
482
				|| (separateVM && userProperties.size() == numberOfEclipseProperties);
483
		if (useGlobalProperties) {
484
			for (Iterator iter = properties.iterator(); iter.hasNext();) {
485
				Property property = (Property) iter.next();
486
				String key = property.getName();
487
				String value = property.getValue(false);
488
				if (value != null) {
489
					appendProperty(commandLine, key, value);
490
				}
491
			}
492
		}
493
494
		if (basedir != null && basedir.length() > 0) {
495
			appendProperty(commandLine, "basedir", basedir); //$NON-NLS-1$
496
		}
497
498
		if (antHome != null) {
499
			commandLine.append(" \"-Dant.home="); //$NON-NLS-1$
500
			commandLine.append(antHome);
501
			commandLine.append('\"');
502
		}
503
504
		if (separateVM) {
505
			if (commandLine.indexOf("-logger") == -1) { //$NON-NLS-1$
506
				if (captureOutput) {
507
					commandLine.append(" -logger "); //$NON-NLS-1$
508
					if (fMode.equals(ILaunchManager.DEBUG_MODE)) {
509
						commandLine.append(REMOTE_ANT_DEBUG_LOGGER_CLASS);
510
					} else {
511
						commandLine.append(REMOTE_ANT_LOGGER_CLASS);
512
					}
513
				}
514
			} else {
515
				fUserSpecifiedLogger = true;
516
			}
517
			if (commandLine.indexOf("-inputhandler") == -1 && setInputHandler) { //$NON-NLS-1$
518
				commandLine.append(" -inputhandler "); //$NON-NLS-1$
519
				commandLine.append(REMOTE_INPUT_HANDLER_CLASS);
520
			}
521
		} else {
522
			if (commandLine.indexOf("-inputhandler") == -1 && setInputHandler) { //$NON-NLS-1$
523
				commandLine.append(" -inputhandler "); //$NON-NLS-1$
524
				commandLine.append(INPUT_HANDLER_CLASS);
525
			}
526
			if (commandLine.indexOf("-logger") == -1) { //$NON-NLS-1$
527
				commandLine.append(" -logger "); //$NON-NLS-1$
528
				if (fMode.equals(ILaunchManager.DEBUG_MODE)) {
529
					commandLine.append(ANT_DEBUG_LOGGER_CLASS);
530
				} else if (captureOutput) {
531
					commandLine.append(ANT_LOGGER_CLASS);
532
				} else {
533
					commandLine.append(NULL_LOGGER_CLASS);
534
				}
535
			}
536
		}
537
538
		if (separateVM) {
539
			appendTaskAndTypes(prefs, commandLine);
540
		}
541
		commandLine.append(" -buildfile \""); //$NON-NLS-1$
542
		commandLine.append(location.toOSString());
543
		commandLine.append('\"');
544
545
		if (targets != null) {
546
			for (int i = 0; i < targets.length; i++) {
547
				commandLine.append(" \""); //$NON-NLS-1$
548
				commandLine.append(targets[i]);
549
				commandLine.append('\"');
550
			}
551
		}
552
		return commandLine;
553
	}
554
555
	private void appendTaskAndTypes(AntCorePreferences prefs,
556
			StringBuffer commandLine) {
557
		List tasks = prefs.getRemoteTasks();
558
		Iterator itr = tasks.iterator();
559
		while (itr.hasNext()) {
560
			Task task = (Task) itr.next();
561
			commandLine.append(" -eclipseTask "); //$NON-NLS-1$
562
			String name = ProjectHelper.genComponentName(task.getURI(), task
563
					.getTaskName());
564
			commandLine.append(name);
565
			commandLine.append(',');
566
			commandLine.append(task.getClassName());
567
		}
568
569
		List types = prefs.getRemoteTypes();
570
		itr = types.iterator();
571
		while (itr.hasNext()) {
572
			Type type = (Type) itr.next();
573
			commandLine.append(" -eclipseType "); //$NON-NLS-1$
574
			String name = ProjectHelper.genComponentName(type.getURI(), type
575
					.getTypeName());
576
			commandLine.append(name);
577
			commandLine.append(',');
578
			commandLine.append(type.getClassName());
579
		}
580
	}
581
582
	private void appendProperty(StringBuffer commandLine, String name,
583
			String value) {
584
		commandLine.append(" \"-D"); //$NON-NLS-1$
585
		commandLine.append(name);
586
		commandLine.append('=');
587
		commandLine.append(value);
588
		if (value.length() > 0
589
				&& value.charAt(value.length() - 1) == File.separatorChar) {
590
			commandLine.append(File.separatorChar);
591
		}
592
		commandLine.append("\""); //$NON-NLS-1$
593
	}
594
595
	private void runInSeparateVM(ILaunchConfiguration configuration,
596
			ILaunch launch, IProgressMonitor monitor, String idStamp,
597
			String antHome, int port, int requestPort,
598
			StringBuffer commandLine, boolean captureOutput,
599
			boolean setInputHandler) throws CoreException {
600
		boolean debug = fMode.equals(ILaunchManager.DEBUG_MODE);
601
		if (captureOutput) {
602
			if (debug) {
603
				RemoteAntDebugBuildListener listener = new RemoteAntDebugBuildListener(
604
						launch);
605
				if (requestPort != -1) {
606
					listener.startListening(port, requestPort);
607
				}
608
			} else if (!fUserSpecifiedLogger) {
609
				RemoteAntBuildListener client = new RemoteAntBuildListener(
610
						launch);
611
				if (port != -1) {
612
					client.startListening(port);
613
				}
614
			}
615
		}
616
617
		ILaunchConfigurationWorkingCopy copy = configuration.getWorkingCopy();
618
		setDefaultWorkingDirectory(copy);
619
		copy.setAttribute(
620
				IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS,
621
				commandLine.toString());
622
		StringBuffer vmArgs = generateVMArguments(copy, setInputHandler,
623
				antHome);
624
		copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
625
				vmArgs.toString());
626
		copy.setAttribute(ILaunchManager.ATTR_PRIVATE, true);
627
		if (copy
628
				.getAttribute(
629
						IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL,
630
						false)) {
631
			setDefaultVM(configuration, copy);
632
		}
633
634
		if (debug) { // do not allow launch in foreground bug 83254
635
			copy.setAttribute(ILaunchManager.ATTR_LAUNCH_IN_BACKGROUND, true);
636
		}
637
638
		// set the ANT_HOME environment variable
639
		if (antHome != null) {
640
			Map vars = copy.getAttribute(
641
					ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, new HashMap(1));
642
			vars.put("ANT_HOME", antHome); //$NON-NLS-1$
643
			copy.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, vars);
644
		}
645
646
		// copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
647
		// "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000");
648
		IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 10);
649
		AntJavaLaunchDelegate delegate = new AntJavaLaunchDelegate();
650
		delegate.preLaunchCheck(copy, ILaunchManager.RUN_MODE, subMonitor);
651
		delegate.launch(copy, ILaunchManager.RUN_MODE, launch, subMonitor);
652
		final IProcess[] processes = launch.getProcesses();
653
		for (int i = 0; i < processes.length; i++) {
654
			setProcessAttributes(processes[i], idStamp, null);
655
		}
656
657
		if (launchManager.isLaunchInBackground(copy)) {
658
			// refresh resources after process finishes
659
			if (configuration.getAttribute(ILaunchManager.ATTR_REFRESH_SCOPE, (String)null) != null) {
660
				BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(
661
						configuration, processes[0]);
662
				refresher.startBackgroundRefresh();
663
			}
664
		} else {
665
			final boolean[] terminated = new boolean[1];
666
			terminated[0] = launch.isTerminated();
667
			IDebugEventSetListener listener = new IDebugEventSetListener() {
668
				public void handleDebugEvents(DebugEvent[] events) {
669
					for (int i = 0; i < events.length; i++) {
670
						DebugEvent event = events[i];
671
						for (int j = 0, numProcesses = processes.length; j < numProcesses; j++) {
672
							if (event.getSource() == processes[j]
673
									&& event.getKind() == DebugEvent.TERMINATE) {
674
								terminated[0] = true;
675
								break;
676
							}
677
						}
678
					}
679
				}
680
			};
681
			DebugPlugin.getDefault().addDebugEventListener(listener);
682
			monitor
683
					.subTask(AntLaunchConfigurationMessages.AntLaunchDelegate_28);
684
			while (!monitor.isCanceled() && !terminated[0]) {
685
				try {
686
					Thread.sleep(50);
687
				} catch (InterruptedException e) {
688
				}
689
			}
690
			DebugPlugin.getDefault().removeDebugEventListener(listener);
691
			if (!monitor.isCanceled()) {
692
				// refresh resources
693
				launchManager.refreshResources(configuration, monitor);
694
			}
695
		}
696
	}
697
698
	private void setDefaultVM(ILaunchConfiguration configuration,
699
			ILaunchConfigurationWorkingCopy copy) {
700
		try {
701
			JavaRuntime.getJavaProject(configuration);
702
			// remove the vm name, install type and jre container path for the
703
			// Java launching concept of default VM
704
			copy.setAttribute(
705
					IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME,
706
					(String) null);
707
			copy.setAttribute(
708
					IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE,
709
					(String) null);
710
			copy.setAttribute(
711
					IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH,
712
					(String) null);
713
		} catch (CoreException ce) {
714
			// not in a Java project
715
			IVMInstall defaultVMInstall = JavaRuntime.getDefaultVMInstall();
716
			copy.setAttribute(
717
					IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME,
718
					defaultVMInstall.getName());
719
			copy.setAttribute(
720
					IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE,
721
					defaultVMInstall.getVMInstallType().getId());
722
		}
723
	}
724
725
	private StringBuffer generateVMArguments(ILaunchConfiguration config,
726
			boolean setInputHandler, String antHome) {
727
		StringBuffer vmArgs = new StringBuffer();
728
		try {
729
			String configArgs = config.getAttribute(
730
					IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
731
					(String) null);
732
			if (configArgs != null) {
733
				vmArgs.append(configArgs);
734
				vmArgs.append(' ');
735
			}
736
		} catch (CoreException e) {
737
		}
738
739
		if (antHome != null) {
740
			vmArgs.append("-Dant.home=\""); //$NON-NLS-1$
741
			vmArgs.append(antHome);
742
			vmArgs.append("\" "); //$NON-NLS-1$
743
744
			File antLibDir = new File(antHome, "lib"); //$NON-NLS-1$
745
			vmArgs.append("-Dant.library.dir=\""); //$NON-NLS-1$
746
			vmArgs.append(antLibDir.getAbsolutePath());
747
			vmArgs.append('\"');
748
		}
749
		if (setInputHandler) {
750
			String swtLocation = getSWTLibraryLocation();
751
			if (swtLocation != null) {
752
				vmArgs.append(" -Djava.library.path=\""); //$NON-NLS-1$
753
				String javaLibPath = System.getProperty("java.library.path"); //$NON-NLS-1$
754
				javaLibPath = stripUnescapedQuotes(javaLibPath);
755
				if (javaLibPath != null) {
756
					vmArgs.append(javaLibPath);
757
					if (vmArgs.charAt(vmArgs.length() - 1) != File.pathSeparatorChar) {
758
						vmArgs.append(File.pathSeparatorChar);
759
					}
760
				}
761
				vmArgs.append(swtLocation);
762
				vmArgs.append('"');
763
			}
764
		}
765
		return vmArgs;
766
	}
767
768
	private String stripUnescapedQuotes(String javaLibPath) {
769
		StringBuffer buf = new StringBuffer(javaLibPath.length());
770
		for (int i = 0; i < javaLibPath.length(); i++) {
771
			char c = javaLibPath.charAt(i);
772
			switch (c) {
773
			case '"':
774
				if (i != 0 && javaLibPath.charAt(i - 1) == '\\') {
775
					buf.append(c);
776
				}
777
				break;
778
			default:
779
				buf.append(c);
780
				break;
781
			}
782
		}
783
		return buf.toString();
784
	}
785
786
	/*
787
	 * (non-Javadoc)
788
	 * 
789
	 * @see
790
	 * org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBuildOrder
791
	 * (org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
792
	 */
793
	protected IProject[] getBuildOrder(ILaunchConfiguration configuration,
794
			String mode) throws CoreException {
795
		IProject[] projects = ExternalToolsCoreUtil.getBuildProjects(
796
				configuration, ATTR_BUILD_SCOPE);
797
		if (projects == null) {
798
			return NO_PROJECTS;
799
		}
800
		boolean isRef = ExternalToolsCoreUtil.isIncludeReferencedProjects(
801
				configuration, ATTR_INCLUDE_REFERENCED_PROJECTS);
802
		if (isRef) {
803
			return computeReferencedBuildOrder(projects);
804
		}
805
		return computeBuildOrder(projects);
806
	}
807
808
	private String getSWTLibraryLocation() {
809
		if (fgSWTLibraryLocation == null) {
810
			Bundle bundle = Platform.getBundle("org.eclipse.swt"); //$NON-NLS-1$
811
			BundleDescription description = Platform.getPlatformAdmin()
812
					.getState(false).getBundle(bundle.getBundleId());
813
			BundleDescription[] fragments = description.getFragments();
814
			if (fragments == null || fragments.length == 0) {
815
				return null;
816
			}
817
			Bundle fragBundle = Platform.getBundle(fragments[0]
818
					.getSymbolicName());
819
			try {
820
				URL url = FileLocator.toFileURL(fragBundle.getEntry("/")); //$NON-NLS-1$
821
				IPath path = new Path(url.getPath());
822
				path = path.removeTrailingSeparator();
823
				fgSWTLibraryLocation = path.toOSString();
824
			} catch (IOException e) {
825
			}
826
		}
827
		return fgSWTLibraryLocation;
828
	}
829
830
	/*
831
	 * (non-Javadoc)
832
	 * 
833
	 * @see
834
	 * org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBreakpoints
835
	 * (org.eclipse.debug.core.ILaunchConfiguration)
836
	 */
837
	protected IBreakpoint[] getBreakpoints(ILaunchConfiguration configuration) {
838
		IBreakpointManager breakpointManager = DebugPlugin.getDefault()
839
				.getBreakpointManager();
840
		if (!breakpointManager.isEnabled()) {
841
			// no need to check breakpoints individually.
842
			return null;
843
		}
844
		return breakpointManager
845
				.getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
846
	}
847
848
	/*
849
	 * (non-Javadoc)
850
	 * 
851
	 * @see
852
	 * org.eclipse.debug.core.model.LaunchConfigurationDelegate#saveBeforeLaunch
853
	 * (org.eclipse.debug.core.ILaunchConfiguration, java.lang.String,
854
	 * org.eclipse.core.runtime.IProgressMonitor)
855
	 */
856
	protected boolean saveBeforeLaunch(ILaunchConfiguration configuration,
857
			String mode, IProgressMonitor monitor) throws CoreException {
858
		if (IExternalToolConstants.ID_EXTERNAL_TOOLS_BUILDER_LAUNCH_CATEGORY
859
				.equals(configuration.getType().getCategory())) {
860
			// don't prompt for builders
861
			return true;
862
		}
863
		return super.saveBeforeLaunch(configuration, mode, monitor);
864
	}
865
866
	/**
867
	 * Sets the default working directory to be the parent folder of the
868
	 * buildfile if the user has not explicitly set the working directory.
869
	 */
870
	private void setDefaultWorkingDirectory(ILaunchConfigurationWorkingCopy copy) {
871
		try {
872
			String wd = copy.getAttribute(
873
					IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
874
					(String) null);
875
			if (wd == null) {
876
				wd = ExternalToolsCoreUtil.getLocation(copy)
877
						.removeLastSegments(1).toOSString();
878
				copy
879
						.setAttribute(
880
								IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
881
								wd);
882
			}
883
		} catch (CoreException e) {
884
			AntLaunching.log(e.getStatus());
885
		}
886
	}
887
888
	public ILaunch getLaunch(ILaunchConfiguration configuration, String mode)
889
			throws CoreException {
890
		return new AntLaunch(configuration, mode, null);
891
	}
892
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntMigrationDelegate.java (+77 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.launchConfigurations;
12
13
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
14
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.variables.IStringVariableManager;
19
import org.eclipse.core.variables.VariablesPlugin;
20
import org.eclipse.debug.core.ILaunchConfiguration;
21
import org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate;
22
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
23
24
/**
25
 * Delegate for migrating Ant launch configurations.
26
 * The migration process involves a resource mapping being created such that launch configurations
27
 * can be filtered from the launch configuration dialog based on resource availability.
28
 * 
29
 * @since 3.2
30
 */
31
public class AntMigrationDelegate implements ILaunchConfigurationMigrationDelegate {
32
	
33
	/**
34
	 * Method to get the file for the specified launch configuration that should be mapped to the launch configuration  
35
	 * 
36
	 * @param candidate the launch configuration that the file will be mapped to.
37
	 * @return the buildfile or <code>null</code> if not in the workspace
38
	 */
39
	protected IFile getFileForCandidate(ILaunchConfiguration candidate) {
40
		IFile file= null;
41
		String expandedLocation= null;
42
		String location= null;
43
		IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
44
		try {
45
			location= candidate.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String)null);
46
			if (location != null) {
47
				expandedLocation= manager.performStringSubstitution(location);
48
				if (expandedLocation != null) {
49
					file= AntLaunchingUtil.getFileForLocation(expandedLocation, null);
50
				}
51
			}
52
		} catch (CoreException e) {
53
		}
54
		return file;
55
	}
56
	
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate#isCandidate()
59
	 */
60
	public boolean isCandidate(ILaunchConfiguration candidate) throws CoreException {
61
		IResource[] mappedResources = candidate.getMappedResources();
62
		if (mappedResources != null && mappedResources.length > 0) {
63
			return false;
64
		}
65
		return getFileForCandidate(candidate) != null;
66
	}
67
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate#migrate(org.eclipse.debug.core.ILaunchConfiguration)
70
	 */
71
	public void migrate(ILaunchConfiguration candidate) throws CoreException {
72
		IFile file = getFileForCandidate(candidate);
73
		ILaunchConfigurationWorkingCopy wc = candidate.getWorkingCopy();
74
		wc.setMappedResources(new IResource[] {file});
75
		wc.doSave();
76
	}
77
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntProcess.java (+172 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.launchConfigurations;
12
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.PlatformObject;
19
import org.eclipse.debug.core.DebugEvent;
20
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.ILaunch;
22
import org.eclipse.debug.core.model.IProcess;
23
import org.eclipse.debug.core.model.IStreamsProxy;
24
25
public class AntProcess extends PlatformObject implements IProcess, IProgressMonitor {
26
	
27
	private AntStreamsProxy fProxy;
28
	private String fLabel = null;
29
	private ILaunch fLaunch = null;
30
	private Map fAttributes = null;
31
	private boolean fTerminated = false;
32
	private boolean fCancelled = false;
33
	
34
	public AntProcess(String label, ILaunch launch, Map attributes) {
35
		fLabel = label;
36
		fLaunch = launch;
37
		if (attributes == null) {
38
			fAttributes = new HashMap();
39
		} else {
40
			fAttributes = attributes;
41
		}
42
		String captureOutput= launch.getAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT);
43
		if(!("false".equals(captureOutput))) { //$NON-NLS-1$
44
			fProxy= new AntStreamsProxy();
45
		}
46
		launch.addProcess(this);
47
	}
48
49
	/**
50
	 * @see org.eclipse.debug.core.model.IProcess#getLabel()
51
	 */
52
	public String getLabel() {
53
		return fLabel;
54
	}
55
56
	/**
57
	 * @see org.eclipse.debug.core.model.IProcess#getLaunch()
58
	 */
59
	public ILaunch getLaunch() {
60
		return fLaunch;
61
	}
62
63
	/**
64
	 * @see org.eclipse.debug.core.model.IProcess#getStreamsProxy()
65
	 */
66
	public IStreamsProxy getStreamsProxy() {
67
		return fProxy;
68
	}
69
70
	/**
71
	 * @see org.eclipse.debug.core.model.IProcess#setAttribute(java.lang.String, java.lang.String)
72
	 */
73
	public void setAttribute(String key, String value) {
74
		fAttributes.put(key, value);
75
	}
76
77
	/**
78
	 * @see org.eclipse.debug.core.model.IProcess#getAttribute(java.lang.String)
79
	 */
80
	public String getAttribute(String key) {
81
		return (String)fAttributes.get(key);
82
	}
83
84
	/**
85
	 * @see org.eclipse.debug.core.model.IProcess#getExitValue()
86
	 */
87
	public int getExitValue() {
88
		return 0;
89
	}
90
91
	/**
92
	 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
93
	 */
94
	public boolean canTerminate() {
95
		return !isCanceled() && !isTerminated();
96
	}
97
98
	/**
99
	 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
100
	 */
101
	public boolean isTerminated() {
102
		return fTerminated;
103
	}
104
	
105
	protected void terminated() {
106
		if (!fTerminated) {
107
			fTerminated = true;
108
			if (DebugPlugin.getDefault() != null) {
109
				DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {new DebugEvent(this, DebugEvent.TERMINATE)});
110
			}
111
		}
112
	}
113
114
	/**
115
	 * @see org.eclipse.debug.core.model.ITerminate#terminate()
116
	 */
117
	public void terminate() {
118
		setCanceled(true);
119
	}
120
	
121
	// IProgressMonitor implemented to support termination.
122
	
123
	/**
124
	 * @see org.eclipse.core.runtime.IProgressMonitor#beginTask(java.lang.String, int)
125
	 */
126
	public void beginTask(String name, int totalWork) {
127
	}
128
129
	/**
130
	 * @see org.eclipse.core.runtime.IProgressMonitor#done()
131
	 */
132
	public void done() {
133
	}
134
135
	/**
136
	 * @see org.eclipse.core.runtime.IProgressMonitor#internalWorked(double)
137
	 */
138
	public void internalWorked(double work) {
139
	}
140
141
	/**
142
	 * @see org.eclipse.core.runtime.IProgressMonitor#isCanceled()
143
	 */
144
	public boolean isCanceled() {
145
		return fCancelled;
146
	}
147
148
	/**
149
	 * @see org.eclipse.core.runtime.IProgressMonitor#setCanceled(boolean)
150
	 */
151
	public void setCanceled(boolean value) {
152
		fCancelled = value;
153
	}
154
155
	/**
156
	 * @see org.eclipse.core.runtime.IProgressMonitor#setTaskName(java.lang.String)
157
	 */
158
	public void setTaskName(String name) {
159
	}
160
161
	/**
162
	 * @see org.eclipse.core.runtime.IProgressMonitor#subTask(java.lang.String)
163
	 */
164
	public void subTask(String name) {
165
	}
166
167
	/**
168
	 * @see org.eclipse.core.runtime.IProgressMonitor#worked(int)
169
	 */
170
	public void worked(int work) {
171
	}
172
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntStreamMonitor.java (+83 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.launchConfigurations;
12
13
import org.eclipse.core.runtime.ListenerList;
14
import org.eclipse.debug.core.IStreamListener;
15
import org.eclipse.debug.core.model.IFlushableStreamMonitor;
16
17
/**
18
 * Stream monitor implementation for an Ant build process.
19
 */
20
public class AntStreamMonitor implements IFlushableStreamMonitor {
21
22
	private StringBuffer fContents = new StringBuffer();
23
	private ListenerList fListeners = new ListenerList(1);
24
	private boolean fBuffered = true;
25
	
26
	/**
27
	 * @see org.eclipse.debug.core.model.IStreamMonitor#addListener(org.eclipse.debug.core.IStreamListener)
28
	 */
29
	public void addListener(IStreamListener listener) {
30
		fListeners.add(listener);
31
	}
32
33
	/**
34
	 * @see org.eclipse.debug.core.model.IStreamMonitor#getContents()
35
	 */
36
	public String getContents() {
37
		return fContents.toString();
38
	}
39
40
	/**
41
	 * @see org.eclipse.debug.core.model.IStreamMonitor#removeListener(org.eclipse.debug.core.IStreamListener)
42
	 */
43
	public void removeListener(IStreamListener listener) {
44
		fListeners.remove(listener);
45
	}
46
47
	/**
48
	 * Appends the given message to this stream, and notifies listeners.
49
	 * 
50
	 * @param message
51
	 */
52
	public void append(String message) {
53
		if (isBuffered()) {
54
			fContents.append(message);
55
		}
56
		Object[] listeners = fListeners.getListeners();
57
		for (int i = 0; i < listeners.length; i++) {
58
			IStreamListener listener = (IStreamListener)listeners[i];
59
			listener.streamAppended(message, this);
60
		}
61
	}
62
	/**
63
	 * @see org.eclipse.debug.core.model.IFlushableStreamMonitor#flushContents()
64
	 */
65
	public void flushContents() {
66
		fContents.setLength(0);
67
	}
68
69
	/**
70
	 * @see org.eclipse.debug.core.model.IFlushableStreamMonitor#isBuffered()
71
	 */
72
	public boolean isBuffered() {
73
		return fBuffered;
74
	}
75
76
	/**
77
	 * @see org.eclipse.debug.core.model.IFlushableStreamMonitor#setBuffered(boolean)
78
	 */
79
	public void setBuffered(boolean buffer) {
80
		fBuffered = buffer;
81
	}
82
}
83
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/AntStreamsProxy.java (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.launchConfigurations;
12
13
14
import org.eclipse.ant.internal.launching.AntLaunching;
15
import org.eclipse.debug.core.model.IStreamMonitor;
16
import org.eclipse.debug.core.model.IStreamsProxy;
17
18
/**
19
 * 
20
 */
21
public class AntStreamsProxy implements IStreamsProxy {
22
	
23
	private AntStreamMonitor fErrorMonitor = new AntStreamMonitor();
24
	private AntStreamMonitor fOutputMonitor = new AntStreamMonitor();
25
	
26
	public static final String ANT_DEBUG_STREAM = AntLaunching.PLUGIN_ID + ".ANT_DEBUG_STREAM"; //$NON-NLS-1$
27
	public static final String ANT_VERBOSE_STREAM = AntLaunching.PLUGIN_ID + ".ANT_VERBOSE_STREAM"; //$NON-NLS-1$
28
	public static final String ANT_WARNING_STREAM = AntLaunching.PLUGIN_ID + ".ANT_WARNING_STREAM"; //$NON-NLS-1$
29
	
30
	private AntStreamMonitor fDebugMonitor = new AntStreamMonitor();
31
	private AntStreamMonitor fVerboseMonitor = new AntStreamMonitor();
32
	private AntStreamMonitor fWarningMonitor = new AntStreamMonitor();
33
34
	/**
35
	 * @see org.eclipse.debug.core.model.IStreamsProxy#getErrorStreamMonitor()
36
	 */
37
	public IStreamMonitor getErrorStreamMonitor() {
38
		return fErrorMonitor;
39
	}
40
41
	/**
42
	 * @see org.eclipse.debug.core.model.IStreamsProxy#getOutputStreamMonitor()
43
	 */
44
	public IStreamMonitor getOutputStreamMonitor() {
45
		return fOutputMonitor;
46
	}
47
48
	/**
49
	 * @see org.eclipse.debug.core.model.IStreamsProxy#write(java.lang.String)
50
	 */
51
	public void write(String input) {
52
	}
53
54
	public IStreamMonitor getWarningStreamMonitor() {
55
		return fWarningMonitor;
56
	}
57
	
58
	public IStreamMonitor getDebugStreamMonitor() {
59
		return fDebugMonitor;
60
	}	
61
	
62
	public IStreamMonitor getVerboseStreamMonitor() {
63
		return fVerboseMonitor;
64
	}	
65
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/ContributedClasspathEntriesEntry.java (+246 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.launching.launchConfigurations;
12
13
import java.io.File;
14
import java.io.FilenameFilter;
15
import java.io.IOException;
16
import java.net.MalformedURLException;
17
import java.net.URL;
18
import java.util.ArrayList;
19
import java.util.List;
20
21
import org.eclipse.ant.core.AntCorePlugin;
22
import org.eclipse.ant.core.AntCorePreferences;
23
import org.eclipse.ant.core.IAntClasspathEntry;
24
import org.eclipse.ant.internal.launching.AntLaunching;
25
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
26
import org.eclipse.ant.launching.IAntLaunchConstants;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.FileLocator;
29
import org.eclipse.core.runtime.IPath;
30
import org.eclipse.core.runtime.Path;
31
import org.eclipse.core.runtime.Platform;
32
import org.eclipse.debug.core.ILaunchConfiguration;
33
import org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry;
34
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
35
import org.eclipse.jdt.launching.IVMInstall;
36
import org.eclipse.jdt.launching.JavaRuntime;
37
import org.eclipse.osgi.service.resolver.BundleDescription;
38
import org.osgi.framework.Bundle;
39
import org.w3c.dom.Document;
40
import org.w3c.dom.Element;
41
42
/**
43
 * A classpath entry that contains a contributed classpath entries
44
 * via the <code>extraClasspathEntries</code> extension point.
45
 * 
46
 * @since 3.0 
47
 */
48
public class ContributedClasspathEntriesEntry extends AbstractRuntimeClasspathEntry {
49
	
50
	public static final String TYPE_ID = "org.eclipse.ant.ui.classpathentry.extraClasspathEntries"; //$NON-NLS-1$
51
    
52
    public static List fgSWTEntries= null;
53
		
54
	/**
55
	 * Default contructor required to instantiate persisted extensions.
56
	 */
57
	public ContributedClasspathEntriesEntry() {
58
	}
59
	
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry#buildMemento(org.w3c.dom.Document, org.w3c.dom.Element)
62
	 */
63
	protected void buildMemento(Document document, Element memento) throws CoreException {
64
	}
65
	
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.jdt.internal.launching.IRuntimeClasspathEntry2#initializeFrom(org.w3c.dom.Element)
68
	 */
69
	public void initializeFrom(Element memento) throws CoreException {
70
	}
71
	
72
	/* (non-Javadoc)
73
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getTypeId()
74
	 */
75
	public String getTypeId() {
76
		return TYPE_ID;
77
	}
78
	
79
	/* (non-Javadoc)
80
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getRuntimeClasspathEntries(org.eclipse.debug.core.ILaunchConfiguration)
81
	 */
82
	public IRuntimeClasspathEntry[] getRuntimeClasspathEntries(ILaunchConfiguration configuration) throws CoreException {
83
		boolean separateVM= AntLaunchingUtil.isSeparateJREAntBuild(configuration);
84
		boolean setInputHandler= configuration.getAttribute(AntLaunching.SET_INPUTHANDLER, true);
85
		AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences();
86
		IAntClasspathEntry[] antClasspathEntries = prefs.getContributedClasspathEntries();
87
		IAntClasspathEntry[] userEntries = prefs.getAdditionalClasspathEntries();
88
		List rtes = new ArrayList(antClasspathEntries.length + userEntries.length);
89
		IAntClasspathEntry entry;
90
		for (int i = 0; i < antClasspathEntries.length; i++) {
91
			 entry= antClasspathEntries[i];
92
			if (!separateVM || (separateVM && !entry.isEclipseRuntimeRequired())) {
93
				rtes.add(JavaRuntime.newStringVariableClasspathEntry(entry.getLabel()));
94
			}
95
		}
96
		boolean haveToolsEntry= false;
97
		String path;
98
		for (int i = 0; i < userEntries.length; i++) {
99
			entry = userEntries[i];
100
			path= entry.getLabel();
101
            IPath toolsPath= new Path(path);
102
			if (toolsPath.lastSegment().equals("tools.jar")) { //$NON-NLS-1$
103
				haveToolsEntry= true;
104
				// replace with dynamically resolved tools.jar based on
105
				// the JRE being used
106
				addToolsJar(configuration, rtes, path);
107
			} else {
108
				rtes.add(JavaRuntime.newStringVariableClasspathEntry(path));
109
			}
110
		}
111
		if (!haveToolsEntry) {
112
			addToolsJar(configuration, rtes, null);
113
		}
114
		
115
		if (setInputHandler && separateVM) {
116
			addSWTJars(rtes);
117
		}
118
		
119
		return (IRuntimeClasspathEntry[]) rtes.toArray(new IRuntimeClasspathEntry[rtes.size()]);
120
	}
121
	
122
	private void addToolsJar(ILaunchConfiguration configuration, List rtes, String path) {
123
		IRuntimeClasspathEntry tools = getToolsJar(configuration);
124
		if (tools == null) {
125
			if (path != null) {
126
				//use the global entry
127
				rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(path)));
128
			} else {
129
				//use the default vm install to try to find a tools.jar
130
				IVMInstall install= JavaRuntime.getDefaultVMInstall();
131
				if (install != null) {
132
					IAntClasspathEntry entry = AntCorePlugin.getPlugin().getPreferences().getToolsJarEntry(new Path(install.getInstallLocation().getAbsolutePath()));
133
					if (entry != null) {
134
						rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(entry.getEntryURL().getPath())));
135
					}
136
				}
137
			}
138
		} else {
139
			rtes.add(tools);
140
		}
141
	}
142
	
143
	private void addSWTJars(List rtes) {
144
        if (fgSWTEntries == null) {
145
            fgSWTEntries= new ArrayList();
146
            Bundle bundle= Platform.getBundle("org.eclipse.swt"); //$NON-NLS-1$
147
            BundleDescription description= Platform.getPlatformAdmin().getState(false).getBundle(bundle.getBundleId());
148
            BundleDescription[] fragments= description.getFragments();
149
            for (int i = 0; i < fragments.length; i++) {
150
                Bundle fragmentBundle= Platform.getBundle(fragments[i].getName());
151
                URL bundleURL;
152
                try {
153
                    bundleURL = FileLocator.resolve(fragmentBundle.getEntry("/")); //$NON-NLS-1$
154
                } catch (IOException e) {
155
                    AntLaunching.log(e);
156
                   continue;
157
                }
158
                String urlFileName= bundleURL.getFile();
159
                if (urlFileName.startsWith("file:")) { //$NON-NLS-1$
160
                    try {
161
                        urlFileName= new URL(urlFileName).getFile();
162
                        if (urlFileName.endsWith("!/")) { //$NON-NLS-1$
163
                            urlFileName= urlFileName.substring(0, urlFileName.length() - 2);
164
                        }
165
                    } catch (MalformedURLException e) {
166
                    	 AntLaunching.log(e);
167
                       continue;
168
                    }
169
                }
170
                IPath fragmentPath= new Path(urlFileName);
171
                if (fragmentPath.getFileExtension() != null) { //JAR file
172
                    fgSWTEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath));
173
                } else { // folder
174
                    File bundleFolder= fragmentPath.toFile();
175
                    if (!bundleFolder.isDirectory()) {
176
                        continue;
177
                    }
178
                    String[] names= bundleFolder.list(new FilenameFilter() {
179
                        public boolean accept(File dir, String name) {
180
                            return name.endsWith(".jar"); //$NON-NLS-1$
181
                        }
182
                    });
183
                    for (int j = 0; j < names.length; j++) {
184
                        String jarName = names[j];
185
                        fgSWTEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath.append(jarName)));
186
                    }
187
                }
188
            }
189
        }
190
        rtes.addAll(fgSWTEntries);
191
	}
192
    
193
	/**
194
	 * Returns the tools.jar to use for this launch configuration, or <code>null</code>
195
	 * if none.
196
	 * 
197
	 * @param configuration configuration to resolve a tools.jar for
198
	 * @return associated tools.jar archive, or <code>null</code>
199
	 */
200
	private IRuntimeClasspathEntry getToolsJar(ILaunchConfiguration configuration) {
201
		try {
202
			IVMInstall install = JavaRuntime.computeVMInstall(configuration);
203
			if (install != null) {
204
				IAntClasspathEntry entry = AntCorePlugin.getPlugin().getPreferences().getToolsJarEntry(new Path(install.getInstallLocation().getAbsolutePath()));
205
				if (entry != null) {
206
					return JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(entry.getEntryURL().getPath()));
207
				}
208
			}
209
		} catch (CoreException ce) {
210
			//likely dealing with a non-Java project
211
		}
212
			
213
		return null;
214
	}
215
	
216
	/* (non-Javadoc)
217
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getName()
218
	 */
219
	public String getName() {
220
		return AntLaunchConfigurationMessages.ContributedClasspathEntriesEntry_1;
221
	}
222
	/* (non-Javadoc)
223
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getType()
224
	 */
225
	public int getType() {
226
		return IRuntimeClasspathEntry.OTHER;
227
	}
228
	/* (non-Javadoc)
229
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#isComposite()
230
	 */
231
	public boolean isComposite() {
232
		return true;
233
	}
234
	/* (non-Javadoc)
235
	 * @see java.lang.Object#equals(java.lang.Object)
236
	 */
237
	public boolean equals(Object obj) {
238
		return obj instanceof ContributedClasspathEntriesEntry;
239
	}
240
	/* (non-Javadoc)
241
	 * @see java.lang.Object#hashCode()
242
	 */
243
	public int hashCode() {
244
		return getClass().hashCode();
245
	}
246
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/MessageIds.java (+21 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.launching.launchConfigurations;
13
14
public class MessageIds {
15
16
	public final static String PROCESS_ID=   "processID"; //$NON-NLS-1$
17
	public final static String BUILD_CANCELLED= "cancelled"; //$NON-NLS-1$
18
	//constants need to start greater than the Project.MSG_* constants
19
    public final static String TASK= "6"; //$NON-NLS-1$
20
    public final static String TARGET= "7"; //$NON-NLS-1$
21
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/RemoteAntBuildListener.java (+402 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2003, 2009 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 *  Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.launching.launchConfigurations;
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.InputStreamReader;
17
import java.net.ServerSocket;
18
import java.net.Socket;
19
import java.net.SocketException;
20
import java.net.SocketTimeoutException;
21
import java.util.ArrayList;
22
import java.util.Iterator;
23
import java.util.List;
24
import java.util.StringTokenizer;
25
26
import org.apache.tools.ant.Project;
27
import org.eclipse.ant.internal.core.AbstractEclipseBuildLogger;
28
import org.eclipse.ant.internal.launching.AntLaunch;
29
import org.eclipse.ant.internal.launching.AntLaunching;
30
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
31
import org.eclipse.ant.internal.launching.IAntLaunchingPreferenceConstants;
32
import org.eclipse.ant.launching.IAntLaunchConstants;
33
import org.eclipse.core.runtime.ISafeRunnable;
34
import org.eclipse.core.runtime.Platform;
35
import org.eclipse.debug.core.DebugPlugin;
36
import org.eclipse.debug.core.ILaunch;
37
import org.eclipse.debug.core.ILaunchesListener;
38
import org.eclipse.debug.core.model.IProcess;
39
40
/**
41
 * Parts adapted from org.eclipse.jdt.internal.junit.ui.RemoteTestRunnerClient
42
 * The client side of the RemoteAntBuildLogger. Handles the marshalling of the
43
 * different messages.
44
 */
45
public class RemoteAntBuildListener implements ILaunchesListener {
46
	public abstract class ListenerSafeRunnable implements ISafeRunnable {
47
		public void handleException(Throwable exception) {
48
			AntLaunching.log(exception);
49
		}
50
	}
51
52
	/**
53
	 * The server socket
54
	 */
55
	private ServerSocket fServerSocket;
56
	private Socket fSocket;
57
	private BufferedReader fBufferedReader;
58
	private IProcess fProcess;
59
	private String fProcessId;
60
	private List fMessageQueue;
61
	protected ILaunch fLaunch;
62
	private String fLastFileName = null;
63
	private String fLastTaskName = null;
64
	private boolean fBuildFailed = false;
65
66
	/**
67
	 * Reads the message stream from the RemoteAntBuildLogger
68
	 */
69
	private class ServerConnection extends Thread {
70
		private int fServerPort;
71
72
		public ServerConnection(int port) {
73
			super("Ant Build Server Connection"); //$NON-NLS-1$
74
			setDaemon(true);
75
			fServerPort = port;
76
		}
77
78
		public void run() {
79
			Exception exception = null;
80
			try {
81
				fServerSocket = new ServerSocket(fServerPort);
82
83
				int socketTimeout = Platform
84
						.getPreferencesService()
85
						.getInt(
86
								AntLaunching.getUniqueIdentifier(),
87
								IAntLaunchingPreferenceConstants.ANT_COMMUNICATION_TIMEOUT,
88
								20000, null);
89
				fServerSocket.setSoTimeout(socketTimeout);
90
				fSocket = fServerSocket.accept();
91
				fBufferedReader = new BufferedReader(new InputStreamReader(
92
						fSocket.getInputStream(), "UTF-8")); //$NON-NLS-1$
93
				String message;
94
				while (fBufferedReader != null
95
						&& (message = fBufferedReader.readLine()) != null) {
96
					receiveMessage(message);
97
				}
98
			} catch (SocketException e) {
99
			} catch (SocketTimeoutException e) {
100
				exception = e;
101
			} catch (IOException e) {
102
				// fall through
103
				exception = e;
104
			}
105
			if (exception != null) {
106
				AntLaunching.log(exception);
107
			}
108
			shutDown();
109
		}
110
	}
111
112
	public RemoteAntBuildListener(ILaunch launch) {
113
		super();
114
		fLaunch = launch;
115
		DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
116
	}
117
118
	/**
119
	 * Start listening to an Ant build. Start a server connection that the
120
	 * RemoteAntBuildLogger can connect to.
121
	 * 
122
	 * @param eventPort
123
	 *            The port number to create the server connection on
124
	 */
125
	public synchronized void startListening(int eventPort) {
126
		ServerConnection connection = new ServerConnection(eventPort);
127
		connection.start();
128
	}
129
130
	protected synchronized void shutDown() {
131
		fLaunch = null;
132
		if (DebugPlugin.getDefault() != null) {
133
			DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(
134
					this);
135
		}
136
		try {
137
			if (fBufferedReader != null) {
138
				fBufferedReader.close();
139
				fBufferedReader = null;
140
			}
141
		} catch (IOException e) {
142
		}
143
		try {
144
			if (fSocket != null) {
145
				fSocket.close();
146
				fSocket = null;
147
			}
148
		} catch (IOException e) {
149
		}
150
		try {
151
			if (fServerSocket != null) {
152
				fServerSocket.close();
153
				fServerSocket = null;
154
			}
155
		} catch (IOException e) {
156
		}
157
	}
158
159
	protected void receiveMessage(String message) {
160
		if (message.startsWith(MessageIds.TASK)) {
161
			receiveTaskMessage(message);
162
		} else if (message.startsWith(MessageIds.TARGET)) {
163
			receiveTargetMessage(message);
164
		} else if (message.startsWith(MessageIds.PROCESS_ID)) {
165
			message = message.substring(MessageIds.PROCESS_ID.length());
166
			fProcessId = message;
167
		} else {
168
			int index = message.indexOf(',');
169
			if (index > 0) {
170
				int priority = Integer.parseInt(message.substring(0, index));
171
				message = message.substring(index + 1);
172
				writeMessage(
173
						message + System.getProperty("line.separator"), priority); //$NON-NLS-1$
174
				if (message.startsWith("BUILD FAILED")) { //$NON-NLS-1$
175
					fBuildFailed = true;
176
				} else if (fBuildFailed) {
177
					if (message.startsWith("Total time:")) { //$NON-NLS-1$
178
						fBuildFailed = false;
179
					} else {
180
						AntLaunchingUtil.linkBuildFailedMessage(message,
181
								getProcess());
182
					}
183
				}
184
185
			}
186
		}
187
	}
188
189
	private void receiveTargetMessage(String message) {
190
		message = message.substring(MessageIds.TARGET.length());
191
		StringTokenizer tokenizer = new StringTokenizer(message, ","); //$NON-NLS-1$
192
		message = tokenizer.nextToken();
193
		if (tokenizer.hasMoreTokens()) {
194
			int locationLength = Integer.parseInt(tokenizer.nextToken());
195
			String location = tokenizer.nextToken();
196
			while (location.length() < locationLength) { // path with a comma in
197
				// it
198
				location += ","; //$NON-NLS-1$
199
				location += tokenizer.nextToken();
200
			}
201
			int lineNumber = Integer.parseInt(tokenizer.nextToken());
202
			generateLink(message, location, lineNumber, 0, message.length() - 1);
203
		}
204
		writeMessage(
205
				message + System.getProperty("line.separator"), Project.MSG_INFO); //$NON-NLS-1$
206
	}
207
208
	private void receiveTaskMessage(String message) {
209
		message = message.substring(MessageIds.TASK.length());
210
211
		int index = message.indexOf(',');
212
		int priority = Integer.parseInt(message.substring(0, index));
213
		int index2 = message.indexOf(',', index + 1);
214
		String taskName = message.substring(index + 1, index2);
215
		if (taskName.length() == 0) {
216
			taskName = fLastTaskName;
217
		}
218
		int index3 = message.indexOf(',', index2 + 1);
219
		int lineLength = Integer
220
				.parseInt(message.substring(index2 + 1, index3));
221
		int index4 = index3 + 1 + lineLength;
222
223
		String line = message.substring(index3 + 1, index4);
224
		StringBuffer labelBuff = new StringBuffer();
225
		labelBuff.append('[');
226
		labelBuff.append(taskName);
227
		labelBuff.append("] "); //$NON-NLS-1$
228
		labelBuff.append(line);
229
		line = labelBuff.toString();
230
231
		fLastTaskName = taskName;
232
233
		int locationIndex = message.indexOf(',', index4 + 1);
234
		int finalIndex = locationIndex + 1;
235
		String fileName = message.substring(index4 + 1, locationIndex);
236
		int locationLength = 0;
237
		if (fileName.length() == 0) {
238
			fileName = fLastFileName;
239
		} else {
240
			finalIndex = message.indexOf(',', locationIndex) + 1;
241
			locationLength = Integer.parseInt(fileName);
242
			fileName = message.substring(finalIndex, finalIndex
243
					+ locationLength);
244
			locationLength += 1; // set past delimiter
245
		}
246
		fLastFileName = fileName;
247
		int lineNumber = Integer.parseInt(message.substring(finalIndex
248
				+ locationLength));
249
250
		int size = AntLaunching.LEFT_COLUMN_SIZE
251
				- (taskName.length() + 3);
252
		int offset = Math.max(size - 2, 1);
253
		int length = AntLaunching.LEFT_COLUMN_SIZE - size - 3;
254
		if (fileName != null) {
255
			generateLink(line, fileName, lineNumber, offset, length);
256
		}
257
258
		StringBuffer fullMessage = new StringBuffer();
259
		adornMessage(taskName, line, fullMessage);
260
		writeMessage(
261
				fullMessage
262
						.append(System.getProperty("line.separator")).toString(), priority); //$NON-NLS-1$
263
	}
264
265
	private void generateLink(String line, String fileName, int lineNumber,
266
			int offset, int length) {
267
		((AntLaunch) fLaunch).addLinkDescriptor(line, fileName, lineNumber,
268
				offset, length);
269
	}
270
271
	/**
272
	 * Returns the associated process, finding it if necessary.
273
	 */
274
	protected IProcess getProcess() {
275
		if (fProcess == null) {
276
			if (fProcessId != null) {
277
				IProcess[] all = DebugPlugin.getDefault().getLaunchManager()
278
						.getProcesses();
279
				for (int i = 0; i < all.length; i++) {
280
					IProcess process = all[i];
281
					if (fProcessId
282
							.equals(process
283
									.getAttribute(AbstractEclipseBuildLogger.ANT_PROCESS_ID))) {
284
						fProcess = process;
285
						break;
286
					}
287
				}
288
			}
289
		}
290
		return fProcess;
291
	}
292
293
	private AntStreamMonitor getMonitor(int priority) {
294
		IProcess process = getProcess();
295
		if (process == null) {
296
			return null;
297
		}
298
		AntStreamsProxy proxy = (AntStreamsProxy) process.getStreamsProxy();
299
		if (proxy == null) {
300
			return null;
301
		}
302
		AntStreamMonitor monitor = null;
303
		switch (priority) {
304
		case Project.MSG_INFO:
305
			monitor = (AntStreamMonitor) proxy.getOutputStreamMonitor();
306
			break;
307
		case Project.MSG_ERR:
308
			monitor = (AntStreamMonitor) proxy.getErrorStreamMonitor();
309
			break;
310
		case Project.MSG_DEBUG:
311
			monitor = (AntStreamMonitor) proxy.getDebugStreamMonitor();
312
			break;
313
		case Project.MSG_WARN:
314
			monitor = (AntStreamMonitor) proxy.getWarningStreamMonitor();
315
			break;
316
		case Project.MSG_VERBOSE:
317
			monitor = (AntStreamMonitor) proxy.getVerboseStreamMonitor();
318
			break;
319
		}
320
		return monitor;
321
	}
322
323
	/**
324
	 * Builds a right justified task prefix for the given build event, placing
325
	 * it in the given string buffer.
326
	 * 
327
	 * @param event
328
	 *            build event
329
	 * @param fullMessage
330
	 *            buffer to place task prefix in
331
	 */
332
	private void adornMessage(String taskName, String line,
333
			StringBuffer fullMessage) {
334
		if (taskName == null) {
335
			taskName = "null"; //$NON-NLS-1$
336
		}
337
338
		int size = AntLaunching.LEFT_COLUMN_SIZE
339
				- (taskName.length() + 6);
340
		for (int i = 0; i < size; i++) {
341
			fullMessage.append(' ');
342
		}
343
344
		fullMessage.append(line);
345
	}
346
347
	protected void writeMessage(String message, int priority) {
348
		AntStreamMonitor monitor = getMonitor(priority);
349
		if (monitor == null) {
350
			if (fMessageQueue == null) {
351
				fMessageQueue = new ArrayList();
352
			}
353
			fMessageQueue.add(message);
354
			return;
355
		}
356
		if (fMessageQueue != null) {
357
			for (Iterator iter = fMessageQueue.iterator(); iter.hasNext();) {
358
				String oldMessage = (String) iter.next();
359
				monitor.append(oldMessage);
360
			}
361
			fMessageQueue = null;
362
		}
363
		monitor.append(message);
364
	}
365
366
	/*
367
	 * (non-Javadoc)
368
	 * 
369
	 * @see
370
	 * org.eclipse.debug.core.ILaunchesListener#launchesAdded(org.eclipse.debug
371
	 * .core.ILaunch[])
372
	 */
373
	public void launchesAdded(ILaunch[] launches) {
374
	}
375
376
	/*
377
	 * (non-Javadoc)
378
	 * 
379
	 * @see
380
	 * org.eclipse.debug.core.ILaunchesListener#launchesChanged(org.eclipse.
381
	 * debug.core.ILaunch[])
382
	 */
383
	public void launchesChanged(ILaunch[] launches) {
384
	}
385
386
	/*
387
	 * (non-Javadoc)
388
	 * 
389
	 * @see
390
	 * org.eclipse.debug.core.ILaunchesListener#launchesRemoved(org.eclipse.
391
	 * debug.core.ILaunch[])
392
	 */
393
	public void launchesRemoved(ILaunch[] launches) {
394
		for (int i = 0; i < launches.length; i++) {
395
			ILaunch launch = launches[i];
396
			if (launch.equals(fLaunch)) {
397
				shutDown();
398
				return;
399
			}
400
		}
401
	}
402
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/RemoteAntProcessFactory.java (+34 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.launching.launchConfigurations;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.ant.launching.IAntLaunchConstants;
18
import org.eclipse.debug.core.ILaunch;
19
import org.eclipse.debug.core.IProcessFactory;
20
import org.eclipse.debug.core.model.IProcess;
21
22
public class RemoteAntProcessFactory implements IProcessFactory {
23
24
	/* (non-Javadoc)
25
	 * @see org.eclipse.debug.core.IProcessFactory#newProcess(org.eclipse.debug.core.ILaunch, java.lang.Process, java.lang.String, java.util.Map)
26
	 */
27
	public IProcess newProcess(ILaunch launch, Process process, String label, Map attributes) {
28
		if (attributes == null) {
29
			attributes= new HashMap(1);
30
		}
31
		attributes.put(IProcess.ATTR_PROCESS_TYPE, IAntLaunchConstants.ID_ANT_PROCESS_TYPE);
32
		return new RemoteAntRuntimeProcess(launch, process, label, attributes);
33
	}
34
}
(-)src/org/eclipse/ant/internal/launching/launchConfigurations/RemoteAntRuntimeProcess.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.launching.launchConfigurations;
13
14
import java.util.Map;
15
import org.eclipse.debug.core.ILaunch;
16
import org.eclipse.debug.core.model.IStreamsProxy;
17
import org.eclipse.debug.core.model.RuntimeProcess;
18
19
public class RemoteAntRuntimeProcess extends RuntimeProcess {
20
21
	/**
22
	 * Constructs a RuntimeProcess on the given system process
23
	 * with the given name, adding this process to the given
24
	 * launch.
25
	 * Sets the streams proxy to an AntStreamsProxy if output is captured.
26
	 */
27
	public RemoteAntRuntimeProcess(ILaunch launch, Process process, String name, Map attributes) {
28
		super(launch, process, name, attributes);
29
	}
30
	
31
	/* (non-Javadoc)
32
	 * @see org.eclipse.debug.core.model.RuntimeProcess#createStreamsProxy()
33
	 */
34
	protected IStreamsProxy createStreamsProxy() {
35
		return new AntStreamsProxy();
36
	}
37
}
(-)src/org/eclipse/ant/launching/IAntLaunchConstants.java (+124 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.launching;
13
14
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
15
16
/**
17
 * Constant definitions for Ant launch configurations.
18
 * 
19
 * @since 1.0
20
 * @noimplement This interface is not intended to be implemented by clients.
21
 */
22
public interface IAntLaunchConstants {
23
24
	/**
25
	 * Ant launch configuration type identifier.
26
	 */
27
	public static final String ID_ANT_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.ant.AntLaunchConfigurationType"; //$NON-NLS-1$
28
29
	/**
30
	 * Ant builder launch configuration type identifier. Ant project builders
31
	 * are of this type.
32
	 */
33
	public static final String ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.ant.AntBuilderLaunchConfigurationType"; //$NON-NLS-1$
34
35
	/**
36
	 * String attribute indicating the Ant targets to execute. Default value is
37
	 * <code>null</code> which indicates that the default target is to be
38
	 * executed. Format is a comma separated listing of targets.
39
	 */
40
	public static final String ATTR_ANT_TARGETS = IExternalToolConstants.UI_PLUGIN_ID + ".ATTR_ANT_TARGETS"; //$NON-NLS-1$
41
42
	/**
43
	 * String attribute indicating the Ant targets to execute after a clean
44
	 * (full build) for an Ant builder. Default value is <code>null</code> which
45
	 * indicates that the default target is to be executed. Format is a comma
46
	 * separated listing of targets.
47
	 */
48
	public static final String ATTR_ANT_AFTER_CLEAN_TARGETS = "org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS"; //$NON-NLS-1$
49
50
	/**
51
	 * String attribute indicating the Ant targets to execute during a manual
52
	 * build for an Ant builder. Default value is <code>null</code> which
53
	 * indicates that the default target is to be executed. Format is a comma
54
	 * separated listing of targets.
55
	 */
56
	public static final String ATTR_ANT_MANUAL_TARGETS = "org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS"; //$NON-NLS-1$
57
58
	/**
59
	 * String attribute indicating the Ant targets to execute during an auto
60
	 * build for an Ant builder. Default value is <code>null</code> which
61
	 * indicates that the default target is to be executed. Format is a comma
62
	 * separated listing of targets.
63
	 */
64
	public static final String ATTR_ANT_AUTO_TARGETS = "org.eclipse.ant.ui.ATTR_ANT_AUTO_TARGETS"; //$NON-NLS-1$
65
66
	/**
67
	 * String attribute indicating the Ant targets to execute during a clean for
68
	 * an Ant builder. Default value is <code>null</code> which indicates that
69
	 * the default target is to be executed. Format is a comma separated listing
70
	 * of targets.
71
	 */
72
	public static final String ATTR_ANT_CLEAN_TARGETS = "org.eclipse.ant.ui.ATTR_ANT_CLEAN_TARGETS"; //$NON-NLS-1$
73
74
	/**
75
	 * Boolean attribute indicating whether or not target specification for an
76
	 * Ant builder has been updated for 3.1
77
	 */
78
	public static final String ATTR_TARGETS_UPDATED = "org.eclipse.ant.ui.ATTR_TARGETS_UPDATED"; //$NON-NLS-1$
79
80
	/**
81
	 * Map attribute indicating the Ant properties to be defined during the
82
	 * build. Default value is <code>null</code> which indicates no additional
83
	 * properties will be defined.
84
	 */
85
	public static final String ATTR_ANT_PROPERTIES = IExternalToolConstants.UI_PLUGIN_ID + ".ATTR_ANT_PROPERTIES"; //$NON-NLS-1$					
86
87
	/**
88
	 * String attribute indicating the Ant targets to execute. Default value is
89
	 * <code>null</code> which indicates that no additional property files will
90
	 * be defined. Format is a comma separated listing of property files.
91
	 */
92
	public static final String ATTR_ANT_PROPERTY_FILES = IExternalToolConstants.UI_PLUGIN_ID + ".ATTR_ANT_PROPERTY_FILES"; //$NON-NLS-1$
93
94
	/**
95
	 * Boolean attribute indicating whether or not internal targets (targets
96
	 * with no description) should be hidden from the user in the launch
97
	 * configuration dialog. Default value is <code>false</code> which indicates
98
	 * that all targets will be displayed.
99
	 */
100
	public static final String ATTR_HIDE_INTERNAL_TARGETS = IExternalToolConstants.UI_PLUGIN_ID + ".ATTR_HIDE_INTERNAL_TARGETS"; //$NON-NLS-1$
101
102
	/**
103
	 * Integer attribute indicating which column targets should be sorted on. A
104
	 * value of 0 indicates target name, 1 indicates target description, and -1
105
	 * indicates no sort. Default value is -1.
106
	 */
107
	public static final String ATTR_SORT_TARGETS = IExternalToolConstants.UI_PLUGIN_ID + "ATTR_SORT_TARGETS"; //$NON-NLS-1$
108
109
	/**
110
	 * Boolean attribute indicating if the default VM install should be used for
111
	 * the separate JRE build Default value is <code>false</code> for backwards
112
	 * compatibility
113
	 */
114
	public static final String ATTR_DEFAULT_VM_INSTALL = "org.eclipse.ant.ui.DEFAULT_VM_INSTALL"; //$NON-NLS-1$
115
116
	/**
117
	 * Identifier for Ant processes (value
118
	 * <code>org.eclipse.ant.ui.antProcess</code>). This identifier is set as
119
	 * the value for the <code>IProcess.ATTR_PROCESS_TYPE</code> attribute in
120
	 * processes created by the Ant launch delegate.
121
	 */
122
	public static final String ID_ANT_PROCESS_TYPE = "org.eclipse.ant.ui.antProcess"; //$NON-NLS-1$
123
124
}
(-)src/org/eclipse/ant/launching/package.html (+13 lines)
Added Link Here
1
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
2
<html>
3
<head>
4
   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
5
   <title>Package-level Javadoc</title>
6
</head>
7
<body>
8
Provides support for Ant launching.
9
<h2>
10
Package Specification</h2>
11
This package defines constants for Ant launch configuration attributes. 
12
</body>
13
</html>
(-)Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java (-5 / +5 lines)
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.debug;
11
package org.eclipse.ant.tests.ui.debug;
12
12
13
import org.eclipse.ant.internal.ui.debug.model.AntDebugTarget;
13
import org.eclipse.ant.internal.launching.debug.model.AntDebugTarget;
14
import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint;
14
import org.eclipse.ant.internal.launching.debug.model.AntLineBreakpoint;
15
import org.eclipse.ant.internal.ui.debug.model.AntStackFrame;
15
import org.eclipse.ant.internal.launching.debug.model.AntStackFrame;
16
import org.eclipse.ant.internal.ui.debug.model.AntThread;
16
import org.eclipse.ant.internal.launching.debug.model.AntThread;
17
import org.eclipse.ant.tests.ui.AbstractAntUIBuildTest;
17
import org.eclipse.ant.tests.ui.AbstractAntUIBuildTest;
18
import org.eclipse.ant.tests.ui.testplugin.DebugElementKindEventWaiter;
18
import org.eclipse.ant.tests.ui.testplugin.DebugElementKindEventWaiter;
19
import org.eclipse.ant.tests.ui.testplugin.DebugEventWaiter;
19
import org.eclipse.ant.tests.ui.testplugin.DebugEventWaiter;
Lines 307-313 Link Here
307
	 */	
307
	 */	
308
	protected AntDebugTarget debugLaunchAndTerminate(ILaunchConfiguration config, int timeout) throws Exception {
308
	protected AntDebugTarget debugLaunchAndTerminate(ILaunchConfiguration config, int timeout) throws Exception {
309
		DebugEventWaiter waiter= new DebugElementKindEventWaiter(DebugEvent.TERMINATE, AntDebugTarget.class);
309
		DebugEventWaiter waiter= new DebugElementKindEventWaiter(DebugEvent.TERMINATE, AntDebugTarget.class);
310
		waiter.setTimeout(timeout);
310
		waiter.setTimeout(2000000000);
311
311
312
		Object terminatee = launchAndWait(config, waiter);		
312
		Object terminatee = launchAndWait(config, waiter);		
313
		assertNotNull("Program did not terminate.", terminatee);
313
		assertNotNull("Program did not terminate.", terminatee);
(-)Ant Debug Tests/org/eclipse/ant/tests/ui/debug/BreakpointTests.java (-5 / +5 lines)
Lines 13-21 Link Here
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.List;
14
import java.util.List;
15
15
16
import org.eclipse.ant.internal.ui.debug.model.AntDebugTarget;
16
import org.eclipse.ant.internal.launching.debug.model.AntDebugTarget;
17
import org.eclipse.ant.internal.ui.debug.model.AntThread;
17
import org.eclipse.ant.internal.launching.debug.model.AntThread;
18
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
18
import org.eclipse.ant.launching.IAntLaunchConstants;
19
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.debug.core.DebugException;
21
import org.eclipse.debug.core.DebugException;
Lines 116-122 Link Here
116
			}
116
			}
117
            ILaunchConfiguration config= getLaunchConfiguration(fileName);
117
            ILaunchConfiguration config= getLaunchConfiguration(fileName);
118
            ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
118
            ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
119
            copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, "entry1,entry2");
119
            copy.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, "entry1,entry2");
120
			thread= launchToLineBreakpoint(copy, bp);
120
			thread= launchToLineBreakpoint(copy, bp);
121
			bp.setEnabled(false);
121
			bp.setEnabled(false);
122
            if (sepVM) {
122
            if (sepVM) {
Lines 200-206 Link Here
200
			}
200
			}
201
			ILaunchConfiguration config= getLaunchConfiguration(fileName);
201
			ILaunchConfiguration config= getLaunchConfiguration(fileName);
202
			ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
202
			ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
203
			copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, defaultTargetName);
203
			copy.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, defaultTargetName);
204
            if (!sepVM) {
204
            if (!sepVM) {
205
                Thread.sleep(3000); //TODO bug 121207: wait for previous launch to fully terminate
205
                Thread.sleep(3000); //TODO bug 121207: wait for previous launch to fully terminate
206
            }
206
            }
(-)Ant Debug Tests/org/eclipse/ant/tests/ui/debug/PropertyTests.java (-8 / +8 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.debug;
11
package org.eclipse.ant.tests.ui.debug;
12
12
13
import org.eclipse.ant.internal.ui.debug.model.AntProperty;
13
import org.eclipse.ant.internal.launching.debug.model.AntProperty;
14
import org.eclipse.ant.internal.ui.debug.model.AntStackFrame;
14
import org.eclipse.ant.internal.launching.debug.model.AntStackFrame;
15
import org.eclipse.ant.internal.ui.debug.model.AntThread;
15
import org.eclipse.ant.internal.launching.debug.model.AntThread;
16
import org.eclipse.ant.internal.ui.debug.model.AntValue;
16
import org.eclipse.ant.internal.launching.debug.model.AntValue;
17
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
17
import org.eclipse.ant.launching.IAntLaunchConstants;
18
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.debug.core.DebugException;
19
import org.eclipse.debug.core.DebugException;
20
import org.eclipse.debug.core.ILaunchConfiguration;
20
import org.eclipse.debug.core.ILaunchConfiguration;
Lines 48-54 Link Here
48
			}
48
			}
49
			ILaunchConfiguration config= getLaunchConfiguration(fileName);
49
			ILaunchConfiguration config= getLaunchConfiguration(fileName);
50
			ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
50
			ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
51
			copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, "properties");
51
			copy.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, "properties");
52
			thread= launchToLineBreakpoint(copy, bp);
52
			thread= launchToLineBreakpoint(copy, bp);
53
53
54
			AntStackFrame frame = (AntStackFrame)thread.getTopStackFrame();
54
			AntStackFrame frame = (AntStackFrame)thread.getTopStackFrame();
Lines 82-88 Link Here
82
			}
82
			}
83
			ILaunchConfiguration config= getLaunchConfiguration(fileName);
83
			ILaunchConfiguration config= getLaunchConfiguration(fileName);
84
			ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
84
			ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
85
			copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, "properties");
85
			copy.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, "properties");
86
			thread= launchToLineBreakpoint(copy, bp);
86
			thread= launchToLineBreakpoint(copy, bp);
87
87
88
			AntStackFrame frame = (AntStackFrame)thread.getTopStackFrame();
88
			AntStackFrame frame = (AntStackFrame)thread.getTopStackFrame();
Lines 118-124 Link Here
118
			}
118
			}
119
			ILaunchConfiguration config= getLaunchConfiguration(fileName);
119
			ILaunchConfiguration config= getLaunchConfiguration(fileName);
120
			ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
120
			ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
121
			copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, "properties");
121
			copy.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, "properties");
122
			thread= launchToLineBreakpoint(copy, bp);
122
			thread= launchToLineBreakpoint(copy, bp);
123
123
124
			AntStackFrame frame = (AntStackFrame)thread.getTopStackFrame();
124
			AntStackFrame frame = (AntStackFrame)thread.getTopStackFrame();
(-)Ant Debug Tests/org/eclipse/ant/tests/ui/debug/RunToLineTests.java (-2 / +2 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.debug;
11
package org.eclipse.ant.tests.ui.debug;
12
12
13
import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint;
13
import org.eclipse.ant.internal.launching.debug.model.AntLineBreakpoint;
14
import org.eclipse.ant.internal.ui.debug.model.AntThread;
14
import org.eclipse.ant.internal.launching.debug.model.AntThread;
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.debug.core.DebugEvent;
16
import org.eclipse.debug.core.DebugEvent;
17
import org.eclipse.debug.core.model.IStackFrame;
17
import org.eclipse.debug.core.model.IStackFrame;
(-)Ant Debug Tests/org/eclipse/ant/tests/ui/debug/StackTests.java (-1 / +1 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.debug;
11
package org.eclipse.ant.tests.ui.debug;
12
12
13
import org.eclipse.ant.internal.ui.debug.model.AntThread;
13
import org.eclipse.ant.internal.launching.debug.model.AntThread;
14
import org.eclipse.core.resources.IFile;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.debug.core.model.ILineBreakpoint;
16
import org.eclipse.debug.core.model.ILineBreakpoint;
(-)Ant Debug Tests/org/eclipse/ant/tests/ui/debug/SteppingTests.java (-2 / +2 lines)
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.tests.ui.debug;
11
package org.eclipse.ant.tests.ui.debug;
12
12
13
import org.eclipse.ant.internal.ui.debug.model.AntStackFrame;
13
import org.eclipse.ant.internal.launching.debug.model.AntStackFrame;
14
import org.eclipse.ant.internal.ui.debug.model.AntThread;
14
import org.eclipse.ant.internal.launching.debug.model.AntThread;
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.debug.core.DebugEvent;
16
import org.eclipse.debug.core.DebugEvent;
17
import org.eclipse.debug.core.DebugException;
17
import org.eclipse.debug.core.DebugException;
(-)Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildTest.java (-1 / +1 lines)
Lines 81-87 Link Here
81
	 * @return thread in which the first suspend event occurred
81
	 * @return thread in which the first suspend event occurred
82
	 */
82
	 */
83
	protected void launch(ILaunchConfiguration config) throws CoreException {
83
	protected void launch(ILaunchConfiguration config) throws CoreException {
84
	    launchAndTerminate(config, 20000);
84
	    launchAndTerminate(config, 200000);
85
	}
85
	}
86
	
86
	
87
	protected void activateLink(final IHyperlink link) {
87
	protected void activateLink(final IHyperlink link) {
(-)Ant Tests/org/eclipse/ant/tests/ui/AntUtilTests.java (-4 / +4 lines)
Lines 16-27 Link Here
16
16
17
import org.eclipse.ant.internal.ui.AntUtil;
17
import org.eclipse.ant.internal.ui.AntUtil;
18
import org.eclipse.ant.internal.ui.model.AntTargetNode;
18
import org.eclipse.ant.internal.ui.model.AntTargetNode;
19
import org.eclipse.ant.launching.IAntLaunchConstants;
19
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
20
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
20
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
21
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.debug.core.ILaunchConfiguration;
23
import org.eclipse.debug.core.ILaunchConfiguration;
23
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
24
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
24
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
25
25
26
public class AntUtilTests extends AbstractAntUITest {
26
public class AntUtilTests extends AbstractAntUITest {
27
27
Lines 101-110 Link Here
101
		    copy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, arguments);
101
		    copy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, arguments);
102
		}
102
		}
103
		if (properties != null) {
103
		if (properties != null) {
104
		    copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, properties);
104
		    copy.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, properties);
105
		}
105
		}
106
		if (propertyFiles != null) {
106
		if (propertyFiles != null) {
107
		    copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, propertyFiles);
107
		    copy.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTY_FILES, propertyFiles);
108
		}
108
		}
109
		return copy;
109
		return copy;
110
    }
110
    }
(-)Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java (-4 / +4 lines)
Lines 18-25 Link Here
18
18
19
import org.eclipse.ant.internal.ui.AntUIPlugin;
19
import org.eclipse.ant.internal.ui.AntUIPlugin;
20
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
20
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
21
import org.eclipse.ant.launching.IAntLaunchConstants;
21
import org.eclipse.ant.tests.ui.testplugin.ConsoleLineTracker;
22
import org.eclipse.ant.tests.ui.testplugin.ConsoleLineTracker;
22
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
23
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.debug.core.ILaunchConfiguration;
25
import org.eclipse.debug.core.ILaunchConfiguration;
Lines 41-47 Link Here
41
   */
41
   */
42
  public void testOutput() throws CoreException {
42
  public void testOutput() throws CoreException {
43
	  launch("echoing");
43
	  launch("echoing");
44
	  assertTrue("Incorrect number of messages logged for build. Should be 8. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 8);
44
	  assertTrue("Incorrect number of messages logged for build. Should be 8. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 8); 
45
	  String message= ConsoleLineTracker.getMessage(6);
45
	  String message= ConsoleLineTracker.getMessage(6);
46
	  assertTrue("Incorrect last message. Should start with Total time:. Message: " + message, message.startsWith("Total time:"));
46
	  assertTrue("Incorrect last message. Should start with Total time:. Message: " + message, message.startsWith("Total time:"));
47
  }
47
  }
Lines 143-150 Link Here
143
		ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
143
		ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
144
		Map properties= new HashMap(1);
144
		Map properties= new HashMap(1);
145
		properties.put("platform.location", "${workspace_loc}");
145
		properties.put("platform.location", "${workspace_loc}");
146
		copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, properties);
146
		copy.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, properties);
147
		copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, properties);
147
		copy.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, properties);
148
		launchAndTerminate(copy, 20000);
148
		launchAndTerminate(copy, 20000);
149
		ConsoleLineTracker.waitForConsole();
149
		ConsoleLineTracker.waitForConsole();
150
		assertTrue("Incorrect number of messages logged for build. Should be 8. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 8);
150
		assertTrue("Incorrect number of messages logged for build. Should be 8. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 8);
(-)Ant Tests/org/eclipse/ant/tests/ui/performance/OpenLaunchConfigurationDialogTests.java (-1 / +1 lines)
Lines 14-19 Link Here
14
import org.eclipse.ant.internal.ui.IAntUIConstants;
14
import org.eclipse.ant.internal.ui.IAntUIConstants;
15
import org.eclipse.ant.tests.ui.editor.performance.EditorTestHelper;
15
import org.eclipse.ant.tests.ui.editor.performance.EditorTestHelper;
16
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
16
import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest;
17
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.Status;
Lines 26-32 Link Here
26
import org.eclipse.jface.viewers.StructuredSelection;
27
import org.eclipse.jface.viewers.StructuredSelection;
27
import org.eclipse.test.performance.Dimension;
28
import org.eclipse.test.performance.Dimension;
28
import org.eclipse.test.performance.PerformanceTestCase;
29
import org.eclipse.test.performance.PerformanceTestCase;
29
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
30
30
31
public class OpenLaunchConfigurationDialogTests extends PerformanceTestCase {
31
public class OpenLaunchConfigurationDialogTests extends PerformanceTestCase {
32
32
(-)Ant Tests/org/eclipse/ant/tests/ui/performance/SeparateVMTests.java (-1 / +1 lines)
Lines 15-26 Link Here
15
import junit.framework.TestSuite;
15
import junit.framework.TestSuite;
16
16
17
import org.eclipse.ant.tests.ui.AbstractAntUIBuildPerformanceTest;
17
import org.eclipse.ant.tests.ui.AbstractAntUIBuildPerformanceTest;
18
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.debug.core.DebugPlugin;
20
import org.eclipse.debug.core.DebugPlugin;
20
import org.eclipse.debug.core.ILaunchConfiguration;
21
import org.eclipse.debug.core.ILaunchConfiguration;
21
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
22
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
22
import org.eclipse.debug.ui.IDebugUIConstants;
23
import org.eclipse.debug.ui.IDebugUIConstants;
23
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
24
24
25
public class SeparateVMTests extends AbstractAntUIBuildPerformanceTest {
25
public class SeparateVMTests extends AbstractAntUIBuildPerformanceTest {
26
		
26
		
(-)Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java (-3 / +3 lines)
Lines 21-30 Link Here
21
21
22
import org.eclipse.ant.internal.ui.AntUIPlugin;
22
import org.eclipse.ant.internal.ui.AntUIPlugin;
23
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
23
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
24
import org.eclipse.ant.launching.IAntLaunchConstants;
24
import org.eclipse.ant.tests.ui.AbstractAntUIBuildTest;
25
import org.eclipse.ant.tests.ui.AbstractAntUIBuildTest;
25
import org.eclipse.ant.tests.ui.testplugin.ConsoleLineTracker;
26
import org.eclipse.ant.tests.ui.testplugin.ConsoleLineTracker;
26
import org.eclipse.ant.tests.ui.testplugin.ProjectHelper;
27
import org.eclipse.ant.tests.ui.testplugin.ProjectHelper;
27
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
28
import org.eclipse.core.resources.IFile;
28
import org.eclipse.core.resources.IFile;
29
import org.eclipse.core.resources.IResource;
29
import org.eclipse.core.resources.IResource;
30
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.CoreException;
Lines 158-164 Link Here
158
		assertNotNull("Could not locate launch configuration for " + "echoingSepVM", config);
158
		assertNotNull("Could not locate launch configuration for " + "echoingSepVM", config);
159
		ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
159
		ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
160
		copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, getJavaProject().getProject().getLocation().toOSString());
160
		copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, getJavaProject().getProject().getLocation().toOSString());
161
		copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, "Bug42984");
161
		copy.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, "Bug42984");
162
		launchAndTerminate(copy, 20000);
162
		launchAndTerminate(copy, 20000);
163
		ConsoleLineTracker.waitForConsole();
163
		ConsoleLineTracker.waitForConsole();
164
		assertTrue("Incorrect number of messages logged for build. Should be 6. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 6);
164
		assertTrue("Incorrect number of messages logged for build. Should be 6. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 6);
Lines 175-181 Link Here
175
		ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
175
		ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
176
		Map properties= new HashMap(1);
176
		Map properties= new HashMap(1);
177
		properties.put("platform.location", "${workspace_loc}");
177
		properties.put("platform.location", "${workspace_loc}");
178
		copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, properties);
178
		copy.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, properties);
179
		launchAndTerminate(copy, 20000);
179
		launchAndTerminate(copy, 20000);
180
		ConsoleLineTracker.waitForConsole();
180
		ConsoleLineTracker.waitForConsole();
181
		assertTrue("Incorrect number of messages logged for build. Should be 6. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 6);
181
		assertTrue("Incorrect number of messages logged for build. Should be 6. Was " + ConsoleLineTracker.getNumberOfMessages(), ConsoleLineTracker.getNumberOfMessages() == 6);
(-)External Tools/org/eclipse/ant/tests/ui/externaltools/MigrationTests.java (-7 / +7 lines)
Lines 15-28 Link Here
15
15
16
import junit.framework.TestCase;
16
import junit.framework.TestCase;
17
17
18
import org.eclipse.ant.internal.ui.AntUtil;
18
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
19
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
19
import org.eclipse.ant.launching.IAntLaunchConstants;
20
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.debug.core.DebugPlugin;
22
import org.eclipse.debug.core.DebugPlugin;
22
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
23
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
23
import org.eclipse.debug.ui.IDebugUIConstants;
24
import org.eclipse.debug.ui.IDebugUIConstants;
24
import org.eclipse.debug.ui.RefreshTab;
25
import org.eclipse.debug.ui.RefreshTab;
25
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
26
import org.eclipse.ui.externaltools.internal.registry.ExternalToolMigration;
26
import org.eclipse.ui.externaltools.internal.registry.ExternalToolMigration;
27
27
28
/**
28
/**
Lines 42-52 Link Here
42
		ILaunchConfigurationWorkingCopy config = ExternalToolMigration.configFromArgumentMap(argumentMap);
42
		ILaunchConfigurationWorkingCopy config = ExternalToolMigration.configFromArgumentMap(argumentMap);
43
		assertNotNull("Migration failed", config);
43
		assertNotNull("Migration failed", config);
44
		
44
		
45
		assertEquals("Wrong configuration type", IAntLaunchConfigurationConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE, config.getType().getIdentifier());
45
		assertEquals("Wrong configuration type", IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE, config.getType().getIdentifier());
46
		assertEquals("ant tool", config.getName());
46
		assertEquals("ant tool", config.getName());
47
		assertEquals("location", config.getAttribute(IExternalToolConstants.ATTR_LOCATION, ""));
47
		assertEquals("location", config.getAttribute(IExternalToolConstants.ATTR_LOCATION, ""));
48
		assertEquals("refresh scope", config.getAttribute(RefreshTab.ATTR_REFRESH_SCOPE, ""));
48
		assertEquals("refresh scope", config.getAttribute(RefreshTab.ATTR_REFRESH_SCOPE, ""));
49
		String[] targets= AntUtil.getTargetNames(config);
49
		String[] targets= AntLaunchingUtil.getTargetNames(config);
50
		assertNotNull("No targets found", targets);
50
		assertNotNull("No targets found", targets);
51
		assertEquals("Wrong number of targets", 2, targets.length);
51
		assertEquals("Wrong number of targets", 2, targets.length);
52
		assertEquals("target1", targets[0]);
52
		assertEquals("target1", targets[0]);
Lines 131-137 Link Here
131
		ILaunchConfigurationWorkingCopy config = ExternalToolMigration.configFromArgumentMap(argumentMap);
131
		ILaunchConfigurationWorkingCopy config = ExternalToolMigration.configFromArgumentMap(argumentMap);
132
		assertNotNull("Migration failed", config);
132
		assertNotNull("Migration failed", config);
133
		
133
		
134
		assertEquals("Wrong config type", IAntLaunchConfigurationConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE, config.getType().getIdentifier());
134
		assertEquals("Wrong config type", IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE, config.getType().getIdentifier());
135
		assertEquals("ant config", config.getName());
135
		assertEquals("ant config", config.getName());
136
		assertEquals("location", config.getAttribute(IExternalToolConstants.ATTR_LOCATION, ""));
136
		assertEquals("location", config.getAttribute(IExternalToolConstants.ATTR_LOCATION, ""));
137
		assertEquals("working directory", config.getAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, ""));
137
		assertEquals("working directory", config.getAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, ""));
Lines 143-149 Link Here
143
		assertEquals(true, config.getAttribute(RefreshTab.ATTR_REFRESH_RECURSIVE, false));
143
		assertEquals(true, config.getAttribute(RefreshTab.ATTR_REFRESH_RECURSIVE, false));
144
		assertEquals("build kinds", config.getAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, ""));
144
		assertEquals("build kinds", config.getAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, ""));
145
		assertEquals("arg1 arg2", config.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, ""));
145
		assertEquals("arg1 arg2", config.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, ""));
146
		String[] targets= AntUtil.getTargetNames(config);
146
		String[] targets= AntLaunchingUtil.getTargetNames(config);
147
		assertEquals("Wrong number of targets", 2, targets.length);
147
		assertEquals("Wrong number of targets", 2, targets.length);
148
		assertEquals("target1", targets[0]);
148
		assertEquals("target1", targets[0]);
149
		assertEquals("target2", targets[1]);
149
		assertEquals("target2", targets[1]);
(-)META-INF/MANIFEST.MF (-1 / +3 lines)
Lines 35-39 Link Here
35
 org.eclipse.ant.ui,
35
 org.eclipse.ant.ui,
36
 org.eclipse.core.runtime,
36
 org.eclipse.core.runtime,
37
 org.eclipse.test.performance,
37
 org.eclipse.test.performance,
38
 org.eclipse.ui.console
38
 org.eclipse.ui.console,
39
 org.eclipse.ant.launching;bundle-version="1.0.0",
40
 org.eclipse.core.externaltools;bundle-version="1.0.0"
39
Bundle-ActivationPolicy: lazy
41
Bundle-ActivationPolicy: lazy
(-)test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java (-3 / +3 lines)
Lines 30-35 Link Here
30
import org.eclipse.ant.internal.ui.model.AntModel;
30
import org.eclipse.ant.internal.ui.model.AntModel;
31
import org.eclipse.ant.tests.ui.editor.support.TestLocationProvider;
31
import org.eclipse.ant.tests.ui.editor.support.TestLocationProvider;
32
import org.eclipse.ant.tests.ui.editor.support.TestProblemRequestor;
32
import org.eclipse.ant.tests.ui.editor.support.TestProblemRequestor;
33
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
33
import org.eclipse.core.resources.IFile;
34
import org.eclipse.core.resources.IFile;
34
import org.eclipse.core.resources.IFolder;
35
import org.eclipse.core.resources.IFolder;
35
import org.eclipse.core.resources.IProject;
36
import org.eclipse.core.resources.IProject;
Lines 53-59 Link Here
53
import org.eclipse.jface.text.Position;
54
import org.eclipse.jface.text.Position;
54
import org.eclipse.swt.graphics.Color;
55
import org.eclipse.swt.graphics.Color;
55
import org.eclipse.ui.console.IHyperlink;
56
import org.eclipse.ui.console.IHyperlink;
56
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
57
import org.eclipse.ui.internal.console.ConsoleHyperlinkPosition;
57
import org.eclipse.ui.internal.console.ConsoleHyperlinkPosition;
58
import org.eclipse.ui.internal.console.IOConsolePartition;
58
import org.eclipse.ui.internal.console.IOConsolePartition;
59
import org.xml.sax.InputSource;
59
import org.xml.sax.InputSource;
Lines 274-280 Link Here
274
    protected void launch(String buildFileName) throws CoreException {
274
    protected void launch(String buildFileName) throws CoreException {
275
        ILaunchConfiguration config = getLaunchConfiguration(buildFileName);
275
        ILaunchConfiguration config = getLaunchConfiguration(buildFileName);
276
        assertNotNull("Could not locate launch configuration for " + buildFileName, config);
276
        assertNotNull("Could not locate launch configuration for " + buildFileName, config);
277
        launchAndTerminate(config, 20000);
277
        launchAndTerminate(config, 2000000);
278
    }
278
    }
279
    
279
    
280
    /**
280
    /**
Lines 393-399 Link Here
393
     */
393
     */
394
    protected void launchAndTerminate(ILaunchConfiguration config, int timeout) throws CoreException {
394
    protected void launchAndTerminate(ILaunchConfiguration config, int timeout) throws CoreException {
395
        DebugEventWaiter waiter= new DebugElementKindEventWaiter(DebugEvent.TERMINATE, IProcess.class);
395
        DebugEventWaiter waiter= new DebugElementKindEventWaiter(DebugEvent.TERMINATE, IProcess.class);
396
        waiter.setTimeout(timeout);
396
        waiter.setTimeout(40000);
397
397
398
        Object terminatee = launchAndWait(config, waiter);      
398
        Object terminatee = launchAndWait(config, waiter);      
399
        assertNotNull("Program did not terminate.", terminatee);
399
        assertNotNull("Program did not terminate.", terminatee);
(-)test plugin/org/eclipse/ant/tests/ui/testplugin/ProjectHelper.java (-5 / +5 lines)
Lines 19-25 Link Here
19
import java.util.List;
19
import java.util.List;
20
20
21
import org.eclipse.ant.internal.ui.IAntUIConstants;
21
import org.eclipse.ant.internal.ui.IAntUIConstants;
22
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
22
import org.eclipse.ant.launching.IAntLaunchConstants;
23
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
23
import org.eclipse.core.resources.IFolder;
24
import org.eclipse.core.resources.IFolder;
24
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.resources.IProject;
25
import org.eclipse.core.resources.IProjectDescription;
26
import org.eclipse.core.resources.IProjectDescription;
Lines 40-46 Link Here
40
import org.eclipse.jdt.launching.IVMInstall;
41
import org.eclipse.jdt.launching.IVMInstall;
41
import org.eclipse.jdt.launching.JavaRuntime;
42
import org.eclipse.jdt.launching.JavaRuntime;
42
import org.eclipse.ui.dialogs.IOverwriteQuery;
43
import org.eclipse.ui.dialogs.IOverwriteQuery;
43
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
44
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
44
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
45
import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
45
import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider;
46
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
46
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
Lines 167-176 Link Here
167
	 */
167
	 */
168
	public static void createLaunchConfigurationForSeparateVM(String launchConfigName, String buildFileName) throws Exception {
168
	public static void createLaunchConfigurationForSeparateVM(String launchConfigName, String buildFileName) throws Exception {
169
		String bf = buildFileName;
169
		String bf = buildFileName;
170
		ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConfigurationConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
170
		ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
171
		ILaunchConfigurationWorkingCopy config = type.newInstance(AbstractAntUITest.getJavaProject().getProject().getFolder("launchConfigurations"), launchConfigName);
171
		ILaunchConfigurationWorkingCopy config = type.newInstance(AbstractAntUITest.getJavaProject().getProject().getFolder("launchConfigurations"), launchConfigName);
172
		
172
		
173
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.eclipse.ant.internal.ui.antsupport.InternalAntRunner"); //$NON-NLS-1$
173
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.eclipse.ant.internal.launching.remote.InternalAntRunner"); //$NON-NLS-1$
174
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); //$NON-NLS-1$
174
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); //$NON-NLS-1$
175
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, AbstractAntUITest.getJavaProject().getElementName());
175
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, AbstractAntUITest.getJavaProject().getElementName());
176
		if (bf == null) {
176
		if (bf == null) {
Lines 216-222 Link Here
216
	 * @throws CoreException
216
	 * @throws CoreException
217
	 */
217
	 */
218
	public static ILaunchConfiguration createLaunchConfiguration(String launchConfigName, String path) throws CoreException {
218
	public static ILaunchConfiguration createLaunchConfiguration(String launchConfigName, String path) throws CoreException {
219
	    ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConfigurationConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
219
	    ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
220
		ILaunchConfigurationWorkingCopy config = type.newInstance(AbstractAntUITest.getJavaProject().getProject().getFolder("launchConfigurations"), launchConfigName);
220
		ILaunchConfigurationWorkingCopy config = type.newInstance(AbstractAntUITest.getJavaProject().getProject().getFolder("launchConfigurations"), launchConfigName);
221
	
221
	
222
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, AbstractAntUITest.getJavaProject().getElementName());
222
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, AbstractAntUITest.getJavaProject().getElementName());
(-).classpath (-3 / +2 lines)
Lines 1-10 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
2
<classpath>
3
	<classpathentry kind="src" path="Ant Tools Support"/>
3
	<classpathentry kind="src" path="Ant Tools Support"/>
4
	<classpathentry output="ant_runner_support_bin" kind="src" path="Ant Runner Support"/>
4
	<classpathentry kind="src" output="ant_runner_support_bin" path="Ant Runner Support"/>
5
	<classpathentry kind="src" path="Ant Editor"/>
5
	<classpathentry kind="src" path="Ant Editor"/>
6
	<classpathentry output="remote_support_bin" kind="src" path="Remote Ant Support"/>
6
	<classpathentry kind="src" output="remote_support_bin" path="Remote Ant Support"/>
7
	<classpathentry output="common_ant_support_bin" kind="src" path="Common Ant Support"/>
8
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
7
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
9
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
8
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
10
	<classpathentry kind="output" path="bin"/>
9
	<classpathentry kind="output" path="bin"/>
(-)Ant Editor/org/eclipse/ant/internal/ui/editor/actions/RunToLineAdapter.java (-4 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-22 Link Here
13
import java.util.HashMap;
13
import java.util.HashMap;
14
import java.util.Map;
14
import java.util.Map;
15
15
16
import org.eclipse.ant.internal.launching.debug.IAntDebugConstants;
17
import org.eclipse.ant.internal.launching.debug.model.AntDebugElement;
18
import org.eclipse.ant.internal.launching.debug.model.AntLineBreakpoint;
16
import org.eclipse.ant.internal.ui.AntUIPlugin;
19
import org.eclipse.ant.internal.ui.AntUIPlugin;
17
import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
18
import org.eclipse.ant.internal.ui.debug.model.AntDebugElement;
19
import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint;
20
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IMarker;
21
import org.eclipse.core.resources.IMarker;
22
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
(-)Ant Editor/org/eclipse/ant/internal/ui/editor/actions/ToggleLineBreakpointAction.java (-3 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.editor.actions;
11
package org.eclipse.ant.internal.ui.editor.actions;
12
12
13
import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
13
import org.eclipse.ant.internal.launching.debug.IAntDebugConstants;
14
import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint;
14
import org.eclipse.ant.internal.launching.debug.model.AntLineBreakpoint;
15
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.debug.core.DebugPlugin;
17
import org.eclipse.debug.core.DebugPlugin;
(-)Ant Editor/org/eclipse/ant/internal/ui/editor/text/AntAnnotationModel.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-21 Link Here
14
import java.util.Iterator;
14
import java.util.Iterator;
15
import java.util.List;
15
import java.util.List;
16
16
17
import org.eclipse.ant.internal.launching.debug.IAntDebugConstants;
17
import org.eclipse.ant.internal.ui.AntUIPlugin;
18
import org.eclipse.ant.internal.ui.AntUIPlugin;
18
import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
19
import org.eclipse.ant.internal.ui.editor.outline.AntEditorMarkerUpdater;
19
import org.eclipse.ant.internal.ui.editor.outline.AntEditorMarkerUpdater;
20
import org.eclipse.ant.internal.ui.model.IProblem;
20
import org.eclipse.ant.internal.ui.model.IProblem;
21
import org.eclipse.ant.internal.ui.model.IProblemRequestor;
21
import org.eclipse.ant.internal.ui.model.IProblemRequestor;
(-)Ant Editor/org/eclipse/ant/internal/ui/editor/text/XMLTextHover.java (-13 / +6 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 18-40 Link Here
18
import org.apache.tools.ant.types.AbstractFileSet;
18
import org.apache.tools.ant.types.AbstractFileSet;
19
import org.apache.tools.ant.types.Path;
19
import org.apache.tools.ant.types.Path;
20
import org.apache.tools.ant.types.PatternSet;
20
import org.apache.tools.ant.types.PatternSet;
21
21
import org.eclipse.ant.internal.launching.debug.model.AntProperty;
22
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.ant.internal.launching.debug.model.AntStackFrame;
23
23
import org.eclipse.ant.internal.launching.debug.model.AntValue;
24
import org.eclipse.ant.internal.ui.debug.model.AntProperty;
25
import org.eclipse.ant.internal.ui.debug.model.AntStackFrame;
26
import org.eclipse.ant.internal.ui.debug.model.AntValue;
27
import org.eclipse.ant.internal.ui.editor.AntEditor;
24
import org.eclipse.ant.internal.ui.editor.AntEditor;
28
import org.eclipse.ant.internal.ui.editor.AntEditorSourceViewerConfiguration;
25
import org.eclipse.ant.internal.ui.editor.AntEditorSourceViewerConfiguration;
29
import org.eclipse.ant.internal.ui.model.AntElementNode;
26
import org.eclipse.ant.internal.ui.model.AntElementNode;
30
import org.eclipse.ant.internal.ui.model.AntModel;
27
import org.eclipse.ant.internal.ui.model.AntModel;
31
import org.eclipse.ant.internal.ui.model.AntPropertyNode;
28
import org.eclipse.ant.internal.ui.model.AntPropertyNode;
32
import org.eclipse.ant.internal.ui.model.IAntModel;
29
import org.eclipse.ant.internal.ui.model.IAntModel;
33
34
import org.eclipse.core.runtime.IAdaptable;
30
import org.eclipse.core.runtime.IAdaptable;
35
31
import org.eclipse.debug.ui.DebugUITools;
36
import org.eclipse.jface.internal.text.html.HTMLPrinter;
32
import org.eclipse.jface.internal.text.html.HTMLPrinter;
37
38
import org.eclipse.jface.text.BadLocationException;
33
import org.eclipse.jface.text.BadLocationException;
39
import org.eclipse.jface.text.DefaultInformationControl;
34
import org.eclipse.jface.text.DefaultInformationControl;
40
import org.eclipse.jface.text.IDocument;
35
import org.eclipse.jface.text.IDocument;
Lines 50-60 Link Here
50
import org.eclipse.jface.text.source.Annotation;
45
import org.eclipse.jface.text.source.Annotation;
51
import org.eclipse.jface.text.source.IAnnotationModel;
46
import org.eclipse.jface.text.source.IAnnotationModel;
52
import org.eclipse.jface.text.source.ISourceViewer;
47
import org.eclipse.jface.text.source.ISourceViewer;
53
48
import org.eclipse.swt.widgets.Shell;
54
import org.eclipse.ui.editors.text.EditorsUI;
49
import org.eclipse.ui.editors.text.EditorsUI;
55
50
56
import org.eclipse.debug.ui.DebugUITools;
57
58
51
59
public class XMLTextHover implements ITextHover, ITextHoverExtension, IInformationProviderExtension2 {
52
public class XMLTextHover implements ITextHover, ITextHoverExtension, IInformationProviderExtension2 {
60
53
(-)Ant Runner Support/org/eclipse/ant/internal/ui/antsupport/AntSupportMessages.java (-11 / +1 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others. All rights reserved. This
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
5
 * available at http://www.eclipse.org/legal/epl-v10.html
Lines 19-34 Link Here
19
	public static String AntInputHandler_Unable_to_respond_to__input__request_4;
19
	public static String AntInputHandler_Unable_to_respond_to__input__request_4;
20
	public static String AntInputHandler_5;
20
	public static String AntInputHandler_5;
21
21
22
	public static String NullBuildLogger_1;
23
	public static String AntProcessBuildLogger_Total_time;
24
	public static String AntProcessBuildLogger__minutes_2;
25
	public static String AntProcessBuildLogger__minute_3;
26
	public static String AntProcessBuildLogger__seconds_4;
27
	public static String AntProcessBuildLogger__second_5;
28
	public static String AntProcessBuildLogger__milliseconds_6;
29
	
30
	public static String AntProcessDebugBuildLogger_1;
31
32
	static {
22
	static {
33
		// load message values from bundle file
23
		// load message values from bundle file
34
		NLS.initializeMessages(BUNDLE_NAME, AntSupportMessages.class);
24
		NLS.initializeMessages(BUNDLE_NAME, AntSupportMessages.class);
(-)Ant Runner Support/org/eclipse/ant/internal/ui/antsupport/AntSupportMessages.properties (-11 / +1 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2005 IBM Corporation and others.
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 13-25 Link Here
13
AntInputHandler_Invalid_input_2=Input does not match validargs attribute
13
AntInputHandler_Invalid_input_2=Input does not match validargs attribute
14
AntInputHandler_Unable_to_respond_to__input__request_4=Unable to respond to <input> request
14
AntInputHandler_Unable_to_respond_to__input__request_4=Unable to respond to <input> request
15
AntInputHandler_5=Unable to respond to input request as a result of the user specified -noinput command
15
AntInputHandler_5=Unable to respond to input request as a result of the user specified -noinput command
16
17
NullBuildLogger_1=BUILD FAILED
18
AntProcessBuildLogger_Total_time=Total time: 
19
AntProcessBuildLogger__minutes_2=\ minutes
20
AntProcessBuildLogger__minute_3=\ minute
21
AntProcessBuildLogger__seconds_4=\ seconds
22
AntProcessBuildLogger__second_5=\ second
23
AntProcessBuildLogger__milliseconds_6=\ milliseconds
24
25
AntProcessDebugBuildLogger_1=Build cancelled.
(-)Ant Runner Support/org/eclipse/ant/internal/ui/antsupport/logger/AntProcessBuildLogger.java (-350 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Matt Conway - Patch for Bug 28052
11
 *******************************************************************************/
12
13
package org.eclipse.ant.internal.ui.antsupport.logger;
14
15
import java.io.BufferedReader;
16
import java.io.File;
17
import java.io.IOException;
18
import java.io.StringReader;
19
import java.util.HashMap;
20
import java.util.Map;
21
22
import org.apache.tools.ant.BuildEvent;
23
import org.apache.tools.ant.Location;
24
import org.apache.tools.ant.Project;
25
import org.apache.tools.ant.Target;
26
import org.apache.tools.ant.util.FileUtils;
27
import org.eclipse.ant.internal.core.AbstractEclipseBuildLogger;
28
import org.eclipse.ant.internal.ui.AntUtil;
29
import org.eclipse.ant.internal.ui.ExternalHyperlink;
30
import org.eclipse.ant.internal.ui.IAntUIConstants;
31
import org.eclipse.ant.internal.ui.antsupport.AntSupportMessages;
32
import org.eclipse.ant.internal.ui.antsupport.logger.util.AntDebugState;
33
import org.eclipse.ant.internal.ui.launchConfigurations.AntProcess;
34
import org.eclipse.ant.internal.ui.launchConfigurations.AntStreamMonitor;
35
import org.eclipse.ant.internal.ui.launchConfigurations.AntStreamsProxy;
36
import org.eclipse.ant.internal.ui.launchConfigurations.TaskLinkManager;
37
import org.eclipse.core.resources.IFile;
38
import org.eclipse.core.runtime.OperationCanceledException;
39
import org.eclipse.debug.core.DebugPlugin;
40
import org.eclipse.debug.core.model.IProcess;
41
import org.eclipse.debug.ui.console.FileLink;
42
import org.eclipse.jface.text.IRegion;
43
import org.eclipse.jface.text.Region;
44
import org.eclipse.ui.console.IHyperlink;
45
	
46
public class AntProcessBuildLogger extends NullBuildLogger {
47
	
48
	private File fBuildFileParent= null;
49
	private long fStartTime;
50
    private Map fFileNameToIFile= new HashMap();
51
52
	/**
53
	 * Associated process - discovered as needed to log messages
54
	 */
55
	private AntProcess fProcess = null;
56
	
57
	protected void logMessage(String message, BuildEvent event, int overridePriority) {
58
		int priority= overridePriority;
59
		if (priority == -1) {
60
			priority= event.getPriority();
61
		} 
62
		
63
		if (priority > getMessageOutputLevel()) {
64
			return;
65
		}
66
		AntProcess antProcess = getAntProcess(fProcessId);
67
		if (antProcess == null) {
68
			return;
69
		}
70
		
71
		StringBuffer fullMessage= new StringBuffer();
72
		 if (!loggingToLogFile()) {
73
			fullMessage.append(System.getProperty("line.separator")); //$NON-NLS-1$
74
		}
75
		if (event.getException() == null && event.getTask() != null && !fEmacsMode) {
76
			adornMessage(event, fullMessage);
77
		} else {
78
			fullMessage.append(message);
79
		}
80
		message= fullMessage.toString();
81
		
82
		if (loggingToLogFile()) {
83
			logMessageToLogFile(message, priority);
84
		} else {
85
			AntStreamMonitor monitor = getMonitor(priority);
86
			monitor.append(message);
87
		}
88
	}
89
90
	/**
91
	 * Builds a right justified task prefix for the given build event, placing it
92
	 * in the given string buffer. Creates the hyperlinks for the task prefix. 
93
	 *  
94
	 * @param event build event
95
	 * @param fullMessage buffer to place task prefix in
96
	 */
97
	private void adornMessage(BuildEvent event, StringBuffer fullMessage) {
98
		String name = event.getTask().getTaskName();
99
		if (name == null) {
100
			name = "null"; //$NON-NLS-1$
101
		}
102
		Location location = event.getTask().getLocation();
103
		StringBuffer column= new StringBuffer();
104
		int size = IAntUIConstants.LEFT_COLUMN_SIZE - (name.length() + 3);
105
		for (int i = 0; i < size; i++) {
106
			column.append(' ');
107
		}
108
		StringBuffer labelBuff= new StringBuffer();
109
		labelBuff.append('[');
110
		labelBuff.append(name);
111
		labelBuff.append("] "); //$NON-NLS-1$
112
		
113
		int offset = Math.max(size, 0) + 1;
114
		String label= labelBuff.toString();
115
		if (event.getMessage() == null) {
116
			return;
117
		}
118
		try {
119
			BufferedReader r = new BufferedReader(new StringReader(event.getMessage()));
120
			String line = r.readLine();
121
			fullMessage.append(column);
122
			appendAndLink(fullMessage, location, label, offset, line);
123
			line = r.readLine();
124
			while (line != null) {
125
				fullMessage.append(System.getProperty("line.separator")); //$NON-NLS-1$
126
				fullMessage.append(column);
127
				appendAndLink(fullMessage, location, label, offset, line);
128
				line = r.readLine();
129
			}
130
		} catch (IOException e) {
131
			if (event.getMessage() != null) {
132
				fullMessage.append(label).append(event.getMessage());
133
			}
134
		}
135
	}
136
	
137
	private void appendAndLink(StringBuffer fullMessage, Location location, String label, int offset, String line) {
138
		fullMessage.append(label);
139
		fullMessage.append(line);
140
		if (location != null) {
141
			String newLine= (label + line).trim();
142
			IRegion region= new Region(offset, label.length() - 3); // only want the name length "[name] "
143
			IHyperlink link= getLocationLink(location);
144
			if (link != null) {
145
				TaskLinkManager.addTaskHyperlink(getAntProcess(fProcessId), link, region, newLine);
146
			}
147
		}
148
	}
149
150
	private AntStreamMonitor getMonitor(int priority) {
151
		AntStreamsProxy proxy = (AntStreamsProxy)fProcess.getStreamsProxy();
152
		AntStreamMonitor monitor = null;
153
		switch (priority) {
154
			case Project.MSG_INFO:
155
				monitor = (AntStreamMonitor)proxy.getOutputStreamMonitor();
156
				break;
157
			case Project.MSG_ERR:
158
				monitor = (AntStreamMonitor)proxy.getErrorStreamMonitor();
159
				break;
160
			case Project.MSG_DEBUG:
161
				monitor = (AntStreamMonitor)proxy.getDebugStreamMonitor();
162
				break;
163
			case Project.MSG_WARN:
164
				monitor = (AntStreamMonitor)proxy.getWarningStreamMonitor();
165
				break;
166
			case Project.MSG_VERBOSE:
167
				monitor = (AntStreamMonitor)proxy.getVerboseStreamMonitor();
168
				break;
169
		}
170
		return monitor;
171
	}
172
173
	private void logMessageToLogFile(String message, int priority) {
174
		if (priority == Project.MSG_ERR) {
175
			getErrorPrintStream().println(message);
176
		} else {
177
			getOutputPrintStream().println(message);
178
		}
179
	}
180
	
181
	/**
182
	 * Returns a hyperlink for the given task, or <code>null</code> if unable to
183
	 * parse a valid location for the task. The link is set to exist at the specified
184
	 * offset and length.
185
	 * 
186
	 * @return hyper link, or <code>null</code>
187
	 */
188
	private IHyperlink getLocationLink(Location location) {
189
		if (location != null && !location.equals(Location.UNKNOWN_LOCATION)) {
190
            try {
191
                String fileName= location.getFileName();
192
                IFile file= (IFile) fFileNameToIFile.get(fileName);
193
                int lineNumber= location.getLineNumber();
194
                if (file != null) {
195
                    return new FileLink(file, null, -1, -1, lineNumber);
196
                } 
197
                file= AntUtil.getFileForLocation(fileName, fBuildFileParent);
198
                if (file != null) {
199
                    fFileNameToIFile.put(fileName, file);
200
                    return new FileLink(file, null, -1, -1, lineNumber);
201
                }
202
                //maintain backwards compatibility
203
                File javaIOFile= FileUtils.newFileUtils().resolveFile(fBuildFileParent, fileName);
204
                if (javaIOFile.exists()) {
205
                    return new ExternalHyperlink(javaIOFile, lineNumber);
206
                }
207
            } catch (NoSuchMethodError e) {
208
                //support for Ant older than 1.6
209
                return AntUtil.getLocationLink(location.toString(), fBuildFileParent);
210
            }
211
		}
212
		return null;
213
	}	
214
	
215
	/**
216
	 * Returns the associated Ant process, finding it if necessary, if not
217
	 * already found.
218
	 */
219
	protected AntProcess getAntProcess(String processId) {
220
		if (fProcess == null && processId != null) {
221
			IProcess[] all = DebugPlugin.getDefault().getLaunchManager().getProcesses();
222
			for (int i = 0; i < all.length; i++) {
223
				IProcess process = all[i];
224
				if (process instanceof AntProcess && processId.equals(process.getAttribute(AbstractEclipseBuildLogger.ANT_PROCESS_ID))) {
225
					fProcess = (AntProcess)process;
226
					break;
227
				}
228
			}
229
		}
230
		return fProcess;
231
	}
232
233
	/* (non-Javadoc)
234
	 * Set the start time.
235
	 * 
236
	 * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
237
	 */
238
	public void buildStarted(BuildEvent event) {
239
		fStartTime= System.currentTimeMillis();
240
	}
241
	
242
	/* (non-Javadoc)
243
	 * @see org.apache.tools.ant.BuildListener#buildFinished(org.apache.tools.ant.BuildEvent)
244
	 */
245
	public void buildFinished(BuildEvent event) {
246
        String message= handleException(event);
247
        if (message != null) {
248
        	try {
249
    			BufferedReader r = new BufferedReader(new StringReader(message));
250
    			String line = r.readLine();
251
    			logMessage(line, event, Project.MSG_ERR);
252
    			line = r.readLine();
253
    			AntProcess antProcess = getAntProcess(fProcessId);
254
    			while (line != null) {
255
    				logMessage(line, event, Project.MSG_ERR);
256
    				if (!message.startsWith("Total time:")) { //$NON-NLS-1$
257
    					AntUtil.linkBuildFailedMessage(line, antProcess);
258
    				}
259
    				line = r.readLine();
260
    			}
261
    			logMessage("", event, Project.MSG_ERR); //$NON-NLS-1$
262
    		} catch (IOException e) {
263
    		}
264
        }
265
		fHandledException= null;
266
		fBuildFileParent= null;
267
		if (!(event.getException() instanceof OperationCanceledException)) {
268
			logMessage(getTimeString(System.currentTimeMillis() - fStartTime), event, fMessageOutputLevel);
269
		}
270
		fProcess= null;
271
		event.getProject().removeBuildListener(this);
272
        fFileNameToIFile= null;
273
	}
274
	
275
	private String getTimeString(long milliseconds) {
276
			long seconds = milliseconds / 1000;
277
			long minutes = seconds / 60;
278
			seconds= seconds % 60;
279
		
280
			StringBuffer result= new StringBuffer(AntSupportMessages.AntProcessBuildLogger_Total_time);
281
			if (minutes > 0) {
282
				result.append(minutes);
283
				if (minutes > 1) {
284
					result.append(AntSupportMessages.AntProcessBuildLogger__minutes_2);
285
				} else {
286
					result.append(AntSupportMessages.AntProcessBuildLogger__minute_3);
287
				}
288
			}
289
			if (seconds > 0) {
290
				if (minutes > 0) {
291
					result.append(' ');
292
				}
293
				result.append(seconds);
294
			
295
				if (seconds > 1) {
296
					result.append(AntSupportMessages.AntProcessBuildLogger__seconds_4);
297
				} else {
298
					result.append(AntSupportMessages.AntProcessBuildLogger__second_5);
299
				} 
300
			}
301
			if (seconds == 0 && minutes == 0) {
302
				result.append(milliseconds);
303
				result.append(AntSupportMessages.AntProcessBuildLogger__milliseconds_6);
304
			}
305
			
306
			result.append(System.getProperty("line.separator")); //$NON-NLS-1$
307
			return result.toString();
308
		}
309
	
310
	/* (non-Javadoc)
311
	 * @see org.apache.tools.ant.BuildListener#messageLogged(org.apache.tools.ant.BuildEvent)
312
	 */
313
	public void messageLogged(BuildEvent event) {
314
		if (event.getPriority() > getMessageOutputLevel()) {
315
			return;
316
		}
317
		if (event.getMessage() != null && event.getMessage().length() > 0) {
318
			logMessage(event.getMessage(), event, -1);
319
		}
320
	}
321
322
	/* (non-Javadoc)
323
	 * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
324
	 */
325
	public void targetStarted(BuildEvent event) {
326
		if (Project.MSG_INFO > getMessageOutputLevel()) {
327
			return;
328
		}
329
		Target target= event.getTarget();
330
		StringBuffer msg= new StringBuffer(System.getProperty("line.separator")); //$NON-NLS-1$
331
		String targetName= target.getName();
332
		msg.append(targetName);
333
		msg.append(':');
334
		String message= msg.toString();
335
		Location location= AntDebugState.getLocation(target);
336
		if (location != null && location != Location.UNKNOWN_LOCATION) {
337
			IRegion region= new Region(0, targetName.length());
338
			IHyperlink link= getLocationLink(location);
339
			if (link != null) {
340
				TaskLinkManager.addTaskHyperlink(getAntProcess(fProcessId), link, region, message.trim());
341
			}
342
		}
343
		logMessage(message, event, Project.MSG_INFO);
344
	}
345
	
346
	private boolean loggingToLogFile() {
347
		//check if user has designated to log to a log file
348
		return getErrorPrintStream() != null && getErrorPrintStream() != System.err;
349
	}
350
}
(-)Ant Runner Support/org/eclipse/ant/internal/ui/antsupport/logger/AntProcessDebugBuildLogger.java (-247 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport.logger;
12
13
import java.io.File;
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.apache.tools.ant.BuildEvent;
18
import org.apache.tools.ant.Location;
19
import org.eclipse.ant.internal.ui.antsupport.AntSupportMessages;
20
import org.eclipse.ant.internal.ui.antsupport.logger.util.AntDebugState;
21
import org.eclipse.ant.internal.ui.antsupport.logger.util.IDebugBuildLogger;
22
import org.eclipse.ant.internal.ui.debug.IAntDebugController;
23
import org.eclipse.ant.internal.ui.debug.model.AntDebugTarget;
24
import org.eclipse.ant.internal.ui.debug.model.AntThread;
25
import org.eclipse.ant.internal.ui.launchConfigurations.AntProcess;
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.OperationCanceledException;
29
import org.eclipse.debug.core.DebugEvent;
30
import org.eclipse.debug.core.ILaunch;
31
import org.eclipse.debug.core.model.IBreakpoint;
32
import org.eclipse.debug.core.model.ILineBreakpoint;
33
import org.eclipse.debug.core.model.IProcess;
34
35
public class AntProcessDebugBuildLogger extends AntProcessBuildLogger implements IAntDebugController, IDebugBuildLogger {
36
	
37
	private AntDebugState fDebugState= null;
38
	
39
	private List fBreakpoints= null;
40
    
41
	private AntDebugTarget fAntDebugTarget;
42
	private boolean fResumed= false;
43
	
44
	/* (non-Javadoc)
45
	 * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
46
	 */
47
	public void buildStarted(BuildEvent event) {
48
		fDebugState= new AntDebugState(this);
49
		super.buildStarted(event);
50
		IProcess process= getAntProcess(fProcessId);
51
		ILaunch launch= process.getLaunch();
52
		fAntDebugTarget= new AntDebugTarget(launch, process, this);
53
		launch.addDebugTarget(fAntDebugTarget);
54
        
55
        fAntDebugTarget.buildStarted();
56
        fDebugState.buildStarted();
57
	}
58
59
	/* (non-Javadoc)
60
	 * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent)
61
	 */
62
	public void taskFinished(BuildEvent event) {
63
		super.taskFinished(event);
64
		fDebugState.taskFinished();
65
	}
66
	
67
	/* (non-Javadoc)
68
	 * @see org.apache.tools.ant.BuildListener#taskStarted(org.apache.tools.ant.BuildEvent)
69
	 */
70
	public void taskStarted(BuildEvent event) {
71
        super.taskStarted(event);
72
		fDebugState.taskStarted(event);
73
	}
74
	
75
	/* (non-Javadoc)
76
	 * @see org.eclipse.ant.internal.ui.antsupport.logger.util.IDebugBuildLogger#waitIfSuspended()
77
	 */
78
	public synchronized void waitIfSuspended() {
79
		fResumed= false;
80
		IBreakpoint breakpoint= breakpointAtLineNumber(fDebugState.getBreakpointLocation());
81
		if (breakpoint != null) {
82
			 fAntDebugTarget.breakpointHit(breakpoint);
83
			 try {
84
				 while (!fResumed) {
85
					 wait(500);
86
					 checkCancelled();
87
				 }
88
			 } catch (InterruptedException e) {
89
			 }
90
		} else if (fDebugState.getCurrentTask() != null) {
91
			int detail= -1;
92
	        boolean shouldSuspend= true;
93
	        if (fDebugState.isStepIntoSuspend()) {
94
	            detail= DebugEvent.STEP_END;
95
	            fDebugState.setStepIntoSuspend(false);               
96
	        } else if ((fDebugState.getLastTaskFinished() != null && fDebugState.getLastTaskFinished() == fDebugState.getStepOverTask()) || fDebugState.shouldSuspend()) {
97
				detail= DebugEvent.STEP_END;
98
				fDebugState.setShouldSuspend(false);
99
				fDebugState.setStepOverTask(null);
100
	        } else if (fDebugState.isClientSuspend()) {
101
	            detail= DebugEvent.CLIENT_REQUEST;
102
	            fDebugState.setClientSuspend(false);
103
	        } else {
104
	            shouldSuspend= false;
105
	        }
106
	        if (shouldSuspend) {
107
                fAntDebugTarget.suspended(detail);
108
	            try {
109
	            	while (!fResumed) {
110
	            		wait(500);
111
	            		checkCancelled();
112
	            	}
113
	            } catch (InterruptedException e) {
114
	            }
115
	        }
116
	    }
117
	}
118
119
	private void checkCancelled() {
120
		AntProcess process= getAntProcess(fProcessId);
121
		if (process != null && process.isCanceled()) {
122
			throw new OperationCanceledException(AntSupportMessages.AntProcessDebugBuildLogger_1);
123
		}
124
	}
125
126
	/* (non-Javadoc)
127
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#resume()
128
	 */
129
	public synchronized void resume() {
130
		fResumed= true;
131
        notifyAll();
132
	}
133
134
	/* (non-Javadoc)
135
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#suspend()
136
	 */
137
	public synchronized void suspend() {
138
		fDebugState.setClientSuspend(true);
139
	}
140
141
	/* (non-Javadoc)
142
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#stepInto()
143
	 */
144
	public synchronized void stepInto() {
145
		fDebugState.setStepIntoSuspend(true);
146
		fResumed= true;
147
		notifyAll();
148
	}
149
150
	/* (non-Javadoc)
151
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#stepOver()
152
	 */
153
	public synchronized void stepOver() {
154
		fResumed= true;
155
		fDebugState.stepOver();
156
	}
157
158
	/* (non-Javadoc)
159
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#handleBreakpoint(org.eclipse.debug.core.model.IBreakpoint, boolean)
160
	 */
161
	public void handleBreakpoint(IBreakpoint breakpoint, boolean added) {
162
		if (added) {
163
			if (fBreakpoints == null) {
164
				fBreakpoints= new ArrayList();
165
			}
166
			if (!fBreakpoints.contains(breakpoint)) {
167
				fBreakpoints.add(breakpoint);
168
			}
169
		} else {
170
			if (fBreakpoints != null) {
171
				fBreakpoints.remove(breakpoint);
172
			}
173
		}
174
	}
175
176
	/* (non-Javadoc)
177
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#getProperties()
178
	 */
179
	public void getProperties() {
180
		if (!fAntDebugTarget.isSuspended()) {
181
			return;
182
		}
183
	    StringBuffer propertiesRepresentation= new StringBuffer();
184
		fDebugState.marshallProperties(propertiesRepresentation, false);
185
		if (fAntDebugTarget.getThreads().length > 0) {
186
			((AntThread) fAntDebugTarget.getThreads()[0]).newProperties(propertiesRepresentation.toString());
187
		}
188
	}
189
190
	/* (non-Javadoc)
191
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#getStackFrames()
192
	 */
193
	public void getStackFrames() {
194
		StringBuffer stackRepresentation= new StringBuffer();
195
		fDebugState.marshalStack(stackRepresentation);
196
		((AntThread) fAntDebugTarget.getThreads()[0]).buildStack(stackRepresentation.toString());
197
	}
198
    
199
    private IBreakpoint breakpointAtLineNumber(Location location) {
200
        if (fBreakpoints == null || location == null || location == Location.UNKNOWN_LOCATION) {
201
            return null;
202
        }
203
        int lineNumber= fDebugState.getLineNumber(location);
204
        File locationFile= new File(fDebugState.getFileName(location));
205
        for (int i = 0; i < fBreakpoints.size(); i++) {
206
            ILineBreakpoint breakpoint = (ILineBreakpoint) fBreakpoints.get(i);
207
            int breakpointLineNumber;
208
            try {
209
            	if (!breakpoint.isEnabled()) {
210
                	continue;
211
                }
212
            	breakpointLineNumber = breakpoint.getLineNumber();
213
            } catch (CoreException e) {
214
               return null;
215
            }
216
            IFile resource= (IFile) breakpoint.getMarker().getResource();
217
            if (breakpointLineNumber == lineNumber && resource.getLocation().toFile().equals(locationFile)) {
218
                return breakpoint;
219
            }
220
        }
221
        return null;
222
    }
223
    
224
    /* (non-Javadoc)
225
     * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
226
     */
227
    public void targetStarted(BuildEvent event) {
228
		fDebugState.targetStarted(event);
229
		waitIfSuspended();
230
		super.targetStarted(event);
231
    }
232
	
233
	/* (non-Javadoc)
234
	 * @see org.apache.tools.ant.BuildListener#targetFinished(org.apache.tools.ant.BuildEvent)
235
	 */
236
	public void targetFinished(BuildEvent event) {
237
		super.targetFinished(event);
238
		fDebugState.setTargetExecuting(null);
239
	}
240
241
	/* (non-Javadoc)
242
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#unescapeString(java.lang.StringBuffer)
243
	 */
244
	public StringBuffer unescapeString(StringBuffer propertyValue) {
245
		return propertyValue;
246
	}
247
}
(-)Ant Runner Support/org/eclipse/ant/internal/ui/antsupport/logger/NullBuildLogger.java (-180 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport.logger;
12
13
14
import java.io.PrintStream;
15
16
import org.apache.tools.ant.BuildEvent;
17
import org.apache.tools.ant.BuildException;
18
import org.apache.tools.ant.BuildLogger;
19
import org.apache.tools.ant.Project;
20
import org.apache.tools.ant.util.StringUtils;
21
import org.eclipse.ant.core.AntSecurityException;
22
import org.eclipse.ant.internal.core.AbstractEclipseBuildLogger;
23
import org.eclipse.ant.internal.ui.antsupport.AntSupportMessages;
24
import org.eclipse.core.runtime.OperationCanceledException;
25
26
public class NullBuildLogger extends AbstractEclipseBuildLogger implements BuildLogger{
27
28
	protected int fMessageOutputLevel = Project.MSG_INFO;
29
	private PrintStream fErr= null;
30
	private PrintStream fOut= null;
31
	protected boolean fEmacsMode= false;
32
	
33
	/**
34
	 * An exception that has already been logged.
35
	 */
36
	protected Throwable fHandledException= null;
37
	
38
	/**
39
	 * @see org.apache.tools.ant.BuildLogger#setMessageOutputLevel(int)
40
	 */
41
	public void setMessageOutputLevel(int level) {
42
		fMessageOutputLevel= level;
43
	}
44
	
45
	protected int getMessageOutputLevel() {
46
		return fMessageOutputLevel;
47
	}
48
49
	/**
50
	 * @see org.apache.tools.ant.BuildLogger#setEmacsMode(boolean)
51
	 */
52
	public void setEmacsMode(boolean emacsMode) {
53
		fEmacsMode= emacsMode;
54
	}
55
56
	/**
57
	 * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
58
	 */
59
	public void buildStarted(BuildEvent event) {
60
	}
61
62
	/**
63
	 * @see org.apache.tools.ant.BuildListener#buildFinished(org.apache.tools.ant.BuildEvent)
64
	 */
65
	public void buildFinished(BuildEvent event) {
66
		String message= handleException(event);
67
        if (message != null) {
68
            logMessage(message, getMessageOutputLevel());
69
        }
70
		fHandledException= null;
71
	}
72
73
	/**
74
	 * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
75
	 */
76
	public void targetStarted(BuildEvent event) {
77
	}
78
79
	/**
80
	 * @see org.apache.tools.ant.BuildListener#targetFinished(org.apache.tools.ant.BuildEvent)
81
	 */
82
	public void targetFinished(BuildEvent event) {
83
	}
84
85
	/**
86
	 * @see org.apache.tools.ant.BuildListener#taskStarted(org.apache.tools.ant.BuildEvent)
87
	 */
88
	public void taskStarted(BuildEvent event) {
89
	}
90
91
	/**
92
	 * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent)
93
	 */
94
	public void taskFinished(BuildEvent event) {
95
	}
96
97
	/* (non-Javadoc)
98
	 * @see org.apache.tools.ant.BuildListener#messageLogged(org.apache.tools.ant.BuildEvent)
99
	 */
100
	public void messageLogged(BuildEvent event) {
101
		logMessage(event.getMessage(), event.getPriority());
102
	}
103
104
	protected PrintStream getErrorPrintStream() {
105
		return fErr;
106
	}
107
	
108
	protected PrintStream getOutputPrintStream() {
109
		return fOut;
110
	}
111
	
112
	/**
113
	 * @see org.apache.tools.ant.BuildLogger#setErrorPrintStream(java.io.PrintStream)
114
	 */
115
	public void setErrorPrintStream(PrintStream err) {
116
		//this build logger logs to "null" unless
117
		//the user has explicitly set a logfile to use
118
		if (err == System.err) {
119
			fErr= null;
120
		} else {
121
			fErr= err;
122
		}
123
	}
124
125
	/**
126
	 * @see org.apache.tools.ant.BuildLogger#setOutputPrintStream(java.io.PrintStream)
127
	 */
128
	public void setOutputPrintStream(PrintStream output) {
129
		//this build logger logs to "null" unless
130
		//the user has explicitly set a logfile to use
131
		if (output == System.out) {
132
			fOut= null;
133
		} else {
134
			fOut= output;
135
		}
136
	}
137
	
138
	protected void logMessage(String message, int priority) {
139
		if (priority > getMessageOutputLevel()) {
140
			return;
141
		}
142
		
143
		if (priority == Project.MSG_ERR) {
144
			if (getErrorPrintStream() != null && getErrorPrintStream() != System.err) {
145
				//user has designated to log to a logfile
146
				getErrorPrintStream().println(message);
147
			}
148
		} else {
149
			if (getOutputPrintStream() != null && getOutputPrintStream() != System.out) {
150
				//user has designated to log to a logfile
151
				getOutputPrintStream().println(message);
152
			} 
153
		}
154
	}
155
	
156
	protected String handleException(BuildEvent event) {
157
		Throwable exception = event.getException();
158
		if (exception == null || exception == fHandledException
159
		|| exception instanceof OperationCanceledException
160
		|| exception instanceof AntSecurityException) {
161
			return null;
162
		}
163
		fHandledException= exception;
164
        StringBuffer message= new StringBuffer();
165
        message.append(StringUtils.LINE_SEP);
166
        message.append(AntSupportMessages.NullBuildLogger_1);
167
        message.append(StringUtils.LINE_SEP);
168
        if (Project.MSG_VERBOSE <= fMessageOutputLevel || !(exception instanceof BuildException)) {
169
            message.append(StringUtils.getStackTrace(exception));
170
        } else {
171
            if (exception instanceof BuildException) {
172
                message.append(exception.toString()).append(StringUtils.LINE_SEP);
173
            } else {
174
                message.append(exception.getMessage()).append(StringUtils.LINE_SEP);
175
            }
176
        }
177
        
178
		return message.toString();	
179
	}
180
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/AntUIPreferenceInitializer.java (-4 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 34-42 Link Here
34
		prefs.setDefault(IAntUIPreferenceConstants.ANT_FIND_BUILD_FILE_NAMES, "build.xml"); //$NON-NLS-1$
34
		prefs.setDefault(IAntUIPreferenceConstants.ANT_FIND_BUILD_FILE_NAMES, "build.xml"); //$NON-NLS-1$
35
		
35
		
36
		prefs.setDefault(IAntUIPreferenceConstants.DOCUMENTATION_URL, "http://ant.apache.org/manual"); //$NON-NLS-1$
36
		prefs.setDefault(IAntUIPreferenceConstants.DOCUMENTATION_URL, "http://ant.apache.org/manual"); //$NON-NLS-1$
37
        
37
	
38
        prefs.setDefault(IAntUIPreferenceConstants.ANT_COMMUNICATION_TIMEOUT, 20000);
39
		
40
		EditorsUI.useAnnotationsPreferencePage(prefs);
38
		EditorsUI.useAnnotationsPreferencePage(prefs);
41
		EditorsUI.useQuickDiffPreferencePage(prefs);
39
		EditorsUI.useQuickDiffPreferencePage(prefs);
42
		if (AntUIPlugin.isMacOS()) {
40
		if (AntUIPlugin.isMacOS()) {
(-)Ant Tools Support/org/eclipse/ant/internal/ui/AntUtil.java (-234 / +16 lines)
Lines 11-17 Link Here
11
package org.eclipse.ant.internal.ui;
11
package org.eclipse.ant.internal.ui;
12
12
13
import java.io.File;
13
import java.io.File;
14
import java.io.IOException;
15
import java.net.MalformedURLException;
14
import java.net.MalformedURLException;
16
import java.net.URL;
15
import java.net.URL;
17
import java.util.ArrayList;
16
import java.util.ArrayList;
Lines 20-50 Link Here
20
import java.util.Iterator;
19
import java.util.Iterator;
21
import java.util.List;
20
import java.util.List;
22
import java.util.Map;
21
import java.util.Map;
23
import java.util.StringTokenizer;
24
import java.util.regex.Pattern;
22
import java.util.regex.Pattern;
25
23
26
import org.apache.tools.ant.BuildException;
27
import org.apache.tools.ant.Target;
24
import org.apache.tools.ant.Target;
28
import org.apache.tools.ant.util.FileUtils;
29
import org.eclipse.ant.core.AntCorePlugin;
25
import org.eclipse.ant.core.AntCorePlugin;
30
import org.eclipse.ant.internal.core.AntCoreUtil;
26
import org.eclipse.ant.internal.core.AntCoreUtil;
27
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
31
import org.eclipse.ant.internal.ui.editor.AntEditor;
28
import org.eclipse.ant.internal.ui.editor.AntEditor;
32
import org.eclipse.ant.internal.ui.launchConfigurations.AntHomeClasspathEntry;
33
import org.eclipse.ant.internal.ui.launchConfigurations.TaskLinkManager;
34
import org.eclipse.ant.internal.ui.model.AntElementNode;
29
import org.eclipse.ant.internal.ui.model.AntElementNode;
35
import org.eclipse.ant.internal.ui.model.AntModel;
30
import org.eclipse.ant.internal.ui.model.AntModel;
36
import org.eclipse.ant.internal.ui.model.AntProjectNode;
31
import org.eclipse.ant.internal.ui.model.AntProjectNode;
37
import org.eclipse.ant.internal.ui.model.AntTargetNode;
32
import org.eclipse.ant.internal.ui.model.AntTargetNode;
38
import org.eclipse.ant.internal.ui.model.IAntModel;
33
import org.eclipse.ant.internal.ui.model.IAntModel;
39
import org.eclipse.ant.internal.ui.model.LocationProvider;
34
import org.eclipse.ant.internal.ui.model.LocationProvider;
40
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
35
import org.eclipse.ant.launching.IAntLaunchConstants;
41
import org.eclipse.core.filebuffers.FileBuffers;
36
import org.eclipse.core.filebuffers.FileBuffers;
42
import org.eclipse.core.filebuffers.ITextFileBuffer;
37
import org.eclipse.core.filebuffers.ITextFileBuffer;
43
import org.eclipse.core.filebuffers.ITextFileBufferManager;
38
import org.eclipse.core.filebuffers.ITextFileBufferManager;
44
import org.eclipse.core.filebuffers.LocationKind;
39
import org.eclipse.core.filebuffers.LocationKind;
40
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
45
import org.eclipse.core.resources.IFile;
41
import org.eclipse.core.resources.IFile;
46
import org.eclipse.core.resources.IWorkspaceRoot;
47
import org.eclipse.core.resources.ResourcesPlugin;
48
import org.eclipse.core.runtime.CoreException;
42
import org.eclipse.core.runtime.CoreException;
49
import org.eclipse.core.runtime.IPath;
43
import org.eclipse.core.runtime.IPath;
50
import org.eclipse.core.runtime.IStatus;
44
import org.eclipse.core.runtime.IStatus;
Lines 54-70 Link Here
54
import org.eclipse.core.variables.IStringVariableManager;
48
import org.eclipse.core.variables.IStringVariableManager;
55
import org.eclipse.core.variables.VariablesPlugin;
49
import org.eclipse.core.variables.VariablesPlugin;
56
import org.eclipse.debug.core.ILaunchConfiguration;
50
import org.eclipse.debug.core.ILaunchConfiguration;
57
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
58
import org.eclipse.debug.core.model.IProcess;
59
import org.eclipse.debug.ui.console.FileLink;
51
import org.eclipse.debug.ui.console.FileLink;
60
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
61
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
62
import org.eclipse.jdt.launching.IRuntimeClasspathEntry2;
63
import org.eclipse.jdt.launching.JavaRuntime;
64
import org.eclipse.jface.dialogs.MessageDialog;
52
import org.eclipse.jface.dialogs.MessageDialog;
65
import org.eclipse.jface.text.BadLocationException;
53
import org.eclipse.jface.text.BadLocationException;
66
import org.eclipse.jface.text.IDocument;
54
import org.eclipse.jface.text.IDocument;
67
import org.eclipse.jface.text.Region;
68
import org.eclipse.swt.SWT;
55
import org.eclipse.swt.SWT;
69
import org.eclipse.swt.program.Program;
56
import org.eclipse.swt.program.Program;
70
import org.eclipse.swt.widgets.Shell;
57
import org.eclipse.swt.widgets.Shell;
Lines 79-86 Link Here
79
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
66
import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
80
import org.eclipse.ui.console.IHyperlink;
67
import org.eclipse.ui.console.IHyperlink;
81
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
68
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
82
import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder;
83
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
84
import org.eclipse.ui.ide.IDE;
69
import org.eclipse.ui.ide.IDE;
85
import org.eclipse.ui.part.FileEditorInput;
70
import org.eclipse.ui.part.FileEditorInput;
86
import org.eclipse.ui.texteditor.IDocumentProvider;
71
import org.eclipse.ui.texteditor.IDocumentProvider;
Lines 114-132 Link Here
114
	 * <code>null</code> if the array is empty.
99
	 * <code>null</code> if the array is empty.
115
	 */
100
	 */
116
	public static String combineStrings(String[] strings) {
101
	public static String combineStrings(String[] strings) {
117
		if (strings.length == 0)
102
		return AntLaunchingUtil.combineStrings(strings);
118
			return null;
119
120
		if (strings.length == 1)
121
			return strings[0];
122
123
		StringBuffer buf = new StringBuffer();
124
		for (int i = 0; i < strings.length - 1; i++) {
125
			buf.append(strings[i]);
126
			buf.append(ATTRIBUTE_SEPARATOR);
127
		}
128
		buf.append(strings[strings.length - 1]);
129
		return buf.toString();
130
	}
103
	}
131
104
132
	/**
105
	/**
Lines 138-172 Link Here
138
	 * @throws CoreException if unable to access the associated attribute
111
	 * @throws CoreException if unable to access the associated attribute
139
	 */
112
	 */
140
	public static String[] getTargetNames(ILaunchConfiguration configuration) throws CoreException {
113
	public static String[] getTargetNames(ILaunchConfiguration configuration) throws CoreException {
141
        String attribute= null;
114
		return AntLaunchingUtil.getTargetNames(configuration);
142
        if (IAntLaunchConfigurationConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE.equals(configuration.getType().getIdentifier())) {
143
            attribute= getTargetNamesForAntBuilder(configuration);
144
        }
145
        if (attribute == null) {
146
            attribute = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, (String) null);
147
            if (attribute == null) {
148
                return null;
149
            } 
150
        }
151
		
152
		return AntUtil.parseRunTargets(attribute);
153
	}
115
	}
154
	
155
	private static String getTargetNamesForAntBuilder(ILaunchConfiguration configuration) throws CoreException {
156
        String buildType= ExternalToolBuilder.getBuildType();
157
        String targets= null;
158
        if (IExternalToolConstants.BUILD_TYPE_AUTO.equals(buildType)) {
159
            targets= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_AUTO_TARGETS, (String)null);
160
        } else if (IExternalToolConstants.BUILD_TYPE_CLEAN.equals(buildType)) {
161
            targets = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_CLEAN_TARGETS, (String) null);
162
        } else if (IExternalToolConstants.BUILD_TYPE_FULL.equals(buildType)) {
163
            targets = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, (String) null);
164
        } else if (IExternalToolConstants.BUILD_TYPE_INCREMENTAL.equals(buildType)) {
165
            targets = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_MANUAL_TARGETS, (String) null);
166
        }
167
       
168
        return targets;
169
    }
170
116
171
    /**
117
    /**
172
	 * Returns a map of properties to be defined for the build, or
118
	 * Returns a map of properties to be defined for the build, or
Lines 177-185 Link Here
177
	 * @return map of properties (name --> value), or <code>null</code>
123
	 * @return map of properties (name --> value), or <code>null</code>
178
	 * @throws CoreException if unable to access the associated attribute
124
	 * @throws CoreException if unable to access the associated attribute
179
	 */
125
	 */
180
	public static Map getProperties(ILaunchConfiguration configuration) throws CoreException {
126
	public static Map getProperties(ILaunchConfiguration configuration) throws CoreException {		
181
		Map map = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, (Map) null);
127
		return AntLaunchingUtil.getProperties(configuration);
182
		return map;
183
	}
128
	}
184
	
129
	
185
	/**
130
	/**
Lines 190-206 Link Here
190
	 * @throws CoreException if unable to access the associated attribute
135
	 * @throws CoreException if unable to access the associated attribute
191
	 */
136
	 */
192
	public static String getAntHome(ILaunchConfiguration configuration) throws CoreException {
137
	public static String getAntHome(ILaunchConfiguration configuration) throws CoreException {
193
		IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(configuration);
138
		return AntLaunchingUtil.getAntHome(configuration);
194
		for (int i = 0; i < entries.length; i++) {
195
			IRuntimeClasspathEntry entry = entries[i];
196
			if (entry.getType() == IRuntimeClasspathEntry.OTHER) {
197
				IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2)entry;
198
				if (entry2.getTypeId().equals(AntHomeClasspathEntry.TYPE_ID)) {
199
					return ((AntHomeClasspathEntry)entry2).getAntHome();
200
				}
201
			}
202
		}
203
		return null;
204
	}
139
	}
205
140
206
	/**
141
	/**
Lines 213-219 Link Here
213
	 * @throws CoreException if unable to access the associated attribute
148
	 * @throws CoreException if unable to access the associated attribute
214
	 */
149
	 */
215
	public static String[] getPropertyFiles(ILaunchConfiguration configuration) throws CoreException {
150
	public static String[] getPropertyFiles(ILaunchConfiguration configuration) throws CoreException {
216
		String attribute = configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, (String) null);
151
		String attribute = configuration.getAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTY_FILES, (String) null);
217
		if (attribute == null) {
152
		if (attribute == null) {
218
			return null;
153
			return null;
219
		}
154
		}
Lines 412-441 Link Here
412
	 * @throws CoreException if file does not exist, IO problems, or invalid format.
347
	 * @throws CoreException if file does not exist, IO problems, or invalid format.
413
	 */
348
	 */
414
	public static URL[] getCustomClasspath(ILaunchConfiguration config) throws CoreException {
349
	public static URL[] getCustomClasspath(ILaunchConfiguration config) throws CoreException {
415
		boolean useDefault = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
350
		return AntLaunchingUtil.getCustomClasspath(config);
416
		if (useDefault) {
417
			return null;
418
		}
419
		IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(config);
420
		// don't consider bootpath entries
421
		List userEntries = new ArrayList(unresolved.length);
422
		for (int i = 0; i < unresolved.length; i++) {
423
			IRuntimeClasspathEntry entry = unresolved[i];
424
			if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {
425
				userEntries.add(entry);
426
			}
427
		}
428
		IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspath((IRuntimeClasspathEntry[])userEntries.toArray(new IRuntimeClasspathEntry[userEntries.size()]), config);
429
		URL[] urls = new URL[entries.length];
430
		for (int i = 0; i < entries.length; i++) {
431
			IRuntimeClasspathEntry entry = entries[i];
432
			try {
433
				urls[i] = new URL("file:"+entry.getLocation()); //$NON-NLS-1$
434
			} catch (MalformedURLException e) {
435
				throw new CoreException(new Status(IStatus.ERROR, AntUIPlugin.getUniqueIdentifier(), AntUIPlugin.INTERNAL_ERROR, AntUIModelMessages.AntUtil_7, e));
436
			}
437
		}
438
		return urls;		
439
	}
351
	}
440
352
441
	private static String expandVariableString(String variableString, String invalidMessage) throws CoreException {
353
	private static String expandVariableString(String variableString, String invalidMessage) throws CoreException {
Lines 456-462 Link Here
456
	 * @return a list of target names
368
	 * @return a list of target names
457
	 */
369
	 */
458
	public static String[] parseRunTargets(String extraAttibuteValue) {
370
	public static String[] parseRunTargets(String extraAttibuteValue) {
459
		return parseString(extraAttibuteValue, ATTRIBUTE_SEPARATOR);
371
		return AntLaunchingUtil.parseRunTargets(extraAttibuteValue);
460
	}
372
	}
461
	
373
	
462
	/**
374
	/**
Lines 466-484 Link Here
466
	 * @return a list of Strings
378
	 * @return a list of Strings
467
	 */
379
	 */
468
	public static String[] parseString(String delimString, String delim) {
380
	public static String[] parseString(String delimString, String delim) {
469
		if (delimString == null) {
381
		return AntLaunchingUtil.parseString(delimString, delim);
470
			return new String[0];
471
		}
472
		
473
		// Need to handle case where separator character is
474
		// actually part of the target name!
475
		StringTokenizer tokenizer = new StringTokenizer(delimString, delim);
476
		String[] results = new String[tokenizer.countTokens()];
477
		for (int i = 0; i < results.length; i++) {
478
			results[i] = tokenizer.nextToken();
479
		}
480
		
481
		return results;
482
	}
382
	}
483
	
383
	
484
	/**
384
	/**
Lines 486-493 Link Here
486
	 * The returned IFile may or may not exist.
386
	 * The returned IFile may or may not exist.
487
	 */
387
	 */
488
	public static IFile getFile(String fullPath) {
388
	public static IFile getFile(String fullPath) {
489
		IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
389
		return AntLaunchingUtil.getFile(fullPath);
490
		return root.getFile(new Path(fullPath));
491
	}
390
	}
492
391
493
	public static IHyperlink getLocationLink(String path, File buildFileParent) {
392
	public static IHyperlink getLocationLink(String path, File buildFileParent) {
Lines 540-587 Link Here
540
	 * @see org.eclipse.core.resources.IWorkspaceRoot#findFilesForLocation(IPath)
439
	 * @see org.eclipse.core.resources.IWorkspaceRoot#findFilesForLocation(IPath)
541
	 */
440
	 */
542
	public static IFile getFileForLocation(String path, File buildFileParent) {
441
	public static IFile getFileForLocation(String path, File buildFileParent) {
543
		if (path == null) {
442
		return AntLaunchingUtil.getFileForLocation(path, buildFileParent);
544
			return null;
545
		}
546
		IPath filePath= new Path(path);
547
		IFile file = null;
548
		IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(filePath);
549
		if (files.length > 0) {
550
			file= files[0];
551
		}
552
		if (file == null) {
553
			//relative path
554
			File relativeFile= null;
555
			try {
556
				//this call is ok if buildFileParent is null
557
				relativeFile= FileUtils.getFileUtils().resolveFile(buildFileParent, path);
558
				filePath= new Path(relativeFile.getAbsolutePath());
559
				files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(filePath);
560
				if (files.length > 0) {
561
					file= files[0];
562
				} else {
563
					return null;
564
				}
565
			} catch (BuildException be) {
566
				return null;
567
			}
568
		}
569
		
570
		if (file.exists()) {
571
			return file;
572
		} 
573
		File ioFile= file.getLocation().toFile();
574
		if (ioFile.exists()) {//needs to handle case insensitivity on WINOS
575
			try {
576
				files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(ioFile.getCanonicalPath()));
577
				if (files.length > 0) {
578
					return files[0];
579
				}
580
			} catch (IOException e) {
581
			}			
582
		}
583
			
584
		return null;
585
	}
443
	}
586
444
587
	/**
445
	/**
Lines 594-633 Link Here
594
	 * @since 3.0
452
	 * @since 3.0
595
	 */
453
	 */
596
	public static void migrateToNewClasspathFormat(ILaunchConfiguration configuration) throws CoreException {
454
	public static void migrateToNewClasspathFormat(ILaunchConfiguration configuration) throws CoreException {
597
		String oldClasspath = configuration.getAttribute(org.eclipse.ant.internal.ui.launchConfigurations.IAntLaunchConfigurationConstants.ATTR_ANT_CUSTOM_CLASSPATH, (String)null);
455
		AntLaunchingUtil.migrateToNewClasspathFormat(configuration);
598
		String oldAntHome = configuration.getAttribute(org.eclipse.ant.internal.ui.launchConfigurations.IAntLaunchConfigurationConstants.ATTR_ANT_HOME, (String)null);
599
		String provider = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, (String)null);
600
		if (oldClasspath != null || oldAntHome != null || provider == null) {
601
			ILaunchConfigurationWorkingCopy workingCopy = null;
602
			if (configuration.isWorkingCopy()) {
603
				workingCopy = (ILaunchConfigurationWorkingCopy) configuration;
604
			} else {
605
				workingCopy = configuration.getWorkingCopy();
606
			}
607
			workingCopy.setAttribute(org.eclipse.ant.internal.ui.launchConfigurations.IAntLaunchConfigurationConstants.ATTR_ANT_CUSTOM_CLASSPATH, (String)null);
608
			workingCopy.setAttribute(org.eclipse.ant.internal.ui.launchConfigurations.IAntLaunchConfigurationConstants.ATTR_ANT_HOME, (String)null);
609
			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); //$NON-NLS-1$
610
			workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
611
			if (oldAntHome != null) {
612
				IRuntimeClasspathEntry[] entries = JavaRuntime.computeUnresolvedRuntimeClasspath(workingCopy);
613
				List mementos = new ArrayList(entries.length);
614
				for (int i = 0; i < entries.length; i++) {
615
					IRuntimeClasspathEntry entry = entries[i];
616
					if (entry.getType() == IRuntimeClasspathEntry.OTHER) {
617
						IRuntimeClasspathEntry2 entry2 = (IRuntimeClasspathEntry2) entry;
618
						if (entry2.getTypeId().equals(AntHomeClasspathEntry.TYPE_ID)) {
619
							AntHomeClasspathEntry homeEntry = new AntHomeClasspathEntry(oldAntHome);
620
							mementos.add(homeEntry.getMemento());
621
							continue;
622
						}
623
					}
624
					mementos.add(entry.getMemento());
625
				}
626
				workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
627
				workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, mementos);
628
			}
629
			workingCopy.doSave();
630
		}
631
	}
456
	}
632
457
633
    private static int getOffset(int line, int column, ITextEditor editor) {
458
    private static int getOffset(int line, int column, ITextEditor editor) {
Lines 749-797 Link Here
749
	}
574
	}
750
    
575
    
751
    public static boolean isSeparateJREAntBuild(ILaunchConfiguration configuration) {
576
    public static boolean isSeparateJREAntBuild(ILaunchConfiguration configuration) {
752
    	boolean separateJRE= true;
577
    	return AntLaunchingUtil.isSeparateJREAntBuild(configuration);
753
		try {
754
			//always null for same JRE
755
			separateJRE = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String)null) != null;
756
		} catch (CoreException e) {
757
			AntUIPlugin.log(AntUIModelMessages.AntUtil_2, e);
758
		}
759
    	
760
		return separateJRE;
761
    }
762
    
763
    public static void linkBuildFailedMessage(String message, IProcess process) {
764
        String fileName = null;
765
        String lineNumber = ""; //$NON-NLS-1$
766
        int fileStart = 0;
767
        int index = message.indexOf("xml"); //$NON-NLS-1$
768
        if (index > 0) {
769
            int numberStart= index + 4;
770
            int numberEnd= message.indexOf(':', numberStart);
771
            int fileEnd = index + 3;
772
            if (numberStart > 0 && fileEnd > 0) {
773
                fileName = message.substring(fileStart, fileEnd).trim();
774
                if (numberEnd > 0) {
775
                    lineNumber = message.substring(numberStart, numberEnd).trim();
776
                }
777
            }
778
        }
779
        
780
        if (fileName != null) {
781
            int num = -1;
782
            try {
783
                num = Integer.parseInt(lineNumber);
784
            } catch (NumberFormatException e) {
785
            }
786
            IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(fileName));
787
            IFile file= null;
788
            if (files.length > 0) {
789
                file= files[0];
790
            }
791
            if (file != null && file.exists()) {
792
                FileLink link = new FileLink(file, null, -1, -1, num);
793
                TaskLinkManager.addTaskHyperlink(process, link, new Region(0, message.length()), message);
794
            }
795
        }
796
    }
578
    }
797
}
579
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/IAntUIPreferenceConstants.java (-7 / +1 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 34-45 Link Here
34
	public static final String CONSOLE_DEBUG_COLOR = "org.eclipse.ant.ui.debugColor"; //$NON-NLS-1$	
34
	public static final String CONSOLE_DEBUG_COLOR = "org.eclipse.ant.ui.debugColor"; //$NON-NLS-1$	
35
	
35
	
36
	public static final String ANT_TOOLS_JAR_WARNING= "toolsJAR"; //$NON-NLS-1$
36
	public static final String ANT_TOOLS_JAR_WARNING= "toolsJAR"; //$NON-NLS-1$
37
    
38
    /**
39
     * int preference identifier constant which specifies the length of time to wait
40
     * to connect with the socket that communicates with the separate JRE to capture the output
41
     */
42
    public static final String ANT_COMMUNICATION_TIMEOUT= "timeout"; //$NON-NLS-1$
43
	
37
	
44
	public static final String ANT_ERROR_DIALOG= "errorDialog"; //$NON-NLS-1$
38
	public static final String ANT_ERROR_DIALOG= "errorDialog"; //$NON-NLS-1$
45
	
39
	
(-)Ant Tools Support/org/eclipse/ant/internal/ui/console/AntConsoleColorProvider.java (-6 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.console;
11
package org.eclipse.ant.internal.ui.console;
12
12
13
import org.eclipse.ant.internal.launching.launchConfigurations.AntStreamsProxy;
13
import org.eclipse.ant.internal.ui.AntUIPlugin;
14
import org.eclipse.ant.internal.ui.AntUIPlugin;
14
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
15
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
15
import org.eclipse.ant.internal.ui.launchConfigurations.AntProcess;
16
import org.eclipse.ant.internal.ui.launchConfigurations.AntStreamsProxy;
17
import org.eclipse.debug.core.model.IProcess;
16
import org.eclipse.debug.core.model.IProcess;
18
import org.eclipse.debug.ui.IDebugUIConstants;
17
import org.eclipse.debug.ui.IDebugUIConstants;
19
import org.eclipse.debug.ui.console.ConsoleColorProvider;
18
import org.eclipse.debug.ui.console.ConsoleColorProvider;
Lines 58-66 Link Here
58
		//an AntStreamsProxy. The remote Ant builds make use of the
57
		//an AntStreamsProxy. The remote Ant builds make use of the
59
		// org.eclipse.debug.core.processFactories extension point
58
		// org.eclipse.debug.core.processFactories extension point
60
		AntStreamsProxy proxy = (AntStreamsProxy)process.getStreamsProxy();
59
		AntStreamsProxy proxy = (AntStreamsProxy)process.getStreamsProxy();
61
		if (process instanceof AntProcess) {
62
			((AntProcess)process).setConsole(console);
63
		}
64
		if (proxy != null) {
60
		if (proxy != null) {
65
			console.connect(proxy.getDebugStreamMonitor(), AntStreamsProxy.ANT_DEBUG_STREAM);
61
			console.connect(proxy.getDebugStreamMonitor(), AntStreamsProxy.ANT_DEBUG_STREAM);
66
			console.connect(proxy.getWarningStreamMonitor(), AntStreamsProxy.ANT_WARNING_STREAM);
62
			console.connect(proxy.getWarningStreamMonitor(), AntStreamsProxy.ANT_WARNING_STREAM);
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/AntDebugMessages.java (-23 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.ant.internal.ui.debug;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class AntDebugMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.ant.internal.ui.debug.AntDebugMessages";//$NON-NLS-1$
16
    
17
	public static String AntSourceContainer_0;
18
19
	static {
20
		// load message values from bundle file
21
		NLS.initializeMessages(BUNDLE_NAME, AntDebugMessages.class);
22
	}
23
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/AntDebugMessages.properties (-12 lines)
Removed Link Here
1
###############################################################################
2
# Copyright (c) 2005 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
AntSourceContainer_0=Ant Source Container
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/AntSourceContainer.java (-73 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.debug;
13
14
import java.io.File;
15
import java.io.IOException;
16
import java.util.ArrayList;
17
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IWorkspaceRoot;
20
import org.eclipse.core.resources.ResourcesPlugin;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
25
import org.eclipse.debug.core.sourcelookup.containers.AbstractSourceContainer;
26
import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage;
27
28
public class AntSourceContainer extends AbstractSourceContainer {
29
30
	private IWorkspaceRoot fRoot;
31
32
	public AntSourceContainer() {
33
		fRoot = ResourcesPlugin.getWorkspace().getRoot();
34
	}
35
36
	/* (non-Javadoc)
37
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#findSourceElements(java.lang.String)
38
	 */
39
	public Object[] findSourceElements(String path) throws CoreException {
40
		ArrayList sources = new ArrayList();
41
		File osFile = new File(path);
42
		if (osFile.exists()) {
43
			try {
44
				IPath canonicalPath = new Path(osFile.getCanonicalPath());
45
				IFile[] files = fRoot.findFilesForLocation(canonicalPath);
46
				if (files.length > 0) {
47
					for (int i = 0; i < files.length; i++) {
48
						sources.add(files[i]);
49
					}
50
				} else {
51
					sources.add(new LocalFileStorage(osFile));
52
				}
53
			} catch (IOException e) {
54
			}
55
		}
56
		return sources.toArray();
57
	}
58
59
	/* (non-Javadoc)
60
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getName()
61
	 */
62
	public String getName() {
63
		return AntDebugMessages.AntSourceContainer_0;
64
	}
65
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.debug.core.sourcelookup.ISourceContainer#getType()
68
     * Not persisted via the launch configuration
69
	 */
70
	public ISourceContainerType getType() {
71
		return null;
72
	}
73
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/AntSourceLookupDirector.java (-36 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector;
15
import org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant;
16
17
/**
18
 * Ant source lookup director. For Ant source lookup there is one source
19
 * lookup participant. 
20
 */
21
public class AntSourceLookupDirector extends AbstractSourceLookupDirector {
22
	
23
	/* (non-Javadoc)
24
	 * @see org.eclipse.debug.core.sourcelookup.ISourceLookupDirector#initializeParticipants()
25
	 */
26
	public void initializeParticipants() {
27
		addParticipants(new ISourceLookupParticipant[]{new AntSourceLookupParticipant()});
28
	}
29
30
    /* (non-Javadoc)
31
     * @see org.eclipse.debug.core.model.IPersistableSourceLocator#getMemento()
32
     */
33
    public String getMemento() throws CoreException {
34
        return null;
35
    }
36
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/AntSourceLookupParticipant.java (-36 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug;
12
13
import org.eclipse.ant.internal.ui.debug.model.AntStackFrame;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupParticipant;
16
17
/**
18
 * The Ant source lookup participant knows how to translate a 
19
 * Ant stack frame into a source file name 
20
 */
21
public class AntSourceLookupParticipant extends AbstractSourceLookupParticipant {
22
	
23
	/* (non-Javadoc)
24
	 * @see org.eclipse.debug.core.sourcelookup.ISourceLookupParticipant#getSourceName(java.lang.Object)
25
	 */
26
	public String getSourceName(Object object) throws CoreException {
27
		if (object instanceof AntStackFrame) {
28
			return ((AntStackFrame)object).getFilePath();
29
		}
30
        if (object instanceof String) {
31
            // assume it's a file name
32
            return (String)object;
33
        }
34
		return null;
35
	}
36
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/AntSourcePathComputerDelegate.java (-33 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.debug.core.ILaunchConfiguration;
16
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
17
import org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate;
18
19
/**
20
 * Computes the default source lookup path for an Ant launch configuration.
21
 * The default source lookup is a container that knows how to map the 
22
 * fully qualified file system paths to either the <code>IFile</code> within the workspace or
23
 * a <code>LocalFileStorage</code> for buildfiles not in the workspace.
24
 */
25
public class AntSourcePathComputerDelegate implements ISourcePathComputerDelegate {
26
	
27
	/* (non-Javadoc)
28
	 * @see org.eclipse.debug.core.sourcelookup.ISourcePathComputerDelegate#computeSourceContainers(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor)
29
	 */
30
	public ISourceContainer[] computeSourceContainers(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
31
		return new ISourceContainer[] {new AntSourceContainer()};
32
	}
33
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/IAntDebugConstants.java (-33 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.debug;
13
14
public interface IAntDebugConstants {
15
	
16
	/**
17
	 * Unique identifier for the Ant debug model (value 
18
	 * <code>org.eclipse.ant.ui.debug</code>).
19
	 */
20
	public static final String ID_ANT_DEBUG_MODEL = "org.eclipse.ant.ui.debug"; //$NON-NLS-1$
21
	
22
	/**
23
	 * Unique identifier for the Ant line breakpoint markers 
24
	 * (value <code>org.eclipse.ant.ui.antLineBreakpointMarker</code>).
25
	 */
26
	public static final String ID_ANT_LINE_BREAKPOINT_MARKER= "org.eclipse.ant.ui.antLineBreakpointMarker"; //$NON-NLS-1$
27
    
28
    /**
29
     * Unique identifier for the Ant run to line breakpoints 
30
     * (value <code>org.eclipse.ant.ui.runToLineBreakpoint</code>).
31
     */
32
    public static final String ANT_RUN_TO_LINE= "org.eclipse.ant.ui.runToLineBreakpoint"; //$NON-NLS-1$
33
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/IAntDebugController.java (-66 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug;
12
13
import org.eclipse.debug.core.model.IBreakpoint;
14
15
public interface IAntDebugController {
16
	
17
    /**
18
     * Resume the Ant build
19
     */
20
	public void resume();
21
    
22
    /**
23
     * Suspend the Ant build
24
     */
25
	public void suspend();
26
    
27
     /**
28
     * Step into the current Ant task
29
     */
30
	public void stepInto();
31
    
32
     /**
33
     * Step over the current Ant task
34
     */
35
	public void stepOver();
36
    
37
    /**
38
     * The provided breakpoint has been added or removed depending on the <code>added</code> parameter.
39
     * Updates the controller for this change.
40
     * 
41
     * @param breakpoint the breakpoint that has been added or removed
42
     * @param added whether or not the breakpoint has been added 
43
     */
44
	public void handleBreakpoint(IBreakpoint breakpoint, boolean added);
45
    
46
     /**
47
     * Retrieve the properties of the Ant build.
48
     * May occur asynchronously depending on implementation.
49
     */
50
	public void getProperties();
51
    
52
    /**
53
     * Retrieve the stack frames of the Ant build.
54
     * May occur asynchronously depending on implementation.
55
     */
56
	public void getStackFrames();
57
58
	/**
59
	 * Some strings are escaped when marshalled for socket communication.
60
	 * The Ant debug controller will properly unescape these Strings if required.
61
	 * 
62
	 * @param value The buffer of the string to unescape
63
	 * @return The unescaped string
64
	 */
65
	public StringBuffer unescapeString(StringBuffer value);
66
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntDebugElement.java (-54 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug.model;
12
13
import org.eclipse.ant.internal.ui.AntUIPlugin;
14
import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.debug.core.DebugException;
18
import org.eclipse.debug.core.model.DebugElement;
19
20
/**
21
 * Common function of Ant debug model elements
22
 */
23
public abstract class AntDebugElement extends DebugElement {
24
	
25
	/**
26
	 * Constructs a new debug element contained in the given
27
	 * debug target.
28
	 * 
29
	 * @param target debug target
30
	 */
31
	public AntDebugElement(AntDebugTarget target) {
32
		super(target);
33
	}
34
	
35
	/* (non-Javadoc)
36
	 * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
37
	 */
38
	public String getModelIdentifier() {
39
		return IAntDebugConstants.ID_ANT_DEBUG_MODEL;
40
	}
41
    
42
	/**
43
     * Throws a debug exception with the given message, error code, and underlying
44
     * exception.
45
     */
46
    protected void throwDebugException(String message) throws DebugException {
47
        throw new DebugException(new Status(IStatus.ERROR, AntUIPlugin.getUniqueIdentifier(),
48
            DebugException.TARGET_REQUEST_FAILED, message, null));
49
    }
50
    
51
    protected AntDebugTarget getAntDebugTarget() {
52
        return (AntDebugTarget)super.getDebugTarget();
53
    }
54
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntDebugModelPresentation.java (-1 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-18 Link Here
13
13
14
import java.io.File;
14
import java.io.File;
15
15
16
import org.eclipse.ant.internal.launching.debug.model.AntLineBreakpoint;
17
import org.eclipse.ant.internal.launching.debug.model.AntProperties;
18
import org.eclipse.ant.internal.launching.debug.model.AntProperty;
19
import org.eclipse.ant.internal.launching.debug.model.AntStackFrame;
20
import org.eclipse.ant.internal.launching.debug.model.AntThread;
21
import org.eclipse.ant.internal.launching.debug.model.DebugModelMessages;
16
import org.eclipse.ant.internal.ui.AntUIImages;
22
import org.eclipse.ant.internal.ui.AntUIImages;
17
import org.eclipse.ant.internal.ui.AntUIPlugin;
23
import org.eclipse.ant.internal.ui.AntUIPlugin;
18
import org.eclipse.ant.internal.ui.preferences.AntObjectLabelProvider;
24
import org.eclipse.ant.internal.ui.preferences.AntObjectLabelProvider;
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntDebugTarget.java (-463 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug.model;
12
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
17
import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
18
import org.eclipse.ant.internal.ui.debug.IAntDebugController;
19
import org.eclipse.core.resources.IMarkerDelta;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.variables.VariablesPlugin;
22
import org.eclipse.debug.core.DebugEvent;
23
import org.eclipse.debug.core.DebugException;
24
import org.eclipse.debug.core.DebugPlugin;
25
import org.eclipse.debug.core.IBreakpointManager;
26
import org.eclipse.debug.core.IBreakpointManagerListener;
27
import org.eclipse.debug.core.IDebugEventSetListener;
28
import org.eclipse.debug.core.ILaunch;
29
import org.eclipse.debug.core.model.IBreakpoint;
30
import org.eclipse.debug.core.model.IDebugTarget;
31
import org.eclipse.debug.core.model.ILineBreakpoint;
32
import org.eclipse.debug.core.model.IMemoryBlock;
33
import org.eclipse.debug.core.model.IProcess;
34
import org.eclipse.debug.core.model.IThread;
35
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
36
37
/**
38
 * Ant Debug Target
39
 */
40
public class AntDebugTarget extends AntDebugElement implements IDebugTarget, IDebugEventSetListener, IBreakpointManagerListener {
41
	
42
	// associated system process (Ant Build)
43
	private IProcess fProcess;
44
	
45
	// containing launch object
46
	private ILaunch fLaunch;
47
	
48
	// Build file name
49
	private String fName;
50
51
	// suspend state
52
	private boolean fSuspended= false;
53
	
54
	// terminated state
55
	private boolean fTerminated= false;
56
	
57
	// threads
58
	private AntThread fThread;
59
	private IThread[] fThreads;
60
	
61
	private IAntDebugController fController;
62
    
63
    private List fRunToLineBreakpoints;
64
65
	/**
66
	 * Constructs a new debug target in the given launch for the 
67
	 * associated Ant build process.
68
	 * 
69
	 * @param launch containing launch
70
	 * @param process Ant build process
71
	 * @param controller the controller to communicate to the Ant build
72
	 */
73
	public AntDebugTarget(ILaunch launch, IProcess process, IAntDebugController controller) {
74
		super(null);
75
		fLaunch = launch;
76
		fProcess = process;
77
		
78
		fController= controller;
79
		
80
		fThread = new AntThread(this);
81
		fThreads = new IThread[] {fThread};
82
        
83
        DebugPlugin.getDefault().getBreakpointManager().addBreakpointManagerListener(this);
84
		DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
85
        DebugPlugin.getDefault().addDebugEventListener(this);
86
	}
87
	
88
	/* (non-Javadoc)
89
	 * @see org.eclipse.debug.core.model.IDebugTarget#getProcess()
90
	 */
91
	public IProcess getProcess() {
92
		return fProcess;
93
	}
94
	
95
	/* (non-Javadoc)
96
	 * @see org.eclipse.debug.core.model.IDebugTarget#getThreads()
97
	 */
98
	public IThread[] getThreads() {
99
		return fThreads;
100
	}
101
	
102
	/* (non-Javadoc)
103
	 * @see org.eclipse.debug.core.model.IDebugTarget#hasThreads()
104
	 */
105
	public boolean hasThreads() throws DebugException {
106
		return !fTerminated && fThreads.length > 0;
107
	}
108
	
109
	/* (non-Javadoc)
110
	 * @see org.eclipse.debug.core.model.IDebugTarget#getName()
111
	 */
112
	public String getName() throws DebugException {
113
		if (fName == null) {
114
			try {
115
				fName= getLaunch().getLaunchConfiguration().getAttribute(IExternalToolConstants.ATTR_LOCATION, DebugModelMessages.AntDebugTarget_0);
116
				fName= VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(fName);
117
			} catch (CoreException e) {
118
				fName = DebugModelMessages.AntDebugTarget_0;
119
			}
120
		}
121
		return fName;
122
	}
123
	
124
	/* (non-Javadoc)
125
	 * @see org.eclipse.debug.core.model.IDebugTarget#supportsBreakpoint(org.eclipse.debug.core.model.IBreakpoint)
126
	 */
127
	public boolean supportsBreakpoint(IBreakpoint breakpoint) {
128
		if (breakpoint.getModelIdentifier().equals(IAntDebugConstants.ID_ANT_DEBUG_MODEL)) {
129
		    //need to consider all breakpoints as no way to tell which set
130
		    //of buildfiles will be executed (ant task)
131
		    return true;
132
		}
133
		return false;
134
	}
135
	
136
	/* (non-Javadoc)
137
	 * @see org.eclipse.debug.core.model.IDebugElement#getDebugTarget()
138
	 */
139
	public IDebugTarget getDebugTarget() {
140
		return this;
141
	}
142
	
143
	/* (non-Javadoc)
144
	 * @see org.eclipse.debug.core.model.IDebugElement#getLaunch()
145
	 */
146
	public ILaunch getLaunch() {
147
		return fLaunch;
148
	}
149
	
150
	/* (non-Javadoc)
151
	 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
152
	 */
153
	public boolean canTerminate() {
154
		return !fTerminated;
155
	}
156
	
157
	/* (non-Javadoc)
158
	 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
159
	 */
160
	public boolean isTerminated() {
161
		return fTerminated;
162
	}
163
	
164
	/* (non-Javadoc)
165
	 * @see org.eclipse.debug.core.model.ITerminate#terminate()
166
	 */
167
	public void terminate() throws DebugException {
168
	    terminated();
169
	}
170
	
171
	/* (non-Javadoc)
172
	 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
173
	 */
174
	public boolean canResume() {
175
		return !isTerminated() && isSuspended();
176
	}
177
	
178
	/* (non-Javadoc)
179
	 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
180
	 */
181
	public boolean canSuspend() {
182
		return !isTerminated() && !isSuspended();
183
	}
184
	
185
	/* (non-Javadoc)
186
	 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
187
	 */
188
	public boolean isSuspended() {
189
		return fSuspended;
190
	}
191
	
192
	/* (non-Javadoc)
193
	 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
194
	 */
195
	public void resume() throws DebugException {
196
	    fSuspended= false;
197
	    fController.resume();
198
	}
199
	
200
	/**
201
	 * Notification the target has suspended for the given reason
202
	 * 
203
	 * @param detail reason for the suspend
204
	 */
205
	public void suspended(int detail) {
206
		fSuspended = true;
207
		fThread.setStepping(false);
208
		fThread.fireSuspendEvent(detail);
209
	}	
210
	
211
	/* (non-Javadoc)
212
	 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
213
	 */
214
	public void suspend() throws DebugException {
215
		fController.suspend();
216
	}
217
	
218
	/* (non-Javadoc)
219
	 * @see org.eclipse.debug.core.IBreakpointListener#breakpointAdded(org.eclipse.debug.core.model.IBreakpoint)
220
	 */
221
	public void breakpointAdded(IBreakpoint breakpoint) {
222
		fController.handleBreakpoint(breakpoint, true);
223
        if (breakpoint instanceof AntLineBreakpoint) {
224
            if (((AntLineBreakpoint) breakpoint).isRunToLine()) {
225
                if (fRunToLineBreakpoints == null) {
226
                    fRunToLineBreakpoints= new ArrayList();
227
                }
228
                fRunToLineBreakpoints.add(breakpoint);
229
            }
230
        }
231
	}
232
233
    /* (non-Javadoc)
234
	 * @see org.eclipse.debug.core.IBreakpointListener#breakpointRemoved(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
235
	 */
236
	public void breakpointRemoved(IBreakpoint breakpoint, IMarkerDelta delta) {
237
		fController.handleBreakpoint(breakpoint, false);
238
        if (fRunToLineBreakpoints != null) {
239
            if (fRunToLineBreakpoints.remove(breakpoint) && fRunToLineBreakpoints.isEmpty()) {
240
                fRunToLineBreakpoints= null;
241
            }
242
        }
243
	}
244
	
245
	/* (non-Javadoc)
246
	 * @see org.eclipse.debug.core.IBreakpointListener#breakpointChanged(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.resources.IMarkerDelta)
247
	 */
248
	public void breakpointChanged(IBreakpoint breakpoint, IMarkerDelta delta) {
249
		if (supportsBreakpoint(breakpoint)) {
250
			try {
251
				if (breakpoint.isEnabled() && DebugPlugin.getDefault().getBreakpointManager().isEnabled()) {
252
					breakpointAdded(breakpoint);
253
				} else {
254
					breakpointRemoved(breakpoint, null);
255
				}
256
			} catch (CoreException e) {
257
			}
258
		}
259
	}
260
	
261
	/* (non-Javadoc)
262
	 * @see org.eclipse.debug.core.model.IDisconnect#canDisconnect()
263
	 */
264
	public boolean canDisconnect() {
265
		return false;
266
	}
267
	
268
	/* (non-Javadoc)
269
	 * @see org.eclipse.debug.core.model.IDisconnect#disconnect()
270
	 */
271
	public void disconnect() throws DebugException {
272
	}
273
	
274
	/* (non-Javadoc)
275
	 * @see org.eclipse.debug.core.model.IDisconnect#isDisconnected()
276
	 */
277
	public boolean isDisconnected() {
278
		return false;
279
	}
280
	
281
	/* (non-Javadoc)
282
	 * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#supportsStorageRetrieval()
283
	 */
284
	public boolean supportsStorageRetrieval() {
285
		return false;
286
	}
287
	
288
	/* (non-Javadoc)
289
	 * @see org.eclipse.debug.core.model.IMemoryBlockRetrieval#getMemoryBlock(long, long)
290
	 */
291
	public IMemoryBlock getMemoryBlock(long startAddress, long length) throws DebugException {
292
		return null;
293
	}
294
295
	/**
296
	 * Notification we have connected to the Ant build logger and it has started.
297
	 * Resume the build.
298
	 */
299
	public void buildStarted() {
300
		fireCreationEvent();
301
		installDeferredBreakpoints();
302
		try {
303
			resume();
304
		} catch (DebugException e) {
305
		}
306
	}
307
	
308
	/**
309
	 * Install breakpoints that are already registered with the breakpoint
310
	 * manager if the breakpoint manager is enabled and the breakpoint is enabled.
311
	 */
312
	private void installDeferredBreakpoints() {
313
		IBreakpointManager manager= DebugPlugin.getDefault().getBreakpointManager();
314
		if (!manager.isEnabled()) {
315
			return;
316
		}
317
		IBreakpoint[] breakpoints = manager.getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
318
		for (int i = 0; i < breakpoints.length; i++) {
319
            IBreakpoint breakpoint= breakpoints[i];
320
            try {
321
                if (breakpoint.isEnabled()) {
322
                    breakpointAdded(breakpoints[i]);
323
                }
324
            } catch (CoreException e) {
325
            }
326
		}
327
	}
328
	
329
	/**
330
	 * Called when this debug target terminates.
331
	 */
332
	protected void terminated() {
333
		fThreads= new IThread[0];
334
		fTerminated = true;
335
		fSuspended = false;
336
		if (DebugPlugin.getDefault() != null) {
337
			DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this);
338
			DebugPlugin.getDefault().removeDebugEventListener(this);
339
			DebugPlugin.getDefault().getBreakpointManager().removeBreakpointManagerListener(this);
340
		}
341
		if (!getProcess().isTerminated()) {
342
		    try {
343
                fProcess.terminate();
344
                resume();
345
		    } catch (DebugException e) {       
346
		    }
347
		}
348
		if (DebugPlugin.getDefault() != null) {
349
			fireTerminateEvent();
350
		}
351
	}
352
	
353
	/**
354
	 * Single step the Ant build.
355
	 * 
356
	 * @throws DebugException if the request fails
357
	 */
358
	protected void stepOver() {
359
	    fSuspended= false;
360
		fController.stepOver();
361
	}
362
	
363
	/**
364
	 * Step-into the Ant build.
365
	 * 
366
	 * @throws DebugException if the request fails
367
	 */
368
	protected void stepInto() {
369
	    fSuspended= false;
370
	    fController.stepInto();
371
	}
372
	
373
	/**
374
	 * Notification a breakpoint was encountered. Determine
375
	 * which breakpoint was hit and fire a suspend event.
376
	 * 
377
	 * @param event debug event
378
	 */
379
	protected void breakpointHit(String event) {
380
		// determine which breakpoint was hit, and set the thread's breakpoint
381
		String[] datum= event.split(DebugMessageIds.MESSAGE_DELIMITER);
382
		String fileName= datum[1];
383
		int lineNumber = Integer.parseInt(datum[2]);
384
		IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
385
        boolean found= false;
386
		for (int i = 0; i < breakpoints.length; i++) {
387
           ILineBreakpoint lineBreakpoint = (ILineBreakpoint)breakpoints[i];
388
           if (setThreadBreakpoint(lineBreakpoint, lineNumber, fileName)) {
389
               found= true;
390
               break;
391
           }
392
		}
393
        if (!found && fRunToLineBreakpoints != null) {
394
            Iterator iter= fRunToLineBreakpoints.iterator();
395
            while (iter.hasNext()) {
396
                ILineBreakpoint lineBreakpoint = (ILineBreakpoint) iter.next();
397
                if (setThreadBreakpoint(lineBreakpoint, lineNumber, fileName)) {
398
                    break;
399
                }
400
            }
401
        }
402
		suspended(DebugEvent.BREAKPOINT);
403
	}	
404
    
405
    private boolean setThreadBreakpoint(ILineBreakpoint lineBreakpoint, int lineNumber, String fileName) {
406
        try {
407
            if (lineBreakpoint.getLineNumber() == lineNumber && 
408
                    fileName.equals(lineBreakpoint.getMarker().getResource().getLocation().toOSString())) {
409
                fThread.setBreakpoints(new IBreakpoint[]{lineBreakpoint});
410
                return true;
411
            }
412
        } catch (CoreException e) {
413
        }
414
        return false;
415
    }
416
	
417
    public void breakpointHit (IBreakpoint breakpoint) {
418
        fThread.setBreakpoints(new IBreakpoint[]{breakpoint});
419
        suspended(DebugEvent.BREAKPOINT);
420
    }
421
    
422
	protected void getStackFrames() {
423
		fController.getStackFrames();
424
	}
425
	
426
	protected void getProperties() {
427
		fController.getProperties();
428
	}
429
430
    /* (non-Javadoc)
431
     * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
432
     */
433
    public void handleDebugEvents(DebugEvent[] events) {
434
        for (int i = 0; i < events.length; i++) {
435
            DebugEvent event = events[i];
436
            if (event.getKind() == DebugEvent.TERMINATE && event.getSource().equals(fProcess)) {
437
                terminated();
438
            }
439
        }
440
    }
441
    
442
    /**
443
     * When the breakpoint manager disables, remove all registered breakpoints
444
     * requests from the VM. When it enables, reinstall them.
445
     *
446
     * @see org.eclipse.debug.core.IBreakpointManagerListener#breakpointManagerEnablementChanged(boolean)
447
     */
448
    public void breakpointManagerEnablementChanged(boolean enabled) {
449
        IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
450
        for (int i = 0; i < breakpoints.length; i++) {
451
            IBreakpoint breakpoint = breakpoints[i];
452
            if (enabled) {
453
                breakpointAdded(breakpoint);
454
            } else {
455
                breakpointRemoved(breakpoint, null);
456
            }
457
        }
458
    }
459
460
	public IAntDebugController getAntDebugController() {
461
		return fController;
462
	}   
463
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntLineBreakpoint.java (-112 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug.model;
12
13
import com.ibm.icu.text.MessageFormat;
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
18
import org.eclipse.core.resources.IMarker;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IWorkspaceRunnable;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.debug.core.DebugException;
24
import org.eclipse.debug.core.DebugPlugin;
25
import org.eclipse.debug.core.model.IBreakpoint;
26
import org.eclipse.debug.core.model.LineBreakpoint;
27
28
/**
29
 * Ant line breakpoint
30
 */
31
public class AntLineBreakpoint extends LineBreakpoint {
32
	
33
	/**
34
	 * Default constructor is required for the breakpoint manager
35
	 * to re-create persisted breakpoints. After instantiating a breakpoint,
36
	 * the <code>setMarker(...)</code> method is called to restore
37
	 * this breakpoint's attributes.
38
	 */
39
	public AntLineBreakpoint() {
40
	}
41
	
42
	/**
43
	 * Constructs a line breakpoint on the given resource at the given
44
	 * line number. The line number is 1-based (i.e. the first line of a
45
	 * file is line number 1).
46
	 * 
47
	 * @param resource file on which to set the breakpoint
48
	 * @param lineNumber 1-based line number of the breakpoint
49
	 * @throws CoreException if unable to create the breakpoint
50
	 */
51
	public AntLineBreakpoint(IResource resource, int lineNumber) throws CoreException {
52
	    this(resource, lineNumber, new HashMap(), true);
53
	}
54
	
55
	/**
56
	 * Constructs a line breakpoint on the given resource at the given
57
	 * line number. The line number is 1-based (i.e. the first line of a
58
	 * file is line number 1).
59
	 * 
60
	 * @param resource file on which to set the breakpoint
61
	 * @param lineNumber 1-based line number of the breakpoint
62
	 * @param attributes the marker attributes to set
63
	 * @param register whether to add this breakpoint to the breakpoint manager
64
	 * @throws CoreException if unable to create the breakpoint
65
	 */
66
	public AntLineBreakpoint(final IResource resource, final int lineNumber, final Map attributes, final boolean register) throws CoreException {
67
	    IWorkspaceRunnable wr= new IWorkspaceRunnable() {
68
			public void run(IProgressMonitor monitor) throws CoreException {
69
			    IMarker marker = resource.createMarker(IAntDebugConstants.ID_ANT_LINE_BREAKPOINT_MARKER);
70
			    setMarker(marker);
71
			    attributes.put(IBreakpoint.ENABLED, Boolean.TRUE);
72
			    attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber));
73
			    attributes.put(IBreakpoint.ID, IAntDebugConstants.ID_ANT_DEBUG_MODEL);
74
                attributes.put(IMarker.MESSAGE, MessageFormat.format(DebugModelMessages.AntLineBreakpoint_0, new String[] {Integer.toString(lineNumber)}));
75
			    ensureMarker().setAttributes(attributes);
76
                
77
                register(register);
78
			}
79
	    };
80
	    run(getMarkerRule(resource), wr);
81
	}
82
	
83
	/* (non-Javadoc)
84
	 * @see org.eclipse.debug.core.model.IBreakpoint#getModelIdentifier()
85
	 */
86
	public String getModelIdentifier() {
87
		return IAntDebugConstants.ID_ANT_DEBUG_MODEL;
88
	}
89
90
    /**
91
     * @return whether this breakpoint is a run to line breakpoint
92
     */
93
    public boolean isRunToLine() {
94
        try {
95
            return ensureMarker().getAttribute(IAntDebugConstants.ANT_RUN_TO_LINE, false);
96
        } catch (DebugException e) {
97
           return false;
98
        }
99
    }
100
    
101
    /**
102
     * Add this breakpoint to the breakpoint manager,
103
     * or sets it as unregistered.
104
     */
105
    private void register(boolean register) throws CoreException {
106
        if (register) {
107
            DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(this);
108
        } else {
109
            setRegistered(false);
110
        }
111
    }
112
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntProperties.java (-109 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug.model;
12
13
import org.eclipse.debug.core.DebugException;
14
import org.eclipse.debug.core.model.IValue;
15
import org.eclipse.debug.core.model.IVariable;
16
17
public class AntProperties extends AntDebugElement implements IVariable {
18
	
19
	private IValue fValue;
20
	private String fName;
21
    private boolean fValid= true;
22
23
	public AntProperties(AntDebugTarget target, String name) {
24
		super(target);
25
		fName= name;
26
	}
27
28
	/* (non-Javadoc)
29
	 * @see org.eclipse.debug.core.model.IVariable#getValue()
30
	 */
31
	public synchronized IValue getValue() throws DebugException {
32
        int attempts= 0;
33
        while (!fValid && !getDebugTarget().isTerminated()) {
34
            try {
35
                wait(50);
36
            } catch (InterruptedException e) {
37
            }
38
            if (attempts == 20 && !fValid && !getDebugTarget().isTerminated()) {
39
                throwDebugException(DebugModelMessages.AntProperties_1);
40
            }
41
            attempts++;
42
        }
43
 		return fValue;
44
	}
45
    
46
    protected IValue getLastValue() {
47
        return fValue;
48
    }
49
50
	/* (non-Javadoc)
51
	 * @see org.eclipse.debug.core.model.IVariable#getName()
52
	 */
53
	public String getName() {
54
		return fName;
55
	}
56
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
59
	 */
60
	public String getReferenceTypeName() {
61
		return ""; //$NON-NLS-1$
62
	}
63
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
66
	 */
67
	public boolean hasValueChanged() {
68
		return false;
69
	}
70
71
	/* (non-Javadoc)
72
	 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
73
	 */
74
	public void setValue(String expression) {
75
	}
76
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
79
	 */
80
	public void setValue(IValue value) {
81
		fValue= value;
82
	}
83
84
	/* (non-Javadoc)
85
	 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
86
	 */
87
	public boolean supportsValueModification() {
88
		return false;
89
	}
90
91
	/* (non-Javadoc)
92
	 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
93
	 */
94
	public boolean verifyValue(String expression) {
95
		return false;
96
	}
97
98
	/* (non-Javadoc)
99
	 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
100
	 */
101
	public boolean verifyValue(IValue value) {
102
		return false;
103
	}
104
105
    protected synchronized void setValid(boolean valid) {
106
        fValid= valid;        
107
        notifyAll();
108
    }
109
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntPropertiesValue.java (-71 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Brock Janiczak (brockj@tpg.com.au) - bug 154907
11
 *******************************************************************************/
12
package org.eclipse.ant.internal.ui.debug.model;
13
14
import java.util.ArrayList;
15
import java.util.Collections;
16
import java.util.List;
17
import org.eclipse.debug.core.model.IValue;
18
import org.eclipse.debug.core.model.IVariable;
19
20
public class AntPropertiesValue extends AntDebugElement implements IValue {
21
	
22
	private List fProperties= new ArrayList();
23
	
24
	public AntPropertiesValue(AntDebugTarget target) {
25
		super(target);
26
	}
27
	
28
	/* (non-Javadoc)
29
	 * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
30
	 */
31
	public String getReferenceTypeName() {
32
		return ""; //$NON-NLS-1$
33
	}
34
	
35
	/* (non-Javadoc)
36
	 * @see org.eclipse.debug.core.model.IValue#getValueString()
37
	 */
38
	public String getValueString() {
39
		return ""; //$NON-NLS-1$
40
	}
41
	
42
	/* (non-Javadoc)
43
	 * @see org.eclipse.debug.core.model.IValue#isAllocated()
44
	 */
45
	public boolean isAllocated() {
46
		return true;
47
	}
48
	
49
	/* (non-Javadoc)
50
	 * @see org.eclipse.debug.core.model.IValue#getVariables()
51
	 */
52
	public IVariable[] getVariables() {
53
		Collections.sort(fProperties);
54
		return (IVariable[])fProperties.toArray(new IVariable[fProperties.size()]);
55
	}
56
	
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.debug.core.model.IValue#hasVariables()
59
	 */
60
	public boolean hasVariables() {
61
		return true;
62
	}
63
	
64
	protected void addProperties(List properties) {
65
		fProperties.addAll(properties);
66
	}
67
68
	protected List getProperties() {
69
		return fProperties;
70
	}
71
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntProperty.java (-121 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Brock Janiczak (brockj@tpg.com.au) - bug 154907
11
 *******************************************************************************/
12
package org.eclipse.ant.internal.ui.debug.model;
13
14
import org.eclipse.debug.core.model.IValue;
15
import org.eclipse.debug.core.model.IVariable;
16
17
/**
18
 * A property in an Ant build.
19
 */
20
public class AntProperty extends AntDebugElement implements IVariable, Comparable {
21
22
	private String fName;
23
	private AntValue fValue;
24
    private String fLabel;
25
	
26
	/**
27
	 * Constructs a variable associated with the debug target
28
	 * with the given name and value.
29
	 * 
30
	 * @param target the debug target
31
	 * @param name property name
32
	 * @param value property value
33
	 */
34
	public AntProperty(AntDebugTarget target, String name, String value) {
35
		super(target);
36
		fName = name;
37
		fValue= new AntValue(target, value);
38
	}
39
	
40
	/*
41
	 * @see org.eclipse.debug.core.model.IVariable#getValue()
42
	 */
43
	public IValue getValue() {
44
		return fValue;
45
	}
46
	
47
	/*
48
	 * @see org.eclipse.debug.core.model.IVariable#getName()
49
	 */
50
	public String getName() {
51
		return fName;
52
	}
53
	
54
	/*
55
	 * @see org.eclipse.debug.core.model.IVariable#getReferenceTypeName()
56
	 */
57
	public String getReferenceTypeName() {
58
		return ""; //$NON-NLS-1$
59
	}
60
	
61
	/*
62
	 * @see org.eclipse.debug.core.model.IVariable#hasValueChanged()
63
	 */
64
	public boolean hasValueChanged() {
65
		return false;
66
	}
67
	
68
	/*
69
	 * @see org.eclipse.debug.core.model.IValueModification#setValue(java.lang.String)
70
	 */
71
	public void setValue(String expression) {
72
	}
73
	
74
	/*
75
	 * @see org.eclipse.debug.core.model.IValueModification#setValue(org.eclipse.debug.core.model.IValue)
76
	 */
77
	public void setValue(IValue value) {
78
	}
79
	
80
	/*
81
	 * @see org.eclipse.debug.core.model.IValueModification#supportsValueModification()
82
	 */
83
	public boolean supportsValueModification() {
84
		return false;
85
	}
86
	
87
	/*
88
	 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(java.lang.String)
89
	 */
90
	public boolean verifyValue(String expression) {
91
		return false;
92
	}
93
	
94
	/*
95
	 * @see org.eclipse.debug.core.model.IValueModification#verifyValue(org.eclipse.debug.core.model.IValue)
96
	 */
97
	public boolean verifyValue(IValue value) {
98
		return false;
99
	}
100
101
    /**
102
     * @return the text used to render this property
103
     */
104
    public String getText() {
105
        if (fLabel == null) {
106
            StringBuffer buffer= new StringBuffer(getName());
107
            buffer.append("= "); //$NON-NLS-1$
108
            buffer.append(fValue.getValueString());          
109
            fLabel=  buffer.toString();
110
        } 
111
        return fLabel;
112
    }
113
    
114
    /*
115
     * @see java.lang.Comparable#compareTo(java.lang.Object)
116
     */
117
    public int compareTo(Object other) {
118
    	AntProperty otherProperty = (AntProperty) other;
119
    	return fName.compareToIgnoreCase(otherProperty.getName());
120
    }
121
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntStackFrame.java (-314 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug.model;
12
13
import org.eclipse.ant.internal.ui.AntUtil;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.runtime.Path;
16
import org.eclipse.debug.core.DebugException;
17
import org.eclipse.debug.core.model.IRegisterGroup;
18
import org.eclipse.debug.core.model.IStackFrame;
19
import org.eclipse.debug.core.model.IThread;
20
import org.eclipse.debug.core.model.IVariable;
21
22
/**
23
 * Ant stack frame.
24
 */
25
public class AntStackFrame extends AntDebugElement implements IStackFrame {
26
	
27
	private AntThread fThread;
28
	private String fName;
29
	private int fLineNumber;
30
	private String fFilePath;
31
	private int fId;
32
    private String fFullPath;
33
	
34
	/**
35
	 * Constructs a stack frame in the given thread with the given id.
36
	 * 
37
	 * @param thread
38
	 * @param id stack frame id (0 is the top of the stack)
39
	 */
40
	public AntStackFrame(AntThread thread, int id, String name, String fullPath, int lineNumber) {
41
		super((AntDebugTarget) thread.getDebugTarget());
42
		fId = id;
43
		fThread = thread;
44
		fLineNumber= lineNumber;
45
		fName= name;
46
		setFilePath(fullPath);
47
	}
48
	
49
	protected void setId(int id) {
50
		fId= id;
51
	}
52
	
53
	/* (non-Javadoc)
54
	 * @see org.eclipse.debug.core.model.IStackFrame#getThread()
55
	 */
56
	public IThread getThread() {
57
		return fThread;
58
	}
59
	
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.debug.core.model.IStackFrame#getVariables()
62
	 */
63
	public IVariable[] getVariables() throws DebugException {
64
	   return fThread.getVariables();
65
	}
66
67
    /* (non-Javadoc)
68
	 * @see org.eclipse.debug.core.model.IStackFrame#hasVariables()
69
	 */
70
	public boolean hasVariables() {
71
		return isSuspended();
72
	}
73
	
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.debug.core.model.IStackFrame#getLineNumber()
76
	 */
77
	public int getLineNumber() {
78
		return fLineNumber;
79
	}
80
	
81
	protected void setLineNumber(int lineNumber) {
82
		fLineNumber= lineNumber;
83
	}
84
	
85
	protected void setFilePath(String fullPath) {
86
        fFullPath= fullPath;
87
        IFile file= AntUtil.getFileForLocation(fullPath, null);
88
        if (file != null) {
89
            fFilePath= file.getProjectRelativePath().toString();
90
        } else {
91
            fFilePath= new Path(fullPath).lastSegment();
92
        }
93
	}
94
	
95
	public String getFilePath() {
96
		return fFullPath;
97
	}
98
	
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.debug.core.model.IStackFrame#getCharStart()
101
	 */
102
	public int getCharStart() {
103
		return -1;
104
	}
105
	
106
	/* (non-Javadoc)
107
	 * @see org.eclipse.debug.core.model.IStackFrame#getCharEnd()
108
	 */
109
	public int getCharEnd() {
110
		return -1;
111
	}
112
	
113
	/* (non-Javadoc)
114
	 * @see org.eclipse.debug.core.model.IStackFrame#getName()
115
	 */
116
	public String getName() {
117
		return fName;
118
	}
119
	
120
	protected void setName(String name) {
121
		fName= name;
122
	}
123
	
124
	/* (non-Javadoc)
125
	 * @see org.eclipse.debug.core.model.IStackFrame#getRegisterGroups()
126
	 */
127
	public IRegisterGroup[] getRegisterGroups() {
128
		return null;
129
	}
130
	
131
	/* (non-Javadoc)
132
	 * @see org.eclipse.debug.core.model.IStackFrame#hasRegisterGroups()
133
	 */
134
	public boolean hasRegisterGroups() {
135
		return false;
136
	}
137
	
138
	/* (non-Javadoc)
139
	 * @see org.eclipse.debug.core.model.IStep#canStepInto()
140
	 */
141
	public boolean canStepInto() {
142
		return getThread().canStepInto();
143
	}
144
	
145
	/* (non-Javadoc)
146
	 * @see org.eclipse.debug.core.model.IStep#canStepOver()
147
	 */
148
	public boolean canStepOver() {
149
		return getThread().canStepOver();
150
	}
151
	
152
	/* (non-Javadoc)
153
	 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
154
	 */
155
	public boolean canStepReturn() {
156
		return getThread().canStepReturn();
157
	}
158
	
159
	/* (non-Javadoc)
160
	 * @see org.eclipse.debug.core.model.IStep#isStepping()
161
	 */
162
	public boolean isStepping() {
163
		return getThread().isStepping();
164
	}
165
	
166
	/* (non-Javadoc)
167
	 * @see org.eclipse.debug.core.model.IStep#stepInto()
168
	 */
169
	public void stepInto() throws DebugException {
170
		getThread().stepInto();
171
	}
172
	
173
	/* (non-Javadoc)
174
	 * @see org.eclipse.debug.core.model.IStep#stepOver()
175
	 */
176
	public void stepOver() throws DebugException {
177
		getThread().stepOver();
178
	}
179
	
180
	/* (non-Javadoc)
181
	 * @see org.eclipse.debug.core.model.IStep#stepReturn()
182
	 */
183
	public void stepReturn() throws DebugException {
184
		getThread().stepReturn();
185
	}
186
	
187
	/* (non-Javadoc)
188
	 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
189
	 */
190
	public boolean canResume() {
191
		return getThread().canResume();
192
	}
193
	
194
	/* (non-Javadoc)
195
	 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
196
	 */
197
	public boolean canSuspend() {
198
		return getThread().canSuspend();
199
	}
200
	
201
	/* (non-Javadoc)
202
	 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
203
	 */
204
	public boolean isSuspended() {
205
		return getThread().isSuspended();
206
	}
207
	
208
	/* (non-Javadoc)
209
	 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
210
	 */
211
	public void resume() throws DebugException {
212
		getThread().resume();
213
	}
214
	
215
	/* (non-Javadoc)
216
	 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
217
	 */
218
	public void suspend() throws DebugException {
219
		getThread().suspend();
220
	}
221
	
222
	/* (non-Javadoc)
223
	 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
224
	 */
225
	public boolean canTerminate() {
226
		return getThread().canTerminate();
227
	}
228
	
229
	/* (non-Javadoc)
230
	 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
231
	 */
232
	public boolean isTerminated() {
233
		return getThread().isTerminated();
234
	}
235
	
236
	/* (non-Javadoc)
237
	 * @see org.eclipse.debug.core.model.ITerminate#terminate()
238
	 */
239
	public void terminate() throws DebugException {
240
		getThread().terminate();
241
	}
242
	
243
	/**
244
	 * Returns the name of the buildfile this stack frame is associated
245
	 * with.
246
	 * 
247
	 * @return the name of the buildfile this stack frame is associated
248
	 * with
249
	 */
250
	public String getSourceName() {
251
		return fFilePath;
252
	}
253
	
254
	/* (non-Javadoc)
255
	 * @see java.lang.Object#equals(java.lang.Object)
256
	 */
257
	public boolean equals(Object obj) {
258
		if (obj instanceof AntStackFrame) {
259
			AntStackFrame sf = (AntStackFrame)obj;
260
			if (getSourceName() != null) {
261
				return getSourceName().equals(sf.getSourceName()) &&
262
					sf.getLineNumber() == getLineNumber() &&
263
					sf.fId == fId;
264
			} 
265
			return sf.fId == fId;
266
		}
267
		return false;
268
	}
269
	
270
	/* (non-Javadoc)
271
	 * @see java.lang.Object#hashCode()
272
	 */
273
	public int hashCode() {
274
	    if (getSourceName() == null) {
275
	        return fId;
276
	    }
277
	    return getSourceName().hashCode() + fId;
278
	}
279
	
280
	/**
281
	 * Returns this stack frame's unique identifier within its thread
282
	 * 
283
	 * @return this stack frame's unique identifier within its thread
284
	 */
285
	protected int getIdentifier() {
286
		return fId;
287
	}
288
    
289
    /**
290
     * Returns the system, user or runtime property
291
     * name, or <code>null</code> if unable to resolve a property with the name.
292
     *
293
     * @param propertyName the name of the variable to search for
294
     * @return a property, or <code>null</code> if none
295
     */
296
    public AntProperty findProperty(String propertyName) {
297
        try {
298
            IVariable[] groups= getVariables();
299
            for (int i = 0; i < groups.length; i++) {
300
                AntProperties propertiesGrouping = (AntProperties) groups[i];
301
                AntPropertiesValue value= (AntPropertiesValue) propertiesGrouping.getValue();
302
                IVariable[] properties= value.getVariables();
303
                for (int j = 0; j < properties.length; j++) {
304
                    AntProperty property = (AntProperty) properties[j];
305
                    if (property.getName().equals(propertyName)) {
306
                        return property;
307
                    }
308
                }
309
            }
310
        } catch (DebugException e) {
311
        }
312
        return null;
313
    } 
314
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntThread.java (-479 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug.model;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.debug.core.DebugEvent;
17
import org.eclipse.debug.core.DebugException;
18
import org.eclipse.debug.core.model.IBreakpoint;
19
import org.eclipse.debug.core.model.IStackFrame;
20
import org.eclipse.debug.core.model.IThread;
21
import org.eclipse.debug.core.model.IVariable;
22
23
/**
24
 * An Ant build thread.
25
 */
26
public class AntThread extends AntDebugElement implements IThread {
27
	
28
	/**
29
	 * Breakpoints this thread is suspended at or <code>null</code>
30
	 * if none.
31
	 */
32
	private IBreakpoint[] fBreakpoints;
33
	
34
	/**
35
	 * The stackframes associated with this thread
36
	 */
37
	private List fFrames= new ArrayList(1);
38
	
39
	/**
40
	 * The stackframes to be reused on suspension
41
	 */
42
	private List fOldFrames;
43
	
44
	/**
45
	 * Whether this thread is stepping
46
	 */
47
	private boolean fStepping = false;
48
	
49
	private boolean fRefreshProperties= true;
50
	
51
	/**
52
	 * The user properties associated with this thread
53
	 */
54
	private AntProperties fUserProperties;
55
	
56
	/**
57
	 * The system properties associated with this thread
58
	 */
59
	private AntProperties fSystemProperties;
60
	
61
	/**
62
	 * The properties set during the build associated with this thread
63
	 */
64
	private AntProperties fRuntimeProperties;
65
    
66
    private Object fPropertiesLock= new Object();
67
	
68
	/**
69
	 * Constructs a new thread for the given target
70
	 * 
71
	 * @param target the Ant Build
72
	 */
73
	public AntThread(AntDebugTarget target) {
74
		super(target);
75
	}
76
	
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.debug.core.model.IThread#getStackFrames()
79
	 */
80
	public synchronized IStackFrame[] getStackFrames() throws DebugException {
81
		if (isSuspended()) {
82
			if (fFrames.size() == 0) {
83
				getStackFrames0();
84
			}
85
		} 
86
		
87
		return (IStackFrame[]) fFrames.toArray(new IStackFrame[fFrames.size()]);
88
	}
89
	
90
	/**
91
	 * Retrieves the current stack frames in the thread
92
	 * possibly waiting until the frames are populated
93
     * 
94
	 */
95
	private void getStackFrames0() throws DebugException {
96
        synchronized (fFrames) {
97
    		getAntDebugTarget().getStackFrames();
98
            if (fFrames.size() > 0) {
99
                //frames set..no need to wait
100
                return;
101
            }
102
            int attempts= 0;
103
    		try {
104
                while (fFrames.size() == 0 && !isTerminated()) {
105
                    fFrames.wait(50);
106
                    if (attempts == 20 && fFrames.size() == 0 && !isTerminated()) {
107
                        throwDebugException(DebugModelMessages.AntThread_3);
108
                    }
109
                    attempts++;
110
                }
111
    		} catch (InterruptedException e) {
112
    		}
113
        }
114
	}
115
	
116
	/* (non-Javadoc)
117
	 * @see org.eclipse.debug.core.model.IThread#hasStackFrames()
118
	 */
119
	public boolean hasStackFrames() throws DebugException {
120
		return isSuspended();
121
	}
122
	
123
	/* (non-Javadoc)
124
	 * @see org.eclipse.debug.core.model.IThread#getPriority()
125
	 */
126
	public int getPriority() throws DebugException {
127
		return 0;
128
	}
129
	
130
	/* (non-Javadoc)
131
	 * @see org.eclipse.debug.core.model.IThread#getTopStackFrame()
132
	 */
133
	public synchronized IStackFrame getTopStackFrame() throws DebugException {
134
		if (isSuspended()) {
135
			if (fFrames.size() == 0) {
136
				getStackFrames0();
137
			}
138
			if (fFrames.size() > 0) {
139
				return (IStackFrame)fFrames.get(0);
140
			}
141
		} 
142
		return null;
143
	}
144
	
145
	/* (non-Javadoc)
146
	 * @see org.eclipse.debug.core.model.IThread#getName()
147
	 */
148
	public String getName() {
149
		return "Thread [Ant Build]"; //$NON-NLS-1$
150
	}
151
	
152
	/* (non-Javadoc)
153
	 * @see org.eclipse.debug.core.model.IThread#getBreakpoints()
154
	 */
155
	public IBreakpoint[] getBreakpoints() {
156
		if (fBreakpoints == null) {
157
			return new IBreakpoint[0];
158
		}
159
		return fBreakpoints;
160
	}
161
	
162
	/**
163
	 * Sets the breakpoints this thread is suspended at, or <code>null</code>
164
	 * if none.
165
	 * 
166
	 * @param breakpoints the breakpoints this thread is suspended at, or <code>null</code>
167
	 * if none
168
	 */
169
	protected void setBreakpoints(IBreakpoint[] breakpoints) {
170
		fBreakpoints = breakpoints;
171
	}
172
	
173
	/* (non-Javadoc)
174
	 * @see org.eclipse.debug.core.model.ISuspendResume#canResume()
175
	 */
176
	public boolean canResume() {
177
		return isSuspended();
178
	}
179
	
180
	/* (non-Javadoc)
181
	 * @see org.eclipse.debug.core.model.ISuspendResume#canSuspend()
182
	 */
183
	public boolean canSuspend() {
184
		return !isSuspended();
185
	}
186
	
187
	/* (non-Javadoc)
188
	 * @see org.eclipse.debug.core.model.ISuspendResume#isSuspended()
189
	 */
190
	public boolean isSuspended() {
191
		return getDebugTarget().isSuspended();
192
	}
193
	
194
	/* (non-Javadoc)
195
	 * @see org.eclipse.debug.core.model.ISuspendResume#resume()
196
	 */
197
	public synchronized void resume() throws DebugException {
198
		aboutToResume(DebugEvent.CLIENT_REQUEST, false);
199
		getDebugTarget().resume();
200
	}
201
	
202
	/* (non-Javadoc)
203
	 * @see org.eclipse.debug.core.model.ISuspendResume#suspend()
204
	 */
205
	public synchronized void suspend() throws DebugException {
206
		getDebugTarget().suspend();
207
	}
208
	
209
	/* (non-Javadoc)
210
	 * @see org.eclipse.debug.core.model.IStep#canStepInto()
211
	 */
212
	public boolean canStepInto() {
213
	    return isSuspended();
214
	}
215
	
216
	/* (non-Javadoc)
217
	 * @see org.eclipse.debug.core.model.IStep#canStepOver()
218
	 */
219
	public boolean canStepOver() {
220
		return isSuspended();
221
	}
222
	
223
	/* (non-Javadoc)
224
	 * @see org.eclipse.debug.core.model.IStep#canStepReturn()
225
	 */
226
	public boolean canStepReturn() {
227
		return false;
228
	}
229
	
230
	/* (non-Javadoc)
231
	 * @see org.eclipse.debug.core.model.IStep#isStepping()
232
	 */
233
	public boolean isStepping() {
234
		return fStepping;
235
	}
236
	
237
	/* (non-Javadoc)
238
	 * @see org.eclipse.debug.core.model.IStep#stepInto()
239
	 */
240
	public synchronized void stepInto() throws DebugException {
241
	    aboutToResume(DebugEvent.STEP_INTO, true);
242
		((AntDebugTarget)getDebugTarget()).stepInto();
243
	}
244
	
245
	private void aboutToResume(int detail, boolean stepping) {
246
	    fRefreshProperties= true;
247
	    fOldFrames= new ArrayList(fFrames);
248
        fFrames.clear();
249
        setPropertiesValid(false);
250
	    setStepping(stepping);
251
	    setBreakpoints(null);
252
		fireResumeEvent(detail);
253
    }
254
255
    private void setPropertiesValid(boolean valid) {
256
        if (fUserProperties != null) {
257
            fUserProperties.setValid(valid);
258
            fSystemProperties.setValid(valid);
259
            fRuntimeProperties.setValid(valid);
260
        }
261
    }
262
263
    /* (non-Javadoc)
264
	 * @see org.eclipse.debug.core.model.IStep#stepOver()
265
	 */
266
	public synchronized void stepOver() throws DebugException {
267
	    aboutToResume(DebugEvent.STEP_OVER, true);
268
		((AntDebugTarget)getDebugTarget()).stepOver();
269
	}
270
	
271
	/* (non-Javadoc)
272
	 * @see org.eclipse.debug.core.model.IStep#stepReturn()
273
	 */
274
	public synchronized void stepReturn() throws DebugException {
275
	}
276
	
277
	/* (non-Javadoc)
278
	 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
279
	 */
280
	public boolean canTerminate() {
281
		return !isTerminated();
282
	}
283
	
284
	/* (non-Javadoc)
285
	 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
286
	 */
287
	public boolean isTerminated() {
288
		return getDebugTarget().isTerminated();
289
	}
290
	
291
	/* (non-Javadoc)
292
	 * @see org.eclipse.debug.core.model.ITerminate#terminate()
293
	 */
294
	public void terminate() throws DebugException {
295
		fFrames.clear();
296
		getDebugTarget().terminate();
297
	}
298
	
299
	/**
300
	 * Sets whether this thread is stepping
301
	 * 
302
	 * @param stepping whether stepping
303
	 */
304
	protected void setStepping(boolean stepping) {
305
		fStepping = stepping;
306
	}
307
308
    public void buildStack(String data) { 
309
        synchronized (fFrames) {
310
            String[] strings= data.split(DebugMessageIds.MESSAGE_DELIMITER);
311
            //0 STACK message
312
            //1 targetName
313
            //2 taskName
314
            //3 filePath
315
            //4 lineNumber
316
            //5 ...
317
            if (fOldFrames != null && (strings.length - 1)/ 4 != fOldFrames.size()) {
318
                fOldFrames= null; //stack size changed..do not preserve
319
            }
320
            StringBuffer name;
321
            String filePath;
322
            int lineNumber;
323
            int stackFrameId= 0;
324
            String taskName;
325
            for (int i = 1; i < strings.length; i++) {
326
                if (strings[i].length() > 0) {
327
                    name= new StringBuffer(strings[i]);
328
                    taskName= strings[++i];
329
                    if (taskName.length() > 0) {
330
                        name.append(": "); //$NON-NLS-1$
331
                        name.append(taskName);
332
                    }
333
                } else {
334
                    name= new StringBuffer(strings[++i]);
335
                }
336
                filePath= strings[++i];
337
                lineNumber= Integer.parseInt(strings[++i]);
338
                addFrame(stackFrameId++, name.toString(), filePath, lineNumber);
339
            }
340
            //wake up the call from getStackFrames
341
            fFrames.notifyAll();
342
        }
343
    }
344
    
345
    private void addFrame(int stackFrameId, String name, String filePath, int lineNumber) {
346
    	AntStackFrame frame= getOldFrame();
347
    	
348
    	if (frame == null || !frame.getFilePath().equals(filePath)) {
349
    		frame= new AntStackFrame(this, stackFrameId, name, filePath, lineNumber);
350
    	} else {
351
    		frame.setFilePath(filePath);
352
    		frame.setId(stackFrameId);
353
    		frame.setLineNumber(lineNumber);
354
    		frame.setName(name);
355
    	}
356
		fFrames.add(frame);
357
    }
358
    
359
    private AntStackFrame getOldFrame() {
360
    	if (fOldFrames == null) {
361
    		return null;
362
    	}
363
    	AntStackFrame frame= (AntStackFrame) fOldFrames.remove(0);
364
    	if (fOldFrames.isEmpty()) {
365
    		fOldFrames= null;
366
    	}
367
    	return frame;
368
    }
369
    
370
    public void newProperties(String data) {
371
        synchronized (fPropertiesLock) {
372
            try {
373
                String[] datum= data.split(DebugMessageIds.MESSAGE_DELIMITER);
374
                if (fUserProperties == null) {
375
                    initializePropertyGroups();
376
                }
377
378
                List userProperties= ((AntPropertiesValue)fUserProperties.getLastValue()).getProperties();
379
                List systemProperties= ((AntPropertiesValue)fSystemProperties.getLastValue()).getProperties();
380
                List runtimeProperties= ((AntPropertiesValue)fRuntimeProperties.getLastValue()).getProperties();
381
                //0 PROPERTIES message
382
                //1 propertyName length
383
                //2 propertyName
384
                //3 propertyValue length
385
                //3 propertyValue
386
                //4 propertyType
387
                //5 ...
388
                if (datum.length > 1) { //new properties
389
                    StringBuffer propertyName;
390
                    StringBuffer propertyValue;
391
                    int propertyNameLength;
392
                    int propertyValueLength;
393
                    for (int i = 1; i < datum.length; i++) {
394
                        propertyNameLength= Integer.parseInt(datum[i]);
395
                        propertyName= new StringBuffer(datum[++i]);
396
                        while (propertyName.length() != propertyNameLength) {
397
                            propertyName.append(DebugMessageIds.MESSAGE_DELIMITER);
398
                            propertyName.append(datum[++i]);
399
                        }
400
401
                        propertyName= getAntDebugTarget().getAntDebugController().unescapeString(propertyName);
402
403
                        propertyValueLength= Integer.parseInt(datum[++i]);
404
                        if (propertyValueLength == 0 && i + 1 == datum.length) { //bug 81299
405
                            propertyValue= new StringBuffer(""); //$NON-NLS-1$
406
                        } else {
407
                            propertyValue= new StringBuffer(datum[++i]);
408
                        }
409
                        while (propertyValue.length() != propertyValueLength) {
410
                            propertyValue.append(DebugMessageIds.MESSAGE_DELIMITER);
411
                            propertyValue.append(datum[++i]);
412
                        }
413
414
                        propertyValue= getAntDebugTarget().getAntDebugController().unescapeString(propertyValue);
415
416
                        int propertyType= Integer.parseInt(datum[++i]);
417
                        addProperty(userProperties, systemProperties, runtimeProperties, propertyName.toString(), propertyValue.toString(), propertyType);
418
                    }
419
                }
420
            } finally {
421
                fRefreshProperties= false;
422
                setPropertiesValid(true);
423
                //wake up the call from getVariables
424
                fPropertiesLock.notifyAll();
425
            }
426
        }
427
	}
428
429
	private void addProperty(List userProperties, List systemProperties, List runtimeProperties, String propertyName, String propertyValue, int propertyType) {
430
		AntProperty property= new AntProperty((AntDebugTarget) getDebugTarget(), propertyName, propertyValue);
431
		switch (propertyType) {
432
			case DebugMessageIds.PROPERTY_SYSTEM:
433
				systemProperties.add(property);
434
				break;
435
			case DebugMessageIds.PROPERTY_USER:
436
				userProperties.add(property);
437
				break;
438
			case DebugMessageIds.PROPERTY_RUNTIME:
439
				runtimeProperties.add(property);
440
				break;
441
		}
442
	}
443
444
	private void initializePropertyGroups() {
445
        AntDebugTarget target= getAntDebugTarget();
446
		fUserProperties= new AntProperties(target, DebugModelMessages.AntThread_0);
447
		fUserProperties.setValue(new AntPropertiesValue(target));
448
		fSystemProperties= new AntProperties(target, DebugModelMessages.AntThread_1);
449
		fSystemProperties.setValue(new AntPropertiesValue(target));
450
		fRuntimeProperties= new AntProperties(target, DebugModelMessages.AntThread_2);
451
		fRuntimeProperties.setValue(new AntPropertiesValue(target));
452
	}
453
    
454
    protected IVariable[] getVariables() throws DebugException {
455
        synchronized (fPropertiesLock) {
456
            if (fRefreshProperties) {
457
                getAntDebugTarget().getProperties();
458
                if (fRefreshProperties) { 
459
                    //properties have not been set; need to wait
460
                    try {
461
                        int attempts= 0;
462
                        while (fRefreshProperties && !isTerminated()) {
463
                            fPropertiesLock.wait(50);
464
                            if (attempts == 20 && fRefreshProperties && !isTerminated()) {
465
                                throwDebugException(DebugModelMessages.AntThread_4);
466
                            }
467
                            attempts++;
468
                        }
469
                    } catch (InterruptedException ie) {
470
                    }
471
                }
472
            }
473
            if (fSystemProperties == null) {
474
                return new IVariable[0];
475
            }
476
            return new IVariable[]{fSystemProperties, fUserProperties, fRuntimeProperties};
477
        }
478
    }
479
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/AntValue.java (-71 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug.model;
12
13
import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
14
import org.eclipse.debug.core.model.IValue;
15
import org.eclipse.debug.core.model.IVariable;
16
17
public class AntValue extends AntDebugElement implements IValue  {
18
19
    private String fValueString;
20
    protected static final IVariable[] EMPTY = new IVariable[0];
21
    
22
    /**
23
     * @param target
24
     */
25
    public AntValue(AntDebugTarget target, String value) {
26
        super(target);
27
        fValueString= value;
28
    }
29
30
    /* (non-Javadoc)
31
     * @see org.eclipse.debug.core.model.IValue#getReferenceTypeName()
32
     */
33
    public String getReferenceTypeName() {
34
        return ""; //$NON-NLS-1$
35
    }
36
37
    /* (non-Javadoc)
38
     * @see org.eclipse.debug.core.model.IValue#getValueString()
39
     */
40
    public String getValueString() {
41
        return fValueString;
42
    }
43
44
    /* (non-Javadoc)
45
     * @see org.eclipse.debug.core.model.IValue#isAllocated()
46
     */
47
    public boolean isAllocated() {
48
        return true;
49
    }
50
51
    /* (non-Javadoc)
52
     * @see org.eclipse.debug.core.model.IValue#getVariables()
53
     */
54
    public IVariable[] getVariables() {
55
        return EMPTY;
56
    }
57
58
    /* (non-Javadoc)
59
     * @see org.eclipse.debug.core.model.IValue#hasVariables()
60
     */
61
    public boolean hasVariables() {
62
        return false;
63
    }
64
65
    /* (non-Javadoc)
66
     * @see org.eclipse.debug.core.model.IDebugElement#getModelIdentifier()
67
     */
68
    public String getModelIdentifier() {
69
        return IAntDebugConstants.ID_ANT_DEBUG_MODEL;
70
    }
71
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/DebugMessageIds.java (-48 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.debug.model;
12
13
public class DebugMessageIds {
14
	
15
	public final static String MESSAGE_DELIMITER= ","; //$NON-NLS-1$
16
	
17
	public final static String BUILD_STARTED=   "build_started"; //$NON-NLS-1$
18
	public final static String TARGET_STARTED= "target_started"; //$NON-NLS-1$
19
	public final static String TARGET_FINISHED= "target_finished"; //$NON-NLS-1$
20
	public final static String TASK_STARTED= "task_started"; //$NON-NLS-1$
21
	public final static String TASK_FINISHED= "task_finished"; //$NON-NLS-1$
22
	
23
	public final static String STEP= "step"; //$NON-NLS-1$
24
	public final static String STEP_OVER= "step_over"; //$NON-NLS-1$
25
	public final static String STEP_INTO= "step_into"; //$NON-NLS-1$
26
	
27
	public final static String TERMINATE= "terminate"; //$NON-NLS-1$
28
	public final static String TERMINATED= "terminated"; //$NON-NLS-1$
29
	
30
	public final static String SUSPEND= "suspend"; //$NON-NLS-1$
31
	public final static String SUSPENDED= "suspended"; //$NON-NLS-1$
32
	
33
	public final static String RESUME= "resume"; //$NON-NLS-1$
34
	
35
	public final static String STACK= "stack"; //$NON-NLS-1$
36
	
37
	public final static String ADD_BREAKPOINT= "add"; //$NON-NLS-1$
38
	public final static String REMOVE_BREAKPOINT= "remove"; //$NON-NLS-1$
39
	
40
	public final static String CLIENT_REQUEST= "client"; //$NON-NLS-1$
41
	public final static String BREAKPOINT= "breakpoint"; //$NON-NLS-1$
42
	
43
	public final static String PROPERTIES= "prop"; //$NON-NLS-1$
44
	public final static String PROPERTY_VALUE= "value"; //$NON-NLS-1$
45
	public final static int PROPERTY_USER= 0;
46
	public final static int PROPERTY_SYSTEM= 1;
47
	public final static int PROPERTY_RUNTIME= 2;
48
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/DebugModelMessages.java (-39 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.ant.internal.ui.debug.model;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class DebugModelMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.ant.internal.ui.debug.model.DebugModelMessages";//$NON-NLS-1$
16
17
	public static String AntDebugTarget_0;
18
19
	public static String AntDebugModelPresentation_0;
20
	public static String AntDebugModelPresentation_1;
21
	public static String AntDebugModelPresentation_2;
22
	public static String AntDebugModelPresentation_3;
23
	public static String AntDebugModelPresentation_4;
24
	public static String AntDebugModelPresentation_5;
25
26
	public static String AntLineBreakpoint_0;
27
	public static String AntThread_0;
28
	public static String AntThread_1;
29
	public static String AntThread_2;
30
    public static String AntThread_3;
31
    public static String AntThread_4;
32
    
33
    public static String AntProperties_1;
34
    
35
	static {
36
		// load message values from bundle file
37
		NLS.initializeMessages(BUNDLE_NAME, DebugModelMessages.class);
38
	}
39
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/DebugModelMessages.properties (-28 lines)
Removed Link Here
1
###############################################################################
2
# Copyright (c) 2004, 2005 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
AntDebugTarget_0=Ant Build
13
14
AntDebugModelPresentation_0=<not available>
15
AntDebugModelPresentation_1=\ line: {0}
16
AntDebugModelPresentation_2=(breakpoint at line {0} in {1})
17
AntDebugModelPresentation_3=\ (Suspended {0})
18
AntDebugModelPresentation_4=\ (Suspended)
19
AntDebugModelPresentation_5=(run to line {0} in {1})
20
21
AntLineBreakpoint_0=Ant breakpoint [line: {0}]
22
AntThread_0=User Properties
23
AntThread_1=System Properties
24
AntThread_2=Runtime Properties
25
AntThread_3=Request to retrieve Ant stack frames failed
26
AntThread_4=Request to retrieve Ant properties failed
27
28
AntProperties_1=Request to Ant properties value failed
(-)Ant Tools Support/org/eclipse/ant/internal/ui/debug/model/RemoteAntDebugBuildListener.java (-321 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.debug.model;
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.InputStreamReader;
17
import java.io.PrintWriter;
18
import java.net.Socket;
19
import java.net.UnknownHostException;
20
21
import org.eclipse.ant.internal.ui.AntUIPlugin;
22
import org.eclipse.ant.internal.ui.debug.IAntDebugController;
23
import org.eclipse.ant.internal.ui.launchConfigurations.RemoteAntBuildListener;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.debug.core.DebugEvent;
26
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.debug.core.ILaunch;
28
import org.eclipse.debug.core.model.IBreakpoint;
29
import org.eclipse.debug.core.model.ILineBreakpoint;
30
import org.eclipse.debug.core.model.IProcess;
31
32
public class RemoteAntDebugBuildListener extends RemoteAntBuildListener implements IAntDebugController {
33
	
34
	// sockets to communicate with the remote Ant debug build logger
35
	private Socket fRequestSocket;
36
	private PrintWriter fRequestWriter;
37
	private BufferedReader fResponseReader;
38
	
39
	private int fRequestPort= -1;
40
	private Thread fReaderThread;
41
	
42
	private AntDebugTarget fTarget;
43
	
44
	/**
45
	 * Reader thread that processes request responses from the remote Ant debug build logger
46
	 */
47
	private class ReaderThread extends Thread {
48
		public ReaderThread() {
49
			super("Ant Request Response Reader Thread"); //$NON-NLS-1$
50
			setDaemon(true);
51
		}
52
53
		public void run(){
54
			try { 
55
				String message= null; 
56
				while (fResponseReader != null) { 
57
				    synchronized (RemoteAntDebugBuildListener.this) {
58
				        if (fResponseReader != null && (message= fResponseReader.readLine()) != null) {
59
				            receiveMessage(message);
60
				        }
61
				    }
62
				} 
63
			} catch (IOException ie) { //the other end has shutdown
64
				RemoteAntDebugBuildListener.this.shutDown();
65
			} catch (Exception e) {
66
				AntUIPlugin.log("Internal error processing remote response", e); //$NON-NLS-1$
67
				RemoteAntDebugBuildListener.this.shutDown();
68
			}
69
		}
70
	}	
71
	
72
	public RemoteAntDebugBuildListener(ILaunch launch) {
73
		super(launch);
74
		//fDebug= true;
75
	}
76
	
77
	protected void receiveMessage(String message) {
78
		if (message.startsWith(DebugMessageIds.BUILD_STARTED)) {
79
			buildStarted();
80
		} else if (message.startsWith(DebugMessageIds.SUSPENDED)){
81
			handleSuspendMessage(message);
82
		} else if (message.startsWith(DebugMessageIds.TERMINATED)){
83
			fTarget.terminated();
84
		} else if (message.startsWith(DebugMessageIds.STACK)){
85
			AntThread thread= (AntThread) fTarget.getThreads()[0];
86
			thread.buildStack(message);
87
		} else if (message.startsWith(DebugMessageIds.PROPERTIES)){
88
		    AntThread thread= (AntThread) fTarget.getThreads()[0];
89
		    thread.newProperties(message);
90
		} else {
91
			super.receiveMessage(message);
92
		}
93
	}
94
95
    private void handleSuspendMessage(String message) {
96
        if (message.endsWith(DebugMessageIds.CLIENT_REQUEST)) {
97
        	fTarget.suspended(DebugEvent.CLIENT_REQUEST);
98
        } else if (message.endsWith(DebugMessageIds.STEP)) {
99
        	fTarget.suspended(DebugEvent.STEP_END);
100
        } else if (message.indexOf(DebugMessageIds.BREAKPOINT) >= 0) {
101
        	fTarget.breakpointHit(message);
102
        }
103
    }
104
105
    private void buildStarted() {
106
        IProcess process= getProcess();
107
        while(process == null) {
108
        	try {
109
        		synchronized (this) {
110
        			wait(400);
111
        		}
112
        		process= getProcess();
113
        	} catch (InterruptedException ie) {
114
        	}
115
        }
116
        fTarget= new AntDebugTarget(fLaunch, process, this);
117
        fLaunch.addDebugTarget(fTarget);
118
        
119
        if (!connectRequest()) {
120
			RemoteAntDebugBuildListener.this.shutDown();
121
			return;
122
        }
123
        
124
        fTarget.buildStarted();
125
    }
126
127
    private boolean connectRequest() {
128
    	Exception exception= null;
129
    	for (int i= 1; i < 20; i++) {
130
    		try {
131
    			fRequestSocket = new Socket("localhost", fRequestPort); //$NON-NLS-1$
132
    			fRequestWriter = new PrintWriter(fRequestSocket.getOutputStream(), true);
133
    			fResponseReader = new BufferedReader(new InputStreamReader(fRequestSocket.getInputStream()));
134
    			
135
    			fReaderThread= new ReaderThread();
136
    			fReaderThread.start();
137
    			return true;
138
    		} catch (UnknownHostException e) {
139
    			exception= e;
140
    			break;
141
    		} catch (IOException e) {
142
    			exception= e;
143
    		}
144
    		try {
145
				Thread.sleep(500);
146
			} catch(InterruptedException e) {
147
			}
148
    	}
149
    	AntUIPlugin.log("Internal error attempting to connect to debug target", exception); //$NON-NLS-1$
150
    	return false;
151
	}
152
153
	/**
154
	 * Start listening to an Ant build. Start a server connection that
155
	 * the RemoteAntDebugBuildLogger can connect to.
156
	 * 
157
	 * @param eventPort The port number to create the server connection on
158
     * @param requestPort The port number to use for sending requests to the remote logger
159
	 */
160
	public synchronized void startListening(int eventPort, int requestPort) {
161
		super.startListening(eventPort);
162
		fRequestPort= requestPort;
163
	}
164
	
165
	/**
166
	 * Sends a request to the Ant build
167
	 * 
168
	 * @param request debug command
169
	 */
170
	protected void sendRequest(String request) {
171
		if (fRequestSocket == null) {
172
			return;
173
		}
174
		synchronized (fRequestSocket) {
175
			fRequestWriter.println(request);
176
		}		
177
	}
178
	
179
	protected synchronized void shutDown() {
180
        if (fTarget != null) {
181
            fTarget.terminated();
182
            fTarget= null;
183
        }
184
		fLaunch= null;
185
		if (DebugPlugin.getDefault() != null) {
186
			DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
187
		}
188
		try {
189
			if (fReaderThread != null)   {
190
				// interrupt reader thread so that we don't block on close
191
				// on a lock held by the BufferedReader
192
				// see bug: 38955
193
				fReaderThread.interrupt();
194
			}
195
			if (fResponseReader != null) {
196
				fResponseReader.close();
197
				fResponseReader= null;
198
			}
199
		} catch(IOException e) {
200
		}	
201
		if (fRequestWriter != null) {
202
			fRequestWriter.close();
203
			fRequestWriter= null;
204
		}
205
		try{
206
			if(fRequestSocket != null) {
207
				fRequestSocket.close();
208
				fRequestSocket= null;
209
			}
210
		} catch(IOException e) {
211
		}
212
		super.shutDown();
213
	}
214
215
	/* (non-Javadoc)
216
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#resume()
217
	 */
218
	public void resume() {
219
		sendRequest(DebugMessageIds.RESUME);
220
	}
221
222
	/* (non-Javadoc)
223
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#suspend()
224
	 */
225
	public void suspend() {
226
		sendRequest(DebugMessageIds.SUSPEND);
227
	}
228
229
	/* (non-Javadoc)
230
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#stepInto()
231
	 */
232
	public void stepInto() {
233
		sendRequest(DebugMessageIds.STEP_INTO);
234
	}
235
236
	/* (non-Javadoc)
237
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#stepOver()
238
	 */
239
	public void stepOver() {
240
		sendRequest(DebugMessageIds.STEP_OVER);
241
	}
242
243
	/* (non-Javadoc)
244
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#handleBreakpoint(IBreakpoint, boolean)
245
	 */
246
	public void handleBreakpoint(IBreakpoint breakpoint, boolean add) {
247
		if (fTarget == null || !fTarget.supportsBreakpoint(breakpoint)) {
248
			return;
249
		}
250
		StringBuffer message= new StringBuffer();
251
		if (add) {
252
			try {
253
				if (!breakpoint.isEnabled()) {
254
					return;
255
				}
256
			} catch (CoreException e) {
257
				AntUIPlugin.log(e);
258
				return;
259
			}
260
			message.append(DebugMessageIds.ADD_BREAKPOINT);
261
		} else {
262
			message.append(DebugMessageIds.REMOVE_BREAKPOINT);
263
		}
264
		message.append(DebugMessageIds.MESSAGE_DELIMITER);
265
		message.append(breakpoint.getMarker().getResource().getLocation().toOSString());
266
		message.append(DebugMessageIds.MESSAGE_DELIMITER);
267
		try {
268
			message.append(((ILineBreakpoint)breakpoint).getLineNumber());
269
			sendRequest(message.toString());
270
		} catch (CoreException ce) {
271
			AntUIPlugin.log(ce);
272
		}
273
	}
274
275
	/* (non-Javadoc)
276
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#getProperties()
277
	 */
278
	public void getProperties() {
279
		sendRequest(DebugMessageIds.PROPERTIES);
280
	}
281
282
	/* (non-Javadoc)
283
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#getStackFrames()
284
	 */
285
	public void getStackFrames() {
286
		sendRequest(DebugMessageIds.STACK);
287
	}
288
289
	/* (non-Javadoc)
290
	 * @see org.eclipse.ant.internal.ui.debug.IAntDebugController#unescapeString(java.lang.StringBuffer)
291
	 */
292
	public StringBuffer unescapeString(StringBuffer property) {
293
		if (property.indexOf("\\r") == -1 && property.indexOf("\\n") == -1) { //$NON-NLS-1$ //$NON-NLS-2$
294
			return property;
295
		}
296
		for (int i= 0; i < property.length(); i++) {
297
			if ('\\' == property.charAt(i)) {
298
				String newString= ""; //$NON-NLS-1$
299
				if ('r' == property.charAt(i + 1)) {
300
					if (i-1 > - 1 && '\\' == property.charAt(i-1)) {
301
						newString= "r"; //$NON-NLS-1$
302
					} else {
303
						newString+= '\r';
304
					}
305
				} else if ('n' == property.charAt(i + 1)) {
306
					if (i-1 > - 1 && '\\' == property.charAt(i-1)) {
307
						newString= "n"; //$NON-NLS-1$
308
					} else {
309
						newString+= '\n';
310
					}
311
					
312
				}
313
				if (newString.length() > 0) {
314
					property.replace(i, i + 2, newString);
315
				}
316
			}
317
		}
318
319
		return property;
320
	}
321
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntBuilderTargetsTab.java (-30 / +30 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 17-22 Link Here
17
import org.eclipse.ant.internal.ui.AntUIPlugin;
17
import org.eclipse.ant.internal.ui.AntUIPlugin;
18
import org.eclipse.ant.internal.ui.AntUtil;
18
import org.eclipse.ant.internal.ui.AntUtil;
19
import org.eclipse.ant.internal.ui.IAntUIConstants;
19
import org.eclipse.ant.internal.ui.IAntUIConstants;
20
import org.eclipse.ant.launching.IAntLaunchConstants;
21
import org.eclipse.core.internal.externaltools.model.BuilderCoreUtils;
22
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
20
import org.eclipse.core.resources.IncrementalProjectBuilder;
23
import org.eclipse.core.resources.IncrementalProjectBuilder;
21
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.debug.core.ILaunchConfiguration;
25
import org.eclipse.debug.core.ILaunchConfiguration;
Lines 36-43 Link Here
36
import org.eclipse.swt.widgets.Label;
39
import org.eclipse.swt.widgets.Label;
37
import org.eclipse.swt.widgets.Text;
40
import org.eclipse.swt.widgets.Text;
38
import org.eclipse.ui.PlatformUI;
41
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.externaltools.internal.model.BuilderUtils;
40
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
41
import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds;
42
import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds;
42
43
43
public class AntBuilderTargetsTab extends AbstractLaunchConfigurationTab {
44
public class AntBuilderTargetsTab extends AbstractLaunchConfigurationTab {
Lines 68-83 Link Here
68
			Object source = e.getSource();
69
			Object source = e.getSource();
69
            Text text= null;
70
            Text text= null;
70
			if (source == fAfterCleanTarget) {
71
			if (source == fAfterCleanTarget) {
71
                attribute= org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AFTER_CLEAN_TARGETS;
72
                attribute= IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS;
72
                text= fAfterCleanTargetText;
73
                text= fAfterCleanTargetText;
73
			} else if (source == fManualBuildTarget) {
74
			} else if (source == fManualBuildTarget) {
74
                attribute= org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_MANUAL_TARGETS;
75
                attribute= IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS;
75
                text= fManualBuildTargetText;
76
                text= fManualBuildTargetText;
76
			} else if (source == fAutoBuildTarget) {
77
			} else if (source == fAutoBuildTarget) {
77
                attribute= org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AUTO_TARGETS;
78
                attribute= IAntLaunchConstants.ATTR_ANT_AUTO_TARGETS;
78
                text= fAutoBuildTargetText;
79
                text= fAutoBuildTargetText;
79
			} else if (source == fDuringCleanTarget) {
80
			} else if (source == fDuringCleanTarget) {
80
                attribute= org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_CLEAN_TARGETS;
81
                attribute= IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS;
81
                text= fDuringCleanTargetText;
82
                text= fDuringCleanTargetText;
82
			}
83
			}
83
			
84
			
Lines 147-153 Link Here
147
        } catch (CoreException e) {
148
        } catch (CoreException e) {
148
           return;
149
           return;
149
        }
150
        }
150
        copy.setAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, (String)fAttributeToTargets.get(attribute));
151
        copy.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, (String)fAttributeToTargets.get(attribute));
151
		SetTargetsDialog dialog= new SetTargetsDialog(getShell(), copy);
152
		SetTargetsDialog dialog= new SetTargetsDialog(getShell(), copy);
152
		if (dialog.open() != Window.OK) {
153
		if (dialog.open() != Window.OK) {
153
		    return;
154
		    return;
Lines 211-217 Link Here
211
212
212
    public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
213
    public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
213
        configuration.setAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, true);
214
        configuration.setAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, true);
214
		configuration.setAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_TARGETS_UPDATED, true);
215
		configuration.setAttribute(IAntLaunchConstants.ATTR_TARGETS_UPDATED, true);
215
    }
216
    }
216
217
217
    public void initializeFrom(ILaunchConfiguration configuration) {
218
    public void initializeFrom(ILaunchConfiguration configuration) {
Lines 233-251 Link Here
233
        String afterCleanTargets= null;
234
        String afterCleanTargets= null;
234
        String duringCleanTargets= null;
235
        String duringCleanTargets= null;
235
        try {
236
        try {
236
			if (!configuration.getAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_TARGETS_UPDATED, false)) {
237
			if (!configuration.getAttribute(IAntLaunchConstants.ATTR_TARGETS_UPDATED, false)) {
237
				//not yet migrated to new format
238
				//not yet migrated to new format
238
				configTargets= configuration.getAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, (String)null);
239
				configTargets= configuration.getAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, (String)null);
239
			}
240
			}
240
            
241
            
241
            autoTargets= configuration.getAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AUTO_TARGETS, (String)null);
242
            autoTargets= configuration.getAttribute(IAntLaunchConstants.ATTR_ANT_AUTO_TARGETS, (String)null);
242
            manualTargets= configuration.getAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_MANUAL_TARGETS, (String)null);
243
            manualTargets= configuration.getAttribute(IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS, (String)null);
243
            afterCleanTargets= configuration.getAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, (String)null);
244
            afterCleanTargets= configuration.getAttribute(IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, (String)null);
244
            duringCleanTargets= configuration.getAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_CLEAN_TARGETS, (String)null);
245
            duringCleanTargets= configuration.getAttribute(IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS, (String)null);
245
			initializeAttributeToTargets(fAutoBuildTargetText, autoTargets, configTargets, org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AUTO_TARGETS);
246
			initializeAttributeToTargets(fAutoBuildTargetText, autoTargets, configTargets, IAntLaunchConstants.ATTR_ANT_AUTO_TARGETS);
246
			initializeAttributeToTargets(fManualBuildTargetText, manualTargets, configTargets, org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_MANUAL_TARGETS);
247
			initializeAttributeToTargets(fManualBuildTargetText, manualTargets, configTargets, IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS);
247
			initializeAttributeToTargets(fDuringCleanTargetText, duringCleanTargets, configTargets, org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_CLEAN_TARGETS);
248
			initializeAttributeToTargets(fDuringCleanTargetText, duringCleanTargets, configTargets, IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS);
248
			initializeAttributeToTargets(fAfterCleanTargetText, afterCleanTargets, configTargets, org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AFTER_CLEAN_TARGETS);
249
			initializeAttributeToTargets(fAfterCleanTargetText, afterCleanTargets, configTargets, IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS);
249
        } catch (CoreException ce) {
250
        } catch (CoreException ce) {
250
            AntUIPlugin.log("Error reading configuration", ce); //$NON-NLS-1$
251
            AntUIPlugin.log("Error reading configuration", ce); //$NON-NLS-1$
251
        }
252
        }
Lines 273-279 Link Here
273
        } catch (CoreException e) {
274
        } catch (CoreException e) {
274
            AntUIPlugin.log("Error reading configuration", e); //$NON-NLS-1$
275
            AntUIPlugin.log("Error reading configuration", e); //$NON-NLS-1$
275
        }
276
        }
276
        int buildTypes[]= BuilderUtils.buildTypesToArray(buildKindString);
277
        int buildTypes[]= BuilderCoreUtils.buildTypesToArray(buildKindString);
277
        for (int i = 0; i < buildTypes.length; i++) {
278
        for (int i = 0; i < buildTypes.length; i++) {
278
            switch (buildTypes[i]) {
279
            switch (buildTypes[i]) {
279
                case IncrementalProjectBuilder.FULL_BUILD:
280
                case IncrementalProjectBuilder.FULL_BUILD:
Lines 308-323 Link Here
308
        }
309
        }
309
        configuration.setAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, buffer.toString());
310
        configuration.setAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, buffer.toString());
310
        
311
        
311
        String targets= (String) fAttributeToTargets.get(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AFTER_CLEAN_TARGETS);
312
        String targets= (String) fAttributeToTargets.get(IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS);
312
        configuration.setAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, targets);
313
        configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS, targets);
313
        targets= (String) fAttributeToTargets.get(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AUTO_TARGETS);
314
        targets= (String) fAttributeToTargets.get(IAntLaunchConstants.ATTR_ANT_AUTO_TARGETS);
314
        configuration.setAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AUTO_TARGETS, targets);
315
        configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_AUTO_TARGETS, targets);
315
        targets= (String) fAttributeToTargets.get(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_MANUAL_TARGETS);
316
        targets= (String) fAttributeToTargets.get(IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS);
316
        configuration.setAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_MANUAL_TARGETS, targets);
317
        configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS, targets);
317
        targets= (String) fAttributeToTargets.get(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_CLEAN_TARGETS);
318
        targets= (String) fAttributeToTargets.get(IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS);
318
        configuration.setAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_CLEAN_TARGETS, targets);
319
        configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS, targets);
319
		
320
		configuration.setAttribute(IAntLaunchConstants.ATTR_TARGETS_UPDATED, true);
320
		configuration.setAttribute(org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_TARGETS_UPDATED, true);
321
    }
321
    }
322
322
323
    /* (non-Javadoc)
323
    /* (non-Javadoc)
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathProvider.java (-50 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.launchConfigurations;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.debug.core.ILaunchConfiguration;
19
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
20
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
21
import org.eclipse.jdt.launching.JavaRuntime;
22
import org.eclipse.jdt.launching.StandardClasspathProvider;
23
24
public class AntClasspathProvider extends StandardClasspathProvider {
25
26
	/* (non-Javadoc)
27
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathProvider#computeUnresolvedClasspath(org.eclipse.debug.core.ILaunchConfiguration)
28
	 */
29
	public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException {
30
		boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
31
		if (useDefault) {
32
			List rtes = new ArrayList(10);
33
			IRuntimeClasspathEntry jreEntry = null;
34
			try {
35
				jreEntry = JavaRuntime.computeJREEntry(configuration);
36
			} catch (CoreException e) {
37
				// not a java project
38
			}
39
			if (jreEntry == null) {
40
				jreEntry = JavaRuntime.newRuntimeContainerClasspathEntry(
41
						JavaRuntime.newDefaultJREContainerPath(), IRuntimeClasspathEntry.STANDARD_CLASSES);
42
			}
43
			rtes.add(jreEntry);
44
			rtes.add(new AntHomeClasspathEntry());
45
			rtes.add(new ContributedClasspathEntriesEntry());
46
			return (IRuntimeClasspathEntry[]) rtes.toArray(new IRuntimeClasspathEntry[rtes.size()]);
47
		}
48
		return super.computeUnresolvedClasspath(configuration);
49
	}
50
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntClasspathTab.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-16 Link Here
11
package org.eclipse.ant.internal.ui.launchConfigurations;
11
package org.eclipse.ant.internal.ui.launchConfigurations;
12
12
13
import org.eclipse.ant.internal.ui.AntUtil;
13
import org.eclipse.ant.internal.ui.AntUtil;
14
import org.eclipse.ant.internal.launching.launchConfigurations.AntHomeClasspathEntry;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.debug.core.ILaunchConfiguration;
16
import org.eclipse.debug.core.ILaunchConfiguration;
16
import org.eclipse.debug.ui.ILaunchConfigurationTab;
17
import org.eclipse.debug.ui.ILaunchConfigurationTab;
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntHomeClasspathEntry.java (-209 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.launchConfigurations;
12
13
import java.io.File;
14
import com.ibm.icu.text.MessageFormat;
15
import java.util.ArrayList;
16
import java.util.List;
17
18
import org.eclipse.ant.core.AntCorePlugin;
19
import org.eclipse.ant.core.AntCorePreferences;
20
import org.eclipse.ant.core.IAntClasspathEntry;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.Path;
24
import org.eclipse.debug.core.ILaunchConfiguration;
25
import org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry;
26
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
27
import org.eclipse.jdt.launching.JavaRuntime;
28
import org.w3c.dom.Document;
29
import org.w3c.dom.Element;
30
31
/**
32
 * A classpath entry that contains a set of archives for a particular
33
 * ANT_HOME.
34
 * 
35
 * @since 3.0 
36
 */
37
public class AntHomeClasspathEntry extends AbstractRuntimeClasspathEntry {
38
	
39
	public static final String TYPE_ID = "org.eclipse.ant.ui.classpathentry.antHome"; //$NON-NLS-1$
40
	
41
	/**
42
	 * Local path on disk where Ant Home is located or <code>null</code>
43
	 * to indicate the use of the default Ant Home.
44
	 */
45
	private String antHomeLocation = null;
46
	
47
	/**
48
	 * Creates an AntHome entry for the default AntHome installation.
49
	 */
50
	public AntHomeClasspathEntry() {
51
		antHomeLocation = null;
52
	}
53
	
54
	/**
55
	 * Constructs an AntHome entry for the Ant installed at the specified
56
	 * root directory.
57
	 * 
58
	 * @param antHome path in the local file system to an Ant installation
59
	 */
60
	public AntHomeClasspathEntry(String antHome) {
61
		antHomeLocation = antHome;
62
	}
63
		
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry#buildMemento(org.w3c.dom.Document, org.w3c.dom.Element)
66
	 */
67
	protected void buildMemento(Document document, Element memento) throws CoreException {
68
		if (antHomeLocation == null) {
69
			memento.setAttribute("default", "true");  //$NON-NLS-1$//$NON-NLS-2$
70
		} else {
71
			memento.setAttribute("antHome", new Path(antHomeLocation).toString()); //$NON-NLS-1$
72
		}
73
	}
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.jdt.internal.launching.IRuntimeClasspathEntry2#initializeFrom(org.w3c.dom.Element)
76
	 */
77
	public void initializeFrom(Element memento) throws CoreException {
78
		String antHome = memento.getAttribute("antHome"); //$NON-NLS-1$
79
		if (antHome != null && (antHome.length() > 0)) {
80
			IPath path = new Path(antHome);
81
			antHomeLocation = path.toOSString();
82
		} else {
83
			antHomeLocation = null;
84
		}
85
	}
86
	/* (non-Javadoc)
87
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getTypeId()
88
	 */
89
	public String getTypeId() {
90
		return TYPE_ID;
91
	}
92
	/* (non-Javadoc)
93
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getRuntimeClasspathEntries(org.eclipse.debug.core.ILaunchConfiguration)
94
	 */
95
	public IRuntimeClasspathEntry[] getRuntimeClasspathEntries(ILaunchConfiguration configuration) throws CoreException {
96
		List libs = new ArrayList(40);
97
		AntCorePreferences preferences = AntCorePlugin.getPlugin().getPreferences();
98
		if (antHomeLocation == null) {
99
			IAntClasspathEntry[] entries = preferences.getAntHomeClasspathEntries();
100
			for (int i = 0; i < entries.length; i++) {
101
				IAntClasspathEntry entry = entries[i];
102
				libs.add(JavaRuntime.newStringVariableClasspathEntry(entry.getLabel()));
103
			}
104
		} else {
105
			File lib= resolveAntHome();
106
			IPath libDir = new Path(antHomeLocation).append("lib"); //$NON-NLS-1$
107
			String[] fileNames = lib.list();
108
			for (int i = 0; i < fileNames.length; i++) {
109
				String name = fileNames[i];
110
				IPath path = new Path(name);
111
				String fileExtension = path.getFileExtension();
112
				if ("jar".equalsIgnoreCase(fileExtension)) { //$NON-NLS-1$
113
					libs.add(JavaRuntime.newArchiveRuntimeClasspathEntry(libDir.append(path)));
114
				}
115
			}
116
		}
117
		return (IRuntimeClasspathEntry[]) libs.toArray(new IRuntimeClasspathEntry[libs.size()]);
118
	}
119
	
120
	public File resolveAntHome() throws CoreException {
121
		if (antHomeLocation == null) { //using the default ant home
122
			return null;
123
		}
124
		IPath libDir= new Path(antHomeLocation).append("lib"); //$NON-NLS-1$
125
		File lib= libDir.toFile();
126
		File parentDir= lib.getParentFile();
127
		if (parentDir == null || !parentDir.exists()) {
128
			abort(MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_10, new String[] {antHomeLocation}), null);
129
		}
130
		if (!lib.exists() || !lib.isDirectory()) {
131
			abort(MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_11, new String[] {antHomeLocation}), null);
132
		}
133
		return lib;
134
	}
135
	
136
	/* (non-Javadoc)
137
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getName()
138
	 */
139
	public String getName() {
140
		if (antHomeLocation == null) {
141
			return AntLaunchConfigurationMessages.AntHomeClasspathEntry_8;
142
		}
143
		return MessageFormat.format(AntLaunchConfigurationMessages.AntHomeClasspathEntry_9, new String[]{antHomeLocation});
144
	}
145
	
146
	/* (non-Javadoc)
147
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getType()
148
	 */
149
	public int getType() {
150
		return IRuntimeClasspathEntry.OTHER;
151
	}
152
	
153
	/* (non-Javadoc)
154
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#isComposite()
155
	 */
156
	public boolean isComposite() {
157
		return true;
158
	}
159
	
160
	/* (non-Javadoc)
161
	 * @see java.lang.Object#equals(java.lang.Object)
162
	 */
163
	public boolean equals(Object obj) {
164
		return obj instanceof AntHomeClasspathEntry &&
165
		  equalsOrNull(antHomeLocation, ((AntHomeClasspathEntry)obj).antHomeLocation);
166
	}
167
	
168
	/**
169
	 * Return whether s1 is equivalent to s2.
170
	 * 
171
	 * @param s1
172
	 * @param s2
173
	 * @return whether s1 is equivalent to s2
174
	 */
175
	private boolean equalsOrNull(String s1, String s2) {
176
		if (s1 == null || s2 == null) {
177
			return s1 == s2;
178
		} 
179
		return s1.equalsIgnoreCase(s2);
180
	}
181
182
	/* (non-Javadoc)
183
	 * @see java.lang.Object#hashCode()
184
	 */
185
	public int hashCode() {
186
		return getClass().hashCode();
187
	}	
188
	
189
	/**
190
	 * Sets the ant home to use.
191
	 * 
192
	 * @param path path to toor of an ant home installation
193
	 */
194
	protected void setAntHome(String path) {
195
		antHomeLocation = path;
196
	}
197
	
198
	/**
199
	 * Returns the ant home location
200
	 * 
201
	 * @return path to root ant installation directory
202
	 */
203
	public String getAntHome() {
204
		if (antHomeLocation == null) {
205
			return AntCorePlugin.getPlugin().getPreferences().getAntHome();
206
		}
207
		return antHomeLocation;
208
	}
209
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntJRETab.java (-8 / +8 lines)
Lines 16-22 Link Here
16
import org.eclipse.ant.internal.ui.AntUIPlugin;
16
import org.eclipse.ant.internal.ui.AntUIPlugin;
17
import org.eclipse.ant.internal.ui.IAntUIConstants;
17
import org.eclipse.ant.internal.ui.IAntUIConstants;
18
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
18
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
19
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
19
import org.eclipse.ant.launching.IAntLaunchConstants;
20
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.variables.IStringVariableManager;
22
import org.eclipse.core.variables.IStringVariableManager;
22
import org.eclipse.core.variables.VariablesPlugin;
23
import org.eclipse.core.variables.VariablesPlugin;
Lines 35-45 Link Here
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
38
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
38
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
39
39
40
public class AntJRETab extends JavaJRETab {
40
public class AntJRETab extends JavaJRETab {
41
41
42
	private static final String MAIN_TYPE_NAME= "org.eclipse.ant.internal.ui.antsupport.InternalAntRunner"; //$NON-NLS-1$
42
	private static final String MAIN_TYPE_NAME= "org.eclipse.ant.internal.launching.remote.InternalAntRunner"; //$NON-NLS-1$
43
	
43
	
44
	private VMArgumentsBlock fVMArgumentsBlock=  new VMArgumentsBlock();
44
	private VMArgumentsBlock fVMArgumentsBlock=  new VMArgumentsBlock();
45
	private AntWorkingDirectoryBlock fWorkingDirectoryBlock= new AntWorkingDirectoryBlock();
45
	private AntWorkingDirectoryBlock fWorkingDirectoryBlock= new AntWorkingDirectoryBlock();
Lines 102-115 Link Here
102
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
102
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
103
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String)null);
103
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, (String)null);
104
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
104
			configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
105
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, false);
105
			configuration.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, false);
106
		} else {
106
		} else {
107
			super.performApply(configuration);
107
			super.performApply(configuration);
108
			
108
			
109
			if (useDefaultSeparateJRE(configuration)) {
109
			if (useDefaultSeparateJRE(configuration)) {
110
				configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, true);
110
				configuration.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, true);
111
			} else {
111
			} else {
112
				configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, false);
112
				configuration.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, false);
113
			}
113
			}
114
			
114
			
115
			applySeparateVMAttributes(configuration);
115
			applySeparateVMAttributes(configuration);
Lines 190-196 Link Here
190
	 */
190
	 */
191
	public void initializeFrom(ILaunchConfiguration configuration) {
191
	public void initializeFrom(ILaunchConfiguration configuration) {
192
		try {
192
		try {
193
			 boolean isDefaultVMInstall= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, false);
193
			 boolean isDefaultVMInstall= configuration.getAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, false);
194
			 if (isDefaultVMInstall) {
194
			 if (isDefaultVMInstall) {
195
			 	ILaunchConfigurationWorkingCopy copy = null;
195
			 	ILaunchConfigurationWorkingCopy copy = null;
196
			 	if (configuration instanceof ILaunchConfigurationWorkingCopy) {
196
			 	if (configuration instanceof ILaunchConfigurationWorkingCopy) {
Lines 275-281 Link Here
275
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); //$NON-NLS-1$
275
		config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SOURCE_PATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); //$NON-NLS-1$
276
		IVMInstall defaultVMInstall= getDefaultVMInstall(config);
276
		IVMInstall defaultVMInstall= getDefaultVMInstall(config);
277
		if (defaultVMInstall != null) {
277
		if (defaultVMInstall != null) {
278
			config.setAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, true);
278
			config.setAttribute(IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL, true);
279
			setDefaultVMInstallAttributes(defaultVMInstall, config);
279
			setDefaultVMInstallAttributes(defaultVMInstall, config);
280
			applySeparateVMAttributes(config);
280
			applySeparateVMAttributes(config);
281
		}
281
		}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntLaunchConfigurationMessages.java (-16 / +2 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others. All rights reserved. This
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
5
 * available at http://www.eclipse.org/legal/epl-v10.html
Lines 20-33 Link Here
20
	public static String AddVariableStringAction_3;
20
	public static String AddVariableStringAction_3;
21
	public static String AddVariableStringAction_4;
21
	public static String AddVariableStringAction_4;
22
22
23
	public static String AntLaunchDelegate_Launching__0__1;
24
	public static String AntLaunchDelegate_Running__0__2;
25
	public static String AntLaunchDelegate_Build_In_Progress;
26
	public static String AntLaunchDelegate_Failure;
27
	public static String AntLaunchDelegate_22;
28
	public static String AntLaunchDelegate_23;
29
	public static String AntLaunchDelegate_28;
30
31
	public static String AntLaunchShortcut_Unable;
23
	public static String AntLaunchShortcut_Unable;
32
	public static String AntLaunchShortcut_2;
24
	public static String AntLaunchShortcut_2;
33
	public static String AntLaunchShortcut_3;
25
	public static String AntLaunchShortcut_3;
Lines 45-53 Link Here
45
37
46
	public static String AntJRETab_2;
38
	public static String AntJRETab_2;
47
	public static String AntJRETab_3;
39
	public static String AntJRETab_3;
48
40
	
49
	public static String AntHomeClasspathEntry_8;
50
	public static String AntHomeClasspathEntry_9;
51
	public static String AntBuilderTargetsTab_0;
41
	public static String AntBuilderTargetsTab_0;
52
	public static String AntBuilderTargetsTab_1;
42
	public static String AntBuilderTargetsTab_1;
53
	public static String AntBuilderTargetsTab_2;
43
	public static String AntBuilderTargetsTab_2;
Lines 58-65 Link Here
58
	public static String AntBuilderTargetsTab_7;
48
	public static String AntBuilderTargetsTab_7;
59
	public static String AntBuilderTargetsTab_8;
49
	public static String AntBuilderTargetsTab_8;
60
	public static String AntBuilderTargetsTab_10;
50
	public static String AntBuilderTargetsTab_10;
61
	public static String AntHomeClasspathEntry_10;
62
	public static String AntHomeClasspathEntry_11;
63
51
64
	public static String AntMainTab__Select_a_build_file__1;
52
	public static String AntMainTab__Select_a_build_file__1;
65
	public static String AntMainTab_3;
53
	public static String AntMainTab_3;
Lines 86-93 Link Here
86
	public static String AntTargetsTab_1;
74
	public static String AntTargetsTab_1;
87
	public static String AntClasspathTab_0;
75
	public static String AntClasspathTab_0;
88
76
89
	public static String ContributedClasspathEntriesEntry_1;
90
91
	public static String EditAntHomeEntryAction_1;
77
	public static String EditAntHomeEntryAction_1;
92
78
93
	public static String TargetOrderDialog_Order_Targets_1;
79
	public static String TargetOrderDialog_Order_Targets_1;
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntLaunchConfigurationMessages.properties (-14 lines)
Lines 15-28 Link Here
15
AddVariableStringAction_3=&Variables...
15
AddVariableStringAction_3=&Variables...
16
AddVariableStringAction_4=Add Variable Classpath Entry
16
AddVariableStringAction_4=Add Variable Classpath Entry
17
17
18
AntLaunchDelegate_Launching__0__1=Launching {0}
19
AntLaunchDelegate_Running__0__2=Running {0}
20
AntLaunchDelegate_Build_In_Progress=Ant build {0} already in progress. Concurrent Ant builds are possible if you specify to build in a separate JRE.
21
AntLaunchDelegate_Failure=Failure of Background Ant Build
22
AntLaunchDelegate_22=&Do not show error dialog when Ant build fails
23
AntLaunchDelegate_23=Ant Build Failed
24
AntLaunchDelegate_28=Waiting for virtual machine to exit...
25
26
AntLaunchShortcut_Unable=Unable to find an Ant file to run.
18
AntLaunchShortcut_Unable=Unable to find an Ant file to run.
27
AntLaunchShortcut_2=An exception occurred while creating a default Ant launch configuration for {0}
19
AntLaunchShortcut_2=An exception occurred while creating a default Ant launch configuration for {0}
28
AntLaunchShortcut_3=An exception occurred while retrieving Ant launch configurations.
20
AntLaunchShortcut_3=An exception occurred while retrieving Ant launch configurations.
Lines 41-48 Link Here
41
AntJRETab_2=Run in the same &JRE as the workspace
33
AntJRETab_2=Run in the same &JRE as the workspace
42
AntJRETab_3=Se&parate JRE:
34
AntJRETab_3=Se&parate JRE:
43
35
44
AntHomeClasspathEntry_8=Ant Home (Default)
45
AntHomeClasspathEntry_9=Ant Home ({0})
46
AntBuilderTargetsTab_0=<Builder is not set to run for this build kind>
36
AntBuilderTargetsTab_0=<Builder is not set to run for this build kind>
47
AntBuilderTargetsTab_1=After a "Clean":
37
AntBuilderTargetsTab_1=After a "Clean":
48
AntBuilderTargetsTab_2=&Set Targets...
38
AntBuilderTargetsTab_2=&Set Targets...
Lines 53-60 Link Here
53
AntBuilderTargetsTab_7=During a "Clean":
43
AntBuilderTargetsTab_7=During a "Clean":
54
AntBuilderTargetsTab_8=Set Tar&gets...
44
AntBuilderTargetsTab_8=Set Tar&gets...
55
AntBuilderTargetsTab_10=<default target selected>
45
AntBuilderTargetsTab_10=<default target selected>
56
AntHomeClasspathEntry_10=Ant Home {0} does not exist
57
AntHomeClasspathEntry_11=Ant Home {0} does not contain a "lib" directory
58
46
59
AntMainTab__Select_a_build_file__1=&Select a buildfile:
47
AntMainTab__Select_a_build_file__1=&Select a buildfile:
60
AntMainTab_3=Base Direct&ory:
48
AntMainTab_3=Base Direct&ory:
Lines 81-88 Link Here
81
AntTargetsTab_1=No targets could be determined for the buildfile
69
AntTargetsTab_1=No targets could be determined for the buildfile
82
AntClasspathTab_0=Add F&olders...
70
AntClasspathTab_0=Add F&olders...
83
71
84
ContributedClasspathEntriesEntry_1=Additional Tasks & Support
85
86
EditAntHomeEntryAction_1=Ant &Home...
72
EditAntHomeEntryAction_1=Ant &Home...
87
73
88
TargetOrderDialog_Order_Targets_1=Order Targets
74
TargetOrderDialog_Order_Targets_1=Order Targets
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntLaunchDelegate.java (-761 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Juan A. Hernandez - bug 89926
11
 *     dakshinamurthy.karra@gmail.com - bug 165371
12
 *******************************************************************************/
13
package org.eclipse.ant.internal.ui.launchConfigurations;
14
15
import java.io.File;
16
import java.io.IOException;
17
import java.net.URL;
18
import java.util.HashMap;
19
import java.util.Iterator;
20
import java.util.List;
21
import java.util.Map;
22
23
import org.apache.tools.ant.ProjectHelper;
24
import org.eclipse.ant.core.AntCorePlugin;
25
import org.eclipse.ant.core.AntCorePreferences;
26
import org.eclipse.ant.core.AntRunner;
27
import org.eclipse.ant.core.Property;
28
import org.eclipse.ant.core.Task;
29
import org.eclipse.ant.core.Type;
30
import org.eclipse.ant.internal.core.AbstractEclipseBuildLogger;
31
import org.eclipse.ant.internal.ui.AntUIPlugin;
32
import org.eclipse.ant.internal.ui.AntUtil;
33
import org.eclipse.ant.internal.ui.IAntUIConstants;
34
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
35
import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
36
import org.eclipse.ant.internal.ui.debug.model.RemoteAntDebugBuildListener;
37
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
38
import org.eclipse.core.resources.IProject;
39
import org.eclipse.core.runtime.CoreException;
40
import org.eclipse.core.runtime.FileLocator;
41
import org.eclipse.core.runtime.IPath;
42
import org.eclipse.core.runtime.IProgressMonitor;
43
import org.eclipse.core.runtime.IStatus;
44
import org.eclipse.core.runtime.Path;
45
import org.eclipse.core.runtime.Platform;
46
import org.eclipse.core.runtime.Status;
47
import org.eclipse.core.runtime.SubProgressMonitor;
48
import org.eclipse.core.variables.VariablesPlugin;
49
import org.eclipse.debug.core.DebugEvent;
50
import org.eclipse.debug.core.DebugPlugin;
51
import org.eclipse.debug.core.IBreakpointManager;
52
import org.eclipse.debug.core.IDebugEventSetListener;
53
import org.eclipse.debug.core.ILaunch;
54
import org.eclipse.debug.core.ILaunchConfiguration;
55
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
56
import org.eclipse.debug.core.ILaunchManager;
57
import org.eclipse.debug.core.model.IBreakpoint;
58
import org.eclipse.debug.core.model.IProcess;
59
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
60
import org.eclipse.debug.ui.CommonTab;
61
import org.eclipse.debug.ui.IDebugUIConstants;
62
import org.eclipse.debug.ui.RefreshTab;
63
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
64
import org.eclipse.jdt.launching.IVMInstall;
65
import org.eclipse.jdt.launching.JavaRuntime;
66
import org.eclipse.jdt.launching.SocketUtil;
67
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
68
import org.eclipse.jface.preference.IPreferenceStore;
69
import org.eclipse.osgi.service.resolver.BundleDescription;
70
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsBuildTab;
71
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
72
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
73
import org.eclipse.ui.externaltools.internal.program.launchConfigurations.BackgroundResourceRefresher;
74
import org.osgi.framework.Bundle;
75
76
import com.ibm.icu.text.MessageFormat;
77
78
/**
79
 * Launch delegate for Ant builds
80
 */
81
public class AntLaunchDelegate extends LaunchConfigurationDelegate  {
82
	
83
	private static final String ANT_LOGGER_CLASS = "org.eclipse.ant.internal.ui.antsupport.logger.AntProcessBuildLogger"; //$NON-NLS-1$
84
	private static final String ANT_DEBUG_LOGGER_CLASS = "org.eclipse.ant.internal.ui.antsupport.logger.AntProcessDebugBuildLogger"; //$NON-NLS-1$
85
	private static final String NULL_LOGGER_CLASS = "org.eclipse.ant.internal.ui.antsupport.logger.NullBuildLogger"; //$NON-NLS-1$
86
	private static final String REMOTE_ANT_LOGGER_CLASS = "org.eclipse.ant.internal.ui.antsupport.logger.RemoteAntBuildLogger"; //$NON-NLS-1$
87
	private static final String REMOTE_ANT_DEBUG_LOGGER_CLASS = "org.eclipse.ant.internal.ui.antsupport.logger.debug.RemoteAntDebugBuildLogger"; //$NON-NLS-1$
88
	private static final String BASE_DIR_PREFIX = "-Dbasedir="; //$NON-NLS-1$
89
	private static final String INPUT_HANDLER_CLASS = "org.eclipse.ant.internal.ui.antsupport.inputhandler.AntInputHandler"; //$NON-NLS-1$
90
	private static final String REMOTE_INPUT_HANDLER_CLASS = "org.eclipse.ant.internal.ui.antsupport.inputhandler.ProxyInputHandler"; //$NON-NLS-1$
91
	
92
	private static final IProject[] NO_PROJECTS = new IProject[0];
93
    
94
	/**
95
	 * String attribute identifying the build scope for a launch configuration.
96
	 * <code>null</code> indicates the default workspace build.
97
	 */
98
	private static final String ATTR_BUILD_SCOPE = AntUIPlugin.getUniqueIdentifier() + ".ATTR_BUILD_SCOPE"; //$NON-NLS-1$
99
100
	/**
101
	 * Attribute identifier specifying whether referenced projects should be 
102
	 * considered when computing the projects to build. Default value is
103
	 * <code>true</code>.
104
	 */
105
	private static final String ATTR_INCLUDE_REFERENCED_PROJECTS = AntUIPlugin.getUniqueIdentifier() + ".ATTR_INCLUDE_REFERENCED_PROJECTS"; //$NON-NLS-1$
106
107
	
108
    private static String fgSWTLibraryLocation;
109
	
110
	private String fMode;
111
    private boolean fUserSpecifiedLogger= false;
112
    
113
    private String getProgramArguments(ILaunchConfiguration configuration) throws CoreException {
114
		String arguments = configuration.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, ""); //$NON-NLS-1$
115
		return VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(arguments);
116
	}
117
	
118
	/**
119
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration,
120
	 *      java.lang.String, org.eclipse.debug.core.ILaunch,
121
	 *      org.eclipse.core.runtime.IProgressMonitor)
122
	 */
123
	public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
124
		if (monitor.isCanceled()) {
125
			return;
126
		}
127
		fUserSpecifiedLogger= false;
128
		fMode= mode;
129
		
130
		// migrate the config to the new classpath format if required
131
		AntUtil.migrateToNewClasspathFormat(configuration);
132
		
133
		boolean isSeparateJRE= AntUtil.isSeparateJREAntBuild(configuration);
134
		
135
		if (CommonTab.isLaunchInBackground(configuration)) {
136
			monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__1, new String[] {configuration.getName()}), 10);
137
		} else {
138
			monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Running__0__2, new String[] {configuration.getName()}), 100);
139
		}
140
		
141
		// resolve location
142
		IPath location = ExternalToolsUtil.getLocation(configuration);
143
		monitor.worked(1);
144
		
145
		if (monitor.isCanceled()) {
146
			return;
147
		}
148
		
149
		if (!isSeparateJRE && AntRunner.isBuildRunning()) {
150
			IStatus status= new Status(IStatus.ERROR, IAntUIConstants.PLUGIN_ID, 1, MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Build_In_Progress, new String[]{location.toOSString()}), null);
151
			throw new CoreException(status);
152
		}		
153
		
154
		// resolve working directory
155
		IPath workingDirectory = ExternalToolsUtil.getWorkingDirectory(configuration);
156
		String basedir = null;
157
		if (workingDirectory != null) {
158
			basedir= workingDirectory.toOSString();
159
		}
160
		monitor.worked(1);
161
		
162
		if (monitor.isCanceled()) {
163
			return;
164
		}
165
166
		// link the process to its build logger via a timestamp
167
		long timeStamp = System.currentTimeMillis();
168
		String idStamp = Long.toString(timeStamp);
169
		StringBuffer idProperty = new StringBuffer("-D"); //$NON-NLS-1$
170
		idProperty.append(AbstractEclipseBuildLogger.ANT_PROCESS_ID);
171
		idProperty.append('=');
172
		idProperty.append(idStamp);
173
		
174
		// resolve arguments	
175
		String[] arguments = null;
176
		if (isSeparateJRE) {
177
			arguments = new String[] {getProgramArguments(configuration)};
178
        } else { 
179
			arguments = ExternalToolsUtil.getArguments(configuration);
180
        }
181
		
182
		Map userProperties= AntUtil.getProperties(configuration);
183
		if (userProperties != null) {//create a copy so as to not affect the configuration with transient properties
184
			userProperties= new HashMap(userProperties);
185
		}
186
		String[] propertyFiles= AntUtil.getPropertyFiles(configuration);
187
		String[] targets = AntUtil.getTargetNames(configuration);
188
		URL[] customClasspath= AntUtil.getCustomClasspath(configuration);
189
		String antHome= AntUtil.getAntHome(configuration);
190
		
191
		boolean setInputHandler= true;
192
		try {
193
			//check if set specify inputhandler
194
			setInputHandler = configuration.getAttribute(IAntUIConstants.SET_INPUTHANDLER, true);
195
		} catch (CoreException ce) {
196
			AntUIPlugin.log(ce);			
197
		}
198
		
199
		AntRunner runner= null;
200
		if (!isSeparateJRE) {
201
			runner = configureAntRunner(configuration, location, basedir, idProperty, arguments, userProperties, propertyFiles, targets, customClasspath, antHome, setInputHandler);
202
		}
203
		 
204
		monitor.worked(1);
205
								
206
		if (monitor.isCanceled()) {
207
			return;
208
		}
209
		boolean captureOutput= ExternalToolsUtil.getCaptureOutput(configuration);
210
		int port= -1;
211
		int requestPort= -1;
212
		if (isSeparateJRE && captureOutput) {
213
			if (userProperties == null) {
214
				userProperties= new HashMap();
215
			}
216
			port= SocketUtil.findFreePort();
217
			userProperties.put(AbstractEclipseBuildLogger.ANT_PROCESS_ID, idStamp);
218
			userProperties.put("eclipse.connect.port", Integer.toString(port)); //$NON-NLS-1$
219
			if (fMode.equals(ILaunchManager.DEBUG_MODE)) {
220
				requestPort= SocketUtil.findFreePort();
221
				userProperties.put("eclipse.connect.request_port", Integer.toString(requestPort)); //$NON-NLS-1$
222
			}
223
		}
224
		
225
		StringBuffer commandLine= generateCommandLine(location, arguments, userProperties, propertyFiles, targets, antHome, basedir, isSeparateJRE, captureOutput, setInputHandler);
226
		
227
		if (isSeparateJRE) {
228
			monitor.beginTask(MessageFormat.format(AntLaunchConfigurationMessages.AntLaunchDelegate_Launching__0__1, new String[] {configuration.getName()}), 10);
229
			runInSeparateVM(configuration, launch, monitor, idStamp, antHome, port, requestPort, commandLine, captureOutput, setInputHandler);
230
		} else {
231
			runInSameVM(configuration, launch, monitor, location, idStamp, runner, commandLine, captureOutput);
232
		}
233
		
234
		monitor.done();	
235
	}
236
	
237
	private void runInSameVM(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor, IPath location, String idStamp, AntRunner runner, StringBuffer commandLine, boolean captureOutput) throws CoreException {
238
		Map attributes= new HashMap(2);
239
		attributes.put(IProcess.ATTR_PROCESS_TYPE, IAntLaunchConfigurationConstants.ID_ANT_PROCESS_TYPE);
240
		attributes.put(AbstractEclipseBuildLogger.ANT_PROCESS_ID, idStamp);
241
				
242
		final AntProcess process = new AntProcess(location.toOSString(), launch, attributes);
243
		setProcessAttributes(process, idStamp, commandLine, captureOutput);
244
		boolean debug= fMode.equals(ILaunchManager.DEBUG_MODE);
245
		if (debug || CommonTab.isLaunchInBackground(configuration)) {
246
			final AntRunner finalRunner= runner;
247
			Runnable r = new Runnable() {
248
				public void run() {
249
					try {
250
						finalRunner.run(process);
251
					} catch (CoreException e) {
252
						handleException(e, AntLaunchConfigurationMessages.AntLaunchDelegate_Failure);
253
					}
254
					process.terminated();
255
				}
256
			};
257
			Thread background = new Thread(r);
258
            background.setDaemon(true);
259
			background.start();
260
			monitor.worked(1);
261
			//refresh resources after process finishes
262
			if (RefreshTab.getRefreshScope(configuration) != null) {
263
				BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(configuration, process);
264
				refresher.startBackgroundRefresh();
265
			}	
266
		} else {
267
			// execute the build 
268
			try {
269
				runner.run(monitor);
270
			} catch (CoreException e) {
271
				process.terminated();
272
				monitor.done();
273
				handleException(e, AntLaunchConfigurationMessages.AntLaunchDelegate_23);
274
				return;
275
			}
276
			process.terminated();
277
			
278
			// refresh resources
279
			RefreshTab.refreshResources(configuration, monitor);
280
		}
281
	}
282
283
	private AntRunner configureAntRunner(ILaunchConfiguration configuration, IPath location, String baseDir, StringBuffer idProperty, String[] arguments, Map userProperties, String[] propertyFiles, String[] targets, URL[] customClasspath, String antHome, boolean setInputHandler) throws CoreException {
284
		int argLength = 1; // at least one user property - timestamp
285
		if (arguments != null) {
286
			argLength += arguments.length;
287
		}		
288
		if (baseDir != null && baseDir.length() > 0) {
289
			argLength++;
290
		}
291
		String[] runnerArgs = new String[argLength];
292
		if (arguments != null) {
293
			System.arraycopy(arguments, 0, runnerArgs, 0, arguments.length);
294
		}
295
		if (baseDir != null && baseDir.length() > 0) {
296
			runnerArgs[runnerArgs.length - 2] = BASE_DIR_PREFIX + baseDir;
297
		}
298
		runnerArgs[runnerArgs.length -1] = idProperty.toString();
299
		
300
		AntRunner runner= new AntRunner();
301
		runner.setBuildFileLocation(location.toOSString());
302
		boolean captureOutput= ExternalToolsUtil.getCaptureOutput(configuration);
303
		if (captureOutput) {
304
			if (fMode.equals(ILaunchManager.DEBUG_MODE)) {
305
				runner.addBuildLogger(ANT_DEBUG_LOGGER_CLASS);
306
			} else {
307
				runner.addBuildLogger(ANT_LOGGER_CLASS);
308
			}
309
		} else {
310
			runner.addBuildLogger(NULL_LOGGER_CLASS);
311
		}
312
		if (setInputHandler) {
313
			runner.setInputHandler(INPUT_HANDLER_CLASS);
314
		} else {
315
			runner.setInputHandler(""); //$NON-NLS-1$
316
		}
317
		runner.setArguments(runnerArgs);
318
		if (userProperties != null) {
319
			runner.addUserProperties(userProperties);
320
		}
321
322
		if (propertyFiles != null) {
323
			runner.setPropertyFiles(propertyFiles);
324
		}
325
326
		if (targets != null) {
327
			runner.setExecutionTargets(targets);
328
		}
329
330
		if (customClasspath != null) {
331
			runner.setCustomClasspath(customClasspath);
332
		}
333
334
		if (antHome != null) {
335
			runner.setAntHome(antHome);
336
		}
337
		return runner;
338
	}
339
340
	private void handleException(final CoreException e, final String title) {
341
		IPreferenceStore store= AntUIPlugin.getDefault().getPreferenceStore();
342
		if (store.getBoolean(IAntUIPreferenceConstants.ANT_ERROR_DIALOG)) {
343
			AntUIPlugin.getStandardDisplay().asyncExec(new Runnable() {
344
				public void run() {
345
					MessageDialogWithToggle.openError(null, title, e.getMessage(), AntLaunchConfigurationMessages.AntLaunchDelegate_22, false, AntUIPlugin.getDefault().getPreferenceStore(), IAntUIPreferenceConstants.ANT_ERROR_DIALOG);
346
				}
347
			});
348
		}
349
	}
350
351
	private void setProcessAttributes(IProcess process, String idStamp, StringBuffer commandLine, boolean captureOutput) {
352
		// link the process to the Eclipse build logger via a timestamp
353
        if (!fUserSpecifiedLogger) {
354
            process.setAttribute(AbstractEclipseBuildLogger.ANT_PROCESS_ID, idStamp);
355
        }
356
		
357
		// create "fake" command line for the process
358
		if (commandLine != null) {
359
			process.setAttribute(IProcess.ATTR_CMDLINE, commandLine.toString());
360
		}
361
		if (captureOutput && !fUserSpecifiedLogger) {
362
			TaskLinkManager.registerAntBuild(process);
363
		}
364
	}
365
366
	private StringBuffer generateCommandLine(IPath location, String[] arguments, Map userProperties, String[] propertyFiles, String[] targets, String antHome, String basedir, boolean separateVM, boolean captureOutput, boolean setInputHandler) {
367
		StringBuffer commandLine= new StringBuffer();
368
369
		if (!separateVM) {
370
			commandLine.append("ant"); //$NON-NLS-1$
371
		}
372
		
373
		if (arguments != null) {
374
			for (int i = 0; i < arguments.length; i++) {
375
				commandLine.append(' ');
376
				commandLine.append(arguments[i]);
377
			}
378
		}
379
		
380
		AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences();
381
		if (propertyFiles == null) { //global
382
			String[] files= prefs.getCustomPropertyFiles();
383
			for (int i = 0; i < files.length; i++) {
384
				String path = files[i];
385
				commandLine.append(" -propertyfile \""); //$NON-NLS-1$
386
				commandLine.append(path);
387
				commandLine.append('\"');
388
			}
389
		} else {//"local" configuration
390
			for (int i = 0; i < propertyFiles.length; i++) {
391
				String path = propertyFiles[i];
392
				commandLine.append(" -propertyfile \""); //$NON-NLS-1$
393
				commandLine.append(path);
394
				commandLine.append('\"');
395
			}
396
		}
397
		//"local" configuration
398
		if (userProperties != null) {
399
			Iterator keys = userProperties.keySet().iterator();
400
			String key;
401
			while (keys.hasNext()) {
402
				key= (String)keys.next();
403
				appendProperty(commandLine, key, (String)userProperties.get(key));
404
			}
405
		}
406
		
407
		//global
408
		List properties= null;
409
		if (!separateVM) {
410
			properties= prefs.getProperties();
411
		} else {
412
			properties= prefs.getRemoteAntProperties();
413
		}
414
		
415
		//if we have user properties this means that the user has chosen to override the global properties
416
		//if in a separate VM and have only two (or three if debug) user properties these are really only Eclipse generated properties
417
		//and the user is still using the global properties
418
		int numberOfEclipseProperties= 2;
419
		if (userProperties != null && userProperties.get("eclipse.connect.request_port") != null){ //$NON-NLS-1$
420
			numberOfEclipseProperties= 3; //debug mode
421
		}
422
		boolean useGlobalProperties = userProperties == null || (separateVM && userProperties.size() == numberOfEclipseProperties);
423
		if (useGlobalProperties) {
424
			for (Iterator iter = properties.iterator(); iter.hasNext();) {
425
				Property property = (Property) iter.next();
426
				String key= property.getName();
427
				String value= property.getValue(false);
428
				if (value != null) {
429
					appendProperty(commandLine, key, value);
430
				}
431
			}
432
		}
433
		
434
		if (basedir != null && basedir.length() > 0) {
435
			appendProperty(commandLine, "basedir", basedir); //$NON-NLS-1$
436
		}
437
		
438
		if (antHome != null) {
439
			commandLine.append(" \"-Dant.home="); //$NON-NLS-1$
440
			commandLine.append(antHome);
441
			commandLine.append('\"');
442
		}
443
		
444
		if (separateVM) { 
445
			if (commandLine.indexOf("-logger") == -1) { //$NON-NLS-1$
446
				if (captureOutput) {
447
				commandLine.append(" -logger "); //$NON-NLS-1$
448
				if (fMode.equals(ILaunchManager.DEBUG_MODE)) {
449
					commandLine.append(REMOTE_ANT_DEBUG_LOGGER_CLASS);
450
					} else {
451
					commandLine.append(REMOTE_ANT_LOGGER_CLASS);
452
				}
453
				}
454
			} else {
455
			    fUserSpecifiedLogger= true;
456
            }
457
			if (commandLine.indexOf("-inputhandler") == -1 && setInputHandler) { //$NON-NLS-1$
458
				commandLine.append(" -inputhandler "); //$NON-NLS-1$
459
				commandLine.append(REMOTE_INPUT_HANDLER_CLASS);
460
			}
461
		} else {
462
			if (commandLine.indexOf("-inputhandler") == -1 && setInputHandler) { //$NON-NLS-1$
463
				commandLine.append(" -inputhandler "); //$NON-NLS-1$
464
				commandLine.append(INPUT_HANDLER_CLASS);
465
			}
466
            if (commandLine.indexOf("-logger") == -1) { //$NON-NLS-1$
467
    			commandLine.append(" -logger "); //$NON-NLS-1$
468
    			if (fMode.equals(ILaunchManager.DEBUG_MODE)) {
469
    				commandLine.append(ANT_DEBUG_LOGGER_CLASS);
470
    			} else if (captureOutput) {
471
    				commandLine.append(ANT_LOGGER_CLASS);
472
    			} else {
473
    				commandLine.append(NULL_LOGGER_CLASS);
474
    			}
475
            }
476
		}
477
		
478
		if (separateVM) {
479
			appendTaskAndTypes(prefs, commandLine);
480
		}
481
		commandLine.append(" -buildfile \""); //$NON-NLS-1$
482
		commandLine.append(location.toOSString());
483
		commandLine.append('\"');
484
		
485
		if (targets != null) {
486
			for (int i = 0; i < targets.length; i++) {
487
				commandLine.append(" \""); //$NON-NLS-1$
488
				commandLine.append(targets[i]);
489
				commandLine.append('\"');
490
			}
491
		}
492
		return commandLine;
493
	}
494
	
495
	private void appendTaskAndTypes(AntCorePreferences prefs, StringBuffer commandLine) {
496
		List tasks= prefs.getRemoteTasks();
497
		Iterator itr= tasks.iterator();
498
		while (itr.hasNext()) {
499
			Task task = (Task) itr.next();
500
			commandLine.append(" -eclipseTask "); //$NON-NLS-1$
501
			String name= ProjectHelper.genComponentName(task.getURI(), task.getTaskName());
502
			commandLine.append(name);
503
			commandLine.append(',');
504
			commandLine.append(task.getClassName());
505
		}
506
		
507
		List types= prefs.getRemoteTypes();
508
		itr= types.iterator();
509
		while (itr.hasNext()) {
510
			Type type = (Type) itr.next();
511
			commandLine.append(" -eclipseType "); //$NON-NLS-1$
512
			String name= ProjectHelper.genComponentName(type.getURI(), type.getTypeName());
513
			commandLine.append(name);
514
			commandLine.append(',');
515
			commandLine.append(type.getClassName());
516
		}
517
	}
518
519
	private void appendProperty(StringBuffer commandLine, String name, String value) {
520
		commandLine.append(" \"-D"); //$NON-NLS-1$
521
		commandLine.append(name);
522
		commandLine.append('=');
523
		commandLine.append(value);
524
        if (value.length() > 0 && value.charAt(value.length() - 1) == File.separatorChar) {
525
            commandLine.append(File.separatorChar);
526
        }
527
		commandLine.append("\""); //$NON-NLS-1$
528
	}
529
	
530
	private void runInSeparateVM(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor, String idStamp, String antHome, int port, int requestPort, StringBuffer commandLine, boolean captureOutput, boolean setInputHandler) throws CoreException {
531
        boolean debug= fMode.equals(ILaunchManager.DEBUG_MODE);
532
		if (captureOutput) {
533
			if (debug) {
534
				RemoteAntDebugBuildListener listener= new RemoteAntDebugBuildListener(launch);
535
				if (requestPort != -1) {
536
					listener.startListening(port, requestPort);
537
				}
538
			} else if (!fUserSpecifiedLogger) {
539
				RemoteAntBuildListener client= new RemoteAntBuildListener(launch);
540
				if (port != -1) {
541
					client.startListening(port);
542
				}
543
			}
544
		}
545
		
546
		ILaunchConfigurationWorkingCopy copy= configuration.getWorkingCopy();
547
		setDefaultWorkingDirectory(copy);
548
		copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, commandLine.toString());
549
		StringBuffer vmArgs= generateVMArguments(copy, setInputHandler, antHome);
550
		copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs.toString());
551
        copy.setAttribute(IDebugUIConstants.ATTR_PRIVATE, true);
552
        if (copy.getAttribute(IAntLaunchConfigurationConstants.ATTR_DEFAULT_VM_INSTALL, false)) {
553
        	setDefaultVM(configuration, copy);
554
        }
555
        if (debug) { //do not allow launch in foreground bug 83254
556
            copy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true);
557
        }
558
        
559
        //set the ANT_HOME environment variable
560
        if (antHome != null) {
561
            Map vars = copy.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, new HashMap(1));
562
            vars.put("ANT_HOME", antHome); //$NON-NLS-1$
563
            copy.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, vars);
564
        }
565
566
		//copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000");
567
		IProgressMonitor subMonitor= new SubProgressMonitor(monitor, 10);
568
		AntJavaLaunchDelegate delegate= new AntJavaLaunchDelegate();
569
		delegate.preLaunchCheck(copy, ILaunchManager.RUN_MODE, subMonitor);
570
		delegate.launch(copy, ILaunchManager.RUN_MODE, launch, subMonitor);
571
		final IProcess[] processes= launch.getProcesses();
572
		for (int i = 0; i < processes.length; i++) {
573
			setProcessAttributes(processes[i], idStamp, null, captureOutput);
574
		}
575
576
		if (CommonTab.isLaunchInBackground(copy)) {
577
			// refresh resources after process finishes
578
			if (RefreshTab.getRefreshScope(configuration) != null) {
579
				BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(configuration, processes[0]);
580
				refresher.startBackgroundRefresh();
581
			}
582
		} else {
583
			final boolean[] terminated= new boolean[1];
584
			terminated[0]= launch.isTerminated();
585
			IDebugEventSetListener listener= new IDebugEventSetListener() {
586
				public void handleDebugEvents(DebugEvent[] events) {
587
					for (int i = 0; i < events.length; i++) {
588
						DebugEvent event = events[i];
589
						for (int j= 0, numProcesses= processes.length; j < numProcesses; j++) {
590
							if (event.getSource() == processes[j] && event.getKind() == DebugEvent.TERMINATE) {
591
								terminated[0]= true;
592
								break;
593
							}
594
						}
595
					}
596
				}
597
			};
598
			DebugPlugin.getDefault().addDebugEventListener(listener);
599
			monitor.subTask(AntLaunchConfigurationMessages.AntLaunchDelegate_28);
600
			while (!monitor.isCanceled() && !terminated[0]) {
601
				try {
602
					Thread.sleep(50);
603
				} catch (InterruptedException e) {
604
				}
605
			}
606
			DebugPlugin.getDefault().removeDebugEventListener(listener);
607
			if (!monitor.isCanceled()) {
608
				// refresh resources
609
				RefreshTab.refreshResources(configuration, monitor);
610
			}
611
		}
612
	}
613
614
	private void setDefaultVM(ILaunchConfiguration configuration, ILaunchConfigurationWorkingCopy copy) {
615
		try {
616
			JavaRuntime.getJavaProject(configuration);
617
			//remove the vm name, install type and jre container path for the Java launching concept of default VM
618
			copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, (String)null);
619
			copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
620
			copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
621
		} catch (CoreException ce) {
622
			//not in a Java project
623
			IVMInstall defaultVMInstall= JavaRuntime.getDefaultVMInstall();
624
			copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, defaultVMInstall.getName());
625
			copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, defaultVMInstall.getVMInstallType().getId());
626
		}
627
	}
628
	
629
	private StringBuffer generateVMArguments(ILaunchConfiguration config, boolean setInputHandler, String antHome) {
630
		StringBuffer vmArgs= new StringBuffer();
631
		try {
632
			String configArgs= config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, (String)null);
633
			if (configArgs != null) {
634
				vmArgs.append(configArgs);
635
				vmArgs.append(' ');
636
			}
637
		} catch (CoreException e) {
638
		}
639
	
640
        if (antHome != null) {
641
            vmArgs.append("-Dant.home=\""); //$NON-NLS-1$
642
            vmArgs.append(antHome);
643
            vmArgs.append("\" "); //$NON-NLS-1$
644
        
645
            File antLibDir= new File(antHome, "lib"); //$NON-NLS-1$
646
            vmArgs.append("-Dant.library.dir=\""); //$NON-NLS-1$
647
            vmArgs.append(antLibDir.getAbsolutePath());
648
            vmArgs.append('\"');
649
        }
650
		if (setInputHandler) {
651
			String swtLocation= getSWTLibraryLocation();
652
			if (swtLocation != null) {
653
				vmArgs.append(" -Djava.library.path=\""); //$NON-NLS-1$
654
				String javaLibPath= System.getProperty("java.library.path"); //$NON-NLS-1$
655
                javaLibPath= stripUnescapedQuotes(javaLibPath);
656
				if (javaLibPath != null) {
657
					vmArgs.append(javaLibPath);
658
					if (vmArgs.charAt(vmArgs.length() - 1) != File.pathSeparatorChar) {
659
						vmArgs.append(File.pathSeparatorChar);
660
					}
661
				}
662
				vmArgs.append(swtLocation);
663
				vmArgs.append('"');
664
			}
665
		}
666
		return vmArgs;
667
    }
668
669
    private String stripUnescapedQuotes(String javaLibPath) {
670
        StringBuffer buf = new StringBuffer(javaLibPath.length());
671
        for (int i = 0; i < javaLibPath.length(); i++) {
672
            char c = javaLibPath.charAt(i);
673
            switch (c) {
674
                case '"':
675
                    if (i != 0 && javaLibPath.charAt(i-1) == '\\') {
676
                        buf.append(c);
677
                    }
678
                    break;
679
                default:
680
                    buf.append(c);
681
                    break;
682
            }
683
        }
684
        return buf.toString();
685
    }
686
687
    /* (non-Javadoc)
688
	 * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBuildOrder(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
689
	 */
690
	protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
691
		IProject[] projects = ExternalToolsBuildTab.getBuildProjects(configuration, ATTR_BUILD_SCOPE);
692
		if (projects == null) {
693
			return NO_PROJECTS;
694
		}
695
		boolean isRef = ExternalToolsBuildTab.isIncludeReferencedProjects(configuration, ATTR_INCLUDE_REFERENCED_PROJECTS);
696
		if (isRef) {
697
			return computeReferencedBuildOrder(projects);
698
		}
699
		return computeBuildOrder(projects);
700
	}
701
702
	private String getSWTLibraryLocation() {
703
       if (fgSWTLibraryLocation == null) {
704
            Bundle bundle= Platform.getBundle("org.eclipse.swt"); //$NON-NLS-1$
705
            BundleDescription description= Platform.getPlatformAdmin().getState(false).getBundle(bundle.getBundleId());
706
            BundleDescription[] fragments= description.getFragments();
707
            if (fragments == null || fragments.length == 0) {
708
                return null;
709
            }
710
            Bundle fragBundle= Platform.getBundle(fragments[0].getSymbolicName());
711
            try {
712
                URL url= FileLocator.toFileURL(fragBundle.getEntry("/")); //$NON-NLS-1$
713
                IPath path= new Path(url.getPath());
714
                path= path.removeTrailingSeparator();
715
                fgSWTLibraryLocation= path.toOSString();
716
            } catch (IOException e) {
717
            }
718
		}
719
        return fgSWTLibraryLocation;
720
	}
721
    
722
     /* (non-Javadoc)
723
     * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBreakpoints(org.eclipse.debug.core.ILaunchConfiguration)
724
     */
725
    protected IBreakpoint[] getBreakpoints(ILaunchConfiguration configuration) {
726
         IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
727
         if (!breakpointManager.isEnabled()) {
728
             // no need to check breakpoints individually.
729
             return null;
730
         }
731
         return breakpointManager.getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
732
     }
733
734
	/* (non-Javadoc)
735
	 * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#saveBeforeLaunch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
736
	 */
737
	protected boolean saveBeforeLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
738
		if (IExternalToolConstants.ID_EXTERNAL_TOOLS_BUILDER_LAUNCH_CATEGORY.equals(
739
				configuration.getType().getCategory())) {
740
					// don't prompt for builders
741
					return true;
742
		}
743
		return super.saveBeforeLaunch(configuration, mode, monitor);
744
	}
745
	
746
	/**
747
	 * Sets the default working directory to be the parent folder of the buildfile if
748
	 * the user has not explicitly set the working directory.
749
	 */
750
	private void setDefaultWorkingDirectory(ILaunchConfigurationWorkingCopy copy) {
751
		try {
752
			String wd = copy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String)null);
753
			if (wd == null) {
754
				wd= ExternalToolsUtil.getLocation(copy).removeLastSegments(1).toOSString();
755
				copy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, wd);
756
			}
757
		} catch (CoreException e) {
758
			AntUIPlugin.log(e.getStatus());
759
		}
760
	}
761
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntLaunchShortcut.java (-6 / +7 lines)
Lines 22-27 Link Here
22
import org.eclipse.ant.internal.ui.model.AntProjectNode;
22
import org.eclipse.ant.internal.ui.model.AntProjectNode;
23
import org.eclipse.ant.internal.ui.model.AntTargetNode;
23
import org.eclipse.ant.internal.ui.model.AntTargetNode;
24
import org.eclipse.ant.internal.ui.model.AntTaskNode;
24
import org.eclipse.ant.internal.ui.model.AntTaskNode;
25
import org.eclipse.ant.launching.IAntLaunchConstants;
26
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
25
import org.eclipse.core.resources.IContainer;
27
import org.eclipse.core.resources.IContainer;
26
import org.eclipse.core.resources.IFile;
28
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IProject;
29
import org.eclipse.core.resources.IProject;
Lines 55-61 Link Here
55
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
57
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
56
import org.eclipse.ui.editors.text.ILocationProvider;
58
import org.eclipse.ui.editors.text.ILocationProvider;
57
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
59
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
58
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
59
60
60
import com.ibm.icu.text.MessageFormat;
61
import com.ibm.icu.text.MessageFormat;
61
62
Lines 166-172 Link Here
166
	 */
167
	 */
167
	protected List collectConfigurations(IPath filepath) {
168
	protected List collectConfigurations(IPath filepath) {
168
		ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
169
		ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
169
		ILaunchConfigurationType type = manager.getLaunchConfigurationType(IAntLaunchConfigurationConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
170
		ILaunchConfigurationType type = manager.getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
170
		if(type != null) {
171
		if(type != null) {
171
			try {
172
			try {
172
				ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
173
				ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
Lines 260-272 Link Here
260
		// set the target to run, if applicable
261
		// set the target to run, if applicable
261
		if (configuration != null) {
262
		if (configuration != null) {
262
			try {
263
			try {
263
				if (targetAttribute != null && !targetAttribute.equals(configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, DEFAULT_TARGET))) {
264
				if (targetAttribute != null && !targetAttribute.equals(configuration.getAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, DEFAULT_TARGET))) {
264
					ILaunchConfigurationWorkingCopy copy = configuration.getWorkingCopy();
265
					ILaunchConfigurationWorkingCopy copy = configuration.getWorkingCopy();
265
					String attrValue = null;
266
					String attrValue = null;
266
					if (!DEFAULT_TARGET.equals(targetAttribute)) {
267
					if (!DEFAULT_TARGET.equals(targetAttribute)) {
267
						attrValue = targetAttribute;
268
						attrValue = targetAttribute;
268
					}
269
					}
269
					copy.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, attrValue);
270
					copy.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, attrValue);
270
					configuration = copy.doSave();
271
					configuration = copy.doSave();
271
				}
272
				}
272
			} catch (CoreException exception) {
273
			} catch (CoreException exception) {
Lines 367-373 Link Here
367
	 */
368
	 */
368
	public static ILaunchConfiguration createDefaultLaunchConfiguration(IPath filePath, IProject project) {
369
	public static ILaunchConfiguration createDefaultLaunchConfiguration(IPath filePath, IProject project) {
369
		ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
370
		ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
370
		ILaunchConfigurationType type = manager.getLaunchConfigurationType(IAntLaunchConfigurationConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
371
		ILaunchConfigurationType type = manager.getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
371
				
372
				
372
		String projectName= project != null ? project.getName() : null;
373
		String projectName= project != null ? project.getName() : null;
373
		String name = getNewLaunchConfigurationName(filePath, projectName, null);
374
		String name = getNewLaunchConfigurationName(filePath, projectName, null);
Lines 415-421 Link Here
415
			IPath filePath = file.getLocation();
416
			IPath filePath = file.getLocation();
416
			if(filePath != null) {
417
			if(filePath != null) {
417
				ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
418
				ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
418
				ILaunchConfigurationType type = manager.getLaunchConfigurationType(IAntLaunchConfigurationConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
419
				ILaunchConfigurationType type = manager.getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
419
				if (type != null) {
420
				if (type != null) {
420
					try {
421
					try {
421
						ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
422
						ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntMainTab.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-19 Link Here
14
import org.eclipse.ant.internal.ui.AntUtil;
14
import org.eclipse.ant.internal.ui.AntUtil;
15
import org.eclipse.ant.internal.ui.IAntUIConstants;
15
import org.eclipse.ant.internal.ui.IAntUIConstants;
16
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
16
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
17
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.resources.ResourcesPlugin;
Lines 35-41 Link Here
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsMainTab;
38
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsMainTab;
38
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
39
import org.eclipse.ui.externaltools.internal.ui.FileSelectionDialog;
39
import org.eclipse.ui.externaltools.internal.ui.FileSelectionDialog;
40
40
41
public class AntMainTab extends ExternalToolsMainTab {
41
public class AntMainTab extends ExternalToolsMainTab {
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntMigrationDelegate.java (-77 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.launchConfigurations;
12
13
import org.eclipse.ant.internal.ui.AntUtil;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.variables.IStringVariableManager;
18
import org.eclipse.core.variables.VariablesPlugin;
19
import org.eclipse.debug.core.ILaunchConfiguration;
20
import org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate;
21
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
22
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
23
24
/**
25
 * Delegate for migrating Ant launch configurations.
26
 * The migration process involves a resource mapping being created such that launch configurations
27
 * can be filtered from the launch configuration dialog based on resource availability.
28
 * 
29
 * @since 3.2
30
 */
31
public class AntMigrationDelegate implements ILaunchConfigurationMigrationDelegate {
32
	
33
	/**
34
	 * Method to get the file for the specified launch configuration that should be mapped to the launch configuration  
35
	 * 
36
	 * @param candidate the launch configuration that the file will be mapped to.
37
	 * @return the buildfile or <code>null</code> if not in the workspace
38
	 */
39
	protected IFile getFileForCandidate(ILaunchConfiguration candidate) {
40
		IFile file= null;
41
		String expandedLocation= null;
42
		String location= null;
43
		IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
44
		try {
45
			location= candidate.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String)null);
46
			if (location != null) {
47
				expandedLocation= manager.performStringSubstitution(location);
48
				if (expandedLocation != null) {
49
					file= AntUtil.getFileForLocation(expandedLocation, null);
50
				}
51
			}
52
		} catch (CoreException e) {
53
		}
54
		return file;
55
	}
56
	
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate#isCandidate()
59
	 */
60
	public boolean isCandidate(ILaunchConfiguration candidate) throws CoreException {
61
		IResource[] mappedResources = candidate.getMappedResources();
62
		if (mappedResources != null && mappedResources.length > 0) {
63
			return false;
64
		}
65
		return getFileForCandidate(candidate) != null;
66
	}
67
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate#migrate(org.eclipse.debug.core.ILaunchConfiguration)
70
	 */
71
	public void migrate(ILaunchConfiguration candidate) throws CoreException {
72
		IFile file = getFileForCandidate(candidate);
73
		ILaunchConfigurationWorkingCopy wc = candidate.getWorkingCopy();
74
		wc.setMappedResources(new IResource[] {file});
75
		wc.doSave();
76
	}
77
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntProcess.java (-193 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.launchConfigurations;
12
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.PlatformObject;
19
import org.eclipse.debug.core.DebugEvent;
20
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.ILaunch;
22
import org.eclipse.debug.core.model.IProcess;
23
import org.eclipse.debug.core.model.IStreamsProxy;
24
import org.eclipse.debug.ui.console.IConsole;
25
26
public class AntProcess extends PlatformObject implements IProcess, IProgressMonitor {
27
	
28
	private AntStreamsProxy fProxy;
29
	private String fLabel = null;
30
	private ILaunch fLaunch = null;
31
	private Map fAttributes = null;
32
	private boolean fTerminated = false;
33
	private boolean fCancelled = false;
34
	private IConsole fConsole = null;
35
	
36
	public AntProcess(String label, ILaunch launch, Map attributes) {
37
		fLabel = label;
38
		fLaunch = launch;
39
		if (attributes == null) {
40
			fAttributes = new HashMap();
41
		} else {
42
			fAttributes = attributes;
43
		}
44
		String captureOutput= launch.getAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT);
45
		if(!("false".equals(captureOutput))) { //$NON-NLS-1$
46
			fProxy= new AntStreamsProxy();
47
		}
48
		launch.addProcess(this);
49
	}
50
51
	/**
52
	 * @see org.eclipse.debug.core.model.IProcess#getLabel()
53
	 */
54
	public String getLabel() {
55
		return fLabel;
56
	}
57
58
	/**
59
	 * @see org.eclipse.debug.core.model.IProcess#getLaunch()
60
	 */
61
	public ILaunch getLaunch() {
62
		return fLaunch;
63
	}
64
65
	/**
66
	 * @see org.eclipse.debug.core.model.IProcess#getStreamsProxy()
67
	 */
68
	public IStreamsProxy getStreamsProxy() {
69
		return fProxy;
70
	}
71
72
	/**
73
	 * @see org.eclipse.debug.core.model.IProcess#setAttribute(java.lang.String, java.lang.String)
74
	 */
75
	public void setAttribute(String key, String value) {
76
		fAttributes.put(key, value);
77
	}
78
79
	/**
80
	 * @see org.eclipse.debug.core.model.IProcess#getAttribute(java.lang.String)
81
	 */
82
	public String getAttribute(String key) {
83
		return (String)fAttributes.get(key);
84
	}
85
86
	/**
87
	 * @see org.eclipse.debug.core.model.IProcess#getExitValue()
88
	 */
89
	public int getExitValue() {
90
		return 0;
91
	}
92
93
	/**
94
	 * @see org.eclipse.debug.core.model.ITerminate#canTerminate()
95
	 */
96
	public boolean canTerminate() {
97
		return !isCanceled() && !isTerminated();
98
	}
99
100
	/**
101
	 * @see org.eclipse.debug.core.model.ITerminate#isTerminated()
102
	 */
103
	public boolean isTerminated() {
104
		return fTerminated;
105
	}
106
	
107
	protected void terminated() {
108
		if (!fTerminated) {
109
			fTerminated = true;
110
			if (DebugPlugin.getDefault() != null) {
111
				DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] {new DebugEvent(this, DebugEvent.TERMINATE)});
112
			}
113
		}
114
	}
115
116
	/**
117
	 * @see org.eclipse.debug.core.model.ITerminate#terminate()
118
	 */
119
	public void terminate() {
120
		setCanceled(true);
121
	}
122
123
	/**
124
	 * Returns the console associated with this process, or <code>null</code> if
125
	 * none.
126
	 * 
127
	 * @return console, or <code>null</code>
128
	 */
129
	public IConsole getConsole() {
130
		return fConsole;
131
	}
132
	
133
	/**
134
	 * Sets the console associated with this process.
135
	 * 
136
	 * @param console
137
	 */
138
	public void setConsole(IConsole console) {
139
		fConsole = console;
140
	}
141
	
142
	// IProgressMonitor implemented to support termination.
143
	
144
	/**
145
	 * @see org.eclipse.core.runtime.IProgressMonitor#beginTask(java.lang.String, int)
146
	 */
147
	public void beginTask(String name, int totalWork) {
148
	}
149
150
	/**
151
	 * @see org.eclipse.core.runtime.IProgressMonitor#done()
152
	 */
153
	public void done() {
154
	}
155
156
	/**
157
	 * @see org.eclipse.core.runtime.IProgressMonitor#internalWorked(double)
158
	 */
159
	public void internalWorked(double work) {
160
	}
161
162
	/**
163
	 * @see org.eclipse.core.runtime.IProgressMonitor#isCanceled()
164
	 */
165
	public boolean isCanceled() {
166
		return fCancelled;
167
	}
168
169
	/**
170
	 * @see org.eclipse.core.runtime.IProgressMonitor#setCanceled(boolean)
171
	 */
172
	public void setCanceled(boolean value) {
173
		fCancelled = value;
174
	}
175
176
	/**
177
	 * @see org.eclipse.core.runtime.IProgressMonitor#setTaskName(java.lang.String)
178
	 */
179
	public void setTaskName(String name) {
180
	}
181
182
	/**
183
	 * @see org.eclipse.core.runtime.IProgressMonitor#subTask(java.lang.String)
184
	 */
185
	public void subTask(String name) {
186
	}
187
188
	/**
189
	 * @see org.eclipse.core.runtime.IProgressMonitor#worked(int)
190
	 */
191
	public void worked(int work) {
192
	}
193
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntPropertiesTab.java (-7 / +7 lines)
Lines 24-30 Link Here
24
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
24
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
25
import org.eclipse.ant.internal.ui.preferences.AntPropertiesBlock;
25
import org.eclipse.ant.internal.ui.preferences.AntPropertiesBlock;
26
import org.eclipse.ant.internal.ui.preferences.IAntBlockContainer;
26
import org.eclipse.ant.internal.ui.preferences.IAntBlockContainer;
27
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
27
import org.eclipse.ant.launching.IAntLaunchConstants;
28
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.debug.core.ILaunchConfiguration;
29
import org.eclipse.debug.core.ILaunchConfiguration;
30
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
30
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
Lines 116-129 Link Here
116
		setMessage(null);
116
		setMessage(null);
117
		Map properties= null;
117
		Map properties= null;
118
		try {
118
		try {
119
			properties= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, (Map)null);
119
			properties= configuration.getAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, (Map)null);
120
		} catch (CoreException ce) {
120
		} catch (CoreException ce) {
121
			AntUIPlugin.log(AntLaunchConfigurationMessages.AntPropertiesTab_Error_reading_configuration_9, ce);
121
			AntUIPlugin.log(AntLaunchConfigurationMessages.AntPropertiesTab_Error_reading_configuration_9, ce);
122
		}
122
		}
123
		
123
		
124
		String propertyFiles= null;
124
		String propertyFiles= null;
125
		try {
125
		try {
126
			propertyFiles= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, (String)null);
126
			propertyFiles= configuration.getAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTY_FILES, (String)null);
127
		} catch (CoreException ce) {
127
		} catch (CoreException ce) {
128
			AntUIPlugin.log(AntLaunchConfigurationMessages.AntPropertiesTab_Error_reading_configuration_9, ce);
128
			AntUIPlugin.log(AntLaunchConfigurationMessages.AntPropertiesTab_Error_reading_configuration_9, ce);
129
		}
129
		}
Lines 160-167 Link Here
160
	 */
160
	 */
161
	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
161
	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
162
		if (fUseDefaultButton.getSelection()) {
162
		if (fUseDefaultButton.getSelection()) {
163
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, (Map)null);
163
			configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, (Map)null);
164
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, (String)null);
164
			configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTY_FILES, (String)null);
165
			return;
165
			return;
166
		}
166
		}
167
				
167
				
Lines 175-181 Link Here
175
			}
175
			}
176
		}
176
		}
177
		
177
		
178
		configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES, properties);
178
		configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTIES, properties);
179
		
179
		
180
		items= fAntPropertiesBlock.getPropertyFiles();
180
		items= fAntPropertiesBlock.getPropertyFiles();
181
		String files= null;
181
		String files= null;
Lines 189-195 Link Here
189
			files= buff.toString();
189
			files= buff.toString();
190
		}
190
		}
191
		
191
		
192
		configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES, files);
192
		configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_PROPERTY_FILES, files);
193
		
193
		
194
		fAntPropertiesBlock.saveSettings();
194
		fAntPropertiesBlock.saveSettings();
195
	}
195
	}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntStreamMonitor.java (-83 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.launchConfigurations;
12
13
import org.eclipse.core.runtime.ListenerList;
14
import org.eclipse.debug.core.IStreamListener;
15
import org.eclipse.debug.core.model.IFlushableStreamMonitor;
16
17
/**
18
 * Stream monitor implementation for an Ant build process.
19
 */
20
public class AntStreamMonitor implements IFlushableStreamMonitor {
21
22
	private StringBuffer fContents = new StringBuffer();
23
	private ListenerList fListeners = new ListenerList(1);
24
	private boolean fBuffered = true;
25
	
26
	/**
27
	 * @see org.eclipse.debug.core.model.IStreamMonitor#addListener(org.eclipse.debug.core.IStreamListener)
28
	 */
29
	public void addListener(IStreamListener listener) {
30
		fListeners.add(listener);
31
	}
32
33
	/**
34
	 * @see org.eclipse.debug.core.model.IStreamMonitor#getContents()
35
	 */
36
	public String getContents() {
37
		return fContents.toString();
38
	}
39
40
	/**
41
	 * @see org.eclipse.debug.core.model.IStreamMonitor#removeListener(org.eclipse.debug.core.IStreamListener)
42
	 */
43
	public void removeListener(IStreamListener listener) {
44
		fListeners.remove(listener);
45
	}
46
47
	/**
48
	 * Appends the given message to this stream, and notifies listeners.
49
	 * 
50
	 * @param message
51
	 */
52
	public void append(String message) {
53
		if (isBuffered()) {
54
			fContents.append(message);
55
		}
56
		Object[] listeners = fListeners.getListeners();
57
		for (int i = 0; i < listeners.length; i++) {
58
			IStreamListener listener = (IStreamListener)listeners[i];
59
			listener.streamAppended(message, this);
60
		}
61
	}
62
	/**
63
	 * @see org.eclipse.debug.core.model.IFlushableStreamMonitor#flushContents()
64
	 */
65
	public void flushContents() {
66
		fContents.setLength(0);
67
	}
68
69
	/**
70
	 * @see org.eclipse.debug.core.model.IFlushableStreamMonitor#isBuffered()
71
	 */
72
	public boolean isBuffered() {
73
		return fBuffered;
74
	}
75
76
	/**
77
	 * @see org.eclipse.debug.core.model.IFlushableStreamMonitor#setBuffered(boolean)
78
	 */
79
	public void setBuffered(boolean buffer) {
80
		fBuffered = buffer;
81
	}
82
}
83
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntStreamsProxy.java (-65 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.launchConfigurations;
12
13
14
import org.eclipse.ant.internal.ui.IAntUIConstants;
15
import org.eclipse.debug.core.model.IStreamMonitor;
16
import org.eclipse.debug.core.model.IStreamsProxy;
17
18
/**
19
 * 
20
 */
21
public class AntStreamsProxy implements IStreamsProxy {
22
	
23
	private AntStreamMonitor fErrorMonitor = new AntStreamMonitor();
24
	private AntStreamMonitor fOutputMonitor = new AntStreamMonitor();
25
	
26
	public static final String ANT_DEBUG_STREAM = IAntUIConstants.PLUGIN_ID + ".ANT_DEBUG_STREAM"; //$NON-NLS-1$
27
	public static final String ANT_VERBOSE_STREAM = IAntUIConstants.PLUGIN_ID + ".ANT_VERBOSE_STREAM"; //$NON-NLS-1$
28
	public static final String ANT_WARNING_STREAM = IAntUIConstants.PLUGIN_ID + ".ANT_WARNING_STREAM"; //$NON-NLS-1$
29
	
30
	private AntStreamMonitor fDebugMonitor = new AntStreamMonitor();
31
	private AntStreamMonitor fVerboseMonitor = new AntStreamMonitor();
32
	private AntStreamMonitor fWarningMonitor = new AntStreamMonitor();
33
34
	/**
35
	 * @see org.eclipse.debug.core.model.IStreamsProxy#getErrorStreamMonitor()
36
	 */
37
	public IStreamMonitor getErrorStreamMonitor() {
38
		return fErrorMonitor;
39
	}
40
41
	/**
42
	 * @see org.eclipse.debug.core.model.IStreamsProxy#getOutputStreamMonitor()
43
	 */
44
	public IStreamMonitor getOutputStreamMonitor() {
45
		return fOutputMonitor;
46
	}
47
48
	/**
49
	 * @see org.eclipse.debug.core.model.IStreamsProxy#write(java.lang.String)
50
	 */
51
	public void write(String input) {
52
	}
53
54
	public IStreamMonitor getWarningStreamMonitor() {
55
		return fWarningMonitor;
56
	}
57
	
58
	public IStreamMonitor getDebugStreamMonitor() {
59
		return fDebugMonitor;
60
	}	
61
	
62
	public IStreamMonitor getVerboseStreamMonitor() {
63
		return fVerboseMonitor;
64
	}	
65
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntTabGroup.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 11-16 Link Here
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.ant.internal.ui.launchConfigurations;
12
package org.eclipse.ant.internal.ui.launchConfigurations;
13
13
14
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
14
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
Lines 27-33 Link Here
27
import org.eclipse.debug.ui.RefreshTab;
28
import org.eclipse.debug.ui.RefreshTab;
28
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
29
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
29
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsBuildTab;
30
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsBuildTab;
30
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
31
31
32
public class AntTabGroup extends AbstractLaunchConfigurationTabGroup {
32
public class AntTabGroup extends AbstractLaunchConfigurationTabGroup {
33
33
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntTargetsTab.java (-13 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 28-34 Link Here
28
import org.eclipse.ant.internal.ui.model.AntProjectNode;
28
import org.eclipse.ant.internal.ui.model.AntProjectNode;
29
import org.eclipse.ant.internal.ui.model.AntTargetNode;
29
import org.eclipse.ant.internal.ui.model.AntTargetNode;
30
import org.eclipse.ant.internal.ui.model.InternalTargetFilter;
30
import org.eclipse.ant.internal.ui.model.InternalTargetFilter;
31
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
31
import org.eclipse.ant.launching.IAntLaunchConstants;
32
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
32
import org.eclipse.core.resources.ResourcesPlugin;
33
import org.eclipse.core.resources.ResourcesPlugin;
33
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.core.runtime.IProgressMonitor;
35
import org.eclipse.core.runtime.IProgressMonitor;
Lines 72-78 Link Here
72
import org.eclipse.swt.widgets.TableColumn;
73
import org.eclipse.swt.widgets.TableColumn;
73
import org.eclipse.swt.widgets.Text;
74
import org.eclipse.swt.widgets.Text;
74
import org.eclipse.ui.PlatformUI;
75
import org.eclipse.ui.PlatformUI;
75
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
76
76
77
import com.ibm.icu.text.MessageFormat;
77
import com.ibm.icu.text.MessageFormat;
78
78
Lines 613-619 Link Here
613
		setDirty(true);
613
		setDirty(true);
614
		boolean hideInternal= false;
614
		boolean hideInternal= false;
615
		try {
615
		try {
616
			hideInternal = fLaunchConfiguration.getAttribute(IAntLaunchConfigurationConstants.ATTR_HIDE_INTERNAL_TARGETS, false);
616
			hideInternal = fLaunchConfiguration.getAttribute(IAntLaunchConstants.ATTR_HIDE_INTERNAL_TARGETS, false);
617
		} catch (CoreException e) {
617
		} catch (CoreException e) {
618
			AntUIPlugin.log(e);
618
			AntUIPlugin.log(e);
619
		}
619
		}
Lines 621-627 Link Here
621
		handleFilterTargetsSelected();
621
		handleFilterTargetsSelected();
622
		int sort= SORT_NONE;
622
		int sort= SORT_NONE;
623
		try {
623
		try {
624
			sort = fLaunchConfiguration.getAttribute(IAntLaunchConfigurationConstants.ATTR_SORT_TARGETS, sort);
624
			sort = fLaunchConfiguration.getAttribute(IAntLaunchConstants.ATTR_SORT_TARGETS, sort);
625
		} catch (CoreException e) {
625
		} catch (CoreException e) {
626
			AntUIPlugin.log(e);
626
			AntUIPlugin.log(e);
627
		}
627
		}
Lines 631-637 Link Here
631
		String newLocation= null;
631
		String newLocation= null;
632
		
632
		
633
		try {
633
		try {
634
			configTargets= configuration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, (String)null);
634
			configTargets= configuration.getAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, (String)null);
635
			newLocation= configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String)null);
635
			newLocation= configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String)null);
636
		} catch (CoreException ce) {
636
		} catch (CoreException ce) {
637
			AntUIPlugin.log(AntLaunchConfigurationMessages.AntTargetsTab_Error_reading_configuration_12, ce);
637
			AntUIPlugin.log(AntLaunchConfigurationMessages.AntTargetsTab_Error_reading_configuration_12, ce);
Lines 697-721 Link Here
697
	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
697
	public void performApply(ILaunchConfigurationWorkingCopy configuration) {
698
		//	attribute added in 3.0, so null must be used instead of false for backwards compatibility
698
		//	attribute added in 3.0, so null must be used instead of false for backwards compatibility
699
		if (fFilterInternalTargets.getSelection()) {
699
		if (fFilterInternalTargets.getSelection()) {
700
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_HIDE_INTERNAL_TARGETS, true);
700
			configuration.setAttribute(IAntLaunchConstants.ATTR_HIDE_INTERNAL_TARGETS, true);
701
		} else {
701
		} else {
702
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_HIDE_INTERNAL_TARGETS, (String)null);
702
			configuration.setAttribute(IAntLaunchConstants.ATTR_HIDE_INTERNAL_TARGETS, (String)null);
703
		}
703
		}
704
		//attribute added in 3.0, so null must be used instead of 0 for backwards compatibility
704
		//attribute added in 3.0, so null must be used instead of 0 for backwards compatibility
705
		if (fSortDirection != SORT_NONE) {
705
		if (fSortDirection != SORT_NONE) {
706
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_SORT_TARGETS, fSortDirection);
706
			configuration.setAttribute(IAntLaunchConstants.ATTR_SORT_TARGETS, fSortDirection);
707
		} else {
707
		} else {
708
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_SORT_TARGETS, (String)null);
708
			configuration.setAttribute(IAntLaunchConstants.ATTR_SORT_TARGETS, (String)null);
709
		}
709
		}
710
		
710
		
711
		if (fOrderedTargets.size() == 1) {
711
		if (fOrderedTargets.size() == 1) {
712
			AntTargetNode item = (AntTargetNode)fOrderedTargets.get(0);
712
			AntTargetNode item = (AntTargetNode)fOrderedTargets.get(0);
713
			if (item.isDefaultTarget()) {
713
			if (item.isDefaultTarget()) {
714
				configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, (String)null);
714
				configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, (String)null);
715
				return;
715
				return;
716
			}
716
			}
717
		} else if (fOrderedTargets.size() == 0) {
717
		} else if (fOrderedTargets.size() == 0) {
718
			configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, (String)null);
718
			configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, (String)null);
719
			return;
719
			return;
720
		}
720
		}
721
		
721
		
Lines 731-737 Link Here
731
			targets= buff.toString();
731
			targets= buff.toString();
732
		}  
732
		}  
733
733
734
		configuration.setAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, targets);
734
		configuration.setAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, targets);
735
	}
735
	}
736
736
737
	/* (non-Javadoc)
737
	/* (non-Javadoc)
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntWorkingDirectoryBlock.java (-1 / +1 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/ContributedClasspathEntriesEntry.java (-246 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.launchConfigurations;
12
13
import java.io.File;
14
import java.io.FilenameFilter;
15
import java.io.IOException;
16
import java.net.MalformedURLException;
17
import java.net.URL;
18
import java.util.ArrayList;
19
import java.util.List;
20
21
import org.eclipse.ant.core.AntCorePlugin;
22
import org.eclipse.ant.core.AntCorePreferences;
23
import org.eclipse.ant.core.IAntClasspathEntry;
24
import org.eclipse.ant.internal.ui.AntUIPlugin;
25
import org.eclipse.ant.internal.ui.AntUtil;
26
import org.eclipse.ant.internal.ui.IAntUIConstants;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.FileLocator;
29
import org.eclipse.core.runtime.IPath;
30
import org.eclipse.core.runtime.Path;
31
import org.eclipse.core.runtime.Platform;
32
import org.eclipse.debug.core.ILaunchConfiguration;
33
import org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry;
34
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
35
import org.eclipse.jdt.launching.IVMInstall;
36
import org.eclipse.jdt.launching.JavaRuntime;
37
import org.eclipse.osgi.service.resolver.BundleDescription;
38
import org.osgi.framework.Bundle;
39
import org.w3c.dom.Document;
40
import org.w3c.dom.Element;
41
42
/**
43
 * A classpath entry that contains a contributed classpath entries
44
 * via the <code>extraClasspathEntries</code> extension point.
45
 * 
46
 * @since 3.0 
47
 */
48
public class ContributedClasspathEntriesEntry extends AbstractRuntimeClasspathEntry {
49
	
50
	public static final String TYPE_ID = "org.eclipse.ant.ui.classpathentry.extraClasspathEntries"; //$NON-NLS-1$
51
    
52
    public static List fgSWTEntries= null;
53
		
54
	/**
55
	 * Default contructor required to instantiate persisted extensions.
56
	 */
57
	public ContributedClasspathEntriesEntry() {
58
	}
59
	
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.jdt.internal.launching.AbstractRuntimeClasspathEntry#buildMemento(org.w3c.dom.Document, org.w3c.dom.Element)
62
	 */
63
	protected void buildMemento(Document document, Element memento) throws CoreException {
64
	}
65
	
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.jdt.internal.launching.IRuntimeClasspathEntry2#initializeFrom(org.w3c.dom.Element)
68
	 */
69
	public void initializeFrom(Element memento) throws CoreException {
70
	}
71
	
72
	/* (non-Javadoc)
73
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getTypeId()
74
	 */
75
	public String getTypeId() {
76
		return TYPE_ID;
77
	}
78
	
79
	/* (non-Javadoc)
80
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getRuntimeClasspathEntries(org.eclipse.debug.core.ILaunchConfiguration)
81
	 */
82
	public IRuntimeClasspathEntry[] getRuntimeClasspathEntries(ILaunchConfiguration configuration) throws CoreException {
83
		boolean separateVM= AntUtil.isSeparateJREAntBuild(configuration);
84
		boolean setInputHandler= configuration.getAttribute(IAntUIConstants.SET_INPUTHANDLER, true);
85
		AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences();
86
		IAntClasspathEntry[] antClasspathEntries = prefs.getContributedClasspathEntries();
87
		IAntClasspathEntry[] userEntries = prefs.getAdditionalClasspathEntries();
88
		List rtes = new ArrayList(antClasspathEntries.length + userEntries.length);
89
		IAntClasspathEntry entry;
90
		for (int i = 0; i < antClasspathEntries.length; i++) {
91
			 entry= antClasspathEntries[i];
92
			if (!separateVM || (separateVM && !entry.isEclipseRuntimeRequired())) {
93
				rtes.add(JavaRuntime.newStringVariableClasspathEntry(entry.getLabel()));
94
			}
95
		}
96
		boolean haveToolsEntry= false;
97
		String path;
98
		for (int i = 0; i < userEntries.length; i++) {
99
			entry = userEntries[i];
100
			path= entry.getLabel();
101
            IPath toolsPath= new Path(path);
102
			if (toolsPath.lastSegment().equals("tools.jar")) { //$NON-NLS-1$
103
				haveToolsEntry= true;
104
				// replace with dynamically resolved tools.jar based on
105
				// the JRE being used
106
				addToolsJar(configuration, rtes, path);
107
			} else {
108
				rtes.add(JavaRuntime.newStringVariableClasspathEntry(path));
109
			}
110
		}
111
		if (!haveToolsEntry) {
112
			addToolsJar(configuration, rtes, null);
113
		}
114
		
115
		if (setInputHandler && separateVM) {
116
			addSWTJars(rtes);
117
		}
118
		
119
		return (IRuntimeClasspathEntry[]) rtes.toArray(new IRuntimeClasspathEntry[rtes.size()]);
120
	}
121
	
122
	private void addToolsJar(ILaunchConfiguration configuration, List rtes, String path) {
123
		IRuntimeClasspathEntry tools = getToolsJar(configuration);
124
		if (tools == null) {
125
			if (path != null) {
126
				//use the global entry
127
				rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(path)));
128
			} else {
129
				//use the default vm install to try to find a tools.jar
130
				IVMInstall install= JavaRuntime.getDefaultVMInstall();
131
				if (install != null) {
132
					IAntClasspathEntry entry = AntCorePlugin.getPlugin().getPreferences().getToolsJarEntry(new Path(install.getInstallLocation().getAbsolutePath()));
133
					if (entry != null) {
134
						rtes.add(JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(entry.getEntryURL().getPath())));
135
					}
136
				}
137
			}
138
		} else {
139
			rtes.add(tools);
140
		}
141
	}
142
	
143
	private void addSWTJars(List rtes) {
144
        if (fgSWTEntries == null) {
145
            fgSWTEntries= new ArrayList();
146
            Bundle bundle= Platform.getBundle("org.eclipse.swt"); //$NON-NLS-1$
147
            BundleDescription description= Platform.getPlatformAdmin().getState(false).getBundle(bundle.getBundleId());
148
            BundleDescription[] fragments= description.getFragments();
149
            for (int i = 0; i < fragments.length; i++) {
150
                Bundle fragmentBundle= Platform.getBundle(fragments[i].getName());
151
                URL bundleURL;
152
                try {
153
                    bundleURL = FileLocator.resolve(fragmentBundle.getEntry("/")); //$NON-NLS-1$
154
                } catch (IOException e) {
155
                    AntUIPlugin.log(e);
156
                   continue;
157
                }
158
                String urlFileName= bundleURL.getFile();
159
                if (urlFileName.startsWith("file:")) { //$NON-NLS-1$
160
                    try {
161
                        urlFileName= new URL(urlFileName).getFile();
162
                        if (urlFileName.endsWith("!/")) { //$NON-NLS-1$
163
                            urlFileName= urlFileName.substring(0, urlFileName.length() - 2);
164
                        }
165
                    } catch (MalformedURLException e) {
166
                        AntUIPlugin.log(e);
167
                       continue;
168
                    }
169
                }
170
                IPath fragmentPath= new Path(urlFileName);
171
                if (fragmentPath.getFileExtension() != null) { //JAR file
172
                    fgSWTEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath));
173
                } else { // folder
174
                    File bundleFolder= fragmentPath.toFile();
175
                    if (!bundleFolder.isDirectory()) {
176
                        continue;
177
                    }
178
                    String[] names= bundleFolder.list(new FilenameFilter() {
179
                        public boolean accept(File dir, String name) {
180
                            return name.endsWith(".jar"); //$NON-NLS-1$
181
                        }
182
                    });
183
                    for (int j = 0; j < names.length; j++) {
184
                        String jarName = names[j];
185
                        fgSWTEntries.add(JavaRuntime.newArchiveRuntimeClasspathEntry(fragmentPath.append(jarName)));
186
                    }
187
                }
188
            }
189
        }
190
        rtes.addAll(fgSWTEntries);
191
	}
192
    
193
	/**
194
	 * Returns the tools.jar to use for this launch configuration, or <code>null</code>
195
	 * if none.
196
	 * 
197
	 * @param configuration configuration to resolve a tools.jar for
198
	 * @return associated tools.jar archive, or <code>null</code>
199
	 */
200
	private IRuntimeClasspathEntry getToolsJar(ILaunchConfiguration configuration) {
201
		try {
202
			IVMInstall install = JavaRuntime.computeVMInstall(configuration);
203
			if (install != null) {
204
				IAntClasspathEntry entry = AntCorePlugin.getPlugin().getPreferences().getToolsJarEntry(new Path(install.getInstallLocation().getAbsolutePath()));
205
				if (entry != null) {
206
					return JavaRuntime.newArchiveRuntimeClasspathEntry(new Path(entry.getEntryURL().getPath()));
207
				}
208
			}
209
		} catch (CoreException ce) {
210
			//likely dealing with a non-Java project
211
		}
212
			
213
		return null;
214
	}
215
	
216
	/* (non-Javadoc)
217
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#getName()
218
	 */
219
	public String getName() {
220
		return AntLaunchConfigurationMessages.ContributedClasspathEntriesEntry_1;
221
	}
222
	/* (non-Javadoc)
223
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry#getType()
224
	 */
225
	public int getType() {
226
		return IRuntimeClasspathEntry.OTHER;
227
	}
228
	/* (non-Javadoc)
229
	 * @see org.eclipse.jdt.launching.IRuntimeClasspathEntry2#isComposite()
230
	 */
231
	public boolean isComposite() {
232
		return true;
233
	}
234
	/* (non-Javadoc)
235
	 * @see java.lang.Object#equals(java.lang.Object)
236
	 */
237
	public boolean equals(Object obj) {
238
		return obj instanceof ContributedClasspathEntriesEntry;
239
	}
240
	/* (non-Javadoc)
241
	 * @see java.lang.Object#hashCode()
242
	 */
243
	public int hashCode() {
244
		return getClass().hashCode();
245
	}
246
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/EditAntHomeEntryAction.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-17 Link Here
12
12
13
import org.eclipse.ant.core.AntCorePlugin;
13
import org.eclipse.ant.core.AntCorePlugin;
14
import org.eclipse.ant.core.AntCorePreferences;
14
import org.eclipse.ant.core.AntCorePreferences;
15
import org.eclipse.ant.internal.launching.launchConfigurations.AntHomeClasspathEntry;
15
import org.eclipse.ant.internal.ui.AntUIPlugin;
16
import org.eclipse.ant.internal.ui.AntUIPlugin;
16
import org.eclipse.ant.internal.ui.IAntUIConstants;
17
import org.eclipse.ant.internal.ui.IAntUIConstants;
17
import org.eclipse.ant.internal.ui.preferences.AntPreferencesMessages;
18
import org.eclipse.ant.internal.ui.preferences.AntPreferencesMessages;
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/IAntLaunchConfigurationConstants.java (-156 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.launchConfigurations;
13
14
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
15
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
16
17
/**
18
 * Constant definitions for Ant launch configurations.
19
 * <p>
20
 * Constant definitions only; not to be implemented.
21
 * </p>
22
 * @since 3.0
23
 * @noimplement This interface is not intended to be implemented by clients.
24
 */
25
public interface IAntLaunchConfigurationConstants {
26
27
	/**
28
	* String attribute indicating the custom runtime classpath to use for an Ant
29
	* build. Default value is <code>null</code> which indicates that the global
30
	* classpath is to be used. Format is a comma separated listing of URLs.
31
	* @deprecated no longer supported: use {@link IJavaLaunchConfigurationConstants#ATTR_CLASSPATH_PROVIDER}
32
	* @see IJavaLaunchConfigurationConstants#ATTR_DEFAULT_CLASSPATH
33
	*/
34
	public static final String ATTR_ANT_CUSTOM_CLASSPATH = IExternalToolConstants.PLUGIN_ID + ".ATTR_ANT_CUSTOM_CLASSPATH"; //$NON-NLS-1$
35
	/**
36
	 * String attribute indicating the custom Ant home to use for an Ant build.
37
	 * Default value is <code>null</code> which indicates that no Ant home is to
38
	 * be set 
39
	 * @deprecated no longer supported: use {@link IJavaLaunchConfigurationConstants#ATTR_CLASSPATH_PROVIDER}
40
	 * @see IJavaLaunchConfigurationConstants#ATTR_DEFAULT_CLASSPATH
41
	 */
42
	public static final String ATTR_ANT_HOME = IExternalToolConstants.PLUGIN_ID + ".ATTR_ANT_HOME"; //$NON-NLS-1$
43
	
44
	
45
	/**
46
	 * String attribute indicating the Ant targets to execute. Default value is
47
	 * <code>null</code> which indicates that the default target is to be
48
	 * executed. Format is a comma separated listing of targets.
49
	 * 
50
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants}
51
	 */
52
	public static final String ATTR_ANT_TARGETS = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS;
53
	/**
54
	 * String attribute indicating the Ant targets to execute after a clean (full build) for an Ant builder. Default value is
55
	 * <code>null</code> which indicates that the default target is to be
56
	 * executed. Format is a comma separated listing of targets.
57
	 * @since 3.1
58
	 * 
59
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants}
60
	 */
61
	public static final String ATTR_ANT_AFTER_CLEAN_TARGETS = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AFTER_CLEAN_TARGETS;
62
	/**
63
	 * String attribute indicating the Ant targets to execute during a manual build for an Ant builder. Default value is
64
	 * <code>null</code> which indicates that the default target is to be
65
	 * executed. Format is a comma separated listing of targets.
66
	 * @since 3.1
67
	 * 
68
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants} 
69
	 */
70
	public static final String ATTR_ANT_MANUAL_TARGETS = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_MANUAL_TARGETS;
71
	/**
72
	 * String attribute indicating the Ant targets to execute during an auto build for an Ant builder. Default value is
73
	 * <code>null</code> which indicates that the default target is to be
74
	 * executed. Format is a comma separated listing of targets.
75
	 * @since 3.1
76
	 * 
77
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants} 
78
	 */
79
	public static final String ATTR_ANT_AUTO_TARGETS = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_AUTO_TARGETS;
80
	/**
81
	 * String attribute indicating the Ant targets to execute during a clean for an Ant builder. Default value is
82
	 * <code>null</code> which indicates that the default target is to be
83
	 * executed. Format is a comma separated listing of targets.
84
	 * @since 3.1
85
	 * 
86
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants} 
87
	 */
88
	public static final String ATTR_ANT_CLEAN_TARGETS = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_CLEAN_TARGETS;
89
	/**
90
	 * Boolean attribute indicating whether or not target specification for an Ant builder has been updated for
91
	 * 3.1 
92
	 * 
93
	 * @since 3.1
94
	 * 
95
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants}
96
	 */
97
	public static final String ATTR_TARGETS_UPDATED = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_TARGETS_UPDATED;
98
	/**
99
	 * Map attribute indicating the Ant properties to be defined during the
100
	 * build. Default value is <code>null</code> which indicates no additional
101
	 * properties will be defined.
102
	 * 
103
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants}
104
	 */
105
	public static final String ATTR_ANT_PROPERTIES = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTIES;				
106
	/**
107
	 * String attribute indicating the Ant targets to execute. Default value is
108
	 * <code>null</code> which indicates that no additional property files
109
	 * will be defined. Format is a comma separated listing of property files.
110
	 * 
111
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants} 
112
	 */
113
	public static final String ATTR_ANT_PROPERTY_FILES = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_ANT_PROPERTY_FILES;
114
	/**
115
	 * Boolean attribute indicating whether or not internal targets (targets with no
116
	 * description) should be hidden from the user in the launch configuration dialog.
117
	 * Default value is <code>false</code> which indicates that all targets will be
118
	 * displayed.
119
	 * 
120
	 * @since 3.0
121
	 * 
122
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants}
123
	 */
124
	public static final String ATTR_HIDE_INTERNAL_TARGETS = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_HIDE_INTERNAL_TARGETS;
125
	/**
126
	 * Integer attribute indicating which column targets should be sorted on. A
127
	 * value of 0 indicates target name, 1 indicates target description, and -1
128
	 * indicates no sort. Default value is -1.
129
	 * 
130
	 * @since 3.0
131
	 * 
132
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants}
133
	 */
134
	public static final String ATTR_SORT_TARGETS = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ATTR_SORT_TARGETS;
135
	/**
136
	 * Ant launch configuration type identifier.
137
	 * 
138
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants} 
139
	 */
140
	public static final String ID_ANT_LAUNCH_CONFIGURATION_TYPE = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE;
141
	/**
142
	 * Ant builder launch configuration type identifier. Ant project builders
143
	 * are of this type.
144
	 * 
145
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants} 
146
	 */
147
	public static final String ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE;
148
	/**
149
	 * Identifier for Ant processes (value <code>org.eclipse.ant.ui.antProcess</code>). This identifier is
150
	 * set as the value for the <code>IProcess.ATTR_PROCESS_TYPE</code>
151
	 * attribute in processes created by the Ant launch delegate.
152
	 * 
153
	 * @deprecated This constant has been migrated to {@link org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants} 
154
	 */
155
	public static final String ID_ANT_PROCESS_TYPE = org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants.ID_ANT_PROCESS_TYPE;
156
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/MessageIds.java (-21 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.launchConfigurations;
13
14
public class MessageIds {
15
16
	public final static String PROCESS_ID=   "processID"; //$NON-NLS-1$
17
	public final static String BUILD_CANCELLED= "cancelled"; //$NON-NLS-1$
18
	//constants need to start greater than the Project.MSG_* constants
19
    public final static String TASK= "6"; //$NON-NLS-1$
20
    public final static String TARGET= "7"; //$NON-NLS-1$
21
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/RemoteAntBuildListener.java (-396 lines)
Removed Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2003, 2008 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 *  Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.launchConfigurations;
13
14
import java.io.BufferedReader;
15
import java.io.File;
16
import java.io.IOException;
17
import java.io.InputStreamReader;
18
import java.net.ServerSocket;
19
import java.net.Socket;
20
import java.net.SocketException;
21
import java.net.SocketTimeoutException;
22
import java.util.ArrayList;
23
import java.util.HashMap;
24
import java.util.Iterator;
25
import java.util.List;
26
import java.util.Map;
27
import java.util.StringTokenizer;
28
29
import org.apache.tools.ant.Project;
30
import org.apache.tools.ant.util.FileUtils;
31
import org.eclipse.ant.internal.core.AbstractEclipseBuildLogger;
32
import org.eclipse.ant.internal.ui.AntUIPlugin;
33
import org.eclipse.ant.internal.ui.AntUtil;
34
import org.eclipse.ant.internal.ui.ExternalHyperlink;
35
import org.eclipse.ant.internal.ui.IAntUIConstants;
36
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
37
import org.eclipse.core.resources.IFile;
38
import org.eclipse.core.runtime.ISafeRunnable;
39
import org.eclipse.debug.core.DebugPlugin;
40
import org.eclipse.debug.core.ILaunch;
41
import org.eclipse.debug.core.ILaunchesListener;
42
import org.eclipse.debug.core.model.IProcess;
43
import org.eclipse.debug.ui.console.FileLink;
44
import org.eclipse.jface.preference.IPreferenceStore;
45
import org.eclipse.jface.text.Region;
46
import org.eclipse.ui.console.IHyperlink;
47
48
/**
49
 * Parts adapted from org.eclipse.jdt.internal.junit.ui.RemoteTestRunnerClient
50
 * The client side of the RemoteAntBuildLogger. Handles the
51
 * marshalling of the different messages.
52
 */
53
public class RemoteAntBuildListener implements ILaunchesListener {
54
    public abstract class ListenerSafeRunnable implements ISafeRunnable {
55
        public void handleException(Throwable exception) {
56
            AntUIPlugin.log(exception);
57
        }
58
    }
59
60
    /**
61
     * The server socket
62
     */
63
    private ServerSocket fServerSocket;
64
    private Socket fSocket;
65
    private BufferedReader fBufferedReader;
66
    private IProcess fProcess;
67
    private String fProcessId;
68
    private File fBuildFileParent= null;
69
    private List fMessageQueue;
70
    protected ILaunch fLaunch;
71
    private Map fFileNameToIFile= new HashMap();
72
    private String fLastFileName= null;
73
    private String fLastTaskName= null;
74
    private boolean fBuildFailed= false;
75
    
76
    /**
77
     * Reads the message stream from the RemoteAntBuildLogger
78
     */
79
    private class ServerConnection extends Thread {
80
        private int fServerPort;
81
        
82
        public ServerConnection(int port) {
83
            super("Ant Build Server Connection"); //$NON-NLS-1$
84
            setDaemon(true);
85
            fServerPort= port;
86
        }
87
        
88
        public void run() {
89
            Exception exception= null;
90
            try {
91
                fServerSocket= new ServerSocket(fServerPort);
92
                IPreferenceStore prefs = AntUIPlugin.getDefault().getPreferenceStore();
93
                int socketTimeout= prefs.getInt(IAntUIPreferenceConstants.ANT_COMMUNICATION_TIMEOUT);
94
                fServerSocket.setSoTimeout(socketTimeout);
95
                fSocket= fServerSocket.accept();
96
                fBufferedReader= new BufferedReader(new InputStreamReader(fSocket.getInputStream(), "UTF-8")); //$NON-NLS-1$
97
                String message;
98
                while(fBufferedReader != null && (message= fBufferedReader.readLine()) != null) {
99
                    receiveMessage(message);
100
                }
101
            } catch (SocketException e) {
102
            } catch (SocketTimeoutException e) {
103
                exception= e;
104
            } catch (IOException e) {
105
                // fall through
106
                exception= e;
107
            }
108
            if (exception != null) {
109
                AntUIPlugin.log(exception);
110
            }
111
            shutDown();
112
        }
113
    }
114
    
115
    public RemoteAntBuildListener(ILaunch launch) {
116
        super();
117
        fLaunch= launch;
118
        DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
119
    }
120
121
    /**
122
     * Start listening to an Ant build. Start a server connection that
123
     * the RemoteAntBuildLogger can connect to.
124
     * 
125
     * @param eventPort The port number to create the server connection on
126
     */
127
    public synchronized void startListening(int eventPort){
128
        ServerConnection connection = new ServerConnection(eventPort);
129
        connection.start();
130
    }
131
132
    protected synchronized void shutDown() {
133
        fLaunch= null;
134
        fFileNameToIFile= null;
135
        if (DebugPlugin.getDefault() != null) {
136
        	DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
137
        }
138
        try {
139
            if (fBufferedReader != null) {
140
                fBufferedReader.close();
141
                fBufferedReader= null;
142
            }
143
        } catch(IOException e) {
144
        }   
145
        try{
146
            if(fSocket != null) {
147
                fSocket.close();
148
                fSocket= null;
149
            }
150
        } catch(IOException e) {
151
        }
152
        try{
153
            if(fServerSocket != null) {
154
                fServerSocket.close();
155
                fServerSocket= null;
156
            }
157
        } catch(IOException e) {
158
        }
159
    }
160
        
161
    protected void receiveMessage(String message) {
162
        if (message.startsWith(MessageIds.TASK)) {
163
            receiveTaskMessage(message);
164
        } else if (message.startsWith(MessageIds.TARGET)) {
165
            receiveTargetMessage(message);
166
        } else if (message.startsWith(MessageIds.PROCESS_ID)) {
167
            message= message.substring(MessageIds.PROCESS_ID.length());
168
            fProcessId= message;
169
        } else {
170
            int index= message.indexOf(',');
171
            if (index > 0) {
172
                int priority= Integer.parseInt(message.substring(0, index));
173
                message= message.substring(index + 1);
174
                
175
                writeMessage(message + System.getProperty("line.separator"), priority); //$NON-NLS-1$
176
                if (message.startsWith("BUILD FAILED")) { //$NON-NLS-1$
177
                    fBuildFailed= true;
178
                } else if (fBuildFailed) {
179
                	if (message.startsWith("Total time:")) { //$NON-NLS-1$
180
                		fBuildFailed= false;
181
                	} else {
182
                		AntUtil.linkBuildFailedMessage(message, getProcess());
183
                	}
184
				}
185
            }
186
        }
187
    }
188
189
    private void receiveTargetMessage(String message) {
190
        message= message.substring(MessageIds.TARGET.length());
191
        StringTokenizer tokenizer= new StringTokenizer(message, ","); //$NON-NLS-1$
192
        message= tokenizer.nextToken();
193
        if (tokenizer.hasMoreTokens()) {
194
        	int locationLength= Integer.parseInt(tokenizer.nextToken());
195
        	String location= tokenizer.nextToken(); 
196
        	while (location.length() < locationLength) { //path with a comma in it
197
        		location+=","; //$NON-NLS-1$
198
        		location+= tokenizer.nextToken();
199
        	}
200
            int lineNumber= Integer.parseInt(tokenizer.nextToken());
201
            generateLink(message, location, lineNumber, 0, message.length() - 1);
202
        }
203
        writeMessage(message + System.getProperty("line.separator"), Project.MSG_INFO); //$NON-NLS-1$
204
    }
205
206
    private void receiveTaskMessage(String message) {
207
        message= message.substring(MessageIds.TASK.length());
208
        
209
        int index= message.indexOf(',');
210
        int priority= Integer.parseInt(message.substring(0, index));
211
        int index2= message.indexOf(',', index + 1);
212
        String taskName= message.substring(index + 1, index2);
213
        if (taskName.length() == 0) {
214
            taskName= fLastTaskName;
215
        }
216
        int index3= message.indexOf(',', index2 + 1);
217
        int lineLength= Integer.parseInt(message.substring(index2 + 1, index3));
218
        int index4= index3 + 1 + lineLength;
219
        
220
        String line= message.substring(index3 + 1, index4);
221
        StringBuffer labelBuff= new StringBuffer();
222
        labelBuff.append('[');
223
        labelBuff.append(taskName);
224
        labelBuff.append("] "); //$NON-NLS-1$
225
        labelBuff.append(line);
226
        line= labelBuff.toString();
227
        
228
        fLastTaskName= taskName;
229
        
230
        int locationIndex= message.indexOf(',', index4 + 1);
231
        int finalIndex= locationIndex + 1;
232
        String fileName= message.substring(index4 + 1, locationIndex);
233
        int locationLength= 0;
234
        if (fileName.length() == 0) {
235
            fileName= fLastFileName;
236
        } else {
237
        	finalIndex= message.indexOf(',', locationIndex) + 1;
238
        	locationLength= Integer.parseInt(fileName);
239
        	fileName= message.substring(finalIndex, finalIndex + locationLength);
240
        	locationLength+=1; //set past delimiter
241
        }
242
        fLastFileName= fileName;
243
        int lineNumber= Integer.parseInt(message.substring(finalIndex + locationLength));
244
245
        int size = IAntUIConstants.LEFT_COLUMN_SIZE - (taskName.length() + 3);
246
        int offset = Math.max(size - 2, 1);
247
        int length = IAntUIConstants.LEFT_COLUMN_SIZE - size - 3;
248
        if (fileName != null) {
249
            generateLink(line, fileName, lineNumber, offset, length);
250
        }
251
        
252
        StringBuffer fullMessage= new StringBuffer();
253
        adornMessage(taskName, line, fullMessage);
254
        writeMessage(fullMessage.append(System.getProperty("line.separator")).toString(), priority); //$NON-NLS-1$
255
    }
256
257
    private void generateLink(String line, String fileName, int lineNumber, int offset, int length) {
258
        IHyperlink taskLink= null;
259
        if (lineNumber == -1) {
260
            //fileName will actually be the String representation of Location
261
           taskLink = AntUtil.getLocationLink(fileName, fBuildFileParent);
262
        } else {
263
            IFile file= (IFile) fFileNameToIFile.get(fileName);
264
            if (file == null) {
265
                file= AntUtil.getFileForLocation(fileName, fBuildFileParent);
266
                if (file != null) {
267
                    fFileNameToIFile.put(fileName, file);
268
                    taskLink= new FileLink(file, null, -1, -1, lineNumber);
269
                } else {
270
                    File javaIOFile= FileUtils.getFileUtils().resolveFile(fBuildFileParent, fileName);
271
                    if (javaIOFile.exists()) {
272
                        taskLink= new ExternalHyperlink(javaIOFile, lineNumber);
273
                    }
274
                }
275
            } else {
276
                taskLink= new FileLink(file, null, -1, -1, lineNumber);
277
            }
278
        }
279
        if (taskLink != null) {
280
            TaskLinkManager.addTaskHyperlink(getProcess(), taskLink, new Region(offset, length), line);
281
        }
282
    }
283
    
284
    /**
285
     * Returns the associated process, finding it if necessary.
286
     */
287
    protected IProcess getProcess() {
288
        if (fProcess == null) {
289
            if (fProcessId != null) {
290
                IProcess[] all = DebugPlugin.getDefault().getLaunchManager().getProcesses();
291
                for (int i = 0; i < all.length; i++) {
292
                    IProcess process = all[i];
293
                    if (fProcessId.equals(process.getAttribute(AbstractEclipseBuildLogger.ANT_PROCESS_ID))) {
294
                        fProcess = process;
295
                        break;
296
                    }
297
                }
298
            }
299
        }
300
        return fProcess;
301
    }
302
    
303
    private AntStreamMonitor getMonitor(int priority) {
304
        IProcess process= getProcess();
305
        if (process == null) {
306
            return null;
307
        }
308
        AntStreamsProxy proxy = (AntStreamsProxy)process.getStreamsProxy();
309
        if (proxy == null) {
310
            return null;
311
        }
312
        AntStreamMonitor monitor = null;
313
        switch (priority) {
314
            case Project.MSG_INFO:
315
                monitor = (AntStreamMonitor)proxy.getOutputStreamMonitor();
316
                break;
317
            case Project.MSG_ERR:
318
                monitor = (AntStreamMonitor)proxy.getErrorStreamMonitor();
319
                break;
320
            case Project.MSG_DEBUG:
321
                monitor = (AntStreamMonitor)proxy.getDebugStreamMonitor();
322
                break;
323
            case Project.MSG_WARN:
324
                monitor = (AntStreamMonitor)proxy.getWarningStreamMonitor();
325
                break;
326
            case Project.MSG_VERBOSE:
327
                monitor = (AntStreamMonitor)proxy.getVerboseStreamMonitor();
328
                break;
329
        }
330
        return monitor;
331
    }
332
    
333
    /**
334
     * Builds a right justified task prefix for the given build event, placing it
335
     * in the given string buffer.
336
     *  
337
     * @param event build event
338
     * @param fullMessage buffer to place task prefix in
339
     */
340
    private void adornMessage(String taskName, String line, StringBuffer fullMessage) {
341
        if (taskName == null) {
342
            taskName = "null"; //$NON-NLS-1$
343
        }
344
        
345
        int size = IAntUIConstants.LEFT_COLUMN_SIZE - (taskName.length() + 6);
346
        for (int i = 0; i < size; i++) {
347
            fullMessage.append(' ');
348
        }
349
        
350
        fullMessage.append(line);
351
    }
352
    
353
    protected void writeMessage(String message, int priority) {
354
        AntStreamMonitor monitor= getMonitor(priority);
355
        if (monitor == null) {
356
            if (fMessageQueue == null) {
357
                fMessageQueue= new ArrayList();
358
            }
359
            fMessageQueue.add(message);
360
            return;
361
        }
362
        if (fMessageQueue != null) {
363
            for (Iterator iter = fMessageQueue.iterator(); iter.hasNext();) {
364
                String oldMessage = (String) iter.next();
365
                monitor.append(oldMessage);
366
            }
367
            fMessageQueue= null;
368
        }
369
        monitor.append(message);
370
    }
371
    
372
    /* (non-Javadoc)
373
     * @see org.eclipse.debug.core.ILaunchesListener#launchesAdded(org.eclipse.debug.core.ILaunch[])
374
     */
375
    public void launchesAdded(ILaunch[] launches) {
376
    }
377
378
    /* (non-Javadoc)
379
     * @see org.eclipse.debug.core.ILaunchesListener#launchesChanged(org.eclipse.debug.core.ILaunch[])
380
     */
381
    public void launchesChanged(ILaunch[] launches) {
382
    }
383
384
    /* (non-Javadoc)
385
     * @see org.eclipse.debug.core.ILaunchesListener#launchesRemoved(org.eclipse.debug.core.ILaunch[])
386
     */
387
    public void launchesRemoved(ILaunch[] launches) {
388
        for (int i = 0; i < launches.length; i++) {
389
            ILaunch launch = launches[i];
390
            if (launch.equals(fLaunch)) {
391
                shutDown();
392
                return;
393
            }
394
        }
395
    }
396
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/RemoteAntProcessFactory.java (-34 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.launchConfigurations;
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
18
import org.eclipse.debug.core.ILaunch;
19
import org.eclipse.debug.core.IProcessFactory;
20
import org.eclipse.debug.core.model.IProcess;
21
22
public class RemoteAntProcessFactory implements IProcessFactory {
23
24
	/* (non-Javadoc)
25
	 * @see org.eclipse.debug.core.IProcessFactory#newProcess(org.eclipse.debug.core.ILaunch, java.lang.Process, java.lang.String, java.util.Map)
26
	 */
27
	public IProcess newProcess(ILaunch launch, Process process, String label, Map attributes) {
28
		if (attributes == null) {
29
			attributes= new HashMap(1);
30
		}
31
		attributes.put(IProcess.ATTR_PROCESS_TYPE, IAntLaunchConfigurationConstants.ID_ANT_PROCESS_TYPE);
32
		return new RemoteAntRuntimeProcess(launch, process, label, attributes);
33
	}
34
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/RemoteAntRuntimeProcess.java (-37 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.launchConfigurations;
13
14
import java.util.Map;
15
import org.eclipse.debug.core.ILaunch;
16
import org.eclipse.debug.core.model.IStreamsProxy;
17
import org.eclipse.debug.core.model.RuntimeProcess;
18
19
public class RemoteAntRuntimeProcess extends RuntimeProcess {
20
21
	/**
22
	 * Constructs a RuntimeProcess on the given system process
23
	 * with the given name, adding this process to the given
24
	 * launch.
25
	 * Sets the streams proxy to an AntStreamsProxy if output is captured.
26
	 */
27
	public RemoteAntRuntimeProcess(ILaunch launch, Process process, String name, Map attributes) {
28
		super(launch, process, name, attributes);
29
	}
30
	
31
	/* (non-Javadoc)
32
	 * @see org.eclipse.debug.core.model.RuntimeProcess#createStreamsProxy()
33
	 */
34
	protected IStreamsProxy createStreamsProxy() {
35
		return new AntStreamsProxy();
36
	}
37
}
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/SetTargetsDialog.java (-2 / +2 lines)
Lines 11-17 Link Here
11
package org.eclipse.ant.internal.ui.launchConfigurations;
11
package org.eclipse.ant.internal.ui.launchConfigurations;
12
12
13
import org.eclipse.ant.internal.ui.AntUIPlugin;
13
import org.eclipse.ant.internal.ui.AntUIPlugin;
14
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
14
import org.eclipse.ant.launching.IAntLaunchConstants;
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
16
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
17
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.dialogs.Dialog;
Lines 64-70 Link Here
64
			defaultValue= ""; //$NON-NLS-1$
64
			defaultValue= ""; //$NON-NLS-1$
65
		}
65
		}
66
        try {
66
        try {
67
            return fConfiguration.getAttribute(IAntLaunchConfigurationConstants.ATTR_ANT_TARGETS, defaultValue);
67
            return fConfiguration.getAttribute(IAntLaunchConstants.ATTR_ANT_TARGETS, defaultValue);
68
        } catch (CoreException e) {
68
        } catch (CoreException e) {
69
            return defaultValue;
69
            return defaultValue;
70
        }
70
        }
(-)Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/TaskLinkManager.java (-128 / +71 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-29 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.launchConfigurations;
11
package org.eclipse.ant.internal.ui.launchConfigurations;
12
12
13
13
import java.io.File;
14
import java.util.ArrayList;
15
import java.util.HashMap;
14
import java.util.HashMap;
16
import java.util.Iterator;
15
import java.util.Iterator;
17
import java.util.List;
16
import java.util.List;
18
import java.util.Map;
17
import java.util.Map;
19
18
19
import org.apache.tools.ant.util.FileUtils;
20
import org.eclipse.ant.internal.launching.AntLaunch;
21
import org.eclipse.ant.internal.launching.AntLaunchingUtil;
22
import org.eclipse.ant.internal.launching.LinkDescriptor;
20
import org.eclipse.ant.internal.ui.AntUtil;
23
import org.eclipse.ant.internal.ui.AntUtil;
24
import org.eclipse.ant.internal.ui.ExternalHyperlink;
21
import org.eclipse.core.resources.IFile;
25
import org.eclipse.core.resources.IFile;
22
import org.eclipse.debug.core.model.IProcess;
26
import org.eclipse.debug.core.model.IProcess;
23
import org.eclipse.debug.ui.console.FileLink;
27
import org.eclipse.debug.ui.console.FileLink;
24
import org.eclipse.debug.ui.console.IConsole;
28
import org.eclipse.debug.ui.console.IConsole;
25
import org.eclipse.jface.text.BadLocationException;
29
import org.eclipse.jface.text.BadLocationException;
26
import org.eclipse.jface.text.IRegion;
30
import org.eclipse.jface.text.IRegion;
31
import org.eclipse.jface.text.Region;
27
import org.eclipse.ui.console.IHyperlink;
32
import org.eclipse.ui.console.IHyperlink;
28
33
29
/**
34
/**
Lines 38-55 Link Here
38
 * may be stored to process future incoming tasks hyperlinks.
43
 * may be stored to process future incoming tasks hyperlinks.
39
 */
44
 */
40
public class TaskLinkManager {
45
public class TaskLinkManager {
41
	
46
42
	/**
47
	private static Map fFileNameToIFile = new HashMap();
43
	 * A map of processes to lists of queued task hyperlink entries
48
44
	 */
49
	private static File fBuildFileParent = null;
45
	private static Map fgProcessToLinks;
46
	
47
	/**
48
	 * A map of processes to lists of queued new line regions
49
	 */
50
	private static Map fgProcessToNewLines;
51
	
52
	private static List fgAntBuilds;
53
	
50
	
54
	private static class HyperlinkEntry {
51
	private static class HyperlinkEntry {
55
		private IHyperlink fLink;
52
		private IHyperlink fLink;
Lines 74-97 Link Here
74
			return fMessage;
71
			return fMessage;
75
		}
72
		}
76
	}
73
	}
77
	
78
	private static class LineEntry {
79
		private IConsole fConsole;
80
		private IRegion fRegion;
81
	
82
		public LineEntry(IConsole console, IRegion region) {
83
			fConsole = console;
84
			fRegion = region;	
85
		}
86
	
87
		public IRegion getRegion() {
88
			return fRegion;
89
		}
90
	
91
		public IConsole getConsole() {
92
			return fConsole;
93
		}
94
	}
95
74
96
	/**
75
	/**
97
	 * Not to be called.
76
	 * Not to be called.
Lines 99-139 Link Here
99
	private TaskLinkManager() {
78
	private TaskLinkManager() {
100
		super();
79
		super();
101
	}
80
	}
102
	
81
103
	/**
82
	private static HyperlinkEntry createHyperlink(
104
	 * Registers a hyperlink for the given process and task name. The given
83
			LinkDescriptor linkDescriptor) {
105
	 * region is relative to the beginning of the line (not the document).
84
		String line = linkDescriptor.getLine();
106
	 * 
85
		String fileName = linkDescriptor.getFileName();
107
	 * @param process the process associated with the link
86
		int lineNumber = linkDescriptor.getLineNumber();
108
	 * @param link the link for the process
87
		int offset = linkDescriptor.getOffset();
109
	 * @param region The region within the line
88
		int length = linkDescriptor.getLength();
110
	 * @param message The message related to the link
89
111
	 */
90
		IHyperlink taskLink = null;
112
	public static synchronized void addTaskHyperlink(IProcess process, IHyperlink link, IRegion region, String message) {
91
		if (lineNumber == -1) {
113
		if (fgProcessToNewLines != null) {
92
			// fileName will actually be the String representation of Location
114
			List newLines = (List)fgProcessToNewLines.get(process);
93
			taskLink = AntUtil.getLocationLink(fileName, fBuildFileParent);
115
			if (newLines != null) {
94
		} else {
116
				for (int index= 0; index < newLines.size(); index++) {
95
			IFile file = (IFile) fFileNameToIFile.get(fileName);
117
					LineEntry newLine = (LineEntry) newLines.get(index);
96
			if (file == null) {
118
					if (addLink(newLine.getConsole(), link, newLine.getRegion(), region, message)) {
97
				file = AntLaunchingUtil.getFileForLocation(fileName,
119
						newLines.subList(0, index + 1).clear();
98
						fBuildFileParent);
120
						return;
99
				if (file != null) {
100
					fFileNameToIFile.put(fileName, file);
101
					taskLink = new FileLink(file, null, -1, -1, lineNumber);
102
				} else if(fileName!=null){
103
					File javaIOFile = FileUtils.getFileUtils().resolveFile(
104
							fBuildFileParent, fileName);
105
					if (javaIOFile.exists()) {
106
						taskLink = new ExternalHyperlink(javaIOFile, lineNumber);
121
					}
107
					}
122
				}
108
				}
109
			} else {
110
				taskLink = new FileLink(file, null, -1, -1, lineNumber);
123
			}
111
			}
124
		}
112
		}
125
				
113
		if (taskLink != null) {
126
		if (fgProcessToLinks == null) {
114
			return new HyperlinkEntry(taskLink, new Region(offset, length),
127
			fgProcessToLinks = new HashMap();
115
					line);
128
			
116
		}
117
		return null;
118
	}
119
120
	private static Map createHyperlinksForLaunch(IProcess process) {
121
		Map links = new HashMap();
122
		AntLaunch antLaunch = (AntLaunch) process.getLaunch();
123
		List linksDescriptors = antLaunch.getLinkDescriptors();
124
		for (int i = 0; i < linksDescriptors.size(); i++) {
125
			links.put(linksDescriptors.get(i), createHyperlink(
126
					(LinkDescriptor) linksDescriptors.get(i)));
129
		}
127
		}
130
		List links = (List)fgProcessToLinks.get(process);
128
		return links;
131
		if (links == null) {
132
			links = new ArrayList(10);
133
			fgProcessToLinks.put(process, links);
134
		}
135
		
136
		links.add(new HyperlinkEntry(link, region, message));
137
	}
129
	}
138
	
130
	
139
	private static boolean addLink(IConsole console, IHyperlink link, IRegion lineRegion, IRegion region, String message) {
131
	private static boolean addLink(IConsole console, IHyperlink link, IRegion lineRegion, IRegion region, String message) {
Lines 164-207 Link Here
164
	 */
156
	 */
165
	public static synchronized void processNewLine(IConsole console, IRegion newLine) {
157
	public static synchronized void processNewLine(IConsole console, IRegion newLine) {
166
		IProcess process = console.getProcess();
158
		IProcess process = console.getProcess();
167
		if (fgAntBuilds != null && fgAntBuilds.contains(process)) {
159
168
			if (linkBuildFileMessage(console, newLine)) {
160
		Map links = createHyperlinksForLaunch(process);
169
				fgAntBuilds.remove(process);
161
170
				return;
162
		if (linkBuildFileMessage(console, newLine)) {
171
			}
172
		}
173
		if (fgProcessToLinks == null) {
174
			addNewLine(console, newLine, process);
175
			return;
163
			return;
176
		}
164
		}
177
		
165
178
		List links = (List)fgProcessToLinks.get(process);
179
		if (links == null) {
166
		if (links == null) {
180
			addNewLine(console, newLine, process);
181
			return;
167
			return;
182
		}
168
		}
183
		
169
184
		for (int index= 0; index < links.size(); index++) {
170
		for (Iterator i = links.keySet().iterator(); i.hasNext();) {
185
			HyperlinkEntry link = (HyperlinkEntry) links.get(index);
171
			LinkDescriptor keyLinkDescriptor = (LinkDescriptor) i.next();
186
			if (addLink(console, link.getLink(), newLine, link.getRegion(), link.getMessage())) {
172
			HyperlinkEntry link = (HyperlinkEntry) links.get(keyLinkDescriptor);
187
				links.subList(0, index + 1).clear();
173
			if (addLink(console, link.getLink(), newLine, link.getRegion(),
174
					link.getMessage())) {
175
				((AntLaunch) process.getLaunch())
176
						.removeLinkDescriptor(keyLinkDescriptor);
177
				links.remove(keyLinkDescriptor);
188
				return;
178
				return;
189
			}
179
			}
190
		}
180
		}
191
	}
181
	}
192
	
193
	private static void addNewLine(IConsole console, IRegion newLine, IProcess process) {
194
		if (fgProcessToNewLines == null) {
195
			fgProcessToNewLines = new HashMap();
196
		}
197
		List newLines = (List)fgProcessToNewLines.get(process);
198
		if (newLines == null) {
199
			newLines= new ArrayList();
200
		}
201
	
202
		newLines.add(new LineEntry(console, newLine));
203
		fgProcessToNewLines.put(process, newLines);
204
	}
205
182
206
	/**
183
	/**
207
	 * Disposes any information stored for the given process.
184
	 * Disposes any information stored for the given process.
Lines 209-251 Link Here
209
	 * @param process
186
	 * @param process
210
	 */
187
	 */
211
	public static void dispose(IProcess process) {
188
	public static void dispose(IProcess process) {
212
		if (fgProcessToLinks != null) {
189
213
			fgProcessToLinks.remove(process);
214
		}
215
		if (fgProcessToNewLines != null) {
216
			fgProcessToNewLines.remove(process);
217
		}
218
		if (fgAntBuilds != null) {
219
			fgAntBuilds.remove(process);
220
		}
221
	}
222
	
223
	/**
224
	 * Registers the specified process as an Ant build process.
225
	 * Allows for the generation of the "Buildfile: somefile" link in the 
226
	 * Ant output.
227
	 * 
228
	 * @param process
229
	 */
230
	public static synchronized void registerAntBuild(IProcess process) {
231
		if (fgProcessToNewLines != null) {
232
			List newLines = (List)fgProcessToNewLines.get(process);
233
			if (newLines != null) {
234
				for (Iterator iter = newLines.iterator(); iter.hasNext();) {
235
					LineEntry newLine = (LineEntry) iter.next();
236
					if (linkBuildFileMessage(newLine.getConsole(), newLine.getRegion())){
237
						iter.remove();
238
						return;
239
					}
240
				}
241
			}
242
		}
243
		if (fgAntBuilds == null) {
244
			fgAntBuilds= new ArrayList();
245
		}
246
		fgAntBuilds.add(process);
247
	}
190
	}
248
	
191
249
	private static boolean linkBuildFileMessage(IConsole console, IRegion region) {
192
	private static boolean linkBuildFileMessage(IConsole console, IRegion region) {
250
		
193
		
251
		String message= ""; //$NON-NLS-1$
194
		String message= ""; //$NON-NLS-1$
(-)Ant Tools Support/org/eclipse/ant/internal/ui/model/AntModelCore.java (-4 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-23 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.model;
11
package org.eclipse.ant.internal.ui.model;
12
12
13
import com.ibm.icu.text.MessageFormat;
14
import java.util.ArrayList;
13
import java.util.ArrayList;
15
import java.util.Iterator;
14
import java.util.Iterator;
16
import java.util.List;
15
import java.util.List;
17
16
17
import org.eclipse.ant.internal.launching.debug.model.AntLineBreakpoint;
18
import org.eclipse.ant.internal.launching.debug.model.DebugModelMessages;
18
import org.eclipse.ant.internal.ui.AntUIPlugin;
19
import org.eclipse.ant.internal.ui.AntUIPlugin;
19
import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint;
20
import org.eclipse.ant.internal.ui.debug.model.DebugModelMessages;
21
import org.eclipse.core.resources.IMarker;
20
import org.eclipse.core.resources.IMarker;
22
import org.eclipse.core.resources.IMarkerDelta;
21
import org.eclipse.core.resources.IMarkerDelta;
23
import org.eclipse.core.resources.IWorkspaceRunnable;
22
import org.eclipse.core.resources.IWorkspaceRunnable;
Lines 28-33 Link Here
28
import org.eclipse.debug.core.IBreakpointsListener;
27
import org.eclipse.debug.core.IBreakpointsListener;
29
import org.eclipse.debug.core.model.IBreakpoint;
28
import org.eclipse.debug.core.model.IBreakpoint;
30
29
30
import com.ibm.icu.text.MessageFormat;
31
31
public class AntModelCore implements IBreakpointsListener {
32
public class AntModelCore implements IBreakpointsListener {
32
	
33
	
33
	private static AntModelCore inst;
34
	private static AntModelCore inst;
(-)Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreferencePage.java (-8 / +26 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.preferences;
11
package org.eclipse.ant.internal.ui.preferences;
12
12
13
13
import org.eclipse.ant.internal.launching.AntLaunching;
14
import com.ibm.icu.text.MessageFormat;
14
import org.eclipse.ant.internal.launching.IAntLaunchingPreferenceConstants;
15
16
import org.eclipse.ant.internal.ui.AntUIPlugin;
15
import org.eclipse.ant.internal.ui.AntUIPlugin;
17
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
16
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
18
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
17
import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants;
18
import org.eclipse.core.runtime.Platform;
19
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
20
import org.eclipse.core.runtime.preferences.InstanceScope;
19
import org.eclipse.jface.preference.BooleanFieldEditor;
21
import org.eclipse.jface.preference.BooleanFieldEditor;
20
import org.eclipse.jface.preference.FieldEditorPreferencePage;
22
import org.eclipse.jface.preference.FieldEditorPreferencePage;
21
import org.eclipse.jface.preference.IPreferenceStore;
23
import org.eclipse.jface.preference.IPreferenceStore;
Lines 40-50 Link Here
40
import org.eclipse.ui.IWorkbenchPreferencePage;
42
import org.eclipse.ui.IWorkbenchPreferencePage;
41
import org.eclipse.ui.PlatformUI;
43
import org.eclipse.ui.PlatformUI;
42
44
45
import com.ibm.icu.text.MessageFormat;
46
43
public class AntPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
47
public class AntPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
44
	
48
	
45
	private List fConsoleColorList;
49
	private List fConsoleColorList;
46
	private ColorEditor fConsoleColorEditor;
50
	private ColorEditor fConsoleColorEditor;
47
	
51
	private IntegerFieldEditor timeout;
52
48
	private BooleanFieldEditor fToolsWarningEditor= null;
53
	private BooleanFieldEditor fToolsWarningEditor= null;
49
	
54
	
50
	// Array containing the message to display, the preference key, and the 
55
	// Array containing the message to display, the preference key, and the 
Lines 84-92 Link Here
84
		
89
		
85
		StringFieldEditor editor = new StringFieldEditor(IAntUIPreferenceConstants.ANT_FIND_BUILD_FILE_NAMES, AntPreferencesMessages.AntPreferencePage__Names__3, getFieldEditorParent());
90
		StringFieldEditor editor = new StringFieldEditor(IAntUIPreferenceConstants.ANT_FIND_BUILD_FILE_NAMES, AntPreferencesMessages.AntPreferencePage__Names__3, getFieldEditorParent());
86
		addField(editor);
91
		addField(editor);
87
		
92
88
		IntegerFieldEditor timeout = new IntegerFieldEditor(IAntUIPreferenceConstants.ANT_COMMUNICATION_TIMEOUT, AntPreferencesMessages.AntPreferencePage_13, getFieldEditorParent());
93
		timeout = new IntegerFieldEditor(IAntLaunchingPreferenceConstants.ANT_COMMUNICATION_TIMEOUT, AntPreferencesMessages.AntPreferencePage_13, getFieldEditorParent());
89
        int minValue= AntUIPlugin.getDefault().getPreferenceStore().getDefaultInt(IAntUIPreferenceConstants.ANT_COMMUNICATION_TIMEOUT);
94
        int minValue= Platform.getPreferencesService().getInt(
95
				AntLaunching.getUniqueIdentifier(),
96
				IAntLaunchingPreferenceConstants.ANT_COMMUNICATION_TIMEOUT,
97
				20000, null);
90
        int maxValue = 1200000;
98
        int maxValue = 1200000;
91
        timeout.setValidRange(minValue, maxValue);
99
        timeout.setValidRange(minValue, maxValue);
92
        timeout.setErrorMessage(MessageFormat.format(AntPreferencesMessages.AntPreferencePage_14, new Object[] {new Integer(minValue), new Integer(maxValue)})); 
100
        timeout.setErrorMessage(MessageFormat.format(AntPreferencesMessages.AntPreferencePage_14, new Object[] {new Integer(minValue), new Integer(maxValue)})); 
Lines 147-152 Link Here
147
			String preference = fAppearanceColorListModel[i][1];
155
			String preference = fAppearanceColorListModel[i][1];
148
			fAppearanceColorListModel[i][2]= store.getString(preference);
156
			fAppearanceColorListModel[i][2]= store.getString(preference);
149
		}
157
		}
158
159
		IEclipsePreferences node = new InstanceScope()
160
				.getNode(AntLaunching.getUniqueIdentifier());
161
		String t = node.get(
162
				IAntLaunchingPreferenceConstants.ANT_COMMUNICATION_TIMEOUT,
163
				"2000"); //$NON-NLS-1$
164
		if (timeout != null) {
165
			t = new Integer(timeout.getIntValue()).toString();
166
		}
167
		node.put(IAntLaunchingPreferenceConstants.ANT_COMMUNICATION_TIMEOUT, t);
150
	}
168
	}
151
	
169
	
152
	private void createColorComposite() {
170
	private void createColorComposite() {
(-)Ant Tools Support/org/eclipse/ant/internal/ui/refactoring/LaunchConfigurationBuildfileChange.java (-4 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2008 IBM Corporation and others.
2
 * Copyright (c) 2003, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 15-21 Link Here
15
15
16
import org.eclipse.ant.core.AntCorePlugin;
16
import org.eclipse.ant.core.AntCorePlugin;
17
import org.eclipse.ant.internal.ui.AntUtil;
17
import org.eclipse.ant.internal.ui.AntUtil;
18
import org.eclipse.ant.ui.launching.IAntLaunchConfigurationConstants;
18
import org.eclipse.ant.launching.IAntLaunchConstants;
19
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
19
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.resources.IContainer;
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IProject;
Lines 39-45 Link Here
39
import org.eclipse.ltk.core.refactoring.Change;
40
import org.eclipse.ltk.core.refactoring.Change;
40
import org.eclipse.ltk.core.refactoring.CompositeChange;
41
import org.eclipse.ltk.core.refactoring.CompositeChange;
41
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
42
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
42
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
43
43
44
import com.ibm.icu.text.MessageFormat;
44
import com.ibm.icu.text.MessageFormat;
45
45
Lines 91-97 Link Here
91
    private static ILaunchConfiguration[] getAntLaunchConfigurations() throws CoreException {
91
    private static ILaunchConfiguration[] getAntLaunchConfigurations() throws CoreException {
92
        ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
92
        ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
93
        // Ant launch configurations
93
        // Ant launch configurations
94
        ILaunchConfigurationType configurationType= manager.getLaunchConfigurationType(IAntLaunchConfigurationConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
94
        ILaunchConfigurationType configurationType= manager.getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE);
95
        ILaunchConfiguration[] configs= manager.getLaunchConfigurations(configurationType);
95
        ILaunchConfiguration[] configs= manager.getLaunchConfigurations(configurationType);
96
        return configs;
96
        return configs;
97
    }
97
    }
(-)Ant Tools Support/org/eclipse/ant/ui/launching/IAntLaunchConfigurationConstants.java (-17 / +44 lines)
Lines 11-119 Link Here
11
11
12
package org.eclipse.ant.ui.launching;
12
package org.eclipse.ant.ui.launching;
13
13
14
import org.eclipse.ant.internal.ui.AntUIPlugin;
14
import org.eclipse.ant.launching.IAntLaunchConstants;
15
import org.eclipse.ant.internal.ui.IAntUIConstants;
16
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
17
15
18
/**
16
/**
19
 * Constant definitions for Ant launch configurations.
17
 * Constant definitions for Ant launch configurations.
20
 * 
18
 * 
21
 * @since 3.4
19
 * @since 3.4
22
 * @noimplement This interface is not intended to be implemented by clients.
20
 * @noimplement This interface is not intended to be implemented by clients.
21
 * @deprecated use {@link IAntLaunchConstants}
23
 */
22
 */
24
public interface IAntLaunchConfigurationConstants {
23
public interface IAntLaunchConfigurationConstants {
25
24
26
	/**
25
	/**
27
	 * Ant launch configuration type identifier.
26
	 * Ant launch configuration type identifier.
27
	 * 
28
	 * @deprecated use {@link IAntLaunchConstants#ID_ANT_LAUNCH_CONFIGURATION_TYPE}
28
	 */
29
	 */
29
	public static final String ID_ANT_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.ant.AntLaunchConfigurationType"; //$NON-NLS-1$
30
	public static final String ID_ANT_LAUNCH_CONFIGURATION_TYPE = IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE;
30
31
31
	/**
32
	/**
32
	 * Ant builder launch configuration type identifier. Ant project builders
33
	 * Ant builder launch configuration type identifier. Ant project builders
33
	 * are of this type.
34
	 * are of this type.
35
	 * 
36
	 * @deprecated use {@link IAntLaunchConstants#ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE}
34
	 */
37
	 */
35
	public static final String ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.ant.AntBuilderLaunchConfigurationType"; //$NON-NLS-1$
38
	public static final String ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE = IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE;
36
	
39
	
37
	/**
40
	/**
38
	 * String attribute indicating the Ant targets to execute. Default value is
41
	 * String attribute indicating the Ant targets to execute. Default value is
39
	 * <code>null</code> which indicates that the default target is to be
42
	 * <code>null</code> which indicates that the default target is to be
40
	 * executed. Format is a comma separated listing of targets.
43
	 * executed. Format is a comma separated listing of targets.
44
	 * 
45
	 * @deprecated use {@link IAntLaunchConstants#ATTR_ANT_TARGETS}
41
	 */
46
	 */
42
	public static final String ATTR_ANT_TARGETS = IExternalToolConstants.PLUGIN_ID + ".ATTR_ANT_TARGETS"; //$NON-NLS-1$
47
	public static final String ATTR_ANT_TARGETS = IAntLaunchConstants.ATTR_ANT_TARGETS;
43
	
48
	
44
	/**
49
	/**
45
	 * String attribute indicating the Ant targets to execute after a clean (full build) for an Ant builder. Default value is
50
	 * String attribute indicating the Ant targets to execute after a clean (full build) for an Ant builder. Default value is
46
	 * <code>null</code> which indicates that the default target is to be
51
	 * <code>null</code> which indicates that the default target is to be
47
	 * executed. Format is a comma separated listing of targets.
52
	 * executed. Format is a comma separated listing of targets.
53
	 * 
54
	 * @deprecated use {@link IAntLaunchConstants#ATTR_ANT_AFTER_CLEAN_TARGETS}
48
	 */
55
	 */
49
	public static final String ATTR_ANT_AFTER_CLEAN_TARGETS = IAntUIConstants.PLUGIN_ID + ".ATTR_ANT_AFTER_CLEAN_TARGETS"; //$NON-NLS-1$
56
	public static final String ATTR_ANT_AFTER_CLEAN_TARGETS = IAntLaunchConstants.ATTR_ANT_AFTER_CLEAN_TARGETS;
50
	
57
	
51
	/**
58
	/**
52
	 * String attribute indicating the Ant targets to execute during a manual build for an Ant builder. Default value is
59
	 * String attribute indicating the Ant targets to execute during a manual build for an Ant builder. Default value is
53
	 * <code>null</code> which indicates that the default target is to be
60
	 * <code>null</code> which indicates that the default target is to be
54
	 * executed. Format is a comma separated listing of targets.
61
	 * executed. Format is a comma separated listing of targets.
62
	 * 
63
	 * @deprecated use {@link IAntLaunchConstants#ATTR_ANT_MANUAL_TARGETS}
55
	 */
64
	 */
56
	public static final String ATTR_ANT_MANUAL_TARGETS = IAntUIConstants.PLUGIN_ID + ".ATTR_ANT_MANUAL_TARGETS"; //$NON-NLS-1$
65
	public static final String ATTR_ANT_MANUAL_TARGETS = IAntLaunchConstants.ATTR_ANT_MANUAL_TARGETS;
57
	
66
	
58
	/**
67
	/**
59
	 * String attribute indicating the Ant targets to execute during an auto build for an Ant builder. Default value is
68
	 * String attribute indicating the Ant targets to execute during an auto build for an Ant builder. Default value is
60
	 * <code>null</code> which indicates that the default target is to be
69
	 * <code>null</code> which indicates that the default target is to be
61
	 * executed. Format is a comma separated listing of targets.
70
	 * executed. Format is a comma separated listing of targets.
71
	 * 
72
	 * @deprecated use {@link IAntLaunchConstants#ATTR_ANT_AUTO_TARGETS}
62
	 */
73
	 */
63
	public static final String ATTR_ANT_AUTO_TARGETS = IAntUIConstants.PLUGIN_ID + ".ATTR_ANT_AUTO_TARGETS"; //$NON-NLS-1$
74
	public static final String ATTR_ANT_AUTO_TARGETS = IAntLaunchConstants.ATTR_ANT_AUTO_TARGETS;
64
	
75
	
65
	/**
76
	/**
66
	 * String attribute indicating the Ant targets to execute during a clean for an Ant builder. Default value is
77
	 * String attribute indicating the Ant targets to execute during a clean for an Ant builder. Default value is
67
	 * <code>null</code> which indicates that the default target is to be
78
	 * <code>null</code> which indicates that the default target is to be
68
	 * executed. Format is a comma separated listing of targets.
79
	 * executed. Format is a comma separated listing of targets.
80
	 * 
81
	 * @deprecated use {@link IAntLaunchConstants#ATTR_ANT_CLEAN_TARGETS}
69
	 */
82
	 */
70
	public static final String ATTR_ANT_CLEAN_TARGETS = IAntUIConstants.PLUGIN_ID + ".ATTR_ANT_CLEAN_TARGETS"; //$NON-NLS-1$
83
	public static final String ATTR_ANT_CLEAN_TARGETS = IAntLaunchConstants.ATTR_ANT_CLEAN_TARGETS;
71
	
84
	
72
	/**
85
	/**
73
	 * Boolean attribute indicating whether or not target specification for an Ant builder 
86
	 * Boolean attribute indicating whether or not target specification for an Ant builder 
74
	 * has been updated for 3.1 
87
	 * has been updated for 3.1 
88
	 * 
89
	 * @deprecated use {@link IAntLaunchConstants#ATTR_TARGETS_UPDATED}
75
	 */
90
	 */
76
	public static final String ATTR_TARGETS_UPDATED = IAntUIConstants.PLUGIN_ID + ".ATTR_TARGETS_UPDATED"; //$NON-NLS-1$
91
	public static final String ATTR_TARGETS_UPDATED = IAntLaunchConstants.ATTR_TARGETS_UPDATED;
77
	
92
	
78
	/**
93
	/**
79
	 * Map attribute indicating the Ant properties to be defined during the
94
	 * Map attribute indicating the Ant properties to be defined during the
80
	 * build. Default value is <code>null</code> which indicates no additional
95
	 * build. Default value is <code>null</code> which indicates no additional
81
	 * properties will be defined.
96
	 * properties will be defined.
97
	 * 
98
	 * @deprecated use {@link IAntLaunchConstants#ATTR_ANT_PROPERTIES}
82
	 */
99
	 */
83
	public static final String ATTR_ANT_PROPERTIES = IExternalToolConstants.PLUGIN_ID + ".ATTR_ANT_PROPERTIES"; //$NON-NLS-1$					
100
	public static final String ATTR_ANT_PROPERTIES = IAntLaunchConstants.ATTR_ANT_PROPERTIES;					
84
	
101
	
85
	/**
102
	/**
86
	 * String attribute indicating the Ant targets to execute. Default value is
103
	 * String attribute indicating the Ant targets to execute. Default value is
87
	 * <code>null</code> which indicates that no additional property files
104
	 * <code>null</code> which indicates that no additional property files
88
	 * will be defined. Format is a comma separated listing of property files.
105
	 * will be defined. Format is a comma separated listing of property files.
106
	 * 
107
	 * @deprecated use {@link IAntLaunchConstants#ATTR_ANT_PROPERTY_FILES}
89
	 */
108
	 */
90
	public static final String ATTR_ANT_PROPERTY_FILES = IExternalToolConstants.PLUGIN_ID + ".ATTR_ANT_PROPERTY_FILES"; //$NON-NLS-1$
109
	public static final String ATTR_ANT_PROPERTY_FILES = IAntLaunchConstants.ATTR_ANT_PROPERTY_FILES;
91
	
110
	
92
	/**
111
	/**
93
	 * Boolean attribute indicating whether or not internal targets (targets with no
112
	 * Boolean attribute indicating whether or not internal targets (targets with no
94
	 * description) should be hidden from the user in the launch configuration dialog.
113
	 * description) should be hidden from the user in the launch configuration dialog.
95
	 * Default value is <code>false</code> which indicates that all targets will be
114
	 * Default value is <code>false</code> which indicates that all targets will be
96
	 * displayed.
115
	 * displayed.
116
	 * 
117
	 * @deprecated use {@link IAntLaunchConstants#ATTR_HIDE_INTERNAL_TARGETS}
97
	 */
118
	 */
98
	public static final String ATTR_HIDE_INTERNAL_TARGETS = IExternalToolConstants.PLUGIN_ID + ".ATTR_HIDE_INTERNAL_TARGETS"; //$NON-NLS-1$
119
	public static final String ATTR_HIDE_INTERNAL_TARGETS = IAntLaunchConstants.ATTR_HIDE_INTERNAL_TARGETS;
99
	
120
	
100
	/**
121
	/**
101
	 * Integer attribute indicating which column targets should be sorted on. A
122
	 * Integer attribute indicating which column targets should be sorted on. A
102
	 * value of 0 indicates target name, 1 indicates target description, and -1
123
	 * value of 0 indicates target name, 1 indicates target description, and -1
103
	 * indicates no sort. Default value is -1.
124
	 * indicates no sort. Default value is -1.
125
	 * 
126
	 * @deprecated use {@link IAntLaunchConstants#ATTR_SORT_TARGETS}
104
	 */
127
	 */
105
	public static final String ATTR_SORT_TARGETS = IExternalToolConstants.PLUGIN_ID + "ATTR_SORT_TARGETS"; //$NON-NLS-1$
128
	public static final String ATTR_SORT_TARGETS = IAntLaunchConstants.ATTR_SORT_TARGETS;
106
129
107
	/**
130
	/**
108
	 * Boolean attribute indicating if the default VM install should be used for the separate JRE build
131
	 * Boolean attribute indicating if the default VM install should be used for the separate JRE build
109
	 * Default value is <code>false</code> for backwards compatibility
132
	 * Default value is <code>false</code> for backwards compatibility
133
	 * 
134
	 * @deprecated use {@link IAntLaunchConstants#ATTR_DEFAULT_VM_INSTALL}
110
	 */
135
	 */
111
	public static final String ATTR_DEFAULT_VM_INSTALL = AntUIPlugin.PI_ANTUI + ".DEFAULT_VM_INSTALL"; //$NON-NLS-1$
136
	public static final String ATTR_DEFAULT_VM_INSTALL = IAntLaunchConstants.ATTR_DEFAULT_VM_INSTALL;
112
137
113
	/**
138
	/**
114
	 * Identifier for Ant processes (value <code>org.eclipse.ant.ui.antProcess</code>). This identifier is
139
	 * Identifier for Ant processes (value <code>org.eclipse.ant.ui.antProcess</code>). This identifier is
115
	 * set as the value for the <code>IProcess.ATTR_PROCESS_TYPE</code>
140
	 * set as the value for the <code>IProcess.ATTR_PROCESS_TYPE</code>
116
	 * attribute in processes created by the Ant launch delegate.
141
	 * attribute in processes created by the Ant launch delegate.
142
	 * 
143
	 * @deprecated use {@link IAntLaunchConstants#ID_ANT_PROCESS_TYPE}
117
	 */
144
	 */
118
	public static final String ID_ANT_PROCESS_TYPE = "org.eclipse.ant.ui.antProcess"; //$NON-NLS-1$
145
	public static final String ID_ANT_PROCESS_TYPE = IAntLaunchConstants.ID_ANT_PROCESS_TYPE;
119
}
146
}
(-)Common Ant Support/META-INF/eclipse.inf (-1 lines)
Removed Link Here
1
jarprocessor.exclude.sign=true
(-)Common Ant Support/org/eclipse/ant/internal/ui/antsupport/logger/util/AntDebugState.java (-529 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.antsupport.logger.util;
13
14
import java.util.HashMap;
15
import java.util.Hashtable;
16
import java.util.Iterator;
17
import java.util.Map;
18
import java.util.Stack;
19
import java.util.Vector;
20
21
import org.apache.tools.ant.BuildEvent;
22
import org.apache.tools.ant.Location;
23
import org.apache.tools.ant.Project;
24
import org.apache.tools.ant.Target;
25
import org.apache.tools.ant.Task;
26
import org.apache.tools.ant.taskdefs.MacroInstance;
27
28
public class AntDebugState {
29
    
30
    private static final String fgAntTaskName= "ant"; //$NON-NLS-1$
31
    private static final String fgAntCallTaskName= "antcall"; //$NON-NLS-1$
32
    
33
	private IDebugBuildLogger fLogger;
34
	private Stack fTasks= new Stack();
35
	private Map fTaskToProxies= new HashMap();
36
	private Task fCurrentTask;
37
	private Task fStepOverTask;
38
	private Task fStepIntoTask;
39
	private Task fLastTaskFinished;
40
    
41
	//properties set before execution
42
    private Map fInitialProperties= null;
43
	private Map fProperties= null;
44
    
45
    private Map fProjectToTargetNames= null;
46
    private Map fProjectToMapOfTargetToBuildSequence= null;
47
    private Stack fTargetsToExecute= new Stack();
48
    private Stack fTargetsExecuting= new Stack();
49
	
50
	private boolean fConsiderTargetBreakpoints= false;
51
	private boolean fShouldSuspend;
52
	private boolean fClientSuspend= false;
53
	private boolean fStepIntoSuspend= false;
54
	private boolean fIsAfterTaskEvent= false;
55
	
56
	
57
	public AntDebugState(IDebugBuildLogger logger) {
58
		fLogger= logger;
59
	}
60
61
	public void waitIfSuspended() {
62
		fLogger.waitIfSuspended();
63
	}
64
65
	public Task getLastTaskFinished() {
66
		return fLastTaskFinished;
67
	}
68
69
	private void setLastTaskFinished(Task lastTaskFinished) {
70
		fLastTaskFinished= lastTaskFinished;
71
72
	}
73
74
	public Task getCurrentTask() {
75
		return fCurrentTask;
76
	}
77
78
	public void setCurrentTask(Task currentTask) {
79
		fCurrentTask= currentTask;
80
81
	}
82
83
	private Map getInitialProperties() {
84
		return fInitialProperties;
85
	}
86
87
	public Task getStepOverTask() {
88
		return fStepOverTask;
89
	}
90
91
	public void setStepOverTask(Task stepOverTask) {
92
		fStepOverTask= stepOverTask;
93
94
	}
95
96
	private boolean considerTargetBreakpoints() {
97
		return fConsiderTargetBreakpoints;
98
	}
99
100
	private void setConsiderTargetBreakpoints(boolean considerTargetBreakpoints) {
101
		fConsiderTargetBreakpoints= considerTargetBreakpoints;
102
	}
103
104
	private Stack getTasks() {
105
		return fTasks;
106
	}
107
	
108
	public void setShouldSuspend(boolean shouldSuspend) {
109
		fShouldSuspend= shouldSuspend;
110
	}
111
112
	public boolean shouldSuspend() {
113
		return fShouldSuspend;
114
	}
115
116
	private Map getTargetToBuildSequence(Project project) {
117
		return (Map) fProjectToMapOfTargetToBuildSequence.get(project);
118
	}
119
120
	public void setTargetToExecute(Target target) {
121
        if (target == null) {
122
            fTargetsToExecute.pop();
123
        } else {
124
            fTargetsToExecute.push(target);
125
        }
126
	}
127
128
	public void setTargetExecuting(Target target) {
129
        if (target == null) {
130
            fTargetsExecuting.pop();
131
        } else {
132
            fTargetsExecuting.push(target);
133
        }
134
	}
135
136
	private Target getTargetToExecute() {
137
	    if (fTargetsToExecute.isEmpty()) {
138
            return null;
139
        }
140
		return (Target) fTargetsToExecute.peek();
141
	}
142
	
143
	private Target getTargetExecuting() {
144
        if (fTargetsExecuting.isEmpty()) {
145
            return null;
146
        }
147
		return (Target) fTargetsExecuting.peek();
148
	}
149
150
	public boolean isStepIntoSuspend() {
151
		return isAfterTaskEvent() && fStepIntoSuspend;
152
	}
153
154
	public void setStepIntoSuspend(boolean stepIntoSuspend) {
155
		fStepIntoSuspend = stepIntoSuspend;
156
	}
157
158
	public boolean isClientSuspend() {
159
		return fClientSuspend;
160
	}
161
162
	public void setClientSuspend(boolean clientSuspend) {
163
		fClientSuspend = clientSuspend;
164
	}
165
166
	public Task getStepIntoTask() {
167
		return fStepIntoTask;
168
	}
169
170
	public void setStepIntoTask(Task stepIntoTask) {
171
		fStepIntoTask = stepIntoTask;
172
	}
173
	
174
	public void resume() {
175
		fLogger.notifyAll();
176
	}
177
178
	public Map getProperties() {
179
		return fProperties;
180
	}
181
	
182
	public Location getBreakpointLocation() {
183
		if (isAfterTaskEvent() && getCurrentTask() != null) {
184
			return getCurrentTask().getLocation();
185
		}
186
		if (considerTargetBreakpoints()) {
187
	        Target targetExecuting= getTargetExecuting();
188
	        if (targetExecuting != null) {
189
                return getLocation(targetExecuting);      
190
            }
191
		}
192
		return null;
193
	}
194
195
	private boolean isAfterTaskEvent() {
196
		return fIsAfterTaskEvent;
197
	}
198
199
	private void setAfterTaskEvent(boolean isAfterTaskEvent) {
200
		fIsAfterTaskEvent = isAfterTaskEvent;
201
	}
202
	
203
	public void taskStarted(BuildEvent event) {
204
		setAfterTaskEvent(true);
205
		if (getInitialProperties() == null) {//implicit or top level target does not fire targetStarted()
206
			fInitialProperties= event.getProject().getProperties();
207
		}
208
		
209
		setCurrentTask(event.getTask());
210
		setConsiderTargetBreakpoints(false);
211
		if (!getTasks().isEmpty()) {
212
			//cache the parent task proxy as when that task is started or finished the
213
			//proxy is not yet available or is nulled out
214
			Task parentTask = (Task) getTasks().peek();
215
			Object proxy = parentTask.getRuntimeConfigurableWrapper().getProxy();
216
			if (proxy != null) {
217
				fTaskToProxies.put(parentTask, proxy);
218
			}
219
		}
220
		getTasks().push(getCurrentTask());
221
		waitIfSuspended();
222
	}
223
	
224
225
    public void taskFinished() {
226
    	Task lastTask= (Task)getTasks().pop();
227
        setLastTaskFinished(lastTask);
228
        setCurrentTask(null);
229
        String taskName= lastTask.getTaskName();
230
       
231
        if (getStepOverTask() != null) {
232
        	if ((fgAntCallTaskName.equals(taskName) || fgAntTaskName.equals(taskName)) && (!fgAntCallTaskName.equals(getStepOverTask().getTaskName()) && !fgAntTaskName.equals(getStepOverTask().getTaskName()))) {
233
        		setShouldSuspend(true);
234
        	} else if (fTaskToProxies.remove(lastTask) instanceof MacroInstance) {
235
        		setShouldSuspend(true);
236
        	}
237
        }
238
        waitIfSuspended();
239
    }
240
241
    public void stepOver() {
242
       setStepOverTask(getCurrentTask());
243
        if (getCurrentTask() == null) {
244
            //stepping over target breakpoint
245
           setShouldSuspend(true);
246
        }
247
        resume();
248
    }
249
250
    public void targetStarted(BuildEvent event) {
251
		setAfterTaskEvent(false);
252
        Project eventProject = event.getProject();
253
        if (getInitialProperties() == null) {
254
            fInitialProperties= eventProject.getProperties();
255
        }
256
        if (fProjectToTargetNames.get(eventProject) == null) {
257
            Object ref= eventProject.getReference("eclipse.ant.targetVector"); //$NON-NLS-1$
258
            if (ref != null) {
259
                fProjectToTargetNames.put(eventProject, ref);
260
                Map targetToBuildSequence= new HashMap();
261
                setTargetToExecute(initializeBuildSequenceInformation(event, targetToBuildSequence));
262
                fProjectToMapOfTargetToBuildSequence.put(eventProject, targetToBuildSequence);
263
            }
264
        }
265
        
266
        setTargetExecuting(event.getTarget());
267
        if (event.getTarget().equals(getTargetToExecute())) {
268
            //the dependencies of the target to execute have been met
269
            //prepare for the next target
270
            Vector targets= (Vector) fProjectToTargetNames.get(eventProject);
271
            if (!targets.isEmpty()) {
272
                setTargetToExecute((Target) eventProject.getTargets().get(targets.remove(0)));
273
            } else {
274
                setTargetToExecute(null);
275
            }
276
        }
277
        setConsiderTargetBreakpoints(true);
278
    }
279
280
	public int getLineNumber(Location location) {
281
	    try { //succeeds with Ant newer than 1.6
282
	        return location.getLineNumber();
283
	    } catch (NoSuchMethodError e) {
284
	        //Ant before 1.6
285
	        String locationString= location.toString();
286
	        if (locationString.length() == 0) {
287
	            return 0;
288
	        }
289
	        //filename: lineNumber: ("c:\buildfile.xml: 12: ")
290
	        int lastIndex= locationString.lastIndexOf(':');
291
	        int index =locationString.lastIndexOf(':', lastIndex - 1);
292
	        if (index != -1) {
293
	            try {
294
	                return Integer.parseInt(locationString.substring(index+1, lastIndex));
295
	            } catch (NumberFormatException nfe) {
296
	                return 0;
297
	            }
298
	        }
299
	        return 0;
300
	    }
301
	}
302
303
	public static Location getLocation(Target target) {
304
	    try {//succeeds with Ant newer than 1.6.2
305
	        return target.getLocation();
306
	    } catch (NoSuchMethodError e) {
307
	        return Location.UNKNOWN_LOCATION;
308
	    }
309
	}
310
311
	public String getFileName(Location location) {
312
	    try {//succeeds with Ant newer than 1.6
313
	        return location.getFileName();
314
	    } catch (NoSuchMethodError e) {
315
	        //Ant before 1.6
316
	        String locationString= location.toString();
317
	        if (locationString.length() == 0) {
318
	            return null;
319
	        }
320
	        //filename: lineNumber: ("c:\buildfile.xml: 12: ")          
321
	        int lastIndex= locationString.lastIndexOf(':');
322
	        int index =locationString.lastIndexOf(':', lastIndex-1);
323
	        if (index == -1) {
324
	            index= lastIndex; //only the filename is known
325
	        }
326
	        if (index != -1) {
327
	        //bug 84403
328
	            //if (locationString.startsWith("file:")) {
329
	              //  return FileUtils.newFileUtils().fromURI(locationString);
330
	            //}
331
	            //remove file:
332
	            return locationString.substring(5, index);
333
	        }
334
	        return null;
335
	    }
336
	}
337
338
	private void appendToStack(StringBuffer stackRepresentation, String targetName, String taskName, Location location) {
339
	    stackRepresentation.append(targetName);
340
	    stackRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
341
	    stackRepresentation.append(taskName);
342
	    stackRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
343
	    
344
	    stackRepresentation.append(getFileName(location));
345
	    stackRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
346
	    stackRepresentation.append(getLineNumber(location));
347
	    stackRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
348
	}
349
350
	public void marshalStack(StringBuffer stackRepresentation) {
351
		Stack tasks= getTasks();
352
		
353
	    stackRepresentation.append(DebugMessageIds.STACK);
354
	    stackRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
355
	    
356
		Target targetToExecute= getTargetToExecute();
357
		Target targetExecuting= getTargetExecuting();
358
      
359
        Project projectExecuting= null;
360
        if (targetExecuting != null) {
361
            projectExecuting= targetExecuting.getProject();
362
        } else { //no target...must be a task
363
            Task task= (Task) tasks.peek();
364
            projectExecuting= task.getProject();
365
        }
366
        
367
		if (!isAfterTaskEvent()) {
368
			appendToStack(stackRepresentation, targetExecuting.getName(), "", getLocation(targetExecuting)); //$NON-NLS-1$
369
		}
370
		for (int i = tasks.size() - 1; i >= 0 ; i--) {
371
			Task task= (Task) tasks.get(i);
372
            if (task.getProject() == projectExecuting) {
373
                appendToStack(stackRepresentation, task.getOwningTarget().getName(), task.getTaskName(), task.getLocation());
374
            } else {
375
                //sub build target dependencies
376
                String targetName= task.getOwningTarget().getName();
377
                if (targetName != null && targetName.length() != 0) { //skip for implicit target
378
                    Iterator itr= fTargetsToExecute.iterator();
379
                    while (itr.hasNext()) {
380
                        Target target= (Target) itr.next();
381
                        if (target.getProject() != projectExecuting) {
382
                        	targetToExecute= target;
383
                            continue;
384
                        }
385
                        marshalTargetDependancyStack(stackRepresentation, target, targetExecuting);
386
                    }
387
                }
388
                projectExecuting= task.getProject();
389
                targetExecuting= task.getOwningTarget();
390
                appendToStack(stackRepresentation, targetExecuting.getName(), task.getTaskName(), task.getLocation());
391
            }
392
		}
393
394
		//target dependency stack 
395
		marshalTargetDependancyStack(stackRepresentation, targetToExecute, targetExecuting);
396
	}
397
398
    private void marshalTargetDependancyStack(StringBuffer stackRepresentation, Target targetToExecute, Target targetExecuting) {
399
        if (targetToExecute != null) {
400
	     	Vector buildSequence= (Vector) getTargetToBuildSequence(targetToExecute.getProject()).get(targetToExecute);
401
	     	int startIndex= buildSequence.indexOf(targetExecuting) + 1;
402
	     	int dependancyStackDepth= buildSequence.indexOf(targetToExecute);
403
	     	
404
	     	Target stackTarget;
405
	     	for (int i = startIndex; i <= dependancyStackDepth; i++) {
406
	     		stackTarget= (Target) buildSequence.get(i);
407
	            if (stackTarget.dependsOn(targetExecuting.getName())) {
408
	     		    appendToStack(stackRepresentation, stackTarget.getName(), "", getLocation(stackTarget)); //$NON-NLS-1$
409
	            }
410
	     	}
411
	     }
412
    }
413
414
	public void marshallProperties(StringBuffer propertiesRepresentation, boolean escapeLineSep) {
415
		if (getTasks().isEmpty()) {
416
			return;
417
		}
418
	    propertiesRepresentation.append(DebugMessageIds.PROPERTIES);
419
	    propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
420
		
421
		Project project= ((Task)getTasks().peek()).getProject();
422
		Map lastProperties= getProperties(); 
423
		
424
	    Map currentProperties= project.getProperties();
425
	    if (lastProperties != null && currentProperties.size() == lastProperties.size()) {
426
	        //no new properties
427
	        return;
428
	    }
429
	    
430
		Map initialProperties= getInitialProperties();
431
	    Map currentUserProperties= project.getUserProperties();
432
	    Iterator iter= currentProperties.keySet().iterator();
433
	    String propertyName;
434
		String originalPropertyName;
435
	    String propertyValue;
436
	    while (iter.hasNext()) {
437
	        propertyName = (String) iter.next();
438
			originalPropertyName= propertyName;
439
	        if (lastProperties == null || lastProperties.get(propertyName) == null) { //new property
440
				if (escapeLineSep) {
441
					propertyName= escapeLineSeparator(propertyName);
442
				}
443
	            propertiesRepresentation.append(propertyName.length());
444
	            propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
445
	            propertiesRepresentation.append(propertyName);
446
	            propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
447
	            propertyValue= (String) currentProperties.get(originalPropertyName);
448
				if (escapeLineSep) {
449
					propertyValue= escapeLineSeparator(propertyValue);
450
				}
451
	            propertiesRepresentation.append(propertyValue.length());
452
	            propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
453
				propertiesRepresentation.append(propertyValue);
454
	            propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
455
	            propertiesRepresentation.append(getPropertyType(initialProperties, currentUserProperties, originalPropertyName));
456
	            propertiesRepresentation.append(DebugMessageIds.MESSAGE_DELIMITER);
457
	        }
458
	    }
459
	    
460
	    propertiesRepresentation.deleteCharAt(propertiesRepresentation.length() - 1);
461
		fProperties= currentProperties;
462
	}
463
464
	private int getPropertyType(Map initialProperties, Map currentUserProperties, String propertyName) {
465
		if (initialProperties.get(propertyName) != null) { //properties set before the start of the build
466
		    if (currentUserProperties.get(propertyName) == null) {
467
		        return DebugMessageIds.PROPERTY_SYSTEM;
468
		    } 
469
			return DebugMessageIds.PROPERTY_USER;
470
		} else if (currentUserProperties.get(propertyName) == null){
471
		    return DebugMessageIds.PROPERTY_RUNTIME;
472
		} else {
473
		    return DebugMessageIds.PROPERTY_USER;
474
		}
475
	}
476
477
	private String escapeLineSeparator(String stringToEscape) {
478
		if (!(stringToEscape.indexOf('\r') != -1 || stringToEscape.indexOf('\n') != -1 || stringToEscape.indexOf("\\r") != -1 || stringToEscape.indexOf("\\n") != -1)) { //$NON-NLS-1$ //$NON-NLS-2$
479
			return stringToEscape;
480
		}
481
		StringBuffer escapedValue= new StringBuffer(stringToEscape);		
482
		for (int i= 0; i < escapedValue.length(); i++) {
483
			switch (escapedValue.charAt(i)) {
484
			case '\r':
485
				escapedValue.replace(i, i+1, "\\r"); //$NON-NLS-1$
486
				i++;
487
				break;
488
			case '\n':
489
				escapedValue.replace(i, i+1, "\\n"); //$NON-NLS-1$
490
				i++;
491
				break;
492
			case '\\':
493
				if (escapedValue.charAt(i + 1) == 'r' || escapedValue.charAt(i + 1) == 'n') {
494
					escapedValue.replace(i, i+1, "\\\\"); //$NON-NLS-1$
495
					i++;
496
				}
497
				break;
498
			default:
499
				break;
500
			}
501
		}
502
503
		return escapedValue.toString();
504
	}
505
506
	private Target initializeBuildSequenceInformation(BuildEvent event, Map targetToBuildSequence) {
507
	    Project antProject= event.getProject();
508
	    Vector targets= (Vector) antProject.getReference("eclipse.ant.targetVector"); //$NON-NLS-1$
509
        if (targets == null) {
510
            return null;
511
        }
512
	    Iterator itr= targets.iterator();
513
	    Hashtable allTargets= antProject.getTargets();
514
	    String targetName;
515
	    Vector sortedTargets;
516
	    while (itr.hasNext()) {
517
	        targetName= (String) itr.next();
518
	        sortedTargets= antProject.topoSort(targetName, allTargets);
519
	        targetToBuildSequence.put(allTargets.get(targetName), sortedTargets);
520
	    }
521
	    //the target to execute
522
	    return (Target) allTargets.get(targets.remove(0));
523
	}
524
    
525
    public void buildStarted() {
526
        fProjectToTargetNames= new HashMap();
527
        fProjectToMapOfTargetToBuildSequence= new HashMap();
528
    }
529
}
(-)Common Ant Support/org/eclipse/ant/internal/ui/antsupport/logger/util/DebugMessageIds.java (-47 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport.logger.util;
12
13
14
public class DebugMessageIds {
15
	
16
	public final static String MESSAGE_DELIMITER= ","; //$NON-NLS-1$
17
	
18
	public final static String BUILD_STARTED=   "build_started"; //$NON-NLS-1$
19
	public final static String TARGET_STARTED= "target_started"; //$NON-NLS-1$
20
	public final static String TARGET_FINISHED= "target_finished"; //$NON-NLS-1$
21
	public final static String TASK_STARTED= "task_started"; //$NON-NLS-1$
22
	public final static String TASK_FINISHED= "task_finished"; //$NON-NLS-1$
23
	
24
	public final static String STEP= "step"; //$NON-NLS-1$
25
	public final static String STEP_OVER= "step_over"; //$NON-NLS-1$
26
	public final static String STEP_INTO= "step_into"; //$NON-NLS-1$
27
	
28
	public final static String TERMINATE= "terminate"; //$NON-NLS-1$
29
	public final static String TERMINATED= "terminated"; //$NON-NLS-1$
30
	public final static String SUSPEND= "suspend"; //$NON-NLS-1$
31
	public final static String SUSPENDED= "suspended"; //$NON-NLS-1$
32
	public final static String RESUME= "resume"; //$NON-NLS-1$
33
	
34
	public final static String STACK= "stack"; //$NON-NLS-1$
35
	
36
	public final static String ADD_BREAKPOINT= "add"; //$NON-NLS-1$
37
	public final static String REMOVE_BREAKPOINT= "remove"; //$NON-NLS-1$
38
	
39
	public final static String CLIENT_REQUEST= "client"; //$NON-NLS-1$
40
	public final static String BREAKPOINT= "breakpoint"; //$NON-NLS-1$
41
	
42
	public final static String PROPERTIES= "prop"; //$NON-NLS-1$
43
	public final static String PROPERTY_VALUE= "value"; //$NON-NLS-1$
44
	public final static int PROPERTY_USER= 0;
45
	public final static int PROPERTY_SYSTEM= 1;
46
	public final static int PROPERTY_RUNTIME= 2;
47
}
(-)Common Ant Support/org/eclipse/ant/internal/ui/antsupport/logger/util/IDebugBuildLogger.java (-21 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport.logger.util;
12
13
14
public interface IDebugBuildLogger {
15
16
	/**
17
	 * Requests to suspend the build if the current debug state
18
	 * indicates that suspension is required.
19
	 */
20
    public abstract void waitIfSuspended();
21
}
(-)META-INF/MANIFEST.MF (-3 / +4 lines)
Lines 2-15 Link Here
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.ant.ui; singleton:=true
4
Bundle-SymbolicName: org.eclipse.ant.ui; singleton:=true
5
Bundle-Version: 3.4.0.qualifier
5
Bundle-Version: 3.5.0.qualifier
6
Bundle-Activator: org.eclipse.ant.internal.ui.AntUIPlugin
6
Bundle-Activator: org.eclipse.ant.internal.ui.AntUIPlugin
7
Bundle-Vendor: %providerName
7
Bundle-Vendor: %providerName
8
Bundle-Localization: plugin
8
Bundle-Localization: plugin
9
Export-Package: org.eclipse.ant.internal.ui;x-internal:=true,
9
Export-Package: org.eclipse.ant.internal.ui;x-internal:=true,
10
 org.eclipse.ant.internal.ui.console;x-internal:=true,
10
 org.eclipse.ant.internal.ui.console;x-internal:=true,
11
 org.eclipse.ant.internal.ui.datatransfer;x-internal:=true,
11
 org.eclipse.ant.internal.ui.datatransfer;x-internal:=true,
12
 org.eclipse.ant.internal.ui.debug;x-internal:=true,
13
 org.eclipse.ant.internal.ui.debug.model;x-internal:=true,
12
 org.eclipse.ant.internal.ui.debug.model;x-internal:=true,
14
 org.eclipse.ant.internal.ui.dtd;x-internal:=true,
13
 org.eclipse.ant.internal.ui.dtd;x-internal:=true,
15
 org.eclipse.ant.internal.ui.dtd.schema;x-internal:=true,
14
 org.eclipse.ant.internal.ui.dtd.schema;x-internal:=true,
Lines 51-57 Link Here
51
 org.eclipse.team.core;bundle-version="[3.2.0,4.0.0)",
50
 org.eclipse.team.core;bundle-version="[3.2.0,4.0.0)",
52
 org.eclipse.ltk.core.refactoring;bundle-version="[3.2.0,4.0.0)",
51
 org.eclipse.ltk.core.refactoring;bundle-version="[3.2.0,4.0.0)",
53
 org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)",
52
 org.eclipse.core.expressions;bundle-version="[3.2.0,4.0.0)",
54
 org.eclipse.jdt.junit;bundle-version="[3.5.0,4.0.0)"
53
 org.eclipse.jdt.junit;bundle-version="[3.5.0,4.0.0)",
54
 org.eclipse.ant.launching;bundle-version="1.0.0",
55
 org.eclipse.core.externaltools;bundle-version="1.0.0"
55
Bundle-ActivationPolicy: lazy
56
Bundle-ActivationPolicy: lazy
56
Import-Package: com.ibm.icu.text
57
Import-Package: com.ibm.icu.text
57
Bundle-RequiredExecutionEnvironment: J2SE-1.4
58
Bundle-RequiredExecutionEnvironment: J2SE-1.4
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/AntSecurityException.java (-23 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport;
12
13
/**
14
 * A security exception that is thrown by the AntSecurityManager if
15
 * an Ant task in some way attempts to halt or exit the Java Virtual Machine.
16
 * 
17
 * @since 2.1
18
 */
19
public class AntSecurityException extends SecurityException {
20
21
	private static final long serialVersionUID = 1L;
22
23
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/AntSecurityManager.java (-371 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport;
12
13
14
import java.io.FileDescriptor;
15
import java.net.InetAddress;
16
import java.net.SocketPermission;
17
import java.security.Permission;
18
import java.util.PropertyPermission;
19
20
/**
21
 * A security manager that always throws an <code>AntSecurityException</code>
22
 * if the calling thread attempts to cause the Java Virtual Machine to 
23
 * exit/halt or if the restricted thread attempts to set a System property.
24
 * Otherwise this manager just delegates to the pre-existing manager
25
 * passed in the constructor or mimics the default security manager behavior
26
 */
27
public class AntSecurityManager extends SecurityManager {
28
29
	private SecurityManager fSecurityManager= null;
30
	private Thread fRestrictedThread= null;
31
	//ensure that the PropertyPermission class is loaded before we 
32
	//start checking permissions: bug 85908
33
	private static final PropertyPermission fgPropertyPermission= new PropertyPermission("*", "write"); //$NON-NLS-1$ //$NON-NLS-2$
34
	
35
	private boolean fAllowSettingSystemProperties= true;
36
	
37
	public AntSecurityManager(SecurityManager securityManager, Thread restrictedThread, boolean allowSettingProperties) {
38
		fSecurityManager= securityManager;
39
		fRestrictedThread= restrictedThread;
40
		fAllowSettingSystemProperties= allowSettingProperties;
41
	}
42
	
43
	public AntSecurityManager(SecurityManager securityManager, Thread restrictedThread) {
44
		this(securityManager, restrictedThread, true);
45
	}
46
	
47
	/* (non-Javadoc)
48
	 * @see java.lang.SecurityManager#checkExit(int)
49
	 */
50
	public void checkExit(int status) {
51
		//no exit allowed from the restricted thread...System.exit is being called
52
		//by some ant task...disallow the exit
53
		if (Thread.currentThread() == fRestrictedThread) {
54
			throw new AntSecurityException();
55
		}
56
		if (fSecurityManager != null) {
57
			fSecurityManager.checkExit(status);
58
		}
59
	}
60
	/* (non-Javadoc)
61
	 * @see java.lang.SecurityManager#checkAccept(java.lang.String, int)
62
	 */
63
	public void checkAccept(String host, int port) {
64
		if (fSecurityManager != null) {
65
			fSecurityManager.checkAccept(host, port);
66
		}
67
	}
68
69
	/* (non-Javadoc)
70
	 * @see java.lang.SecurityManager#checkAccess(java.lang.Thread)
71
	 */
72
	public void checkAccess(Thread t) {
73
		if (fSecurityManager != null) {
74
			fSecurityManager.checkAccess(t);
75
		}
76
	}
77
78
	/* (non-Javadoc)
79
	 * @see java.lang.SecurityManager#checkAccess(java.lang.ThreadGroup)
80
	 */
81
	public void checkAccess(ThreadGroup g) {
82
		if (fSecurityManager != null) {
83
			fSecurityManager.checkAccess(g);
84
		}
85
	}
86
87
	/* (non-Javadoc)
88
	 * @see java.lang.SecurityManager#checkAwtEventQueueAccess()
89
	 */
90
	public void checkAwtEventQueueAccess() {
91
		if (fSecurityManager != null) {
92
			fSecurityManager.checkAwtEventQueueAccess();
93
		}
94
	}
95
96
	/* (non-Javadoc)
97
	 * @see java.lang.SecurityManager#checkConnect(java.lang.String, int, java.lang.Object)
98
	 */
99
	public void checkConnect(String host, int port, Object context) {
100
		if (fSecurityManager != null) {
101
			fSecurityManager.checkConnect(host, port, context);
102
		}
103
	}
104
105
	/* (non-Javadoc)
106
	 * @see java.lang.SecurityManager#checkConnect(java.lang.String, int)
107
	 */
108
	public void checkConnect(String host, int port) {
109
		if (fSecurityManager != null) {
110
			fSecurityManager.checkConnect(host, port);
111
		}
112
	}
113
114
	/* (non-Javadoc)
115
	 * @see java.lang.SecurityManager#checkCreateClassLoader()
116
	 */
117
	public void checkCreateClassLoader() {
118
		if (fSecurityManager != null) {
119
			fSecurityManager.checkCreateClassLoader();
120
		}
121
	}
122
123
	/* (non-Javadoc)
124
	 * @see java.lang.SecurityManager#checkDelete(java.lang.String)
125
	 */
126
	public void checkDelete(String file) {
127
		if (fSecurityManager != null) {
128
			fSecurityManager.checkDelete(file);
129
		}
130
	}
131
132
	/* (non-Javadoc)
133
	 * @see java.lang.SecurityManager#checkExec(java.lang.String)
134
	 */
135
	public void checkExec(String cmd) {
136
		if (fSecurityManager != null) {
137
			fSecurityManager.checkExec(cmd);
138
		}
139
	}
140
141
	/* (non-Javadoc)
142
	 * @see java.lang.SecurityManager#checkLink(java.lang.String)
143
	 */
144
	public void checkLink(String lib) {
145
		if (fSecurityManager != null) {
146
			fSecurityManager.checkLink(lib);
147
		}
148
	}
149
150
	/* (non-Javadoc)
151
	 * @see java.lang.SecurityManager#checkListen(int)
152
	 */
153
	public void checkListen(int port) {
154
		if (fSecurityManager != null) {
155
			fSecurityManager.checkListen(port);
156
		}
157
	}
158
159
	/* (non-Javadoc)
160
	 * @see java.lang.SecurityManager#checkMemberAccess(java.lang.Class, int)
161
	 */
162
	public void checkMemberAccess(Class clazz, int which) {
163
		if (fSecurityManager != null) {
164
			fSecurityManager.checkMemberAccess(clazz, which);
165
		}
166
	}
167
168
	/**
169
	 * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress, byte)
170
	 * @deprecated
171
	 */
172
	public void checkMulticast(InetAddress maddr, byte ttl) {
173
		if (fSecurityManager != null) {
174
			String host = maddr.getHostAddress();
175
			if (!host.startsWith("[") && host.indexOf(':') != -1) { //$NON-NLS-1$
176
	   			host = "[" + host + "]"; //$NON-NLS-1$ //$NON-NLS-2$
177
			}
178
	    	checkPermission(new SocketPermission(host, "accept,connect")); //$NON-NLS-1$
179
		}
180
	}
181
182
	/* (non-Javadoc)
183
	 * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress)
184
	 */
185
	public void checkMulticast(InetAddress maddr) {
186
		if (fSecurityManager != null) {
187
			fSecurityManager.checkMulticast(maddr);
188
		}
189
	}
190
191
	/* (non-Javadoc)
192
	 * @see java.lang.SecurityManager#checkPackageAccess(java.lang.String)
193
	 */
194
	public void checkPackageAccess(String pkg) {
195
		if (fSecurityManager != null) {
196
			fSecurityManager.checkPackageAccess(pkg);
197
		}
198
	}
199
200
	/* (non-Javadoc)
201
	 * @see java.lang.SecurityManager#checkPackageDefinition(java.lang.String)
202
	 */
203
	public void checkPackageDefinition(String pkg) {
204
		if (fSecurityManager != null) {
205
			fSecurityManager.checkPackageDefinition(pkg);
206
		}
207
	}
208
209
	/* (non-Javadoc)
210
	 * @see java.lang.SecurityManager#checkPermission(java.security.Permission, java.lang.Object)
211
	 */
212
	public void checkPermission(Permission perm, Object context) {
213
		if (fSecurityManager != null) {
214
			fSecurityManager.checkPermission(perm, context);
215
		}
216
	}
217
218
	/* (non-Javadoc)
219
	 * @see java.lang.SecurityManager#checkPermission(java.security.Permission)
220
	 */
221
	public void checkPermission(Permission perm) {
222
		if (!fAllowSettingSystemProperties && fgPropertyPermission.implies(perm) && fRestrictedThread == Thread.currentThread()) {
223
			//attempting to write a system property
224
			throw new AntSecurityException();
225
		}
226
		if (fSecurityManager != null) {
227
			fSecurityManager.checkPermission(perm);
228
		}
229
	}
230
231
	/* (non-Javadoc)
232
	 * @see java.lang.SecurityManager#checkPrintJobAccess()
233
	 */
234
	public void checkPrintJobAccess() {
235
		if (fSecurityManager != null) {
236
			fSecurityManager.checkPrintJobAccess();
237
		}
238
	}
239
240
	/* (non-Javadoc)
241
	 * @see java.lang.SecurityManager#checkPropertiesAccess()
242
	 */
243
	public void checkPropertiesAccess() {
244
		if (fSecurityManager != null) {
245
			fSecurityManager.checkPropertiesAccess();
246
		}
247
		super.checkPropertiesAccess();
248
	}
249
250
	/* (non-Javadoc)
251
	 * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String)
252
	 */
253
	public void checkPropertyAccess(String key) {
254
		if (fSecurityManager != null) {
255
			fSecurityManager.checkPropertyAccess(key);
256
		}
257
	}
258
259
	/* (non-Javadoc)
260
	 * @see java.lang.SecurityManager#checkRead(java.io.FileDescriptor)
261
	 */
262
	public void checkRead(FileDescriptor fd) {
263
		if (fSecurityManager != null) {
264
			fSecurityManager.checkRead(fd);
265
		}
266
	}
267
268
	/* (non-Javadoc)
269
	 * @see java.lang.SecurityManager#checkRead(java.lang.String, java.lang.Object)
270
	 */
271
	public void checkRead(String file, Object context) {
272
		if (fSecurityManager != null) {
273
			fSecurityManager.checkRead(file, context);
274
		}
275
	}
276
277
	/* (non-Javadoc)
278
	 * @see java.lang.SecurityManager#checkRead(java.lang.String)
279
	 */
280
	public void checkRead(String file) {
281
		if (fSecurityManager != null) {
282
			fSecurityManager.checkRead(file);
283
		}
284
	}
285
286
	/* (non-Javadoc)
287
	 * @see java.lang.SecurityManager#checkSecurityAccess(java.lang.String)
288
	 */
289
	public void checkSecurityAccess(String target) {
290
		if (fSecurityManager != null) {
291
			fSecurityManager.checkSecurityAccess(target);
292
		}
293
	}
294
295
	/* (non-Javadoc)
296
	 * @see java.lang.SecurityManager#checkSetFactory()
297
	 */
298
	public void checkSetFactory() {
299
		if (fSecurityManager != null) {
300
			fSecurityManager.checkSetFactory();
301
		}
302
	}
303
304
	/* (non-Javadoc)
305
	 * @see java.lang.SecurityManager#checkSystemClipboardAccess()
306
	 */
307
	public void checkSystemClipboardAccess() {
308
		if (fSecurityManager != null) {
309
			fSecurityManager.checkSystemClipboardAccess();
310
		}
311
	}
312
313
	/* (non-Javadoc)
314
	 * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object)
315
	 */
316
	public boolean checkTopLevelWindow(Object window) {
317
		if (fSecurityManager != null) {
318
			return fSecurityManager.checkTopLevelWindow(window);
319
		}
320
		return super.checkTopLevelWindow(window);
321
	}
322
323
	/* (non-Javadoc)
324
	 * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor)
325
	 */
326
	public void checkWrite(FileDescriptor fd) {
327
		if (fSecurityManager != null) {
328
			fSecurityManager.checkWrite(fd);
329
		}
330
	}
331
332
	/* (non-Javadoc)
333
	 * @see java.lang.SecurityManager#checkWrite(java.lang.String)
334
	 */
335
	public void checkWrite(String file) {
336
		if (fSecurityManager != null) {
337
			fSecurityManager.checkWrite(file);
338
		}
339
	}
340
341
	/**
342
	 * @see java.lang.SecurityManager#getInCheck()
343
	 * @deprecated
344
	 */
345
	public boolean getInCheck() {
346
		if (fSecurityManager != null) {
347
			return fSecurityManager.getInCheck();
348
		}
349
		return super.getInCheck();
350
	}
351
352
	/* (non-Javadoc)
353
	 * @see java.lang.SecurityManager#getSecurityContext()
354
	 */
355
	public Object getSecurityContext() {
356
		if (fSecurityManager != null) {
357
			return fSecurityManager.getSecurityContext();
358
		}
359
		return super.getSecurityContext();
360
	}
361
362
	/* (non-Javadoc)
363
	 * @see java.lang.SecurityManager#getThreadGroup()
364
	 */
365
	public ThreadGroup getThreadGroup() {
366
		if (fSecurityManager != null) {
367
			fSecurityManager.getThreadGroup();
368
		}
369
		return super.getThreadGroup();
370
	}
371
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/DemuxInputStreamSetter.java (-26 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport;
12
13
14
import org.apache.tools.ant.DemuxInputStream;
15
import org.apache.tools.ant.Project;
16
17
/**
18
 * This class exists so that the Ant integration has backwards compatibility
19
 * with Ant releases previous to 1.6. DemuxInputStream is a new class to Ant 1.6.
20
 */
21
class DemuxInputStreamSetter {
22
23
	protected void remapSystemIn(Project project) {
24
		System.setIn(new DemuxInputStream(project));
25
	}
26
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/EclipseDefaultExecutor.java (-41 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport;
12
13
import java.util.Arrays;
14
import java.util.Vector;
15
16
import org.apache.tools.ant.BuildException;
17
import org.apache.tools.ant.Executor;
18
import org.apache.tools.ant.Project;
19
import org.apache.tools.ant.helper.DefaultExecutor;
20
21
public class EclipseDefaultExecutor extends DefaultExecutor {
22
23
    private static final EclipseSingleCheckExecutor SUB_EXECUTOR = new EclipseSingleCheckExecutor();
24
    
25
    /* (non-Javadoc)
26
     * @see org.apache.tools.ant.Executor#executeTargets(org.apache.tools.ant.Project, java.lang.String[])
27
     */
28
    public void executeTargets(Project project, String[] targetNames) throws BuildException {
29
        Vector v= new Vector();
30
        v.addAll(Arrays.asList(targetNames));
31
        project.addReference("eclipse.ant.targetVector", v); //$NON-NLS-1$
32
        super.executeTargets(project, targetNames);
33
    }
34
    
35
    /* (non-Javadoc)
36
     * @see org.apache.tools.ant.Executor#getSubProjectExecutor()
37
     */
38
    public Executor getSubProjectExecutor() {
39
       return SUB_EXECUTOR;
40
    }
41
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/EclipseSingleCheckExecutor.java (-39 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport;
12
13
import java.util.Arrays;
14
import java.util.Vector;
15
16
import org.apache.tools.ant.BuildException;
17
import org.apache.tools.ant.Executor;
18
import org.apache.tools.ant.Project;
19
import org.apache.tools.ant.helper.SingleCheckExecutor;
20
21
public class EclipseSingleCheckExecutor extends SingleCheckExecutor {
22
23
    /* (non-Javadoc)
24
     * @see org.apache.tools.ant.Executor#executeTargets(org.apache.tools.ant.Project, java.lang.String[])
25
     */
26
    public void executeTargets(Project project, String[] targetNames) throws BuildException {
27
        Vector v= new Vector();
28
        v.addAll(Arrays.asList(targetNames));
29
        project.addReference("eclipse.ant.targetVector", v); //$NON-NLS-1$
30
        super.executeTargets(project, targetNames);
31
    }
32
    
33
    /* (non-Javadoc)
34
     * @see org.apache.tools.ant.Executor#getSubProjectExecutor()
35
     */
36
    public Executor getSubProjectExecutor() {
37
        return this;
38
    }
39
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/ExecutorSetter.java (-26 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport;
12
13
import org.apache.tools.ant.Executor;
14
import org.apache.tools.ant.Project;
15
16
/**
17
 * This class exists so that the Ant integration has backwards compatibility
18
 * with Ant releases previous to 1.6.3. Executors are a new feature of Ant 1.6.3.
19
 */
20
public class ExecutorSetter {
21
22
    protected void setExecutor(Project project) {
23
        Executor executor= new EclipseDefaultExecutor();
24
        project.setExecutor(executor);
25
    }
26
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/InputHandlerSetter.java (-44 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport;
12
13
14
import java.text.MessageFormat; // can't use ICU, used by ant
15
16
import org.apache.tools.ant.BuildException;
17
import org.apache.tools.ant.Project;
18
import org.apache.tools.ant.input.DefaultInputHandler;
19
import org.apache.tools.ant.input.InputHandler;
20
21
/**
22
 * This class exists so that the Ant integration has backwards compatibility
23
 * with Ant releases previous to 1.5. InputHandlers are a new feature of Ant 1.5.
24
 */
25
class InputHandlerSetter {
26
27
	protected void setInputHandler(Project project, String inputHandlerClassname) {
28
		InputHandler handler = null;
29
		if (inputHandlerClassname == null) {
30
			handler = new DefaultInputHandler();
31
		} else {
32
			try {
33
				handler = (InputHandler)(Class.forName(inputHandlerClassname).newInstance());
34
			} catch (ClassCastException e) {
35
				String msg = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.The_specified_input_handler_class_{0}_does_not_implement_the_org.apache.tools.ant.input.InputHandler_interface_5"), new String[]{inputHandlerClassname}); //$NON-NLS-1$
36
				throw new BuildException(msg, e);
37
			} catch (Exception e) {
38
				String msg = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unable_to_instantiate_specified_input_handler_class_{0}___{1}_6"), new String[]{inputHandlerClassname, e.getClass().getName()}); //$NON-NLS-1$
39
				throw new BuildException(msg, e);
40
			}
41
		}
42
		project.setInputHandler(handler);
43
	}
44
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/InternalAntRunner.java (-1231 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * Portions Copyright  2000-2005 The Apache Software Foundation
4
 * All rights reserved. This program and the accompanying materials are made 
5
 * available under the terms of the Apache Software License v2.0 which 
6
 * accompanies this distribution and is available at 
7
 * http://www.apache.org/licenses/LICENSE-2.0.
8
 * 
9
 * Contributors:
10
 *     IBM Corporation - derived implementation
11
 *******************************************************************************/
12
13
package org.eclipse.ant.internal.ui.antsupport;
14
15
import java.io.File;
16
import java.io.FileInputStream;
17
import java.io.FileNotFoundException;
18
import java.io.FileOutputStream;
19
import java.io.IOException;
20
import java.io.InputStream;
21
import java.io.PrintStream;
22
import java.text.MessageFormat; // can't use ICU, used by ant build
23
import java.util.ArrayList;
24
import java.util.Collections;
25
import java.util.Enumeration;
26
import java.util.HashMap;
27
import java.util.Iterator;
28
import java.util.List;
29
import java.util.Map;
30
import java.util.Properties;
31
import java.util.Vector;
32
33
import org.apache.tools.ant.AntTypeDefinition;
34
import org.apache.tools.ant.BuildEvent;
35
import org.apache.tools.ant.BuildException;
36
import org.apache.tools.ant.BuildListener;
37
import org.apache.tools.ant.BuildLogger;
38
import org.apache.tools.ant.ComponentHelper;
39
import org.apache.tools.ant.DefaultLogger;
40
import org.apache.tools.ant.DemuxOutputStream;
41
import org.apache.tools.ant.Diagnostics;
42
import org.apache.tools.ant.Main;
43
import org.apache.tools.ant.Project;
44
import org.apache.tools.ant.ProjectHelper;
45
import org.apache.tools.ant.Target;
46
import org.apache.tools.ant.Task;
47
import org.apache.tools.ant.TaskAdapter;
48
import org.apache.tools.ant.util.FileUtils;
49
import org.eclipse.ant.internal.ui.antsupport.logger.RemoteAntBuildLogger;
50
51
/**
52
 * Eclipse application entry point into Ant in a separate VM. Derived from the original Ant Main class
53
 * to ensure that the functionality is equivalent when running in the platform.
54
 */
55
public class InternalAntRunner {
56
57
	/**
58
	 *  Message priority for project help messages. 
59
	 */
60
	public static final int MSG_PROJECT_HELP= Project.MSG_DEBUG + 1;
61
	
62
	private List buildListeners;
63
64
	private String buildFileLocation;
65
66
	/** 
67
	 * Targets we want to run.
68
	 */
69
	private Vector targets;
70
71
	private Map userProperties;
72
	
73
	private Project currentProject;
74
	
75
	private BuildLogger buildLogger= null;
76
	
77
	private Map eclipseSpecifiedTasks;
78
	private Map eclipseSpecifiedTypes;
79
	
80
	/**
81
	 * Cache of the Ant version number when it has been loaded
82
	 */
83
	private String antVersionNumber= null;
84
85
	/** Our current message output status. Follows Project.MSG_XXX */
86
	private int messageOutputLevel = Project.MSG_INFO;
87
88
	/** Indicates whether output to the log is to be unadorned. */
89
	private boolean emacsMode = false;
90
91
	/** Indicates we should only parse and display the project help information */
92
	private boolean projectHelp = false;
93
94
	/** Stream that we are using for logging */
95
	private PrintStream out = System.out;
96
97
	/** Stream that we are using for logging error messages */
98
	private PrintStream err = System.err;
99
100
	/**
101
	 * The Ant logger class. There may be only one logger. It will have the
102
	 * right to use the 'out' PrintStream. The class must implement the BuildLogger
103
	 * interface.  An empty String indicates that no logger is to be used.  A <code>null</code>
104
	 * name indicates that the <code>org.apache.tools.ant.DefaultLogger</code> will be used.
105
	 */
106
	private String loggerClassname = null;
107
108
	/** Extra arguments to be parsed as command line arguments. */
109
	private String[] extraArguments = null;
110
	
111
	private boolean scriptExecuted= false;
112
	
113
	private List propertyFiles= new ArrayList();
114
	
115
	/**
116
     * The Ant InputHandler class. There may be only one input handler.
117
     */
118
    private String inputHandlerClassname = null;
119
    
120
    /** 
121
     * Indicates whether to execute all targets that 
122
     * do not depend on failed targets
123
     * @since Ant 1.6.0
124
     */
125
    private boolean keepGoing= false;
126
127
    /** 
128
     * Indicates whether this build is to support interactive input 
129
     * @since Ant 1.6.0
130
     */
131
    private boolean allowInput = true;
132
    
133
    private String fEarlyErrorMessage= null;
134
    
135
    public static void main(String[] args) {
136
    	try {
137
    		new InternalAntRunner().run(getArrayList(args));
138
    	} catch (Throwable t) {
139
    	    t.printStackTrace();
140
    		System.exit(1);
141
    	}
142
		System.exit(0);
143
	}
144
145
	private void addBuildListeners(Project project) {
146
		String className= null;
147
		try {
148
			BuildLogger logger= createLogger();
149
			if (logger != null) {
150
				project.addBuildListener(logger);
151
			}
152
			if (buildListeners != null) {
153
				for (Iterator iterator = buildListeners.iterator(); iterator.hasNext();) {
154
					className = (String) iterator.next();
155
					Class listener = Class.forName(className);
156
					project.addBuildListener((BuildListener) listener.newInstance());
157
				}
158
			}
159
		} catch (ClassCastException e) {
160
			String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.{0}_which_was_specified_to_be_a_build_listener_is_not_an_instance_of_org.apache.tools.ant.BuildListener._1"), new String[]{className}); //$NON-NLS-1$
161
			logMessage(null, message, Project.MSG_ERR);
162
			throw new BuildException(message, e);
163
		} catch (BuildException e) {
164
			throw e;
165
		} catch (Exception e) {
166
			throw new BuildException(e);
167
		}
168
	}
169
170
	/**
171
	 * Parses the build file and adds necessary information into
172
	 * the given project.
173
	 * @param project The project to configure
174
	 */
175
	private void parseBuildFile(Project project) {
176
		File buildFile = new File(getBuildFileLocation());
177
		if (!buildFile.exists()) {
178
			throw new BuildException(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Buildfile__{0}_does_not_exist_!_1"), //$NON-NLS-1$
179
						 new String[]{buildFile.getAbsolutePath()}));
180
		}
181
		if (!buildFile.isFile()) {
182
			throw new BuildException(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Buildfile__{0}_is_not_a_file_1"), //$NON-NLS-1$
183
							new String[]{buildFile.getAbsolutePath()}));
184
		}
185
		
186
        if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
187
            parseBuildFile(project, buildFile);
188
        } else {
189
            ProjectHelper helper = ProjectHelper.getProjectHelper();
190
            project.addReference("ant.projectHelper", helper); //$NON-NLS-1$
191
            helper.parse(project, buildFile);
192
        }
193
    }
194
    
195
    /**
196
     * @deprecated support for Ant older than 1.5
197
     */
198
    private void parseBuildFile(Project project, File buildFile) {
199
        ProjectHelper.configureProject(project, buildFile);   
200
    }
201
202
	private void printArguments(Project project) {
203
		if ((messageOutputLevel != Project.MSG_DEBUG) && (messageOutputLevel != Project.MSG_VERBOSE)) {
204
			return;
205
		}
206
		StringBuffer sb = new StringBuffer();
207
		for (int i = 0; i < extraArguments.length; i++) {
208
			sb.append(extraArguments[i]);
209
			sb.append(' ');
210
		}
211
		project.log(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Arguments__{0}_2"), new String[]{sb.toString().trim()})); //$NON-NLS-1$
212
	}
213
214
215
	/**
216
	 * Logs a message with the client that lists the targets
217
	 * in a project
218
	 * 
219
	 * @param project the project to list targets from
220
	 */
221
	private void printTargets(Project project) {
222
		//notify the logger that project help message are coming
223
		//since there is no buildstarted or targetstarted to 
224
		//to be used to establish the connection
225
		logMessage(project, "", MSG_PROJECT_HELP); //$NON-NLS-1$
226
		// find the target with the longest name
227
		int maxLength = 0;
228
		Enumeration ptargets = project.getTargets().elements();
229
		String targetName;
230
		String targetDescription;
231
		Target currentTarget;
232
		// split the targets in top-level and sub-targets depending
233
		// on the presence of a description
234
		List topNames = new ArrayList();
235
		List topDescriptions = new ArrayList();
236
		List subNames = new ArrayList();
237
238
		while (ptargets.hasMoreElements()) {
239
			currentTarget = (Target) ptargets.nextElement();
240
			targetName = currentTarget.getName();
241
			targetDescription = currentTarget.getDescription();
242
			if (targetDescription == null) {
243
				subNames.add(targetName);
244
			} else {
245
				topNames.add(targetName);
246
				topDescriptions.add(targetDescription);
247
				if (targetName.length() > maxLength) {
248
					maxLength = targetName.length();
249
				}
250
			}
251
		}
252
253
		Collections.sort(subNames);
254
		Collections.sort(topNames);
255
		Collections.sort(topDescriptions);
256
		
257
		String defaultTargetName = project.getDefaultTarget();
258
		if (defaultTargetName != null && !"".equals(defaultTargetName)) { // shouldn't need to check but... //$NON-NLS-1$
259
			List defaultName = new ArrayList(1);
260
			List defaultDesc = null;
261
			defaultName.add(defaultTargetName);
262
263
			int indexOfDefDesc = topNames.indexOf(defaultTargetName);
264
			if (indexOfDefDesc >= 0) {
265
				defaultDesc = new ArrayList(1);
266
				defaultDesc.add(topDescriptions.get(indexOfDefDesc));
267
			}
268
			printTargets(project, defaultName, defaultDesc, RemoteAntMessages.getString("InternalAntRunner.Default_target__3"), maxLength); //$NON-NLS-1$
269
270
		}
271
272
		printTargets(project, topNames, topDescriptions, RemoteAntMessages.getString("InternalAntRunner.Main_targets__4"), maxLength); //$NON-NLS-1$
273
		printTargets(project, subNames, null, RemoteAntMessages.getString("InternalAntRunner.Subtargets__5"), 0); //$NON-NLS-1$
274
	}
275
276
	/**
277
	 * Logs a message with the client that lists the target names and optional descriptions
278
	 * 
279
	 * @param project the enclosing target
280
	 * @param names the targets names
281
	 * @param descriptions the corresponding descriptions
282
	 * @param heading the message heading
283
	 * @param maxlen maximum length that can be allocated for a name
284
	 */
285
	private void printTargets(Project project, List names, List descriptions, String heading, int maxlen) {
286
		// now, start printing the targets and their descriptions
287
		String lSep = System.getProperty("line.separator"); //$NON-NLS-1$
288
		
289
		String spaces = "    "; //$NON-NLS-1$
290
		while (spaces.length() < maxlen) {
291
			spaces += spaces;
292
		}
293
		StringBuffer msg = new StringBuffer();
294
		msg.append(heading + lSep + lSep);
295
		for (int i = 0; i < names.size(); i++) {
296
			msg.append(' ');
297
			msg.append(names.get(i));
298
			if (descriptions != null) {
299
				msg.append(spaces.substring(0, maxlen - ((String) names.get(i)).length() + 2));
300
				msg.append(descriptions.get(i));
301
			}
302
			msg.append(lSep);
303
		}
304
		logMessage(project, msg.toString(), Project.MSG_INFO);
305
	}
306
307
	/*
308
	 * Note that the list passed to this method must support
309
	 * List#remove(Object)
310
	 */
311
	private void run(List argList) {
312
		setCurrentProject(new Project());
313
         if (isVersionCompatible("1.6.3")) { //$NON-NLS-1$
314
               new ExecutorSetter().setExecutor(getCurrentProject());
315
            }
316
		Throwable error = null;
317
		PrintStream originalErr = System.err;
318
		PrintStream originalOut = System.out;
319
		InputStream originalIn= System.in;
320
		
321
		SecurityManager originalSM= System.getSecurityManager();
322
		scriptExecuted= true;
323
		try {
324
			if (argList != null && (argList.remove("-projecthelp") || argList.remove("-p"))) { //$NON-NLS-1$ //$NON-NLS-2$
325
				projectHelp = true;
326
			}
327
			getCurrentProject().init();
328
			if (argList != null) {
329
				scriptExecuted= preprocessCommandLine(argList);
330
			
331
				if (!scriptExecuted) {
332
					return;
333
				}
334
			}
335
			
336
            boolean exceptionState= processProperties(argList);
337
            
338
			addBuildListeners(getCurrentProject());
339
            
340
			addInputHandler(getCurrentProject());
341
			
342
			remapSystemIn();
343
			System.setOut(new PrintStream(new DemuxOutputStream(getCurrentProject(), false)));
344
			System.setErr(new PrintStream(new DemuxOutputStream(getCurrentProject(), true)));
345
			
346
			if (!projectHelp) {
347
				fireBuildStarted(getCurrentProject());
348
			}
349
            
350
            if (fEarlyErrorMessage != null) {
351
                //an error occurred processing the properties
352
                //build started has fired and we have
353
                //listeners/loggers to report the error
354
                logMessage(getCurrentProject(), fEarlyErrorMessage, Project.MSG_ERR);
355
                if (exceptionState) {
356
                    throw new BuildException(fEarlyErrorMessage);
357
                }
358
            }
359
            
360
            //properties can only be set after buildStarted as some listeners/loggers
361
            //depend on this (e.g. XMLLogger)
362
            setProperties(getCurrentProject());
363
			
364
			if (argList != null && !argList.isEmpty()) {
365
				try {
366
					scriptExecuted= processCommandLine(argList);
367
				} catch (BuildException e) {
368
					scriptExecuted= false;
369
					throw e;
370
				}
371
			}
372
			if (!scriptExecuted) {
373
				return;
374
			}
375
			
376
            //needs to occur after processCommandLine(List)
377
			if (allowInput && (inputHandlerClassname != null && inputHandlerClassname.length() > 0)) {
378
				if (isVersionCompatible("1.6")) { //$NON-NLS-1$
379
					getCurrentProject().setDefaultInputStream(originalIn);
380
				}
381
			} else {
382
				//set the system property that any input handler
383
				//can check to see if handling input is allowed
384
				System.setProperty("eclipse.ant.noInput", "true");  //$NON-NLS-1$//$NON-NLS-2$
385
				if (isVersionCompatible("1.5") && (inputHandlerClassname == null || inputHandlerClassname.length() == 0)) { //$NON-NLS-1$
386
					InputHandlerSetter setter= new InputHandlerSetter();
387
					setter.setInputHandler(getCurrentProject(), "org.eclipse.ant.internal.ui.antsupport.inputhandler.FailInputHandler"); //$NON-NLS-1$
388
				}
389
			}
390
			
391
			getCurrentProject().log(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Build_file__{0}_1"), new String[]{getBuildFileLocation()})); //$NON-NLS-1$
392
			
393
			setTasks();
394
			setTypes();
395
			
396
			if (isVersionCompatible("1.6")) { //$NON-NLS-1$
397
				getCurrentProject().setKeepGoingMode(keepGoing);
398
			}
399
			
400
			parseBuildFile(getCurrentProject());
401
			
402
			if (projectHelp) {
403
				printHelp(getCurrentProject());
404
				scriptExecuted= false;
405
				return;
406
			}
407
			
408
			if (extraArguments != null) {
409
				printArguments(getCurrentProject());
410
			}
411
			
412
			System.setSecurityManager(new AntSecurityManager(originalSM, Thread.currentThread()));
413
			
414
			if (targets == null) {
415
                targets= new Vector(1);
416
            }
417
            if (targets.isEmpty() && getCurrentProject().getDefaultTarget() != null) {
418
                targets.add(getCurrentProject().getDefaultTarget());
419
            }
420
			if (!isVersionCompatible("1.6.3")) {  //$NON-NLS-1$
421
	            getCurrentProject().addReference("eclipse.ant.targetVector", targets); //$NON-NLS-1$
422
			}
423
			getCurrentProject().executeTargets(targets);
424
		} catch (AntSecurityException e) {
425
			//expected
426
		} catch (Throwable e) {
427
			error = e;
428
		} finally {
429
			System.setErr(originalErr);
430
			System.setOut(originalOut);
431
			System.setIn(originalIn);
432
			if (System.getSecurityManager() instanceof AntSecurityManager) {
433
				System.setSecurityManager(originalSM);
434
			}
435
			
436
			if (!projectHelp) {				
437
				fireBuildFinished(getCurrentProject(), error);
438
			}
439
						
440
			//close any user specified build log
441
			if (err != originalErr) {
442
				err.close();
443
			}
444
			if (out != originalOut) {
445
				out.close();
446
			}
447
		}
448
	}
449
	
450
	private void setTasks() {
451
		if (eclipseSpecifiedTasks != null) {
452
			Iterator itr= eclipseSpecifiedTasks.keySet().iterator();
453
			String taskName;
454
			String taskClassName;
455
			while (itr.hasNext()) {
456
				taskName= (String) itr.next();
457
				taskClassName= (String) eclipseSpecifiedTasks.get(taskName);
458
				
459
				if (isVersionCompatible("1.6")) { //$NON-NLS-1$
460
					AntTypeDefinition def= new AntTypeDefinition();
461
					def.setName(taskName);
462
		            def.setClassName(taskClassName);
463
		            def.setClassLoader(this.getClass().getClassLoader());
464
		            def.setAdaptToClass(Task.class);
465
		            def.setAdapterClass(TaskAdapter.class);
466
		            ComponentHelper.getComponentHelper(getCurrentProject()).addDataTypeDefinition(def);
467
				} else {
468
					try {
469
						Class taskClass = Class.forName(taskClassName);
470
						getCurrentProject().addTaskDefinition(taskName, taskClass);
471
					} catch (ClassNotFoundException e) {
472
						String message= MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.161"), new String[]{taskClassName, taskName}); //$NON-NLS-1$
473
						getCurrentProject().log(message, Project.MSG_WARN);
474
					}	
475
				}
476
			}
477
		}
478
	}
479
480
	private void setTypes() {
481
		if (eclipseSpecifiedTypes != null) {
482
			Iterator itr= eclipseSpecifiedTypes.keySet().iterator();
483
			String typeName;
484
			String typeClassName;
485
			while (itr.hasNext()) {
486
				typeName = (String) itr.next();
487
				typeClassName= (String) eclipseSpecifiedTypes.get(typeName);
488
				if (isVersionCompatible("1.6")) { //$NON-NLS-1$
489
					AntTypeDefinition def = new AntTypeDefinition();
490
	                def.setName(typeName);
491
	                def.setClassName(typeClassName);
492
	                def.setClassLoader(this.getClass().getClassLoader());
493
	                ComponentHelper.getComponentHelper(getCurrentProject()).addDataTypeDefinition(def);
494
				} else {
495
					try {
496
						Class typeClass = Class.forName(typeClassName);
497
						getCurrentProject().addDataTypeDefinition(typeName, typeClass);
498
					} catch (ClassNotFoundException e) {
499
						String message= MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.162"), new String[]{typeClassName, typeName}); //$NON-NLS-1$
500
						getCurrentProject().log(message, Project.MSG_WARN);
501
					}	
502
				}
503
			}
504
		}
505
	}
506
507
	private void remapSystemIn() {
508
		if (!isVersionCompatible("1.6")) { //$NON-NLS-1$
509
			return;
510
		}
511
		DemuxInputStreamSetter setter= new DemuxInputStreamSetter();
512
		setter.remapSystemIn(getCurrentProject());
513
	}
514
	
515
	/**
516
	 * Creates and returns the default build logger for logging build events to the ant log.
517
	 * 
518
	 * @return the default build logger for logging build events to the ant log
519
	 * 			can return <code>null</code> if no logging is to occur
520
	 */
521
	private BuildLogger createLogger() {
522
		if (loggerClassname == null) {
523
			buildLogger= new DefaultLogger();
524
		} else if (!"".equals(loggerClassname)) { //$NON-NLS-1$
525
			try {
526
				buildLogger = (BuildLogger) (Class.forName(loggerClassname).newInstance());
527
			} catch (ClassCastException e) {
528
				String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.{0}_which_was_specified_to_perform_logging_is_not_an_instance_of_org.apache.tools.ant.BuildLogger._2"), new String[]{loggerClassname}); //$NON-NLS-1$
529
				logMessage(null, message, Project.MSG_ERR);
530
				throw new BuildException(message, e);
531
			} catch (Exception e) {
532
				String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unable_to_instantiate_logger__{0}_6"), new String[]{loggerClassname}); //$NON-NLS-1$
533
				logMessage(null, message, Project.MSG_ERR);
534
				throw new BuildException(message, e);
535
			}
536
		} 
537
		
538
		if (buildLogger != null) {
539
			buildLogger.setMessageOutputLevel(messageOutputLevel);
540
			buildLogger.setOutputPrintStream(out);
541
			buildLogger.setErrorPrintStream(err);
542
			buildLogger.setEmacsMode(emacsMode);
543
            if (buildLogger instanceof RemoteAntBuildLogger) {
544
                ((RemoteAntBuildLogger) buildLogger).configure(userProperties);
545
            }
546
		}
547
548
		return buildLogger;
549
    }
550
    
551
    /**
552
     * Project.fireBuildStarted is protected in Ant earlier than 1.5.*.
553
     * Provides backwards compatibility with old Ant installs.
554
     */
555
    private void fireBuildStarted(Project project) {
556
        if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
557
            BuildEvent event = new BuildEvent(project);
558
            for (Iterator iterator = project.getBuildListeners().iterator(); iterator.hasNext();) {
559
                BuildListener listener = (BuildListener) iterator.next();
560
                listener.buildStarted(event);
561
            }
562
        } else {
563
            project.fireBuildStarted();
564
        }
565
    }
566
567
	private void fireBuildFinished(Project project, Throwable error) {
568
		if (error == null && scriptExecuted) {
569
			logMessage(project, RemoteAntMessages.getString("InternalAntRunner.BUILD_SUCCESSFUL_1"), messageOutputLevel); //$NON-NLS-1$
570
		}
571
        if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
572
            BuildEvent event = new BuildEvent(project);
573
            event.setException(error);
574
            Iterator iter = project.getBuildListeners().iterator();
575
            while (iter.hasNext()) {
576
                BuildListener listener = (BuildListener) iter.next();
577
                listener.buildFinished(event);
578
            }   
579
        } else {
580
            project.fireBuildFinished(error);
581
        }
582
	}
583
584
	private void logMessage(Project project, String message, int priority) {
585
		if (project != null) {
586
			project.log(message, priority);	
587
		} else {
588
			if (buildListeners != null) {
589
				project = new Project();
590
				BuildEvent event = new BuildEvent(project);
591
				event.setMessage(message, priority);
592
				//notify the build listeners that are not registered as
593
				//no project existed
594
				for (Iterator iterator = buildListeners.iterator(); iterator.hasNext();) {
595
					try {
596
						BuildListener listener = (BuildListener) iterator.next();
597
						listener.messageLogged(event);
598
					} catch (ClassCastException e) {
599
						//ignore we could be trying to log that a build listener is the
600
						//wrong type of class
601
					}
602
				}
603
			}
604
		}
605
	}
606
607
	/**
608
	 * Sets the buildFileLocation.
609
	 * 
610
	 * @param buildFileLocation the file system location of the build file
611
	 */
612
	private void setBuildFileLocation(String buildFileLocation) {
613
		this.buildFileLocation = buildFileLocation;
614
		if (getCurrentProject() != null) {
615
			getCurrentProject().setUserProperty("ant.file", buildFileLocation); //$NON-NLS-1$
616
		}
617
	}
618
619
	private String getBuildFileLocation() {
620
		if (buildFileLocation == null) {
621
			buildFileLocation = new File("build.xml").getAbsolutePath(); //$NON-NLS-1$
622
		}
623
		return buildFileLocation;
624
	}
625
626
	/**
627
	 * Sets the message output level. Use -1 for none.
628
	 * @param level The message output level
629
	 */
630
	private void setMessageOutputLevel(int level) {
631
		messageOutputLevel = level;
632
		if (buildLogger != null) {
633
			buildLogger.setMessageOutputLevel(level);
634
		}
635
	}
636
	
637
	/*
638
	 * Returns a String representation of the Ant version number as specified
639
	 * in the version.txt file.
640
	 */
641
	private String getAntVersionNumber() throws BuildException {
642
		if (antVersionNumber == null) {
643
			try {
644
				Properties props = new Properties();
645
				InputStream in = Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt"); //$NON-NLS-1$
646
				props.load(in);
647
				in.close();
648
				String versionNumber= props.getProperty("VERSION");  //$NON-NLS-1$
649
				antVersionNumber= versionNumber;
650
			} catch (IOException ioe) {
651
				throw new BuildException(MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_the_version_information._{0}_9"), new String[]{ioe.getMessage()})); //$NON-NLS-1$
652
			} catch (NullPointerException npe) {
653
				throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_the_version_information._10")); //$NON-NLS-1$
654
			}
655
		}
656
		return antVersionNumber;
657
	}
658
	
659
	/*
660
	 * Returns whether the given version is compatible with the
661
	 * current Ant version. A version is compatible if it is less
662
	 * than or equal to the current version. 
663
	 */
664
	private boolean isVersionCompatible(String comparison) {
665
		String version= getAntVersionNumber();
666
		return version.compareTo(comparison) >= 0;
667
	}
668
	
669
	private boolean preprocessCommandLine(List commands) {
670
		
671
		String arg = getArgument(commands, "-listener"); //$NON-NLS-1$
672
		while (arg != null) {
673
			if (arg.length() == 0) {
674
				throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.You_must_specify_a_classname_when_using_the_-listener_argument_1")); //$NON-NLS-1$
675
			} 
676
			if (buildListeners == null) {
677
				buildListeners= new ArrayList(1);
678
			}
679
			buildListeners.add(arg);
680
			arg = getArgument(commands, "-listener"); //$NON-NLS-1$
681
		}
682
683
		arg = getArgument(commands, "-logger"); //$NON-NLS-1$
684
		if (arg != null) {
685
			//allow empty string to mean no logger
686
			loggerClassname = arg;
687
		}
688
		arg = getArgument(commands, "-logger"); //$NON-NLS-1$
689
		if (arg != null) {
690
			throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.Only_one_logger_class_may_be_specified_1")); //$NON-NLS-1$
691
		}
692
		
693
		arg = getArgument(commands, "-inputhandler"); //$NON-NLS-1$
694
		if (arg != null) {
695
			if (arg.length() == 0) {
696
				throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.You_must_specify_a_classname_when_using_the_-inputhandler_argument_1")); //$NON-NLS-1$
697
			} 
698
			inputHandlerClassname = arg;
699
		}
700
		arg = getArgument(commands, "-inputhandler"); //$NON-NLS-1$
701
		if (arg != null) {
702
			throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.Only_one_input_handler_class_may_be_specified._2")); //$NON-NLS-1$
703
		}
704
		return true;
705
	}
706
	
707
	/*
708
	 * Looks for interesting command line arguments. 
709
	 * Returns whether it is OK to run the script.
710
	 */
711
	private boolean processCommandLine(List commands) {
712
		
713
		if (commands.remove("-help") || commands.remove("-h")) { //$NON-NLS-1$ //$NON-NLS-2$
714
			printUsage();
715
			return false;
716
		}
717
		
718
		if (commands.remove("-version")) { //$NON-NLS-1$
719
			printVersion();
720
			return false;
721
		}
722
		
723
		if (commands.remove("-verbose") || commands.remove("-v")) { //$NON-NLS-1$ //$NON-NLS-2$
724
			printVersion();
725
			setMessageOutputLevel(Project.MSG_VERBOSE);
726
		}
727
		
728
		if (commands.remove("-debug") || commands.remove("-d")) { //$NON-NLS-1$ //$NON-NLS-2$
729
			printVersion();
730
			setMessageOutputLevel(Project.MSG_DEBUG);
731
		}
732
		
733
		if (commands.remove("-quiet") || commands.remove("-q")) { //$NON-NLS-1$ //$NON-NLS-2$
734
			setMessageOutputLevel(Project.MSG_WARN);
735
		}
736
737
		if (commands.remove("-emacs") || commands.remove("-e")) { //$NON-NLS-1$ //$NON-NLS-2$
738
			emacsMode = true;
739
			if (buildLogger != null) {
740
				buildLogger.setEmacsMode(true);
741
			}
742
		}
743
		
744
		if (commands.remove("-diagnostics")) { //$NON-NLS-1$
745
			if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
746
				throw new BuildException(RemoteAntMessages.getString("InternalAntRunner.The_diagnositics_options_is_an_Ant_1.5.*_feature._Please_update_your_Ant_classpath_to_include_an_Ant_version_greater_than_this._4")); //$NON-NLS-1$
747
			}
748
			try {
749
				Diagnostics.doReport(System.out);
750
			} catch (NullPointerException e) {
751
				logMessage(getCurrentProject(), RemoteAntMessages.getString("InternalAntRunner.ANT_HOME_must_be_set_to_use_Ant_diagnostics_2"), Project.MSG_ERR); //$NON-NLS-1$
752
			}
753
			return false;
754
		}
755
		
756
		String arg = getArgument(commands, "-logfile"); //$NON-NLS-1$
757
		if (arg == null) {
758
			arg = getArgument(commands, "-l"); //$NON-NLS-1$
759
		}
760
		if (arg != null) {
761
			if (arg.length() == 0) {
762
				String message= RemoteAntMessages.getString("InternalAntRunner.You_must_specify_a_log_file_when_using_the_-log_argument_3"); //$NON-NLS-1$
763
				logMessage(currentProject, message, Project.MSG_ERR); 
764
				throw new BuildException(message);
765
			} 
766
			try {
767
				createLogFile(arg);
768
			} catch (IOException e) {
769
				// just log message and ignore exception
770
				logMessage(getCurrentProject(), MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_write_to_the_specified_log_file__{0}._Make_sure_the_path_exists_and_you_have_write_permissions._2"), new String[]{arg}), Project.MSG_ERR); //$NON-NLS-1$
771
				return false;
772
			}
773
		
774
		}
775
		
776
		arg = getArgument(commands, "-buildfile"); //$NON-NLS-1$
777
		if (arg == null) {
778
			arg = getArgument(commands, "-file"); //$NON-NLS-1$
779
			if (arg == null) {
780
				arg = getArgument(commands, "-f"); //$NON-NLS-1$
781
			}
782
		}
783
		
784
		if (arg != null) {
785
			if (arg.length() == 0) {
786
				String message= RemoteAntMessages.getString("InternalAntRunner.You_must_specify_a_buildfile_when_using_the_-buildfile_argument_4"); //$NON-NLS-1$
787
				logMessage(currentProject, message, Project.MSG_ERR); 
788
				throw new BuildException(message);
789
			} 
790
			setBuildFileLocation(arg);
791
		}
792
		
793
		if (isVersionCompatible("1.6")) { //$NON-NLS-1$
794
			if (commands.remove("-k") || commands.remove("-keep-going")) { //$NON-NLS-1$ //$NON-NLS-2$
795
				keepGoing= true;
796
			}
797
			if (commands.remove("-noinput")) { //$NON-NLS-1$
798
				allowInput= false;
799
			}
800
			arg= getArgument(commands, "-lib"); //$NON-NLS-1$
801
			if (arg != null) {
802
				logMessage(currentProject, RemoteAntMessages.getString("InternalAntRunner.157"), Project.MSG_ERR); //$NON-NLS-1$
803
				return false;
804
			}
805
		}
806
		
807
		arg= getArgument(commands, "-find"); //$NON-NLS-1$
808
		if (arg == null) {
809
			arg= getArgument(commands, "-s"); //$NON-NLS-1$
810
		}
811
		if (arg != null) {
812
			logMessage(currentProject, RemoteAntMessages.getString("InternalAntRunner.-find_not_supported"), Project.MSG_ERR); //$NON-NLS-1$
813
			return false;
814
		}
815
		
816
		processTasksAndTypes(commands);
817
		
818
		if (!commands.isEmpty()) {
819
			processUnrecognizedCommands(commands);
820
		}
821
822
		if (!commands.isEmpty()) {
823
			processTargets(commands);
824
		}
825
		
826
		return true;
827
	}
828
	
829
	private void processTasksAndTypes(List commands) {
830
		String arg = getArgument(commands, "-eclipseTask"); //$NON-NLS-1$
831
		while (arg != null) {
832
			if (eclipseSpecifiedTasks == null) {
833
				eclipseSpecifiedTasks= new HashMap();
834
			}
835
			int index= arg.indexOf(',');
836
			if (index != -1) {
837
				String name= arg.substring(0, index);
838
				String className= arg.substring(index + 1);
839
				eclipseSpecifiedTasks.put(name, className);
840
			}
841
			arg = getArgument(commands, "-eclipseTask"); //$NON-NLS-1$
842
		}
843
		
844
		arg = getArgument(commands, "-eclipseType"); //$NON-NLS-1$
845
		while (arg != null) {
846
			if (eclipseSpecifiedTypes == null) {
847
				eclipseSpecifiedTypes= new HashMap();
848
			}
849
			int index= arg.indexOf(',');
850
			if (index != -1) {	
851
				String name= arg.substring(0, index);
852
				String className= arg.substring(index + 1);
853
				eclipseSpecifiedTypes.put(name, className);
854
			}
855
			arg = getArgument(commands, "-eclipseType"); //$NON-NLS-1$
856
		}
857
	}
858
859
	/*
860
	 * Checks for unrecognized arguments on the command line.
861
	 * Since there is no syntactic way to distingush between
862
	 * ant -foo target1 target2
863
	 * ant -foo fooarg target
864
	 * we remove everything up to the last argument that
865
	 * begins with a '-'.  In the latter case, above, that
866
	 * means that there will be an extra target, 'fooarg',
867
	 * left lying around.
868
	 */
869
	private void processUnrecognizedCommands(List commands) {
870
		int p = -1;
871
872
		// find the last arg that begins with '-'
873
		for (int i = commands.size() - 1; i >= 0; i--) {
874
			if (((String) commands.get(0)).startsWith("-")) { //$NON-NLS-1$
875
				p = i;
876
				break;
877
			}
878
		}
879
		if (p < 0) { return; }
880
881
		// remove everything preceding that last '-arg'
882
		String s = ""; //$NON-NLS-1$
883
		for (int i = 0; i <= p; i++) {
884
			s += " " + ((String) commands.get(0)); //$NON-NLS-1$
885
			commands.remove(0);
886
		}
887
		
888
		// warn of ignored commands
889
		String message = MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Unknown_argument__{0}_2"), new Object[]{ s.substring(1) }); //$NON-NLS-1$
890
		logMessage(currentProject, message, Project.MSG_WARN); 
891
	}
892
	
893
894
	/*
895
	 * Checks for targets specified at the command line.
896
	 */
897
	private void processTargets(List commands) {
898
		if (targets == null) {
899
			targets = new Vector(commands.size());
900
		}
901
		for (Iterator iter = commands.iterator(); iter.hasNext();) {
902
			targets.add(iter.next());
903
		}
904
	}
905
906
	/*
907
	 * Creates the log file with the name specified by the user.
908
	 * If the fileName is not absolute, the file will be created in the
909
	 * working directory if specified or in the same directory as the location
910
	 * of the build file.
911
	 */
912
	private void createLogFile(String fileName) throws FileNotFoundException, IOException {
913
		File logFile = getFileRelativeToBaseDir(fileName);
914
		
915
		//this stream is closed in the finally block of run(list)
916
		out = new PrintStream(new FileOutputStream(logFile));
917
		err = out;
918
		logMessage(getCurrentProject(), MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Using_{0}_file_as_build_log._1"), new String[]{logFile.getCanonicalPath()}), Project.MSG_INFO); //$NON-NLS-1$
919
		if (buildLogger != null) {
920
			buildLogger.setErrorPrintStream(err);
921
			buildLogger.setOutputPrintStream(out);
922
		}
923
	}
924
925
	private File getFileRelativeToBaseDir(String fileName) {
926
		File parentFile= null;
927
		
928
		String base= getCurrentProject().getUserProperty("basedir"); //$NON-NLS-1$
929
		if (base != null) {
930
			parentFile= new File(base);
931
		} else {
932
			//relative to the build file location
933
			parentFile= new File(getBuildFileLocation()).getParentFile();
934
		}
935
		
936
		//remain backwards compatible for older Ant usage
937
		return FileUtils.newFileUtils().resolveFile(parentFile, fileName);
938
	}
939
940
	/*
941
	 * Processes cmd line properties and adds the user properties
942
	 * Any user properties that have been explicitly set are set as well.
943
	 * Ensures that -D properties take precedence.
944
	 */
945
	private boolean processProperties(List commands) {
946
        boolean exceptionToBeThrown= false;
947
		//MULTIPLE property files are allowed
948
		String arg= getArgument(commands, "-propertyfile"); //$NON-NLS-1$
949
		while (arg != null) {
950
			if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
951
				fEarlyErrorMessage= RemoteAntMessages.getString("InternalAntRunner.Specifying_property_files_is_a_Ant_1.5.*_feature._Please_update_your_Ant_classpath._6"); //$NON-NLS-1$
952
				break;
953
			}
954
			if (arg.length() == 0) {
955
                fEarlyErrorMessage= RemoteAntMessages.getString("InternalAntRunner.You_must_specify_a_property_filename_when_using_the_-propertyfile_argument_3"); //$NON-NLS-1$
956
                exceptionToBeThrown= true;
957
                break;
958
			} 
959
			
960
			propertyFiles.add(arg);
961
			arg= getArgument(commands, "-propertyfile"); //$NON-NLS-1$
962
		}
963
        
964
        if (propertyFiles != null && !propertyFiles.isEmpty()) {
965
            loadPropertyFiles();
966
        }
967
        
968
        if (commands != null) {
969
            processMinusDProperties(commands);
970
        }
971
        return exceptionToBeThrown;
972
	}
973
974
	private void processMinusDProperties(List commands) {
975
		String[] args = (String[]) commands.toArray(new String[commands.size()]);
976
		for (int i = 0; i < args.length; i++) {
977
			String arg = args[i];
978
			if (arg.startsWith("-D")) { //$NON-NLS-1$
979
				String name = arg.substring(2, arg.length());
980
				String value = null;
981
				int posEq = name.indexOf("="); //$NON-NLS-1$
982
				if (posEq == 0) {
983
					value= name.substring(1);
984
					name= ""; //$NON-NLS-1$
985
				} else if (posEq > 0 && posEq != name.length() - 1) {
986
					value = name.substring(posEq + 1).trim();
987
					name = name.substring(0, posEq);
988
				}
989
				
990
				if (value == null) {
991
					//the user has specified something like "-Debug"
992
					continue;
993
				}
994
				if (userProperties == null) {
995
					userProperties= new HashMap();
996
				}
997
				userProperties.put(name, value);
998
				commands.remove(args[i]);
999
			}
1000
		}
1001
	}
1002
	
1003
	private void setProperties(Project project) {
1004
		setBuiltInProperties(project);
1005
		if (userProperties != null) {
1006
			for (Iterator iterator = userProperties.entrySet().iterator(); iterator.hasNext();) {
1007
				Map.Entry entry = (Map.Entry) iterator.next();
1008
				project.setUserProperty((String) entry.getKey(), (String) entry.getValue());
1009
			}
1010
		} 
1011
	}
1012
1013
	private void setBuiltInProperties(Project project) {
1014
		project.setUserProperty("ant.file", getBuildFileLocation()); //$NON-NLS-1$
1015
		project.setUserProperty("ant.version", Main.getAntVersion()); //$NON-NLS-1$
1016
	}
1017
1018
	/*
1019
	 * Print the project description, if any
1020
	 */
1021
	private void printHelp(Project project) {
1022
		if (project.getDescription() != null) {
1023
			logMessage(project, project.getDescription(), Project.MSG_INFO);
1024
		}
1025
		printTargets(project);
1026
	}
1027
1028
	/*
1029
	 * Logs a message with the client indicating the version of <b>Ant</b> that this class
1030
	 * fronts.
1031
	 */
1032
	private void printVersion() {
1033
		logMessage(getCurrentProject(), Main.getAntVersion(), Project.MSG_INFO);
1034
	}
1035
1036
	/*
1037
	 * Logs a message with the client outlining the usage of <b>Ant</b>.
1038
	 */
1039
	private void printUsage() {
1040
		String lSep = System.getProperty("line.separator"); //$NON-NLS-1$
1041
		StringBuffer msg = new StringBuffer();
1042
		msg.append("ant ["); //$NON-NLS-1$
1043
		msg.append(RemoteAntMessages.getString("InternalAntRunner.options_13")); //$NON-NLS-1$
1044
		msg.append("] ["); //$NON-NLS-1$
1045
		msg.append(RemoteAntMessages.getString("InternalAntRunner.target_15")); //$NON-NLS-1$
1046
		msg.append(" ["); //$NON-NLS-1$
1047
		msg.append(RemoteAntMessages.getString("InternalAntRunner.target_15")); //$NON-NLS-1$
1048
		msg.append("2 ["); //$NON-NLS-1$
1049
		msg.append(RemoteAntMessages.getString("InternalAntRunner.target_15")); //$NON-NLS-1$
1050
		msg.append("3] ...]]"); //$NON-NLS-1$
1051
		msg.append(lSep);
1052
		msg.append(RemoteAntMessages.getString("InternalAntRunner.Options___21")); //$NON-NLS-1$
1053
		msg.append(lSep);
1054
		msg.append("\t-help, -h\t\t\t\t"); //$NON-NLS-1$
1055
		msg.append(RemoteAntMessages.getString("InternalAntRunner.print_this_message_23")); //$NON-NLS-1$
1056
		msg.append(lSep);
1057
		msg.append("\t-projecthelp, -p\t\t"); //$NON-NLS-1$
1058
		msg.append(RemoteAntMessages.getString("InternalAntRunner.print_project_help_information_25")); //$NON-NLS-1$
1059
		msg.append(lSep);
1060
		msg.append("\t-version\t\t\t\t"); //$NON-NLS-1$
1061
		msg.append(RemoteAntMessages.getString("InternalAntRunner.print_the_version_information_and_exit_27")); //$NON-NLS-1$
1062
		msg.append(lSep); 
1063
		msg.append("\t-diagnostics\t\t\t"); //$NON-NLS-1$
1064
		msg.append(RemoteAntMessages.getString("InternalAntRunner.12")); //$NON-NLS-1$
1065
		msg.append(lSep);
1066
		msg.append(RemoteAntMessages.getString("InternalAntRunner.13")); //$NON-NLS-1$
1067
		msg.append(lSep);
1068
		msg.append("\t-quiet, -q\t\t\t"); //$NON-NLS-1$
1069
		msg.append(RemoteAntMessages.getString("InternalAntRunner.be_extra_quiet_29")); //$NON-NLS-1$
1070
		msg.append(lSep);
1071
		msg.append("\t-verbose, -v\t\t\t"); //$NON-NLS-1$
1072
		msg.append(RemoteAntMessages.getString("InternalAntRunner.be_extra_verbose_31")); //$NON-NLS-1$
1073
		msg.append(lSep);
1074
		msg.append("\t-debug, -d\t\t\t"); //$NON-NLS-1$
1075
		msg.append(RemoteAntMessages.getString("InternalAntRunner.print_debugging_information_33")); //$NON-NLS-1$
1076
		msg.append(lSep);
1077
		msg.append("\t-emacs, -e\t\t\t"); //$NON-NLS-1$
1078
		msg.append(RemoteAntMessages.getString("InternalAntRunner.produce_logging_information_without_adornments_35")); //$NON-NLS-1$
1079
		msg.append(lSep);
1080
		msg.append("\t-logfile\t<file>\t\t"); //$NON-NLS-1$
1081
		msg.append(RemoteAntMessages.getString("InternalAntRunner.use_given_file_for_log_37")); //$NON-NLS-1$
1082
		msg.append(lSep);
1083
		msg.append("\t\t-l\t<file>"); //$NON-NLS-1$
1084
		msg.append(RemoteAntMessages.getString("InternalAntRunner.1")); //$NON-NLS-1$
1085
		msg.append(lSep);  
1086
		msg.append("\t-logger <classname>\t\t"); //$NON-NLS-1$
1087
		msg.append(RemoteAntMessages.getString("InternalAntRunner.the_class_which_is_to_perform_logging_39")); //$NON-NLS-1$
1088
		msg.append(lSep);  
1089
		msg.append("\t-listener <classname>\t"); //$NON-NLS-1$
1090
		msg.append(RemoteAntMessages.getString("InternalAntRunner.add_an_instance_of_class_as_a_project_listener_41")); //$NON-NLS-1$
1091
		msg.append(lSep);
1092
		msg.append("\t-noinput\t"); //$NON-NLS-1$
1093
		msg.append(RemoteAntMessages.getString("InternalAntRunner.158")); //$NON-NLS-1$
1094
		msg.append(lSep); 
1095
		msg.append("\t-buildfile\t<file>\t"); //$NON-NLS-1$
1096
		msg.append(RemoteAntMessages.getString("InternalAntRunner.use_given_buildfile_43")); //$NON-NLS-1$
1097
		msg.append(lSep); 
1098
		msg.append("\t\t-file\t<file>"); //$NON-NLS-1$
1099
		msg.append(RemoteAntMessages.getString("InternalAntRunner.1")); //$NON-NLS-1$
1100
		msg.append(lSep);
1101
		msg.append("\t\t-f\t\t<file>"); //$NON-NLS-1$
1102
		msg.append(RemoteAntMessages.getString("InternalAntRunner.1")); //$NON-NLS-1$
1103
		msg.append(lSep);
1104
		msg.append("\t-D<property>=<value>\t"); //$NON-NLS-1$
1105
		msg.append(RemoteAntMessages.getString("InternalAntRunner.use_value_for_given_property_45")); //$NON-NLS-1$
1106
		msg.append(lSep);
1107
		msg.append("\t-keep-going, -k"); //$NON-NLS-1$
1108
		msg.append(RemoteAntMessages.getString("InternalAntRunner.159")); //$NON-NLS-1$
1109
		msg.append(lSep);
1110
		msg.append(RemoteAntMessages.getString("InternalAntRunner.160")); //$NON-NLS-1$
1111
		msg.append(lSep); 
1112
		msg.append("\t-propertyfile <name>\t"); //$NON-NLS-1$
1113
		msg.append(RemoteAntMessages.getString("InternalAntRunner.19")); //$NON-NLS-1$
1114
		msg.append(lSep);
1115
		msg.append(RemoteAntMessages.getString("InternalAntRunner.20")); //$NON-NLS-1$
1116
		msg.append(lSep);
1117
		msg.append("\t-inputhandler <class>\t"); //$NON-NLS-1$
1118
		msg.append(RemoteAntMessages.getString("InternalAntRunner.22")); //$NON-NLS-1$
1119
		msg.append(lSep);
1120
1121
		logMessage(getCurrentProject(), msg.toString(), Project.MSG_INFO);
1122
	}
1123
1124
	/*
1125
	 * From a command line list, return the argument for the given parameter.
1126
	 * The parameter and its argument are removed from the list.
1127
	 * 
1128
	 * @return <code>null</code> if the parameter is not found 
1129
	 * 			or an empty String if no arguments are found
1130
	 */
1131
	private String getArgument(List commands, String param) {
1132
		if (commands == null) {
1133
			return null;
1134
		}
1135
		int index = commands.indexOf(param);
1136
		if (index == -1) {
1137
			return null;
1138
		}
1139
		commands.remove(index);
1140
		if (index == commands.size()) {// if this is the last command
1141
			return ""; //$NON-NLS-1$
1142
		}
1143
		
1144
		String command = (String) commands.get(index);
1145
		if (command.startsWith("-")) { //new parameter //$NON-NLS-1$
1146
			return ""; //$NON-NLS-1$
1147
		}
1148
		
1149
		commands.remove(index);
1150
		return command;
1151
	}
1152
1153
	/*
1154
	 * Helper method to ensure an array is converted into an ArrayList.
1155
	 */
1156
	private static ArrayList getArrayList(String[] args) {
1157
		if (args == null) {
1158
			return null;
1159
		}
1160
		// We could be using Arrays.asList() here, but it does not specify
1161
		// what kind of list it will return. We need a list that
1162
		// implements the method List.remove(Object) and ArrayList does.
1163
		ArrayList result = new ArrayList(args.length);
1164
		for (int i = 0; i < args.length; i++) {
1165
			result.add(args[i]);
1166
		}
1167
		return result;
1168
	}
1169
1170
	private Project getCurrentProject() {
1171
		return currentProject;
1172
	}
1173
1174
	private void setCurrentProject(Project currentProject) {
1175
		this.currentProject = currentProject;
1176
	}
1177
	
1178
	/**
1179
	 * Load all properties from the files 
1180
	 * specified by -propertyfile.
1181
	 */
1182
	private void loadPropertyFiles() {
1183
		Iterator itr= propertyFiles.iterator();
1184
        while (itr.hasNext()) {
1185
            String filename= (String) itr.next();
1186
           	File file= getFileRelativeToBaseDir(filename);
1187
            Properties props = new Properties();
1188
            FileInputStream fis = null;
1189
            try {
1190
                fis = new FileInputStream(file);
1191
                props.load(fis);
1192
            } catch (IOException e) {
1193
            	fEarlyErrorMessage= MessageFormat.format(RemoteAntMessages.getString("InternalAntRunner.Could_not_load_property_file_{0}__{1}_4"), new String[]{filename, e.getMessage()}); //$NON-NLS-1$
1194
            } finally {
1195
                if (fis != null) {
1196
                    try {
1197
                        fis.close();
1198
                    } catch (IOException e){
1199
                    }
1200
                }
1201
            }
1202
1203
            if (userProperties == null) {
1204
            	userProperties= new HashMap();
1205
            }
1206
            Enumeration propertyNames = props.propertyNames();
1207
            while (propertyNames.hasMoreElements()) {
1208
                String name = (String) propertyNames.nextElement();
1209
                //most specific to global
1210
                //do not overwrite specific with a global property
1211
                if (userProperties.get(name) == null) {
1212
            		userProperties.put(name, props.getProperty(name));
1213
                }
1214
            }
1215
        }
1216
	}
1217
	
1218
	/*
1219
     * Creates the InputHandler and adds it to the project.
1220
     *
1221
     * @exception BuildException if a specified InputHandler
1222
     *                           implementation could not be loaded.
1223
     */
1224
    private void addInputHandler(Project project) {
1225
    	if (!isVersionCompatible("1.5")) { //$NON-NLS-1$
1226
			return;
1227
		}
1228
		InputHandlerSetter setter= new InputHandlerSetter();
1229
		setter.setInputHandler(project, inputHandlerClassname);
1230
    }
1231
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/RemoteAntMessages.java (-33 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport;
12
13
14
import java.util.MissingResourceException;
15
import java.util.ResourceBundle;
16
17
public class RemoteAntMessages {
18
19
	private static final String BUNDLE_NAME = "org.eclipse.ant.internal.ui.antsupport.RemoteAntMessages"; //$NON-NLS-1$
20
21
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
22
23
	private RemoteAntMessages() {
24
	}
25
26
	public static String getString(String key) {
27
		try {
28
			return RESOURCE_BUNDLE.getString(key);
29
		} catch (MissingResourceException e) {
30
			return '!' + key + '!';
31
		}
32
	}
33
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/RemoteAntMessages.properties (-83 lines)
Removed Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2008 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
InternalAntRunner.Build_file__{0}_1=Buildfile: {0}
13
InternalAntRunner.Arguments__{0}_2=Arguments: {0}
14
InternalAntRunner.Default_target__3=Default target:
15
InternalAntRunner.Main_targets__4=Main targets:
16
InternalAntRunner.Subtargets__5=Subtargets:
17
InternalAntRunner.Unable_to_instantiate_logger__{0}_6=Unable to instantiate logger: {0}
18
InternalAntRunner.Could_not_load_the_version_information._{0}_9=Could not load the version information. {0}
19
InternalAntRunner.Could_not_load_the_version_information._10=Could not load the version information.
20
InternalAntRunner.options_13=options
21
InternalAntRunner.target_15=target
22
InternalAntRunner.Options___21=Options: 
23
InternalAntRunner.print_this_message_23=print this message
24
InternalAntRunner.print_project_help_information_25=print project help information
25
InternalAntRunner.print_the_version_information_and_exit_27=print the version information and exit
26
InternalAntRunner.be_extra_quiet_29=be extra quiet
27
InternalAntRunner.be_extra_verbose_31=be extra verbose
28
InternalAntRunner.print_debugging_information_33=print debugging information
29
InternalAntRunner.produce_logging_information_without_adornments_35=produce logging information without adornments
30
InternalAntRunner.use_given_file_for_log_37=use given file for log
31
InternalAntRunner.the_class_which_is_to_perform_logging_39=the class which is to perform logging
32
InternalAntRunner.add_an_instance_of_class_as_a_project_listener_41=add an instance of class as a project listener
33
InternalAntRunner.use_given_buildfile_43=use given buildfile
34
InternalAntRunner.use_value_for_given_property_45=use value for given property
35
InternalAntRunner.Using_{0}_file_as_build_log._1=Using {0} file as build log.
36
InternalAntRunner.Could_not_write_to_the_specified_log_file__{0}._Make_sure_the_path_exists_and_you_have_write_permissions._2=Cannot write on the specified log file: {0}. Make sure the path exists and you have write permissions.
37
InternalAntRunner.BUILD_SUCCESSFUL_1=BUILD SUCCESSFUL
38
InternalAntRunner.Unknown_argument__{0}_2=Unknown argument: {0}
39
InternalAntRunner.Buildfile__{0}_does_not_exist_!_1=Buildfile: {0} does not exist
40
InternalAntRunner.{0}_which_was_specified_to_be_a_build_listener_is_not_an_instance_of_org.apache.tools.ant.BuildListener._1={0} which was specified to be a build listener is not an instance of org.apache.tools.ant.BuildListener.
41
InternalAntRunner.{0}_which_was_specified_to_perform_logging_is_not_an_instance_of_org.apache.tools.ant.BuildLogger._2={0} which was specified to perform logging is not an instance of org.apache.tools.ant.BuildLogger.
42
InternalAntRunner.You_must_specify_a_classname_when_using_the_-listener_argument_1=You must specify a classname when using the -listener argument
43
InternalAntRunner.You_must_specify_a_log_file_when_using_the_-log_argument_3=You must specify a log file when using the -log argument
44
InternalAntRunner.You_must_specify_a_buildfile_when_using_the_-buildfile_argument_4=You must specify a buildfile when using the -buildfile argument
45
InternalAntRunner.12=print information that might be helpful to
46
InternalAntRunner.13=\t\t\t\t\t\t\tdiagnose or report problems.
47
InternalAntRunner.19=load all properties from file with -D
48
InternalAntRunner.20=\t\t\t\t\t\t\tproperties taking precedence
49
InternalAntRunner.22=the class which will handle input requests
50
InternalAntRunner.1=\t\t\t\t\'
51
InternalAntRunner.Only_one_logger_class_may_be_specified_1=Only one logger class may be specified
52
InternalAntRunner.You_must_specify_a_classname_when_using_the_-inputhandler_argument_1=You must specify a classname when using the -inputhandler argument
53
InternalAntRunner.Only_one_input_handler_class_may_be_specified._2=Only one input handler class may be specified.
54
InternalAntRunner.You_must_specify_a_property_filename_when_using_the_-propertyfile_argument_3=You must specify a property filename when using the -propertyfile argument
55
InternalAntRunner.Could_not_load_property_file_{0}__{1}_4=Could not load property file {0}: {1}
56
InternalAntRunner.The_specified_input_handler_class_{0}_does_not_implement_the_org.apache.tools.ant.input.InputHandler_interface_5=The specified input handler class {0} does not implement the org.apache.tools.ant.input.InputHandler interface
57
InternalAntRunner.Unable_to_instantiate_specified_input_handler_class_{0}___{1}_6=Unable to instantiate specified input handler class {0} : {1}
58
InternalAntRunner.The_diagnositics_options_is_an_Ant_1.5.*_feature._Please_update_your_Ant_classpath_to_include_an_Ant_version_greater_than_this._4=The diagnostics options is an Ant 1.5.* feature. Please update your Ant classpath to include an Ant version greater than this.
59
InternalAntRunner.Specifying_property_files_is_a_Ant_1.5.*_feature._Please_update_your_Ant_classpath._6=Specifying property files is a Ant 1.5.* feature. Please update your Ant classpath to include an Ant version greater than this.
60
InternalAntRunner.ANT_HOME_must_be_set_to_use_Ant_diagnostics_2=ANT_HOME must be set to use Ant diagnostics
61
InternalAntRunner.Buildfile__{0}_is_not_a_file_1=Buildfile: {0} is not a file
62
InternalAntRunner.-find_not_supported=-find not supported.\nCan be emulated using Run As > Ant Build located\nin the Run > External Tools menu
63
InternalAntRunner.157=-lib not supported\nConfigure the Ant runtime classpath using either the\nglobal Ant runtime classpath or the Ant runtime classpath\n for this particular build
64
InternalAntRunner.158=\t\t\tdo not allow interactive input
65
InternalAntRunner.159=\t\texecute all targets that do not depend
66
InternalAntRunner.160=\t\t\t\t\t\ton failed target(s)
67
InternalAntRunner.161=Class {0} not found for task {1}
68
InternalAntRunner.162=Class {0} not found for type {1}
69
70
RemoteAntBuildLogger.1=BUILD FAILED
71
RemoteAntBuildLogger.Total_time=Total time: 
72
RemoteAntBuildLogger._minutes_2=\ minutes
73
RemoteAntBuildLogger._minute_3=\ minute
74
RemoteAntBuildLogger._seconds_4=\ seconds
75
RemoteAntBuildLogger._second_5=\ second
76
RemoteAntBuildLogger._milliseconds_6=\ milliseconds
77
78
SWTInputHandler.0=Unable to respond to input request as a result of the user specified -noinput command
79
SWTInputHandler.1=Ant Input Request
80
SWTInputHandler.2=Unable to respond to <input> request
81
SWTInputHandler.3=Input does not match validargs attribute
82
SWTInputHandler.4=OK
83
SWTInputHandler.5=Cancel
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/inputhandler/FailInputHandler.java (-29 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.ant.internal.ui.antsupport.inputhandler;
13
14
import java.io.IOException;
15
import java.io.InputStream;
16
17
import org.apache.tools.ant.input.DefaultInputHandler;
18
19
public class FailInputHandler extends DefaultInputHandler {
20
	
21
	protected InputStream getInputStream() {
22
		//ensure any attempts to read input fail
23
		return new InputStream(){
24
			public int read() throws IOException {
25
				throw new IOException();
26
			}
27
		};
28
	}
29
}
(-)Remote (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport.inputhandler;
12
13
14
import java.util.MissingResourceException;
15
import java.util.ResourceBundle;
16
17
public class RemoteAntMessages {
18
19
	private static final String BUNDLE_NAME = "org.eclipse.ant.internal.ui.antsupport.inputhandler.RemoteAntMessages"; //$NON-NLS-1$
20
21
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
22
23
	private RemoteAntMessages() {
24
	}
25
26
	public static String getString(String key) {
27
		try {
28
			return RESOURCE_BUNDLE.getString(key);
29
		} catch (MissingResourceException e) {
30
			return '!' + key + '!';
31
		}
32
	}
33
}
(-)Remote (+17 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
SWTInputHandler.0=Unable to respond to input request as a result of the user specified -noinput command
13
SWTInputHandler.1=Ant Input Request
14
SWTInputHandler.2=Unable to respond to <input> request
15
SWTInputHandler.3=Input does not match validargs attribute
16
SWTInputHandler.4=OK
17
SWTInputHandler.5=Cancel
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/inputhandler/SWTInputHandler.java (-1 lines)
Lines 18-24 Link Here
18
import org.apache.tools.ant.input.DefaultInputHandler;
18
import org.apache.tools.ant.input.DefaultInputHandler;
19
import org.apache.tools.ant.input.InputRequest;
19
import org.apache.tools.ant.input.InputRequest;
20
import org.apache.tools.ant.input.MultipleChoiceInputRequest;
20
import org.apache.tools.ant.input.MultipleChoiceInputRequest;
21
import org.eclipse.ant.internal.ui.antsupport.RemoteAntMessages;
22
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.events.ModifyEvent;
22
import org.eclipse.swt.events.ModifyEvent;
24
import org.eclipse.swt.events.ModifyListener;
23
import org.eclipse.swt.events.ModifyListener;
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/logger/MessageIds.java (-21 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport.logger;
12
13
14
public class MessageIds {
15
16
	public final static String PROCESS_ID=   "processID"; //$NON-NLS-1$
17
	public final static String BUILD_CANCELLED= "cancelled"; //$NON-NLS-1$
18
    //constants need to start greater than the Project.MSG_* constants
19
	public final static String TASK= "6"; //$NON-NLS-1$
20
	public final static String TARGET= "7"; //$NON-NLS-1$
21
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/logger/RemoteAntBuildLogger.java (-396 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport.logger;
12
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.PrintStream;
17
import java.io.PrintWriter;
18
import java.io.StringReader;
19
import java.net.Socket;
20
import java.util.ArrayList;
21
import java.util.Iterator;
22
import java.util.List;
23
import java.util.Map;
24
25
import org.apache.tools.ant.BuildEvent;
26
import org.apache.tools.ant.BuildException;
27
import org.apache.tools.ant.DefaultLogger;
28
import org.apache.tools.ant.Location;
29
import org.apache.tools.ant.Project;
30
import org.apache.tools.ant.Target;
31
import org.apache.tools.ant.util.StringUtils;
32
import org.eclipse.ant.internal.ui.antsupport.AntSecurityException;
33
import org.eclipse.ant.internal.ui.antsupport.InternalAntRunner;
34
import org.eclipse.ant.internal.ui.antsupport.RemoteAntMessages;
35
import org.eclipse.ant.internal.ui.antsupport.logger.util.AntDebugState;
36
37
/**
38
 * Parts adapted from org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
39
 * A build logger that reports via a socket connection.
40
 * See MessageIds for more information about the protocol.
41
 */
42
public class RemoteAntBuildLogger extends DefaultLogger {
43
44
    /** Time of the start of the build */
45
    private long fStartTime = System.currentTimeMillis();
46
47
    /**
48
     * The client socket.
49
     */
50
    private Socket fEventSocket;
51
    /**
52
     * Print writer for sending messages
53
     */
54
    private PrintWriter fWriter;
55
    /**
56
     * Host to connect to, default is the localhost
57
     */
58
    protected String fHost= ""; //$NON-NLS-1$
59
    /**
60
     * Port to connect to.
61
     */
62
    private int fEventPort= -1;
63
    
64
    private String fProcessId= null;
65
    
66
    /**
67
     * Is the debug mode enabled?
68
     */
69
    protected boolean fDebugMode= false;    
70
    
71
    protected boolean fSentProcessId= false;
72
    
73
    private List fEventQueue;
74
    
75
    private String fLastFileName= null;
76
    private String fLastTaskName= null;
77
    
78
    /* (non-Javadoc)
79
     * @see org.apache.tools.ant.DefaultLogger#printMessage(java.lang.String, java.io.PrintStream, int)
80
     */
81
    protected void printMessage(String message, PrintStream stream, int priority) {
82
        marshalMessage(priority, message);
83
    }
84
    
85
    /**
86
     * Connect to the remote Ant build listener.
87
     */
88
    protected void connect() {
89
        if (fDebugMode) {
90
            System.out.println("RemoteAntBuildLogger: trying to connect" + fHost + ":" + fEventPort); //$NON-NLS-1$ //$NON-NLS-2$
91
        }
92
        
93
        for (int i= 1; i < 5; i++) {
94
            try{
95
                fEventSocket= new Socket(fHost, fEventPort);
96
                fWriter= new PrintWriter(fEventSocket.getOutputStream(), true);
97
                return;
98
            } catch(IOException e){
99
            }
100
            try {
101
                Thread.sleep(500);
102
            } catch(InterruptedException e) {
103
            }
104
        }
105
        shutDown();
106
    }
107
108
    /**
109
     * Shutdown the connection to the remote build listener.
110
     */
111
    protected void shutDown() {
112
        if (fEventQueue != null) {
113
            fEventQueue.clear();
114
        }
115
        if (fWriter != null) {
116
            fWriter.close();
117
            fWriter= null;
118
        }
119
        
120
        try {
121
            if (fEventSocket != null) {
122
                fEventSocket.close();
123
                fEventSocket= null;
124
            }
125
        } catch(IOException e) {
126
        }
127
    }
128
129
    private void sendMessage(String msg) {
130
        if (fWriter == null) {
131
            return;
132
        }
133
        
134
        fWriter.println(msg);
135
    }
136
    
137
    /* (non-Javadoc)
138
     * @see org.apache.tools.ant.BuildListener#buildFinished(org.apache.tools.ant.BuildEvent)
139
     */
140
    public void buildFinished(BuildEvent event) {
141
        if (!fSentProcessId) {
142
            establishConnection();
143
        }
144
        handleException(event);
145
        printMessage( getTimeString(System.currentTimeMillis() - fStartTime), out, Project.MSG_INFO); 
146
        shutDown();
147
    }
148
    
149
    protected void handleException(BuildEvent event) {
150
        Throwable exception = event.getException();
151
        if (exception == null || exception instanceof AntSecurityException) {
152
            return;
153
        }
154
        
155
         StringBuffer message= new StringBuffer();
156
         message.append(StringUtils.LINE_SEP);
157
         message.append(RemoteAntMessages.getString("RemoteAntBuildLogger.1")); //$NON-NLS-1$
158
         message.append(StringUtils.LINE_SEP);
159
         if (Project.MSG_VERBOSE <= this.msgOutputLevel || !(exception instanceof BuildException)) {
160
             message.append(StringUtils.getStackTrace(exception));
161
         } else {
162
             if (exception instanceof BuildException) {
163
                 message.append(exception.toString()).append(StringUtils.LINE_SEP);
164
             } else {
165
                 message.append(exception.getMessage()).append(StringUtils.LINE_SEP);
166
             }
167
         }
168
        message.append(StringUtils.LINE_SEP);
169
        printMessage(message.toString(), out, Project.MSG_ERR); 
170
    }
171
    
172
    private String getTimeString(long milliseconds) {
173
        long seconds = milliseconds / 1000;
174
        long minutes = seconds / 60;
175
        seconds= seconds % 60;
176
177
        StringBuffer result= new StringBuffer(RemoteAntMessages.getString("RemoteAntBuildLogger.Total_time")); //$NON-NLS-1$
178
        if (minutes > 0) {
179
            result.append(minutes);
180
            if (minutes > 1) {
181
                result.append(RemoteAntMessages.getString("RemoteAntBuildLogger._minutes_2")); //$NON-NLS-1$
182
            } else {
183
                result.append(RemoteAntMessages.getString("RemoteAntBuildLogger._minute_3")); //$NON-NLS-1$
184
            }
185
        }
186
        if (seconds > 0) {
187
            if (minutes > 0) {
188
                result.append(' ');
189
            }
190
            result.append(seconds);
191
    
192
            if (seconds > 1) {
193
                result.append(RemoteAntMessages.getString("RemoteAntBuildLogger._seconds_4")); //$NON-NLS-1$
194
            } else {
195
                result.append(RemoteAntMessages.getString("RemoteAntBuildLogger._second_5")); //$NON-NLS-1$
196
            } 
197
        }
198
        if (seconds == 0 && minutes == 0) {
199
            result.append(milliseconds);
200
            result.append(RemoteAntMessages.getString("RemoteAntBuildLogger._milliseconds_6"));      //$NON-NLS-1$
201
        }
202
        return result.toString();
203
    }
204
            
205
206
    /* (non-Javadoc)
207
     * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
208
     */
209
    public void targetStarted(BuildEvent event) {
210
        if (!fSentProcessId) {
211
            establishConnection();
212
        }
213
214
        if (Project.MSG_INFO <= msgOutputLevel) {
215
            marshalTargetMessage(event);
216
        }
217
    }
218
219
    protected void establishConnection() {
220
        if (fEventPort != -1) {
221
            connect();
222
        } else {
223
            shutDown();
224
            return;
225
        }
226
        
227
        fSentProcessId= true;
228
        StringBuffer message= new StringBuffer(MessageIds.PROCESS_ID);
229
        message.append(fProcessId);
230
        sendMessage(message.toString());
231
        if (fEventQueue != null) {
232
            for (Iterator iter = fEventQueue.iterator(); iter.hasNext();) {
233
                processEvent((BuildEvent)iter.next());
234
            }
235
            fEventQueue= null;
236
        }
237
    }
238
239
    /* (non-Javadoc)
240
     * @see org.apache.tools.ant.BuildListener#messageLogged(org.apache.tools.ant.BuildEvent)
241
     */
242
    public void messageLogged(BuildEvent event) {
243
        if (event.getPriority() > msgOutputLevel && event.getPriority() != InternalAntRunner.MSG_PROJECT_HELP) {
244
            return;
245
        }
246
        
247
        if (!fSentProcessId) {
248
            if (event.getPriority() == InternalAntRunner.MSG_PROJECT_HELP) {
249
                if (Project.MSG_INFO > msgOutputLevel) {
250
                    return;
251
                }
252
                //no buildstarted or project started for project help option
253
                establishConnection();
254
                return;
255
            }
256
            if (fEventQueue == null){
257
                fEventQueue= new ArrayList(10);
258
            }
259
            fEventQueue.add(event);
260
            return;
261
        }
262
        
263
        processEvent(event);
264
    }
265
266
    private void processEvent(BuildEvent event) {
267
        if (event.getTask() != null & !emacsMode) {
268
            try {
269
                marshalTaskMessage(event);
270
            } catch (IOException e) {
271
            }
272
        } else {
273
            marshalMessage(event);
274
        }
275
    }
276
    
277
    private void marshalMessage(BuildEvent event) {
278
        String eventMessage= event.getMessage();
279
        if (eventMessage.length() == 0) {
280
            return;
281
        }
282
        marshalMessage(event.getPriority(), eventMessage);
283
    }
284
285
    protected void marshalMessage(int priority, String message) {
286
        try {
287
            BufferedReader r = new BufferedReader(new StringReader(message));
288
            String line = r.readLine();
289
            StringBuffer messageLine;
290
            while (line != null) {
291
                messageLine= new StringBuffer();
292
                if (priority != -1) {
293
                    messageLine.append(priority);
294
                    messageLine.append(',');
295
                }
296
                messageLine.append(line);
297
                sendMessage(messageLine.toString());
298
                line = r.readLine();
299
            }
300
        } catch (IOException e) {
301
        }
302
    }
303
304
    private void marshalTaskMessage(BuildEvent event) throws IOException {
305
        String eventMessage= event.getMessage();
306
        if (eventMessage.length() == 0) {
307
            return;
308
        }
309
        BufferedReader r = new BufferedReader(new StringReader(eventMessage));
310
        String line = r.readLine();
311
        StringBuffer message;
312
        String taskName= event.getTask().getTaskName();
313
        if (taskName != null && taskName.equals(fLastTaskName)) {
314
            taskName= ""; //$NON-NLS-1$
315
        } else {
316
            fLastTaskName= taskName;
317
        }
318
        Location location= event.getTask().getLocation();
319
        String fileName= null;
320
        int lineNumber= -1;
321
        try {
322
            fileName= location.getFileName();
323
            lineNumber= location.getLineNumber();
324
        } catch (NoSuchMethodError e) {
325
            //older Ant
326
            fileName= location.toString();
327
        }
328
        if (location.equals(Location.UNKNOWN_LOCATION)) {
329
            fileName= location.toString();
330
            lineNumber= -1;
331
        }
332
        int priority= event.getPriority();
333
        while (line != null) {
334
            message= new StringBuffer(MessageIds.TASK);
335
            message.append(priority);
336
            message.append(',');
337
            message.append(taskName);
338
            message.append(',');
339
            message.append(line.length());
340
            message.append(',');
341
            message.append(line);
342
            message.append(',');
343
            if (!fileName.equals(fLastFileName)) {
344
            	message.append(fileName.length());
345
            	message.append(',');
346
                message.append(fileName);
347
            } 
348
            message.append(',');
349
            message.append(lineNumber);
350
            sendMessage(message.toString());
351
            fLastFileName= fileName;
352
            line= r.readLine();
353
        }
354
    }
355
    
356
    private void marshalTargetMessage(BuildEvent event) {
357
        Target target= event.getTarget();
358
        Location location= AntDebugState.getLocation(target);
359
        
360
        StringBuffer message= new StringBuffer();
361
        message.append(MessageIds.TARGET);
362
        message.append(',');
363
        message.append(target.getName());
364
        message.append(':');
365
        message.append(',');
366
        if (location != null && location != Location.UNKNOWN_LOCATION) {
367
            //if a target has a valid location then we are on an Ant that is 
368
            //new enough to have the accessor methods on Location
369
        	String fileName= location.getFileName();
370
        	message.append(fileName.length());
371
        	message.append(',');
372
            message.append(fileName);
373
            message.append(',');
374
            message.append(location.getLineNumber());
375
        }
376
        sendMessage(message.toString());
377
    }
378
379
    /* (non-Javadoc)
380
     * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
381
     */
382
    public void buildStarted(BuildEvent event) {
383
        establishConnection();
384
        super.buildStarted(event);
385
    }
386
    
387
    public void configure(Map userProperties) {
388
        String portProperty= (String) userProperties.remove("eclipse.connect.port"); //$NON-NLS-1$
389
        
390
        if (portProperty != null) {
391
            fEventPort= Integer.parseInt(portProperty);
392
        }
393
        
394
        fProcessId= (String) userProperties.remove("org.eclipse.ant.core.ANT_PROCESS_ID"); //$NON-NLS-1$
395
    } 
396
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/logger/debug/RemoteAntBreakpoint.java (-73 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport.logger.debug;
12
13
import java.io.File;
14
import org.eclipse.ant.internal.ui.antsupport.logger.util.DebugMessageIds;
15
16
public class RemoteAntBreakpoint {
17
	
18
    private File fFile;
19
	private int fLineNumber;
20
	private String fFileName;
21
	
22
	public RemoteAntBreakpoint(String breakpointRepresentation) {
23
		String[] data= breakpointRepresentation.split(DebugMessageIds.MESSAGE_DELIMITER);
24
		String fileName= data[1];
25
		String lineNumber= data[2];
26
		fFileName= fileName;
27
		fFile= new File(fileName);
28
		fLineNumber= Integer.parseInt(lineNumber);
29
	}
30
31
	public boolean isAt(String fileName, int lineNumber) {
32
		return fLineNumber == lineNumber && fileName != null && fFile.equals(new File(fileName));
33
	}
34
	
35
	public String toMarshallString() {
36
		StringBuffer buffer= new StringBuffer(DebugMessageIds.BREAKPOINT);
37
		buffer.append(DebugMessageIds.MESSAGE_DELIMITER);
38
		buffer.append(fFileName);
39
		buffer.append(DebugMessageIds.MESSAGE_DELIMITER);
40
		buffer.append(fLineNumber);
41
		return buffer.toString();
42
	}
43
	
44
	/* (non-Javadoc)
45
	 * @see java.lang.Object#equals(java.lang.Object)
46
	 */
47
	public boolean equals(Object obj) {
48
		if (!(obj instanceof RemoteAntBreakpoint)) {
49
			return false;
50
		}
51
		RemoteAntBreakpoint other= (RemoteAntBreakpoint) obj;
52
		return other.getLineNumber() == fLineNumber && other.getFile().equals(fFile);
53
	}
54
	
55
	/* (non-Javadoc)
56
	 * @see java.lang.Object#hashCode()
57
	 */
58
	public int hashCode() {
59
		return fFileName.hashCode() + fLineNumber;
60
	}
61
	
62
	public int getLineNumber() {
63
		return fLineNumber;
64
	}
65
66
	public String getFileName() {
67
		return fFileName;
68
	}
69
	
70
	public File getFile() {
71
	    return fFile;
72
	}
73
}
(-)Remote Ant Support/org/eclipse/ant/internal/ui/antsupport/logger/debug/RemoteAntDebugBuildLogger.java (-354 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2003, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ant.internal.ui.antsupport.logger.debug;
12
13
import java.io.BufferedReader;
14
import java.io.IOException;
15
import java.io.InputStreamReader;
16
import java.io.PrintWriter;
17
import java.net.ServerSocket;
18
import java.net.Socket;
19
import java.net.SocketTimeoutException;
20
import java.util.ArrayList;
21
import java.util.Iterator;
22
import java.util.List;
23
import java.util.Map;
24
25
import org.apache.tools.ant.BuildEvent;
26
import org.apache.tools.ant.Location;
27
import org.apache.tools.ant.Task;
28
import org.eclipse.ant.internal.ui.antsupport.logger.RemoteAntBuildLogger;
29
import org.eclipse.ant.internal.ui.antsupport.logger.util.AntDebugState;
30
import org.eclipse.ant.internal.ui.antsupport.logger.util.DebugMessageIds;
31
import org.eclipse.ant.internal.ui.antsupport.logger.util.IDebugBuildLogger;
32
33
/**
34
 * Parts adapted from org.eclipse.jdt.internal.junit.runner.RemoteTestRunner
35
 * A build logger that reports via a socket connection.
36
 * See DebugMessageIds and MessageIds for more information about the protocol.
37
 */
38
public class RemoteAntDebugBuildLogger extends RemoteAntBuildLogger implements IDebugBuildLogger {
39
	
40
	private ServerSocket fServerSocket;
41
	private static final int fgServerSocketTimeout= 5000;
42
	private Socket fRequestSocket;
43
	
44
	private PrintWriter fRequestWriter;
45
	
46
	private BufferedReader fRequestReader;
47
	
48
    private boolean fBuildStartedSuspend= true;
49
	
50
	private Task fStepOverTaskInterrupted;
51
	
52
	private List fBreakpoints= null;
53
	
54
	/**
55
	 * Request port to connect to.
56
	 * Used for debug connections
57
	 */
58
	private int fRequestPort= -1;
59
	private AntDebugState fDebugState;
60
61
	/**
62
	 * Reader thread that processes requests from the debug client.
63
	 */
64
	private class ReaderThread extends Thread {
65
		public ReaderThread() {
66
			super("ReaderThread"); //$NON-NLS-1$
67
			setDaemon(true);
68
		}
69
70
		public void run(){
71
			try { 
72
				String message= null; 
73
				while (fRequestReader != null) { 
74
					if ((message= fRequestReader.readLine()) != null) {
75
						
76
						if (message.startsWith(DebugMessageIds.STEP_INTO)){
77
							synchronized(RemoteAntDebugBuildLogger.this) {
78
								fDebugState.setStepIntoSuspend(true);
79
								fDebugState.setStepIntoTask(fDebugState.getCurrentTask());
80
								RemoteAntDebugBuildLogger.this.notifyAll();
81
							}
82
						} if (message.startsWith(DebugMessageIds.STEP_OVER)){
83
							synchronized(RemoteAntDebugBuildLogger.this) {
84
								fDebugState.stepOver();
85
							}
86
						} else if (message.startsWith(DebugMessageIds.SUSPEND)) {
87
							synchronized(RemoteAntDebugBuildLogger.this) {
88
								fDebugState.setStepIntoTask(null);
89
								fDebugState.setStepOverTask(null);
90
								fStepOverTaskInterrupted= null;
91
								fDebugState.setClientSuspend(true);
92
							}
93
						} else if (message.startsWith(DebugMessageIds.RESUME)) {
94
							synchronized(RemoteAntDebugBuildLogger.this) {
95
								fDebugState.setStepIntoTask(null);
96
								fDebugState.setStepOverTask(null);
97
								fStepOverTaskInterrupted= null;
98
								RemoteAntDebugBuildLogger.this.notifyAll();
99
							}
100
						} else if (message.startsWith(DebugMessageIds.TERMINATE)) {
101
						    sendRequestResponse(DebugMessageIds.TERMINATED);
102
							shutDown();
103
						} else if (message.startsWith(DebugMessageIds.STACK)) {
104
							marshallStack();
105
						} else if (message.startsWith(DebugMessageIds.ADD_BREAKPOINT)) {
106
							addBreakpoint(message);
107
						} else if (message.startsWith(DebugMessageIds.REMOVE_BREAKPOINT)) {
108
							removeBreakpoint(message);
109
						}  else if (message.startsWith(DebugMessageIds.PROPERTIES)) {
110
							marshallProperties();
111
						}
112
					}
113
				} 
114
			} catch (Exception e) {
115
				RemoteAntDebugBuildLogger.this.shutDown();
116
			}
117
		}
118
	}
119
	
120
	private void requestConnect() {
121
		if (fDebugMode) {
122
			System.out.println("RemoteAntDebugBuildLogger: trying to connect" + fHost + ":" + fRequestPort); //$NON-NLS-1$ //$NON-NLS-2$
123
		}
124
		
125
		try{
126
			fServerSocket.setSoTimeout(fgServerSocketTimeout);
127
			fRequestSocket= fServerSocket.accept();
128
			fRequestWriter= new PrintWriter(fRequestSocket.getOutputStream(), true);
129
			fRequestReader = new BufferedReader(new InputStreamReader(fRequestSocket.getInputStream()));
130
			
131
			ReaderThread readerThread= new ReaderThread();
132
			readerThread.setDaemon(true);
133
			readerThread.start();
134
			return;
135
		} catch(SocketTimeoutException e){
136
		} catch(IOException e) {
137
		}
138
		shutDown();
139
	}
140
	
141
	/* (non-Javadoc)
142
	 * @see org.eclipse.ant.internal.ui.antsupport.logger.RemoteAntBuildLogger#shutDown()
143
	 */
144
	protected void shutDown() {
145
		if (fRequestWriter != null) {
146
			fRequestWriter.close();
147
			fRequestWriter= null;
148
		}
149
		
150
		if (fRequestReader != null) {
151
			try {
152
				fRequestReader.close();
153
			} catch (IOException e) {
154
			}
155
			fRequestReader= null;
156
		}
157
		
158
		if (fRequestSocket != null) {
159
			try {
160
				fRequestSocket.close();	
161
			} catch(IOException e) {
162
			}
163
		}
164
		fRequestSocket= null;
165
		
166
		super.shutDown();
167
	}
168
	
169
	/* (non-Javadoc)
170
	 * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
171
	 */
172
	public synchronized void buildStarted(BuildEvent event) {
173
		fDebugState= new AntDebugState(this);
174
		super.buildStarted(event);
175
		marshalMessage(-1, DebugMessageIds.BUILD_STARTED);
176
		if (fRequestPort != -1) {
177
			try {
178
				fServerSocket= new ServerSocket(fRequestPort);
179
			} catch (IOException ioe) {
180
				shutDown();
181
			}
182
			requestConnect();
183
		} else {
184
			shutDown();
185
		}
186
        fDebugState.buildStarted();
187
		fDebugState.setShouldSuspend(true);
188
		waitIfSuspended();
189
	}
190
191
	/* (non-Javadoc)
192
	 * @see org.apache.tools.ant.BuildListener#taskStarted(org.apache.tools.ant.BuildEvent)
193
	 */
194
	public void taskStarted(BuildEvent event) {
195
        super.taskStarted(event);
196
		fDebugState.taskStarted(event);
197
	}
198
	
199
	/* (non-Javadoc)
200
	 * @see org.apache.tools.ant.BuildListener#taskFinished(org.apache.tools.ant.BuildEvent)
201
	 */
202
	public synchronized void taskFinished(BuildEvent event) {
203
		super.taskFinished(event);
204
		fDebugState.taskFinished();
205
	}
206
	
207
	/* (non-Javadoc)
208
	 * @see org.eclipse.ant.internal.ui.antsupport.logger.util.IDebugBuildLogger#waitIfSuspended()
209
	 */
210
	public synchronized void waitIfSuspended() {
211
		String detail= null;
212
		boolean shouldSuspend= true;
213
		RemoteAntBreakpoint breakpoint= breakpointAtLineNumber(fDebugState.getBreakpointLocation());
214
		if (breakpoint != null) {
215
			detail= breakpoint.toMarshallString();
216
			fDebugState.setShouldSuspend(false);
217
			if (fDebugState.getStepOverTask() != null) {
218
				fStepOverTaskInterrupted= fDebugState.getStepOverTask();
219
				fDebugState.setStepOverTask(null);
220
			}
221
		} else if (fDebugState.getCurrentTask() != null) {
222
	        if (fDebugState.isStepIntoSuspend()) {
223
	            detail= DebugMessageIds.STEP;
224
				fDebugState.setStepIntoSuspend(false);
225
	        } else if ((fDebugState.getLastTaskFinished() != null && fDebugState.getLastTaskFinished() == fDebugState.getStepOverTask()) || fDebugState.shouldSuspend()) {
226
	        	//suspend as a step over has finished
227
	        	detail= DebugMessageIds.STEP;
228
				fDebugState.setStepOverTask(null);
229
				fDebugState.setShouldSuspend(false);
230
	        } else if (fDebugState.getLastTaskFinished() != null && fDebugState.getLastTaskFinished() == fDebugState.getStepIntoTask()) {
231
	        	//suspend as a task that was stepped into has finally completed
232
	        	 detail= DebugMessageIds.STEP;
233
	        	 fDebugState.setStepIntoTask(null);
234
	        } else if (fDebugState.getLastTaskFinished() != null && fDebugState.getLastTaskFinished() == fStepOverTaskInterrupted) {
235
	        	//suspend as a task that was stepped over but hit a breakpoint has finally completed
236
	        	 detail= DebugMessageIds.STEP;
237
	        	 fStepOverTaskInterrupted= null;
238
	        } else if (fDebugState.isClientSuspend()) {
239
	            detail= DebugMessageIds.CLIENT_REQUEST;
240
				fDebugState.setClientSuspend(false);
241
	        } else {
242
	            shouldSuspend= false;
243
	        }
244
	    } else if (fDebugState.shouldSuspend() && fBuildStartedSuspend) {
245
            fBuildStartedSuspend= false;
246
			fDebugState.setShouldSuspend(false);
247
	    } else {
248
			shouldSuspend= false;
249
	    }
250
		
251
		if (shouldSuspend) {
252
			if (detail != null) {
253
				StringBuffer message= new StringBuffer(DebugMessageIds.SUSPENDED);
254
				message.append(detail);
255
				sendRequestResponse(message.toString());
256
			}
257
			 try {
258
				 wait();
259
                 shouldSuspend= false;
260
			 } catch (InterruptedException e) {
261
			 }
262
		}
263
	}
264
265
	private RemoteAntBreakpoint breakpointAtLineNumber(Location location) {
266
		if (fBreakpoints == null || location == null || location == Location.UNKNOWN_LOCATION) {
267
			return null;
268
		}
269
		String fileName= fDebugState.getFileName(location);
270
		int lineNumber= fDebugState.getLineNumber(location);
271
		for (int i = 0; i < fBreakpoints.size(); i++) {
272
			RemoteAntBreakpoint breakpoint = (RemoteAntBreakpoint) fBreakpoints.get(i);
273
			if (breakpoint.isAt(fileName, lineNumber)) {
274
				return breakpoint;
275
			}
276
		}
277
		return null;
278
	}
279
280
	private void sendRequestResponse(String message) {
281
		if (fRequestWriter == null) {
282
			return;
283
		}
284
		
285
		fRequestWriter.println(message);
286
	}
287
	
288
	protected void marshallStack() {
289
	    StringBuffer stackRepresentation= new StringBuffer();
290
	    fDebugState.marshalStack(stackRepresentation);
291
	    sendRequestResponse(stackRepresentation.toString());
292
	}
293
	
294
	protected void marshallProperties() {
295
	    StringBuffer propertiesRepresentation= new StringBuffer();
296
		fDebugState.marshallProperties(propertiesRepresentation, true);
297
	    sendRequestResponse(propertiesRepresentation.toString());
298
	}
299
	
300
	protected void addBreakpoint(String breakpointRepresentation) {
301
		if (fBreakpoints == null) {
302
			fBreakpoints= new ArrayList();
303
		}
304
		RemoteAntBreakpoint newBreakpoint= new RemoteAntBreakpoint(breakpointRepresentation);
305
		if (!fBreakpoints.contains(newBreakpoint)) {
306
			fBreakpoints.add(newBreakpoint);	
307
		}
308
	}
309
	
310
	protected void removeBreakpoint(String breakpointRepresentation) {
311
		if (fBreakpoints == null) {
312
			return;
313
		} 
314
		RemoteAntBreakpoint equivalentBreakpoint= new RemoteAntBreakpoint(breakpointRepresentation);
315
		for (Iterator iter = fBreakpoints.iterator(); iter.hasNext(); ) {
316
			RemoteAntBreakpoint breakpoint = (RemoteAntBreakpoint) iter.next();
317
			if (breakpoint.equals(equivalentBreakpoint)) {
318
				iter.remove();
319
				return;
320
			}
321
		}
322
	}
323
324
	/* (non-Javadoc)
325
	 * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
326
	 */
327
	public void targetStarted(BuildEvent event) {
328
		fDebugState.targetStarted(event);
329
		if (!fSentProcessId) {
330
			establishConnection();
331
		}
332
		waitIfSuspended();
333
		super.targetStarted(event);
334
	}
335
    
336
    /* (non-Javadoc)
337
     * @see org.apache.tools.ant.BuildListener#targetFinished(org.apache.tools.ant.BuildEvent)
338
     */
339
    public void targetFinished(BuildEvent event) {
340
        super.targetFinished(event);
341
		fDebugState.setTargetExecuting(null);
342
    }   
343
    
344
    /* (non-Javadoc)
345
     * @see org.eclipse.ant.internal.ui.antsupport.logger.RemoteAntBuildLogger#configure(java.util.Map)
346
     */
347
    public void configure(Map userProperties) {
348
       super.configure(userProperties);
349
       String requestPortProperty= (String) userProperties.remove("eclipse.connect.request_port"); //$NON-NLS-1$
350
        if (requestPortProperty != null) {
351
            fRequestPort= Integer.parseInt(requestPortProperty);
352
        }
353
    }
354
}
(-)buildfiles/buildExtraJAR.xml (-3 / +2 lines)
Lines 39-45 Link Here
39
					<include name="org.eclipse.ant.ui/bin"/>
39
					<include name="org.eclipse.ant.ui/bin"/>
40
					<include name="org.eclipse.swt*/bin"/>
40
					<include name="org.eclipse.swt*/bin"/>
41
					<include name="org.eclipse.text/bin"/>
41
					<include name="org.eclipse.text/bin"/>
42
			 		<include name="org.eclipse.ant.core/bin"/>
42
			 		<include name="org.eclipse.ant.core/bin"/>
					<include name="org.eclipse.ant.launching/bin"/>
43
			 		<include name="org.eclipse.debug.core/bin"/>
43
			 		<include name="org.eclipse.debug.core/bin"/>
44
					<include name="org.eclipse.debug.ui/bin"/>
44
					<include name="org.eclipse.debug.ui/bin"/>
45
					<include name="org.eclipse.ui.console/bin"/>
45
					<include name="org.eclipse.ui.console/bin"/>
Lines 54-60 Link Here
54
					<include name="plugins/org.eclipse.core.resources*.jar"/>
54
					<include name="plugins/org.eclipse.core.resources*.jar"/>
55
					<include name="plugins/org.eclipse.swt*.jar"/>
55
					<include name="plugins/org.eclipse.swt*.jar"/>
56
					<include name="plugins/org.eclipse.text*.jar"/>
56
					<include name="plugins/org.eclipse.text*.jar"/>
57
					<include name="plugins/org.eclipse.ant.core*.jar"/>
57
					<include name="plugins/org.eclipse.ant.core*.jar"/>
					<include name="plugins/org.eclipse.ant.launching*.jar"/>
58
					<include name="plugins/org.eclipse.debug.core*.jar"/>
58
					<include name="plugins/org.eclipse.debug.core*.jar"/>
59
					<include name="plugins/org.eclipse.debug.ui*.jar"/>
59
					<include name="plugins/org.eclipse.debug.ui*.jar"/>
60
					<include name="plugins/org.eclipse.ui.console*.jar"/>
60
					<include name="plugins/org.eclipse.ui.console*.jar"/>
Lines 67-73 Link Here
67
		<!-- copy necessary resources -->
67
		<!-- copy necessary resources -->
68
		<copy todir="${destdir}">
68
		<copy todir="${destdir}">
69
			<fileset dir="Ant Runner Support/" excludes="**/*.java"/>
69
			<fileset dir="Ant Runner Support/" excludes="**/*.java"/>
70
			<fileset dir="${basedir}/common_ant_support_bin"/>
71
		</copy>
70
		</copy>
72
		<mkdir dir="${build.result.folder}/lib"/>
71
		<mkdir dir="${build.result.folder}/lib"/>
73
		<jar destfile="${build.result.folder}/lib/antrunner.jar" basedir="${destdir}"/>
72
		<jar destfile="${build.result.folder}/lib/antrunner.jar" basedir="${destdir}"/>
(-)buildfiles/buildRemoteExtraJAR.xml (-2 / +2 lines)
Lines 30-40 Link Here
30
			<classpath>
30
			<classpath>
31
				<dirset dir="${basedir}/..">
31
				<dirset dir="${basedir}/..">
32
					<include name="org.eclipse.swt*/bin"/>
32
					<include name="org.eclipse.swt*/bin"/>
33
					<include name="org.eclipse.ant.ui/common_ant_support_bin"/>
33
					<include name="org.eclipse.ant.launching/common_bin"/>
34
				</dirset>
34
				</dirset>
35
				<fileset dir="${eclipse.home}">
35
				<fileset dir="${eclipse.home}">
36
					<include name="plugins/org.eclipse.swt*.jar"/>
36
					<include name="plugins/org.eclipse.swt*.jar"/>
37
					<include name="plugins/org.eclipse.osgi*.jar"/>
37
					<include name="plugins/org.eclipse.osgi*.jar"/>
38
					<include name="plugins/org.eclipse.ant.launching*.jar"/>
38
				</fileset>
39
				</fileset>
39
			</classpath>
40
			</classpath>
40
			<src path="Remote Ant Support/"/>
41
			<src path="Remote Ant Support/"/>
Lines 42-48 Link Here
42
		<!-- copy necessary resources -->
43
		<!-- copy necessary resources -->
43
		<copy todir="${destdir}">
44
		<copy todir="${destdir}">
44
			<fileset dir="Remote Ant Support/" excludes="**/*.java"/>
45
			<fileset dir="Remote Ant Support/" excludes="**/*.java"/>
45
			<fileset dir="${basedir}/common_ant_support_bin"/>
46
		</copy>
46
		</copy>
47
		<mkdir dir="${build.result.folder}/lib"/>
47
		<mkdir dir="${build.result.folder}/lib"/>
48
		<jar destfile="${build.result.folder}/lib/remoteAnt.jar" basedir="${destdir}"/>
48
		<jar destfile="${build.result.folder}/lib/remoteAnt.jar" basedir="${destdir}"/>
(-)plugin.xml (-51 / +2 lines)
Lines 24-71 Link Here
24
      </editor>
24
      </editor>
25
   </extension>
25
   </extension>
26
   <extension
26
   <extension
27
         point="org.eclipse.debug.core.launchConfigurationTypes">
28
      <launchConfigurationType
29
            category="org.eclipse.ui.externaltools"
30
            delegate="org.eclipse.ant.internal.ui.launchConfigurations.AntLaunchDelegate"
31
            delegateDescription="%AntLaunchDelegate.description"
32
            delegateName="%AntLaunchDelegate.name"
33
            id="org.eclipse.ant.AntLaunchConfigurationType"
34
            migrationDelegate="org.eclipse.ant.internal.ui.launchConfigurations.AntMigrationDelegate"
35
            modes="run, debug"
36
            name="%AntBuild"
37
            sourceLocatorId="org.eclipse.ant.ui.debug.sourceLookupDirector"
38
            sourcePathComputerId="org.eclipse.ant.ui.debug.sourcePathComputer">
39
      </launchConfigurationType>
40
      <launchConfigurationType
41
            category="org.eclipse.ui.externaltools.builder"
42
            delegate="org.eclipse.ant.internal.ui.launchConfigurations.AntLaunchDelegate"
43
            delegateDescription="%AntBuilderLaunchDelegate.description"
44
            delegateName="%AntBuilderLaunchDelegate.name"
45
            id="org.eclipse.ant.AntBuilderLaunchConfigurationType"
46
            modes="run"
47
            name="%AntBuilder.name">
48
      </launchConfigurationType>
49
   </extension>
50
   <extension
51
         point="org.eclipse.jdt.launching.classpathProviders">
52
      <classpathProvider
53
            class="org.eclipse.ant.internal.ui.launchConfigurations.AntClasspathProvider"
54
            id="org.eclipse.ant.ui.AntClasspathProvider">
55
      </classpathProvider>
56
   </extension>
57
   <extension
58
         point="org.eclipse.jdt.launching.runtimeClasspathEntries">
59
      <runtimeClasspathEntry
60
            class="org.eclipse.ant.internal.ui.launchConfigurations.AntHomeClasspathEntry"
61
            id="org.eclipse.ant.ui.classpathentry.antHome">
62
      </runtimeClasspathEntry>
63
      <runtimeClasspathEntry
64
            class="org.eclipse.ant.internal.ui.launchConfigurations.ContributedClasspathEntriesEntry"
65
            id="org.eclipse.ant.ui.classpathentry.extraClasspathEntries">
66
      </runtimeClasspathEntry>
67
   </extension>
68
   <extension
69
         point="org.eclipse.ui.views">
27
         point="org.eclipse.ui.views">
70
      <category
28
      <category
71
            name="%CategoryView.antViews"
29
            name="%CategoryView.antViews"
Lines 553-565 Link Here
553
            id="org.eclipse.ant.ui.statusHandler.runAntInit">
511
            id="org.eclipse.ant.ui.statusHandler.runAntInit">
554
      </statusHandler>
512
      </statusHandler>
555
   </extension>
513
   </extension>
556
   <extension
557
         point="org.eclipse.debug.core.processFactories">
558
      <processFactory
559
            class="org.eclipse.ant.internal.ui.launchConfigurations.RemoteAntProcessFactory"
560
            id="org.eclipse.ant.ui.remoteAntProcessFactory">
561
      </processFactory>
562
   </extension>
563
   
514
   
564
   <extension
515
   <extension
565
         point="org.eclipse.ui.editors.templates">
516
         point="org.eclipse.ui.editors.templates">
Lines 648-661 Link Here
648
         point="org.eclipse.debug.core.sourceLocators">
599
         point="org.eclipse.debug.core.sourceLocators">
649
      <sourceLocator
600
      <sourceLocator
650
            name="%antSourceLookupDirector.name"
601
            name="%antSourceLookupDirector.name"
651
            class="org.eclipse.ant.internal.ui.debug.AntSourceLookupDirector"
602
            class="org.eclipse.ant.internal.launching.debug.AntSourceLookupDirector"
652
            id="org.eclipse.ant.ui.debug.sourceLookupDirector">
603
            id="org.eclipse.ant.ui.debug.sourceLookupDirector">
653
      </sourceLocator>
604
      </sourceLocator>
654
   </extension>
605
   </extension>
655
   <extension
606
   <extension
656
         point="org.eclipse.debug.core.sourcePathComputers">
607
         point="org.eclipse.debug.core.sourcePathComputers">
657
      <sourcePathComputer
608
      <sourcePathComputer
658
            class="org.eclipse.ant.internal.ui.debug.AntSourcePathComputerDelegate"
609
            class="org.eclipse.ant.internal.launching.debug.AntSourcePathComputerDelegate"
659
            id="org.eclipse.ant.ui.debug.sourcePathComputer">
610
            id="org.eclipse.ant.ui.debug.sourcePathComputer">
660
      </sourcePathComputer>
611
      </sourcePathComputer>
661
   </extension>
612
   </extension>
(-)META-INF/MANIFEST.MF (-2 / +4 lines)
Lines 1-7 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.core.externaltools
4
Bundle-SymbolicName: org.eclipse.core.externaltools;singleton:=true
5
Bundle-Version: 1.0.0.qualifier
5
Bundle-Version: 1.0.0.qualifier
6
Bundle-Activator: org.eclipse.core.internal.externaltools.ExternalToolsCore
6
Bundle-Activator: org.eclipse.core.internal.externaltools.ExternalToolsCore
7
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
7
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
Lines 10-13 Link Here
10
Bundle-RequiredExecutionEnvironment: J2SE-1.4
10
Bundle-RequiredExecutionEnvironment: J2SE-1.4
11
Bundle-ActivationPolicy: lazy
11
Bundle-ActivationPolicy: lazy
12
Bundle-Vendor: %providerName
12
Bundle-Vendor: %providerName
13
Export-Package: org.eclipse.core.internal.externaltools;x-internal:=true
13
Export-Package: org.eclipse.core.internal.externaltools;x-friends:="org.eclipse.ant.tests.ui,org.eclipse.ui.externaltools,org.eclipse.ant.launching",
14
 org.eclipse.core.internal.externaltools.launchConfigurations;x-friends:="org.eclipse.ant.launching",
15
 org.eclipse.core.internal.externaltools.model;x-friends:="org.eclipse.ant.launching,org.eclipse.ant.ui"
(-)build.properties (-1 / +3 lines)
Lines 1-4 Link Here
1
source.. = src/
1
source.. = src/
2
output.. = bin/
2
output.. = bin/
3
bin.includes = META-INF/,\
3
bin.includes = META-INF/,\
4
               .
4
               .,\
5
               plugin.xml,\
6
               plugin.properties
(-)plugin.properties (-1 / +14 lines)
Lines 10-13 Link Here
10
###############################################################################
10
###############################################################################
11
11
12
pluginName=External Tools Headless Support
12
pluginName=External Tools Headless Support
13
providerName=Eclipse.org
13
providerName=Eclipse.org
14
15
Program.externalTools = Program
16
Program.externalTools = Program
17
Program.externalTools = Program
18
Program.externalTools = Program
19
Program.externalTools = Program
20
Program.externalTools = Program
21
Program.externalTools = Program
22
Program.externalTools = Program
23
Program.externalTools = Program
24
Program.externalTools = Program
25
Program.externalTools = Program
26
Program.externalTools = Program
(-)plugin.xml (+32 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.4"?>
3
<plugin>
4
 <extension
5
         point="org.eclipse.debug.core.launchConfigurationTypes">
6
      <launchConfigurationType
7
            name="%Program.externalTools"
8
            delegate="org.eclipse.core.internal.externaltools.launchConfigurations.ProgramLaunchDelegate"
9
            category="org.eclipse.ui.externaltools"
10
            modes="run"
11
            id="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
12
      </launchConfigurationType>
13
      <launchConfigurationType
14
            name="%Program.externalTools"
15
            delegate="org.eclipse.core.internal.externaltools.launchConfigurations.ProgramLaunchDelegate"
16
            category="org.eclipse.ui.externaltools.builder"
17
            modes="run"
18
            id="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
19
      </launchConfigurationType>
20
   </extension>
21
   <extension
22
         id="ExternalToolBuilder"
23
         name="%Builder.externalTools"
24
         point="org.eclipse.core.resources.builders">
25
     <builder
26
      	isConfigurable= "true">
27
         <run
28
               class="org.eclipse.core.internal.externaltools.model.ExternalToolBuilder">
29
         </run>
30
      </builder>
31
   </extension>
32
</plugin>
(-)src/org/eclipse/core/internal/externaltools/ExternalToolsCore.java (+59 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.core.internal.externaltools;
11
package org.eclipse.core.internal.externaltools;
12
12
13
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.core.runtime.Plugin;
16
import org.eclipse.core.runtime.Plugin;
17
import org.eclipse.core.runtime.Status;
14
import org.osgi.framework.BundleContext;
18
import org.osgi.framework.BundleContext;
15
19
16
/**
20
/**
Lines 20-25 Link Here
20
24
21
	// The plug-in ID
25
	// The plug-in ID
22
	public static final String PLUGIN_ID = "org.eclipse.core.externaltools"; //$NON-NLS-1$
26
	public static final String PLUGIN_ID = "org.eclipse.core.externaltools"; //$NON-NLS-1$
27
	
28
	private static final String EMPTY_STRING= ""; //$NON-NLS-1$
29
	
30
	/**
31
	 * Status code indicating an unexpected internal error.
32
	 * @since 2.1
33
	 */
34
	public static final int INTERNAL_ERROR = 120;	
23
35
24
	// The shared instance
36
	// The shared instance
25
	private static ExternalToolsCore plugin;
37
	private static ExternalToolsCore plugin;
Lines 56-60 Link Here
56
	public static ExternalToolsCore getDefault() {
68
	public static ExternalToolsCore getDefault() {
57
		return plugin;
69
		return plugin;
58
	}
70
	}
71
	
72
	/**
73
	 * Logs the specified throwable with this plug-in's log.
74
	 * 
75
	 * @param t throwable to log 
76
	 */
77
	public static void log(Throwable t) {
78
		IStatus status= new Status(IStatus.ERROR, PLUGIN_ID, INTERNAL_ERROR, "Error logged from Ant UI: ", t); //$NON-NLS-1$
79
		log(status);
80
	}
81
82
	/**
83
	 * Logs the specified status with this plug-in's log.
84
	 * 
85
	 * @param status status 
86
	 */
87
	public static void log(IStatus status) {
88
		getDefault().getLog().log(status);
89
	}
90
	
91
	/**
92
	 * Writes the message to the plug-in's log
93
	 * 
94
	 * @param message the text to write to the log
95
	 */
96
	public static void log(String message, Throwable exception) {
97
		IStatus status = newErrorStatus(message, exception);
98
		log(status);
99
	}
100
	
101
	/**
102
	 * Returns a new <code>IStatus</code> for this plug-in
103
	 */
104
	public static IStatus newErrorStatus(String message, Throwable exception) {
105
		if (message == null) {
106
			message= EMPTY_STRING; 
107
		}		
108
		return new Status(IStatus.ERROR, PLUGIN_ID, 0, message, exception);
109
	}
110
	
111
	/**
112
	 * Returns a new <code>CoreException</code> for this plug-in
113
	 */
114
	public static CoreException newError(String message, Throwable exception) {
115
		return new CoreException(new Status(IStatus.ERROR,
116
				IExternalToolConstants.PLUGIN_ID, 0, message, exception));
117
	}
59
118
60
}
119
}
(-)src/org/eclipse/core/internal/externaltools/launchConfigurations/BackgroundResourceRefresher.java (+88 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.internal.externaltools.launchConfigurations;
12
13
14
import org.eclipse.core.internal.externaltools.ExternalToolsCore;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.debug.core.DebugEvent;
21
import org.eclipse.debug.core.DebugPlugin;
22
import org.eclipse.debug.core.IDebugEventSetListener;
23
import org.eclipse.debug.core.ILaunchConfiguration;
24
import org.eclipse.debug.core.model.IProcess;
25
26
/**
27
 * Refreshes resources as specified by a launch configuration, when 
28
 * an associated process terminates.
29
 */
30
public class BackgroundResourceRefresher implements IDebugEventSetListener  {
31
32
	private ILaunchConfiguration fConfiguration;
33
	private IProcess fProcess;
34
	
35
	
36
	
37
	public BackgroundResourceRefresher(ILaunchConfiguration configuration, IProcess process) {
38
		fConfiguration = configuration;
39
		fProcess = process;
40
	}
41
	
42
	/**
43
	 * If the process has already terminated, resource refreshing is done
44
	 * immediately in the current thread. Otherwise, refreshing is done when the
45
	 * process terminates.
46
	 */
47
	public void startBackgroundRefresh() {
48
		synchronized (fProcess) {
49
			if (fProcess.isTerminated()) {
50
				refresh();
51
			} else {
52
				DebugPlugin.getDefault().addDebugEventListener(this);
53
			}
54
		}
55
	}
56
	
57
	/* (non-Javadoc)
58
	 * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
59
	 */
60
	public void handleDebugEvents(DebugEvent[] events) {
61
		for (int i = 0; i < events.length; i++) {
62
			DebugEvent event = events[i];
63
			if (event.getSource() == fProcess && event.getKind() == DebugEvent.TERMINATE) {
64
				DebugPlugin.getDefault().removeDebugEventListener(this);
65
				refresh();
66
				break;
67
			}
68
		}
69
	}
70
	
71
	/**
72
	 * Submits a job to do the refresh
73
	 */
74
	protected void refresh() {
75
		Job job= new Job(ExternalToolsProgramMessages.BackgroundResourceRefresher_0) {
76
			public IStatus run(IProgressMonitor monitor) {
77
				try {
78
					DebugPlugin.getDefault().getLaunchManager().refreshResources(fConfiguration, monitor);
79
				} catch (CoreException e) {
80
					ExternalToolsCore.log(e);
81
					return e.getStatus();
82
				}	
83
				return Status.OK_STATUS;
84
			}
85
		};
86
		job.schedule();
87
	}
88
}
(-)src/org/eclipse/core/internal/externaltools/launchConfigurations/ExternalToolsCoreLaunchConfigurationMessages.java (+26 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 * dakshinamurthy.karra@gmail.com - bug 165371
10
 **********************************************************************/
11
package org.eclipse.core.internal.externaltools.launchConfigurations;
12
13
import org.eclipse.osgi.util.NLS;
14
15
public class ExternalToolsCoreLaunchConfigurationMessages extends NLS {
16
	private static final String BUNDLE_NAME = "org.eclipse.core.externaltools.internal.launchConfigurations.ExternalToolsLaunchConfigurationMessages";//$NON-NLS-1$
17
18
	public static String ExternalToolsUtil_Location_not_specified_by__0__1;
19
	public static String ExternalToolsUtil_invalidLocation__0_;
20
	public static String ExternalToolsUtil_invalidDirectory__0_;
21
22
	static {
23
		// load message values from bundle file
24
		NLS.initializeMessages(BUNDLE_NAME, ExternalToolsCoreLaunchConfigurationMessages.class);
25
	}
26
}
(-)src/org/eclipse/core/internal/externaltools/launchConfigurations/ExternalToolsCoreLaunchConfigurationMessages.properties (+15 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
#     dakshinamurthy.karra@gmail.com - bug 165371
11
###############################################################################
12
13
ExternalToolsUtil_Location_not_specified_by__0__1=Location not specified by {0}
14
ExternalToolsUtil_invalidLocation__0_ = The file does not exist for the external tool named {0}.
15
ExternalToolsUtil_invalidDirectory__0_ = The working directory {0} does not exist for the external tool named {1}.
(-)src/org/eclipse/core/internal/externaltools/launchConfigurations/ExternalToolsCoreUtil.java (+258 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Keith Seitz (keiths@redhat.com) - Bug 27243 (environment variables contribution)
11
 *     dakshinamurthy.karra@gmail.com - bug 165371
12
 *******************************************************************************/
13
package org.eclipse.core.internal.externaltools.launchConfigurations;
14
15
16
import java.io.File;
17
18
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IWorkspaceRoot;
22
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IStatus;
26
import org.eclipse.core.runtime.Path;
27
import org.eclipse.core.runtime.Status;
28
import org.eclipse.core.variables.IStringVariableManager;
29
import org.eclipse.core.variables.VariablesPlugin;
30
import org.eclipse.debug.core.DebugPlugin;
31
import org.eclipse.debug.core.ILaunchConfiguration;
32
import org.eclipse.osgi.util.NLS;
33
34
/**
35
 * Utilities for external tool launch configurations.
36
 * <p>
37
 * This class it not intended to be instantiated.
38
 * </p>
39
 */
40
public class ExternalToolsCoreUtil {
41
42
	/**
43
	 * Throws a core exception with an error status object built from
44
	 * the given message, lower level exception, and error code.
45
	 * 
46
	 * @param message the status message
47
	 * @param exception lower level exception associated with the
48
	 *  error, or <code>null</code> if none
49
	 * @param code error code
50
	 */
51
	protected static void abort(String message, Throwable exception, int code) throws CoreException {
52
		throw new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, code, message, exception));
53
	}
54
	
55
	/**
56
	 * Expands and returns the location attribute of the given launch
57
	 * configuration. The location is
58
	 * verified to point to an existing file, in the local file system.
59
	 * 
60
	 * @param configuration launch configuration
61
	 * @return an absolute path to a file in the local file system  
62
	 * @throws CoreException if unable to retrieve the associated launch
63
	 * configuration attribute, if unable to resolve any variables, or if the
64
	 * resolved location does not point to an existing file in the local file
65
	 * system
66
	 */
67
	public static IPath getLocation(ILaunchConfiguration configuration) throws CoreException {
68
		String location = configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String) null);
69
		if (location == null) {
70
			abort(NLS.bind(ExternalToolsCoreLaunchConfigurationMessages.ExternalToolsUtil_Location_not_specified_by__0__1, new String[] { configuration.getName()}), null, 0);
71
		} else {
72
			String expandedLocation = getStringVariableManager().performStringSubstitution(location);
73
			if (expandedLocation == null || expandedLocation.length() == 0) {
74
				String msg = NLS.bind(ExternalToolsCoreLaunchConfigurationMessages.ExternalToolsUtil_invalidLocation__0_, new Object[] { configuration.getName()});
75
				abort(msg, null, 0);
76
			} else {
77
				File file = new File(expandedLocation);
78
				if (file.isFile()) {
79
					return new Path(expandedLocation);
80
				} 
81
				
82
				String msg = NLS.bind(ExternalToolsCoreLaunchConfigurationMessages.ExternalToolsUtil_invalidLocation__0_, new Object[] { configuration.getName()});
83
				abort(msg, null, 0);
84
			}
85
		}
86
		// execution will not reach here
87
		return null;
88
	}
89
	
90
	/**
91
	 * Returns a boolean specifying whether or not output should be captured for
92
	 * the given configuration
93
	 * 
94
	 * @param configuration the configuration from which the value will be
95
	 * extracted
96
	 * @return boolean specifying whether or not output should be captured
97
	 * @throws CoreException if unable to access the associated attribute
98
	 */
99
	public static boolean getCaptureOutput(ILaunchConfiguration configuration) throws CoreException {
100
	    return configuration.getAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, true);
101
	}
102
103
	/**
104
	 * Expands and returns the working directory attribute of the given launch
105
	 * configuration. Returns <code>null</code> if a working directory is not
106
	 * specified. If specified, the working is verified to point to an existing
107
	 * directory in the local file system.
108
	 * 
109
	 * @param configuration launch configuration
110
	 * @return an absolute path to a directory in the local file system, or
111
	 * <code>null</code> if unspecified
112
	 * @throws CoreException if unable to retrieve the associated launch
113
	 * configuration attribute, if unable to resolve any variables, or if the
114
	 * resolved location does not point to an existing directory in the local
115
	 * file system
116
	 */
117
	public static IPath getWorkingDirectory(ILaunchConfiguration configuration) throws CoreException {
118
		String location = configuration.getAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, (String) null);
119
		if (location != null) {
120
			String expandedLocation = getStringVariableManager().performStringSubstitution(location);
121
			if (expandedLocation.length() > 0) {
122
				File path = new File(expandedLocation);
123
				if (path.isDirectory()) {
124
					return new Path(expandedLocation);
125
				} 
126
				String msg = NLS.bind(ExternalToolsCoreLaunchConfigurationMessages.ExternalToolsUtil_invalidDirectory__0_, new Object[] { expandedLocation, configuration.getName()});
127
				abort(msg, null, 0);
128
			}
129
		}
130
		return null;
131
	}
132
133
	/**
134
	 * Expands and returns the arguments attribute of the given launch
135
	 * configuration. Returns <code>null</code> if arguments are not specified.
136
	 * 
137
	 * @param configuration launch configuration
138
	 * @return an array of resolved arguments, or <code>null</code> if
139
	 * unspecified
140
	 * @throws CoreException if unable to retrieve the associated launch
141
	 * configuration attribute, or if unable to resolve any variables
142
	 */
143
	public static String[] getArguments(ILaunchConfiguration configuration) throws CoreException {
144
		String args = configuration.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, (String) null);
145
		if (args != null) {
146
			String expanded = getStringVariableManager().performStringSubstitution(args);
147
			return parseStringIntoList(expanded);
148
		}
149
		return null;
150
	}
151
152
	private static IStringVariableManager getStringVariableManager() {
153
		return VariablesPlugin.getDefault().getStringVariableManager();
154
	}
155
	
156
	/**
157
	 * Returns whether the given launch configuration is enabled. This property
158
	 * is intended only to apply to external tool builder configurations and
159
	 * determines whether the project builder will launch the configuration
160
	 * when it builds.
161
	 *  
162
	 * @param configuration the configuration for which the enabled state should
163
	 * 		be determined.
164
	 * @return whether the given configuration is enabled to be run when a build occurs.
165
	 * @throws CoreException if unable to access the associated attribute
166
	 */
167
	public static boolean isBuilderEnabled(ILaunchConfiguration configuration) throws CoreException {
168
		return configuration.getAttribute(IExternalToolConstants.ATTR_BUILDER_ENABLED, true);
169
	}
170
	
171
	/**
172
	 * Returns the collection of resources for the build scope as specified by the given launch configuration.
173
	 * 
174
	 * @param configuration launch configuration
175
	 * @throws CoreException if an exception occurs while retrieving the resources
176
	 */
177
	public static IResource[] getResourcesForBuildScope(ILaunchConfiguration configuration) throws CoreException {
178
		String scope = configuration.getAttribute(IExternalToolConstants.ATTR_BUILDER_SCOPE, (String) null);
179
		if (scope == null) {
180
			return null;
181
		}
182
	
183
		return DebugPlugin.getDefault().getLaunchManager().toResources(scope);
184
	}
185
	
186
	/**
187
	 * Parses the argument text into an array of individual
188
	 * strings using the space character as the delimiter.
189
	 * An individual argument containing spaces must have a
190
	 * double quote (") at the start and end. Two double 
191
	 * quotes together is taken to mean an embedded double
192
	 * quote in the argument text.
193
	 * 
194
	 * @param arguments the arguments as one string
195
	 * @return the array of arguments
196
	 */
197
	public static String[] parseStringIntoList(String arguments) {
198
		if (arguments == null || arguments.length() == 0) {
199
			return new String[0];
200
		}
201
		String[] res= DebugPlugin.parseArguments(arguments);
202
		return res;		
203
	}	
204
	/**
205
	 * Returns a collection of projects referenced by a build scope attribute.
206
	 * 
207
	 * @return collection of projects referred to by configuration
208
	 */
209
	public static IProject[] getBuildProjects(ILaunchConfiguration configuration, String buildScopeId) {
210
		
211
		String scope = null;
212
		String id = buildScopeId ;
213
		if (id == null) {
214
			id = IExternalToolConstants.ATTR_BUILD_SCOPE ;
215
		}
216
		try {
217
			scope = configuration.getAttribute(id, (String)null);
218
		} catch (CoreException e) {
219
			return null;
220
		}
221
		if (scope == null) {
222
			return null;
223
		}
224
		if (scope.startsWith("${projects:")) { //$NON-NLS-1$
225
			String pathString = scope.substring(11, scope.length() - 1);
226
			if (pathString.length() > 1) {
227
				String[] names = pathString.split(","); //$NON-NLS-1$
228
				IProject[] projects = new IProject[names.length];
229
				IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
230
				for (int i = 0; i < names.length; i++) {
231
					projects[i] = root.getProject(names[i]);
232
				}
233
				return projects;
234
			}
235
		} else if (scope.equals("${project}")) { //$NON-NLS-1$
236
			if(configuration.getFile()!=null)
237
				return new IProject[]{((IResource)configuration.getFile()).getProject()};
238
		}
239
		return new IProject[0];
240
	}
241
	
242
	/**
243
	 * Whether referenced projects should be considered when building. Only valid
244
	 * when a set of projects is to be built.
245
	 * 
246
	 * @param configuration
247
	 * @return whether referenced projects should be considerd when building
248
	 * @throws CoreException if unable to access the associated attribute
249
	 */
250
	public static boolean isIncludeReferencedProjects(ILaunchConfiguration configuration, String includeReferencedProjectsId) throws CoreException {
251
		String id = includeReferencedProjectsId;
252
		if (id == null) {
253
			id = IExternalToolConstants.ATTR_INCLUDE_REFERENCED_PROJECTS ;
254
		}
255
		return configuration.getAttribute(id, true);
256
	}
257
	
258
}
(-)src/org/eclipse/core/internal/externaltools/launchConfigurations/ExternalToolsMigrationMessages.java (+25 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.core.internal.externaltools.launchConfigurations;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class ExternalToolsMigrationMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.core.externaltools.internal.launchConfigurations.ExternalToolsUIMessages";//$NON-NLS-1$
16
17
	public static String ExternalToolMigration_37;
18
	public static String ExternalToolMigration_38;
19
20
	static {
21
		// load message values from bundle file
22
		NLS.initializeMessages(BUNDLE_NAME,
23
				ExternalToolsMigrationMessages.class);
24
	}
25
}
(-)src/org/eclipse/core/internal/externaltools/launchConfigurations/ExternalToolsMigrationMessages.properties (+13 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
ExternalToolMigration_37=An exception occurred accessing external tool\'s \"run in background\" attribute
13
ExternalToolMigration_38=An exception occurred attempting to migrate external tool\'s \"run in background\" attribute
(-)src/org/eclipse/core/internal/externaltools/launchConfigurations/ExternalToolsProgramMessages.java (+26 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved.   This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.core.internal.externaltools.launchConfigurations;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class ExternalToolsProgramMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.core.externaltools.internal.program.launchConfigurations.ExternalToolsProgramMessages";//$NON-NLS-1$
16
17
	public static String BackgroundResourceRefresher_0;
18
19
	public static String ProgramLaunchDelegate_3;
20
	public static String ProgramLaunchDelegate_4;
21
22
	static {
23
		// load message values from bundle file
24
		NLS.initializeMessages(BUNDLE_NAME, ExternalToolsProgramMessages.class);
25
	}
26
}
(-)src/org/eclipse/core/internal/externaltools/launchConfigurations/ExternalToolsProgramMessages.properties (+19 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
BackgroundResourceRefresher_0=Refreshing resources...
13
14
ProgramLaunchDelegate_Workbench_Closing_1=Workbench Closing
15
ProgramLaunchDelegate_The_workbench_is_exiting=The workbench is exiting and a program launched from an external tool appears to still be running. These programs will be terminated when the workbench exits. It is recommended that you exit any external programs launched from the workbench before you proceed.\n\nClick OK to continue exiting the workbench.
16
ProgramLaunchDelegate_3=Running {0}...
17
ProgramLaunchDelegate_4=An IProcess could not be created for the launch
18
19
ProgramMainTab_Select=&Select a program:
(-)src/org/eclipse/core/internal/externaltools/launchConfigurations/ProgramLaunchDelegate.java (+212 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Keith Seitz (keiths@redhat.com) - environment variables contribution (Bug 27243)
11
 *     dakshinamurthy.karra@gmail.com - bug 165371
12
 *******************************************************************************/
13
package org.eclipse.core.internal.externaltools.launchConfigurations;
14
15
import java.io.File;
16
import java.util.HashMap;
17
import java.util.Map;
18
19
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.debug.core.ILaunch;
28
import org.eclipse.debug.core.ILaunchConfiguration;
29
import org.eclipse.debug.core.ILaunchManager;
30
import org.eclipse.debug.core.model.IProcess;
31
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
32
import org.eclipse.osgi.util.NLS;
33
34
/**
35
 * Launch delegate for a program.
36
 */
37
public class ProgramLaunchDelegate extends LaunchConfigurationDelegate {
38
39
	/**
40
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration,
41
	 *      java.lang.String, org.eclipse.debug.core.ILaunch,
42
	 *      org.eclipse.core.runtime.IProgressMonitor)
43
	 */
44
45
	private ILaunchManager launchManager;
46
47
	public void launch(ILaunchConfiguration configuration, String mode,
48
			ILaunch launch, IProgressMonitor monitor) throws CoreException {
49
50
		if (monitor.isCanceled()) {
51
			return;
52
		}
53
54
		launchManager = DebugPlugin.getDefault().getLaunchManager();
55
56
		// resolve location
57
		IPath location = ExternalToolsCoreUtil.getLocation(configuration);
58
59
		if (monitor.isCanceled()) {
60
			return;
61
		}
62
63
		// resolve working directory
64
		IPath workingDirectory = ExternalToolsCoreUtil
65
				.getWorkingDirectory(configuration);
66
67
		if (monitor.isCanceled()) {
68
			return;
69
		}
70
71
		// resolve arguments
72
		String[] arguments = ExternalToolsCoreUtil.getArguments(configuration);
73
74
		if (monitor.isCanceled()) {
75
			return;
76
		}
77
78
		int cmdLineLength = 1;
79
		if (arguments != null) {
80
			cmdLineLength += arguments.length;
81
		}
82
		String[] cmdLine = new String[cmdLineLength];
83
		cmdLine[0] = location.toOSString();
84
		if (arguments != null) {
85
			System.arraycopy(arguments, 0, cmdLine, 1, arguments.length);
86
		}
87
88
		File workingDir = null;
89
		if (workingDirectory != null) {
90
			workingDir = workingDirectory.toFile();
91
		}
92
93
		if (monitor.isCanceled()) {
94
			return;
95
		}
96
97
		String[] envp = DebugPlugin.getDefault().getLaunchManager()
98
				.getEnvironment(configuration);
99
100
		if (monitor.isCanceled()) {
101
			return;
102
		}
103
104
		Process p = DebugPlugin.exec(cmdLine, workingDir, envp);
105
		IProcess process = null;
106
107
		// add process type to process attributes
108
		Map processAttributes = new HashMap();
109
		String programName = location.lastSegment();
110
		String extension = location.getFileExtension();
111
		if (extension != null) {
112
			programName = programName.substring(0, programName.length()
113
					- (extension.length() + 1));
114
		}
115
		programName = programName.toLowerCase();
116
		processAttributes.put(IProcess.ATTR_PROCESS_TYPE, programName);
117
118
		if (p != null) {
119
			monitor.beginTask(NLS.bind(
120
					ExternalToolsProgramMessages.ProgramLaunchDelegate_3,
121
					new String[] { configuration.getName() }),
122
					IProgressMonitor.UNKNOWN);
123
			process = DebugPlugin.newProcess(launch, p, location.toOSString(),
124
					processAttributes);
125
		}
126
		if (p == null || process == null) {
127
			if (p != null)
128
				p.destroy();
129
			throw new CoreException(new Status(IStatus.ERROR,
130
					IExternalToolConstants.PLUGIN_ID,
131
					IExternalToolConstants.ERR_INTERNAL_ERROR,
132
					ExternalToolsProgramMessages.ProgramLaunchDelegate_4, null));
133
		}
134
		process.setAttribute(IProcess.ATTR_CMDLINE,
135
				generateCommandLine(cmdLine));
136
137
//		if (launchManager.isLaunchInBackground(configuration)) {
138
//			// refresh resources after process finishes
139
//			if (launchManager.getRefreshScope(configuration) != null) {
140
//				BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(
141
//						configuration, process);
142
//				refresher.startBackgroundRefresh();
143
//			}
144
//		} else {
145
			// wait for process to exit
146
			while (!process.isTerminated()) {
147
				try {
148
					if (monitor.isCanceled()) {
149
						process.terminate();
150
						break;
151
					}
152
					Thread.sleep(50);
153
				} catch (InterruptedException e) {
154
				}
155
			}
156
157
			// refresh resources
158
			launchManager.refreshResources(configuration, monitor);
159
//		}
160
	}
161
162
	private String generateCommandLine(String[] commandLine) {
163
		if (commandLine.length < 1)
164
			return ""; //$NON-NLS-1$
165
		StringBuffer buf = new StringBuffer();
166
		for (int i = 0; i < commandLine.length; i++) {
167
			buf.append(' ');
168
			char[] characters = commandLine[i].toCharArray();
169
			StringBuffer command = new StringBuffer();
170
			boolean containsSpace = false;
171
			for (int j = 0; j < characters.length; j++) {
172
				char character = characters[j];
173
				if (character == '\"') {
174
					command.append('\\');
175
				} else if (character == ' ') {
176
					containsSpace = true;
177
				}
178
				command.append(character);
179
			}
180
			if (containsSpace) {
181
				buf.append('\"');
182
				buf.append(command);
183
				buf.append('\"');
184
			} else {
185
				buf.append(command);
186
			}
187
		}
188
		return buf.toString();
189
	}
190
191
	/*
192
	 * (non-Javadoc)
193
	 * 
194
	 * @see
195
	 * org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBuildOrder
196
	 * (org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
197
	 */
198
	protected IProject[] getBuildOrder(ILaunchConfiguration configuration,
199
			String mode) throws CoreException {
200
		IProject[] projects = ExternalToolsCoreUtil.getBuildProjects(
201
				configuration, null);
202
		if (projects == null) {
203
			return null;
204
		}
205
		boolean isRef = ExternalToolsCoreUtil.isIncludeReferencedProjects(
206
				configuration, null);
207
		if (isRef) {
208
			return computeReferencedBuildOrder(projects);
209
		}
210
		return computeBuildOrder(projects);
211
	}
212
}
(-)src/org/eclipse/core/internal/externaltools/model/BuilderCoreUtils.java (+340 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.internal.externaltools.model;
12
13
import java.util.HashMap;
14
import java.util.Map;
15
import java.util.StringTokenizer;
16
17
import org.eclipse.core.internal.externaltools.registry.ExternalToolMigration;
18
import org.eclipse.core.resources.ICommand;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IFolder;
21
import org.eclipse.core.resources.IProject;
22
import org.eclipse.core.resources.IResource;
23
import org.eclipse.core.resources.IncrementalProjectBuilder;
24
import org.eclipse.core.resources.ResourcesPlugin;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IPath;
27
import org.eclipse.core.runtime.IStatus;
28
import org.eclipse.core.runtime.NullProgressMonitor;
29
import org.eclipse.core.runtime.Path;
30
import org.eclipse.debug.core.DebugPlugin;
31
import org.eclipse.debug.core.ILaunchConfiguration;
32
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
33
import org.eclipse.debug.core.ILaunchManager;
34
35
/**
36
 * Utility methods for working with external tool project builders.
37
 */
38
public class BuilderCoreUtils {
39
40
	public static final String LAUNCH_CONFIG_HANDLE = "LaunchConfigHandle"; //$NON-NLS-1$
41
42
	/**
43
	 * Constant used to find a builder using the 3.0-interim format
44
	 */
45
	public static final String BUILDER_FOLDER_NAME = ".externalToolBuilders"; //$NON-NLS-1$
46
	/**
47
	 * Constant used to represent the current project in the 3.0-final format.
48
	 */
49
	public static final String PROJECT_TAG = "<project>"; //$NON-NLS-1$
50
51
	public static final String VERSION_1_0 = "1.0"; //$NON-NLS-1$
52
	public static final String VERSION_2_1 = "2.1"; //$NON-NLS-1$
53
	// The format shipped up to and including Eclipse 3.0 RC1
54
	public static final String VERSION_3_0_interim = "3.0.interim"; //$NON-NLS-1$
55
	// The format shipped in Eclipse 3.0 final
56
	public static final String VERSION_3_0_final = "3.0"; //$NON-NLS-1$
57
58
	private static final String BUILD_TYPE_SEPARATOR = ","; //$NON-NLS-1$
59
	private static final int[] DEFAULT_BUILD_TYPES = new int[] {
60
			IncrementalProjectBuilder.INCREMENTAL_BUILD,
61
			IncrementalProjectBuilder.FULL_BUILD };
62
63
	/**
64
	 * Returns a launch configuration from the given ICommand arguments. If the
65
	 * given arguments are from an old-style external tool, an unsaved working
66
	 * copy will be created from the arguments and returned.
67
	 * 
68
	 * @param commandArgs
69
	 *            the builder ICommand arguments
70
	 * @return a launch configuration, a launch configuration working copy, or
71
	 *         <code>null</code> if not possible.
72
	 */
73
	public static ILaunchConfiguration configFromBuildCommandArgs(
74
			IProject project, Map commandArgs, String[] version) {
75
		String configHandle = (String) commandArgs.get(LAUNCH_CONFIG_HANDLE);
76
		if (configHandle == null) {
77
			// Probably an old-style (Eclipse 1.0 or 2.0) external tool. Try to
78
			// migrate.
79
			version[0] = VERSION_1_0;
80
			return ExternalToolMigration.configFromArgumentMap(commandArgs);
81
		}
82
		ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
83
		ILaunchConfiguration configuration = null;
84
		if (configHandle.startsWith(PROJECT_TAG)) {
85
			version[0] = VERSION_3_0_final;
86
			IPath path = new Path(configHandle);
87
			IFile file = project.getFile(path.removeFirstSegments(1));
88
			if (file.exists()) {
89
				configuration = manager.getLaunchConfiguration(file);
90
			}
91
		} else {
92
			// Try treating the handle as a file name.
93
			// This is the format used in 3.0 RC1.
94
			IPath path = new Path(BUILDER_FOLDER_NAME).append(configHandle);
95
			IFile file = project.getFile(path);
96
			if (file.exists()) {
97
				version[0] = VERSION_3_0_interim;
98
				configuration = manager.getLaunchConfiguration(file);
99
			} else {
100
				try {
101
					// Treat the configHandle as a memento. This is the format
102
					// used in Eclipse 2.1.
103
					configuration = manager
104
							.getLaunchConfiguration(configHandle);
105
				} catch (CoreException e) {
106
				}
107
				if (configuration != null) {
108
					version[0] = VERSION_2_1;
109
				}
110
			}
111
		}
112
		return configuration;
113
	}
114
115
	public static void configureTriggers(ILaunchConfiguration config,
116
			ICommand newCommand) throws CoreException {
117
		newCommand.setBuilding(IncrementalProjectBuilder.FULL_BUILD, false);
118
		newCommand.setBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD,
119
				false);
120
		newCommand.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, false);
121
		newCommand.setBuilding(IncrementalProjectBuilder.CLEAN_BUILD, false);
122
		String buildKinds = config.getAttribute(
123
				IExternalToolConstants.ATTR_RUN_BUILD_KINDS, (String) null);
124
		int[] triggers = BuilderCoreUtils.buildTypesToArray(buildKinds);
125
		for (int i = 0; i < triggers.length; i++) {
126
			switch (triggers[i]) {
127
			case IncrementalProjectBuilder.FULL_BUILD:
128
				newCommand.setBuilding(IncrementalProjectBuilder.FULL_BUILD,
129
						true);
130
				break;
131
			case IncrementalProjectBuilder.INCREMENTAL_BUILD:
132
				newCommand.setBuilding(
133
						IncrementalProjectBuilder.INCREMENTAL_BUILD, true);
134
				break;
135
			case IncrementalProjectBuilder.AUTO_BUILD:
136
				newCommand.setBuilding(IncrementalProjectBuilder.AUTO_BUILD,
137
						true);
138
				break;
139
			case IncrementalProjectBuilder.CLEAN_BUILD:
140
				newCommand.setBuilding(IncrementalProjectBuilder.CLEAN_BUILD,
141
						true);
142
				break;
143
			}
144
		}
145
		if (!config.getAttribute(
146
				IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, false)) {
147
			ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy();
148
			copy.setAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED,
149
					true);
150
			copy.doSave();
151
		}
152
	}
153
154
	/**
155
	 * Returns whether the given configuration is an "unmigrated" builder.
156
	 * Unmigrated builders are external tools that are stored in an old format
157
	 * but have not been migrated by the user. Old format builders are always
158
	 * translated into launch config working copies in memory, but they're not
159
	 * considered "migrated" until the config has been saved and the project
160
	 * spec updated.
161
	 * 
162
	 * @param config
163
	 *            the config to examine
164
	 * @return whether the given config represents an unmigrated builder
165
	 */
166
	public static boolean isUnmigratedConfig(ILaunchConfiguration config) {
167
		return config.isWorkingCopy()
168
				&& ((ILaunchConfigurationWorkingCopy) config).getOriginal() == null;
169
	}
170
171
	/**
172
	 * Converts the given config to a build command which is stored in the given
173
	 * command.
174
	 * 
175
	 * @return the configured build command
176
	 */
177
	public static ICommand toBuildCommand(IProject project,
178
			ILaunchConfiguration config, ICommand command) throws CoreException {
179
		Map args = null;
180
		if (isUnmigratedConfig(config)) {
181
			// This config represents an old external tool builder that hasn't
182
			// been edited. Try to find the old ICommand and reuse the
183
			// arguments.
184
			// The goal here is to not change the storage format of old,
185
			// unedited builders.
186
			ICommand[] commands = project.getDescription().getBuildSpec();
187
			for (int i = 0; i < commands.length; i++) {
188
				ICommand projectCommand = commands[i];
189
				String name = ExternalToolMigration
190
						.getNameFromCommandArgs(projectCommand.getArguments());
191
				if (name != null && name.equals(config.getName())) {
192
					args = projectCommand.getArguments();
193
					break;
194
				}
195
			}
196
		} else {
197
			if (config instanceof ILaunchConfigurationWorkingCopy) {
198
				ILaunchConfigurationWorkingCopy workingCopy = (ILaunchConfigurationWorkingCopy) config;
199
				if (workingCopy.getOriginal() != null) {
200
					config = workingCopy.getOriginal();
201
				}
202
			}
203
			args = new HashMap();
204
			// Launch configuration builders are stored with a project-relative
205
			// path
206
			StringBuffer buffer = new StringBuffer(PROJECT_TAG);
207
			// Append the project-relative path (workspace path minus first
208
			// segment)
209
			buffer.append('/').append(
210
					config.getFile().getFullPath().removeFirstSegments(1));
211
			args.put(LAUNCH_CONFIG_HANDLE, buffer.toString());
212
		}
213
		command.setBuilderName(ExternalToolBuilder.ID);
214
		command.setArguments(args);
215
		return command;
216
	}
217
218
	/**
219
	 * Returns the folder where project builders should be stored or
220
	 * <code>null</code> if the folder could not be created
221
	 */
222
	public static IFolder getBuilderFolder(IProject project, boolean create) {
223
		IFolder folder = project.getFolder(BUILDER_FOLDER_NAME);
224
		if (!folder.exists() && create) {
225
			try {
226
				folder.create(true, true, new NullProgressMonitor());
227
			} catch (CoreException e) {
228
				return null;
229
			}
230
		}
231
		return folder;
232
	}
233
234
	/**
235
	 * Migrates the launch configuration working copy, which is based on an old-
236
	 * style external tool builder, to a new, saved launch configuration. The
237
	 * returned launch configuration will contain the same attributes as the
238
	 * given working copy with the exception of the configuration name, which
239
	 * may be changed during the migration. The name of the configuration will
240
	 * only be changed if the current name is not a valid name for a saved
241
	 * config.
242
	 * 
243
	 * @param workingCopy
244
	 *            the launch configuration containing attributes from an
245
	 *            old-style project builder.
246
	 * @return ILaunchConfiguration a new, saved launch configuration whose
247
	 *         attributes match those of the given working copy as well as
248
	 *         possible
249
	 * @throws CoreException
250
	 *             if an exception occurs while attempting to save the new
251
	 *             launch configuration
252
	 */
253
	public static ILaunchConfiguration migrateBuilderConfiguration(
254
			IProject project, ILaunchConfigurationWorkingCopy workingCopy)
255
			throws CoreException {
256
		workingCopy.setContainer(getBuilderFolder(project, true));
257
		// Before saving, make sure the name is valid
258
		String name = workingCopy.getName();
259
		name = name.replace('/', '.');
260
		if (name.charAt(0) == ('.')) {
261
			name = name.substring(1);
262
		}
263
		IStatus status = ResourcesPlugin.getWorkspace().validateName(name,
264
				IResource.FILE);
265
		if (!status.isOK()) {
266
			name = "ExternalTool"; //$NON-NLS-1$
267
		}
268
		name = DebugPlugin.getDefault().getLaunchManager()
269
				.generateUniqueLaunchConfigurationNameFrom(name);
270
		workingCopy.rename(name);
271
		return workingCopy.doSave();
272
	}
273
274
	/**
275
	 * Converts the build types string into an array of build kinds.
276
	 * 
277
	 * @param buildTypes
278
	 *            the string of built types to convert
279
	 * @return the array of build kinds.
280
	 */
281
	public static int[] buildTypesToArray(String buildTypes) {
282
		if (buildTypes == null || buildTypes.length() == 0) {
283
			return DEFAULT_BUILD_TYPES;
284
		}
285
286
		int count = 0;
287
		boolean incremental = false;
288
		boolean full = false;
289
		boolean auto = false;
290
		boolean clean = false;
291
292
		StringTokenizer tokenizer = new StringTokenizer(buildTypes,
293
				BUILD_TYPE_SEPARATOR);
294
		while (tokenizer.hasMoreTokens()) {
295
			String token = tokenizer.nextToken();
296
			if (IExternalToolConstants.BUILD_TYPE_INCREMENTAL.equals(token)) {
297
				if (!incremental) {
298
					incremental = true;
299
					count++;
300
				}
301
			} else if (IExternalToolConstants.BUILD_TYPE_FULL.equals(token)) {
302
				if (!full) {
303
					full = true;
304
					count++;
305
				}
306
			} else if (IExternalToolConstants.BUILD_TYPE_AUTO.equals(token)) {
307
				if (!auto) {
308
					auto = true;
309
					count++;
310
				}
311
			} else if (IExternalToolConstants.BUILD_TYPE_CLEAN.equals(token)) {
312
				if (!clean) {
313
					clean = true;
314
					count++;
315
				}
316
			}
317
		}
318
319
		int[] results = new int[count];
320
		count = 0;
321
		if (incremental) {
322
			results[count] = IncrementalProjectBuilder.INCREMENTAL_BUILD;
323
			count++;
324
		}
325
		if (full) {
326
			results[count] = IncrementalProjectBuilder.FULL_BUILD;
327
			count++;
328
		}
329
		if (auto) {
330
			results[count] = IncrementalProjectBuilder.AUTO_BUILD;
331
			count++;
332
		}
333
		if (clean) {
334
			results[count] = IncrementalProjectBuilder.CLEAN_BUILD;
335
			count++;
336
		}
337
338
		return results;
339
	}
340
}
(-)src/org/eclipse/core/internal/externaltools/model/ExternalToolBuilder.java (+289 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Matthew Conway  - Bug 175186
11
 *******************************************************************************/
12
package org.eclipse.core.internal.externaltools.model;
13
14
15
import java.util.Map;
16
17
import org.eclipse.core.internal.externaltools.ExternalToolsCore;
18
import org.eclipse.core.internal.externaltools.launchConfigurations.ExternalToolsCoreUtil;
19
import org.eclipse.core.internal.externaltools.registry.ExternalToolMigration;
20
import org.eclipse.core.resources.ICommand;
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.IProjectDescription;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.resources.IResourceDelta;
26
import org.eclipse.core.resources.IResourceDeltaVisitor;
27
import org.eclipse.core.resources.IncrementalProjectBuilder;
28
import org.eclipse.core.runtime.CoreException;
29
import org.eclipse.core.runtime.IPath;
30
import org.eclipse.core.runtime.IProgressMonitor;
31
import org.eclipse.debug.core.ILaunchConfiguration;
32
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
33
import org.eclipse.debug.core.ILaunchManager;
34
import org.eclipse.osgi.util.NLS;
35
import org.osgi.framework.Bundle;
36
37
/**
38
 * This project builder implementation will run an external tool during the
39
 * build process. 
40
 */
41
public final class ExternalToolBuilder extends IncrementalProjectBuilder {
42
	private final class IgnoreTeamPrivateChanges implements IResourceDeltaVisitor {
43
		private boolean[] fTrueChange;
44
		private IgnoreTeamPrivateChanges(boolean[] trueChange) {
45
			super();
46
			fTrueChange= trueChange;
47
		}
48
		public boolean visit(IResourceDelta visitDelta) throws CoreException {
49
			IResource resource= visitDelta.getResource();
50
			if (resource instanceof IFile) {
51
				fTrueChange[0]= true;
52
				return false;
53
			}
54
			return true;
55
		}
56
	}
57
58
	public static final String ID = "org.eclipse.ui.externaltools.ExternalToolBuilder"; //$NON-NLS-1$;
59
60
	private static String buildType = IExternalToolConstants.BUILD_TYPE_NONE;
61
	
62
	private static IProject buildProject= null;
63
    private static IResourceDelta buildDelta= null;
64
	
65
	/* (non-Javadoc)
66
	 * @see org.eclipse.core.internal.events.InternalBuilder#build(int, java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
67
	 */
68
	protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {		
69
		if (ExternalToolsCore.getDefault().getBundle().getState() != Bundle.ACTIVE) {
70
			return null;
71
		}
72
		
73
		ILaunchConfiguration config= BuilderCoreUtils.configFromBuildCommandArgs(getProject(), args, new String[1]);
74
        if (config == null) {
75
            throw ExternalToolsCore.newError(ExternalToolsModelMessages.ExternalToolBuilder_0, null);
76
        }
77
		IProject[] projectsWithinScope= null;
78
		IResource[] resources = ExternalToolsCoreUtil.getResourcesForBuildScope(config);
79
		if (resources != null) {
80
			projectsWithinScope= new IProject[resources.length];
81
			for (int i = 0; i < resources.length; i++) {
82
				projectsWithinScope[i]= resources[i].getProject();
83
			}
84
		}
85
        boolean kindCompatible= commandConfiguredForKind(config, kind);
86
        if (kindCompatible && configEnabled(config)) {
87
            doBuildBasedOnScope(resources, kind, config, monitor);
88
        }
89
        
90
		return projectsWithinScope;
91
	}
92
93
    private boolean commandConfiguredForKind(ILaunchConfiguration config, int kind) {
94
        try {
95
            if (!(config.getAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, false))) {
96
                ICommand command= getCommand();
97
                //adapt the builder command to make use of the 3.1 support for setting command build kinds
98
                //this will only happen once for builder/command defined before the support existed
99
                BuilderCoreUtils.configureTriggers(config, command);
100
                IProjectDescription desc= getProject().getDescription();
101
                ICommand[] commands= desc.getBuildSpec();
102
                int index= getBuilderCommandIndex(commands, command);
103
                if (index != -1) {
104
                    commands[index]= command;
105
                    desc.setBuildSpec(commands);
106
                    getProject().setDescription(desc, null);
107
                    ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
108
                    copy.setAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, true);
109
                    copy.doSave();
110
                }
111
                return command.isBuilding(kind);
112
            }
113
        } catch (CoreException e) {
114
           ExternalToolsCore.log(e);
115
           return true;
116
        }
117
        return true;
118
    }
119
    
120
    private int getBuilderCommandIndex(ICommand[] buildSpec, ICommand command) {
121
        Map commandArgs= command.getArguments();
122
        if (commandArgs == null) {
123
            return -1;
124
        }
125
        String handle= (String) commandArgs.get(BuilderCoreUtils.LAUNCH_CONFIG_HANDLE);
126
        if (handle == null) {
127
            return -1;
128
        }
129
        for (int i = 0; i < buildSpec.length; ++i) {
130
            ICommand buildSpecCommand= buildSpec[i];
131
            if (ID.equals(buildSpecCommand.getBuilderName())) {
132
                Map buildSpecArgs= buildSpecCommand.getArguments();
133
                if (buildSpecArgs != null) {
134
                    String buildSpecHandle= (String) buildSpecArgs.get(BuilderCoreUtils.LAUNCH_CONFIG_HANDLE);
135
                    if (handle.equals(buildSpecHandle)) {
136
                        return i;
137
                    }
138
                }
139
            }
140
        }
141
        return -1;
142
    }
143
144
	/**
145
	 * Returns whether the given builder config is enabled or not.
146
	 * 
147
	 * @param config the config to examine
148
	 * @return whether the config is enabled
149
	 */
150
	private boolean configEnabled(ILaunchConfiguration config) {
151
		try {
152
			return ExternalToolsCoreUtil.isBuilderEnabled(config);
153
		} catch (CoreException e) {
154
			ExternalToolsCore.log(e);
155
		}
156
		return true;
157
	}
158
159
	private void doBuildBasedOnScope(IResource[] resources, int kind, ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
160
		boolean buildForChange = true;
161
		if (kind != FULL_BUILD) { //scope not applied for full builds
162
			if (resources != null && resources.length > 0) {
163
				buildForChange = buildScopeIndicatesBuild(resources);
164
			}
165
		}
166
167
		if (buildForChange) {
168
			launchBuild(kind, config, monitor);
169
		}
170
	}
171
	
172
	private void launchBuild(int kind, ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
173
		monitor.subTask(NLS.bind(ExternalToolsModelMessages.ExternalToolBuilder_Running__0_____1, new String[] { config.getName()}));
174
		buildStarted(kind);
175
		// The default value for "launch in background" is true in debug core. If
176
		// the user doesn't go through the UI, the new attribute won't be set. This means
177
		// that existing Ant builders will try to run in the background (and likely conflict with
178
		// each other) without migration.
179
		config= ExternalToolMigration.migrateRunInBackground(config);
180
		config.launch(ILaunchManager.RUN_MODE, monitor);
181
		buildEnded();
182
	}
183
184
	/**
185
	 * Returns the build type being performed if the
186
	 * external tool is being run as a project builder.
187
	 * 
188
	 * @return one of the <code>IExternalToolConstants.BUILD_TYPE_*</code> constants.
189
	 */
190
	public static String getBuildType() {
191
		return buildType;
192
	}
193
	
194
	/**
195
	 * Returns the project that is being built and has triggered the current external
196
	 * tool builder. <code>null</code> is returned if no build is currently occurring.
197
	 * 
198
	 * @return project being built or <code>null</code>.
199
	 */
200
	public static IProject getBuildProject() {
201
		return buildProject;
202
	}
203
204
    /**
205
     * Returns the <code>IResourceDelta</code> that is being built and has triggered the current external
206
     * tool builder. <code>null</code> is returned if no build is currently occurring.
207
     * 
208
     * @return resource delta for the build or <code>null</code>
209
     */
210
    public static IResourceDelta getBuildDelta() {
211
        return buildDelta;
212
    }
213
    
214
	/**
215
	 * Stores the currently active build kind and build project when a build begins
216
	 * @param buildKind
217
	 */
218
	private void buildStarted(int buildKind) {
219
		switch (buildKind) {
220
			case IncrementalProjectBuilder.INCREMENTAL_BUILD :
221
				buildType = IExternalToolConstants.BUILD_TYPE_INCREMENTAL;
222
				buildDelta = getDelta(getProject());
223
				break;
224
			case IncrementalProjectBuilder.FULL_BUILD :
225
				buildType = IExternalToolConstants.BUILD_TYPE_FULL;
226
				break;
227
			case IncrementalProjectBuilder.AUTO_BUILD :
228
				buildType = IExternalToolConstants.BUILD_TYPE_AUTO;
229
				buildDelta = getDelta(getProject());
230
				break;
231
            case IncrementalProjectBuilder.CLEAN_BUILD :
232
                buildType = IExternalToolConstants.BUILD_TYPE_CLEAN;
233
                break;
234
			default :
235
				buildType = IExternalToolConstants.BUILD_TYPE_NONE;
236
				break;
237
		}
238
		buildProject= getProject();
239
	}
240
	
241
	/**
242
	 * Clears the current build kind, build project and build delta when a build finishes.
243
	 */
244
	private void buildEnded() {
245
		buildType= IExternalToolConstants.BUILD_TYPE_NONE;
246
		buildProject= null;
247
        buildDelta= null;
248
	}
249
	
250
	private boolean buildScopeIndicatesBuild(IResource[] resources) {
251
		for (int i = 0; i < resources.length; i++) {
252
			IResourceDelta delta = getDelta(resources[i].getProject());
253
			if (delta == null) {
254
				//project just added to the workspace..no previous build tree
255
				return true;
256
			} 
257
			IPath path= resources[i].getProjectRelativePath();
258
			IResourceDelta change= delta.findMember(path);
259
			if (change != null) {
260
				final boolean[] trueChange= new boolean[1];
261
				trueChange[0]= false;
262
				try {
263
					change.accept(new IgnoreTeamPrivateChanges(trueChange));
264
				} catch (CoreException e) {
265
					ExternalToolsCore.log("Internal error resolving changed resources during build", e); //$NON-NLS-1$
266
				}
267
				
268
				return trueChange[0]; //filtered out team private changes
269
			}
270
		}
271
		return false;
272
	}
273
    
274
    protected void clean(IProgressMonitor monitor) throws CoreException {
275
	    ICommand command= getCommand();
276
        ILaunchConfiguration config= BuilderCoreUtils.configFromBuildCommandArgs(getProject(), command.getArguments(), new String[1]);
277
    	if (!configEnabled(config)) {
278
	    	return;
279
	    }
280
        
281
        if ((!config.getAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, false))) {
282
            //old behavior
283
            super.clean(monitor);
284
            return;
285
        }
286
	
287
		launchBuild(IncrementalProjectBuilder.CLEAN_BUILD, config, monitor);
288
    }
289
}
(-)src/org/eclipse/core/internal/externaltools/model/ExternalToolsModelMessages.java (+28 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.core.internal.externaltools.model;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class ExternalToolsModelMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.ui.externaltools.internal.model.ExternalToolsModelMessages";//$NON-NLS-1$
16
    
17
	public static String ImageDescriptorRegistry_Allocating_image_for_wrong_display_1;
18
	public static String ExternalToolBuilder_Running__0_____1;
19
	public static String ExternalToolBuilder_0;
20
	public static String BuilderUtils_5;
21
	public static String BuilderUtils_6;
22
	public static String BuilderUtils_7;
23
24
	static {
25
		// load message values from bundle file
26
		NLS.initializeMessages(BUNDLE_NAME, ExternalToolsModelMessages.class);
27
	}
28
}
(-)src/org/eclipse/core/internal/externaltools/model/ExternalToolsModelMessages.properties (+17 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
ImageDescriptorRegistry_Allocating_image_for_wrong_display_1=Allocating image for wrong display
13
ExternalToolBuilder_Running__0_____1=Running {0}...
14
ExternalToolBuilder_0=The builder launch configuration could not be found.
15
BuilderUtils_5=Command Error
16
BuilderUtils_6=An error occurred while saving the build commands of the project
17
BuilderUtils_7=\ [Builder]
(-)src/org/eclipse/core/internal/externaltools/model/IExternalToolConstants.java (+236 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     dakshinamurthy.karra@gmail.com - bug 165371
11
 *******************************************************************************/
12
package org.eclipse.core.internal.externaltools.model;
13
14
/**
15
 * Defines the constants available for client use.
16
 * <p>
17
 * This interface is not intended to be extended or implemented by clients.
18
 * </p>
19
 */
20
public interface IExternalToolConstants {
21
	/**
22
	 * Plug-in identifier for external tools UI (value <code>org.eclipse.ui.externaltools</code>).
23
	 */
24
	public static final String UI_PLUGIN_ID = "org.eclipse.ui.externaltools"; //$NON-NLS-1$;
25
	
26
	/**
27
	 * Plug-in identifier for external tools core (value <code>org.eclipse.core.externaltools</code>).
28
	 */
29
	public static final String PLUGIN_ID = "org.eclipse.core.externaltools"; //$NON-NLS-1$;
30
31
	// ------- Extensions Points -------
32
	/**
33
	 * Extension point to declare the launch configuration type that should be
34
	 * created when duplicating an existing configuration as a project builder.
35
	 */
36
	public static final String EXTENSION_POINT_CONFIGURATION_DUPLICATION_MAPS = "configurationDuplicationMaps"; //$NON-NLS-1$
37
	// ------- Refresh Variables -------
38
	/**
39
	 * Variable that expands to the workspace root object (value <code>workspace</code>).
40
	 */
41
	public static final String VAR_WORKSPACE = "workspace"; //$NON-NLS-1$
42
	/**
43
	 * Variable that expands to the project resource (value <code>project</code>).
44
	 */
45
	public static final String VAR_PROJECT = "project"; //$NON-NLS-1$
46
	/**
47
	 * Variable that expands to the container resource (value <code>container</code>).
48
	 */
49
	public static final String VAR_CONTAINER = "container"; //$NON-NLS-1$
50
	/**
51
	 * Variable that expands to a resource (value <code>resource</code>).
52
	 */
53
	public static final String VAR_RESOURCE = "resource"; //$NON-NLS-1$
54
	/**
55
	 * Variable that expands to the working set object (value <code>working_set</code>).
56
	 */
57
	public static final String VAR_WORKING_SET = "working_set"; //$NON-NLS-1$
58
	// ------- Tool Types -------
59
	/**
60
	 * External tool type for programs such as executables, batch files, 
61
	 * shell scripts, etc (value <code>programType</code>).
62
	 */
63
	public static final String TOOL_TYPE_PROGRAM = "programType"; //$NON-NLS-1$;
64
65
	// ------- Build Types -------
66
	/**
67
	 * Build type indicating an incremental project build request for
68
	 * the external tool running as a builder (value <code>incremental</code>).
69
	 */
70
	public static final String BUILD_TYPE_INCREMENTAL = "incremental"; //$NON-NLS-1$
71
72
	/**
73
	 * Build type indicating a full project build request for
74
	 * the external tool running as a builder (value <code>full</code>).
75
	 */
76
	public static final String BUILD_TYPE_FULL = "full"; //$NON-NLS-1$
77
78
	/**
79
	 * Build type indicating an automatic project build request for
80
	 * the external tool running as a builder (value <code>auto</code>).
81
	 */
82
	public static final String BUILD_TYPE_AUTO = "auto"; //$NON-NLS-1$
83
	
84
	/**
85
	 * Build type indicating a clean project build request for
86
	 * the external tool running as a builder (value <code>clean</code>).
87
	 */
88
	public static final String BUILD_TYPE_CLEAN = "clean"; //$NON-NLS-1$
89
90
	/**
91
	 * Build type indicating no project build request for
92
	 * the external tool running as a builder (value <code>none</code>).
93
	 */
94
	public static final String BUILD_TYPE_NONE = "none"; //$NON-NLS-1$
95
96
	// ------- Images -------
97
98
	/**
99
	 * Main tab image.
100
	 */
101
	public static final String IMG_TAB_MAIN = UI_PLUGIN_ID + ".IMG_TAB_MAIN"; //$NON-NLS-1$
102
103
	/**
104
	 * Build tab image
105
	 */
106
	public static final String IMG_TAB_BUILD = UI_PLUGIN_ID + ".IMG_TAB_BUILD"; //$NON-NLS-1$
107
108
	// ------- Launch configuration types --------
109
	/**
110
	 * Program launch configuration type identifier.
111
	 */
112
	public static final String ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"; //$NON-NLS-1$
113
	
114
	/**
115
	 * Program builder launch configuration type identifier. Program project
116
	 * builders are of this type.
117
	 */
118
	public static final String ID_PROGRAM_BUILDER_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType"; //$NON-NLS-1$	
119
	
120
	// ------- Launch configuration category --------
121
	/**
122
	 * Identifier for external tools launch configuration category. Launch
123
	 * configuration types for external tools that appear in the external tools
124
	 * launch configuration dialog should belong to this category.
125
	 */
126
	public static final String ID_EXTERNAL_TOOLS_LAUNCH_CATEGORY = "org.eclipse.ui.externaltools"; //$NON-NLS-1$
127
	/**
128
	 * Identifier for external tools launch configuration builders category.
129
	 * Launch configuration types that can be added as project builders should
130
	 * belong to this category.
131
	 */
132
	public static final String ID_EXTERNAL_TOOLS_BUILDER_LAUNCH_CATEGORY = "org.eclipse.ui.externaltools.builder"; //$NON-NLS-1$
133
134
	// ------- Launch configuration groups --------
135
	/**
136
	 * Identifier for external tools launch configuration group. The external
137
	 * tools launch configuration group corresponds to the external tools
138
	 * category in run mode.
139
	 */
140
	public static final String ID_EXTERNAL_TOOLS_LAUNCH_GROUP = "org.eclipse.ui.externaltools.launchGroup"; //$NON-NLS-1$
141
	/**
142
	 * Identifier for external tools launch configuration group
143
	 */
144
	public static final String ID_EXTERNAL_TOOLS_BUILDER_LAUNCH_GROUP = "org.eclipse.ui.externaltools.launchGroup.builder"; //$NON-NLS-1$
145
146
	// ------- Common External Tool Launch Configuration Attributes -------
147
148
	/**
149
	 * Boolean attribute indicating if external tool output should be captured.
150
	 * Default value is <code>false</code>.
151
	 * @deprecated since 3.1 Replaced by <code>org.eclipse.debug.core.DebugPlugin.ATTR_CAPTURE_OUTPUT</code>
152
	 */
153
	public static final String ATTR_CAPTURE_OUTPUT = UI_PLUGIN_ID + ".ATTR_CAPTURE_OUTPUT"; //$NON-NLS-1$
154
	/**
155
	 * String attribute identifying the location of an external. Default value
156
	 * is <code>null</code>. Encoding is tool specific.
157
	 */
158
	public static final String ATTR_LOCATION = UI_PLUGIN_ID + ".ATTR_LOCATION"; //$NON-NLS-1$
159
160
	/**
161
	 * Boolean attribute indicating if the user should be prompted for
162
	 * arguments before running a tool. Default value is <code>false</code>.
163
	 * THIS ATTRIBUTE IS NOT USED.
164
	 */
165
	public static final String ATTR_PROMPT_FOR_ARGUMENTS = UI_PLUGIN_ID + ".ATTR_PROMPT_FOR_ARGUMENTS"; //$NON-NLS-1$
166
	
167
	/**
168
	 * String attribute identifying the scope of resources that should trigger an 
169
	 * external tool to run. Default value is <code>null</code>
170
	 * indicating that the builder will be triggered for all changes.
171
	 */
172
	public static final String ATTR_BUILDER_SCOPE = UI_PLUGIN_ID + ".ATTR_BUILD_SCOPE"; //$NON-NLS-1$
173
		
174
	/**
175
	 * String attribute containing an array of build kinds for which an
176
	 * external tool builder should be run.
177
	 */
178
	public static final String ATTR_RUN_BUILD_KINDS = UI_PLUGIN_ID + ".ATTR_RUN_BUILD_KINDS"; //$NON-NLS-1$
179
	
180
	/**
181
	 * Boolean attribute indicating if the console should be shown on external
182
	 * tool output. Default value is <code>false</code>.
183
	 */
184
	public static final String ATTR_SHOW_CONSOLE = UI_PLUGIN_ID + ".ATTR_SHOW_CONSOLE"; //$NON-NLS-1$
185
186
	/**
187
	 * String attribute containing the arguments that should be passed to the
188
	 * tool. Default value is <code>null</code>, and encoding is tool specific.
189
	 */
190
	public static final String ATTR_TOOL_ARGUMENTS = UI_PLUGIN_ID + ".ATTR_TOOL_ARGUMENTS"; //$NON-NLS-1$
191
192
	/**
193
	 * String attribute identifying the working directory of an external tool.
194
	 * Default value is <code>null</code>, which indicates a default working
195
	 * directory, which is tool specific.
196
	 */
197
	public static final String ATTR_WORKING_DIRECTORY = UI_PLUGIN_ID + ".ATTR_WORKING_DIRECTORY"; //$NON-NLS-1$
198
	
199
	/**
200
	 * String attribute identifying whether an external tool builder configuration
201
	 * is enabled. The default value is <code>true</code>, which indicates
202
	 * that the configuration will be executed as appropriate by the builder.
203
	 */
204
	public static final String ATTR_BUILDER_ENABLED = UI_PLUGIN_ID + ".ATTR_BUILDER_ENABLED"; //$NON-NLS-1$
205
	
206
	/**
207
	 * Status code indicating an unexpected internal error.
208
	 */
209
	public static final int ERR_INTERNAL_ERROR = 150;
210
211
	/**
212
	 * String attribute identifying a non-external tool builder launch configuration that is disabled
213
	 * The value is the name of the disabled builder.
214
	 */
215
	public static final String ATTR_DISABLED_BUILDER = UI_PLUGIN_ID + ".ATTR_DISABLED_BUILDER";		 //$NON-NLS-1$
216
	
217
	/**
218
	 * boolean attribute identifying that an external tool builder has been configured for triggering
219
	 * using the <code>ICommand.setBuilding(int)</code> mechanism
220
	 * @since 3.1
221
	 */
222
	public static final String ATTR_TRIGGERS_CONFIGURED = UI_PLUGIN_ID + ".ATTR_TRIGGERS_CONFIGURED";		 //$NON-NLS-1$
223
224
	/**
225
	 * String attribute identifying the build scope for a launch configuration.
226
	 * <code>null</code> indicates the default workspace build.
227
	 */
228
	public static final String ATTR_BUILD_SCOPE = UI_PLUGIN_ID + ".ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE"; //$NON-NLS-1$
229
230
	/**
231
	 * Attribute identifier specifying whether referenced projects should be 
232
	 * considered when computing the projects to build. Default value is
233
	 * <code>true</code>.
234
	 */
235
	public static final String ATTR_INCLUDE_REFERENCED_PROJECTS = UI_PLUGIN_ID + ".ATTR_INCLUDE_REFERENCED_PROJECTS"; //$NON-NLS-1$
236
}
(-)src/org/eclipse/core/internal/externaltools/registry/ExternalToolMigration.java (+410 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.internal.externaltools.registry;
12
13
14
import java.util.ArrayList;
15
import java.util.Map;
16
import java.util.StringTokenizer;
17
18
import org.eclipse.core.internal.externaltools.ExternalToolsCore;
19
import org.eclipse.core.internal.externaltools.launchConfigurations.ExternalToolsMigrationMessages;
20
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.debug.core.DebugPlugin;
23
import org.eclipse.debug.core.ILaunchConfiguration;
24
import org.eclipse.debug.core.ILaunchConfigurationType;
25
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
26
import org.eclipse.debug.core.ILaunchManager;
27
28
29
/**
30
 * Responsible reading an old external tool format and creating
31
 * and migrating it to create a new external tool.
32
 */
33
public final class ExternalToolMigration {
34
	/**
35
	 * Structure to represent a variable definition within a
36
	 * source string.
37
	 */
38
	public static final class VariableDefinition {
39
		/**
40
		 * Index in the source text where the variable started
41
		 * or <code>-1</code> if no valid variable start tag 
42
		 * identifier found.
43
		 */
44
		public int start = -1;
45
		
46
		/**
47
		 * Index in the source text of the character following
48
		 * the end of the variable or <code>-1</code> if no 
49
		 * valid variable end tag found.
50
		 */
51
		public int end = -1;
52
		
53
		/**
54
		 * The variable's name found in the source text, or
55
		 * <code>null</code> if no valid variable found.
56
		 */
57
		public String name = null;
58
		
59
		/**
60
		 * The variable's argument found in the source text, or
61
		 * <code>null</code> if no valid variable found or if
62
		 * the variable did not specify an argument
63
		 */
64
		public String argument = null;
65
		
66
		/**
67
		 * Create an initialized variable definition.
68
		 */
69
		private VariableDefinition() {
70
			super();
71
		}
72
	}
73
	
74
	/**
75
	 * Variable tag indentifiers
76
	 */
77
	private static final String VAR_TAG_START = "${"; //$NON-NLS-1$
78
	private static final String VAR_TAG_END = "}"; //$NON-NLS-1$
79
	private static final String VAR_TAG_SEP = ":"; //$NON-NLS-1$	
80
	
81
	/**
82
	 * External tool type for Ant build files (value <code>antBuildType</code>).
83
	 */
84
	public static final String TOOL_TYPE_ANT_BUILD = "antBuildType"; //$NON-NLS-1$;
85
	/**
86
	 * Ant builder launch configuration type identifier. Ant project builders
87
	 * are of this type.
88
	 */
89
	public static final String ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.ant.AntBuilderLaunchConfigurationType"; //$NON-NLS-1$
90
		
91
	public static final String RUN_TARGETS_ATTRIBUTE = TOOL_TYPE_ANT_BUILD + ".runTargets"; //$NON-NLS-1$;
92
93
	/**
94
	* String attribute indicating the Ant targets to execute. Default value is
95
	 * <code>null</code> which indicates that the default target is to be
96
	 * executed. Format is a comma separated listing of targets.
97
	 * NOTE: This value is copied here from org.eclipse.ant.ui.internal.IAntLaunchConfigurationConstants.
98
	 * 		Ant no longer resides in External Tools and this plug-in. This value is kept here only
99
	 * 		for migration.
100
	 */
101
	public static final String ATTR_ANT_TARGETS = IExternalToolConstants.UI_PLUGIN_ID + ".ATTR_ANT_TARGETS"; //$NON-NLS-1$
102
	
103
	/*
104
	 * 2.0 External Tool Tags
105
	 */
106
	public static final String TAG_TOOL_TYPE = "!{tool_type}"; //$NON-NLS-1$
107
	public static final String TAG_TOOL_NAME = "!{tool_name}"; //$NON-NLS-1$
108
	public static final String TAG_TOOL_LOCATION = "!{tool_loc}"; //$NON-NLS-1$
109
	public static final String TAG_TOOL_ARGUMENTS = "!{tool_args}"; //$NON-NLS-1$
110
	public static final String TAG_TOOL_DIRECTORY = "!{tool_dir}"; //$NON-NLS-1$
111
	public static final String TAG_TOOL_REFRESH = "!{tool_refresh}"; //$NON-NLS-1$
112
	public static final String TAG_TOOL_SHOW_LOG = "!{tool_show_log}"; //$NON-NLS-1$
113
	public static final String TAG_TOOL_BUILD_TYPES = "!{tool_build_types}"; //$NON-NLS-1$
114
	public static final String TAG_TOOL_BLOCK = "!{tool_block}"; //$NON-NLS-1$
115
116
	// Known kind of tools
117
	private static final String TOOL_TYPE_ANT = "org.eclipse.ui.externaltools.type.ant"; //$NON-NLS-1$
118
	private static final String TOOL_TYPE_PROGRAM = "org.eclipse.ui.externaltools.type.program"; //$NON-NLS-1$
119
120
	/*
121
	 * 2.1 External Tool Keys
122
	 */
123
	public static final String TAG_TYPE = "type"; //$NON-NLS-1$
124
	public static final String TAG_NAME = "name"; //$NON-NLS-1$
125
	public static final String TAG_LOCATION = "location"; //$NON-NLS-1$
126
	public static final String TAG_WORK_DIR = "workDirectory"; //$NON-NLS-1$
127
	public static final String TAG_CAPTURE_OUTPUT = "captureOutput"; //$NON-NLS-1$
128
	public static final String TAG_SHOW_CONSOLE = "showConsole"; //$NON-NLS-1$
129
	public static final String TAG_RUN_BKGRND = "runInBackground"; //$NON-NLS-1$
130
	public static final String TAG_PROMPT_ARGS = "promptForArguments"; //$NON-NLS-1$
131
	public static final String TAG_ARGS = "arguments"; //$NON-NLS-1$
132
	public static final String TAG_REFRESH_SCOPE = "refreshScope"; //$NON-NLS-1$
133
	public static final String TAG_REFRESH_RECURSIVE = "refreshRecursive"; //$NON-NLS-1$
134
	public static final String TAG_RUN_BUILD_KINDS = "runForBuildKinds"; //$NON-NLS-1$
135
	public static final String TAG_EXTRA_ATTR = "extraAttribute"; //$NON-NLS-1$
136
	public static final String TAG_VERSION = "version"; //$NON-NLS-1$
137
138
	private static final String EXTRA_ATTR_SEPARATOR = "="; //$NON-NLS-1$
139
140
	private static final String VERSION_21 = "2.1"; //$NON-NLS-1$;
141
142
	private static final String TRUE = "true"; //$NON-NLS-1$
143
	private static final String FALSE = "false"; //$NON-NLS-1$
144
145
	/**
146
	 * Allows no instances.
147
	 */
148
	private ExternalToolMigration() {
149
		super();
150
	}
151
152
	/**
153
	 * Returns a  launch configuration working copy from the argument map or
154
	 * <code>null</code> if the given map cannot be interpreted as a 2.0 or 2.1
155
	 * branch external tool. The returned working copy will be unsaved and its
156
	 * location will be set to the metadata area.
157
	 */
158
	public static ILaunchConfigurationWorkingCopy configFromArgumentMap(Map args) {
159
		String version = (String) args.get(TAG_VERSION);
160
		if (VERSION_21.equals(version)) {
161
			return configFrom21ArgumentMap(args);
162
		}
163
		return configFrom20ArgumentMap(args);
164
	}
165
166
	public static ILaunchConfigurationWorkingCopy configFrom21ArgumentMap(Map commandArgs) {
167
		String name = (String) commandArgs.get(TAG_NAME);
168
		String type = (String) commandArgs.get(TAG_TYPE);
169
		
170
		ILaunchConfigurationWorkingCopy config = newConfig(type, name);
171
		if (config == null) {
172
			return null;
173
		}
174
		
175
		config.setAttribute(IExternalToolConstants.ATTR_LOCATION, (String) commandArgs.get(TAG_LOCATION));
176
		config.setAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, (String) commandArgs.get(TAG_WORK_DIR));
177
		config.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, TRUE.equals(commandArgs.get(TAG_CAPTURE_OUTPUT)));
178
		config.setAttribute(IExternalToolConstants.ATTR_SHOW_CONSOLE, TRUE.equals(commandArgs.get(TAG_SHOW_CONSOLE)));
179
		//config.setAttribute(ILaunchManager.ATTR_LAUNCH_IN_BACKGROUND, TRUE.equals(commandArgs.get(TAG_RUN_BKGRND)));
180
		config.setAttribute(IExternalToolConstants.ATTR_PROMPT_FOR_ARGUMENTS, TRUE.equals(commandArgs.get(TAG_PROMPT_ARGS)));
181
		config.setAttribute(ILaunchManager.ATTR_REFRESH_SCOPE, (String) commandArgs.get(TAG_REFRESH_SCOPE));
182
		config.setAttribute(ILaunchManager.ATTR_REFRESH_RECURSIVE, TRUE.equals(commandArgs.get(TAG_REFRESH_RECURSIVE)));
183
184
		config.setAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, (String) commandArgs.get(TAG_RUN_BUILD_KINDS));
185
		
186
		String args = (String) commandArgs.get(TAG_ARGS);
187
		if (args != null) {
188
			config.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, args);
189
		}
190
191
		String extraAttributes = (String) commandArgs.get(TAG_EXTRA_ATTR);
192
		if (extraAttributes != null) {
193
			StringTokenizer tokenizer = new StringTokenizer(extraAttributes, EXTRA_ATTR_SEPARATOR);
194
			while (tokenizer.hasMoreTokens()) {
195
				String key = tokenizer.nextToken();
196
				if (!tokenizer.hasMoreTokens())
197
					break;
198
				String value = tokenizer.nextToken();
199
				if (key.equals(RUN_TARGETS_ATTRIBUTE)) {
200
					// 2.1 implementation only defined 1 "extra attribute"
201
					config.setAttribute(ATTR_ANT_TARGETS, value);
202
				}
203
			}
204
		}
205
		return config;
206
	}
207
208
	/**
209
	 * Creates an external tool from the map.
210
	 */
211
	public static ILaunchConfigurationWorkingCopy configFrom20ArgumentMap(Map args) {
212
		// Update the type...
213
		String type = (String) args.get(TAG_TOOL_TYPE);
214
		if (TOOL_TYPE_ANT.equals(type)) {
215
			type = TOOL_TYPE_ANT_BUILD;
216
		} else if (TOOL_TYPE_PROGRAM.equals(type)){
217
			type = IExternalToolConstants.TOOL_TYPE_PROGRAM;
218
		} else {
219
			return null;
220
		}
221
222
		String name = (String) args.get(TAG_TOOL_NAME);
223
		
224
		ILaunchConfigurationWorkingCopy config = newConfig(type, name);
225
		if (config == null) {
226
			return null;
227
		}
228
229
		// Update the location...
230
		String location = (String) args.get(TAG_TOOL_LOCATION);
231
		config.setAttribute(IExternalToolConstants.ATTR_LOCATION, location);
232
233
		// Update the refresh scope...
234
		String refresh = (String) args.get(TAG_TOOL_REFRESH);
235
		if (refresh != null) {
236
			VariableDefinition varDef = extractVariableDefinition(refresh, 0);
237
			if ("none".equals(varDef.name)) { //$NON-NLS-1$
238
				refresh = null;
239
			}
240
			config.setAttribute(ILaunchManager.ATTR_REFRESH_SCOPE, refresh);
241
		}
242
243
		// Update the arguments
244
		String arguments = (String) args.get(TAG_TOOL_ARGUMENTS);
245
		if (type.equals(TOOL_TYPE_ANT_BUILD)) {
246
			String targetNames = null;
247
			if (arguments != null) {
248
				int start = 0;
249
				ArrayList targets = new ArrayList();
250
				StringBuffer buffer = new StringBuffer();
251
				VariableDefinition varDef = extractVariableDefinition(arguments, start);
252
				while (varDef.end != -1) {
253
					if ("ant_target".equals(varDef.name) && varDef.argument != null) { //$NON-NLS-1$
254
						targets.add(varDef.argument);
255
						buffer.append(arguments.substring(start, varDef.start));
256
					} else {
257
						buffer.append(arguments.substring(start, varDef.end));
258
					}
259
					start = varDef.end;
260
					varDef = extractVariableDefinition(arguments, start);
261
				}
262
				buffer.append(arguments.substring(start, arguments.length()));
263
				arguments = buffer.toString();
264
	
265
				buffer.setLength(0);
266
				for (int i = 0; i < targets.size(); i++) {
267
					String target = (String) targets.get(i);
268
					if (target != null && target.length() > 0) {
269
						buffer.append(target);
270
						buffer.append(","); //$NON-NLS-1$
271
					}
272
				}
273
				targetNames = buffer.toString();
274
			}
275
			if (targetNames != null && targetNames.length() > 0) {
276
				config.setAttribute(ATTR_ANT_TARGETS, targetNames);
277
			}
278
		}
279
		config.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, arguments);
280
281
		// Collect the rest of the information
282
		config.setAttribute(IExternalToolConstants.ATTR_SHOW_CONSOLE, TRUE.equals(args.get(TAG_TOOL_SHOW_LOG)));
283
		config.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, TRUE.equals(args.get(TAG_TOOL_SHOW_LOG)));
284
		//config.setAttribute(ILaunchManager.ATTR_LAUNCH_IN_BACKGROUND, FALSE.equals(args.get(TAG_TOOL_BLOCK)));
285
		String buildKinds= (String) args.get(TAG_TOOL_BUILD_TYPES);
286
		if (buildKinds != null) {
287
			buildKinds= buildKinds.replace(';', ','); // Replace the old separator with the new
288
		}
289
		config.setAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, buildKinds);
290
		config.setAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, (String) args.get(TAG_TOOL_DIRECTORY));
291
		return config;
292
	}
293
294
	/**
295
	 * Returns a new working copy with the given external tool name and external
296
	 * tool type or <code>null</code> if no config could be created.
297
	 */
298
	private static ILaunchConfigurationWorkingCopy newConfig(String type, String name) {
299
		if (type == null || name == null) {
300
			return null;
301
		}
302
		ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
303
		ILaunchConfigurationType configType;
304
		if (TOOL_TYPE_ANT_BUILD.equals(type)) {
305
			configType = manager.getLaunchConfigurationType(ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE);
306
		} else if (IExternalToolConstants.TOOL_TYPE_PROGRAM.equals(type)) {
307
			configType = manager.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_BUILDER_LAUNCH_CONFIGURATION_TYPE);
308
		} else {
309
			return null;
310
		}
311
		try {
312
			if (configType != null) {
313
				return configType.newInstance(null, name);
314
			}
315
		} catch (CoreException e) {
316
			ExternalToolsCore.getDefault().log(e);
317
		}
318
		return null;
319
	}
320
	
321
	/**
322
	 * Returns the tool name extracted from the given command argument map.
323
	 * Extraction is attempted using 2.0 and 2.1 external tool formats.
324
	 */
325
	public static String getNameFromCommandArgs(Map commandArgs) {
326
		String name= (String) commandArgs.get(TAG_NAME);
327
		if (name == null) {
328
			name= (String) commandArgs.get(TAG_TOOL_NAME);
329
		}
330
		return name;
331
	}
332
	
333
	/**
334
	 * Migrate the old RUN_IN_BACKGROUND launch config attribute to the new
335
	 * LAUNCH_IN_BACKGROUND attribute provided by the debug ui plugin.
336
	 * 
337
	 * @param config the config to migrate
338
	 * @return the migrated config
339
	 */
340
	public static ILaunchConfiguration migrateRunInBackground(ILaunchConfiguration config) {
341
		String noValueFlag= "NoValue"; //$NON-NLS-1$
342
		String attr= null;
343
		try {
344
			attr = config.getAttribute(ILaunchManager.ATTR_LAUNCH_IN_BACKGROUND, noValueFlag);
345
		} catch (CoreException e) {
346
			// Exception will occur if the attribute is already set because the attribute is actually a boolean.
347
			// No migration necessary.
348
			return config;
349
		}
350
		if (noValueFlag.equals(attr)) {
351
			//the old constant
352
			String ATTR_RUN_IN_BACKGROUND= IExternalToolConstants.UI_PLUGIN_ID + ".ATTR_RUN_IN_BACKGROUND"; //$NON-NLS-1$
353
			boolean runInBackground= false;
354
			try {
355
				runInBackground = config.getAttribute(ATTR_RUN_IN_BACKGROUND, runInBackground);
356
			} catch (CoreException e) {
357
				ExternalToolsCore.getDefault().log(ExternalToolsMigrationMessages.ExternalToolMigration_37, e);
358
			}
359
			try {
360
				ILaunchConfigurationWorkingCopy workingCopy= config.getWorkingCopy();
361
				workingCopy.setAttribute(ILaunchManager.ATTR_LAUNCH_IN_BACKGROUND, runInBackground);
362
				config= workingCopy.doSave();
363
			} catch (CoreException e) {
364
				ExternalToolsCore.getDefault().log(ExternalToolsMigrationMessages.ExternalToolMigration_38, e);
365
			}
366
		}
367
		return config;
368
	}
369
	
370
	/**
371
	 * Extracts a variable name and argument from the given string.
372
	 * 
373
	 * @param text the source text to parse for a variable tag
374
	 * @param start the index in the string to start the search
375
	 * @return the variable definition
376
	 */
377
	public static VariableDefinition extractVariableDefinition(String text, int start) {
378
		VariableDefinition varDef = new VariableDefinition();
379
		
380
		varDef.start = text.indexOf(VAR_TAG_START, start);
381
		if (varDef.start < 0){
382
			return varDef;
383
		}
384
		start = varDef.start + VAR_TAG_START.length();
385
		
386
		int end = text.indexOf(VAR_TAG_END, start);
387
		if (end < 0) {
388
			return varDef;
389
		}
390
		varDef.end = end + VAR_TAG_END.length();
391
		if (end == start) {
392
			return varDef;
393
		}
394
	
395
		int mid = text.indexOf(VAR_TAG_SEP, start);
396
		if (mid < 0 || mid > end) {
397
			varDef.name = text.substring(start, end);
398
		} else {
399
			if (mid > start) {
400
				varDef.name = text.substring(start, mid);
401
			}
402
			mid = mid + VAR_TAG_SEP.length();
403
			if (mid < end) {
404
				varDef.argument = text.substring(mid, end);
405
			}
406
		}
407
		
408
		return varDef;
409
	}	
410
}
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 23-27 Link Here
23
 org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)",
23
 org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)",
24
 org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)"
24
 org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)"
25
Bundle-ActivationPolicy: lazy
25
Bundle-ActivationPolicy: lazy
26
Import-Package: com.ibm.icu.text
26
Import-Package: com.ibm.icu.text,
27
 org.eclipse.jface.util
27
Bundle-RequiredExecutionEnvironment: J2SE-1.4
28
Bundle-RequiredExecutionEnvironment: J2SE-1.4
(-)core/org/eclipse/debug/core/ILaunchManager.java (-3 / +123 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.debug.core;
11
package org.eclipse.debug.core;
12
12
13
 
14
import java.util.Map;
13
import java.util.Map;
15
14
16
import org.eclipse.core.resources.IFile;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.debug.core.model.IDebugTarget;
19
import org.eclipse.debug.core.model.IDebugTarget;
19
import org.eclipse.debug.core.model.IPersistableSourceLocator;
20
import org.eclipse.debug.core.model.IPersistableSourceLocator;
20
import org.eclipse.debug.core.model.IProcess;
21
import org.eclipse.debug.core.model.IProcess;
Lines 44-49 Link Here
44
	 * @since 3.0
45
	 * @since 3.0
45
	 */
46
	 */
46
	public static final String PROFILE_MODE= "profile"; //$NON-NLS-1$	
47
	public static final String PROFILE_MODE= "profile"; //$NON-NLS-1$	
48
49
	/**
50
	 * Launch configuration attribute - a boolean value indicating whether a
51
	 * configuration should be launched in the background. Default value is
52
	 * <code>true</code>.
53
	 * 
54
	 * @since 3.6
55
	 */
56
	public static final String ATTR_LAUNCH_IN_BACKGROUND = "org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND"; //$NON-NLS-1$
57
58
	/**
59
	 * Launch configuration attribute - a boolean value that indicates if the
60
	 * launch configuration is 'private'. A private configuration is one that
61
	 * does not appear to the user in the launch history or the launch
62
	 * configuration dialog.
63
	 * 
64
	 * @since 3.6
65
	 */
66
	public static final String ATTR_PRIVATE = "org.eclipse.debug.ui.private"; //$NON-NLS-1$
67
68
	/**
69
	 * String attribute identifying a scope of resources that should be
70
	 * refreshed - for example, after an external tool is run. The value is either
71
	 * a refresh variable or the default value, <code>null</code>, indicating no
72
	 * refresh.
73
	 * 
74
	 * @since 3.6
75
	 */
76
	public static final String ATTR_REFRESH_SCOPE = DebugPlugin.getUniqueIdentifier() + ".ATTR_REFRESH_SCOPE"; //$NON-NLS-1$
77
78
	/**
79
	 * Boolean attribute indicating if a refresh scope is recursive. Default
80
	 * value is <code>true</code>.
81
	 * 
82
	 * @since 3.6
83
	 */
84
	public static final String ATTR_REFRESH_RECURSIVE = DebugPlugin.getUniqueIdentifier() + ".ATTR_REFRESH_RECURSIVE"; //$NON-NLS-1$
85
86
	/**
87
	 * Resource memento referring to the selected resource's project.
88
	 * Only works when the debug user interface is running.
89
	 * 
90
	 * @since 3.6
91
	 * @see ILaunchManager#toResources(String)
92
	 */
93
	public static final String MEMENTO_SELECTED_PROJECT = "${project}"; //$NON-NLS-1$
94
	
95
	/**
96
	 * Resource memento referring to the selected resource's container.
97
	 * Only works when the debug user interface is running.
98
	 * 
99
	 * @since 3.6
100
	 * @see ILaunchManager#toResources(String)
101
	 */	
102
	public static final String MEMENTO_SELECTED_CONTAINER = "${container}"; //$NON-NLS-1$
103
	
104
	/**
105
	 * Resource memento referring to the selected resource.
106
	 * Only works when the debug user interface is running.
107
	 * 
108
	 * @since 3.6
109
	 * @see ILaunchManager#toResources(String)
110
	 */	
111
	public static final String MEMENTO_SELECTED_RESOURCE = "${resource}"; //$NON-NLS-1$
112
	
113
	/**
114
	 * Resource memento referring to the workspace root.
115
	 * 
116
	 * @since 3.6
117
	 * @see ILaunchManager#toResources(String)
118
	 */	
119
	public static final String MEMENTO_WORKSPACE = "${workspace}"; //$NON-NLS-1$
47
	
120
	
48
	/**
121
	/**
49
	 * Launch configuration attribute name. The value is a map of environment
122
	 * Launch configuration attribute name. The value is a map of environment
Lines 515-521 Link Here
515
	 * @param listener the listener to unregister
588
	 * @param listener the listener to unregister
516
	 */
589
	 */
517
	public void removeLaunchListener(ILaunchListener listener);
590
	public void removeLaunchListener(ILaunchListener listener);
518
	
519
}
520
591
592
	/**
593
	 * Returns whether the given configuration should be launched in the
594
	 * background.
595
	 * 
596
	 * @param configuration
597
	 *            the configuration
598
	 * @return whether the configuration is configured to launch in the
599
	 *         background
600
	 * @since 3.6
601
	 */
602
	public boolean isLaunchInBackground(ILaunchConfiguration configuration);
603
604
	/**
605
	 * Refreshes the resources as specified by the given launch configuration.
606
	 * 
607
	 * @param configuration
608
	 *            launch configuration
609
	 * @param monitor
610
	 *            progress monitor which may be <code>null</code>
611
	 * @throws CoreException
612
	 *             if an exception occurs while refreshing resources
613
	 * @since 3.6
614
	 */
615
	public void refreshResources(ILaunchConfiguration configuration,
616
			IProgressMonitor monitor) throws CoreException;
617
618
	/**
619
	 * Returns a collection of resources referred to by the specified
620
	 * memento generated via {@link #toMemento(IResource[])}.
621
	 * 
622
	 * @param memento
623
	 *            resource memento generated by this manager
624
	 * @return collection of resources referred to by the memento
625
	 * @throws CoreException
626
	 *             if unable to resolve a set of resources
627
	 * @since 3.6
628
	 */
629
	public IResource[] toResources(String memento) throws CoreException;
630
	
631
	/**
632
	 * Returns a memento for a collection of resources that can be restored
633
	 * via {@link #toResources(String)}.
634
	 * 
635
	 * @param resources resources to create a memento for
636
	 * @return memento for the given resources
637
	 * @since 3.6
638
	 */
639
	public String toMemento(IResource[] resources);	
521
640
641
}
(-)core/org/eclipse/debug/internal/core/DebugCoreMessages.java (+3 lines)
Lines 113-118 Link Here
113
	public static String RuntimeProcess_Exit_value_not_available_until_process_terminates__1;
113
	public static String RuntimeProcess_Exit_value_not_available_until_process_terminates__1;
114
	public static String WatchExpression_0;
114
	public static String WatchExpression_0;
115
	public static String NullStreamsProxy_0;
115
	public static String NullStreamsProxy_0;
116
	
117
	public static String RefreshingResources;
118
	public static String RefreshingResourcesError;
116
119
117
	static {
120
	static {
118
		// load message values from bundle file
121
		// load message values from bundle file
(-)core/org/eclipse/debug/internal/core/DebugCoreMessages.properties (+18 lines)
Lines 100-102 Link Here
100
LaunchConfigurationType_7=Launch mode not supported: {0}
100
LaunchConfigurationType_7=Launch mode not supported: {0}
101
WatchExpression_0=(Watch expressions not supported)
101
WatchExpression_0=(Watch expressions not supported)
102
NullStreamsProxy_0=Null Stream Monitor
102
NullStreamsProxy_0=Null Stream Monitor
103
RefreshingResources=Refresh resources...
104
RefreshingResourcesError=Exception(s) occurred during refresh.
105
RefreshingResources=Refresh resources...
106
RefreshingResourcesError=Exception(s) occurred during refresh.
107
RefreshingResources=Refresh resources...
108
RefreshingResourcesError=Exception(s) occurred during refresh.
109
RefreshingResources=Refresh resources...
110
RefreshingResourcesError=Exception(s) occurred during refresh.
111
RefreshingResources=Refresh resources...
112
RefreshingResourcesError=Exception(s) occurred during refresh.
113
RefreshingResources=Refresh resources...
114
RefreshingResourcesError=Exception(s) occurred during refresh.
115
RefreshingResources=Refresh resources...
116
RefreshingResourcesError=Exception(s) occurred during refresh.
117
RefreshingResources=Refresh resources...
118
RefreshingResourcesError=Exception(s) occurred during refresh.
119
RefreshingResources=Refresh resources...
120
RefreshingResourcesError=Exception(s) occurred during refresh.
(-)core/org/eclipse/debug/internal/core/IMementoConstants.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.core;
12
13
public interface IMementoConstants {
14
	// These persistence constant is stored in XML. Do not
15
	// change it.
16
	public static final String TAG_FACTORY_ID = "factoryID"; //$NON-NLS-1$
17
	
18
	public static final String TAG_EDITOR_STATE = "editorState"; //$NON-NLS-1$
19
20
	public static final String MEMENTO_ITEM = "item"; //$NON-NLS-1$
21
22
	public static final String TAG_EDIT_PAGE_ID = "editPageId"; //$NON-NLS-1$
23
24
	public static final String TAG_NAME = "name"; //$NON-NLS-1$
25
26
	public static final String TAG_LABEL = "label"; //$NON-NLS-1$
27
28
	public static final String TAG_ID = "id"; //$NON-NLS-1$
29
30
	public static final String TAG_LAUNCH_CONFIGURATION_WORKING_SET = "launchConfigurationWorkingSet"; //$NON-NLS-1$
31
32
}
(-)core/org/eclipse/debug/internal/core/LaunchManager.java (+180 lines)
Lines 25-30 Link Here
25
import java.io.IOException;
25
import java.io.IOException;
26
import java.io.InputStream;
26
import java.io.InputStream;
27
import java.io.InputStreamReader;
27
import java.io.InputStreamReader;
28
import java.io.StringReader;
29
import java.io.StringWriter;
28
import java.util.ArrayList;
30
import java.util.ArrayList;
29
import java.util.Arrays;
31
import java.util.Arrays;
30
import java.util.Collection;
32
import java.util.Collection;
Lines 78-83 Link Here
78
import org.eclipse.core.runtime.PlatformObject;
80
import org.eclipse.core.runtime.PlatformObject;
79
import org.eclipse.core.runtime.SafeRunner;
81
import org.eclipse.core.runtime.SafeRunner;
80
import org.eclipse.core.runtime.Status;
82
import org.eclipse.core.runtime.Status;
83
import org.eclipse.core.variables.IStringVariableManager;
81
import org.eclipse.core.variables.VariablesPlugin;
84
import org.eclipse.core.variables.VariablesPlugin;
82
import org.eclipse.debug.core.DebugException;
85
import org.eclipse.debug.core.DebugException;
83
import org.eclipse.debug.core.DebugPlugin;
86
import org.eclipse.debug.core.DebugPlugin;
Lines 180-185 Link Here
180
	 */
183
	 */
181
	private StepFilterManager fStepFilterManager = null;
184
	private StepFilterManager fStepFilterManager = null;
182
	
185
	
186
	// indicates no working set has been selected
187
	private static final String NO_WORKING_SET = "NONE"; //$NON-NLS-1$
188
	
183
	/**
189
	/**
184
	 * Notifies a launch config listener in a safe runnable to handle
190
	 * Notifies a launch config listener in a safe runnable to handle
185
	 * exceptions.
191
	 * exceptions.
Lines 2657-2660 Link Here
2657
		}
2663
		}
2658
		return true;
2664
		return true;
2659
	}	
2665
	}	
2666
	
2667
	/**
2668
	 * Returns whether the given configuration should be launched in the
2669
	 * background.
2670
	 * 
2671
	 * @param configuration
2672
	 *            the configuration
2673
	 * @return whether the configuration is configured to launch in the
2674
	 *         background
2675
	 */
2676
	public boolean isLaunchInBackground(ILaunchConfiguration configuration) {
2677
		boolean launchInBackground = true;
2678
		try {
2679
			launchInBackground = configuration.getAttribute(
2680
					ILaunchManager.ATTR_LAUNCH_IN_BACKGROUND, true);
2681
		} catch (CoreException ce) {
2682
			DebugPlugin.log(ce);
2683
		}
2684
		return launchInBackground;
2685
	}
2686
2687
	public void refreshResources(ILaunchConfiguration configuration,
2688
			IProgressMonitor monitor) throws CoreException {
2689
		if (monitor == null) {
2690
			monitor = new NullProgressMonitor();
2691
		}
2692
		String scope = configuration.getAttribute(ATTR_REFRESH_SCOPE, (String) null);
2693
		IResource[] resources = null;
2694
		if (scope != null) {
2695
			resources = toResources(scope);
2696
		}
2697
		if (resources == null || resources.length == 0) {
2698
			return;
2699
		}
2700
		int depth = IResource.DEPTH_ONE;
2701
		if (isRefreshRecursive(configuration))
2702
			depth = IResource.DEPTH_INFINITE;
2703
2704
		if (monitor.isCanceled()) {
2705
			return;
2706
		}
2707
2708
		monitor.beginTask(DebugCoreMessages.RefreshingResources,
2709
				resources.length);
2710
2711
		MultiStatus status = new MultiStatus(DebugPlugin.getUniqueIdentifier(),
2712
				0, DebugCoreMessages.RefreshingResourcesError, null);
2713
		for (int i = 0; i < resources.length; i++) {
2714
			if (monitor.isCanceled())
2715
				break;
2716
			if (resources[i] != null && resources[i].isAccessible()) {
2717
				try {
2718
					resources[i].refreshLocal(depth, null);
2719
				} catch (CoreException e) {
2720
					status.merge(e.getStatus());
2721
				}
2722
			}
2723
			monitor.worked(1);
2724
		}
2725
2726
		monitor.done();
2727
		if (!status.isOK()) {
2728
			throw new CoreException(status);
2729
		}
2730
	}
2731
2732
	/* (non-Javadoc)
2733
	 * @see org.eclipse.debug.core.ILaunchManager#toResources(java.lang.String)
2734
	 */
2735
	public IResource[] toResources(String scope) throws CoreException {
2736
		if (scope.startsWith("${resource:")) { //$NON-NLS-1$
2737
			// This is an old format that is replaced with 'working_set'
2738
			String pathString = scope.substring(11, scope.length() - 1);
2739
			Path path = new Path(pathString);
2740
			IResource resource = ResourcesPlugin.getWorkspace().getRoot()
2741
					.findMember(path);
2742
			if (resource == null) {
2743
				throw new CoreException(new Status(IStatus.ERROR, DebugPlugin
2744
						.getUniqueIdentifier(), IStatus.ERROR, MessageFormat
2745
						.format(StringSubstitutionMessages.RefreshTab_43,
2746
								new String[] { pathString }), null));
2747
			}
2748
			return new IResource[] { resource };
2749
		} else if (scope.startsWith("${working_set:")) { //$NON-NLS-1$
2750
			String memento = scope.substring(14, scope.length() - 1);
2751
			return getResources(memento);
2752
		} else if (scope.equals(ILaunchManager.MEMENTO_WORKSPACE)) {
2753
			return new IResource[] { ResourcesPlugin.getWorkspace().getRoot() };
2754
		} else {
2755
			// result the selected resource for backwards compatibility
2756
			IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
2757
			IResource resource = null;
2758
			try {
2759
				String pathString = manager.performStringSubstitution("${selected_resource_path}"); //$NON-NLS-1$
2760
				resource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(pathString));
2761
			} catch (CoreException e) {
2762
				// unable to resolve a resource
2763
			}
2764
			if (resource != null) {
2765
				if (scope.equals(ILaunchManager.MEMENTO_SELECTED_RESOURCE)) {
2766
					return new IResource[] { resource };
2767
				} else if (scope.equals(ILaunchManager.MEMENTO_SELECTED_CONTAINER)) {
2768
					return new IResource[] {resource.getParent()};
2769
				} else if (scope.equals(ILaunchManager.MEMENTO_SELECTED_PROJECT)) {
2770
					return new IResource[] {resource.getProject()};
2771
				}
2772
			}
2773
		}
2774
		throw new CoreException(new Status(IStatus.ERROR, DebugPlugin.getUniqueIdentifier(), MessageFormat.format("Unable to restore resource memento: {0}", new String[]{scope})));
2775
	}
2776
2777
	public static IResource[] getResources(String mementoString) {
2778
2779
		if (NO_WORKING_SET.equals(mementoString)) {
2780
			return null;
2781
		}
2782
2783
		List resourcesList = new ArrayList();
2784
		StringReader reader = new StringReader(mementoString);
2785
2786
		XMLMemento memento = null;
2787
		try {
2788
			memento = XMLMemento.createReadRoot(reader);
2789
		} catch (Exception e) {
2790
			DebugPlugin.log(e);
2791
			return null;
2792
		}
2793
2794
		XMLMemento[] mementos = memento
2795
				.getChildren(IMementoConstants.MEMENTO_ITEM);
2796
		for (int i = 0; i < mementos.length; i++) {
2797
			resourcesList.add(ResourceFactory.createElement(mementos[i]));
2798
		}
2799
2800
		return (IResource[]) resourcesList.toArray(new IResource[resourcesList
2801
				.size()]);
2802
2803
	}
2804
2805
	/**
2806
	 * Returns whether the refresh scope specified by the given launch
2807
	 * configuration is recursive.
2808
	 * 
2809
	 * @param configuration
2810
	 * @return whether the refresh scope is recursive
2811
	 * @throws CoreException
2812
	 *             if unable to access the associated attribute
2813
	 */
2814
	private boolean isRefreshRecursive(ILaunchConfiguration configuration)
2815
			throws CoreException {
2816
		return configuration.getAttribute(ATTR_REFRESH_RECURSIVE, true);
2817
	}
2818
2819
	/* (non-Javadoc)
2820
	 * @see org.eclipse.debug.core.ILaunchManager#toMemento(org.eclipse.core.resources.IResource[])
2821
	 */
2822
	public String toMemento(IResource[] resources) {
2823
		XMLMemento memento = XMLMemento.createWriteRoot("resources"); //$NON-NLS-1$
2824
		for (int i = 0; i < resources.length; i++) {
2825
			final XMLMemento itemMemento = memento.createChild(IMementoConstants.MEMENTO_ITEM);
2826
			ResourceFactory.saveState(itemMemento, resources[i]);
2827
		}
2828
		StringWriter writer = new StringWriter();
2829
		try {
2830
			memento.save(writer);
2831
		} catch (IOException e) {
2832
			DebugPlugin.log(e);
2833
		}
2834
		StringBuffer buf = new StringBuffer();
2835
		buf.append("${working_set:"); //$NON-NLS-1$
2836
		buf.append(writer.toString());
2837
		buf.append("}"); //$NON-NLS-1$
2838
		return buf.toString();
2839
	}	
2660
}
2840
}
(-)core/org/eclipse/debug/internal/core/ResourceFactory.java (+73 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.core;
12
13
14
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IWorkspaceRoot;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.Path;
19
20
/**
21
 * The ResourceFactory is used to save and recreate an IResource object.
22
 * As such, it implements the IPersistableElement interface for storage
23
 * and the IElementFactory interface for recreation.
24
 */
25
public class ResourceFactory {
26
27
    // These persistence constants are stored in XML.  Do not
28
    // change them.
29
    public static final String TAG_PATH = "path";//$NON-NLS-1$
30
31
    public static final String TAG_TYPE = "type";//$NON-NLS-1$
32
33
    /**
34
     * Creates and returns an element based on the given memento
35
     * 
36
     * @param memento element memento
37
     * @return associated element
38
     */
39
    public static IAdaptable createElement(XMLMemento memento) {
40
        // Get the file name.
41
        String fileName = memento.getString(TAG_PATH);
42
        if (fileName == null) {
43
			return null;
44
		}
45
46
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
47
        String type = memento.getString(TAG_TYPE);
48
        IResource res = null;
49
        if (type == null) {
50
            // Old format memento. Create an IResource using findMember. 
51
            // Will return null for resources in closed projects.
52
            res = root.findMember(new Path(fileName));
53
        } else {
54
            int resourceType = Integer.parseInt(type);
55
56
            if (resourceType == IResource.ROOT) {
57
				res = root;
58
			} else if (resourceType == IResource.PROJECT) {
59
				res = root.getProject(fileName);
60
			} else if (resourceType == IResource.FOLDER) {
61
				res = root.getFolder(new Path(fileName));
62
			} else if (resourceType == IResource.FILE) {
63
				res = root.getFile(new Path(fileName));
64
			}
65
        }
66
        return res;
67
    }
68
69
    public static void saveState(XMLMemento memento, IResource res) {
70
        memento.putString(TAG_PATH, res.getFullPath().toString());
71
        memento.putString(TAG_TYPE, Integer.toString(res.getType()));
72
    }
73
}
(-)core/org/eclipse/debug/internal/core/StringSubstitutionMessages.java (+60 lines)
Added Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved.   This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.debug.internal.core;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class StringSubstitutionMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.stringsubstitution.StringSubstitutionMessages";//$NON-NLS-1$
16
17
	public static String PromptExpanderBase_0;
18
	public static String PromptExpanderBase_1;
19
	public static String PromptingResolver_0;
20
21
	public static String RefreshTab_0;
22
23
	public static String RefreshTab_43;
24
25
	public static String RefreshTab_44;
26
	public static String RefreshTab_6;
27
	public static String RefreshTab_7;
28
	public static String RefreshTab_8;
29
	public static String RefreshTab_31;
30
	public static String RefreshTab_32;
31
	public static String RefreshTab_33;
32
	public static String RefreshTab_34;
33
	public static String RefreshTab_35;
34
	public static String RefreshTab_36;
35
	public static String RefreshTab_37;
36
	public static String RefreshTab_40;
37
	public static String RefreshTab_42;
38
39
	public static String ResourceSelector_0;
40
41
	public static String SelectedResourceResolver_0;
42
43
	public static String StringPromptExpander_0;
44
45
	public static String StringVariableSelectionDialog_2;
46
	public static String StringVariableSelectionDialog_3;
47
	public static String StringVariableSelectionDialog_6;
48
	public static String StringVariableSelectionDialog_7;
49
	public static String StringVariableSelectionDialog_8;
50
	public static String StringVariableSelectionDialog_0;
51
52
	static {
53
		// load message values from bundle file
54
		NLS.initializeMessages(BUNDLE_NAME, StringSubstitutionMessages.class);
55
	}
56
57
	public static String SystemPropertyArgumentSelector_0;
58
59
	public static String SystemPropertyArgumentSelector_1;
60
}
(-)core/org/eclipse/debug/internal/core/StringSubstitutionMessages.properties (+44 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
12
PromptExpanderBase_0=Please input a value for {0}
13
PromptExpanderBase_1=Please input a value
14
PromptingResolver_0=Failed to expand {0}. Input was cancelled.
15
16
RefreshTab_0=Recursively &include sub-folders
17
RefreshTab_6=Refresh
18
RefreshTab_7=Refresh resources...
19
RefreshTab_8=Exception(s) occurred during refresh.
20
RefreshTab_31=Refresh resources &upon completion.
21
RefreshTab_32=The &entire workspace
22
RefreshTab_33=The se&lected resource
23
RefreshTab_34=The &project containing the selected resource
24
RefreshTab_35=The f&older containing the selected resource
25
RefreshTab_36=&Specific resources
26
RefreshTab_37=Specify &Resources...
27
RefreshTab_40=working set
28
RefreshTab_42=Must select resources to refresh.
29
RefreshTab_43=Refresh scope refers to non-existent resource {0}
30
RefreshTab_44=Refresh scope invalid
31
32
ResourceSelector_0=Select Resource
33
34
SelectedResourceResolver_0=Unable to resource a selected resource: {0}
35
StringPromptExpander_0=Variable input
36
37
StringVariableSelectionDialog_2=Select Variable
38
StringVariableSelectionDialog_3=&Choose a variable (? = any character, * = any string):
39
StringVariableSelectionDialog_6=&Argument:
40
StringVariableSelectionDialog_7=C&onfigure...
41
StringVariableSelectionDialog_8=&Variable Description:
42
StringVariableSelectionDialog_0=&Edit Variables...
43
SystemPropertyArgumentSelector_0=Select System Property
44
SystemPropertyArgumentSelector_1=Select a system property (? = any character, * = any String):
(-)core/org/eclipse/debug/internal/core/XMLMemento.java (+606 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.core;
12
13
14
import java.io.IOException;
15
import java.io.PrintWriter;
16
import java.io.Reader;
17
import java.io.Writer;
18
import java.util.ArrayList;
19
20
import javax.xml.parsers.DocumentBuilder;
21
import javax.xml.parsers.DocumentBuilderFactory;
22
import javax.xml.parsers.ParserConfigurationException;
23
24
import org.eclipse.debug.core.DebugPlugin;
25
import org.w3c.dom.Attr;
26
import org.w3c.dom.Document;
27
import org.w3c.dom.Element;
28
import org.w3c.dom.NamedNodeMap;
29
import org.w3c.dom.Node;
30
import org.w3c.dom.NodeList;
31
import org.w3c.dom.Text;
32
import org.xml.sax.InputSource;
33
import org.xml.sax.SAXException;
34
35
/**
36
 * An XML memento. Copied from workspace plug-in.
37
 */
38
public final class XMLMemento {
39
    private Document factory;
40
41
    private Element element;
42
43
    /**
44
     * Creates a <code>Document</code> from the <code>Reader</code>
45
     * and returns a memento on the first <code>Element</code> for reading
46
     * the document.
47
     * <p>
48
     * Same as calling createReadRoot(reader, null)
49
     * </p>
50
     * 
51
     * @param reader the <code>Reader</code> used to create the memento's document
52
     * @return a memento on the first <code>Element</code> for reading the document
53
     * @throws Exception if IO problems, invalid format, or no element.
54
     */
55
    public static XMLMemento createReadRoot(Reader reader)
56
            throws Exception {
57
        return createReadRoot(reader, null);
58
    }
59
60
    /**
61
     * Creates a <code>Document</code> from the <code>Reader</code>
62
     * and returns a memento on the first <code>Element</code> for reading
63
     * the document.
64
     * 
65
     * @param reader the <code>Reader</code> used to create the memento's document
66
     * @param baseDir the directory used to resolve relative file names
67
     * 		in the XML document. This directory must exist and include the
68
     * 		trailing separator. The directory format, including the separators,
69
     * 		must be valid for the platform. Can be <code>null</code> if not
70
     * 		needed.
71
     * @return a memento on the first <code>Element</code> for reading the document
72
     * @throws Exception if IO problems, invalid format, or no element.
73
     */
74
    public static XMLMemento createReadRoot(Reader reader, String baseDir)
75
            throws Exception {
76
        String errorMessage = null;
77
        Exception exception = null;
78
79
        try {
80
            DocumentBuilderFactory factory = DocumentBuilderFactory
81
                    .newInstance();
82
            DocumentBuilder parser = factory.newDocumentBuilder();
83
            InputSource source = new InputSource(reader);
84
            if (baseDir != null) {
85
				source.setSystemId(baseDir);
86
			}
87
            Document document = parser.parse(source);
88
            NodeList list = document.getChildNodes();
89
            for (int i = 0; i < list.getLength(); i++) {
90
                Node node = list.item(i);
91
                if (node instanceof Element) {
92
					return new XMLMemento(document, (Element) node);
93
				}
94
            }
95
        } catch (ParserConfigurationException e) {
96
            exception = e;
97
           // errorMessage = WorkbenchMessages.XMLMemento_parserConfigError;
98
        } catch (IOException e) {
99
            exception = e;
100
           // errorMessage = WorkbenchMessages.XMLMemento_ioError; 
101
        } catch (SAXException e) {
102
            exception = e;
103
           // errorMessage = WorkbenchMessages.XMLMemento_formatError; 
104
        }
105
106
        String problemText = null;
107
        if (exception != null) {
108
			problemText = exception.getMessage();
109
		}
110
        if (problemText == null || problemText.length() == 0) {
111
			problemText = errorMessage != null ? errorMessage
112
                    :"ERROR"; //;WorkbenchMessages.XMLMemento_noElement; //$NON-NLS-1$
113
		} 
114
        throw new Exception(problemText, exception);
115
    }
116
117
    /**
118
     * Returns a root memento for writing a document.
119
     * 
120
     * @param type the element node type to create on the document
121
     * @return the root memento for writing a document
122
     */
123
    public static XMLMemento createWriteRoot(String type) {
124
        Document document;
125
        try {
126
            document = DocumentBuilderFactory.newInstance()
127
                    .newDocumentBuilder().newDocument();
128
            Element element = document.createElement(type);
129
            document.appendChild(element);
130
            return new XMLMemento(document, element);
131
        } catch (ParserConfigurationException e) {
132
//            throw new Error(e);
133
            throw new Error(e.getMessage());
134
        }
135
    }
136
137
    /**
138
     * Creates a memento for the specified document and element.
139
     * <p>
140
     * Clients should use <code>createReadRoot</code> and
141
     * <code>createWriteRoot</code> to create the initial
142
     * memento on a document.
143
     * </p>
144
     * 
145
     * @param document the document for the memento
146
     * @param element the element node for the memento
147
     */
148
    public XMLMemento(Document document, Element element) {
149
        super();
150
        this.factory = document;
151
        this.element = element;
152
    }
153
154
    /* (non-Javadoc)
155
     * Method declared in XMLMemento.
156
     */
157
    public XMLMemento createChild(String type) {
158
        Element child = factory.createElement(type);
159
        element.appendChild(child);
160
        return new XMLMemento(factory, child);
161
    }
162
163
    /* (non-Javadoc)
164
     * Method declared in XMLMemento.
165
     */
166
    public XMLMemento createChild(String type, String id) {
167
        Element child = factory.createElement(type);
168
        child.setAttribute(IMementoConstants.TAG_ID, id == null ? "" : id); //$NON-NLS-1$
169
        element.appendChild(child);
170
        return new XMLMemento(factory, child);
171
    }
172
173
    /* (non-Javadoc)
174
     * Method declared in XMLMemento.
175
     */
176
    public XMLMemento copyChild(XMLMemento child) {
177
        Element childElement = ((XMLMemento) child).element;
178
        Element newElement = (Element) factory.importNode(childElement, true);
179
        element.appendChild(newElement);
180
        return new XMLMemento(factory, newElement);
181
    }
182
183
    /* (non-Javadoc)
184
     * Method declared in XMLMemento.
185
     */
186
    public XMLMemento getChild(String type) {
187
188
        // Get the nodes.
189
        NodeList nodes = element.getChildNodes();
190
        int size = nodes.getLength();
191
        if (size == 0) {
192
			return null;
193
		}
194
195
        // Find the first node which is a child of this node.
196
        for (int nX = 0; nX < size; nX++) {
197
            Node node = nodes.item(nX);
198
            if (node instanceof Element) {
199
                Element element = (Element) node;
200
                if (element.getNodeName().equals(type)) {
201
					return new XMLMemento(factory, element);
202
				}
203
            }
204
        }
205
206
        // A child was not found.
207
        return null;
208
    }
209
210
    /* (non-Javadoc)
211
     * Method declared in XMLMemento.
212
     */
213
    public XMLMemento[] getChildren(String type) {
214
215
        // Get the nodes.
216
        NodeList nodes = element.getChildNodes();
217
        int size = nodes.getLength();
218
        if (size == 0) {
219
			return new XMLMemento[0];
220
		}
221
222
        // Extract each node with given type.
223
        ArrayList list = new ArrayList(size);
224
        for (int nX = 0; nX < size; nX++) {
225
            Node node = nodes.item(nX);
226
            if (node instanceof Element) {
227
                Element element = (Element) node;
228
                if (element.getNodeName().equals(type)) {
229
					list.add(element);
230
				}
231
            }
232
        }
233
234
        // Create a memento for each node.
235
        size = list.size();
236
        XMLMemento[] results = new XMLMemento[size];
237
        for (int x = 0; x < size; x++) {
238
            results[x] = new XMLMemento(factory, (Element) list.get(x));
239
        }
240
        return results;
241
    }
242
243
    /* (non-Javadoc)
244
     * Method declared in XMLMemento.
245
     */
246
    public Float getFloat(String key) {
247
        Attr attr = element.getAttributeNode(key);
248
        if (attr == null) {
249
			return null;
250
		}
251
        String strValue = attr.getValue();
252
        try {
253
            return new Float(strValue);
254
        } catch (NumberFormatException e) {
255
           DebugPlugin.logMessage("Memento problem - Invalid float for key: " //$NON-NLS-1$
256
                    + key + " value: " + strValue, e); //$NON-NLS-1$
257
            return null;
258
        }
259
    }
260
261
	/**
262
	 * @since 3.4
263
	 */
264
	public String getType() {
265
		return element.getNodeName();
266
	}
267
268
    /* (non-Javadoc)
269
     * Method declared in XMLMemento.
270
     */
271
    public String getID() {
272
        return element.getAttribute(IMementoConstants.TAG_ID);
273
    }
274
275
    /* (non-Javadoc)
276
     * Method declared in XMLMemento.
277
     */
278
    public Integer getInteger(String key) {
279
        Attr attr = element.getAttributeNode(key);
280
        if (attr == null) {
281
			return null;
282
		}
283
        String strValue = attr.getValue();
284
        try {
285
            return new Integer(strValue);
286
        } catch (NumberFormatException e) {
287
            DebugPlugin
288
                    .logMessage("Memento problem - invalid integer for key: " + key //$NON-NLS-1$
289
                            + " value: " + strValue, e); //$NON-NLS-1$
290
            return null;
291
        }
292
    }
293
294
    /* (non-Javadoc)
295
     * Method declared in XMLMemento.
296
     */
297
    public String getString(String key) {
298
        Attr attr = element.getAttributeNode(key);
299
        if (attr == null) {
300
			return null;
301
		}
302
        return attr.getValue();
303
    }
304
305
	/**
306
	 * @since 3.4
307
	 */
308
	public Boolean getBoolean(String key) {
309
        Attr attr = element.getAttributeNode(key);
310
        if (attr == null) {
311
			return null;
312
		}
313
        return Boolean.valueOf(attr.getValue());
314
	}
315
316
    /* (non-Javadoc)
317
     * Method declared in XMLMemento.
318
     */
319
    public String getTextData() {
320
        Text textNode = getTextNode();
321
        if (textNode != null) {
322
            return textNode.getData();
323
        }
324
        return null;
325
    }
326
327
	/**
328
	 * @since 3.4
329
	 */
330
	public String[] getAttributeKeys() {
331
		NamedNodeMap map = element.getAttributes();
332
		int size = map.getLength();
333
		String[] attributes = new String[size];
334
		for (int i = 0; i < size; i++) {
335
			Node node = map.item(i);
336
			attributes[i] = node.getNodeName();
337
		}
338
		return attributes;
339
	}
340
341
    /**
342
     * Returns the Text node of the memento. Each memento is allowed only 
343
     * one Text node.
344
     * 
345
     * @return the Text node of the memento, or <code>null</code> if
346
     * the memento has no Text node.
347
     */
348
    private Text getTextNode() {
349
        // Get the nodes.
350
        NodeList nodes = element.getChildNodes();
351
        int size = nodes.getLength();
352
        if (size == 0) {
353
			return null;
354
		}
355
        for (int nX = 0; nX < size; nX++) {
356
            Node node = nodes.item(nX);
357
            if (node instanceof Text) {
358
                return (Text) node;
359
            }
360
        }
361
        // a Text node was not found
362
        return null;
363
    }
364
365
    /**
366
     * Places the element's attributes into the document.
367
     * @param copyText true if the first text node should be copied
368
     */
369
    private void putElement(Element element, boolean copyText) {
370
        NamedNodeMap nodeMap = element.getAttributes();
371
        int size = nodeMap.getLength();
372
        for (int i = 0; i < size; i++) {
373
            Attr attr = (Attr) nodeMap.item(i);
374
            putString(attr.getName(), attr.getValue());
375
        }
376
377
        NodeList nodes = element.getChildNodes();
378
        size = nodes.getLength();
379
        // Copy first text node (fixes bug 113659).
380
        // Note that text data will be added as the first child (see putTextData)
381
        boolean needToCopyText = copyText;
382
        for (int i = 0; i < size; i++) {
383
            Node node = nodes.item(i);
384
            if (node instanceof Element) {
385
                XMLMemento child = (XMLMemento) createChild(node.getNodeName());
386
                child.putElement((Element) node, true);
387
            } else if (node instanceof Text && needToCopyText) {
388
                putTextData(((Text) node).getData());
389
                needToCopyText = false;
390
            }
391
        }
392
    }
393
394
    /* (non-Javadoc)
395
     * Method declared in XMLMemento.
396
     */
397
    public void putFloat(String key, float f) {
398
        element.setAttribute(key, String.valueOf(f));
399
    }
400
401
    /* (non-Javadoc)
402
     * Method declared in XMLMemento.
403
     */
404
    public void putInteger(String key, int n) {
405
        element.setAttribute(key, String.valueOf(n));
406
    }
407
408
    /* (non-Javadoc)
409
     * Method declared in XMLMemento.
410
     */
411
    public void putMemento(XMLMemento memento) {
412
    	// Do not copy the element's top level text node (this would overwrite the existing text).
413
    	// Text nodes of children are copied.
414
        putElement(((XMLMemento) memento).element, false);
415
    }
416
417
    /* (non-Javadoc)
418
     * Method declared in XMLMemento.
419
     */
420
    public void putString(String key, String value) {
421
        if (value == null) {
422
			return;
423
		}
424
        element.setAttribute(key, value);
425
    }
426
427
	/**
428
	 * @since 3.4
429
	 */
430
	public void putBoolean(String key, boolean value) {
431
		element.setAttribute(key, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
432
	}
433
434
    /* (non-Javadoc)
435
     * Method declared in XMLMemento.
436
     */
437
    public void putTextData(String data) {
438
        Text textNode = getTextNode();
439
        if (textNode == null) {
440
            textNode = factory.createTextNode(data);
441
			// Always add the text node as the first child (fixes bug 93718) 
442
			element.insertBefore(textNode, element.getFirstChild());
443
        } else {
444
            textNode.setData(data);
445
        }
446
    }
447
448
    /**
449
     * Saves this memento's document current values to the
450
     * specified writer. 
451
     * 
452
     * @param writer the writer used to save the memento's document
453
     * @throws IOException if there is a problem serializing the document to the stream.
454
     */
455
    public void save(Writer writer) throws IOException {
456
    	DOMWriter out = new DOMWriter(writer);
457
        try {
458
        	out.print(element);
459
    	} finally {
460
    		out.close();
461
    	}
462
	}
463
464
	/**
465
     * A simple XML writer.  Using this instead of the javax.xml.transform classes allows
466
     * compilation against JCL Foundation (bug 80053). 
467
     */
468
    private static final class DOMWriter extends PrintWriter {
469
    	
470
    	private int tab;
471
472
    	/* constants */
473
    	private static final String XML_VERSION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; //$NON-NLS-1$
474
475
    	/**
476
    	 * Creates a new DOM writer on the given output writer.
477
    	 * 
478
    	 * @param output the output writer
479
    	 */
480
    	public DOMWriter(Writer output) {
481
    		super(output);
482
    		tab = 0;
483
    		println(XML_VERSION);
484
    	}
485
486
    	/**
487
    	 * Prints the given element.
488
    	 * 
489
    	 * @param element the element to print
490
    	 */
491
        public void print(Element element) {
492
        	// Ensure extra whitespace is not emitted next to a Text node,
493
        	// as that will result in a situation where the restored text data is not the
494
        	// same as the saved text data.
495
        	boolean hasChildren = element.hasChildNodes();
496
        	startTag(element, hasChildren);
497
        	if (hasChildren) {
498
	        	tab++;
499
	        	boolean prevWasText = false;
500
	        	NodeList children = element.getChildNodes();
501
	    		for (int i = 0; i < children.getLength(); i++) {
502
	    			Node node = children.item(i);
503
	    			if (node instanceof Element) {
504
	    				if (!prevWasText) {
505
	    					println();
506
	    					printTabulation();
507
	    				}
508
	    				print((Element) children.item(i));
509
	    				prevWasText = false;
510
	    			}
511
	    			else if (node instanceof Text) {
512
	    				print(getEscaped(node.getNodeValue()));
513
	    				prevWasText = true;
514
	    			}
515
	    		}
516
	    		tab--;
517
	    		if (!prevWasText) {
518
	    			println();
519
	    			printTabulation();
520
	    		}
521
	    		endTag(element);
522
        	}
523
    	}
524
525
    	private void printTabulation() {
526
        	// Indenting is disabled, as it can affect the result of getTextData().
527
        	// In 3.0, elements were separated by a newline but not indented.
528
    		// This causes getTextData() to return "\n" even if no text data had explicitly been set.
529
        	// The code here emulates that behaviour.
530
    		
531
//    		for (int i = 0; i < tab; i++)
532
//    			super.print("\t"); //$NON-NLS-1$
533
    	}
534
535
    	private void startTag(Element element, boolean hasChildren) {
536
    		StringBuffer sb = new StringBuffer();
537
    		sb.append("<"); //$NON-NLS-1$
538
    		sb.append(element.getTagName());
539
    		NamedNodeMap attributes = element.getAttributes();
540
   			for (int i = 0;  i < attributes.getLength(); i++) {
541
   				Attr attribute = (Attr)attributes.item(i);
542
				sb.append(" "); //$NON-NLS-1$
543
				sb.append(attribute.getName());
544
				sb.append("=\""); //$NON-NLS-1$
545
				sb.append(getEscaped(String.valueOf(attribute.getValue())));
546
				sb.append("\""); //$NON-NLS-1$
547
   			}
548
   			sb.append(hasChildren ? ">" : "/>"); //$NON-NLS-1$ //$NON-NLS-2$
549
   			print(sb.toString());
550
    	}
551
552
    	private void endTag(Element element) {
553
    		StringBuffer sb = new StringBuffer();
554
    		sb.append("</"); //$NON-NLS-1$
555
    		sb.append(element.getNodeName());
556
    		sb.append(">"); //$NON-NLS-1$
557
   			print(sb.toString());
558
    	}
559
    	
560
    	private static void appendEscapedChar(StringBuffer buffer, char c) {
561
    		String replacement = getReplacement(c);
562
    		if (replacement != null) {
563
    			buffer.append('&');
564
    			buffer.append(replacement);
565
    			buffer.append(';');
566
    		} else if (c==9 || c==10 || c==13 || c>=32){
567
    			buffer.append(c);
568
    		}
569
    	}
570
571
    	private static String getEscaped(String s) {
572
    		StringBuffer result = new StringBuffer(s.length() + 10);
573
    		for (int i = 0; i < s.length(); ++i) {
574
				appendEscapedChar(result, s.charAt(i));
575
			}
576
    		return result.toString();
577
    	}
578
579
    	private static String getReplacement(char c) {
580
    		// Encode special XML characters into the equivalent character references.
581
			// The first five are defined by default for all XML documents.
582
			// The next three (#xD, #xA, #x9) are encoded to avoid them
583
			// being converted to spaces on deserialization
584
			// (fixes bug 93720)
585
    		switch (c) {
586
    			case '<' :
587
    				return "lt"; //$NON-NLS-1$
588
    			case '>' :
589
    				return "gt"; //$NON-NLS-1$
590
    			case '"' :
591
    				return "quot"; //$NON-NLS-1$
592
    			case '\'' :
593
    				return "apos"; //$NON-NLS-1$
594
    			case '&' :
595
    				return "amp"; //$NON-NLS-1$
596
				case '\r':
597
					return "#x0D"; //$NON-NLS-1$
598
				case '\n':
599
					return "#x0A"; //$NON-NLS-1$
600
				case '\u0009':
601
					return "#x09"; //$NON-NLS-1$
602
    		}
603
    		return null;
604
    	}
605
    }
606
}
(-)ui/org/eclipse/debug/ui/CommonTab.java (-7 / +1 lines)
Lines 590-602 Link Here
590
	 * @return whether the configuration is configured to launch in the background
590
	 * @return whether the configuration is configured to launch in the background
591
	 */
591
	 */
592
	public static boolean isLaunchInBackground(ILaunchConfiguration configuration) {
592
	public static boolean isLaunchInBackground(ILaunchConfiguration configuration) {
593
		boolean launchInBackground= true;
593
		return false;//DebugPlugin.getDefault().getLaunchManager().isLaunchInBackground(configuration);
594
		try {
595
			launchInBackground= configuration.getAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true);
596
		} catch (CoreException ce) {
597
			DebugUIPlugin.log(ce);
598
		}
599
		return launchInBackground;
600
	}
594
	}
601
595
602
	/**
596
	/**
(-)ui/org/eclipse/debug/ui/IDebugUIConstants.java (-1 / +2 lines)
Lines 14-19 Link Here
14
14
15
15
16
import org.eclipse.debug.core.DebugPlugin;
16
import org.eclipse.debug.core.DebugPlugin;
17
import org.eclipse.debug.core.ILaunchManager;
17
 
18
 
18
/**
19
/**
19
 * Constant definitions for debug UI plug-in.
20
 * Constant definitions for debug UI plug-in.
Lines 861-867 Link Here
861
	 * 
862
	 * 
862
	 * @since 2.0
863
	 * @since 2.0
863
	 */
864
	 */
864
	public static final String ATTR_PRIVATE = PLUGIN_ID + ".private"; //$NON-NLS-1$
865
	public static final String ATTR_PRIVATE = ILaunchManager.ATTR_PRIVATE;
865
	
866
	
866
	/**
867
	/**
867
	 * Launch configuration attribute - a boolean value that indicates if the launch configuration
868
	 * Launch configuration attribute - a boolean value that indicates if the launch configuration
(-)ui/org/eclipse/debug/ui/RefreshTab.java (-127 / +30 lines)
Lines 11-39 Link Here
11
package org.eclipse.debug.ui;
11
package org.eclipse.debug.ui;
12
12
13
13
14
import java.io.IOException;
15
import java.io.StringReader;
16
import java.io.StringWriter;
17
import com.ibm.icu.text.MessageFormat;
18
import org.eclipse.core.resources.IResource;
14
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.ResourcesPlugin;
20
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.core.runtime.MultiStatus;
18
import org.eclipse.core.runtime.MultiStatus;
25
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.core.runtime.NullProgressMonitor;
26
import org.eclipse.core.runtime.Path;
27
import org.eclipse.core.runtime.Status;
28
import org.eclipse.debug.core.DebugPlugin;
20
import org.eclipse.debug.core.DebugPlugin;
29
import org.eclipse.debug.core.ILaunchConfiguration;
21
import org.eclipse.debug.core.ILaunchConfiguration;
30
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
22
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
23
import org.eclipse.debug.core.ILaunchManager;
31
import org.eclipse.debug.internal.ui.DebugPluginImages;
24
import org.eclipse.debug.internal.ui.DebugPluginImages;
32
import org.eclipse.debug.internal.ui.DebugUIPlugin;
25
import org.eclipse.debug.internal.ui.DebugUIPlugin;
33
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
26
import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
34
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
27
import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
35
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
28
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
36
import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager;
37
import org.eclipse.debug.internal.ui.stringsubstitution.StringSubstitutionMessages;
29
import org.eclipse.debug.internal.ui.stringsubstitution.StringSubstitutionMessages;
38
import org.eclipse.jface.window.Window;
30
import org.eclipse.jface.window.Window;
39
import org.eclipse.jface.wizard.WizardDialog;
31
import org.eclipse.jface.wizard.WizardDialog;
Lines 49-56 Link Here
49
import org.eclipse.ui.IWorkingSet;
41
import org.eclipse.ui.IWorkingSet;
50
import org.eclipse.ui.IWorkingSetManager;
42
import org.eclipse.ui.IWorkingSetManager;
51
import org.eclipse.ui.PlatformUI;
43
import org.eclipse.ui.PlatformUI;
52
import org.eclipse.ui.WorkbenchException;
53
import org.eclipse.ui.XMLMemento;
54
import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
44
import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
55
45
56
/**
46
/**
Lines 67-86 Link Here
67
57
68
	/**
58
	/**
69
	 * Boolean attribute indicating if a refresh scope is recursive. Default
59
	 * Boolean attribute indicating if a refresh scope is recursive. Default
70
	 * value is <code>false</code>.
60
	 * value is <code>true</code>.
71
	 */
61
	 */
72
	public static final String ATTR_REFRESH_RECURSIVE = DebugPlugin.getUniqueIdentifier() + ".ATTR_REFRESH_RECURSIVE"; //$NON-NLS-1$
62
	public static final String ATTR_REFRESH_RECURSIVE = ILaunchManager.ATTR_REFRESH_RECURSIVE;
73
63
74
	/**
64
	/**
75
	 * String attribute identifying the scope of resources that should be
65
	 * String attribute identifying the scope of resources that should be
76
	 * refreshed after an external tool is run. The value is either a refresh
66
	 * refreshed after an external tool is run. The value is either a refresh
77
	 * variable or the default value, <code>null</code>, indicating no refresh.
67
	 * variable or the default value, <code>null</code>, indicating no refresh.
78
	 */
68
	 */
79
	public static final String ATTR_REFRESH_SCOPE = DebugPlugin.getUniqueIdentifier() + ".ATTR_REFRESH_SCOPE"; //$NON-NLS-1$
69
	public static final String ATTR_REFRESH_SCOPE = ILaunchManager.ATTR_REFRESH_SCOPE;
80
	
70
		
81
	// indicates no working set has been selected
82
	private static final String NO_WORKING_SET = "NONE"; //$NON-NLS-1$
83
	
84
	// Check Buttons
71
	// Check Buttons
85
	private Button fRefreshButton;
72
	private Button fRefreshButton;
86
	private Button fRecursiveButton;
73
	private Button fRecursiveButton;
Lines 100-116 Link Here
100
	
87
	
101
	// Working set
88
	// Working set
102
	private IWorkingSet fWorkingSet;
89
	private IWorkingSet fWorkingSet;
103
104
	/**
105
	 * XML tag used to designate the root of the persisted IWorkingSet
106
	 */
107
	private static final String TAG_LAUNCH_CONFIGURATION_WORKING_SET= "launchConfigurationWorkingSet"; //$NON-NLS-1$
108
109
	/**
110
	 * XML tag used for setting / getting the factory ID of the persisted IWorkingSet
111
	 * Bug 37143
112
	 */	
113
	private static final String TAG_FACTORY_ID = "factoryID"; //$NON-NLS-1$
114
	
90
	
115
	/**
91
	/**
116
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
92
	 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
Lines 269-281 Link Here
269
			// select the workspace by default
245
			// select the workspace by default
270
			fWorkspaceButton.setSelection(true);
246
			fWorkspaceButton.setSelection(true);
271
		} else {
247
		} else {
272
			if (scope.equals("${workspace}")) { //$NON-NLS-1$
248
			if (scope.equals(ILaunchManager.MEMENTO_WORKSPACE)) {
273
				fWorkspaceButton.setSelection(true);
249
				fWorkspaceButton.setSelection(true);
274
			} else if (scope.equals("${resource}")) { //$NON-NLS-1$
250
			} else if (scope.equals(ILaunchManager.MEMENTO_SELECTED_RESOURCE)) { 
275
				fResourceButton.setSelection(true);
251
				fResourceButton.setSelection(true);
276
			} else if (scope.equals("${container}")) { //$NON-NLS-1$
252
			} else if (scope.equals(ILaunchManager.MEMENTO_SELECTED_CONTAINER)) { 
277
				fContainerButton.setSelection(true);
253
				fContainerButton.setSelection(true);
278
			} else if (scope.equals("${project}")) { //$NON-NLS-1$
254
			} else if (scope.equals(ILaunchManager.MEMENTO_SELECTED_PROJECT)) { 
279
				fProjectButton.setSelection(true);
255
				fProjectButton.setSelection(true);
280
			} else if (scope.startsWith("${resource:")) { //$NON-NLS-1$
256
			} else if (scope.startsWith("${resource:")) { //$NON-NLS-1$
281
				fWorkingSetButton.setSelection(true);
257
				fWorkingSetButton.setSelection(true);
Lines 288-295 Link Here
288
				}
264
				}
289
			} else if (scope.startsWith("${working_set:")) { //$NON-NLS-1$
265
			} else if (scope.startsWith("${working_set:")) { //$NON-NLS-1$
290
				fWorkingSetButton.setSelection(true);
266
				fWorkingSetButton.setSelection(true);
291
				String memento = scope.substring(14, scope.length() - 1);
267
				fWorkingSet = getWorkingSet(scope);
292
				fWorkingSet = restoreWorkingSet(memento);
293
			}
268
			}
294
		}
269
		}
295
	}
270
	}
Lines 343-358 Link Here
343
	 */
318
	 */
344
	private String generateScopeMemento() {
319
	private String generateScopeMemento() {
345
		if (fWorkspaceButton.getSelection()) {
320
		if (fWorkspaceButton.getSelection()) {
346
			return "${workspace}"; //$NON-NLS-1$
321
			return ILaunchManager.MEMENTO_WORKSPACE;
347
		}
322
		}
348
		if (fResourceButton.getSelection()) {
323
		if (fResourceButton.getSelection()) {
349
			return "${resource}"; //$NON-NLS-1$
324
			return ILaunchManager.MEMENTO_SELECTED_RESOURCE;
350
		}
325
		}
351
		if (fContainerButton.getSelection()) {
326
		if (fContainerButton.getSelection()) {
352
			return "${container}"; //$NON-NLS-1$
327
			return ILaunchManager.MEMENTO_SELECTED_CONTAINER;
353
		}
328
		}
354
		if (fProjectButton.getSelection()) {
329
		if (fProjectButton.getSelection()) {
355
			return "${project}"; //$NON-NLS-1$
330
			return ILaunchManager.MEMENTO_SELECTED_PROJECT;
356
		}
331
		}
357
		if (fWorkingSetButton.getSelection()) {
332
		if (fWorkingSetButton.getSelection()) {
358
			return getRefreshAttribute(fWorkingSet);
333
			return getRefreshAttribute(fWorkingSet);
Lines 460-535 Link Here
460
	 * @throws CoreException if unable to resolve a set of resources
435
	 * @throws CoreException if unable to resolve a set of resources
461
	 */
436
	 */
462
	public static IResource[] getRefreshResources(String scope) throws CoreException {
437
	public static IResource[] getRefreshResources(String scope) throws CoreException {
463
		if (scope.startsWith("${resource:")) { //$NON-NLS-1$
438
		return DebugPlugin.getDefault().getLaunchManager().toResources(scope);
464
			// This is an old format that is replaced with 'working_set'
465
			String pathString = scope.substring(11, scope.length() - 1);
466
			Path path = new Path(pathString);
467
			IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
468
			if (resource == null) {
469
				throw new CoreException(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, MessageFormat.format(StringSubstitutionMessages.RefreshTab_43, new String[]{pathString}), null)); 
470
			} 
471
			return new IResource[]{resource};
472
		} else if (scope.startsWith("${working_set:")) { //$NON-NLS-1$
473
			IWorkingSet workingSet =  getWorkingSet(scope);
474
			if (workingSet == null) {
475
				throw new CoreException(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), IStatus.ERROR, StringSubstitutionMessages.RefreshTab_44, null));  
476
			} 
477
			IAdaptable[] elements = workingSet.getElements();
478
			IResource[] resources = new IResource[elements.length];
479
			for (int i = 0; i < elements.length; i++) {
480
				IAdaptable adaptable = elements[i];
481
				if (adaptable instanceof IResource) {
482
					resources[i] = (IResource) adaptable;
483
				} else {
484
					resources[i] = (IResource) adaptable.getAdapter(IResource.class);
485
				}
486
			}
487
			return resources;				
488
		} else if(scope.equals("${workspace}")) { //$NON-NLS-1$
489
			return new IResource[]{ResourcesPlugin.getWorkspace().getRoot()};
490
		} else {
491
			IResource resource = SelectedResourceManager.getDefault().getSelectedResource();
492
			if (resource == null) {
493
				// empty selection
494
				return new IResource[]{};
495
			}
496
			if (scope.equals("${resource}")) { //$NON-NLS-1$
497
				// resource = resource
498
			} else if (scope.equals("${container}")) { //$NON-NLS-1$
499
				resource = resource.getParent();
500
			} else if (scope.equals("${project}")) { //$NON-NLS-1$
501
				resource = resource.getProject();
502
			}
503
			return new IResource[]{resource};
504
		}
505
	}
439
	}
506
	
440
	
507
	/**
441
	/**
508
	 * Restores a working set based on the XMLMemento represented within
509
	 * the mementoString.
510
	 * 
511
	 * @param mementoString The string memento of the working set
512
	 * @return the restored working set or <code>null</code> if problems occurred restoring the
513
	 * working set.
514
	 */
515
	private static IWorkingSet restoreWorkingSet(String mementoString) {
516
		if (NO_WORKING_SET.equals(mementoString)) {
517
			return null;
518
		}
519
		StringReader reader= new StringReader(mementoString);
520
		XMLMemento memento= null;
521
		try {
522
			memento = XMLMemento.createReadRoot(reader);
523
		} catch (WorkbenchException e) {
524
			DebugUIPlugin.log(e);
525
			return null;
526
		}
527
528
		IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager();
529
		return workingSetManager.createWorkingSet(memento);
530
	}	
531
	
532
	/**
533
	 * Returns the refresh scope attribute specified by the given launch configuration
442
	 * Returns the refresh scope attribute specified by the given launch configuration
534
	 * or <code>null</code> if none.
443
	 * or <code>null</code> if none.
535
	 * 
444
	 * 
Lines 561-589 Link Here
561
	 * @return an equivalent refresh attribute
470
	 * @return an equivalent refresh attribute
562
	 */
471
	 */
563
	public static String getRefreshAttribute(IWorkingSet workingSet) {
472
	public static String getRefreshAttribute(IWorkingSet workingSet) {
564
		String set = null;
565
		if (workingSet == null || workingSet.getElements().length == 0) {
473
		if (workingSet == null || workingSet.getElements().length == 0) {
566
			set = NO_WORKING_SET;
474
			return DebugPlugin.getDefault().getLaunchManager().toMemento(new IResource[0]);
567
		} else {
475
		} else {
568
			XMLMemento workingSetMemento = XMLMemento.createWriteRoot(TAG_LAUNCH_CONFIGURATION_WORKING_SET);
476
			IAdaptable[] elements = workingSet.getElements();
569
			workingSetMemento.putString(RefreshTab.TAG_FACTORY_ID, workingSet.getFactoryId());
477
			IResource[] resources = new IResource[elements.length];
570
			workingSet.saveState(workingSetMemento);
478
			for (int i = 0; i < resources.length; i++) {
571
			StringWriter writer= new StringWriter();
479
				resources[i]= (IResource) elements[i].getAdapter(IResource.class);
572
			try {
573
				workingSetMemento.save(writer);
574
			} catch (IOException e) {
575
				DebugUIPlugin.log(e);
576
			}
480
			}
577
			set = writer.toString();
481
			return DebugPlugin.getDefault().getLaunchManager().toMemento(resources);
578
		}
579
		if (set != null) {
580
			StringBuffer memento = new StringBuffer();
581
			memento.append("${working_set:"); //$NON-NLS-1$
582
			memento.append(set);
583
			memento.append("}"); //$NON-NLS-1$
584
			return memento.toString();
585
		}
482
		}
586
		return null;
587
	}
483
	}
588
	
484
	
589
	/**
485
	/**
Lines 596-603 Link Here
596
	 */
492
	 */
597
	public static IWorkingSet getWorkingSet(String refreshAttribute) {
493
	public static IWorkingSet getWorkingSet(String refreshAttribute) {
598
		if (refreshAttribute.startsWith("${working_set:")) { //$NON-NLS-1$
494
		if (refreshAttribute.startsWith("${working_set:")) { //$NON-NLS-1$
599
			String memento = refreshAttribute.substring(14, refreshAttribute.length() - 1);
495
			try {
600
			return  restoreWorkingSet(memento);
496
				IResource[] resources = DebugPlugin.getDefault().getLaunchManager().toResources(refreshAttribute);
497
				IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
498
				// TODO: NLS Name?
499
				IWorkingSet workingSet = workingSetManager.createWorkingSet("workingSet", resources);
500
				return workingSet;
501
			} catch (CoreException e) {
502
				DebugUIPlugin.log(e);
503
			}
601
		}
504
		}
602
		return null;
505
		return null;
603
	}
506
	}
(-)External Tools Base/org/eclipse/ui/externaltools/internal/launchConfigurations/ExternalToolsBuildTab.java (-41 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-31 Link Here
16
import java.util.Iterator;
16
import java.util.Iterator;
17
import java.util.List;
17
import java.util.List;
18
18
19
import org.eclipse.core.internal.externaltools.launchConfigurations.ExternalToolsCoreUtil;
20
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
19
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.resources.IWorkspace;
22
import org.eclipse.core.resources.IWorkspace;
22
import org.eclipse.core.resources.IWorkspaceRoot;
23
import org.eclipse.core.resources.ResourcesPlugin;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.debug.core.ILaunchConfiguration;
25
import org.eclipse.debug.core.ILaunchConfiguration;
26
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
26
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
27
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
27
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
28
import org.eclipse.debug.ui.DebugUITools;
29
import org.eclipse.jface.viewers.IStructuredContentProvider;
28
import org.eclipse.jface.viewers.IStructuredContentProvider;
30
import org.eclipse.jface.viewers.Viewer;
29
import org.eclipse.jface.viewers.Viewer;
31
import org.eclipse.jface.window.Window;
30
import org.eclipse.jface.window.Window;
Lines 41-47 Link Here
41
import org.eclipse.ui.dialogs.ListSelectionDialog;
40
import org.eclipse.ui.dialogs.ListSelectionDialog;
42
import org.eclipse.ui.externaltools.internal.model.ExternalToolsImages;
41
import org.eclipse.ui.externaltools.internal.model.ExternalToolsImages;
43
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
42
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
44
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
45
import org.eclipse.ui.model.WorkbenchLabelProvider;
43
import org.eclipse.ui.model.WorkbenchLabelProvider;
46
44
47
/**
45
/**
Lines 330-366 Link Here
330
	 * @return collection of projects referred to by configuration
328
	 * @return collection of projects referred to by configuration
331
	 */
329
	 */
332
	public static IProject[] getBuildProjects(ILaunchConfiguration configuration, String buildScopeId) {
330
	public static IProject[] getBuildProjects(ILaunchConfiguration configuration, String buildScopeId) {
333
		String scope = null;
331
		return ExternalToolsCoreUtil.getBuildProjects(configuration,
334
		String id = buildScopeId ;
332
				buildScopeId);
335
		if (id == null) {
333
336
			id = IExternalToolConstants.ATTR_BUILD_SCOPE ;
337
		}
338
		try {
339
			scope = configuration.getAttribute(id, (String)null);
340
		} catch (CoreException e) {
341
			return null;
342
		}
343
		if (scope == null) {
344
			return null;
345
		}
346
		if (scope.startsWith("${projects:")) { //$NON-NLS-1$
347
			String pathString = scope.substring(11, scope.length() - 1);
348
			if (pathString.length() > 1) {
349
				String[] names = pathString.split(","); //$NON-NLS-1$
350
				IProject[] projects = new IProject[names.length];
351
				IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
352
				for (int i = 0; i < names.length; i++) {
353
					projects[i] = root.getProject(names[i]);
354
				}
355
				return projects;
356
			}
357
		} else if (scope.equals("${project}")) { //$NON-NLS-1$
358
			IResource resource = DebugUITools.getSelectedResource();
359
			if (resource != null) {
360
				return new IProject[]{resource.getProject()};
361
			}
362
		}
363
		return new IProject[0];
364
	}
334
	}
365
	
335
	
366
	/**
336
	/**
Lines 372-382 Link Here
372
	 * @throws CoreException if unable to access the associated attribute
342
	 * @throws CoreException if unable to access the associated attribute
373
	 */
343
	 */
374
	public static boolean isIncludeReferencedProjects(ILaunchConfiguration configuration, String includeReferencedProjectsId) throws CoreException {
344
	public static boolean isIncludeReferencedProjects(ILaunchConfiguration configuration, String includeReferencedProjectsId) throws CoreException {
375
		String id = includeReferencedProjectsId;
345
		return ExternalToolsCoreUtil.isIncludeReferencedProjects(configuration,
376
		if (id == null) {
346
				includeReferencedProjectsId);
377
			id = IExternalToolConstants.ATTR_INCLUDE_REFERENCED_PROJECTS ;
378
		}
379
		return configuration.getAttribute(id, true);
380
	}
347
	}
381
	
348
	
382
	/**
349
	/**
(-)External Tools Base/org/eclipse/ui/externaltools/internal/launchConfigurations/ExternalToolsBuilderTab.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-17 Link Here
12
package org.eclipse.ui.externaltools.internal.launchConfigurations;
12
package org.eclipse.ui.externaltools.internal.launchConfigurations;
13
13
14
14
15
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.IncrementalProjectBuilder;
17
import org.eclipse.core.resources.IncrementalProjectBuilder;
17
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.resources.ResourcesPlugin;
Lines 50-56 Link Here
50
import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
51
import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
51
import org.eclipse.ui.externaltools.internal.model.BuilderUtils;
52
import org.eclipse.ui.externaltools.internal.model.BuilderUtils;
52
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
53
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
53
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
54
import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds;
54
import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds;
55
import org.eclipse.ui.ide.IDE;
55
import org.eclipse.ui.ide.IDE;
56
import org.eclipse.ui.model.WorkbenchContentProvider;
56
import org.eclipse.ui.model.WorkbenchContentProvider;
(-)External Tools Base/org/eclipse/ui/externaltools/internal/launchConfigurations/ExternalToolsLaunchConfigurationMessages.java (-6 / +1 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others. All rights reserved. This
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
5
 * available at http://www.eclipse.org/legal/epl-v10.html
Lines 48-58 Link Here
48
	public static String ExternalToolsBuildTab_8;
48
	public static String ExternalToolsBuildTab_8;
49
	public static String ExternalToolsBuildTab_9;
49
	public static String ExternalToolsBuildTab_9;
50
50
51
52
	public static String ExternalToolsUtil_Location_not_specified_by__0__1;
53
	public static String ExternalToolsUtil_invalidLocation__0_;
54
	public static String ExternalToolsUtil_invalidDirectory__0_;
55
56
	public static String ExternalToolsBuilderTab_Run_this_builder_for__1;
51
	public static String ExternalToolsBuilderTab_Run_this_builder_for__1;
57
	public static String ExternalToolsBuilderTab__Full_builds_2;
52
	public static String ExternalToolsBuilderTab__Full_builds_2;
58
	public static String ExternalToolsBuilderTab_Full;
53
	public static String ExternalToolsBuilderTab_Full;
(-)External Tools Base/org/eclipse/ui/externaltools/internal/launchConfigurations/ExternalToolsLaunchConfigurationMessages.properties (-5 / +1 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2007 IBM Corporation and others.
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 43-52 Link Here
43
ExternalToolsBuildTab_8=Build
43
ExternalToolsBuildTab_8=Build
44
ExternalToolsBuildTab_9=No projects specified
44
ExternalToolsBuildTab_9=No projects specified
45
45
46
ExternalToolsUtil_Location_not_specified_by__0__1=Location not specified by {0}
47
ExternalToolsUtil_invalidLocation__0_ = The file does not exist for the external tool named {0}.
48
ExternalToolsUtil_invalidDirectory__0_ = The working directory {0} does not exist for the external tool named {1}.
49
50
ExternalToolsBuilderTab_Run_this_builder_for__1=Run the builder:
46
ExternalToolsBuilderTab_Run_this_builder_for__1=Run the builder:
51
ExternalToolsBuilderTab__Full_builds_2=A&fter a \"Clean\"
47
ExternalToolsBuilderTab__Full_builds_2=A&fter a \"Clean\"
52
ExternalToolsBuilderTab_Full=Runs on the first build that occurs after a clean.
48
ExternalToolsBuilderTab_Full=Runs on the first build that occurs after a clean.
(-)External Tools Base/org/eclipse/ui/externaltools/internal/launchConfigurations/ExternalToolsMainTab.java (-2 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-17 Link Here
12
12
13
13
14
import java.io.File;
14
import java.io.File;
15
16
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
15
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.ResourcesPlugin;
18
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
Lines 46-52 Link Here
46
import org.eclipse.ui.dialogs.ResourceSelectionDialog;
48
import org.eclipse.ui.dialogs.ResourceSelectionDialog;
47
import org.eclipse.ui.externaltools.internal.model.ExternalToolsImages;
49
import org.eclipse.ui.externaltools.internal.model.ExternalToolsImages;
48
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
50
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
49
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
50
51
51
/**
52
/**
52
 * The external tools main tab allows the user to configure primary attributes
53
 * The external tools main tab allows the user to configure primary attributes
(-)External Tools Base/org/eclipse/ui/externaltools/internal/launchConfigurations/ExternalToolsUtil.java (-67 / +11 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-33 Link Here
13
package org.eclipse.ui.externaltools.internal.launchConfigurations;
13
package org.eclipse.ui.externaltools.internal.launchConfigurations;
14
14
15
15
16
import java.io.File;
16
import org.eclipse.core.internal.externaltools.launchConfigurations.ExternalToolsCoreUtil;
17
18
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IPath;
19
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Path;
23
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.runtime.Status;
24
import org.eclipse.core.variables.IStringVariableManager;
25
import org.eclipse.core.variables.VariablesPlugin;
26
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.debug.core.ILaunchConfiguration;
22
import org.eclipse.debug.core.ILaunchConfiguration;
28
import org.eclipse.debug.ui.RefreshTab;
23
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
29
import org.eclipse.osgi.util.NLS;
30
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
31
24
32
/**
25
/**
33
 * Utilities for external tool launch configurations.
26
 * Utilities for external tool launch configurations.
Lines 47-53 Link Here
47
	 * @param code error code
40
	 * @param code error code
48
	 */
41
	 */
49
	protected static void abort(String message, Throwable exception, int code) throws CoreException {
42
	protected static void abort(String message, Throwable exception, int code) throws CoreException {
50
		throw new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, code, message, exception));
43
		throw new CoreException(new Status(IStatus.ERROR, ExternalToolsPlugin.PLUGIN_ID, code, message, exception));
51
	}
44
	}
52
	
45
	
53
	/**
46
	/**
Lines 63-88 Link Here
63
	 * system
56
	 * system
64
	 */
57
	 */
65
	public static IPath getLocation(ILaunchConfiguration configuration) throws CoreException {
58
	public static IPath getLocation(ILaunchConfiguration configuration) throws CoreException {
66
		String location = configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String) null);
59
		return ExternalToolsCoreUtil.getLocation(configuration);
67
		if (location == null) {
68
			abort(NLS.bind(ExternalToolsLaunchConfigurationMessages.ExternalToolsUtil_Location_not_specified_by__0__1, new String[] { configuration.getName()}), null, 0);
69
		} else {
70
			String expandedLocation = getStringVariableManager().performStringSubstitution(location);
71
			if (expandedLocation == null || expandedLocation.length() == 0) {
72
				String msg = NLS.bind(ExternalToolsLaunchConfigurationMessages.ExternalToolsUtil_invalidLocation__0_, new Object[] { configuration.getName()});
73
				abort(msg, null, 0);
74
			} else {
75
				File file = new File(expandedLocation);
76
				if (file.isFile()) {
77
					return new Path(expandedLocation);
78
				} 
79
				
80
				String msg = NLS.bind(ExternalToolsLaunchConfigurationMessages.ExternalToolsUtil_invalidLocation__0_, new Object[] { configuration.getName()});
81
				abort(msg, null, 0);
82
			}
83
		}
84
		// execution will not reach here
85
		return null;
86
	}
60
	}
87
	
61
	
88
	/**
62
	/**
Lines 95-101 Link Here
95
	 * @throws CoreException if unable to access the associated attribute
69
	 * @throws CoreException if unable to access the associated attribute
96
	 */
70
	 */
97
	public static boolean getCaptureOutput(ILaunchConfiguration configuration) throws CoreException {
71
	public static boolean getCaptureOutput(ILaunchConfiguration configuration) throws CoreException {
98
	    return configuration.getAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, true);
72
	    return ExternalToolsCoreUtil.getCaptureOutput(configuration);
99
	}
73
	}
100
74
101
	/**
75
	/**
Lines 113-131 Link Here
113
	 * file system
87
	 * file system
114
	 */
88
	 */
115
	public static IPath getWorkingDirectory(ILaunchConfiguration configuration) throws CoreException {
89
	public static IPath getWorkingDirectory(ILaunchConfiguration configuration) throws CoreException {
116
		String location = configuration.getAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, (String) null);
90
		return ExternalToolsCoreUtil.getWorkingDirectory(configuration);
117
		if (location != null) {
118
			String expandedLocation = getStringVariableManager().performStringSubstitution(location);
119
			if (expandedLocation.length() > 0) {
120
				File path = new File(expandedLocation);
121
				if (path.isDirectory()) {
122
					return new Path(expandedLocation);
123
				} 
124
				String msg = NLS.bind(ExternalToolsLaunchConfigurationMessages.ExternalToolsUtil_invalidDirectory__0_, new Object[] { expandedLocation, configuration.getName()});
125
				abort(msg, null, 0);
126
			}
127
		}
128
		return null;
129
	}
91
	}
130
92
131
	/**
93
	/**
Lines 139-154 Link Here
139
	 * configuration attribute, or if unable to resolve any variables
101
	 * configuration attribute, or if unable to resolve any variables
140
	 */
102
	 */
141
	public static String[] getArguments(ILaunchConfiguration configuration) throws CoreException {
103
	public static String[] getArguments(ILaunchConfiguration configuration) throws CoreException {
142
		String args = configuration.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, (String) null);
104
		return ExternalToolsCoreUtil.getArguments(configuration);
143
		if (args != null) {
144
			String expanded = getStringVariableManager().performStringSubstitution(args);
145
			return parseStringIntoList(expanded);
146
		}
147
		return null;
148
	}
149
150
	private static IStringVariableManager getStringVariableManager() {
151
		return VariablesPlugin.getDefault().getStringVariableManager();
152
	}
105
	}
153
	
106
	
154
	/**
107
	/**
Lines 163-169 Link Here
163
	 * @throws CoreException if unable to access the associated attribute
116
	 * @throws CoreException if unable to access the associated attribute
164
	 */
117
	 */
165
	public static boolean isBuilderEnabled(ILaunchConfiguration configuration) throws CoreException {
118
	public static boolean isBuilderEnabled(ILaunchConfiguration configuration) throws CoreException {
166
		return configuration.getAttribute(IExternalToolConstants.ATTR_BUILDER_ENABLED, true);
119
		return ExternalToolsCoreUtil.isBuilderEnabled(configuration);
167
	}
120
	}
168
	
121
	
169
	/**
122
	/**
Lines 173-184 Link Here
173
	 * @throws CoreException if an exception occurs while retrieving the resources
126
	 * @throws CoreException if an exception occurs while retrieving the resources
174
	 */
127
	 */
175
	public static IResource[] getResourcesForBuildScope(ILaunchConfiguration configuration) throws CoreException {
128
	public static IResource[] getResourcesForBuildScope(ILaunchConfiguration configuration) throws CoreException {
176
		String scope = configuration.getAttribute(IExternalToolConstants.ATTR_BUILDER_SCOPE, (String) null);
129
		return ExternalToolsCoreUtil.getResourcesForBuildScope(configuration);
177
		if (scope == null) {
178
			return null;
179
		}
180
	
181
		return RefreshTab.getRefreshResources(scope);
182
	}
130
	}
183
	
131
	
184
	/**
132
	/**
Lines 193-203 Link Here
193
	 * @return the array of arguments
141
	 * @return the array of arguments
194
	 */
142
	 */
195
	public static String[] parseStringIntoList(String arguments) {
143
	public static String[] parseStringIntoList(String arguments) {
196
		if (arguments == null || arguments.length() == 0) {
144
		return ExternalToolsCoreUtil.parseStringIntoList(arguments);
197
			return new String[0];
198
		}
199
		String[] res= DebugPlugin.parseArguments(arguments);
200
		return res;		
201
	}	
145
	}	
202
	
146
	
203
}
147
}
(-)External Tools Base/org/eclipse/ui/externaltools/internal/menu/ExternalToolMenuDelegate.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-18 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.externaltools.internal.menu;
11
package org.eclipse.ui.externaltools.internal.menu;
12
12
13
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
13
import org.eclipse.debug.ui.actions.AbstractLaunchToolbarAction;
14
import org.eclipse.debug.ui.actions.AbstractLaunchToolbarAction;
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.action.IAction;
15
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
16
16
17
/**
17
/**
18
 * This action delegate is responsible for producing the
18
 * This action delegate is responsible for producing the
(-)External Tools Base/org/eclipse/ui/externaltools/internal/menu/OpenExternalToolsConfigurations.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.externaltools.internal.menu;
11
package org.eclipse.ui.externaltools.internal.menu;
12
12
13
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
13
import org.eclipse.debug.ui.actions.OpenLaunchDialogAction;
14
import org.eclipse.debug.ui.actions.OpenLaunchDialogAction;
14
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
15
15
16
/**
16
/**
17
 * Opens the launch config dialog on the external tools launch group.
17
 * Opens the launch config dialog on the external tools launch group.
(-)External Tools Base/org/eclipse/ui/externaltools/internal/model/BuilderUtils.java (-216 / +17 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-75 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.externaltools.internal.model;
11
package org.eclipse.ui.externaltools.internal.model;
12
12
13
import java.util.HashMap;
14
import java.util.Map;
13
import java.util.Map;
15
import java.util.StringTokenizer;
16
14
15
import org.eclipse.core.internal.externaltools.model.BuilderCoreUtils;
16
import org.eclipse.core.internal.externaltools.model.ExternalToolsModelMessages;
17
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
17
import org.eclipse.core.resources.ICommand;
18
import org.eclipse.core.resources.ICommand;
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IFolder;
19
import org.eclipse.core.resources.IFolder;
20
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IncrementalProjectBuilder;
23
import org.eclipse.core.resources.ResourcesPlugin;
24
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IConfigurationElement;
22
import org.eclipse.core.runtime.IConfigurationElement;
26
import org.eclipse.core.runtime.IExtensionPoint;
23
import org.eclipse.core.runtime.IExtensionPoint;
27
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.IStatus;
29
import org.eclipse.core.runtime.NullProgressMonitor;
30
import org.eclipse.core.runtime.Path;
31
import org.eclipse.core.runtime.Platform;
24
import org.eclipse.core.runtime.Platform;
32
import org.eclipse.debug.core.DebugPlugin;
25
import org.eclipse.debug.core.DebugPlugin;
33
import org.eclipse.debug.core.ILaunchConfiguration;
26
import org.eclipse.debug.core.ILaunchConfiguration;
34
import org.eclipse.debug.core.ILaunchConfigurationType;
27
import org.eclipse.debug.core.ILaunchConfigurationType;
35
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
28
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
36
import org.eclipse.debug.core.ILaunchManager;
37
import org.eclipse.jface.dialogs.MessageDialog;
29
import org.eclipse.jface.dialogs.MessageDialog;
38
import org.eclipse.swt.widgets.Shell;
30
import org.eclipse.swt.widgets.Shell;
39
import org.eclipse.ui.externaltools.internal.registry.ExternalToolMigration;
40
31
41
/**
32
/**
42
 * Utility methods for working with external tool project builders.
33
 * Utility methods for working with external tool project builders.
43
 */
34
 */
44
public class BuilderUtils {
35
public class BuilderUtils {
45
46
	public static final String LAUNCH_CONFIG_HANDLE = "LaunchConfigHandle"; //$NON-NLS-1$
47
48
	/**
49
	 * Constant used to find a builder using the 3.0-interim format
50
	 */
51
	public static final String BUILDER_FOLDER_NAME= ".externalToolBuilders"; //$NON-NLS-1$
52
	/**
53
	 * Constant used to represent the current project in the 3.0-final format.
54
	 */
55
	public static final String PROJECT_TAG= "<project>"; //$NON-NLS-1$
56
	
57
	public static final String VERSION_1_0= "1.0"; //$NON-NLS-1$
58
	public static final String VERSION_2_1= "2.1"; //$NON-NLS-1$
59
	// The format shipped up to and including Eclipse 3.0 RC1
60
	public static final String VERSION_3_0_interim= "3.0.interim"; //$NON-NLS-1$
61
	// The format shipped in Eclipse 3.0 final
62
	public static final String VERSION_3_0_final= "3.0"; //$NON-NLS-1$
63
	
36
	
64
	// Extension point constants.
37
	// Extension point constants.
65
	private static final String TAG_CONFIGURATION_MAP= "configurationMap"; //$NON-NLS-1$
38
	private static final String TAG_CONFIGURATION_MAP = "configurationMap"; //$NON-NLS-1$
66
	private static final String TAG_SOURCE_TYPE= "sourceType"; //$NON-NLS-1$
39
	private static final String TAG_SOURCE_TYPE = "sourceType"; //$NON-NLS-1$
67
	private static final String TAG_BUILDER_TYPE= "builderType"; //$NON-NLS-1$
40
	private static final String TAG_BUILDER_TYPE = "builderType"; //$NON-NLS-1$	
68
    
69
    private static final String BUILD_TYPE_SEPARATOR = ","; //$NON-NLS-1$
70
    private static final int[] DEFAULT_BUILD_TYPES= new int[] {
71
                                    IncrementalProjectBuilder.INCREMENTAL_BUILD,
72
                                    IncrementalProjectBuilder.FULL_BUILD};
73
41
74
	/**
42
	/**
75
	 * Returns a launch configuration from the given ICommand arguments. If the
43
	 * Returns a launch configuration from the given ICommand arguments. If the
Lines 81-122 Link Here
81
	 * <code>null</code> if not possible.
49
	 * <code>null</code> if not possible.
82
	 */
50
	 */
83
	public static ILaunchConfiguration configFromBuildCommandArgs(IProject project, Map commandArgs, String[] version) {
51
	public static ILaunchConfiguration configFromBuildCommandArgs(IProject project, Map commandArgs, String[] version) {
84
		String configHandle = (String) commandArgs.get(LAUNCH_CONFIG_HANDLE);
52
		return BuilderCoreUtils.configFromBuildCommandArgs(project, commandArgs, version);
85
		if (configHandle == null) {
86
			// Probably an old-style (Eclipse 1.0 or 2.0) external tool. Try to migrate.
87
			version[0]= VERSION_1_0;
88
			return ExternalToolMigration.configFromArgumentMap(commandArgs);
89
		}
90
		ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
91
		ILaunchConfiguration configuration= null;
92
		if (configHandle.startsWith(PROJECT_TAG)) {
93
			version[0]= VERSION_3_0_final;
94
			IPath path= new Path(configHandle);
95
			IFile file= project.getFile(path.removeFirstSegments(1));
96
			if (file.exists()) {
97
				configuration= manager.getLaunchConfiguration(file);
98
			}
99
		} else {
100
		    // Try treating the handle as a file name.
101
			// This is the format used in 3.0 RC1.
102
			IPath path= new Path(BUILDER_FOLDER_NAME).append(configHandle);
103
			IFile file= project.getFile(path);
104
			if (file.exists()) {
105
				version[0]= VERSION_3_0_interim;
106
				configuration= manager.getLaunchConfiguration(file);
107
			} else {
108
				try {
109
					// Treat the configHandle as a memento. This is the format
110
					// used in Eclipse 2.1.
111
					configuration = manager.getLaunchConfiguration(configHandle);
112
				} catch (CoreException e) {
113
				}
114
				if (configuration != null) {
115
					version[0]= VERSION_2_1;
116
				}
117
			}
118
		}
119
		return configuration;
120
	}
53
	}
121
54
122
	/**
55
	/**
Lines 144-176 Link Here
144
	}
77
	}
145
	
78
	
146
	public static void configureTriggers(ILaunchConfiguration config, ICommand newCommand) throws CoreException {
79
	public static void configureTriggers(ILaunchConfiguration config, ICommand newCommand) throws CoreException {
147
		newCommand.setBuilding(IncrementalProjectBuilder.FULL_BUILD, false);
80
		BuilderCoreUtils.configureTriggers(config, newCommand);
148
		newCommand.setBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD, false);
149
		newCommand.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, false);
150
		newCommand.setBuilding(IncrementalProjectBuilder.CLEAN_BUILD, false);
151
		String buildKinds= config.getAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, (String)null);
152
		int[] triggers= BuilderUtils.buildTypesToArray(buildKinds);
153
		for (int i = 0; i < triggers.length; i++) {
154
			switch (triggers[i]) {
155
				case IncrementalProjectBuilder.FULL_BUILD:
156
					newCommand.setBuilding(IncrementalProjectBuilder.FULL_BUILD, true);
157
					break;
158
				case IncrementalProjectBuilder.INCREMENTAL_BUILD:
159
					newCommand.setBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD, true);
160
					break;
161
				case IncrementalProjectBuilder.AUTO_BUILD:
162
					newCommand.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, true);
163
					break;
164
				case IncrementalProjectBuilder.CLEAN_BUILD:
165
					newCommand.setBuilding(IncrementalProjectBuilder.CLEAN_BUILD, true);
166
					break;
167
			}
168
		}
169
		if (!config.getAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, false)) {
170
			ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
171
			copy.setAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, true);
172
			copy.doSave();
173
		}
174
	}
81
	}
175
82
176
	/**
83
	/**
Lines 184-190 Link Here
184
	 * @return whether the given config represents an unmigrated builder
91
	 * @return whether the given config represents an unmigrated builder
185
	 */
92
	 */
186
	public static boolean isUnmigratedConfig(ILaunchConfiguration config) {
93
	public static boolean isUnmigratedConfig(ILaunchConfiguration config) {
187
		return config.isWorkingCopy() && ((ILaunchConfigurationWorkingCopy) config).getOriginal() == null;
94
		return BuilderCoreUtils.isUnmigratedConfig(config);
188
	}
95
	}
189
96
190
	/**
97
	/**
Lines 194-230 Link Here
194
	 * @return the configured build command
101
	 * @return the configured build command
195
	 */
102
	 */
196
	public static ICommand toBuildCommand(IProject project, ILaunchConfiguration config, ICommand command) throws CoreException {
103
	public static ICommand toBuildCommand(IProject project, ILaunchConfiguration config, ICommand command) throws CoreException {
197
		Map args= null;
104
		return BuilderCoreUtils.toBuildCommand(project, config, command);
198
		if (isUnmigratedConfig(config)) {
199
			// This config represents an old external tool builder that hasn't
200
			// been edited. Try to find the old ICommand and reuse the arguments.
201
			// The goal here is to not change the storage format of old, unedited builders.
202
			ICommand[] commands= project.getDescription().getBuildSpec();
203
			for (int i = 0; i < commands.length; i++) {
204
				ICommand projectCommand = commands[i];
205
				String name= ExternalToolMigration.getNameFromCommandArgs(projectCommand.getArguments());
206
				if (name != null && name.equals(config.getName())) {
207
					args= projectCommand.getArguments();
208
					break;
209
				}
210
			}
211
		} else {
212
			if (config instanceof ILaunchConfigurationWorkingCopy) {
213
				ILaunchConfigurationWorkingCopy workingCopy= (ILaunchConfigurationWorkingCopy) config;
214
				if (workingCopy.getOriginal() != null) {
215
					config= workingCopy.getOriginal();
216
				}
217
			}
218
			args= new HashMap();
219
			// Launch configuration builders are stored with a project-relative path
220
			StringBuffer buffer= new StringBuffer(PROJECT_TAG);
221
			// Append the project-relative path (workspace path minus first segment)
222
			buffer.append('/').append(config.getFile().getFullPath().removeFirstSegments(1));
223
			args.put(LAUNCH_CONFIG_HANDLE, buffer.toString());
224
		}
225
		command.setBuilderName(ExternalToolBuilder.ID);
226
		command.setArguments(args);
227
		return command;
228
	}
105
	}
229
	
106
	
230
	/**
107
	/**
Lines 233-239 Link Here
233
	 * if an extension has been specified to explicitly declare the mapping.
110
	 * if an extension has been specified to explicitly declare the mapping.
234
	 */
111
	 */
235
	public static ILaunchConfigurationType getConfigurationDuplicationType(ILaunchConfiguration config) throws CoreException {
112
	public static ILaunchConfigurationType getConfigurationDuplicationType(ILaunchConfiguration config) throws CoreException {
236
		IExtensionPoint ep= Platform.getExtensionRegistry().getExtensionPoint(IExternalToolConstants.PLUGIN_ID, IExternalToolConstants.EXTENSION_POINT_CONFIGURATION_DUPLICATION_MAPS); 
113
		IExtensionPoint ep= Platform.getExtensionRegistry().getExtensionPoint(ExternalToolsPlugin.PLUGIN_ID, IExternalToolConstants.EXTENSION_POINT_CONFIGURATION_DUPLICATION_MAPS); 
237
		IConfigurationElement[] elements = ep.getConfigurationElements();
114
		IConfigurationElement[] elements = ep.getConfigurationElements();
238
		String sourceType= config.getType().getIdentifier();
115
		String sourceType= config.getType().getIdentifier();
239
		String builderType= null;
116
		String builderType= null;
Lines 258-272 Link Here
258
	 * <code>null</code> if the folder could not be created
135
	 * <code>null</code> if the folder could not be created
259
	 */
136
	 */
260
	public static IFolder getBuilderFolder(IProject project, boolean create) {
137
	public static IFolder getBuilderFolder(IProject project, boolean create) {
261
		IFolder folder = project.getFolder(BUILDER_FOLDER_NAME);
138
		return BuilderCoreUtils.getBuilderFolder(project, create);
262
		if (!folder.exists() && create) {
263
			try {
264
				folder.create(true, true, new NullProgressMonitor());
265
			} catch (CoreException e) {
266
				return null;
267
			}
268
		}
269
		return folder;
270
	}
139
	}
271
140
272
	/**
141
	/**
Lines 302-323 Link Here
302
	 * new launch configuration
171
	 * new launch configuration
303
	 */
172
	 */
304
	public static ILaunchConfiguration migrateBuilderConfiguration(IProject project, ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
173
	public static ILaunchConfiguration migrateBuilderConfiguration(IProject project, ILaunchConfigurationWorkingCopy workingCopy) throws CoreException {
305
		workingCopy.setContainer(getBuilderFolder(project, true));
174
		return BuilderCoreUtils.migrateBuilderConfiguration(project, workingCopy);
306
		// Before saving, make sure the name is valid
307
		String name= workingCopy.getName();
308
		name= name.replace('/', '.');
309
		if (name.charAt(0) == ('.')) {
310
			name = name.substring(1);
311
		}
312
		IStatus status = ResourcesPlugin.getWorkspace().validateName(name, IResource.FILE);
313
		if (!status.isOK()) {
314
			name = "ExternalTool"; //$NON-NLS-1$
315
		}
316
		name = DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(name);
317
		workingCopy.rename(name);
318
		return workingCopy.doSave();
319
	}
175
	}
320
176
	
321
    /**
177
    /**
322
     * Converts the build types string into an array of
178
     * Converts the build types string into an array of
323
     * build kinds.
179
     * build kinds.
Lines 326-386 Link Here
326
     * @return the array of build kinds.
182
     * @return the array of build kinds.
327
     */
183
     */
328
    public static int[] buildTypesToArray(String buildTypes) {
184
    public static int[] buildTypesToArray(String buildTypes) {
329
    	if (buildTypes == null || buildTypes.length() == 0) {
185
    	return BuilderCoreUtils.buildTypesToArray(buildTypes);
330
    		return DEFAULT_BUILD_TYPES;
186
    }	
331
    	}
332
    	
333
    	int count = 0;
334
    	boolean incremental = false;
335
    	boolean full = false;
336
    	boolean auto = false;
337
        boolean clean= false;
338
    
339
    	StringTokenizer tokenizer = new StringTokenizer(buildTypes, BUILD_TYPE_SEPARATOR);
340
    	while (tokenizer.hasMoreTokens()) {
341
    		String token = tokenizer.nextToken();
342
    		if (IExternalToolConstants.BUILD_TYPE_INCREMENTAL.equals(token)) {
343
    			if (!incremental) {
344
    				incremental = true;
345
    				count++;
346
    			}
347
    		} else if (IExternalToolConstants.BUILD_TYPE_FULL.equals(token)) {
348
    			if (!full) {
349
    				full = true;
350
    				count++;
351
    			}
352
    		} else if (IExternalToolConstants.BUILD_TYPE_AUTO.equals(token)) {
353
    			if (!auto) {
354
    				auto = true;
355
    				count++;
356
    			}
357
    		} else if (IExternalToolConstants.BUILD_TYPE_CLEAN.equals(token)) {
358
                if (!clean) {
359
                    clean = true;
360
                    count++;
361
                }
362
            }
363
    	}
364
    
365
    	int[] results = new int[count];
366
    	count = 0;
367
    	if (incremental) {
368
    		results[count] = IncrementalProjectBuilder.INCREMENTAL_BUILD;
369
    		count++;
370
    	}
371
    	if (full) {
372
    		results[count] = IncrementalProjectBuilder.FULL_BUILD;
373
    		count++;
374
    	}
375
    	if (auto) {
376
    		results[count] = IncrementalProjectBuilder.AUTO_BUILD;
377
    		count++;
378
    	}
379
        if (clean) {
380
            results[count] = IncrementalProjectBuilder.CLEAN_BUILD;
381
            count++;
382
        }
383
    
384
    	return results;
385
    }
386
}
187
}
(-)External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolBuilder.java (-288 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Matthew Conway  - Bug 175186
11
 *******************************************************************************/
12
package org.eclipse.ui.externaltools.internal.model;
13
14
15
import java.util.Map;
16
17
import org.eclipse.core.resources.ICommand;
18
import org.eclipse.core.resources.IFile;
19
import org.eclipse.core.resources.IProject;
20
import org.eclipse.core.resources.IProjectDescription;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.resources.IResourceDelta;
23
import org.eclipse.core.resources.IResourceDeltaVisitor;
24
import org.eclipse.core.resources.IncrementalProjectBuilder;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IPath;
27
import org.eclipse.core.runtime.IProgressMonitor;
28
import org.eclipse.debug.core.ILaunchConfiguration;
29
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
30
import org.eclipse.debug.core.ILaunchManager;
31
import org.eclipse.osgi.util.NLS;
32
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
33
import org.eclipse.ui.externaltools.internal.registry.ExternalToolMigration;
34
import org.osgi.framework.Bundle;
35
36
/**
37
 * This project builder implementation will run an external tool during the
38
 * build process. 
39
 */
40
public final class ExternalToolBuilder extends IncrementalProjectBuilder {
41
	private final class IgnoreTeamPrivateChanges implements IResourceDeltaVisitor {
42
		private boolean[] fTrueChange;
43
		private IgnoreTeamPrivateChanges(boolean[] trueChange) {
44
			super();
45
			fTrueChange= trueChange;
46
		}
47
		public boolean visit(IResourceDelta visitDelta) throws CoreException {
48
			IResource resource= visitDelta.getResource();
49
			if (resource instanceof IFile) {
50
				fTrueChange[0]= true;
51
				return false;
52
			}
53
			return true;
54
		}
55
	}
56
57
	public static final String ID = "org.eclipse.ui.externaltools.ExternalToolBuilder"; //$NON-NLS-1$;
58
59
	private static String buildType = IExternalToolConstants.BUILD_TYPE_NONE;
60
	
61
	private static IProject buildProject= null;
62
    private static IResourceDelta buildDelta= null;
63
	
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.core.internal.events.InternalBuilder#build(int, java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
66
	 */
67
	protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {		
68
		if (ExternalToolsPlugin.getDefault().getBundle().getState() != Bundle.ACTIVE) {
69
			return null;
70
		}
71
		
72
		ILaunchConfiguration config= BuilderUtils.configFromBuildCommandArgs(getProject(), args, new String[1]);
73
        if (config == null) {
74
            throw ExternalToolsPlugin.newError(ExternalToolsModelMessages.ExternalToolBuilder_0, null);
75
        }
76
		IProject[] projectsWithinScope= null;
77
		IResource[] resources = ExternalToolsUtil.getResourcesForBuildScope(config);
78
		if (resources != null) {
79
			projectsWithinScope= new IProject[resources.length];
80
			for (int i = 0; i < resources.length; i++) {
81
				projectsWithinScope[i]= resources[i].getProject();
82
			}
83
		}
84
        boolean kindCompatible= commandConfiguredForKind(config, kind);
85
        if (kindCompatible && configEnabled(config)) {
86
            doBuildBasedOnScope(resources, kind, config, monitor);
87
        }
88
        
89
		return projectsWithinScope;
90
	}
91
92
    private boolean commandConfiguredForKind(ILaunchConfiguration config, int kind) {
93
        try {
94
            if (!(config.getAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, false))) {
95
                ICommand command= getCommand();
96
                //adapt the builder command to make use of the 3.1 support for setting command build kinds
97
                //this will only happen once for builder/command defined before the support existed
98
                BuilderUtils.configureTriggers(config, command);
99
                IProjectDescription desc= getProject().getDescription();
100
                ICommand[] commands= desc.getBuildSpec();
101
                int index= getBuilderCommandIndex(commands, command);
102
                if (index != -1) {
103
                    commands[index]= command;
104
                    desc.setBuildSpec(commands);
105
                    getProject().setDescription(desc, null);
106
                    ILaunchConfigurationWorkingCopy copy= config.getWorkingCopy();
107
                    copy.setAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, true);
108
                    copy.doSave();
109
                }
110
                return command.isBuilding(kind);
111
            }
112
        } catch (CoreException e) {
113
           ExternalToolsPlugin.getDefault().log(e);
114
           return true;
115
        }
116
        return true;
117
    }
118
    
119
    private int getBuilderCommandIndex(ICommand[] buildSpec, ICommand command) {
120
        Map commandArgs= command.getArguments();
121
        if (commandArgs == null) {
122
            return -1;
123
        }
124
        String handle= (String) commandArgs.get(BuilderUtils.LAUNCH_CONFIG_HANDLE);
125
        if (handle == null) {
126
            return -1;
127
        }
128
        for (int i = 0; i < buildSpec.length; ++i) {
129
            ICommand buildSpecCommand= buildSpec[i];
130
            if (ID.equals(buildSpecCommand.getBuilderName())) {
131
                Map buildSpecArgs= buildSpecCommand.getArguments();
132
                if (buildSpecArgs != null) {
133
                    String buildSpecHandle= (String) buildSpecArgs.get(BuilderUtils.LAUNCH_CONFIG_HANDLE);
134
                    if (handle.equals(buildSpecHandle)) {
135
                        return i;
136
                    }
137
                }
138
            }
139
        }
140
        return -1;
141
    }
142
143
	/**
144
	 * Returns whether the given builder config is enabled or not.
145
	 * 
146
	 * @param config the config to examine
147
	 * @return whether the config is enabled
148
	 */
149
	private boolean configEnabled(ILaunchConfiguration config) {
150
		try {
151
			return ExternalToolsUtil.isBuilderEnabled(config);
152
		} catch (CoreException e) {
153
			ExternalToolsPlugin.getDefault().log(e);
154
		}
155
		return true;
156
	}
157
158
	private void doBuildBasedOnScope(IResource[] resources, int kind, ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
159
		boolean buildForChange = true;
160
		if (kind != FULL_BUILD) { //scope not applied for full builds
161
			if (resources != null && resources.length > 0) {
162
				buildForChange = buildScopeIndicatesBuild(resources);
163
			}
164
		}
165
166
		if (buildForChange) {
167
			launchBuild(kind, config, monitor);
168
		}
169
	}
170
	
171
	private void launchBuild(int kind, ILaunchConfiguration config, IProgressMonitor monitor) throws CoreException {
172
		monitor.subTask(NLS.bind(ExternalToolsModelMessages.ExternalToolBuilder_Running__0_____1, new String[] { config.getName()}));
173
		buildStarted(kind);
174
		// The default value for "launch in background" is true in debug core. If
175
		// the user doesn't go through the UI, the new attribute won't be set. This means
176
		// that existing Ant builders will try to run in the background (and likely conflict with
177
		// each other) without migration.
178
		config= ExternalToolMigration.migrateRunInBackground(config);
179
		config.launch(ILaunchManager.RUN_MODE, monitor);
180
		buildEnded();
181
	}
182
183
	/**
184
	 * Returns the build type being performed if the
185
	 * external tool is being run as a project builder.
186
	 * 
187
	 * @return one of the <code>IExternalToolConstants.BUILD_TYPE_*</code> constants.
188
	 */
189
	public static String getBuildType() {
190
		return buildType;
191
	}
192
	
193
	/**
194
	 * Returns the project that is being built and has triggered the current external
195
	 * tool builder. <code>null</code> is returned if no build is currently occurring.
196
	 * 
197
	 * @return project being built or <code>null</code>.
198
	 */
199
	public static IProject getBuildProject() {
200
		return buildProject;
201
	}
202
203
    /**
204
     * Returns the <code>IResourceDelta</code> that is being built and has triggered the current external
205
     * tool builder. <code>null</code> is returned if no build is currently occurring.
206
     * 
207
     * @return resource delta for the build or <code>null</code>
208
     */
209
    public static IResourceDelta getBuildDelta() {
210
        return buildDelta;
211
    }
212
    
213
	/**
214
	 * Stores the currently active build kind and build project when a build begins
215
	 * @param buildKind
216
	 */
217
	private void buildStarted(int buildKind) {
218
		switch (buildKind) {
219
			case IncrementalProjectBuilder.INCREMENTAL_BUILD :
220
				buildType = IExternalToolConstants.BUILD_TYPE_INCREMENTAL;
221
				buildDelta = getDelta(getProject());
222
				break;
223
			case IncrementalProjectBuilder.FULL_BUILD :
224
				buildType = IExternalToolConstants.BUILD_TYPE_FULL;
225
				break;
226
			case IncrementalProjectBuilder.AUTO_BUILD :
227
				buildType = IExternalToolConstants.BUILD_TYPE_AUTO;
228
				buildDelta = getDelta(getProject());
229
				break;
230
            case IncrementalProjectBuilder.CLEAN_BUILD :
231
                buildType = IExternalToolConstants.BUILD_TYPE_CLEAN;
232
                break;
233
			default :
234
				buildType = IExternalToolConstants.BUILD_TYPE_NONE;
235
				break;
236
		}
237
		buildProject= getProject();
238
	}
239
	
240
	/**
241
	 * Clears the current build kind, build project and build delta when a build finishes.
242
	 */
243
	private void buildEnded() {
244
		buildType= IExternalToolConstants.BUILD_TYPE_NONE;
245
		buildProject= null;
246
        buildDelta= null;
247
	}
248
	
249
	private boolean buildScopeIndicatesBuild(IResource[] resources) {
250
		for (int i = 0; i < resources.length; i++) {
251
			IResourceDelta delta = getDelta(resources[i].getProject());
252
			if (delta == null) {
253
				//project just added to the workspace..no previous build tree
254
				return true;
255
			} 
256
			IPath path= resources[i].getProjectRelativePath();
257
			IResourceDelta change= delta.findMember(path);
258
			if (change != null) {
259
				final boolean[] trueChange= new boolean[1];
260
				trueChange[0]= false;
261
				try {
262
					change.accept(new IgnoreTeamPrivateChanges(trueChange));
263
				} catch (CoreException e) {
264
					ExternalToolsPlugin.getDefault().log("Internal error resolving changed resources during build", e); //$NON-NLS-1$
265
				}
266
				
267
				return trueChange[0]; //filtered out team private changes
268
			}
269
		}
270
		return false;
271
	}
272
    
273
    protected void clean(IProgressMonitor monitor) throws CoreException {
274
	    ICommand command= getCommand();
275
        ILaunchConfiguration config= BuilderUtils.configFromBuildCommandArgs(getProject(), command.getArguments(), new String[1]);
276
    	if (!configEnabled(config)) {
277
	    	return;
278
	    }
279
        
280
        if ((!config.getAttribute(IExternalToolConstants.ATTR_TRIGGERS_CONFIGURED, false))) {
281
            //old behavior
282
            super.clean(monitor);
283
            return;
284
        }
285
	
286
		launchBuild(IncrementalProjectBuilder.CLEAN_BUILD, config, monitor);
287
    }
288
}
(-)External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolsImages.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-19 Link Here
14
import java.net.MalformedURLException;
14
import java.net.MalformedURLException;
15
import java.net.URL;
15
import java.net.URL;
16
16
17
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
17
import org.eclipse.jface.action.IAction;
18
import org.eclipse.jface.action.IAction;
18
import org.eclipse.jface.resource.CompositeImageDescriptor;
19
import org.eclipse.jface.resource.CompositeImageDescriptor;
19
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.resource.ImageDescriptor;
(-)External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolsModelMessages.java (-28 lines)
Removed Link Here
1
/**********************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: 
8
 * IBM - Initial API and implementation
9
 **********************************************************************/
10
package org.eclipse.ui.externaltools.internal.model;
11
12
import org.eclipse.osgi.util.NLS;
13
14
public class ExternalToolsModelMessages extends NLS {
15
	private static final String BUNDLE_NAME = "org.eclipse.ui.externaltools.internal.model.ExternalToolsModelMessages";//$NON-NLS-1$
16
    
17
	public static String ImageDescriptorRegistry_Allocating_image_for_wrong_display_1;
18
	public static String ExternalToolBuilder_Running__0_____1;
19
	public static String ExternalToolBuilder_0;
20
	public static String BuilderUtils_5;
21
	public static String BuilderUtils_6;
22
	public static String BuilderUtils_7;
23
24
	static {
25
		// load message values from bundle file
26
		NLS.initializeMessages(BUNDLE_NAME, ExternalToolsModelMessages.class);
27
	}
28
}
(-)External Tools Base/org/eclipse/ui/externaltools/internal/model/ExternalToolsPlugin.java (-9 / +133 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-28 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.externaltools.internal.model;
11
package org.eclipse.ui.externaltools.internal.model;
12
12
13
14
import java.net.MalformedURLException;
13
import java.net.MalformedURLException;
15
import java.net.URL;
14
import java.net.URL;
16
15
16
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
17
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.ILaunch;
22
import org.eclipse.debug.core.ILaunchConfiguration;
23
import org.eclipse.debug.core.ILaunchConfigurationType;
24
import org.eclipse.debug.core.ILaunchListener;
25
import org.eclipse.debug.core.ILaunchManager;
26
import org.eclipse.debug.internal.ui.views.console.ProcessConsoleManager;
27
import org.eclipse.jface.dialogs.MessageDialog;
20
import org.eclipse.jface.resource.ImageDescriptor;
28
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.resource.ImageRegistry;
29
import org.eclipse.jface.resource.ImageRegistry;
22
import org.eclipse.swt.widgets.Display;
30
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Shell;
31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.ui.IWindowListener;
24
import org.eclipse.ui.IWorkbenchPage;
33
import org.eclipse.ui.IWorkbenchPage;
25
import org.eclipse.ui.IWorkbenchWindow;
34
import org.eclipse.ui.IWorkbenchWindow;
35
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.ui.externaltools.internal.program.launchConfigurations.ExternalToolsProgramMessages;
26
import org.eclipse.ui.plugin.AbstractUIPlugin;
37
import org.eclipse.ui.plugin.AbstractUIPlugin;
27
import org.osgi.framework.Bundle;
38
import org.osgi.framework.Bundle;
28
import org.osgi.framework.BundleContext;
39
import org.osgi.framework.BundleContext;
Lines 30-44 Link Here
30
/**
41
/**
31
 * External tools plug-in class
42
 * External tools plug-in class
32
 */
43
 */
33
public final class ExternalToolsPlugin extends AbstractUIPlugin {
44
public final class ExternalToolsPlugin extends AbstractUIPlugin implements
45
		ILaunchListener {
46
	
47
	public static final String PLUGIN_ID = "org.eclipse.ui.externaltools"; //$NON-NLS-1$
48
	
34
	/**
49
	/**
35
	 * Status representing no problems encountered during operation.
50
	 * Status representing no problems encountered during operation.
36
	 */
51
	 */
37
	public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
52
	public static final IStatus OK_STATUS = new Status(IStatus.OK, PLUGIN_ID, 0, "", null); //$NON-NLS-1$
38
53
		
39
	private static ExternalToolsPlugin plugin;
54
	private static ExternalToolsPlugin plugin;
40
	
55
41
	private static final String EMPTY_STRING= ""; //$NON-NLS-1$
56
	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
57
58
	private static IWindowListener fWindowListener;
59
60
	private static ILaunchManager launchManager;
61
62
	/**
63
	 * Singleton console document manager
64
	 */
65
	private ProcessConsoleManager fProcessConsoleManager = null;
66
67
	/**
68
	 * A window listener that warns the user about any running programs when the
69
	 * workbench closes. Programs are killed when the VM exits.
70
	 */
71
	private class ProgramLaunchWindowListener implements IWindowListener {
72
		public void windowActivated(IWorkbenchWindow window) {
73
		}
74
75
		public void windowDeactivated(IWorkbenchWindow window) {
76
		}
77
78
		public void windowClosed(IWorkbenchWindow window) {
79
			IWorkbenchWindow windows[] = PlatformUI.getWorkbench()
80
					.getWorkbenchWindows();
81
			if (windows.length > 1) {
82
				// There are more windows still open.
83
				return;
84
			}
85
			ILaunchManager manager = DebugPlugin.getDefault()
86
					.getLaunchManager();
87
			ILaunchConfigurationType programType = manager
88
					.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE);
89
			if (programType == null) {
90
				return;
91
			}
92
			ILaunch launches[] = manager.getLaunches();
93
			ILaunchConfigurationType configType;
94
			ILaunchConfiguration config;
95
			for (int i = 0; i < launches.length; i++) {
96
				try {
97
					config = launches[i].getLaunchConfiguration();
98
					if (config == null) {
99
						continue;
100
					}
101
					configType = config.getType();
102
				} catch (CoreException e) {
103
					continue;
104
				}
105
				if (configType.equals(programType)) {
106
					if (!launches[i].isTerminated()) {
107
						MessageDialog
108
								.openWarning(
109
										window.getShell(),
110
										ExternalToolsProgramMessages.ProgramLaunchDelegate_Workbench_Closing_1,
111
										ExternalToolsProgramMessages.ProgramLaunchDelegate_The_workbench_is_exiting);
112
						break;
113
					}
114
				}
115
			}
116
		}
117
118
		public void windowOpened(IWorkbenchWindow window) {
119
		}
120
	}
42
121
43
	/**
122
	/**
44
	 * Create an instance of the External Tools plug-in.
123
	 * Create an instance of the External Tools plug-in.
Lines 63-76 Link Here
63
		if (message == null) {
142
		if (message == null) {
64
			message= EMPTY_STRING; 
143
			message= EMPTY_STRING; 
65
		}		
144
		}		
66
		return new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception);
145
		return new Status(IStatus.ERROR, PLUGIN_ID, 0, message, exception);
67
	}
146
	}
68
147
69
	/**
148
	/**
70
	 * Returns a new <code>CoreException</code> for this plug-in
149
	 * Returns a new <code>CoreException</code> for this plug-in
71
	 */
150
	 */
72
	public static CoreException newError(String message, Throwable exception) {
151
	public static CoreException newError(String message, Throwable exception) {
73
		return new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception));
152
		return new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, 0, message, exception));
74
	}
153
	}
75
154
76
	/**
155
	/**
Lines 164-167 Link Here
164
			super.stop(context);
243
			super.stop(context);
165
		}
244
		}
166
	}
245
	}
246
247
	public void start(BundleContext context) throws Exception {
248
		super.start(context);
249
		// Listen to launches to lazily create "launch processors"
250
		launchManager = DebugPlugin.getDefault().getLaunchManager();
251
		ILaunch[] launches = launchManager.getLaunches();
252
		if (launches.length > 0) {
253
			if (fWindowListener == null) {
254
				fWindowListener = new ProgramLaunchWindowListener();
255
				PlatformUI.getWorkbench().addWindowListener(fWindowListener);
256
			}
257
		} else {
258
			// if no launches, wait for first launch to initialize processors
259
			launchManager.addLaunchListener(this);
260
		}
261
	}
262
263
	public void launchAdded(ILaunch launch) {
264
		ILaunchConfiguration launchConfiguration = launch
265
				.getLaunchConfiguration();
266
		try {
267
			ILaunchConfigurationType launchConfigurationType = launchConfiguration
268
					.getType();
269
			if (launchConfigurationType
270
					.getIdentifier()
271
					.equals(
272
							IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE)) {
273
				if (fWindowListener == null) {
274
					fWindowListener = new ProgramLaunchWindowListener();
275
					PlatformUI.getWorkbench()
276
							.addWindowListener(fWindowListener);
277
				}
278
			}
279
		} catch (CoreException e) {
280
			log(e);
281
		}
282
	}
283
284
	public void launchChanged(ILaunch launch) {
285
286
	}
287
288
	public void launchRemoved(ILaunch launch) {
289
		launchManager.removeLaunch(launch);
290
	}
167
}
291
}
(-)External Tools Base/org/eclipse/ui/externaltools/internal/model/IExternalToolConstants.java (-231 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     dakshinamurthy.karra@gmail.com - bug 165371
11
 *******************************************************************************/
12
package org.eclipse.ui.externaltools.internal.model;
13
14
/**
15
 * Defines the constants available for client use.
16
 * <p>
17
 * This interface is not intended to be extended or implemented by clients.
18
 * </p>
19
 */
20
public interface IExternalToolConstants {
21
	/**
22
	 * Plugin identifier for external tools (value <code>org.eclipse.ui.externaltools</code>).
23
	 */
24
	public static final String PLUGIN_ID = "org.eclipse.ui.externaltools"; //$NON-NLS-1$;
25
26
	// ------- Extensions Points -------
27
	/**
28
	 * Extension point to declare the launch configuration type that should be
29
	 * created when duplicating an existing configuration as a project builder.
30
	 */
31
	public static final String EXTENSION_POINT_CONFIGURATION_DUPLICATION_MAPS = "configurationDuplicationMaps"; //$NON-NLS-1$
32
	// ------- Refresh Variables -------
33
	/**
34
	 * Variable that expands to the workspace root object (value <code>workspace</code>).
35
	 */
36
	public static final String VAR_WORKSPACE = "workspace"; //$NON-NLS-1$
37
	/**
38
	 * Variable that expands to the project resource (value <code>project</code>).
39
	 */
40
	public static final String VAR_PROJECT = "project"; //$NON-NLS-1$
41
	/**
42
	 * Variable that expands to the container resource (value <code>container</code>).
43
	 */
44
	public static final String VAR_CONTAINER = "container"; //$NON-NLS-1$
45
	/**
46
	 * Variable that expands to a resource (value <code>resource</code>).
47
	 */
48
	public static final String VAR_RESOURCE = "resource"; //$NON-NLS-1$
49
	/**
50
	 * Variable that expands to the working set object (value <code>working_set</code>).
51
	 */
52
	public static final String VAR_WORKING_SET = "working_set"; //$NON-NLS-1$
53
	// ------- Tool Types -------
54
	/**
55
	 * External tool type for programs such as executables, batch files, 
56
	 * shell scripts, etc (value <code>programType</code>).
57
	 */
58
	public static final String TOOL_TYPE_PROGRAM = "programType"; //$NON-NLS-1$;
59
60
	// ------- Build Types -------
61
	/**
62
	 * Build type indicating an incremental project build request for
63
	 * the external tool running as a builder (value <code>incremental</code>).
64
	 */
65
	public static final String BUILD_TYPE_INCREMENTAL = "incremental"; //$NON-NLS-1$
66
67
	/**
68
	 * Build type indicating a full project build request for
69
	 * the external tool running as a builder (value <code>full</code>).
70
	 */
71
	public static final String BUILD_TYPE_FULL = "full"; //$NON-NLS-1$
72
73
	/**
74
	 * Build type indicating an automatic project build request for
75
	 * the external tool running as a builder (value <code>auto</code>).
76
	 */
77
	public static final String BUILD_TYPE_AUTO = "auto"; //$NON-NLS-1$
78
	
79
	/**
80
	 * Build type indicating a clean project build request for
81
	 * the external tool running as a builder (value <code>clean</code>).
82
	 */
83
	public static final String BUILD_TYPE_CLEAN = "clean"; //$NON-NLS-1$
84
85
	/**
86
	 * Build type indicating no project build request for
87
	 * the external tool running as a builder (value <code>none</code>).
88
	 */
89
	public static final String BUILD_TYPE_NONE = "none"; //$NON-NLS-1$
90
91
	// ------- Images -------
92
93
	/**
94
	 * Main tab image.
95
	 */
96
	public static final String IMG_TAB_MAIN = PLUGIN_ID + ".IMG_TAB_MAIN"; //$NON-NLS-1$
97
98
	/**
99
	 * Build tab image
100
	 */
101
	public static final String IMG_TAB_BUILD = PLUGIN_ID + ".IMG_TAB_BUILD"; //$NON-NLS-1$
102
103
	// ------- Launch configuration types --------
104
	/**
105
	 * Program launch configuration type identifier.
106
	 */
107
	public static final String ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"; //$NON-NLS-1$
108
	
109
	/**
110
	 * Program builder launch configuration type identifier. Program project
111
	 * builders are of this type.
112
	 */
113
	public static final String ID_PROGRAM_BUILDER_LAUNCH_CONFIGURATION_TYPE = "org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType"; //$NON-NLS-1$	
114
	
115
	// ------- Launch configuration category --------
116
	/**
117
	 * Identifier for external tools launch configuration category. Launch
118
	 * configuration types for external tools that appear in the external tools
119
	 * launch configuration dialog should belong to this category.
120
	 */
121
	public static final String ID_EXTERNAL_TOOLS_LAUNCH_CATEGORY = "org.eclipse.ui.externaltools"; //$NON-NLS-1$
122
	/**
123
	 * Identifier for external tools launch configuration builders category.
124
	 * Launch configuration types that can be added as project builders should
125
	 * belong to this category.
126
	 */
127
	public static final String ID_EXTERNAL_TOOLS_BUILDER_LAUNCH_CATEGORY = "org.eclipse.ui.externaltools.builder"; //$NON-NLS-1$
128
129
	// ------- Launch configuration groups --------
130
	/**
131
	 * Identifier for external tools launch configuration group. The external
132
	 * tools launch configuration group corresponds to the external tools
133
	 * category in run mode.
134
	 */
135
	public static final String ID_EXTERNAL_TOOLS_LAUNCH_GROUP = "org.eclipse.ui.externaltools.launchGroup"; //$NON-NLS-1$
136
	/**
137
	 * Identifier for external tools launch configuration group
138
	 */
139
	public static final String ID_EXTERNAL_TOOLS_BUILDER_LAUNCH_GROUP = "org.eclipse.ui.externaltools.launchGroup.builder"; //$NON-NLS-1$
140
141
	// ------- Common External Tool Launch Configuration Attributes -------
142
143
	/**
144
	 * Boolean attribute indicating if external tool output should be captured.
145
	 * Default value is <code>false</code>.
146
	 * @deprecated since 3.1 Replaced by <code>org.eclipse.debug.core.DebugPlugin.ATTR_CAPTURE_OUTPUT</code>
147
	 */
148
	public static final String ATTR_CAPTURE_OUTPUT = PLUGIN_ID + ".ATTR_CAPTURE_OUTPUT"; //$NON-NLS-1$
149
	/**
150
	 * String attribute identifying the location of an external. Default value
151
	 * is <code>null</code>. Encoding is tool specific.
152
	 */
153
	public static final String ATTR_LOCATION = PLUGIN_ID + ".ATTR_LOCATION"; //$NON-NLS-1$
154
155
	/**
156
	 * Boolean attribute indicating if the user should be prompted for
157
	 * arguments before running a tool. Default value is <code>false</code>.
158
	 * THIS ATTRIBUTE IS NOT USED.
159
	 */
160
	public static final String ATTR_PROMPT_FOR_ARGUMENTS = PLUGIN_ID + ".ATTR_PROMPT_FOR_ARGUMENTS"; //$NON-NLS-1$
161
	
162
	/**
163
	 * String attribute identifying the scope of resources that should trigger an 
164
	 * external tool to run. Default value is <code>null</code>
165
	 * indicating that the builder will be triggered for all changes.
166
	 */
167
	public static final String ATTR_BUILDER_SCOPE = PLUGIN_ID + ".ATTR_BUILD_SCOPE"; //$NON-NLS-1$
168
		
169
	/**
170
	 * String attribute containing an array of build kinds for which an
171
	 * external tool builder should be run.
172
	 */
173
	public static final String ATTR_RUN_BUILD_KINDS = PLUGIN_ID + ".ATTR_RUN_BUILD_KINDS"; //$NON-NLS-1$
174
	
175
	/**
176
	 * Boolean attribute indicating if the console should be shown on external
177
	 * tool output. Default value is <code>false</code>.
178
	 */
179
	public static final String ATTR_SHOW_CONSOLE = PLUGIN_ID + ".ATTR_SHOW_CONSOLE"; //$NON-NLS-1$
180
181
	/**
182
	 * String attribute containing the arguments that should be passed to the
183
	 * tool. Default value is <code>null</code>, and encoding is tool specific.
184
	 */
185
	public static final String ATTR_TOOL_ARGUMENTS = PLUGIN_ID + ".ATTR_TOOL_ARGUMENTS"; //$NON-NLS-1$
186
187
	/**
188
	 * String attribute identifying the working directory of an external tool.
189
	 * Default value is <code>null</code>, which indicates a default working
190
	 * directory, which is tool specific.
191
	 */
192
	public static final String ATTR_WORKING_DIRECTORY = PLUGIN_ID + ".ATTR_WORKING_DIRECTORY"; //$NON-NLS-1$
193
	
194
	/**
195
	 * String attribute identifying whether an external tool builder configuration
196
	 * is enabled. The default value is <code>true</code>, which indicates
197
	 * that the configuration will be executed as appropriate by the builder.
198
	 */
199
	public static final String ATTR_BUILDER_ENABLED = PLUGIN_ID + ".ATTR_BUILDER_ENABLED"; //$NON-NLS-1$
200
	
201
	/**
202
	 * Status code indicating an unexpected internal error.
203
	 */
204
	public static final int ERR_INTERNAL_ERROR = 150;
205
206
	/**
207
	 * String attribute identifying a non-external tool builder launch configuration that is disabled
208
	 * The value is the name of the disabled builder.
209
	 */
210
	public static final String ATTR_DISABLED_BUILDER = PLUGIN_ID + ".ATTR_DISABLED_BUILDER";		 //$NON-NLS-1$
211
	
212
	/**
213
	 * boolean attribute identifying that an external tool builder has been configured for triggering
214
	 * using the <code>ICommand.setBuilding(int)</code> mechanism
215
	 * @since 3.1
216
	 */
217
	public static final String ATTR_TRIGGERS_CONFIGURED = PLUGIN_ID + ".ATTR_TRIGGERS_CONFIGURED";		 //$NON-NLS-1$
218
219
	/**
220
	 * String attribute identifying the build scope for a launch configuration.
221
	 * <code>null</code> indicates the default workspace build.
222
	 */
223
	public static final String ATTR_BUILD_SCOPE = PLUGIN_ID + ".ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE"; //$NON-NLS-1$
224
225
	/**
226
	 * Attribute identifier specifying whether referenced projects should be 
227
	 * considered when computing the projects to build. Default value is
228
	 * <code>true</code>.
229
	 */
230
	public static final String ATTR_INCLUDE_REFERENCED_PROJECTS = PLUGIN_ID + ".ATTR_INCLUDE_REFERENCED_PROJECTS"; //$NON-NLS-1$
231
}
(-)External Tools Base/org/eclipse/ui/externaltools/internal/model/ImageDescriptorRegistry.java (-1 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 14-19 Link Here
14
import java.util.HashMap;
14
import java.util.HashMap;
15
import java.util.Iterator;
15
import java.util.Iterator;
16
16
17
import org.eclipse.core.internal.externaltools.model.ExternalToolsModelMessages;
17
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.swt.graphics.Image;
(-)External Tools Base/org/eclipse/ui/externaltools/internal/registry/ExternalToolMigration.java (-7 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 15-20 Link Here
15
import java.util.Map;
15
import java.util.Map;
16
import java.util.StringTokenizer;
16
import java.util.StringTokenizer;
17
17
18
import org.eclipse.core.internal.externaltools.launchConfigurations.ExternalToolsMigrationMessages;
19
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
18
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.DebugPlugin;
20
import org.eclipse.debug.core.ILaunchConfiguration;
22
import org.eclipse.debug.core.ILaunchConfiguration;
Lines 24-31 Link Here
24
import org.eclipse.debug.ui.IDebugUIConstants;
26
import org.eclipse.debug.ui.IDebugUIConstants;
25
import org.eclipse.debug.ui.RefreshTab;
27
import org.eclipse.debug.ui.RefreshTab;
26
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
28
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
27
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
28
import org.eclipse.ui.externaltools.internal.ui.ExternalToolsUIMessages;
29
29
30
/**
30
/**
31
 * Responsible reading an old external tool format and creating
31
 * Responsible reading an old external tool format and creating
Lines 99-105 Link Here
99
	 * 		Ant no longer resides in External Tools and this plug-in. This value is kept here only
99
	 * 		Ant no longer resides in External Tools and this plug-in. This value is kept here only
100
	 * 		for migration.
100
	 * 		for migration.
101
	 */
101
	 */
102
	public static final String ATTR_ANT_TARGETS = IExternalToolConstants.PLUGIN_ID + ".ATTR_ANT_TARGETS"; //$NON-NLS-1$
102
	public static final String ATTR_ANT_TARGETS = IExternalToolConstants.UI_PLUGIN_ID + ".ATTR_ANT_TARGETS"; //$NON-NLS-1$
103
	
103
	
104
	/*
104
	/*
105
	 * 2.0 External Tool Tags
105
	 * 2.0 External Tool Tags
Lines 350-368 Link Here
350
		}
350
		}
351
		if (noValueFlag.equals(attr)) {
351
		if (noValueFlag.equals(attr)) {
352
			//the old constant
352
			//the old constant
353
			String ATTR_RUN_IN_BACKGROUND= IExternalToolConstants.PLUGIN_ID + ".ATTR_RUN_IN_BACKGROUND"; //$NON-NLS-1$
353
			String ATTR_RUN_IN_BACKGROUND= IExternalToolConstants.UI_PLUGIN_ID + ".ATTR_RUN_IN_BACKGROUND"; //$NON-NLS-1$
354
			boolean runInBackground= false;
354
			boolean runInBackground= false;
355
			try {
355
			try {
356
				runInBackground = config.getAttribute(ATTR_RUN_IN_BACKGROUND, runInBackground);
356
				runInBackground = config.getAttribute(ATTR_RUN_IN_BACKGROUND, runInBackground);
357
			} catch (CoreException e) {
357
			} catch (CoreException e) {
358
				ExternalToolsPlugin.getDefault().log(ExternalToolsUIMessages.ExternalToolMigration_37, e);
358
				ExternalToolsPlugin.getDefault().log(ExternalToolsMigrationMessages.ExternalToolMigration_37, e);
359
			}
359
			}
360
			try {
360
			try {
361
				ILaunchConfigurationWorkingCopy workingCopy= config.getWorkingCopy();
361
				ILaunchConfigurationWorkingCopy workingCopy= config.getWorkingCopy();
362
				workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, runInBackground);
362
				workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, runInBackground);
363
				config= workingCopy.doSave();
363
				config= workingCopy.doSave();
364
			} catch (CoreException e) {
364
			} catch (CoreException e) {
365
				ExternalToolsPlugin.getDefault().log(ExternalToolsUIMessages.ExternalToolMigration_38, e);
365
				ExternalToolsPlugin.getDefault().log(ExternalToolsMigrationMessages.ExternalToolMigration_38, e);
366
			}
366
			}
367
		}
367
		}
368
		return config;
368
		return config;
(-)External Tools Base/org/eclipse/ui/externaltools/internal/ui/BuilderLabelProvider.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.externaltools.internal.ui;
11
package org.eclipse.ui.externaltools.internal.ui;
12
12
13
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
13
import org.eclipse.core.resources.ICommand;
14
import org.eclipse.core.resources.ICommand;
14
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.resources.ResourcesPlugin;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
Lines 23-29 Link Here
23
import org.eclipse.osgi.util.NLS;
24
import org.eclipse.osgi.util.NLS;
24
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.swt.graphics.Image;
25
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
26
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
26
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
27
import org.eclipse.ui.externaltools.internal.ui.BuilderPropertyPage.ErrorConfig;
27
import org.eclipse.ui.externaltools.internal.ui.BuilderPropertyPage.ErrorConfig;
28
28
29
29
(-)External Tools Base/org/eclipse/ui/externaltools/internal/ui/BuilderPropertyPage.java (-7 / +8 lines)
Lines 18-23 Link Here
18
import java.util.List;
18
import java.util.List;
19
import java.util.Map;
19
import java.util.Map;
20
20
21
import org.eclipse.core.internal.externaltools.model.BuilderCoreUtils;
22
import org.eclipse.core.internal.externaltools.model.ExternalToolBuilder;
23
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
21
import org.eclipse.core.resources.ICommand;
24
import org.eclipse.core.resources.ICommand;
22
import org.eclipse.core.resources.IFolder;
25
import org.eclipse.core.resources.IFolder;
23
import org.eclipse.core.resources.IProject;
26
import org.eclipse.core.resources.IProject;
Lines 74-86 Link Here
74
import org.eclipse.ui.PlatformUI;
77
import org.eclipse.ui.PlatformUI;
75
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
78
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
76
import org.eclipse.ui.dialogs.PropertyPage;
79
import org.eclipse.ui.dialogs.PropertyPage;
77
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsMainTab;
78
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
80
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
81
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsMainTab;
79
import org.eclipse.ui.externaltools.internal.launchConfigurations.IgnoreWhiteSpaceComparator;
82
import org.eclipse.ui.externaltools.internal.launchConfigurations.IgnoreWhiteSpaceComparator;
80
import org.eclipse.ui.externaltools.internal.model.BuilderUtils;
83
import org.eclipse.ui.externaltools.internal.model.BuilderUtils;
81
import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder;
82
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
84
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
83
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
84
import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds;
85
import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds;
85
import org.eclipse.ui.externaltools.internal.model.IPreferenceConstants;
86
import org.eclipse.ui.externaltools.internal.model.IPreferenceConstants;
86
import org.eclipse.ui.progress.IProgressService;
87
import org.eclipse.ui.progress.IProgressService;
Lines 210-216 Link Here
210
		for (int i = 0; i < commands.length; i++) {
211
		for (int i = 0; i < commands.length; i++) {
211
			String[] version= new String[] {""}; //$NON-NLS-1$
212
			String[] version= new String[] {""}; //$NON-NLS-1$
212
			ILaunchConfiguration config = BuilderUtils.configFromBuildCommandArgs(project, commands[i].getArguments(), version);
213
			ILaunchConfiguration config = BuilderUtils.configFromBuildCommandArgs(project, commands[i].getArguments(), version);
213
			if (BuilderUtils.VERSION_2_1.equals(version[0])) {
214
			if (BuilderCoreUtils.VERSION_2_1.equals(version[0])) {
214
				// Storing the .project file of a project with 2.1 configs, will
215
				// Storing the .project file of a project with 2.1 configs, will
215
				// edit the file in a way that isn't backwards compatible.
216
				// edit the file in a way that isn't backwards compatible.
216
				projectNeedsMigration= true;
217
				projectNeedsMigration= true;
Lines 222-228 Link Here
222
                    if (shell == null) {
223
                    if (shell == null) {
223
                        return;
224
                        return;
224
                    }
225
                    }
225
					IStatus status = new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, 0, NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_Exists, new String[]{config.getName()}), null);
226
					IStatus status = new Status(IStatus.ERROR, ExternalToolsPlugin.PLUGIN_ID, 0, NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_Exists, new String[]{config.getName()}), null);
226
					ErrorDialog.openError(getShell(), ExternalToolsUIMessages.BuilderPropertyPage_errorTitle,
227
					ErrorDialog.openError(getShell(), ExternalToolsUIMessages.BuilderPropertyPage_errorTitle,
227
									NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_External_Tool_Builder__0__Not_Added_2, new String[]{config.getName()}),
228
									NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_External_Tool_Builder__0__Not_Added_2, new String[]{config.getName()}),
228
									status);
229
									status);
Lines 232-238 Link Here
232
				}
233
				}
233
			} else {
234
			} else {
234
				String builderID = commands[i].getBuilderName();
235
				String builderID = commands[i].getBuilderName();
235
				if (builderID.equals(ExternalToolBuilder.ID) && commands[i].getArguments().get(BuilderUtils.LAUNCH_CONFIG_HANDLE) != null) {
236
				if (builderID.equals(ExternalToolBuilder.ID) && commands[i].getArguments().get(BuilderCoreUtils.LAUNCH_CONFIG_HANDLE) != null) {
236
					// An invalid external tool entry.
237
					// An invalid external tool entry.
237
					element= new ErrorConfig(commands[i]);
238
					element= new ErrorConfig(commands[i]);
238
				} else {
239
				} else {
Lines 767-773 Link Here
767
		if (e instanceof CoreException) {
768
		if (e instanceof CoreException) {
768
			status[0] = ((CoreException) e).getStatus();
769
			status[0] = ((CoreException) e).getStatus();
769
		} else {
770
		} else {
770
			status[0] = new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, 0, ExternalToolsUIMessages.BuilderPropertyPage_statusMessage, e);
771
			status[0] = new Status(IStatus.ERROR, ExternalToolsPlugin.PLUGIN_ID, 0, ExternalToolsUIMessages.BuilderPropertyPage_statusMessage, e);
771
		}
772
		}
772
		Display.getDefault().asyncExec(new Runnable() {
773
		Display.getDefault().asyncExec(new Runnable() {
773
		    public void run() {
774
		    public void run() {
(-)External Tools Base/org/eclipse/ui/externaltools/internal/ui/ExternalToolsUIMessages.java (-3 / +1 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others. All rights reserved. This
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
5
 * available at http://www.eclipse.org/legal/epl-v10.html
Lines 55-62 Link Here
55
	public static String ExternalToolsPreferencePage_Prompt_before_migrating_3;
55
	public static String ExternalToolsPreferencePage_Prompt_before_migrating_3;
56
	public static String ExternalToolsPreferencePage_1;
56
	public static String ExternalToolsPreferencePage_1;
57
57
58
	public static String ExternalToolMigration_37;
59
	public static String ExternalToolMigration_38;
60
	public static String EditCommandDialog_0;
58
	public static String EditCommandDialog_0;
61
	public static String EditCommandDialog_1;
59
	public static String EditCommandDialog_1;
62
	public static String EditCommandDialog_2;
60
	public static String EditCommandDialog_2;
(-)External Tools Base/org/eclipse/ui/externaltools/internal/ui/ExternalToolsUIMessages.properties (-3 / +1 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2006 IBM Corporation and others.
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 50-57 Link Here
50
ExternalToolsPreferencePage_Prompt_before_migrating_3=&Confirm before migrating external tool project builders for edit
50
ExternalToolsPreferencePage_Prompt_before_migrating_3=&Confirm before migrating external tool project builders for edit
51
ExternalToolsPreferencePage_1=C&onfirm before migrating projects to the new format
51
ExternalToolsPreferencePage_1=C&onfirm before migrating projects to the new format
52
52
53
ExternalToolMigration_37=An exception occurred accessing external tool\'s \"run in background\" attribute
54
ExternalToolMigration_38=An exception occurred attempting to migrate external tool\'s \"run in background\" attribute
55
EditCommandDialog_0=Configure Builder
53
EditCommandDialog_0=Configure Builder
56
EditCommandDialog_1=Run this builder:
54
EditCommandDialog_1=Run this builder:
57
EditCommandDialog_2=After a "&Clean"
55
EditCommandDialog_2=After a "&Clean"
(-)External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildFilesResolver.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007 Matthew Conway and others.
2
 * Copyright (c) 2007, 2009 Matthew Conway and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 13-25 Link Here
13
import java.util.LinkedHashSet;
13
import java.util.LinkedHashSet;
14
import java.util.Set;
14
import java.util.Set;
15
15
16
import org.eclipse.core.internal.externaltools.model.ExternalToolBuilder;
16
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResourceDelta;
18
import org.eclipse.core.resources.IResourceDelta;
18
import org.eclipse.core.resources.IResourceDeltaVisitor;
19
import org.eclipse.core.resources.IResourceDeltaVisitor;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.variables.IDynamicVariable;
21
import org.eclipse.core.variables.IDynamicVariable;
21
import org.eclipse.core.variables.IDynamicVariableResolver;
22
import org.eclipse.core.variables.IDynamicVariableResolver;
22
import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder;
23
23
24
public class BuildFilesResolver implements IDynamicVariableResolver
24
public class BuildFilesResolver implements IDynamicVariableResolver
25
{
25
{
(-)External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildProjectResolver.java (-4 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.externaltools.internal.variables;
11
package org.eclipse.ui.externaltools.internal.variables;
12
12
13
import org.eclipse.core.internal.externaltools.model.ExternalToolBuilder;
14
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
13
import org.eclipse.core.resources.IProject;
15
import org.eclipse.core.resources.IProject;
14
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.CoreException;
Lines 19-26 Link Here
19
import org.eclipse.core.variables.IDynamicVariable;
21
import org.eclipse.core.variables.IDynamicVariable;
20
import org.eclipse.core.variables.IDynamicVariableResolver;
22
import org.eclipse.core.variables.IDynamicVariableResolver;
21
import org.eclipse.osgi.util.NLS;
23
import org.eclipse.osgi.util.NLS;
22
import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder;
24
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
23
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
24
25
25
26
26
public class BuildProjectResolver implements IDynamicVariableResolver {
27
public class BuildProjectResolver implements IDynamicVariableResolver {
Lines 48-54 Link Here
48
	 * @throws CoreException
49
	 * @throws CoreException
49
	 */
50
	 */
50
	protected void abort(String message, Throwable exception) throws CoreException {
51
	protected void abort(String message, Throwable exception) throws CoreException {
51
		throw new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, IExternalToolConstants.ERR_INTERNAL_ERROR, message, exception));
52
		throw new CoreException(new Status(IStatus.ERROR, ExternalToolsPlugin.PLUGIN_ID, IExternalToolConstants.ERR_INTERNAL_ERROR, message, exception));
52
	}
53
	}
53
	
54
	
54
	/**
55
	/**
(-)External Tools Base/org/eclipse/ui/externaltools/internal/variables/BuildTypeResolver.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-18 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.externaltools.internal.variables;
11
package org.eclipse.ui.externaltools.internal.variables;
12
12
13
import org.eclipse.core.internal.externaltools.model.ExternalToolBuilder;
13
import org.eclipse.core.variables.IDynamicVariable;
14
import org.eclipse.core.variables.IDynamicVariable;
14
import org.eclipse.core.variables.IDynamicVariableResolver;
15
import org.eclipse.core.variables.IDynamicVariableResolver;
15
import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder;
16
16
17
17
18
public class BuildTypeResolver implements IDynamicVariableResolver {
18
public class BuildTypeResolver implements IDynamicVariableResolver {
(-)External Tools Base/org/eclipse/ui/externaltools/internal/variables/SystemPathResolver.java (-3 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2007 IBM Corporation and others.
2
 * Copyright (c) 2005, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 15-27 Link Here
15
import java.util.Map;
15
import java.util.Map;
16
import java.util.StringTokenizer;
16
import java.util.StringTokenizer;
17
17
18
import org.eclipse.core.internal.externaltools.model.IExternalToolConstants;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.variables.IDynamicVariable;
22
import org.eclipse.core.variables.IDynamicVariable;
22
import org.eclipse.core.variables.IDynamicVariableResolver;
23
import org.eclipse.core.variables.IDynamicVariableResolver;
23
import org.eclipse.debug.core.DebugPlugin;
24
import org.eclipse.debug.core.DebugPlugin;
24
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
25
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
25
26
26
public class SystemPathResolver implements IDynamicVariableResolver {
27
public class SystemPathResolver implements IDynamicVariableResolver {
27
    
28
    
Lines 30-36 Link Here
30
	 */
31
	 */
31
	public String resolveValue(IDynamicVariable variable, String argument) throws CoreException {
32
	public String resolveValue(IDynamicVariable variable, String argument) throws CoreException {
32
        if (argument == null) {
33
        if (argument == null) {
33
            throw new CoreException(new Status(IStatus.ERROR,  IExternalToolConstants.PLUGIN_ID, IExternalToolConstants.ERR_INTERNAL_ERROR, VariableMessages.SystemPathResolver_0, null));
34
            throw new CoreException(new Status(IStatus.ERROR,  ExternalToolsPlugin.PLUGIN_ID, IExternalToolConstants.ERR_INTERNAL_ERROR, VariableMessages.SystemPathResolver_0, null));
34
        }
35
        }
35
        Map map= DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment();
36
        Map map= DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment();
36
        String path= (String) map.get("PATH"); //$NON-NLS-1$
37
        String path= (String) map.get("PATH"); //$NON-NLS-1$
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 19-24 Link Here
19
 org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
19
 org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
20
 org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)",
20
 org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)",
21
 org.eclipse.debug.ui;bundle-version="[3.2.0,4.0.0)",
21
 org.eclipse.debug.ui;bundle-version="[3.2.0,4.0.0)",
22
 org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)"
22
 org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)",
23
 org.eclipse.core.externaltools;bundle-version="1.0.0"
23
Bundle-ActivationPolicy: lazy
24
Bundle-ActivationPolicy: lazy
24
Bundle-RequiredExecutionEnvironment: J2SE-1.4
25
Bundle-RequiredExecutionEnvironment: J2SE-1.4
(-)Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/BackgroundResourceRefresher.java (-87 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.externaltools.internal.program.launchConfigurations;
12
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.jobs.Job;
19
import org.eclipse.debug.core.DebugEvent;
20
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.IDebugEventSetListener;
22
import org.eclipse.debug.core.ILaunchConfiguration;
23
import org.eclipse.debug.core.model.IProcess;
24
import org.eclipse.debug.ui.RefreshTab;
25
import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
26
27
/**
28
 * Refreshes resources as specified by a launch configuration, when 
29
 * an associated process terminates.
30
 */
31
public class BackgroundResourceRefresher implements IDebugEventSetListener  {
32
33
	private ILaunchConfiguration fConfiguration;
34
	private IProcess fProcess;
35
	
36
	public BackgroundResourceRefresher(ILaunchConfiguration configuration, IProcess process) {
37
		fConfiguration = configuration;
38
		fProcess = process;
39
	}
40
	
41
	/**
42
	 * If the process has already terminated, resource refreshing is done
43
	 * immediately in the current thread. Otherwise, refreshing is done when the
44
	 * process terminates.
45
	 */
46
	public void startBackgroundRefresh() {
47
		synchronized (fProcess) {
48
			if (fProcess.isTerminated()) {
49
				refresh();
50
			} else {
51
				DebugPlugin.getDefault().addDebugEventListener(this);
52
			}
53
		}
54
	}
55
	
56
	/* (non-Javadoc)
57
	 * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
58
	 */
59
	public void handleDebugEvents(DebugEvent[] events) {
60
		for (int i = 0; i < events.length; i++) {
61
			DebugEvent event = events[i];
62
			if (event.getSource() == fProcess && event.getKind() == DebugEvent.TERMINATE) {
63
				DebugPlugin.getDefault().removeDebugEventListener(this);
64
				refresh();
65
				break;
66
			}
67
		}
68
	}
69
	
70
	/**
71
	 * Submits a job to do the refresh
72
	 */
73
	protected void refresh() {
74
		Job job= new Job(ExternalToolsProgramMessages.BackgroundResourceRefresher_0) {
75
			public IStatus run(IProgressMonitor monitor) {
76
				try {
77
					RefreshTab.refreshResources(fConfiguration, monitor);
78
				} catch (CoreException e) {
79
					ExternalToolsPlugin.getDefault().log(e);
80
					return e.getStatus();
81
				}	
82
				return Status.OK_STATUS;
83
			}
84
		};
85
		job.schedule();
86
	}
87
}
(-)Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.java (-3 / +1 lines)
Lines 1-5 Link Here
1
/**********************************************************************
1
/**********************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation and others. All rights reserved.   This
2
 * Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved.   This
3
 * program and the accompanying materials are made available under the terms of
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
5
 * available at http://www.eclipse.org/legal/epl-v10.html
Lines 18-25 Link Here
18
18
19
	public static String ProgramLaunchDelegate_Workbench_Closing_1;
19
	public static String ProgramLaunchDelegate_Workbench_Closing_1;
20
	public static String ProgramLaunchDelegate_The_workbench_is_exiting;
20
	public static String ProgramLaunchDelegate_The_workbench_is_exiting;
21
	public static String ProgramLaunchDelegate_3;
22
	public static String ProgramLaunchDelegate_4;
23
21
24
	public static String ProgramMainTab_Select;
22
	public static String ProgramMainTab_Select;
25
23
(-)Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ExternalToolsProgramMessages.properties (-3 / +1 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2005 IBM Corporation and others.
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 13-19 Link Here
13
13
14
ProgramLaunchDelegate_Workbench_Closing_1=Workbench Closing
14
ProgramLaunchDelegate_Workbench_Closing_1=Workbench Closing
15
ProgramLaunchDelegate_The_workbench_is_exiting=The workbench is exiting and a program launched from an external tool appears to still be running. These programs will be terminated when the workbench exits. It is recommended that you exit any external programs launched from the workbench before you proceed.\n\nClick OK to continue exiting the workbench.
15
ProgramLaunchDelegate_The_workbench_is_exiting=The workbench is exiting and a program launched from an external tool appears to still be running. These programs will be terminated when the workbench exits. It is recommended that you exit any external programs launched from the workbench before you proceed.\n\nClick OK to continue exiting the workbench.
16
ProgramLaunchDelegate_3=Running {0}...
17
ProgramLaunchDelegate_4=An IProcess could not be created for the launch
18
16
19
ProgramMainTab_Select=&Select a program:
17
ProgramMainTab_Select=&Select a program:
(-)Program Tools Support/org/eclipse/ui/externaltools/internal/program/launchConfigurations/ProgramLaunchDelegate.java (-246 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Keith Seitz (keiths@redhat.com) - environment variables contribution (Bug 27243)
11
 *     dakshinamurthy.karra@gmail.com - bug 165371
12
 *******************************************************************************/
13
package org.eclipse.ui.externaltools.internal.program.launchConfigurations;
14
15
16
import java.io.File;
17
import java.util.HashMap;
18
import java.util.Map;
19
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.IPath;
23
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IStatus;
25
import org.eclipse.core.runtime.Status;
26
import org.eclipse.debug.core.DebugPlugin;
27
import org.eclipse.debug.core.ILaunch;
28
import org.eclipse.debug.core.ILaunchConfiguration;
29
import org.eclipse.debug.core.ILaunchConfigurationType;
30
import org.eclipse.debug.core.ILaunchManager;
31
import org.eclipse.debug.core.model.IProcess;
32
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
33
import org.eclipse.debug.ui.CommonTab;
34
import org.eclipse.debug.ui.RefreshTab;
35
import org.eclipse.jface.dialogs.MessageDialog;
36
import org.eclipse.osgi.util.NLS;
37
import org.eclipse.ui.IWindowListener;
38
import org.eclipse.ui.IWorkbenchWindow;
39
import org.eclipse.ui.PlatformUI;
40
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsBuildTab;
41
import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
42
import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
43
44
/**
45
 * Launch delegate for a program.
46
 */
47
public class ProgramLaunchDelegate extends LaunchConfigurationDelegate {
48
49
	private static IWindowListener fWindowListener;
50
51
	/**
52
	 * A window listener that warns the user about any running programs when
53
	 * the workbench closes. Programs are killed when the VM exits.
54
	 */
55
	private class ProgramLaunchWindowListener implements IWindowListener {
56
		public void windowActivated(IWorkbenchWindow window) {
57
		}
58
		public void windowDeactivated(IWorkbenchWindow window) {
59
		}
60
		public void windowClosed(IWorkbenchWindow window) {
61
			IWorkbenchWindow windows[]= PlatformUI.getWorkbench().getWorkbenchWindows();
62
			if (windows.length > 1) {
63
				// There are more windows still open.
64
				return;
65
			}
66
			ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
67
			ILaunchConfigurationType programType= manager.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE);
68
			if (programType == null) {
69
				return;
70
			}
71
			ILaunch launches[]= manager.getLaunches();
72
			ILaunchConfigurationType configType;
73
			ILaunchConfiguration config;
74
			for (int i = 0; i < launches.length; i++) {
75
				try {
76
					config= launches[i].getLaunchConfiguration();
77
					if (config == null) {
78
						continue;
79
					}
80
					configType= config.getType();
81
				} catch (CoreException e) {
82
					continue;
83
				}
84
				if (configType.equals(programType)) {
85
					if (!launches[i].isTerminated()) {
86
						MessageDialog.openWarning(window.getShell(), ExternalToolsProgramMessages.ProgramLaunchDelegate_Workbench_Closing_1, ExternalToolsProgramMessages.ProgramLaunchDelegate_The_workbench_is_exiting);
87
						break;
88
					}
89
				}
90
			}
91
		}
92
		public void windowOpened(IWorkbenchWindow window) {
93
		}
94
	}
95
96
	/**
97
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
98
	 */
99
	public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
100
		
101
		if (monitor.isCanceled()) {
102
			return;
103
		}
104
		
105
		// resolve location
106
		IPath location = ExternalToolsUtil.getLocation(configuration);
107
		
108
		if (monitor.isCanceled()) {
109
			return;
110
		}		
111
		
112
		// resolve working directory
113
		IPath workingDirectory = ExternalToolsUtil.getWorkingDirectory(configuration);
114
		
115
		if (monitor.isCanceled()) {
116
			return;
117
		}
118
		
119
		// resolve arguments
120
		String[] arguments = ExternalToolsUtil.getArguments(configuration);
121
		
122
		if (monitor.isCanceled()) {
123
			return;
124
		}
125
		
126
		int cmdLineLength = 1;
127
		if (arguments != null) {
128
			cmdLineLength += arguments.length;
129
		}
130
		String[] cmdLine = new String[cmdLineLength];
131
		cmdLine[0] = location.toOSString();
132
		if (arguments != null) {
133
			System.arraycopy(arguments, 0, cmdLine, 1, arguments.length);
134
		}
135
		
136
		File workingDir = null;
137
		if (workingDirectory != null) {
138
			workingDir = workingDirectory.toFile();
139
		}
140
		
141
		if (monitor.isCanceled()) {
142
			return;
143
		}
144
		
145
		String[] envp = DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration);
146
		
147
		if (monitor.isCanceled()) {
148
			return;
149
		}
150
		
151
		if (fWindowListener == null) {
152
			fWindowListener= new ProgramLaunchWindowListener();
153
			PlatformUI.getWorkbench().addWindowListener(fWindowListener);
154
		}
155
		Process p = DebugPlugin.exec(cmdLine, workingDir, envp);
156
		IProcess process = null;
157
		
158
		// add process type to process attributes
159
		Map processAttributes = new HashMap();
160
		String programName = location.lastSegment();
161
		String extension = location.getFileExtension();
162
		if (extension != null) {
163
			programName = programName.substring(0, programName.length() - (extension.length() + 1));
164
		}
165
		programName = programName.toLowerCase();
166
		processAttributes.put(IProcess.ATTR_PROCESS_TYPE, programName);
167
		
168
		if (p != null) {
169
			monitor.beginTask(NLS.bind(ExternalToolsProgramMessages.ProgramLaunchDelegate_3, new String[] {configuration.getName()}), IProgressMonitor.UNKNOWN);
170
			process = DebugPlugin.newProcess(launch, p, location.toOSString(), processAttributes);
171
		}
172
		if (p == null || process == null) {
173
			if (p != null)
174
				p.destroy();
175
			throw new CoreException(new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, IExternalToolConstants.ERR_INTERNAL_ERROR, ExternalToolsProgramMessages.ProgramLaunchDelegate_4, null));
176
		}
177
		process.setAttribute(IProcess.ATTR_CMDLINE, generateCommandLine(cmdLine));
178
		
179
		if (CommonTab.isLaunchInBackground(configuration)) {
180
			// refresh resources after process finishes
181
			if (RefreshTab.getRefreshScope(configuration) != null) {
182
				BackgroundResourceRefresher refresher = new BackgroundResourceRefresher(configuration, process);
183
				refresher.startBackgroundRefresh();
184
			}				
185
		} else {
186
			// wait for process to exit
187
			while (!process.isTerminated()) {
188
				try {
189
					if (monitor.isCanceled()) {
190
						process.terminate();
191
						break;
192
					}
193
					Thread.sleep(50);
194
				} catch (InterruptedException e) {
195
				}
196
			}
197
			
198
			// refresh resources
199
			RefreshTab.refreshResources(configuration, monitor);
200
		}
201
	}
202
	
203
	private String generateCommandLine(String[] commandLine) {
204
		if (commandLine.length < 1)
205
			return ""; //$NON-NLS-1$
206
		StringBuffer buf= new StringBuffer();
207
		for (int i= 0; i < commandLine.length; i++) {
208
			buf.append(' ');
209
			char[] characters= commandLine[i].toCharArray();
210
			StringBuffer command= new StringBuffer();
211
			boolean containsSpace= false;
212
			for (int j = 0; j < characters.length; j++) {
213
				char character= characters[j];
214
				if (character == '\"') {
215
					command.append('\\');
216
				} else if (character == ' ') {
217
					containsSpace = true;
218
				}
219
				command.append(character);
220
			}
221
			if (containsSpace) {
222
				buf.append('\"');
223
				buf.append(command);
224
				buf.append('\"');
225
			} else {
226
				buf.append(command);
227
			}
228
		}	
229
		return buf.toString();
230
	}	
231
	
232
    /* (non-Javadoc)
233
	 * @see org.eclipse.debug.core.model.LaunchConfigurationDelegate#getBuildOrder(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String)
234
	 */
235
	protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
236
		IProject[] projects = ExternalToolsBuildTab.getBuildProjects(configuration, null);
237
		if (projects == null) {
238
			return null ;
239
		}
240
		boolean isRef = ExternalToolsBuildTab.isIncludeReferencedProjects(configuration, null);
241
		if (isRef) {
242
			return computeReferencedBuildOrder(projects);
243
		}
244
		return computeBuildOrder(projects);
245
	}
246
}
(-)plugin.xml (-28 lines)
Lines 99-134 Link Here
99
		</enabledWhen>
99
		</enabledWhen>
100
      </page>
100
      </page>
101
   </extension>
101
   </extension>
102
   <extension
103
         id="ExternalToolBuilder"
104
         name="%Builder.externalTools"
105
         point="org.eclipse.core.resources.builders">
106
      <builder
107
      	isConfigurable= "true">
108
         <run
109
               class="org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder">
110
         </run>
111
      </builder>
112
   </extension>
113
<!-- Launch Configuration Extensions -->
102
<!-- Launch Configuration Extensions -->
114
   <extension
103
   <extension
115
         point="org.eclipse.debug.core.launchConfigurationTypes">
116
      <launchConfigurationType
117
            name="%Program.externalTools"
118
            delegate="org.eclipse.ui.externaltools.internal.program.launchConfigurations.ProgramLaunchDelegate"
119
            category="org.eclipse.ui.externaltools"
120
            modes="run"
121
            id="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
122
      </launchConfigurationType>
123
      <launchConfigurationType
124
            name="%Program.externalTools"
125
            delegate="org.eclipse.ui.externaltools.internal.program.launchConfigurations.ProgramLaunchDelegate"
126
            category="org.eclipse.ui.externaltools.builder"
127
            modes="run"
128
            id="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
129
      </launchConfigurationType>
130
   </extension>
131
   <extension
132
         point="org.eclipse.ui.externaltools.configurationDuplicationMaps">
104
         point="org.eclipse.ui.externaltools.configurationDuplicationMaps">
133
      <configurationMap
105
      <configurationMap
134
            sourceType="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"
106
            sourceType="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType"

Return to bug 264338