~ubuntu-branches/ubuntu/utopic/maven-enforcer/utopic

« back to all changes in this revision

Viewing changes to enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractRequireFiles.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-12 22:30:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110912223016-e2pk04avoq8bur7t
Tags: 1.0-1
* Team upload
* New upstream release.
* Add more Build-Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.apache.maven.plugins.enforcer;
 
2
 
1
3
/*
2
4
 * Licensed to the Apache Software Foundation (ASF) under one
3
5
 * or more contributor license agreements.  See the NOTICE file
16
18
 * specific language governing permissions and limitations
17
19
 * under the License.
18
20
 */
19
 
package org.apache.maven.plugins.enforcer;
20
21
 
21
22
import java.io.File;
22
23
import java.util.ArrayList;
26
27
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
27
28
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
28
29
 
29
 
// TODO: Auto-generated Javadoc
30
30
/**
31
31
 * Contains the common code to compare an array of files against a requirement.
32
 
 * 
 
32
 *
33
33
 * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
34
34
 */
35
 
abstract public class AbstractRequireFiles
 
35
public abstract class AbstractRequireFiles
36
36
    extends AbstractStandardEnforcerRule
37
37
{
38
38
 
39
39
    /** Array of files to check. */
40
40
    File[] files;
41
 
    
42
 
    //if null file handles should be allowed. If they are allowed, it means treat it as a success.
 
41
 
 
42
    /** if null file handles should be allowed. If they are allowed, it means treat it as a success. */
43
43
    boolean allowNulls = false;
44
44
 
45
45
    // check the file for the specific condition
46
46
    /**
47
47
     * Check one file.
48
 
     * 
 
48
     *
49
49
     * @param file the file
50
50
     * @return <code>true</code> if successful
51
51
     */
52
52
    abstract boolean checkFile( File file );
53
53
 
54
 
    // retun standard error message
 
54
    // return standard error message
55
55
    /**
56
56
     * Gets the error msg.
57
 
     * 
 
57
     *
58
58
     * @return the error msg
59
59
     */
60
60
    abstract String getErrorMsg();
61
61
 
62
62
    /*
63
63
     * (non-Javadoc)
64
 
     * 
 
64
     *
65
65
     * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper)
66
66
     */
67
67
    public void execute( EnforcerRuleHelper helper )
68
68
        throws EnforcerRuleException
69
69
    {
70
 
        
71
 
        if (!allowNulls && files.length == 0)
 
70
 
 
71
        if ( !allowNulls && files.length == 0 )
72
72
        {
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." );
74
74
        }
75
75
 
76
76
        ArrayList failures = new ArrayList();
77
77
        for ( int i = 0; i < files.length; i++ )
78
78
        {
79
 
                if (!allowNulls && files[i] == null)
 
79
            if ( !allowNulls && files[i] == null )
80
80
                {
81
 
                        failures.add(files[i]);
 
81
                failures.add( files[i] );
82
82
                }
83
83
                else if ( !checkFile( files[i] ) )
84
84
            {
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.
122
 
     * 
 
122
     *
123
123
     * @return the cache id
124
124
     */
125
125
    public String getCacheId()
130
130
    /**
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.
133
 
     * 
 
133
     *
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.
136
136
     */
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.
156
 
     * 
 
156
     *
157
157
     * @return <code>true</code> if rule is cacheable
158
158
     */
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.
169
 
     * 
 
169
     *
170
170
     * @param cachedRule the cached rule
171
171
     * @return <code>true</code> if the stored results are valid for the same id.
172
172
     */