Skip to content

Commit

Permalink
[#1668] simplify work with launch attributes
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ruspl-afed committed Feb 11, 2025
1 parent dc18b24 commit 195c995
Show file tree
Hide file tree
Showing 11 changed files with 416 additions and 144 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2013 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -10,9 +10,12 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Alexander Fedorov (ArSysOp) - https://github.com/eclipse-platform/eclipse.platform/issues/1668
*******************************************************************************/
package org.eclipse.ant.internal.ui.launchConfigurations;

import java.util.Optional;

import org.eclipse.ant.internal.core.IAntCoreConstants;
import org.eclipse.ant.internal.ui.AntUIPlugin;
import org.eclipse.ant.internal.ui.AntUtil;
Expand All @@ -24,7 +27,6 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.variables.IStringVariableManager;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
Expand All @@ -45,44 +47,27 @@

public class AntMainTab extends ExternalToolsMainTab {

private String fCurrentLocation = null;
private Optional<String> fCurrentLocation;
private Button fSetInputHandlerButton;
private IFile fNewFile;

@Override
public void initializeFrom(ILaunchConfiguration configuration) {
super.initializeFrom(configuration);
try {
fCurrentLocation = configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String) null);
}
catch (CoreException e) {
// do nothing
}
fCurrentLocation = IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.read(configuration);
updateCheckButtons(configuration);
}

@Override
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
super.performApply(configuration);
try {
// has the location changed
String newLocation = configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String) null);
if (newLocation != null) {
if (!newLocation.equals(fCurrentLocation)) {
updateTargetsTab();
fCurrentLocation = newLocation;
updateProjectName(configuration);
}
} else if (fCurrentLocation != null) {
updateTargetsTab();
fCurrentLocation = newLocation;
updateProjectName(configuration);
}
}
catch (CoreException e) {
// do nothing
// has the location changed
Optional<String> newLocation = IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.read(configuration);
if (!newLocation.equals(fCurrentLocation)) {
updateTargetsTab();
fCurrentLocation = newLocation;
updateProjectName(configuration);
}

setMappedResources(configuration);
setAttribute(IAntUIConstants.SET_INPUTHANDLER, configuration, fSetInputHandlerButton.getSelection(), true);
}
Expand Down Expand Up @@ -110,26 +95,21 @@ private void updateProjectName(ILaunchConfigurationWorkingCopy configuration) {
}

private IFile getIFile(ILaunchConfigurationWorkingCopy configuration) {
IFile file = null;
if (fNewFile != null) {
file = fNewFile;
IFile file = fNewFile;
fNewFile = null;
} else {
IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
try {
String location = configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String) null);
if (location != null) {
String expandedLocation = manager.performStringSubstitution(location);
if (expandedLocation != null) {
file = AntUtil.getFileForLocation(expandedLocation, null);
}
}
}
catch (CoreException e) {
// do nothing
}
return file;
}
return IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.read(configuration).flatMap(this::resolve).map(exp -> AntUtil.getFileForLocation(exp, null)).orElse(null);
}

private Optional<String> resolve(String location) {
try {
return Optional.of(VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(location));
}
catch (CoreException e) {
return Optional.empty();
}
return file;
}

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

/**
* Creates the controls needed to edit the set input handler attribute of an Ant build
*
*
* @param parent
* the composite to create the controls in
*/
Expand Down
2 changes: 1 addition & 1 deletion debug/org.eclipse.core.externaltools/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.core.externaltools;singleton:=true
Bundle-Version: 1.3.400.qualifier
Bundle-Version: 1.3.500.qualifier
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.9.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.2.800,4.0.0)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2013 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -11,9 +11,16 @@
* Contributors:
* IBM Corporation - initial API and implementation
* [email protected] - bug 165371
* Alexander Fedorov (ArSysOp) - https://github.com/eclipse-platform/eclipse.platform/issues/1668
*******************************************************************************/

package org.eclipse.core.externaltools.internal;

import org.eclipse.core.externaltools.internal.launchConfigurations.ExternalToolsProgramMessages;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
import org.eclipse.debug.core.ILaunchAttribute;
import org.eclipse.debug.core.ILaunchAttributeIdentity;

/**
* Defines the constants available for client use.
* <p>
Expand All @@ -30,71 +37,77 @@ public interface IExternalToolConstants {
String EMPTY_STRING = ""; //$NON-NLS-1$

/**
* Plug-in identifier for external tools UI (value <code>org.eclipse.ui.externaltools</code>).
* Plug-in identifier for external tools UI (value
* <code>org.eclipse.ui.externaltools</code>).
*/
String UI_PLUGIN_ID = "org.eclipse.ui.externaltools"; //$NON-NLS-1$;
String UI_PLUGIN_ID = "org.eclipse.ui.externaltools"; //$NON-NLS-1$ ;

/**
* Plug-in identifier for external tools core (value <code>org.eclipse.core.externaltools</code>).
* Plug-in identifier for external tools core (value
* <code>org.eclipse.core.externaltools</code>).
*/
String PLUGIN_ID = "org.eclipse.core.externaltools"; //$NON-NLS-1$;
String PLUGIN_ID = "org.eclipse.core.externaltools"; //$NON-NLS-1$ ;

