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