1 package org.apache.maven.resolver.internal.ant;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static org.hamcrest.MatcherAssert.*;
23 import static org.hamcrest.Matchers.*;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.util.Arrays;
28 import java.util.Iterator;
29 import java.util.Map;
30
31 import org.apache.tools.ant.types.Path;
32 import org.apache.tools.ant.types.ResourceCollection;
33 import org.apache.tools.ant.types.resources.FileResource;
34
35 public class ResolveTest
36 extends AntBuildsTest
37 {
38
39 public void testResolveGlobalPom()
40 {
41 executeTarget( "testResolveGlobalPom" );
42
43 String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" );
44 assertThat( "aether-api was not resolved as a property", prop, notNullValue() );
45 assertThat( "aether-api was not resolved to default local repository", prop,
46 allOf( containsString( "aether-api" ), endsWith( ".jar" ) ) );
47 }
48
49 public void testResolveOverrideGlobalPom()
50 {
51 executeTarget( "testResolveOverrideGlobalPom" );
52
53 String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" );
54 assertThat( "aether-api was not resolved as a property", prop, notNullValue() );
55 assertThat( "aether-api was not resolved to default local repository", prop,
56 allOf( containsString( "aether-api" ), endsWith( ".jar" ) ) );
57 }
58
59 public void testResolveGlobalPomIntoOtherLocalRepo()
60 {
61 executeTarget( "testResolveGlobalPomIntoOtherLocalRepo" );
62
63 String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" );
64 assertThat( "aether-api was not resolved as a property", prop, notNullValue() );
65 assertThat( "aether-api was not resolved to default local repository", prop.replace( '\\', '/' ),
66 endsWith( "local-repo-custom/org/eclipse/aether/aether-api/0.9.0.M3/aether-api-0.9.0.M3.jar" ) );
67 }
68
69 public void testResolveCustomFileLayout()
70 throws IOException
71 {
72 File dir = new File( BUILD_DIR, "resolve-custom-layout" );
73 executeTarget( "testResolveCustomFileLayout" );
74
75 assertThat( "aether-api was not saved with custom file layout",
76 new File( dir, "org.eclipse.aether/aether-api/org/eclipse/aether/jar" ).exists() );
77 }
78
79 public void testResolveAttachments()
80 throws IOException
81 {
82 File dir = new File( BUILD_DIR, "resolve-attachments" );
83 executeTarget( "testResolveAttachments" );
84
85 File jdocDir = new File(dir, "javadoc");
86
87 assertThat( "aether-api-javadoc was not saved with custom file layout",
88 new File( jdocDir, "org.eclipse.aether-aether-api-javadoc.jar" ).exists() );
89
90 assertThat( "found non-javadoc files", Arrays.asList( jdocDir.list() ), everyItem( endsWith( "javadoc.jar" ) ) );
91
92 File sourcesDir = new File( dir, "sources" );
93 assertThat( "aether-api-sources was not saved with custom file layout",
94 new File( sourcesDir, "org.eclipse.aether-aether-api-sources.jar" ).exists() );
95 assertThat( "found non-sources files", Arrays.asList( sourcesDir.list() ),
96 everyItem( endsWith( "sources.jar" ) ) );
97 }
98
99 public void testResolvePath()
100 {
101 executeTarget( "testResolvePath" );
102 Map<?, ?> refs = getProject().getReferences();
103 Object obj = refs.get( "out" );
104 assertThat( "ref 'out' is no path", obj, instanceOf( Path.class ) );
105 Path path = (Path) obj;
106 String[] elements = path.list();
107 assertThat( "no aether-api on classpath", elements,
108 hasItemInArray( allOf( containsString( "aether-api" ), endsWith( ".jar" ) ) ) );
109 }
110
111 public void testResolveDepsFromFile()
112 {
113 executeTarget( "testResolveDepsFromFile" );
114
115 String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-spi:jar" );
116 assertThat( "aether-spi was not resolved as a property", prop, notNullValue() );
117 assertThat( "aether-spi was not resolved to default local repository", prop,
118 allOf( containsString( "aether-spi" ), endsWith( ".jar" ) ) );
119 prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" );
120 assertThat( "aether-api was resolved as a property", prop, nullValue() );
121 }
122
123 public void testResolveNestedDependencyCollections()
124 {
125 executeTarget( "testResolveNestedDependencyCollections" );
126
127 String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-spi:jar" );
128 assertThat( "aether-spi was not resolved as a property", prop, notNullValue() );
129 prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-util:jar" );
130 assertThat( "aether-util was not resolved as a property", prop, notNullValue() );
131 prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" );
132 assertThat( "aether-api was resolved as a property", prop, nullValue() );
133 }
134
135 public void testResolveResourceCollectionOnly()
136 {
137 executeTarget( "testResolveResourceCollectionOnly" );
138
139 ResourceCollection resources = (ResourceCollection) getProject().getReference( "files" );
140 assertThat( resources, is( notNullValue() ) );
141 assertThat( resources.size(), is( 2 ) );
142 assertThat( resources.isFilesystemOnly(), is( true ) );
143 Iterator<?> it = resources.iterator();
144 FileResource file = (FileResource) it.next();
145 assertThat( file.getFile().getName(), is( "aether-spi-0.9.0.v20140226.jar" ) );
146 file = (FileResource) it.next();
147 assertThat( file.getFile().getName(), is( "aether-api-0.9.0.v20140226.jar" ) );
148 }
149
150 }