View Javadoc

1   /*
2    * Copyright (c) 2007, Ounce Labs, Inc.
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *     * Redistributions of source code must retain the above copyright
8    *       notice, this list of conditions and the following disclaimer.
9    *     * Redistributions in binary form must reproduce the above copyright
10   *       notice, this list of conditions and the following disclaimer in the
11   *       documentation and/or other materials provided with the distribution.
12   *     * Neither the name of the <organization> nor the
13   *       names of its contributors may be used to endorse or promote products
14   *       derived from this software without specific prior written permission.
15   *
16   * THIS SOFTWARE IS PROVIDED BY OUNCE LABS, INC. ``AS IS'' AND ANY
17   * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18   * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19   * DISCLAIMED. IN NO EVENT SHALL OUNCE LABS, INC. BE LIABLE FOR ANY
20   * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26   */
27  
28  package org.codehaus.mojo.ounce;
29  
30  import java.util.Map;
31  
32  import org.apache.maven.plugin.AbstractMojo;
33  import org.apache.maven.project.MavenProject;
34  import org.codehaus.mojo.ounce.core.OunceCore;
35  import org.codehaus.plexus.PlexusConstants;
36  import org.codehaus.plexus.PlexusContainer;
37  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
38  import org.codehaus.plexus.context.Context;
39  import org.codehaus.plexus.context.ContextException;
40  import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
41  
42  /**
43   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
44   */
45  public abstract class AbstractOunceMojo
46      extends AbstractMojo
47      implements Contextualizable
48  {
49      /**
50       * The current Project.
51       * 
52       * @parameter expression="${project}"
53       * @readonly
54       */
55      protected MavenProject project;
56  
57      /**
58       * This hint provides a way to switch the core implementation. Consult Ounce support for details, most users should
59       * leave this set to the default. Use -Dounce.core=console to have have the output displayed instead of written to
60       * the file for debugging purposes.
61       * 
62       * @parameter default-value="ouncexml" expression="${ounce.core}
63       */
64      protected String coreHint;
65  
66      /**
67       * Map of Ounce variable names and paths.<br/> pathVariableMap variables are automatically registered with Ounce by
68       * the Ounce/Maven plugin if the Ounce Automation Server is installed.
69       * 
70       * @parameter
71       */
72      Map pathVariableMap;
73  
74      /**
75       * The name of the project set in the pom.
76       * 
77       * @parameter expression="${project.artifactId}
78       * @readonly
79       */
80      protected String name;
81  
82      /**
83       * The root of the project.
84       * 
85       * @parameter expression="${basedir}"
86       * @readonly
87       */
88      private String projectRoot;
89  
90      /**
91       * If pom packaging projects should be skipped. Typically these will not have source code and should be excluded.
92       * This is true by default because typically the application or projects will be created at a pom level and the poms
93       * have no source to be analyzed Only set this if you have source in your "pom" packaging projects that needs to be
94       * scanned.
95       * 
96       * @parameter expression="${ounce.skipPoms}" default-value="true"
97       */
98      protected boolean skipPoms;
99  
100     /**
101      * Extra Options supported by Ounce.
102      */
103     protected Map options;
104 
105     // set by the contextualize method. Only way to get the
106     // plugin's container in 2.0.x
107     protected PlexusContainer container;
108 
109     public void contextualize( Context context )
110         throws ContextException
111     {
112         container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
113     }
114 
115     protected OunceCore getCore()
116         throws ComponentLookupException
117     {
118         return (OunceCore) container.lookup( OunceCore.ROLE, coreHint );
119     }
120 
121     /**
122      * @return the project
123      */
124     protected MavenProject getProject()
125     {
126         return this.project;
127     }
128 
129     /**
130      * @param theProject the project to set
131      */
132     protected void setProject( MavenProject theProject )
133     {
134         this.project = theProject;
135     }
136 
137     /**
138      * @return the coreHint
139      */
140     protected String getCoreHint()
141     {
142         return this.coreHint;
143     }
144 
145     /**
146      * @param theCoreHint the coreHint to set
147      */
148     protected void setCoreHint( String theCoreHint )
149     {
150         this.coreHint = theCoreHint;
151     }
152 
153     /**
154      * @return the name
155      */
156     protected String getName()
157     {
158         return this.name;
159     }
160 
161     /**
162      * @param theName the name to set
163      */
164     protected void setName( String theName )
165     {
166         this.name = theName;
167     }
168 
169     /**
170      * @return the projectRoot
171      */
172     protected String getProjectRoot()
173     {
174         return this.projectRoot;
175     }
176 
177     /**
178      * @param theProjectRoot the projectRoot to set
179      */
180     protected void setProjectRoot( String theProjectRoot )
181     {
182         this.projectRoot = theProjectRoot;
183     }
184 
185     /**
186      * @return the skipPoms
187      */
188     public boolean isSkipPoms()
189     {
190         return this.skipPoms;
191     }
192 
193     /**
194      * @param theSkipPoms the skipPoms to set
195      */
196     public void setSkipPoms( boolean theSkipPoms )
197     {
198         this.skipPoms = theSkipPoms;
199     }
200 
201 }