1
1
/*******************************************************************************
2
- * Copyright (c) 2000, 2013 IBM Corporation and others.
2
+ * Copyright (c) 2000, 2025 IBM Corporation and others.
3
3
*
4
4
* This program and the accompanying materials
5
5
* are made available under the terms of the Eclipse Public License 2.0
10
10
*
11
11
* Contributors:
12
12
* IBM Corporation - initial API and implementation
13
+ * Alexander Fedorov (ArSysOp) - https://github.com/eclipse-platform/eclipse.platform/issues/1668
13
14
*******************************************************************************/
14
15
package org .eclipse .ant .internal .ui .launchConfigurations ;
15
16
17
+ import java .util .Optional ;
18
+
16
19
import org .eclipse .ant .internal .core .IAntCoreConstants ;
17
20
import org .eclipse .ant .internal .ui .AntUIPlugin ;
18
21
import org .eclipse .ant .internal .ui .AntUtil ;
19
22
import org .eclipse .ant .internal .ui .IAntUIConstants ;
20
23
import org .eclipse .ant .internal .ui .IAntUIHelpContextIds ;
21
24
import org .eclipse .ant .launching .IAntLaunchConstants ;
22
- import org .eclipse .core .externaltools .internal .IExternalToolConstants ;
23
25
import org .eclipse .core .resources .IFile ;
24
26
import org .eclipse .core .resources .IResource ;
25
27
import org .eclipse .core .resources .ResourcesPlugin ;
26
28
import org .eclipse .core .runtime .CoreException ;
27
- import org .eclipse .core .variables .IStringVariableManager ;
28
29
import org .eclipse .core .variables .VariablesPlugin ;
29
30
import org .eclipse .debug .core .ILaunchConfiguration ;
30
31
import org .eclipse .debug .core .ILaunchConfigurationWorkingCopy ;
32
+ import org .eclipse .debug .core .LaunchAttributeProbe ;
31
33
import org .eclipse .debug .ui .ILaunchConfigurationTab ;
32
34
import org .eclipse .jdt .launching .IJavaLaunchConfigurationConstants ;
33
35
import org .eclipse .jface .dialogs .Dialog ;
45
47
46
48
public class AntMainTab extends ExternalToolsMainTab {
47
49
48
- private String fCurrentLocation = null ;
50
+ private Optional < String > fCurrentLocation ;
49
51
private Button fSetInputHandlerButton ;
50
52
private IFile fNewFile ;
51
53
52
54
@ Override
53
55
public void initializeFrom (ILaunchConfiguration configuration ) {
54
56
super .initializeFrom (configuration );
55
- try {
56
- fCurrentLocation = configuration .getAttribute (IExternalToolConstants .ATTR_LOCATION , (String ) null );
57
- }
58
- catch (CoreException e ) {
59
- // do nothing
60
- }
57
+ fCurrentLocation = new LaunchAttributeProbe <>(configuration , locationAttribute ).get ();
61
58
updateCheckButtons (configuration );
62
59
}
63
60
64
61
@ Override
65
62
public void performApply (ILaunchConfigurationWorkingCopy configuration ) {
66
63
super .performApply (configuration );
67
- try {
68
- // has the location changed
69
- String newLocation = configuration .getAttribute (IExternalToolConstants .ATTR_LOCATION , (String ) null );
70
- if (newLocation != null ) {
71
- if (!newLocation .equals (fCurrentLocation )) {
72
- updateTargetsTab ();
73
- fCurrentLocation = newLocation ;
74
- updateProjectName (configuration );
75
- }
76
- } else if (fCurrentLocation != null ) {
77
- updateTargetsTab ();
78
- fCurrentLocation = newLocation ;
79
- updateProjectName (configuration );
80
- }
81
- }
82
- catch (CoreException e ) {
83
- // do nothing
64
+ // has the location changed
65
+ Optional <String > newLocation = new LaunchAttributeProbe <>(configuration , locationAttribute ).get ();
66
+ if (!newLocation .equals (fCurrentLocation )) {
67
+ updateTargetsTab ();
68
+ fCurrentLocation = newLocation ;
69
+ updateProjectName (configuration );
84
70
}
85
-
86
71
setMappedResources (configuration );
87
72
setAttribute (IAntUIConstants .SET_INPUTHANDLER , configuration , fSetInputHandlerButton .getSelection (), true );
88
73
}
@@ -110,26 +95,21 @@ private void updateProjectName(ILaunchConfigurationWorkingCopy configuration) {
110
95
}
111
96
112
97
private IFile getIFile (ILaunchConfigurationWorkingCopy configuration ) {
113
- IFile file = null ;
114
98
if (fNewFile != null ) {
115
- file = fNewFile ;
99
+ IFile file = fNewFile ;
116
100
fNewFile = null ;
117
- } else {
118
- IStringVariableManager manager = VariablesPlugin .getDefault ().getStringVariableManager ();
119
- try {
120
- String location = configuration .getAttribute (IExternalToolConstants .ATTR_LOCATION , (String ) null );
121
- if (location != null ) {
122
- String expandedLocation = manager .performStringSubstitution (location );
123
- if (expandedLocation != null ) {
124
- file = AntUtil .getFileForLocation (expandedLocation , null );
125
- }
126
- }
127
- }
128
- catch (CoreException e ) {
129
- // do nothing
130
- }
101
+ return file ;
102
+ }
103
+ return new LaunchAttributeProbe <>(configuration , locationAttribute ).get ().flatMap (this ::resolve ).map (exp -> AntUtil .getFileForLocation (exp , null )).orElse (null );
104
+ }
105
+
106
+ private Optional <String > resolve (String location ) {
107
+ try {
108
+ return Optional .of (VariablesPlugin .getDefault ().getStringVariableManager ().performStringSubstitution (location ));
109
+ }
110
+ catch (CoreException e ) {
111
+ return Optional .empty ();
131
112
}
132
- return file ;
133
113
}
134
114
135
115
@ Override
@@ -153,7 +133,7 @@ public void createControl(Composite parent) {
153
133
154
134
/**
155
135
* Creates the controls needed to edit the set input handler attribute of an Ant build
156
- *
136
+ *
157
137
* @param parent
158
138
* the composite to create the controls in
159
139
*/
0 commit comments