Search in sources :

Example 26 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class LintIdeClient method getBuildTools.

@Override
@Nullable
public BuildToolInfo getBuildTools(@NonNull com.android.tools.lint.detector.api.Project project) {
    if (project.isGradleProject()) {
        Module module = getModule();
        if (module != null) {
            AndroidModuleModel model = AndroidModuleModel.get(module);
            if (model != null) {
                GradleVersion version = model.getModelVersion();
                if (version != null && version.isAtLeast(2, 1, 0)) {
                    String buildToolsVersion = model.getAndroidProject().getBuildToolsVersion();
                    AndroidSdkHandler sdk = getSdk();
                    if (sdk != null) {
                        try {
                            Revision revision = Revision.parseRevision(buildToolsVersion);
                            BuildToolInfo buildToolInfo = sdk.getBuildToolInfo(revision, getRepositoryLogger());
                            if (buildToolInfo != null) {
                                return buildToolInfo;
                            }
                        } catch (NumberFormatException ignore) {
                        // Fall through and use the latest
                        }
                    }
                }
            }
        }
    }
    return super.getBuildTools(project);
}
Also used : Revision(com.android.repository.Revision) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Module(com.intellij.openapi.module.Module) GradleVersion(com.android.ide.common.repository.GradleVersion) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class IdeSdks method isJdk7Supported.

public boolean isJdk7Supported(@Nullable AndroidSdkData sdkData) {
    if (sdkData != null) {
        ProgressIndicator progress = new StudioLoggerProgressIndicator(Jdks.class);
        LocalPackage info = sdkData.getSdkHandler().getLocalPackage(SdkConstants.FD_PLATFORM_TOOLS, progress);
        if (info != null) {
            Revision revision = info.getVersion();
            if (revision.getMajor() >= 19) {
                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)) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) LocalPackage(com.android.repository.api.LocalPackage) Revision(com.android.repository.Revision) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) ProgressIndicator(com.android.repository.api.ProgressIndicator) SdkPaths.validateAndroidSdk(com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk)

Example 28 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class InstantRunConfigurable method updateProjectToInstantRunTools.

/** Update versions relevant for Instant Run, and trigger a Gradle sync if successful */
public static boolean updateProjectToInstantRunTools(@NotNull Project project, @Nullable GradleSyncListener listener) {
    String pluginVersion = MINIMUM_GRADLE_PLUGIN_VERSION_STRING;
    // Pick max version of "recommended Gradle plugin" and "minimum required for instant run"
    if (GradleVersion.parse(GRADLE_PLUGIN_RECOMMENDED_VERSION).compareTo(MINIMUM_GRADLE_PLUGIN_VERSION) > 0) {
        pluginVersion = GRADLE_PLUGIN_RECOMMENDED_VERSION;
    }
    // Update plugin version
    AndroidPluginVersionUpdater updater = AndroidPluginVersionUpdater.getInstance(project);
    UpdateResult result = updater.updatePluginVersion(GradleVersion.parse(pluginVersion), GradleVersion.parse(GRADLE_LATEST_VERSION));
    if (result.isPluginVersionUpdated() && result.versionUpdateSuccess()) {
        // Should be at least 23.0.2
        String buildToolsVersion = "23.0.2";
        AndroidSdkHandler sdk = AndroidSdks.getInstance().tryToChooseSdkHandler();
        BuildToolInfo latestBuildTool = sdk.getLatestBuildTool(new StudioLoggerProgressIndicator(InstantRunConfigurable.class), false);
        if (latestBuildTool != null) {
            Revision revision = latestBuildTool.getRevision();
            if (revision.compareTo(Revision.parseRevision(buildToolsVersion)) > 0) {
                buildToolsVersion = revision.toShortString();
            }
        }
        // Also update build files to set build tools version 23.0.2
        GradleUtil.setBuildToolsVersion(project, buildToolsVersion);
        // Also update Gradle wrapper version
        GradleWrapper gradleWrapper = GradleWrapper.find(project);
        if (gradleWrapper != null) {
            gradleWrapper.updateDistributionUrlAndDisplayFailure(GRADLE_LATEST_VERSION);
        }
        // Request a sync
        GradleSyncInvoker.Request request = new GradleSyncInvoker.Request().setRunInBackground(false);
        GradleSyncInvoker.getInstance().requestProjectSync(project, request, listener);
        return true;
    } else {
        return false;
    }
}
Also used : StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) GradleSyncInvoker(com.android.tools.idea.gradle.project.sync.GradleSyncInvoker) Revision(com.android.repository.Revision) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) AndroidPluginVersionUpdater(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater) UpdateResult(com.android.tools.idea.gradle.plugin.AndroidPluginVersionUpdater.UpdateResult) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper)

Example 29 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class InstallBuildToolsHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    List<String> requested = Lists.newArrayList();
    Revision minBuildToolsRev = Revision.parseRevision(myVersion);
    requested.add(DetailsTypes.getBuildToolsPath(minBuildToolsRev));
    ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(project, requested);
    if (dialog != null && dialog.showAndGet()) {
        if (myBuildFile != null) {
            setBuildToolsVersion(project, myBuildFile, myVersion, true);
        } else {
            GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, null);
        }
    }
}
Also used : Revision(com.android.repository.Revision) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog)

Example 30 with Revision

use of com.android.repository.Revision in project android by JetBrains.

