Search in sources :

Example 71 with JpsModule

use of org.jetbrains.jps.model.module.JpsModule in project android by JetBrains.

the class AndroidManifestMergingBuilder method doManifestMerging.

private static boolean doManifestMerging(AndroidManifestMergingTarget target, CompileContext context, BuildOutputConsumer outputConsumer) throws IOException {
    final JpsModule module = target.getModule();
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
    assert extension != null;
    assert !extension.isLibrary();
    assert extension.isManifestMergingEnabled();
    final File outputDir = target.getOutputDirectory(context);
    if (!outputDir.exists() && !outputDir.mkdirs()) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", outputDir.getPath())));
        return false;
    }
    File manifestFile = null;
    final List<File> libManifests = new ArrayList<File>();
    final List<AndroidManifestMergingTarget.MyRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
    for (AndroidManifestMergingTarget.MyRootDescriptor root : roots) {
        if (root.isLibManifestRoot()) {
            libManifests.add(root.getRootFile());
        } else {
            manifestFile = root.getRootFile();
        }
    }
    if (manifestFile == null) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.errors.manifest.not.found", module.getName())));
        return false;
    }
    final File outputFile = new File(outputDir, SdkConstants.FN_ANDROID_MANIFEST_XML);
    if (!doMergeManifests(context, manifestFile, libManifests, outputFile)) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "[" + module.getName() + "] Cannot perform manifest merging"));
        return false;
    }
    final List<String> srcPaths = new ArrayList<String>();
    srcPaths.add(manifestFile.getPath());
    for (File libManifest : libManifests) {
        srcPaths.add(libManifest.getPath());
    }
    outputConsumer.registerOutputFile(outputFile, srcPaths);
    return true;
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) ArrayList(java.util.ArrayList) File(java.io.File)

Example 72 with JpsModule

use of org.jetbrains.jps.model.module.JpsModule 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)

Example 73 with JpsModule

use of org.jetbrains.jps.model.module.JpsModule in project android by JetBrains.

the class AndroidSourceGeneratingBuilder method doBuild.

