[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[imp-commit] r22813 - in trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp: utils wizards
|
- From: genie@xxxxxxxxxxx
- Date: Fri, 19 Nov 2010 12:48:45 -0500 (EST)
- Delivered-to: imp-commit@eclipse.org
Author: rfuhrer
Date: 2010-11-19 12:48:44 -0500 (Fri, 19 Nov 2010)
New Revision: 22813
Added:
trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/utils/DynamicBundleUtils.java
Modified:
trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/utils/ExtensionPointUtils.java
trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/ExtensionEnabler.java
trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/IMPWizardPage.java
trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/NewBuilder.java
trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/NewFormattingSpecification.java
trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/WizardUtilities.java
Log:
Moved some extension-point- and language-related utility methods from WizardUtilities to a better home in ExtensionPointUtils. Added support for dynamically registering languages in new class DynamicBundleUtils.
Added: trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/utils/DynamicBundleUtils.java
===================================================================
--- trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/utils/DynamicBundleUtils.java (rev 0)
+++ trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/utils/DynamicBundleUtils.java 2010-11-19 17:48:44 UTC (rev 22813)
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Robert Fuhrer (rfuhrer@xxxxxxxxxxxxxx) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.imp.utils;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.imp.WizardPlugin;
+import org.eclipse.imp.language.ServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+/**
+ * @author rfuhrer
+ */
+public class DynamicBundleUtils {
+ public static Bundle activateWorkspaceBundleForExtension(String langName, String extensionPointID) {
+ if (langName == null)
+ return null;
+ IProject owningProject= ExtensionPointUtils.findProjectForLanguageExtension(langName, extensionPointID);
+ if (owningProject != null) {
+ try {
+ BundleContext context= WizardPlugin.getInstance().getBundle().getBundleContext();
+ URL bundleURL= new URL("file", null, owningProject.getLocation().toPortableString());
+ Bundle bundle= context.installBundle(bundleURL.toExternalForm());
+
+ if (bundle != null && bundle.getState() != Bundle.ACTIVE && bundle.getState() != Bundle.STARTING) {
+ try {
+ bundle.start(Bundle.START_TRANSIENT);
+ } catch (BundleException e) {
+ WizardPlugin.getInstance().logException("Unable to activate bundle project containing extension " + extensionPointID + " for language " + langName, e);
+ }
+ }
+ return bundle;
+ } catch (BundleException e) {
+ WizardPlugin.getInstance().logException("Unable to install bundle project containing extension " + extensionPointID + " for language " + langName, e);
+ } catch (MalformedURLException e) {
+ WizardPlugin.getInstance().logException("Unable to form install URL for bundle project containing extension " + extensionPointID + " for language " + langName, e);
+ }
+ }
+ return null;
+ }
+
+ public static void deactivateWorkspaceBundle(Bundle bundle) {
+ try {
+ if (bundle != null) {
+ bundle.uninstall();
+ }
+ } catch (BundleException e) {
+ WizardPlugin.getInstance().logException("Unable to deactivate bundle " + bundle.getBundleId(), e);
+ }
+ }
+
+ public static Bundle activateWorkspaceBundleForLanguage(String langName) {
+ return activateWorkspaceBundleForExtension(langName, ServiceFactory.LANGUAGE_DESCRIPTION_QUALIFIED_POINT_ID);
+ }
+}
Property changes on: trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/utils/DynamicBundleUtils.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/utils/ExtensionPointUtils.java
===================================================================
--- trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/utils/ExtensionPointUtils.java 2010-11-19 17:44:37 UTC (rev 22812)
+++ trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/utils/ExtensionPointUtils.java 2010-11-19 17:48:44 UTC (rev 22813)
@@ -18,9 +18,13 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.imp.WizardPlugin;
+import org.eclipse.imp.core.ErrorHandler;
+import org.eclipse.imp.language.ServiceFactory;
import org.eclipse.imp.wizards.ExtensionEnabler;
+import org.eclipse.imp.wizards.IMPWizardPage;
import org.eclipse.jdt.core.IJavaModel;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
@@ -28,6 +32,7 @@
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.pde.core.plugin.IExtensions;
import org.eclipse.pde.core.plugin.IPluginAttribute;
+import org.eclipse.pde.core.plugin.IPluginElement;
import org.eclipse.pde.core.plugin.IPluginExtension;
import org.eclipse.pde.core.plugin.IPluginModel;
import org.eclipse.pde.core.plugin.IPluginModelBase;
@@ -233,4 +238,134 @@
return result;
}
+
+ public static IProject findProjectForLanguage(String langName) {
+ IProject[] allProjects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ String lowerLangName= langName.toLowerCase();
+
+ for(IProject proj: allProjects) {
+ String projLangName= ExtensionPointUtils.discoverLanguageForProject(proj);
+ if (projLangName != null && projLangName.toLowerCase().equals(lowerLangName)) {
+ return proj;
+ }
+ }
+ return null;
+ }
+
+ public static IProject findProjectForLanguageExtension(String langName, String extensionPointID) {
+ IProject[] allProjects= ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ String lowerLangName= langName.toLowerCase();
+
+ for(IProject proj: allProjects) {
+ if (ExtensionPointUtils.projectHasLanguageExtension(proj, lowerLangName, extensionPointID)) {
+ return proj;
+ }
+ }
+ return null;
+ }
+
+ public static String getLanguageID(IPluginExtension extension) {
+ IPluginObject[] children= extension.getChildren();
+
+ for(int j= 0; j < children.length; j++) {
+ IPluginElement childElt= (IPluginElement) children[j];
+ IPluginAttribute langAttr= childElt.getAttribute("language");
+ if (langAttr != null) {
+ try {
+ return langAttr.getValue();
+ } catch (Exception e) {
+ ErrorHandler.reportError("Exception getting language attribute value; returning", e);
+ }
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static String getLanguageIDFromDescriptor(IPluginExtension extension) {
+ IPluginObject[] children= extension.getChildren();
+
+ for(int j= 0; j < children.length; j++) {
+ if (children[j].getName().equals("language")) {
+ try {
+ return ((IPluginElement) children[j]).getAttribute("language").getValue();
+ } catch (Exception e) {
+ ErrorHandler.reportError("Exception getting language attribute value; returning", e);
+ }
+ return null;
+ }
+ }
+ return null;
+ }
+
+ public static String discoverLanguageForProject(IProject project) {
+ IPluginModelBase pluginModel= IMPWizardPage.getPluginModel(project.getName());
+
+ if (pluginModel != null) {
+ // SMS 26 Jul 2007
+ // Load the extensions model in detail, using the adapted IMP representation,
+ // to assure that the children of model elements are represented
+ try {
+ ExtensionEnabler.loadImpExtensionsModel((IPluginModel) pluginModel, project);
+ } catch (CoreException e) {
+ // WizardPlugin.getInstance().logException("WizardUtilities.discoverLanguageForProject(): exception loading extensions model", e);
+ } catch (ClassCastException e) {
+ WizardPlugin.getInstance().logException("exception while loading extensions model", e);
+ }
+
+ IPluginExtension[] extensions= pluginModel.getExtensions().getExtensions();
+
+ // Prefer the language descriptor, if it exists
+ for(int i= 0; i < extensions.length; i++) {
+ IPluginExtension extension= extensions[i];
+ if (extension.getPoint().equals(ServiceFactory.LANGUAGE_DESCRIPTION_QUALIFIED_POINT_ID)) {
+ String langID= getLanguageIDFromDescriptor(extension);
+ if (langID != null) {
+ return langID;
+ }
+ }
+ }
+ // No language descriptor; take the language ID from any of the IMP extensions
+ for(int i= 0; i < extensions.length; i++) {
+ IPluginExtension extension= extensions[i];
+ String pointID= extension.getPoint();
+ if (ServiceFactory.ALL_SERVICES.contains(pointID)) {
+ String langID= getLanguageID(extension);
+ if (langID != null) {
+ return langID;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public static boolean projectHasLanguageExtension(IProject project, String langName, String extensionPointID) {
+ IPluginModelBase pluginModel= IMPWizardPage.getPluginModel(project.getName()); // TODO getPluginModel() probably belongs on ExtensionPointUtils
+
+ if (pluginModel != null) {
+ try {
+ ExtensionEnabler.loadImpExtensionsModel((IPluginModel) pluginModel, project);
+ } catch (CoreException e) {
+ // WizardPlugin.getInstance().logException("WizardUtilities.discoverLanguageForProject(): exception loading extensions model", e);
+ } catch (ClassCastException e) {
+ WizardPlugin.getInstance().logException("exception while loading extensions model", e);
+ }
+
+ IPluginExtension[] extensions= pluginModel.getExtensions().getExtensions();
+
+ for(int i= 0; i < extensions.length; i++) {
+ IPluginExtension extension= extensions[i];
+ String pointID= extension.getPoint();
+ if (pointID.equals(extensionPointID)) {
+ String langID= getLanguageID(extension);
+
+ if (langID != null && langID.equals(langName)) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
}
Modified: trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/ExtensionEnabler.java
===================================================================
--- trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/ExtensionEnabler.java 2010-11-19 17:44:37 UTC (rev 22812)
+++ trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/ExtensionEnabler.java 2010-11-19 17:48:44 UTC (rev 22813)
@@ -575,6 +575,7 @@
// Hook the extensions model into the bundle plugin model base
IBundlePluginModelBase bpmb= (IBundlePluginModelBase) pluginModel;
+
extensions.setBundleModel(bpmb);
bpmb.setExtensionsModel(extensions);
return extensions;
Modified: trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/IMPWizardPage.java
===================================================================
--- trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/IMPWizardPage.java 2010-11-19 17:44:37 UTC (rev 22812)
+++ trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/IMPWizardPage.java 2010-11-19 17:48:44 UTC (rev 22813)
@@ -29,6 +29,7 @@
import org.eclipse.imp.ui.dialogs.providers.LabelProviderForProjects;
import org.eclipse.imp.ui.dialogs.validators.SelectionValidatorForIDEProjects;
import org.eclipse.imp.ui.dialogs.validators.SelectionValidatorForPluginProjects;
+import org.eclipse.imp.utils.ExtensionPointUtils;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
@@ -494,7 +495,7 @@
// System.out.println("IMPWIzardPage.discoverProjectLanguage(): updated fProject == "
// + fProject.getName());
}
- String languageName= WizardUtilities.discoverLanguageForProject(fProject);
+ String languageName= ExtensionPointUtils.discoverLanguageForProject(fProject);
if (languageName != null) {
fLanguageText.setText(languageName);
}
@@ -612,7 +613,7 @@
return null;
}
- protected static IPluginModelBase getPluginModel(String projectName) {
+ public static IPluginModelBase getPluginModel(String projectName) {
try {
if (projectName == null)
return null;
@@ -1116,7 +1117,7 @@
if (fProject == null) {
fProject= ResourcesPlugin.getWorkspace().getRoot().getProject(fProjectText.getText());
}
- String langName= WizardUtilities.discoverLanguageForProject(fProject);
+ String langName= ExtensionPointUtils.discoverLanguageForProject(fProject);
if (langName != null) {
fLanguageText.setEnabled(false);
}
Modified: trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/NewBuilder.java
===================================================================
--- trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/NewBuilder.java 2010-11-19 17:44:37 UTC (rev 22812)
+++ trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/NewBuilder.java 2010-11-19 17:48:44 UTC (rev 22813)
@@ -21,7 +21,6 @@
import java.util.Map;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
@@ -217,7 +216,4 @@
}
return true;
}
-
-
-
-}
\ No newline at end of file
+}
Modified: trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/NewFormattingSpecification.java
===================================================================
--- trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/NewFormattingSpecification.java 2010-11-19 17:44:37 UTC (rev 22812)
+++ trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/NewFormattingSpecification.java 2010-11-19 17:48:44 UTC (rev 22813)
@@ -7,7 +7,6 @@
*
* Contributors:
* Robert Fuhrer (rfuhrer@xxxxxxxxxxxxxx) - initial API and implementation
-
*******************************************************************************/
package org.eclipse.imp.wizards;
@@ -22,19 +21,8 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.imp.WizardPlugin;
import org.eclipse.imp.runtime.RuntimePlugin;
-/*******************************************************************************
-* Copyright (c) 2008 IBM Corporation.
-* All rights reserved. This program and the accompanying materials
-* are made available under the terms of the Eclipse Public License v1.0
-* which accompanies this distribution, and is available at
-* http://www.eclipse.org/legal/epl-v10.html
-*
-* Contributors:
-* Robert Fuhrer (rfuhrer@xxxxxxxxxxxxxx) - initial API and implementation
-*******************************************************************************/
-
-
+// TODO Move this wizard to the formatting plugin
public class NewFormattingSpecification extends ExtensionPointWizard {
private String fSpecFilename;
@@ -43,29 +31,30 @@
}
protected List<String> getPluginDependencies() {
- return Arrays.asList(new String[] {
- "org.eclipse.core.runtime",
- "org.eclipse.core.resources",
- "org.eclipse.imp.runtime",
+ return Arrays.asList(new String[] {
+ "org.eclipse.core.runtime",
+ "org.eclipse.core.resources",
+ "org.eclipse.imp.runtime",
"org.eclipse.imp.formatting" });
}
-
+
private class NewFormattingSpecificationWizardPage extends ExtensionPointWizardPage {
public NewFormattingSpecificationWizardPage(ExtensionPointWizard owner) {
- super(owner, WizardPlugin.kPluginID, "formattingSpecification");
+ // TODO Replace the literal plugin ID below with a ref to the appropriate activator constant field
+ super(owner, "org.eclipse.imp.formatting", "formattingSpecification");
}
}
-
+
@Override
public boolean canFinish() {
if (!fileFieldIsValid()) {
- pages[0].setErrorMessage("File name should end with \".fsp\"");
+ pages[0].setErrorMessage("File name must end with \".fsp\"");
return false;
}
-
+
return super.canFinish();
}
-
+
protected void collectCodeParms() {
fSpecFilename = pages[0].getValue("file");
fLanguageName = pages[0].getValue("language");
@@ -75,22 +64,21 @@
@Override
protected void generateCodeStubs(IProgressMonitor mon) throws CoreException {
Map<String,String> subs= getStandardSubstitutions();
-
+
WizardUtilities.createFileFromTemplate(
- fSpecFilename, WizardPlugin.kPluginID, "formatter.fsp", "", getProjectSourceLocation(fProject),
+ fSpecFilename, WizardPlugin.kPluginID /*"org.eclipse.imp.formatting.metatooling"*/, "formatter.fsp", "", getProjectSourceLocation(fProject),
subs, fProject, new NullProgressMonitor());
-
- ExtensionEnabler.
- enable(
- fProject, RuntimePlugin.IMP_RUNTIME, "formatter",
+
+ ExtensionEnabler.enable(
+ fProject, RuntimePlugin.IMP_RUNTIME, "formatter",
new String[][] {
{ "extension:id", fProject.getName() + ".formatter" },
{ "extension:name", fLanguageName + " Formatter" },
{ "formatter:class", "org.eclipse.imp.formatting.SourceFormatter" },
- { "formatter:language", fLanguageName }
- }
- , false,
- getPluginDependencies(),
+ { "formatter:language", fLanguageName }
+ },
+ false,
+ getPluginDependencies(),
new NullProgressMonitor());
}
@@ -104,5 +92,4 @@
final String text = pages[0].getField("file").fText.getText();
return text == null || text.length() == 0 || text.endsWith(".fsp");
}
-
-}
\ No newline at end of file
+}
Modified: trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/WizardUtilities.java
===================================================================
--- trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/WizardUtilities.java 2010-11-19 17:44:37 UTC (rev 22812)
+++ trunk/org.eclipse.imp.metatooling/src/org/eclipse/imp/wizards/WizardUtilities.java 2010-11-19 17:48:44 UTC (rev 22813)
@@ -15,6 +15,7 @@
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Iterator;
@@ -37,7 +38,6 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.imp.WizardPlugin;
import org.eclipse.imp.core.ErrorHandler;
-import org.eclipse.imp.language.ServiceFactory;
import org.eclipse.imp.utils.StreamUtils;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
@@ -46,16 +46,12 @@
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.internal.core.JavaModel;
import org.eclipse.jdt.internal.core.JavaModelManager;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextSelection;
-import org.eclipse.pde.core.plugin.IPluginAttribute;
-import org.eclipse.pde.core.plugin.IPluginElement;
-import org.eclipse.pde.core.plugin.IPluginExtension;
-import org.eclipse.pde.core.plugin.IPluginModel;
-import org.eclipse.pde.core.plugin.IPluginModelBase;
-import org.eclipse.pde.core.plugin.IPluginObject;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.TextEdit;
@@ -205,10 +201,7 @@
* substituted from the replacements
* @throws CoreException
*/
- public static String createFileContentsFromTemplate(
- String templateName,
- Map<String,String> replacements,
- IProgressMonitor monitor) {
+ public static String createFileContentsFromTemplate(String templateName, Map<String,String> replacements, IProgressMonitor monitor) {
return createFileContentsFromTemplate(templateName, getTemplateBundleID(), replacements, monitor);
}
@@ -350,18 +343,13 @@
return file;
}
-
-
-
+
/**
* Like createFileFromTemplate, but does not attempt to perform any meta-variable substitutions.
* Useful for binary files (e.g. images) that are to be copied as-is to the user's workspace.
* The name of the source file is used for that of the target file.
*/
- protected static IFile copyLiteralFile(
- String fileName, String folder, IProject project, IProgressMonitor monitor)
- throws CoreException
- {
+ protected static IFile copyLiteralFile(String fileName, String folder, IProject project, IProgressMonitor monitor) throws CoreException {
monitor.setTaskName("Creating " + fileName);
final IFile file= project.getFile(new Path(folder + "/" + fileName));
@@ -376,17 +364,13 @@
// monitor.worked(1);
return file;
}
-
-
+
/**
* Like createFileFromTemplate, but does not attempt to perform any meta-variable substitutions.
* Useful for binary files (e.g. images) that are to be copied as-is to the user's workspace.
* This version allows the name of the target file to be specified independently of the source file.
*/
- protected static IFile copyLiteralFile(
- String inFileName, String outFileName, String folder, IProject project, IProgressMonitor monitor)
- throws CoreException
- {
+ protected static IFile copyLiteralFile(String inFileName, String outFileName, String folder, IProject project, IProgressMonitor monitor) throws CoreException {
monitor.setTaskName("Creating " + outFileName + " as a copy of " + inFileName);
final IFile file= project.getFile(new Path(folder + "/" + outFileName));
@@ -401,14 +385,15 @@
// monitor.worked(1);
return file;
}
-
-
+
public static void addBuilder(IProject project, String id) throws CoreException {
IProjectDescription desc= project.getDescription();
ICommand[] commands= desc.getBuildSpec();
- for(int i= 0; i < commands.length; ++i)
- if (commands[i].getBuilderName().equals(id))
- return;
+ for(int i= 0; i < commands.length; ++i) {
+ if (commands[i].getBuilderName().equals(id)) {
+ return;
+ }
+ }
//add builder to project
ICommand command= desc.newCommand();
command.setBuilderName(id);
@@ -421,26 +406,22 @@
}
public static void enableBuilders(IProgressMonitor monitor, final IProject project, final String[] builderIDs) {
- monitor.setTaskName("Enabling builders...");
- Job job= new WorkspaceJob("Enabling builders...") {
- public IStatus runInWorkspace(IProgressMonitor monitor) {
- try {
- for(int i= 0; i < builderIDs.length; i++) {
- addBuilder(project, builderIDs[i]);
- }
- } catch (Throwable e) {
- e.printStackTrace();
- }
- return Status.OK_STATUS;
- }
- };
- job.schedule();
+ monitor.setTaskName("Enabling builders...");
+ Job job= new WorkspaceJob("Enabling builders...") {
+ public IStatus runInWorkspace(IProgressMonitor monitor) {
+ try {
+ for(int i= 0; i < builderIDs.length; i++) {
+ addBuilder(project, builderIDs[i]);
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.schedule();
}
-
-
-// public void init(IWorkbench workbench, IStructuredSelection selection) {}
-
/**
* Opens the given file in the appropriate editor for editing.<br>
* If the file contains a comment "// START_HERE", the cursor will
@@ -473,8 +454,7 @@
});
monitor.worked(1);
}
-
-
+
public static void createSubFolders(String folder, IProject project, IProgressMonitor monitor) throws CoreException {
String[] subFolderNames= folder.split("[\\" + File.separator + "\\/]");
String subFolderStr= "";
@@ -489,10 +469,8 @@
subFolderStr= childPath;
}
}
-
-
- public static byte[] getTemplateFileContents(String filePath)
- {
+
+ public static byte[] getTemplateFileContents(String filePath) {
try {
String path= null;
@@ -526,12 +504,10 @@
}
}
-
/**
* @return the path to the standard IMP template folder, in platform-specific format
*/
- public static String getStandardTemplateFolderLocation()
- {
+ public static String getStandardTemplateFolderLocation() {
try {
// Initially, perform path computations in platform-independent format
Bundle bundle= Platform.getBundle(getTemplateBundleID());
@@ -550,7 +526,7 @@
return null;
}
}
-
+
public static String getStandardTemplateFileName(IMPWizard wizard, String componentID) {
if (wizard instanceof NewTokenColorer) {
return "colorer_simple.java";
@@ -608,11 +584,6 @@
return null;
}
-
-
-
-
-
/**
* Gets the contents of a named template file from the "templates" folder
* of a plugin with a given plugin id. Created for use with the version of
@@ -624,7 +595,7 @@
* are to be returned
* @return The contents of the named template file
*/
- public static byte[] getTemplateFileContents(String templateBundleId, String fileName) {
+ public static byte[] getTemplateFileContents(String templateBundleId, final String fileName) {
try {
Bundle bundle= Platform.getBundle(templateBundleId);
URL templateURL= FileLocator.find(bundle, new Path("/templates/" + fileName), null);
@@ -655,10 +626,18 @@
is.close();
fis.close();
return bytes;
+ } catch (FileNotFoundException e) {
+ final Display display= PlatformUI.getWorkbench().getDisplay();
+ display.asyncExec(new Runnable() {
+ public void run() {
+ MessageDialog.openError(display.getActiveShell(), "Unable to find code template", "Error when attempting to locate code template " + fileName);
+ }
+ });
} catch (Exception e) {
+ MessageDialog.openError(null, "Unable to find code template", "Error when attempting to locate code template " + fileName);
e.printStackTrace();
- return ("// missing template file: " + fileName).getBytes();
}
+ return ("// missing template file: " + fileName).getBytes();
}
@@ -702,81 +681,4 @@
contents= l_doc.get();
return contents;
}
-
-
- public static String discoverLanguageForProject(IProject project) {
- IPluginModelBase pluginModel= IMPWizardPage.getPluginModel(project.getName());
-
- if (pluginModel != null) {
- // SMS 26 Jul 2007
- // Load the extensions model in detail, using the adapted IMP representation,
- // to assure that the children of model elements are represented
- try {
- ExtensionEnabler.loadImpExtensionsModel((IPluginModel) pluginModel, project);
- } catch (CoreException e) {
- // WizardPlugin.getInstance().logException("WizardUtilities.discoverLanguageForProject(): exception loading extensions model", e);
- } catch (ClassCastException e) {
- WizardPlugin.getInstance().logException("exception while loading extensions model", e);
- }
-
- IPluginExtension[] extensions= pluginModel.getExtensions().getExtensions();
-
- // Prefer the language descriptor, if it exists
- for(int i= 0; i < extensions.length; i++) {
- IPluginExtension extension= extensions[i];
- if (extension.getPoint().equals(ServiceFactory.LANGUAGE_DESCRIPTION_QUALIFIED_POINT_ID)) {
- String langID= getLanguageIDFromDescriptor(extension);
- if (langID != null) {
- return langID;
- }
- }
- }
- // No language descriptor; take the language ID from any of the IMP extensions
- for(int i= 0; i < extensions.length; i++) {
- IPluginExtension extension= extensions[i];
- String pointID= extension.getPoint();
- if (ServiceFactory.ALL_SERVICES.contains(pointID)) {
- String langID= getLanguageID(extension);
- if (langID != null) {
- return langID;
- }
- }
- }
- }
- return null;
- }
-
- private static String getLanguageIDFromDescriptor(IPluginExtension extension) {
- IPluginObject[] children= extension.getChildren();
-
- for(int j= 0; j < children.length; j++) {
- if (children[j].getName().equals("language")) {
- try {
- return ((IPluginElement) children[j]).getAttribute("language").getValue();
- } catch (Exception e) {
- ErrorHandler.reportError("Exception getting language attribute value; returning", e);
- }
- return null;
- }
- }
- return null;
- }
-
- private static String getLanguageID(IPluginExtension extension) {
- IPluginObject[] children= extension.getChildren();
-
- for(int j= 0; j < children.length; j++) {
- IPluginElement childElt= (IPluginElement) children[j];
- IPluginAttribute langAttr= childElt.getAttribute("language");
- if (langAttr != null) {
- try {
- return langAttr.getValue();
- } catch (Exception e) {
- ErrorHandler.reportError("Exception getting language attribute value; returning", e);
- }
- return null;
- }
- }
- return null;
- }
}