Example #1
0
File: Main.java Project: MIPS/sdk
  /**
   * Updates an existing Android project based on command-line parameters
   *
   * @param library whether the project is a library project.
   */
  private void updateProject(boolean library) {
    // get the target and try to resolve it.
    IAndroidTarget target = null;
    String targetStr = mSdkCommandLine.getParamTargetId();
    // For "update project" the target parameter is optional so having null is acceptable.
    // However if there's a value, it must be valid.
    if (targetStr != null) {
      IAndroidTarget[] targets = mSdkManager.getTargets();
      int targetId = resolveTargetName(targetStr);
      if (targetId == INVALID_TARGET_ID || targetId > targets.length) {
        errorAndExit(
            "Target id '%1$s' is not valid. Use '%2$s list targets' to get the target ids.",
            targetStr, SdkConstants.androidCmdName());
      }
      target = targets[targetId - 1]; // target id is 1-based
    }

    ProjectCreator creator = getProjectCreator();

    String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());

    String libraryPath =
        library ? null : mSdkCommandLine.getParamProjectLibrary(SdkCommandLine.OBJECT_PROJECT);

    creator.updateProject(projectDir, target, mSdkCommandLine.getParamName(), libraryPath);

    if (library == false) {
      boolean doSubProjects = mSdkCommandLine.getParamSubProject();
      boolean couldHaveDone = false;

      // If there are any sub-folders with a manifest, try to update them as projects
      // too. This will take care of updating any underlying test project even if the
      // user changed the folder name.
      File[] files = new File(projectDir).listFiles();
      if (files != null) {
        for (File dir : files) {
          if (dir.isDirectory() && new File(dir, SdkConstants.FN_ANDROID_MANIFEST_XML).isFile()) {
            if (doSubProjects) {
              creator.updateProject(
                  dir.getPath(), target, mSdkCommandLine.getParamName(), null /*libraryPath*/);
            } else {
              couldHaveDone = true;
            }
          }
        }
      }

      if (couldHaveDone) {
        mSdkLog.printf(
            "It seems that there are sub-projects. If you want to update them\nplease use the --%1$s parameter.\n",
            SdkCommandLine.KEY_SUBPROJECTS);
      }
    }
  }
Example #2
0
File: Main.java Project: MIPS/sdk
  /**
   * Init the application by making sure the SDK path is available and doing basic parsing of the
   * SDK.
   */
  private void init() {
    mSdkCommandLine = new SdkCommandLine(mSdkLog);

    // We get passed a property for the tools dir
    String toolsDirProp = System.getProperty(TOOLSDIR);
    if (toolsDirProp == null) {
      // for debugging, it's easier to override using the process environment
      toolsDirProp = System.getenv(TOOLSDIR);
    }

    if (toolsDirProp != null) {
      // got back a level for the SDK folder
      File tools;
      if (toolsDirProp.length() > 0) {
        tools = new File(toolsDirProp);
        mOsSdkFolder = tools.getParent();
      } else {
        try {
          tools = new File(".").getCanonicalFile();
          mOsSdkFolder = tools.getParent();
        } catch (IOException e) {
          // Will print an error below since mSdkFolder is not defined
        }
      }
    }

    if (mOsSdkFolder == null) {
      errorAndExit(
          "The tools directory property is not set, please make sure you are executing %1$s",
          SdkConstants.androidCmdName());
    }

    // We might get passed a property for the working directory
    // Either it is a valid directory and mWorkDir is set to it's absolute canonical value
    // or mWorkDir remains null.
    String workDirProp = System.getProperty(WORKDIR);
    if (workDirProp == null) {
      workDirProp = System.getenv(WORKDIR);
    }
    if (workDirProp != null) {
      // This should be a valid directory
      mWorkDir = new File(workDirProp);
      try {
        mWorkDir = mWorkDir.getCanonicalFile().getAbsoluteFile();
      } catch (IOException e) {
        mWorkDir = null;
      }
      if (mWorkDir == null || !mWorkDir.isDirectory()) {
        errorAndExit("The working directory does not seem to be valid: '%1$s", workDirProp);
      }
    }
  }
  /** Creates the icon of the window shell. */
  private void setWindowImage(Shell androidSdkUpdater) {
    String imageName = "android_icon_16.png"; // $NON-NLS-1$
    if (SdkConstants.currentPlatform() == SdkConstants.PLATFORM_DARWIN) {
      imageName = "android_icon_128.png"; // $NON-NLS-1$
    }

    if (mUpdaterData != null) {
      ImageFactory imgFactory = mUpdaterData.getImageFactory();
      if (imgFactory != null) {
        mAndroidSdkUpdater.setImage(imgFactory.getImageByName(imageName));
      }
    }
  }
