Author: rdonkin
Date: Fri Dec 6 18:40:33 2013
New Revision: 1548656
URL: http://svn.apache.org/r1548656
Log:
Reformatted code with spaces. The empty constructors are needed for reflection
used by the Maven and Ant plugins. This was caught by the integration tests.
Modified:
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
Modified:
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java
URL:
http://svn.apache.org/viewvc/creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java?rev=1548656&r1=1548655&r2=1548656&view=diff
==============================================================================
---
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java
(original)
+++
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/BaseLicense.java
Fri Dec 6 18:40:33 2013
@@ -26,136 +26,147 @@ import org.apache.rat.api.MetaData;
*/
public class BaseLicense {
- /** The license family category. */
- private String licenseFamilyCategory;
+ /** The license family category. */
+ private String licenseFamilyCategory;
- /** The license family name. */
- private String licenseFamilyName;
+ /** The license family name. */
+ private String licenseFamilyName;
- /** The notes. */
- private String notes;
+ /** The notes. */
+ private String notes;
- /**
- * Instantiates a new base license.
- *
- * @param licenseFamilyCategory
- * the license family category
- * @param licenseFamilyName
- * the license family name
- * @param notes
- * the notes
- */
- public BaseLicense(final MetaData.Datum licenseFamilyCategory,
- final MetaData.Datum licenseFamilyName, final String
notes) {
- if (!MetaData.RAT_URL_LICENSE_FAMILY_CATEGORY
- .equals(licenseFamilyCategory.getName())) {
- throw new IllegalStateException("Expected "
- +
MetaData.RAT_URL_LICENSE_FAMILY_CATEGORY + ", got "
- + licenseFamilyCategory.getName());
- }
- setLicenseFamilyCategory(licenseFamilyCategory.getValue());
- if
(!MetaData.RAT_URL_LICENSE_FAMILY_NAME.equals(licenseFamilyName
- .getName())) {
- throw new IllegalStateException("Expected "
- + MetaData.RAT_URL_LICENSE_FAMILY_NAME
+ ", got "
- + licenseFamilyName.getName());
- }
- setLicenseFamilyName(licenseFamilyName.getValue());
- setNotes(notes);
- }
-
- /**
- * Gets the license family category.
- *
- * @return the license family category
- */
- public String getLicenseFamilyCategory() {
- return licenseFamilyCategory;
- }
-
- /**
- * Sets the license family category.
- *
- * @param pDocumentCategory
- * the new license family category
- */
- public void setLicenseFamilyCategory(final String pDocumentCategory) {
- licenseFamilyCategory = pDocumentCategory;
- }
-
- /**
- * Gets the license family name.
- *
- * @return the license family name
- */
- public String getLicenseFamilyName() {
- return licenseFamilyName;
- }
-
- /**
- * Sets the license family name.
- *
- * @param pLicenseFamilyCategory
- * the new license family name
- */
- public void setLicenseFamilyName(final String pLicenseFamilyCategory) {
- licenseFamilyName = pLicenseFamilyCategory;
- }
-
- /**
- * Gets the notes.
- *
- * @return the notes
- */
- public String getNotes() {
- return notes;
- }
-
- /**
- * Sets the notes.
- *
- * @param pNotes
- * the new notes
- */
- public void setNotes(final String pNotes) {
- notes = pNotes;
- }
-
- /**
- * Report on license.
- *
- * @param subject
- * the subject
- */
- public final void reportOnLicense(final Document subject) {
- final MetaData metaData = subject.getMetaData();
- metaData.set(new MetaData.Datum(MetaData.RAT_URL_HEADER_SAMPLE,
notes));
- final String licFamilyCategory = getLicenseFamilyCategory();
- metaData.set(new
MetaData.Datum(MetaData.RAT_URL_HEADER_CATEGORY,
- licFamilyCategory));
- metaData.set(new MetaData.Datum(
- MetaData.RAT_URL_LICENSE_FAMILY_CATEGORY,
licFamilyCategory));
- metaData.set(new
MetaData.Datum(MetaData.RAT_URL_LICENSE_FAMILY_NAME,
- getLicenseFamilyName()));
- }
-
- /**
- * Prune.
- *
- * @param text
- * the text
- * @return the string
- */
- protected static final String prune(final String text) {
- final int length = text.length();
- final StringBuilder buffer = new StringBuilder(length);
- for (int i = 0; i < length; i++) {
- char charIndex = text.charAt(i);
- if (Character.isLetterOrDigit(charIndex)) {
- buffer.append(charIndex);
- }
- }
- return buffer.toString();
- }
+ /**
+ * Constructs empty base license. Useful when creating an instance via
+ * reflection.
+ */
+ public BaseLicense() {
+ this.licenseFamilyCategory = null;
+ this.licenseFamilyName = null;
+ this.notes = null;
+ }
+
+ /**
+ * Instantiates a new base license.
+ *
+ * @param licenseFamilyCategory
+ * the license family category
+ * @param licenseFamilyName
+ * the license family name
+ * @param notes
+ * the notes
+ */
+ public BaseLicense(final MetaData.Datum licenseFamilyCategory,
+ final MetaData.Datum licenseFamilyName, final String notes) {
+ if (!MetaData.RAT_URL_LICENSE_FAMILY_CATEGORY
+ .equals(licenseFamilyCategory.getName())) {
+ throw new IllegalStateException("Expected "
+ + MetaData.RAT_URL_LICENSE_FAMILY_CATEGORY + ", got "
+ + licenseFamilyCategory.getName());
+ }
+ setLicenseFamilyCategory(licenseFamilyCategory.getValue());
+ if (!MetaData.RAT_URL_LICENSE_FAMILY_NAME.equals(licenseFamilyName
+ .getName())) {
+ throw new IllegalStateException("Expected "
+ + MetaData.RAT_URL_LICENSE_FAMILY_NAME + ", got "
+ + licenseFamilyName.getName());
+ }
+ setLicenseFamilyName(licenseFamilyName.getValue());
+ setNotes(notes);
+ }
+
+ /**
+ * Gets the license family category.
+ *
+ * @return the license family category
+ */
+ public String getLicenseFamilyCategory() {
+ return this.licenseFamilyCategory;
+ }
+
+ /**
+ * Sets the license family category.
+ *
+ * @param pDocumentCategory
+ * the new license family category
+ */
+ public void setLicenseFamilyCategory(final String pDocumentCategory) {
+ this.licenseFamilyCategory = pDocumentCategory;
+ }
+
+ /**
+ * Gets the license family name.
+ *
+ * @return the license family name
+ */
+ public String getLicenseFamilyName() {
+ return this.licenseFamilyName;
+ }
+
+ /**
+ * Sets the license family name.
+ *
+ * @param pLicenseFamilyCategory
+ * the new license family name
+ */
+ public void setLicenseFamilyName(final String pLicenseFamilyCategory) {
+ this.licenseFamilyName = pLicenseFamilyCategory;
+ }
+
+ /**
+ * Gets the notes.
+ *
+ * @return the notes
+ */
+ public String getNotes() {
+ return this.notes;
+ }
+
+ /**
+ * Sets the notes.
+ *
+ * @param pNotes
+ * the new notes
+ */
+ public void setNotes(final String pNotes) {
+ this.notes = pNotes;
+ }
+
+ /**
+ * Report on license.
+ *
+ * @param subject
+ * the subject
+ */
+ public final void reportOnLicense(final Document subject) {
+ final MetaData metaData = subject.getMetaData();
+ metaData.set(new MetaData.Datum(MetaData.RAT_URL_HEADER_SAMPLE,
+ this.notes));
+ final String licFamilyCategory = getLicenseFamilyCategory();
+ metaData.set(new MetaData.Datum(MetaData.RAT_URL_HEADER_CATEGORY,
+ licFamilyCategory));
+ metaData.set(new MetaData.Datum(
+ MetaData.RAT_URL_LICENSE_FAMILY_CATEGORY, licFamilyCategory));
+ metaData.set(new MetaData.Datum(MetaData.RAT_URL_LICENSE_FAMILY_NAME,
+ getLicenseFamilyName()));
+ }
+
+ /**
+ * Prune.
+ *
+ * @param text
+ * the text
+ * @return the string
+ */
+ protected static final String prune(final String text) {
+ final int length = text.length();
+ final StringBuilder buffer = new StringBuilder(length);
+ for (int i = 0; i < length; i++) {
+ final char charIndex = text.charAt(i);
+ if (Character.isLetterOrDigit(charIndex)) {
+ buffer.append(charIndex);
+ }
+ }
+ return buffer.toString();
+ }
}
Modified:
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java
URL:
http://svn.apache.org/viewvc/creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java?rev=1548656&r1=1548655&r2=1548656&view=diff
==============================================================================
---
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java
(original)
+++
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/FullTextMatchingLicense.java
Fri Dec 6 18:40:33 2013
@@ -37,112 +37,132 @@ import org.apache.rat.api.MetaData.Datum
* @since Rat 0.9
*/
public class FullTextMatchingLicense extends BaseLicense implements
- IHeaderMatcher {
+ IHeaderMatcher {
- /** The Constant DEFAULT_INITIAL_LINE_LENGTH. */
- // Number of match characters assumed to be present on first line
- private static final int DEFAULT_INITIAL_LINE_LENGTH = 20;
-
- private static final int ZERO = 0;
-
- /** The full text. */
- private String fullText;
-
- /** The first line. */
- private String firstLine;
-
- /** The seen first line. */
- private boolean seenFirstLine;
-
- /** The buffer. */
- private final StringBuilder buffer = new StringBuilder();
-
- /**
- * Instantiates a new full text matching license.
- *
- * @param licenseFamilyCategory the license family category
- * @param licenseFamilyName the license family name
- * @param notes the notes
- * @param fullText the full text
- */
- protected FullTextMatchingLicense(final Datum licenseFamilyCategory,
- final Datum licenseFamilyName, final String notes,
final String fullText) {
- super(licenseFamilyCategory, licenseFamilyName, notes);
- setFullText(fullText);
- }
-
- /**
- * Sets the full text.
- *
- * @param text the new full text
- */
- public final void setFullText(final String text) {
- int offset = text.indexOf('\n');
- if (offset == -1) {
- offset = Math.min(DEFAULT_INITIAL_LINE_LENGTH,
text.length());
- }
- firstLine = prune(text.substring(0, offset))
- .toLowerCase(Locale.ENGLISH);
- fullText = prune(text).toLowerCase(Locale.ENGLISH);
- init();
- }
-
- /**
- * Checks for full text.
- *
- * @return true, if successful
- */
- public final boolean hasFullText() {
- return fullText != null;
- }
-
- /* (non-Javadoc)
- * @see
org.apache.rat.analysis.IHeaderMatcher#match(org.apache.rat.api.Document,
java.lang.String)
- */
- public boolean match(final Document subject, final String line) {
- boolean result = false;
- boolean follow = true;
- final String inputToMatch =
prune(line).toLowerCase(Locale.ENGLISH);
- if (seenFirstLine) {
- // Accumulate more input
- buffer.append(inputToMatch);
- } else {
- int offset = inputToMatch.indexOf(firstLine);
- if (offset >= ZERO) {
- // we have a match, save the text starting with
the match
- buffer.append(inputToMatch.substring(offset));
- seenFirstLine = true;
- // Drop out to check whether full text is
matched
- } else {
- // we assume that the first line must appear in
a single line no
- // more to do here
- result = false;
- follow = false;
- }
- }
- if (buffer.length() >= fullText.length() && follow) {
- // we have enough data to match
- if (buffer.toString().contains(fullText)) {
- reportOnLicense(subject);
- // we found a match
- result = true;
- }
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see org.apache.rat.analysis.IHeaderMatcher#reset()
- */
- public void reset() {
- init();
- }
-
- /**
- * This is called indirectly from a ctor so must be final or private
- */
- private void init() {
- buffer.setLength(0);
- seenFirstLine = false;
- }
+ /** The Constant DEFAULT_INITIAL_LINE_LENGTH. */
+ // Number of match characters assumed to be present on first line
+ private static final int DEFAULT_INITIAL_LINE_LENGTH = 20;
+
+ private static final int ZERO = 0;
+
+ /** The full text. */
+ private String fullText;
+
+ /** The first line. */
+ private String firstLine;
+
+ /** The seen first line. */
+ private boolean seenFirstLine;
+
+ /** The buffer. */
+ private final StringBuilder buffer = new StringBuilder();
+
+ /**
+ * Constructor suitable for reflection.
+ */
+ public FullTextMatchingLicense() {
+ super();
+ this.fullText = null;
+ }
+
+ /**
+ * Instantiates a new full text matching license.
+ *
+ * @param licenseFamilyCategory
+ * the license family category
+ * @param licenseFamilyName
+ * the license family name
+ * @param notes
+ * the notes
+ * @param fullText
+ * the full text
+ */
+ public FullTextMatchingLicense(final Datum licenseFamilyCategory,
+ final Datum licenseFamilyName, final String notes,
+ final String fullText) {
+ super(licenseFamilyCategory, licenseFamilyName, notes);
+ setFullText(fullText);
+ }
+
+ /**
+ * Sets the full text.
+ *
+ * @param text
+ * the new full text
+ */
+ public final void setFullText(final String text) {
+ int offset = text.indexOf('\n');
+ if (offset == -1) {
+ offset = Math.min(DEFAULT_INITIAL_LINE_LENGTH, text.length());
+ }
+ this.firstLine =
+ prune(text.substring(0, offset)).toLowerCase(Locale.ENGLISH);
+ this.fullText = prune(text).toLowerCase(Locale.ENGLISH);
+ init();
+ }
+
+ /**
+ * Checks for full text.
+ *
+ * @return true, if successful
+ */
+ public final boolean hasFullText() {
+ return this.fullText != null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ *
org.apache.rat.analysis.IHeaderMatcher#match(org.apache.rat.api.Document,
+ * java.lang.String)
+ */
+ public boolean match(final Document subject, final String line) {
+ boolean result = false;
+ boolean follow = true;
+ final String inputToMatch = prune(line).toLowerCase(Locale.ENGLISH);
+ if (this.seenFirstLine) {
+ // Accumulate more input
+ this.buffer.append(inputToMatch);
+ } else {
+ final int offset = inputToMatch.indexOf(this.firstLine);
+ if (offset >= ZERO) {
+ // we have a match, save the text starting with the match
+ this.buffer.append(inputToMatch.substring(offset));
+ this.seenFirstLine = true;
+ // Drop out to check whether full text is matched
+ } else {
+ // we assume that the first line must appear in a single line
no
+ // more to do here
+ result = false;
+ follow = false;
+ }
+ }
+ if (this.buffer.length() >= this.fullText.length() && follow) {
+ // we have enough data to match
+ if (this.buffer.toString().contains(this.fullText)) {
+ reportOnLicense(subject);
+ // we found a match
+ result = true;
+ }
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.rat.analysis.IHeaderMatcher#reset()
+ */
+ public void reset() {
+ init();
+ }
+
+ /**
+ * This is called indirectly from a ctor so must be final or private
+ */
+ private void init() {
+ this.buffer.setLength(0);
+ this.seenFirstLine = false;
+ }
}
\ No newline at end of file
Modified:
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
URL:
http://svn.apache.org/viewvc/creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java?rev=1548656&r1=1548655&r2=1548656&view=diff
==============================================================================
---
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
(original)
+++
creadur/rat/branches/gsoc/apache-rat-core/src/main/java/org/apache/rat/analysis/license/SimplePatternBasedLicense.java
Fri Dec 6 18:40:33 2013
@@ -28,91 +28,95 @@ import org.apache.rat.api.MetaData.Datum
* @since Rat 0.8
*/
public class SimplePatternBasedLicense extends BaseLicense implements
- IHeaderMatcher {
+ IHeaderMatcher {
- /** The patterns. */
- private String[] patterns;
-
- private static final int ZERO = 0;
-
- /**
- * Instantiates a new simple pattern based license.
- *
- * @param pLicenseFamilyCategory
- * the license family category
- * @param pLicenseFamilyName
- * the license family name
- * @param pNotes
- * the notes
- * @param pPatterns
- * the patterns
- */
- protected SimplePatternBasedLicense(final Datum pLicenseFamilyCategory,
- final Datum pLicenseFamilyName, final String pNotes,
final String... pPatterns) {
- super(pLicenseFamilyCategory, pLicenseFamilyName, pNotes);
- setPatterns(pPatterns);
- }
-
- /**
- * Gets the patterns.
- *
- * @return the patterns
- */
- public String[] getPatterns() {
- return patterns.clone();
- }
-
- /**
- * Sets the patterns.
- *
- * @param pPatterns
- * the new patterns
- */
- public void setPatterns(final String... pPatterns) {
- patterns = pPatterns;
- }
-
- /**
- * Matches.
- *
- * @param pLine
- * the line
- * @return true, if successful
- */
- protected boolean matches(final String pLine) {
- boolean result = false;
- final String[] pttrns = getPatterns();
- if (pLine != null && pttrns != null) {
- for (String pttrn : pttrns) {
- if (pLine.indexOf(pttrn, 0) >= ZERO) {
- result = true;
- }
- }
- }
- return result;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.rat.analysis.IHeaderMatcher#reset()
- */
- public void reset() {
- // Nothing to do
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- *
org.apache.rat.analysis.IHeaderMatcher#match(org.apache.rat.api.Document,
- * java.lang.String)
- */
- public boolean match(final Document pSubject, final String pLine) {
- final boolean result = matches(pLine);
- if (result) {
- reportOnLicense(pSubject);
- }
- return result;
- }
+ /** The patterns. */
+ private String[] patterns;
+
+ private static final int ZERO = 0;
+
+ /**
+ * Constructs empty base license. Useful when creating an instance via
+ * reflection.
+ */
+ public SimplePatternBasedLicense() {
+ super();
+ }
+
+ /**
+ * Constructs an instance with data filled in.
+ *
+ * @param pLicenseFamilyCategory
+ * the license family category, not null
+ * @param pLicenseFamilyName
+ * the license family name, not null
+ * @param pNotes
+ * the notes, not null
+ * @param pPatterns
+ * the patterns, not null
+ */
+ public SimplePatternBasedLicense(final Datum pLicenseFamilyCategory,
+ final Datum pLicenseFamilyName, final String pNotes,
+ final String... pPatterns) {
+ super(pLicenseFamilyCategory, pLicenseFamilyName, pNotes);
+ setPatterns(pPatterns);
+ }
+
+ /**
+ * Gets the patterns.
+ *
+ * @return the patterns
+ */
+ public String[] getPatterns() {
+ return this.patterns.clone();
+ }
+
+ /**
+ * Sets the patterns.
+ *
+ * @param pPatterns
+ * the new patterns
+ */
+ public void setPatterns(final String... pPatterns) {
+ this.patterns = pPatterns;
+ }
+
+ /**
+ * Does the line match this license pattern?
+ *
+ * @param pLine
+ * the line
+ * @return true when the line matches, false otherwise
+ */
+ protected boolean matches(final String pLine) {
+ boolean result = false;
+ final String[] pttrns = getPatterns();
+ if (pLine != null && pttrns != null) {
+ for (final String pttrn : pttrns) {
+ if (pLine.indexOf(pttrn, 0) >= ZERO) {
+ result = true;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @see org.apache.rat.analysis.IHeaderMatcher#reset()
+ */
+ public void reset() {
+ // Nothing to do
+ }
+
+ /**
+ * @see
org.apache.rat.analysis.IHeaderMatcher#match(org.apache.rat.api.Document,
+ * java.lang.String)
+ */
+ public boolean match(final Document pSubject, final String pLine) {
+ final boolean result = matches(pLine);
+ if (result) {
+ reportOnLicense(pSubject);
+ }
+ return result;
+ }
}