use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.
the class JavaBuilder method buildOutputDirectoriesMap.
private static Map<File, Set<File>> buildOutputDirectoriesMap(CompileContext context, ModuleChunk chunk) {
final Map<File, Set<File>> map = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
for (ModuleBuildTarget target : chunk.getTargets()) {
final File outputDir = target.getOutputDir();
if (outputDir == null) {
continue;
}
final Set<File> roots = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
for (JavaSourceRootDescriptor descriptor : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) {
roots.add(descriptor.root);
}
map.put(outputDir, roots);
}
return map;
}
use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.
the class CompilerEncodingConfiguration method computeModuleCharsetMap.
private Map<JpsModule, Set<String>> computeModuleCharsetMap() {
final Map<JpsModule, Set<String>> map = new THashMap<>();
final Iterable<JavaBuilderExtension> builderExtensions = JpsServiceManager.getInstance().getExtensions(JavaBuilderExtension.class);
for (Map.Entry<String, String> entry : myUrlToCharset.entrySet()) {
final String fileUrl = entry.getKey();
final String charset = entry.getValue();
File file = JpsPathUtil.urlToFile(fileUrl);
if (charset == null || (!file.isDirectory() && !shouldHonorEncodingForCompilation(builderExtensions, file))) {
continue;
}
final JavaSourceRootDescriptor rootDescriptor = myRootsIndex.findJavaRootDescriptor(null, file);
if (rootDescriptor == null) {
continue;
}
final JpsModule module = rootDescriptor.target.getModule();
Set<String> set = map.get(module);
if (set == null) {
set = new LinkedHashSet<>();
map.put(module, set);
// need to search parents only once because
// file parent's charset, if explicitly defined, has higher priority than the charset assigned to individual files
// we deliberately check parents until the source roots
final File sourceRoot = rootDescriptor.root;
File current = FileUtilRt.getParentFile(file);
String parentCharset = null;
while (current != null) {
final String currentCharset = lookupCharsetMap(current);
if (currentCharset != null) {
parentCharset = currentCharset;
}
if (FileUtil.filesEqual(current, sourceRoot)) {
break;
}
current = FileUtilRt.getParentFile(current);
}
if (parentCharset != null) {
set.add(parentCharset);
}
}
set.add(charset);
}
for (JpsModule module : myJpsModel.getProject().getModules()) {
for (JpsModuleSourceRoot srcRoot : module.getSourceRoots()) {
final String encoding = getEncoding(srcRoot.getFile());
if (encoding != null) {
Set<String> charsets = map.get(module);
if (charsets == null) {
charsets = new LinkedHashSet<>();
map.put(module, charsets);
}
charsets.add(encoding);
}
}
}
return map;
}
use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.
the class FSOperations method markDirtyIfNotDeleted.
public static void markDirtyIfNotDeleted(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.markDirtyIfNotDeleted(context, round, file, rd, pd.timestamps.getStorage());
}
}
use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.
the class FSOperations method markDirtyFiles.
static void markDirtyFiles(CompileContext context, BuildTarget<?> target, final CompilationRound round, Timestamps timestamps, boolean forceMarkDirty, @Nullable THashSet<File> currentFiles, @Nullable FileFilter filter) throws IOException {
if (filter == null && forceMarkDirty) {
addCompletelyMarkedDirtyTarget(context, target);
}
for (BuildRootDescriptor rd : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) {
if (!rd.getRootFile().exists() || //temp roots are managed by compilers themselves
(rd instanceof JavaSourceRootDescriptor && ((JavaSourceRootDescriptor) rd).isTemp)) {
continue;
}
if (filter == null) {
context.getProjectDescriptor().fsState.clearRecompile(rd);
}
final FSCache fsCache = rd.canUseFileCache() ? context.getProjectDescriptor().getFSCache() : FSCache.NO_CACHE;
traverseRecursively(context, rd, round, rd.getRootFile(), timestamps, forceMarkDirty, currentFiles, filter, fsCache);
}
}
use of org.jetbrains.jps.builders.java.JavaSourceRootDescriptor in project intellij-community by JetBrains.
the class FormsBindingManager method build.
@Override
public ExitCode build(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder, OutputConsumer outputConsumer) throws ProjectBuildException, IOException {
ExitCode exitCode = ExitCode.NOTHING_DONE;
final JpsProject project = context.getProjectDescriptor().getProject();
final JpsUiDesignerConfiguration config = JpsUiDesignerExtensionService.getInstance().getOrCreateUiDesignerConfiguration(project);
if (!config.isInstrumentClasses() && !config.isCopyFormsRuntimeToOutput()) {
return exitCode;
}
final Map<File, ModuleBuildTarget> filesToCompile = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
final Map<File, ModuleBuildTarget> formsToCompile = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
final Map<File, Collection<File>> srcToForms = new THashMap<>(FileUtil.FILE_HASHING_STRATEGY);
if (!JavaBuilderUtil.isForcedRecompilationAllJavaModules(context) && config.isInstrumentClasses() && FORCE_FORMS_REBUILD_FLAG.get(context, Boolean.FALSE)) {
// force compilation of all forms, but only once per chunk
if (!FORMS_REBUILD_FORCED.get(context, Boolean.FALSE)) {
FORMS_REBUILD_FORCED.set(context, Boolean.TRUE);
FSOperations.markDirty(context, CompilationRound.CURRENT, chunk, FORM_SOURCES_FILTER);
}
}
dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {
public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor descriptor) throws IOException {
if (JAVA_SOURCES_FILTER.accept(file)) {
filesToCompile.put(file, target);
} else if (FORM_SOURCES_FILTER.accept(file)) {
formsToCompile.put(file, target);
}
return true;
}
});
if (config.isInstrumentClasses()) {
final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(project);
final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
// force compilation of bound source file if the form is dirty
for (final Map.Entry<File, ModuleBuildTarget> entry : formsToCompile.entrySet()) {
final File form = entry.getKey();
final ModuleBuildTarget target = entry.getValue();
final Collection<File> sources = findBoundSourceCandidates(context, target, form);
for (File boundSource : sources) {
if (!excludes.isExcluded(boundSource)) {
addBinding(boundSource, form, srcToForms);
FSOperations.markDirty(context, CompilationRound.CURRENT, boundSource);
filesToCompile.put(boundSource, target);
exitCode = ExitCode.OK;
}
}
}
// form should be considered dirty if the class it is bound to is dirty
final OneToManyPathsMapping sourceToFormMap = context.getProjectDescriptor().dataManager.getSourceToFormMap();
for (Map.Entry<File, ModuleBuildTarget> entry : filesToCompile.entrySet()) {
final File srcFile = entry.getKey();
final ModuleBuildTarget target = entry.getValue();
final Collection<String> boundForms = sourceToFormMap.getState(srcFile.getPath());
if (boundForms != null) {
for (String formPath : boundForms) {
final File formFile = new File(formPath);
if (!excludes.isExcluded(formFile) && formFile.exists()) {
addBinding(srcFile, formFile, srcToForms);
FSOperations.markDirty(context, CompilationRound.CURRENT, formFile);
formsToCompile.put(formFile, target);
exitCode = ExitCode.OK;
}
}
}
}
}
FORMS_TO_COMPILE.set(context, srcToForms.isEmpty() ? null : srcToForms);
if (config.isCopyFormsRuntimeToOutput() && containsValidForm(formsToCompile.keySet())) {
for (ModuleBuildTarget target : chunk.getTargets()) {
if (!target.isTests()) {
final File outputDir = target.getOutputDir();
if (outputDir != null) {
final String outputRoot = FileUtil.toSystemIndependentName(outputDir.getPath());
final List<File> generatedFiles = CopyResourcesUtil.copyFormsRuntime(outputRoot, false);
if (!generatedFiles.isEmpty()) {
exitCode = ExitCode.OK;
// now inform others about files just copied
for (File file : generatedFiles) {
outputConsumer.registerOutputFile(target, file, Collections.<String>emptyList());
}
}
}
}
}
}
return exitCode;
}
Aggregations