Search in sources :

Example 21 with JpsLibrary

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);
            }
        }
    }
}
Also used : JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot)

Example 22 with JpsLibrary

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");
}
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 23 with JpsLibrary

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);
}
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 24 with JpsLibrary

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");
}
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 25 with JpsLibrary

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;
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) Element(org.jdom.Element) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) File(java.io.File)

Aggregations

JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)41 JpsModule (org.jetbrains.jps.model.module.JpsModule)11 File (java.io.File)10 Element (org.jdom.Element)8 NotNull (org.jetbrains.annotations.NotNull)7 JpsSimpleElement (org.jetbrains.jps.model.JpsSimpleElement)7 JpsLibraryRoot (org.jetbrains.jps.model.library.JpsLibraryRoot)6 JpsAndroidModuleExtensionImpl (org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl)5 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)5 JpsElement (org.jetbrains.jps.model.JpsElement)5 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 JpsDependencyElement (org.jetbrains.jps.model.module.JpsDependencyElement)3 JpsLibraryDependency (org.jetbrains.jps.model.module.JpsLibraryDependency)3 Logger (com.intellij.openapi.diagnostic.Logger)2 SystemInfo (com.intellij.openapi.util.SystemInfo)2 JpsElementFactory (org.jetbrains.jps.model.JpsElementFactory)2 JpsSdkReference (org.jetbrains.jps.model.library.sdk.JpsSdkReference)2