Search in sources :

Example 11 with BuildRootDescriptor

use of org.jetbrains.jps.builders.BuildRootDescriptor in project android by JetBrains.

the class AndroidPackagingBuildTarget method doComputeRootDescriptors.

@NotNull
@Override
protected List<BuildRootDescriptor> doComputeRootDescriptors(JpsModel model, ModuleExcludeIndex index, IgnoredFileIndex ignoredFileIndex, BuildDataPaths dataPaths) {
    final File resPackage = AndroidResourcePackagingBuildTarget.getOutputFile(dataPaths, myModule);
    final File classesDexFile = AndroidDexBuildTarget.getOutputFile(dataPaths, myModule);
    final List<BuildRootDescriptor> roots = new ArrayList<BuildRootDescriptor>();
    roots.add(new BuildRootDescriptorImpl(this, resPackage));
    roots.add(new BuildRootDescriptorImpl(this, classesDexFile));
    final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(myModule, null, null);
    if (platform != null) {
        for (String jarOrLibDir : AndroidJpsUtil.getExternalLibraries(dataPaths, myModule, platform, false, true, false)) {
            roots.add(new BuildRootDescriptorImpl(this, new File(jarOrLibDir), false));
        }
    }
    for (File resourceRoot : AndroidJpsUtil.getJavaOutputRootsForModuleAndDependencies(myModule)) {
        roots.add(new MyResourceRootDescriptor(this, resourceRoot));
    }
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(myModule);
    assert extension != null;
    for (String nativeLibDir : collectNativeLibsFolders(extension, false)) {
        roots.add(new BuildRootDescriptorImpl(this, new File(nativeLibDir)));
    }
    return roots;
}
Also used : BuildRootDescriptorImpl(org.jetbrains.jps.builders.impl.BuildRootDescriptorImpl) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) ArrayList(java.util.ArrayList) AndroidPlatform(org.jetbrains.jps.android.AndroidPlatform) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with BuildRootDescriptor

use of org.jetbrains.jps.builders.BuildRootDescriptor in project android by JetBrains.

the class AndroidResourcePackagingBuildTarget 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;
    final String[] resourceDirs = AndroidJpsUtil.collectResourceDirsForCompilation(extension, true, dataPaths, false);
    final List<String> assertDirs = new ArrayList<String>();
    collectAssetDirs(extension, assertDirs, false);
    final File manifestFile = AndroidJpsUtil.getPreprocessedManifestFile(extension, dataPaths);
    final List<BuildRootDescriptor> result = new ArrayList<BuildRootDescriptor>();
    for (String resourceDir : resourceDirs) {
        result.add(new BuildRootDescriptorImpl(this, new File(resourceDir)));
    }
    for (String assetDir : assertDirs) {
        result.add(new BuildRootDescriptorImpl(this, new File(assetDir)));
    }
    if (manifestFile != null) {
        result.add(new BuildRootDescriptorImpl(this, manifestFile));
    }
    return result;
}
Also used : BuildRootDescriptorImpl(org.jetbrains.jps.builders.impl.BuildRootDescriptorImpl) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) ArrayList(java.util.ArrayList) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with BuildRootDescriptor

use of org.jetbrains.jps.builders.BuildRootDescriptor in project android by JetBrains.

the class AndroidResourceCachingBuilder method runPngCaching.

private static boolean runPngCaching(AndroidResourceCachingBuildTarget target, CompileContext context, BuildOutputConsumer outputConsumer) throws IOException {
    final JpsModule module = target.getModule();
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
    assert extension != null;
    context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.INFO, AndroidJpsBundle.message("android.jps.progress.res.caching", module.getName())));
    final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
    if (platform == null) {
        return false;
    }
    final File resCacheDir = target.getOutputDir(context);
    // todo: probably it may be done automatically
    if (context.getScope().isBuildForced(target) && resCacheDir.exists()) {
        if (!FileUtil.delete(resCacheDir)) {
            context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", resCacheDir.getPath())));
            return false;
        }
    }
    if (!resCacheDir.exists()) {
        if (!resCacheDir.mkdirs()) {
            context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", resCacheDir.getPath())));
            return false;
        }
    }
    final IAndroidTarget androidTarget = platform.getTarget();
    final List<BuildRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
    if (roots.size() == 0) {
        return true;
    }
    final List<String> inputDirs = new ArrayList<String>();
    for (BuildRootDescriptor root : roots) {
        final File f = root.getRootFile();
        if (f.exists()) {
            inputDirs.add(f.getPath());
        }
    }
    final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApt.crunch(androidTarget, inputDirs, resCacheDir.getPath());
    AndroidJpsUtil.addMessages(context, messages, BUILDER_NAME, module.getName());
    final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).isEmpty();
    if (success) {
        final Map<String, File> outputFiles = new HashMap<String, File>();
        FileUtil.processFilesRecursively(resCacheDir, new Processor<File>() {

            @Override
            public boolean process(File file) {
                if (file.isFile()) {
                    final String relativePath = FileUtil.getRelativePath(resCacheDir, file);
                    if (relativePath != null) {
                        outputFiles.put(relativePath, file);
                    }
                }
                return true;
            }
        });
        for (Map.Entry<String, File> entry : outputFiles.entrySet()) {
            final String relativePath = entry.getKey();
            final File outputFile = entry.getValue();
            for (String inputDir : inputDirs) {
                final File srcFile = new File(inputDir, relativePath);
                outputConsumer.registerOutputFile(outputFile, Collections.singletonList(srcFile.getPath()));
            }
        }
    }
    return success;
}
Also used : BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) HashMap(com.intellij.util.containers.HashMap) ArrayList(java.util.ArrayList) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidCompilerMessageKind(org.jetbrains.android.util.AndroidCompilerMessageKind) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map)

