use of org.jetbrains.jps.builders.storage.SourceToOutputMapping 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");
}
use of org.jetbrains.jps.builders.storage.SourceToOutputMapping 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.builders.storage.SourceToOutputMapping 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);
}
}
use of org.jetbrains.jps.builders.storage.SourceToOutputMapping in project intellij-community by JetBrains.
the class IncProjectBuilder method clearOutputFiles.
public static void clearOutputFiles(CompileContext context, BuildTarget<?> target) throws IOException {
final SourceToOutputMapping map = context.getProjectDescriptor().dataManager.getSourceToOutputMap(target);
final THashSet<File> dirsToDelete = target instanceof ModuleBasedTarget ? new THashSet<>(FileUtil.FILE_HASHING_STRATEGY) : null;
for (String srcPath : map.getSources()) {
final Collection<String> outs = map.getOutputs(srcPath);
if (outs != null && !outs.isEmpty()) {
List<String> deletedPaths = new ArrayList<>();
for (String out : outs) {
BuildOperations.deleteRecursively(out, deletedPaths, dirsToDelete);
}
if (!deletedPaths.isEmpty()) {
context.processMessage(new FileDeletedEvent(deletedPaths));
}
}
}
registerTargetsWithClearedOutput(context, Collections.singletonList(target));
if (dirsToDelete != null) {
FSOperations.pruneEmptyDirs(context, dirsToDelete);
}
}
use of org.jetbrains.jps.builders.storage.SourceToOutputMapping in project android by JetBrains.
the class AndroidSourceGeneratingBuilder method runAidlCompiler.
private static boolean runAidlCompiler(@NotNull final CompileContext context, @NotNull Map<File, ModuleBuildTarget> files, @NotNull Map<JpsModule, MyModuleData> moduleDataMap) {
if (files.size() > 0) {
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.aidl")));
}
boolean success = true;
for (Map.Entry<File, ModuleBuildTarget> entry : files.entrySet()) {
final File file = entry.getKey();
final ModuleBuildTarget buildTarget = entry.getValue();
final String filePath = file.getPath();
final MyModuleData moduleData = moduleDataMap.get(buildTarget.getModule());
if (!LOG.assertTrue(moduleData != null)) {
context.processMessage(new CompilerMessage(ANDROID_IDL_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.internal.error")));
success = false;
continue;
}
final File generatedSourcesDir = AndroidJpsUtil.getGeneratedSourcesStorage(buildTarget.getModule(), context.getProjectDescriptor().dataManager);
final File aidlOutputDirectory = new File(generatedSourcesDir, AndroidJpsUtil.AIDL_GENERATED_SOURCE_ROOT_NAME);
if (!aidlOutputDirectory.exists() && !aidlOutputDirectory.mkdirs()) {
context.processMessage(new CompilerMessage(ANDROID_IDL_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", aidlOutputDirectory.getPath())));
success = false;
continue;
}
final IAndroidTarget target = moduleData.getPlatform().getTarget();
try {
final File[] sourceRoots = AndroidJpsUtil.getSourceRootsForModuleAndDependencies(buildTarget.getModule());
final String[] sourceRootPaths = AndroidJpsUtil.toPaths(sourceRoots);
final String packageName = computePackageForFile(context, file);
if (packageName == null) {
context.processMessage(new CompilerMessage(ANDROID_IDL_COMPILER, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.cannot.compute.package", filePath)));
success = false;
continue;
}
final File outputFile = new File(aidlOutputDirectory, packageName.replace('.', File.separatorChar) + File.separator + FileUtil.getNameWithoutExtension(file) + ".java");
final String outputFilePath = outputFile.getPath();
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidIdl.execute(target, filePath, outputFilePath, sourceRootPaths);
addMessages(context, messages, filePath, ANDROID_IDL_COMPILER);
if (messages.get(AndroidCompilerMessageKind.ERROR).size() > 0) {
success = false;
} else if (outputFile.exists()) {
final SourceToOutputMapping sourceToOutputMap = context.getProjectDescriptor().dataManager.getSourceToOutputMap(buildTarget);
sourceToOutputMap.setOutput(filePath, outputFilePath);
FSOperations.markDirty(context, CompilationRound.CURRENT, outputFile);
}
} catch (final IOException e) {
AndroidJpsUtil.reportExceptionError(context, filePath, e, ANDROID_IDL_COMPILER);
success = false;
}
}
return success;
}
Aggregations