72a51597881c90ce7e1d4585c7e2dec93d77c155
[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 myHeapSize = JpsGroovySettings.DEFAULT_HEAP_SIZE;
39   private boolean myInvokeDynamic = JpsGroovySettings.DEFAULT_INVOKE_DYNAMIC;
40   public boolean transformsOk = JpsGroovySettings.DEFAULT_TRANSFORMS_OK;
41   private final ExcludedEntriesConfiguration myExcludeFromStubGeneration = new ExcludedEntriesConfiguration();
42
43   @Override
44   public JpsGroovySettings getState() {
45     final JpsGroovySettings bean = new JpsGroovySettings();
46     bean.heapSize = myHeapSize;
47     bean.invokeDynamic = myInvokeDynamic;
48     bean.transformsOk = transformsOk;
49     myExcludeFromStubGeneration.writeExternal(bean.excludes);
50     return bean;
51   }
52
53   public static ExcludesConfiguration getExcludeConfiguration(Project project) {
54     return getInstance(project).myExcludeFromStubGeneration;
55   }
56
57   public ExcludesConfiguration getExcludeFromStubGeneration() {
58     return myExcludeFromStubGeneration;
59   }
60
61   @Override
62   public void loadState(JpsGroovySettings state) {
63     myHeapSize = state.heapSize;
64     myInvokeDynamic = state.invokeDynamic;
65     transformsOk = state.transformsOk;
66
67     myExcludeFromStubGeneration.readExternal(state.excludes);
68   }
69
70   public static GroovyCompilerConfiguration getInstance(Project project) {
71     return ServiceManager.getService(project, GroovyCompilerConfiguration.class);
72   }
73
74   public String getHeapSize() {
75     return myHeapSize;
76   }
77
78   public boolean isInvokeDynamic() {
79     return myInvokeDynamic;
80   }
81
82   public void setHeapSize(String heapSize) {
83     myHeapSize = heapSize;
84   }
85
86   public void setInvokeDynamic(boolean invokeDynamic) {
87     myInvokeDynamic = invokeDynamic;
88   }
89
90   @Override
91   public void dispose() {
92     Disposer.dispose(myExcludeFromStubGeneration);
93   }
94
95 }