use of org.jetbrains.jps.cmdline.ProjectDescriptor 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.cmdline.ProjectDescriptor in project intellij-community by JetBrains.
the class NotNullInstrumentingBuilder method instrument.
// todo: probably instrument other NotNull-like annotations defined in project settings?
@Override
@Nullable
protected BinaryContent instrument(CompileContext context, CompiledClass compiledClass, ClassReader reader, ClassWriter writer, InstrumentationClassFinder finder) {
try {
final ProjectDescriptor pd = context.getProjectDescriptor();
final List<String> notNulls = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(pd.getProject()).getNotNullAnnotations();
if (NotNullVerifyingInstrumenter.processClassFile((FailSafeClassReader) reader, writer, ArrayUtil.toStringArray(notNulls))) {
return new BinaryContent(writer.toByteArray());
}
} catch (Throwable e) {
LOG.error(e);
final Collection<File> sourceFiles = compiledClass.getSourceFiles();
String msg = "Cannot instrument " + ContainerUtil.map(sourceFiles, file -> file.getName()) + ": " + e.getMessage();
context.processMessage(new CompilerMessage(getPresentableName(), BuildMessage.Kind.ERROR, msg, ContainerUtil.getFirstItem(compiledClass.getSourceFilesPaths())));
}
return null;
}
use of org.jetbrains.jps.cmdline.ProjectDescriptor in project intellij-community by JetBrains.
the class JpsBuildTestCase method createProjectDescriptor.
protected ProjectDescriptor createProjectDescriptor(final BuildLoggingManager buildLoggingManager) {
try {
BuildTargetRegistryImpl targetRegistry = new BuildTargetRegistryImpl(myModel);
ModuleExcludeIndex index = new ModuleExcludeIndexImpl(myModel);
IgnoredFileIndexImpl ignoredFileIndex = new IgnoredFileIndexImpl(myModel);
BuildDataPaths dataPaths = new BuildDataPathsImpl(myDataStorageRoot);
BuildRootIndexImpl buildRootIndex = new BuildRootIndexImpl(targetRegistry, myModel, index, dataPaths, ignoredFileIndex);
BuildTargetIndexImpl targetIndex = new BuildTargetIndexImpl(targetRegistry, buildRootIndex);
BuildTargetsState targetsState = new BuildTargetsState(dataPaths, myModel, buildRootIndex);
ProjectTimestamps timestamps = new ProjectTimestamps(myDataStorageRoot, targetsState);
BuildDataManager dataManager = new BuildDataManager(dataPaths, targetsState, true);
return new ProjectDescriptor(myModel, new BuildFSState(true), timestamps, dataManager, buildLoggingManager, index, targetsState, targetIndex, buildRootIndex, ignoredFileIndex);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.jetbrains.jps.cmdline.ProjectDescriptor in project intellij-community by JetBrains.
the class BuildOperations method initTargetFSState.
private static void initTargetFSState(CompileContext context, BuildTarget<?> target, final boolean forceMarkDirty) throws IOException {
final ProjectDescriptor pd = context.getProjectDescriptor();
final Timestamps timestamps = pd.timestamps.getStorage();
final THashSet<File> currentFiles = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
FSOperations.markDirtyFiles(context, target, CompilationRound.CURRENT, timestamps, forceMarkDirty, currentFiles, null);
// handle deleted paths
final BuildFSState fsState = pd.fsState;
fsState.clearDeletedPaths(target);
final SourceToOutputMapping sourceToOutputMap = pd.dataManager.getSourceToOutputMap(target);
for (final Iterator<String> it = sourceToOutputMap.getSourcesIterator(); it.hasNext(); ) {
final String path = it.next();
// can check if the file exists
final File file = new File(path);
if (!currentFiles.contains(file)) {
fsState.registerDeleted(context, target, file, timestamps);
}
}
pd.fsState.markInitialScanPerformed(target);
}
use of org.jetbrains.jps.cmdline.ProjectDescriptor in project intellij-community by JetBrains.
the class IncProjectBuilder method flushContext.
private static void flushContext(CompileContext context) {
if (context != null) {
final ProjectDescriptor pd = context.getProjectDescriptor();
pd.timestamps.getStorage().force();
pd.dataManager.flush(false);
}
final ExternalJavacManager server = ExternalJavacManager.KEY.get(context);
if (server != null) {
server.stop();
ExternalJavacManager.KEY.set(context, null);
}
}
Aggregations