Example 14 with BuildRootDescriptor

use of org.jetbrains.jps.builders.BuildRootDescriptor in project android by JetBrains.

the class AndroidDexBuilder method doDexBuild.

private static boolean doDexBuild(@NotNull AndroidDexBuildTarget target, @NotNull CompileContext context, boolean hasDirtyFiles, @NotNull BuildOutputConsumer outputConsumer) throws IOException {
    final JpsModule module = target.getModule();
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
    assert extension != null;
    assert !extension.isLibrary();
    final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, DEX_BUILDER_NAME);
    if (platform == null) {
        return false;
    }
    File dexOutputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
    dexOutputDir = AndroidJpsUtil.createDirIfNotExist(dexOutputDir, context, DEX_BUILDER_NAME);
    if (dexOutputDir == null) {
        return false;
    }
    final ProGuardOptions proGuardOptions = AndroidJpsUtil.getProGuardConfigIfShouldRun(context, extension);
    if (proGuardOptions != null) {
        if (proGuardOptions.getCfgFiles() == null) {
            context.processMessage(new CompilerMessage(DEX_BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.cannot.find.proguard.cfg", module.getName())));
            return false;
        }
    }
    final File proguardCfgOutputFile = new File(dexOutputDir, AndroidCommonUtils.PROGUARD_CFG_OUTPUT_FILE_NAME);
    final AndroidProGuardStateStorage proGuardOptionsStorage = context.getProjectDescriptor().dataManager.getStorage(target, AndroidProGuardOptionsStorageProvider.INSTANCE);
    final AndroidProGuardStateStorage.MyState oldProGuardState = proGuardOptionsStorage.read();
    final Set<String> fileSet;
    AndroidProGuardStateStorage.MyState newProGuardState = null;
    try {
        if (proGuardOptions != null) {
            final List<String> proguardCfgFilePathsList = new ArrayList<String>();
            for (File file : proGuardOptions.getCfgFiles()) {
                proguardCfgFilePathsList.add(file.getAbsolutePath());
            }
            proguardCfgFilePathsList.add(proguardCfgOutputFile.getPath());
            final String[] proguardCfgFilePaths = ArrayUtil.toStringArray(proguardCfgFilePathsList);
            final String outputJarPath = FileUtil.toSystemDependentName(dexOutputDir.getPath() + '/' + AndroidCommonUtils.PROGUARD_OUTPUT_JAR_NAME);
            final Pair<Boolean, AndroidProGuardStateStorage.MyState> pair = runProguardIfNecessary(extension, target, platform, context, outputJarPath, proguardCfgFilePaths, hasDirtyFiles, oldProGuardState);
            if (pair == null) {
                // error reported
                return false;
            }
            if (!pair.getFirst()) {
                // nothing changed
                return true;
            }
            newProGuardState = pair.getSecond();
            assert newProGuardState != null;
            fileSet = Collections.singleton(outputJarPath);
        } else {
            if (!hasDirtyFiles && oldProGuardState == null) {
                return true;
            }
            final List<BuildRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
            fileSet = new HashSet<String>();
            final boolean predexingEnabled = extension.isPreDexingEnabled() && isPredexingInScope(context);
            for (BuildRootDescriptor root : roots) {
                final File rootFile = root.getRootFile();
                if (!rootFile.exists()) {
                    continue;
                }
                if (root instanceof AndroidDexBuildTarget.MyClassesDirBuildRootDescriptor) {
                    final AndroidDexBuildTarget.ClassesDirType type = ((AndroidDexBuildTarget.MyClassesDirBuildRootDescriptor) root).getClassesDirType();
                    if (type == AndroidDexBuildTarget.ClassesDirType.JAVA) {
                        fileSet.add(rootFile.getPath());
                    } else if (type == AndroidDexBuildTarget.ClassesDirType.ANDROID_APP) {
                        AndroidJpsUtil.addSubdirectories(rootFile, fileSet);
                    }
                } else if (root instanceof AndroidDexBuildTarget.MyJarBuildRootDescriptor) {
                    if (((AndroidDexBuildTarget.MyJarBuildRootDescriptor) root).isPreDexed() == predexingEnabled) {
                        fileSet.add(rootFile.getPath());
                    }
                }
            }
        }
        final boolean success;
        if (fileSet.size() > 0) {
            final String[] files = new String[fileSet.size()];
            int i = 0;
            for (String filePath : fileSet) {
                files[i++] = FileUtil.toSystemDependentName(filePath);
            }
            context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.dex", module.getName())));
            Arrays.sort(files);
            success = runDex(platform, dexOutputDir.getPath(), files, context, module, outputConsumer);
        } else {
            success = true;
        }
        if (success) {
            proGuardOptionsStorage.update(newProGuardState);
        }
        return success;
    } catch (IOException e) {
        AndroidJpsUtil.reportExceptionError(context, null, e, DEX_BUILDER_NAME);
        return false;
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) AndroidDexBuildTarget(org.jetbrains.jps.android.builder.AndroidDexBuildTarget) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) IOException(java.io.IOException) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) File(java.io.File)

