Ejemplo n.º 1
0
 @Override
 public String getPath(int pathId) {
   String path = myAlternativePaths.get(pathId);
   if (path != null) {
     return path;
   }
   return myWrapee.getPath(pathId);
 }
  @Override
  public void execute() throws BuildException {
    Project antProject = getProject();

    // get the SDK location
    String sdkLocation = antProject.getProperty(ProjectProperties.PROPERTY_SDK);

    // check if it's valid and exists
    if (sdkLocation == null || sdkLocation.length() == 0) {
      throw new BuildException("SDK Location is not set.");
    }

    File sdk = new File(sdkLocation);
    if (sdk.isDirectory() == false) {
      throw new BuildException(String.format("SDK Location '%s' is not valid.", sdkLocation));
    }

    // get the target property value
    String targetHashString = antProject.getProperty(ProjectProperties.PROPERTY_TARGET);
    if (targetHashString == null) {
      throw new BuildException("Android Target is not set.");
    }

    // load up the sdk targets.
    final ArrayList<String> messages = new ArrayList<String>();
    SdkManager manager =
        SdkManager.createManager(
            sdkLocation,
            new ISdkLog() {
              public void error(Throwable t, String errorFormat, Object... args) {
                if (errorFormat != null) {
                  messages.add(String.format("Error: " + errorFormat, args));
                }
                if (t != null) {
                  messages.add("Error: " + t.getMessage());
                }
              }

              public void printf(String msgFormat, Object... args) {
                messages.add(String.format(msgFormat, args));
              }

              public void warning(String warningFormat, Object... args) {
                messages.add(String.format("Warning: " + warningFormat, args));
              }
            });

    if (manager == null) {
      // since we failed to parse the SDK, lets display the parsing output.
      for (String msg : messages) {
        System.out.println(msg);
      }
      throw new BuildException("Failed to parse SDK content.");
    }

    // resolve it
    IAndroidTarget androidTarget = manager.getTargetFromHashString(targetHashString);

    if (androidTarget == null) {
      throw new BuildException(String.format("Unable to resolve target '%s'", targetHashString));
    }

    // display it
    System.out.println("Project Target: " + androidTarget.getName());
    if (androidTarget.isPlatform() == false) {
      System.out.println("Vendor: " + androidTarget.getVendor());
    }
    System.out.println("Platform Version: " + androidTarget.getApiVersionName());
    System.out.println("API level: " + androidTarget.getApiVersionNumber());

    // sets up the properties to find android.jar/framework.aidl
    String androidJar = androidTarget.getPath(IAndroidTarget.ANDROID_JAR);
    String androidAidl = androidTarget.getPath(IAndroidTarget.ANDROID_AIDL);
    antProject.setProperty(PROPERTY_ANDROID_JAR, androidJar);
    antProject.setProperty(PROPERTY_ANDROID_AIDL, androidAidl);

    // sets up the boot classpath

    // create the Path object
    Path bootclasspath = new Path(antProject);

    // create a PathElement for the framework jar
    PathElement element = bootclasspath.createPathElement();
    element.setPath(androidJar);

    // create PathElement for each optional library.
    IOptionalLibrary[] libraries = androidTarget.getOptionalLibraries();
    if (libraries != null) {
      HashSet<String> visitedJars = new HashSet<String>();
      for (IOptionalLibrary library : libraries) {
        String jarPath = library.getJarPath();
        if (visitedJars.contains(jarPath) == false) {
          visitedJars.add(jarPath);

          element = bootclasspath.createPathElement();
          element.setPath(library.getJarPath());
        }
      }
    }

    // finally sets the path in the project with a reference
    antProject.addReference(REF_CLASSPATH, bootclasspath);

    // find the file to import, and import it.
    String templateFolder = androidTarget.getPath(IAndroidTarget.TEMPLATES);

    // make sure the file exists.
    File templates = new File(templateFolder);
    if (templates.isDirectory() == false) {
      throw new BuildException(
          String.format("Template directory '%s' is missing.", templateFolder));
    }

    // now check the rules file exists.
    File rules = new File(templateFolder, ANDROID_RULES);
    if (rules.isFile() == false) {
      throw new BuildException(String.format("Build rules file '%s' is missing.", templateFolder));
    }

    // set the file location to import
    setFile(rules.getAbsolutePath());

    // and import it
    super.execute();
  }
Ejemplo n.º 3
0
 private boolean canFindTool(int pathId) {
   String path = myWrapee.getPath(pathId);
   return path != null && new File(path).exists();
 }
  private boolean loadLibrary(@NotNull IAndroidTarget target)
      throws RenderingException, IOException {
    final String layoutLibJarPath = target.getPath(IAndroidTarget.LAYOUT_LIB);
    final VirtualFile layoutLibJar = LocalFileSystem.getInstance().findFileByPath(layoutLibJarPath);
    if (layoutLibJar == null || layoutLibJar.isDirectory()) {
      throw new RenderingException(
          AndroidBundle.message(
              "android.file.not.exist.error", FileUtil.toSystemDependentName(layoutLibJarPath)));
    }

    final String resFolderPath = target.getPath(IAndroidTarget.RESOURCES);
    final VirtualFile resFolder = LocalFileSystem.getInstance().findFileByPath(resFolderPath);
    if (resFolder == null || !resFolder.isDirectory()) {
      throw new RenderingException(
          AndroidBundle.message(
              "android.directory.cannot.be.found.error",
              FileUtil.toSystemDependentName(resFolderPath)));
    }

    final String fontFolderPath = target.getPath(IAndroidTarget.FONTS);
    final VirtualFile fontFolder = LocalFileSystem.getInstance().findFileByPath(fontFolderPath);
    if (fontFolder == null || !fontFolder.isDirectory()) {
      throw new RenderingException(
          AndroidBundle.message(
              "android.directory.cannot.be.found.error",
              FileUtil.toSystemDependentName(fontFolderPath)));
    }

    final String platformFolderPath =
        target.isPlatform() ? target.getLocation() : target.getParent().getLocation();
    final File platformFolder = new File(platformFolderPath);
    if (!platformFolder.isDirectory()) {
      throw new RenderingException(
          AndroidBundle.message(
              "android.directory.cannot.be.found.error",
              FileUtil.toSystemDependentName(platformFolderPath)));
    }

    final File buildProp = new File(platformFolder, SdkConstants.FN_BUILD_PROP);
    if (!buildProp.isFile()) {
      throw new RenderingException(
          AndroidBundle.message(
              "android.file.not.exist.error", FileUtil.toSystemDependentName(buildProp.getPath())));
    }

    final SimpleLogger logger = new SimpleLogger(LOG);

    myLibrary =
        LayoutLibrary.load(
            layoutLibJar.getPath(),
            logger,
            ApplicationNamesInfo.getInstance().getFullProductName());
    if (myLibrary.getStatus() != LoadStatus.LOADED) {
      throw new RenderingException(myLibrary.getLoadMessage());
    }

    myResources = loadPlatformResources(new File(resFolder.getPath()), logger);

    final Map<String, String> buildPropMap =
        ProjectProperties.parsePropertyFile(new BufferingFileWrapper(buildProp), logger);
    return myLibrary.init(buildPropMap, new File(fontFolder.getPath()), myEnumMap, logger);
  }