Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions src/java/org/codehaus/testdox/intellij/IntelliJApiFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -34,24 +29,25 @@ 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);
}

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();
}
}