@Test public void find_in_maven_local_repository_if_defined() throws IOException { File localRepository = temp.newFolder(); FileUtils.touch(new File(localRepository, "foo/bar/1.0/bar-1.0.jar")); when(fileSystem.mavenLocalRepository()).thenReturn(localRepository); markAsAbsentFromArtifactory(); File file = underTest.locateResolvedVersion(MavenLocation.of("foo", "bar", "1.0")); assertThat(file).exists().hasName("bar-1.0.jar"); verifyZeroInteractions(artifactory); verifyEmptyCache(); }
@Nullable File locateResolvedVersion(MavenLocation resolvedLocation) { String cacheKey = cacheKeyOf(resolvedLocation); File cachedDir = new File(fileSystem.getCacheDir(), cacheKey); if (cachedDir.exists()) { Collection<File> files = FileUtils.listFiles(cachedDir, null, false); if (files.size() == 1) { File file = files.iterator().next(); LOG.info("Found {} at {}", resolvedLocation, file); return file; } } File file = locateInLocalRepository(resolvedLocation); if (file != null) { LOG.info("Found {} in Maven local repository at {}", resolvedLocation, file); return file; } if (resolvedLocation.getVersion().endsWith("-SNAPSHOT")) { return null; } File cachedFile = new File(cachedDir, resolvedLocation.getFilename()); boolean found = artifactory.downloadToFile(resolvedLocation, cachedFile); return found ? cachedFile : null; }
MavenLocator implements Locator<MavenLocation> { @Nullable File locateResolvedVersion(MavenLocation resolvedLocation) { String cacheKey = cacheKeyOf(resolvedLocation); File cachedDir = new File(fileSystem.getCacheDir(), cacheKey); if (cachedDir.exists()) { Collection<File> files = FileUtils.listFiles(cachedDir, null, false); if (files.size() == 1) { File file = files.iterator().next(); LOG.info("Found {} at {}", resolvedLocation, file); return file; } } File file = locateInLocalRepository(resolvedLocation); if (file != null) { LOG.info("Found {} in Maven local repository at {}", resolvedLocation, file); return file; } if (resolvedLocation.getVersion().endsWith("-SNAPSHOT")) { return null; } File cachedFile = new File(cachedDir, resolvedLocation.getFilename()); boolean found = artifactory.downloadToFile(resolvedLocation, cachedFile); return found ? cachedFile : null; } }
MavenLocator implements Locator<MavenLocation> { @Nullable File locateResolvedVersion(MavenLocation resolvedLocation) { String cacheKey = cacheKeyOf(resolvedLocation); File cachedDir = new File(fileSystem.getCacheDir(), cacheKey); if (cachedDir.exists()) { Collection<File> files = FileUtils.listFiles(cachedDir, null, false); if (files.size() == 1) { File file = files.iterator().next(); LOG.info("Found {} at {}", resolvedLocation, file); return file; } } File file = locateInLocalRepository(resolvedLocation); if (file != null) { LOG.info("Found {} in Maven local repository at {}", resolvedLocation, file); return file; } if (resolvedLocation.getVersion().endsWith("-SNAPSHOT")) { return null; } File cachedFile = new File(cachedDir, resolvedLocation.getFilename()); boolean found = artifactory.downloadToFile(resolvedLocation, cachedFile); return found ? cachedFile : null; } MavenLocator(FileSystem fileSystem, Artifactory artifactory); }
MavenLocator implements Locator<MavenLocation> { @Nullable File locateResolvedVersion(MavenLocation resolvedLocation) { String cacheKey = cacheKeyOf(resolvedLocation); File cachedDir = new File(fileSystem.getCacheDir(), cacheKey); if (cachedDir.exists()) { Collection<File> files = FileUtils.listFiles(cachedDir, null, false); if (files.size() == 1) { File file = files.iterator().next(); LOG.info("Found {} at {}", resolvedLocation, file); return file; } } File file = locateInLocalRepository(resolvedLocation); if (file != null) { LOG.info("Found {} in Maven local repository at {}", resolvedLocation, file); return file; } if (resolvedLocation.getVersion().endsWith("-SNAPSHOT")) { return null; } File cachedFile = new File(cachedDir, resolvedLocation.getFilename()); boolean found = artifactory.downloadToFile(resolvedLocation, cachedFile); return found ? cachedFile : null; } MavenLocator(FileSystem fileSystem, Artifactory artifactory); @Override File locate(MavenLocation location); Optional<String> resolveVersion(MavenLocation location); @Override File copyToDirectory(MavenLocation location, File toDir); @Override File copyToFile(MavenLocation location, File toFile); @Override @CheckForNull InputStream openInputStream(MavenLocation location); }
MavenLocator implements Locator<MavenLocation> { @Nullable File locateResolvedVersion(MavenLocation resolvedLocation) { String cacheKey = cacheKeyOf(resolvedLocation); File cachedDir = new File(fileSystem.getCacheDir(), cacheKey); if (cachedDir.exists()) { Collection<File> files = FileUtils.listFiles(cachedDir, null, false); if (files.size() == 1) { File file = files.iterator().next(); LOG.info("Found {} at {}", resolvedLocation, file); return file; } } File file = locateInLocalRepository(resolvedLocation); if (file != null) { LOG.info("Found {} in Maven local repository at {}", resolvedLocation, file); return file; } if (resolvedLocation.getVersion().endsWith("-SNAPSHOT")) { return null; } File cachedFile = new File(cachedDir, resolvedLocation.getFilename()); boolean found = artifactory.downloadToFile(resolvedLocation, cachedFile); return found ? cachedFile : null; } MavenLocator(FileSystem fileSystem, Artifactory artifactory); @Override File locate(MavenLocation location); Optional<String> resolveVersion(MavenLocation location); @Override File copyToDirectory(MavenLocation location, File toDir); @Override File copyToFile(MavenLocation location, File toFile); @Override @CheckForNull InputStream openInputStream(MavenLocation location);  }