Search in sources :

Example 1 with ProjectBuilderLogger

use of org.jetbrains.jps.builders.logging.ProjectBuilderLogger in project intellij-community by JetBrains.

the class FormsInstrumenter method build.

@Override
public ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
    final JpsProject project = context.getProjectDescriptor().getProject();
    final JpsUiDesignerConfiguration config = JpsUiDesignerExtensionService.getInstance().getOrCreateUiDesignerConfiguration(project);
    if (!config.isInstrumentClasses()) {
        return ExitCode.NOTHING_DONE;
    }
    final Map<File, Collection<File>> srcToForms = FORMS_TO_COMPILE.get(context);
    FORMS_TO_COMPILE.set(context, null);
    if (srcToForms == null || srcToForms.isEmpty()) {
        return ExitCode.NOTHING_DONE;
    }
    final Set<File> formsToCompile = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
    for (Collection<File> files : srcToForms.values()) {
        formsToCompile.addAll(files);
    }
    if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
        final ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
        if (logger.isEnabled()) {
            logger.logCompiledFiles(formsToCompile, getPresentableName(), "Compiling forms:");
        }
    }
    try {
        final Collection<File> platformCp = ProjectPaths.getPlatformCompilationClasspath(chunk, false);
        final List<File> classpath = new ArrayList<>();
        classpath.addAll(ProjectPaths.getCompilationClasspath(chunk, false));
        // forms_rt.jar
        classpath.add(getResourcePath(GridConstraints.class));
        final Map<File, String> chunkSourcePath = ProjectPaths.getSourceRootsWithDependents(chunk);
        // sourcepath for loading forms resources
        classpath.addAll(chunkSourcePath.keySet());
        final JpsSdk<JpsDummyElement> sdk = chunk.representativeTarget().getModule().getSdk(JpsJavaSdkType.INSTANCE);
        final InstrumentationClassFinder finder = ClassProcessingBuilder.createInstrumentationClassFinder(sdk, platformCp, classpath, outputConsumer);
        try {
            final Map<File, Collection<File>> processed = instrumentForms(context, chunk, chunkSourcePath, finder, formsToCompile, outputConsumer);
            final OneToManyPathsMapping sourceToFormMap = context.getProjectDescriptor().dataManager.getSourceToFormMap();
            for (Map.Entry<File, Collection<File>> entry : processed.entrySet()) {
                final File src = entry.getKey();
                final Collection<File> forms = entry.getValue();
                final Collection<String> formPaths = new ArrayList<>(forms.size());
                for (File form : forms) {
                    formPaths.add(form.getPath());
                }
                sourceToFormMap.update(src.getPath(), formPaths);
                srcToForms.remove(src);
            }
            // clean mapping
            for (File srcFile : srcToForms.keySet()) {
                sourceToFormMap.remove(srcFile.getPath());
            }
        } finally {
            finder.releaseResources();
        }
    } finally {
        context.processMessage(new ProgressMessage("Finished instrumenting forms [" + chunk.getPresentableShortName() + "]"));
    }
    return ExitCode.OK;
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) OneToManyPathsMapping(org.jetbrains.jps.incremental.storage.OneToManyPathsMapping) InstrumentationClassFinder(com.intellij.compiler.instrumentation.InstrumentationClassFinder) THashSet(gnu.trove.THashSet) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) JpsUiDesignerConfiguration(org.jetbrains.jps.uiDesigner.model.JpsUiDesignerConfiguration) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) JpsProject(org.jetbrains.jps.model.JpsProject) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) THashMap(gnu.trove.THashMap)

Example 2 with ProjectBuilderLogger

use of org.jetbrains.jps.builders.logging.ProjectBuilderLogger in project intellij-community by JetBrains.

the class BuildOperations method cleanOutputsCorrespondingToChangedFiles.

