diff options
author | Xavier Ducrohet <xav@android.com> | 2011-01-12 17:49:55 -0800 |
---|---|---|
committer | Android Code Review <code-review@android.com> | 2011-01-12 17:49:55 -0800 |
commit | 6fb212b55eb3c2819c7a4f530f6beb3586b0a07e (patch) | |
tree | 648f78e7c047a4859ff63cb89fe6e08b6d359e7f /sdkmanager/app | |
parent | f4df12efd1906b947b32e92489b241ac19fab2e6 (diff) | |
parent | 57aa211a4bff699d81f755c0d827b496ad7eef26 (diff) | |
download | sdk-6fb212b55eb3c2819c7a4f530f6beb3586b0a07e.zip sdk-6fb212b55eb3c2819c7a4f530f6beb3586b0a07e.tar.gz sdk-6fb212b55eb3c2819c7a4f530f6beb3586b0a07e.tar.bz2 |
Merge "Merge 74f725db from master: Add snapshot handling for AVD creation, details, and launch" into tools_r9
Diffstat (limited to 'sdkmanager/app')
8 files changed, 451 insertions, 62 deletions
diff --git a/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java b/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java index 73b0f6b..8f5dec4 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java +++ b/sdkmanager/app/src/com/android/sdkmanager/CommandLineProcessor.java @@ -828,6 +828,7 @@ class CommandLineProcessor { * Internal helper to define a new argument for a give action. * * @param mode The {@link Mode} for the argument. + * @param mandatory The argument is required (never if {@link Mode.BOOLEAN}) * @param verb The verb name. Can be #INTERNAL_VERB. * @param directObject The action name. Can be #NO_VERB_OBJECT or #INTERNAL_FLAG. * @param shortName The one-letter short argument name. Can be empty but not null. diff --git a/sdkmanager/app/src/com/android/sdkmanager/Main.java b/sdkmanager/app/src/com/android/sdkmanager/Main.java index e951cc5..1fe6d97 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/Main.java +++ b/sdkmanager/app/src/com/android/sdkmanager/Main.java @@ -19,17 +19,17 @@ package com.android.sdkmanager; 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.ISdkLog; import com.android.sdklib.SdkConstants; import com.android.sdklib.SdkManager; -import com.android.sdklib.IAndroidTarget.IOptionalLibrary; import com.android.sdklib.internal.avd.AvdManager; -import com.android.sdklib.internal.avd.HardwareProperties; import com.android.sdklib.internal.avd.AvdManager.AvdInfo; +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.io.FileWrapper; import com.android.sdklib.repository.SdkRepoConstants; @@ -133,6 +133,11 @@ public class Main { }; } + /** For testing */ + public void setLogger(ISdkLog logger) { + mSdkLog = logger; + } + /** * Init the application by making sure the SDK path is available and * doing basic parsing of the SDK. @@ -788,72 +793,84 @@ public class Main { } /** - * Displays the list of available AVDs. + * Displays the list of available AVDs for the given AvdManager. + * + * @param avdManager */ - private void displayAvdList() { - try { - AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog); + public void displayAvdList(AvdManager avdManager) { + mSdkLog.printf("Available Android Virtual Devices:\n"); + + AvdInfo[] avds = avdManager.getValidAvds(); + for (int index = 0 ; index < avds.length ; index++) { + AvdInfo info = avds[index]; + if (index > 0) { + mSdkLog.printf("---------\n"); + } + mSdkLog.printf(" Name: %s\n", info.getName()); + mSdkLog.printf(" Path: %s\n", info.getPath()); - mSdkLog.printf("Available Android Virtual Devices:\n"); + // get the target of the AVD + IAndroidTarget target = info.getTarget(); + if (target.isPlatform()) { + mSdkLog.printf(" Target: %s (API level %s)\n", target.getName(), + target.getVersion().getApiString()); + } else { + mSdkLog.printf(" Target: %s (%s)\n", target.getName(), target + .getVendor()); + mSdkLog.printf(" Based on Android %s (API level %s)\n", + target.getVersionName(), target.getVersion().getApiString()); + } - AvdInfo[] avds = avdManager.getValidAvds(); - for (int index = 0 ; index < avds.length ; index++) { - AvdInfo info = avds[index]; - if (index > 0) { - mSdkLog.printf("---------\n"); + // display some extra values. + Map<String, String> properties = info.getProperties(); + if (properties != null) { + String skin = properties.get(AvdManager.AVD_INI_SKIN_NAME); + if (skin != null) { + mSdkLog.printf(" Skin: %s\n", skin); } - mSdkLog.printf(" Name: %s\n", info.getName()); - mSdkLog.printf(" Path: %s\n", info.getPath()); - - // get the target of the AVD - IAndroidTarget target = info.getTarget(); - if (target.isPlatform()) { - mSdkLog.printf(" Target: %s (API level %s)\n", target.getName(), - target.getVersion().getApiString()); - } else { - mSdkLog.printf(" Target: %s (%s)\n", target.getName(), target - .getVendor()); - mSdkLog.printf(" Based on Android %s (API level %s)\n", - target.getVersionName(), target.getVersion().getApiString()); + String sdcard = properties.get(AvdManager.AVD_INI_SDCARD_SIZE); + if (sdcard == null) { + sdcard = properties.get(AvdManager.AVD_INI_SDCARD_PATH); } - - // display some extra values. - Map<String, String> properties = info.getProperties(); - if (properties != null) { - String skin = properties.get(AvdManager.AVD_INI_SKIN_NAME); - if (skin != null) { - mSdkLog.printf(" Skin: %s\n", skin); - } - String sdcard = properties.get(AvdManager.AVD_INI_SDCARD_SIZE); - if (sdcard == null) { - sdcard = properties.get(AvdManager.AVD_INI_SDCARD_PATH); - } - if (sdcard != null) { - mSdkLog.printf(" Sdcard: %s\n", sdcard); - } + if (sdcard != null) { + mSdkLog.printf(" Sdcard: %s\n", sdcard); + } + String snapshot = properties.get(AvdManager.AVD_INI_SNAPSHOT_PRESENT); + if (snapshot != null) { + mSdkLog.printf("Snapshot: %s\n", snapshot); } } + } - // Are there some unused AVDs? - AvdInfo[] badAvds = avdManager.getBrokenAvds(); + // Are there some unused AVDs? + AvdInfo[] badAvds = avdManager.getBrokenAvds(); - if (badAvds.length == 0) { - return; + if (badAvds.length == 0) { + return; + } + + mSdkLog.printf("\nThe following Android Virtual Devices could not be loaded:\n"); + boolean needSeparator = false; + for (AvdInfo info : badAvds) { + if (needSeparator) { + mSdkLog.printf("---------\n"); } + mSdkLog.printf(" Name: %s\n", info.getName() == null ? "--" : info.getName()); + mSdkLog.printf(" Path: %s\n", info.getPath() == null ? "--" : info.getPath()); - mSdkLog.printf("\nThe following Android Virtual Devices could not be loaded:\n"); - boolean needSeparator = false; - for (AvdInfo info : badAvds) { - if (needSeparator) { - mSdkLog.printf("---------\n"); - } - mSdkLog.printf(" Name: %s\n", info.getName() == null ? "--" : info.getName()); - mSdkLog.printf(" Path: %s\n", info.getPath() == null ? "--" : info.getPath()); + String error = info.getErrorMessage(); + mSdkLog.printf(" Error: %s\n", error == null ? "Uknown error" : error); + needSeparator = true; + } + } - String error = info.getErrorMessage(); - mSdkLog.printf(" Error: %s\n", error == null ? "Uknown error" : error); - needSeparator = true; - } + /** + * Displays the list of available AVDs. + */ + private void displayAvdList() { + try { + AvdManager avdManager = new AvdManager(mSdkManager, mSdkLog); + displayAvdList(avdManager); } catch (AndroidLocationException e) { errorAndExit(e.getMessage()); } @@ -972,6 +989,7 @@ public class Main { mSdkCommandLine.getParamSdCard(), hardwareConfig, removePrevious, + mSdkCommandLine.getFlagSnapshot(), mSdkLog); } catch (AndroidLocationException e) { diff --git a/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java b/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java index 7062fae..5bb6c4e 100644 --- a/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java +++ b/sdkmanager/app/src/com/android/sdkmanager/SdkCommandLine.java @@ -78,6 +78,7 @@ class SdkCommandLine extends CommandLineProcessor { public static final String KEY_PROXY_HOST = "proxy-host"; public static final String KEY_DRY_MODE = "dry-mode"; public static final String KEY_OBSOLETE = "obsolete"; + public static final String KEY_SNAPSHOT = "snapshot"; /** * Action definitions for SdkManager command line. @@ -166,6 +167,9 @@ class SdkCommandLine extends CommandLineProcessor { define(Mode.BOOLEAN, false, VERB_CREATE, OBJECT_AVD, "f", KEY_FORCE, "Forces creation (overwrites an existing AVD)", false); + define(Mode.BOOLEAN, false, + VERB_CREATE, OBJECT_AVD, "a", KEY_SNAPSHOT, + "Place a snapshots file in the AVD, to enable persistence.", false); // --- delete avd --- @@ -408,6 +412,11 @@ class SdkCommandLine extends CommandLineProcessor { return ((Boolean) getValue(null, null, KEY_FORCE)).booleanValue(); } + /** Helper to retrieve the --snapshot flag. */ + public boolean getFlagSnapshot() { + return ((Boolean) getValue(null, null, KEY_SNAPSHOT)).booleanValue(); + } + // -- some helpers for avd action flags /** Helper to retrieve the --rename value for a move verb. */ diff --git a/sdkmanager/app/tests/com/android/sdkmanager/AvdManagerTest.java b/sdkmanager/app/tests/com/android/sdkmanager/AvdManagerTest.java new file mode 100644 index 0000000..bb1ba75 --- /dev/null +++ b/sdkmanager/app/tests/com/android/sdkmanager/AvdManagerTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.sdkmanager; + +import static java.io.File.createTempFile; + +import com.android.sdklib.IAndroidTarget; +import com.android.sdklib.SdkManager; +import com.android.sdklib.internal.avd.AvdManager; +import com.android.sdklib.internal.project.ProjectProperties; +import com.android.sdklib.io.FileWrapper; + +import java.io.File; +import java.util.Map; + +import junit.framework.TestCase; + +public class AvdManagerTest extends TestCase { + + private AvdManager mAvdManager; + private SdkManager mSdkManager; + private MockLog mLog; + private File mFakeSdk; + private File mAvdFolder; + private IAndroidTarget mTarget; + + @Override + public void setUp() throws Exception { + mLog = new MockLog(); + mFakeSdk = SdkManagerTestUtil.makeFakeSdk(createTempFile(this.getClass().getSimpleName(), null)); + mSdkManager = SdkManager.createManager(mFakeSdk.getAbsolutePath(), mLog); + assertNotNull("sdkManager location was invalid", mSdkManager); + + mAvdManager = new AvdManager(mSdkManager, mLog); + mAvdFolder = new File(mFakeSdk, "avdData"); + mTarget = mSdkManager.getTargets()[0]; + } + + @Override + public void tearDown() throws Exception { + SdkManagerTestUtil.deleteDir(mFakeSdk); + } + + public void testCreateAvdWithoutSnapshot() { + mAvdManager.createAvd( + mAvdFolder, this.getName(), mTarget, null, null, null, false, false, mLog); + + assertEquals("[P Created AVD '" + this.getName() + "' based on Android 0.0\n]", + mLog.toString()); + assertTrue("Expected config.ini in " + mAvdFolder, + new File(mAvdFolder, "config.ini").exists()); + Map<String, String> map = ProjectProperties.parsePropertyFile( + new FileWrapper(mAvdFolder, "config.ini"), mLog); + assertEquals("HVGA", map.get("skin.name")); + assertEquals("platforms/v0_0/skins/HVGA", map.get("skin.path")); + assertEquals("platforms/v0_0/images/", map.get("image.sysdir.1")); + assertEquals(null, map.get("snapshot.present")); + assertTrue("Expected userdata.img in " + mAvdFolder, + new File(mAvdFolder, "userdata.img").exists()); + assertFalse("Expected NO snapshots.img in " + mAvdFolder, + new File(mAvdFolder, "snapshots.img").exists()); + } + + public void testCreateAvdWithSnapshot() { + mAvdManager.createAvd( + mAvdFolder, this.getName(), mTarget, null, null, null, false, true, mLog); + + assertEquals("[P Created AVD '" + this.getName() + "' based on Android 0.0\n]", + mLog.toString()); + assertTrue("Expected snapshots.img in " + mAvdFolder, + new File(mAvdFolder, "snapshots.img").exists()); + Map<String, String> map = ProjectProperties.parsePropertyFile( + new FileWrapper(mAvdFolder, "config.ini"), mLog); + assertEquals("true", map.get("snapshot.present")); + } +} diff --git a/sdkmanager/app/tests/com/android/sdkmanager/MainTest.java b/sdkmanager/app/tests/com/android/sdkmanager/MainTest.java new file mode 100644 index 0000000..f6e3bbe --- /dev/null +++ b/sdkmanager/app/tests/com/android/sdkmanager/MainTest.java @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.sdkmanager; + + +import static java.io.File.createTempFile; + +import com.android.sdklib.IAndroidTarget; +import com.android.sdklib.SdkManager; +import com.android.sdklib.internal.avd.AvdManager; + +import java.io.File; + +import junit.framework.TestCase; + +public class MainTest extends TestCase { + + private File mFakeSdk; + private MockLog mLog; + private SdkManager mSdkManager; + private AvdManager mAvdManager; + private File mAvdFolder; + private IAndroidTarget mTarget; + private File fakeSdkDir; + + @Override + public void setUp() throws Exception { + mLog = new MockLog(); + fakeSdkDir = createTempFile(this.getClass().getSimpleName() + "_" + this.getName(), null); + mFakeSdk = SdkManagerTestUtil.makeFakeSdk(fakeSdkDir); + mSdkManager = SdkManager.createManager(mFakeSdk.getAbsolutePath(), mLog); + assertNotNull("sdkManager location was invalid", mSdkManager); + + mAvdManager = new AvdManager(mSdkManager, mLog); + mAvdFolder = new File(mFakeSdk, "avdData"); + mTarget = mSdkManager.getTargets()[0]; + } + + @Override + public void tearDown() throws Exception { + SdkManagerTestUtil.deleteDir(mFakeSdk); + } + + public void txestDisplayEmptyAvdList() { + Main main = new Main(); + main.setLogger(mLog); + mLog.clear(); + main.displayAvdList(mAvdManager); + assertEquals("P Available Android Virtual Devices:\n", mLog.toString()); + } + + public void testDisplayAvdListOfOneNonSnapshot() { + Main main = new Main(); + main.setLogger(mLog); + mAvdManager.createAvd( + mAvdFolder, this.getName(), mTarget, null, null, null, false, false, mLog); + mLog.clear(); + main.displayAvdList(mAvdManager); + assertEquals( + "[P Available Android Virtual Devices:\n" + + ", P Name: " + this.getName() + "\n" + + ", P Path: " + mAvdFolder + "\n" + + ", P Target: Android 0.0 (API level 0)\n" + + ", P Skin: HVGA\n" + + "]", + mLog.toString()); + } + + public void testDisplayAvdListOfOneSnapshot() { + Main main = new Main(); + main.setLogger(mLog); + mAvdManager.createAvd( + mAvdFolder, this.getName(), mTarget, null, null, null, false, true, mLog); + mLog.clear(); + main.displayAvdList(mAvdManager); + assertEquals( + "[P Available Android Virtual Devices:\n" + + ", P Name: " + this.getName() + "\n" + + ", P Path: " + mAvdFolder + "\n" + + ", P Target: Android 0.0 (API level 0)\n" + + ", P Skin: HVGA\n" + + ", P Snapshot: true\n" + + "]", + mLog.toString()); + } +} diff --git a/sdkmanager/app/tests/com/android/sdkmanager/MockLog.java b/sdkmanager/app/tests/com/android/sdkmanager/MockLog.java new file mode 100644 index 0000000..a8ca90a --- /dev/null +++ b/sdkmanager/app/tests/com/android/sdkmanager/MockLog.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.sdkmanager; + +import com.android.sdklib.ISdkLog; + +import java.util.ArrayList; +import java.util.Formatter; + +public class MockLog implements ISdkLog { + private ArrayList<String> mMessages = new ArrayList<String>(); + + private void add(String code, String format, Object... args) { + mMessages.add(new Formatter().format(code + format, args).toString()); + } + + @Override + public void warning(String format, Object... args) { + add("W ", format, args); + } + + @Override + public void printf(String format, Object... args) { + add("P ", format, args); + } + + @Override + public void error(Throwable t, String format, Object... args) { + if (t != null) { + add("T", "%s", t.toString()); + } + add("E ", format, args); + } + + @Override + public String toString() { + return mMessages.toString(); + } + + public void clear() { + mMessages.clear(); + } +} diff --git a/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java b/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java index 8206e2a..036d2ec 100644 --- a/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java +++ b/sdkmanager/app/tests/com/android/sdkmanager/SdkCommandLineTest.java @@ -24,7 +24,7 @@ import junit.framework.TestCase; public class SdkCommandLineTest extends TestCase { private StdSdkLog mLog; - + /** * A mock version of the {@link SdkCommandLine} class that does not * exits and discards its stdout/stderr output. @@ -32,7 +32,7 @@ public class SdkCommandLineTest extends TestCase { public static class MockSdkCommandLine extends SdkCommandLine { private boolean mExitCalled; private boolean mHelpCalled; - + public MockSdkCommandLine(ISdkLog logger) { super(logger); } @@ -48,12 +48,12 @@ public class SdkCommandLineTest extends TestCase { protected void exit() { mExitCalled = true; } - + @Override protected void stdout(String format, Object... args) { // discard } - + @Override protected void stderr(String format, Object... args) { // discard @@ -62,7 +62,7 @@ public class SdkCommandLineTest extends TestCase { public boolean wasExitCalled() { return mExitCalled; } - + public boolean wasHelpCalled() { return mHelpCalled; } @@ -139,4 +139,30 @@ public class SdkCommandLineTest extends TestCase { assertEquals("target", c.getDirectObject()); assertFalse(c.isVerbose()); } + + public final void testCreate_Avd() { + MockSdkCommandLine c = new MockSdkCommandLine(mLog); + c.parseArgs(new String[] { "create", "avd", "-t", "android-100", "-n", "myProject" }); + assertFalse(c.wasHelpCalled()); + assertFalse(c.wasExitCalled()); + assertEquals("create", c.getVerb()); + assertEquals("avd", c.getDirectObject()); + assertFalse(c.getFlagSnapshot()); + assertEquals("android-100", c.getParamTargetId()); + assertEquals("myProject", c.getParamName()); + assertFalse(c.isVerbose()); + } + + public final void testCreate_Avd_Snapshot() { + MockSdkCommandLine c = new MockSdkCommandLine(mLog); + c.parseArgs(new String[] { "create", "avd", "-t", "android-100", "-n", "myProject", "-a" }); + assertFalse(c.wasHelpCalled()); + assertFalse(c.wasExitCalled()); + assertEquals("create", c.getVerb()); + assertEquals("avd", c.getDirectObject()); + assertTrue(c.getFlagSnapshot()); + assertEquals("android-100", c.getParamTargetId()); + assertEquals("myProject", c.getParamName()); + assertFalse(c.isVerbose()); + } } diff --git a/sdkmanager/app/tests/com/android/sdkmanager/SdkManagerTestUtil.java b/sdkmanager/app/tests/com/android/sdkmanager/SdkManagerTestUtil.java new file mode 100644 index 0000000..96efb5c --- /dev/null +++ b/sdkmanager/app/tests/com/android/sdkmanager/SdkManagerTestUtil.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.sdkmanager; + +import com.android.prefs.AndroidLocation; +import com.android.sdklib.SdkConstants; +import com.android.sdklib.SdkManager; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; + +public class SdkManagerTestUtil { + /** + * Build enough of a skeleton SDK to make the tests pass. + *<p> + * Ideally this wouldn't touch the file system, but I'm not inclined to + * fiddle around with mock file systems just at the moment. + * + * @return an sdk manager to a fake sdk + * @throws IOException + */ + public static File makeFakeSdk(File fakeSdk) throws IOException { + fakeSdk.delete(); + fakeSdk.mkdirs(); + AndroidLocation.resetFolder(); + System.setProperty("user.home", fakeSdk.getAbsolutePath()); + File addonsDir = new File(fakeSdk, SdkConstants.FD_ADDONS); + addonsDir.mkdir(); + File toolsLibEmuDir = new File(fakeSdk, SdkConstants.OS_SDK_TOOLS_LIB_FOLDER + "emulator"); + toolsLibEmuDir.mkdirs(); + new File(toolsLibEmuDir, "snapshots.img").createNewFile(); + File platformsDir = new File(fakeSdk, SdkConstants.FD_PLATFORMS); + + // Creating a fake target here on down + File targetDir = new File(platformsDir, "v0_0"); + targetDir.mkdirs(); + new File(targetDir, SdkConstants.FN_FRAMEWORK_LIBRARY).createNewFile(); + new File(targetDir, SdkConstants.FN_FRAMEWORK_AIDL).createNewFile(); + new File(targetDir, SdkConstants.FN_SOURCE_PROP).createNewFile(); + File buildProp = new File(targetDir, SdkConstants.FN_BUILD_PROP); + FileWriter out = new FileWriter(buildProp); + out.write(SdkManager.PROP_VERSION_RELEASE + "=0.0\n"); + out.write(SdkManager.PROP_VERSION_SDK + "=0\n"); + out.write(SdkManager.PROP_VERSION_CODENAME + "=REL\n"); + out.close(); + File imagesDir = new File(targetDir, "images"); + imagesDir.mkdirs(); + new File(imagesDir, "userdata.img").createNewFile(); + File skinsDir = new File(targetDir, "skins"); + File hvgaDir = new File(skinsDir, "HVGA"); + hvgaDir.mkdirs(); + return fakeSdk; + } + + /** + * Recursive delete directory. Mostly for fake SDKs. + * + * @param root directory to delete + */ + public static void deleteDir(File root) { + if (root.exists()) { + for (File file : root.listFiles()) { + if (file.isDirectory()) { + deleteDir(file); + } else { + file.delete(); + } + } + root.delete(); + } + } + +} |