Search in sources :

Example 1 with SupportLibrary

use of com.android.tools.idea.templates.SupportLibrary in project android by JetBrains.

the class MavenDependencyLookupDialog method isKnownLocalLibrary.

private static boolean isKnownLocalLibrary(@NotNull String text) {
    String group = getGroup(text);
    String artifact = getArtifact(text);
    if (group == null || artifact == null) {
        return false;
    }
    SupportLibrary library = SupportLibrary.find(group, artifact);
    return library != null;
}
Also used : SupportLibrary(com.android.tools.idea.templates.SupportLibrary)

Example 2 with SupportLibrary

use of com.android.tools.idea.templates.SupportLibrary in project android by JetBrains.

the class ModuleDependenciesPanel method installRepositoryIfNeeded.

private String installRepositoryIfNeeded(String coordinateText) {
    GradleCoordinate gradleCoordinate = GradleCoordinate.parseCoordinateString(coordinateText);
    // Only allowed to click ok when the string is valid.
    assert gradleCoordinate != null;
    SupportLibrary supportLibrary = SupportLibrary.forGradleCoordinate(gradleCoordinate);
    if (!REVISION_ANY.equals(gradleCoordinate.getRevision()) || supportLibrary == null) {
        // No installation needed, or it's not a local repository.
        return coordinateText;
    }
    String message = "Library " + gradleCoordinate.getArtifactId() + " is not installed. Install repository?";
    if (Messages.showYesNoDialog(myProject, message, "Install Repository", Messages.getQuestionIcon()) != Messages.YES) {
        // User cancelled installation.
        return null;
    }
    List<String> requested = Lists.newArrayList();
    SdkMavenRepository repository;
    if (coordinateText.startsWith("com.android.support")) {
        repository = SdkMavenRepository.ANDROID;
    } else if (coordinateText.startsWith("com.google.android")) {
        repository = SdkMavenRepository.GOOGLE;
    } else {
        // EXTRAS_REPOSITORY.containsKey() should have returned false.
        assert false;
        return coordinateText + ':' + REVISION_ANY;
    }
    requested.add(repository.getPackageId());
    ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(myProject, requested);
    if (dialog != null) {
        dialog.setTitle("Install Missing Components");
        if (dialog.showAndGet()) {
            return RepositoryUrlManager.get().getLibraryStringCoordinate(supportLibrary, true);
        }
    }
    // Installation wizard didn't complete - skip adding the dependency.
    return null;
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) SdkMavenRepository(com.android.ide.common.repository.SdkMavenRepository) SupportLibrary(com.android.tools.idea.templates.SupportLibrary) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 3 with SupportLibrary

use of com.android.tools.idea.templates.SupportLibrary in project android by JetBrains.

the class AndroidAddLibraryDependencyAction method findAllDependencies.

/**
   * Finds all the "extras repository" dependencies that haven't been already added to the project.
   */
@NotNull
private static ImmutableCollection<String> findAllDependencies(@NotNull GradleBuildModel buildModel) {
    HashSet<String> existingDependencies = Sets.newHashSet();
    for (ArtifactDependencyModel dependency : buildModel.dependencies().artifacts()) {
        existingDependencies.add(dependency.group().value() + ":" + dependency.name().value());
    }
    ImmutableList.Builder<String> dependenciesBuilder = ImmutableList.builder();
    RepositoryUrlManager repositoryUrlManager = RepositoryUrlManager.get();
    for (SupportLibrary library : SupportLibrary.values()) {
        // Coordinate for any version available
        GradleCoordinate libraryCoordinate = library.getGradleCoordinate("+");
        // Get from the library coordinate only the group and artifactId to check if we have already added it
        if (!existingDependencies.contains(libraryCoordinate.getId())) {
            GradleCoordinate coordinate = repositoryUrlManager.resolveDynamicCoordinate(libraryCoordinate, buildModel.getProject());
            if (coordinate != null) {
                dependenciesBuilder.add(coordinate.toString());
            }
        }
    }
    return dependenciesBuilder.build();
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) ImmutableList(com.google.common.collect.ImmutableList) RepositoryUrlManager(com.android.tools.idea.templates.RepositoryUrlManager) SupportLibrary(com.android.tools.idea.templates.SupportLibrary) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SupportLibrary (com.android.tools.idea.templates.SupportLibrary)3 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)2 SdkMavenRepository (com.android.ide.common.repository.SdkMavenRepository)1 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)1 RepositoryUrlManager (com.android.tools.idea.templates.RepositoryUrlManager)1 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)1 ImmutableList (com.google.common.collect.ImmutableList)1 NotNull (org.jetbrains.annotations.NotNull)1