mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-18 21:55:45 +02:00
finish up target manager/target
This commit is contained in:
parent
1f7bb3b6ab
commit
fa4ec73cb8
6 changed files with 224 additions and 117 deletions
|
@ -19,8 +19,6 @@ public interface IMakeTarget {
|
||||||
String getName();
|
String getName();
|
||||||
String getTargetBuilderID();
|
String getTargetBuilderID();
|
||||||
|
|
||||||
String getBuilderID();
|
|
||||||
|
|
||||||
boolean isStopOnError();
|
boolean isStopOnError();
|
||||||
void setStopOnError(boolean stopOnError);
|
void setStopOnError(boolean stopOnError);
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,15 @@ 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;
|
||||||
|
|
||||||
public interface IMakeTargetProvider {
|
public interface IMakeTargetManager {
|
||||||
IMakeTarget addTarget(IContainer container, String targetBuilderID, String targetName) throws CoreException;
|
IMakeTarget addTarget(IContainer container, String targetBuilderID, String targetName) 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;
|
||||||
|
|
||||||
IMakeTarget[] getTargets(IContainer container) throws CoreException;
|
IMakeTarget[] getTargets(IContainer container) throws CoreException;
|
||||||
IProject[] getTargetBuilderProjects() throws CoreException;
|
IProject[] getTargetBuilderProjects() throws CoreException;
|
||||||
|
|
||||||
|
String getBuilderID(String targetBuilderID);
|
||||||
|
|
||||||
void addListener(IMakeTargetListener listener);
|
void addListener(IMakeTargetListener listener);
|
||||||
void removeListener(IMakeTargetListener listener);
|
void removeListener(IMakeTargetListener listener);
|
|
@ -10,6 +10,7 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.core;
|
package org.eclipse.cdt.make.core;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
|
@ -17,19 +18,22 @@ import java.util.ResourceBundle;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.make.internal.core.BuildInfoFactory;
|
import org.eclipse.cdt.make.internal.core.BuildInfoFactory;
|
||||||
import org.eclipse.cdt.make.internal.core.MakeTargetProvider;
|
import org.eclipse.cdt.make.internal.core.MakeTargetManager;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPluginDescriptor;
|
import org.eclipse.core.runtime.IPluginDescriptor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Plugin;
|
import org.eclipse.core.runtime.Plugin;
|
||||||
import org.eclipse.core.runtime.Preferences;
|
import org.eclipse.core.runtime.Preferences;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main plugin class to be used in the desktop.
|
* The main plugin class to be used in the desktop.
|
||||||
*/
|
*/
|
||||||
public class MakeCorePlugin extends Plugin {
|
public class MakeCorePlugin extends Plugin {
|
||||||
private IMakeTargetProvider fTargetProvider;
|
private MakeTargetManager fTargetManager;
|
||||||
public static final String OLD_BUILDER_ID = "org.eclipse.cdt.core.cbuilder"; //$NON-NLS-1$
|
public static final String OLD_BUILDER_ID = "org.eclipse.cdt.core.cbuilder"; //$NON-NLS-1$
|
||||||
//The shared instance.
|
//The shared instance.
|
||||||
private static MakeCorePlugin plugin;
|
private static MakeCorePlugin plugin;
|
||||||
|
@ -56,6 +60,21 @@ public class MakeCorePlugin extends Plugin {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void log(Throwable e) {
|
||||||
|
if (e instanceof InvocationTargetException)
|
||||||
|
e = ((InvocationTargetException) e).getTargetException();
|
||||||
|
IStatus status = null;
|
||||||
|
if (e instanceof CoreException)
|
||||||
|
status = ((CoreException) e).getStatus();
|
||||||
|
else
|
||||||
|
status = new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.OK, e.getMessage(), e);
|
||||||
|
log(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void log(IStatus status) {
|
||||||
|
ResourcesPlugin.getPlugin().getLog().log(status);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the string from the plugin's resource bundle,
|
* Returns the string from the plugin's resource bundle,
|
||||||
* or 'key' if not found.
|
* or 'key' if not found.
|
||||||
|
@ -120,10 +139,18 @@ public class MakeCorePlugin extends Plugin {
|
||||||
return BuildInfoFactory.create(args, builderID);
|
return BuildInfoFactory.create(args, builderID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMakeTargetProvider getTargetProvider() {
|
public IMakeTargetManager getTargetProvider() {
|
||||||
if ( fTargetProvider == null) {
|
if ( fTargetManager == null) {
|
||||||
fTargetProvider = new MakeTargetProvider();
|
fTargetManager = new MakeTargetManager();
|
||||||
|
fTargetManager.startup();
|
||||||
|
}
|
||||||
|
return fTargetManager;
|
||||||
|
}
|
||||||
|
public void shutdown() throws CoreException {
|
||||||
|
super.shutdown();
|
||||||
|
if ( fTargetManager != null) {
|
||||||
|
fTargetManager.shutdown();
|
||||||
|
fTargetManager = null;
|
||||||
}
|
}
|
||||||
return fTargetProvider;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,94 +8,93 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.core;
|
package org.eclipse.cdt.make.internal.core;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.make.core.IMakeBuilderInfo;
|
||||||
import org.eclipse.cdt.make.core.IMakeTarget;
|
import org.eclipse.cdt.make.core.IMakeTarget;
|
||||||
|
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IncrementalProjectBuilder;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
public class MakeTarget implements IMakeTarget {
|
public class MakeTarget implements IMakeTarget {
|
||||||
|
|
||||||
private boolean bDirty;
|
private String buildArguments;
|
||||||
|
private IPath buildCommand;
|
||||||
|
private boolean isDefaultBuildCmd;
|
||||||
|
private boolean isStopOnError;
|
||||||
|
private String name;
|
||||||
|
private String targetBuilderID;
|
||||||
|
private IContainer container;
|
||||||
|
|
||||||
MakeTarget(IContainer container, String targetBuilderID, String targetName) {
|
MakeTarget(IContainer container, String targetBuilderID, String name) {
|
||||||
// dinglis-TODO Auto-generated constructor stub
|
this.container = container;
|
||||||
|
this.targetBuilderID = targetBuilderID;
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setName(String name) {
|
void setName(String name) {
|
||||||
// dinglis-TODO Auto-generated method stub
|
this.name = name;
|
||||||
}
|
|
||||||
|
|
||||||
void setContainer(IContainer container) {
|
|
||||||
// dinglis-TODO Auto-generated method stub
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
// dinglis-TODO Auto-generated method stub
|
return name;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTargetBuilderID() {
|
public String getTargetBuilderID() {
|
||||||
// dinglis-TODO Auto-generated method stub
|
return targetBuilderID;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBuilderID() {
|
|
||||||
// dinglis-TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStopOnError() {
|
public boolean isStopOnError() {
|
||||||
// dinglis-TODO Auto-generated method stub
|
return isStopOnError;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStopOnError(boolean stopOnError) {
|
public void setStopOnError(boolean stopOnError) {
|
||||||
// dinglis-TODO Auto-generated method stub
|
isStopOnError = stopOnError;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDefaultBuildCmd() {
|
public boolean isDefaultBuildCmd() {
|
||||||
// dinglis-TODO Auto-generated method stub
|
return isDefaultBuildCmd;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseDefaultBuildCmd(boolean useDefault) {
|
public void setUseDefaultBuildCmd(boolean useDefault) {
|
||||||
// dinglis-TODO Auto-generated method stub
|
isDefaultBuildCmd = useDefault;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IPath getBuildCommand() {
|
public IPath getBuildCommand() {
|
||||||
// dinglis-TODO Auto-generated method stub
|
return buildCommand;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBuildCommand(IPath command) {
|
public void setBuildCommand(IPath command) {
|
||||||
// dinglis-TODO Auto-generated method stub
|
buildCommand = command;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBuildArguments() {
|
public String getBuildArguments() {
|
||||||
// dinglis-TODO Auto-generated method stub
|
return buildArguments;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBuildArguments(String arguments) {
|
public void setBuildArguments(String arguments) {
|
||||||
// dinglis-TODO Auto-generated method stub
|
buildArguments = arguments;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IContainer getContainer() {
|
public IContainer getContainer() {
|
||||||
// dinglis-TODO Auto-generated method stub
|
return container;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void build(IProgressMonitor monitor) throws CoreException {
|
public void build(IProgressMonitor monitor) throws CoreException {
|
||||||
// dinglis-TODO Auto-generated method stub
|
IProject project = container.getProject();
|
||||||
|
String builderID = MakeCorePlugin.getDefault().getTargetProvider().getBuilderID(targetBuilderID);
|
||||||
}
|
HashMap infoMap = new HashMap();
|
||||||
|
IMakeBuilderInfo info = MakeCorePlugin.createBuildInfo(infoMap, builderID);
|
||||||
public boolean isDirty() {
|
info.setBuildArguments(buildArguments);
|
||||||
return bDirty;
|
info.setBuildCommand(buildCommand);
|
||||||
|
info.setUseDefaultBuildCmd(isDefaultBuildCmd);
|
||||||
|
info.setStopOnError(isStopOnError);
|
||||||
|
info.setFullBuildEnable(true);
|
||||||
|
info.setFullBuildTarget(buildArguments);
|
||||||
|
project.build(IncrementalProjectBuilder.FULL_BUILD, builderID, infoMap, monitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,21 +11,27 @@
|
||||||
package org.eclipse.cdt.make.internal.core;
|
package org.eclipse.cdt.make.internal.core;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import org.eclipse.cdt.make.core.IMakeTarget;
|
import org.eclipse.cdt.make.core.IMakeTarget;
|
||||||
import org.eclipse.cdt.make.core.IMakeTargetListener;
|
import org.eclipse.cdt.make.core.IMakeTargetListener;
|
||||||
import org.eclipse.cdt.make.core.IMakeTargetProvider;
|
import org.eclipse.cdt.make.core.IMakeTargetManager;
|
||||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
||||||
import org.eclipse.cdt.make.core.MakeTargetEvent;
|
import org.eclipse.cdt.make.core.MakeTargetEvent;
|
||||||
import org.eclipse.core.resources.ICommand;
|
import org.eclipse.core.resources.ICommand;
|
||||||
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.resources.IProjectDescription;
|
import org.eclipse.core.resources.IProjectDescription;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IResourceChangeEvent;
|
import org.eclipse.core.resources.IResourceChangeEvent;
|
||||||
import org.eclipse.core.resources.IResourceChangeListener;
|
import org.eclipse.core.resources.IResourceChangeListener;
|
||||||
|
import org.eclipse.core.resources.IResourceDelta;
|
||||||
|
import org.eclipse.core.resources.IResourceDeltaVisitor;
|
||||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
@ -36,56 +42,59 @@ import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
|
||||||
public class MakeTargetProvider implements IMakeTargetProvider, IResourceChangeListener {
|
public class MakeTargetManager implements IMakeTargetManager, IResourceChangeListener {
|
||||||
private static String TARGET_BUILD_EXT = MakeCorePlugin.getUniqueIdentifier() + ".MakeTargetBuilder"; //$NON-NLS-1$
|
private static String TARGET_BUILD_EXT = "MakeTargetBuilder"; //$NON-NLS-1$
|
||||||
|
|
||||||
private ListenerList listeners = new ListenerList();
|
private ListenerList listeners = new ListenerList();
|
||||||
private HashMap projectMap = new HashMap();
|
private HashMap projectMap = new HashMap();
|
||||||
private HashMap builderMap;
|
private HashMap builderMap;
|
||||||
|
private Vector fProjects = new Vector();
|
||||||
|
|
||||||
public MakeTargetProvider() {
|
public MakeTargetManager() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMakeTarget addTarget(IContainer container, String targetBuilderID, String targetName) throws CoreException {
|
public IMakeTarget addTarget(IContainer container, String targetBuilderID, String targetName) throws CoreException {
|
||||||
if (container instanceof IWorkspaceRoot) {
|
if (container instanceof IWorkspaceRoot) {
|
||||||
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeCorePlugin.getResourceString("MakeTargetProvider.add_to_workspace_root"), null)); //$NON-NLS-1$
|
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) {
|
if (projectTargets == null) {
|
||||||
projectTargets = readTargets(container.getProject());
|
projectTargets = readTargets(container.getProject());
|
||||||
}
|
}
|
||||||
MakeTarget target = new MakeTarget(container, targetBuilderID, targetName);
|
MakeTarget target = new MakeTarget(container, targetBuilderID, targetName);
|
||||||
projectTargets.add(target);
|
projectTargets.add(target);
|
||||||
|
writeTargets(projectTargets);
|
||||||
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, target));
|
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_ADD, target));
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeTarget(IMakeTarget target) throws CoreException {
|
public void removeTarget(IMakeTarget target) throws CoreException {
|
||||||
IProject project = target.getContainer().getProject();
|
IProject project = target.getContainer().getProject();
|
||||||
ProjectTargets projectTargets = (ProjectTargets)projectMap.get(project);
|
ProjectTargets projectTargets = (ProjectTargets) projectMap.get(project);
|
||||||
if (projectTargets == null) {
|
if (projectTargets == null) {
|
||||||
projectTargets = readTargets(project);
|
projectTargets = readTargets(project);
|
||||||
}
|
}
|
||||||
projectTargets.remove(target);
|
projectTargets.remove(target);
|
||||||
|
writeTargets(projectTargets);
|
||||||
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_REMOVED, target));
|
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_REMOVED, target));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renameTarget(IMakeTarget target, String name) throws CoreException {
|
public void renameTarget(IMakeTarget target, String name) throws CoreException {
|
||||||
IProject project = target.getContainer().getProject();
|
IProject project = target.getContainer().getProject();
|
||||||
ProjectTargets projectTargets = (ProjectTargets)projectMap.get(project);
|
ProjectTargets projectTargets = (ProjectTargets) projectMap.get(project);
|
||||||
if (projectTargets == null) {
|
if (projectTargets == null) {
|
||||||
projectTargets = readTargets(project);
|
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("MakeTargetProvider.target_exists"), null)); //$NON-NLS-1$
|
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);
|
||||||
projectTargets.setDirty();
|
writeTargets(projectTargets);
|
||||||
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_CHANGED, target));
|
notifyListeners(new MakeTargetEvent(this, MakeTargetEvent.TARGET_CHANGED, target));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMakeTarget[] getTargets(IContainer container) throws CoreException {
|
public IMakeTarget[] getTargets(IContainer container) throws CoreException {
|
||||||
ProjectTargets projectTargets = (ProjectTargets)projectMap.get(container.getProject());
|
ProjectTargets projectTargets = (ProjectTargets) projectMap.get(container.getProject());
|
||||||
if (projectTargets == null) {
|
if (projectTargets == null) {
|
||||||
projectTargets = readTargets(container.getProject());
|
projectTargets = readTargets(container.getProject());
|
||||||
}
|
}
|
||||||
|
@ -93,23 +102,32 @@ public class MakeTargetProvider implements IMakeTargetProvider, IResourceChangeL
|
||||||
}
|
}
|
||||||
|
|
||||||
public IProject[] getTargetBuilderProjects() throws CoreException {
|
public IProject[] getTargetBuilderProjects() throws CoreException {
|
||||||
Vector tProj = new Vector();
|
return (IProject[]) fProjects.toArray(new IProject[fProjects.size()]);
|
||||||
IProject project[] = ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
}
|
||||||
for (int i = 0; i < project.length; i++) {
|
|
||||||
IProjectDescription description = project[i].getDescription();
|
protected boolean hasTargetBuilder(IProject project) throws CoreException {
|
||||||
ICommand builder[] = description.getBuildSpec();
|
IProjectDescription description = project.getDescription();
|
||||||
for (int j = 0; j < builder.length; j++) {
|
ICommand builder[] = description.getBuildSpec();
|
||||||
if (builderMap.containsValue(builder[j].getBuilderName())) {
|
for (int j = 0; j < builder.length; j++) {
|
||||||
tProj.add(project[i]);
|
if (builderMap.containsValue(builder[j].getBuilderName())) {
|
||||||
break;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (IProject[])tProj.toArray(new IProject[tProj.size()]);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startup() {
|
public void startup() {
|
||||||
initializeBuilders();
|
initializeBuilders();
|
||||||
|
IProject project[] = ResourcesPlugin.getWorkspace().getRoot().getProjects();
|
||||||
|
for (int i = 0; i < project.length; i++) {
|
||||||
|
try {
|
||||||
|
if (hasTargetBuilder(project[i])) {
|
||||||
|
fProjects.add(project[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
|
ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,17 +136,86 @@ public class MakeTargetProvider implements IMakeTargetProvider, IResourceChangeL
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resourceChanged(IResourceChangeEvent event) {
|
public void resourceChanged(IResourceChangeEvent event) {
|
||||||
// dinglis-TODO listen for project that add/remove a target type builder
|
IResourceDelta delta = event.getDelta();
|
||||||
|
if (delta != null) {
|
||||||
|
try {
|
||||||
|
delta.accept(new MakeTargetVisitor());
|
||||||
|
} catch (CoreException e) {
|
||||||
|
MakeCorePlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void writeTargets(ProjectTargets projectTargets) {
|
class MakeTargetVisitor implements IResourceDeltaVisitor {
|
||||||
|
/**
|
||||||
|
* @see IResourceDeltaVisitor#visit(IResourceDelta)
|
||||||
|
*/
|
||||||
|
public boolean visit(IResourceDelta delta) {
|
||||||
|
if (delta == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IResource resource = delta.getResource();
|
||||||
|
if (resource.getType() == IResource.PROJECT) {
|
||||||
|
IProject project = (IProject) resource;
|
||||||
|
int flags = delta.getFlags();
|
||||||
|
int deltaKind = delta.getKind();
|
||||||
|
if (deltaKind == IResourceDelta.ADDED) {
|
||||||
|
try {
|
||||||
|
if (hasTargetBuilder(project)) {
|
||||||
|
fProjects.add(project);
|
||||||
|
notifyListeners(new MakeTargetEvent(MakeTargetManager.this, MakeTargetEvent.PROJECT_ADDED, project));
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
}
|
||||||
|
} else if (deltaKind == IResourceDelta.REMOVED) {
|
||||||
|
if (fProjects.contains(project)) {
|
||||||
|
fProjects.remove(project);
|
||||||
|
notifyListeners(new MakeTargetEvent(MakeTargetManager.this, MakeTargetEvent.PROJECT_REMOVED, project));
|
||||||
|
}
|
||||||
|
} else if (deltaKind == IResourceDelta.CHANGED) {
|
||||||
|
try {
|
||||||
|
if (0 != (flags & IResourceDelta.DESCRIPTION)) {
|
||||||
|
if (fProjects.contains(project) && !hasTargetBuilder(project)) {
|
||||||
|
fProjects.remove(project);
|
||||||
|
notifyListeners(
|
||||||
|
new MakeTargetEvent(MakeTargetManager.this, MakeTargetEvent.PROJECT_REMOVED, project));
|
||||||
|
} else if (!fProjects.contains(project) && hasTargetBuilder(project)) {
|
||||||
|
fProjects.add(project);
|
||||||
|
notifyListeners(
|
||||||
|
new MakeTargetEvent(MakeTargetManager.this, MakeTargetEvent.PROJECT_ADDED, project));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (0 != (flags & IResourceDelta.OPEN)) {
|
||||||
|
if (!project.isOpen() && fProjects.contains(project)) {
|
||||||
|
fProjects.remove(project);
|
||||||
|
notifyListeners(
|
||||||
|
new MakeTargetEvent(MakeTargetManager.this, MakeTargetEvent.PROJECT_REMOVED, project));
|
||||||
|
} else if (project.isOpen() && hasTargetBuilder(project) && !fProjects.contains(project)) {
|
||||||
|
fProjects.add(project);
|
||||||
|
notifyListeners(
|
||||||
|
new MakeTargetEvent(MakeTargetManager.this, MakeTargetEvent.PROJECT_ADDED, project));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return resource instanceof IWorkspaceRoot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected void writeTargets(ProjectTargets projectTargets) throws CoreException {
|
||||||
IPath targetFilePath = MakeCorePlugin.getDefault().getStateLocation().append(projectTargets.getProject().getName());
|
IPath targetFilePath = MakeCorePlugin.getDefault().getStateLocation().append(projectTargets.getProject().getName());
|
||||||
File targetFile = targetFilePath.toFile();
|
File targetFile = targetFilePath.toFile();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
FileOutputStream file = new FileOutputStream(targetFile);
|
FileOutputStream file = new FileOutputStream(targetFile);
|
||||||
} catch (Exception e) {
|
projectTargets.saveTargets(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new CoreException(
|
||||||
|
new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, "Error writing target file", e));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ProjectTargets readTargets(IProject project) throws CoreException {
|
protected ProjectTargets readTargets(IProject project) throws CoreException {
|
||||||
|
@ -136,8 +223,10 @@ public class MakeTargetProvider implements IMakeTargetProvider, IResourceChangeL
|
||||||
File targetFile = targetFilePath.toFile();
|
File targetFile = targetFilePath.toFile();
|
||||||
if (targetFile.exists()) {
|
if (targetFile.exists()) {
|
||||||
try {
|
try {
|
||||||
return new ProjectTargets(project, targetFile);
|
return new ProjectTargets(project, new FileInputStream(targetFile));
|
||||||
} catch (Exception e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new CoreException(
|
||||||
|
new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, "Error reading target file", e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ProjectTargets(project);
|
return new ProjectTargets(project);
|
||||||
|
@ -145,8 +234,7 @@ public class MakeTargetProvider implements IMakeTargetProvider, IResourceChangeL
|
||||||
|
|
||||||
protected void initializeBuilders() {
|
protected void initializeBuilders() {
|
||||||
builderMap = new HashMap();
|
builderMap = new HashMap();
|
||||||
|
IExtensionPoint point = MakeCorePlugin.getDefault().getDescriptor().getExtensionPoint(MakeTargetManager.TARGET_BUILD_EXT);
|
||||||
IExtensionPoint point = MakeCorePlugin.getDefault().getDescriptor().getExtensionPoint(MakeTargetProvider.TARGET_BUILD_EXT);
|
|
||||||
IExtension[] ext = point.getExtensions();
|
IExtension[] ext = point.getExtensions();
|
||||||
for (int i = 0; i < ext.length; i++) {
|
for (int i = 0; i < ext.length; i++) {
|
||||||
IConfigurationElement[] element = ext[i].getConfigurationElements();
|
IConfigurationElement[] element = ext[i].getConfigurationElements();
|
||||||
|
@ -163,7 +251,7 @@ public class MakeTargetProvider implements IMakeTargetProvider, IResourceChangeL
|
||||||
protected void notifyListeners(MakeTargetEvent event) {
|
protected void notifyListeners(MakeTargetEvent event) {
|
||||||
Object[] list = listeners.getListeners();
|
Object[] list = listeners.getListeners();
|
||||||
for (int i = 0; i < list.length; i++) {
|
for (int i = 0; i < list.length; i++) {
|
||||||
((IMakeTargetListener)list[i]).targetChanged(event);
|
((IMakeTargetListener) list[i]).targetChanged(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,4 +262,8 @@ public class MakeTargetProvider implements IMakeTargetProvider, IResourceChangeL
|
||||||
public void removeListener(IMakeTargetListener listener) {
|
public void removeListener(IMakeTargetListener listener) {
|
||||||
listeners.remove(listeners);
|
listeners.remove(listeners);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getBuilderID(String targetBuilderID) {
|
||||||
|
return (String) builderMap.get(targetBuilderID);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,9 +1,8 @@
|
||||||
package org.eclipse.cdt.make.internal.core;
|
package org.eclipse.cdt.make.internal.core;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -34,22 +33,21 @@ public class ProjectTargets {
|
||||||
private static String BUILD_TARGET_ELEMENT = "buildTargets"; //$NON-NLS-1$
|
private static String BUILD_TARGET_ELEMENT = "buildTargets"; //$NON-NLS-1$
|
||||||
private static String TARGET_ELEMENT = "target"; //$NON-NLS-1$
|
private static String TARGET_ELEMENT = "target"; //$NON-NLS-1$
|
||||||
|
|
||||||
private boolean isDirty;
|
|
||||||
private HashMap targetMap = new HashMap();
|
private HashMap targetMap = new HashMap();
|
||||||
private IProject project;
|
private IProject project;
|
||||||
|
|
||||||
public ProjectTargets(IProject project) {
|
public ProjectTargets(IProject project) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectTargets(IProject project, File targetFile) throws CoreException {
|
public ProjectTargets(IProject project, InputStream input) throws CoreException {
|
||||||
Document document = null;
|
Document document = null;
|
||||||
try {
|
try {
|
||||||
FileInputStream file = new FileInputStream(targetFile);
|
|
||||||
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
|
||||||
document = parser.parse(file);
|
document = parser.parse(input);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, "Error reading target file", e));
|
throw new CoreException(
|
||||||
|
new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, "Error reading target file", e));
|
||||||
}
|
}
|
||||||
Node node = document.getFirstChild();
|
Node node = document.getFirstChild();
|
||||||
if (node.getNodeName().equals(BUILD_TARGET_ELEMENT)) {
|
if (node.getNodeName().equals(BUILD_TARGET_ELEMENT)) {
|
||||||
|
@ -103,17 +101,17 @@ public class ProjectTargets {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IMakeTarget[] get(IContainer container) {
|
public IMakeTarget[] get(IContainer container) {
|
||||||
ArrayList list = (ArrayList)targetMap.get(container);
|
ArrayList list = (ArrayList) targetMap.get(container);
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
return (IMakeTarget[])list.toArray(new IMakeTarget[list.size()]);
|
return (IMakeTarget[]) list.toArray(new IMakeTarget[list.size()]);
|
||||||
}
|
}
|
||||||
return new IMakeTarget[0];
|
return new IMakeTarget[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(MakeTarget target) throws CoreException {
|
public void add(MakeTarget target) throws CoreException {
|
||||||
ArrayList list = (ArrayList)targetMap.get(target.getContainer());
|
ArrayList list = (ArrayList) 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, MakeCorePlugin.getResourceString("MakeTargetProvider.target_exists"), null)); //$NON-NLS-1$
|
throw new CoreException(new Status(IStatus.ERROR, MakeCorePlugin.getUniqueIdentifier(), -1, MakeCorePlugin.getResourceString("MakeTargetManager.target_exists"), null)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
list = new ArrayList();
|
list = new ArrayList();
|
||||||
|
@ -123,7 +121,7 @@ public class ProjectTargets {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(MakeTarget target) {
|
public boolean contains(MakeTarget target) {
|
||||||
ArrayList list = (ArrayList)targetMap.get(target.getContainer());
|
ArrayList list = (ArrayList) targetMap.get(target.getContainer());
|
||||||
if (list != null && list.contains(target)) {
|
if (list != null && list.contains(target)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +129,7 @@ public class ProjectTargets {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(IMakeTarget target) {
|
public void remove(IMakeTarget target) {
|
||||||
ArrayList list = (ArrayList)targetMap.get(target.getContainer());
|
ArrayList list = (ArrayList) targetMap.get(target.getContainer());
|
||||||
if (list != null && !list.contains(target)) {
|
if (list != null && !list.contains(target)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -141,35 +139,26 @@ public class ProjectTargets {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDirty() {
|
|
||||||
isDirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDirty() {
|
|
||||||
return isDirty;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IProject getProject() {
|
public IProject getProject() {
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getAsXML() throws IOException {
|
protected Document getAsXML() throws IOException {
|
||||||
Document doc = new DocumentImpl();
|
Document doc = new DocumentImpl();
|
||||||
Element configRootElement = doc.createElement(BUILD_TARGET_ELEMENT);
|
Element configRootElement = doc.createElement(BUILD_TARGET_ELEMENT);
|
||||||
doc.appendChild(configRootElement);
|
doc.appendChild(configRootElement);
|
||||||
return serializeDocument(doc);
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String serializeDocument(Document doc) throws IOException {
|
public void saveTargets(OutputStream output) throws IOException {
|
||||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
Document doc = getAsXML();
|
||||||
OutputFormat format = new OutputFormat();
|
OutputFormat format = new OutputFormat();
|
||||||
format.setIndenting(true);
|
format.setIndenting(true);
|
||||||
|
format.setPreserveSpace(true);
|
||||||
format.setLineSeparator(System.getProperty("line.separator")); //$NON-NLS-1$
|
format.setLineSeparator(System.getProperty("line.separator")); //$NON-NLS-1$
|
||||||
Serializer serializer =
|
Serializer serializer =
|
||||||
SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(new OutputStreamWriter(s, "UTF8"), format);
|
SerializerFactory.getSerializerFactory(Method.XML).makeSerializer(new OutputStreamWriter(output, "UTF8"), format);
|
||||||
serializer.asDOMSerializer().serialize(doc);
|
serializer.asDOMSerializer().serialize(doc);
|
||||||
return s.toString("UTF8"); //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue