Search in sources :

Example 6 with JavaSourceRootDescriptor

use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.

the class AppEngineEnhancerBuilder method processModule.

private static boolean processModule(final CompileContext context, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, JpsAppEngineModuleExtension extension) throws IOException, ProjectBuildException {
    final Set<File> roots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    for (String path : extension.getFilesToEnhance()) {
        roots.add(new File(FileUtil.toSystemDependentName(path)));
    }
    final List<String> pathsToProcess = new ArrayList<>();
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        @Override
        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor root) throws IOException {
            if (JpsPathUtil.isUnder(roots, file)) {
                Collection<String> outputs = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target).getOutputs(file.getAbsolutePath());
                if (outputs != null) {
                    pathsToProcess.addAll(outputs);
                }
            }
            return true;
        }
    });
    if (pathsToProcess.isEmpty()) {
        return false;
    }
    JpsModule module = extension.getModule();
    JpsSdk<JpsDummyElement> sdk = JavaBuilderUtil.ensureModuleHasJdk(module, context, NAME);
    context.processMessage(new ProgressMessage("Enhancing classes in module '" + module.getName() + "'..."));
    List<String> vmParams = Collections.singletonList("-Xmx256m");
    List<String> classpath = new ArrayList<>();
    classpath.add(extension.getToolsApiJarPath());
    classpath.add(PathManager.getJarPathForClass(EnhancerRunner.class));
    boolean removeOrmJars = Boolean.parseBoolean(System.getProperty("jps.appengine.enhancer.remove.orm.jars", "true"));
    for (File file : JpsJavaExtensionService.dependencies(module).recursively().compileOnly().productionOnly().classes().getRoots()) {
        if (removeOrmJars && FileUtil.isAncestor(new File(extension.getOrmLibPath()), file, true)) {
            continue;
        }
        classpath.add(file.getAbsolutePath());
    }
    List<String> programParams = new ArrayList<>();
    final File argsFile = FileUtil.createTempFile("appEngineEnhanceFiles", ".txt");
    PrintWriter writer = new PrintWriter(argsFile);
    try {
        for (String path : pathsToProcess) {
            writer.println(FileUtil.toSystemDependentName(path));
        }
    } finally {
        writer.close();
    }
    programParams.add(argsFile.getAbsolutePath());
    programParams.add("com.google.appengine.tools.enhancer.Enhance");
    programParams.add("-api");
    PersistenceApi api = extension.getPersistenceApi();
    programParams.add(api.getEnhancerApiName());
    if (api.getEnhancerVersion() == 2) {
        programParams.add("-enhancerVersion");
        programParams.add("v2");
    }
    programParams.add("-v");
    List<String> commandLine = ExternalProcessUtil.buildJavaCommandLine(JpsJavaSdkType.getJavaExecutable(sdk), EnhancerRunner.class.getName(), Collections.<String>emptyList(), classpath, vmParams, programParams);
    Process process = new ProcessBuilder(commandLine).start();
    ExternalEnhancerProcessHandler handler = new ExternalEnhancerProcessHandler(process, commandLine, context);
    handler.startNotify();
    handler.waitFor();
    ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
    if (logger.isEnabled()) {
        logger.logCompiledPaths(pathsToProcess, NAME, "Enhancing classes:");
    }
    return true;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) EnhancerRunner(com.intellij.appengine.rt.EnhancerRunner) JpsModule(org.jetbrains.jps.model.module.JpsModule) PersistenceApi(org.jetbrains.jps.appengine.model.PersistenceApi) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 7 with JavaSourceRootDescriptor

use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.

the class CompilingGroovycRunner method addStubRootsToJavacSourcePath.

private static void addStubRootsToJavacSourcePath(CompileContext context, Map<ModuleBuildTarget, String> generationOutputs) {
    final BuildRootIndex rootsIndex = context.getProjectDescriptor().getBuildRootIndex();
    for (ModuleBuildTarget target : generationOutputs.keySet()) {
        File root = new File(generationOutputs.get(target));
        rootsIndex.associateTempRoot(context, target, new JavaSourceRootDescriptor(root, target, true, true, "", Collections.<File>emptySet()));
    }
}
Also used : ModuleBuildTarget(org.jetbrains.jps.incremental.ModuleBuildTarget) BuildRootIndex(org.jetbrains.jps.builders.BuildRootIndex) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) File(java.io.File)

Example 8 with JavaSourceRootDescriptor

use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.

the class FSOperations method markDirty.

public static void markDirty(CompileContext context, final CompilationRound round, final File file) throws IOException {
    final JavaSourceRootDescriptor rd = context.getProjectDescriptor().getBuildRootIndex().findJavaRootDescriptor(context, file);
    if (rd != null) {
        final ProjectDescriptor pd = context.getProjectDescriptor();
        pd.fsState.markDirty(context, round, file, rd, pd.timestamps.getStorage(), false);
    }
}
Also used : ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)

