Search in sources :

Example 1 with DependenciesTask

use of org.apache.maven.artifact.ant.DependenciesTask in project robolectric by robolectric.

the class MavenDependencyResolver method getLocalArtifactUrls.

/**
   * Get an array of local artifact URLs for the given dependencies. The order of the URLs is guaranteed to be the
   * same as the input order of dependencies, i.e., urls[i] is the local artifact URL for dependencies[i].
   */
public URL[] getLocalArtifactUrls(DependencyJar... dependencies) {
    DependenciesTask dependenciesTask = createDependenciesTask();
    configureMaven(dependenciesTask);
    RemoteRepository remoteRepository = new RemoteRepository();
    remoteRepository.setUrl(repositoryUrl);
    remoteRepository.setId(repositoryId);
    dependenciesTask.addConfiguredRemoteRepository(remoteRepository);
    dependenciesTask.setProject(project);
    for (DependencyJar dependencyJar : dependencies) {
        Dependency dependency = new Dependency();
        dependency.setArtifactId(dependencyJar.getArtifactId());
        dependency.setGroupId(dependencyJar.getGroupId());
        dependency.setType(dependencyJar.getType());
        dependency.setVersion(dependencyJar.getVersion());
        if (dependencyJar.getClassifier() != null) {
            dependency.setClassifier(dependencyJar.getClassifier());
        }
        dependenciesTask.addDependency(dependency);
    }
    dependenciesTask.execute();
    @SuppressWarnings("unchecked") Hashtable<String, String> artifacts = project.getProperties();
    URL[] urls = new URL[dependencies.length];
    for (int i = 0; i < urls.length; i++) {
        try {
            urls[i] = Util.url(artifacts.get(key(dependencies[i])));
        } catch (MalformedURLException e) {
            throw new RuntimeException(e);
        }
    }
    return urls;
}
Also used : DependenciesTask(org.apache.maven.artifact.ant.DependenciesTask) MalformedURLException(java.net.MalformedURLException) RemoteRepository(org.apache.maven.artifact.ant.RemoteRepository) Dependency(org.apache.maven.model.Dependency) URL(java.net.URL)

Example 2 with DependenciesTask

use of org.apache.maven.artifact.ant.DependenciesTask in project robolectric by robolectric.

the class MavenDependencyResolverTest method setUp.

@Before
public void setUp() {
    dependenciesTask = spy(new DependenciesTask());
    doNothing().when(dependenciesTask).execute();
    doAnswer(new Answer() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            invocationOnMock.callRealMethod();
            Object[] args = invocationOnMock.getArguments();
            project = (Project) args[0];
            project.setProperty("group1:artifact1:jar", "path1");
            project.setProperty("group2:artifact2:jar", "path2");
            project.setProperty("group3:artifact3:jar:classifier3", "path3");
            return null;
        }
    }).when(dependenciesTask).setProject(any(Project.class));
}
Also used : DependenciesTask(org.apache.maven.artifact.ant.DependenciesTask) Answer(org.mockito.stubbing.Answer) Project(org.apache.tools.ant.Project) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Before(org.junit.Before)

Aggregations

DependenciesTask (org.apache.maven.artifact.ant.DependenciesTask)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 RemoteRepository (org.apache.maven.artifact.ant.RemoteRepository)1 Dependency (org.apache.maven.model.Dependency)1 Project (org.apache.tools.ant.Project)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1