Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

#1 Intellij IDEA 12 compatibility

  • Loading branch information...
commit 5978941a0c3ff786fca095a4edcc88826df3a469 1 parent 089b3ee
Stanley Shyiko authored
2  gradle.properties
View
@@ -1,2 +1,2 @@
idea.home=/home/oss/idea-IC
-build.number=1.0
+build.number=1.0.1
40 src/main/java/com/github/shyiko/native2asciiplug/Native2AsciiPlugProjectComponent.java
View
@@ -15,19 +15,28 @@
*/
package com.github.shyiko.native2asciiplug;
+import com.intellij.compiler.CompilerWorkspaceConfiguration;
+import com.intellij.openapi.compiler.*;
import com.intellij.openapi.compiler.Compiler;
-import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.components.ProjectComponent;
+import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
public class Native2AsciiPlugProjectComponent implements ProjectComponent {
+ private static final Logger logger = Logger.getInstance("#" + Native2AsciiPlugProjectComponent.class.getName());
+
private final CompilerManager compilerManager;
private final Compiler compiler;
+ private final Project project;
public Native2AsciiPlugProjectComponent(Project project, CompilerManager compilerManager) {
+ this.project = project;
this.compilerManager = compilerManager;
this.compiler = new Native2AsciiPlugCompiler(project);
}
@@ -42,10 +51,37 @@ public String getComponentName() {
}
public void projectOpened() {
- compilerManager.addCompiler(compiler);
+ if (isOutOfProcessBuildTurnedOn()) {
+ injectCompilerForOutOfProcessBuild();
+ } else {
+ compilerManager.addCompiler(compiler);
+ }
compilerManager.addCompilableFileType(StdFileTypes.PROPERTIES);
}
+ private boolean isOutOfProcessBuildTurnedOn() {
+ CompilerWorkspaceConfiguration configuration = CompilerWorkspaceConfiguration.getInstance(project);
+ try {
+ Method useOutOfProcessBuild = configuration.getClass().getMethod("useOutOfProcessBuild");
+ return (Boolean) useOutOfProcessBuild.invoke(configuration);
+ } catch (NoSuchMethodException e) {
+ // expected on IDEA releases less than 12
+ } catch (Exception e) {
+ logger.error("Failed to determine whether \"Use external build\" is turned on", e);
+ }
+ return false;
+ }
+
+ private void injectCompilerForOutOfProcessBuild() {
+ try {
+ Class<?> compilerAdapter = Class.forName("com.intellij.compiler.impl.FileProcessingCompilerAdapterTask");
+ Constructor<?> constructor = compilerAdapter.getConstructor(FileProcessingCompiler.class);
+ compilerManager.addAfterTask((CompileTask) constructor.newInstance(compiler));
+ } catch (Exception e) {
+ logger.error("Failed to inject compiler with \"Use external build\" being turned on", e);
+ }
+ }
+
public void projectClosed() {
compilerManager.removeCompilableFileType(StdFileTypes.PROPERTIES);
compilerManager.removeCompiler(compiler);
8 src/main/resources/META-INF/plugin.xml
View
@@ -4,11 +4,15 @@
Converts property files with native-encoded characters (characters which are non-Latin 1 and non-Unicode) to Unicode-encoded.
Processing is being done automatically during compilation phase.
]]></description>
- <version>1.0</version>
+ <version>1.0.1</version>
<vendor email="stanley.shyiko@gmail.com" url="https://github.com/shyiko/native2asciiplug">Stanley Shyiko</vendor>
<idea-version since-build="8000"/>
<change-notes><![CDATA[
- 1.0
+ 1.0.1
+ <ul>
+ <li>Intellij IDEA 12 compatibility</li>
+ </ul>
+ 1.0.0
<ul>
<li>Intellij IDEA 9+ support</li>
<li>Compatibility with Maven plugin</li>
Please sign in to comment.
Something went wrong with that request. Please try again.