Example #4
0
File: Main.java Project: MIPS/sdk
  /** Creates a new Android project based on command-line parameters */
  private void createProject(boolean library) {
    String directObject =
        library ? SdkCommandLine.OBJECT_LIB_PROJECT : SdkCommandLine.OBJECT_PROJECT;

    // get the target and try to resolve it.
    int targetId = resolveTargetName(mSdkCommandLine.getParamTargetId());
    IAndroidTarget[] targets = mSdkManager.getTargets();
    if (targetId == INVALID_TARGET_ID || targetId > targets.length) {
      errorAndExit(
          "Target id is not valid. Use '%s list targets' to get the target ids.",
          SdkConstants.androidCmdName());
    }
    IAndroidTarget target = targets[targetId - 1]; // target id is 1-based

    ProjectCreator creator = getProjectCreator();

    String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());

    String projectName = mSdkCommandLine.getParamName();
    String packageName = mSdkCommandLine.getParamProjectPackage(directObject);
    String activityName = null;
    if (library == false) {
      activityName = mSdkCommandLine.getParamProjectActivity();
    }

    if (projectName != null && !ProjectCreator.RE_PROJECT_NAME.matcher(projectName).matches()) {
      errorAndExit(
          "Project name '%1$s' contains invalid characters.\nAllowed characters are: %2$s",
          projectName, ProjectCreator.CHARS_PROJECT_NAME);
      return;
    }

    if (activityName != null && !ProjectCreator.RE_ACTIVITY_NAME.matcher(activityName).matches()) {
      errorAndExit(
          "Activity name '%1$s' contains invalid characters.\nAllowed characters are: %2$s",
          activityName, ProjectCreator.CHARS_ACTIVITY_NAME);
      return;
    }

    if (packageName != null && !ProjectCreator.RE_PACKAGE_NAME.matcher(packageName).matches()) {
      errorAndExit(
          "Package name '%1$s' contains invalid characters.\n"
              + "A package name must be constitued of two Java identifiers.\n"
              + "Each identifier allowed characters are: %2$s",
          packageName, ProjectCreator.CHARS_PACKAGE_NAME);
      return;
    }

    creator.createProject(
        projectDir, projectName, packageName, activityName, target, library, null /*pathToMain*/);
  }
  /** The tool package executes tools/lib/post_tools_install[.bat|.sh] {@inheritDoc} */
  @Override
  public void postInstallHook(Archive archive, ITaskMonitor monitor, File installFolder) {
    super.postInstallHook(archive, monitor, installFolder);

    if (installFolder == null) {
      return;
    }

    File libDir = new File(installFolder, SdkConstants.FD_LIB);
    if (!libDir.isDirectory()) {
      return;
    }

    String scriptName = "post_tools_install"; // $NON-NLS-1$
    String shell = ""; // $NON-NLS-1$
    if (SdkConstants.currentPlatform() == SdkConstants.PLATFORM_WINDOWS) {
      shell = "cmd.exe /c "; // $NON-NLS-1$
      scriptName += ".bat"; // $NON-NLS-1$
    } else {
      scriptName += ".sh"; // $NON-NLS-1$
    }

    File scriptFile = new File(libDir, scriptName);
    if (!scriptFile.isFile()) {
      return;
    }

    Process proc;
    int status = -1;

    try {
      proc =
          Runtime.getRuntime()
              .exec(
                  shell + scriptName, // command
                  null, // environment
                  libDir); // working dir

      status = grabProcessOutput(proc, monitor, scriptName);

    } catch (Exception e) {
      monitor.logError("Exception: %s", e.toString());
    }

    if (status != 0) {
      monitor.logError("Failed to execute %s", scriptName);
      return;
    }
  }
