use of org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl in project android by JetBrains.
the class AndroidBuilderTest method testResOverlay.
public void testResOverlay() throws Exception {
final MyExecutor executor = new MyExecutor("com.example.simple");
final JpsModule module = setUpSimpleAndroidStructure(ArrayUtil.EMPTY_STRING_ARRAY, executor, null).getFirst();
final JpsAndroidModuleProperties props = ((JpsAndroidModuleExtensionImpl) AndroidJpsUtil.getExtension(module)).getProperties();
props.RES_OVERLAY_FOLDERS = Arrays.asList("/res-overlay");
rebuildAll();
checkBuildLog(executor, "expected_log");
checkMakeUpToDate(executor);
props.RES_OVERLAY_FOLDERS = Collections.emptyList();
makeAll().assertSuccessful();
checkBuildLog(executor, "expected_log_1");
}
use of org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl 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);
}
use of org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl 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");
}
use of org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl 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");
}
use of org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl 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));
}
Aggregations