Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
with:
ref: main

- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11

- name: Configure Git user
run: |
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ It runs PMD's God Class Rule and Coupling Between Objects rule and scans your Gi
The graphs generated in the report will look similar to this one:
![image info](./RefactorFirst_Sample_Report.png)

## Please Note: Java 11 is now required to run RefactorFirst
The change to require Java 11 is needed to address vulnerability CVE-2023-4759 in JGit
Java 21 features are not yet integrated since PMD APIs have changed.

## There are several ways to run the analysis on your codebase:

### From The Command Line
Run the following command from the root of your project (the source code does not need to be built):

```bash
mvn org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.5.0:report
mvn org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.5.0-M1:report
```

### As Part of a Build
Expand All @@ -24,7 +28,7 @@ Add the following to your project in the build section. **showDetails** will sh
<plugin>
<groupId>org.hjug.refactorfirst.plugin</groupId>
<artifactId>refactor-first-maven-plugin</artifactId>
<version>0.5.0</version>
<version>0.5.0-M1</version>
<!-- optional -->
<configuration>
<showDetails>true</showDetails>
Expand All @@ -44,7 +48,7 @@ Add the following to your project in the reports section.
<plugin>
<groupId>org.hjug.refactorfirst.plugin</groupId>
<artifactId>refactor-first-maven-plugin</artifactId>
<version>0.5.0</version>
<version>0.5.0-M1</version>
</plugin>
...
</plugins>
Expand Down Expand Up @@ -75,8 +79,9 @@ you will need to add the following to your pom.xml:

### As an HTML Report
```bash
mvn org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.5.0:htmlReport
mvn org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.5.0-M1:htmlReport
```
View the report at ```target/site/refactor-first-report.html```

## But I'm using Gradle / my project layout isn't typical!
I would like to create a Gradle plugin and (possibly) support non-conventional projects in the future, but in the meantime you can create a dummy POM file in the same directory as your .git directory:
Expand All @@ -94,10 +99,11 @@ I would like to create a Gradle plugin and (possibly) support non-conventional p
and then (assuming Maven is installed) run

```bash
mvn org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.4.0:report
mvn org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.5.0-M1:htmlReport
```

## Viewing the Report
View the report at ```target/site/refactor-first-report.html```
Once the plugin finishes executing (it may take a while for a large / old codebase), open the file **target/site/refactor-first-report.html** in the root of the project. It will contain a graph similar to the one above, and a table that lists God classes in the recommended order that they should be refactored. The classes in the top left of the graph are the easiest to refactor while also having the biggest positive impact to team productivity.
If highly coupled classes are detected, a graph and table listing Highly Coupled Classes in will be generated.

Expand Down
2 changes: 1 addition & 1 deletion change-proneness-ranker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.hjug.refactorfirst</groupId>
<artifactId>refactor-first</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-M1-SNAPSHOT</version>
</parent>

<groupId>org.hjug.refactorfirst.changepronenessranker</groupId>
Expand Down
38 changes: 38 additions & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
87 changes: 87 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.hjug.refactorfirst</groupId>
<artifactId>refactor-first</artifactId>
<version>0.5.0-M1-SNAPSHOT</version>
</parent>

<packaging>jar</packaging>

<groupId>org.hjug.refactorfirst.report</groupId>
<artifactId>cli</artifactId>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>4.7.4</version>
</dependency>
<dependency>
<groupId>org.hjug.refactorfirst.report</groupId>
<artifactId>report</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.7</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.9.2</version>
<scope>compile</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.hjug.refactorfirst.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.skife.maven</groupId>
<artifactId>really-executable-jar-maven-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<programFile>rf</programFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>really-executable-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
12 changes: 12 additions & 0 deletions cli/src/main/java/org/hjug/refactorfirst/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.hjug.refactorfirst;

import picocli.CommandLine;

public class Main {
public static void main(String[] args) {
int exitCode = new CommandLine(new ReportCommand())
.setCaseInsensitiveEnumValuesAllowed(true)
.execute(args);
System.exit(exitCode);
}
}
118 changes: 118 additions & 0 deletions cli/src/main/java/org/hjug/refactorfirst/ReportCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package org.hjug.refactorfirst;

