// Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
// public abstract class AbstractNexusOperation
// {
//   public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
// 
//   protected final String username;
// 
//   protected final String password;
// 
//   protected final String nexusBaseurl;
// 
//   public AbstractNexusOperation(Nexus nexus) {
//     this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
//     this.username = nexus.getUsername();
//     this.password = nexus.getPassword();
//   }
// 
//   private static String sanitizeBaseurl(String nexusBaseurl) {
//     if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
//       return null;
//     }
//     nexusBaseurl = nexusBaseurl.trim();
//     return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
//   }
// 
//   protected DefaultHttpClient getHttpClient() {
//     ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread());
// 
//     DefaultHttpClient httpclient = info.getContextValue("httpclient");
//     if (httpclient == null) {
//       HttpParams params = new BasicHttpParams();
//       HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
//       HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
//       httpclient = new DefaultHttpClient(params);
//       httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY,
//           new UsernamePasswordCredentials(username, password));
//       info.setContextValue("httpclient", httpclient);
//     }
//     return httpclient;
//   }
// 
//   protected boolean isSuccess(HttpResponse response) {
//     return response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 299;
//   }
// 
//   @SuppressWarnings("unchecked")
//   protected NexusClient getNexusClient(final SubsystemFactory<?, JerseyNexusClient>... subsystemFactories) {
//     if (nexusBaseurl == null) {
//       throw new IllegalStateException();
//     }
//     BaseUrl baseUrl;
//     try {
//       baseUrl = BaseUrl.baseUrlFrom(this.nexusBaseurl);
//     }
//     catch (MalformedURLException e) {
//       throw new RuntimeException(e);
//     }
//     AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo(this.username, this.password);
//     ConnectionInfo connectionInfo = new ConnectionInfo(baseUrl, authenticationInfo, null /* proxyInfos */);
//     return new JerseyNexusClientFactory(subsystemFactories).createFor(connectionInfo);
//   }
// 
//   @SuppressWarnings("rawtypes")
//   protected JerseyRepositoriesFactory newRepositoryFactories() {
//     Set<RepositoryFactory> repositoryFactories = new HashSet<>();
//     repositoryFactories.add(new JerseyMavenHostedRepositoryFactory());
//     repositoryFactories.add(new JerseyMavenGroupRepositoryFactory());
//     repositoryFactories.add(new JerseyMavenProxyRepositoryFactory());
//     return new JerseyRepositoriesFactory(repositoryFactories);
//   }
// 
//   @SuppressWarnings("unchecked")
//   protected String getRepoBaseurl(String repoid) {
//     final String layout = System.getProperty("nexus.layout", "NX3");
//     switch (layout) {
//       case "NX2":
//         return getNexusClient(newRepositoryFactories()).getSubsystem(Repositories.class).get(repoid).contentUri();
//       case "NX3":
//         return this.nexusBaseurl + "repository/" + repoid;
//       default:
//         throw new IllegalArgumentException("Unknown -Dnexus.layout: " + layout);
//     }
//   }
// }
// 
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
//   String getSwarmName();
// 
//   int getClientId();
// 
//   int getRequestId();
// 
//   <T> void setContextValue(String key, T value);
// 
//   <T> T getContextValue(String key);
// }
// 
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// @JsonTypeInfo(use = Id.MINIMAL_CLASS, include = As.PROPERTY, property = "class")
// public static interface Operation {
//   public void perform(ClientRequestInfo requestInfo) throws Exception;
// }
// 
// Path: src/main/java/com/sonatype/nexus/perftest/Nexus.java
// public class Nexus {
//   private final String baseurl;
// 
//   private final String username;
// 
//   private final String password;
// 
//   public Nexus() {
//     this.baseurl = System.getProperty("nexus.baseurl");
//     this.username = System.getProperty("nexus.username");
//     this.password = System.getProperty("nexus.password");
//   }
// 
//   @JsonCreator
//   public Nexus(@JsonProperty("baseurl") String baseurl, @JsonProperty("username") String username,
//       @JsonProperty("password") String password) {
//     this.baseurl = baseurl;
//     this.username = username;
//     this.password = password;
//   }
// 
//   public String getBaseurl() {
//     return baseurl;
//   }
// 
//   public String getUsername() {
//     return username;
//   }
// 
//   public String getPassword() {
//     return password;
//   }
// }