public static <R extends BuildRootDescriptor, T extends BuildTarget<R>> Map<T, Set<File>> cleanOutputsCorrespondingToChangedFiles(final CompileContext context, DirtyFilesHolder<R, T> dirtyFilesHolder) throws ProjectBuildException {
    final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
    try {
        final Map<T, Set<File>> cleanedSources = new HashMap<>();
        final THashSet<File> dirsToDelete = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
        final Collection<String> deletedPaths = new ArrayList<>();
        dirtyFilesHolder.processDirtyFiles(new FileProcessor<R, T>() {

            // cache the mapping locally
            private final Map<T, SourceToOutputMapping> mappingsCache = new HashMap<>();

            private final TObjectIntHashMap<T> idsCache = new TObjectIntHashMap<>();

            @Override
            public boolean apply(T target, File file, R sourceRoot) throws IOException {
                SourceToOutputMapping srcToOut = mappingsCache.get(target);
                if (srcToOut == null) {
                    srcToOut = dataManager.getSourceToOutputMap(target);
                    mappingsCache.put(target, srcToOut);
                }
                final int targetId;
                if (!idsCache.containsKey(target)) {
                    targetId = dataManager.getTargetsState().getBuildTargetId(target);
                    idsCache.put(target, targetId);
                } else {
                    targetId = idsCache.get(target);
                }
                final String srcPath = file.getPath();
                final Collection<String> outputs = srcToOut.getOutputs(srcPath);
                if (outputs != null) {
                    final boolean shouldPruneOutputDirs = target instanceof ModuleBasedTarget;
                    final List<String> deletedForThisSource = new ArrayList<>(outputs.size());
                    for (String output : outputs) {
                        deleteRecursively(output, deletedForThisSource, shouldPruneOutputDirs ? dirsToDelete : null);
                    }
                    deletedPaths.addAll(deletedForThisSource);
                    dataManager.getOutputToTargetRegistry().removeMapping(deletedForThisSource, targetId);
                    Set<File> cleaned = cleanedSources.get(target);
                    if (cleaned == null) {
                        cleaned = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
                        cleanedSources.put(target, cleaned);
                    }
                    cleaned.add(file);
                }
                return true;
            }
        });
        if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
            final ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
            if (logger.isEnabled()) {
                logger.logDeletedFiles(deletedPaths);
            }
        }
        if (!deletedPaths.isEmpty()) {
            context.processMessage(new FileDeletedEvent(deletedPaths));
        }
        // attempting to delete potentially empty directories
        FSOperations.pruneEmptyDirs(context, dirsToDelete);
        return cleanedSources;
    } catch (Exception e) {
        throw new ProjectBuildException(e);
    }
}
Also used : SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) THashSet(gnu.trove.THashSet) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) IOException(java.io.IOException) FileDeletedEvent(org.jetbrains.jps.incremental.messages.FileDeletedEvent) File(java.io.File)

Example 3 with ProjectBuilderLogger

use of org.jetbrains.jps.builders.logging.ProjectBuilderLogger 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 4 with ProjectBuilderLogger

use of org.jetbrains.jps.builders.logging.ProjectBuilderLogger in project intellij-community by JetBrains.

the class IncProjectBuilder method processDeletedPaths.

