IDEA-89797 Annotation processors configuration should has two separate fields for generated test sources and generated production sources

This commit is contained in:
Eugene Zhuravlev
2012-10-15 18:50:44 +02:00
parent 890193c2b6
commit 31de58ec12
12 changed files with 82 additions and 45 deletions
@@ -759,7 +759,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
final ProcessorConfigProfile profile = new ProcessorConfigProfileImpl(myDefaultProcessorsProfile);
profile.setName("Profile" + (++profileIndex));
profile.setEnabled(isEnabled);
profile.setGeneratedSourcesDirectoryName(dirName);
profile.setGeneratedSourcesDirectoryName(dirName, false);
for (String moduleName : entry.getValue()) {
profile.addModuleName(moduleName);
}
@@ -15,7 +15,6 @@
*/
package com.intellij.compiler.options;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import com.intellij.openapi.fileChooser.FileChooser;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
@@ -27,6 +26,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.*;
import com.intellij.ui.table.JBTable;
import com.intellij.util.ui.EditableModel;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
@@ -54,7 +54,8 @@ public class ProcessorProfilePanel extends JPanel {
private JRadioButton myRbClasspath;
private JRadioButton myRbProcessorsPath;
private TextFieldWithBrowseButton myProcessorPathField;
private JTextField myGeneratedSourcesDirNameField;
private JTextField myGeneratedProductionDirField;
private JTextField myGeneratedTestsDirField;
private ProcessorTableModel myProcessorsModel;
private JCheckBox myCbEnableProcessing;
private JBTable myProcessorTable;
@@ -109,8 +110,8 @@ public class ProcessorProfilePanel extends JPanel {
myOptionsPanel = createTablePanel(myOptionsTable);
optionsTablePanel.add(myOptionsPanel, BorderLayout.CENTER);
myGeneratedSourcesDirNameField = new JTextField();
myGeneratedProductionDirField = new JTextField();
myGeneratedTestsDirField = new JTextField();
final JLabel warning = new JLabel("<html>WARNING!<br>" +
/*"All source files located in the generated sources output directory WILL BE EXCLUDED from annotation processing. " +*/
@@ -133,17 +134,22 @@ public class ProcessorProfilePanel extends JPanel {
add(noteMessage,
new GridBagConstraints(0, 3, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0));
add(new JLabel("Directory name:"),
add(new JLabel("Production sources directory:"),
new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0));
add(myGeneratedSourcesDirNameField,
add(myGeneratedProductionDirField,
new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0));
add(new JLabel("Test sources directory:"),
new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0));
add(myGeneratedTestsDirField,
new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0));
add(processorTablePanel,
new GridBagConstraints(0, 5, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0));
add(optionsTablePanel,
new GridBagConstraints(0, 6, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0));
add(optionsTablePanel,
new GridBagConstraints(0, 7, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(10, 0, 0, 0), 0, 0));
add(warning,
new GridBagConstraints(0, 7, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0));
new GridBagConstraints(0, 8, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 5, 0, 0), 0, 0));
myRbClasspath.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
@@ -175,8 +181,10 @@ public class ProcessorProfilePanel extends JPanel {
(config.isObtainProcessorsFromClasspath()? myRbClasspath : myRbProcessorsPath).setSelected(true);
myProcessorPathField.setText(FileUtil.toSystemDependentName(config.getProcessorPath()));
final String srcDirName = config.getGeneratedSourcesDirectoryName();
myGeneratedSourcesDirNameField.setText(srcDirName != null? srcDirName.trim() : "");
final String productionDirName = config.getGeneratedSourcesDirectoryName(false);
myGeneratedProductionDirField.setText(productionDirName != null? productionDirName.trim() : "");
final String testsDirName = config.getGeneratedSourcesDirectoryName(true);
myGeneratedTestsDirField.setText(testsDirName != null? testsDirName.trim() : "");
myProcessorsModel.setProcessors(config.getProcessors());
myOptionsModel.setOptions(config.getProcessorOptions());
@@ -187,9 +195,11 @@ public class ProcessorProfilePanel extends JPanel {
profile.setEnabled(myCbEnableProcessing.isSelected());
profile.setObtainProcessorsFromClasspath(myRbClasspath.isSelected());
profile.setProcessorPath(myProcessorPathField.getText().trim());
final String dirName = myGeneratedSourcesDirNameField.getText().trim();
profile.setGeneratedSourcesDirectoryName(StringUtil.isEmpty(dirName)? null : dirName);
final String productionDir = myGeneratedProductionDirField.getText().trim();
profile.setGeneratedSourcesDirectoryName(StringUtil.isEmpty(productionDir)? null : productionDir, false);
final String testsDir = myGeneratedTestsDirField.getText().trim();
profile.setGeneratedSourcesDirectoryName(StringUtil.isEmpty(testsDir)? null : testsDir, true);
profile.clearProcessors();
for (String processor : myProcessorsModel.getProcessors()) {
@@ -228,7 +238,8 @@ public class ProcessorProfilePanel extends JPanel {
myProcessorPathField.setEnabled(enabled && useProcessorpath);
updateTable(myProcessorPanel, myProcessorTable, enabled);
updateTable(myOptionsPanel, myOptionsTable, enabled);
myGeneratedSourcesDirNameField.setEnabled(enabled);
myGeneratedProductionDirField.setEnabled(enabled);
myGeneratedTestsDirField.setEnabled(enabled);
}
private static void updateTable(final JPanel tablePanel, final JBTable table, boolean enabled) {
@@ -216,7 +216,7 @@ public class CompilerPaths {
public static String getAnnotationProcessorsGenerationPath(Module module) {
final CompilerConfiguration config = CompilerConfiguration.getInstance(module.getProject());
final String sourceDirName = config.getAnnotationProcessingConfiguration(module).getGeneratedSourcesDirectoryName();
final String sourceDirName = config.getAnnotationProcessingConfiguration(module).getGeneratedSourcesDirectoryName(false);
if (!StringUtil.isEmpty(sourceDirName)) {
final String[] roots = ModuleRootManager.getInstance(module).getContentRootUrls();
if (roots.length == 0) {
@@ -363,12 +363,14 @@ public class IncProjectBuilder {
}
}
final Set<File> annotationOutputs = new HashSet<File>(); // separate collection because no root intersection checks needed for annotation generated sources
final Set<File> annotationOutputs = new THashSet<File>(FileUtil.FILE_HASHING_STRATEGY); // separate collection because no root intersection checks needed for annotation generated sources
for (JavaModuleBuildTargetType type : JavaModuleBuildTargetType.ALL_TYPES) {
for (ModuleBuildTarget target : projectDescriptor.getBuildTargetIndex().getAllTargets(type)) {
final ProcessorConfigProfile profile = context.getAnnotationProcessingProfile(target.getModule());
if (profile.isEnabled()) {
File annotationOut = paths.getAnnotationProcessorGeneratedSourcesOutputDir(target.getModule(), target.isTests(), profile.getGeneratedSourcesDirectoryName());
final File annotationOut = paths.getAnnotationProcessorGeneratedSourcesOutputDir(
target.getModule(), target.isTests(), profile.getGeneratedSourcesDirectoryName(target.isTests())
);
if (annotationOut != null) {
annotationOutputs.add(annotationOut);
}
@@ -751,9 +751,10 @@ public class JavaBuilder extends ModuleLevelBuilder {
options.add("-A" + optionEntry.getKey() + "=" + optionEntry.getValue());
}
final File srcOutput = context.getProjectPaths()
.getAnnotationProcessorGeneratedSourcesOutputDir(chunk.getModules().iterator().next(), chunk.containsTests(),
profile.getGeneratedSourcesDirectoryName());
final boolean forTests = chunk.containsTests();
final File srcOutput = context.getProjectPaths().getAnnotationProcessorGeneratedSourcesOutputDir(
chunk.getModules().iterator().next(), forTests, profile.getGeneratedSourcesDirectoryName(forTests)
);
if (srcOutput != null) {
srcOutput.mkdirs();
options.add("-s");
@@ -32,7 +32,7 @@ public interface AnnotationProcessingConfiguration {
String getProcessorPath();
@Nullable
String getGeneratedSourcesDirectoryName();
String getGeneratedSourcesDirectoryName(boolean forTests);
@NotNull
Set<String> getProcessors();
@@ -22,7 +22,7 @@ public interface ProcessorConfigProfile extends AnnotationProcessingConfiguratio
void setObtainProcessorsFromClasspath(boolean value);
void setGeneratedSourcesDirectoryName(@Nullable String generatedSourcesDirectoryName);
void setGeneratedSourcesDirectoryName(@Nullable String generatedSourcesDirectoryName, boolean forTests);
@NotNull
Set<String> getModuleNames();
@@ -33,7 +33,8 @@ public final class ProcessorConfigProfileImpl implements ProcessorConfigProfile
private final Set<String> myProcessors = new HashSet<String>(); // empty list means all discovered
private final Map<String, String> myProcessorOptions = new HashMap<String, String>(); // key=value map of options
@Nullable
private String myGeneratedSourcesDirectoryName = null; // null means 'auto'
private String myGeneratedProductionDirectoryName = null; // null means 'auto'
private String myGeneratedTestsDirectoryName = null; // null means 'auto'
private final Set<String> myModuleNames = new HashSet<String>();
public ProcessorConfigProfileImpl(String name) {
@@ -54,7 +55,8 @@ public final class ProcessorConfigProfileImpl implements ProcessorConfigProfile
myProcessors.addAll(other.getProcessors());
myProcessorOptions.clear();
myProcessorOptions.putAll(other.getProcessorOptions());
myGeneratedSourcesDirectoryName = other.getGeneratedSourcesDirectoryName();
myGeneratedProductionDirectoryName = other.getGeneratedSourcesDirectoryName(false);
myGeneratedTestsDirectoryName = other.getGeneratedSourcesDirectoryName(true);
myModuleNames.clear();
myModuleNames.addAll(other.getModuleNames());
}
@@ -102,13 +104,18 @@ public final class ProcessorConfigProfileImpl implements ProcessorConfigProfile
@Override
@Nullable
public String getGeneratedSourcesDirectoryName() {
return myGeneratedSourcesDirectoryName;
public String getGeneratedSourcesDirectoryName(boolean forTests) {
return forTests? myGeneratedTestsDirectoryName : myGeneratedProductionDirectoryName;
}
@Override
public void setGeneratedSourcesDirectoryName(@Nullable String generatedSourcesDirectoryName) {
myGeneratedSourcesDirectoryName = generatedSourcesDirectoryName;
public void setGeneratedSourcesDirectoryName(@Nullable String name, boolean forTests) {
if (forTests) {
myGeneratedTestsDirectoryName = name;
}
else {
myGeneratedProductionDirectoryName = name;
}
}
@Override
@@ -194,9 +201,14 @@ public final class ProcessorConfigProfileImpl implements ProcessorConfigProfile
if (myEnabled != profile.myEnabled) return false;
if (myObtainProcessorsFromClasspath != profile.myObtainProcessorsFromClasspath) return false;
if (myGeneratedSourcesDirectoryName != null
? !myGeneratedSourcesDirectoryName.equals(profile.myGeneratedSourcesDirectoryName)
: profile.myGeneratedSourcesDirectoryName != null) {
if (myGeneratedProductionDirectoryName != null
? !myGeneratedProductionDirectoryName.equals(profile.myGeneratedProductionDirectoryName)
: profile.myGeneratedProductionDirectoryName != null) {
return false;
}
if (myGeneratedTestsDirectoryName != null
? !myGeneratedTestsDirectoryName.equals(profile.myGeneratedTestsDirectoryName)
: profile.myGeneratedTestsDirectoryName != null) {
return false;
}
if (!myModuleNames.equals(profile.myModuleNames)) return false;
@@ -216,7 +228,8 @@ public final class ProcessorConfigProfileImpl implements ProcessorConfigProfile
result = 31 * result + (myProcessorPath != null ? myProcessorPath.hashCode() : 0);
result = 31 * result + myProcessors.hashCode();
result = 31 * result + myProcessorOptions.hashCode();
result = 31 * result + (myGeneratedSourcesDirectoryName != null ? myGeneratedSourcesDirectoryName.hashCode() : 0);
result = 31 * result + (myGeneratedProductionDirectoryName != null ? myGeneratedProductionDirectoryName.hashCode() : 0);
result = 31 * result + (myGeneratedTestsDirectoryName != null ? myGeneratedTestsDirectoryName.hashCode() : 0);
result = 31 * result + myModuleNames.hashCode();
return result;
}
@@ -45,7 +45,10 @@ public class AnnotationProcessorProfileSerializer {
profile.setEnabled(Boolean.valueOf(element.getAttributeValue(ENABLED, "false")));
final Element srcOutput = element.getChild("sourceOutputDir");
profile.setGeneratedSourcesDirectoryName(srcOutput != null ? srcOutput.getAttributeValue(NAME) : null);
profile.setGeneratedSourcesDirectoryName(srcOutput != null ? srcOutput.getAttributeValue(NAME) : null, false);
final Element srcTestOutput = element.getChild("sourceTestOutputDir");
profile.setGeneratedSourcesDirectoryName(srcTestOutput != null ? srcTestOutput.getAttributeValue(NAME) : null, true);
profile.clearProcessorOptions();
for (Object optionElement : element.getChildren(OPTION)) {
@@ -94,10 +97,14 @@ public class AnnotationProcessorProfileSerializer {
element.setAttribute(NAME, profile.getName());
element.setAttribute(ENABLED, Boolean.toString(profile.isEnabled()));
final String srcDirName = profile.getGeneratedSourcesDirectoryName();
final String srcDirName = profile.getGeneratedSourcesDirectoryName(false);
if (srcDirName != null) {
addChild(element, "sourceOutputDir").setAttribute(NAME, srcDirName);
}
final String testSrcDirName = profile.getGeneratedSourcesDirectoryName(true);
if (testSrcDirName != null) {
addChild(element, "sourceTestOutputDir").setAttribute(NAME, testSrcDirName);
}
final Map<String, String> options = profile.getProcessorOptions();
if (!options.isEmpty()) {
@@ -1,12 +1,12 @@
package org.jetbrains.jps.model.serialization;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.jps.util.JpsPathUtil;
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.java.compiler.JpsJavaCompilerOptions;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import org.jetbrains.jps.util.JpsPathUtil;
public class JpsCompilerConfigurationTest extends JpsSerializationTestCase {
public void testLoadFromIpr() {
@@ -29,7 +29,7 @@ public class JpsCompilerConfigurationTest extends JpsSerializationTestCase {
assertEquals(FileUtil.toSystemDependentName(JpsPathUtil.urlToPath(getUrl("src"))), defaultProfile.getProcessorPath());
assertEquals("b", defaultProfile.getProcessorOptions().get("a"));
assertEquals("d", defaultProfile.getProcessorOptions().get("c"));
assertEquals("gen", defaultProfile.getGeneratedSourcesDirectoryName());
assertEquals("gen", defaultProfile.getGeneratedSourcesDirectoryName(false));
JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
assertFalse(isExcluded(excludes, "src/nonrec/x/Y.java"));
assertTrue(isExcluded(excludes, "src/nonrec/Y.java"));
@@ -19,15 +19,13 @@ import com.intellij.compiler.CompilerConfiguration;
import com.intellij.compiler.CompilerConfigurationImpl;
import com.intellij.openapi.compiler.options.ExcludeEntryDescription;
import com.intellij.openapi.compiler.options.ExcludedEntriesConfiguration;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.libraries.LibraryTable;
import org.jetbrains.idea.maven.utils.MavenJDOMUtil;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.JarFileSystem;
@@ -41,14 +39,19 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.idea.maven.model.MavenArtifact;
import org.jetbrains.idea.maven.model.MavenConstants;
import org.jetbrains.idea.maven.project.*;
import org.jetbrains.idea.maven.utils.MavenJDOMUtil;
import org.jetbrains.idea.maven.utils.MavenUtil;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl;
import java.io.File;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class MavenModuleImporter {
@@ -352,7 +355,7 @@ public class MavenModuleImporter {
defaultMavenProfile = new ProcessorConfigProfileImpl(MAVEN_DEFAULT_ANNOTATION_PROFILE);
defaultMavenProfile.setEnabled(true);
defaultMavenProfile.setObtainProcessorsFromClasspath(true);
defaultMavenProfile.setGeneratedSourcesDirectoryName("target/generated-sources/annotations");
defaultMavenProfile.setGeneratedSourcesDirectoryName("target/generated-sources/annotations", false);
compilerConfiguration.addModuleProcessorProfile(defaultMavenProfile);
}
@@ -375,7 +378,7 @@ public class MavenModuleImporter {
compilerConfiguration.addModuleProcessorProfile(moduleProfile);
}
moduleProfile.setGeneratedSourcesDirectoryName(annotationProcessorDirectory);
moduleProfile.setGeneratedSourcesDirectoryName(annotationProcessorDirectory, false);
moduleProfile.clearProcessorOptions();
for (Map.Entry<String, String> entry : options.entrySet()) {
@@ -129,7 +129,7 @@ class AnnotationProcessorImportingTest extends MavenImportingTestCase {
def compilerConfiguration = ((CompilerConfigurationImpl)CompilerConfiguration.getInstance(myProject))
assert compilerConfiguration.findModuleProcessorProfile(MavenModuleImporter.MAVEN_DEFAULT_ANNOTATION_PROFILE) == null
assert compilerConfiguration.findModuleProcessorProfile(MavenModuleImporter.PROFILE_PREFIX + "project").getGeneratedSourcesDirectoryName().replace('\\', '/').endsWith("out/generated")
assert compilerConfiguration.findModuleProcessorProfile(MavenModuleImporter.PROFILE_PREFIX + "project").getGeneratedSourcesDirectoryName(false).replace('\\', '/').endsWith("out/generated")
}
public void testImportAnnotationProcessorOptions() {