mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Maven: classpath test improved
This commit is contained in:
+164
-130
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.idea.maven.execution;
|
||||
|
||||
import com.intellij.execution.CantRunException;
|
||||
import com.intellij.execution.configurations.JavaParameters;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -23,12 +22,14 @@ import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.roots.CompilerModuleExtension;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderEnumerator;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.util.PathsList;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.MavenImportingTestCase;
|
||||
|
||||
@@ -38,6 +39,10 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
private enum Type {PRODUCTION, TESTS}
|
||||
|
||||
private enum Scope {COMPILE, RUNTIME}
|
||||
|
||||
public void testConfiguringModuleDependencies() throws Exception {
|
||||
VirtualFile m1 = createModulePom("m1", "<groupId>test</groupId>" +
|
||||
"<artifactId>m1</artifactId>" +
|
||||
@@ -85,17 +90,17 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2", "m3", "m4");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getProjectPath() + "/m3/target/classes");
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getProjectPath() + "/m3/target/classes");
|
||||
|
||||
assertModuleClasspath("m2",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getProjectPath() + "/m3/target/classes",
|
||||
getProjectPath() + "/m4/target/classes");
|
||||
assertAllTestsClasspath("m2",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getProjectPath() + "/m3/target/classes",
|
||||
getProjectPath() + "/m4/target/classes");
|
||||
}
|
||||
|
||||
public void testDoNotIncludeTestClassesWhenConfiguringModuleDependenciesForProductionCode() throws Exception {
|
||||
@@ -121,14 +126,12 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_ONLY,
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
assertAllProductionClasspath("m1",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
|
||||
assertModuleClasspath("m2",
|
||||
JavaParameters.CLASSES_ONLY,
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
assertAllProductionClasspath("m2",
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
}
|
||||
|
||||
public void testConfiguringModuleDependenciesOnTestJar() throws Exception {
|
||||
@@ -163,17 +166,16 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2", "m3");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m3/target/test-classes");
|
||||
assertAllProductionClasspath("m1",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m3/target/test-classes");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_ONLY,
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m3/target/test-classes");
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m3/target/test-classes");
|
||||
}
|
||||
|
||||
public void testConfiguringModuleDependenciesOnTestJarWithTestScope() throws Exception {
|
||||
@@ -210,15 +212,14 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2", "m3");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m3/target/test-classes");
|
||||
assertAllProductionClasspath("m1",
|
||||
getProjectPath() + "/m1/target/classes");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_ONLY,
|
||||
getProjectPath() + "/m1/target/classes");
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m3/target/test-classes");
|
||||
}
|
||||
|
||||
public void testConfiguringModuleDependenciesOnTestJarWithTestScopeAndRegularDependency() throws Exception {
|
||||
@@ -250,16 +251,15 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes");
|
||||
assertAllProductionClasspath("m1",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_ONLY,
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes");
|
||||
}
|
||||
|
||||
public void testConfiguringModuleDependenciesOnBothNormalAndTestJar() throws Exception {
|
||||
@@ -290,17 +290,16 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2", "m2");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes");
|
||||
assertAllProductionClasspath("m1",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_ONLY,
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes");
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes");
|
||||
}
|
||||
|
||||
public void testOptionalLibraryDependencies() throws Exception {
|
||||
@@ -344,17 +343,17 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/jmock/jmock/1.0/jmock-1.0.jar");
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/jmock/jmock/1.0/jmock-1.0.jar");
|
||||
|
||||
assertModuleClasspath("m2",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/jmock/jmock/1.0/jmock-1.0.jar",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
assertAllTestsClasspath("m2",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/jmock/jmock/1.0/jmock-1.0.jar",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
}
|
||||
|
||||
public void testDoNotChangeClasspathForRegularModules() throws Exception {
|
||||
@@ -409,20 +408,20 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2", "user");
|
||||
|
||||
assertModuleClasspath("user",
|
||||
getProjectPath() + "/user/test-output",
|
||||
getProjectPath() + "/user/output",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
assertAllTestsClasspath("user",
|
||||
getProjectPath() + "/user/test-output",
|
||||
getProjectPath() + "/user/output",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
}
|
||||
|
||||
public void testDoNotIncludeProvidedAndTestDependenciesInProductionClasspath() throws Exception {
|
||||
@@ -472,20 +471,24 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2", "m3");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_ONLY,
|
||||
getProjectPath() + "/m1/target/classes");
|
||||
assertCompileProductionClasspath("m1",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
assertRuntimeProductionClasspath("m1",
|
||||
getProjectPath() + "/m1/target/classes");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_AND_TESTS,
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar",
|
||||
getProjectPath() + "/m3/target/classes",
|
||||
getRepositoryPath() + "/jmock/jmock/4.0/jmock-4.0.jar");
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar",
|
||||
getProjectPath() + "/m3/target/classes",
|
||||
getRepositoryPath() + "/jmock/jmock/4.0/jmock-4.0.jar");
|
||||
}
|
||||
|
||||
// todo next
|
||||
|
||||
public void testDoNotIncludeProvidedAndTestTransitiveDependencies() throws Exception {
|
||||
createRepositoryFile("jmock/jmock/1.0/jmock-1.0.jar");
|
||||
VirtualFile m1 = createModulePom("m1", "<groupId>test</groupId>" +
|
||||
@@ -528,27 +531,27 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_ONLY,
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
assertAllProductionClasspath("m1",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
|
||||
assertModuleClasspath("m2",
|
||||
JavaParameters.CLASSES_ONLY,
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_AND_TESTS,
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
|
||||
assertModuleClasspath("m2",
|
||||
JavaParameters.CLASSES_AND_TESTS,
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/jmock/jmock/1.0/jmock-1.0.jar",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
assertCompileProductionClasspath("m2",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/jmock/jmock/1.0/jmock-1.0.jar");
|
||||
assertRuntimeProductionClasspath("m2",
|
||||
getProjectPath() + "/m2/target/classes");
|
||||
|
||||
assertRuntimeTestsClasspath("m2",
|
||||
getProjectPath() + "/m2/target/test-classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/jmock/jmock/1.0/jmock-1.0.jar",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
}
|
||||
|
||||
public void testDoNotIncludeConflictingTransitiveDependenciesInTheClasspath() throws Exception {
|
||||
@@ -580,6 +583,7 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
" <version>4.0</version>" +
|
||||
" </dependency>" +
|
||||
"</dependencies>");
|
||||
|
||||
VirtualFile m3 = createModulePom("m3", "<groupId>test</groupId>" +
|
||||
"<artifactId>m3</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
@@ -600,12 +604,12 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1", "m2", "m3");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar",
|
||||
getProjectPath() + "/m3/target/classes");
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getProjectPath() + "/m2/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar",
|
||||
getProjectPath() + "/m3/target/classes");
|
||||
}
|
||||
|
||||
public void testAdditionalClasspathElementsInTests() throws Exception {
|
||||
@@ -652,33 +656,63 @@ public class MavenClasspathConfigurationTest extends MavenImportingTestCase {
|
||||
|
||||
setupJdkForModules("m1");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_ONLY,
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
assertAllProductionClasspath("m1",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar");
|
||||
|
||||
assertModuleClasspath("m1",
|
||||
JavaParameters.CLASSES_AND_TESTS,
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar",
|
||||
f1.getPath(),
|
||||
f2.getPath());
|
||||
assertAllTestsClasspath("m1",
|
||||
getProjectPath() + "/m1/target/test-classes",
|
||||
getProjectPath() + "/m1/target/classes",
|
||||
getRepositoryPath() + "/junit/junit/4.0/junit-4.0.jar",
|
||||
f1.getPath(),
|
||||
f2.getPath());
|
||||
}
|
||||
|
||||
private void assertModuleClasspath(String moduleName, String... paths) throws CantRunException {
|
||||
assertModuleClasspath(moduleName, JavaParameters.CLASSES_AND_TESTS, paths);
|
||||
private void assertAllProductionClasspath(String moduleName, String... paths) throws Exception {
|
||||
assertClasspath(moduleName, Scope.COMPILE, Type.PRODUCTION, paths);
|
||||
assertClasspath(moduleName, Scope.RUNTIME, Type.PRODUCTION, paths);
|
||||
}
|
||||
|
||||
private void assertModuleClasspath(String moduleName, int classpathType, String... paths) throws CantRunException {
|
||||
private void assertAllTestsClasspath(String moduleName, String... paths) throws Exception {
|
||||
assertClasspath(moduleName, Scope.COMPILE, Type.TESTS, paths);
|
||||
assertClasspath(moduleName, Scope.RUNTIME, Type.TESTS, paths);
|
||||
}
|
||||
|
||||
private void assertCompileProductionClasspath(String moduleName, String... paths) throws Exception {
|
||||
assertClasspath(moduleName, Scope.COMPILE, Type.PRODUCTION, paths);
|
||||
}
|
||||
|
||||
private void assertCompileTestsClasspath(String moduleName, String... paths) throws Exception {
|
||||
assertClasspath(moduleName, Scope.COMPILE, Type.TESTS, paths);
|
||||
}
|
||||
|
||||
private void assertRuntimeProductionClasspath(String moduleName, String... paths) throws Exception {
|
||||
assertClasspath(moduleName, Scope.RUNTIME, Type.PRODUCTION, paths);
|
||||
}
|
||||
|
||||
private void assertRuntimeTestsClasspath(String moduleName, String... paths) throws Exception {
|
||||
assertClasspath(moduleName, Scope.RUNTIME, Type.TESTS, paths);
|
||||
}
|
||||
|
||||
private void assertClasspath(String moduleName, Scope scope, Type type, String... paths) throws Exception {
|
||||
createOutputDirectories();
|
||||
JavaParameters params = new JavaParameters();
|
||||
params.configureByModule(getModule(moduleName), classpathType);
|
||||
PathsList actualPaths;
|
||||
if (scope == Scope.RUNTIME) {
|
||||
JavaParameters params = new JavaParameters();
|
||||
params.configureByModule(getModule(moduleName), type == Type.TESTS ? JavaParameters.CLASSES_AND_TESTS : JavaParameters.CLASSES_ONLY);
|
||||
actualPaths = params.getClassPath();
|
||||
}
|
||||
else {
|
||||
OrderEnumerator en = OrderEnumerator.orderEntries(getModule(moduleName)).recursively().withoutSdk().compileOnly();
|
||||
if (type == Type.PRODUCTION) en.productionOnly();
|
||||
actualPaths = en.classes().getPathsList();
|
||||
}
|
||||
|
||||
List<String> systemPaths = new ArrayList<String>();
|
||||
for (String each : paths) {
|
||||
systemPaths.add(FileUtil.toSystemDependentName(each));
|
||||
}
|
||||
assertOrderedElementsAreEqual(params.getClassPath().getPathList(), systemPaths);
|
||||
assertOrderedElementsAreEqual(actualPaths.getPathList(), systemPaths);
|
||||
}
|
||||
|
||||
private void createRepositoryFile(String filePath) throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user