support configscript in groovy compilation (IDEA-103342)
authorpeter <peter@jetbrains.com>
Wed, 24 Jun 2015 17:34:22 +0000 (19:34 +0200)
committerpeter <peter@jetbrains.com>
Wed, 24 Jun 2015 17:41:15 +0000 (19:41 +0200)
plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/ForkedGroovyc.java
plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/InProcessGroovyc.java
plugins/groovy/jps-plugin/src/org/jetbrains/jps/incremental/groovy/JpsGroovySettings.java
plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/DependentGroovycRunner.java
plugins/groovy/rt/src/org/jetbrains/groovy/compiler/rt/GroovycRunner.java
plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfigurable.form
plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfigurable.java
plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfiguration.java
plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GroovyCompilerTest.groovy

index 694b9df8756eb977fdfa96e7c5b3fd39fc4156da..0cc76b796353671959295e54560437670b843bea 100644 (file)
@@ -18,6 +18,7 @@ package org.jetbrains.jps.incremental.groovy;
 import com.intellij.execution.process.BaseOSProcessHandler;
 import com.intellij.execution.process.ProcessHandler;
 import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.util.ArrayUtil;
 import com.intellij.util.Function;
 import com.intellij.util.SystemProperties;
@@ -76,8 +77,8 @@ class ForkedGroovyc implements GroovycFlavor {
     if ("false".equals(System.getProperty(GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY))) {
       vmParams.add("-D" + GroovyRtConstants.GROOVYC_ASM_RESOLVING_ONLY + "=false");
     }
-    String configScript = System.getProperty(GroovyRtConstants.GROOVYC_CONFIG_SCRIPT);
-    if (configScript != null) {
+    String configScript = settings.configScript;
+    if (StringUtil.isNotEmpty(configScript)) {
       vmParams.add("-D" + GroovyRtConstants.GROOVYC_CONFIG_SCRIPT + "=" + configScript);
     }
 
index 8696fa19500c3ab12bf98f1483452c27ce3cd42d..df2d2a58ac6f5333fe36841da8e4571ac22b183e 100644 (file)
@@ -144,8 +144,8 @@ class InProcessGroovyc implements GroovycFlavor {
     Thread.currentThread().setContextClassLoader(loader);
     try {
       Class<?> runnerClass = loader.loadClass("org.jetbrains.groovy.compiler.rt.GroovycRunner");
-      Method intMain = runnerClass.getDeclaredMethod("intMain2", boolean.class, boolean.class, boolean.class, String.class, Queue.class);
-      Integer exitCode = (Integer)intMain.invoke(null, settings.invokeDynamic, false, forStubs, tempFile.getPath(), mailbox);
+      Method intMain = runnerClass.getDeclaredMethod("intMain2", boolean.class, boolean.class, boolean.class, String.class, String.class, Queue.class);
+      Integer exitCode = (Integer)intMain.invoke(null, settings.invokeDynamic, false, forStubs, tempFile.getPath(), settings.configScript, mailbox);
       parser.notifyFinished(exitCode);
     }
     catch (Exception e) {
index 76e76cb7c440dfb89d3dbe363f5dd0e5c36585cc..ab135352a6325c7f197f0ecf890654ab5cd0fa32 100644 (file)
@@ -37,6 +37,7 @@ public class JpsGroovySettings extends JpsElementBase<JpsGroovySettings> {
   public static final boolean DEFAULT_INVOKE_DYNAMIC = false;
   public static final boolean DEFAULT_TRANSFORMS_OK = false;
 
+  public String configScript = "";
   public String heapSize = DEFAULT_HEAP_SIZE;
   public boolean invokeDynamic = DEFAULT_INVOKE_DYNAMIC;
 
@@ -48,9 +49,10 @@ public class JpsGroovySettings extends JpsElementBase<JpsGroovySettings> {
   public JpsGroovySettings() {
   }
 
-  public JpsGroovySettings(JpsGroovySettings original) {
+  private JpsGroovySettings(JpsGroovySettings original) {
     heapSize = original.heapSize;
     invokeDynamic = original.invokeDynamic;
+    configScript = original.configScript;
   }
 
   void initExcludes() {
index c48e9bb443b7e7b3432fd01c4438e792eef4374f..2fcd1c5cb844ecf71c7109c155c898110911310a 100644 (file)
@@ -46,7 +46,7 @@ public class DependentGroovycRunner {
   public static final String[] RESOURCES_TO_MASK = {"META-INF/services/org.codehaus.groovy.transform.ASTTransformation", "META-INF/services/org.codehaus.groovy.runtime.ExtensionModule"};
   private static final String STUB_DIR = "stubDir";
 
-  public static boolean runGroovyc(boolean forStubs, String argsPath, Queue mailbox) {
+  public static boolean runGroovyc(boolean forStubs, String argsPath, String configScript, Queue mailbox) {
     File argsFile = new File(argsPath);
     final CompilerConfiguration config = new CompilerConfiguration();
     config.setClasspath("");
@@ -83,8 +83,7 @@ public class DependentGroovycRunner {
     catch (NoSuchMethodError ignored) { // old groovyc's don't have optimization options
     }
 
-    String configScript = System.getProperty(GroovyRtConstants.GROOVYC_CONFIG_SCRIPT);
-    if (configScript != null) {
+    if (configScript != null && configScript.length() > 0) {
       try {
         applyConfigurationScript(new File(configScript), config);
       }
index 1aeb686282976eb1d327a9926165f623a06a35cb..6c731efc7d774e09a7daec24d3fe2248d518ef8d 100644 (file)
@@ -97,10 +97,12 @@ public class GroovycRunner {
     final boolean forStubs = "stubs".equals(args[1]);
     String argPath = args[2];
 
-    return intMain2(indy, optimize, forStubs, argPath, null);
+    String configScript = System.getProperty(GroovyRtConstants.GROOVYC_CONFIG_SCRIPT);
+
+    return intMain2(indy, optimize, forStubs, argPath, configScript, null);
   }
 
-  public static int intMain2(boolean indy, boolean optimize, boolean forStubs, String argPath, Queue mailbox) {
+  public static int intMain2(boolean indy, boolean optimize, boolean forStubs, String argPath, String configScript, Queue mailbox) {
     if (indy) {
       System.setProperty("groovy.target.indy", "true");
     }
@@ -128,8 +130,8 @@ public class GroovycRunner {
 
     try {
       Class<?> aClass = Class.forName("org.jetbrains.groovy.compiler.rt.DependentGroovycRunner", true, loader);
-      Method method = aClass.getDeclaredMethod("runGroovyc", boolean.class, String.class, Queue.class);
-      method.invoke(null, forStubs, argPath, mailbox);
+      Method method = aClass.getDeclaredMethod("runGroovyc", boolean.class, String.class, String.class, Queue.class);
+      method.invoke(null, forStubs, argPath, configScript, mailbox);
     }
     catch (Throwable e) {
       while (e.getCause() != null) {
index 5dd2805cf78062b9c13c04e9182db161e9577e72..fb577bed909baa7a4428ad357fe41dc7989f429d 100644 (file)
@@ -8,7 +8,7 @@
     <properties/>
     <border type="none"/>
     <children>
-      <grid id="838f2" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+      <grid id="838f2" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
         <margin top="0" left="0" bottom="0" right="0"/>
         <constraints>
           <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
               <visible value="false"/>
             </properties>
           </component>
-          <hspacer id="5e141">
-            <constraints>
-              <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
-            </constraints>
-          </hspacer>
           <component id="52aeb" class="com.intellij.ui.components.JBCheckBox" binding="myInvokeDynamicSupportCB">
             <constraints>
-              <grid row="1" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+              <grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
             </constraints>
             <properties>
               <text value="Invoke &amp;dynamic support"/>
             </properties>
           </component>
+          <component id="80fe6" class="javax.swing.JLabel">
+            <constraints>
+              <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties>
+              <labelFor value="9edf9"/>
+              <text value="Path to &amp;configscript:"/>
+            </properties>
+          </component>
+          <component id="9edf9" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myConfigScriptPath">
+            <constraints>
+              <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false">
+                <preferred-size width="150" height="-1"/>
+              </grid>
+            </constraints>
+            <properties>
+              <text value=""/>
+            </properties>
+          </component>
         </children>
       </grid>
       <grid id="4e3dc" binding="myExcludesPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
index 809f08beec5c7ae9e1353e4682aba64b9b28930c..3e8e76fbc928748c6458110fb057fe9f79a964e1 100644 (file)
@@ -28,7 +28,9 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.roots.ModuleRootManager;
 import com.intellij.openapi.roots.ProjectFileIndex;
 import com.intellij.openapi.roots.ProjectRootManager;
+import com.intellij.openapi.ui.TextFieldWithBrowseButton;
 import com.intellij.openapi.util.Comparing;
+import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.ui.components.JBCheckBox;
 import com.intellij.util.Function;
@@ -48,6 +50,7 @@ public class GroovyCompilerConfigurable implements SearchableConfigurable, Confi
   private JPanel myMainPanel;
   private JPanel myExcludesPanel;
   private JBCheckBox myInvokeDynamicSupportCB;
+  private TextFieldWithBrowseButton myConfigScriptPath;
 
   private final ExcludedEntriesConfigurable myExcludes;
   private final GroovyCompilerConfiguration myConfig;
@@ -55,6 +58,9 @@ public class GroovyCompilerConfigurable implements SearchableConfigurable, Confi
   public GroovyCompilerConfigurable(Project project) {
     myConfig = GroovyCompilerConfiguration.getInstance(project);
     myExcludes = createExcludedConfigurable(project);
+
+    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false);
+    myConfigScriptPath.addBrowseFolderListener(null, "Select path to Groovy compiler configscript", null, descriptor);
   }
 
   public ExcludedEntriesConfigurable getExcludes() {
@@ -112,6 +118,7 @@ public class GroovyCompilerConfigurable implements SearchableConfigurable, Confi
   @Override
   public boolean isModified() {
     return !Comparing.equal(myConfig.getHeapSize(), myHeapSize.getText()) ||
+           !Comparing.equal(myConfig.getConfigScript(), getExternalizableConfigScript()) ||
            myInvokeDynamicSupportCB.isSelected() != myConfig.isInvokeDynamic() ||
            myExcludes.isModified();
   }
@@ -121,11 +128,13 @@ public class GroovyCompilerConfigurable implements SearchableConfigurable, Confi
     myExcludes.apply();
     myConfig.setHeapSize(myHeapSize.getText());
     myConfig.setInvokeDynamic(myInvokeDynamicSupportCB.isSelected());
+    myConfig.setConfigScript(getExternalizableConfigScript());
   }
 
   @Override
   public void reset() {
     myHeapSize.setText(myConfig.getHeapSize());
+    myConfigScriptPath.setText(FileUtil.toSystemDependentName(myConfig.getConfigScript()));
     myInvokeDynamicSupportCB.setSelected(myConfig.isInvokeDynamic());
     myExcludes.reset();
   }
@@ -134,4 +143,10 @@ public class GroovyCompilerConfigurable implements SearchableConfigurable, Confi
   public void disposeUIResources() {
     myExcludes.disposeUIResources();
   }
+
+  @NotNull
+  private String getExternalizableConfigScript() {
+    return FileUtil.toSystemIndependentName(myConfigScriptPath.getText());
+  }
+
 }
index 72a51597881c90ce7e1d4585c7e2dec93d77c155..df86b9d39a775865dbc08394532dc63e751beb00 100644 (file)
@@ -35,6 +35,7 @@ import org.jetbrains.jps.incremental.groovy.JpsGroovySettings;
   }
 )
 public class GroovyCompilerConfiguration implements PersistentStateComponent<JpsGroovySettings>, Disposable {
+  private String myConfigScript = "";
   private String myHeapSize = JpsGroovySettings.DEFAULT_HEAP_SIZE;
   private boolean myInvokeDynamic = JpsGroovySettings.DEFAULT_INVOKE_DYNAMIC;
   public boolean transformsOk = JpsGroovySettings.DEFAULT_TRANSFORMS_OK;
@@ -44,6 +45,7 @@ public class GroovyCompilerConfiguration implements PersistentStateComponent<Jps
   public JpsGroovySettings getState() {
     final JpsGroovySettings bean = new JpsGroovySettings();
     bean.heapSize = myHeapSize;
+    bean.configScript = myConfigScript;
     bean.invokeDynamic = myInvokeDynamic;
     bean.transformsOk = transformsOk;
     myExcludeFromStubGeneration.writeExternal(bean.excludes);
@@ -61,6 +63,7 @@ public class GroovyCompilerConfiguration implements PersistentStateComponent<Jps
   @Override
   public void loadState(JpsGroovySettings state) {
     myHeapSize = state.heapSize;
+    myConfigScript = state.configScript;
     myInvokeDynamic = state.invokeDynamic;
     transformsOk = state.transformsOk;
 
@@ -87,6 +90,14 @@ public class GroovyCompilerConfiguration implements PersistentStateComponent<Jps
     myInvokeDynamic = invokeDynamic;
   }
 
+  public String getConfigScript() {
+    return myConfigScript;
+  }
+
+  public void setConfigScript(String configScript) {
+    myConfigScript = configScript;
+  }
+
   @Override
   public void dispose() {
     Disposer.dispose(myExcludeFromStubGeneration);
index bd9aff7377659bc0fc5d61180aa56391c908cf00..c331a3b4f0d7c8fcb636f53dae68f4e4a846ac94 100644 (file)
@@ -17,7 +17,6 @@
 package org.jetbrains.plugins.groovy.compiler
 import com.intellij.compiler.CompilerConfiguration
 import com.intellij.compiler.CompilerConfigurationImpl
-import com.intellij.compiler.CompilerWorkspaceConfiguration
 import com.intellij.compiler.server.BuildManager
 import com.intellij.execution.executors.DefaultRunExecutor
 import com.intellij.execution.impl.DefaultJavaProgramRunner
@@ -913,8 +912,8 @@ class AppTest {
       def script = FileUtil.createTempFile("configScriptTest", ".groovy", true)
       FileUtil.writeToFile(script, "import groovy.transform.*; withConfig(configuration) { ast(CompileStatic) }")
 
-      CompilerWorkspaceConfiguration.getInstance(project).COMPILER_PROCESS_ADDITIONAL_VM_OPTIONS = "-Dgroovyc.config.script=" + script.path
-
+      GroovyCompilerConfiguration.getInstance(project).configScript = script.path
+      
       myFixture.addFileToProject("a.groovy", "class A { int s = 'foo' }")
       shouldFail { make() }
     }