-
Notifications
You must be signed in to change notification settings - Fork 79
/
PomDependenciesUnitTestCase.java
222 lines (182 loc) · 8.82 KB
/
PomDependenciesUnitTestCase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.shrinkwrap.resolver.impl.maven.integration;
import java.io.File;
import org.jboss.shrinkwrap.resolver.api.Resolvers;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.jboss.shrinkwrap.resolver.api.maven.MavenResolverSystem;
import org.jboss.shrinkwrap.resolver.api.maven.ScopeType;
import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependencies;
import org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency;
import org.jboss.shrinkwrap.resolver.impl.maven.bootstrap.MavenSettingsBuilder;
import org.jboss.shrinkwrap.resolver.impl.maven.util.ValidationUtil;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
/**
* @author <a href="mailto:kpiwko@redhat.com">Karel Piwko</a>
* @author <a href="http://community.jboss.org/people/silenius">Samuel Santos</a>
*/
public class PomDependenciesUnitTestCase {
@BeforeClass
public static void setRemoteRepository() {
System.setProperty(MavenSettingsBuilder.ALT_LOCAL_REPOSITORY_LOCATION, "target/the-other-repository");
}
@AfterClass
public static void clearRemoteRepository() {
System.clearProperty(MavenSettingsBuilder.ALT_LOCAL_REPOSITORY_LOCATION);
}
/**
* Tests loading of a POM file with parent not available on local file system
*
*/
@Test
public void parentPomRepositories() {
File[] files = Resolvers.use(MavenResolverSystem.class).loadPomFromFile("target/poms/test-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-child:1.0.0").withTransitivity().as(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-child.tree"),
ScopeType.COMPILE, ScopeType.RUNTIME).validate(files);
}
/**
* Tests loading of a POM file with parent not available on local file system
*
*/
@Test
public void shortcutParentPomRepositories() {
File[] files = Maven.resolver().loadPomFromFile("target/poms/test-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-child:1.0.0").withoutTransitivity().as(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-child-shortcut.tree"),
ScopeType.COMPILE).validate(files);
}
/**
* Tests loading of a POM file with parent available on local file system
*
*/
@Test
public void parentPomRemoteRepositories() {
File[] files = Resolvers.use(MavenResolverSystem.class).loadPomFromFile("target/poms/test-remote-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0").withTransitivity().as(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c.tree")).validate(
files);
}
/**
* Tests loading of a POM file with parent available on local file system
*
*/
@Test
public void shortcutParentPomRemoteRepositories() {
File[] files = Maven.resolver().loadPomFromFile("target/poms/test-remote-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c:1.0.0").withoutTransitivity().as(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c-shortcut.tree"))
.validate(files);
}
/**
* Tests loading of a POM file with parent available on local file system Uses POM to get artifact version
*
*/
@Test
public void artifactVersionRetrievalFromPom() {
File[] files = Resolvers.use(MavenResolverSystem.class).loadPomFromFile("target/poms/test-remote-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c").withTransitivity().as(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c.tree")).validate(
files);
}
/**
* Tests loading of a POM file with parent available on local file system Uses POM to get artifact version
*
*/
@Test
public void shortcutArtifactVersionRetrievalFromPom() {
File[] files = Maven.resolver().loadPomFromFile("target/poms/test-remote-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c").withoutTransitivity().as(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c-shortcut.tree"))
.validate(files);
}
/**
* Tests loading of a POM file with parent available on local file system Uses POM to get artifact version
*
*/
@Test
public void shortcutArtifactVersionRetrievalFromPomAsFile() {
File file = Maven.resolver().loadPomFromFile("target/poms/test-remote-child.xml")
.resolve("org.jboss.shrinkwrap.test:test-deps-c").withoutTransitivity().asSingle(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c-shortcut.tree"))
.validate(file);
}
/**
* Tests loading of a POM file with parent available on local file system. However, the artifact version is not used
* from there, but specified manually
*
*/
@Test
public void artifactVersionRetrievalFromPomOverride() {
final MavenDependency dependency = MavenDependencies.createDependency(
"org.jboss.shrinkwrap.test:test-deps-c:2.0.0", null, false);
File[] files = Resolvers.use(MavenResolverSystem.class).loadPomFromFile("target/poms/test-remote-child.xml")
.addDependency(dependency).resolve().withTransitivity().as(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c-2.tree")).validate(
files);
}
/**
* Tests loading of a POM file with parent available on local file system. However, the artifact version is not used
* from there, but specified manually
*
*/
@Test
public void shortcutArtifactVersionRetrievalFromPomOverride() {
final MavenDependency dependency = MavenDependencies.createDependency(
"org.jboss.shrinkwrap.test:test-deps-c:2.0.0", null, false);
File file = Maven.resolver().loadPomFromFile("target/poms/test-remote-child.xml").addDependency(dependency)
.resolve().withoutTransitivity().asSingle(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-deps-c-2-shortcut.tree"))
.validate(file);
}
/**
* Tests resolution of dependencies for a POM file with parent on local file system
*
*/
@Test
public void pomBasedDependencies() {
File[] files = Maven.resolver().loadPomFromFile("target/poms/test-child.xml").importRuntimeDependencies()
.as(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-child.tree"), false,
ScopeType.COMPILE, ScopeType.RUNTIME).validate(files);
}
/**
* Tests resolution of dependencies for a POM file without parent on local file system
*
*/
@Test
public void pomRemoteBasedDependencies() {
File[] files = Maven.resolver().loadPomFromFile("target/poms/test-remote-child.xml")
.importRuntimeDependencies().as(File.class);
ValidationUtil.fromDependencyTree(new File("src/test/resources/dependency-trees/test-remote-child.tree"),
false, ScopeType.COMPILE, ScopeType.RUNTIME).validate(files);
}
/**
* Tests resolving a version from pom.xml which has non-default scope
* https://issues.jboss.org/browse/SHRINKRES-103
*
*/
@Test
public void scopedArtifactVersionRetrievalFromPom() {
File[] files = Maven.configureResolver().fromFile("target/settings/profiles/settings.xml")
.loadPomFromFile("target/poms/test-dependency-test-scope.xml")
.resolve("org.jboss.shrinkwrap.test:test-managed-dependency").withoutTransitivity().as(File.class);
new ValidationUtil("test-managed-dependency").validate(files);
}
}