Search in sources :

Example 1 with ProjectLibraries

use of com.android.tools.idea.gradle.ProjectLibraries in project android by JetBrains.

the class GradleSyncIntegrationTest method testWithUserDefinedLibrarySources.

// Disabled until the prebuilt Maven repo has all dependencies.
public void testWithUserDefinedLibrarySources() throws Exception {
    if (SystemInfo.isWindows) {
        // Do not run tests on Windows (see http://b.android.com/222904)
        return;
    }
    loadSimpleApplication();
    ProjectLibraries libraries = new ProjectLibraries(getProject());
    String libraryNameRegex = "guava-.*";
    Library library = libraries.findMatchingLibrary(libraryNameRegex);
    assertNotNull(library);
    String url = "jar://$USER_HOME$/fake-dir/fake-sources.jar!/";
    // add an extra source path.
    Library.ModifiableModel libraryModel = library.getModifiableModel();
    libraryModel.addRoot(url, SOURCES);
    ApplicationManager.getApplication().runWriteAction(libraryModel::commit);
    requestSyncAndWait();
    library = libraries.findMatchingLibrary(libraryNameRegex);
    assertNotNull(library);
    String[] urls = library.getUrls(SOURCES);
    assertThat(urls).asList().contains(url);
}
Also used : ProjectLibraries(com.android.tools.idea.gradle.ProjectLibraries) Library(com.intellij.openapi.roots.libraries.Library)

Example 2 with ProjectLibraries

use of com.android.tools.idea.gradle.ProjectLibraries in project android by JetBrains.

the class GradleSyncIntegrationTest method testJarsFolderInExplodedAarIsExcluded.

// https://code.google.com/p/android/issues/detail?id=227931
public void testJarsFolderInExplodedAarIsExcluded() throws Exception {
    loadSimpleApplication();
    Module appModule = myModules.getAppModule();
    AndroidModuleModel androidModel = AndroidModuleModel.get(appModule);
    assertNotNull(androidModel);
    Collection<SyncIssue> issues = androidModel.getSyncIssues();
    assertThat(issues).isEmpty();
    AndroidPluginInfo pluginInfo = AndroidPluginInfo.find(getProject());
    assertNotNull(pluginInfo);
    assertEquals(pluginInfo.getPluginGeneration(), ORIGINAL);
    GradleVersion pluginVersion = pluginInfo.getPluginVersion();
    assertNotNull(pluginVersion);
    if (pluginVersion.compareIgnoringQualifiers("2.3.0") >= 0) {
        // it is not inside the project.
        return;
    }
    ProjectLibraries libraries = new ProjectLibraries(getProject());
    Library appCompat = libraries.findMatchingLibrary("appcompat-v7.*");
    assertNotNull(appCompat);
    File jarsFolderPath = null;
    for (String url : appCompat.getUrls(CLASSES)) {
        if (url.startsWith(JAR_PROTOCOL_PREFIX)) {
            File jarPath = getJarFromJarUrl(url);
            assertNotNull(jarPath);
            jarsFolderPath = jarPath.getParentFile();
            break;
        }
    }
    assertNotNull(jarsFolderPath);
    ContentEntry[] contentEntries = ModuleRootManager.getInstance(appModule).getContentEntries();
    assertThat(contentEntries).hasLength(1);
    ContentEntry contentEntry = contentEntries[0];
    List<String> excludeFolderUrls = contentEntry.getExcludeFolderUrls();
    assertThat(excludeFolderUrls).contains(pathToIdeaUrl(jarsFolderPath));
}
Also used : SyncIssue(com.android.builder.model.SyncIssue) ProjectLibraries(com.android.tools.idea.gradle.ProjectLibraries) AndroidPluginInfo(com.android.tools.idea.gradle.plugin.AndroidPluginInfo) ContentEntry(com.intellij.openapi.roots.ContentEntry) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) GradleVersion(com.android.ide.common.repository.GradleVersion) FileUtil.writeToFile(com.intellij.openapi.util.io.FileUtil.writeToFile) File(java.io.File)

Aggregations

ProjectLibraries (com.android.tools.idea.gradle.ProjectLibraries)2 Library (com.intellij.openapi.roots.libraries.Library)2 SyncIssue (com.android.builder.model.SyncIssue)1 GradleVersion (com.android.ide.common.repository.GradleVersion)1 AndroidPluginInfo (com.android.tools.idea.gradle.plugin.AndroidPluginInfo)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 Module (com.intellij.openapi.module.Module)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1 FileUtil.writeToFile (com.intellij.openapi.util.io.FileUtil.writeToFile)1 File (java.io.File)1