Handle optional dependencies in babel core and editor componentd
diff --git a/org.eclipse.babel.core/src/org/eclipse/babel/core/message/strategy/PropertiesFileGroupStrategy.java b/org.eclipse.babel.core/src/org/eclipse/babel/core/message/strategy/PropertiesFileGroupStrategy.java index 5905295..51657c6 100644 --- a/org.eclipse.babel.core/src/org/eclipse/babel/core/message/strategy/PropertiesFileGroupStrategy.java +++ b/org.eclipse.babel.core/src/org/eclipse/babel/core/message/strategy/PropertiesFileGroupStrategy.java
@@ -35,7 +35,7 @@ * MessagesBundleGroup strategy for standard Java properties file structure. * That is, all *.properties files of the same base name within the same * directory. This implementation works on files outside the Eclipse workspace. - * + * * @author Pascal Essiembre */ public class PropertiesFileGroupStrategy implements @@ -59,7 +59,7 @@ /** * Constructor. - * + * * @param file * file from which to derive the group */ @@ -130,7 +130,7 @@ /** * Creates a resource bundle for an existing resource. - * + * * @param locale * locale for which to create a bundle * @param resource @@ -152,14 +152,20 @@ } public String createMessagesBundleId() { - String path = file.getAbsolutePath(); - int index = path.indexOf("src"); - String pathBeforeSrc = path.substring(0, index - 1); - int lastIndexOf = pathBeforeSrc.lastIndexOf(File.separatorChar); - String projectName = path.substring(lastIndexOf + 1, index - 1); - String relativeFilePath = path.substring(index, path.length()); + final String path = file.getAbsolutePath(); + final int index = path.indexOf("src"); + final String pathBeforeSrc = path.substring(0, Math.max(index - 1, 0)); + final int lastIndexOf = pathBeforeSrc.lastIndexOf(File.separatorChar); + final String relativeFilePath = path.substring(Math.max(index, 0), + Math.max(path.length(), 0)); + String projectName = path.substring(Math.max(lastIndexOf + 1, 0), + Math.max(index - 1, 0)); - IFile f = ResourcesPlugin.getWorkspace().getRoot() + if (projectName.equals("")) { + projectName = "no_project"; + } + + final IFile f = ResourcesPlugin.getWorkspace().getRoot() .getProject(projectName).getFile(relativeFilePath); return NameUtils.getResourceBundleId(f);
diff --git a/org.eclipse.babel.core/src/org/eclipse/babel/core/util/NameUtils.java b/org.eclipse.babel.core/src/org/eclipse/babel/core/util/NameUtils.java index b1beb90..7637e36 100644 --- a/org.eclipse.babel.core/src/org/eclipse/babel/core/util/NameUtils.java +++ b/org.eclipse.babel.core/src/org/eclipse/babel/core/util/NameUtils.java
@@ -4,7 +4,7 @@ * 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: * Alexej Strelzow - initial API and implementation ******************************************************************************/ @@ -19,7 +19,7 @@ /** * Contains methods, which return names/IDs or Objects by name. - * + * * @author Alexej Strelzow */ public class NameUtils { @@ -27,11 +27,15 @@ public static String getResourceBundleId(IResource resource) { String packageFragment = ""; - IJavaElement propertyFile = JavaCore.create(resource.getParent()); - if (propertyFile != null && propertyFile instanceof IPackageFragment) - packageFragment = ((IPackageFragment) propertyFile) - .getElementName(); - + try { + IJavaElement propertyFile = JavaCore.create(resource.getParent()); + if (propertyFile != null + && propertyFile instanceof IPackageFragment) + packageFragment = ((IPackageFragment) propertyFile) + .getElementName(); + } catch (NoClassDefFoundError e) { + // do nothing + } return (packageFragment.length() > 0 ? packageFragment + "." : "") + getResourceBundleName(resource); }
diff --git a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/bundle/DefaultBundleGroupStrategy.java b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/bundle/DefaultBundleGroupStrategy.java index 8bf0259..3113b29 100644 --- a/org.eclipse.babel.editor/src/org/eclipse/babel/editor/bundle/DefaultBundleGroupStrategy.java +++ b/org.eclipse.babel.editor/src/org/eclipse/babel/editor/bundle/DefaultBundleGroupStrategy.java
@@ -46,7 +46,7 @@ /** * MessagesBundle group strategy for standard properties file structure. That * is, all *.properties files of the same base name within the same directory. - * + * * @author Pascal Essiembre */ public class DefaultBundleGroupStrategy implements IMessagesBundleGroupStrategy { @@ -69,7 +69,7 @@ /** * Constructor. - * + * * @param site * editor site * @param file @@ -107,11 +107,15 @@ public static String getResourceBundleId(IResource resource) { String packageFragment = ""; - IJavaElement propertyFile = JavaCore.create(resource.getParent()); - if (propertyFile != null && propertyFile instanceof IPackageFragment) - packageFragment = ((IPackageFragment) propertyFile) - .getElementName(); - + try { + IJavaElement propertyFile = JavaCore.create(resource.getParent()); + if (propertyFile != null + && propertyFile instanceof IPackageFragment) + packageFragment = ((IPackageFragment) propertyFile) + .getElementName(); + } catch (NoClassDefFoundError e) { + // do nothing + } return (packageFragment.length() > 0 ? packageFragment + "." : "") + getResourceBundleName(resource); } @@ -167,7 +171,7 @@ /* * (non-Javadoc) - * + * * @see * org.eclipse.babel.core.bundle.IBundleGroupStrategy#createBundle(java. * util.Locale) @@ -198,7 +202,7 @@ /** * Creates a resource bundle for an existing resource. - * + * * @param locale * locale for which to create a bundle * @param resource @@ -236,7 +240,7 @@ /** * Creates an Eclipse editor. - * + * * @param site * @param resource * @param locale