Skip to content

Commit 893238c

Browse files
committed
[#1668] simplify work with launch attributes
* identify launch attribute * connect it with preference metadata (to supply defaults/label/description) * read attribute from configuration * write attribute to configuration working copy * demonstrate usage for ExternalTools
1 parent 0520433 commit 893238c

File tree

15 files changed

+366
-191
lines changed

15 files changed

+366
-191
lines changed

ant/org.eclipse.ant.launching/src/org/eclipse/ant/internal/launching/debug/model/AntDebugTarget.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2004, 2016 IBM Corporation and others.
2+
* Copyright (c) 2004, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* Alexander Fedorov (ArSysOp) - API to process launch configuration attributes
1314
*******************************************************************************/
1415
package org.eclipse.ant.internal.launching.debug.model;
1516

@@ -22,7 +23,6 @@
2223
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
2324
import org.eclipse.core.resources.IMarkerDelta;
2425
import org.eclipse.core.runtime.CoreException;
25-
import org.eclipse.core.variables.VariablesPlugin;
2626
import org.eclipse.debug.core.DebugEvent;
2727
import org.eclipse.debug.core.DebugException;
2828
import org.eclipse.debug.core.DebugPlugin;
@@ -108,13 +108,7 @@ public boolean hasThreads() throws DebugException {
108108
@Override
109109
public String getName() throws DebugException {
110110
if (fName == null) {
111-
try {
112-
fName = getLaunch().getLaunchConfiguration().getAttribute(IExternalToolConstants.ATTR_LOCATION, DebugModelMessages.AntDebugTarget_0);
113-
fName = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(fName);
114-
}
115-
catch (CoreException e) {
116-
fName = DebugModelMessages.AntDebugTarget_0;
117-
}
111+
fName = IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.probe(getLaunch().getLaunchConfiguration()).orElse(DebugModelMessages.AntDebugTarget_0);
118112
}
119113
return fName;
120114
}

ant/org.eclipse.ant.launching/src/org/eclipse/ant/internal/launching/launchConfigurations/AntMigrationDelegate.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2006, 2013 IBM Corporation and others.
2+
* Copyright (c) 2006, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* Alexander Fedorov (ArSysOp) - API to process launch configuration attributes
1314
*******************************************************************************/
1415
package org.eclipse.ant.internal.launching.launchConfigurations;
1516

@@ -18,8 +19,6 @@
1819
import org.eclipse.core.resources.IFile;
1920
import org.eclipse.core.resources.IResource;
2021
import org.eclipse.core.runtime.CoreException;
21-
import org.eclipse.core.variables.IStringVariableManager;
22-
import org.eclipse.core.variables.VariablesPlugin;
2322
import org.eclipse.debug.core.ILaunchConfiguration;
2423
import org.eclipse.debug.core.ILaunchConfigurationMigrationDelegate;
2524
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
@@ -40,23 +39,7 @@ public class AntMigrationDelegate implements ILaunchConfigurationMigrationDelega
4039
* @return the buildfile or <code>null</code> if not in the workspace
4140
*/
4241
protected IFile getFileForCandidate(ILaunchConfiguration candidate) {
43-
IFile file = null;
44-
String expandedLocation = null;
45-
String location = null;
46-
IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
47-
try {
48-
location = candidate.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String) null);
49-
if (location != null) {
50-
expandedLocation = manager.performStringSubstitution(location);
51-
if (expandedLocation != null) {
52-
file = AntLaunchingUtil.getFileForLocation(expandedLocation, null);
53-
}
54-
}
55-
}
56-
catch (CoreException e) {
57-
// do nothing
58-
}
59-
return file;
42+
return IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.probe(candidate).map(l -> AntLaunchingUtil.getFileForLocation(l, null)).orElse(null);
6043
}
6144

6245
@Override

ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/AntUtil.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* Alexander Fedorov (ArSysOp) - API to process launch configuration attributes
1314
*******************************************************************************/
1415
package org.eclipse.ant.internal.ui;
1516

