List<Release> releases = moduleService.getReleases(moduleName.getOwner(), moduleName.getName(), null);
if(releases.isEmpty())
throw new FileNotFoundException("No releases found for module '" + moduleName + '\'');
Release best = null;
for(Release release : releases)
if((best == null || release.getVersion().compareTo(best.getVersion()) > 0) &&
(range == null || range.isIncluded(release.getVersion())))
best = release;
if(best == null)
throw new FileNotFoundException("No releases matching '" + range + "' found for module '" + moduleName +
'\'');
if(!destinationIncludesTopFolder)
// Use module name as the default
destination = new File(destination, moduleName.getName());
if(destination.exists()) {
if(!force)
throw new IOException("Destination folder is not empty: " + destination.getAbsolutePath());
// Don't remove .project, .settings, .git, .svn, etc. if they are present.
FileUtils.rmR(destination, FileUtils.DEFAULT_EXCLUDES);
}
File moduleFile = cache.retrieve(best.getFullName(), best.getVersion());
// Unpack closes its input.
TarUtils.unpack(new GZIPInputStream(new FileInputStream(moduleFile)), destination, true, null);
return forgeUtil.loadJSONMetadata(new File(destination, METADATA_JSON_NAME));
}