aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/app
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2010-02-11 15:02:48 -0800
committerXavier Ducrohet <xav@android.com>2010-02-11 16:56:40 -0800
commit4ccd166171209813443bf29867c31d9e34858fd3 (patch)
tree6d1043497225606c69f39944297dc6ee133e347d /sdkmanager/app
parente273b35198873938be67a7f954b2045008e30a0a (diff)
downloadsdk-4ccd166171209813443bf29867c31d9e34858fd3.zip
sdk-4ccd166171209813443bf29867c31d9e34858fd3.tar.gz
sdk-4ccd166171209813443bf29867c31d9e34858fd3.tar.bz2
Add support for creating/updating library project to the "android" command-line tool.
Also, support to add a reference to a library from a regular project. Bug: 2294012 Change-Id: I5323dd5816426651a1e77ab206d9d17ee5749813
Diffstat (limited to 'sdkmanager/app')
-rw-r--r--sdkmanager/app/src/com/android/sdkmanager/Main.java116
-rw-r--r--sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java60
2 files changed, 122 insertions, 54 deletions
diff --git a/sdkmanager/app/src/com/android/sdkmanager/Main.java b/sdkmanager/app/src/com/android/sdkmanager/Main.java
index 7f49ea3..e9992a2 100644
--- a/sdkmanager/app/src/com/android/sdkmanager/Main.java
+++ b/sdkmanager/app/src/com/android/sdkmanager/Main.java
@@ -211,10 +211,26 @@ public class Main {
displayAvdList();
}
- } else if (SdkCommandLine.VERB_CREATE.equals(verb) &&
- SdkCommandLine.OBJECT_AVD.equals(directObject)) {
- createAvd();
-
+ } else if (SdkCommandLine.VERB_CREATE.equals(verb)) {
+ if (SdkCommandLine.OBJECT_AVD.equals(directObject)) {
+ createAvd();
+ } else if (SdkCommandLine.OBJECT_PROJECT.equals(directObject)) {
+ createProject(false /*library*/);
+ } else if (SdkCommandLine.OBJECT_TEST_PROJECT.equals(directObject)) {
+ createTestProject();
+ } else if (SdkCommandLine.OBJECT_LIB_PROJECT.equals(directObject)) {
+ createProject(true /*library*/);
+ }
+ } else if (SdkCommandLine.VERB_UPDATE.equals(verb)) {
+ if (SdkCommandLine.OBJECT_AVD.equals(directObject)) {
+ updateAvd();
+ } else if (SdkCommandLine.OBJECT_PROJECT.equals(directObject)) {
+ updateProject(false /*library*/);
+ } else if (SdkCommandLine.OBJECT_TEST_PROJECT.equals(directObject)) {
+ updateTestProject();
+ } else if (SdkCommandLine.OBJECT_LIB_PROJECT.equals(directObject)) {
+ updateProject(true /*library*/);
+ }
} else if (SdkCommandLine.VERB_DELETE.equals(verb) &&
SdkCommandLine.OBJECT_AVD.equals(directObject)) {
deleteAvd();
@@ -223,26 +239,6 @@ public class Main {
SdkCommandLine.OBJECT_AVD.equals(directObject)) {
moveAvd();
- } else if (SdkCommandLine.VERB_UPDATE.equals(verb) &&
- SdkCommandLine.OBJECT_AVD.equals(directObject)) {
- updateAvd();
-
- } else if (SdkCommandLine.VERB_CREATE.equals(verb) &&
- SdkCommandLine.OBJECT_PROJECT.equals(directObject)) {
- createProject();
-
- } else if (SdkCommandLine.VERB_CREATE.equals(verb) &&
- SdkCommandLine.OBJECT_TEST_PROJECT.equals(directObject)) {
- createTestProject();
-
- } else if (SdkCommandLine.VERB_UPDATE.equals(verb) &&
- SdkCommandLine.OBJECT_PROJECT.equals(directObject)) {
- updateProject();
-
- } else if (SdkCommandLine.VERB_UPDATE.equals(verb) &&
- SdkCommandLine.OBJECT_TEST_PROJECT.equals(directObject)) {
- updateTestProject();
-
} else if (verb == null && directObject == null) {
showMainWindow(false /*autoUpdate*/);
@@ -287,7 +283,10 @@ public class Main {
/**
* Creates a new Android project based on command-line parameters
*/
- private void createProject() {
+ 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();
@@ -306,8 +305,11 @@ public class Main {
String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());
String projectName = mSdkCommandLine.getParamName();
- String packageName = mSdkCommandLine.getParamProjectPackage();
- String activityName = mSdkCommandLine.getParamProjectActivity();
+ String packageName = mSdkCommandLine.getParamProjectPackage(directObject);
+ String activityName = null;
+ if (library == false) {
+ activityName = mSdkCommandLine.getParamProjectActivity();
+ }
if (projectName != null &&
!ProjectCreator.RE_PROJECT_NAME.matcher(projectName).matches()) {
@@ -317,6 +319,7 @@ public class Main {
return;
}
+
if (activityName != null &&
!ProjectCreator.RE_ACTIVITY_NAME.matcher(activityName).matches()) {
errorAndExit(
@@ -340,6 +343,7 @@ public class Main {
packageName,
activityName,
target,
+ library,
null /*pathToMain*/);
}
@@ -458,14 +462,16 @@ public class Main {
packageName,
activityName,
target,
+ false /* library*/,
pathToMainProject);
}
/**
* Updates an existing Android project based on command-line parameters
+ * @param library whether the project is a library project.
*/
- private void updateProject() {
+ private void updateProject(boolean library) {
// get the target and try to resolve it.
IAndroidTarget target = null;
String targetStr = mSdkCommandLine.getParamTargetId();
@@ -490,35 +496,43 @@ public class Main {
String projectDir = getProjectLocation(mSdkCommandLine.getParamLocationPath());
+ String libraryPath = mSdkCommandLine.getParamProjectLibrary(
+ library ? SdkCommandLine.OBJECT_LIB_PROJECT : SdkCommandLine.OBJECT_PROJECT);
+
creator.updateProject(projectDir,
target,
- mSdkCommandLine.getParamName());
-
- 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());
- } else {
- couldHaveDone = true;
+ 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);
+ 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);
+ }
}
}
diff --git a/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java b/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java
index 80ee5dd..bbeb1f6 100644
--- a/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java
+++ b/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java
@@ -48,6 +48,7 @@ class SdkCommandLine extends CommandLineProcessor {
public static final String OBJECT_TARGETS = "targets";
public static final String OBJECT_PROJECT = "project";
public static final String OBJECT_TEST_PROJECT = "test-project";
+ public static final String OBJECT_LIB_PROJECT = "lib-project";
public static final String OBJECT_ADB = "adb";
public static final String ARG_ALIAS = "alias";
@@ -58,6 +59,7 @@ class SdkCommandLine extends CommandLineProcessor {
public static final String KEY_MODE = "mode";
public static final String KEY_TARGET_ID = OBJECT_TARGET;
public static final String KEY_NAME = "name";
+ public static final String KEY_LIBRARY = "library";
public static final String KEY_PATH = "path";
public static final String KEY_FILTER = "filter";
public static final String KEY_SKIN = "skin";
@@ -111,6 +113,11 @@ class SdkCommandLine extends CommandLineProcessor {
{ VERB_UPDATE, OBJECT_TEST_PROJECT,
"Updates an Android Test Project (must have an AndroidManifest.xml)." },
+ { VERB_CREATE, OBJECT_LIB_PROJECT,
+ "Creates a new Android Library Project." },
+ { VERB_UPDATE, OBJECT_LIB_PROJECT,
+ "Updates an Android Library Project (must have an AndroidManifest.xml)." },
+
{ VERB_UPDATE, OBJECT_ADB,
"Updates adb to support the USB devices declared in the SDK add-ons." },
@@ -207,6 +214,22 @@ class SdkCommandLine extends CommandLineProcessor {
VERB_CREATE, OBJECT_TEST_PROJECT, "m", KEY_MAIN_PROJECT,
"Location path of the project to test, relative to the new project", null);
+ // --- create lib-project ---
+
+ define(Mode.STRING, true,
+ VERB_CREATE, OBJECT_LIB_PROJECT,
+ "p", KEY_PATH,
+ "Location path of new project", null);
+ define(Mode.STRING, true,
+ VERB_CREATE, OBJECT_LIB_PROJECT, "t", KEY_TARGET_ID,
+ "Target id of the new project", null);
+ define(Mode.STRING, false,
+ VERB_CREATE, OBJECT_LIB_PROJECT, "n", KEY_NAME,
+ "Project name", null);
+ define(Mode.STRING, true,
+ VERB_CREATE, OBJECT_LIB_PROJECT, "k", KEY_PACKAGE,
+ "Package name", null);
+
// --- update project ---
define(Mode.STRING, true,
@@ -225,6 +248,10 @@ class SdkCommandLine extends CommandLineProcessor {
VERB_UPDATE, OBJECT_PROJECT,
"s", KEY_SUBPROJECTS,
"Also update any projects in sub-folders, such as test projects.", false);
+ define(Mode.STRING, false,
+ VERB_UPDATE, OBJECT_PROJECT,
+ "l", KEY_LIBRARY,
+ "Location path of an Android Library to add, relative to the main project", null);
// --- update test project ---
@@ -236,6 +263,21 @@ class SdkCommandLine extends CommandLineProcessor {
VERB_UPDATE, OBJECT_TEST_PROJECT,
"m", KEY_MAIN_PROJECT,
"Location path of the project to test, relative to the new project", null);
+
+ // --- update lib project ---
+
+ define(Mode.STRING, true,
+ VERB_UPDATE, OBJECT_LIB_PROJECT,
+ "p", KEY_PATH,
+ "Location path of the project", null);
+ define(Mode.STRING, false,
+ VERB_UPDATE, OBJECT_LIB_PROJECT,
+ "t", KEY_TARGET_ID,
+ "Target id to set for the project", null);
+ define(Mode.STRING, false,
+ VERB_UPDATE, OBJECT_LIB_PROJECT,
+ "l", KEY_LIBRARY,
+ "Location path of an Android Library to add, relative to the main project", null);
}
@Override
@@ -292,9 +334,12 @@ class SdkCommandLine extends CommandLineProcessor {
// -- some helpers for project action flags
- /** Helper to retrieve the --package value. */
- public String getParamProjectPackage() {
- return ((String) getValue(null, OBJECT_PROJECT, KEY_PACKAGE));
+ /** Helper to retrieve the --package value.
+ * @param directObject the directObject of the action, either {@link #OBJECT_PROJECT}
+ * or {@link #OBJECT_LIB_PROJECT}.
+ */
+ public String getParamProjectPackage(String directObject) {
+ return ((String) getValue(null, directObject, KEY_PACKAGE));
}
/** Helper to retrieve the --activity for any project action. */
@@ -302,6 +347,15 @@ class SdkCommandLine extends CommandLineProcessor {
return ((String) getValue(null, OBJECT_PROJECT, KEY_ACTIVITY));
}
+ /** Helper to retrieve the --library value.
+ * @param directObject the directObject of the action, either {@link #OBJECT_PROJECT}
+ * or {@link #OBJECT_LIB_PROJECT}.
+ */
+ public String getParamProjectLibrary(String directObject) {
+ return ((String) getValue(null, directObject, KEY_LIBRARY));
+ }
+
+
/** Helper to retrieve the --subprojects for any project action. */
public boolean getParamSubProject() {
return ((Boolean) getValue(null, OBJECT_PROJECT, KEY_SUBPROJECTS)).booleanValue();