Search in sources :

Example 76 with JpsModule

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

the class AndroidBuilderTest method test4.

public void test4() 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").file("MyClass.class"));
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } finally {
                    if (tmpDir != null) {
                        FileUtil.delete(tmpDir);
                    }
                }
            }
        }
    };
    final JpsModule androidModule = setUpSimpleAndroidStructure(new String[] { "src" }, executor, "android_module").getFirst();
    final String copiedSourceRoot = copyToProject(getDefaultTestDataDirForCurrentTest() + "/project/java_module/src", "root/java_module/src");
    final JpsModule javaModule = addModule("java_module", copiedSourceRoot);
    rebuildAll();
    checkBuildLog(executor, "expected_log");
    checkMakeUpToDate(executor);
    androidModule.getDependenciesList().addModuleDependency(javaModule);
    makeAll();
    checkBuildLog(executor, "expected_log_1");
    checkMakeUpToDate(executor);
    change(getProjectPath("src/com/example/simple/MyActivity.java"), "package com.example.simple;\n" + "import android.app.Activity;\n" + "import android.os.Bundle;\n" + "public class MyActivity extends Activity {\n" + "    @Override\n" + "    public void onCreate(Bundle savedInstanceState) {\n" + "        super.onCreate(savedInstanceState);\n" + "        final String s = MyClass.getMessage();\n" + "    }\n" + "}\n");
    makeAll();
    checkBuildLog(executor, "expected_log_2");
    assertCompiled(JavaBuilder.BUILDER_NAME, "root/src/com/example/simple/MyActivity.java");
    checkMakeUpToDate(executor);
    change(getProjectPath("java_module/src/com/example/simple/MyClass.java"));
    makeAll();
    checkBuildLog(executor, "expected_log_3");
    assertCompiled(JavaBuilder.BUILDER_NAME, "root/java_module/src/com/example/simple/MyClass.java");
    checkMakeUpToDate(executor);
    final String systemProguardCfgPath = FileUtil.toSystemDependentName(androidModule.getSdk(JpsAndroidSdkType.INSTANCE).getHomePath() + "/tools/proguard/proguard-android.txt");
    myBuildParams.put(AndroidCommonUtils.PROGUARD_CFG_PATHS_OPTION, systemProguardCfgPath + File.pathSeparator + getProjectPath("proguard-project.txt"));
    makeAll();
    checkBuildLog(executor, "expected_log_4");
    assertEquals(Collections.singleton("proguard_input_jar"), executor.getCheckedJars());
    checkMakeUpToDate(executor);
    final JpsAndroidExtensionService service = JpsAndroidExtensionService.getInstance();
    final JpsAndroidDexCompilerConfiguration c = service.getDexCompilerConfiguration(myProject);
    assertNotNull(c);
    service.setDexCompilerConfiguration(myProject, c);
    c.setProguardVmOptions("-Xmx700M");
    makeAll();
    checkBuildLog(executor, "expected_log_5");
    checkMakeUpToDate(executor);
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) NotNull(org.jetbrains.annotations.NotNull)

Example 77 with JpsModule

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

the class AndroidBuilderTest method testMaven.

