Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RAT-355 and RAT-366 fixes in one package #233

Merged
merged 69 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
22c69f3
Changed to block processing and added IHeaders
Claudenw Nov 1, 2023
11aee9e
fixed IO error
Claudenw Nov 2, 2023
4e2859f
cleaned up code
Claudenw Mar 22, 2024
cf09aab
fixed javadoc error
Claudenw Mar 22, 2024
5a1444d
Cleaned up tests
Claudenw Mar 28, 2024
78d9c6d
Removed format only changes
Claudenw Mar 28, 2024
f4cf89e
first passing text
Claudenw Mar 29, 2024
4d20428
added Unapporved licensce report test and added examples of output
Claudenw Mar 29, 2024
f4e65d5
fixed issues with rat maven plugin
Claudenw Mar 30, 2024
b7df9e9
added XSDs
Claudenw Mar 30, 2024
f6ae778
fixed tests and build issues
Claudenw Mar 31, 2024
63278a6
Fixed ReportTransformerTest and missing-headers.xsl
Claudenw Apr 1, 2024
e2eb9f6
initial work started
Claudenw Jan 20, 2024
1694b3d
first attempt
Claudenw Jan 20, 2024
daa862d
working version
Claudenw Jan 21, 2024
512a592
added ASF licenses and cleaned up code
Claudenw Jan 21, 2024
98f4690
updated ant tasks to match requierments
Claudenw Jan 21, 2024
80f8302
fixed javadoc error
Claudenw Jan 21, 2024
58dd6b0
fixedup javadoc
Claudenw Jan 21, 2024
09cad95
updated javadoc
Claudenw Jan 21, 2024
1ef03a1
change to parameter descriptions
Claudenw Mar 15, 2024
8ec9eb4
fixes some issues
Claudenw Mar 15, 2024
4ee76f8
Switched to annotation based markers
Claudenw Mar 22, 2024
4d2e2cf
adding missed changes
Claudenw Mar 22, 2024
058bb70
changes for readind xml
Claudenw Mar 24, 2024
746bf87
modified to build description map
Claudenw Mar 24, 2024
8eca6cb
cleanup parameter parsing
Claudenw Mar 25, 2024
5a9dfce
started description test
Claudenw Mar 25, 2024
a112547
toward parse/serialize licenses and matchers
Claudenw Mar 26, 2024
f56ec9e
added Documentation class to dump text based documentation about the …
Claudenw Mar 27, 2024
a95a287
fixed parsing issue
Claudenw Mar 27, 2024
48ec807
removed debugging test
Claudenw Mar 27, 2024
8d6ae3e
fixed missing tests
Claudenw Mar 27, 2024
9660279
added some documentation
Claudenw Mar 28, 2024
90656cb
fixed merge errors
Claudenw Apr 1, 2024
718b3dc
fixed testing errors
Claudenw Apr 1, 2024
e287834
Cleaned up code
Claudenw Apr 1, 2024
700970b
fixed Maven tests
Claudenw Apr 1, 2024
53001fc
cleaned up code
Claudenw Apr 1, 2024
af0bf1a
added additional logging and fixed ant tests
Claudenw Apr 1, 2024
fc38288
fixed tests
Claudenw Apr 1, 2024
52ee8cd
fixed maven integration tests
Claudenw Apr 1, 2024
76fad34
fixed some javadoc
Claudenw Apr 1, 2024
00f2170
cleaned up javadoc, added ImplementationException, and deprecated un…
Claudenw Apr 2, 2024
4c2a4fe
updated javadoc
Claudenw Apr 2, 2024
d41a64d
updated javadoc
Claudenw Apr 2, 2024
2c6a092
updated default output example
Claudenw Apr 2, 2024
71c4eff
updated javadoc
Claudenw Apr 2, 2024
1153c96
Cleaned up javadoc, added user documentation, removed unnecessary code
Claudenw Apr 2, 2024
e494efb
Cleaned up pull request
Claudenw Apr 8, 2024
80c0777
Cleaned up pull request
Claudenw Apr 8, 2024
c38b3eb
fixes for review comments
Claudenw Apr 13, 2024
d7fa079
fixed javadoc
Claudenw Apr 13, 2024
3d783f9
fixed integration tests
Claudenw Apr 13, 2024
aa2765d
cleaned up javadoc issues
Claudenw Apr 13, 2024
df98d15
fixed javadoc
Claudenw Apr 14, 2024
db74c5b
changed to system defined EOL markers for output
Claudenw Apr 14, 2024
1eb5f13
updated as per review
Claudenw Apr 14, 2024
6c17aa5
fixed javadoc errors
Claudenw Apr 14, 2024
fc6fba5
fixed javadoc errors
Claudenw Apr 14, 2024
ab62b3e
fixed javadoc and temp files in test
Claudenw Apr 14, 2024
10d0a43
fixed issue with releaseing files after output is complete
Claudenw Apr 14, 2024
a6501e9
added change missed in last commit
Claudenw Apr 14, 2024
20ecb2e
Attempt to fix windows issue
Claudenw Apr 14, 2024
7af00f2
Fixe for xml output test
Claudenw Apr 14, 2024
24e2513
renabled antunit tests
Claudenw Apr 15, 2024
573c404
updated documentation
Claudenw Apr 15, 2024
1fea3ea
updated documentation
Claudenw Apr 15, 2024
056e53b
Removed dependency on commons-cli 1.7.0-SNAPSHOT
Claudenw Apr 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apache-rat-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
<artifactId>apache-rat-core</artifactId>
<packaging>jar</packaging>
<name>Apache Creadur Rat::Core</name>
<description>The core functionality, shared by the Ant tasks
and the Maven plugin.</description>
<description>The core functionality of Rat that is used by all Clients.</description>
<build>
<resources>
<resource>
Expand Down
13 changes: 8 additions & 5 deletions apache-rat-core/src/main/java/org/apache/rat/Defaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.rat.license.ILicenseFamily;
import org.apache.rat.license.LicenseSetFactory;
import org.apache.rat.license.LicenseSetFactory.LicenseFilter;
import org.apache.rat.utils.Log;

