1 package org.apache.maven.continuum.web.validator;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
34
35
36
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
47
48 private InstallationService installationService;
49
50
51
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
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
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 }