Example 9 with JavaSourceRootDescriptor

use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.

the class IncProjectBuilder method runModuleLevelBuilders.

// return true if changed something, false otherwise
private boolean runModuleLevelBuilders(final CompileContext context, final ModuleChunk chunk) throws ProjectBuildException, IOException {
    for (BuilderCategory category : BuilderCategory.values()) {
        for (ModuleLevelBuilder builder : myBuilderRegistry.getBuilders(category)) {
            builder.chunkBuildStarted(context, chunk);
        }
    }
    boolean doneSomething = false;
    boolean rebuildFromScratchRequested = false;
    float stageCount = myTotalModuleLevelBuilderCount;
    final int modulesInChunk = chunk.getModules().size();
    int buildersPassed = 0;
    boolean nextPassRequired;
    ChunkBuildOutputConsumerImpl outputConsumer = new ChunkBuildOutputConsumerImpl(context);
    try {
        do {
            nextPassRequired = false;
            myProjectDescriptor.fsState.beforeNextRoundStart(context, chunk);
            DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder = new DirtyFilesHolderBase<JavaSourceRootDescriptor, ModuleBuildTarget>(context) {

                @Override
                public void processDirtyFiles(@NotNull FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget> processor) throws IOException {
                    FSOperations.processFilesToRecompile(context, chunk, processor);
                }
            };
            if (!JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
                final Map<ModuleBuildTarget, Set<File>> cleanedSources = BuildOperations.cleanOutputsCorrespondingToChangedFiles(context, dirtyFilesHolder);
                for (Map.Entry<ModuleBuildTarget, Set<File>> entry : cleanedSources.entrySet()) {
                    final ModuleBuildTarget target = entry.getKey();
                    final Set<File> files = entry.getValue();
                    if (!files.isEmpty()) {
                        final SourceToOutputMapping mapping = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target);
                        for (File srcFile : files) {
                            mapping.setOutputs(srcFile.getPath(), Collections.<String>emptyList());
                        }
                    }
                }
            }
            BUILDER_CATEGORY_LOOP: for (BuilderCategory category : BuilderCategory.values()) {
                final List<ModuleLevelBuilder> builders = myBuilderRegistry.getBuilders(category);
                if (category == BuilderCategory.CLASS_POST_PROCESSOR) {
                    // ensure changes from instrumenters are visible to class post-processors
                    saveInstrumentedClasses(outputConsumer);
                }
                if (builders.isEmpty()) {
                    continue;
                }
                try {
                    for (ModuleLevelBuilder builder : builders) {
                        processDeletedPaths(context, chunk.getTargets());
                        long start = System.nanoTime();
                        int processedSourcesBefore = outputConsumer.getNumberOfProcessedSources();
                        final ModuleLevelBuilder.ExitCode buildResult = builder.build(context, chunk, dirtyFilesHolder, outputConsumer);
                        storeBuilderStatistics(builder, System.nanoTime() - start, outputConsumer.getNumberOfProcessedSources() - processedSourcesBefore);
                        doneSomething |= (buildResult != ModuleLevelBuilder.ExitCode.NOTHING_DONE);
                        if (buildResult == ModuleLevelBuilder.ExitCode.ABORT) {
                            throw new StopBuildException("Builder " + builder.getPresentableName() + " requested build stop");
                        }
                        context.checkCanceled();
                        if (buildResult == ModuleLevelBuilder.ExitCode.ADDITIONAL_PASS_REQUIRED) {
                            nextPassRequired = true;
                        } else if (buildResult == ModuleLevelBuilder.ExitCode.CHUNK_REBUILD_REQUIRED) {
                            if (!rebuildFromScratchRequested && !JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
                                LOG.info("Builder " + builder.getPresentableName() + " requested rebuild of module chunk " + chunk.getName());
                                // allow rebuild from scratch only once per chunk
                                rebuildFromScratchRequested = true;
                                try {
                                    // forcibly mark all files in the chunk dirty
                                    context.getProjectDescriptor().fsState.clearContextRoundData(context);
                                    FSOperations.markDirty(context, CompilationRound.NEXT, chunk, null);
                                    // reverting to the beginning
                                    myTargetsProcessed -= (buildersPassed * modulesInChunk) / stageCount;
                                    stageCount = myTotalModuleLevelBuilderCount;
                                    buildersPassed = 0;
                                    nextPassRequired = true;
                                    outputConsumer.clear();
                                    break BUILDER_CATEGORY_LOOP;
                                } catch (Exception e) {
                                    throw new ProjectBuildException(e);
                                }
                            } else {
                                LOG.debug("Builder " + builder.getPresentableName() + " requested second chunk rebuild");
                            }
                        }
                        buildersPassed++;
                        updateDoneFraction(context, modulesInChunk / (stageCount));
                    }
                } finally {
                    final boolean moreToCompile = JavaBuilderUtil.updateMappingsOnRoundCompletion(context, dirtyFilesHolder, chunk);
                    if (moreToCompile) {
                        nextPassRequired = true;
                    }
                    if (nextPassRequired && !rebuildFromScratchRequested) {
                        // recalculate basis
                        myTargetsProcessed -= (buildersPassed * modulesInChunk) / stageCount;
                        stageCount += myTotalModuleLevelBuilderCount;
                        myTargetsProcessed += (buildersPassed * modulesInChunk) / stageCount;
                    }
                }
            }
        } while (nextPassRequired);
    } finally {
        saveInstrumentedClasses(outputConsumer);
        outputConsumer.fireFileGeneratedEvents();
        outputConsumer.clear();
        for (BuilderCategory category : BuilderCategory.values()) {
            for (ModuleLevelBuilder builder : myBuilderRegistry.getBuilders(category)) {
                builder.chunkBuildFinished(context, chunk);
            }
        }
    }
    return doneSomething;
}
Also used : SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) THashSet(gnu.trove.THashSet) NotNull(org.jetbrains.annotations.NotNull) InvocationTargetException(java.lang.reflect.InvocationTargetException) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) IOException(java.io.IOException) MappingFailedException(com.intellij.util.io.MappingFailedException) DirtyFilesHolderBase(org.jetbrains.jps.builders.impl.DirtyFilesHolderBase) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) SmartList(com.intellij.util.SmartList) THashMap(gnu.trove.THashMap) MultiMap(com.intellij.util.containers.MultiMap) File(java.io.File)

