Search in sources :

Example 1 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.

the class InstantRunPositionManager method getAllPlatformSourcePackages.

private static Collection<? extends LocalPackage> getAllPlatformSourcePackages() {
    AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
    RepoManager sdkManager = sdkHandler.getSdkManager(new StudioLoggerProgressIndicator(InstantRunPositionManager.class));
    return sdkManager.getPackages().getLocalPackagesForPrefix(SdkConstants.FD_ANDROID_SOURCES);
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) RepoManager(com.android.repository.api.RepoManager) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler)

Example 2 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.

the class UnresolvedDependenciesReporter method report.

private void report(@NotNull String dependency, @NotNull Module module, @Nullable VirtualFile buildFile) {
    String group = "Unresolved Android dependencies";
    GradleCoordinate coordinate = GradleCoordinate.parseCoordinateString(dependency);
    RepoPackage constraintPackage = null;
    if (coordinate != null) {
        ProgressIndicator indicator = new StudioLoggerProgressIndicator(getClass());
        reloadRemoteSdkWithModalProgress();
        Collection<RemotePackage> remotePackages = getRemotePackages(indicator);
        constraintPackage = findBestPackageMatching(coordinate, remotePackages);
    }
    List<NotificationHyperlink> quickFixes = new ArrayList<>();
    if (dependency.startsWith("com.android.support.constraint:constraint-layout:") && !canGetConstraintLayoutFromSdkManager(module)) {
        quickFixes.add(new FixAndroidGradlePluginVersionHyperlink());
    } else if (constraintPackage != null) {
        quickFixes.add(new InstallArtifactHyperlink(constraintPackage.getPath()));
    } else if (dependency.startsWith("com.android.support")) {
        quickFixes.add(new InstallRepositoryHyperlink(ANDROID));
    } else if (dependency.startsWith("com.google.android")) {
        quickFixes.add(new InstallRepositoryHyperlink(GOOGLE));
    } else {
        group = "Unresolved dependencies";
        Project project = module.getProject();
        if (isOfflineBuildModeEnabled(project)) {
            quickFixes.add(new DisableOfflineModeHyperlink());
        }
    }
    String text = "Failed to resolve: " + dependency;
    SyncMessage message;
    if (buildFile != null) {
        PositionInFile position = findDependencyPosition(dependency, buildFile);
        message = new SyncMessage(module.getProject(), group, ERROR, position, text);
        String hyperlinkText = position.line > -1 ? "Show in File" : "Open File";
        quickFixes.add(new OpenFileHyperlink(buildFile.getPath(), hyperlinkText, position.line, position.column));
    } else {
        message = new SyncMessage(group, ERROR, NonNavigatable.INSTANCE, text);
    }
    if (IdeInfo.getInstance().isAndroidStudio()) {
        if (coordinate != null) {
            quickFixes.add(new ShowDependencyInProjectStructureHyperlink(module, coordinate));
        }
    }
    message.add(quickFixes);
    getSyncMessages(module).report(message);
}
Also used : GradleCoordinate(com.android.ide.common.repository.GradleCoordinate) ArrayList(java.util.ArrayList) PositionInFile(com.android.tools.idea.gradle.util.PositionInFile) StringUtil.unquoteString(com.intellij.openapi.util.text.StringUtil.unquoteString) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Project(com.intellij.openapi.project.Project) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) RemotePackage(com.android.repository.api.RemotePackage) RepoPackage(com.android.repository.api.RepoPackage)

Example 3 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.

the class FormFactorApiComboBox method deriveValues.

/**
   * Fill in the values that can be derived from the selected min SDK level:
   *
   * minApiLevel will be set to the selected api level (string or number)
   * minApi will be set to the numerical equivalent
   * buildApi will be set to the highest installed platform, or to the preview platform if a preview is selected
   * buildApiString will be set to the corresponding string
   * targetApi will be set to the highest installed platform or to the preview platform if a preview is selected
   * targetApiString will be set to the corresponding string
   *
   * @param stateStore
   * @param modified
   */
