Skip to content

Commit

Permalink
Make max property and doctype name lengths configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
winniae committed Dec 7, 2012
1 parent e230c8d commit bbf4cc1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ public abstract class AbstractBeanModellerMojo extends AbstractMojo {
*/
private int defaultPropertyStringLength;

/**
* Max length of property names to validate against.
*
* @parameter default-value=18
*/
private int maxPropertyNameLength = ContentBeanAnalyzator.MAX_PROPERTY_LENGTH;

/**
* Max length of doctype names to validate against.
*
* @parameter default-value=15
*/
private int maxDoctypeNameLength = ContentBeanAnalyzator.MAX_CONTENT_TYPE_LENGTH;

private long startTime;
private Long lastMeasurement = null;

Expand All @@ -51,6 +65,9 @@ protected Set<ContentBeanInformation> analyzeContentBeans() throws MojoFailureEx
// set parameters
analyzer.setPropertyDefaultStringLength(defaultPropertyStringLength);

analyzer.setMaxDoctypeNameLength(maxDoctypeNameLength);
analyzer.setMaxPropertyNameLength(maxPropertyNameLength);

// start analyzation
analyzer.findContentBeans(contentBeanPackage);
ContentBeanHierarchy hierarchy = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public class ContentBeanAnalyzator extends MavenProcessor {
// TODO 18 is only true for Oracle! MySQL for instance allows more chars.
public static final int MAX_PROPERTY_LENGTH = 18;

// now configurable
private int maxDoctypeNameLength = MAX_CONTENT_TYPE_LENGTH;
private int maxPropertyNameLength = MAX_PROPERTY_LENGTH;

private static final ContentBeanInformation PROPERTY_DEFAULT_LINKLIST_TYPE = EmptyContentBeanInformation.getInstance();

// this map is used during analyzation to track methods to consider as content bean properties, which is used later
Expand Down Expand Up @@ -306,9 +310,9 @@ private boolean checkMethod(ContentBeanAnalyzationException potentialException,
String documentTypePropertyName = getDocumentTypePropertyNameFromMethod(method);
// VALIDATE
//check if the property name name is too long
if (documentTypePropertyName.length() > MAX_PROPERTY_LENGTH) {
if (documentTypePropertyName.length() > maxPropertyNameLength) {
potentialException.addError(currentClass, documentTypePropertyName, ContentBeanAnalyzationException.METHODNAME_TOO_LOGN_FOR_DOCTPYENAME_MESSAGE + "max is " +
MAX_PROPERTY_LENGTH);
maxPropertyNameLength);
//we ignore this method
return true;
}
Expand Down Expand Up @@ -421,9 +425,9 @@ else if (isAspectDoctype) {
}

//check if the doctpye name name is too long
if (docTypeName.length() > MAX_CONTENT_TYPE_LENGTH) {
if (docTypeName.length() > maxDoctypeNameLength) {
potentialException.addError(classToAnalyze, ContentBeanAnalyzationException.CLASSNAME_TOO_LOGN_FOR_DOCTPYENAME_MESSAGE + classToAnalyze.getCanonicalName()
+ " (the name \'" + docTypeName + "\' is " + docTypeName.length() + " - max is " + MAX_CONTENT_TYPE_LENGTH + ").");
+ " (the name \'" + docTypeName + "\' is " + docTypeName.length() + " - max is " + maxDoctypeNameLength + ").");
// and ignore property
break;
}
Expand Down Expand Up @@ -857,4 +861,20 @@ public String getPropertyDefaultMarkupGrammar() {
public void setPropertyDefaultMarkupGrammar(String propertyDefaultMarkupGrammar) {
this.propertyDefaultMarkupGrammar = propertyDefaultMarkupGrammar;
}

public int getMaxDoctypeNameLength() {
return maxDoctypeNameLength;
}

public void setMaxDoctypeNameLength(int maxDoctypeNameLength) {
this.maxDoctypeNameLength = maxDoctypeNameLength;
}

public int getMaxPropertyNameLength() {
return maxPropertyNameLength;
}

public void setMaxPropertyNameLength(int maxPropertyNameLength) {
this.maxPropertyNameLength = maxPropertyNameLength;
}
}

0 comments on commit bbf4cc1

Please sign in to comment.