Skip to content

Commit 4571d59

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 e8c3e2d commit 4571d59

File tree

15 files changed

+442
-212
lines changed

15 files changed

+442
-212
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: 26 additions & 28 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;
@@ -100,7 +100,7 @@ private AntUtil() {
100100

101101
/**
102102
* Returns a single-string of the strings for storage.
103-
*
103+
*
104104
* @param strings
105105
* the array of strings
106106
* @return a single-string representation of the strings or <code>null</code> if the array is empty.
@@ -112,7 +112,7 @@ public static String combineStrings(String[] strings) {
112112
/**
113113
* Returns an array of targets to be run, or <code>null</code> if none are specified (indicating the default target or implicit target should be
114114
* run).
115-
*
115+
*
116116
* @param configuration
117117
* launch configuration
118118
* @return array of target names, or <code>null</code>
@@ -126,7 +126,7 @@ public static String[] getTargetNames(ILaunchConfiguration configuration) throws
126126
/**
127127
* Returns a map of properties to be defined for the build, or <code>null</code> if none are specified (indicating no additional properties
128128
* specified for the build).
129-
*
129+
*
130130
* @param configuration
131131
* launch configuration
132132
* @return map of properties (name --&gt; value), or <code>null</code>
@@ -139,7 +139,7 @@ public static Map<String, String> getProperties(ILaunchConfiguration configurati
139139

140140
/**
141141
* Returns a String specifying the Ant home to use for the build.
142-
*
142+
*
143143
* @param configuration
144144
* launch configuration
145145
* @return String specifying Ant home to use or <code>null</code>
@@ -153,7 +153,7 @@ public static String getAntHome(ILaunchConfiguration configuration) throws CoreE
153153
/**
154154
* Returns an array of property files to be used for the build, or <code>null</code> if none are specified (indicating no additional property
155155
* files specified for the build).
156-
*
156+
*
157157
* @param configuration
158158
* launch configuration
159159
* @return array of property file names, or <code>null</code>
@@ -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
}
@@ -349,11 +347,11 @@ private static IDocument getDocument(File buildFile) {
349347

350348
/**
351349
* Returns the list of URLs that define the custom classpath for the Ant build, or <code>null</code> if the global classpath is to be used.
352-
*
350+
*
353351
* @param config
354352
* launch configuration
355353
* @return a list of <code>URL</code>
356-
*
354+
*
357355
* @throws CoreException
358356
* if file does not exist, IO problems, or invalid format.
359357
*/
@@ -373,7 +371,7 @@ private static String expandVariableString(String variableString, String invalid
373371

374372
/**
375373
* Returns the list of target names to run
376-
*
374+
*
377375
* @param extraAttibuteValue
378376
* the external tool's extra attribute value for the run targets key.
379377
* @return a list of target names
@@ -384,7 +382,7 @@ public static String[] parseRunTargets(String extraAttibuteValue) {
384382

385383
/**
386384
* Returns the list of Strings that were delimiter separated.
387-
*
385+
*
388386
* @param delimString
389387
* the String to be tokenized based on the delimiter
390388
* @param delim
@@ -397,7 +395,7 @@ public static String[] parseString(String delimString, String delim) {
397395

398396
/**
399397
* Returns an IFile with the given fully qualified path (relative to the workspace root). The returned IFile may or may not exist.
400-
*
398+
*
401399
* @param fullPath
402400
* the path to look up
403401
* @return the {@link IFile} which may or may not exist
@@ -446,9 +444,9 @@ public static IHyperlink getLocationLink(String path, File buildFileParent) {
446444
/**
447445
* Returns the workspace file associated with the given path in the local file system, or <code>null</code> if none. If the path happens to be a
448446
* relative path, then the path is interpreted as relative to the specified parent file.
449-
*
447+
*
450448
* Attempts to handle linked files; the first found linked file with the correct path is returned.
451-
*
449+
*
452450
* @return file or <code>null</code>
453451
* @see org.eclipse.core.resources.IWorkspaceRoot#findFilesForLocation(IPath)
454452
*/
@@ -459,7 +457,7 @@ public static IFile getFileForLocation(String path, File buildFileParent) {
459457
/**
460458
* Migrates the classpath in the given configuration from the old format to the new format. The old format is not preserved. Instead, the default
461459
* classpath will be used. However, ANT_HOME settings are preserved.
462-
*
460+
*
463461
* @param configuration
464462
* a configuration to migrate
465463
* @throws CoreException
@@ -500,7 +498,7 @@ private static int getOffset(int line, int column, ITextEditor editor) {
500498

501499
/**
502500
* Opens the given editor on the buildfile of the provided node and selects that node in the editor.
503-
*
501+
*
504502
* @param page
505503
* the page to open the editor in
506504
* @param editorDescriptor
@@ -540,7 +538,7 @@ public static void openInEditor(IWorkbenchPage page, IEditorDescriptor editorDes
540538

541539
/**
542540
* Opens an editor on the buildfile of the provided node and selects that node in the editor.
543-
*
541+
*
544542
* @param page
545543
* the page to open the editor in
546544
* @param node
@@ -639,9 +637,9 @@ public static boolean isKnownAntFile(IResource resource) {
639637

640638
/**
641639
* Returns if the given extension is a known extension to Ant i.e. a supported content type extension.
642-
*
640+
*
643641
* @return true if the file extension is supported false otherwise
644-
*
642+
*
645643
* @since 3.8
646644
*/
647645
public static boolean isKnownAntFile(File file) {
@@ -666,7 +664,7 @@ public static boolean isKnownAntFile(File file) {
666664

667665
/**
668666
* Returns an array of build file names from the ant preference store
669-
*
667+
*
670668
* @return an array of build file names
671669
* @since 3.6
672670
*/
@@ -682,7 +680,7 @@ public static String[] getKnownBuildfileNames() {
682680

683681
/**
684682
* Returns if the given file is a known build file name, based on the given names from the Ant &gt; Names preference
685-
*
683+
*
686684
* @return true if the name of the file is given in the Ant &gt; Names preference, false otherwise
687685
* @since 3.6
688686
*/
@@ -698,7 +696,7 @@ public static boolean isKnownBuildfileName(String filename) {
698696

699697
/**
700698
* A helper method to extract the build filename extensions as defined in the extender of the content-types extension-point.
701-
*
699+
*
702700
* @return An empty array or list of filename extensions as specified in the content-types extension
703701
* @since 3.8
704702
*/
@@ -719,7 +717,7 @@ public static String[] getKnownBuildFileExtensions() {
719717

720718
/**
721719
* A helper method to construct a RegEx pattern out of the extensions
722-
*
720+
*
723721
* @return A String that is a RegEx pattern representing the extensions
724722
* @since 3.8
725723
*/
@@ -734,7 +732,7 @@ public static String getKnownBuildFileExtensionsAsPattern() {
734732
/**
735733
* Returns if the given file name is known as a build file. This method consults all of the known file extensions from the Ant-defined content
736734
* types
737-
*
735+
*
738736
* @return <code>true</code> if the file name matches an Ant build file pattern <code>false</code> otherwise
739737
* @since 3.8
740738
*/

0 commit comments

Comments
 (0)