embed the default return value into the provider
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/EffectivePomEditorProvider.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/EffectivePomEditorProvider.java
index 617f558..2f96e93 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/EffectivePomEditorProvider.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/EffectivePomEditorProvider.java
@@ -1,7 +1,16 @@
package org.eclipse.m2e.editor.pom;
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.MavenProject;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.m2e.core.actions.OpenPomAction.MavenStorageEditorInput;
+import org.eclipse.m2e.core.core.MavenLogger;
import org.eclipse.m2e.editor.MavenEditorPlugin;
+import org.eclipse.m2e.editor.internal.Messages;
import org.eclipse.ui.IEditorInput;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.osgi.framework.BundleContext;
@@ -15,31 +24,30 @@
public static IEditorInput createEditorInput(MavenProject project, String name) {
BundleContext context = MavenEditorPlugin.getDefault().getBundle().getBundleContext();
if (context == null) {
- return null;
+ return createDefaultEditorInput(project, name);
}
ServiceReference ref = context.getServiceReference(Implementation.class.getName());
- if (ref == null) {
- return null;
- }
- Implementation service = (Implementation)context.getService(ref);
- if (service != null) {
- try {
- return service.createEditorInput(project, name);
- } finally {
- context.ungetService(ref);
+ if(ref != null) {
+ Implementation service = (Implementation) context.getService(ref);
+ if(service != null) {
+ try {
+ return service.createEditorInput(project, name);
+ } finally {
+ context.ungetService(ref);
+ }
}
}
- return null;
+ return createDefaultEditorInput(project, name);
}
public static StructuredTextEditor createTextEditor() {
BundleContext context = MavenEditorPlugin.getDefault().getBundle().getBundleContext();
if (context == null) {
- return null;
+ return createDefaultEditor();
}
ServiceReference ref = context.getServiceReference(Implementation.class.getName());
if (ref == null) {
- return null;
+ return createDefaultEditor();
}
Implementation service = (Implementation)context.getService(ref);
if (service != null) {
@@ -49,8 +57,26 @@
context.ungetService(ref);
}
}
- return null;
- }
+ return createDefaultEditor();
+ }
+
+ private static StructuredTextEditor createDefaultEditor() {
+ return new StructuredTextEditor();
+ }
+
+ private static IEditorInput createDefaultEditorInput(MavenProject mavenProject, String name) {
+ StringWriter sw = new StringWriter();
+ byte[] bytes = new byte[0];
+ try {
+ new MavenXpp3Writer().write(sw, mavenProject.getModel());
+ String content = sw.toString();
+ bytes = content.getBytes("UTF-8");
+ } catch (IOException ie) {
+ MavenLogger.log(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, -1,
+ Messages.MavenPomEditor_error_failed_effective, ie));
+ }
+ return new MavenStorageEditorInput(name, name, null, bytes); //$NON-NLS-1$
+ }
diff --git a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java
index a4120e0..273c451 100644
--- a/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java
+++ b/org.eclipse.m2e.editor/src/org/eclipse/m2e/editor/pom/MavenPomEditor.java
@@ -534,18 +534,7 @@
showEffectivePomError(name);
return Status.CANCEL_STATUS;
}
- IEditorInput editorInput = EffectivePomEditorProvider.createEditorInput(mavenProject, name);
- if (editorInput == null) {
- try{
- StringWriter sw = new StringWriter();
- new MavenXpp3Writer().write(sw, mavenProject.getModel());
- final String content = sw.toString();
- editorInput = new MavenStorageEditorInput(name, name, null, content.getBytes("UTF-8")); //$NON-NLS-1$
- }catch(IOException ie){
- MavenLogger.log(new Status(IStatus.ERROR, MavenEditorPlugin.PLUGIN_ID, -1, Messages.MavenPomEditor_error_failed_effective, ie));
- }
- }
- final IEditorInput fEditorInput = editorInput;
+ final IEditorInput fEditorInput = EffectivePomEditorProvider.createEditorInput(mavenProject, name);;
Display.getDefault().asyncExec(new Runnable(){
public void run() {
effectivePomSourcePage.setInput(fEditorInput);
@@ -680,9 +669,6 @@
sourcePage.setEditorPart(this);
//the page for showing the effective POM
effectivePomSourcePage = EffectivePomEditorProvider.createTextEditor();
- if (effectivePomSourcePage == null) {
- effectivePomSourcePage = new StructuredTextEditor();
- }
effectivePomSourcePage.setEditorPart(this);
try {
int dex = addPage(effectivePomSourcePage, getEditorInput());