Search in sources :

Example 36 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class InstallTaskTest method setUp.

@Before
public void setUp() {
    Mockito.when(myExisting1.getPath()).thenReturn("p1");
    Mockito.when(myAvailable1.getPath()).thenReturn("p2");
    Mockito.when(myAvailable2.getPath()).thenReturn("p3");
    RepositoryPackages repoPackages = new RepositoryPackages(ImmutableList.of(myExisting1), ImmutableList.of(myAvailable1, myAvailable2));
    AndroidSdkHandler repoHandler = new AndroidSdkHandler(SDK_ROOT, null, myFileOp, new FakeRepoManager(SDK_ROOT, repoPackages));
    RepoManager repoManager = repoHandler.getSdkManager(myProgressIndicator);
    myInstallTask = new InstallTask(factory, repoHandler, new FakeSettingsController(false), myProgressIndicator);
    myInstallTask.setInstallRequests(ImmutableList.of(new UpdatablePackage(myAvailable1), new UpdatablePackage(myAvailable2)));
    myInstallTask.setUninstallRequests(ImmutableList.of(myExisting1));
    Mockito.when(myInstaller.prepare(myProgressIndicator)).thenReturn(true);
    Mockito.when(myInstaller2.prepare(myProgressIndicator)).thenReturn(true);
    Mockito.when(myUninstaller.prepare(myProgressIndicator)).thenReturn(true);
    Mockito.when(myInstaller.complete(myProgressIndicator)).thenReturn(true);
    Mockito.when(myInstaller2.complete(myProgressIndicator)).thenReturn(true);
    Mockito.when(myUninstaller.complete(myProgressIndicator)).thenReturn(true);
    myOperations = new HashMap<>();
    myOperations.put(myExisting1, myUninstaller);
    myOperations.put(myAvailable1, myInstaller);
    myOperations.put(myAvailable2, myInstaller2);
    Mockito.when(factory.createInstaller(eq(myAvailable1), eq(repoManager), any(), eq(myFileOp))).thenReturn(myInstaller);
    Mockito.when(factory.createInstaller(eq(myAvailable2), eq(repoManager), any(), eq(myFileOp))).thenReturn(myInstaller2);
    Mockito.when(factory.createUninstaller(myExisting1, repoManager, myFileOp)).thenReturn(myUninstaller);
}
Also used : RepositoryPackages(com.android.repository.impl.meta.RepositoryPackages) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) FakeRepoManager(com.android.repository.testframework.FakeRepoManager) FakeSettingsController(com.android.repository.testframework.FakeSettingsController) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Before(org.junit.Before)

Example 37 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class AndroidSdksTest method testTryToChooseSdkHandler.

public void testTryToChooseSdkHandler() {
    myAndroidSdks.create(findAndroidTarget(), mySdkPath, myJdk, false);
    AndroidSdkHandler sdkHandler = myAndroidSdks.tryToChooseSdkHandler();
    AndroidSdkData sdkData = getSdkData(mySdkPath);
    assertNotNull(sdkData);
    assertSame(sdkData.getSdkHandler(), sdkHandler);
}
Also used : AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler)

Example 38 with AndroidSdkHandler

use of com.android.sdklib.repository.AndroidSdkHandler in project android by JetBrains.

the class AndroidJpsUtil method getAndroidTarget.

@Nullable
public static Pair<IAndroidTarget, AndroidSdkHandler> getAndroidTarget(@NotNull JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> sdk, @Nullable CompileContext context, String builderName) {
    JpsAndroidSdkProperties sdkProperties = sdk.getSdkProperties().getData();
    final String targetHashString = sdkProperties.getBuildTargetHashString();
    if (targetHashString == null) {
        if (context != null) {
            context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, "Cannot parse SDK " + sdk.getParent().getName() + ": build target is not specified"));
        }
        return null;
    }
    final AndroidSdkHandler sdkHandler = AndroidSdkHandler.getInstance(new File(sdk.getHomePath()));
    RepoLogger log = new RepoLogger();
    final IAndroidTarget target = sdkHandler.getAndroidTargetManager(log).getTargetFromHashString(targetHashString, log);
    if (target == null) {
        if (context != null) {
            context.processMessage(new CompilerMessage(builderName, BuildMessage.Kind.ERROR, "Cannot parse SDK '" + sdk.getParent().getName() + "': unknown target " + targetHashString));
        }
        return null;
    }
    return Pair.create(target, sdkHandler);
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) IAndroidTarget(com.android.sdklib.IAndroidTarget) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)38 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)23 File (java.io.File)11 Nullable (org.jetbrains.annotations.Nullable)11 RepoManager (com.android.repository.api.RepoManager)10 NotNull (org.jetbrains.annotations.NotNull)9 RemotePackage (com.android.repository.api.RemotePackage)8 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)8 ProgressIndicator (com.android.repository.api.ProgressIndicator)6 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)6 BuildToolInfo (com.android.sdklib.BuildToolInfo)6 IAndroidTarget (com.android.sdklib.IAndroidTarget)6 StudioProgressRunner (com.android.tools.idea.sdk.progress.StudioProgressRunner)6 ImmutableList (com.google.common.collect.ImmutableList)4 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)3 Revision (com.android.repository.Revision)3 LocalPackage (com.android.repository.api.LocalPackage)3 RepoPackage (com.android.repository.api.RepoPackage)3 FakeRepoManager (com.android.repository.testframework.FakeRepoManager)3 MockFileOp (com.android.repository.testframework.MockFileOp)3