// ------- Refresh Variables -------
/**
* Variable that expands to the workspace root object (value <code>workspace</code>).
* Variable that expands to the workspace root object (value
* <code>workspace</code>).
*/
String VAR_WORKSPACE = "workspace"; //$NON-NLS-1$
/**
* Variable that expands to the project resource (value <code>project</code>).
* Variable that expands to the project resource (value
* <code>project</code>).
*/
String VAR_PROJECT = "project"; //$NON-NLS-1$
/**
* Variable that expands to the container resource (value <code>container</code>).
* Variable that expands to the container resource (value
* <code>container</code>).
*/
String VAR_CONTAINER = "container"; //$NON-NLS-1$
/**
* Variable that expands to a resource (value <code>resource</code>).
*/
String VAR_RESOURCE = "resource"; //$NON-NLS-1$
/**
* Variable that expands to the working set object (value <code>working_set</code>).
* Variable that expands to the working set object (value
* <code>working_set</code>).
*/
String VAR_WORKING_SET = "working_set"; //$NON-NLS-1$
// ------- Tool Types -------
/**
* External tool type for programs such as executables, batch files,
* shell scripts, etc (value <code>programType</code>).
* External tool type for programs such as executables, batch files, shell
* scripts, etc (value <code>programType</code>).
*/
String TOOL_TYPE_PROGRAM = "programType"; //$NON-NLS-1$;
String TOOL_TYPE_PROGRAM = "programType"; //$NON-NLS-1$ ;

// ------- Build Types -------
/**
* Build type indicating an incremental project build request for
* the external tool running as a builder (value <code>incremental</code>).
* Build type indicating an incremental project build request for the
* external tool running as a builder (value <code>incremental</code>).
*/
String BUILD_TYPE_INCREMENTAL = "incremental"; //$NON-NLS-1$

/**
* Build type indicating a full project build request for
* the external tool running as a builder (value <code>full</code>).
* Build type indicating a full project build request for the external tool
* running as a builder (value <code>full</code>).
*/
String BUILD_TYPE_FULL = "full"; //$NON-NLS-1$

/**
* Build type indicating an automatic project build request for
* the external tool running as a builder (value <code>auto</code>).
* Build type indicating an automatic project build request for the external
* tool running as a builder (value <code>auto</code>).
*/
String BUILD_TYPE_AUTO = "auto"; //$NON-NLS-1$

/**
* Build type indicating a clean project build request for
* the external tool running as a builder (value <code>clean</code>).
* Build type indicating a clean project build request for the external tool
* running as a builder (value <code>clean</code>).
*/
String BUILD_TYPE_CLEAN = "clean"; //$NON-NLS-1$

/**
* Build type indicating no project build request for
* the external tool running as a builder (value <code>none</code>).
* Build type indicating no project build request for the external tool
* running as a builder (value <code>none</code>).
*/
String BUILD_TYPE_NONE = "none"; //$NON-NLS-1$

