diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeTargetManager.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeTargetManager.java index a0a8134935c..34ed240d8b2 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeTargetManager.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeTargetManager.java @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Red Hat Inc - Add setTargets method *******************************************************************************/ package org.eclipse.cdt.make.core; @@ -31,7 +32,8 @@ public interface IMakeTargetManager { void addTarget(IMakeTarget target) throws CoreException; /** - * Adds target to manager on a specific projects folder. + * Adds target to manager on a specific projects folder. It is assumed + * that the target and container belong to the same project. * @param container * @param target * @throws CoreException @@ -40,6 +42,21 @@ public interface IMakeTargetManager { void removeTarget(IMakeTarget target) throws CoreException; void renameTarget(IMakeTarget target, String name) throws CoreException; + /** + * Set targets on a specific projects folder. It is assumed + * all targets and container belong to the same project which + * is determined from the first element of the + * targets array. If no container is specified, the project is used. + * All previous targets for the container are replaced upon success and if + * failure occurs, an exception is thrown and the previous set of targets + * for the container are unchanged. + * + * @param container to set targets for or null if project should be used + * @param targets array + * @throws CoreException + */ + public void setTargets(IContainer container, IMakeTarget[] targets) throws CoreException; + boolean targetExists(IMakeTarget target); IMakeTarget[] getTargets(IContainer container) throws CoreException; diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeTargetEvent.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeTargetEvent.java index ea2b43d5e4b..2287103c1ef 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeTargetEvent.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/MakeTargetEvent.java @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Red Hat Inc. - Allow multiple targets *******************************************************************************/ package org.eclipse.cdt.make.core; @@ -27,7 +28,7 @@ public class MakeTargetEvent extends EventObject { public static final int PROJECT_ADDED = 4; public static final int PROJECT_REMOVED = 5; - IMakeTarget target; + IMakeTarget[] targets; IProject project; int type; @@ -37,7 +38,21 @@ public class MakeTargetEvent extends EventObject { public MakeTargetEvent(Object source, int type, IMakeTarget target) { super(source); this.type = type; - this.target = target; + this.targets = new IMakeTarget[] {target}; + } + + /** + * @param source + * @param type event type (e.g. TARGET_ADD, TARGET_CHANGED) + * @param targets array of MakeTargets + * @since 7.0 + * + */ + public MakeTargetEvent(Object source, int type, IMakeTarget[] targets) { + super(source); + this.type = type; + this.targets = new IMakeTarget[targets.length]; + System.arraycopy(targets, 0, this.targets, 0, targets.length); } public MakeTargetEvent(Object source, int type, IProject project) { @@ -50,7 +65,19 @@ public class MakeTargetEvent extends EventObject { return type; } + /** + * @deprecated + * Use getTargets() instead. + */ + @Deprecated public IMakeTarget getTarget() { - return target; + return targets[0]; + } + + /** + * @since 7.0 + */ + public IMakeTarget[] getTargets() { + return targets; } } diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java index abf759a80ef..d91108570ac 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * QNX Software Systems - Initial API and implementation + * Red Hat Inc. - add setTargets method *******************************************************************************/ package org.eclipse.cdt.make.internal.core; @@ -81,6 +82,28 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, target)); } + public void setTargets(IContainer container, IMakeTarget[] targets) throws CoreException { + 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$ + } + ProjectTargets projectTargets = projectMap.get(targets[0].getProject()); + if (projectTargets == null) { + projectTargets = readTargets(targets[0].getProject()); + } + if (container == null) + container = targets[0].getProject(); + IMakeTarget[] oldTargets = projectTargets.get(container); + projectTargets.set(container, targets); + try { + writeTargets(projectTargets); + } catch (CoreException e) { + // we only need to reset the targets if writing of targets fails + projectTargets.set(container, oldTargets); + throw e; + } + notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, targets[0])); + } + public boolean targetExists(IMakeTarget target) { ProjectTargets projectTargets = projectMap.get(target.getProject()); if (projectTargets == null) { diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java index 32dd67c239a..b0fc7a35bf9 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 QNX Software Systems and others. + * Copyright (c) 2000, 2010 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation * James Blackburn (Broadcom Corp.) - Use ICStorageElement + * Red Hat Inc. - Add set method *******************************************************************************/ package org.eclipse.cdt.make.internal.core; @@ -108,6 +109,20 @@ public class ProjectTargets { return new IMakeTarget[0]; } + public void set(IContainer container, IMakeTarget[] targets) throws CoreException { + List newList = new ArrayList(); + for (int i = 0; i < targets.length; ++i) { + IMakeTarget target = targets[i]; + target.setContainer(container); + if (newList.contains(target)) { + throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, + MakeMessages.getString("MakeTargetManager.target_exists"), null)); //$NON-NLS-1$ + } + newList.add(target); + } + targetMap.put(container, newList); + } + public IMakeTarget findTarget(IContainer container, String name) { List list = targetMap.get(container); if (list != null) {