update copyright
[fedora-idea.git] / plugins / maven / src / test / java / org / jetbrains / idea / maven / SnapshotDependenciesImportingTest.java
blob63f0738369d4b2cdb89f4d3b6547e3e37b087ac2
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.idea.maven;
18 import com.intellij.openapi.util.io.FileUtil;
19 import com.intellij.openapi.vfs.VirtualFile;
21 import java.io.File;
22 import java.io.IOException;
24 public class SnapshotDependenciesImportingTest extends MavenImportingTestCase {
25 private File remoteRepoDir;
27 @Override
28 protected void setUp() throws Exception {
29 super.setUp();
30 // disable local mirrors
31 updateSettingsXmlFully("<settings></settings>");
34 @Override
35 protected void setUpInWriteAction() throws Exception {
36 super.setUpInWriteAction();
38 remoteRepoDir = new File(myDir, "remote");
39 remoteRepoDir.mkdirs();
42 public void testSnapshotVersionDependencyToModule() throws Exception {
43 performTestWithDependencyVersion("1-SNAPSHOT");
46 public void testSnapshotRangeDependencyToModule() throws Exception {
47 performTestWithDependencyVersion("SNAPSHOT");
50 private void performTestWithDependencyVersion(String version) throws Exception {
51 if (!hasMavenInstallation()) return;
53 createProjectPom("<groupId>test</groupId>" +
54 "<artifactId>project</artifactId>" +
55 "<packaging>pom</packaging>" +
56 "<version>1</version>" +
58 "<modules>" +
59 " <module>m1</module>" +
60 " <module>m2</module>" +
61 "</modules>");
63 createModulePom("m1", "<groupId>test</groupId>" +
64 "<artifactId>m1</artifactId>" +
65 "<version>1</version>" +
67 repositoriesSection() +
69 "<dependencies>" +
70 " <dependency>" +
71 " <groupId>test</groupId>" +
72 " <artifactId>m2</artifactId>" +
73 " <version>" + version + "</version>" +
74 " </dependency>" +
75 "</dependencies>");
77 createModulePom("m2", "<groupId>test</groupId>" +
78 "<artifactId>m2</artifactId>" +
79 "<version>" + version + "</version>" +
81 distributionManagementSection());
83 importProject();
84 assertModules("project", "m1", "m2");
85 assertModuleModuleDeps("m1", "m2");
87 // in order to force maven to resolve dependency into remote one we have to
88 // clean up local repository.
89 deploy("m2");
90 removeFromLocalRepository("test");
92 importProject();
94 assertModules("project", "m1", "m2");
95 assertModuleModuleDeps("m1", "m2");
98 public void testNamingLibraryTheSameWayRegardlessAvailableSnapshotVersion() throws Exception {
99 if (!hasMavenInstallation()) return;
101 deployArtifact("test", "foo", "1-SNAPSHOT");
103 importProject("<groupId>test</groupId>" +
104 "<artifactId>project</artifactId>" +
105 "<version>1</version>" +
107 repositoriesSection() +
109 "<dependencies>" +
110 " <dependency>" +
111 " <groupId>test</groupId>" +
112 " <artifactId>foo</artifactId>" +
113 " <version>1-SNAPSHOT</version>" +
114 " </dependency>" +
115 "</dependencies>");
116 assertModuleLibDeps("project", "Maven: test:foo:1-SNAPSHOT");
118 removeFromLocalRepository("test");
120 importProject();
121 assertModuleLibDeps("project", "Maven: test:foo:1-SNAPSHOT");
124 public void testAttachingCorrectJavaDocsAndSources() throws Exception {
125 if (!hasMavenInstallation()) return;
127 deployArtifact("test", "foo", "1-SNAPSHOT",
128 "<build>" +
129 " <plugins>" +
130 " <plugin>" +
131 " <artifactId>maven-source-plugin</artifactId>" +
132 " <executions>" +
133 " <execution>" +
134 " <goals>" +
135 " <goal>jar</goal>" +
136 " </goals>" +
137 " </execution>" +
138 " </executions>" +
139 " </plugin>" +
140 " <plugin>" +
141 " <artifactId>maven-javadoc-plugin</artifactId>" +
142 " <executions>" +
143 " <execution>" +
144 " <goals>" +
145 " <goal>jar</goal>" +
146 " </goals>" +
147 " </execution>" +
148 " </executions>" +
149 " </plugin>" +
150 " </plugins>" +
151 "</build>");
153 removeFromLocalRepository("test");
155 importProject("<groupId>test</groupId>" +
156 "<artifactId>project</artifactId>" +
157 "<version>1</version>" +
159 repositoriesSection() +
161 "<dependencies>" +
162 " <dependency>" +
163 " <groupId>test</groupId>" +
164 " <artifactId>foo</artifactId>" +
165 " <version>1-SNAPSHOT</version>" +
166 " </dependency>" +
167 "</dependencies>");
168 assertModuleLibDeps("project", "Maven: test:foo:1-SNAPSHOT");
170 resolveDependenciesAndImport();
171 downloadArtifacts();
173 assertModuleLibDep("project",
174 "Maven: test:foo:1-SNAPSHOT",
175 "jar://" + getRepositoryPath() + "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT.jar!/",
176 "jar://" + getRepositoryPath() + "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT-sources.jar!/",
177 "jar://" + getRepositoryPath() + "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT-javadoc.jar!/");
179 assertTrue(new File(getRepositoryFile(), "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT.jar").exists());
180 assertTrue(new File(getRepositoryFile(), "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT-sources.jar").exists());
181 assertTrue(new File(getRepositoryFile(), "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT-javadoc.jar").exists());
184 public void testCorrectlryUpdateRootEntriesWithActualPathForSnapshotDependencies() throws Exception {
185 if (!hasMavenInstallation()) return;
187 deployArtifact("test", "foo", "1-SNAPSHOT",
188 "<build>" +
189 " <plugins>" +
190 " <plugin>" +
191 " <artifactId>maven-source-plugin</artifactId>" +
192 " <executions>" +
193 " <execution>" +
194 " <goals>" +
195 " <goal>jar</goal>" +
196 " </goals>" +
197 " </execution>" +
198 " </executions>" +
199 " </plugin>" +
200 " <plugin>" +
201 " <artifactId>maven-javadoc-plugin</artifactId>" +
202 " <executions>" +
203 " <execution>" +
204 " <goals>" +
205 " <goal>jar</goal>" +
206 " </goals>" +
207 " </execution>" +
208 " </executions>" +
209 " </plugin>" +
210 " </plugins>" +
211 "</build>");
212 removeFromLocalRepository("test");
214 importProject("<groupId>test</groupId>" +
215 "<artifactId>project</artifactId>" +
216 "<version>1</version>" +
218 repositoriesSection() +
220 "<dependencies>" +
221 " <dependency>" +
222 " <groupId>test</groupId>" +
223 " <artifactId>foo</artifactId>" +
224 " <version>1-SNAPSHOT</version>" +
225 " </dependency>" +
226 "</dependencies>");
227 assertModuleLibDeps("project", "Maven: test:foo:1-SNAPSHOT");
229 resolveDependenciesAndImport();
230 downloadArtifacts();
232 assertModuleLibDep("project",
233 "Maven: test:foo:1-SNAPSHOT",
234 "jar://" + getRepositoryPath() + "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT.jar!/",
235 "jar://" + getRepositoryPath() + "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT-sources.jar!/",
236 "jar://" + getRepositoryPath() + "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT-javadoc.jar!/");
239 deployArtifact("test", "foo", "1-SNAPSHOT",
240 "<build>" +
241 " <plugins>" +
242 " <plugin>" +
243 " <artifactId>maven-source-plugin</artifactId>" +
244 " <executions>" +
245 " <execution>" +
246 " <goals>" +
247 " <goal>jar</goal>" +
248 " </goals>" +
249 " </execution>" +
250 " </executions>" +
251 " </plugin>" +
252 " <plugin>" +
253 " <artifactId>maven-javadoc-plugin</artifactId>" +
254 " <executions>" +
255 " <execution>" +
256 " <goals>" +
257 " <goal>jar</goal>" +
258 " </goals>" +
259 " </execution>" +
260 " </executions>" +
261 " </plugin>" +
262 " </plugins>" +
263 "</build>");
264 removeFromLocalRepository("test");
266 scheduleResolveAll();
267 resolveDependenciesAndImport();
269 assertModuleLibDep("project",
270 "Maven: test:foo:1-SNAPSHOT",
271 "jar://" + getRepositoryPath() + "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT.jar!/",
272 "jar://" + getRepositoryPath() + "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT-sources.jar!/",
273 "jar://" + getRepositoryPath() + "/test/foo/1-SNAPSHOT/foo-1-SNAPSHOT-javadoc.jar!/");
276 private void deployArtifact(String groupId, String artifactId, String version) throws IOException {
277 deployArtifact(groupId, artifactId, version, "");
280 private void deployArtifact(String groupId, String artifactId, String version, String tail) throws IOException {
281 String moduleName = "___" + artifactId;
283 createProjectSubFile(moduleName + "/src/main/java/Foo.java",
284 "/**\n" +
285 " * some doc\n" +
286 " */\n" +
287 "public class Foo { }");
289 VirtualFile m = createModulePom(moduleName,
290 "<groupId>" + groupId + "</groupId>" +
291 "<artifactId>" + artifactId + "</artifactId>" +
292 "<version>" + version + "</version>" +
294 distributionManagementSection() +
296 tail);
298 deploy(moduleName);
299 FileUtil.delete(new File(m.getParent().getPath()));
302 private void deploy(String modulePath) {
303 executeGoal(modulePath, "deploy");
306 private String repositoriesSection() {
307 return "<repositories>" +
308 " <repository>" +
309 " <id>internal</id>" +
310 " <url>file:///" + FileUtil.toSystemIndependentName(remoteRepoDir.getPath()) + "</url>" +
311 " <snapshots>" +
312 " <enabled>true</enabled>" +
313 " <updatePolicy>always</updatePolicy>" +
314 " </snapshots>" +
315 " </repository>" +
316 "</repositories>";
319 private String distributionManagementSection() {
320 return "<distributionManagement>" +
321 " <snapshotRepository>" +
322 " <id>internal</id>" +
323 " <url>file:///" + FileUtil.toSystemIndependentName(remoteRepoDir.getPath()) + "</url>" +
324 " </snapshotRepository>" +
325 "</distributionManagement>";