Skip to content

Commit 0eaee71

Browse files
committed
[#1668] API types to simplify work with launch configuration 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 29bc65f commit 0eaee71

File tree

18 files changed

+514
-102
lines changed

18 files changed

+514
-102
lines changed

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

+26-46
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,24 +10,26 @@
1010
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
13+
* Alexander Fedorov (ArSysOp) - https://github.com/eclipse-platform/eclipse.platform/issues/1668
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;
1922
import org.eclipse.ant.internal.ui.IAntUIConstants;
2023
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
2124
import org.eclipse.ant.launching.IAntLaunchConstants;
22-
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
2325
import org.eclipse.core.resources.IFile;
2426
import org.eclipse.core.resources.IResource;
2527
import org.eclipse.core.resources.ResourcesPlugin;
2628
import org.eclipse.core.runtime.CoreException;
27-
import org.eclipse.core.variables.IStringVariableManager;
2829
import org.eclipse.core.variables.VariablesPlugin;
2930
import org.eclipse.debug.core.ILaunchConfiguration;
3031
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
32+
import org.eclipse.debug.core.LaunchAttributeProbe;
3133
import org.eclipse.debug.ui.ILaunchConfigurationTab;
3234
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
3335
import org.eclipse.jface.dialogs.Dialog;
@@ -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 = new LaunchAttributeProbe<>(configuration, locationAttribute).get();
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 = new LaunchAttributeProbe<>(configuration, locationAttribute).get();
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,21 @@ 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;
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();
131112
}
132-
return file;
133113
}
134114

135115
@Override
@@ -153,7 +133,7 @@ public void createControl(Composite parent) {
153133

154134
/**
155135
* Creates the controls needed to edit the set input handler attribute of an Ant build
156-
*
136+
*
157137
* @param parent
158138
* the composite to create the controls in
159139
*/

debug/org.eclipse.core.externaltools/META-INF/MANIFEST.MF

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-Localization: plugin
55
Bundle-SymbolicName: org.eclipse.core.externaltools;singleton:=true
6-
Bundle-Version: 1.3.400.qualifier
6+
Bundle-Version: 1.3.500.qualifier
77
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
88
org.eclipse.debug.core;bundle-version="[3.9.0,4.0.0)",
99
org.eclipse.core.variables;bundle-version="[3.2.800,4.0.0)"

debug/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/IExternalToolConstants.java

+15-1
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
@@ -11,9 +11,14 @@
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
* [email protected] - bug 165371
14+
* Alexander Fedorov (ArSysOp) - https://github.com/eclipse-platform/eclipse.platform/issues/1668
1415
*******************************************************************************/
1516

1617
package org.eclipse.core.externaltools.internal;
18+
19+
import org.eclipse.debug.core.LauchAttributeIdentityRecord;
20+
import org.eclipse.debug.core.LaunchAttributeIdentity;
21+
1722
/**
1823
* Defines the constants available for client use.
1924
* <p>
@@ -221,4 +226,13 @@ public interface IExternalToolConstants {
221226
* <code>true</code>.
222227
*/
223228
String ATTR_INCLUDE_REFERENCED_PROJECTS = UI_PLUGIN_ID + ".ATTR_INCLUDE_REFERENCED_PROJECTS"; //$NON-NLS-1$
229+
230+
interface LaunchAttributes {
231+
232+
LaunchAttributeIdentity location = new LauchAttributeIdentityRecord(ATTR_LOCATION);
233+
LaunchAttributeIdentity workingDirectory = new LauchAttributeIdentityRecord(ATTR_WORKING_DIRECTORY);
234+
LaunchAttributeIdentity arguments = new LauchAttributeIdentityRecord(ATTR_TOOL_ARGUMENTS);
235+
236+
}
237+
224238
}

debug/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/launchConfigurations/ExternalToolsProgramMessages.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2009 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) - https://github.com/eclipse-platform/eclipse.platform/issues/1668
1314
*******************************************************************************/
1415
package org.eclipse.core.externaltools.internal.launchConfigurations;
1516