/**
* A class that holds the list of licenses and approved licenses from one or more configuration files.
Expand Down Expand Up @@ -70,8 +71,8 @@ public static void init() {
/**
* Builder constructs instances.
*/
private Defaults(Set<URL> urls) {
this.setFactory = Defaults.readConfigFiles(urls);
private Defaults(Log log, Set<URL> urls) {
this.setFactory = Defaults.readConfigFiles(log, urls);
}

/**
Expand All @@ -86,7 +87,7 @@ public static Builder builder() {
* Reads the configuration files.
* @param urls the URLs to read.
*/
private static LicenseSetFactory readConfigFiles(Collection<URL> urls) {
private static LicenseSetFactory readConfigFiles(Log log, Collection<URL> urls) {

SortedSet<ILicense> licenses = LicenseSetFactory.emptyLicenseSet();

Expand All @@ -102,6 +103,7 @@ private static LicenseSetFactory readConfigFiles(Collection<URL> urls) {

LicenseReader lReader = fmt.licenseReader();
if (lReader != null) {
lReader.setLog(log);
lReader.addLicenses(url);
licenses.addAll(lReader.readLicenses());
lReader.approvedLicenseId().stream().map(ILicenseFamily::makeCategory).forEach(approvedLicenseIds::add);
Expand Down Expand Up @@ -241,10 +243,11 @@ public Builder noDefault() {

/**
* Builds the defaults object.
* @param log the Log to use to report errors when building the defaults.
* @return the current defaults object.
*/
public Defaults build() {
return new Defaults(fileNames);
public Defaults build(Log log) {
return new Defaults(log, fileNames);
}
}
}
152 changes: 152 additions & 0 deletions apache-rat-core/src/main/java/org/apache/rat/Documentation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
Claudenw marked this conversation as resolved.
Show resolved Hide resolved
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.rat;

import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
import org.apache.rat.config.parameters.Description;
import org.apache.rat.config.parameters.DescriptionBuilder;
import org.apache.rat.configuration.MatcherBuilderTracker;
import org.apache.rat.configuration.builders.AbstractBuilder;
import org.apache.rat.license.ILicense;
import org.apache.rat.license.ILicenseFamily;
import org.apache.rat.license.LicenseSetFactory.LicenseFilter;

/**
* Generates text based documentation for Licenses, LicenceFamilies, and Matchers.
*
* Utilizes the same command line as the CLI based Report client so that additional licenses, etc. can be added.
*
*/
public class Documentation {

private static final String INDENT = " ";

private Documentation() {
}

/**
* Output the ReportConfiguration to a writer.
* @param cfg The configuration to write.
* @param writer the writer to write to.
* @throws IOException on error.
*/
public static void output(ReportConfiguration cfg, Writer writer) throws IOException {
writer.write(String.format("%n>>>> LICENSES <<<<%n%n"));
for (ILicense l : cfg.getLicenses(LicenseFilter.all)) {
printLicense(l, writer);
}

writer.write(String.format("%n>>>> MATCHERS (Datatype IHeaderMatcher) <<<<%n%n"));
for (Class<? extends AbstractBuilder> mClazz : MatcherBuilderTracker.INSTANCE.getClasses()) {
try {
AbstractBuilder builder = mClazz.getConstructor().newInstance();
printMatcher(DescriptionBuilder.buildMap(builder.builtClass()), writer);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException e) {
throw new ConfigurationException(
String.format("Can not instantiate matcher builder %s ", mClazz.getName()), e);
}
}

writer.write(String.format("%n>>>> FAMILIES (Datatype ILicenseFamily) <<<<%n%n"));
for (ILicenseFamily family : cfg.getLicenseFamilies(LicenseFilter.all)) {
printFamily(family, writer);
}
}

private static void printFamily(ILicenseFamily family, Writer writer) throws IOException {
writer.write(String.format("'%s' - %s%n", family.getFamilyCategory().trim(), family.getFamilyName()));
}

private static void printMatcher(Description matcher, Writer writer) throws IOException {
writer.write(String.format("'%s' - %s%n", matcher.getCommonName(), matcher.getDescription()));
printChildren(1, matcher.getChildren(), writer);

}

private static void printLicense(ILicense license, Writer writer) throws IOException {
Description dLicense = license.getDescription();
writer.write(String.format("'%s' - %s %n", dLicense.getCommonName(), dLicense.getDescription()));
printChildren(1, dLicense.getChildren(), writer);
}

private static void writeIndent(int indent, Writer writer) throws IOException {
for (int i = 0; i < indent; i++) {
writer.write(INDENT);
}
}

private static void printChildren(int indent, Map<String, Description> children, Writer writer) throws IOException {
for (Description d : children.values()) {
writeIndent(indent, writer);
switch (d.getType()) {
case Parameter:
case BuilderParam:
writer.write(String.format("'%s' %s (Datatype: %s%s)%n", d.getCommonName(), d.getDescription(),
d.isCollection() ? "Collection of " : "", d.getChildType().getSimpleName()));
break;
case Unlabeled:
writer.write(String.format("'%s name' %s (Datatype: %s%s)%n", d.getCommonName(), d.getDescription(),
d.isCollection() ? "Collection of " : "", d.getChildType().getSimpleName()));
break;
case License:
// do noting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo ;) nothing - i though of moving it to a default block .... when reading it first.

break;
case Matcher:
writeIndent(indent + 1, writer);
writer.write(String.format("%s %s %n", d.isCollection() ? "Collection of " : "A ",
d.getChildType().getSimpleName()));
printChildren(indent + 2, d.getChildren(), writer);
break;
}
}
}

/**
* Creates the documentation. Writes to the outpus specified by the -o or --out option. Defaults to System.out.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: output

* @param args the arguments. Try --help for help.
* @throws IOException on error
*/
public static void main(String[] args) throws IOException {
ReportConfiguration config = Report.parseCommands(args, Documentation::printUsage, true);
if (config != null) {
try (Writer writer = config.getWriter().get()) {
Documentation.output(config, writer);
}
}
}

private static void printUsage(Options opts) {
HelpFormatter f = new HelpFormatter();
f.setOptionComparator(new Report.OptionComparator());
f.setWidth(120);
String header = "\nAvailable options";
String footer = "";
String cmdLine = String.format("java -jar apache-rat/target/apache-rat-CURRENT-VERSION.jar %s [options]",
Documentation.class.getName());
f.printHelp(cmdLine, header, opts, footer, false);
System.exit(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one *
* or more contributor license agreements. See the NOTICE file *
* distributed with this work for additional information *
* regarding copyright ownership. The ASF licenses this file *
* to you under the Apache License, Version 2.0 (the *
* "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
* KIND, either express or implied. See the License for the *
* specific language governing permissions and limitations *
* under the License. *
*/
package org.apache.rat;

/**
* An exception thrown when there is an issue with the Configuration.
*/
public class ImplementationException extends RuntimeException {

private static final long serialVersionUID = 7257245932787579431L;

public static ImplementationException makeInstance(Exception e) {
if (e instanceof ImplementationException) {
return (ImplementationException) e;
}
return new ImplementationException(e);
}

public ImplementationException(String message, Throwable cause) {
super(message, cause);
}

public ImplementationException(String message) {
super(message);
}

public ImplementationException(Throwable cause) {
super(cause);
}

}
Loading