public void deriveValues(@NotNull ScopedStateStore stateStore, @NotNull Set<Key> modified) {
    if (modified.contains(myTargetComboBoxKey) || modified.contains(myInclusionKey)) {
        // First remove the last request, no need to install more than one platform
        if (!myInstallRequests.isEmpty()) {
            for (String request : myInstallRequests) {
                stateStore.listRemove(INSTALL_REQUESTS_KEY, request);
            }
            myInstallRequests.clear();
        }
        // If this form factor is not included then there is nothing to do:
        AndroidTargetComboBoxItem targetItem = stateStore.get(myTargetComboBoxKey);
        if (targetItem == null || !stateStore.getNotNull(myInclusionKey, false)) {
            return;
        }
        stateStore.put(FormFactorUtils.getMinApiKey(myFormFactor), targetItem.getData());
        stateStore.put(FormFactorUtils.getMinApiLevelKey(myFormFactor), targetItem.myApiLevel);
        IAndroidTarget target = targetItem.target;
        if (target != null && (target.getVersion().isPreview() || !target.isPlatform())) {
            // Make sure we set target and build to the preview version as well
            populateApiLevels(targetItem.myApiLevel, target, stateStore);
        } else {
            int targetApiLevel;
            if (ourHighestInstalledApiTarget != null) {
                targetApiLevel = ourHighestInstalledApiTarget.getVersion().getFeatureLevel();
            } else {
                targetApiLevel = 0;
            }
            populateApiLevels(targetApiLevel, ourHighestInstalledApiTarget, stateStore);
        }
        AndroidVersion androidVersion = targetItem.myAndroidVersion;
        String platformPath = DetailsTypes.getPlatformPath(androidVersion);
        // Update build tools: use preview versions with preview platforms, etc
        BuildToolInfo buildTool = (target == null) ? null : target.getBuildToolInfo();
        if (buildTool == null) {
            final AndroidSdkHandler sdkHandler = AndroidSdks.getInstance().tryToChooseSdkHandler();
            buildTool = sdkHandler.getLatestBuildTool(new StudioLoggerProgressIndicator(ConfigureAndroidProjectPath.class), false);
        }
        if (buildTool != null) {
            stateStore.put(WizardConstants.BUILD_TOOLS_VERSION_KEY, buildTool.getRevision().toString());
        }
        // Check to see if this is installed. If not, request that we install it
        if (targetItem.myAddon != null) {
            // The user selected a non platform SDK (e.g. for Google Glass). Let us install it:
            String packagePath = targetItem.myAddon.getPath();
            stateStore.listPush(INSTALL_REQUESTS_KEY, packagePath);
            myInstallRequests.add(packagePath);
            // We also need the platform if not already installed:
            AndroidTargetManager targetManager = AndroidSdks.getInstance().tryToChooseSdkHandler().getAndroidTargetManager(REPO_LOG);
            if (targetManager.getTargetFromHashString(AndroidTargetHash.getPlatformHashString(androidVersion), REPO_LOG) == null) {
                stateStore.listPush(INSTALL_REQUESTS_KEY, platformPath);
                myInstallRequests.add(platformPath);
            }
            // The selected minVersion should also be the buildApi:
            populateApiLevels(targetItem.myApiLevel, null, stateStore);
        } else if (target == null) {
            // unlikely, so this logic can wait for a followup CL.
            if (ourHighestInstalledApiTarget == null || (androidVersion.getApiLevel() > ourHighestInstalledApiTarget.getVersion().getApiLevel() && !ourInstalledVersions.contains(androidVersion))) {
                // Let us install the HIGHEST_KNOWN_STABLE_API.
                platformPath = DetailsTypes.getPlatformPath(new AndroidVersion(SdkVersionInfo.HIGHEST_KNOWN_STABLE_API, null));
                stateStore.listPush(INSTALL_REQUESTS_KEY, platformPath);
                myInstallRequests.add(platformPath);
                // HIGHEST_KNOWN_STABLE_API would also be the highest sdkVersion after this install, so specify buildApi again here:
                populateApiLevels(SdkVersionInfo.HIGHEST_KNOWN_STABLE_API, null, stateStore);
            }
        }
        PropertiesComponent.getInstance().setValue(getPropertiesComponentMinSdkKey(myFormFactor), targetItem.getData());
        // Check Java language level; should be 7 for L; eventually this will be automatically defaulted by the Android Gradle plugin
        // instead: https://code.google.com/p/android/issues/detail?id=76252
        String javaVersion = null;
        if (ourHighestInstalledApiTarget != null && ourHighestInstalledApiTarget.getVersion().getFeatureLevel() >= 21) {
            AndroidSdkData sdkData = AndroidSdks.getInstance().tryToChooseAndroidSdk();
            if (sdkData != null) {
                JavaSdk jdk = JavaSdk.getInstance();
                Sdk sdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(jdk);
                if (sdk != null) {
                    JavaSdkVersion version = jdk.getVersion(sdk);
                    if (version != null && version.isAtLeast(JavaSdkVersion.JDK_1_7)) {
                        javaVersion = JavaSdkVersion.JDK_1_7.getDescription();
                    }
                }
            }
        }
        stateStore.put(FormFactorUtils.getLanguageLevelKey(myFormFactor), javaVersion);
    }
}
Also used : JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) AndroidTargetManager(com.android.sdklib.repository.targets.AndroidTargetManager) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 4 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.