//private static void createClasspathIndex(final BuildTargetChunk chunk) {
//  final Set<File> outputDirs = new THashSet<File>(FileUtil.FILE_HASHING_STRATEGY);
//  for (BuildTarget<?> target : chunk.getTargets()) {
//    if (target instanceof ModuleBuildTarget) {
//      File outputDir = ((ModuleBuildTarget)target).getOutputDir();
//      if (outputDir != null && outputDirs.add(outputDir)) {
//        try {
//          BufferedWriter writer = new BufferedWriter(new FileWriter(new File(outputDir, CLASSPATH_INDEX_FILE_NAME)));
//          try {
//            writeIndex(writer, outputDir, "");
//          }
//          finally {
//            writer.close();
//          }
//        }
//        catch (IOException e) {
//          // Ignore. Failed to create optional classpath index
//        }
//      }
//    }
//  }
//}
//private static void writeIndex(final BufferedWriter writer, final File file, final String path) throws IOException {
//  writer.write(path);
//  writer.write('\n');
//  final File[] files = file.listFiles();
//  if (files != null) {
//    for (File child : files) {
//      final String _path = path.isEmpty() ? child.getName() : path + "/" + child.getName();
//      writeIndex(writer, child, _path);
//    }
//  }
//}
private boolean processDeletedPaths(CompileContext context, final Set<? extends BuildTarget<?>> targets) throws ProjectBuildException {
    boolean doneSomething = false;
    try {
        // cleanup outputs
        final Map<BuildTarget<?>, Collection<String>> targetToRemovedSources = new HashMap<>();
        final THashSet<File> dirsToDelete = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
        for (BuildTarget<?> target : targets) {
            final Collection<String> deletedPaths = myProjectDescriptor.fsState.getAndClearDeletedPaths(target);
            if (deletedPaths.isEmpty()) {
                continue;
            }
            targetToRemovedSources.put(target, deletedPaths);
            if (isTargetOutputCleared(context, target)) {
                continue;
            }
            final int buildTargetId = context.getProjectDescriptor().getTargetsState().getBuildTargetId(target);
            final boolean shouldPruneEmptyDirs = target instanceof ModuleBasedTarget;
            final SourceToOutputMapping sourceToOutputStorage = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target);
            final ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
            // actually delete outputs associated with removed paths
            final Collection<String> pathsForIteration;
            if (myIsTestMode) {
                // ensure predictable order in test logs
                pathsForIteration = new ArrayList<>(deletedPaths);
                Collections.sort((List<String>) pathsForIteration);
            } else {
                pathsForIteration = deletedPaths;
            }
            for (String deletedSource : pathsForIteration) {
                // deleting outputs corresponding to non-existing source
                final Collection<String> outputs = sourceToOutputStorage.getOutputs(deletedSource);
                if (outputs != null && !outputs.isEmpty()) {
                    List<String> deletedOutputPaths = new ArrayList<>();
                    final OutputToTargetRegistry outputToSourceRegistry = context.getProjectDescriptor().dataManager.getOutputToTargetRegistry();
                    for (String output : outputToSourceRegistry.getSafeToDeleteOutputs(outputs, buildTargetId)) {
                        final boolean deleted = BuildOperations.deleteRecursively(output, deletedOutputPaths, shouldPruneEmptyDirs ? dirsToDelete : null);
                        if (deleted) {
                            doneSomething = true;
                        }
                    }
                    for (String outputPath : outputs) {
                        outputToSourceRegistry.removeMapping(outputPath, buildTargetId);
                    }
                    if (!deletedOutputPaths.isEmpty()) {
                        if (logger.isEnabled()) {
                            logger.logDeletedFiles(deletedOutputPaths);
                        }
                        context.processMessage(new FileDeletedEvent(deletedOutputPaths));
                    }
                }
                if (target instanceof ModuleBuildTarget) {
                    // check if deleted source was associated with a form
                    final OneToManyPathsMapping sourceToFormMap = context.getProjectDescriptor().dataManager.getSourceToFormMap();
                    final Collection<String> boundForms = sourceToFormMap.getState(deletedSource);
                    if (boundForms != null) {
                        for (String formPath : boundForms) {
                            final File formFile = new File(formPath);
                            if (formFile.exists()) {
                                FSOperations.markDirty(context, CompilationRound.CURRENT, formFile);
                            }
                        }
                        sourceToFormMap.remove(deletedSource);
                    }
                }
            }
        }
        if (!targetToRemovedSources.isEmpty()) {
            final Map<BuildTarget<?>, Collection<String>> existing = Utils.REMOVED_SOURCES_KEY.get(context);
            if (existing != null) {
                for (Map.Entry<BuildTarget<?>, Collection<String>> entry : existing.entrySet()) {
                    final Collection<String> paths = targetToRemovedSources.get(entry.getKey());
                    if (paths != null) {
                        paths.addAll(entry.getValue());
                    } else {
                        targetToRemovedSources.put(entry.getKey(), entry.getValue());
                    }
                }
            }
            Utils.REMOVED_SOURCES_KEY.set(context, targetToRemovedSources);
        }
        FSOperations.pruneEmptyDirs(context, dirsToDelete);
    } catch (IOException e) {
        throw new ProjectBuildException(e);
    }
    return doneSomething;
}
Also used : SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) THashMap(gnu.trove.THashMap) OneToManyPathsMapping(org.jetbrains.jps.incremental.storage.OneToManyPathsMapping) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) OutputToTargetRegistry(org.jetbrains.jps.incremental.storage.OutputToTargetRegistry) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) File(java.io.File) THashMap(gnu.trove.THashMap) MultiMap(com.intellij.util.containers.MultiMap)

