Default contribution check for PlatformDetailsSectionProcessor

-Remove trailing newline
-add null safety

Bug: 507041
Change-Id: Icd5e3101d11a39b6a5d7e27859c0b317ee1848f5
Signed-off-by: Daniel Haftstein <haftsteind@gmail.com>
diff --git a/bundles/org.eclipse.epp.logging.aeri.ide/src/org/eclipse/epp/internal/logging/aeri/ide/processors/PlatformDetailsSectionProcessor.java b/bundles/org.eclipse.epp.logging.aeri.ide/src/org/eclipse/epp/internal/logging/aeri/ide/processors/PlatformDetailsSectionProcessor.java
index 454c597..f8958d0 100644
--- a/bundles/org.eclipse.epp.logging.aeri.ide/src/org/eclipse/epp/internal/logging/aeri/ide/processors/PlatformDetailsSectionProcessor.java
+++ b/bundles/org.eclipse.epp.logging.aeri.ide/src/org/eclipse/epp/internal/logging/aeri/ide/processors/PlatformDetailsSectionProcessor.java
@@ -7,7 +7,8 @@
  */
 package org.eclipse.epp.internal.logging.aeri.ide.processors;
 
-import org.apache.commons.lang3.StringUtils;
+import static org.apache.commons.lang3.StringUtils.defaultString;
+
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.e4.core.contexts.IEclipseContext;
 import org.eclipse.epp.internal.logging.aeri.ide.IProcessorDescriptor;
@@ -26,7 +27,9 @@
 
     @Override
     public boolean canContribute(IStatus status) {
-        return !StringUtils.isEmpty(ConfigurationInfo.getConfiguration("Platform Details"));
+        // the contribution may be an empty string but pre-fetching the configuration is expensive
+        // and may cause ui freezes (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=507041)
+        return true;
     }
 
     @Override
@@ -37,7 +40,7 @@
     @Override
     @VisibleForTesting
     protected String doAnalyze() {
-        String configuration = ConfigurationInfo.getConfiguration("Platform Details");
+        String configuration = getPlatformDetailsConfiguration();
         int sectionStart = configuration.indexOf(sectionTitle);
         if (sectionStart == -1) {
             return "";
@@ -54,7 +57,11 @@
                 sectionEnd = configuration.length();
             }
         }
-        return configuration.substring(sectionStart, sectionEnd);
+        return configuration.substring(sectionStart, sectionEnd).trim();
+    }
+
+    private String getPlatformDetailsConfiguration() {
+        return defaultString(ConfigurationInfo.getConfiguration("Platform Details"));
     }
 
 }
diff --git a/tests/org.eclipse.epp.logging.aeri.ide.tests/src/org/eclipse/epp/internal/logging/aeri/ide/processors/PlatformDetailsSectionProcessorsTest.java b/tests/org.eclipse.epp.logging.aeri.ide.tests/src/org/eclipse/epp/internal/logging/aeri/ide/processors/PlatformDetailsSectionProcessorsTest.java
index 71ecd3c..5c8c987 100644
--- a/tests/org.eclipse.epp.logging.aeri.ide.tests/src/org/eclipse/epp/internal/logging/aeri/ide/processors/PlatformDetailsSectionProcessorsTest.java
+++ b/tests/org.eclipse.epp.logging.aeri.ide.tests/src/org/eclipse/epp/internal/logging/aeri/ide/processors/PlatformDetailsSectionProcessorsTest.java
@@ -7,13 +7,14 @@
  */
 package org.eclipse.epp.internal.logging.aeri.ide.processors;
 
-import static org.hamcrest.Matchers.isEmptyString;
-import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.is;
 import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
 
 import java.util.Arrays;
 import java.util.Collection;
 
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.epp.internal.logging.aeri.ide.IProcessorDescriptor;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -40,13 +41,13 @@
     public PlatformDetailsSectionProcessor processor;
 
     @Test
-    public void testNotEmpty() {
+    public void testCanContribute() {
         // if the test fails, a section is probably renamed in the configuration section
-        assertThat(processor.doAnalyze(), not(isEmptyString()));
+        assertThat(processor.canContribute(mock(IStatus.class)), is(true));
     }
 
     private static IProcessorDescriptor mockDescriptor(String directive) {
-        IProcessorDescriptor descriptor = Mockito.mock(IProcessorDescriptor.class);
+        IProcessorDescriptor descriptor = mock(IProcessorDescriptor.class);
         Mockito.when(descriptor.getDescription()).thenReturn(directive);
         return descriptor;
     }