From 436f8b77bfff1ca45055883bcc70114dbd00ebf8 Mon Sep 17 00:00:00 2001 From: andreykudr Date: Tue, 23 Aug 2016 19:24:29 +0300 Subject: [PATCH] Update IntelliJApiFactory.java --- .../testdox/intellij/IntelliJApiFactory.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/java/org/codehaus/testdox/intellij/IntelliJApiFactory.java b/src/java/org/codehaus/testdox/intellij/IntelliJApiFactory.java index 6bbf03e..7cf583f 100644 --- a/src/java/org/codehaus/testdox/intellij/IntelliJApiFactory.java +++ b/src/java/org/codehaus/testdox/intellij/IntelliJApiFactory.java @@ -9,23 +9,18 @@ public class IntelliJApiFactory implements EditorApiFactory { private final MutablePicoContainer picoContainer; - private String ideaName; - private String buildNumber; private Class editorApiClass; + ApplicationInfo applicationInfo; + public IntelliJApiFactory(MutablePicoContainer picoContainer) { this.picoContainer = picoContainer; - - ApplicationInfo applicationInfo = ApplicationInfo.getInstance(); - ideaName = applicationInfo.getVersionName(); - buildNumber = applicationInfo.getBuild().asStringWithoutProductCode(); + applicationInfo = ApplicationInfo.getInstance(); try { - editorApiClass = Class.forName(getClassForIDEA(ideaName, Double.parseDouble(buildNumber))); - } catch (NumberFormatException e) { - throw newFactoryRuntimeException(ideaName, buildNumber, e); + editorApiClass = Class.forName(MAIA_API_CLASS_NAME); } catch (ClassNotFoundException e) { - throw newFactoryRuntimeException(ideaName, buildNumber, e); + throw newFactoryRuntimeException(getIdeaName(), getBuildNumber(), e); } } @@ -34,19 +29,12 @@ public EditorApi createEditorApi() { EditorApi editorApi = (EditorApi) picoContainer.getComponentInstance(EditorApi.class); if (editorApi == null) { - throw newFactoryRuntimeException(ideaName, buildNumber); + throw newFactoryRuntimeException(getIdeaName(), getBuildNumber()); } return editorApi; } - private String getClassForIDEA(String ideaName, double buildNumber) { - if (ideaName.toLowerCase().matches(".*maia.*") || buildNumber >= 90.116D) { - return MAIA_API_CLASS_NAME; - } - throw newFactoryRuntimeException(ideaName, String.valueOf(buildNumber)); - } - private RuntimeException newFactoryRuntimeException(String ideaName, String buildNumber) { return new RuntimeException("Could not load API connector for " + ideaName + " build #" + buildNumber); } @@ -54,4 +42,12 @@ private RuntimeException newFactoryRuntimeException(String ideaName, String buil private RuntimeException newFactoryRuntimeException(String ideaName, String buildNumber, Exception e) { return new RuntimeException("Could not load API connector for " + ideaName + " build #" + buildNumber, e); } + + public String getIdeaName() { + return applicationInfo.getVersionName(); + } + + public String getBuildNumber() { + return applicationInfo.getBuild().asString(); + } }