Skip to content

Commit

Permalink
enable update policy definition
Browse files Browse the repository at this point in the history
  • Loading branch information
domi committed Nov 10, 2010
1 parent 4eabad6 commit b2c17b6
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public class ArtifactDeployer extends Builder implements Serializable {
static Logger log = Logger.getLogger(ArtifactDeployer.class.getName());

public boolean enableRepoLogging = true;
public String file;
public String groupId;
public String artifactId;
public String classifier;
public String version;
public String extension;
public String repoId;
public final String file;
public final String groupId;
public final String artifactId;
public final String classifier;
public final String version;
public final String extension;
public final String repoId;

@DataBoundConstructor
public ArtifactDeployer(String groupId, String artifactId, String classifier, String version, String extension, String file, String repoId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.sonatype.aether.collection.DependencyCollectionException;
import org.sonatype.aether.repository.RepositoryPolicy;
import org.sonatype.aether.resolution.ArtifactResolutionException;

/**
Expand All @@ -50,13 +51,22 @@ public class ArtifactResolver extends Builder implements Serializable {
public List<Artifact> artifacts;
public boolean failOnError = true;
public boolean enableRepoLogging = true;
public final String snapshotUpdatePolicy;
public final String releaseUpdatePolicy;
public final String snapshotChecksumPolicy;
public final String releaseChecksumPolicy;

@DataBoundConstructor
public ArtifactResolver(String targetDirectory, List<Artifact> artifacts, boolean failOnError, boolean enableRepoLogging) {
public ArtifactResolver(String targetDirectory, List<Artifact> artifacts, boolean failOnError, boolean enableRepoLogging, String snapshotUpdatePolicy,
String snapshotChecksumPolicy, String releaseUpdatePolicy, String releaseChecksumPolicy) {
this.artifacts = artifacts != null ? artifacts : new ArrayList<Artifact>();
this.targetDirectory = StringUtils.isBlank(targetDirectory) ? DEFAULT_TARGET : targetDirectory;
this.failOnError = failOnError;
this.enableRepoLogging = enableRepoLogging;
this.releaseUpdatePolicy = releaseUpdatePolicy;
this.releaseChecksumPolicy = RepositoryPolicy.CHECKSUM_POLICY_WARN;
this.snapshotUpdatePolicy = snapshotUpdatePolicy;
this.snapshotChecksumPolicy = RepositoryPolicy.CHECKSUM_POLICY_WARN;
}

public String getTargetDirectory() {
Expand Down Expand Up @@ -112,7 +122,8 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
private boolean download(AbstractBuild<?, ?> build, final PrintStream logger, final Collection<Repository> repositories, File localRepository) {
boolean hasError = false;

Aether aether = new Aether(repositories, localRepository, logger, enableRepoLogging);
Aether aether = new Aether(repositories, localRepository, logger, enableRepoLogging, snapshotUpdatePolicy, snapshotChecksumPolicy, releaseUpdatePolicy,
releaseChecksumPolicy);

for (Artifact artifact : artifacts) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.sonatype.aether.repository.Authentication;
import org.sonatype.aether.repository.LocalRepository;
import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.repository.RepositoryPolicy;
import org.sonatype.aether.resolution.ArtifactResolutionException;
import org.sonatype.aether.spi.connector.RepositoryConnectorFactory;
import org.sonatype.aether.util.artifact.DefaultArtifact;
Expand All @@ -49,22 +50,31 @@ public class Aether {
private final LocalRepository localRepository;
private final PrintStream logger;
private final boolean extendedLogging;
public String snapshotUpdatePolicy;
public String releaseUpdatePolicy;
public String snapshotChecksumPolicy;
public String releaseChecksumPolicy;

public Aether(Collection<Repository> remoteRepositories, File localRepository, PrintStream logger, boolean extendedLogging) {
public Aether(Collection<Repository> remoteRepositories, File localRepository, PrintStream logger, boolean extendedLogging, String snapshotUpdatePolicy,
String snapshotChecksumPolicy, String releaseUpdatePolicy, String releaseChecksumPolicy) {
this.remoteRepositories = remoteRepositories;
this.repositorySystem = newManualSystem();
this.localRepository = new LocalRepository(localRepository);
this.logger = logger;
this.extendedLogging = extendedLogging;
this.releaseUpdatePolicy = releaseUpdatePolicy;
this.releaseChecksumPolicy = releaseChecksumPolicy;
this.snapshotUpdatePolicy = snapshotUpdatePolicy;
this.snapshotChecksumPolicy = snapshotChecksumPolicy;
}

public Aether(Repository remoteRepository, File localRepository, PrintStream logger, boolean extendedLogging) {
this.remoteRepositories = new ArrayList<Repository>();
remoteRepositories.add(remoteRepository);
this.repositorySystem = newManualSystem();
this.remoteRepositories.add(remoteRepository);
this.localRepository = new LocalRepository(localRepository);
this.logger = logger;
this.extendedLogging = extendedLogging;
this.repositorySystem = newManualSystem();
}

private RepositorySystem newManualSystem() {
Expand Down Expand Up @@ -96,6 +106,10 @@ public AetherResult resolve(String groupId, String artifactId, String classifier
for (Repository repo : remoteRepositories) {
logger.println("define repo: " + repo);
RemoteRepository repoObj = new RemoteRepository(repo.getId(), repo.getType(), repo.getUrl());
RepositoryPolicy snapshotPolicy = new RepositoryPolicy(true, snapshotUpdatePolicy, snapshotChecksumPolicy);
RepositoryPolicy releasePolicy = new RepositoryPolicy(true, releaseUpdatePolicy, releaseChecksumPolicy);
repoObj.setPolicy(true, snapshotPolicy);
repoObj.setPolicy(false, releasePolicy);
collectRequest.addRepository(repoObj);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.sonatype.aether.transfer.TransferCancelledException;
import org.sonatype.aether.transfer.TransferEvent;
import org.sonatype.aether.transfer.TransferListener;
import org.sonatype.aether.transfer.TransferResource;

public class ConsoleTransferListener implements TransferListener {

private static final Log LOG = LogFactory.getLog(ConsoleTransferListener.class);
private PrintStream out;

private Map<TransferResource, Long> downloads = new ConcurrentHashMap<TransferResource, Long>();
Expand All @@ -38,11 +40,8 @@ public ConsoleTransferListener(PrintStream out) {
}

public void transferInitiated(TransferEvent event) {
String message = event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploading"
: "Downloading";

out.println(message + ": " + event.getResource().getRepositoryUrl()
+ event.getResource().getResourceName());
String message = event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploading" : "Downloading";
out.println(message + ": " + event.getResource().getRepositoryUrl() + event.getResource().getResourceName());
}

public void transferProgressed(TransferEvent event) {
Expand Down Expand Up @@ -93,32 +92,25 @@ public void transferSucceeded(TransferEvent event) {
TransferResource resource = event.getResource();
long contentLength = event.getTransferredBytes();
if (contentLength >= 0) {
String type = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded"
: "Downloaded");
String len = contentLength >= 1024 ? toKB(contentLength) + " KB"
: contentLength + " B";
String type = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
String len = contentLength >= 1024 ? toKB(contentLength) + " KB" : contentLength + " B";

String throughput = "";
long duration = System.currentTimeMillis()
- resource.getTransferStartTime();
long duration = System.currentTimeMillis() - resource.getTransferStartTime();
if (duration > 0) {
DecimalFormat format = new DecimalFormat("0.0",
new DecimalFormatSymbols(Locale.ENGLISH));
double kbPerSec = (contentLength / 1024.0)
/ (duration / 1000.0);
DecimalFormat format = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
double kbPerSec = (contentLength / 1024.0) / (duration / 1000.0);
throughput = " at " + format.format(kbPerSec) + " KB/sec";
}

out.println(type + ": " + resource.getRepositoryUrl()
+ resource.getResourceName() + " (" + len + throughput
+ ")");
out.println(type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len + throughput + ")");
}
}

public void transferFailed(TransferEvent event) {
transferCompleted(event);

event.getException().printStackTrace(out);
LOG.debug("transferFailed", event.getException());
out.println(event.getException().getClass() + ": " + event.getException().getMessage());
}

private void transferCompleted(TransferEvent event) {
Expand All @@ -141,8 +133,7 @@ protected long toKB(long bytes) {
/**
* @see org.sonatype.aether.transfer.TransferListener#transferStarted(org.sonatype.aether.transfer.TransferEvent)
*/
public void transferStarted(TransferEvent arg0)
throws TransferCancelledException {
public void transferStarted(TransferEvent arg0) throws TransferCancelledException {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
<f:textbox name="targetDirectory" value="${instance.targetDirectory}" />
</f:entry>

<f:entry title="${%Release update policy}">
<select class="setting-input" name="releaseUpdatePolicy">
<f:option selected="${instance.releaseUpdatePolicy=='daily'}"
value="never">daily</f:option>
<f:option selected="${instance.releaseUpdatePolicy=='never'}"
value="never">never</f:option>
<f:option selected="${instance.releaseUpdatePolicy=='always'}"
value="always">always</f:option>
</select>
</f:entry>

<f:entry title="${%Snapshot update policy}">
<select class="setting-input" name="snapshotUpdatePolicy">
<f:option selected="${instance.snapshotUpdatePolicy=='daily'}"
value="never">daily</f:option>
<f:option selected="${instance.snapshotUpdatePolicy=='never'}"
value="never">never</f:option>
<f:option selected="${instance.snapshotUpdatePolicy=='always'}"
value="always">always</f:option>
</select>
</f:entry>

<f:entry title="${Artifacts}">
<f:repeatable var="artifact" items="${instance.artifacts}"
name="artifacts" noAddButton="true" minimum="1">
Expand Down

0 comments on commit b2c17b6

Please sign in to comment.