Search in sources :

Example 1 with TestFileSystemBuilder

use of com.intellij.util.io.TestFileSystemBuilder in project android by JetBrains.

the class AndroidBuilderTest method test7.

public void test7() throws Exception {
    final boolean[] class1Deleted = { false };
    final MyExecutor executor = new MyExecutor("com.example.simple") {

        @Override
        protected void doCheckJar(@NotNull String jarId, @NotNull String jarPath) {
            if ("library_package_jar".equals(jarId)) {
                File tmpDir = null;
                try {
                    tmpDir = FileUtil.createTempDirectory("library_package_jar_checking", "tmp");
                    final File jar = new File(tmpDir, "file.jar");
                    FileUtil.copy(new File(jarPath), jar);
                    TestFileSystemBuilder fs = TestFileSystemItem.fs().archive("file.jar").dir("lib").file("MyLibClass.class");
                    if (!class1Deleted[0]) {
                        fs = fs.file("MyLibClass1.class");
                    }
                    assertOutput(tmpDir.getPath(), fs);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } finally {
                    if (tmpDir != null) {
                        FileUtil.delete(tmpDir);
                    }
                }
            }
        }
    };
    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("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;
    rebuildAll();
    checkBuildLog(executor, "expected_log");
    assertEquals(Collections.singleton("library_package_jar"), executor.getCheckedJars());
    checkMakeUpToDate(executor);
    appModule.getDependenciesList().addModuleDependency(libModule);
    makeAll();
    checkBuildLog(executor, "expected_log_1");
    assertTrue(executor.getCheckedJars().isEmpty());
    checkMakeUpToDate(executor);
    change(getProjectPath("lib/src/lib/MyLibClass.java"));
    makeAll();
    checkBuildLog(executor, "expected_log_2");
    assertEquals(Collections.singleton("library_package_jar"), executor.getCheckedJars());
    checkMakeUpToDate(executor);
    assertTrue(FileUtil.delete(new File(getProjectPath("lib/src/lib/MyLibClass1.java"))));
    class1Deleted[0] = true;
    makeAll();
    checkBuildLog(executor, "expected_log_2");
    assertEquals(Collections.singleton("library_package_jar"), executor.getCheckedJars());
    checkMakeUpToDate(executor);
    assertTrue(FileUtil.delete(new File(getProjectPath("lib/src/lib/MyLibClass.java"))));
    makeAll();
    checkBuildLog(executor, "expected_log_3");
    assertTrue(executor.getCheckedJars().isEmpty());
    checkMakeUpToDate(executor);
    final JpsLibrary appLib = appModule.addModuleLibrary("appLib", JpsJavaLibraryType.INSTANCE);
    appLib.addRoot(getProjectPath("lib/external_jar.jar"), JpsOrderRootType.COMPILED);
    appModule.getDependenciesList().addLibraryDependency(appLib);
    final JpsLibrary libLib = libModule.addModuleLibrary("libLib", JpsJavaLibraryType.INSTANCE);
    libLib.addRoot(new File(getProjectPath("lib/external_jar.jar")), JpsOrderRootType.COMPILED);
    libModule.getDependenciesList().addLibraryDependency(libLib);
    makeAll().assertSuccessful();
    checkBuildLog(executor, "expected_log_4");
    assertTrue(executor.getCheckedJars().isEmpty());
    checkMakeUpToDate(executor);
}
Also used : TestFileSystemBuilder(com.intellij.util.io.TestFileSystemBuilder) JpsSimpleElement(org.jetbrains.jps.model.JpsSimpleElement) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) NotNull(org.jetbrains.annotations.NotNull) JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsAndroidModuleExtensionImpl(org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Aggregations

TestFileSystemBuilder (com.intellij.util.io.TestFileSystemBuilder)1 NotNull (org.jetbrains.annotations.NotNull)1 JpsAndroidModuleExtensionImpl (org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl)1 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)1 JpsSimpleElement (org.jetbrains.jps.model.JpsSimpleElement)1 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)1 JpsModule (org.jetbrains.jps.model.module.JpsModule)1