AndroidNaturepublic class AndroidNature extends Object implements org.eclipse.core.resources.IProjectNatureProject nature for the Android Projects. |
Fields Summary |
---|
private org.eclipse.core.resources.IProject | mProjectthe project this nature object is associated with |
Methods Summary |
---|
private static void | addNatureToProjectDescription(org.eclipse.core.resources.IProject project, java.lang.String natureId, org.eclipse.core.runtime.IProgressMonitor monitor)Add the specified nature to the specified project. The nature is only
added if not already present.
Android Natures are always inserted at the beginning of the list of natures in order to
have the jdt views/dialogs display the proper icon.
if (!project.hasNature(natureId)) {
IProjectDescription description = project.getDescription();
String[] natures = description.getNatureIds();
String[] newNatures = new String[natures.length + 1];
// Android natures always come first.
if (natureId.equals(AndroidConstants.NATURE)) {
System.arraycopy(natures, 0, newNatures, 1, natures.length);
newNatures[0] = natureId;
} else {
System.arraycopy(natures, 0, newNatures, 0, natures.length);
newNatures[natures.length] = natureId;
}
description.setNatureIds(newNatures);
project.setDescription(description, new SubProgressMonitor(monitor, 10));
}
| public void | configure()Configures this nature for its project. This is called by the workspace
when natures are added to the project using
IProject.setDescription and should not be called directly
by clients. The nature extension id is added to the list of natures
before this method is called, and need not be added here.
Exceptions thrown by this method will be propagated back to the caller of
IProject.setDescription , but the nature will remain in
the project description.
The Android nature adds the pre-builder and the APK builder if necessary.
configureResourceManagerBuilder(mProject);
configurePreBuilder(mProject);
configureApkBuilder(mProject);
| public static void | configureApkBuilder(org.eclipse.core.resources.IProject project)
// Add the .apk builder at the end if it's not already there
IProjectDescription desc = project.getDescription();
ICommand[] commands = desc.getBuildSpec();
for (int i = 0; i < commands.length; ++i) {
if (ApkBuilder.ID.equals(commands[i].getBuilderName())) {
return;
}
}
ICommand[] newCommands = new ICommand[commands.length + 1];
System.arraycopy(commands, 0, newCommands, 0, commands.length);
ICommand command = desc.newCommand();
command.setBuilderName(ApkBuilder.ID);
newCommands[commands.length] = command;
desc.setBuildSpec(newCommands);
project.setDescription(desc, null);
| public static void | configurePreBuilder(org.eclipse.core.resources.IProject project)Adds the PreCompilerBuilder if its not already there. It'll check for
presence of the ResourceManager and insert itself right after.
// get the builder list
IProjectDescription desc = project.getDescription();
ICommand[] commands = desc.getBuildSpec();
// look for the builder in case it's already there.
for (int i = 0; i < commands.length; ++i) {
if (PreCompilerBuilder.ID.equals(commands[i].getBuilderName())) {
return;
}
}
// we need to add it after the resource manager builder.
// Let's look for it
int index = -1;
for (int i = 0; i < commands.length; ++i) {
if (ResourceManagerBuilder.ID.equals(commands[i].getBuilderName())) {
index = i;
break;
}
}
// we're inserting after
index++;
// do the insertion
// copy the builders before.
ICommand[] newCommands = new ICommand[commands.length + 1];
System.arraycopy(commands, 0, newCommands, 0, index);
// insert the new builder
ICommand command = desc.newCommand();
command.setBuilderName(PreCompilerBuilder.ID);
newCommands[index] = command;
// copy the builder after
System.arraycopy(commands, index, newCommands, index + 1, commands.length-index);
// set the new builders in the project
desc.setBuildSpec(newCommands);
project.setDescription(desc, null);
| public static void | configureResourceManagerBuilder(org.eclipse.core.resources.IProject project)Adds the ResourceManagerBuilder, if its not already there. It'll insert
itself as the first builder.
// get the builder list
IProjectDescription desc = project.getDescription();
ICommand[] commands = desc.getBuildSpec();
// look for the builder in case it's already there.
for (int i = 0; i < commands.length; ++i) {
if (ResourceManagerBuilder.ID.equals(commands[i].getBuilderName())) {
return;
}
}
// it's not there, lets add it at the beginning of the builders
ICommand[] newCommands = new ICommand[commands.length + 1];
System.arraycopy(commands, 0, newCommands, 1, commands.length);
ICommand command = desc.newCommand();
command.setBuilderName(ResourceManagerBuilder.ID);
newCommands[0] = command;
desc.setBuildSpec(newCommands);
project.setDescription(desc, null);
| public void | deconfigure()De-configures this nature for its project. This is called by the
workspace when natures are removed from the project using
IProject.setDescription and should not be called directly
by clients. The nature extension id is removed from the list of natures
before this method is called, and need not be removed here.
Exceptions thrown by this method will be propagated back to the caller of
IProject.setDescription , but the nature will still be
removed from the project description.
The Android nature removes the custom pre builder and APK builder.
// remove the android builders
removeBuilder(mProject, ResourceManagerBuilder.ID);
removeBuilder(mProject, PreCompilerBuilder.ID);
removeBuilder(mProject, ApkBuilder.ID);
| public org.eclipse.core.resources.IProject | getProject()Returns the project to which this project nature applies.
return mProject;
| public static boolean | removeBuilder(org.eclipse.core.resources.IProject project, java.lang.String id)Removes a builder from the project.
IProjectDescription description = project.getDescription();
ICommand[] commands = description.getBuildSpec();
for (int i = 0; i < commands.length; ++i) {
if (id.equals(commands[i].getBuilderName())) {
ICommand[] newCommands = new ICommand[commands.length - 1];
System.arraycopy(commands, 0, newCommands, 0, i);
System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
description.setBuildSpec(newCommands);
project.setDescription(description, null);
return true;
}
}
return false;
| public void | setProject(org.eclipse.core.resources.IProject project)Sets the project to which this nature applies. Used when instantiating
this project nature runtime. This is called by
IProject.create() or
IProject.setDescription() and should not be called
directly by clients.
mProject = project;
| public static synchronized void | setupProjectNatures(org.eclipse.core.resources.IProject project, org.eclipse.core.runtime.IProgressMonitor monitor)Adds the Android Nature and the Java Nature to the project if it doesn't
already have them.
if (project == null || !project.isOpen()) return;
if (monitor == null) monitor = new NullProgressMonitor();
// Add the natures. We need to add the Java nature first, so it adds its builder to the
// project first. This way, when the android nature is added, we can control where to put
// the android builders in relation to the java builder.
// Adding the java nature after the android one, would place the java builder before the
// android builders.
addNatureToProjectDescription(project, JavaCore.NATURE_ID, monitor);
addNatureToProjectDescription(project, AndroidConstants.NATURE, monitor);
|
|