Search in sources :

Example 6 with BuildRootDescriptor

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) {
                }
            }
        }
    }
}
Also used : BuildFSState(org.jetbrains.jps.incremental.fs.BuildFSState) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) IOException(java.io.IOException) File(java.io.File)

Example 7 with BuildRootDescriptor

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);
    }
}
Also used : BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor)

Example 8 with BuildRootDescriptor

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;
}
Also used : BuildRootDescriptorImpl(org.jetbrains.jps.builders.impl.BuildRootDescriptorImpl) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with BuildRootDescriptor

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);
        }
    }
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) AndroidBuildTestingManager(org.jetbrains.android.util.AndroidBuildTestingManager) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File)

Example 10 with BuildRootDescriptor

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;
}
Also used : BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) ModuleBuildTarget(org.jetbrains.jps.incremental.ModuleBuildTarget) THashSet(gnu.trove.THashSet) JpsModule(org.jetbrains.jps.model.module.JpsModule) THashMap(gnu.trove.THashMap) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) File(java.io.File) THashMap(gnu.trove.THashMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

BuildRootDescriptor (org.jetbrains.jps.builders.BuildRootDescriptor)16 File (java.io.File)15 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)5 JpsModule (org.jetbrains.jps.model.module.JpsModule)5 BuildRootDescriptorImpl (org.jetbrains.jps.builders.impl.BuildRootDescriptorImpl)4 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)4 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)4 JpsFlexBuildConfiguration (com.intellij.flex.model.bc.JpsFlexBuildConfiguration)2 THashSet (gnu.trove.THashSet)2 AndroidBuildTestingManager (org.jetbrains.android.util.AndroidBuildTestingManager)2 AndroidCompilerMessageKind (org.jetbrains.android.util.AndroidCompilerMessageKind)2 AndroidDexBuildTarget (org.jetbrains.jps.android.builder.AndroidDexBuildTarget)2 BuildFSState (org.jetbrains.jps.incremental.fs.BuildFSState)2 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 FlexBuildTarget (com.intellij.flex.build.FlexBuildTarget)1 FlexResourceBuildTarget (com.intellij.flex.build.FlexResourceBuildTarget)1 HashMap (com.intellij.util.containers.HashMap)1