Search in sources :

Example 1 with ArtifactType

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

Aggregations

ArtifactType (com.android.ide.common.repository.GradleCoordinate.ArtifactType)1 SdkMavenRepository (com.android.ide.common.repository.SdkMavenRepository)1 File (java.io.File)1 Nullable (org.jetbrains.annotations.Nullable)1