the class IdeSdks method getAndroidNdkPath.

@Nullable
public File getAndroidNdkPath() {
    AndroidSdkHandler sdkHandler = myAndroidSdks.tryToChooseSdkHandler();
    LocalPackage ndk = sdkHandler.getLocalPackage(SdkConstants.FD_NDK, new StudioLoggerProgressIndicator(IdeSdks.class));
    return ndk == null ? null : ndk.getLocation();
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) LocalPackage(com.android.repository.api.LocalPackage) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with StudioLoggerProgressIndicator

use of com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator in project android by JetBrains.

the class SystemInfoStatsMonitor method runEmulatorCheck.

@Nullable
private static Integer runEmulatorCheck(@NotNull String argument, @NotNull Revision lowestToolsRevisiion, @NotNull AndroidSdkHandler handler) throws ExecutionException {
    LocalPackage toolsPackage = handler.getLocalPackage(SdkConstants.FD_TOOLS, new StudioLoggerProgressIndicator(AndroidSdkInitializer.class));
    if (toolsPackage == null) {
        throw new ExecutionException("No SDK tools package");
    }
    final Revision toolsRevision = toolsPackage.getVersion();
    if (toolsRevision.compareTo(lowestToolsRevisiion) < 0) {
        return null;
    }
    File checkBinary = getEmulatorCheckBinary(handler);
    if (!checkBinary.isFile()) {
        throw new ExecutionException("No emulator-check binary in the SDK tools package");
    }
    GeneralCommandLine commandLine = new GeneralCommandLine(checkBinary.getPath(), argument);
    CapturingAnsiEscapesAwareProcessHandler process = new CapturingAnsiEscapesAwareProcessHandler(commandLine);
    ProcessOutput output = process.runProcess();
    int exitCode = output.getExitCode();
    if (exitCode == EMULATOR_CHECK_ERROR_EXIT_CODE) {
        throw new ExecutionException(String.format("Emulator-check failed to check for '%s' with a generic error code %d", argument, EMULATOR_CHECK_ERROR_EXIT_CODE));
    }
    return exitCode;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) LocalPackage(com.android.repository.api.LocalPackage) AndroidSdkInitializer(com.android.tools.idea.startup.AndroidSdkInitializer) Revision(com.android.repository.Revision) CapturingAnsiEscapesAwareProcessHandler(com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ProcessOutput(com.intellij.execution.process.ProcessOutput) ExecutionException(com.intellij.execution.ExecutionException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)40 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)22 File (java.io.File)11 Nullable (org.jetbrains.annotations.Nullable)9 RepoManager (com.android.repository.api.RepoManager)8 StudioDownloader (com.android.tools.idea.sdk.StudioDownloader)8 ProgressIndicator (com.android.repository.api.ProgressIndicator)7 Revision (com.android.repository.Revision)6 LocalPackage (com.android.repository.api.LocalPackage)6 RemotePackage (com.android.repository.api.RemotePackage)6 BuildToolInfo (com.android.sdklib.BuildToolInfo)6 NotNull (org.jetbrains.annotations.NotNull)6 IAndroidTarget (com.android.sdklib.IAndroidTarget)4 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)4 VisibleForTesting (com.android.annotations.VisibleForTesting)3 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)3 RepositoryPackages (com.android.repository.impl.meta.RepositoryPackages)3 GradleSyncInvoker (com.android.tools.idea.gradle.project.sync.GradleSyncInvoker)3 StudioProgressRunner (com.android.tools.idea.sdk.progress.StudioProgressRunner)3 ImmutableList (com.google.common.collect.ImmutableList)3