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 (-36 / +141 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.awt.ActionID;
55
import org.openide.awt.ActionRegistration;
56
import org.openide.filesystems.FileUtil;
57
import org.openide.util.ContextAwareAction;
58
import org.openide.util.Lookup;
53
import org.openide.util.NbBundle.Messages;
59
import org.openide.util.NbBundle.Messages;
54
import org.openide.util.RequestProcessor;
60
import org.openide.util.Utilities;
55
61
56
/**
62
/**
57
 * Action to display test failures.
63
 * Action to display test failures.
58
 */
64
 */
59
public class ShowFailures extends AbstractAction {
65
@Messages("ShowFailures.label=Show Test Failures")
66
@ActionRegistration(lazy = false, displayName = "#ShowFailures.label")
67
@ActionID(id = "org.netbeans.modules.hudson.ui.actions.ShowFailures",
68
        category = "Hudson")
69
public class ShowFailures extends AbstractAction implements ContextAwareAction {
60
70
61
    private static final Logger LOG = Logger.getLogger(ShowFailures.class.getName());
71
    private static ShowFailures INSTANCE = null;
62
    private static final RequestProcessor RP = new RequestProcessor(ShowFailures.class);
72
    private final Lookup context;
63
    private final HudsonJobBuild build;
64
    private final HudsonMavenModuleBuild moduleBuild;
65
73
66
    public ShowFailures(HudsonJobBuild build) {
74
    /**
67
        this(build, null);
75
     * Get the shared instance from system filesystem.
76
     */
77
    public static ShowFailures getInstance() {
78
        if (INSTANCE == null) {
79
            INSTANCE = FileUtil.getConfigObject(
80
                    "Actions/Hudson/org-netbeans-modules-hudson-ui" //NOI18N
81
                    + "-actions-ShowFailures.instance", //NOI18N
82
                    ShowFailures.class);
83
        }
84
        return INSTANCE;
68
    }
85
    }
69
86
70
    public ShowFailures(HudsonMavenModuleBuild module) {
87
    public ShowFailures() {
71
        this(module.getBuild(), module);
88
        this(Utilities.actionsGlobalContext());
72
    }
89
    }
73
90
74
    @Messages("ShowFailures.label=Show Test Failures")
91
    private ShowFailures(Lookup context) {
75
    private ShowFailures(HudsonJobBuild build,
92
        putValue(NAME, Bundle.ShowFailures_label());
76
            HudsonMavenModuleBuild moduleBuild) {
93
        this.context = context;
77
78
        this.build = build;
79
        this.moduleBuild = moduleBuild;
80
        putValue(NAME, ShowFailures_label());
81
    }
94
    }
82
95
83
    @Override
96
    /**
84
    public void actionPerformed(ActionEvent e) {
97
     * Check if failures for job build or maven module build can be shown. The
85
        HudsonInstance hudsonInstance = build.getJob().getInstance();
98
     * build has to be unstable, and a failure displayer has to be available.
86
        if (hudsonInstance instanceof HudsonInstanceImpl) {
99
     */
87
            HudsonInstanceImpl hudsonInstanceImpl =
100
    private boolean canShowFailures(HudsonJobBuild build,
88
                    (HudsonInstanceImpl) hudsonInstance;
101
            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();
102
        HudsonInstance instance = build.getJob().getInstance();
101
        if (instance instanceof HudsonInstanceImpl) {
103
        if (instance instanceof HudsonInstanceImpl) {
104
            if (module == null && !HudsonJobBuild.Result.UNSTABLE.equals(
105
                    build.getResult())) {
106
                return false;
107
            } else if (module != null) {
108
                boolean failed = false;
109
                switch (module.getColor()) {
110
                    case yellow:
111
                    case yellow_anime:
112
                        failed = true;
113
                }
114
                if (!failed) {
115
                    return false;
116
                }
117
            }
102
            BuilderConnector builderClient =
118
            BuilderConnector builderClient =
103
                    ((HudsonInstanceImpl) instance).getBuilderConnector();
119
                    ((HudsonInstanceImpl) instance).getBuilderConnector();
104
            return builderClient.getFailureDisplayer() != null;
120
            return builderClient.getFailureDisplayer() != null;
105
        }
121
        }
106
        return false;
122
        return false;
107
    }
123
    }
124
125
    /**
126
     * Find maven module builds that are part of a job build but are not already
127
     * included in the context.
128
     */
129
    private List<HudsonMavenModuleBuild> getExtraModuleBuilds(
130
            HudsonJobBuild build) {
131
        List<HudsonMavenModuleBuild> result = new LinkedList<HudsonMavenModuleBuild>();
132
        for (HudsonMavenModuleBuild m : build.getMavenModules()) {
133
            if (null == context.lookup(new Lookup.Template<HudsonMavenModuleBuild>(
134
                    HudsonMavenModuleBuild.class, null, m))) {
135
                result.add(m);
136
            }
137
        }
138
        return result;
139
    }
140
141
    /**
142
     * If there is at least one unstable build in the context, this action will
143
     * be enabled.
144
     */
145
    @Override
146
    public boolean isEnabled() {
147
        for (HudsonJobBuild job : context.lookupAll(HudsonJobBuild.class)) {
148
            if (canShowFailures(job, null)) {
149
                return true;
150
            }
151
        }
152
        for (HudsonMavenModuleBuild module
153
                : context.lookupAll(HudsonMavenModuleBuild.class)) {
154
            if (canShowFailures(module.getBuild(), module)) {
155
                return true;
156
            }
157
        }
158
        return false;
159
    }
160
161
    @Override
162
    public void actionPerformed(ActionEvent e) {
163
164
        for (HudsonJobBuild job : context.lookupAll(HudsonJobBuild.class)) {
165
            showFailures(job, null);
166
        }
167
        for (HudsonMavenModuleBuild module
168
                : context.lookupAll(HudsonMavenModuleBuild.class)) {
169
            showFailures(module.getBuild(), module);
170
        }
171
    }
172
173
    /**
174
     * Show failures in a job build or maven module build. If a maven module
175
     * build is not specified, but the job build contains some module build,
176
     * failures from all its module builds will be shown.
177
     */
178
    private void showFailures(HudsonJobBuild build,
179
            HudsonMavenModuleBuild moduleBuild) {
180
181
        if (!canShowFailures(build, moduleBuild)) {
182
            return;
183
        }
184
        HudsonInstance hudsonInstance = build.getJob().getInstance();
185
        if (hudsonInstance instanceof HudsonInstanceImpl) {
186
            HudsonInstanceImpl hudsonInstanceImpl =
187
                    (HudsonInstanceImpl) hudsonInstance;
188
            BuilderConnector builderClient =
189
                    hudsonInstanceImpl.getBuilderConnector();
190
            BuilderConnector.FailureDisplayer failureDisplayer =
191
                    builderClient.getFailureDisplayer();
192
            if (failureDisplayer != null) {
193
                if (moduleBuild != null) {
194
                    failureDisplayer.showFailures(moduleBuild);
195
                } else {
196
                    if (build.getMavenModules().isEmpty()) {
197
                        failureDisplayer.showFailures(build);
198
                    } else {
199
                        for (HudsonMavenModuleBuild extraModule
200
                                : getExtraModuleBuilds(build)) {
201
                            failureDisplayer.showFailures(extraModule);
202
                        }
203
                    }
204
                }
205
            }
206
        }
207
    }
208
209
    @Override
210
    public Action createContextAwareInstance(Lookup actionContext) {
211
        return new ShowFailures(actionContext);
212
    }
108
}
213
}
(-)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