- don't create .buildpath file if it already exists - log possible errors - refactoring
diff --git a/plugins/org.eclipse.dltk.javascript.jdt.integration/src/org/eclipse/dltk/javascript/jdt/integration/Activator.java b/plugins/org.eclipse.dltk.javascript.jdt.integration/src/org/eclipse/dltk/javascript/jdt/integration/Activator.java index 857c0f0..3938de3 100644 --- a/plugins/org.eclipse.dltk.javascript.jdt.integration/src/org/eclipse/dltk/javascript/jdt/integration/Activator.java +++ b/plugins/org.eclipse.dltk.javascript.jdt.integration/src/org/eclipse/dltk/javascript/jdt/integration/Activator.java
@@ -9,7 +9,9 @@ *******************************************************************************/ package org.eclipse.dltk.javascript.jdt.integration; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; import org.osgi.framework.BundleContext; /** @@ -22,26 +24,20 @@ // The shared instance private static Activator plugin; - + /** * The constructor */ public Activator() { } - /* - * (non-Javadoc) - * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext) - */ + @Override public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } - /* - * (non-Javadoc) - * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) - */ + @Override public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); @@ -49,11 +45,17 @@ /** * Returns the shared instance - * + * * @return the shared instance */ public static Activator getDefault() { return plugin; } + public static void error(Throwable e) { + getDefault().getLog().log( + new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, e + .getLocalizedMessage(), e)); + } + }
diff --git a/plugins/org.eclipse.dltk.javascript.jdt.integration/src/org/eclipse/dltk/javascript/jdt/integration/AddJsNatureAction.java b/plugins/org.eclipse.dltk.javascript.jdt.integration/src/org/eclipse/dltk/javascript/jdt/integration/AddJsNatureAction.java index 87d9adb..b49f99d 100644 --- a/plugins/org.eclipse.dltk.javascript.jdt.integration/src/org/eclipse/dltk/javascript/jdt/integration/AddJsNatureAction.java +++ b/plugins/org.eclipse.dltk.javascript.jdt.integration/src/org/eclipse/dltk/javascript/jdt/integration/AddJsNatureAction.java
@@ -9,32 +9,26 @@ *******************************************************************************/ package org.eclipse.dltk.javascript.jdt.integration; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; import org.eclipse.dltk.core.IScriptProjectFilenames; import org.eclipse.dltk.javascript.core.JavaScriptNature; +import org.eclipse.dltk.utils.AdaptUtils; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; -public class AddJsNatureAction implements IExecutableExtension, - IObjectActionDelegate { +public class AddJsNatureAction implements IObjectActionDelegate { - ISelection selection; + private ISelection selection; public AddJsNatureAction() { } - public void setInitializationData(IConfigurationElement config, - String propertyName, Object data) throws CoreException { - } - public void setActivePart(IAction action, IWorkbenchPart targetPart) { } @@ -43,29 +37,29 @@ IStructuredSelection ssel = (IStructuredSelection) selection; Object[] array = ssel.toArray(); for (int a = 0; a < array.length; a++) { - Object o = array[a]; - if (o instanceof IAdaptable) { - IAdaptable adaptable = (IAdaptable) o; - IProject adapter = (IProject) adaptable - .getAdapter(IProject.class); - try { - IProjectDescription description = adapter - .getDescription(); - String[] natureIds = description.getNatureIds(); - String[] newNStrings = new String[natureIds.length + 1]; - System.arraycopy(natureIds, 0, newNStrings, 0, - natureIds.length); - newNStrings[natureIds.length] = JavaScriptNature.NATURE_ID; - description.setNatureIds(newNStrings); - adapter.setDescription(description, null); - adapter.getFile( - IScriptProjectFilenames.BUILDPATH_FILENAME) - .create( - this.getClass().getResourceAsStream( - "buildpath.snap"), true, null); - } catch (CoreException e) { - e.printStackTrace(); + final IProject project = AdaptUtils.getAdapter( + array[a], IProject.class); + if (project == null) { + continue; + } + try { + IProjectDescription description = project.getDescription(); + String[] natureIds = description.getNatureIds(); + String[] newNStrings = new String[natureIds.length + 1]; + System.arraycopy(natureIds, 0, newNStrings, 0, + natureIds.length); + newNStrings[natureIds.length] = JavaScriptNature.NATURE_ID; + description.setNatureIds(newNStrings); + project.setDescription(description, null); + IFile buildpathFile = project + .getFile(IScriptProjectFilenames.BUILDPATH_FILENAME); + if (!buildpathFile.exists()) { + buildpathFile.create(this.getClass() + .getResourceAsStream("buildpath.snap"), true, + null); } + } catch (CoreException e) { + Activator.error(e); } } }