1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 01:05:38 +02:00

fixed for bug#94831

This commit is contained in:
David Inglis 2005-07-04 14:06:27 +00:00
parent d4b824ca8c
commit bcf69885a2
6 changed files with 82 additions and 42 deletions

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.make.core; package org.eclipse.cdt.make.core;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -22,6 +23,8 @@ public interface IMakeTarget extends IAdaptable, IMakeCommonBuildInfo {
String getName(); String getName();
String getTargetBuilderID(); String getTargetBuilderID();
IProject getProject();
/** /**
* @deprecated * @deprecated
*/ */

View file

@ -16,10 +16,25 @@ import org.eclipse.core.runtime.CoreException;
public interface IMakeTargetManager { public interface IMakeTargetManager {
IMakeTarget createTarget(IProject project, String targetName, String targetBuilderID) throws CoreException; IMakeTarget createTarget(IProject project, String targetName, String targetBuilderID) throws CoreException;
/**
* Adds target to manager.
* @param target
* @throws CoreException
*/
void addTarget(IMakeTarget target) throws CoreException;
/**
* Adds target to manager on a specific projects folder.
* @param container
* @param target
* @throws CoreException
*/
void addTarget(IContainer container, IMakeTarget target) throws CoreException; void addTarget(IContainer container, IMakeTarget target) throws CoreException;
void removeTarget(IMakeTarget target) throws CoreException; void removeTarget(IMakeTarget target) throws CoreException;
void renameTarget(IMakeTarget target, String name) throws CoreException; void renameTarget(IMakeTarget target, String name) throws CoreException;
boolean targetExists(IMakeTarget target);
IMakeTarget[] getTargets(IContainer container) throws CoreException; IMakeTarget[] getTargets(IContainer container) throws CoreException;
IMakeTarget findTarget(IContainer container, String name) throws CoreException; IMakeTarget findTarget(IContainer container, String name) throws CoreException;

View file

@ -38,6 +38,7 @@ import org.eclipse.osgi.service.environment.Constants;
public class MakeTarget extends PlatformObject implements IMakeTarget { public class MakeTarget extends PlatformObject implements IMakeTarget {
private final MakeTargetManager manager; private final MakeTargetManager manager;
private final IProject project;
private String name; private String name;
private boolean isDefaultBuildCmd; private boolean isDefaultBuildCmd;
private boolean isStopOnError; private boolean isStopOnError;
@ -50,6 +51,7 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
MakeTarget(MakeTargetManager manager, IProject project, String targetBuilderID, String name) throws CoreException { MakeTarget(MakeTargetManager manager, IProject project, String targetBuilderID, String name) throws CoreException {
this.manager = manager; this.manager = manager;
this.project = project;
this.targetBuilderID = targetBuilderID; this.targetBuilderID = targetBuilderID;
this.name = name; this.name = name;
IMakeBuilderInfo info = MakeCorePlugin.createBuildInfo(project, manager.getBuilderID(targetBuilderID)); IMakeBuilderInfo info = MakeCorePlugin.createBuildInfo(project, manager.getBuilderID(targetBuilderID));
@ -61,6 +63,10 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
buildEnvironment = info.getEnvironment(); buildEnvironment = info.getEnvironment();
} }
public IProject getProject() {
return project;
}
public void setContainer(IContainer container) { public void setContainer(IContainer container) {
this.container = container; this.container = container;
} }
@ -103,7 +109,7 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
if (isDefaultBuildCmd()) { if (isDefaultBuildCmd()) {
IMakeBuilderInfo info; IMakeBuilderInfo info;
try { try {
info = MakeCorePlugin.createBuildInfo(container.getProject(), manager.getBuilderID(targetBuilderID)); info = MakeCorePlugin.createBuildInfo(getProject(), manager.getBuilderID(targetBuilderID));
return info.getBuildCommand(); return info.getBuildCommand();
} catch (CoreException e) { } catch (CoreException e) {
} }
@ -176,7 +182,7 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
public String[] getErrorParsers() { public String[] getErrorParsers() {
IMakeBuilderInfo projectInfo; IMakeBuilderInfo projectInfo;
try { try {
projectInfo = MakeCorePlugin.createBuildInfo(container.getProject(), manager.getBuilderID(targetBuilderID)); projectInfo = MakeCorePlugin.createBuildInfo(getProject(), manager.getBuilderID(targetBuilderID));
return projectInfo.getErrorParsers(); return projectInfo.getErrorParsers();
} catch (CoreException e) { } catch (CoreException e) {
} }
@ -249,7 +255,6 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
} }
public void build(IProgressMonitor monitor) throws CoreException { public void build(IProgressMonitor monitor) throws CoreException {
final IProject project = container.getProject();
final String builderID = manager.getBuilderID(targetBuilderID); final String builderID = manager.getBuilderID(targetBuilderID);
final HashMap infoMap = new HashMap(); final HashMap infoMap = new HashMap();
@ -265,7 +270,7 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
if (container != null) { if (container != null) {
info.setBuildAttribute(IMakeCommonBuildInfo.BUILD_LOCATION, container.getFullPath().toString()); info.setBuildAttribute(IMakeCommonBuildInfo.BUILD_LOCATION, container.getFullPath().toString());
} }
IMakeBuilderInfo projectInfo = MakeCorePlugin.createBuildInfo(project, builderID); IMakeBuilderInfo projectInfo = MakeCorePlugin.createBuildInfo(getProject(), builderID);
info.setErrorParsers(projectInfo.getErrorParsers()); info.setErrorParsers(projectInfo.getErrorParsers());
IWorkspaceRunnable op = new IWorkspaceRunnable() { IWorkspaceRunnable op = new IWorkspaceRunnable() {
@ -301,7 +306,7 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
public Object getAdapter(Class adapter) { public Object getAdapter(Class adapter) {
if (adapter.equals(IProject.class)) { if (adapter.equals(IProject.class)) {
return container.getProject(); return getProject();
} else if (adapter.equals(IResource.class)) { } else if (adapter.equals(IResource.class)) {
return container; return container;
} }

View file

@ -59,19 +59,19 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
return new MakeTarget(this, project, targetBuilderID, name); return new MakeTarget(this, project, targetBuilderID, name);
} }
public void addTarget(IMakeTarget target) throws CoreException {
addTarget(null, target);
}
public void addTarget(IContainer container, IMakeTarget target) throws CoreException { public void addTarget(IContainer container, IMakeTarget target) throws CoreException {
if (container instanceof IWorkspaceRoot) { if (container instanceof IWorkspaceRoot) {
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeMessages.getString("MakeTargetManager.add_to_workspace_root"), null)); //$NON-NLS-1$ throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeMessages.getString("MakeTargetManager.add_to_workspace_root"), null)); //$NON-NLS-1$
} }
if (target.getContainer() != null) { ProjectTargets projectTargets = (ProjectTargets)projectMap.get(target.getProject());
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeMessages.getString("MakeTargetManager.add_temporary_target"), null)); //$NON-NLS-1$
}
IProject project = container.getProject();
ProjectTargets projectTargets = (ProjectTargets)projectMap.get(project);
if (projectTargets == null) { if (projectTargets == null) {
projectTargets = readTargets(project); projectTargets = readTargets(target.getProject());
} }
((MakeTarget) target).setContainer(container); ((MakeTarget) target).setContainer(container == null ? target.getProject() : container);
projectTargets.add((MakeTarget) target); projectTargets.add((MakeTarget) target);
try { try {
writeTargets(projectTargets); writeTargets(projectTargets);
@ -82,11 +82,18 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, target)); notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, target));
} }
public void removeTarget(IMakeTarget target) throws CoreException { public boolean targetExists(IMakeTarget target) {
IProject project = target.getContainer().getProject(); ProjectTargets projectTargets = (ProjectTargets)projectMap.get(target.getProject());
ProjectTargets projectTargets = (ProjectTargets)projectMap.get(project);
if (projectTargets == null) { if (projectTargets == null) {
projectTargets = readTargets(project); projectTargets = readTargets(target.getProject());
}
return projectTargets.contains((MakeTarget) target);
}
public void removeTarget(IMakeTarget target) throws CoreException {
ProjectTargets projectTargets = (ProjectTargets)projectMap.get(target.getProject());
if (projectTargets == null) {
projectTargets = readTargets(target.getProject());
} }
if (projectTargets.remove((MakeTarget) target)) { if (projectTargets.remove((MakeTarget) target)) {
try { try {
@ -100,10 +107,9 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
} }
public void renameTarget(IMakeTarget target, String name) throws CoreException { public void renameTarget(IMakeTarget target, String name) throws CoreException {
IProject project = target.getContainer().getProject(); ProjectTargets projectTargets = (ProjectTargets)projectMap.get(target.getProject());
ProjectTargets projectTargets = (ProjectTargets)projectMap.get(project);
if (projectTargets == null) { if (projectTargets == null) {
projectTargets = readTargets(project); projectTargets = readTargets(target.getProject());
} }
if (!projectTargets.contains((MakeTarget)target)) { if (!projectTargets.contains((MakeTarget)target)) {
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeMessages.getString("MakeTargetManager.target_exists"), null)); //$NON-NLS-1$ throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeMessages.getString("MakeTargetManager.target_exists"), null)); //$NON-NLS-1$
@ -250,8 +256,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
protected void updateTarget(MakeTarget target) throws CoreException { protected void updateTarget(MakeTarget target) throws CoreException {
if (target.getContainer() != null ) { // target has not been added to manager. if (target.getContainer() != null ) { // target has not been added to manager.
IProject project = target.getContainer().getProject(); ProjectTargets projectTargets = (ProjectTargets)projectMap.get(target.getProject());
ProjectTargets projectTargets = (ProjectTargets)projectMap.get(project);
if (projectTargets == null || !projectTargets.contains(target)) { if (projectTargets == null || !projectTargets.contains(target)) {
return; // target has not been added to manager. return; // target has not been added to manager.
} }

View file

@ -19,6 +19,7 @@ import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.makefile.ITargetRule; import org.eclipse.cdt.make.core.makefile.ITargetRule;
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
import org.eclipse.cdt.make.ui.dialogs.MakeTargetDialog; import org.eclipse.cdt.make.ui.dialogs.MakeTargetDialog;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action; import org.eclipse.jface.action.Action;
@ -68,18 +69,15 @@ public class AddBuildTargetAction extends Action {
sbMakefileTarget.append(' ').append(name); sbMakefileTarget.append(' ').append(name);
} }
} }
String buildName = sbBuildName.toString(); String buildName = generateUniqueName(file.getParent(), sbBuildName.toString());
String makefileTarget = sbMakefileTarget.toString(); String makefileTarget = sbMakefileTarget.toString();
IMakeTarget target; IMakeTarget target = null;
try { try {
target = manager.findTarget(file.getParent(), buildName); String[] ids = manager.getTargetBuilders(file.getProject());
if (target == null) { if (ids.length > 0) {
String[] ids = manager.getTargetBuilders(file.getProject()); target = manager.createTarget(file.getProject(), buildName, ids[0]);
if (ids.length > 0) { target.setBuildAttribute(IMakeTarget.BUILD_TARGET, makefileTarget);
target = manager.createTarget(file.getProject(), buildName, ids[0]); target.setContainer(file.getParent());
target.setBuildTarget(makefileTarget);
manager.addTarget(file.getParent(), target);
}
} }
} catch (CoreException e) { } catch (CoreException e) {
MakeUIPlugin.errorDialog(shell, MakeUIPlugin.getResourceString("AddBuildTargetAction.exception.internal"), e.toString(), e); //$NON-NLS-1$ MakeUIPlugin.errorDialog(shell, MakeUIPlugin.getResourceString("AddBuildTargetAction.exception.internal"), e.toString(), e); //$NON-NLS-1$
@ -99,6 +97,20 @@ public class AddBuildTargetAction extends Action {
} }
} }
private String generateUniqueName(IContainer container, String targetString) {
String newName = targetString;
int i = 0;
IMakeTargetManager manager = MakeCorePlugin.getDefault().getTargetManager();
try {
while (manager.findTarget(container, newName) != null) {
i++;
newName = targetString + " (" + Integer.toString(i) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
} catch (CoreException e) {
}
return newName;
}
public boolean canActionBeAdded(ISelection selection) { public boolean canActionBeAdded(ISelection selection) {
ITargetRule[] rules = getTargetRules(selection); ITargetRule[] rules = getTargetRules(selection);
for (int i = 0; i < rules.length; i++) { for (int i = 0; i < rules.length; i++) {

View file

@ -91,7 +91,7 @@ public class MakeTargetDialog extends Dialog {
buildCommand = target.getBuildCommand(); buildCommand = target.getBuildCommand();
buildArguments = target.getBuildArguments(); buildArguments = target.getBuildArguments();
targetName = target.getName(); targetName = target.getName();
targetString = target.getBuildTarget(); targetString = target.getBuildAttribute(IMakeTarget.BUILD_TARGET, "all");
targetBuildID = target.getTargetBuilderID(); targetBuildID = target.getTargetBuilderID();
runAllBuilders = target.runAllBuilders(); runAllBuilders = target.runAllBuilders();
} }
@ -125,7 +125,7 @@ public class MakeTargetDialog extends Dialog {
private String getTitle() { private String getTitle() {
String title; String title;
if (fTarget == null) { if (fTarget == null || !MakeCorePlugin.getDefault().getTargetManager().targetExists(fTarget)) {
title = MakeUIPlugin.getResourceString("MakeTargetDialog.title.createMakeTarget"); //$NON-NLS-1$ title = MakeUIPlugin.getResourceString("MakeTargetDialog.title.createMakeTarget"); //$NON-NLS-1$
} else { } else {
title = MakeUIPlugin.getResourceString("MakeTargetDialog.title.modifyMakeTarget"); //$NON-NLS-1$ title = MakeUIPlugin.getResourceString("MakeTargetDialog.title.modifyMakeTarget"); //$NON-NLS-1$
@ -298,10 +298,10 @@ public class MakeTargetDialog extends Dialog {
} }
protected void createButtonsForButtonBar(Composite parent) { protected void createButtonsForButtonBar(Composite parent) {
if (fTarget != null) { if (fTarget == null || !MakeCorePlugin.getDefault().getTargetManager().targetExists(fTarget)) {
createButton(parent, IDialogConstants.OK_ID, MakeUIPlugin.getResourceString("MakeTargetDialog.button.update"), true); //$NON-NLS-1$
} else {
createButton(parent, IDialogConstants.OK_ID, MakeUIPlugin.getResourceString("MakeTargetDialog.button.create"), true); //$NON-NLS-1$ createButton(parent, IDialogConstants.OK_ID, MakeUIPlugin.getResourceString("MakeTargetDialog.button.create"), true); //$NON-NLS-1$
} else {
createButton(parent, IDialogConstants.OK_ID, MakeUIPlugin.getResourceString("MakeTargetDialog.button.update"), true); //$NON-NLS-1$
} }
createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
//do this here because setting the text will set enablement on the ok //do this here because setting the text will set enablement on the ok
@ -333,7 +333,7 @@ public class MakeTargetDialog extends Dialog {
} }
protected boolean targetHasChanged() { protected boolean targetHasChanged() {
if (initializing || fTarget == null) if (initializing || fTarget == null || !MakeCorePlugin.getDefault().getTargetManager().targetExists(fTarget))
return true; return true;
if (isStopOnError != isStopOnError()) if (isStopOnError != isStopOnError())
return true; return true;
@ -421,16 +421,16 @@ public class MakeTargetDialog extends Dialog {
} else { } else {
path = new Path(bldLine.substring(start, end)); path = new Path(bldLine.substring(start, end));
} }
target.setBuildCommand(path); target.setBuildAttribute(IMakeTarget.BUILD_COMMAND, path.toString());
String args = ""; //$NON-NLS-1$ String args = ""; //$NON-NLS-1$
if (end != -1) { if (end != -1) {
args = bldLine.substring(end + 1); args = bldLine.substring(end + 1);
} }
target.setBuildArguments(args); target.setBuildAttribute(IMakeTarget.BUILD_ARGUMENTS, args);
} }
target.setBuildTarget(getTarget()); target.setBuildAttribute(IMakeTarget.BUILD_TARGET, getTarget());
if (fTarget == null) { if (fTarget == null || !MakeCorePlugin.getDefault().getTargetManager().targetExists(fTarget)) {
fTargetManager.addTarget(fContainer, target); fTargetManager.addTarget(fContainer, target);
} else { } else {
if (!target.getName().equals(getTargetName())) { if (!target.getName().equals(getTargetName())) {