use of org.jetbrains.jps.model.library.JpsLibrary in project android by JetBrains.
the class AndroidJpsUtil method processClasspath.
private static void processClasspath(@NotNull BuildDataPaths paths, @NotNull final JpsModule module, @NotNull final AndroidDependencyProcessor processor, @NotNull final Set<String> visitedModules, final boolean exportedLibrariesOnly, final boolean recursive, final boolean resolveJars, final boolean withAarDeps) {
if (!visitedModules.add(module.getName())) {
return;
}
if (processor.isToProcess(AndroidDependencyType.EXTERNAL_LIBRARY)) {
for (JpsDependencyElement item : JpsJavaExtensionService.getInstance().getDependencies(module, JpsJavaClasspathKind.PRODUCTION_RUNTIME, exportedLibrariesOnly)) {
if (item instanceof JpsLibraryDependency) {
final JpsLibrary library = ((JpsLibraryDependency) item).getLibrary();
if (library != null && (withAarDeps || getResDirAndJarsIfAar(library) == null)) {
for (JpsLibraryRoot root : library.getRoots(JpsOrderRootType.COMPILED)) {
final File file = JpsPathUtil.urlToFile(root.getUrl());
if (resolveJars) {
processClassFilesAndJarsRecursively(file, new Processor<File>() {
@Override
public boolean process(File file) {
processor.processExternalLibrary(file);
return true;
}
});
} else {
processor.processExternalLibrary(file);
}
}
}
}
}
}
if (processor.isToProcess(AndroidDependencyType.PROVIDED_LIBRARY)) {
for (JpsDependencyElement item : module.getDependenciesList().getDependencies()) {
if (item instanceof JpsLibraryDependency) {
final JpsLibrary library = ((JpsLibraryDependency) item).getLibrary();
final JpsJavaDependencyExtension extension = JpsJavaExtensionService.getInstance().getDependencyExtension(item);
if (library != null && extension != null && extension.getScope() == JpsJavaDependencyScope.PROVIDED) {
for (JpsLibraryRoot root : library.getRoots(JpsOrderRootType.COMPILED)) {
processor.processProvidedLibrary(JpsPathUtil.urlToFile(root.getUrl()));
}
}
}
}
}
for (JpsDependencyElement item : JpsJavaExtensionService.getInstance().getDependencies(module, JpsJavaClasspathKind.PRODUCTION_RUNTIME, false)) {
if (item instanceof JpsModuleDependency) {
final JpsModule depModule = ((JpsModuleDependency) item).getModule();
if (depModule == null)
continue;
final JpsAndroidModuleExtension depExtension = getExtension(depModule);
final boolean depLibrary = depExtension != null && depExtension.isLibrary();
final File depClassDir = new ModuleBuildTarget(depModule, JavaModuleBuildTargetType.PRODUCTION).getOutputDir();
if (depLibrary) {
if (processor.isToProcess(AndroidDependencyType.ANDROID_LIBRARY_PACKAGE)) {
final File intArtifactsDir = getDirectoryForIntermediateArtifacts(paths, depModule);
final File packagedClassesJar = new File(intArtifactsDir, AndroidCommonUtils.CLASSES_JAR_FILE_NAME);
processor.processAndroidLibraryPackage(packagedClassesJar, depModule);
}
if (processor.isToProcess(AndroidDependencyType.ANDROID_LIBRARY_OUTPUT_DIRECTORY)) {
if (depClassDir != null) {
processor.processAndroidLibraryOutputDirectory(depClassDir);
}
}
} else if (processor.isToProcess(AndroidDependencyType.JAVA_MODULE_OUTPUT_DIR) && depExtension == null && depClassDir != null) {
// do not support android-app->android-app compile dependencies
processor.processJavaModuleOutputDirectory(depClassDir);
}
if (recursive) {
final boolean newRecursive = shouldProcessDependenciesRecursively(depModule);
processClasspath(paths, depModule, processor, visitedModules, !depLibrary || exportedLibrariesOnly, newRecursive, resolveJars, withAarDeps);
}
}
}
}
use of org.jetbrains.jps.model.library.JpsLibrary 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.model.library.JpsLibrary 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);
}
use of org.jetbrains.jps.model.library.JpsLibrary in project android by JetBrains.
the class AndroidBuilderTest method testPreDexing.
public void testPreDexing() throws Exception {
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();
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);
final JpsLibrary lib = appModule.addModuleLibrary("ext_lib", JpsJavaLibraryType.INSTANCE);
lib.addRoot(new File(getProjectPath("app/libs/external_jar.jar")), JpsOrderRootType.COMPILED);
appModule.getDependenciesList().addLibraryDependency(lib);
final JpsLibrary lib1 = appModule.addModuleLibrary("ext_lib_1", JpsJavaLibraryType.INSTANCE);
lib1.addRoot(new File(getProjectPath("lib/libs/external_jar_1.jar")), JpsOrderRootType.COMPILED);
libModule.getDependenciesList().addLibraryDependency(lib1);
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");
executor.clear();
makeAll().assertSuccessful();
checkBuildLog(executor, "expected_log_1");
executor.clear();
doBuild(CompileScopeTestBuilder.make().allModules().targetTypes(AndroidManifestMergingTarget.MyTargetType.INSTANCE, AndroidDexBuildTarget.MyTargetType.INSTANCE, AndroidResourceCachingBuildTarget.MyTargetType.INSTANCE, AndroidResourcePackagingBuildTarget.MyTargetType.INSTANCE, AndroidPackagingBuildTarget.MyTargetType.INSTANCE, AndroidLibraryPackagingTarget.MyTargetType.INSTANCE, AndroidPackagingBuildTarget.MyTargetType.INSTANCE)).assertUpToDate();
executor.clear();
rebuildAll();
checkBuildLog(executor, "expected_log_2");
final JpsAndroidModuleExtension appExtension = AndroidJpsUtil.getExtension(appModule);
assert appExtension != null;
final JpsAndroidModuleProperties appProps = ((JpsAndroidModuleExtensionImpl) appExtension).getProperties();
checkMakeUpToDate(executor);
appProps.ENABLE_PRE_DEXING = false;
makeAll().assertSuccessful();
checkBuildLog(executor, "expected_log_3");
checkMakeUpToDate(executor);
appProps.ENABLE_PRE_DEXING = true;
makeAll().assertSuccessful();
checkBuildLog(executor, "expected_log_4");
}
use of org.jetbrains.jps.model.library.JpsLibrary in project intellij-community by JetBrains.
the class JpsSdkTableSerializer method loadSdk.
private static JpsLibrary loadSdk(Element sdkElement) {
String name = getAttributeValue(sdkElement, NAME_TAG);
String typeId = getAttributeValue(sdkElement, TYPE_TAG);
LOG.debug("Loading " + typeId + " SDK '" + name + "'");
JpsSdkPropertiesSerializer<?> serializer = getSdkPropertiesSerializer(typeId);
final JpsLibrary library = createSdk(name, serializer, sdkElement);
final Element roots = sdkElement.getChild(ROOTS_TAG);
for (Element rootTypeElement : JDOMUtil.getChildren(roots)) {
JpsLibraryRootTypeSerializer rootTypeSerializer = getRootTypeSerializer(rootTypeElement.getName());
if (rootTypeSerializer != null) {
for (Element rootElement : rootTypeElement.getChildren()) {
loadRoots(rootElement, library, rootTypeSerializer.getType());
}
} else {
LOG.info("root type serializer not found for " + rootTypeElement.getName());
}
}
if (LOG.isDebugEnabled()) {
List<File> files = library.getFiles(JpsOrderRootType.COMPILED);
LOG.debug(name + " SDK classpath (" + files.size() + " roots):");
for (File file : files) {
LOG.debug(" " + file.getAbsolutePath());
}
}
return library;
}
Aggregations