Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #121 from escoem/JENKINS-47779
[FIXED JENKINS-47779] Could not attach 'plugins/active.txt' to support bundle
  • Loading branch information
batmat committed Nov 13, 2017
2 parents 9fc6229 + 292dbb4 commit eabbb45
Showing 1 changed file with 61 additions and 39 deletions.
100 changes: 61 additions & 39 deletions src/main/java/com/cloudbees/jenkins/support/impl/AboutJenkins.java
Expand Up @@ -62,6 +62,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -106,15 +107,19 @@ public String getDisplayName() {

@Override
public void addContents(@NonNull Container container) {
container.add(new AboutContent());
List<PluginWrapper> activePlugins = new ArrayList<PluginWrapper>();
List<PluginWrapper> disabledPlugins = new ArrayList<PluginWrapper>();

populatePluginsLists(activePlugins, disabledPlugins);

container.add(new AboutContent(activePlugins));
container.add(new ItemsContent());
container.add(new NodesContent());
container.add(new ActivePlugins("plugins/active.txt"));
container.add(new DisabledPlugins());
container.add(new ActivePlugins(activePlugins));
container.add(new DisabledPlugins(disabledPlugins));
container.add(new FailedPlugins());

// container.add(new ActivePlugins("docker/plugins.txt"));
container.add(new Dockerfile());
container.add(new Dockerfile(activePlugins, disabledPlugins));

container.add(new MasterChecksumsContent());
for (final Node node : Helper.getActiveInstance().getNodes()) {
Expand Down Expand Up @@ -539,8 +544,11 @@ public synchronized int n() {
}

private static class AboutContent extends PrintedContent {
AboutContent() {
private final Iterable<PluginWrapper> plugins;

AboutContent(Iterable<PluginWrapper> plugins) {
super("about.md");
this.plugins = plugins;
}
@Override protected void printTo(PrintWriter out) throws IOException {
final Jenkins jenkins = Helper.getActiveInstance();
Expand Down Expand Up @@ -582,9 +590,7 @@ private static class AboutContent extends PrintedContent {
out.println("Active Plugins");
out.println("--------------");
out.println();
PluginManager pluginManager = jenkins.getPluginManager();
List<PluginWrapper> plugins = new ArrayList<PluginWrapper>(pluginManager.getPlugins());
Collections.sort(plugins);

for (PluginWrapper w : plugins) {
if (w.isActive()) {
out.println(" * " + w.getShortName() + ":" + w.getVersion() + (w.hasUpdate()
Expand Down Expand Up @@ -698,37 +704,33 @@ private static class ItemsContent extends PrintedContent {
}

private static class ActivePlugins extends PrintedContent {
public ActivePlugins(String path) {
super(path);
private final Iterable<PluginWrapper> plugins;

public ActivePlugins(Iterable<PluginWrapper> plugins) {
super("plugins/active.txt");
this.plugins = plugins;
}

@Override
protected void printTo(PrintWriter out) throws IOException {
PluginManager pluginManager = Helper.getActiveInstance().getPluginManager();
List<PluginWrapper> plugins = pluginManager.getPlugins();
Collections.sort(plugins);
for (PluginWrapper w : plugins) {
if (w.isActive()) {
out.println(w.getShortName() + ":" + w.getVersion() + ":" + (w.isPinned() ? "pinned" : "not-pinned"));
}
out.println(w.getShortName() + ":" + w.getVersion() + ":" + (w.isPinned() ? "pinned" : "not-pinned"));
}
}
}

private static class DisabledPlugins extends PrintedContent {
public DisabledPlugins() {
private final Iterable<PluginWrapper> plugins;

public DisabledPlugins(Iterable<PluginWrapper> plugins) {
super("plugins/disabled.txt");
this.plugins = plugins;
}

@Override
protected void printTo(PrintWriter out) throws IOException {
PluginManager pluginManager = Helper.getActiveInstance().getPluginManager();
List<PluginWrapper> plugins = pluginManager.getPlugins();
Collections.sort(plugins);
for (PluginWrapper w : plugins) {
if (!w.isActive()) {
out.println(w.getShortName() + ":" + w.getVersion() + ":" + (w.isPinned() ? "pinned" : "not-pinned"));
}
out.println(w.getShortName() + ":" + w.getVersion() + ":" + (w.isPinned() ? "pinned" : "not-pinned"));
}
}
}
Expand All @@ -750,8 +752,13 @@ protected void printTo(PrintWriter out) throws IOException {
}

private static class Dockerfile extends PrintedContent {
public Dockerfile() {
private final List<PluginWrapper> activated;
private final List<PluginWrapper> disabled;

public Dockerfile(List<PluginWrapper> activated, List<PluginWrapper> disabled) {
super("docker/Dockerfile");
this.activated = activated;
this.disabled = disabled;
}

@Override
Expand All @@ -771,20 +778,6 @@ protected void printTo(PrintWriter out) throws IOException {

out.println("RUN mkdir -p /usr/share/jenkins/ref/plugins/");

List<PluginWrapper> plugins = pluginManager.getPlugins();
Collections.sort(plugins);

List<PluginWrapper> activated = new ArrayList<PluginWrapper>();
List<PluginWrapper> disabled = new ArrayList<PluginWrapper>();
for (PluginWrapper w : plugins) {
if (!w.isEnabled()) {
disabled.add(w);
}
if (w.isActive()) {
activated.add(w);
}
}

out.println("RUN curl \\");
Iterator<PluginWrapper> activatedIT = activated.iterator();
while (activatedIT.hasNext()) {
Expand Down Expand Up @@ -1010,4 +1003,33 @@ private class NodeChecksumsContent extends PrintedContent {
}
}

/**
* Fixes JENKINS-47779 caused by JENKINS-47713
* Not using SortedSet because of PluginWrapper doesn't implements equals and hashCode.
* @return new copy of the PluginManager.getPlugins sorted
*/
private static Iterable<PluginWrapper> getPluginsSorted() {
PluginManager pluginManager = Helper.getActiveInstance().getPluginManager();
return getPluginsSorted(pluginManager);
}

private static Iterable<PluginWrapper> getPluginsSorted(PluginManager pluginManager) {
return listToSortedIterable(pluginManager.getPlugins());
}

private static <T extends Comparable<T>> Iterable<T> listToSortedIterable(List<T> list) {
final List<T> sorted = new LinkedList<T>(list);
Collections.sort(sorted);
return sorted;
}

private static void populatePluginsLists(List<PluginWrapper> activePlugins, List<PluginWrapper> disabledPlugins) {
for(PluginWrapper plugin : getPluginsSorted()){
if(plugin.isActive()) {
activePlugins.add(plugin);
} else {
disabledPlugins.add(plugin);
}
}
}
}

0 comments on commit eabbb45

Please sign in to comment.