private static IClasspathContainer allocateLibraryContainer(IJavaProject javaProject) {
    final IProject iProject = javaProject.getProject();

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

    /*
     * At this point we're going to gather a list of all that need to go in the
     * dependency container.
     * - Library project outputs (direct and indirect)
     * - Java project output (those can be indirectly referenced through library projects
     *   or other other Java projects)
     * - Jar files:
     *    + inside this project's libs/
     *    + inside the library projects' libs/
     *    + inside the referenced Java projects' classpath
     */
    List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();

    // list of java project dependencies and jar files that will be built while
    // going through the library projects.
    Set<File> jarFiles = new HashSet<File>();
    Set<IProject> refProjects = new HashSet<IProject>();

    // process all the libraries

    List<IProject> libProjects = state.getFullLibraryProjects();
    for (IProject libProject : libProjects) {
      // process all of the library project's dependencies
      getDependencyListFromClasspath(libProject, refProjects, jarFiles, true);
    }

    // now process this projects' referenced projects only.
    processReferencedProjects(iProject, refProjects, jarFiles);

    // and the content of its libs folder
    getJarListFromLibsFolder(iProject, jarFiles);

    // now add a classpath entry for each Java project (this is a set so dups are already
    // removed)
    for (IProject p : refProjects) {
      entries.add(JavaCore.newProjectEntry(p.getFullPath(), true /*isExported*/));
    }

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

    return allocateContainer(
        javaProject,
        entries,
        new Path(AndmoreAndroidConstants.CONTAINER_PRIVATE_LIBRARIES),
        "Android Private Libraries");
  }
  /**
   * Updates the {@link IJavaProject} objects with new library.
   *
   * @param androidProjects the projects to update.
   * @return <code>true</code> if success, <code>false</code> otherwise.
   */
  public static boolean updateProject(List<ProjectState> projects) {
    List<IJavaProject> javaProjectList = new ArrayList<IJavaProject>(projects.size());
    for (ProjectState p : projects) {
      IJavaProject javaProject = JavaCore.create(p.getProject());
      if (javaProject != null) {
        javaProjectList.add(javaProject);
      }
    }

    IJavaProject[] javaProjects = javaProjectList.toArray(new IJavaProject[javaProjectList.size()]);

    return updateProjects(javaProjects);
  }
Exemplo n.º 3
0
  @Override
  public void launch(ISelection selection, String mode) {
    if (!(selection instanceof IStructuredSelection)) {
      return;
    }

    Object s = ((IStructuredSelection) selection).getFirstElement();
    if (!(s instanceof IAdaptable)) {
      return;
    }

    IResource r = (IResource) ((IAdaptable) s).getAdapter(IResource.class);
    if (r == null) {
      return;
    }

    IProject project = r.getProject();
    if (project == null) {
      return;
    }

    // verify that this is a non library Android project
    ProjectState state = Sdk.getProjectState(project);
    if (state == null || state.isLibrary()) {
      return;
    }

    // verify that this project has C/C++ nature
    if (!CoreModel.hasCCNature(project) && !CoreModel.hasCNature(project)) {
      AndmoreAndroidPlugin.printErrorToConsole(
          project,
          String.format(
              "Selected project (%s) does not have C/C++ nature. "
                  + "To add native support, right click on the project, "
                  + "Android Tools -> Add Native Support",
              project.getName()));
      return;
    }

    debugProject(project, mode);
  }
  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");
    }
  }