import static picocli.CommandLine.Option;

import java.io.File;
import java.io.FileReader;
import java.util.concurrent.Callable;
import lombok.extern.slf4j.Slf4j;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.hjug.refactorfirst.report.CsvReport;
import org.hjug.refactorfirst.report.HtmlReport;
import org.hjug.refactorfirst.report.json.JsonReportExecutor;
import picocli.CommandLine.Command;

@Command(mixinStandardHelpOptions = true, description = "Generate a report")
@Slf4j
public class ReportCommand implements Callable<Integer> {

@Option(
names = {"-d", "--details"},
description = "Show detailed report")
private boolean showDetails;

@Option(
names = {"-p", "--project"},
description = "Project name")
private String projectName;

@Option(
names = {"-v", "--version"},
description = "Project version")
private String projectVersion;

@Option(
names = {"-o", "--output"},
defaultValue = ".",
description = "Output directory")
private String outputDirectory;

@Option(
names = {"-b", "--base-dir"},
defaultValue = ".",
description = "Base directory of the project")
private File baseDir;

@Option(
names = {"-t", "--type"},
description = "Report type: ${COMPLETION-CANDIDATES}",
defaultValue = "HTML")
private ReportType reportType;

@Override
public Integer call() {

// TODO: add support for inferring arguments from gradle properties
inferArgumentsFromMavenProject();
populateDefaultArguments();
switch (reportType) {
case HTML:
HtmlReport htmlReport = new HtmlReport();
htmlReport.execute(showDetails, projectName, projectVersion, outputDirectory, baseDir);
return 0;
case JSON:
JsonReportExecutor jsonReportExecutor = new JsonReportExecutor();
jsonReportExecutor.execute(baseDir, outputDirectory);
return 0;
case CSV:
CsvReport csvReport = new CsvReport();
csvReport.execute(showDetails, projectName, projectVersion, outputDirectory, baseDir);
return 0;
}

return 0;
}

private void populateDefaultArguments() {
if (projectName == null || projectName.isEmpty()) {
projectName = "my-project";
}
if (projectVersion == null || projectVersion.isEmpty()) {
projectVersion = "0.0.0";
}
}

private void inferArgumentsFromMavenProject() {
if (baseDir.isDirectory()) {
File[] potentialPomFiles = baseDir.listFiles(f -> f.getName().equals("pom.xml"));
File pomFile = null;
if (potentialPomFiles != null && potentialPomFiles.length > 0) {
pomFile = potentialPomFiles[0];
}
if (pomFile != null) {
Model model;
FileReader reader;
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
try {
reader = new FileReader(pomFile);
model = mavenreader.read(reader);
model.setPomFile(pomFile);
} catch (Exception ex) {
log.info("Unable to infer arguments from pom file");
return;
}
MavenProject project = new MavenProject(model);

// only override project name and version if they are not set
if (projectName == null || projectName.isEmpty()) {
projectName = project.getName();
}
if (projectVersion == null || projectVersion.isEmpty()) {
projectVersion = project.getVersion();
}
}
}
}
}
7 changes: 7 additions & 0 deletions cli/src/main/java/org/hjug/refactorfirst/ReportType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hjug.refactorfirst;

public enum ReportType {
HTML,
JSON,
CSV;
}
2 changes: 1 addition & 1 deletion cost-benefit-calculator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.hjug.refactorfirst</groupId>
<artifactId>refactor-first</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-M1-SNAPSHOT</version>
</parent>

<groupId>org.hjug.refactorfirst.costbenefitcalculator</groupId>
Expand Down
2 changes: 1 addition & 1 deletion coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.hjug.refactorfirst</groupId>
<artifactId>refactor-first</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-M1-SNAPSHOT</version>
</parent>

<artifactId>coverage</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions effort-ranker/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.hjug.refactorfirst</groupId>
<artifactId>refactor-first</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-M1-SNAPSHOT</version>
</parent>

<groupId>org.hjug.refactorfirst.effortranker</groupId>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>org.hjug.refactorfirst.testresources</groupId>
<artifactId>test-resources</artifactId>
<version>0.4.1-SNAPSHOT</version>
<version>0.5.0-M1-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Loading