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 junit.framework.JUnit4TestAdapter;
32 import org.apache.tools.ant.types.Path;
33 import org.apache.tools.ant.types.ResourceCollection;
34 import org.apache.tools.ant.types.resources.FileResource;
35 import org.junit.Test;
36
37 public class ResolveTest
38 extends AntBuildsTest
39 {
40 public static junit.framework.Test suite()
41 {
42 return new JUnit4TestAdapter( ResolveTest.class );
43 }
44
45 @Test
46 public void testResolveGlobalPom()
47 {
48 executeTarget( "testResolveGlobalPom" );
49
50 String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" );
51 assertThat( "aether-api was not resolved as a property", prop, notNullValue() );
52 assertThat( "aether-api was not resolved to default local repository", prop,
53 allOf( containsString( "aether-api" ), endsWith( ".jar" ) ) );
54 }
55
56 @Test
57 public void testResolveOverrideGlobalPom()
58 {
59 executeTarget( "testResolveOverrideGlobalPom" );
60
61 String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" );
62 assertThat( "aether-api was not resolved as a property", prop, notNullValue() );
63 assertThat( "aether-api was not resolved to default local repository", prop,
64 allOf( containsString( "aether-api" ), endsWith( ".jar" ) ) );
65 }
66
67 @Test
68 public void testResolveGlobalPomIntoOtherLocalRepo()
69 {
70 executeTarget( "testResolveGlobalPomIntoOtherLocalRepo" );
71
72 String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" );
73 assertThat( "aether-api was not resolved as a property", prop, notNullValue() );
74 assertThat( "aether-api was not resolved to default local repository", prop.replace( '\\', '/' ),
75 endsWith( "local-repo-custom/org/eclipse/aether/aether-api/0.9.0.M3/aether-api-0.9.0.M3.jar" ) );
76 }
77
78 @Test
79 public void testResolveCustomFileLayout()
80 throws IOException
81 {
82 File dir = new File( BUILD_DIR, "resolve-custom-layout" );
83 executeTarget( "testResolveCustomFileLayout" );
84
85 assertThat( "aether-api was not saved with custom file layout",
86 new File( dir, "org.eclipse.aether/aether-api/org/eclipse/aether/jar" ).exists() );
87 }
88
89 @Test
90 public void testResolveAttachments()
91 throws IOException
92 {
93 File dir = new File( BUILD_DIR, "resolve-attachments" );
94 executeTarget( "testResolveAttachments" );
95
96 File jdocDir = new File(dir, "javadoc");
97
98 assertThat( "aether-api-javadoc was not saved with custom file layout",
99 new File( jdocDir, "org.eclipse.aether-aether-api-javadoc.jar" ).exists() );
100
101 assertThat( "found non-javadoc files", Arrays.asList( jdocDir.list() ), everyItem( endsWith( "javadoc.jar" ) ) );
102
103 File sourcesDir = new File( dir, "sources" );
104 assertThat( "aether-api-sources was not saved with custom file layout",
105 new File( sourcesDir, "org.eclipse.aether-aether-api-sources.jar" ).exists() );
106 assertThat( "found non-sources files", Arrays.asList( sourcesDir.list() ),
107 everyItem( endsWith( "sources.jar" ) ) );
108 }
109
110 @Test
111 public void testResolvePath()
112 {
113 executeTarget( "testResolvePath" );
114 Map<?, ?> refs = getProject().getReferences();
115 Object obj = refs.get( "out" );
116 assertThat( "ref 'out' is no path", obj, instanceOf( Path.class ) );
117 Path path = (Path) obj;
118 String[] elements = path.list();
119 assertThat( "no aether-api on classpath", elements,
120 hasItemInArray( allOf( containsString( "aether-api" ), endsWith( ".jar" ) ) ) );
121 }
122
123 @Test
124 public void testResolveDepsFromFile()
125 {
126 executeTarget( "testResolveDepsFromFile" );
127
128 String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-spi:jar" );
129 assertThat( "aether-spi was not resolved as a property", prop, notNullValue() );
130 assertThat( "aether-spi was not resolved to default local repository", prop,
131 allOf( containsString( "aether-spi" ), endsWith( ".jar" ) ) );
132 prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" );
133 assertThat( "aether-api was resolved as a property", prop, nullValue() );
134 }
135
136 @Test
137 public void testResolveNestedDependencyCollections()
138 {
139 executeTarget( "testResolveNestedDependencyCollections" );
140
141 String prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-spi:jar" );
142 assertThat( "aether-spi was not resolved as a property", prop, notNullValue() );
143 prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-util:jar" );
144 assertThat( "aether-util was not resolved as a property", prop, notNullValue() );
145 prop = getProject().getProperty( "test.resolve.path.org.eclipse.aether:aether-api:jar" );
146 assertThat( "aether-api was resolved as a property", prop, nullValue() );
147 }
148
149 @Test
150 public void testResolveResourceCollectionOnly()
151 {
152 executeTarget( "testResolveResourceCollectionOnly" );
153
154 ResourceCollection resources = (ResourceCollection) getProject().getReference( "files" );
155 assertThat( resources, is( notNullValue() ) );
156 assertThat( resources.size(), is( 2 ) );
157 assertThat( resources.isFilesystemOnly(), is( true ) );
158 Iterator<?> it = resources.iterator();
159 FileResource file = (FileResource) it.next();
160 assertThat( file.getFile().getName(), is( "aether-spi-0.9.0.v20140226.jar" ) );
161 file = (FileResource) it.next();
162 assertThat( file.getFile().getName(), is( "aether-api-0.9.0.v20140226.jar" ) );
163 }
164
165 }