diff --git a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java index 25805ab30b13..c1dfb58dd79c 100644 --- a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java @@ -171,8 +171,9 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements addChild(newChild, JpsJavaCompilerConfigurationSerializer.ENTRY).setAttribute(JpsJavaCompilerConfigurationSerializer.NAME, pattern); } + boolean savingStateInNewFormatAllowed = Registry.is("saving.state.in.new.format.is.allowed", false); if ((myWildcardPatternsInitialized || !myWildcardPatterns.isEmpty()) && - (!Registry.is("saving.state.in.new.format.is.allowed", false) || !DEFAULT_WILDCARD_PATTERNS.equals(myWildcardPatterns))) { + (!savingStateInNewFormatAllowed || !DEFAULT_WILDCARD_PATTERNS.equals(myWildcardPatterns))) { final Element wildcardPatterns = addChild(state, JpsJavaCompilerConfigurationSerializer.WILDCARD_RESOURCE_PATTERNS); for (final String wildcardPattern : myWildcardPatterns) { addChild(wildcardPatterns, JpsJavaCompilerConfigurationSerializer.ENTRY) @@ -180,12 +181,26 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements } } - final Element annotationProcessingSettings = addChild(state, JpsJavaCompilerConfigurationSerializer.ANNOTATION_PROCESSING); - final Element defaultProfileElem = addChild(annotationProcessingSettings, "profile").setAttribute("default", "true"); - AnnotationProcessorProfileSerializer.writeExternal(myDefaultProcessorsProfile, defaultProfileElem); + Element annotationProcessingSettings = new Element(JpsJavaCompilerConfigurationSerializer.ANNOTATION_PROCESSING); + + Element profileElement = new Element("profile"); + profileElement.setAttribute("default", "true"); + AnnotationProcessorProfileSerializer.writeExternal(myDefaultProcessorsProfile, profileElement); + if (!savingStateInNewFormatAllowed || !JDOMUtil.isEmpty(profileElement, 2)) { + annotationProcessingSettings.addContent(profileElement); + } + for (ProcessorConfigProfile profile : myModuleProcessorProfiles) { - final Element profileElem = addChild(annotationProcessingSettings, "profile").setAttribute("default", "false"); - AnnotationProcessorProfileSerializer.writeExternal(profile, profileElem); + Element element = new Element("profile"); + if (!savingStateInNewFormatAllowed) { + element.setAttribute("default", "false"); + } + AnnotationProcessorProfileSerializer.writeExternal(profile, element); + annotationProcessingSettings.addContent(element); + } + + if (!savingStateInNewFormatAllowed || !JDOMUtil.isEmpty(annotationProcessingSettings)) { + state.addContent(annotationProcessingSettings); } if (!StringUtil.isEmpty(myBytecodeTargetLevel) || !myModuleBytecodeTarget.isEmpty()) { diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/AnnotationProcessorProfileSerializer.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/AnnotationProcessorProfileSerializer.java index adebd336ff86..d4b94d3db6ac 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/AnnotationProcessorProfileSerializer.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/java/compiler/AnnotationProcessorProfileSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -16,8 +16,10 @@ package org.jetbrains.jps.model.serialization.java.compiler; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import org.jdom.Element; +import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile; import java.io.File; @@ -100,9 +102,11 @@ public class AnnotationProcessorProfileSerializer { } } - public static void writeExternal(ProcessorConfigProfile profile, final Element element) { + public static void writeExternal(@NotNull ProcessorConfigProfile profile, @NotNull Element element) { element.setAttribute(NAME, profile.getName()); - element.setAttribute(ENABLED, Boolean.toString(profile.isEnabled())); + if (!Registry.is("saving.state.in.new.format.is.allowed", false) || profile.isEnabled()) { + element.setAttribute(ENABLED, Boolean.toString(profile.isEnabled())); + } final String srcDirName = profile.getGeneratedSourcesDirectoryName(false); if (!StringUtil.equals(ProcessorConfigProfile.DEFAULT_PRODUCTION_DIR_NAME, srcDirName)) { @@ -135,10 +139,18 @@ public class AnnotationProcessorProfileSerializer { } } - final Element pathElement = addChild(element, "processorPath").setAttribute("useClasspath", Boolean.toString( - profile.isObtainProcessorsFromClasspath())); + + Element pathElement = null; + if (!Registry.is("saving.state.in.new.format.is.allowed", false) || !profile.isObtainProcessorsFromClasspath()) { + pathElement = addChild(element, "processorPath"); + pathElement.setAttribute("useClasspath", Boolean.toString(profile.isObtainProcessorsFromClasspath())); + } + final String path = profile.getProcessorPath(); if (!StringUtil.isEmpty(path)) { + if (pathElement == null) { + pathElement = addChild(element, "processorPath"); + } final StringTokenizer tokenizer = new StringTokenizer(path, File.pathSeparator, false); while (tokenizer.hasMoreTokens()) { final String token = tokenizer.nextToken(); diff --git a/platform/util/src/com/intellij/openapi/util/JDOMUtil.java b/platform/util/src/com/intellij/openapi/util/JDOMUtil.java index edd24378e9e9..722bb062cbe5 100644 --- a/platform/util/src/com/intellij/openapi/util/JDOMUtil.java +++ b/platform/util/src/com/intellij/openapi/util/JDOMUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -770,4 +770,8 @@ public class JDOMUtil { public static boolean isEmpty(@Nullable Element element) { return element == null || (element.getAttributes().isEmpty() && element.getContent().isEmpty()); } + + public static boolean isEmpty(@Nullable Element element, int attributeCount) { + return element == null || (element.getAttributes().size() == attributeCount && element.getContent().isEmpty()); + } }