View Javadoc

1   package org.apache.maven.plugins.enforcer;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Date;
23  import java.util.Properties;
24  
25  import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
26  import org.apache.maven.execution.MavenSession;
27  import org.apache.maven.model.Plugin;
28  import org.apache.maven.plugin.logging.SystemStreamLog;
29  import org.apache.maven.plugins.enforcer.utils.MockEnforcerExpressionEvaluator;
30  import org.apache.maven.project.MavenProject;
31  import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
32  
33  // TODO: Auto-generated Javadoc
34  /**
35   * The Class EnforcerTestUtils.
36   *
37   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
38   */
39  public final class EnforcerTestUtils
40  {
41      /**
42       * Gets the maven session.
43       *
44       * @return the maven session
45       */
46      public static MavenSession getMavenSession()
47      {
48          return new MavenSession( new MockPlexusContainer(), null, null, null, null, null, null, new Properties(),
49                                   new Date() );
50      }
51  
52      /**
53       * Gets the helper.
54       *
55       * @return the helper
56       */
57      public static EnforcerRuleHelper getHelper()
58      {
59          return getHelper( new MockProject(), false );
60      }
61  
62      /**
63       * Gets the helper.
64       *
65       * @param mockExpression the mock expression
66       * @return the helper
67       */
68      public static EnforcerRuleHelper getHelper( boolean mockExpression )
69      {
70          return getHelper( new MockProject(), mockExpression );
71      }
72  
73      /**
74       * Gets the helper.
75       *
76       * @param project the project
77       * @return the helper
78       */
79      public static EnforcerRuleHelper getHelper( MavenProject project )
80      {
81          return getHelper( project, false );
82      }
83  
84      /**
85       * Gets the helper.
86       *
87       * @param project the project
88       * @param mockExpression the mock expression
89       * @return the helper
90       */
91      public static EnforcerRuleHelper getHelper( MavenProject project, boolean mockExpression )
92      {
93          MavenSession session = getMavenSession();
94          ExpressionEvaluator eval;
95          if ( mockExpression )
96          {
97              eval = new MockEnforcerExpressionEvaluator( session, new MockPathTranslator(), project );
98          }
99          else
100         {
101             eval = new EnforcerExpressionEvaluator( session, new MockPathTranslator(), project );
102         }
103         return new DefaultEnforcementRuleHelper( session, eval, new SystemStreamLog(), null );
104     }
105 
106     /**
107      * Gets the helper.
108      *
109      * @param project the project
110      * @param eval the expression evaluator to use
111      * @return the helper
112      */
113     public static EnforcerRuleHelper getHelper( MavenProject project, ExpressionEvaluator eval )
114     {
115         MavenSession session = getMavenSession();
116         return new DefaultEnforcementRuleHelper( session, eval, new SystemStreamLog(), null );
117     }
118 
119     /**
120      * New plugin.
121      *
122      * @param groupId the group id
123      * @param artifactId the artifact id
124      * @param version the version
125      * @return the plugin
126      */
127     public static Plugin newPlugin( String groupId, String artifactId, String version )
128     {
129         Plugin plugin = new Plugin();
130         plugin.setArtifactId( artifactId );
131         plugin.setGroupId( groupId );
132         plugin.setVersion( version );
133         return plugin;
134     }
135 }