Search in sources :

Example 1 with ProjectDescriptor

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;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) BuildRootIndex(org.jetbrains.jps.builders.BuildRootIndex) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) THashSet(gnu.trove.THashSet)

Example 2 with ProjectDescriptor

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;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) Collection(java.util.Collection) BinaryContent(org.jetbrains.jps.incremental.BinaryContent) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ProjectDescriptor

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);
    }
}
Also used : ProjectTimestamps(org.jetbrains.jps.incremental.storage.ProjectTimestamps) BuildTargetRegistryImpl(org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl) BuildRootIndexImpl(org.jetbrains.jps.builders.impl.BuildRootIndexImpl) IgnoredFileIndexImpl(org.jetbrains.jps.indices.impl.IgnoredFileIndexImpl) BuildTargetIndexImpl(org.jetbrains.jps.builders.impl.BuildTargetIndexImpl) IOException(java.io.IOException) BuildTargetsState(org.jetbrains.jps.incremental.storage.BuildTargetsState) BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) BuildDataPaths(org.jetbrains.jps.builders.storage.BuildDataPaths) ModuleExcludeIndex(org.jetbrains.jps.indices.ModuleExcludeIndex) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) ModuleExcludeIndexImpl(org.jetbrains.jps.indices.impl.ModuleExcludeIndexImpl) BuildDataPathsImpl(org.jetbrains.jps.builders.impl.BuildDataPathsImpl) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Example 4 with ProjectDescriptor

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);
}
Also used : Timestamps(org.jetbrains.jps.incremental.storage.Timestamps) BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) File(java.io.File) THashSet(gnu.trove.THashSet)

Example 5 with ProjectDescriptor

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);
    }
}
Also used : ExternalJavacManager(org.jetbrains.jps.javac.ExternalJavacManager) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor)

Aggregations

ProjectDescriptor (org.jetbrains.jps.cmdline.ProjectDescriptor)18 IOException (java.io.IOException)6 BuildFSState (org.jetbrains.jps.incremental.fs.BuildFSState)6 File (java.io.File)5 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)4 THashSet (gnu.trove.THashSet)3 Timestamps (org.jetbrains.jps.incremental.storage.Timestamps)3 ModuleExcludeIndex (org.jetbrains.jps.indices.ModuleExcludeIndex)3 MultiMap (com.intellij.util.containers.MultiMap)2 BuildDataPathsImpl (org.jetbrains.jps.builders.impl.BuildDataPathsImpl)2 BuildRootIndexImpl (org.jetbrains.jps.builders.impl.BuildRootIndexImpl)2 BuildTargetIndexImpl (org.jetbrains.jps.builders.impl.BuildTargetIndexImpl)2 BuildTargetRegistryImpl (org.jetbrains.jps.builders.impl.BuildTargetRegistryImpl)2 BuildDataPaths (org.jetbrains.jps.builders.storage.BuildDataPaths)2 SourceToOutputMapping (org.jetbrains.jps.builders.storage.SourceToOutputMapping)2 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)2 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)2 BuildDataManager (org.jetbrains.jps.incremental.storage.BuildDataManager)2 BuildTargetsState (org.jetbrains.jps.incremental.storage.BuildTargetsState)2 ProjectTimestamps (org.jetbrains.jps.incremental.storage.ProjectTimestamps)2