Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1668] API types to simplify work with launch configuration attributes #1669

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,24 +10,26 @@
*
* 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;
import org.eclipse.ant.internal.ui.IAntUIConstants;
import org.eclipse.ant.internal.ui.IAntUIHelpContextIds;
import org.eclipse.ant.launching.IAntLaunchConstants;
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
import org.eclipse.core.resources.IFile;
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;
import org.eclipse.debug.core.LaunchAttributeProbe;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jface.dialogs.Dialog;
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 = new LaunchAttributeProbe<>(configuration, locationAttribute).get();
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 = new LaunchAttributeProbe<>(configuration, locationAttribute).get();
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 new LaunchAttributeProbe<>(configuration, locationAttribute).get().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,14 @@
* 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.debug.core.LauchAttributeIdentityRecord;
import org.eclipse.debug.core.LaunchAttributeIdentity;

/**
* Defines the constants available for client use.
* <p>
Expand Down Expand Up @@ -221,4 +226,13 @@ public interface IExternalToolConstants {
* <code>true</code>.
*/
String ATTR_INCLUDE_REFERENCED_PROJECTS = UI_PLUGIN_ID + ".ATTR_INCLUDE_REFERENCED_PROJECTS"; //$NON-NLS-1$

interface LaunchAttributes {

LaunchAttributeIdentity location = new LauchAttributeIdentityRecord(ATTR_LOCATION);
LaunchAttributeIdentity workingDirectory = new LauchAttributeIdentityRecord(ATTR_WORKING_DIRECTORY);
LaunchAttributeIdentity arguments = new LauchAttributeIdentityRecord(ATTR_TOOL_ARGUMENTS);

}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2009 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,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Alexander Fedorov (ArSysOp) - https://github.com/eclipse-platform/eclipse.platform/issues/1668
*******************************************************************************/
package org.eclipse.core.externaltools.internal.launchConfigurations;

Expand All @@ -29,6 +30,15 @@ public class ExternalToolsProgramMessages extends NLS {
public static String ExternalToolsUtil_invalidLocation__0_;
public static String ExternalToolsUtil_invalidDirectory__0_;


public static String LaunchAttributeArguments_name;


public static String LaunchAttributeLocation_name;


public static String LaunchAttributeWorkingDirectory_name;

static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, ExternalToolsProgramMessages.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2000, 2009 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,6 +10,7 @@
#
# Contributors:
# IBM Corporation - initial API and implementation
# Alexander Fedorov (ArSysOp) - https://github.com/eclipse-platform/eclipse.platform/issues/1668
###############################################################################

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

ExternalToolsUtil_Location_not_specified_by__0__1=Location not specified by {0}
ExternalToolsUtil_invalidLocation__0_ = The file does not exist for the external tool named {0}.
ExternalToolsUtil_invalidDirectory__0_ = The working directory {0} does not exist for the external tool named {1}.
ExternalToolsUtil_invalidDirectory__0_ = The working directory {0} does not exist for the external tool named {1}.
LaunchAttributeArguments_name=Arguments
LaunchAttributeLocation_name=Location
LaunchAttributeWorkingDirectory_name=Working Directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2025 ArSysOp.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.core.externaltools.internal.launchConfigurations;

import org.eclipse.core.externaltools.internal.IExternalToolConstants;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
import org.eclipse.debug.core.LaunchAttributeDefined;
import org.eclipse.debug.core.LaunchAttributeIdentity;

public final class LaunchAttributeArguments implements LaunchAttributeDefined<String> {

@Override
public LaunchAttributeIdentity identity() {
return IExternalToolConstants.LaunchAttributes.arguments;
}

@Override
public PreferenceMetadata<String> metadata() {
return new PreferenceMetadata<>(String.class, //
identity().id(),
null, // unspecified by default
ExternalToolsProgramMessages.LaunchAttributeArguments_name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2025 ArSysOp.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.core.externaltools.internal.launchConfigurations;

import org.eclipse.core.externaltools.internal.IExternalToolConstants;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
import org.eclipse.debug.core.LaunchAttributeDefined;
import org.eclipse.debug.core.LaunchAttributeIdentity;

public final class LaunchAttributeLocation implements LaunchAttributeDefined<String> {

@Override
public LaunchAttributeIdentity identity() {
return IExternalToolConstants.LaunchAttributes.location;
}

@Override
public PreferenceMetadata<String> metadata() {
return new PreferenceMetadata<>(String.class, //
identity().id(),
null, // unspecified by default
ExternalToolsProgramMessages.LaunchAttributeLocation_name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2025 ArSysOp.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.core.externaltools.internal.launchConfigurations;

import org.eclipse.core.externaltools.internal.IExternalToolConstants;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
import org.eclipse.debug.core.LaunchAttributeDefined;
import org.eclipse.debug.core.LaunchAttributeIdentity;

public final class LaunchAttributeWorkingDirectory implements LaunchAttributeDefined<String> {

@Override
public LaunchAttributeIdentity identity() {
return IExternalToolConstants.LaunchAttributes.workingDirectory;
}

@Override
public PreferenceMetadata<String> metadata() {
return new PreferenceMetadata<>(String.class, //
identity().id(),
null, // unspecified by default
ExternalToolsProgramMessages.LaunchAttributeWorkingDirectory_name);
}

}
2 changes: 1 addition & 1 deletion debug/org.eclipse.debug.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.debug.core; singleton:=true
Bundle-Version: 3.22.100.qualifier
Bundle-Version: 3.23.0.qualifier
Bundle-Activator: org.eclipse.debug.core.DebugPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2024, 2025 ArSysOp.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Alexander Fedorov (ArSysOp) - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.core;

/**
* Default implementation for {@link LaunchAttributeIdentity}
*
* @since 3.23
*/
public record LauchAttributeIdentityRecord(String id) implements LaunchAttributeIdentity {

/**
* Convenience way to compose full qualified name for launch attribute
*
* @param qualifier usually corresponds to Bundle-Symbolic-Name
* @param key short key to name this very attribute in the scope of
* qualifier
*/
public LauchAttributeIdentityRecord(String qualifier, String key) {
this(qualifier + "." + key); //$NON-NLS-1$
}

}
Loading
Loading