From 0b90752bb2c8ac82c09b78afdb84aff8e050ddf4 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 6 May 2015 13:17:24 +0200 Subject: [PATCH] custom repositories: use only compatible plugins from host test --- .../updateSettings/impl/UpdateChecker.java | 10 ++-- .../plugin1.xml | 11 ++++ .../plugin2.xml | 11 ++++ ...UpdatePluginsFromCustomRepositoryTest.java | 60 +++++++++++++++++++ 4 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 platform/platform-tests/testData/updates/customRepositories/onlyCompatiblePluginsAreChecked/plugin1.xml create mode 100644 platform/platform-tests/testData/updates/customRepositories/onlyCompatiblePluginsAreChecked/plugin2.xml create mode 100644 platform/platform-tests/testSrc/com/intellij/openapi/updateSettings/UpdatePluginsFromCustomRepositoryTest.java diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java index 187364b26f36..a0033329711e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java @@ -312,11 +312,11 @@ public final class UpdateChecker { return toUpdate.isEmpty() ? null : toUpdate.values(); } - private static void checkAndPrepareToInstall(PluginDownloader downloader, - InstalledPluginsState state, - Map toUpdate, - Collection incompatiblePlugins, - @Nullable ProgressIndicator indicator) throws IOException { + public static void checkAndPrepareToInstall(PluginDownloader downloader, + InstalledPluginsState state, + Map toUpdate, + Collection incompatiblePlugins, + @Nullable ProgressIndicator indicator) throws IOException { String pluginId = downloader.getPluginId(); if (PluginManagerCore.getDisabledPlugins().contains(pluginId)) return; diff --git a/platform/platform-tests/testData/updates/customRepositories/onlyCompatiblePluginsAreChecked/plugin1.xml b/platform/platform-tests/testData/updates/customRepositories/onlyCompatiblePluginsAreChecked/plugin1.xml new file mode 100644 index 000000000000..21467d4fbd28 --- /dev/null +++ b/platform/platform-tests/testData/updates/customRepositories/onlyCompatiblePluginsAreChecked/plugin1.xml @@ -0,0 +1,11 @@ + + + + testPluginId + + Copyright Notice. This plugin is used to ensure files in a project or module have + a consistent copyright notice. + + 0.1 + + diff --git a/platform/platform-tests/testData/updates/customRepositories/onlyCompatiblePluginsAreChecked/plugin2.xml b/platform/platform-tests/testData/updates/customRepositories/onlyCompatiblePluginsAreChecked/plugin2.xml new file mode 100644 index 000000000000..e1985c3d4c3b --- /dev/null +++ b/platform/platform-tests/testData/updates/customRepositories/onlyCompatiblePluginsAreChecked/plugin2.xml @@ -0,0 +1,11 @@ + + + + testPluginId + + Copyright Notice. This plugin is used to ensure files in a project or module have + a consistent copyright notice. + + 0.2 + + diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/updateSettings/UpdatePluginsFromCustomRepositoryTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/updateSettings/UpdatePluginsFromCustomRepositoryTest.java new file mode 100644 index 000000000000..629894b09cf2 --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/openapi/updateSettings/UpdatePluginsFromCustomRepositoryTest.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * 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.intellij.openapi.updateSettings; + +import com.intellij.ide.plugins.IdeaPluginDescriptor; +import com.intellij.ide.plugins.IdeaPluginDescriptorImpl; +import com.intellij.ide.plugins.InstalledPluginsState; +import com.intellij.openapi.extensions.PluginId; +import com.intellij.openapi.updateSettings.impl.PluginDownloader; +import com.intellij.openapi.updateSettings.impl.UpdateChecker; +import com.intellij.openapi.updateSettings.impl.UpdateSettings; +import com.intellij.openapi.util.BuildNumber; +import com.intellij.openapi.util.InvalidDataException; +import com.intellij.testFramework.PlatformTestCase; +import com.intellij.testFramework.PlatformTestUtil; +import org.junit.Assert; + +import java.io.File; +import java.io.FileNotFoundException; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +public class UpdatePluginsFromCustomRepositoryTest extends PlatformTestCase { + public void testOnlyCompatiblePluginsAreChecked() throws Exception { + final LinkedHashMap toUpdate = new LinkedHashMap(); + final IdeaPluginDescriptor[] descriptors = new IdeaPluginDescriptor[] {loadDescriptor("plugin1.xml"), loadDescriptor("plugin2.xml")}; + + final BuildNumber currentBuildNumber = BuildNumber.fromString("IU-142.100"); + for (IdeaPluginDescriptor descriptor : descriptors) { + UpdateChecker.checkAndPrepareToInstall(PluginDownloader.createDownloader(descriptor, null, currentBuildNumber), new InstalledPluginsState(new UpdateSettings()), + toUpdate, new ArrayList(), null); + } + Assert.assertEquals("Found: " + toUpdate.size(), 1, toUpdate.size()); + final PluginDownloader downloader = toUpdate.values().iterator().next(); + Assert.assertNotNull(downloader); + Assert.assertEquals("0.1", downloader.getPluginVersion()); + } + + private IdeaPluginDescriptor loadDescriptor(String filePath) throws InvalidDataException, FileNotFoundException, MalformedURLException { + String path = PlatformTestUtil.getCommunityPath() + "/platform/platform-tests/testData/updates/customRepositories/" + getTestName(true) + "/"; + final File descriptorFile = new File(path, filePath); + IdeaPluginDescriptorImpl descriptor = new IdeaPluginDescriptorImpl(descriptorFile.getParentFile()); + descriptor.readExternal(descriptorFile.toURI().toURL()); + return descriptor; + } +}