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