private void endNotifyMonitor( CacheMonitorRouter monitor, boolean existed, Artifact artifact, File destination) { if (monitor != null) { if (existed) { monitor.updatedLocalCache(artifact.toURL(), destination); } else { monitor.addedToLocalCache(artifact.toURL(), destination); } } }
@Override public void run() { File destinationFile = new File( destination, artifact.getArtifactId() + ((options.isStripVersions()) ? "" : "-" + artifact.getVersion()) + (artifact.getClassifier().isEmpty() ? "" : ("-" + artifact.getClassifier())) + ".jar"); for (String server : options.getServers()) { URL u = artifact.toURL(server); HttpURLConnection con = null; BufferedInputStream bis = null; BufferedOutputStream bos = null; try { if (!isUpToDate(u, destinationFile)) { con = URLSupport.openURL(u, options.getProxyServer()); con.setConnectTimeout(CONNECTION_TIMEOUT); con.connect(); bis = new BufferedInputStream(con.getInputStream()); bos = new BufferedOutputStream(new FileOutputStream(destinationFile)); Deque<TransferBuffer> dq = new ArrayDeque<TransferBuffer>(); ArtifactReader r = new ArtifactReader( project, bis, dq, BUFFER_SIZE, options.isCheckSHADigests() && !artifact.getDigest().isEmpty()); Thread rt = new Thread(r); rt.start(); ArtifactWriter w = new ArtifactWriter(project, bos, dq); Thread wt = new Thread(w); wt.start(); rt.join(); wt.join(); if (r.wasSuccessful() && w.wasSuccessful()) { if (options.isCheckSHADigests() && !artifact.getDigest().isEmpty()) { if (!digestEquals(artifact, r.getDigest())) { artifact.setStatus(Artifact.Status.DIGEST_MISMATCH); destinationFile.deleteOnExit(); project.log( "download failed with incorrect digest: " + artifact + " - actual: " + byteArrayDigestToHexString(r.getDigest()), Project.MSG_ERR); return; } } artifact.setStatus(Artifact.Status.DOWNLOADED); } } else { artifact.setStatus(Artifact.Status.UPTODATE); } project.log( "download successful: " + artifact, (artifact.getStatus() != Artifact.Status.UPTODATE) ? Project.MSG_ERR : Project.MSG_VERBOSE); return; } catch (Exception e) { if (!YankTask.SOURCE_CLASSIFIER.equals(artifact.getClassifier())) { project.log(e.getMessage(), e, Project.MSG_VERBOSE); project.log("download failed: " + artifact, Project.MSG_ERR); } artifact.setStatus(Artifact.Status.FAILED); } finally { Closer.close(bis); Closer.close(bos); Closer.close(con); } } }