@Test
  public void testSourceSetOutputDirsAsRuntimeDependencies() throws Exception {
    importProject(
        "apply plugin: 'java'\n"
            + "sourceSets.main.output.dir file(\"$buildDir/generated-resources/main\")");

    assertModules("project", "project_main", "project_test");
    final String path = pathFromBasedir("build/generated-resources/main");
    final String depName = PathUtil.toPresentableUrl(path);
    assertModuleLibDep("project_main", depName, "file://" + path);
    assertModuleLibDepScope("project_main", depName, DependencyScope.RUNTIME);
  }
  @Test
  public void testSourceSetOutputDirsAsRuntimeDependenciesOfDependantModules() throws Exception {
    createSettingsFile("include 'projectA', 'projectB', 'projectC' ");
    importProject(
        "project(':projectA') {\n"
            + "  apply plugin: 'java'\n"
            + "  sourceSets.main.output.dir file(\"$buildDir/generated-resources/main\")\n"
            + "}\n"
            + "project(':projectB') {\n"
            + "  apply plugin: 'java'\n"
            + "  dependencies {\n"
            + "    compile project(':projectA')\n"
            + "  }\n"
            + "}\n"
            + "project(':projectC') {\n"
            + "  apply plugin: 'java'\n"
            + "  dependencies {\n"
            + "    runtime project(':projectB')\n"
            + "  }\n"
            + "}");

    assertModules(
        "project",
        "projectA",
        "projectA_main",
        "projectA_test",
        "projectB",
        "projectB_main",
        "projectB_test",
        "projectC",
        "projectC_main",
        "projectC_test");

    assertModuleModuleDepScope("projectB_main", "projectA_main", DependencyScope.COMPILE);
    assertModuleModuleDepScope("projectC_main", "projectA_main", DependencyScope.RUNTIME);
    assertModuleModuleDepScope("projectC_main", "projectB_main", DependencyScope.RUNTIME);

    final String path = pathFromBasedir("projectA/build/generated-resources/main");
    final String classesPath = "file://" + path;
    final String depName = PathUtil.toPresentableUrl(path);
    assertModuleLibDep("projectA_main", depName, classesPath);
    assertModuleLibDepScope("projectA_main", depName, DependencyScope.RUNTIME);
    assertModuleLibDep("projectB_main", depName, classesPath);
    assertModuleLibDepScope("projectB_main", depName, DependencyScope.COMPILE);
    assertModuleLibDep("projectC_main", depName, classesPath);
    assertModuleLibDepScope("projectC_main", depName, DependencyScope.RUNTIME);
  }
  @TestOnly
  private static void assertAccessInTests(
      @NotNull VirtualFileSystemEntry child, @NotNull NewVirtualFileSystem delegate) {
    final Application application = ApplicationManager.getApplication();
    if (IS_UNDER_TEAMCITY
        && SHOULD_PERFORM_ACCESS_CHECK
        && application.isUnitTestMode()
        && application instanceof ApplicationImpl
        && ((ApplicationImpl) application).isComponentsCreated()) {
      if (delegate != LocalFileSystem.getInstance() && delegate != JarFileSystem.getInstance()) {
        return;
      }
      // root' children are loaded always
      if (child.getParent() == null || child.getParent().getParent() == null) return;

      Set<String> allowed = allowedRoots();
      boolean isUnder = allowed == null;
      if (!isUnder) {
        String childPath = child.getPath();
        if (delegate == JarFileSystem.getInstance()) {
          VirtualFile local = JarFileSystem.getInstance().getVirtualFileForJar(child);
          assert local != null : child;
          childPath = local.getPath();
        }
        for (String root : allowed) {
          if (FileUtil.startsWith(childPath, root)) {
            isUnder = true;
            break;
          }
          if (root.startsWith(JarFileSystem.PROTOCOL_PREFIX)) {
            String rootLocalPath =
                FileUtil.toSystemIndependentName(PathUtil.toPresentableUrl(root));
            isUnder = FileUtil.startsWith(childPath, rootLocalPath);
            if (isUnder) break;
          }
        }
      }

      assert isUnder || allowed.isEmpty()
          : "File accessed outside allowed roots: "
              + child
              + ";\nAllowed roots: "
              + new ArrayList<String>(allowed);
    }
  }
  @Test
  public void testDependencyWithDifferentClassifiers() throws Exception {
    final VirtualFile depJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0.jar");
    final VirtualFile depTestsJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0-tests.jar");
    final VirtualFile depNonJar = createProjectSubFile("lib/dep/dep/1.0/dep-1.0.someExt");

    importProject(
        "allprojects {\n"
            + "  apply plugin: 'java'\n"
            + "  sourceCompatibility = 1.5\n"
            + "  version = '1.0'\n"
            + "\n"
            + "  repositories {\n"
            + "    maven{ url file('lib') }\n"
            + "  }\n"
            + "}\n"
            + "\n"
            + "dependencies {\n"
            + "  compile 'dep:dep:1.0'\n"
            + "  testCompile 'dep:dep:1.0:tests'\n"
            + "  runtime 'dep:dep:1.0@someExt'\n"
            + "}");

    assertModules("project", "project_main", "project_test");

    assertModuleModuleDepScope("project_test", "project_main", DependencyScope.COMPILE);

    final String depName = "Gradle: dep:dep:1.0";
    assertModuleLibDep("project_main", depName, depJar.getUrl());
    assertModuleLibDepScope("project_main", depName, DependencyScope.COMPILE);
    assertModuleLibDep("project_test", depName, depJar.getUrl());
    assertModuleLibDepScope("project_test", depName, DependencyScope.COMPILE);

    final boolean isArtifactResolutionQuerySupported =
        GradleVersion.version(gradleVersion).compareTo(GradleVersion.version("2.0")) >= 0;
    final String depTestsName =
        isArtifactResolutionQuerySupported
            ? "Gradle: dep:dep:tests:1.0"
            : PathUtil.toPresentableUrl(depTestsJar.getUrl());
    assertModuleLibDep("project_test", depTestsName, depTestsJar.getUrl());
    assertModuleLibDepScope("project_test", depTestsName, DependencyScope.COMPILE);

    final String depNonJarName =
        isArtifactResolutionQuerySupported
            ? "Gradle: dep:dep:someExt:1.0"
            : PathUtil.toPresentableUrl(depNonJar.getUrl());
    assertModuleLibDep("project_main", depNonJarName, depNonJar.getUrl());
    assertModuleLibDepScope("project_main", depNonJarName, DependencyScope.RUNTIME);
    assertModuleLibDep("project_test", depNonJarName, depNonJar.getUrl());
    assertModuleLibDepScope("project_test", depNonJarName, DependencyScope.RUNTIME);

    importProjectUsingSingeModulePerGradleProject();
    assertModules("project");

    assertModuleLibDep("project", depName, depJar.getUrl());
    assertModuleLibDepScope("project", depName, DependencyScope.COMPILE);

    assertModuleLibDep("project", "Gradle: dep:dep:1.0:tests", depTestsJar.getUrl());
    assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:tests", DependencyScope.TEST);

    assertModuleLibDep("project", "Gradle: dep:dep:1.0:someExt", depNonJar.getUrl());
    assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:someExt", DependencyScope.RUNTIME);
  }
 @NotNull
 public static IFile virtualToIFile(@NotNull VirtualFile file) {
   return FileSystem.FILE_SYSTEM.createFile(PathUtil.toPresentableUrl(file.getUrl()));
 }
예제 #6
0
 @NotNull
 public static File virtualToIoFile(@NotNull VirtualFile file) {
   return new File(PathUtil.toPresentableUrl(file.getUrl()));
 }