Class AbstractRequireFiles
- java.lang.Object
-
- org.apache.maven.plugins.enforcer.AbstractStandardEnforcerRule
-
- org.apache.maven.plugins.enforcer.AbstractRequireFiles
-
- All Implemented Interfaces:
EnforcerRule,EnforcerRule2
- Direct Known Subclasses:
RequireFilesDontExist,RequireFilesExist,RequireFilesSize
public abstract class AbstractRequireFiles extends AbstractStandardEnforcerRule
Contains the common code to compare an array of files against a requirement.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowNullsif null file handles should be allowed.private java.io.File[]filesArray of files to check.
-
Constructor Summary
Constructors Constructor Description AbstractRequireFiles()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) abstract booleancheckFile(java.io.File file)Check one file.voidexecute(EnforcerRuleHelper helper)This is the interface into the rule.java.lang.StringgetCacheId()If your rule is cacheable, you must return a unique id when parameters or conditions change that would cause the result to be different.(package private) abstract java.lang.StringgetErrorMsg()Gets the error msg.java.io.File[]getFiles()private static inthashCode(java.lang.Object[] items)Calculates a hash code for the specified array asArrays.hashCode()would do.booleanisAllowNulls()booleanisCacheable()This tells the system if the results are cacheable at all.booleanisResultValid(EnforcerRule cachedRule)If the rule is cacheable and the same id is found in the cache, the stored results are passed to this method to allow double checking of the results.voidsetAllowNulls(boolean allowNulls)voidsetFiles(java.io.File[] files)-
Methods inherited from class org.apache.maven.plugins.enforcer.AbstractStandardEnforcerRule
getLevel, getMessage, setLevel, setMessage
-
-
-
-
Method Detail
-
checkFile
abstract boolean checkFile(java.io.File file)
Check one file.- Parameters:
file- the file- Returns:
trueif successful
-
getErrorMsg
abstract java.lang.String getErrorMsg()
Gets the error msg.- Returns:
- the error msg
-
execute
public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException
Description copied from interface:EnforcerRuleThis is the interface into the rule. This method should throw an exception containing a reason message if the rule fails the check. The plugin will then decide based on the fail flag if it should stop or just log the message as a warning.- Parameters:
helper- The helper provides access to the log, MavenSession and has helpers to get common components. It is also able to lookup components by class name.- Throws:
EnforcerRuleException- the enforcer rule exception
-
getCacheId
public java.lang.String getCacheId()
If your rule is cacheable, you must return a unique id when parameters or conditions change that would cause the result to be different. Multiple cached results are stored based on their id. The easiest way to do this is to return a hash computed from the values of your parameters. If your rule is not cacheable, then the result here is not important, you may return anything.- Returns:
- the cache id
-
hashCode
private static int hashCode(java.lang.Object[] items)
Calculates a hash code for the specified array asArrays.hashCode()would do. Unfortunately, the mentioned method is only available for Java 1.5 and later.- Parameters:
items- The array for which to compute the hash code, may benull.- Returns:
- The hash code for the array.
-
isCacheable
public boolean isCacheable()
This tells the system if the results are cacheable at all. Keep in mind that during forked builds and other things, a given rule may be executed more than once for the same project. This means that even things that change from project to project may still be cacheable in certain instances.- Returns:
trueif rule is cacheable
-
isResultValid
public boolean isResultValid(EnforcerRule cachedRule)
If the rule is cacheable and the same id is found in the cache, the stored results are passed to this method to allow double checking of the results. Most of the time this can be done by generating unique ids, but sometimes the results of objects returned by the helper need to be queried. You may for example, store certain objects in your rule and then query them later.- Parameters:
cachedRule- the cached rule- Returns:
trueif the stored results are valid for the same id.
-
getFiles
public java.io.File[] getFiles()
-
setFiles
public void setFiles(java.io.File[] files)
-
isAllowNulls
public boolean isAllowNulls()
-
setAllowNulls
public void setAllowNulls(boolean allowNulls)
-
-