Skip to content

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

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

Open
wants to merge 3 commits 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) 2004, 2016 IBM Corporation and others.
* Copyright (c) 2004, 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) - API to process launch configuration attributes
*******************************************************************************/
package org.eclipse.ant.internal.launching.debug.model;

Expand All @@ -22,7 +23,6 @@
import org.eclipse.core.externaltools.internal.IExternalToolConstants;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.debug.core.DebugEvent;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
Expand Down Expand Up @@ -108,13 +108,7 @@ public boolean hasThreads() throws DebugException {
@Override
public String getName() throws DebugException {
if (fName == null) {
try {
fName = getLaunch().getLaunchConfiguration().getAttribute(IExternalToolConstants.ATTR_LOCATION, DebugModelMessages.AntDebugTarget_0);
fName = VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(fName);
}
catch (CoreException e) {
fName = DebugModelMessages.AntDebugTarget_0;
}
fName = IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.probe(getLaunch().getLaunchConfiguration()).orElse(DebugModelMessages.AntDebugTarget_0);
}
return fName;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2013 IBM Corporation and others.
* Copyright (c) 2006, 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) - API to process launch configuration attributes
*******************************************************************************/
package org.eclipse.ant.internal.launching.launchConfigurations;

Expand All @@ -18,8 +19,6 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
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.ILaunchConfigurationMigrationDelegate;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
Expand All @@ -40,23 +39,7 @@ public class AntMigrationDelegate implements ILaunchConfigurationMigrationDelega
* @return the buildfile or <code>null</code> if not in the workspace
*/
protected IFile getFileForCandidate(ILaunchConfiguration candidate) {
IFile file = null;
String expandedLocation = null;
String location = null;
IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
try {
location = candidate.getAttribute(IExternalToolConstants.ATTR_LOCATION, (String) null);
if (location != null) {
expandedLocation = manager.performStringSubstitution(location);
if (expandedLocation != null) {
file = AntLaunchingUtil.getFileForLocation(expandedLocation, null);
}
}
}
catch (CoreException e) {
// do nothing
}
return file;
return IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.probe(candidate).map(l -> AntLaunchingUtil.getFileForLocation(l, null)).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2015 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) - API to process launch configuration attributes
*******************************************************************************/
package org.eclipse.ant.internal.ui;

Expand All @@ -20,7 +21,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -195,7 +195,7 @@ public static AntTargetNode[] getTargets(String path, ILaunchConfiguration confi
}

private static Map<String, String> getAllProperties(ILaunchConfiguration config) throws CoreException {
String allArgs = config.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, (String) null);
String allArgs = IExternalToolConstants.LAUNCH_ATTRIBUTE_ARGUMENTS.read(config);
Map<String, String> properties = new HashMap<>();
if (allArgs != null) {
// filter arguments to avoid resolving variables that will prompt the user
Expand All @@ -213,9 +213,7 @@ private static Map<String, String> getAllProperties(ILaunchConfiguration config)
}
Map<String, String> configProperties = getProperties(config);
if (configProperties != null) {
Iterator<String> keys = configProperties.keySet().iterator();
while (keys.hasNext()) {
String name = keys.next();
for (String name : configProperties.keySet()) {
if (properties.get(name) == null) {
properties.put(name, configProperties.get(name));
}
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 @@ -10,9 +10,12 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Alexander Fedorov (ArSysOp) - API to process launch configuration attributes
*******************************************************************************/
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.probe(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.probe(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,12 @@ 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 file;
return IExternalToolConstants.LAUNCH_ATTRIBUTE_LOCATION.probe(configuration).map(exp -> AntUtil.getFileForLocation(exp, null)).orElse(null);
}

@Override
Expand Down
Loading
Loading