public void store(File file, String path) throws Exception { int n = 0; URL url = new URL(base + path); SHA1 sha1 = SHA1.digest(file); MD5 md5 = MD5.digest(file); TaggedData go = client.build().put().upload(file).updateTag().asTag().go(url); switch (go.getState()) { case NOT_FOUND: case OTHER: throw new IOException("Could not store " + path + " from " + file + " with " + go); case UNMODIFIED: case UPDATED: default: break; } client.build().put().upload(sha1.asHex()).asTag().go(new URL(base + path + ".sha1")); client.build().put().upload(md5.asHex()).asTag().go(new URL(base + path + ".md5")); }
public TaggedData fetch(String path, File file) throws Exception { URL url = new URL(base + path); int n = 0; while (true) try { reporter.trace("Fetching %s", path); TaggedData tag = client .build() .headers("User-Agent", "Bnd") .useCache(file, DEFAULT_MAX_STALE) .asTag() .go(url); reporter.trace("Fetched %s", tag); if (tag.getState() == State.UPDATED) { // https://issues.sonatype.org/browse/NEXUS-4900 if (!path.endsWith("/maven-metadata.xml")) { URL shaUrl = new URL(base + path + ".sha1"); URL md5Url = new URL(base + path + ".md5"); String sha = client.build().asString().timeout(15000).go(shaUrl); if (sha != null) { String fileSha = SHA1.digest(file).asHex(); checkDigest(fileSha, sha, file); } else { String md5 = client.build().asString().timeout(15000).go(md5Url); if (md5 != null) { String fileMD5 = MD5.digest(file).asHex(); checkDigest(fileMD5, md5, file); } } } } return tag; } catch (Exception e) { n++; if (n > 3) throw e; Thread.sleep(1000 * n); } }