use of org.jetbrains.jps.builders.BuildRootDescriptor in project intellij-community by JetBrains.
the class ChainedTargetsBuildListener method filesGenerated.
@Override
public void filesGenerated(FileGeneratedEvent event) {
final ProjectDescriptor pd = myContext.getProjectDescriptor();
final BuildFSState fsState = pd.fsState;
for (Pair<String, String> pair : event.getPaths()) {
final String relativePath = pair.getSecond();
final File file = relativePath.equals(".") ? new File(pair.getFirst()) : new File(pair.getFirst(), relativePath);
for (BuildRootDescriptor desc : pd.getBuildRootIndex().findAllParentDescriptors(file, myContext)) {
if (!event.getSourceTarget().equals(desc.getTarget())) {
// It is assumed that those files will be explicitly marked dirty by particular builder, if needed.
try {
fsState.markDirty(myContext, file, desc, pd.timestamps.getStorage(), false);
} catch (IOException ignored) {
}
}
}
}
}
use of org.jetbrains.jps.builders.BuildRootDescriptor 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.BuildRootDescriptor in project android by JetBrains.
the class AndroidAarDepsBuildTarget method doComputeRootDescriptors.
@NotNull
@Override
protected List<BuildRootDescriptor> doComputeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
final Set<JpsLibrary> libraries = JpsJavaExtensionService.getInstance().enumerateDependencies(Collections.singleton(myModule)).runtimeOnly().productionOnly().getLibraries();
final List<BuildRootDescriptor> result = new ArrayList<BuildRootDescriptor>();
for (JpsLibrary library : libraries) {
final Pair<File, List<File>> pair = AndroidJpsUtil.getResDirAndJarsIfAar(library);
final List<File> jars = pair != null ? pair.getSecond() : null;
if (jars != null) {
for (File jar : jars) {
result.add(new BuildRootDescriptorImpl(this, jar));
}
}
}
return result;
}
use of org.jetbrains.jps.builders.BuildRootDescriptor in project android by JetBrains.
the class AndroidAarDepsBuilder method doBuild.
private static boolean doBuild(final CompileContext context, AndroidAarDepsBuildTarget target, BuildOutputConsumer outputConsumer) {
final JpsModule module = target.getModule();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
if (extension == null || extension.isLibrary()) {
return true;
}
File outputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME);
if (outputDir == null) {
return false;
}
final List<String> srcJarFiles = new ArrayList<String>();
for (BuildRootDescriptor descriptor : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) {
final File file = descriptor.getRootFile();
if (file.exists()) {
srcJarFiles.add(file.getPath());
}
}
if (srcJarFiles.size() == 0) {
return true;
}
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.aar.dependencies.packaging", module.getName())));
File tempDir = null;
try {
tempDir = FileUtil.createTempDirectory("extracted_aar_deps", "tmp");
for (int i = srcJarFiles.size() - 1; i >= 0; i--) {
ZipUtil.extract(new File(srcJarFiles.get(i)), tempDir, null, true);
}
final File outputJarFile = new File(outputDir, AndroidCommonUtils.AAR_DEPS_JAR_FILE_NAME);
if (!packDirectoryIntoJar(tempDir, outputJarFile, context)) {
return false;
}
final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
if (testingManager != null && outputJarFile.isFile()) {
testingManager.getCommandExecutor().checkJarContent("aar_dependencies_package_jar", outputJarFile.getPath());
}
outputConsumer.registerOutputFile(outputJarFile, srcJarFiles);
return true;
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, BUILDER_NAME);
return false;
} finally {
if (tempDir != null) {
FileUtil.delete(tempDir);
}
}
}
use of org.jetbrains.jps.builders.BuildRootDescriptor in project android by JetBrains.
the class AndroidDexBuildTarget method doComputeRootDescriptors.
@NotNull
@Override
protected List<BuildRootDescriptor> doComputeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(myModule);
assert extension != null;
if (extension.isLibrary()) {
return Collections.emptyList();
}
final Map<String, String> libPackage2ModuleName = new THashMap<String, String>(FileUtil.PATH_HASHING_STRATEGY);
final Set<String> appClassesDirs = new THashSet<String>(FileUtil.PATH_HASHING_STRATEGY);
final Set<String> javaClassesDirs = new THashSet<String>(FileUtil.PATH_HASHING_STRATEGY);
final Set<String> libClassesDirs = new THashSet<String>(FileUtil.PATH_HASHING_STRATEGY);
final File moduleClassesDir = new ModuleBuildTarget(myModule, JavaModuleBuildTargetType.PRODUCTION).getOutputDir();
if (moduleClassesDir != null) {
appClassesDirs.add(moduleClassesDir.getPath());
}
AndroidJpsUtil.processClasspath(dataPaths, myModule, new AndroidDependencyProcessor() {
@Override
public void processAndroidLibraryPackage(@NotNull File file, @NotNull JpsModule depModule) {
libPackage2ModuleName.put(file.getPath(), depModule.getName());
}
@Override
public void processAndroidLibraryOutputDirectory(@NotNull File dir) {
libClassesDirs.add(dir.getPath());
}
@Override
public void processJavaModuleOutputDirectory(@NotNull File dir) {
javaClassesDirs.add(dir.getPath());
}
@Override
public boolean isToProcess(@NotNull AndroidDependencyType type) {
return type == AndroidDependencyType.ANDROID_LIBRARY_PACKAGE || type == AndroidDependencyType.ANDROID_LIBRARY_OUTPUT_DIRECTORY || type == AndroidDependencyType.JAVA_MODULE_OUTPUT_DIR;
}
}, false, false);
if (extension.isPackTestCode()) {
final File testModuleClassesDir = new ModuleBuildTarget(myModule, JavaModuleBuildTargetType.TEST).getOutputDir();
if (testModuleClassesDir != null) {
appClassesDirs.add(testModuleClassesDir.getPath());
}
}
final List<BuildRootDescriptor> result = new ArrayList<BuildRootDescriptor>();
for (String classesDir : appClassesDirs) {
result.add(new MyClassesDirBuildRootDescriptor(this, new File(classesDir), ClassesDirType.ANDROID_APP));
}
for (String classesDir : libClassesDirs) {
result.add(new MyClassesDirBuildRootDescriptor(this, new File(classesDir), ClassesDirType.ANDROID_LIB));
}
for (String classesDir : javaClassesDirs) {
result.add(new MyClassesDirBuildRootDescriptor(this, new File(classesDir), ClassesDirType.JAVA));
}
final File preDexOutputDir = AndroidPreDexBuildTarget.getOutputDir(dataPaths);
for (Map.Entry<String, String> entry : libPackage2ModuleName.entrySet()) {
final String libPackage = entry.getKey();
final String moduleName = entry.getValue();
final File libPackageJarFile = new File(libPackage);
assert AndroidPreDexBuilder.canBePreDexed(libPackageJarFile);
result.add(new MyJarBuildRootDescriptor(this, libPackageJarFile, true, false));
result.add(new MyJarBuildRootDescriptor(this, new File(new File(preDexOutputDir, moduleName), libPackageJarFile.getName()), true, true));
}
final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(myModule, null, null);
if (platform != null) {
for (String jarOrLibDir : AndroidJpsUtil.getExternalLibraries(dataPaths, myModule, platform, false, false, true)) {
File file = new File(jarOrLibDir);
File preDexedFile = file;
if (AndroidPreDexBuilder.canBePreDexed(file)) {
final String preDexedFileName = AndroidPreDexBuilder.getOutputFileNameForExternalJar(file);
if (preDexedFileName != null) {
preDexedFile = new File(preDexOutputDir, preDexedFileName);
}
}
result.add(new MyJarBuildRootDescriptor(this, file, false, false));
result.add(new MyJarBuildRootDescriptor(this, preDexedFile, false, true));
}
}
for (String path : AndroidJpsUtil.getProvidedLibraries(dataPaths, myModule)) {
result.add(new MyProvidedJarBuildRootDescriptor(this, new File(path)));
}
return result;
}
Aggregations