Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Inglis2003-08-21 15:41:29 -0400
committerDavid Inglis2003-08-21 15:41:29 -0400
commit19672f2ef59ba7e064e6bb6b05773aa089895ccb (patch)
treeab47dfbe631c0097a81c4b269815cd1f702b63fa
parente9a58e48b61f0ff1d2a78dc8ae202fc8ccaa8ea4 (diff)
downloadorg.eclipse.cdt-19672f2ef59ba7e064e6bb6b05773aa089895ccb.tar.gz
org.eclipse.cdt-19672f2ef59ba7e064e6bb6b05773aa089895ccb.tar.xz
org.eclipse.cdt-19672f2ef59ba7e064e6bb6b05773aa089895ccb.zip
added findTarget to MakeTargetManager
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/core/IMakeTargetManager.java2
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTarget.java14
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTargetManager.java36
-rw-r--r--build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/ProjectTargets.java28
4 files changed, 61 insertions, 19 deletions
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 2c0636e5b0f..9bdd4e3df1d 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
@@ -20,6 +20,8 @@ public interface IMakeTargetManager {
void renameTarget(IMakeTarget target, String name) throws CoreException;
IMakeTarget[] getTargets(IContainer container) throws CoreException;
+ IMakeTarget findTarget(IContainer container, String name);
+
IProject[] getTargetBuilderProjects() throws CoreException;
String getBuilderID(String targetBuilderID);
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTarget.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTarget.java
index 3b5f9950e4c..823371035af 100644
--- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTarget.java
+++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/MakeTarget.java
@@ -84,6 +84,20 @@ public class MakeTarget implements IMakeTarget {
return container;
}
+ public boolean equals(Object obj) {
+ if (obj == this)
+ return true;
+ if (obj instanceof MakeTarget) {
+ MakeTarget other = (MakeTarget) obj;
+ return container.equals(other.getContainer()) && name.equals(other.getName());
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ return container.hashCode() * 17 + name.hashCode();
+ }
+
public void build(IProgressMonitor monitor) throws CoreException {
IProject project = container.getProject();
String builderID = MakeCorePlugin.getDefault().getTargetManager().getBuilderID(targetBuilderID);
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 e29b04accc5..dcd40e869ed 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
@@ -60,7 +60,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
if (container instanceof IWorkspaceRoot) {
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeCorePlugin.getResourceString("MakeTargetManager.add_to_workspace_root"), null)); //$NON-NLS-1$
}
- ProjectTargets projectTargets = (ProjectTargets)projectMap.get(container.getProject());
+ ProjectTargets projectTargets = (ProjectTargets) projectMap.get(container.getProject());
if (projectTargets == null) {
projectTargets = readTargets(container.getProject());
}
@@ -73,7 +73,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
public void removeTarget(IMakeTarget target) throws CoreException {
IProject project = target.getContainer().getProject();
- ProjectTargets projectTargets = (ProjectTargets)projectMap.get(project);
+ ProjectTargets projectTargets = (ProjectTargets) projectMap.get(project);
if (projectTargets == null) {
projectTargets = readTargets(project);
}
@@ -84,28 +84,36 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
public void renameTarget(IMakeTarget target, String name) throws CoreException {
IProject project = target.getContainer().getProject();
- ProjectTargets projectTargets = (ProjectTargets)projectMap.get(project);
+ ProjectTargets projectTargets = (ProjectTargets) projectMap.get(project);
if (projectTargets == null) {
projectTargets = readTargets(project);
}
- if (!projectTargets.contains((MakeTarget)target)) {
+ if (!projectTargets.contains((MakeTarget) target)) {
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeCorePlugin.getResourceString("MakeTargetManager.target_exists"), null)); //$NON-NLS-1$
}
- ((MakeTarget)target).setName(name);
+ ((MakeTarget) target).setName(name);
writeTargets(projectTargets);
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_CHANGED, target));
}
public IMakeTarget[] getTargets(IContainer container) throws CoreException {
- ProjectTargets projectTargets = (ProjectTargets)projectMap.get(container.getProject());
+ ProjectTargets projectTargets = (ProjectTargets) projectMap.get(container.getProject());
if (projectTargets == null) {
projectTargets = readTargets(container.getProject());
}
return projectTargets.get(container);
}
+ public IMakeTarget findTarget(IContainer container, String name) {
+ ProjectTargets projectTargets = (ProjectTargets) projectMap.get(container.getProject());
+ if (projectTargets == null) {
+ projectTargets = readTargets(container.getProject());
+ }
+ return projectTargets.findTarget(container, name);
+ }
+
public IProject[] getTargetBuilderProjects() throws CoreException {
- return (IProject[])fProjects.toArray(new IProject[fProjects.size()]);
+ return (IProject[]) fProjects.toArray(new IProject[fProjects.size()]);
}
public String[] getTargetBuilders(IProject project) {
@@ -117,13 +125,13 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
for (int i = 0; i < builder.length; i++) {
Iterator entries = builderMap.entrySet().iterator();
while (entries.hasNext()) {
- Map.Entry entry = (Entry)entries.next();
+ Map.Entry entry = (Entry) entries.next();
if (entry.getValue().equals(builder[i].getBuilderName())) {
ids.add(entry.getKey());
}
}
}
- return (String[])ids.toArray(new String[ids.size()]);
+ return (String[]) ids.toArray(new String[ids.size()]);
} catch (CoreException e) {
}
}
@@ -182,7 +190,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
}
IResource resource = delta.getResource();
if (resource.getType() == IResource.PROJECT) {
- IProject project = (IProject)resource;
+ IProject project = (IProject) resource;
int flags = delta.getFlags();
int deltaKind = delta.getKind();
if (deltaKind == IResourceDelta.ADDED) {
@@ -234,15 +242,13 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
}
- protected ProjectTargets readTargets(IProject project) throws CoreException {
+ protected ProjectTargets readTargets(IProject project) {
IPath targetFilePath = MakeCorePlugin.getDefault().getStateLocation().append(project.getName());
File targetFile = targetFilePath.toFile();
if (targetFile.exists()) {
try {
return new ProjectTargets(project, new FileInputStream(targetFile));
} catch (FileNotFoundException e) {
- throw new CoreException(
- new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, "Error reading target file", e));
}
}
return new ProjectTargets(project);
@@ -267,7 +273,7 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
protected void notifyListeners(MakeTargetEvent event) {
Object[] list = listeners.getListeners();
for (int i = 0; i < list.length; i++) {
- ((IMakeTargetListener)list[i]).targetChanged(event);
+ ((IMakeTargetListener) list[i]).targetChanged(event);
}
}
@@ -280,6 +286,6 @@ public class MakeTargetManager implements IMakeTargetManager, IResourceChangeLis
}
public String getBuilderID(String targetBuilderID) {
- return (String)builderMap.get(targetBuilderID);
+ return (String) builderMap.get(targetBuilderID);
}
} \ No newline at end of file
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 3ae94bd5fef..db5047b7391 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
@@ -6,6 +6,7 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -40,14 +41,15 @@ public class ProjectTargets {
this.project = project;
}
- public ProjectTargets(IProject project, InputStream input) throws CoreException {
+ public ProjectTargets(IProject project, InputStream input) {
+ this(project);
+
Document document = null;
try {
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
document = parser.parse(input);
} catch (Exception e) {
- throw new CoreException(
- new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, "Error reading target file", e));
+ MakeCorePlugin.log(e);
}
Node node = document.getFirstChild();
if (node.getNodeName().equals(BUILD_TARGET_ELEMENT)) {
@@ -80,7 +82,11 @@ public class ProjectTargets {
if (option != null) {
target.setBuildArguments(option);
}
- add(target);
+ try {
+ add(target);
+ } catch (CoreException e) {
+ MakeCorePlugin.log(e);
+ }
}
}
}
@@ -107,6 +113,20 @@ public class ProjectTargets {
}
return new IMakeTarget[0];
}
+
+ public IMakeTarget findTarget(IContainer container, String name) {
+ ArrayList list = (ArrayList) targetMap.get(container);
+ if (list != null) {
+ Iterator targets = list.iterator();
+ while( targets.hasNext()) {
+ IMakeTarget target = (IMakeTarget)targets.next();
+ if ( target.getName().equals(name) ) {
+ return target;
+ }
+ }
+ }
+ return null;
+ }
public void add(MakeTarget target) throws CoreException {
ArrayList list = (ArrayList) targetMap.get(target.getContainer());

Back to the top