1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

bug 241178: MakeTargetManager implementation should allow to manage arbitrary IMakeTarget not assuming concrete MakeTarget type

This commit is contained in:
Andrew Gvozdev 2010-02-10 03:55:42 +00:00
parent 91cdaecd4c
commit 01cef9b0e9
4 changed files with 46 additions and 28 deletions

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.core; package org.eclipse.cdt.make.core;
import org.eclipse.cdt.make.internal.core.MakeTargetManager;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -25,44 +26,61 @@ import org.eclipse.core.runtime.IProgressMonitor;
public interface IMakeTarget extends IAdaptable, IMakeCommonBuildInfo { public interface IMakeTarget extends IAdaptable, IMakeCommonBuildInfo {
public final static String BUILD_TARGET = ARGS_PREFIX + ".build.target"; //$NON-NLS-1$ public final static String BUILD_TARGET = ARGS_PREFIX + ".build.target"; //$NON-NLS-1$
String getName(); public String getName();
/**
* @noreference This method is not intended to be referenced by clients.
* Do not use this method to change target name, rather use {@link MakeTargetManager#renameTarget(IMakeTarget, String)}.
* This method is for internal use only.
*
* @param name
* @since 7.0
*/
public void setName(String name);
String getTargetBuilderID(); public String getTargetBuilderID();
IProject getProject(); public IProject getProject();
/** /**
* @deprecated * @deprecated
*
* @param target
* @throws CoreException
*/ */
void setBuildTarget(String target) throws CoreException; @Deprecated
public void setBuildTarget(String target) throws CoreException;
/** /**
* @deprecated * @deprecated
*
* @return build target
*/ */
String getBuildTarget() ; @Deprecated
public String getBuildTarget();
void setRunAllBuilders(boolean runAllBuilders) throws CoreException; public void setRunAllBuilders(boolean runAllBuilders) throws CoreException;
boolean runAllBuilders(); public boolean runAllBuilders();
/** /**
* Get the target build container. * Get the target build container.
* *
* @return IContainer of where target build will be invoked. * @return IContainer of where target build will be invoked.
*/ */
IContainer getContainer(); public IContainer getContainer();
/** /**
* Make this target temporary on the container, this target will not be persisted, * Make this target temporary on the container, this target will not be persisted,
* and may not be added to the IMakeTargetManager. * and may not be added to the IMakeTargetManager.
* @param container * @param container
*/ */
void setContainer(IContainer container); public void setContainer(IContainer container);
void setAppendProjectEnvironment(boolean append); public void setAppendProjectEnvironment(boolean append);
boolean appendProjectEnvironment(); public boolean appendProjectEnvironment();
void build(IProgressMonitor monitor) throws CoreException; public void build(IProgressMonitor monitor) throws CoreException;
} }

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -51,7 +51,7 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
private Map<String, String> buildEnvironment = new HashMap<String, String>(); private Map<String, String> buildEnvironment = new HashMap<String, String>();
private final Map<String, String> targetAttributes = new HashMap<String, String>(); private final Map<String, String> targetAttributes = new HashMap<String, String>();
MakeTarget(MakeTargetManager manager, IProject project, String targetBuilderID, String name) throws CoreException { public MakeTarget(MakeTargetManager manager, IProject project, String targetBuilderID, String name) throws CoreException {
this.manager = manager; this.manager = manager;
this.project = project; this.project = project;
this.targetBuilderID = targetBuilderID; this.targetBuilderID = targetBuilderID;
@ -71,7 +71,7 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
this.container = container; this.container = container;
} }
void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
@ -331,7 +331,7 @@ public class MakeTarget extends PlatformObject implements IMakeTarget {
} }
} }
@SuppressWarnings("unchecked") @SuppressWarnings("rawtypes")
@Override @Override
public Object getAdapter(Class adapter) { public Object getAdapter(Class adapter) {
if (adapter.equals(IProject.class)) { if (adapter.equals(IProject.class)) {

View file

@ -71,12 +71,12 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
if (projectTargets == null) { if (projectTargets == null) {
projectTargets = readTargets(target.getProject()); projectTargets = readTargets(target.getProject());
} }
((MakeTarget) target).setContainer(container == null ? target.getProject() : container); target.setContainer(container == null ? target.getProject() : container);
projectTargets.add((MakeTarget) target); projectTargets.add(target);
try { try {
writeTargets(projectTargets); writeTargets(projectTargets);
} catch (CoreException e) { } catch (CoreException e) {
projectTargets.remove((MakeTarget) target); projectTargets.remove(target);
throw e; throw e;
} }
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, target)); notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, target));
@ -109,7 +109,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
if (projectTargets == null) { if (projectTargets == null) {
projectTargets = readTargets(target.getProject()); projectTargets = readTargets(target.getProject());
} }
return projectTargets.contains((MakeTarget) target); return projectTargets.contains(target);
} }
public void removeTarget(IMakeTarget target) throws CoreException { public void removeTarget(IMakeTarget target) throws CoreException {
@ -117,11 +117,11 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
if (projectTargets == null) { if (projectTargets == null) {
projectTargets = readTargets(target.getProject()); projectTargets = readTargets(target.getProject());
} }
if (projectTargets.remove((MakeTarget) target)) { if (projectTargets.remove(target)) {
try { try {
writeTargets(projectTargets); writeTargets(projectTargets);
} catch (CoreException e) { } catch (CoreException e) {
projectTargets.add((MakeTarget) target); projectTargets.add(target);
throw e; throw e;
} }
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_REMOVED, target)); notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_REMOVED, target));
@ -129,7 +129,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
} }
public void renameTarget(IMakeTarget target, String name) throws CoreException { public void renameTarget(IMakeTarget target, String name) throws CoreException {
MakeTarget makeTarget = (MakeTarget)target; IMakeTarget makeTarget = target;
ProjectTargets projectTargets = projectMap.get(makeTarget.getProject()); ProjectTargets projectTargets = projectMap.get(makeTarget.getProject());
if (projectTargets == null) { if (projectTargets == null) {
@ -276,7 +276,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
} }
} }
protected void updateTarget(MakeTarget target) throws CoreException { protected void updateTarget(IMakeTarget 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.
ProjectTargets projectTargets = projectMap.get(target.getProject()); ProjectTargets projectTargets = projectMap.get(target.getProject());
if (projectTargets == null || !projectTargets.contains(target)) { if (projectTargets == null || !projectTargets.contains(target)) {

View file

@ -132,7 +132,7 @@ public class ProjectTargets {
return null; return null;
} }
public void add(MakeTarget target) throws CoreException { public void add(IMakeTarget target) throws CoreException {
List<IMakeTarget> list = targetMap.get(target.getContainer()); List<IMakeTarget> list = targetMap.get(target.getContainer());
if (list != null && list.contains(target)) { if (list != null && list.contains(target)) {
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1,
@ -145,7 +145,7 @@ public class ProjectTargets {
list.add(target); list.add(target);
} }
public boolean contains(MakeTarget target) { public boolean contains(IMakeTarget target) {
List<IMakeTarget> list = targetMap.get(target.getContainer()); List<IMakeTarget> list = targetMap.get(target.getContainer());
if (list != null && list.contains(target)) { if (list != null && list.contains(target)) {
return true; return true;
@ -153,7 +153,7 @@ public class ProjectTargets {
return false; return false;
} }
public boolean remove(MakeTarget target) { public boolean remove(IMakeTarget target) {
List<IMakeTarget> list = targetMap.get(target.getContainer()); List<IMakeTarget> list = targetMap.get(target.getContainer());
if (list == null || !list.contains(target)) { if (list == null || !list.contains(target)) {
return false; return false;
@ -264,7 +264,7 @@ public class ProjectTargets {
container = project; container = project;
} }
try { try {
MakeTarget target = new MakeTarget(manager, project, node.getAttribute(TARGET_ATTR_ID), IMakeTarget target = new MakeTarget(manager, project, node.getAttribute(TARGET_ATTR_ID),
node.getAttribute(TARGET_ATTR_NAME)); node.getAttribute(TARGET_ATTR_NAME));
target.setContainer(container); target.setContainer(container);
ICStorageElement[] option = node.getChildrenByName(TARGET_STOP_ON_ERROR); ICStorageElement[] option = node.getChildrenByName(TARGET_STOP_ON_ERROR);