Пример #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 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");
    }
  }