jps reads groovy compiler settings (IDEA-95909, IDEA-84089)

This commit is contained in:
peter
2013-01-18 18:36:55 +01:00
parent 0510bbd398
commit d0f0889923
8 changed files with 195 additions and 53 deletions
@@ -22,6 +22,7 @@ import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
import org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes;
import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration;
import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer;
@@ -55,16 +56,7 @@ public class JpsJavaCompilerConfigurationSerializer extends JpsProjectExtensionS
configuration.setAddNotNullAssertions(Boolean.parseBoolean(addNotNullTag.getAttributeValue(ENABLED, "true")));
}
Element excludeFromCompileTag = componentTag.getChild(EXCLUDE_FROM_COMPILE);
if (excludeFromCompileTag != null) {
for (Element fileTag : JDOMUtil.getChildren(excludeFromCompileTag, "file")) {
configuration.getCompilerExcludes().addExcludedFile(fileTag.getAttributeValue("url"));
}
for (Element directoryTag : JDOMUtil.getChildren(excludeFromCompileTag, "directory")) {
boolean recursively = Boolean.parseBoolean(directoryTag.getAttributeValue("includeSubdirectories"));
configuration.getCompilerExcludes().addExcludedDirectory(directoryTag.getAttributeValue("url"), recursively);
}
}
readExcludes(componentTag.getChild(EXCLUDE_FROM_COMPILE), configuration.getCompilerExcludes());
Element resourcePatternsTag = componentTag.getChild(WILDCARD_RESOURCE_PATTERNS);
for (Element entry : JDOMUtil.getChildren(resourcePatternsTag, ENTRY)) {
@@ -105,6 +97,18 @@ public class JpsJavaCompilerConfigurationSerializer extends JpsProjectExtensionS
}
}
public static void readExcludes(Element excludeFromCompileTag, JpsCompilerExcludes excludes) {
if (excludeFromCompileTag != null) {
for (Element fileTag : JDOMUtil.getChildren(excludeFromCompileTag, "file")) {
excludes.addExcludedFile(fileTag.getAttributeValue("url"));
}
for (Element directoryTag : JDOMUtil.getChildren(excludeFromCompileTag, "directory")) {
boolean recursively = Boolean.parseBoolean(directoryTag.getAttributeValue("includeSubdirectories"));
excludes.addExcludedDirectory(directoryTag.getAttributeValue("url"), recursively);
}
}
}
@Override
public void saveExtension(@NotNull JpsProject project, @NotNull Element componentTag) {
}
@@ -10,6 +10,8 @@
<orderEntry type="module" module-name="jps-model-api" />
<orderEntry type="module" module-name="jps-builders" />
<orderEntry type="module" module-name="groovy-rt-constants" />
<orderEntry type="module" module-name="jps-model-serialization" />
<orderEntry type="module" module-name="jps-model-impl" />
</component>
</module>
@@ -0,0 +1 @@
org.jetbrains.jps.incremental.groovy.GroovyModelSerializerExtension
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Consumer;
import com.intellij.util.SystemProperties;
import com.intellij.util.containers.ContainerUtilRt;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -84,7 +85,9 @@ public class GroovyBuilder extends ModuleLevelBuilder {
DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder,
OutputConsumer outputConsumer) throws ProjectBuildException {
try {
final List<File> toCompile = collectChangedFiles(context, dirtyFilesHolder);
JpsGroovySettings settings = JpsGroovySettings.getSettings(context.getProjectDescriptor().getProject());
final List<File> toCompile = collectChangedFiles(context, dirtyFilesHolder, settings);
if (toCompile.isEmpty()) {
return ExitCode.NOTHING_DONE;
}
@@ -115,7 +118,7 @@ public class GroovyBuilder extends ModuleLevelBuilder {
final File tempFile = GroovycOSProcessHandler.fillFileWithGroovycParameters(
compilerOutput, toCompilePaths, finalOutput, class2Src, encoding, patchers
);
final GroovycOSProcessHandler handler = runGroovyc(context, chunk, tempFile);
final GroovycOSProcessHandler handler = runGroovyc(context, chunk, tempFile, settings);
Map<ModuleBuildTarget, Collection<GroovycOSProcessHandler.OutputItem>>
compiled = processCompiledFiles(context, chunk, generationOutputs, compilerOutput, handler);
@@ -154,20 +157,28 @@ public class GroovyBuilder extends ModuleLevelBuilder {
return toCompilePaths;
}
private GroovycOSProcessHandler runGroovyc(final CompileContext context, ModuleChunk chunk, File tempFile) throws IOException {
//todo xmx
private GroovycOSProcessHandler runGroovyc(final CompileContext context,
ModuleChunk chunk,
File tempFile,
final JpsGroovySettings settings) throws IOException {
ArrayList<String> classpath = new ArrayList<String>(generateClasspath(context, chunk));
if (LOG.isDebugEnabled()) {
LOG.debug("Groovyc classpath: " + classpath);
}
List<String> programParams = ContainerUtilRt.newArrayList(myForStubs ? "stubs" : "groovyc", tempFile.getPath());
if (settings.invokeDynamic) {
programParams.add("--indy");
}
final List<String> cmd = ExternalProcessUtil.buildJavaCommandLine(
getJavaExecutable(chunk),
"org.jetbrains.groovy.compiler.rt.GroovycRunner",
Collections.<String>emptyList(), classpath,
Arrays.asList("-Xmx384m",
Arrays.asList("-Xmx" + settings.heapSize + "m",
"-Dfile.encoding=" + System.getProperty("file.encoding")/*,
"-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239"*/),
Arrays.<String>asList(myForStubs ? "stubs" : "groovyc", tempFile.getPath())
programParams
);
final Process process = Runtime.getRuntime().exec(ArrayUtil.toStringArray(cmd));
@@ -320,8 +331,8 @@ public class GroovyBuilder extends ModuleLevelBuilder {
return SystemProperties.getJavaHome() + "/bin/java";
}
private static List<File> collectChangedFiles(CompileContext context,
DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder) throws IOException {
private List<File> collectChangedFiles(CompileContext context,
DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, final JpsGroovySettings settings) throws IOException {
final ResourcePatterns patterns = ResourcePatterns.KEY.get(context);
assert patterns != null;
final List<File> toCompile = new ArrayList<File>();
@@ -329,6 +340,10 @@ public class GroovyBuilder extends ModuleLevelBuilder {
public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor sourceRoot) throws IOException {
final String path = file.getPath();
if (isGroovyFile(path) && !patterns.isResourceFile(file, sourceRoot.root)) { //todo file type check
if (myForStubs && settings.isExcludedFromStubGeneration(file)) {
return true;
}
toCompile.add(file);
}
return true;
@@ -0,0 +1,52 @@
/*
* Copyright 2000-2013 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.incremental.groovy;
import com.intellij.util.xmlb.XmlSerializer;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.serialization.JpsModelSerializerExtension;
import org.jetbrains.jps.model.serialization.JpsProjectExtensionSerializer;
import java.util.Arrays;
import java.util.List;
/**
* @author peter
*/
public class GroovyModelSerializerExtension extends JpsModelSerializerExtension {
@NotNull
@Override
public List<? extends JpsProjectExtensionSerializer> getProjectExtensionSerializers() {
return Arrays.asList(new JpsProjectExtensionSerializer("groovyc.xml", "GroovyCompilerProjectConfiguration") {
@Override
public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) {
JpsGroovySettings configuration = XmlSerializer.deserialize(componentTag, JpsGroovySettings.class);
if (configuration == null) {
configuration = new JpsGroovySettings();
}
configuration.initExcludes();
project.getContainer().setChild(JpsGroovySettings.ROLE, configuration);
}
@Override
public void saveExtension(@NotNull JpsProject project, @NotNull Element componentTag) {
}
});
}
}
@@ -0,0 +1,80 @@
/*
* Copyright 2000-2013 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.incremental.groovy;
import com.intellij.util.xmlb.annotations.Tag;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsElementChildRole;
import org.jetbrains.jps.model.JpsProject;
import org.jetbrains.jps.model.ex.JpsElementBase;
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;
import org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes;
import org.jetbrains.jps.model.java.impl.compiler.JpsCompilerExcludesImpl;
import org.jetbrains.jps.model.serialization.java.compiler.JpsJavaCompilerConfigurationSerializer;
import java.io.File;
/**
* @author peter
*/
public class JpsGroovySettings extends JpsElementBase<JpsGroovySettings> {
static final JpsElementChildRole<JpsGroovySettings> ROLE = JpsElementChildRoleBase.create("Groovy Compiler Configuration");
public static final String DEFAULT_HEAP_SIZE = "400";
public static final boolean DEFAULT_INVOKE_DYNAMIC = false;
public static final boolean DEFAULT_TRANSFORMS_OK = false;
public String heapSize = DEFAULT_HEAP_SIZE;
public boolean invokeDynamic = DEFAULT_INVOKE_DYNAMIC;
@Tag("excludes") public Element excludes = new Element("aaa");
public boolean transformsOk = DEFAULT_TRANSFORMS_OK;
private JpsCompilerExcludes myExcludeFromStubGeneration;
public JpsGroovySettings() {
}
public JpsGroovySettings(JpsGroovySettings original) {
heapSize = original.heapSize;
invokeDynamic = original.invokeDynamic;
}
void initExcludes() {
myExcludeFromStubGeneration = new JpsCompilerExcludesImpl();
JpsJavaCompilerConfigurationSerializer.readExcludes(excludes, myExcludeFromStubGeneration);
}
@NotNull
@Override
public JpsGroovySettings createCopy() {
return new JpsGroovySettings(this);
}
@Override
public void applyChanges(@NotNull JpsGroovySettings modified) {
}
@NotNull
public static JpsGroovySettings getSettings(@NotNull JpsProject project) {
JpsGroovySettings settings = project.getContainer().getChild(ROLE);
return settings == null ? new JpsGroovySettings() : settings;
}
public boolean isExcludedFromStubGeneration(File file) {
return myExcludeFromStubGeneration != null && myExcludeFromStubGeneration.isExcluded(file);
}
}
@@ -21,8 +21,7 @@ import com.intellij.openapi.compiler.options.ExcludedEntriesConfiguration;
import com.intellij.openapi.components.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.xmlb.annotations.Tag;
import org.jdom.Element;
import org.jetbrains.jps.incremental.groovy.JpsGroovySettings;
/**
* @author peter
@@ -34,27 +33,23 @@ import org.jdom.Element;
@Storage( file = StoragePathMacros.PROJECT_CONFIG_DIR + "/groovyc.xml", scheme = StorageScheme.DIRECTORY_BASED)
}
)
public class GroovyCompilerConfiguration implements PersistentStateComponent<GroovyCompilerConfiguration.MyStateBean>, Disposable {
static final String DEFAULT_HEAP_SIZE = "400";
static final boolean DEFAULT_INVOKE_DYNAMIC = false;
static final boolean DEFAULT_TRANSFORMS_OK = false;
private String myHeapSize = DEFAULT_HEAP_SIZE;
private boolean myInvokeDynamic = DEFAULT_INVOKE_DYNAMIC;
public boolean transformsOk = DEFAULT_TRANSFORMS_OK;
public class GroovyCompilerConfiguration implements PersistentStateComponent<JpsGroovySettings>, Disposable {
private String myHeapSize = JpsGroovySettings.DEFAULT_HEAP_SIZE;
private boolean myInvokeDynamic = JpsGroovySettings.DEFAULT_INVOKE_DYNAMIC;
public boolean transformsOk = JpsGroovySettings.DEFAULT_TRANSFORMS_OK;
private final ExcludedEntriesConfiguration myExcludeFromStubGeneration = new ExcludedEntriesConfiguration();
public GroovyCompilerConfiguration(Project project) {
GroovyCompilerWorkspaceConfiguration workspaceConfiguration = ServiceManager.getService(project, GroovyCompilerWorkspaceConfiguration.class);
loadState(workspaceConfiguration.getState());
workspaceConfiguration.myHeapSize = DEFAULT_HEAP_SIZE;
workspaceConfiguration.transformsOk = DEFAULT_TRANSFORMS_OK;
workspaceConfiguration.myInvokeDynamic = DEFAULT_INVOKE_DYNAMIC;
workspaceConfiguration.myHeapSize = JpsGroovySettings.DEFAULT_HEAP_SIZE;
workspaceConfiguration.transformsOk = JpsGroovySettings.DEFAULT_TRANSFORMS_OK;
workspaceConfiguration.myInvokeDynamic = JpsGroovySettings.DEFAULT_INVOKE_DYNAMIC;
workspaceConfiguration.myExcludeFromStubGeneration.removeAllExcludeEntryDescriptions();
}
public MyStateBean getState() {
final MyStateBean bean = new MyStateBean();
public JpsGroovySettings getState() {
final JpsGroovySettings bean = new JpsGroovySettings();
bean.heapSize = myHeapSize;
bean.invokeDynamic = myInvokeDynamic;
bean.transformsOk = transformsOk;
@@ -70,7 +65,7 @@ public class GroovyCompilerConfiguration implements PersistentStateComponent<Gro
return myExcludeFromStubGeneration;
}
public void loadState(MyStateBean state) {
public void loadState(JpsGroovySettings state) {
myHeapSize = state.heapSize;
myInvokeDynamic = state.invokeDynamic;
transformsOk = state.transformsOk;
@@ -102,13 +97,4 @@ public class GroovyCompilerConfiguration implements PersistentStateComponent<Gro
Disposer.dispose(myExcludeFromStubGeneration);
}
public static class MyStateBean {
public String heapSize = DEFAULT_HEAP_SIZE;
public boolean invokeDynamic = DEFAULT_INVOKE_DYNAMIC;
@Tag("excludes") public Element excludes = new Element("aaa");
public boolean transformsOk = DEFAULT_TRANSFORMS_OK;
}
}
@@ -18,23 +18,25 @@ package org.jetbrains.plugins.groovy.compiler;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.compiler.options.ExcludedEntriesConfiguration;
import com.intellij.openapi.components.*;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.StoragePathMacros;
import com.intellij.openapi.util.Disposer;
import static org.jetbrains.plugins.groovy.compiler.GroovyCompilerConfiguration.MyStateBean;
import org.jetbrains.jps.incremental.groovy.JpsGroovySettings;
/**
* @author peter
*/
@State(name = "GroovyCompilerConfiguration", storages = @Storage( file = StoragePathMacros.WORKSPACE_FILE))
public class GroovyCompilerWorkspaceConfiguration implements PersistentStateComponent<MyStateBean>, Disposable {
String myHeapSize = GroovyCompilerConfiguration.DEFAULT_HEAP_SIZE;
boolean myInvokeDynamic = GroovyCompilerConfiguration.DEFAULT_INVOKE_DYNAMIC;
boolean transformsOk = GroovyCompilerConfiguration.DEFAULT_TRANSFORMS_OK;
public class GroovyCompilerWorkspaceConfiguration implements PersistentStateComponent<JpsGroovySettings>, Disposable {
String myHeapSize = JpsGroovySettings.DEFAULT_HEAP_SIZE;
boolean myInvokeDynamic = JpsGroovySettings.DEFAULT_INVOKE_DYNAMIC;
boolean transformsOk = JpsGroovySettings.DEFAULT_TRANSFORMS_OK;
final ExcludedEntriesConfiguration myExcludeFromStubGeneration = new ExcludedEntriesConfiguration();
public MyStateBean getState() {
final MyStateBean bean = new MyStateBean();
public JpsGroovySettings getState() {
final JpsGroovySettings bean = new JpsGroovySettings();
bean.heapSize = myHeapSize;
bean.invokeDynamic = myInvokeDynamic;
bean.transformsOk = transformsOk;
@@ -42,7 +44,7 @@ public class GroovyCompilerWorkspaceConfiguration implements PersistentStateComp
return bean;
}
public void loadState(MyStateBean state) {
public void loadState(JpsGroovySettings state) {
myHeapSize = state.heapSize;
myInvokeDynamic = state.invokeDynamic;
transformsOk = state.transformsOk;