Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 214300 | Differences between
and this patch

Collapse All | Expand All

(-)a/hudson/src/org/netbeans/modules/hudson/api/UI.java (-9 / +3 lines)
 Lines 56-61    Link Here 
56
import org.openide.nodes.Node;
56
import org.openide.nodes.Node;
57
import org.openide.nodes.NodeNotFoundException;
57
import org.openide.nodes.NodeNotFoundException;
58
import org.openide.nodes.NodeOp;
58
import org.openide.nodes.NodeOp;
59
import org.openide.util.ContextAwareAction;
59
import org.openide.util.ImageUtilities;
60
import org.openide.util.ImageUtilities;
60
import org.openide.util.Mutex;
61
import org.openide.util.Mutex;
61
import org.openide.util.RequestProcessor;
62
import org.openide.util.RequestProcessor;
 Lines 146-160    Link Here 
146
    /**
147
    /**
147
     * Action to show test failures of a build.
148
     * Action to show test failures of a build.
148
     */
149
     */
149
    public static Action showFailuresAction(HudsonJobBuild build) {
150
    public static ContextAwareAction showFailuresAction() {
150
        return new ShowFailures(build);
151
        return ShowFailures.getInstance();
151
    }
152
153
    /**
154
     * Action to show test failures of a Maven module build.
155
     */
156
    public static Action showFailuresAction(HudsonMavenModuleBuild build) {
157
        return new ShowFailures(build);
158
    }
152
    }
159
153
160
    /**
154
    /**
(-)a/hudson/src/org/netbeans/modules/hudson/ui/actions/ShowFailures.java (-35 / +131 lines)
 Lines 42-108    Link Here 
42
package org.netbeans.modules.hudson.ui.actions;
42
package org.netbeans.modules.hudson.ui.actions;
43
43
44
import java.awt.event.ActionEvent;
44
import java.awt.event.ActionEvent;
45
import java.util.logging.Logger;
45
import java.util.LinkedList;
46
import java.util.List;
46
import javax.swing.AbstractAction;
47
import javax.swing.AbstractAction;
48
import javax.swing.Action;
47
import org.netbeans.modules.hudson.api.HudsonInstance;
49
import org.netbeans.modules.hudson.api.HudsonInstance;
48
import org.netbeans.modules.hudson.api.HudsonJobBuild;
50
import org.netbeans.modules.hudson.api.HudsonJobBuild;
49
import org.netbeans.modules.hudson.api.HudsonMavenModuleBuild;
51
import org.netbeans.modules.hudson.api.HudsonMavenModuleBuild;
50
import org.netbeans.modules.hudson.impl.HudsonInstanceImpl;
52
import org.netbeans.modules.hudson.impl.HudsonInstanceImpl;
51
import org.netbeans.modules.hudson.spi.BuilderConnector;
53
import org.netbeans.modules.hudson.spi.BuilderConnector;
52
import static org.netbeans.modules.hudson.ui.actions.Bundle.*;
54
import org.openide.util.ContextAwareAction;
55
import org.openide.util.Lookup;
53
import org.openide.util.NbBundle.Messages;
56
import org.openide.util.NbBundle.Messages;
54
import org.openide.util.RequestProcessor;
57
import org.openide.util.Utilities;
55
58
56
/**
59
/**
57
 * Action to display test failures.
60
 * Action to display test failures.
58
 */
61
 */
