Skip to content

Commit

Permalink
re-introduce check on tag alignment for a repository
Browse files Browse the repository at this point in the history
In the multimodule branch there was a check to ensure that all plugins
from a given repository use the same tag, but this was not carried over
in #510

this changes the assumption that the input is correct and could silently
provide invorrect results, to an explicit check that fails early before
starting to check compatability.

Only plugins that are being checked for compatability will be involved
in the repository.  This is to allows a war to contain a plugin that was
formerly in the repository that has been changed to just migrate data to
a new location (by adding a dependency on a replacement plugin) to still
be in the war, even after it has been deleted from the repository.
  • Loading branch information
jtnord committed Apr 19, 2023
1 parent 57c72c3 commit 67e313d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/org/jenkins/tools/test/PluginCompatTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
import org.jenkins.tools.test.exception.PluginCompatibilityTesterException;
import org.jenkins.tools.test.exception.PluginSourcesUnavailableException;
Expand Down Expand Up @@ -104,6 +106,18 @@ public void testPlugins() throws PluginCompatibilityTesterException {
} else {
List<Plugin> plugins = warExtractor.extractPlugins();
pluginsByRepository = WarExtractor.byRepository(plugins);

// Sanity check all plugins in the repository come from the same hash/tag
for (List<Plugin> pluginList : pluginsByRepository.values()) {
Set<String> tags = pluginList.stream().map(Plugin::getTag).collect(Collectors.toSet());
if (tags.size() != 1) {
throw new IllegalArgumentException("Repository "
+ pluginList.get(0).getGitUrl()
+ " present with multiple tags: "
+ String.join(", ", tags));
}
}

/*
* Run the before checkout hooks on everything that we are about to check out (as opposed to an existing local
* checkout).
Expand All @@ -126,7 +140,7 @@ public void testPlugins() throws PluginCompatibilityTesterException {
cloneDir = config.getLocalCheckoutDir();
} else {
cloneDir = new File(config.getWorkingDir(), getRepoNameFromGitUrl(gitUrl));
// All plugins from the same reactor are assumed to be of the same version
// All plugins from the same reactor are from the same tag
String tag = entry.getValue().get(0).getTag();

try {
Expand Down

0 comments on commit 67e313d

Please sign in to comment.