support configscript in groovy compilation (IDEA-103342)
[idea/community.git] / plugins / groovy / src / org / jetbrains / plugins / groovy / compiler / GroovyCompilerConfiguration.java
1 /*
2  * Copyright 2000-2014 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.jetbrains.plugins.groovy.compiler;
18
19 import com.intellij.openapi.Disposable;
20 import com.intellij.openapi.compiler.options.ExcludedEntriesConfiguration;
21 import com.intellij.openapi.compiler.options.ExcludesConfiguration;
22 import com.intellij.openapi.components.*;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.util.Disposer;
25 import org.jetbrains.jps.incremental.groovy.JpsGroovySettings;
26
27 /**
28  * @author peter
29  */
30 @State(
31   name = "GroovyCompilerProjectConfiguration",
32   storages = {
33     @Storage(file = StoragePathMacros.PROJECT_FILE),
34     @Storage(file = StoragePathMacros.PROJECT_CONFIG_DIR + "/groovyc.xml", scheme = StorageScheme.DIRECTORY_BASED)
35   }
36 )
37 public class GroovyCompilerConfiguration implements PersistentStateComponent<JpsGroovySettings>, Disposable {
38   private String myConfigScript = "";
39   private String myHeapSize = JpsGroovySettings.DEFAULT_HEAP_SIZE;
40   private boolean myInvokeDynamic = JpsGroovySettings.DEFAULT_INVOKE_DYNAMIC;
41   public boolean transformsOk = JpsGroovySettings.DEFAULT_TRANSFORMS_OK;
42   private final ExcludedEntriesConfiguration myExcludeFromStubGeneration = new ExcludedEntriesConfiguration();
43
44   @Override
45   public JpsGroovySettings getState() {
46     final JpsGroovySettings bean = new JpsGroovySettings();
47     bean.heapSize = myHeapSize;
48     bean.configScript = myConfigScript;
49     bean.invokeDynamic = myInvokeDynamic;
50     bean.transformsOk = transformsOk;
51     myExcludeFromStubGeneration.writeExternal(bean.excludes);
52     return bean;
53   }
54
55   public static ExcludesConfiguration getExcludeConfiguration(Project project) {
56     return getInstance(project).myExcludeFromStubGeneration;
57   }
58
59   public ExcludesConfiguration getExcludeFromStubGeneration() {
60     return myExcludeFromStubGeneration;
61   }
62
63   @Override
64   public void loadState(JpsGroovySettings state) {
65     myHeapSize = state.heapSize;
66     myConfigScript = state.configScript;
67     myInvokeDynamic = state.invokeDynamic;
68     transformsOk = state.transformsOk;
69
70     myExcludeFromStubGeneration.readExternal(state.excludes);
71   }
72
73   public static GroovyCompilerConfiguration getInstance(Project project) {
74     return ServiceManager.getService(project, GroovyCompilerConfiguration.class);
75   }
76
77   public String getHeapSize() {
78     return myHeapSize;
79   }
80
81   public boolean isInvokeDynamic() {
82     return myInvokeDynamic;
83   }
84
85   public void setHeapSize(String heapSize) {
86     myHeapSize = heapSize;
87   }
88
89   public void setInvokeDynamic(boolean invokeDynamic) {
90     myInvokeDynamic = invokeDynamic;
91   }
92
93   public String getConfigScript() {
94     return myConfigScript;
95   }
96
97   public void setConfigScript(String configScript) {
98     myConfigScript = configScript;
99   }
100
101   @Override
102   public void dispose() {
103     Disposer.dispose(myExcludeFromStubGeneration);
104   }
105
106 }