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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 * Olivier Lamy
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.maven.reporters;
26
27 import hudson.FilePath;
28 import hudson.Util;
29 import hudson.maven.*;
30 import hudson.model.AbstractItem;
31 import hudson.model.Action;
32 import hudson.model.BuildListener;
33 import hudson.model.Result;
34 import hudson.tasks.JavadocArchiver.JavadocAction;
35 import org.apache.maven.project.MavenProject;
36 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
37
38 import java.io.File;
39 import java.io.IOException;
40 import java.util.Collection;
41
42 /**
43 * Records the javadoc and archives it.
44 *
45 * @author Kohsuke Kawaguchi
46 */
47 public abstract class AbstractMavenJavadocArchiver extends MavenReporter {
48
49
50 private boolean aggregated = false;
51
52 private FilePath target;
53
54
55 /**
56 * return true if this mojo is a javadoc one sources or test sources
57 * @param mojo
58 * @return
59 */
60 public abstract boolean checkIsJavadocMojo(MojoInfo mojo);
61
62 public abstract String getArchiveTargetPath();
63
64 public boolean postExecute(MavenBuildProxy build, MavenProject pom, MojoInfo mojo, BuildListener listener, Throwable error) throws InterruptedException, IOException {
65 if (!checkIsJavadocMojo(mojo)) return true;
66
67 File destDir;
68 try {
69 aggregated = mojo.getConfigurationValue("aggregate",Boolean.class, Boolean.FALSE) || mojo.getGoal().equals("aggregate")
70 || mojo.getGoal().equals("test-aggregate");
71 if(aggregated && !pom.isExecutionRoot())
72 return true; // in the aggregated mode, the generation will only happen for the root module
73
74 destDir = mojo.getConfigurationValue("reportOutputDirectory", File.class);
75 if(destDir==null)
76 destDir = mojo.getConfigurationValue("outputDirectory", File.class);
77 } catch (ComponentConfigurationException e) {
78 e.printStackTrace(listener.fatalError(Messages.MavenJavadocArchiver_NoDestDir()));
79 build.setResult(Result.FAILURE);
80 return true;
81 }
82
83 if(destDir != null && destDir.exists()) {
84 // javadoc:javadoc just skips itself when the current project is not a java project
85 if(aggregated) {
86 // store at MavenModuleSet level.
87 listener.getLogger().println("[JENKINS] Archiving aggregated javadoc");
88 target = build.getModuleSetRootDir();
89 } else {
90
91 listener.getLogger().println("[JENKINS] Archiving javadoc");
92 target = build.getProjectRootDir();
93 }
94
95 target = target.child(getArchiveTargetPath());
96
97 try {
98 new FilePath(destDir).copyRecursiveTo("**/*", target);
99 } catch (IOException e) {
100 Util.displayIOException(e,listener);
101 e.printStackTrace(listener.fatalError(Messages.MavenJavadocArchiver_FailedToCopy(destDir,target)));
102 build.setResult(Result.FAILURE);
103 }
104
105 if(aggregated)
106 build.registerAsAggregatedProjectAction(this);
107 else
108 build.registerAsProjectAction(this);
109
110 // JENKINS-9202 if project without any module
111 if (pom.getModules() != null && pom.getModules().isEmpty() && pom.isExecutionRoot() ) {
112 build.registerAsAggregatedProjectAction(this);
113 }
114
115 }
116
117 return true;
118 }
119
120 @Override
121 public boolean reportGenerated(MavenBuildProxy build, MavenProject pom, MavenReportInfo report, BuildListener listener) throws InterruptedException, IOException {
122 return postExecute(build,pom,report,listener,null);
123 }
124
125 public abstract Collection<? extends Action> getProjectActions(MavenModule project);
126
127 public abstract Action getAggregatedProjectAction(MavenModuleSet project);
128
129 public FilePath getTarget() {
130 return target;
131 }
132
133 protected static class MavenJavadocAction extends JavadocAction {
134 private final AbstractItem abstractItem;
135 private final FilePath target;
136 private final String title;
137 private final String urlName;
138 private final String displayName;
139
140 public MavenJavadocAction(AbstractItem project,FilePath target, String title,String urlName,String displayName) {
141 super(project);
142 this.abstractItem = project;
143 this.target = target;
144 this.title = title;
145 this.urlName = urlName;
146 this.displayName = displayName;
147 }
148
149 public String getDisplayName() {
150 File dir = dir();
151 if (dir != null && new File(dir, "help-doc.html").exists())
152 return this.displayName;
153 else
154 return hudson.tasks.Messages.JavadocArchiver_DisplayName_Generic();
155 }
156
157
158 @Override
159 protected String getTitle() {
160 return abstractItem.getDisplayName()+ " "+title;
161 }
162
163 @Override
164 public String getUrlName() {
165 return this.urlName;
166 }
167
168 @Override
169 protected File dir() {
170 return target == null ? null : new File(target.getRemote());
171 }
172
173 }
174
175
176 private static final long serialVersionUID = 1L;
177 }
178