59
public class ShowFailures extends AbstractAction {
62
public class ShowFailures extends AbstractAction implements ContextAwareAction {
60
63
61
    private static final Logger LOG = Logger.getLogger(ShowFailures.class.getName());
64
    private static ShowFailures INSTANCE = null;
62
    private static final RequestProcessor RP = new RequestProcessor(ShowFailures.class);
65
    private final Lookup context;
63
    private final HudsonJobBuild build;
64
    private final HudsonMavenModuleBuild moduleBuild;
65
66
66
    public ShowFailures(HudsonJobBuild build) {
67
    /**
67
        this(build, null);
68
     * Get the shared instance from system filesystem.
69
     */
70
    public static ShowFailures getInstance() {
71
        if (INSTANCE == null) {
72
            INSTANCE = new ShowFailures();
73
        }
74
        return INSTANCE;
68
    }
75
    }
69
76
70
    public ShowFailures(HudsonMavenModuleBuild module) {
77
    public ShowFailures() {
71
        this(module.getBuild(), module);
78
        this(Utilities.actionsGlobalContext());
72
    }
79
    }
73
80
74
    @Messages("ShowFailures.label=Show Test Failures")
81
    @Messages("ShowFailures.label=Show Test Failures")
75
    private ShowFailures(HudsonJobBuild build,
82
    private ShowFailures(Lookup context) {
76
            HudsonMavenModuleBuild moduleBuild) {
83
        putValue(NAME, Bundle.ShowFailures_label());
77
84
        this.context = context;
78
        this.build = build;
79
        this.moduleBuild = moduleBuild;
80
        putValue(NAME, ShowFailures_label());
81
    }
85
    }
82
86
83
    @Override
87
    /**
84
    public void actionPerformed(ActionEvent e) {
88
     * Check if failures for job build or maven module build can be shown. The
85
        HudsonInstance hudsonInstance = build.getJob().getInstance();
89
     * build has to be unstable, and a failure displayer has to be available.
86
        if (hudsonInstance instanceof HudsonInstanceImpl) {
90
     */
87
            HudsonInstanceImpl hudsonInstanceImpl =
91
    private boolean canShowFailures(HudsonJobBuild build,
88
                    (HudsonInstanceImpl) hudsonInstance;
92
            HudsonMavenModuleBuild module) {
89
            BuilderConnector builderClient = hudsonInstanceImpl.getBuilderConnector();
90
            if (moduleBuild != null) {
91
                builderClient.getFailureDisplayer().showFailures(moduleBuild);
92
            } else {
93
                builderClient.getFailureDisplayer().showFailures(build);
94
            }
95
        }
96
    }
97
98
    @Override
99
    public boolean isEnabled() {
100
        HudsonInstance instance = build.getJob().getInstance();
93
        HudsonInstance instance = build.getJob().getInstance();
101
        if (instance instanceof HudsonInstanceImpl) {
94
        if (instance instanceof HudsonInstanceImpl) {
95
            if (module == null && !HudsonJobBuild.Result.UNSTABLE.equals(
96
                    build.getResult())) {
97
                return false;
98
            } else if (module != null) {
99
                boolean failed = false;
100
                switch (module.getColor()) {
101
                    case yellow:
102
                    case yellow_anime:
103
                        failed = true;
104
                }
105
                if (!failed) {
106
                    return false;
107
                }
108
            }
102
            BuilderConnector builderClient =
109
            BuilderConnector builderClient =
103
                    ((HudsonInstanceImpl) instance).getBuilderConnector();
110
                    ((HudsonInstanceImpl) instance).getBuilderConnector();
104
            return builderClient.getFailureDisplayer() != null;
111
            return builderClient.getFailureDisplayer() != null;
105
        }
112
        }
106
        return false;
113
        return false;
107
    }
114
    }
115
116
    /**
117
     * Find maven module builds that are part of a job build but are not already
118
     * included in the context.
119
     */
120
    private List<HudsonMavenModuleBuild> getExtraModuleBuilds(
121
            HudsonJobBuild build) {
122
        List<HudsonMavenModuleBuild> result = new LinkedList<HudsonMavenModuleBuild>();
123
        for (HudsonMavenModuleBuild m : build.getMavenModules()) {
124
            if (null == context.lookup(new Lookup.Template<HudsonMavenModuleBuild>(
125
                    HudsonMavenModuleBuild.class, null, m))) {
126
                result.add(m);
127
            }
128
        }
129
        return result;
130
    }
131
132
    /**
133
     * If there is at least one unstable build in the context, this action will
134
     * be enabled.
135
     */
136
    @Override
137
    public boolean isEnabled() {
138
        for (HudsonJobBuild job : context.lookupAll(HudsonJobBuild.class)) {
139
            if (canShowFailures(job, null)) {
140
                return true;
141
            }
142
        }
143
        for (HudsonMavenModuleBuild module
144
                : context.lookupAll(HudsonMavenModuleBuild.class)) {
145
            if (canShowFailures(module.getBuild(), module)) {
146
                return true;
147
            }
148
        }
149
        return false;
150
    }
151
152
    @Override
153
    public void actionPerformed(ActionEvent e) {
154
155
        for (HudsonJobBuild job : context.lookupAll(HudsonJobBuild.class)) {
156
            showFailures(job, null);
157
        }
158
        for (HudsonMavenModuleBuild module
159
                : context.lookupAll(HudsonMavenModuleBuild.class)) {
160
            showFailures(module.getBuild(), module);
161
        }
162
    }
163
164
    /**
165
     * Show failures in a job build or maven module build. If a maven module
166
     * build is not specified, but the job build contains some module build,
167
     * failures from all its module builds will be shown.
168
     */
169
    private void showFailures(HudsonJobBuild build,
170
            HudsonMavenModuleBuild moduleBuild) {
171
172
        if (!canShowFailures(build, moduleBuild)) {
173
            return;
174
        }
175
        HudsonInstance hudsonInstance = build.getJob().getInstance();
176
        if (hudsonInstance instanceof HudsonInstanceImpl) {
177
            HudsonInstanceImpl hudsonInstanceImpl =
178
                    (HudsonInstanceImpl) hudsonInstance;
179
            BuilderConnector builderClient =
180
                    hudsonInstanceImpl.getBuilderConnector();
181
            BuilderConnector.FailureDisplayer failureDisplayer =
182
                    builderClient.getFailureDisplayer();
183
            if (failureDisplayer != null) {
184
                if (moduleBuild != null) {
185
                    failureDisplayer.showFailures(moduleBuild);
186
                } else {
187
                    if (build.getMavenModules().isEmpty()) {
188
                        failureDisplayer.showFailures(build);
189
                    } else {
190
                        for (HudsonMavenModuleBuild extraModule
191
                                : getExtraModuleBuilds(build)) {
192
                            failureDisplayer.showFailures(extraModule);
193
                        }
194
                    }
195
                }
196
            }
197
        }
198
    }
