Search in sources :

Example 1 with SdkMavenRepository

use of com.android.ide.common.repository.SdkMavenRepository in project android by JetBrains.

the class RepositoryUrlManager method getArchiveForCoordinate.

/**
   * Gets the file on the local filesystem that corresponds to the given maven coordinate.
   *
   * @param gradleCoordinate the coordinate to retrieve an archive file for
   * @param sdkLocation      SDK to use
   * @param fileOp           {@link FileOp} used for file operations
   * @return a file pointing at the archive for the given coordinate or null if no SDK is configured
   */
@Nullable
public File getArchiveForCoordinate(@NotNull GradleCoordinate gradleCoordinate, @NotNull File sdkLocation, @NotNull FileOp fileOp) {
    if (gradleCoordinate.getGroupId() == null || gradleCoordinate.getArtifactId() == null) {
        return null;
    }
    SdkMavenRepository repository = SdkMavenRepository.find(sdkLocation, gradleCoordinate.getGroupId(), gradleCoordinate.getArtifactId(), fileOp);
    if (repository == null) {
        return null;
    }
    File repositoryLocation = repository.getRepositoryLocation(sdkLocation, true, fileOp);
    if (repositoryLocation == null) {
        return null;
    }
    File artifactDirectory = MavenRepositories.getArtifactDirectory(repositoryLocation, gradleCoordinate);
    if (!fileOp.isDirectory(artifactDirectory)) {
        return null;
    }
    for (ArtifactType artifactType : ImmutableList.of(ArtifactType.JAR, ArtifactType.AAR)) {
        File archive = new File(artifactDirectory, String.format("%s-%s.%s", gradleCoordinate.getArtifactId(), gradleCoordinate.getRevision(), artifactType.toString()));
        if (fileOp.isFile(archive)) {
            return archive;
        }
    }
    return null;
}
Also used : SdkMavenRepository(com.android.ide.common.repository.SdkMavenRepository) ArtifactType(com.android.ide.common.repository.GradleCoordinate.ArtifactType) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with SdkMavenRepository

use of com.android.ide.common.repository.SdkMavenRepository 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 SdkMavenRepository

use of com.android.ide.common.repository.SdkMavenRepository in project android by JetBrains.

the class RepositoryUrlManager method getLibraryRevision.

/**
   * Returns the string for the specific version number of the most recent version of the given library
   * (matching the given prefix filter, if any) in one of the Sdk repositories.
   *
   * @param groupId         the group id
   * @param artifactId      the artifact id
   * @param filterPrefix    a prefix, if any
   * @param includePreviews whether to include preview versions of libraries
   * @return
   */
@Nullable
public String getLibraryRevision(@NotNull String groupId, @NotNull String artifactId, @Nullable String filterPrefix, boolean includePreviews, @NotNull File sdkLocation, @NotNull FileOp fileOp) {
    // Try the new, combined repository first:
    File combinedRepo = FileUtils.join(sdkLocation, FD_EXTRAS, FD_M2_REPOSITORY);
    if (fileOp.isDirectory(combinedRepo)) {
        GradleCoordinate versionInCombined = MavenRepositories.getHighestInstalledVersion(groupId, artifactId, combinedRepo, filterPrefix, includePreviews, fileOp);
        if (versionInCombined != null) {
            return versionInCombined.getRevision();
        }
    }
    // Now try the "old" repositories, "google" and "android":
    SdkMavenRepository repository = SdkMavenRepository.find(sdkLocation, groupId, artifactId, fileOp);
    if (repository == null) {
        // Try the repo embedded in AS. We distribute for example the constraint layout there for now.
        List<File> paths = EmbeddedDistributionPaths.getInstance().findAndroidStudioLocalMavenRepoPaths();
        for (File path : paths) {
            if (path != null && path.isDirectory()) {
                GradleCoordinate versionInEmbedded = MavenRepositories.getHighestInstalledVersion(groupId, artifactId, path, filterPrefix, includePreviews, fileOp);
                if (versionInEmbedded != null) {
                    return versionInEmbedded.getRevision();
                }
            }
        }
        return null;
    }
    File repositoryLocation = repository.getRepositoryLocation(sdkLocation, true, fileOp);
    if (repositoryLocation == null) {
        return null;
    }
    // Try using the POM file:
    File mavenMetadataFile = MavenRepositories.getMavenMetadataFile(repositoryLocation, groupId, artifactId);
    if (fileOp.isFile(mavenMetadataFile)) {
        try {
            return getLatestVersionFromMavenMetadata(mavenMetadataFile, filterPrefix, includePreviews, fileOp);
        } catch (IOException e) {
            return null;
        }
    }
    // Just scan all the directories:
    GradleCoordinate max = repository.getHighestInstalledVersion(sdkLocation, groupId, artifactId, filterPrefix, includePreviews, fileOp);
    if (max == null) {
        return null;
    }
    return max.getRevision();
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) SdkMavenRepository(com.android.ide.common.repository.SdkMavenRepository) IOException(java.io.IOException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with SdkMavenRepository

use of com.android.ide.common.repository.SdkMavenRepository in project android by JetBrains.

the class AndroidSdk method getRequiredSdkPackages.

@NotNull
@Override
protected Collection<String> getRequiredSdkPackages() {
    Collection<String> result = Lists.newArrayList();
    result.add(SdkConstants.FD_TOOLS);
    result.add(SdkConstants.FD_PLATFORM_TOOLS);
    String buildToolsPath = getLatestCompatibleBuildToolsPath();
    if (buildToolsPath != null) {
        result.add(buildToolsPath);
    }
    for (SdkMavenRepository repository : SdkMavenRepository.values()) {
        result.add(repository.getRepositoryLocation(new File(""), false).getPath().substring(1).replace(File.separatorChar, RepoPackage.PATH_SEPARATOR));
    }
    return result;
}
Also used : SdkMavenRepository(com.android.ide.common.repository.SdkMavenRepository) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SdkMavenRepository (com.android.ide.common.repository.SdkMavenRepository)4 File (java.io.File)3 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)2 Nullable (org.jetbrains.annotations.Nullable)2 ArtifactType (com.android.ide.common.repository.GradleCoordinate.ArtifactType)1 SupportLibrary (com.android.tools.idea.templates.SupportLibrary)1 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1