26
27
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
27
28
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
29
// TODO: Auto-generated Javadoc
31
31
* Contains the common code to compare an array of files against a requirement.
33
33
* @author <a href="mailto:brianf@apache.org">Brian Fox</a>
35
abstract public class AbstractRequireFiles
35
public abstract class AbstractRequireFiles
36
36
extends AbstractStandardEnforcerRule
39
39
/** Array of files to check. */
42
//if null file handles should be allowed. If they are allowed, it means treat it as a success.
42
/** if null file handles should be allowed. If they are allowed, it means treat it as a success. */
43
43
boolean allowNulls = false;
45
45
// check the file for the specific condition
49
49
* @param file the file
50
50
* @return <code>true</code> if successful
52
52
abstract boolean checkFile( File file );
54
// retun standard error message
54
// return standard error message
56
56
* Gets the error msg.
58
58
* @return the error msg
60
60
abstract String getErrorMsg();
65
65
* @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper)
67
67
public void execute( EnforcerRuleHelper helper )
68
68
throws EnforcerRuleException
71
if (!allowNulls && files.length == 0)
71
if ( !allowNulls && files.length == 0 )
73
throw new EnforcerRuleException("The file list is empty and Null files are disabled.");
73
throw new EnforcerRuleException( "The file list is empty and Null files are disabled." );
76
76
ArrayList failures = new ArrayList();
77
77
for ( int i = 0; i < files.length; i++ )
79
if (!allowNulls && files[i] == null)
79
if ( !allowNulls && files[i] == null )
81
failures.add(files[i]);
81
failures.add( files[i] );
83
83
else if ( !checkFile( files[i] ) )
119
119
* result to be different. Multiple cached results are stored based on their id. The easiest way to do this is to
120
120
* return a hash computed from the values of your parameters. If your rule is not cacheable, then the result here is
121
121
* not important, you may return anything.
123
123
* @return the cache id
125
125
public String getCacheId()
131
131
* Calculates a hash code for the specified array as <code>Arrays.hashCode()</code> would do. Unfortunately, the
132
132
* mentioned method is only available for Java 1.5 and later.
134
134
* @param items The array for which to compute the hash code, may be <code>null</code>.
135
135
* @return The hash code for the array.
153
153
* This tells the system if the results are cacheable at all. Keep in mind that during forked builds and other
154
154
* things, a given rule may be executed more than once for the same project. This means that even things that change
155
155
* from project to project may still be cacheable in certain instances.
157
157
* @return <code>true</code> if rule is cacheable
159
159
public boolean isCacheable()
166
166
* allow double checking of the results. Most of the time this can be done by generating unique ids, but sometimes
167
167
* the results of objects returned by the helper need to be queried. You may for example, store certain objects in
168
168
* your rule and then query them later.
170
170
* @param cachedRule the cached rule
171
171
* @return <code>true</code> if the stored results are valid for the same id.