Search in sources :

Example 1 with OutputToTargetRegistry

use of org.jetbrains.jps.incremental.storage.OutputToTargetRegistry in project intellij-community by JetBrains.

the class BuildResult method dumpSourceToOutputMappings.

private static void dumpSourceToOutputMappings(ProjectDescriptor pd, PrintStream stream) throws IOException {
    List<BuildTarget<?>> targets = new ArrayList<>(pd.getBuildTargetIndex().getAllTargets());
    targets.sort((o1, o2) -> StringUtil.comparePairs(o1.getTargetType().getTypeId(), o1.getId(), o2.getTargetType().getTypeId(), o2.getId(), false));
    final TIntObjectHashMap<BuildTarget<?>> id2Target = new TIntObjectHashMap<>();
    for (BuildTarget<?> target : targets) {
        id2Target.put(pd.dataManager.getTargetsState().getBuildTargetId(target), target);
    }
    TIntObjectHashMap<String> hashCodeToOutputPath = new TIntObjectHashMap<>();
    for (BuildTarget<?> target : targets) {
        stream.println("Begin Of SourceToOutput (target " + getTargetIdWithTypeId(target) + ")");
        SourceToOutputMapping map = pd.dataManager.getSourceToOutputMap(target);
        List<String> sourcesList = new ArrayList<>(map.getSources());
        Collections.sort(sourcesList);
        for (String source : sourcesList) {
            List<String> outputs = new ArrayList<>(ObjectUtils.notNull(map.getOutputs(source), Collections.<String>emptySet()));
            Collections.sort(outputs);
            for (String output : outputs) {
                hashCodeToOutputPath.put(FileUtil.pathHashCode(output), output);
            }
            String sourceToCompare = SystemInfo.isFileSystemCaseSensitive ? source : source.toLowerCase(Locale.US);
            stream.println(" " + sourceToCompare + " -> " + StringUtil.join(outputs, ","));
        }
        stream.println("End Of SourceToOutput (target " + getTargetIdWithTypeId(target) + ")");
    }
    OutputToTargetRegistry registry = pd.dataManager.getOutputToTargetRegistry();
    List<Integer> keys = new ArrayList<>(registry.getKeys());
    Collections.sort(keys);
    stream.println("Begin Of OutputToTarget");
    for (Integer key : keys) {
        TIntHashSet targetsIds = registry.getState(key);
        if (targetsIds == null)
            continue;
        final List<String> targetsNames = new ArrayList<>();
        targetsIds.forEach(value -> {
            BuildTarget<?> target = id2Target.get(value);
            targetsNames.add(target != null ? getTargetIdWithTypeId(target) : "<unknown " + value + ">");
            return true;
        });
        Collections.sort(targetsNames);
        stream.println(hashCodeToOutputPath.get(key) + " -> " + targetsNames);
    }
    stream.println("End Of OutputToTarget");
}
Also used : SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) OutputToTargetRegistry(org.jetbrains.jps.incremental.storage.OutputToTargetRegistry) ArrayList(java.util.ArrayList) TIntHashSet(gnu.trove.TIntHashSet) TIntObjectHashMap(gnu.trove.TIntObjectHashMap)

Example 2 with OutputToTargetRegistry

use of org.jetbrains.jps.incremental.storage.OutputToTargetRegistry 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)

Aggregations

SourceToOutputMapping (org.jetbrains.jps.builders.storage.SourceToOutputMapping)2 OutputToTargetRegistry (org.jetbrains.jps.incremental.storage.OutputToTargetRegistry)2 MultiMap (com.intellij.util.containers.MultiMap)1 THashMap (gnu.trove.THashMap)1 THashSet (gnu.trove.THashSet)1 TIntHashSet (gnu.trove.TIntHashSet)1 TIntObjectHashMap (gnu.trove.TIntObjectHashMap)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ProjectBuilderLogger (org.jetbrains.jps.builders.logging.ProjectBuilderLogger)1 OneToManyPathsMapping (org.jetbrains.jps.incremental.storage.OneToManyPathsMapping)1