View Javadoc

1   package org.apache.maven.continuum.web.validator;
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 com.opensymphony.xwork2.validator.ValidationException;
23  import com.opensymphony.xwork2.validator.validators.ValidatorSupport;
24  import org.apache.maven.continuum.execution.ExecutorConfigurator;
25  import org.apache.maven.continuum.installation.InstallationException;
26  import org.apache.maven.continuum.installation.InstallationService;
27  import org.codehaus.plexus.util.StringUtils;
28  import org.slf4j.Logger;
29  import org.slf4j.LoggerFactory;
30  
31  
32  /**
33   * @author <a href="mailto:olamy@codehaus.org">olamy</a>
34   * @version $Id: InstallationValidator.java 1372260 2012-08-13 04:29:09Z brett $
35   * @plexus.component role="com.opensymphony.xwork2.validator.Validator" role-hint="org.apache.maven.continuum.web.validator.InstallationValidator"
36   * @since 19 juin 07
37   */
38  public class InstallationValidator
39      extends ValidatorSupport
40  {
41      private String fieldName;
42  
43      private static final Logger logger = LoggerFactory.getLogger( InstallationValidator.class );
44  
45      /**
46       * @plexus.requirement role-hint="default"
47       */
48      private InstallationService installationService;
49  
50      /**
51       * @see com.opensymphony.xwork2.validator.Validator#validate(java.lang.Object)
52       */
53      public void validate( Object object )
54          throws ValidationException
55      {
56          String name = (String) this.getFieldValue( "installation.name", object );
57          if ( StringUtils.isEmpty( name ) )
58          {
59              return;
60          }
61  
62          String varValue = (String) this.getFieldValue( "installation.varValue", object );
63          if ( StringUtils.isEmpty( varValue ) )
64          {
65              return;
66          }
67          // TODO validating varValue != null depending on type (not null for envVar)
68  
69          String type = (String) this.getFieldValue( "installation.type", object );
70  
71          ExecutorConfigurator executorConfigurator = installationService.getExecutorConfigurator( type );
72          try
73          {
74              if ( executorConfigurator != null )
75              {
76                  if ( executorConfigurator.getVersionArgument() != null )
77                  {
78                      // just try to get version infos to validate path is valid
79                      installationService.getExecutorConfiguratorVersion( varValue, executorConfigurator, null );
80                  }
81              }
82          }
83          catch ( InstallationException e )
84          {
85              String message = getMessage( getMessageKey() ) + e.getMessage();
86              logger.error( message );
87              addFieldError( "installation.varValue", message );
88          }
89      }
90  
91      public String getFieldName()
92      {
93          return fieldName;
94      }
95  
96      public void setFieldName( String fieldName )
97      {
98          this.fieldName = fieldName;
99      }
100 }