import com.sonatype.nexus.perftest.AbstractNexusOperation;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import com.sonatype.nexus.perftest.ClientSwarm.Operation;
import com.sonatype.nexus.perftest.Nexus;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonProperty;
/*
 * Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
 *
 * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
 * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
 */
package com.sonatype.nexus.perftest.maven;



/**
 * Downloads series of artifacts from a maven2 repository.
 */
public class DownloadOperation extends AbstractNexusOperation implements Operation {
  private final String repoBaseurl;

  private final DownloadPaths paths;

  public DownloadOperation(@JacksonInject Nexus nexus, @JsonProperty("repo") String repoid,
      @JsonProperty("paths") DownloadPaths paths ) {
    super(nexus);
    this.repoBaseurl = getRepoBaseurl(repoid);
    this.paths = paths;
  }

  @Override
// Path: src/main/java/com/sonatype/nexus/perftest/AbstractNexusOperation.java
// public abstract class AbstractNexusOperation
// {
//   public static final int HTTP_TIMEOUT = Integer.parseInt(System.getProperty("perftest.http.timeout", "60000"));
// 
//   protected final String username;
// 
//   protected final String password;
// 
//   protected final String nexusBaseurl;
// 
//   public AbstractNexusOperation(Nexus nexus) {
//     this.nexusBaseurl = sanitizeBaseurl(nexus.getBaseurl());
//     this.username = nexus.getUsername();
//     this.password = nexus.getPassword();
//   }
// 
//   private static String sanitizeBaseurl(String nexusBaseurl) {
//     if (nexusBaseurl == null || nexusBaseurl.trim().isEmpty()) {
//       return null;
//     }
//     nexusBaseurl = nexusBaseurl.trim();
//     return nexusBaseurl.endsWith("/") ? nexusBaseurl : (nexusBaseurl + "/");
//   }
// 
//   protected DefaultHttpClient getHttpClient() {
//     ClientRequestInfo info = ((ClientRequestInfo) Thread.currentThread());
// 
//     DefaultHttpClient httpclient = info.getContextValue("httpclient");
//     if (httpclient == null) {
//       HttpParams params = new BasicHttpParams();
//       HttpConnectionParams.setConnectionTimeout(params, HTTP_TIMEOUT);
//       HttpConnectionParams.setSoTimeout(params, HTTP_TIMEOUT);
//       httpclient = new DefaultHttpClient(params);
//       httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY,
//           new UsernamePasswordCredentials(username, password));
//       info.setContextValue("httpclient", httpclient);
//     }
//     return httpclient;
//   }
// 
//   protected boolean isSuccess(HttpResponse response) {
//     return response.getStatusLine().getStatusCode() >= 200 && response.getStatusLine().getStatusCode() <= 299;
//   }
// 
//   @SuppressWarnings("unchecked")
//   protected NexusClient getNexusClient(final SubsystemFactory<?, JerseyNexusClient>... subsystemFactories) {
//     if (nexusBaseurl == null) {
//       throw new IllegalStateException();
//     }
//     BaseUrl baseUrl;
//     try {
//       baseUrl = BaseUrl.baseUrlFrom(this.nexusBaseurl);
//     }
//     catch (MalformedURLException e) {
//       throw new RuntimeException(e);
//     }
//     AuthenticationInfo authenticationInfo = new UsernamePasswordAuthenticationInfo(this.username, this.password);
//     ConnectionInfo connectionInfo = new ConnectionInfo(baseUrl, authenticationInfo, null /* proxyInfos */);
//     return new JerseyNexusClientFactory(subsystemFactories).createFor(connectionInfo);
//   }
// 
//   @SuppressWarnings("rawtypes")
//   protected JerseyRepositoriesFactory newRepositoryFactories() {
//     Set<RepositoryFactory> repositoryFactories = new HashSet<>();
//     repositoryFactories.add(new JerseyMavenHostedRepositoryFactory());
//     repositoryFactories.add(new JerseyMavenGroupRepositoryFactory());
//     repositoryFactories.add(new JerseyMavenProxyRepositoryFactory());
//     return new JerseyRepositoriesFactory(repositoryFactories);
//   }
// 
//   @SuppressWarnings("unchecked")
//   protected String getRepoBaseurl(String repoid) {
//     final String layout = System.getProperty("nexus.layout", "NX3");
//     switch (layout) {
//       case "NX2":
//         return getNexusClient(newRepositoryFactories()).getSubsystem(Repositories.class).get(repoid).contentUri();
//       case "NX3":
//         return this.nexusBaseurl + "repository/" + repoid;
//       default:
//         throw new IllegalArgumentException("Unknown -Dnexus.layout: " + layout);
//     }
//   }
// }
// 
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// public static interface ClientRequestInfo {
//   String getSwarmName();
// 
//   int getClientId();
// 
//   int getRequestId();
// 
//   <T> void setContextValue(String key, T value);
// 
//   <T> T getContextValue(String key);
// }
// 
// Path: src/main/java/com/sonatype/nexus/perftest/ClientSwarm.java
// @JsonTypeInfo(use = Id.MINIMAL_CLASS, include = As.PROPERTY, property = "class")
// public static interface Operation {
//   public void perform(ClientRequestInfo requestInfo) throws Exception;
// }
// 
// Path: src/main/java/com/sonatype/nexus/perftest/Nexus.java
// public class Nexus {
//   private final String baseurl;
// 
//   private final String username;
// 
//   private final String password;
// 
//   public Nexus() {
//     this.baseurl = System.getProperty("nexus.baseurl");
//     this.username = System.getProperty("nexus.username");
//     this.password = System.getProperty("nexus.password");
//   }
// 
//   @JsonCreator
//   public Nexus(@JsonProperty("baseurl") String baseurl, @JsonProperty("username") String username,
//       @JsonProperty("password") String password) {
//     this.baseurl = baseurl;
//     this.username = username;
//     this.password = password;
//   }
// 
//   public String getBaseurl() {
//     return baseurl;
//   }
// 
//   public String getUsername() {
//     return username;
//   }
// 
//   public String getPassword() {
//     return password;
//   }
// }


// Path: src/main/java/com/sonatype/nexus/perftest/maven/DownloadOperation.java
import com.sonatype.nexus.perftest.AbstractNexusOperation;
import com.sonatype.nexus.perftest.ClientSwarm.ClientRequestInfo;
import com.sonatype.nexus.perftest.ClientSwarm.Operation;
import com.sonatype.nexus.perftest.Nexus;
import com.fasterxml.jackson.annotation.JacksonInject;
import com.fasterxml.jackson.annotation.JsonProperty;

/*
 * Copyright (c) 2007-2013 Sonatype, Inc. All rights reserved.
 *
 * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
 * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
 */
package com.sonatype.nexus.perftest.maven;



/**
 * Downloads series of artifacts from a maven2 repository.
 */
public class DownloadOperation extends AbstractNexusOperation implements Operation {
  private final String repoBaseurl;

  private final DownloadPaths paths;

  public DownloadOperation(@JacksonInject Nexus nexus, @JsonProperty("repo") String repoid,
      @JsonProperty("paths") DownloadPaths paths ) {
    super(nexus);
    this.repoBaseurl = getRepoBaseurl(repoid);
    this.paths = paths;
  }

  @Override
  public void perform(ClientRequestInfo requestInfo) throws Exception {