AetherClient { public Artifact findLatestAvailableArtifact(String groupIdArtifactId) throws ArtifactResolutionException { final RepositorySystem system = _newRepositorySystem(); final List<RemoteRepository> repos = _repos(); final String range = "[0,)"; final Artifact artifactRange = new DefaultArtifact(groupIdArtifactId + ":" + range); final VersionRangeRequest rangeRequest = new VersionRangeRequest(); rangeRequest.setArtifact(artifactRange); rangeRequest.setRepositories(repos); final RepositorySystemSession session = _newRepositorySystemSession(system, _localRepositoryPath); Version version = null; try { VersionRangeResult versionRangeResult = system.resolveVersionRange(session, rangeRequest); version = versionRangeResult.getHighestVersion(); } catch (Exception e) { } if (version == null) { return null; } Artifact artifact = new DefaultArtifact(groupIdArtifactId + ":" + version); ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifact); artifactRequest.setRepositories(repos); ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest); return artifactResult.getArtifact(); } AetherClient();  AetherClient(String[] repoUrls);  AetherClient(String[] repoUrls, String localRepositoryPath); Artifact findLatestAvailableArtifact(String groupIdArtifactId);  }
@Ignore @Test public void testCheckLatestArchetypeVersionOffline() throws Exception { AetherClient client = new AetherClient(null, "test-resources/localrepo"); Artifact artifact = client.findLatestAvailableArtifact( "com.liferay:com.liferay.gradle.plugins.workspace:jar:sources"); Assert.assertNotNull(artifact); File file = artifact.getFile(); Assert.assertNotNull(file); Assert.assertTrue(file.exists()); String filePathString = file.getPath(); Assert.assertTrue(filePathString.contains("test-resources/localrepo")); String name = file.getName(); Assert.assertTrue(name.startsWith("com.liferay.gradle.plugins.workspace")); Assert.assertTrue(name.endsWith("sources.jar")); Assert.assertTrue(name.contains("1.0.8")); }
@Ignore @Test public void testCheckLatestArchetypeVersionOnline() throws Exception { AetherClient client = new AetherClient(); Artifact artifact = client.findLatestAvailableArtifact( "com.liferay:com.liferay.gradle.plugins.workspace:jar:sources"); Assert.assertNotNull(artifact); File file = artifact.getFile(); Assert.assertNotNull(file); Assert.assertTrue(file.exists()); String name = file.getName(); Assert.assertTrue(name.startsWith("com.liferay.gradle.plugins.workspace")); Assert.assertTrue(name.endsWith("sources.jar")); Assert.assertEquals(name, true, name.matches(".*-1\\.[0-9]+\\.[0-9]+-.*")); }