diff options
author | Xavier Ducrohet <xav@android.com> | 2012-09-27 15:37:32 -0700 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2012-09-27 15:37:58 -0700 |
commit | b30fa0d8b6e139c4f5dc5b13858af44f3e86b134 (patch) | |
tree | bc35147c86f12f9c4a59f9ca162dda9b6147b05c /sdkmanager/app | |
parent | 364609d0f89acd2b9fd00f1ef503a6671ae892fa (diff) | |
download | sdk-b30fa0d8b6e139c4f5dc5b13858af44f3e86b134.zip sdk-b30fa0d8b6e139c4f5dc5b13858af44f3e86b134.tar.gz sdk-b30fa0d8b6e139c4f5dc5b13858af44f3e86b134.tar.bz2 |
Add cmd line support to create ui automator projects.
Change-Id: I34ffff7d7828c171444c40e48fc3dcf093391324
Diffstat (limited to 'sdkmanager/app')
-rw-r--r-- | sdkmanager/app/src/com/android/sdkmanager/Main.java | 70 | ||||
-rw-r--r-- | sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java | 16 |
2 files changed, 83 insertions, 3 deletions
diff --git a/sdkmanager/app/src/com/android/sdkmanager/Main.java b/sdkmanager/app/src/com/android/sdkmanager/Main.java index c4e71b3..8f58612 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/Main.java +++ b/sdkmanager/app/src/com/android/sdkmanager/Main.java @@ -24,17 +24,18 @@ import com.android.io.FileWrapper; import com.android.prefs.AndroidLocation; import com.android.prefs.AndroidLocation.AndroidLocationException; import com.android.sdklib.IAndroidTarget; +import com.android.sdklib.IAndroidTarget.IOptionalLibrary; import com.android.sdklib.ISystemImage; import com.android.sdklib.SdkManager; -import com.android.sdklib.IAndroidTarget.IOptionalLibrary; import com.android.sdklib.internal.avd.AvdInfo; import com.android.sdklib.internal.avd.AvdManager; import com.android.sdklib.internal.avd.HardwareProperties; import com.android.sdklib.internal.avd.HardwareProperties.HardwareProperty; import com.android.sdklib.internal.project.ProjectCreator; -import com.android.sdklib.internal.project.ProjectProperties; import com.android.sdklib.internal.project.ProjectCreator.OutputLevel; +import com.android.sdklib.internal.project.ProjectProperties; import com.android.sdklib.internal.project.ProjectProperties.PropertyType; +import com.android.sdklib.internal.project.ProjectPropertiesWorkingCopy; import com.android.sdklib.internal.repository.DownloadCache; import com.android.sdklib.internal.repository.DownloadCache.Strategy; import com.android.sdklib.internal.repository.packages.PlatformToolPackage; @@ -44,8 +45,8 @@ import com.android.sdklib.repository.SdkRepoConstants; import com.android.sdkuilib.internal.repository.SdkUpdaterNoWindow; import com.android.sdkuilib.internal.widgets.MessageBoxLog; import com.android.sdkuilib.repository.AvdManagerWindow; -import com.android.sdkuilib.repository.SdkUpdaterWindow; import com.android.sdkuilib.repository.AvdManagerWindow.AvdInvocationContext; +import com.android.sdkuilib.repository.SdkUpdaterWindow; import com.android.sdkuilib.repository.SdkUpdaterWindow.SdkInvocationContext; import com.android.utils.ILogger; import com.android.utils.Pair; @@ -275,6 +276,9 @@ public class Main { } else if (SdkCommandLine.OBJECT_LIB_PROJECT.equals(directObject)) { createProject(true /*library*/); + } else if (SdkCommandLine.OBJECT_UITEST_PROJECT.equals(directObject)) { + createUiTestProject(); + } } else if (SdkCommandLine.VERB_UPDATE.equals(verb)) { if (SdkCommandLine.OBJECT_AVD.equals(directObject)) { @@ -691,6 +695,66 @@ public class Main { } /** + * Creates a new Android UI test project based on command-line parameters + */ + private void createUiTestProject() { + + String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath()); + + // 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 + + if (target.getVersion().getApiLevel() < 16) { + errorAndExit("UI test projects can only target API 16 and above"); + } + + // get the project name + String projectName = mSdkCommandLine.getParamName(); + // if none, use the folder name. + if (projectName == null) { + File f = new File(projectDir); + projectName = f.getName(); + } + + try { + // create src folder + File srcFolder = new File(projectDir, SdkConstants.FD_SOURCES); + srcFolder.mkdir(); + + // create the local.prop file. + // location of the SDK goes in localProperty + ProjectPropertiesWorkingCopy localProperties = ProjectProperties.create(projectDir, + PropertyType.LOCAL); + localProperties.setProperty(ProjectProperties.PROPERTY_SDK, mOsSdkFolder); + localProperties.save(); + + // target goes in project properties + ProjectPropertiesWorkingCopy projectProperties = ProjectProperties.create(projectDir, + PropertyType.PROJECT); + projectProperties.setProperty(ProjectProperties.PROPERTY_TARGET, target.hashString()); + projectProperties.save(); + + // copy the build file using the keywords replacement. + final Map<String, String> keywords = new HashMap<String, String>(); + keywords.put(ProjectCreator.PH_PROJECT_NAME, projectName); + + ProjectCreator creator = getProjectCreator(); + + creator.installTemplate("uibuild.template", + new File(projectDir, SdkConstants.FN_BUILD_XML), + keywords); + } catch (Exception e) { + mSdkLog.error(e, null); + } + } + + /** * Updates an existing Android project based on command-line parameters * @param library whether the project is a library project. */ diff --git a/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java b/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java index 68b1943..6a74c29 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java +++ b/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java @@ -54,6 +54,7 @@ class SdkCommandLine extends CommandLineParser { public static final String OBJECT_TARGETS = "targets"; //$NON-NLS-1$ public static final String OBJECT_PROJECT = "project"; //$NON-NLS-1$ public static final String OBJECT_TEST_PROJECT = "test-project"; //$NON-NLS-1$ + public static final String OBJECT_UITEST_PROJECT = "uitest-project"; //$NON-NLS-1$ public static final String OBJECT_LIB_PROJECT = "lib-project"; //$NON-NLS-1$ public static final String OBJECT_ADB = "adb"; //$NON-NLS-1$ @@ -150,6 +151,9 @@ class SdkCommandLine extends CommandLineParser { { VERB_UPDATE, OBJECT_LIB_PROJECT, "Updates an Android library project (must already have an AndroidManifest.xml)." }, + { VERB_CREATE, OBJECT_UITEST_PROJECT, + "Creates a new UI test project." }, + { VERB_UPDATE, OBJECT_ADB, "Updates adb to support the USB devices declared in the SDK add-ons." }, @@ -363,6 +367,18 @@ class SdkCommandLine extends CommandLineParser { "Path to directory of the app under test, relative to the test project directory.", null); + // --- create uitest-project --- + + define(Mode.STRING, true, + VERB_CREATE, OBJECT_UITEST_PROJECT, "p", KEY_PATH, //$NON-NLS-1$ + "The new project's directory.", null); + define(Mode.STRING, false, + VERB_CREATE, OBJECT_UITEST_PROJECT, "n", KEY_NAME, //$NON-NLS-1$ + "Project name.", null); + define(Mode.STRING, true, + VERB_CREATE, OBJECT_UITEST_PROJECT, "t", KEY_TARGET_ID, //$NON-NLS-1$ + "Target ID of the new project.", null); + // --- create lib-project --- define(Mode.STRING, true, |