-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not iterate through transient plugin dependencies if a newer dependency version is explicitly defined in the plugin list #102
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8f01fd1
Reproduce #101 in tests
oleg-nenashev 1b20071
Ensure that the plugin manager does not resolve subdependencies when …
oleg-nenashev 6487bfb
Use local archived resources for testing
oleg-nenashev f4087fe
Update plugin-management-library/src/main/java/io/jenkins/tools/plugi…
oleg-nenashev 5f43697
Migrate the dependency resolution test to the new test framework
oleg-nenashev e2d62bb
Add support for empty dependencies without download
oleg-nenashev 3f4ea55
Expect the request top-level plugins in the tests
oleg-nenashev b23e7fd
Add ZIP Resources to the test
oleg-nenashev 9ecbe57
Checkstyle...
oleg-nenashev f823428
Checkstyle...
oleg-nenashev 4c29c9b
Checkstyle?
oleg-nenashev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
...brary/src/test/java/io/jenkins/tools/pluginmanager/impl/PluginManagerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package io.jenkins.tools.pluginmanager.impl; | ||
|
||
import hudson.util.VersionNumber; | ||
import io.jenkins.tools.pluginmanager.config.Config; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
import org.apache.commons.io.IOUtils; | ||
import org.json.JSONObject; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.contrib.java.lang.system.SystemOutRule; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* Tests for {@link PluginManager} which operate with real data. | ||
* No mocks here. | ||
*/ | ||
public class PluginManagerIntegrationTest { | ||
|
||
static JSONObject latestUcJson; | ||
static File pluginVersionsFile; | ||
|
||
@ClassRule | ||
public static TemporaryFolder tmp = new TemporaryFolder(); | ||
public static File jenkinsWar; | ||
public static File cacheDir; | ||
public static File pluginsDir; | ||
|
||
@Rule | ||
public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); | ||
|
||
// TODO: Convert to a rule | ||
public interface Configurator { | ||
void configure(Config.Builder configBuilder); | ||
} | ||
|
||
public static PluginManager initPluginManager(Configurator configurator) throws IOException { | ||
Config.Builder configBuilder = Config.builder() | ||
.withJenkinsWar(jenkinsWar.getAbsolutePath()) | ||
.withPluginDir(pluginsDir) | ||
.withShowAvailableUpdates(true) | ||
.withIsVerbose(true) | ||
.withDoDownload(false); | ||
configurator.configure(configBuilder); | ||
Config config = configBuilder.build(); | ||
|
||
PluginManager pluginManager = new PluginManager(config); | ||
pluginManager.setCm(new CacheManager(cacheDir.toPath(), true)); | ||
pluginManager.setJenkinsVersion(new VersionNumber("2.222.1")); | ||
pluginManager.setLatestUcJson(latestUcJson); | ||
pluginManager.setLatestUcPlugins(latestUcJson.getJSONObject("plugins")); | ||
pluginManager.setPluginInfoJson(pluginManager.getJson(pluginVersionsFile.toURI().toURL(), "plugin-versions")); | ||
|
||
return pluginManager; | ||
} | ||
|
||
private static void unzipResource(Class clazz, String resourceName, String fileName, File target) throws IOException { | ||
final File archivePath = new File(tmp.getRoot(), target.toPath().getFileName() + ".zip"); | ||
try (InputStream archive = clazz.getResourceAsStream(resourceName)) { | ||
if (archive == null) { | ||
throw new IOException("Cannot find " + resourceName + " in " + clazz); | ||
} | ||
Files.copy(archive, archivePath.toPath()); | ||
} | ||
|
||
try (ZipFile zip = new ZipFile(archivePath)){ | ||
ZipEntry entry = zip.getEntry(fileName); | ||
if (entry == null) { | ||
throw new IOException(String.format("Cannot find file %s within ZIP resource %s/%s", fileName, clazz.getName(), resourceName)); | ||
} | ||
try(InputStream archive = zip.getInputStream(entry)) { | ||
Files.copy(archive, target.toPath()); | ||
} | ||
} | ||
} | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
File updatesJSON = new File(tmp.getRoot(), "updates.json"); | ||
unzipResource(PluginManagerIntegrationTest.class, "updates.zip", "updates.json", updatesJSON); | ||
try (InputStream istream = new FileInputStream(updatesJSON)) { | ||
latestUcJson = new JSONObject(IOUtils.toString(istream, StandardCharsets.UTF_8)); | ||
} | ||
|
||
pluginVersionsFile = new File(tmp.getRoot(), "plugin-versions.json"); | ||
unzipResource(PluginManagerIntegrationTest.class, "plugin-versions.zip", "plugin-versions.json", pluginVersionsFile); | ||
|
||
//TODO: Use real 2.222.1 war instead | ||
jenkinsWar = new File(tmp.getRoot(), "jenkins.war"); | ||
try(InputStream war = PluginManagerIntegrationTest.class.getResourceAsStream("/bundledplugintest.war")) { | ||
Files.copy(war, jenkinsWar.toPath()); | ||
} | ||
|
||
cacheDir = tmp.newFolder("cache"); | ||
pluginsDir = tmp.newFolder("pluginsDir"); | ||
} | ||
|
||
// https://github.com/jenkinsci/plugin-installation-manager-tool/issues/101 | ||
@Test | ||
public void showAvailableUpdates_shouldNotFailOnUIThemes() throws IOException { | ||
Plugin pluginDockerCommons = new Plugin("docker-commons", "1.16", null, null); | ||
Plugin pluginYAD = new Plugin("yet-another-docker-plugin", "0.2.0", null, null); | ||
Plugin pluginIconShim = new Plugin("icon-shim", "2.0.3", null, null); | ||
PluginManager pluginManager = initPluginManager( | ||
configBuilder -> configBuilder.withPlugins(Arrays.asList(pluginDockerCommons, pluginIconShim, pluginYAD))); | ||
|
||
pluginManager.start(false); | ||
assertThat(systemOutRule.getLog(), not(containsString("uithemes"))); | ||
} | ||
|
||
@Test | ||
public void findPluginsAndDependenciesTest() throws IOException { | ||
Plugin plugin1 = new Plugin("plugin1", "1.0", null, null); | ||
Plugin replaced = new Plugin("replaced", "1.0", null, null).withoutDependencies(); | ||
Plugin plugin2 = new Plugin("plugin2", "2.0", null, null); | ||
Plugin plugin3 = new Plugin("plugin3", "3.0", null, null); | ||
|
||
Plugin plugin1Dependency1 = new Plugin("plugin1Dependency1", "1.0.1", null, null).withoutDependencies(); | ||
Plugin plugin1Dependency2 = new Plugin("plugin1Dependency2", "1.0.2", null, null).withoutDependencies(); | ||
Plugin replaced1 = new Plugin("replaced", "1.0.1", null, null).withoutDependencies(); | ||
plugin1.setDependencies(Arrays.asList(plugin1Dependency1, plugin1Dependency2, replaced1)); | ||
|
||
Plugin plugin2Dependency1 = new Plugin("plugin2Dependency1", "2.0.1", null, null).withoutDependencies(); | ||
Plugin plugin2Dependency2 = new Plugin("plugin2Dependency2", "2.0.2", null, null).withoutDependencies(); | ||
Plugin replaced2 = new Plugin("replaced", "2.0.2", null, null).withoutDependencies(); | ||
Plugin replacedSecond = new Plugin("replaced2", "2.0.2", null, null).withoutDependencies(); | ||
plugin2.setDependencies(Arrays.asList(plugin2Dependency1, plugin2Dependency2, replaced2, replacedSecond)); | ||
|
||
Plugin plugin3Dependency1 = new Plugin("plugin3Dependency1", "3.0.1", null, null).withoutDependencies(); | ||
Plugin replacedSecond2 = new Plugin("replaced2", "3.2", null, null).withoutDependencies(); | ||
plugin3.setDependencies(Arrays.asList(plugin3Dependency1, replacedSecond2)); | ||
|
||
// Expected | ||
List<Plugin> expectedPlugins = new ArrayList<>(Arrays.asList(plugin1, plugin1Dependency1, plugin1Dependency2, | ||
plugin2Dependency1, plugin2, plugin2Dependency2, plugin3, plugin3Dependency1, replaced2, replacedSecond2)); | ||
Collections.sort(expectedPlugins); | ||
|
||
// Actual | ||
List<Plugin> requestedPlugins = new ArrayList<>(Arrays.asList(plugin1, plugin2, plugin3, replaced)); | ||
PluginManager pluginManager = initPluginManager( | ||
configBuilder -> configBuilder.withPlugins(requestedPlugins)); | ||
List<Plugin> pluginsAndDependencies = new ArrayList<>(pluginManager.findPluginsAndDependencies(requestedPlugins).values()); | ||
Collections.sort(pluginsAndDependencies); | ||
|
||
assertEquals(expectedPlugins, pluginsAndDependencies); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO there should be an error by default, but it is not how the tests are written now
Skipping it for now, original test from @stopalopa will fail