Example 5 with ProjectBuilderLogger

use of org.jetbrains.jps.builders.logging.ProjectBuilderLogger in project intellij-community by JetBrains.

the class IncArtifactBuilder method deleteOutdatedFiles.

private static void deleteOutdatedFiles(MultiMap<String, String> filesToDelete, CompileContext context, SourceToOutputMapping srcOutMapping, ArtifactOutputToSourceMapping outSrcMapping) throws IOException {
    if (filesToDelete.isEmpty())
        return;
    context.processMessage(new ProgressMessage("Deleting outdated files..."));
    int notDeletedFilesCount = 0;
    final THashSet<String> notDeletedPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
    final THashSet<String> deletedPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
    for (String filePath : filesToDelete.keySet()) {
        if (notDeletedPaths.contains(filePath)) {
            continue;
        }
        boolean deleted = deletedPaths.contains(filePath);
        if (!deleted) {
            deleted = FileUtil.delete(new File(filePath));
        }
        if (deleted) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Outdated output file deleted: " + filePath);
            }
            outSrcMapping.remove(filePath);
            deletedPaths.add(filePath);
            for (String sourcePath : filesToDelete.get(filePath)) {
                srcOutMapping.removeOutput(sourcePath, filePath);
            }
        } else {
            notDeletedPaths.add(filePath);
            if (notDeletedFilesCount++ > 50) {
                context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.WARNING, "Deletion of outdated files stopped because too many files cannot be deleted"));
                break;
            }
            context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.WARNING, "Cannot delete file '" + filePath + "'"));
        }
    }
    ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
    if (logger.isEnabled()) {
        logger.logDeletedFiles(deletedPaths);
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) ProjectBuilderLogger(org.jetbrains.jps.builders.logging.ProjectBuilderLogger) File(java.io.File) THashSet(gnu.trove.THashSet)

Aggregations

ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)10 THashSet (gnu.trove.THashSet)7 File (java.io.File)6 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)4 IOException (java.io.IOException)3 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)3 THashMap (gnu.trove.THashMap)2 JavaSourceRootDescriptor (org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)2 SourceToOutputMapping (org.jetbrains.jps.builders.storage.SourceToOutputMapping)2 OneToManyPathsMapping (org.jetbrains.jps.incremental.storage.OneToManyPathsMapping)2 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)2 JpsModule (org.jetbrains.jps.model.module.JpsModule)2 EnhancerRunner (com.intellij.appengine.rt.EnhancerRunner)1 InstrumentationClassFinder (com.intellij.compiler.instrumentation.InstrumentationClassFinder)1 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 MultiMap (com.intellij.util.containers.MultiMap)1 TObjectIntHashMap (gnu.trove.TObjectIntHashMap)1 PrintWriter (java.io.PrintWriter)1 JarFile (java.util.jar.JarFile)1 JarOutputStream (java.util.jar.JarOutputStream)1