package org.robolectric;

import org.apache.maven.artifact.ant.DependenciesTask;
import org.apache.maven.model.Dependency;
import org.apache.tools.ant.Project;
import org.robolectric.util.Util;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

public class MavenCentral {
  private final Project project = new Project();

  public Map<String, URL> getLocalArtifactUrls(RobolectricTestRunner robolectricTestRunner, Dependency... dependencies) {
    DependenciesTask dependenciesTask = new DependenciesTask();
    if (robolectricTestRunner != null) {
      robolectricTestRunner.configureMaven(dependenciesTask);
    }
    dependenciesTask.setProject(project);
    for (Dependency dependency : dependencies) {
      dependenciesTask.addDependency(dependency);
    }
    dependenciesTask.execute();

    @SuppressWarnings("unchecked")
    Hashtable<String, String> artifacts = project.getProperties();
    Map<String, URL> urls = new HashMap<String, URL>();
    for (Map.Entry<String, String> entry : artifacts.entrySet()) {
      try {
        urls.put(entry.getKey(), Util.url(entry.getValue()));
      } catch (MalformedURLException e) {
        throw new RuntimeException(e);
      }

    }
    return urls;
  }

  public URL getLocalArtifactUrl(RobolectricTestRunner robolectricTestRunner, Dependency dependency) {
    Map<String, URL> map = getLocalArtifactUrls(robolectricTestRunner, dependency);
    return map.get(dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getType() + ":" + dependency.getClassifier());
  }
}

@@ -74,16 +74,71 @@
 esTask;%0A
+import org.apache.maven.artifact.ant.RemoteRepository;%0A
 import o
@@ -745,32 +745,294 @@
 iesTask);%0A    %7D%0A
+    RemoteRepository sonatypeRepository = new RemoteRepository();%0A    sonatypeRepository.setUrl(%22https://oss.sonatype.org/content/groups/public/%22);%0A    sonatypeRepository.setId(%22sonatype%22);%0A    dependenciesTask.addConfiguredRemoteRepository(sonatypeRepository);%0A
     dependencies

Add Sonatype repository for resolving real android dependencies.