Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenlr committed Apr 10, 2024
2 parents 9f63258 + 9e25963 commit 4f28887
Show file tree
Hide file tree
Showing 13 changed files with 418 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name: Java CI with Gradle

on:
push:
branches: [ "main" ]
branches: [ "main", "release/**", "feature/**" ]
pull_request:
branches: [ "main" ]

Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ plugins {
id("io.gofannon.cots-report") version ("0.1.0-SNAPSHOT")
}
```


### Extension usage
The plugin provides the `cotsReport` extension.
This extension contains 3 properties:
* **reportFile** which is the path to the report. This property is optional. By default, the report file is `build/reports/project/cots-report.txt`.
* **configurations** which contains the list of the configurations to parse. This property is optional. By default, the configuration is `runtimeClasspath`.
* **ignorableGroupIds** which contains the list of the groups to ignore. This property is optional. By default, there is no ignorable group.

Example:

### Examples:

__Groovy__
```groovy
cotsReporting {
reportFile = layout.buildDirectory.file("my-report.txt")
Expand All @@ -58,8 +63,19 @@ cotsReporting {
}
```

__Kotlin__
```kotlin
cotsReporting {
reportFile = layout.buildDirectory.file("sample.txt")
configurations.set(listOf("runtimeClasspath","testRuntimeClasspath"))
ignorableGroupIds.set(listOf("commons-io", "com.fasterxml.jackson.module", "jackson-module-kotlin"))
}
```


## Run
To run the plugin, just execute the task

```shell
gradle :cotsReport
```
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies {
compileOnly("com.google.code.findbugs:jsr305:3.0.2")

testImplementation("org.codehaus.groovy:groovy:3.0.21")
//testImplementation("commons-io:commons-io:2.16.0")

testImplementation(platform("org.junit:junit-bom:5.10.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kotlin.code.style=official
version=1.0.0-SNAPSHOT
version=1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void initialize(CotsReportExtension extension) {
private void initializeReportRenderer(CotsReportExtension extension) {
CotsContext context = createContext(extension);
DependencyCollector dependencyCollector = new DependencyCollector(context);
DependencyReportRenderer reportRenderer = new CotsReportRenderer(dependencyCollector);
ReportFormatter formatter = new TextReportFormatter();
DependencyReportRenderer reportRenderer = new CotsReportRenderer(dependencyCollector, formatter);
setRenderer(reportRenderer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,19 @@

@NonNullApi
public class CotsReportRenderer extends TextReportRenderer implements DependencyReportRenderer {

private final ReportFormatter formatter;
private final DependencyCollector dependencyCollector;

private DependencyGraphsParser dependencyGraphParser;

public CotsReportRenderer(DependencyCollector dependencyCollector) {
public CotsReportRenderer(DependencyCollector dependencyCollector, ReportFormatter formatter) {
this.dependencyCollector = dependencyCollector;
this.formatter = formatter;
}

@Override
public void startProject(ProjectDetails project) {
getTextOutput().println("---------------------------------");
getTextOutput().println("--- " + project.getDisplayName());
getTextOutput().println("---------------------------------");

this.formatter.setOutput(getTextOutput());
formatter.printProjectHeader(project);
dependencyGraphParser = new DependencyGraphsParser(dependencyCollector);
}

Expand Down Expand Up @@ -88,18 +86,7 @@ public void parseRenderableDependency(RenderableDependency root) {

@Override
public void complete() {
getTextOutput().println("--- COTS configurations");
for (var configurationName : dependencyCollector.getConfigurationList()) {
getTextOutput().println(configurationName);
}

getTextOutput().println();

getTextOutput().println("--- COTS dependencies");
List<String> dependencyList = dependencyCollector.getDependencyIdList();
dependencyList.sort(String::compareTo);
for (var dependencyId : dependencyList) {
getTextOutput().println(dependencyId);
}
formatter.printConfigurations(dependencyCollector.getConfigurationList());
formatter.printDependencies(dependencyCollector.getDependencyIdList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class DependencyCollector implements DependencyVisitor {

private final DependencyCollectorConfiguration configuration;

private final SortedSet<String> dependencyIdSet = new TreeSet<>();
private final SortedSet<String> configurationNameSet = new TreeSet<>();
private final SortedSet<String> dependencyIdSet = new TreeSet<>();
private final SortedSet<String> configurationNameSet = new TreeSet<>();


/**
Expand All @@ -42,11 +42,10 @@ public class DependencyCollector implements DependencyVisitor {
* @param configuration all information to select the dependencies to collect
*/
public DependencyCollector(DependencyCollectorConfiguration configuration) {
this.configuration = configuration;
this.configuration = configuration;
}



/**
* Visit a Gradle dependency (aka JAR)
*
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/io/gofannon/gradle/cots/report/ReportFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2024 the original author or authors.
*
* Licensed 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 io.gofannon.gradle.cots.report;

import org.gradle.api.NonNullApi;
import org.gradle.api.tasks.diagnostics.internal.ProjectDetails;
import org.gradle.internal.logging.text.StyledTextOutput;

import java.util.List;

/**
* Formatter for dependency report
*/
@NonNullApi
public interface ReportFormatter {

/**
* Inject the console output
*
* @param output the console output
*/
void setOutput(StyledTextOutput output);

/**
* Print the header of the project
*
* @param project the project to print
*/
void printProjectHeader(ProjectDetails project);

/**
* Print the configurations in the project
*
* @param configurationNames the names of the configurations
*/
void printConfigurations(List<String> configurationNames);

/**
* Print the dependencies in the project
*
* @param dependencyIdList the list of the dependency identifiers
*/
void printDependencies(List<String> dependencyIdList);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2024 the original author or authors.
*
* Licensed 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 io.gofannon.gradle.cots.report;

import org.gradle.api.NonNullApi;
import org.gradle.api.tasks.diagnostics.internal.ProjectDetails;
import org.gradle.internal.logging.text.StyledTextOutput;

import java.util.List;

/**
* Dependency report formatter that generates report in text format
*/
@NonNullApi
public class TextReportFormatter implements ReportFormatter {

private StyledTextOutput output;

@Override
public void setOutput(StyledTextOutput output) {
this.output = output;
}

@Override
public void printProjectHeader(ProjectDetails project) {
output.println("---------------------------------")
.println("--- " + project.getDisplayName())
.println("---------------------------------");
}

@Override
public void printConfigurations(List<String> configurationNames) {
output.println("--- COTS configurations");
configurationNames.stream()
.sorted(String::compareTo)
.forEach(output::println);
output.println();
}


@Override
public void printDependencies(List<String> dependencyIdList) {
output.println("--- COTS dependencies");
dependencyIdList.stream()
.sorted(String::compareTo)
.forEach(output::println);
}
}
Loading

0 comments on commit 4f28887

Please sign in to comment.