Exemplo n.º 1
0
  @Before
  public void setUp() throws Exception {
    startMonitoringJob();

    System.out.println("AdtProject: setup");
    System.out.println("Starting Test: " + testName.getMethodName());
    // Prevent preview icon computation during plugin test to make test
    // faster

    if (AndmoreAndroidPlugin.getDefault() == null) {
      fail("This test must be run as an Eclipse plugin test, not a plain JUnit test!");
    }

    AdtPrefs.getPrefs().setPaletteModes("ICON_TEXT"); // $NON-NLS-1$

    getProject();

    Sdk current = Sdk.getCurrent();
    assertNotNull(current);
    LoadStatus sdkStatus = AndmoreAndroidPlugin.getDefault().getSdkLoadStatus();
    assertSame(LoadStatus.LOADED, sdkStatus);
    IAndroidTarget target = current.getTarget(getProject());
    IJavaProject javaProject = BaseProjectHelper.getJavaProject(getProject());
    assertNotNull(javaProject);
    int iterations = 0;
    while (true) {
      if (iterations == 100) {
        fail("Couldn't load target; ran out of time");
      }
      LoadStatus status = current.checkAndLoadTargetData(target, javaProject);
      if (status == LoadStatus.FAILED) {
        fail("Couldn't load target " + target);
      }
      if (status != LoadStatus.LOADING) {
        break;
      }
      Thread.sleep(250);
      iterations++;
    }
    //		AndroidTargetData targetData = current.getTargetData(target);
    //		assertNotNull(targetData);
    //		LayoutDescriptors layoutDescriptors = targetData.getLayoutDescriptors();
    //		assertNotNull(layoutDescriptors);
    //		List<ViewElementDescriptor> viewDescriptors = layoutDescriptors.getViewDescriptors();
    //		assertNotNull(viewDescriptors);
    //		assertTrue(viewDescriptors.size() > 0);
    //		List<ViewElementDescriptor> layoutParamDescriptors =
    // layoutDescriptors.getLayoutDescriptors();
    //		assertNotNull(layoutParamDescriptors);
    //		assertTrue(layoutParamDescriptors.size() > 0);
  }
  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");
  }
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");
    }
  }