Skip to content

Commit

Permalink
Cleaned up documentation and consolidated and removed unused source
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudenw committed May 9, 2024
1 parent d12fcc1 commit 008e684
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public void run(final RatReport report) throws RatException {

/**
* Creates an input stream from the Directory being walked.
* @return
* @throws IOException
* @return A buffered input stream reading the archive data.
* @throws IOException on error
*/
private InputStream createInputStream() throws IOException {
return new BufferedInputStream(getDocument().inputStream());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class Walker implements IReportable {
private final Document document;

/**
* Create the walker
* Creates the walker
* @param document The document the walker is walking.
* @param filesToIgnore the Files to ignore. If {@code null} no files are ignored.
*/
Expand All @@ -48,15 +48,15 @@ protected Walker(final Document document, final FilenameFilter filesToIgnore) {
}

/**
* Retrieve the file from the constructor.
* @return the file from the constructor.
* Retrieves the document from the constructor.
* @return the document from the constructor.
*/
protected Document getDocument() {
return document;
}

/**
* Test if the specified path should be ignored.
* Tests if the specified path should be ignored.
* @param pth the Path to test
* @return {@code true} if the file should not be ignored.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
import java.util.Arrays;

import org.apache.rat.api.Document;
import org.apache.rat.testhelpers.TestingDocument;
import org.apache.rat.license.ILicense;
import org.apache.rat.testhelpers.TestingLicense;
import org.apache.rat.testhelpers.TestingLocation;
import org.junit.jupiter.api.Test;


public class HeaderCheckWorkerTest {

@Test
public void isFinished() throws Exception {
final Document subject = new TestingLocation("subject");
final Document subject = new TestingDocument("subject");
ILicense matcher = new TestingLicense();
HeaderCheckWorker worker = new HeaderCheckWorker(new StringReader(""), Arrays.asList(matcher), subject);
worker.read();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
package org.apache.rat.document.impl.guesser;

import org.apache.rat.document.MockDocument;
import org.apache.rat.testhelpers.TestingDocument;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -27,13 +27,13 @@ public class NoteGuesserTest {

@Test
public void testMatches() {
assertTrue(NoteGuesser.isNote(new MockDocument("DEPENDENCIES")));
assertTrue(NoteGuesser.isNote(new MockDocument("LICENSE")));
assertTrue(NoteGuesser.isNote(new MockDocument("LICENSE.txt")));
assertTrue(NoteGuesser.isNote(new MockDocument("NOTICE")));
assertTrue(NoteGuesser.isNote(new MockDocument("NOTICE.txt")));
assertTrue(NoteGuesser.isNote(new MockDocument("README")));
assertTrue(NoteGuesser.isNote(new MockDocument("README.txt")));
assertTrue(NoteGuesser.isNote(new TestingDocument("DEPENDENCIES")));
assertTrue(NoteGuesser.isNote(new TestingDocument("LICENSE")));
assertTrue(NoteGuesser.isNote(new TestingDocument("LICENSE.txt")));
assertTrue(NoteGuesser.isNote(new TestingDocument("NOTICE")));
assertTrue(NoteGuesser.isNote(new TestingDocument("NOTICE.txt")));
assertTrue(NoteGuesser.isNote(new TestingDocument("README")));
assertTrue(NoteGuesser.isNote(new TestingDocument("README.txt")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.apache.rat.document.impl.util;

import org.apache.rat.document.IDocumentAnalyser;
import org.apache.rat.document.MockDocument;
import org.apache.rat.document.MockDocumentAnalyser;
import org.apache.rat.testhelpers.TestingDocument;
import org.apache.rat.testhelpers.TestingDocumentAnalyser;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -30,30 +30,30 @@ public class DocumentAnalyserMultiplexerTest {

private DocumentAnalyserMultiplexer multiplexer;
private IDocumentAnalyser[] analysers;
private MockDocument document;
private TestingDocument document;

@BeforeEach
public void setUp() {
IDocumentAnalyser[] analysers = {
new MockDocumentAnalyser(),
new MockDocumentAnalyser(),
new MockDocumentAnalyser()
new TestingDocumentAnalyser(),
new TestingDocumentAnalyser(),
new TestingDocumentAnalyser()
};
this.analysers = analysers;
document = new MockDocument();
document = new TestingDocument();
multiplexer = new DocumentAnalyserMultiplexer(analysers);
}

@Test
public void testAnalyse() throws Exception {
multiplexer.analyse(document);
MockDocumentAnalyser analyser = (MockDocumentAnalyser) (analysers[0]);
TestingDocumentAnalyser analyser = (TestingDocumentAnalyser) (analysers[0]);
assertEquals(1, analyser.matches.size(),"Call made to analyser");
assertEquals( document, analyser.matches.get(0), "Call made to analyser");
analyser = (MockDocumentAnalyser) (analysers[1]);
analyser = (TestingDocumentAnalyser) (analysers[1]);
assertEquals(1, analyser.matches.size(), "Call made to analyser");
assertEquals(document, analyser.matches.get(0), "Call made to analyser");
analyser = (MockDocumentAnalyser) (analysers[2]);
analyser = (TestingDocumentAnalyser) (analysers[2]);
assertEquals( 1, analyser.matches.size());
assertEquals( document, analyser.matches.get(0),"Call made to analyser");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.rat.license.LicenseFamilySetFactory;
import org.apache.rat.license.LicenseSetFactory.LicenseFilter;
import org.apache.rat.testhelpers.TestingLicense;
import org.apache.rat.testhelpers.TestingLocation;
import org.apache.rat.testhelpers.TestingDocument;
import org.apache.rat.utils.DefaultLog;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -62,7 +62,7 @@ public class DefaultPolicyTest {
public void setUp() throws Exception {
defaults = Defaults.builder().build(DefaultLog.INSTANCE);
policy = new DefaultPolicy(defaults.getLicenseFamilies(LicenseFilter.APPROVED));
document = new TestingLocation("subject");
document = new TestingDocument("subject");
}

private void assertApproval(boolean pApproved) {
Expand Down Expand Up @@ -153,7 +153,7 @@ public void testNonStandardDocumentsDoNotFailLicenseTests() {
Document.Type[] nonStandardDocuments = { Document.Type.NOTICE, Document.Type.ARCHIVE, Document.Type.BINARY };

for (Document.Type d : nonStandardDocuments) {
document = new TestingLocation("subject");
document = new TestingDocument("subject");
document.getMetaData().setDocumentType(d);
policy.analyse(document);
assertEquals(0, document.getMetaData().licenses().count(), "failed on " + d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,29 @@
* specific language governing permissions and limitations *
* under the License. *
*/
package org.apache.rat.document;
package org.apache.rat.testhelpers;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.SortedSet;

import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData;

public class MockDocument extends Document {
public class TestingDocument extends Document {

private final Reader reader;

public MockDocument() {
public TestingDocument() {
this(null, "name");
}

public MockDocument(String name) {
public TestingDocument(String name) {
this(null, name);
}

public MockDocument(Reader reader, String name) {
public TestingDocument(Reader reader, String name) {
super(name);
this.reader = reader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
* specific language governing permissions and limitations *
* under the License. *
*/
package org.apache.rat.document;
package org.apache.rat.testhelpers;

import java.util.ArrayList;
import java.util.List;

import org.apache.rat.api.Document;
import org.apache.rat.document.IDocumentAnalyser;

public class MockDocumentAnalyser implements IDocumentAnalyser {
public class TestingDocumentAnalyser implements IDocumentAnalyser {

public final List<Document> matches = new ArrayList<>();

@Override
public void analyse(Document document) throws RatDocumentAnalysisException {
public void analyse(Document document) {
matches.add(document);
}

Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions apache-rat/src/site/apt/index.apt.vm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ usage: java -jar apache-rat/target/apache-rat-${project.version}.jar
-A,--addLicense Add the default license header to any file with an unknown license that is not in the
exclusion list. By default new files will be created with the license header, to force the
modification of existing files use the --force option.
--archive <ProcessingType> Specifies how ARCHIVE processing will be handled. (default is NOTIFICATION)
--archive <ProcessingType> Specifies the level of detail in ARCHIVE reporting. (default is NOTIFICATION)
-c,--copyright <arg> The copyright message to use in the license headers, usually in the form of "Copyright 2008
Foo"
-d,--dir <DirOrArchive> (deprecated, use '--') Used to indicate source when using --exclude.
Expand All @@ -102,7 +102,7 @@ usage: java -jar apache-rat/target/apache-rat-${project.version}.jar
--log-level <LogLevel> sets the log level.
--no-default-licenses Ignore default configuration. By default all approved default licenses are used
-o,--out <arg> Define the output file where to write a report to (default is System.out).
-s,--stylesheet <arg> XSLT stylesheet to use when creating the report. Not compatible with -x. Either an
-s,--stylesheet <StyleSheet> XSLT stylesheet to use when creating the report. Not compatible with -x. Either an
external xsl file may be specified or one of the internal named sheets: plain-rat (default),
missing-headers, or unapproved-licenses
--scan-hidden-directories Scan hidden directories
Expand Down

0 comments on commit 008e684

Please sign in to comment.