View Javadoc

1   /**
2    * Copyright (C) 2010-2012 Joerg Bellmann <joerg.bellmann@googlemail.com>
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.googlecode.t7mp;
17  
18  import java.io.File;
19  import java.util.ArrayList;
20  import java.util.HashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.apache.commons.lang.StringUtils;
25  import org.apache.maven.artifact.factory.ArtifactFactory;
26  import org.apache.maven.artifact.repository.ArtifactRepository;
27  import org.apache.maven.artifact.resolver.ArtifactCollector;
28  import org.apache.maven.artifact.resolver.ArtifactResolver;
29  import org.apache.maven.plugin.AbstractMojo;
30  import org.apache.maven.project.MavenProject;
31  import org.codehaus.plexus.archiver.manager.ArchiverManager;
32  
33  import com.googlecode.t7mp.scanner.ScannerConfiguration;
34  
35  /**
36   * Maven components.
37   * 
38   * Maybe used in subclasses.
39   */
40  public abstract class AbstractT7BaseMojo extends AbstractMojo {
41  
42      public static final String T7_BOOTSTRAP_CONTEXT_ID = "com.googlecode.t7mp.Bootstrap";
43  
44      public static final int DEFAULT_TOMCAT_HTTP_PORT = 8080;
45  
46      public static final int DEFAULT_TOMCAT_SHUTDOWN_PORT = 8005;
47  
48      public static final String DEFAULT_TOMCAT_VERSION = "7.0.29";
49  
50      public static final String CONTEXT_PATH_ROOT = "ROOT";
51  
52      /**
53       * @parameter expression="${project}"
54       * @required
55       * @readonly
56       * 
57       */
58      protected MavenProject mavenProject;
59  
60      /**
61       * Used to look up Artifacts in the remote repository.
62       *
63       * @component
64       */
65      protected ArtifactFactory factory;
66  
67      /**
68       * Used to look up Artifacts in the remote repository.
69       *
70       * @component
71       */
72      protected ArtifactResolver resolver;
73  
74      /**
75       * Artifact collector, needed to resolve dependencies.
76       *
77       * @component role="org.apache.maven.artifact.resolver.ArtifactCollector"
78       * @required
79       * @readonly
80       */
81      protected ArtifactCollector artifactCollector;
82  
83      /**
84       * Location of the local repository.
85       *
86       * @parameter expression="${localRepository}"
87       * @readonly
88       * @required
89       */
90      protected ArtifactRepository local;
91  
92      /**
93       * List of Remote Repositories used by the resolver.
94       *
95       * @parameter expression="${project.remoteArtifactRepositories}"
96       * @readonly
97       * @required
98       */
99      protected java.util.List<ArtifactRepository> remoteRepos;
100 
101     /**
102      * To look up Archiver/UnArchiver implementations.
103      *
104      * @component
105      */
106     protected ArchiverManager archiverManager;
107 
108     /**
109      * 
110      * @parameter expression="${t7.tomcatSetAwait}" default-value="true"
111      * @required
112      * 
113      */
114     protected boolean tomcatSetAwait = true;
115 
116     /**
117      * 
118      * @parameter expression="${t7.lookInside}" default-value="false"
119      * @required
120      * 
121      */
122     protected boolean lookInside = false;
123 
124     /**
125      * 
126      * @parameter expression="${t7.resolverUpdateSnapshotsAlways}" default-value="false"
127      * @required
128      */
129     protected boolean resolverUpdateSnapshotsAllways = false;
130 
131     /**
132      * 
133      * @parameter expression="${t7.tomcatVersion}" default-value="7.0.29"
134      */
135     protected String tomcatVersion = DEFAULT_TOMCAT_VERSION;
136 
137     /**
138      * 
139      * @parameter expression="${t7.tomcatHttpPort}" default-value="8080"
140      */
141     protected int tomcatHttpPort = DEFAULT_TOMCAT_HTTP_PORT;
142 
143     /**
144      * 
145      * @parameter expression="${t7.tomcatShutdownPort}" default-value="8005"
146      */
147     protected int tomcatShutdownPort = DEFAULT_TOMCAT_SHUTDOWN_PORT;
148 
149     /**
150      * 
151      * @parameter expression="${t7.tomcatShutdownCommand}" default-value="SHUTDOWN"
152      */
153     protected String tomcatShutdownCommand = "SHUTDOWN";
154 
155     /**
156      * 
157      * @parameter expression="${t7.tomcatShutdownHost}" default-value="localhost"
158      * 
159      */
160     protected String tomcatShutdownHost = "localhost";
161     
162     /**
163      * 
164      * @parameter expression="${t7.tomcatHostName}" default-value="localhost"
165      * 
166      */
167     protected String tomcatHostName = "localhost";
168 
169     /**
170      * 
171      * @parameter default-value="${project.build.directory}/tomcat"
172      * @readonly // at the moment
173      * 
174      */
175     protected File catalinaBase;
176 
177     /**
178      * 
179      * @parameter expression="${t7.tomcatConfigDirectory}" default-value="${basedir}/src/main/tomcat/conf"
180      * @optional
181      * 
182      */
183     protected File tomcatConfigDirectory;
184 
185     /**
186      * 
187      * @parameter expression="${t7.overwriteWebXML}"
188      */
189     protected File overwriteWebXML;
190 
191     /**
192      * 
193      * @parameter default-value="${project.build.directory}/${project.build.finalName}"
194      * @readonly
195      * 
196      */
197     protected File webappOutputDirectory;
198 
199     /**
200      *
201      * @parameter expression="${t7.contextPath}" default-value="${project.build.finalName}"
202      * @optional
203      *
204      */
205     protected String contextPath;
206 
207     /**
208      * @parameter default-value="${project.build.finalName}"
209      * @readonly
210      */
211     protected String buildFinalName;
212 
213     /**
214      * @parameter default-value="${basedir}/src/main/webapp"
215      * @readonly
216      */
217     protected File webappSourceDirectory;
218 
219     /**
220      * @parameter default-value="${project.packaging}"
221      * 
222      * 
223      */
224     protected String packaging = "war";
225 
226     /**
227      * 
228      * @parameter expression="${t7.scanClasses}" default-value="false"
229      */
230     protected boolean scanClasses = false;
231 
232     /**
233      * 
234      * @parameter expression="${t7.addGithubRepository}" default-value="false"
235      */
236     protected boolean addGithubRepository = false;
237 
238     /**
239      * @parameter default-value="${basedir}/target/classes"
240      * @readonly
241      */
242     protected File webappClassDirectory;
243 
244     /**
245      * @parameter
246      * @optional
247      */
248     protected File contextFile = null;
249 
250     /**
251      * 
252      * @parameter
253      */
254     protected ArrayList<WebappArtifact> webapps = new ArrayList<WebappArtifact>();
255 
256     /**
257      * 
258      * @parameter
259      */
260     protected Map<String, String> systemProperties = new HashMap<String, String>();
261 
262     /**
263      * 
264      * @parameter
265      */
266     protected ArrayList<JarArtifact> libs = new ArrayList<JarArtifact>();
267 
268     /**
269      * 
270      * @parameter
271      */
272     protected ArrayList<ScannerConfiguration> scanners = new ArrayList<ScannerConfiguration>();
273 
274     /**
275      * 
276      * @parameter default-value="false"
277      */
278     protected boolean suspendConsoleOutput = false;
279 
280     /**
281      * @parameter
282      */
283     protected ConfigurationArtifact configArtifact = null;
284     
285     /**
286      * 
287      * 
288      * @parameter default-value="1"
289      */
290     protected int instanceCount = 1;
291 
292     public boolean isWebProject() {
293         return this.packaging.equals("war");
294     }
295 
296     public boolean isTomcatSetAwait() {
297         return tomcatSetAwait;
298     }
299 
300     public void setTomcatSetAwait(boolean setAwait) {
301         this.tomcatSetAwait = setAwait;
302     }
303 
304     public boolean isLookInside() {
305         return lookInside;
306     }
307 
308     public void setLookInside(boolean lookInside) {
309         this.lookInside = lookInside;
310     }
311 
312     public boolean isScanClasses() {
313         return scanClasses;
314     }
315 
316     public void setScanClasses(boolean scanClasses) {
317         this.scanClasses = scanClasses;
318     }
319 
320     public boolean isAddGithubRepository() {
321         return addGithubRepository;
322     }
323 
324     public void setAddGithubRepository(boolean addGithubRepository) {
325         this.addGithubRepository = addGithubRepository;
326     }
327 
328     public String getTomcatVersion() {
329         return tomcatVersion;
330     }
331 
332     public void setTomcatVersion(String tomcatVersion) {
333         this.tomcatVersion = tomcatVersion;
334     }
335 
336     public int getTomcatHttpPort() {
337         return tomcatHttpPort;
338     }
339 
340     public void setTomcatHttpPort(int tomcatHttpPort) {
341         this.tomcatHttpPort = tomcatHttpPort;
342     }
343 
344     public int getTomcatShutdownPort() {
345         return tomcatShutdownPort;
346     }
347 
348     public void setTomcatShutdownPort(int tomcatShutdownPort) {
349         this.tomcatShutdownPort = tomcatShutdownPort;
350     }
351 
352     public String getTomcatShutdownCommand() {
353         return tomcatShutdownCommand;
354     }
355 
356     public void setTomcatShutdownCommand(String tomcatShutdownCommand) {
357         this.tomcatShutdownCommand = tomcatShutdownCommand;
358     }
359 
360     public String getTomcatShutdownHost() {
361         return tomcatShutdownHost;
362     }
363 
364     public void setTomcatShutdownHost(String tomcatShutdownHost) {
365         this.tomcatShutdownHost = tomcatShutdownHost;
366     }
367 
368     public String getTomcatHostName() {
369         return tomcatHostName;
370     }
371 
372     public void setTomcatHostName(String tomcatHostName) {
373         this.tomcatHostName = tomcatHostName;
374     }
375 
376     public File getUserConfigDir() {
377         return tomcatConfigDirectory;
378     }
379 
380     public void setUserConfigDir(File userConfigDir) {
381         this.tomcatConfigDirectory = userConfigDir;
382     }
383 
384     public File getWebappOutputDirectory() {
385         return webappOutputDirectory;
386     }
387 
388     public void setWebappOutputDirectory(File webappOutputDirectory) {
389         this.webappOutputDirectory = webappOutputDirectory;
390     }
391 
392     public String getContextPath() {
393         if (StringUtils.isEmpty(contextPath) || "/".equals(contextPath)) {
394             return CONTEXT_PATH_ROOT;
395         }
396         if (contextPath.startsWith("/")) {
397             return contextPath.substring(1);
398         }
399         return contextPath;
400     }
401 
402     public void setContextPath(String contextPath) {
403         this.contextPath = contextPath;
404     }
405 
406     public File getOverwriteWebXML() {
407         return overwriteWebXML;
408     }
409 
410     public void setOverwriteWebXML(File overwriteWebXML) {
411         this.overwriteWebXML = overwriteWebXML;
412     }
413 
414     public File getContextFile() {
415         return contextFile;
416     }
417 
418     public void setContextFile(File contextFile) {
419         this.contextFile = contextFile;
420     }
421 
422     public File getCatalinaBase() {
423         return catalinaBase;
424     }
425 
426     public void setCatalinaBase(File catalinaBase) {
427         this.catalinaBase = catalinaBase;
428     }
429 
430     public ArrayList<ScannerConfiguration> getScanners() {
431         return scanners;
432     }
433 
434     public String getBuildFinalName() {
435         return buildFinalName;
436     }
437 
438     public void setBuildFinalName(String buildFinalName) {
439         this.buildFinalName = buildFinalName;
440     }
441 
442     public String getPackaging() {
443         return packaging;
444     }
445 
446     public void setPackaging(String packaging) {
447         this.packaging = packaging;
448     }
449 
450     public List<JarArtifact> getLibs() {
451         return libs;
452     }
453 
454     public void setLibs(ArrayList<JarArtifact> libs) {
455         this.libs = libs;
456     }
457 
458     public File getTomcatConfigDirectory() {
459         return tomcatConfigDirectory;
460     }
461 
462     public void setTomcatConfigDirectory(File tomcatConfigDirectory) {
463         this.tomcatConfigDirectory = tomcatConfigDirectory;
464     }
465 
466     public File getWebappSourceDirectory() {
467         return webappSourceDirectory;
468     }
469 
470     public void setWebappSourceDirectory(File webappSourceDirectory) {
471         this.webappSourceDirectory = webappSourceDirectory;
472     }
473 
474     public File getWebappClassDirectory() {
475         return webappClassDirectory;
476     }
477 
478     public void setWebappClassDirectory(File webappClassDirectory) {
479         this.webappClassDirectory = webappClassDirectory;
480     }
481 
482     public List<WebappArtifact> getWebapps() {
483         return webapps;
484     }
485 
486     public void setWebapps(ArrayList<WebappArtifact> webapps) {
487         this.webapps = webapps;
488     }
489 
490     public Map<String, String> getSystemProperties() {
491         return systemProperties;
492     }
493 
494     public void setSystemProperties(Map<String, String> systemProperties) {
495         this.systemProperties = systemProperties;
496     }
497 
498     public ArtifactFactory getFactory() {
499         return factory;
500     }
501 
502     public void setFactory(ArtifactFactory factory) {
503         this.factory = factory;
504     }
505 
506     public ArtifactResolver getResolver() {
507         return resolver;
508     }
509 
510     public void setResolver(ArtifactResolver resolver) {
511         this.resolver = resolver;
512     }
513 
514     public ArtifactCollector getArtifactCollector() {
515         return artifactCollector;
516     }
517 
518     public void setArtifactCollector(ArtifactCollector artifactCollector) {
519         this.artifactCollector = artifactCollector;
520     }
521 
522     public ArtifactRepository getLocal() {
523         return local;
524     }
525 
526     public void setLocal(ArtifactRepository local) {
527         this.local = local;
528     }
529 
530     public java.util.List<ArtifactRepository> getRemoteRepos() {
531         return remoteRepos;
532     }
533 
534     public void setRemoteRepos(java.util.List<ArtifactRepository> remoteRepos) {
535         this.remoteRepos = remoteRepos;
536     }
537 
538     public ArchiverManager getArchiverManager() {
539         return archiverManager;
540     }
541 
542     public void setArchiverManager(ArchiverManager archiverManager) {
543         this.archiverManager = archiverManager;
544     }
545 
546     public boolean isResolverUpdateSnapshotsAllways() {
547         return resolverUpdateSnapshotsAllways;
548     }
549 
550     public void setResolverUpdateSnapshotsAllways(boolean resolverUpdateSnapshotsAllways) {
551         this.resolverUpdateSnapshotsAllways = resolverUpdateSnapshotsAllways;
552     }
553 
554     public void setScanners(ArrayList<ScannerConfiguration> scanners) {
555         this.scanners = scanners;
556     }
557 
558     public MavenProject getMavenProject() {
559         return mavenProject;
560     }
561 
562     public void setMavenProject(MavenProject mavenProject) {
563         this.mavenProject = mavenProject;
564     }
565 
566     public boolean isSuspendConsoleOutput() {
567         return suspendConsoleOutput;
568     }
569 
570     public void setSuspendConsoleOutput(boolean suspendConsoleOutput) {
571         this.suspendConsoleOutput = suspendConsoleOutput;
572     }
573 
574     public ConfigurationArtifact getConfigArtifact() {
575         return configArtifact;
576     }
577 
578     public void setConfigArtifact(ConfigurationArtifact configurationArtifact) {
579         this.configArtifact = configurationArtifact;
580     }
581 
582     public int getInstanceCount() {
583         return instanceCount;
584     }
585 
586     public void setInstanceCount(int instanceCount) {
587         this.instanceCount = instanceCount;
588     }
589 
590 }