199
200
    @Override
201
    public Action createContextAwareInstance(Lookup actionContext) {
202
        return new ShowFailures(actionContext);
203
    }
108
}
204
}
(-)a/hudson/src/org/netbeans/modules/hudson/ui/nodes/HudsonJobBuildNode.java (-3 / +1 lines)
 Lines 94-102    Link Here 
94
        List<Action> actions = new ArrayList<Action>();
94
        List<Action> actions = new ArrayList<Action>();
95
        actions.add(UI.showChangesAction(build));
95
        actions.add(UI.showChangesAction(build));
96
        actions.add(UI.showConsoleAction(build));
96
        actions.add(UI.showConsoleAction(build));
97
        if (build.getResult() == HudsonJobBuild.Result.UNSTABLE && build.getMavenModules().isEmpty()) {
97
        actions.add(UI.showFailuresAction());
98
            actions.add(UI.showFailuresAction(build));
99
        }
100
        actions.add(null);
98
        actions.add(null);
101
        if (build instanceof OpenableInBrowser) {
99
        if (build instanceof OpenableInBrowser) {
102
            actions.add(OpenUrlAction.forOpenable((OpenableInBrowser) build));
100
            actions.add(OpenUrlAction.forOpenable((OpenableInBrowser) build));
(-)a/hudson/src/org/netbeans/modules/hudson/ui/nodes/HudsonMavenModuleBuildNode.java (-5 / +1 lines)
 Lines 85-95    Link Here 
85
    public @Override Action[] getActions(boolean context) {
85
    public @Override Action[] getActions(boolean context) {
86
        List<Action> actions = new ArrayList<Action>();
86
        List<Action> actions = new ArrayList<Action>();
87
        actions.add(UI.showConsoleAction(module));
87
        actions.add(UI.showConsoleAction(module));
88
        switch (module.getColor()) {
88
        actions.add(UI.showFailuresAction());
89
        case yellow:
90
        case yellow_anime:
91
            actions.add(UI.showFailuresAction(module));
92
        }
93
        actions.add(null);
89
        actions.add(null);
94
        if (module instanceof OpenableInBrowser) {
90
        if (module instanceof OpenableInBrowser) {
95
            actions.add(OpenUrlAction.forOpenable((OpenableInBrowser) module));
91
            actions.add(OpenUrlAction.forOpenable((OpenableInBrowser) module));
(-)a/hudson/src/org/netbeans/modules/hudson/ui/notification/ProblemNotification.java (-2 / +6 lines)
 Lines 59-64    Link Here 
59
import org.openide.util.NbBundle.Messages;
59
import org.openide.util.NbBundle.Messages;
60
import org.openide.util.RequestProcessor;
60
import org.openide.util.RequestProcessor;
61
import static org.netbeans.modules.hudson.ui.notification.Bundle.*;
61
import static org.netbeans.modules.hudson.ui.notification.Bundle.*;
62
import org.openide.util.lookup.Lookups;
62
63
63
/**
64
/**
64
 * Build failed or was unstable.
65
 * Build failed or was unstable.
 Lines 109-121    Link Here 
109
                        if (failed) {
110
                        if (failed) {
110
                            UI.showConsoleAction(b).actionPerformed(null);
111
                            UI.showConsoleAction(b).actionPerformed(null);
111
                        } else if (b.getMavenModules().isEmpty()) {
112
                        } else if (b.getMavenModules().isEmpty()) {
112
                            UI.showFailuresAction(b).actionPerformed(null);
113
                            UI.showFailuresAction().createContextAwareInstance(
114
                                    Lookups.singleton(b)).actionPerformed(null);
113
                        } else {
115
                        } else {
114
                            for (HudsonMavenModuleBuild module : b.getMavenModules()) {
116
                            for (HudsonMavenModuleBuild module : b.getMavenModules()) {
115
                                switch (module.getColor()) {
117
                                switch (module.getColor()) {
116
                                case yellow:
118
                                case yellow:
117
                                case yellow_anime:
119
                                case yellow_anime:
118
                                    UI.showFailuresAction(module).actionPerformed(null);
120
                                    UI.showFailuresAction()
121
                                            .createContextAwareInstance(Lookups.singleton(module))
122
                                            .actionPerformed(null);
119
                                }
123
                                }
120
                            }
124
                            }
121
                        }
125
                        }

Return to bug 214300
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo