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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2011, Sun Microsystems, Inc., Kohsuke Kawaguchi,
5 * Jorg Heymans, Stephen Connolly, Tom Huybrechts
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25 package hudson.model;
26
27 import hudson.Util;
28 import hudson.model.Descriptor.FormException;
29 import hudson.tasks.BuildStep;
30 import hudson.tasks.BuildWrapper;
31 import hudson.tasks.BuildWrappers;
32 import hudson.tasks.Builder;
33 import hudson.tasks.Fingerprinter;
34 import hudson.tasks.Publisher;
35 import hudson.tasks.Maven;
36 import hudson.tasks.Maven.ProjectWithMaven;
37 import hudson.tasks.Maven.MavenInstallation;
38 import hudson.triggers.Trigger;
39 import hudson.util.DescribableList;
40 import net.sf.json.JSONObject;
41 import org.kohsuke.stapler.StaplerRequest;
42 import org.kohsuke.stapler.StaplerResponse;
43
44 import javax.servlet.ServletException;
45 import java.io.IOException;
46 import java.util.HashSet;
47 import java.util.List;
48 import java.util.Map;
49 import java.util.Set;
50
51 /**
52 * Buildable software project.
53 *
54 * @author Kohsuke Kawaguchi
55 */
56 public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
57 extends AbstractProject<P,B> implements SCMedItem, Saveable, ProjectWithMaven, BuildableItemWithBuildWrappers {
58
59 /**
60 * List of active {@link Builder}s configured for this project.
61 */
62 private DescribableList<Builder,Descriptor<Builder>> builders;
63
64 /**
65 * List of active {@link Publisher}s configured for this project.
66 */
67 private DescribableList<Publisher,Descriptor<Publisher>> publishers;
68
69 /**
70 * List of active {@link BuildWrapper}s configured for this project.
71 */
72 private DescribableList<BuildWrapper,Descriptor<BuildWrapper>> buildWrappers;
73
74 /**
75 * Creates a new project.
76 */
77 public Project(ItemGroup parent,String name) {
78 super(parent,name);
79 }
80
81 @Override
82 public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
83 super.onLoad(parent, name);
84 getBuildersList().setOwner(this);
85 getPublishersList().setOwner(this);
86 getBuildWrappersList().setOwner(this);
87 }
88
89 public AbstractProject<?, ?> asProject() {
90 return this;
91 }
92
93 public List<Builder> getBuilders() {
94 return getBuildersList().toList();
95 }
96
97 /**
98 * @deprecated as of 1.463
99 * We will be soon removing the restriction that only one instance of publisher is allowed per type.
100 * Use {@link #getPublishersList()} instead.
101 */
102 public Map<Descriptor<Publisher>,Publisher> getPublishers() {
103 return getPublishersList().toMap();
104 }
105
106 public synchronized DescribableList<Builder,Descriptor<Builder>> getBuildersList() {
107 if (builders == null) {
108 builders = new DescribableList<Builder,Descriptor<Builder>>(this);
109 }
110 return builders;
111 }
112
113 public synchronized DescribableList<Publisher,Descriptor<Publisher>> getPublishersList() {
114 if (publishers == null) {
115 publishers = new DescribableList<Publisher,Descriptor<Publisher>>(this);
116 }
117 return publishers;
118 }
119
120 public Map<Descriptor<BuildWrapper>,BuildWrapper> getBuildWrappers() {
121 return getBuildWrappersList().toMap();
122 }
123
124 public synchronized DescribableList<BuildWrapper, Descriptor<BuildWrapper>> getBuildWrappersList() {
125 if (buildWrappers == null) {
126 buildWrappers = new DescribableList<BuildWrapper,Descriptor<BuildWrapper>>(this);
127 }
128 return buildWrappers;
129 }
130
131 @Override
132 protected Set<ResourceActivity> getResourceActivities() {
133 final Set<ResourceActivity> activities = new HashSet<ResourceActivity>();
134
135 activities.addAll(super.getResourceActivities());
136 activities.addAll(Util.filter(getBuildersList(),ResourceActivity.class));
137 activities.addAll(Util.filter(getPublishersList(),ResourceActivity.class));
138 activities.addAll(Util.filter(getBuildWrappersList(),ResourceActivity.class));
139
140 return activities;
141 }
142
143 /**
144 * Adds a new {@link BuildStep} to this {@link Project} and saves the configuration.
145 *
146 * @deprecated as of 1.290
147 * Use {@code getPublishersList().add(x)}
148 */
149 public void addPublisher(Publisher buildStep) throws IOException {
150 getPublishersList().add(buildStep);
151 }
152
153 /**
154 * Removes a publisher from this project, if it's active.
155 *
156 * @deprecated as of 1.290
157 * Use {@code getPublishersList().remove(x)}
158 */
159 public void removePublisher(Descriptor<Publisher> descriptor) throws IOException {
160 getPublishersList().remove(descriptor);
161 }
162
163 public Publisher getPublisher(Descriptor<Publisher> descriptor) {
164 for (Publisher p : getPublishersList()) {
165 if(p.getDescriptor()==descriptor)
166 return p;
167 }
168 return null;
169 }
170
171 protected void buildDependencyGraph(DependencyGraph graph) {
172 getPublishersList().buildDependencyGraph(this,graph);
173 getBuildersList().buildDependencyGraph(this,graph);
174 getBuildWrappersList().buildDependencyGraph(this,graph);
175 }
176
177 @Override
178 public boolean isFingerprintConfigured() {
179 return getPublishersList().get(Fingerprinter.class)!=null;
180 }
181
182 public MavenInstallation inferMavenInstallation() {
183 Maven m = getBuildersList().get(Maven.class);
184 if (m!=null) return m.getMaven();
185 return null;
186 }
187
188 //
189 //
190 // actions
191 //
192 //
193 @Override
194 protected void submit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException {
195 super.submit(req,rsp);
196
197 JSONObject json = req.getSubmittedForm();
198
199 getBuildWrappersList().rebuild(req,json, BuildWrappers.getFor(this));
200 getBuildersList().rebuildHetero(req,json, Builder.all(), "builder");
201 getPublishersList().rebuildHetero(req, json, Publisher.all(), "publisher");
202 }
203
204 @Override
205 protected List<Action> createTransientActions() {
206 List<Action> r = super.createTransientActions();
207
208 for (BuildStep step : getBuildersList())
209 r.addAll(step.getProjectActions(this));
210 for (BuildStep step : getPublishersList())
211 r.addAll(step.getProjectActions(this));
212 for (BuildWrapper step : getBuildWrappers().values())
213 r.addAll(step.getProjectActions(this));
214 for (Trigger trigger : getTriggers().values())
215 r.addAll(trigger.getProjectActions());
216
217 return r;
218 }
219 }
220