Skip to content

Commit

Permalink
[JENKINS-38606 Follow-up] Ensure AllView gets migrated
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Dec 7, 2016
1 parent 41f1e2d commit 375eb15
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Expand Up @@ -70,6 +70,8 @@
import hudson.views.ViewsTabBar;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.ArrayList;
Expand Down Expand Up @@ -230,6 +232,21 @@ protected void init() {

if (folderViews == null) {
if (views != null && !views.isEmpty()) {
if (primaryView != null) {
// TODO replace reflection with direct access once baseline core has JENKINS-38606 fix merged
try {
Method migrateLegacyPrimaryAllViewLocalizedName = AllView.class
.getMethod("migrateLegacyPrimaryAllViewLocalizedName", List.class, String.class);
primaryView =
(String) migrateLegacyPrimaryAllViewLocalizedName.invoke(null, views, primaryView);
} catch (NoSuchMethodException e) {
// ignore, Jenkins core does not have JENKINS-38606 fix merged
} catch (IllegalAccessException e) {
// ignore, Jenkins core does not have JENKINS-38606 fix merged
} catch (InvocationTargetException e) {
// ignore, Jenkins core does not have JENKINS-38606 fix merged
}
}
folderViews = new DefaultFolderViewHolder(views, primaryView, viewsTabBar == null ? newDefaultViewsTabBar()
: viewsTabBar);
} else {
Expand Down
Expand Up @@ -27,17 +27,27 @@
import com.cloudbees.hudson.plugins.folder.AbstractFolder;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.AllView;
import hudson.model.View;
import hudson.views.ViewsTabBar;
import java.io.ObjectStreamException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* The default implementation of {@link AbstractFolderViewHolder} which allows all the elements to be modified.
*/
public class DefaultFolderViewHolder extends AbstractFolderViewHolder {
/**
* Our logger.
*/
private static final Logger LOGGER = Logger.getLogger(DefaultFolderViewHolder.class.getName());
/**
* The views.
*/
Expand Down Expand Up @@ -122,4 +132,22 @@ public void setTabBar(ViewsTabBar tabBar) {
this.tabBar = tabBar;
}

private Object readResolve() throws ObjectStreamException {
if (primaryView != null) {
// TODO replace reflection with direct access once baseline core has JENKINS-38606 fix merged
try {
Method migrateLegacyPrimaryAllViewLocalizedName = AllView.class
.getMethod("migrateLegacyPrimaryAllViewLocalizedName", List.class, String.class);
primaryView =
(String) migrateLegacyPrimaryAllViewLocalizedName.invoke(null, views, primaryView);
} catch (NoSuchMethodException e) {
// ignore, Jenkins core does not have JENKINS-38606 fix merged
} catch (IllegalAccessException e) {
// ignore, Jenkins core does not have JENKINS-38606 fix merged
} catch (InvocationTargetException e) {
// ignore, Jenkins core does not have JENKINS-38606 fix merged
}
}

}
}

0 comments on commit 375eb15

Please sign in to comment.