Example #1
0
File: Main.java Project: MIPS/sdk
  /** Updates an existing test project with a new path to the main project. */
  private void updateTestProject() {
    ProjectCreator creator = getProjectCreator();

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

    creator.updateTestProject(projectDir, mSdkCommandLine.getParamTestProjectMain(), mSdkManager);
  }
Example #2
0
File: Main.java Project: MIPS/sdk
  /** Creates a new Android Export project based on command-line parameters */
  private void createExportProject() {
    ProjectCreator creator = getProjectCreator();

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

    String projectName = mSdkCommandLine.getParamName();
    String packageName =
        mSdkCommandLine.getParamProjectPackage(SdkCommandLine.OBJECT_EXPORT_PROJECT);

    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 (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.createExportProject(projectDir, projectName, packageName);
  }
Example #3
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 #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*/);
  }
Example #5
0
File: Main.java Project: MIPS/sdk
  /** Updates an existing Android export project based on command-line parameters */
  private void updateExportProject() {
    ProjectCreator creator = getProjectCreator();

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

    String projectName = mSdkCommandLine.getParamName();
    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;
    }

    creator.updateExportProject(projectDir, projectName, mSdkCommandLine.getFlagForce());
  }
Example #6
0
File: Main.java Project: MIPS/sdk
  /** Creates a new Android test project based on command-line parameters */
  private void createTestProject() {

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

    // first check the path of the parent project, and make sure it's valid.
    String pathToMainProject = mSdkCommandLine.getParamTestProjectMain();

    File parentProject = new File(pathToMainProject);
    if (parentProject.isAbsolute() == false) {
      // if the path is not absolute, we need to resolve it based on the
      // destination path of the project
      try {
        parentProject = new File(projectDir, pathToMainProject).getCanonicalFile();
      } catch (IOException e) {
        errorAndExit("Unable to resolve Main project's directory: %1$s", pathToMainProject);
        return; // help Eclipse static analyzer understand we'll never execute the rest.
      }
    }

    if (parentProject.isDirectory() == false) {
      errorAndExit("Main project's directory does not exist: %1$s", pathToMainProject);
      return;
    }

    // now look for a manifest in there
    File manifest = new File(parentProject, SdkConstants.FN_ANDROID_MANIFEST_XML);
    if (manifest.isFile() == false) {
      errorAndExit(
          "No AndroidManifest.xml file found in the main project directory: %1$s",
          parentProject.getAbsolutePath());
      return;
    }

    // now query the manifest for the package file.
    XPath xpath = AndroidXPathFactory.newXPath();
    String packageName, activityName;

    try {
      packageName =
          xpath.evaluate("/manifest/@package", new InputSource(new FileInputStream(manifest)));

      mSdkLog.printf("Found main project package: %1$s\n", packageName);

      // now get the name of the first activity we find
      activityName =
          xpath.evaluate(
              "/manifest/application/activity[1]/@android:name",
              new InputSource(new FileInputStream(manifest)));
      // xpath will return empty string when there's no match
      if (activityName == null || activityName.length() == 0) {
        activityName = null;
      } else {
        mSdkLog.printf("Found main project activity: %1$s\n", activityName);
      }
    } catch (FileNotFoundException e) {
      // this shouldn't happen as we test it above.
      errorAndExit("No AndroidManifest.xml file found in main project.");
      return; // this is not strictly needed because errorAndExit will stop the execution,
      // but this makes the java compiler happy, wrt to uninitialized variables.
    } catch (XPathExpressionException e) {
      // looks like the main manifest is not valid.
      errorAndExit("Unable to parse main project manifest to get information.");
      return; // this is not strictly needed because errorAndExit will stop the execution,
      // but this makes the java compiler happy, wrt to uninitialized variables.
    }

    // now get the target hash
    ProjectProperties p =
        ProjectProperties.load(parentProject.getAbsolutePath(), PropertyType.DEFAULT);
    if (p == null) {
      errorAndExit("Unable to load the main project's %1$s", PropertyType.DEFAULT.getFilename());
      return;
    }

    String targetHash = p.getProperty(ProjectProperties.PROPERTY_TARGET);
    if (targetHash == null) {
      errorAndExit("Couldn't find the main project target");
      return;
    }

    // and resolve it.
    IAndroidTarget target = mSdkManager.getTargetFromHashString(targetHash);
    if (target == null) {
      errorAndExit(
          "Unable to resolve main project target '%1$s'. You may want to install the platform in your SDK.",
          targetHash);
      return;
    }

    mSdkLog.printf("Found main project target: %1$s\n", target.getFullName());

    ProjectCreator creator = getProjectCreator();

    String projectName = mSdkCommandLine.getParamName();

    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;
    }

    creator.createProject(
        projectDir,
        projectName,
        packageName,
        activityName,
        target,
        false /* library*/,
        pathToMainProject);
  }