public void testMaven() throws Exception {
    createMavenConfigFile();
    final MyExecutor executor = new MyExecutor("com.example.simple");
    final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> androidSdk = addJdkAndAndroidSdk();
    addPathPatterns(executor, androidSdk);
    final JpsModule appModule = addAndroidModule("app", new String[] { "src" }, "app", "app", androidSdk).getFirst();
    final JpsModule libModule = addAndroidModule("lib2", new String[] { "src" }, "lib", "lib2", androidSdk).getFirst();
    final JpsModule libModule1 = addAndroidModule("lib1", new String[] { "src" }, "lib1", "lib1", androidSdk).getFirst();
    JpsMavenExtensionService.getInstance().getOrCreateExtension(appModule);
    final MavenProjectConfiguration mavenConf = ((JpsMavenExtensionServiceImpl) JpsMavenExtensionService.getInstance()).getMavenProjectConfiguration(myDataStorageRoot);
    addMavenResourcesConf(mavenConf, "app");
    addMavenResourcesConf(mavenConf, "lib2");
    addMavenResourcesConf(mavenConf, "lib1");
    final JpsAndroidModuleExtension libExtension = AndroidJpsUtil.getExtension(libModule);
    assert libExtension != null;
    final JpsAndroidModuleProperties libProps = ((JpsAndroidModuleExtensionImpl) libExtension).getProperties();
    libProps.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
    final JpsAndroidModuleExtension libExtension1 = AndroidJpsUtil.getExtension(libModule1);
    assert libExtension1 != null;
    final JpsAndroidModuleProperties libProps1 = ((JpsAndroidModuleExtensionImpl) libExtension1).getProperties();
    libProps1.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
    appModule.getDependenciesList().addModuleDependency(libModule);
    libModule.getDependenciesList().addModuleDependency(libModule1);
    rebuildAll();
    checkBuildLog(executor, "expected_log");
    assertOutput(appModule, TestFileSystemItem.fs().file("com").archive("app.apk").dir("lib").file("lib_resource.txt").end().dir("com").file("app_resource.txt").end().file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content"));
    checkMakeUpToDate(executor);
    JpsMavenExtensionService.getInstance().getOrCreateExtension(libModule);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    checkMakeUpToDate(executor);
    final JpsModule nonMavenAppModule = addAndroidModule("non_maven_app", new String[] { "src" }, "app", "non_maven_app", androidSdk).getFirst();
    nonMavenAppModule.getDependenciesList().addModuleDependency(libModule);
    final JpsModule libModule2 = addAndroidModule("lib3", new String[] { "src" }, "lib1", "lib3", androidSdk).getFirst();
    final JpsAndroidModuleExtension libExtension2 = AndroidJpsUtil.getExtension(libModule2);
    assert libExtension2 != null;
    final JpsAndroidModuleProperties libProps2 = ((JpsAndroidModuleExtensionImpl) libExtension2).getProperties();
    libProps2.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
    libModule1.getDependenciesList().addModuleDependency(libModule2);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_2");
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtensionImpl(org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)

Example 78 with JpsModule

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

the class AndroidBuilderTest method addAndroidModule.

private Pair<JpsModule, Path> addAndroidModule(String moduleName, String[] sourceRoots, String contentRootDir, String dstContentRootDir, JpsSdk<? extends JpsElement> androidSdk, String testDirName) {
    final String testDataRoot = getTestDataDirForCurrentTest(testDirName);
    final String projectRoot = testDataRoot + "/project";
    final String moduleContentRoot = contentRootDir != null ? new File(projectRoot, contentRootDir).getPath() : projectRoot;
    final String dstRoot = dstContentRootDir != null ? "root/" + dstContentRootDir : "root";
    final String root = copyToProject(moduleContentRoot, dstRoot);
    final String outputPath = getAbsolutePath("out/production/" + moduleName);
    final String testOutputPath = getAbsolutePath("out/test/" + moduleName);
    final JpsModule module = addModule(moduleName, ArrayUtil.EMPTY_STRING_ARRAY, outputPath, testOutputPath, androidSdk);
    module.getContentRootsList().addUrl(JpsPathUtil.pathToUrl(root));
    for (String sourceRoot : sourceRoots) {
        final String sourceRootName = new File(sourceRoot).getName();
        final String copiedSourceRoot = copyToProject(moduleContentRoot + "/" + sourceRoot, dstRoot + "/" + sourceRootName);
        module.addSourceRoot(JpsPathUtil.pathToUrl(copiedSourceRoot), JavaSourceRootType.SOURCE);
    }
    final JpsAndroidModuleProperties properties = new JpsAndroidModuleProperties();
    properties.MANIFEST_FILE_RELATIVE_PATH = "/AndroidManifest.xml";
    properties.RES_FOLDER_RELATIVE_PATH = "/res";
    properties.ASSETS_FOLDER_RELATIVE_PATH = "/assets";
    properties.LIBS_FOLDER_RELATIVE_PATH = "/libs";
    properties.GEN_FOLDER_RELATIVE_PATH_APT = "/gen";
    properties.GEN_FOLDER_RELATIVE_PATH_AIDL = "/gen";
    properties.PACK_TEST_CODE = false;
    module.getContainer().setChild(JpsModuleSerializationDataExtensionImpl.ROLE, new JpsModuleSerializationDataExtensionImpl(Paths.get(root)));
    module.getContainer().setChild(JpsAndroidModuleExtensionImpl.KIND, new JpsAndroidModuleExtensionImpl(properties));
    return Pair.create(module, Paths.get(root));
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtensionImpl(org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl) JpsModuleSerializationDataExtensionImpl(org.jetbrains.jps.model.serialization.impl.JpsModuleSerializationDataExtensionImpl) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)

Example 79 with JpsModule

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

the class AndroidBuilderTest method test9.

public void test9() throws Exception {
    final MyExecutor executor = new MyExecutor("com.example.simple");
    final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> androidSdk = addJdkAndAndroidSdk();
    addPathPatterns(executor, androidSdk);
    final JpsModule appModule1 = addAndroidModule("app1", new String[] { "src" }, "app1", "app1", androidSdk).getFirst();
    final JpsModule appModule2 = addAndroidModule("app2", new String[] { "src" }, "app2", "app2", androidSdk).getFirst();
    final JpsModule libModule = addAndroidModule("lib", new String[] { "src" }, "lib", "lib", androidSdk).getFirst();
    final JpsAndroidModuleExtension libExtension = AndroidJpsUtil.getExtension(libModule);
    assert libExtension != null;
    final JpsAndroidModuleProperties libProps = ((JpsAndroidModuleExtensionImpl) libExtension).getProperties();
    libProps.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log");
    assertEquals(1, executor.getCheckedJars().size());
    checkMakeUpToDate(executor);
    appModule1.getDependenciesList().addModuleDependency(libModule);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    assertTrue(executor.getCheckedJars().isEmpty());
    checkMakeUpToDate(executor);
    appModule2.getDependenciesList().addModuleDependency(libModule);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_2");
    assertTrue(executor.getCheckedJars().isEmpty());
    checkMakeUpToDate(executor);
    final JpsLibrary appLib = appModule1.addModuleLibrary("appLib1", JpsJavaLibraryType.INSTANCE);
    appLib.addRoot(getProjectPath("lib/external_jar.jar"), JpsOrderRootType.COMPILED);
    appModule1.getDependenciesList().addLibraryDependency(appLib);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_3");
    assertTrue(executor.getCheckedJars().isEmpty());
    checkMakeUpToDate(executor);
    final JpsLibrary libLib = appModule2.addModuleLibrary("appLib2", JpsJavaLibraryType.INSTANCE);
    libLib.addRoot(new File(getProjectPath("lib/external_jar.jar")), JpsOrderRootType.COMPILED);
    appModule2.getDependenciesList().addLibraryDependency(libLib);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_4");
    assertTrue(executor.getCheckedJars().isEmpty());
    checkMakeUpToDate(executor);
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtensionImpl(org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Example 80 with JpsModule

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

the class AndroidBuilderTest method test2.

public void test2() throws Exception {
    final MyExecutor executor = new MyExecutor("com.example.simple");
    final JpsModule module = setUpSimpleAndroidStructure(new String[] { "src" }, 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").file("MyActivity.class").end().end().end().archive("module.apk").file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content").dir("lib").dir("armeabi").file("mylib.so", "mylib_content"));
    change(getProjectPath("src/com/example/simple/MyActivity.java"));
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_1");
    assertCompiled(JavaBuilder.BUILDER_NAME, "root/src/com/example/simple/MyActivity.java");
    checkMakeUpToDate(executor);
    change(getProjectPath("res/layout/main.xml"));
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_2");
    assertCompiled(JavaBuilder.BUILDER_NAME);
    checkMakeUpToDate(executor);
    change(getProjectPath("res/values/strings.xml"), "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<resources>\n" + "    <string name=\"app_name\">changed_string</string>\n" + "</resources>");
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_10");
    checkMakeUpToDate(executor);
    change(getProjectPath("res/values/strings.xml"), "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<resources>\n" + "    <string name=\"app_name\">changed_string</string>\n" + "    <string name=\"new_string\">new_string</string>\n" + "</resources>");
    executor.setRClassContent("public static int change = 1;");
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_3");
    assertCompiled(JavaBuilder.BUILDER_NAME, "targets/java-production/module/android/generated_sources/aapt/com/example/simple/R.java");
    checkMakeUpToDate(executor);
    FileUtil.rename(new File(getProjectPath("res/drawable-hdpi/ic_launcher.png")), new File(getProjectPath("res/drawable-hdpi/new_name.png")));
    executor.setRClassContent("public static int change = 2;");
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_4");
    assertCompiled(JavaBuilder.BUILDER_NAME, "targets/java-production/module/android/generated_sources/aapt/com/example/simple/R.java");
    checkMakeUpToDate(executor);
    FileUtil.writeToFile(new File(getProjectPath("res/drawable-hdpi/new_file.png")), "new_file_png_content");
    executor.setRClassContent("public static int change = 3;");
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_5");
    assertCompiled(JavaBuilder.BUILDER_NAME, "targets/java-production/module/android/generated_sources/aapt/com/example/simple/R.java");
    checkMakeUpToDate(executor);
    change(getProjectPath("libs/armeabi/mylib.so"), "mylib_content_changed");
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_11");
    assertCompiled(JavaBuilder.BUILDER_NAME);
    assertOutput(module, TestFileSystemItem.fs().file("com").archive("module.apk").file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content").dir("lib").dir("armeabi").file("mylib.so", "mylib_content_changed"));
    checkMakeUpToDate(executor);
    change(getProjectPath("AndroidManifest.xml"));
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_6");
    assertCompiled(JavaBuilder.BUILDER_NAME);
    checkMakeUpToDate(executor);
    delete(getProjectPath("AndroidManifest.xml"));
    copyToProject(getDefaultTestDataDirForCurrentTest() + "/changed_manifest.xml", "root/AndroidManifest.xml");
    executor.clear();
    executor.setPackage("com.example.simple1");
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_7");
    assertCompiled(JavaBuilder.BUILDER_NAME, "targets/java-production/module/android/generated_sources/aapt/com/example/simple1/R.java", "targets/java-production/module/android/generated_sources/build_config/com/example/simple1/BuildConfig.java");
    checkMakeUpToDate(executor);
    change(getProjectPath("assets/myasset.txt"));
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_8");
    assertCompiled(JavaBuilder.BUILDER_NAME);
    checkMakeUpToDate(executor);
    FileUtil.writeToFile(new File(getProjectPath("assets/new_asset.png")), "new_asset_content");
    executor.clear();
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_9");
    assertCompiled(JavaBuilder.BUILDER_NAME);
    checkMakeUpToDate(executor);
    assertOutput(module, TestFileSystemItem.fs().dir("com").dir("example").dir("simple1").file("BuildConfig.class").file("R.class").end().dir("simple").file("MyActivity.class").end().end().end().archive("module.apk").file("META-INF").file("res_apk_entry", "res_apk_entry_content").file("classes.dex", "classes_dex_content").dir("lib").dir("armeabi").file("mylib.so", "mylib_content_changed"));
    assertTrue(FileUtil.delete(new File(getProjectPath("libs/armeabi/mylib.so"))));
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_12");
    checkMakeUpToDate(executor);
    assertTrue(FileUtil.delete(new File(getProjectPath("libs"))));
    rebuildAll();
    checkBuildLog(executor, "expected_log_13");
    checkMakeUpToDate(executor);
}
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