Example 10 with JavaSourceRootDescriptor

use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.

the class JavaBuilder method doBuild.

public ExitCode doBuild(@NotNull CompileContext context, @NotNull ModuleChunk chunk, @NotNull DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, @NotNull OutputConsumer outputConsumer, @NotNull JavaCompilingTool compilingTool) throws ProjectBuildException, IOException {
    try {
        final Set<File> filesToCompile = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
        dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

            @Override
            public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor descriptor) throws IOException {
                if (JAVA_SOURCES_FILTER.accept(file) && ourCompilableModuleTypes.contains(target.getModule().getModuleType())) {
                    filesToCompile.add(file);
                }
                return true;
            }
        });
        if ((!filesToCompile.isEmpty() || dirtyFilesHolder.hasRemovedFiles()) && JpsJavaSdkType.parseVersion(getLanguageLevel(ContainerUtil.getFirstItem(chunk.getModules()))) >= 9) {
            // at the moment, there is no incremental compilation for module-info files, so they should be rebuilt on every change
            JavaModuleIndex index = getJavaModuleIndex(context);
            for (JpsModule module : chunk.getModules()) {
                ContainerUtil.addIfNotNull(filesToCompile, index.getModuleInfoFile(module));
            }
        }
        if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
            ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
            if (logger.isEnabled() && !filesToCompile.isEmpty()) {
                logger.logCompiledFiles(filesToCompile, BUILDER_NAME, "Compiling files:");
            }
        }
        return compile(context, chunk, dirtyFilesHolder, filesToCompile, outputConsumer, compilingTool);
    } catch (BuildDataCorruptedException | PersistentEnumeratorBase.CorruptedException | ProjectBuildException e) {
        throw e;
    } catch (Exception e) {
        LOG.info(e);
        String message = e.getMessage();
        if (message == null) {
            final ByteArrayOutputStream out = new ByteArrayOutputStream();
            final PrintStream stream = new PrintStream(out);
            try {
                e.printStackTrace(stream);
            } finally {
                stream.close();
            }
            message = "Internal error: \n" + out;
        }
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, message));
        throw new StopBuildException();
    }
}
Also used : JavaModuleIndex(org.jetbrains.jps.model.java.JavaModuleIndex) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) THashSet(gnu.trove.THashSet) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) JpsModule(org.jetbrains.jps.model.module.JpsModule) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) BuildDataCorruptedException(org.jetbrains.jps.builders.storage.BuildDataCorruptedException) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)

Aggregations

JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)20 File (java.io.File)9 THashSet (gnu.trove.THashSet)7 JpsModule (org.jetbrains.jps.model.module.JpsModule)5 THashMap (gnu.trove.THashMap)4 IOException (java.io.IOException)4 NotNull (org.jetbrains.annotations.NotNull)4 ProjectDescriptor (org.jetbrains.jps.cmdline.ProjectDescriptor)4 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)3 JpsJavaCompilerConfiguration (org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration)3 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 BuildRootIndex (org.jetbrains.jps.builders.BuildRootIndex)2 ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)2 BuildDataCorruptedException (org.jetbrains.jps.builders.storage.BuildDataCorruptedException)2 ModuleBuildTarget (org.jetbrains.jps.incremental.ModuleBuildTarget)2 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)2 EnhancerRunner (com.intellij.appengine.rt.EnhancerRunner)1 FailSafeClassReader (com.intellij.compiler.instrumentation.FailSafeClassReader)1 SmartList (com.intellij.util.SmartList)1