1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.sdklib.internal.repository.packages; 18 19 import com.android.sdklib.IAndroidTarget; 20 import com.android.sdklib.internal.repository.MockPlatformTarget; 21 import com.android.sdklib.internal.repository.packages.PlatformPackage; 22 import com.android.sdklib.internal.repository.sources.SdkSource; 23 import com.android.sdklib.repository.PkgProps; 24 25 import java.util.Properties; 26 27 /** 28 * A mock {@link PlatformPackage} for testing. 29 * 30 * By design, this package contains one and only one archive. 31 */ 32 public class MockPlatformPackage extends PlatformPackage { 33 34 private final IAndroidTarget mTarget; 35 36 /** 37 * Creates a {@link MockPlatformTarget} with the requested API and revision 38 * and then a {@link MockPlatformPackage} wrapping it. 39 * 40 * By design, this package contains one and only one archive. 41 */ 42 public MockPlatformPackage(int apiLevel, int revision) { 43 this(null /*source*/, new MockPlatformTarget(apiLevel, revision), null /*props*/); 44 } 45 46 /** 47 * Creates a {@link MockPlatformTarget} with the requested API and revision 48 * and then a {@link MockPlatformPackage} wrapping it. 49 * 50 * Also sets the min-tools-rev of the platform. 51 * 52 * By design, this package contains one and only one archive. 53 */ 54 public MockPlatformPackage(int apiLevel, int revision, int min_tools_rev) { 55 this(null /*source*/, 56 new MockPlatformTarget(apiLevel, revision), 57 createProps(min_tools_rev)); 58 } 59 60 public MockPlatformPackage(SdkSource source, int apiLevel, int revision, int min_tools_rev) { 61 this(source, new MockPlatformTarget(apiLevel, revision), createProps(min_tools_rev)); 62 } 63 64 /** A little trick to be able to capture the target new after passing it to the super. */ 65 private MockPlatformPackage(SdkSource source, IAndroidTarget target, Properties props) { 66 super(source, target, props); 67 mTarget = target; 68 } 69 70 private static Properties createProps(int min_tools_rev) { 71 Properties props = new Properties(); 72 props.setProperty(PkgProps.MIN_TOOLS_REV, Integer.toString((min_tools_rev))); 73 return props; 74 } 75 76 public IAndroidTarget getTarget() { 77 return mTarget; 78 } 79 } 80