use of org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile in project intellij-community by JetBrains.
the class JpsCompilerConfigurationTest method doTest.
private void doTest(final String path) {
loadProject(path);
JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getCompilerConfiguration(myProject);
assertNotNull(configuration);
assertFalse(configuration.isClearOutputDirectoryOnRebuild());
assertFalse(configuration.isAddNotNullAssertions());
ProcessorConfigProfile defaultProfile = configuration.getDefaultAnnotationProcessingProfile();
assertTrue(defaultProfile.isEnabled());
assertFalse(defaultProfile.isObtainProcessorsFromClasspath());
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(false));
JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
assertFalse(isExcluded(excludes, "src/nonrec/x/Y.java"));
assertTrue(isExcluded(excludes, "src/nonrec/Y.java"));
assertTrue(isExcluded(excludes, "src/rec/x/Y.java"));
assertTrue(isExcluded(excludes, "src/rec/Y.java"));
assertTrue(isExcluded(excludes, "src/A.java"));
assertFalse(isExcluded(excludes, "src/B.java"));
JpsJavaCompilerOptions options = configuration.getCurrentCompilerOptions();
assertNotNull(options);
assertEquals(512, options.MAXIMUM_HEAP_SIZE);
assertFalse(options.DEBUGGING_INFO);
assertTrue(options.GENERATE_NO_WARNINGS);
assertEquals("-Xlint", options.ADDITIONAL_OPTIONS_STRING);
}
use of org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile in project intellij-community by JetBrains.
the class ModuleBuildTarget method computeRootDescriptors.
@NotNull
@Override
public List<JavaSourceRootDescriptor> computeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
List<JavaSourceRootDescriptor> roots = new ArrayList<>();
JavaSourceRootType type = isTests() ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE;
Iterable<ExcludedJavaSourceRootProvider> excludedRootProviders = JpsServiceManager.getInstance().getExtensions(ExcludedJavaSourceRootProvider.class);
final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(myModule.getProject());
roots_loop: for (JpsTypedModuleSourceRoot<JavaSourceRootProperties> sourceRoot : myModule.getSourceRoots(type)) {
if (index.isExcludedFromModule(sourceRoot.getFile(), myModule)) {
continue;
}
for (ExcludedJavaSourceRootProvider provider : excludedRootProviders) {
if (provider.isExcludedFromCompilation(myModule, sourceRoot)) {
continue roots_loop;
}
}
final String packagePrefix = sourceRoot.getProperties().getPackagePrefix();
// consider annotation processors output for generated sources, if contained under some source root
Set<File> excludes = computeRootExcludes(sourceRoot.getFile(), index);
final ProcessorConfigProfile profile = compilerConfig.getAnnotationProcessingProfile(myModule);
if (profile.isEnabled()) {
final File outputDir = ProjectPaths.getAnnotationProcessorGeneratedSourcesOutputDir(myModule, JavaSourceRootType.TEST_SOURCE == sourceRoot.getRootType(), profile);
if (outputDir != null && FileUtil.isAncestor(sourceRoot.getFile(), outputDir, true)) {
excludes = ContainerUtil.newTroveSet(FileUtil.FILE_HASHING_STRATEGY, excludes);
excludes.add(outputDir);
}
}
roots.add(new JavaSourceRootDescriptor(sourceRoot.getFile(), this, false, false, packagePrefix, excludes));
}
return roots;
}
use of org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile in project intellij-community by JetBrains.
the class GreclipseBuilder method build.
@Override
public ExitCode build(final CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
if (!useGreclipse(context))
return ModuleLevelBuilder.ExitCode.NOTHING_DONE;
try {
final List<File> toCompile = myHelper.collectChangedFiles(context, dirtyFilesHolder, false, true, Ref.create(false));
if (toCompile.isEmpty()) {
return ExitCode.NOTHING_DONE;
}
Map<ModuleBuildTarget, String> outputDirs = GroovyBuilder.getCanonicalModuleOutputs(context, chunk, this);
if (outputDirs == null) {
return ExitCode.ABORT;
}
JpsProject project = context.getProjectDescriptor().getProject();
GreclipseSettings greclipseSettings = GreclipseJpsCompilerSettings.getSettings(project);
if (greclipseSettings == null) {
String message = "Compiler settings component not initialized for " + project;
LOG.error(message);
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message));
return ExitCode.ABORT;
}
ClassLoader loader = createGreclipseLoader(greclipseSettings.greclipsePath);
if (loader == null) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "Invalid jar path in the compiler settings: '" + greclipseSettings.greclipsePath + "'"));
return ExitCode.ABORT;
}
final JpsJavaExtensionService javaExt = JpsJavaExtensionService.getInstance();
final JpsJavaCompilerConfiguration compilerConfig = javaExt.getCompilerConfiguration(project);
assert compilerConfig != null;
final Set<JpsModule> modules = chunk.getModules();
ProcessorConfigProfile profile = null;
if (modules.size() == 1) {
profile = compilerConfig.getAnnotationProcessingProfile(modules.iterator().next());
} else {
String message = JavaBuilder.validateCycle(chunk, javaExt, compilerConfig, modules);
if (message != null) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, message));
return ExitCode.ABORT;
}
}
String mainOutputDir = outputDirs.get(chunk.representativeTarget());
final List<String> args = createCommandLine(context, chunk, toCompile, mainOutputDir, profile, greclipseSettings);
if (Utils.IS_TEST_MODE || LOG.isDebugEnabled()) {
LOG.debug("Compiling with args: " + args);
}
Boolean notified = COMPILER_VERSION_INFO.get(context);
if (notified != Boolean.TRUE) {
context.processMessage(new CompilerMessage("", BuildMessage.Kind.INFO, "Using Groovy-Eclipse to compile Java & Groovy sources"));
COMPILER_VERSION_INFO.set(context, Boolean.TRUE);
}
context.processMessage(new ProgressMessage("Compiling java & groovy [" + chunk.getPresentableShortName() + "]"));
StringWriter out = new StringWriter();
StringWriter err = new StringWriter();
HashMap<String, List<String>> outputMap = ContainerUtil.newHashMap();
boolean success = performCompilation(args, out, err, outputMap, context, chunk);
List<GroovycOutputParser.OutputItem> items = ContainerUtil.newArrayList();
for (String src : outputMap.keySet()) {
//noinspection ConstantConditions
for (String classFile : outputMap.get(src)) {
items.add(new GroovycOutputParser.OutputItem(FileUtil.toSystemIndependentName(mainOutputDir + classFile), FileUtil.toSystemIndependentName(src)));
}
}
MultiMap<ModuleBuildTarget, GroovycOutputParser.OutputItem> successfullyCompiled = myHelper.processCompiledFiles(context, chunk, outputDirs, mainOutputDir, items);
EclipseOutputParser parser = new EclipseOutputParser(getPresentableName(), chunk);
List<CompilerMessage> messages = ContainerUtil.concat(parser.parseMessages(out.toString()), parser.parseMessages(err.toString()));
boolean hasError = false;
for (CompilerMessage message : messages) {
if (message.getKind() == BuildMessage.Kind.ERROR) {
hasError = true;
}
context.processMessage(message);
}
if (!success && !hasError) {
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, "Compilation failed"));
}
myHelper.updateDependencies(context, toCompile, successfullyCompiled, new DefaultOutputConsumer(outputConsumer), this);
return ExitCode.OK;
} catch (Exception e) {
throw new ProjectBuildException(e);
}
}
use of org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile in project android by JetBrains.
the class AndroidBuilderTest method testGeneratedSources.
public void testGeneratedSources() throws Exception {
final MyExecutor executor = new MyExecutor("com.example.simple");
final JpsModule module = setUpSimpleAndroidStructure(new String[] { "src", "gen" }, executor, null).getFirst();
rebuildAll();
checkBuildLog(executor, "expected_log");
checkMakeUpToDate(executor);
change(getProjectPath("gen/com/example/simple/R.java"), AndroidCommonUtils.AUTOGENERATED_JAVA_FILE_HEADER + "\n\n" + "package com.example.simple;\n" + "public class R {}");
makeAll().assertSuccessful();
checkBuildLog(executor, "expected_log_1");
assertCompiled(JavaBuilder.BUILDER_NAME, "targets/java-production/module/android/copied_sources/com/example/simple/MyGeneratedClass.java");
checkMakeUpToDate(executor);
change(getProjectPath("gen/com/example/simple/R.java"));
checkMakeUpToDate(executor);
change(getProjectPath("gen/com/example/simple/MyGeneratedClass.java"));
makeAll().assertSuccessful();
checkBuildLog(executor, "expected_log_3");
assertCompiled(JavaBuilder.BUILDER_NAME, "targets/java-production/module/android/copied_sources/com/example/simple/MyGeneratedClass.java");
checkMakeUpToDate(executor);
change(getProjectPath("gen/com/example/simple/MyGeneratedClass.java"), AndroidCommonUtils.AUTOGENERATED_JAVA_FILE_HEADER + "\n\n" + "package com.example.simple;\n" + "public class MyGeneratedClass {}");
makeAll().assertSuccessful();
checkBuildLog(executor, "expected_log_4");
assertCompiled(JavaBuilder.BUILDER_NAME);
checkMakeUpToDate(executor);
change(getProjectPath("gen/com/example/simple/MyGeneratedClass.java"), "package com.example.simple;\n" + "public class MyGeneratedClass {}");
change(getProjectPath("src/com/example/simple/MyActivity.java"), "package com.example.simple;\n" + "import android.app.Activity;\n" + "import android.os.Bundle;\n" + "public class MyActivity extends Activity {\n" + " public void onCreate(Bundle savedInstanceState) {\n" + " super.onCreate(savedInstanceState);\n" + " new MyGeneratedClass();" + " }\n" + "}\n");
makeAll().assertSuccessful();
checkBuildLog(executor, "expected_log_5");
assertCompiled(JavaBuilder.BUILDER_NAME, "root/src/com/example/simple/MyActivity.java", "targets/java-production/module/android/copied_sources/com/example/simple/MyGeneratedClass.java");
checkMakeUpToDate(executor);
final JpsJavaCompilerConfiguration compilerConfig = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(myProject);
final ProcessorConfigProfile profile = compilerConfig.getAnnotationProcessingProfile(module);
profile.setEnabled(true);
profile.setOutputRelativeToContentRoot(true);
profile.setGeneratedSourcesDirectoryName("gen", false);
final BuildResult result = makeAll();
result.assertFailed();
final List<BuildMessage> warnMessages = result.getMessages(BuildMessage.Kind.WARNING);
boolean containsForciblyExcludedRootWarn = false;
for (BuildMessage message : warnMessages) {
if (message.getMessageText().endsWith("was forcibly excluded by the IDE, so custom generated files won't be compiled")) {
containsForciblyExcludedRootWarn = true;
}
}
assertTrue(containsForciblyExcludedRootWarn);
}
use of org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile in project intellij-community by JetBrains.
the class CompilerConfigurationImpl method readExternal.
public void readExternal(Element parentNode) {
myState = XmlSerializer.deserialize(parentNode, State.class);
if (!myProject.isDefault()) {
for (Element option : parentNode.getChildren("option")) {
if ("DEFAULT_COMPILER".equals(option.getAttributeValue("name"))) {
break;
}
}
if (myState.BUILD_PROCESS_HEAP_SIZE == DEFAULT_BUILD_PROCESS_HEAP_SIZE) {
final CompilerWorkspaceConfiguration workspace = CompilerWorkspaceConfiguration.getInstance(myProject);
// older version compatibility: as a fallback load this setting from workspace
myState.BUILD_PROCESS_HEAP_SIZE = workspace.COMPILER_PROCESS_HEAP_SIZE;
}
}
final Element notNullAssertions = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.ADD_NOTNULL_ASSERTIONS);
if (notNullAssertions != null) {
myAddNotNullAssertions = Boolean.valueOf(notNullAssertions.getAttributeValue(JpsJavaCompilerConfigurationSerializer.ENABLED, "true"));
}
Element node = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.EXCLUDE_FROM_COMPILE);
if (node != null) {
myExcludesConfiguration.readExternal(node);
}
try {
removeRegexpPatterns();
node = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.RESOURCE_EXTENSIONS);
if (node != null) {
for (final Object o : node.getChildren(JpsJavaCompilerConfigurationSerializer.ENTRY)) {
Element element = (Element) o;
String pattern = element.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME);
if (!StringUtil.isEmpty(pattern)) {
addRegexpPattern(pattern);
}
}
}
node = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.WILDCARD_RESOURCE_PATTERNS);
if (node != null) {
myWildcardPatternsInitialized = true;
removeWildcardPatterns();
for (Element element : node.getChildren(JpsJavaCompilerConfigurationSerializer.ENTRY)) {
String pattern = element.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME);
if (!StringUtil.isEmpty(pattern)) {
addWildcardResourcePattern(pattern);
}
}
}
} catch (MalformedPatternException e) {
LOG.error(e);
}
myModuleProcessorProfiles.clear();
myProcessorsProfilesMap = null;
final Element annotationProcessingSettings = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.ANNOTATION_PROCESSING);
if (annotationProcessingSettings != null) {
final List profiles = annotationProcessingSettings.getChildren("profile");
if (!profiles.isEmpty()) {
for (Object elem : profiles) {
final Element profileElement = (Element) elem;
final boolean isDefault = "true".equals(profileElement.getAttributeValue("default"));
if (isDefault) {
AnnotationProcessorProfileSerializer.readExternal(myDefaultProcessorsProfile, profileElement);
} else {
final ProcessorConfigProfile profile = new ProcessorConfigProfileImpl("");
AnnotationProcessorProfileSerializer.readExternal(profile, profileElement);
myModuleProcessorProfiles.add(profile);
}
}
} else {
// assuming older format
loadProfilesFromOldFormat(annotationProcessingSettings);
}
}
myBytecodeTargetLevel = null;
myModuleBytecodeTarget.clear();
final Element bytecodeTargetElement = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.BYTECODE_TARGET_LEVEL);
if (bytecodeTargetElement != null) {
myBytecodeTargetLevel = bytecodeTargetElement.getAttributeValue(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE);
for (Element elem : bytecodeTargetElement.getChildren(JpsJavaCompilerConfigurationSerializer.MODULE)) {
final String name = elem.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME);
if (name == null) {
continue;
}
final String target = elem.getAttributeValue(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE);
if (target == null) {
continue;
}
myModuleBytecodeTarget.put(name, target);
}
}
}
Aggregations