Search in sources :

Example 1 with LibraryDependency

use of com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency in project android by JetBrains.

the class DependenciesModuleSetupStep method updateModuleDependency.

private void updateModuleDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull ModuleDependency dependency, @NotNull AndroidProject androidProject) {
    Module moduleDependency = dependency.getModule(modelsProvider);
    LibraryDependency compiledArtifact = dependency.getBackupDependency();
    if (moduleDependency != null) {
        ModuleOrderEntry orderEntry = modelsProvider.getModifiableRootModel(module).addModuleOrderEntry(moduleDependency);
        orderEntry.setScope(dependency.getScope());
        orderEntry.setExported(true);
        if (compiledArtifact != null) {
            setModuleCompiledArtifact(moduleDependency, compiledArtifact);
        }
        return;
    }
    DependencySetupErrors dependencySetupErrors = DependencySetupErrors.getInstance(module.getProject());
    String backupName = compiledArtifact != null ? compiledArtifact.getName() : null;
    dependencySetupErrors.addMissingModule(dependency.getGradlePath(), module.getName(), backupName);
    // fall back to library dependency, if available.
    if (compiledArtifact != null) {
        updateLibraryDependency(module, modelsProvider, compiledArtifact, androidProject);
    }
}
Also used : DependencySetupErrors(com.android.tools.idea.gradle.project.sync.setup.module.common.DependencySetupErrors) LibraryDependency(com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) Module(com.intellij.openapi.module.Module)

Example 2 with LibraryDependency

use of com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency in project android by JetBrains.

the class DependenciesModuleSetupStepTest method createFakeLibraryDependency.

@NotNull
private static LibraryDependency createFakeLibraryDependency(@NotNull File jarsFolderPath) {
    LibraryDependency dependency = new LibraryDependency(new File(jarsFolderPath, "myLibrary.jar"), COMPILE);
    dependency.addPath(DOCUMENTATION, new File(jarsFolderPath, "myLibrary-javadoc.jar"));
    return dependency;
}
Also used : LibraryDependency(com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LibraryDependency

use of com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency in project android by JetBrains.

the class DependenciesModuleSetupStep method doSetUpModule.

@Override
protected void doSetUpModule(@NotNull Module module, @NotNull IdeModifiableModelsProvider ideModelsProvider, @NotNull AndroidModuleModel androidModel, @Nullable SyncAction.ModuleModels gradleModels, @Nullable ProgressIndicator indicator) {
    AndroidProject androidProject = androidModel.getAndroidProject();
    DependencySet dependencies = myDependenciesExtractor.extractFrom(androidModel);
    for (LibraryDependency dependency : dependencies.onLibraries()) {
        updateLibraryDependency(module, ideModelsProvider, dependency, androidProject);
    }
    for (ModuleDependency dependency : dependencies.onModules()) {
        updateModuleDependency(module, ideModelsProvider, dependency, androidProject);
    }
    addExtraSdkLibrariesAsDependencies(module, ideModelsProvider, androidProject);
    Collection<SyncIssue> syncIssues = androidModel.getSyncIssues();
    if (syncIssues != null) {
        SyncIssuesReporter.getInstance().report(syncIssues, module);
    } else {
        //noinspection deprecation
        Collection<String> unresolvedDependencies = androidProject.getUnresolvedDependencies();
        UnresolvedDependenciesReporter.getInstance().report(unresolvedDependencies, module);
    }
}
Also used : ModuleDependency(com.android.tools.idea.gradle.project.sync.setup.module.dependency.ModuleDependency) LibraryDependency(com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency) SyncIssue(com.android.builder.model.SyncIssue) DependencySet(com.android.tools.idea.gradle.project.sync.setup.module.dependency.DependencySet) AndroidProject(com.android.builder.model.AndroidProject)

Example 4 with LibraryDependency

use of com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency in project android by JetBrains.

the class DependenciesModuleSetupStepTest method testUpdateLibraryDependencyWithLibraryInModule.

public void testUpdateLibraryDependencyWithLibraryInModule() throws IOException {
    Module module = getModule();
    createContentRoot(module);
    VirtualFile moduleFolder = getModuleFolder(module);
    // Create "build" folder inside the module.
    String name = "build";
    VirtualFile buildFolder = createFolder(moduleFolder, name);
    AndroidProject androidProject = mock(AndroidProject.class);
    when(androidProject.getBuildFolder()).thenReturn(virtualToIoFile(buildFolder));
    // Create "jars" folder inside the module's "build" folder.
    VirtualFile jarsFolder = createFolder(buildFolder, "jars");
    File jarsFolderPath = virtualToIoFile(jarsFolder);
    // We simulate the dependency to set up being inside the "jars" folder. We expect the "jars" folder to be excluded to avoid unnecessary
    // indexing of the jar files.
    LibraryDependency dependency = createFakeLibraryDependency(jarsFolderPath);
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(getProject());
    mySetupStep.updateLibraryDependency(module, modelsProvider, dependency, androidProject);
    ApplicationManager.getApplication().runWriteAction(modelsProvider::commit);
    // Make sure DependenciesSetup#setUpLibraryDependency was invoked.
    verify(myDependenciesSetup).setUpLibraryDependency(module, modelsProvider, "myLibrary", COMPILE, dependency.getArtifactPath(), dependency.getPaths(BINARY), dependency.getPaths(DOCUMENTATION));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) LibraryDependency(com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency) AndroidProject(com.android.builder.model.AndroidProject) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)

Aggregations

LibraryDependency (com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency)4 AndroidProject (com.android.builder.model.AndroidProject)2 Module (com.intellij.openapi.module.Module)2 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 SyncIssue (com.android.builder.model.SyncIssue)1 DependencySetupErrors (com.android.tools.idea.gradle.project.sync.setup.module.common.DependencySetupErrors)1 DependencySet (com.android.tools.idea.gradle.project.sync.setup.module.dependency.DependencySet)1 ModuleDependency (com.android.tools.idea.gradle.project.sync.setup.module.dependency.ModuleDependency)1 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)1 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)1 ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)1 NotNull (org.jetbrains.annotations.NotNull)1