@@ -20,7 +21,6 @@
2021
import java.util.ArrayList;
2122
import java.util.HashMap;
2223
import java.util.Hashtable;
23-
import java.util.Iterator;
2424
import java.util.List;
2525
import java.util.Map;
2626
import java.util.regex.Pattern;
@@ -195,7 +195,7 @@ public static AntTargetNode[] getTargets(String path, ILaunchConfiguration confi
195195
}
196196

197197
private static Map<String, String> getAllProperties(ILaunchConfiguration config) throws CoreException {
198-
String allArgs = config.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, (String) null);
198+
String allArgs = IExternalToolConstants.LAUNCH_ATTRIBUTE_ARGUMENTS.read(config);
199199
Map<String, String> properties = new HashMap<>();
200200
if (allArgs != null) {
201201
// filter arguments to avoid resolving variables that will prompt the user
@@ -213,9 +213,7 @@ private static Map<String, String> getAllProperties(ILaunchConfiguration config)
213213
}
214214
Map<String, String> configProperties = getProperties(config);
215215
if (configProperties != null) {
216-
Iterator<String> keys = configProperties.keySet().iterator();
217-
while (keys.hasNext()) {
218-
String name = keys.next();
216+
for (String name : configProperties.keySet()) {
219217
if (properties.get(name) == null) {
220218
properties.put(name, configProperties.get(name));
221219
}

ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/launchConfigurations/AntMainTab.java

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2013 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,9 +10,12 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* Alexander Fedorov (ArSysOp) - API to process launch configuration attributes
1314
*******************************************************************************/
1415
package org.eclipse.ant.internal.ui.launchConfigurations;
1516

17+
import java.util.Optional;
18+
1619
import org.eclipse.ant.internal.core.IAntCoreConstants;
1720
import org.eclipse.ant.internal.ui.AntUIPlugin;
1821
import org.eclipse.ant.internal.ui.AntUtil;
@@ -24,7 +27,6 @@
2427
import org.eclipse.core.resources.IResource;
2528
import org.eclipse.core.resources.ResourcesPlugin;
2629
import org.eclipse.core.runtime.CoreException;
27-
import org.eclipse.core.variables.IStringVariableManager;
2830
import org.eclipse.core.variables.VariablesPlugin;
2931
import org.eclipse.debug.core.ILaunchConfiguration;
3032
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
@@ -45,44 +47,27 @@
4547

4648
public class AntMainTab extends ExternalToolsMainTab {
4749

48-
private String fCurrentLocation = null;
50+
private Optional<String> fCurrentLocation;
4951
private Button fSetInputHandlerButton;
5052
private IFile fNewFile;
5153

5254
@Override
5355
public void initializeFrom(ILaunchConfiguration configuration) {
5456
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 = IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.probe(configuration);
6158
updateCheckButtons(configuration);
6259
}
6360

6461
@Override
6562
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
6663
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 = IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.probe(configuration);
66+
if (!newLocation.equals(fCurrentLocation)) {
67+
updateTargetsTab();
68+
fCurrentLocation = newLocation;
69+
updateProjectName(configuration);
8470
}
85-
8671
setMappedResources(configuration);
8772
setAttribute(IAntUIConstants.SET_INPUTHANDLER, configuration, fSetInputHandlerButton.getSelection(), true);
8873
}
@@ -110,26 +95,12 @@ private void updateProjectName(ILaunchConfigurationWorkingCopy configuration) {
11095
}
11196

11297
private IFile getIFile(ILaunchConfigurationWorkingCopy configuration) {
113-
IFile file = null;
11498
if (fNewFile != null) {
115-
file = fNewFile;
99+
IFile file = fNewFile;
116100
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;
131102
}
132-
return file;
103+
return IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.probe(configuration).map(exp -> AntUtil.getFileForLocation(exp, null)).orElse(null);
133104
}
134105

135106
@Override

0 commit comments

Comments
 (0)