@@ -29,6 +30,15 @@ public class ExternalToolsProgramMessages extends NLS {
2930
public static String ExternalToolsUtil_invalidLocation__0_;
3031
public static String ExternalToolsUtil_invalidDirectory__0_;
3132

33+
34+
public static String LaunchAttributeArguments_name;
35+
36+
37+
public static String LaunchAttributeLocation_name;
38+
39+
40+
public static String LaunchAttributeWorkingDirectory_name;
41+
3242
static {
3343
// load message values from bundle file
3444
NLS.initializeMessages(BUNDLE_NAME, ExternalToolsProgramMessages.class);

debug/org.eclipse.core.externaltools/src/org/eclipse/core/externaltools/internal/launchConfigurations/ExternalToolsProgramMessages.properties

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
###############################################################################
2-
# Copyright (c) 2000, 2009 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) - https://github.com/eclipse-platform/eclipse.platform/issues/1668
1314
###############################################################################
1415

1516
BackgroundResourceRefresher_0=Refreshing resources...
@@ -20,4 +21,7 @@ ProgramLaunchDelegate_5=[pid: {0}]
2021

2122
ExternalToolsUtil_Location_not_specified_by__0__1=Location not specified by {0}
2223
ExternalToolsUtil_invalidLocation__0_ = The file does not exist for the external tool named {0}.
23-
ExternalToolsUtil_invalidDirectory__0_ = The working directory {0} does not exist for the external tool named {1}.
24+
ExternalToolsUtil_invalidDirectory__0_ = The working directory {0} does not exist for the external tool named {1}.
25+
LaunchAttributeArguments_name=Arguments
26+
LaunchAttributeLocation_name=Location
27+
LaunchAttributeWorkingDirectory_name=Working Directory
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 ArSysOp.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Alexander Fedorov (ArSysOp) - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.core.externaltools.internal.launchConfigurations;
15+
16+
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
17+
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
18+
import org.eclipse.debug.core.LaunchAttributeDefined;
19+
import org.eclipse.debug.core.LaunchAttributeIdentity;
20+
21+
public final class LaunchAttributeArguments implements LaunchAttributeDefined<String> {
22+
23+
@Override
24+
public LaunchAttributeIdentity identity() {
25+
return IExternalToolConstants.LaunchAttributes.arguments;
26+
}
27+
28+
@Override
29+
public PreferenceMetadata<String> metadata() {
30+
return new PreferenceMetadata<>(String.class, //
31+
identity().id(),
32+
null, // unspecified by default
33+
ExternalToolsProgramMessages.LaunchAttributeArguments_name);
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 ArSysOp.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Alexander Fedorov (ArSysOp) - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.core.externaltools.internal.launchConfigurations;
15+
16+
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
17+
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
18+
import org.eclipse.debug.core.LaunchAttributeDefined;
19+
import org.eclipse.debug.core.LaunchAttributeIdentity;
20+
21+
public final class LaunchAttributeLocation implements LaunchAttributeDefined<String> {
22+
23+
@Override
24+
public LaunchAttributeIdentity identity() {
25+
return IExternalToolConstants.LaunchAttributes.location;
26+
}
27+
28+
@Override
29+
public PreferenceMetadata<String> metadata() {
30+
return new PreferenceMetadata<>(String.class, //
31+
identity().id(),
32+
null, // unspecified by default
33+
ExternalToolsProgramMessages.LaunchAttributeLocation_name);
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 ArSysOp.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Alexander Fedorov (ArSysOp) - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.core.externaltools.internal.launchConfigurations;
15+
16+
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
17+
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
18+
import org.eclipse.debug.core.LaunchAttributeDefined;
19+
import org.eclipse.debug.core.LaunchAttributeIdentity;
20+
21+
public final class LaunchAttributeWorkingDirectory implements LaunchAttributeDefined<String> {
22+
23+
@Override
24+
public LaunchAttributeIdentity identity() {
25+
return IExternalToolConstants.LaunchAttributes.workingDirectory;
26+
}
27+
28+
@Override
29+
public PreferenceMetadata<String> metadata() {
30+
return new PreferenceMetadata<>(String.class, //
31+
identity().id(),
32+
null, // unspecified by default
33+
ExternalToolsProgramMessages.LaunchAttributeWorkingDirectory_name);
34+
}
35+
36+
}

debug/org.eclipse.debug.core/META-INF/MANIFEST.MF

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.debug.core; singleton:=true
5-
Bundle-Version: 3.22.100.qualifier
5+
Bundle-Version: 3.23.0.qualifier
66
Bundle-Activator: org.eclipse.debug.core.DebugPlugin
77
Bundle-Vendor: %providerName
88
Bundle-Localization: plugin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024, 2025 ArSysOp.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Alexander Fedorov (ArSysOp) - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.debug.core;
15+
16+
/**
17+
* Default implementation for {@link LaunchAttributeIdentity}
18+
*
19+
* @since 3.23
20+
*/
21+
public record LauchAttributeIdentityRecord(String id) implements LaunchAttributeIdentity {
22+
23+
/**
24+
* Convenience way to compose full qualified name for launch attribute
25+
*
26+
* @param qualifier usually corresponds to Bundle-Symbolic-Name
27+
* @param key short key to name this very attribute in the scope of
28+
* qualifier
29+
*/
30+
public LauchAttributeIdentityRecord(String qualifier, String key) {
31+
this(qualifier + "." + key); //$NON-NLS-1$
32+
}
33+
34+
}

0 commit comments

Comments
 (0)