/**
  * Returns the file's sha1, computing it if necessary.
  *
  * @return the sha1
  * @throws Sha1Exception
  */
 private String getSha1() throws Sha1Exception {
   if (mSha1 == null) {
     mSha1 = JarListSanitizer.getSha1(mFile);
   }
   return mSha1;
 }
  private static List<IClasspathEntry> convertJarsToClasspathEntries(
      final IProject iProject, Set<File> jarFiles) {
    List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>(jarFiles.size());

    // and process the jar files list, but first sanitize it to remove dups.
    JarListSanitizer sanitizer =
        new JarListSanitizer(
            iProject.getFolder(SdkConstants.FD_OUTPUT).getLocation().toFile(),
            new AndroidPrintStream(iProject, null /*prefix*/, AndmoreAndroidPlugin.getOutStream()));

    String errorMessage = null;

    try {
      List<File> sanitizedList = sanitizer.sanitize(jarFiles);

      for (File jarFile : sanitizedList) {
        if (jarFile instanceof CPEFile) {
          CPEFile cpeFile = (CPEFile) jarFile;
          IClasspathEntry e = cpeFile.getClasspathEntry();

          entries.add(
              JavaCore.newLibraryEntry(
                  e.getPath(),
                  e.getSourceAttachmentPath(),
                  e.getSourceAttachmentRootPath(),
                  e.getAccessRules(),
                  e.getExtraAttributes(),
                  true /*isExported*/));
        } else {
          String jarPath = jarFile.getAbsolutePath();

          IPath sourceAttachmentPath = null;
          IClasspathAttribute javaDocAttribute = null;

          File jarProperties = new File(jarPath + DOT_PROPERTIES);
          if (jarProperties.isFile()) {
            Properties p = new Properties();
            InputStream is = null;
            try {
              p.load(is = new FileInputStream(jarProperties));

              String value = p.getProperty(ATTR_SRC);
              if (value != null) {
                File srcPath = getFile(jarFile, value);

                if (srcPath.exists()) {
                  sourceAttachmentPath = new Path(srcPath.getAbsolutePath());
                }
              }

              value = p.getProperty(ATTR_DOC);
              if (value != null) {
                File docPath = getFile(jarFile, value);
                if (docPath.exists()) {
                  try {
                    javaDocAttribute =
                        JavaCore.newClasspathAttribute(
                            IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                            docPath.toURI().toURL().toString());
                  } catch (MalformedURLException e) {
                    AndmoreAndroidPlugin.log(
                        e,
                        "Failed to process 'doc' attribute for %s",
                        jarProperties.getAbsolutePath());
                  }
                }
              }

            } catch (FileNotFoundException e) {
              // shouldn't happen since we check upfront
            } catch (IOException e) {
              AndmoreAndroidPlugin.log(e, "Failed to read %s", jarProperties.getAbsolutePath());
            } finally {
              if (is != null) {
                try {
                  is.close();
                } catch (IOException e) {
                  // ignore
                }
              }
            }
          }

          if (javaDocAttribute != null) {
            entries.add(
                JavaCore.newLibraryEntry(
                    new Path(jarPath),
                    sourceAttachmentPath,
                    null /*sourceAttachmentRootPath*/,
                    new IAccessRule[0],
                    new IClasspathAttribute[] {javaDocAttribute},
                    true /*isExported*/));
          } else {
            entries.add(
                JavaCore.newLibraryEntry(
                    new Path(jarPath),
                    sourceAttachmentPath,
                    null /*sourceAttachmentRootPath*/,
                    true /*isExported*/));
          }
        }
      }
    } catch (DifferentLibException e) {
      errorMessage = e.getMessage();
      AndmoreAndroidPlugin.printErrorToConsole(iProject, (Object[]) e.getDetails());
    } catch (Sha1Exception e) {
      errorMessage = e.getMessage();
    }

    processError(
        iProject,
        errorMessage,
        AndmoreAndroidConstants.MARKER_DEPENDENCY,
        true /*outputToConsole*/);

    return entries;
  }