File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\DisplayNameListener.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2011, Yahoo!, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.model;
25
26
27
28 import java.io.IOException;
29 import java.util.logging.Level;
30 import java.util.logging.Logger;
31
32 import hudson.Extension;
33 import hudson.model.listeners.ItemListener;
34
35 /**
36 * @author kingfai
37 *
38 */
39 @Extension
40 public class DisplayNameListener extends ItemListener {
41
42 private final static Logger LOGGER = Logger.getLogger(DisplayNameListener.class.getName());
43
44 @Override
45 /**
46 * Called after the user has clicked OK in the New Job page when
47 * Copy existing job has been selected.
48 * The fields in item will be displayed in when the config page is loaded
49 * displayed.
50 */
51 public void onCopied(Item src, Item item) {
52 // bug 5056825 - Display name field should be cleared when you copy a job.
53 if(item instanceof AbstractItem) {
54 AbstractItem dest = (AbstractItem)item;
55 try {
56 dest.setDisplayName(null);
57 } catch(IOException ioe) {
58 LOGGER.log(Level.WARNING, String.format("onCopied():Exception while trying to clear the displayName for Item.name:%s", item.getName()), ioe);
59 }
60 }
61 }
62
63 @Override
64 /**
65 * Called after the user has changed the project name of a job and then
66 * clicked on submit.
67 * @param item The item that has been renamed. The new project name is already
68 * in item.getName()
69 * @param oldName the old name
70 * @param newName the new name
71 */
72 public void onRenamed(Item item, String oldName, String newName) {
73 // bug 5077308 - Display name field should be cleared when you rename a job.
74 if(item instanceof AbstractItem) {
75 AbstractItem abstractItem = (AbstractItem)item;
76 if(oldName.equals(abstractItem.getDisplayName())) {
77 // the user renamed the job, but the old project name which is shown as the
78 // displayname if no displayname was set, has been set into the displayname field.
79 // This means that the displayname was never set, so we want to set it
80 // to null as it was before
81 try {
82 LOGGER.info(String.format("onRenamed():Setting displayname to null for item.name=%s", item.getName()));
83 abstractItem.setDisplayName(null);
84 }
85 catch(IOException ioe) {
86 LOGGER.log(Level.WARNING, String.format("onRenamed():Exception while trying to clear the displayName for Item.name:%s",
87 item.getName()), ioe);
88 }
89 }
90 }
91 }
92
93 }
94