the class SdkComponentSourceTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    //noinspection Convert2Lambda Since otherwise it desn't create new instances.
    myDisposable = new Disposable() {

        @Override
        public void dispose() {
        }
    };
    MockApplicationEx instance = new MockApplicationEx(myDisposable);
    instance.registerService(ExternalComponentManager.class, ExternalComponentManagerImpl.class);
    instance.registerService(UpdateSettings.class, UpdateSettings.class);
    ApplicationManager.setApplication(instance, myDisposable);
    myFileOp = new MockFileOp();
    myFileOp.recordExistingFile("/sdk/noRemote/package.xml", getLocalRepoXml("noRemote", new Revision(1)));
    myFileOp.recordExistingFile("/sdk/newerRemote/package.xml", getLocalRepoXml("newerRemote", new Revision(1)));
    myFileOp.recordExistingFile("/sdk/sameRemote/package.xml", getLocalRepoXml("sameRemote", new Revision(1)));
    myFileOp.recordExistingFile("/sdk/olderRemote/package.xml", getLocalRepoXml("olderRemote", new Revision(1, 2)));
    myFileOp.recordExistingFile("/sdk/hasPreview/package.xml", getLocalRepoXml("hasPreview", new Revision(1)));
    myFileOp.recordExistingFile("/sdk/newerPreview/package.xml", getLocalRepoXml("newerPreview", new Revision(1, 0, 0, 1)));
    myFileOp.recordExistingFile("/sdk/samePreview/package.xml", getLocalRepoXml("samePreview", new Revision(1, 0, 0, 1)));
    myFileOp.recordExistingFile("/sdk/olderPreview/package.xml", getLocalRepoXml("olderPreview", new Revision(2)));
    myFileOp.recordExistingFile("/sdk/zNewerInBeta/package.xml", getLocalRepoXml("zNewerInBeta", new Revision(1)));
    final FakeDownloader downloader = new FakeDownloader(myFileOp);
    List<String> remotePaths = Lists.newArrayList();
    List<Revision> remoteRevisions = Lists.newArrayList();
    List<Integer> remoteChannels = Lists.newArrayList();
    remotePaths.add("newerRemote");
    remoteRevisions.add(new Revision(1, 1));
    remoteChannels.add(0);
    remotePaths.add("sameRemote");
    remoteRevisions.add(new Revision(1));
    remoteChannels.add(0);
    remotePaths.add("olderRemote");
    remoteRevisions.add(new Revision(1, 1));
    remoteChannels.add(0);
    remotePaths.add("hasPreview");
    remoteRevisions.add(new Revision(1, 0, 0, 1));
    remoteChannels.add(0);
    remotePaths.add("newerPreview");
    remoteRevisions.add(new Revision(1, 0, 0, 2));
    remoteChannels.add(0);
    remotePaths.add("samePreview");
    remoteRevisions.add(new Revision(1, 0, 0, 1));
    remoteChannels.add(0);
    remotePaths.add("olderPreview");
    remoteRevisions.add(new Revision(1, 0, 0, 1));
    remoteChannels.add(0);
    remotePaths.add("onlyRemote");
    remoteRevisions.add(new Revision(1));
    remoteChannels.add(0);
    remotePaths.add("zNewerInBeta");
    remoteRevisions.add(new Revision(2));
    remoteChannels.add(1);
    String url = "http://example.com/repo";
    downloader.registerUrl(new URL(url), getRepoXml(remotePaths, remoteRevisions, remoteChannels, true).getBytes());
    final RepoManager mgr = new RepoManagerImpl(myFileOp);
    mgr.setLocalPath(new File("/sdk"));
    mgr.registerSchemaModule(AndroidSdkHandler.getRepositoryModule());
    mgr.registerSchemaModule(AndroidSdkHandler.getCommonModule());
    mgr.registerSourceProvider(new FakeRepositorySourceProvider(ImmutableList.<RepositorySource>of(new SimpleRepositorySource(url, "dummy", true, mgr.getSchemaModules(), null))));
    myChannelId = 0;
    myTestComponentSource = new SdkComponentSource() {

        @Nullable
        @Override
        public List<String> getAllChannels() {
            return null;
        }

        @Override
        @NotNull
        RepoManager getRepoManager() {
            return mgr;
        }

        @NotNull
        @Override
        SettingsController getSettingsController() {
            return new FakeSettingsController(false) {

                @Override
                public Channel getChannel() {
                    return Channel.create(myChannelId);
                }
            };
        }

        @NotNull
        @Override
        Downloader getDownloader(@Nullable ProgressIndicator indicator) {
            return downloader;
        }
    };
}
Also used : NotNull(org.jetbrains.annotations.NotNull) URL(java.net.URL) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ImmutableList(com.google.common.collect.ImmutableList) Disposable(com.intellij.openapi.Disposable) MockApplicationEx(com.intellij.mock.MockApplicationEx) RepoManagerImpl(com.android.repository.impl.manager.RepoManagerImpl) Revision(com.android.repository.Revision) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Revision (com.android.repository.Revision)37 Test (org.junit.Test)11 FakeRemotePackage (com.android.repository.testframework.FakePackage.FakeRemotePackage)10 FakeLocalPackage (com.android.repository.testframework.FakePackage.FakeLocalPackage)9 File (java.io.File)8 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)6 UpdatableExternalComponent (com.intellij.ide.externalComponents.UpdatableExternalComponent)6 Nullable (org.jetbrains.annotations.Nullable)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 LocalPackage (com.android.repository.api.LocalPackage)4 BuildToolInfo (com.android.sdklib.BuildToolInfo)4 StudioProgressIndicatorAdapter (com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter)4 NotNull (org.jetbrains.annotations.NotNull)4 Installer (com.android.repository.api.Installer)3 FakeDownloader (com.android.repository.testframework.FakeDownloader)3 AndroidSdkHandler (com.android.sdklib.repository.AndroidSdkHandler)3 ExternalUpdate (com.intellij.openapi.updateSettings.impl.ExternalUpdate)3 UpdateSettings (com.intellij.openapi.updateSettings.impl.UpdateSettings)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 GradleVersion (com.android.ide.common.repository.GradleVersion)2