Expand Down Expand Up @@ -129,32 +142,35 @@ public interface IExternalToolConstants {
/**
* Boolean attribute indicating if external tool output should be captured.
* Default value is <code>false</code>.
* @deprecated since 3.1 Replaced by <code>org.eclipse.debug.core.DebugPlugin.ATTR_CAPTURE_OUTPUT</code>
*
* @deprecated since 3.1 Replaced by
* <code>org.eclipse.debug.core.DebugPlugin.ATTR_CAPTURE_OUTPUT</code>
*/
@Deprecated String ATTR_CAPTURE_OUTPUT = UI_PLUGIN_ID + ".ATTR_CAPTURE_OUTPUT"; //$NON-NLS-1$
@Deprecated
String ATTR_CAPTURE_OUTPUT = UI_PLUGIN_ID + ".ATTR_CAPTURE_OUTPUT"; //$NON-NLS-1$
/**
* String attribute identifying the location of an external. Default value
* is <code>null</code>. Encoding is tool specific.
*/
String ATTR_LOCATION = UI_PLUGIN_ID + ".ATTR_LOCATION"; //$NON-NLS-1$

/**
* Boolean attribute indicating if the user should be prompted for
* arguments before running a tool. Default value is <code>false</code>.
* THIS ATTRIBUTE IS NOT USED.
* Boolean attribute indicating if the user should be prompted for arguments
* before running a tool. Default value is <code>false</code>. THIS
* ATTRIBUTE IS NOT USED.
*/
String ATTR_PROMPT_FOR_ARGUMENTS = UI_PLUGIN_ID + ".ATTR_PROMPT_FOR_ARGUMENTS"; //$NON-NLS-1$

/**
* String attribute identifying the scope of resources that should trigger an
* external tool to run. Default value is <code>null</code>
* indicating that the builder will be triggered for all changes.
* String attribute identifying the scope of resources that should trigger
* an external tool to run. Default value is <code>null</code> indicating
* that the builder will be triggered for all changes.
*/
String ATTR_BUILDER_SCOPE = UI_PLUGIN_ID + ".ATTR_BUILD_SCOPE"; //$NON-NLS-1$

/**
* String attribute containing an array of build kinds for which an
* external tool builder should be run.
* String attribute containing an array of build kinds for which an external
* tool builder should be run.
*/
String ATTR_RUN_BUILD_KINDS = UI_PLUGIN_ID + ".ATTR_RUN_BUILD_KINDS"; //$NON-NLS-1$

Expand All @@ -178,16 +194,17 @@ public interface IExternalToolConstants {
String ATTR_WORKING_DIRECTORY = UI_PLUGIN_ID + ".ATTR_WORKING_DIRECTORY"; //$NON-NLS-1$

/**
* String attribute identifying whether an external tool builder configuration
* is enabled. The default value is <code>true</code>, which indicates
* that the configuration will be executed as appropriate by the builder.
* String attribute identifying whether an external tool builder
* configuration is enabled. The default value is <code>true</code>, which
* indicates that the configuration will be executed as appropriate by the
* builder.
*/
String ATTR_BUILDER_ENABLED = UI_PLUGIN_ID + ".ATTR_BUILDER_ENABLED"; //$NON-NLS-1$

/**
* Boolean attribute identifying whether an external tool launcher should execute
* synchronously (value <code>false</code>) or asynchronously (value <code>true</code>).
* Default value is
* Boolean attribute identifying whether an external tool launcher should
* execute synchronously (value <code>false</code>) or asynchronously (value
* <code>true</code>). Default value is
*/
String ATTR_LAUNCH_IN_BACKGROUND = "org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND"; //$NON-NLS-1$

Expand All @@ -197,17 +214,20 @@ public interface IExternalToolConstants {
int ERR_INTERNAL_ERROR = 150;

/**
* String attribute identifying a non-external tool builder launch configuration that is disabled
* The value is the name of the disabled builder.
* String attribute identifying a non-external tool builder launch
* configuration that is disabled The value is the name of the disabled
* builder.
*/
String ATTR_DISABLED_BUILDER = UI_PLUGIN_ID + ".ATTR_DISABLED_BUILDER"; //$NON-NLS-1$
String ATTR_DISABLED_BUILDER = UI_PLUGIN_ID + ".ATTR_DISABLED_BUILDER"; //$NON-NLS-1$

/**
* boolean attribute identifying that an external tool builder has been configured for triggering
* using the <code>ICommand.setBuilding(int)</code> mechanism
* boolean attribute identifying that an external tool builder has been
* configured for triggering using the
* <code>ICommand.setBuilding(int)</code> mechanism
*
* @since 3.1
*/
String ATTR_TRIGGERS_CONFIGURED = UI_PLUGIN_ID + ".ATTR_TRIGGERS_CONFIGURED"; //$NON-NLS-1$
String ATTR_TRIGGERS_CONFIGURED = UI_PLUGIN_ID + ".ATTR_TRIGGERS_CONFIGURED"; //$NON-NLS-1$

/**
* String attribute identifying the build scope for a launch configuration.
Expand All @@ -221,4 +241,37 @@ public interface IExternalToolConstants {
* <code>true</code>.
*/
String ATTR_INCLUDE_REFERENCED_PROJECTS = UI_PLUGIN_ID + ".ATTR_INCLUDE_REFERENCED_PROJECTS"; //$NON-NLS-1$

/**
* {@link ILaunchAttribute<String>} identifying the location of an external.
* Default value is <code>null</code>. Encoding is tool specific.
*/
ILaunchAttribute<String> LAUNCH_ATTRIBUTE_LOCATION = ILaunchAttribute.DEFAULT.create(//
new PreferenceMetadata<>(String.class, //
ILaunchAttributeIdentity.DEFAULT.create(ATTR_LOCATION).id(), //
(String) null, // unspecified by default
ExternalToolsProgramMessages.LaunchAttributeLocation_name));

/**
* {@link ILaunchAttribute<String>} identifying the working directory of an
* external tool. Default value is <code>null</code>, which indicates a
* default working directory, which is tool specific.
*/
ILaunchAttribute<String> LAUNCH_ATTRIBUTE_WORKING_DIRECTORY = ILaunchAttribute.DEFAULT.create(//
new PreferenceMetadata<>(String.class, //
ILaunchAttributeIdentity.DEFAULT.create(ATTR_WORKING_DIRECTORY).id(), //
(String) null, // unspecified by default
ExternalToolsProgramMessages.LaunchAttributeWorkingDirectory_name));

/**
* {@link ILaunchAttribute<String>} containing the arguments that should be
* passed to the tool. Default value is <code>null</code>, and encoding is
* tool specific.
*/
ILaunchAttribute<String> LAUNCH_ATTRIBUTE_ARGUMENTS = ILaunchAttribute.DEFAULT.create(//
new PreferenceMetadata<>(String.class, //
ILaunchAttributeIdentity.DEFAULT.create(ATTR_TOOL_ARGUMENTS).id(), //
(String) null, // unspecified by default
ExternalToolsProgramMessages.LaunchAttributeArguments_name));

}
Loading

0 comments on commit 195c995

Please sign in to comment.