use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.
the class JavaBuilder method compile.
private ExitCode compile(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, Collection<File> files, OutputConsumer outputConsumer, JavaCompilingTool compilingTool) throws Exception {
ExitCode exitCode = ExitCode.NOTHING_DONE;
final boolean hasSourcesToCompile = !files.isEmpty();
if (!hasSourcesToCompile && !dirtyFilesHolder.hasRemovedFiles()) {
return exitCode;
}
final ProjectDescriptor pd = context.getProjectDescriptor();
JavaBuilderUtil.ensureModuleHasJdk(chunk.representativeTarget().getModule(), context, BUILDER_NAME);
final Collection<File> classpath = ProjectPaths.getCompilationClasspath(chunk, false);
final Collection<File> platformCp = ProjectPaths.getPlatformCompilationClasspath(chunk, false);
// begin compilation round
final OutputFilesSink outputSink = new OutputFilesSink(context, outputConsumer, JavaBuilderUtil.getDependenciesRegistrar(context), chunk.getPresentableShortName());
Collection<File> filesWithErrors = null;
try {
if (hasSourcesToCompile) {
exitCode = ExitCode.OK;
final Set<File> srcPath = new HashSet<>();
final BuildRootIndex index = pd.getBuildRootIndex();
for (ModuleBuildTarget target : chunk.getTargets()) {
for (JavaSourceRootDescriptor rd : index.getTempTargetRoots(target, context)) {
srcPath.add(rd.root);
}
}
final DiagnosticSink diagnosticSink = new DiagnosticSink(context);
final String chunkName = chunk.getName();
context.processMessage(new ProgressMessage("Parsing java... [" + chunk.getPresentableShortName() + "]"));
final int filesCount = files.size();
boolean compiledOk = true;
if (filesCount > 0) {
LOG.info("Compiling " + filesCount + " java files; module: " + chunkName + (chunk.containsTests() ? " (tests)" : ""));
if (LOG.isDebugEnabled()) {
for (File file : files) {
LOG.debug("Compiling " + file.getPath());
}
LOG.debug(" classpath for " + chunkName + ":");
for (File file : classpath) {
LOG.debug(" " + file.getAbsolutePath());
}
LOG.debug(" platform classpath for " + chunkName + ":");
for (File file : platformCp) {
LOG.debug(" " + file.getAbsolutePath());
}
}
try {
compiledOk = compileJava(context, chunk, files, classpath, platformCp, srcPath, diagnosticSink, outputSink, compilingTool);
} finally {
// heuristic: incorrect paths data recovery, so that the next make should not contain non-existing sources in 'recompile' list
filesWithErrors = diagnosticSink.getFilesWithErrors();
for (File file : filesWithErrors) {
if (!file.exists()) {
FSOperations.markDeleted(context, file);
}
}
}
}
context.checkCanceled();
if (!compiledOk && diagnosticSink.getErrorCount() == 0) {
diagnosticSink.report(new PlainMessageDiagnostic(Diagnostic.Kind.ERROR, "Compilation failed: internal java compiler error"));
}
if (!Utils.PROCEED_ON_ERROR_KEY.get(context, Boolean.FALSE) && diagnosticSink.getErrorCount() > 0) {
if (!compiledOk) {
diagnosticSink.report(new JpsInfoDiagnostic("Errors occurred while compiling module '" + chunkName + "'"));
}
throw new StopBuildException("Compilation failed: errors: " + diagnosticSink.getErrorCount() + "; warnings: " + diagnosticSink.getWarningCount());
}
}
} finally {
JavaBuilderUtil.registerFilesToCompile(context, files);
if (filesWithErrors != null) {
JavaBuilderUtil.registerFilesWithErrors(context, filesWithErrors);
}
JavaBuilderUtil.registerSuccessfullyCompiled(context, outputSink.getSuccessfullyCompiled());
}
return exitCode;
}
use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.
the class OutputFilesSink method save.
public void save(@NotNull final OutputFileObject fileObject) {
final BinaryContent content = fileObject.getContent();
final File srcFile = fileObject.getSourceFile();
boolean isTemp = false;
final JavaFileObject.Kind outKind = fileObject.getKind();
if (srcFile != null && content != null) {
final String sourcePath = FileUtil.toSystemIndependentName(srcFile.getPath());
final JavaSourceRootDescriptor rootDescriptor = myContext.getProjectDescriptor().getBuildRootIndex().findJavaRootDescriptor(myContext, srcFile);
try {
if (rootDescriptor != null) {
isTemp = rootDescriptor.isTemp;
if (!isTemp) {
// first, handle [src->output] mapping and register paths for files_generated event
if (outKind == JavaFileObject.Kind.CLASS) {
// todo: avoid array copying?
myOutputConsumer.registerCompiledClass(rootDescriptor.target, new CompiledClass(fileObject.getFile(), srcFile, fileObject.getClassName(), content));
} else {
myOutputConsumer.registerOutputFile(rootDescriptor.target, fileObject.getFile(), Collections.<String>singleton(sourcePath));
}
}
} else {
// was not able to determine the source root descriptor or the source root is excluded from compilation (e.g. for annotation processors)
if (outKind == JavaFileObject.Kind.CLASS) {
myOutputConsumer.registerCompiledClass(null, new CompiledClass(fileObject.getFile(), srcFile, fileObject.getClassName(), content));
}
}
} catch (IOException e) {
myContext.processMessage(new CompilerMessage(JavaBuilder.BUILDER_NAME, e));
}
if (!isTemp && outKind == JavaFileObject.Kind.CLASS) {
// register in mappings any non-temp class file
try {
final ClassReader reader = new FailSafeClassReader(content.getBuffer(), content.getOffset(), content.getLength());
myMappingsCallback.associate(FileUtil.toSystemIndependentName(fileObject.getFile().getPath()), sourcePath, reader);
} catch (Throwable e) {
// need this to make sure that unexpected errors in, for example, ASM will not ruin the compilation
final String message = "Class dependency information may be incomplete! Error parsing generated class " + fileObject.getFile().getPath();
LOG.info(message, e);
myContext.processMessage(new CompilerMessage(JavaBuilder.BUILDER_NAME, BuildMessage.Kind.WARNING, message + "\n" + CompilerMessage.getTextFromThrowable(e), sourcePath));
}
}
}
if (outKind == JavaFileObject.Kind.CLASS) {
myContext.processMessage(new ProgressMessage("Writing classes... " + myChunkName));
if (!isTemp && srcFile != null) {
mySuccessfullyCompiled.add(srcFile);
}
}
}
use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.
the class ModuleBuildTarget method writeConfiguration.
@Override
public void writeConfiguration(ProjectDescriptor pd, PrintWriter out) {
final JpsModule module = getModule();
int fingerprint = getDependenciesFingerprint();
for (JavaSourceRootDescriptor root : pd.getBuildRootIndex().getTargetRoots(this, null)) {
fingerprint += FileUtil.fileHashCode(root.getRootFile());
}
final LanguageLevel level = JpsJavaExtensionService.getInstance().getLanguageLevel(module);
if (level != null) {
fingerprint += level.name().hashCode();
}
final JpsJavaCompilerConfiguration config = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(module.getProject());
final String bytecodeTarget = config.getByteCodeTargetLevel(module.getName());
if (bytecodeTarget != null) {
fingerprint += bytecodeTarget.hashCode();
}
final CompilerEncodingConfiguration encodingConfig = pd.getEncodingConfiguration();
final String encoding = encodingConfig.getPreferredModuleEncoding(module);
if (encoding != null) {
fingerprint += encoding.hashCode();
}
out.write(Integer.toHexString(fingerprint));
}
use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor 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.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.
the class FSOperations method markDeleted.
public static void markDeleted(CompileContext context, File file) throws IOException {
final JavaSourceRootDescriptor rd = context.getProjectDescriptor().getBuildRootIndex().findJavaRootDescriptor(context, file);
if (rd != null) {
final ProjectDescriptor pd = context.getProjectDescriptor();
pd.fsState.registerDeleted(context, rd.target, file, pd.timestamps.getStorage());
}
}
Aggregations