コード例 #1
0
  @NotNull
  private static AbstractGradleDependency buildDependency(
      @NotNull GradleModule ownerModule,
      @NotNull IdeaSingleEntryLibraryDependency dependency,
      @NotNull GradleProject intellijProject)
      throws IllegalStateException {
    File binaryPath = dependency.getFile();
    if (binaryPath == null) {
      throw new IllegalStateException(
          String.format(
              "Can't parse external library dependency '%s'. Reason: it doesn't specify path to the binaries",
              dependency));
    }

    // Gradle API doesn't provide library name at the moment.
    GradleLibrary library = new GradleLibrary(FileUtil.getNameWithoutExtension(binaryPath));
    library.addPath(LibraryPathType.BINARY, binaryPath.getAbsolutePath());

    File sourcePath = dependency.getSource();
    if (sourcePath != null) {
      library.addPath(LibraryPathType.SOURCE, sourcePath.getAbsolutePath());
    }

    File javadocPath = dependency.getJavadoc();
    if (javadocPath != null) {
      library.addPath(LibraryPathType.DOC, javadocPath.getAbsolutePath());
    }

    if (!intellijProject.addLibrary(library)) {
      for (GradleLibrary registeredLibrary : intellijProject.getLibraries()) {
        if (registeredLibrary.equals(library)) {
          return new GradleLibraryDependency(ownerModule, registeredLibrary);
        }
      }
    }

    return new GradleLibraryDependency(ownerModule, library);
  }