AI 143223: am: CL 143034 ADT #1738834: Properly validate project name, package name and

activity name for "create project".
  Also validate AVD name for "create avd".
  Original author: raphael
  Merged from: //branches/cupcake/...

Automated import of CL 143223
This commit is contained in:
Raphael Moll
2009-03-27 19:13:58 -07:00
committed by The Android Open Source Project
parent 49f4090c7a
commit 77708b2fd0
2 changed files with 78 additions and 6 deletions

View File

@@ -62,6 +62,27 @@ public class ProjectCreator {
private final static String FOLDER_TESTS = "tests";
/** Pattern for characters accepted in a project name. Since this will be used as a
* directory name, we're being a bit conservative on purpose: dot and space cannot be used. */
public static final Pattern RE_PROJECT_NAME = Pattern.compile("[a-zA-Z0-9_]+");
/** List of valid characters for a project name. Used for display purposes. */
public final static String CHARS_PROJECT_NAME = "a-z A-Z 0-9 _";
/** Pattern for characters accepted in a package name. A package is list of Java identifier
* separated by a dot. We need to have at least one dot (e.g. a two-level package name).
* A Java identifier cannot start by a digit. */
public static final Pattern RE_PACKAGE_NAME =
Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]*(?:\\.[a-zA-Z_][a-zA-Z0-9_]*)+");
/** List of valid characters for a project name. Used for display purposes. */
public final static String CHARS_PACKAGE_NAME = "a-z A-Z 0-9 _";
/** Pattern for characters accepted in an activity name, which is a Java identifier. */
public static final Pattern RE_ACTIVITY_NAME =
Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]*");
/** List of valid characters for a project name. Used for display purposes. */
public final static String CHARS_ACTIVITY_NAME = "a-z A-Z 0-9 _";
public enum OutputLevel {
/** Silent mode. Project creation will only display errors. */
SILENT,
@@ -106,11 +127,17 @@ public class ProjectCreator {
/**
* Creates a new project.
* <p/>
* The caller should have already checked and sanitized the parameters.
*
* @param folderPath the folder of the project to create.
* @param projectName the name of the project.
* @param packageName the package of the project.
* @param activityName the activity of the project as it will appear in the manifest.
* @param projectName the name of the project. The name must match the
* {@link #RE_PROJECT_NAME} regex.
* @param packageName the package of the project. The name must match the
* {@link #RE_PACKAGE_NAME} regex.
* @param activityName the activity of the project as it will appear in the manifest. Can be
* null if no activity should be created. The name must match the
* {@link #RE_ACTIVITY_NAME} regex.
* @param target the project target.
* @param isTestProject whether the project to create is a test project.
*/