private static ModuleLevelBuilder.ExitCode doBuild(CompileContext context, ModuleChunk chunk, DirtyFilesHolder<JavaSourceRootDescriptor, ModuleBuildTarget> dirtyFilesHolder) throws IOException {
    final Map<JpsModule, MyModuleData> moduleDataMap = computeModuleDatas(chunk.getModules(), context);
    if (moduleDataMap == null || moduleDataMap.size() == 0) {
        return ExitCode.ABORT;
    }
    if (!checkVersions(moduleDataMap, context)) {
        return ExitCode.ABORT;
    }
    checkAndroidDependencies(moduleDataMap, context);
    if (!checkArtifacts(context)) {
        return ExitCode.ABORT;
    }
    if (JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
        if (!clearAndroidStorages(context, chunk.getModules())) {
            return ExitCode.ABORT;
        }
    }
    final Map<File, ModuleBuildTarget> idlFilesToCompile = new HashMap<File, ModuleBuildTarget>();
    final Map<File, ModuleBuildTarget> rsFilesToCompile = new HashMap<File, ModuleBuildTarget>();
    dirtyFilesHolder.processDirtyFiles(new FileProcessor<JavaSourceRootDescriptor, ModuleBuildTarget>() {

        @Override
        public boolean apply(ModuleBuildTarget target, File file, JavaSourceRootDescriptor sourceRoot) throws IOException {
            final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(target.getModule());
            if (extension == null) {
                return true;
            }
            String fileName = file.getName();
            if (FileUtilRt.extensionEquals(fileName, AIDL_EXTENSION)) {
                idlFilesToCompile.put(file, target);
            } else if (FileUtilRt.extensionEquals(fileName, RENDERSCRIPT_EXTENSION)) {
                rsFilesToCompile.put(file, target);
            }
            return true;
        }
    });
    boolean success = true;
    final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
    if (JavaBuilderUtil.isForcedRecompilationAllJavaModules(context)) {
        for (JpsModule module : moduleDataMap.keySet()) {
            final File generatedSourcesStorage = AndroidJpsUtil.getGeneratedSourcesStorage(module, dataManager);
            if (generatedSourcesStorage.exists() && !deleteAndMarkRecursively(generatedSourcesStorage, context, BUILDER_NAME)) {
                success = false;
            }
            final File generatedResourcesStorage = AndroidJpsUtil.getGeneratedResourcesStorage(module, dataManager);
            if (generatedResourcesStorage.exists() && !deleteAndMarkRecursively(generatedResourcesStorage, context, BUILDER_NAME)) {
                success = false;
            }
        }
    }
    if (!success) {
        return ExitCode.ABORT;
    }
    boolean didSomething = false;
    if (idlFilesToCompile.size() > 0) {
        if (!runAidlCompiler(context, idlFilesToCompile, moduleDataMap)) {
            success = false;
        }
        didSomething = true;
    }
    if (rsFilesToCompile.size() > 0) {
        if (!runRenderscriptCompiler(context, rsFilesToCompile, moduleDataMap)) {
            success = false;
        }
        didSomething = true;
    }
    MyExitStatus status = runAaptCompiler(context, moduleDataMap);
    if (status == MyExitStatus.FAIL) {
        success = false;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    status = runBuildConfigGeneration(context, moduleDataMap);
    if (status == MyExitStatus.FAIL) {
        success = false;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    if (!success) {
        return ExitCode.ABORT;
    }
    status = copyGeneratedSources(moduleDataMap, dataManager, context);
    if (status == MyExitStatus.FAIL) {
        return ExitCode.ABORT;
    } else if (status == MyExitStatus.OK) {
        didSomething = true;
    }
    if (didSomething) {
        return ExitCode.OK;
    }
    return ExitCode.NOTHING_DONE;
}
Also used : HashMap(com.intellij.util.containers.HashMap) TObjectLongHashMap(gnu.trove.TObjectLongHashMap) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtension(org.jetbrains.jps.android.model.JpsAndroidModuleExtension) JavaSourceRootDescriptor(org.jetbrains.jps.builders.java.JavaSourceRootDescriptor) BuildDataManager(org.jetbrains.jps.incremental.storage.BuildDataManager)

Example 74 with JpsModule

use of org.jetbrains.jps.model.module.JpsModule in project android by JetBrains.

the class AndroidBuilderTest method testProGuardWithJar.

public void testProGuardWithJar() throws Exception {
    final MyExecutor executor = new MyExecutor("com.example.simple") {

        @Override
        protected void doCheckJar(@NotNull String jarId, @NotNull String jarPath) {
            if ("proguard_input_jar".equals(jarId)) {
                File tmpDir = null;
                try {
                    tmpDir = FileUtil.createTempDirectory("proguard_input_jar_checking", "tmp");
                    final File jar = new File(tmpDir, "file.jar");
                    FileUtil.copy(new File(jarPath), jar);
                    assertOutput(tmpDir.getPath(), TestFileSystemItem.fs().archive("file.jar").dir("com").dir("example").dir("simple").file("BuildConfig.class").file("R.class").file("MyActivity.class"));
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } finally {
                    if (tmpDir != null) {
                        FileUtil.delete(tmpDir);
                    }
                }
            }
        }
    };
    final JpsModule module = setUpSimpleAndroidStructure(new String[] { "src" }, executor, null).getFirst();
    module.addSourceRoot(JpsPathUtil.pathToUrl(getProjectPath("tests")), JavaSourceRootType.TEST_SOURCE);
    final JpsLibrary lib = module.addModuleLibrary("lib", JpsJavaLibraryType.INSTANCE);
    lib.addRoot(new File(getProjectPath("libs/external_jar.jar")), JpsOrderRootType.COMPILED);
    module.getDependenciesList().addLibraryDependency(lib);
    final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
    assert extension instanceof JpsAndroidModuleExtensionImpl;
    final JpsAndroidModuleProperties properties = ((JpsAndroidModuleExtensionImpl) extension).getProperties();
    assert properties != null;
    properties.RUN_PROGUARD = true;
    properties.myProGuardCfgFiles = Arrays.asList("file://%MODULE_SDK_HOME%/tools/proguard/proguard-android.txt", VfsUtilCore.pathToUrl(getProjectPath("proguard-project.txt")));
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log");
    checkMakeUpToDate(executor);
    doBuild(CompileScopeTestBuilder.rebuild().allModules().targetTypes(AndroidManifestMergingTarget.MyTargetType.INSTANCE, AndroidDexBuildTarget.MyTargetType.INSTANCE, AndroidResourceCachingBuildTarget.MyTargetType.INSTANCE, AndroidResourcePackagingBuildTarget.MyTargetType.INSTANCE, AndroidPackagingBuildTarget.MyTargetType.INSTANCE, AndroidLibraryPackagingTarget.MyTargetType.INSTANCE, AndroidPackagingBuildTarget.MyTargetType.INSTANCE)).assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtensionImpl(org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) NotNull(org.jetbrains.annotations.NotNull) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Example 75 with JpsModule

use of org.jetbrains.jps.model.module.JpsModule in project android by JetBrains.

the class AndroidBuilderTest method test1.

public void test1() throws Exception {
    final MyExecutor executor = new MyExecutor("com.example.simple");
    final JpsModule module = setUpSimpleAndroidStructure(ArrayUtil.EMPTY_STRING_ARRAY, executor, null).getFirst();
    rebuildAll();
    checkBuildLog(executor, "expected_log");
    checkMakeUpToDate(executor);
    assertOutput(module, TestFileSystemItem.fs().dir("com").dir("example").dir("simple").file("BuildConfig.class").file("R.class").end().end().end().archive("module.apk").file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content"));
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule)

Aggregations

JpsModule (org.jetbrains.jps.model.module.JpsModule)128 File (java.io.File)33 NotNull (org.jetbrains.annotations.NotNull)15 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)15 JpsAndroidModuleExtension (org.jetbrains.jps.android.model.JpsAndroidModuleExtension)14 JpsAndroidModuleExtensionImpl (org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl)13 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)13 THashSet (gnu.trove.THashSet)11 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)11 ProgressMessage (org.jetbrains.jps.incremental.messages.ProgressMessage)10 JpsSimpleElement (org.jetbrains.jps.model.JpsSimpleElement)10 JpsArtifact (org.jetbrains.jps.model.artifact.JpsArtifact)10 ArrayList (java.util.ArrayList)9 HashMap (com.intellij.util.containers.HashMap)8 IOException (java.io.IOException)8 TObjectLongHashMap (gnu.trove.TObjectLongHashMap)7 JpsDependencyElement (org.jetbrains.jps.model.module.JpsDependencyElement)7 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)6 Pair (com.intellij.openapi.util.Pair)5 Nullable (org.jetbrains.annotations.Nullable)5