File: idea.gradle

package info (click to toggle)
groovy 2.4.21-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 30,708 kB
  • sloc: java: 157,114; xml: 728; sh: 357; makefile: 64; javascript: 15
file content (230 lines) | stat: -rw-r--r-- 10,185 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 */
/**
 * Configuration for gradle idea.
 *
 * Inspired from the Gradle build.
 */

def appendNode(node, text) {
    node.append(new XmlParser().parseText(text))
}

allprojects {
    apply plugin: 'idea'

    idea {
        module.iml.withXml { provider ->
            def node = provider.asNode()

            // remove target classes from libraries
            def moduleRoot = node.component.find { it.'@name' == 'NewModuleRootManager' }
            def entries = moduleRoot.orderEntry.findAll { oe ->
                oe.library.CLASSES.root.'@url' =~ /target/
            }
            if (entries) {
                entries.each { moduleRoot.remove(it) }
            }
        }
    }
}

idea {
    project {
        ipr {
            withXml { provider ->
                def node = provider.asNode()

                // jdk, language level fix
                def pRoot = node.component.find { it.'@name' == 'ProjectRootManager' }
                pRoot.'@languageLevel' = 'JDK_1_6'
                pRoot.'@project-jdk-name' = '1.8'

                // Use git
                def vcsConfig = node.component.find { it.'@name' == 'VcsDirectoryMappings' }
                vcsConfig.mapping[0].'@vcs' = 'Git'

                // license header
                def copyrightManager = node.component.find { it.'@name' == 'CopyrightManager' }
                copyrightManager.@default = 'ASL2'
                def aslCopyright = copyrightManager.copyright.find { it.option.find { it.@name == 'myName' }?.@value == 'ASL2' }
                if (aslCopyright == null) {
                    appendNode(copyrightManager, '''
                      <copyright>
                          <option name="notice" value=" Licensed to the Apache Software Foundation (ASF) under one&#10; or more contributor license agreements.  See the NOTICE file&#10; distributed with this work for additional information&#10; regarding copyright ownership.  The ASF licenses this file&#10; to you under the Apache License, Version 2.0 (the&#10; &quot;License&quot;); you may not use this file except in compliance&#10; with the License.  You may obtain a copy of the License at&#10;&#10;   http://www.apache.org/licenses/LICENSE-2.0&#10;&#10; Unless required by applicable law or agreed to in writing,&#10; software distributed under the License is distributed on an&#10; &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY&#10; KIND, either express or implied.  See the License for the&#10; specific language governing permissions and limitations&#10; under the License." />
                          <option name="keyword" value="Copyright" />
                          <option name="allowReplaceKeyword" value="" />
                          <option name="myName" value="ASL2" />
                          <option name="myLocal" value="true" />
                      </copyright>
                    ''')
                    appendNode(copyrightManager, '''
                        <LanguageOptions name="__TEMPLATE__">
                            <option name="addBlankAfter" value="false" />
                        </LanguageOptions>
                    ''')
                }

                def compilerConfig = node.component.find { it.@name == 'CompilerConfiguration' }
                ['/**/org.codehaus.groovy.runtime.ExtensionModule',
                '*.jar',
                'test-resources:/**/*.groovy','test-resources:/**/*.java',
                '!?*.groovy',
                '/groovy/inspect/swingui/AstBrowserProperties.groovy',
                '/groovy/inspect/swingui/AstBrowserProperties.groovy',
                '/**/org.codehaus.groovy.runtime.ExtensionModule;*.jar',
                '/groovy/inspect/swingui/AstBrowserProperties.groovy',
                '/**/org.codehaus.groovy.runtime.ExtensionModule',
                '*.jar'].each {
                    appendNode(compilerConfig.wildcardResourcePatterns[0], "<entry name=\"$it\" />")
                }
                appendNode(compilerConfig,'''<excludeFromCompile>
      <directory url="file://$PROJECT_DIR$/src/test-resources" includeSubdirectories="true" />
    </excludeFromCompile>''')
            }
        }
    }

    workspace {
        iws {
            withXml { provider ->
                def node = provider.asNode()

                // exclude some files from stub generation
                def groovyCompilerConfig = node.component.find { it.'@name' == 'GroovyCompilerConfiguration' }
                if (!groovyCompilerConfig) {
                    node.append(new XmlParser().parseText('''
                   <component name='GroovyCompilerConfiguration'>
                      <excludes></excludes>
                   </component>'''))
                    groovyCompilerConfig = node.component.find { it.'@name' == 'GroovyCompilerConfiguration' }
                }
                def excludeNode = groovyCompilerConfig.excludes[0]
                ['/src/test/org/codehaus/groovy/transform/DelegateTransformTest.groovy',
                '/src/test/groovy/bugs/Groovy593_Bug.groovy'].each { excludedFile ->
                    def url = "file://\$PROJECT_DIR\$$excludedFile"
                    if (!excludeNode.file.any { it.'@url' == url }) {
                        excludeNode.append(new XmlParser().parseText("<file url=\"$url\" />"))
                    }
                }

                // add sample configurations
                def runmanager = node.component.find { it.'@name' == 'RunManager' }
                appendNode(runmanager, '''<configuration default="false" name="Console" type="Application" factoryName="Application">
      <extension name="coverage" enabled="false" merge="false" runner="idea">
        <pattern>
          <option name="PATTERN" value="groovy.ui.*" />
          <option name="ENABLED" value="true" />
        </pattern>
      </extension>
      <option name="MAIN_CLASS_NAME" value="groovy.ui.Console" />
      <option name="VM_PARAMETERS" />
      <option name="PROGRAM_PARAMETERS" />
      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
      <option name="ALTERNATIVE_JRE_PATH" />
      <option name="ENABLE_SWING_INSPECTOR" value="false" />
      <option name="ENV_VARIABLES" />
      <option name="PASS_PARENT_ENVS" value="true" />
      <module name="groovy-console" />
      <envs />
      <RunnerSettings RunnerId="Debug">
        <option name="DEBUG_PORT" value="" />
        <option name="TRANSPORT" value="0" />
        <option name="LOCAL" value="true" />
      </RunnerSettings>
      <RunnerSettings RunnerId="Profile ">
        <option name="myExternalizedOptions" />
      </RunnerSettings>
      <RunnerSettings RunnerId="Run" />
      <ConfigurationWrapper RunnerId="Debug" />
      <ConfigurationWrapper RunnerId="Run" />
      <method />
    </configuration>
''')
                appendNode(runmanager,'''<configuration default="false" name="groovy.transform.stc in groovy" type="JUnit" factoryName="JUnit">
      <extension name="coverage" enabled="false" merge="false" runner="idea">
        <pattern>
          <option name="PATTERN" value="groovy.transform.stc.*" />
          <option name="ENABLED" value="true" />
        </pattern>
      </extension>
      <module name="groovy" />
      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
      <option name="ALTERNATIVE_JRE_PATH" />
      <option name="PACKAGE_NAME" value="groovy.transform.stc" />
      <option name="MAIN_CLASS_NAME" />
      <option name="METHOD_NAME" />
      <option name="TEST_OBJECT" value="package" />
      <option name="VM_PARAMETERS" />
      <option name="PARAMETERS" />
      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
      <option name="ENV_VARIABLES" />
      <option name="PASS_PARENT_ENVS" value="true" />
      <option name="TEST_SEARCH_SCOPE">
        <value defaultName="moduleWithDependencies" />
      </option>
      <envs />
      <patterns />
      <RunnerSettings RunnerId="Debug">
        <option name="DEBUG_PORT" value="" />
        <option name="TRANSPORT" value="0" />
        <option name="LOCAL" value="true" />
      </RunnerSettings>
      <RunnerSettings RunnerId="Profile ">
        <option name="myExternalizedOptions" />
      </RunnerSettings>
      <RunnerSettings RunnerId="Run" />
      <ConfigurationWrapper RunnerId="Debug" />
      <ConfigurationWrapper RunnerId="Run" />
      <method />
    </configuration>
''')
            }
        }
    }

    module.iml.withXml { provider ->
        def node = provider.asNode()

        // remove compiler classes from libraries
        def moduleRoot = node.component.find { it.'@name' == 'NewModuleRootManager' }
        def entry = moduleRoot.orderEntry.find { oe ->
            oe.library.CLASSES.root.'@url' =~ /classes\/compiler/
        }
        if (entry) {
            moduleRoot.remove(entry)
        }

        // add an entry for groovy jar
        appendNode(moduleRoot, """
            <orderEntry type="module-library" exported="">
              <library>
                <CLASSES>
                  <root url="jar://${rootProject.jar.archivePath}!/"/>
                </CLASSES>
              </library>
            </orderEntry>
        """)
    }

    tasks.withType(GenerateIdeaProject).all {
        it.dependsOn(jar)
    }
}