/**
  * Returns the lastest build tools that's at least the passed version.
  *
  * @param fullRevision the minimum required build tools version.
  * @return the latest build tools.
  * @throws RuntimeException if the latest build tools is older than fullRevision.
  */
 static File getAapt(FullRevision fullRevision) {
   ILogger logger = new StdLogger(StdLogger.Level.VERBOSE);
   SdkManager sdkManager = SdkManager.createManager(getSdkDir().getAbsolutePath(), logger);
   assert sdkManager != null;
   BuildToolInfo buildToolInfo = sdkManager.getLatestBuildTool();
   if (buildToolInfo == null || buildToolInfo.getRevision().compareTo(fullRevision) < 0) {
     throw new RuntimeException("Test requires build-tools " + fullRevision.toShortString());
   }
   return new File(buildToolInfo.getPath(BuildToolInfo.PathId.AAPT));
 }
  private static IClasspathContainer allocateDependencyContainer(IJavaProject javaProject) {
    final IProject iProject = javaProject.getProject();
    final List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
    final Set<File> jarFiles = new HashSet<File>();
    final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

    AndmoreAndroidPlugin plugin = AndmoreAndroidPlugin.getDefault();
    if (plugin == null) { // This is totally weird, but I've seen it happen!
      return null;
    }

    synchronized (Sdk.getLock()) {
      boolean sdkIsLoaded = plugin.getSdkLoadStatus() == LoadStatus.LOADED;

      // check if the project has a valid target.
      final ProjectState state = Sdk.getProjectState(iProject);
      if (state == null) {
        // getProjectState should already have logged an error. Just bail out.
        return null;
      }

      // annotations support for older version of android
      if (state.getTarget() != null && state.getTarget().getVersion().getApiLevel() <= 15) {
        File annotationsJar =
            new File(
                Sdk.getCurrent().getSdkOsLocation(),
                SdkConstants.FD_TOOLS
                    + File.separator
                    + SdkConstants.FD_SUPPORT
                    + File.separator
                    + SdkConstants.FN_ANNOTATIONS_JAR);

        jarFiles.add(annotationsJar);
      }

      if (state.getRenderScriptSupportMode()) {
        if (!sdkIsLoaded) {
          return null;
        }
        BuildToolInfo buildToolInfo = state.getBuildToolInfo();
        if (buildToolInfo == null) {
          buildToolInfo = Sdk.getCurrent().getLatestBuildTool();

          if (buildToolInfo == null) {
            return null;
          }
        }

        File renderScriptSupportJar =
            RenderScriptProcessor.getSupportJar(buildToolInfo.getLocation().getAbsolutePath());

        jarFiles.add(renderScriptSupportJar);
      }

      // process all the libraries

      List<IProject> libProjects = state.getFullLibraryProjects();
      for (IProject libProject : libProjects) {
        // get the project output
        IFolder outputFolder = BaseProjectHelper.getAndroidOutputFolder(libProject);

        if (outputFolder != null) { // can happen when closing/deleting a library)
          IFile jarIFile =
              outputFolder.getFile(libProject.getName().toLowerCase() + SdkConstants.DOT_JAR);

          // get the source folder for the library project
          List<IPath> srcs = BaseProjectHelper.getSourceClasspaths(libProject);
          // find the first non-derived source folder.
          IPath sourceFolder = null;
          for (IPath src : srcs) {
            IFolder srcFolder = workspaceRoot.getFolder(src);
            if (srcFolder.isDerived() == false) {
              sourceFolder = src;
              break;
            }
          }

          // we can directly add a CPE for this jar as there's no risk of a duplicate.
          IClasspathEntry entry =
              JavaCore.newLibraryEntry(
                  jarIFile.getLocation(),
                  sourceFolder, // source attachment path
                  null, // default source attachment root path.
                  true /*isExported*/);

          entries.add(entry);
        }
      }

      entries.addAll(convertJarsToClasspathEntries(iProject, jarFiles));

      return allocateContainer(
          javaProject, entries, new Path(CONTAINER_DEPENDENCIES), "Android Dependencies");
    }
  }