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
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
35
36
37
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
48
49 private InstallationService installationService;
50
51
52
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
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
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 }