Example #6
0
File: Main.java Project: MIPS/sdk
  /** Creates a new AVD. This is a text based creation with command line prompt. */
  private void createAvd() {
    // find a matching target
    int targetId = resolveTargetName(mSdkCommandLine.getParamTargetId());
    IAndroidTarget[] targets = mSdkManager.getTargets();

    if (targetId == INVALID_TARGET_ID || targetId > targets.length) {
      errorAndExit(
          "Target id is not valid. Use '%s list targets' to get the target ids.",
          SdkConstants.androidCmdName());
    }

    IAndroidTarget target = targets[targetId - 1]; // target id is 1-based

    try {
      boolean removePrevious = mSdkCommandLine.getFlagForce();
      AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog);

      String avdName = mSdkCommandLine.getParamName();

      if (!AvdManager.RE_AVD_NAME.matcher(avdName).matches()) {
        errorAndExit(
            "AVD name '%1$s' contains invalid characters.\nAllowed characters are: %2$s",
            avdName, AvdManager.CHARS_AVD_NAME);
        return;
      }

      AvdInfo info = avdManager.getAvd(avdName, false /*validAvdOnly*/);
      if (info != null) {
        if (removePrevious) {
          mSdkLog.warning(
              "Android Virtual Device '%s' already exists and will be replaced.", avdName);
        } else {
          errorAndExit(
              "Android Virtual Device '%s' already exists.\n"
                  + "Use --force if you want to replace it.",
              avdName);
          return;
        }
      }

      String paramFolderPath = mSdkCommandLine.getParamLocationPath();
      File avdFolder = null;
      if (paramFolderPath != null) {
        avdFolder = new File(paramFolderPath);
      } else {
        avdFolder = AvdManager.AvdInfo.getAvdFolder(avdName);
      }

      // Validate skin is either default (empty) or NNNxMMM or a valid skin name.
      Map<String, String> skinHardwareConfig = null;
      String skin = mSdkCommandLine.getParamSkin();
      if (skin != null && skin.length() == 0) {
        skin = null;
      }

      if (skin != null && target != null) {
        boolean valid = false;
        // Is it a know skin name for this target?
        for (String s : target.getSkins()) {
          if (skin.equalsIgnoreCase(s)) {
            skin = s; // Make skin names case-insensitive.
            valid = true;

            // get the hardware properties for this skin
            File skinFolder = avdManager.getSkinPath(skin, target);
            FileWrapper skinHardwareFile = new FileWrapper(skinFolder, AvdManager.HARDWARE_INI);
            if (skinHardwareFile.isFile()) {
              skinHardwareConfig = ProjectProperties.parsePropertyFile(skinHardwareFile, mSdkLog);
            }
            break;
          }
        }

        // Is it NNNxMMM?
        if (!valid) {
          valid = AvdManager.NUMERIC_SKIN_SIZE.matcher(skin).matches();
        }

        if (!valid) {
          displaySkinList(target, "Valid skins: ");
          errorAndExit("'%s' is not a valid skin name or size (NNNxMMM)", skin);
          return;
        }
      }

      Map<String, String> hardwareConfig = null;
      if (target != null && target.isPlatform()) {
        try {
          hardwareConfig = promptForHardware(target, skinHardwareConfig);
        } catch (IOException e) {
          errorAndExit(e.getMessage());
        }
      }

      @SuppressWarnings("unused") // oldAvdInfo is never read, yet useful for debugging
      AvdInfo oldAvdInfo = null;
      if (removePrevious) {
        oldAvdInfo = avdManager.getAvd(avdName, false /*validAvdOnly*/);
      }

      @SuppressWarnings("unused") // newAvdInfo is never read, yet useful for debugging
      AvdInfo newAvdInfo =
          avdManager.createAvd(
              avdFolder,
              avdName,
              target,
              skin,
              mSdkCommandLine.getParamSdCard(),
              hardwareConfig,
              removePrevious,
              mSdkCommandLine.getFlagSnapshot(),
              mSdkLog);

    } catch (AndroidLocationException e) {
      errorAndExit(e.getMessage());
    }
  }