mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
bug 295148: MakeTargetManager does not scale for Makefiles with a large number of Make Targets
Patch from Jeff Johnston
This commit is contained in:
parent
6f30d79326
commit
88548c7e81
4 changed files with 88 additions and 6 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<IMakeTarget> newList = new ArrayList<IMakeTarget>();
|
||||
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<IMakeTarget> list = targetMap.get(container);
|
||||
if (list != null) {
|
||||
|
|
Loading…
Add table
Reference in a new issue