Example 15 with BuildRootDescriptor

use of org.jetbrains.jps.builders.BuildRootDescriptor in project intellij-plugins by JetBrains.

the class FlexResourceBuilder method build.

public void build(@NotNull final FlexResourceBuildTarget target, @NotNull final DirtyFilesHolder<BuildRootDescriptor, FlexResourceBuildTarget> holder, @NotNull final BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException, IOException {
    final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getOrCreateCompilerConfiguration(target.getModule().getProject());
    final JpsCompilerExcludes excludes = configuration.getCompilerExcludes();
    try {
        holder.processDirtyFiles(new FileProcessor<BuildRootDescriptor, FlexResourceBuildTarget>() {

            public boolean apply(final FlexResourceBuildTarget target, final File file, final BuildRootDescriptor root) throws IOException {
                if (excludes.isExcluded(file))
                    return true;
                final String relativePath = FileUtil.toSystemIndependentName(FileUtil.getRelativePath(root.getRootFile(), file));
                if (target.isTests()) {
                    if (!FlexCommonUtils.isSourceFile(file.getName())) {
                        final String outputRootUrl = JpsJavaExtensionService.getInstance().getOutputUrl(target.getModule(), target.isTests());
                        if (outputRootUrl == null)
                            return true;
                        final String targetPath = JpsPathUtil.urlToPath(outputRootUrl) + '/' + relativePath;
                        context.processMessage(new ProgressMessage("Copying " + file.getPath()));
                        copyResource(context, file, Collections.singleton(targetPath), outputConsumer);
                    }
                } else {
                    final Collection<String> targetPaths = new ArrayList<>();
                    for (JpsFlexBuildConfiguration bc : target.getModule().getProperties().getBuildConfigurations()) {
                        if (bc.isSkipCompile() || !FlexCommonUtils.canHaveResourceFiles(bc.getNature()) || bc.getCompilerOptions().getResourceFilesMode() == JpsFlexCompilerOptions.ResourceFilesMode.None) {
                            continue;
                        }
                        final JpsFlexCompilerOptions.ResourceFilesMode mode = bc.getCompilerOptions().getResourceFilesMode();
                        if (mode == JpsFlexCompilerOptions.ResourceFilesMode.All && !FlexCommonUtils.isSourceFile(file.getName()) || mode == JpsFlexCompilerOptions.ResourceFilesMode.ResourcePatterns && configuration.isResourceFile(file, root.getRootFile())) {
                            final String outputFolder = PathUtilRt.getParentPath(bc.getActualOutputFilePath());
                            targetPaths.add(outputFolder + "/" + relativePath);
                        }
                    }
                    if (!targetPaths.isEmpty()) {
                        context.processMessage(new ProgressMessage("Copying " + file.getPath()));
                        copyResource(context, file, targetPaths, outputConsumer);
                    }
                }
                return true;
            }
        });
    } catch (Exception e) {
        throw new ProjectBuildException(e.getMessage(), e);
    }
}
Also used : ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsJavaCompilerConfiguration(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerConfiguration) BuildRootDescriptor(org.jetbrains.jps.builders.BuildRootDescriptor) ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) IOException(java.io.IOException) FlexResourceBuildTarget(com.intellij.flex.build.FlexResourceBuildTarget) IOException(java.io.IOException) ProjectBuildException(org.jetbrains.jps.incremental.ProjectBuildException) JpsCompilerExcludes(org.jetbrains.jps.model.java.compiler.JpsCompilerExcludes) Collection(java.util.Collection) JpsFlexBuildConfiguration(com.intellij.flex.model.bc.JpsFlexBuildConfiguration) File(java.io.File)

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