GradleResolver implements MavenResolver { File downloadFromRemoteRepository(ArtifactCoordinates artifactCoordinates, String packaging, Path artifactDirectory) { String artifactRelativeHttpPath = toGradleArtifactPath(artifactCoordinates); String artifactRelativeMetadataHttpPath = artifactCoordinates.relativeMetadataPath('/'); for (String remoteRepos : remoteRepositories) { String artifactAbsoluteHttpPath = remoteRepos + artifactRelativeHttpPath + "."; File targetArtifactPomDirectory = artifactDirectory.resolve(computeGradleUUID(artifactCoordinates + ":pom")).toFile(); File targetArtifactDirectory = artifactDirectory.resolve(computeGradleUUID(artifactCoordinates + ":" + packaging)).toFile(); File artifactFile = doDownload(remoteRepos, artifactAbsoluteHttpPath, artifactRelativeHttpPath, artifactCoordinates, packaging, targetArtifactPomDirectory, targetArtifactDirectory); if (artifactFile != null) { return artifactFile; } if (artifactCoordinates.isSnapshot()) { String remoteMetadataPath = remoteRepos + artifactRelativeMetadataHttpPath; try { String timestamp = MavenArtifactUtil.downloadTimestampVersion(artifactCoordinates + ":" + packaging, remoteMetadataPath); String timestampedArtifactRelativePath = artifactCoordinates.relativeArtifactPath('/', timestamp); String artifactTimestampedAbsoluteHttpPath = remoteRepos + timestampedArtifactRelativePath + "."; File targetTimestampedArtifactPomDirectory = artifactDirectory.resolve(computeGradleUUID(artifactCoordinates + ":" + timestamp + ":pom")).toFile(); File targetTimestampedArtifactDirectory = artifactDirectory.resolve(computeGradleUUID(artifactCoordinates + ":" + packaging)).toFile(); File snapshotArtifactFile = doDownload(remoteRepos, artifactTimestampedAbsoluteHttpPath, timestampedArtifactRelativePath, artifactCoordinates, packaging, targetTimestampedArtifactPomDirectory, targetTimestampedArtifactDirectory); if (snapshotArtifactFile != null) { return snapshotArtifactFile; } } catch (XPathExpressionException | IOException ex) { Module.getModuleLogger().trace(ex, "Could not doDownload '%s' from '%s' repository", artifactRelativeHttpPath, remoteRepos); } } } return null; } GradleResolver(String gradleCachePath); @Override File resolveArtifact(ArtifactCoordinates artifactCoordinates, String packaging);  }
@Test public void downloadFromRemoteRepository() throws IOException { File dirFile = TempFileManager.INSTANCE.newTempDirectory(".gradle", null); Path gradleCachePath = dirFile.toPath(); String group = "org.wildfly.swarm"; String packaging = "jar"; String artifact = "bootstrap"; String version = "2017.1.1"; ArtifactCoordinates artifactCoordinates = new ArtifactCoordinates(group, artifact, version); Path artifactDirectory = gradleCachePath.resolve(group); GradleResolver resolver = spy(new GradleResolver(gradleCachePath.toString())); File targetFile = mock(File.class); doReturn(targetFile).when(resolver).doDownload(anyString(), anyString(), anyString(), eq(artifactCoordinates), eq(packaging), any(File.class), any(File.class)); File result = resolver.downloadFromRemoteRepository(artifactCoordinates, packaging, artifactDirectory); assertEquals(targetFile, result); }