mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
jps: load some compiler options and annotation processing options from project files
This commit is contained in:
@@ -8,5 +8,15 @@ class CompilerConfiguration {
|
||||
List<String> resourceIncludePatterns = "properties,xml,gif,png,jpeg,jpg,jtml,dtd,tld,ftl".split(",").collect {"**/?*.$it"}
|
||||
List<String> resourceExcludePatterns = []
|
||||
Map<String, String> javacOptions = [:]
|
||||
|
||||
boolean clearOutputDirectoryOnRebuild = true
|
||||
boolean addNotNullAssertions = true
|
||||
AnnotationProcessingConfiguration annotationProcessing = new AnnotationProcessingConfiguration()
|
||||
}
|
||||
|
||||
class AnnotationProcessingConfiguration {
|
||||
boolean enabled = false
|
||||
boolean obtainProcessorsFromClasspath = true
|
||||
String processorsPath
|
||||
Map<String, String> processorsOptions = [:]
|
||||
Map<String, String> processModule = [:]
|
||||
}
|
||||
@@ -105,6 +105,7 @@ public class IdeaProjectLoader {
|
||||
loadProjectLibraries(getComponent(root, "libraryTable"))
|
||||
loadArtifacts(getComponent(root, "ArtifactManager"))
|
||||
loadRunConfigurations(getComponent(root, "ProjectRunConfigurationManager"))
|
||||
loadWorkspaceConfiguration(new File(iprFile.parentFile, iprFile.name[0..-4]+"iws"))
|
||||
}
|
||||
|
||||
def loadFromDirectoryBased(File dir) {
|
||||
@@ -125,6 +126,7 @@ public class IdeaProjectLoader {
|
||||
if (compilerXml.exists()) {
|
||||
loadCompilerConfiguration(new XmlParser(false, false).parse(compilerXml))
|
||||
}
|
||||
loadWorkspaceConfiguration(new File(dir, "workspace.xml"))
|
||||
|
||||
Node modulesXmlRoot = new XmlParser(false, false).parse(modulesXml)
|
||||
loadModules(modulesXmlRoot.component[0])
|
||||
@@ -160,6 +162,15 @@ public class IdeaProjectLoader {
|
||||
}
|
||||
}
|
||||
|
||||
private def loadWorkspaceConfiguration(File workspaceFile) {
|
||||
if (!workspaceFile.exists()) return
|
||||
|
||||
def root = new XmlParser(false, false).parse(workspaceFile)
|
||||
def options = loadOptions(getComponent(root, "CompilerWorkspaceConfiguration"))
|
||||
project.compilerConfiguration.addNotNullAssertions = parseBoolean(options["ASSERT_NOT_NULL"], true);
|
||||
project.compilerConfiguration.clearOutputDirectoryOnRebuild = parseBoolean(options["CLEAR_OUTPUT_DIRECTORY"], true);
|
||||
}
|
||||
|
||||
private def loadCompilerConfiguration(Node root) {
|
||||
def rawPatterns = []
|
||||
def includePatterns = []
|
||||
@@ -184,12 +195,42 @@ public class IdeaProjectLoader {
|
||||
configuration.resourcePatterns = rawPatterns;
|
||||
}
|
||||
|
||||
def javacComponentTag = getComponent(root, "JavacSettings");
|
||||
javacComponentTag?.option?.each {Node optionTag ->
|
||||
configuration.javacOptions[optionTag."@name"] = optionTag."@value";
|
||||
configuration.javacOptions.putAll(loadOptions(getComponent(root, "JavacSettings")))
|
||||
|
||||
def annotationProcessingTag = componentTag.annotationProcessing
|
||||
if (annotationProcessingTag != null) {
|
||||
configuration.annotationProcessing.enabled = parseBoolean(annotationProcessingTag."@enabled", false)
|
||||
configuration.annotationProcessing.obtainProcessorsFromClasspath = parseBoolean(annotationProcessingTag."@useClasspath", true)
|
||||
List<String> processorPaths = []
|
||||
annotationProcessingTag.processorPath?.each {
|
||||
processorPaths << projectMacroExpander.expandMacros(it."@value")
|
||||
}
|
||||
configuration.annotationProcessing.processorsPath = processorPaths.join(File.pathSeparator)
|
||||
annotationProcessingTag.processor?.each {
|
||||
configuration.annotationProcessing.processorsOptions[it."@name"] = it."@options" ?: ""
|
||||
}
|
||||
annotationProcessingTag.processModule?.each {
|
||||
configuration.annotationProcessing.processModule[it."@name"] = it."@generatedDirName"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean parseBoolean(Object value, boolean defaultValue) {
|
||||
if (value instanceof NodeList) {
|
||||
if (value.isEmpty()) return defaultValue
|
||||
value = value[0]
|
||||
}
|
||||
return value != null ? Boolean.parseBoolean((String)value) : defaultValue
|
||||
}
|
||||
|
||||
private Map<String, String> loadOptions(Node optionsTag) {
|
||||
def result = new HashMap<String, String>()
|
||||
optionsTag?.option?.each {Node optionTag ->
|
||||
result[optionTag."@name"] = optionTag."@value";
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private String convertPattern(String pattern) {
|
||||
if (pattern.indexOf('/') == -1) {
|
||||
return "**/" + pattern
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<excludeFromCompile>
|
||||
<directory url="file://$PROJECT_DIR$/src" includeSubdirectories="true" />
|
||||
</excludeFromCompile>
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="?*.properties" />
|
||||
<entry name="?*.xml" />
|
||||
<entry name="?*.gif" />
|
||||
<entry name="?*.png" />
|
||||
<entry name="?*.jpeg" />
|
||||
<entry name="?*.jpg" />
|
||||
<entry name="?*.html" />
|
||||
<entry name="?*.dtd" />
|
||||
<entry name="?*.tld" />
|
||||
<entry name="?*.ftl" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing enabled="true" useClasspath="false">
|
||||
<processorPath value="$PROJECT_DIR$/src" />
|
||||
<processor name="my.proc" options="a=b c=d" />
|
||||
<processModule name="compilerConfiguration" generatedDirName="gen" />
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/compilerConfiguration.iml" filepath="$PROJECT_DIR$/compilerConfiguration.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectResources">
|
||||
<default-html-doctype>http://www.w3.org/1999/xhtml</default-html-doctype>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerWorkspaceConfiguration">
|
||||
<option name="CLEAR_OUTPUT_DIRECTORY" value="false" />
|
||||
<option name="ASSERT_NOT_NULL" value="false" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<excludeFromCompile>
|
||||
<directory url="file://$PROJECT_DIR$/src" includeSubdirectories="true" />
|
||||
</excludeFromCompile>
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="?*.properties" />
|
||||
<entry name="?*.xml" />
|
||||
<entry name="?*.gif" />
|
||||
<entry name="?*.png" />
|
||||
<entry name="?*.jpeg" />
|
||||
<entry name="?*.jpg" />
|
||||
<entry name="?*.html" />
|
||||
<entry name="?*.dtd" />
|
||||
<entry name="?*.tld" />
|
||||
<entry name="?*.ftl" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing enabled="true" useClasspath="false">
|
||||
<processorPath value="$PROJECT_DIR$/src" />
|
||||
<processor name="my.proc" options="a=b c=d" />
|
||||
<processModule name="compilerConfiguration" generatedDirName="gen" />
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/compilerConfiguration.iml" filepath="$PROJECT_DIR$/compilerConfiguration.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerWorkspaceConfiguration">
|
||||
<option name="CLEAR_OUTPUT_DIRECTORY" value="false" />
|
||||
<option name="ASSERT_NOT_NULL" value="false" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<excludeFromCompile>
|
||||
<directory url="file://$PROJECT_DIR$/src" includeSubdirectories="true" />
|
||||
</excludeFromCompile>
|
||||
<resourceExtensions />
|
||||
<wildcardResourcePatterns>
|
||||
<entry name="?*.properties" />
|
||||
<entry name="?*.xml" />
|
||||
<entry name="?*.gif" />
|
||||
<entry name="?*.png" />
|
||||
<entry name="?*.jpeg" />
|
||||
<entry name="?*.jpg" />
|
||||
<entry name="?*.html" />
|
||||
<entry name="?*.dtd" />
|
||||
<entry name="?*.tld" />
|
||||
<entry name="?*.ftl" />
|
||||
</wildcardResourcePatterns>
|
||||
<annotationProcessing enabled="true" useClasspath="false">
|
||||
<processorPath value="$PROJECT_DIR$/src" />
|
||||
<processor name="my.proc" options="a=b c=d" />
|
||||
<processModule name="compilerConfiguration" generatedDirName="gen" />
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/compilerConfiguration.iml" filepath="$PROJECT_DIR$/compilerConfiguration.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
package org.jetbrains.jps
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class CompilerConfigurationTest extends JpsBuildTestCase {
|
||||
public void testLoadFromIpr() {
|
||||
doTest("testData/compilerConfiguration/compilerConfiguration.ipr")
|
||||
}
|
||||
|
||||
public void testLoadFromDirectory() {
|
||||
doTest("testData/compilerConfigurationDir")
|
||||
}
|
||||
|
||||
private def doTest(final String path) {
|
||||
Project project = loadProject(path, [:])
|
||||
CompilerConfiguration configuration = project.compilerConfiguration
|
||||
assertFalse(configuration.clearOutputDirectoryOnRebuild)
|
||||
assertFalse(configuration.addNotNullAssertions)
|
||||
assertTrue(configuration.annotationProcessing.enabled)
|
||||
assertFalse(configuration.annotationProcessing.obtainProcessorsFromClasspath)
|
||||
assertTrue(configuration.annotationProcessing.processorsPath.endsWith("/src"))
|
||||
assertEquals("a=b c=d", configuration.annotationProcessing.processorsOptions["my.proc"])
|
||||
assertEquals("gen", configuration.annotationProcessing.processModule["compilerConfiguration"])
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ abstract class JpsBuildTestCase extends TestCase {
|
||||
binding.includeTool << Jps
|
||||
def project = new GantBasedProject(binding)
|
||||
initGlobal(project)
|
||||
IdeaProjectLoader.loadFromPath(project, projectPath, pathVariables, null, new AntErrorReporter(binding))
|
||||
IdeaProjectLoader.loadFromPath(project, "../community/jps/$projectPath", pathVariables, null, new AntErrorReporter(binding))
|
||||
return project
|
||||
}
|
||||
|
||||
@@ -99,7 +99,3 @@ abstract class JpsBuildTestCase extends TestCase {
|
||||
return myTempFiles.createTempFile();
|
||||
}
|
||||
}
|
||||
|
||||
interface ProjectInitializer {
|
||||
void init(Project project, ProjectBuilder projectBuilder)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user