Skip to content

#82 and #103 #146

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Binary file not shown.
55 changes: 30 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ It scans your Git repository generates a single page application by runing:
- PMD's Coupling Between Objects

Code map viewers are powered by [3D Force Graph](https://vasturiano.github.io/3d-force-graph), [sigma.js](https://www.sigmajs.org/), and [GraphViz DOT](https://graphviz.org/docs/layouts/dot/)
<br>If there are more than 4000 classes + relationships, a simplified 3D viewer will be used to avoid slowdowns. Features will be toggleable in the 3D UI in a future release.
<br>If there are more than 4,000 classes + relationships, a simplified 3D viewer will be used to avoid slowdowns. Features will be toggleable in the 3D UI in a future release.

Take a look at the [Spring Petclinic REST project sample report](https://rawcdn.githack.com/refactorfirst/RefactorFirst/c46d26211a91ffbe08d4089e04a85ff31eb093c0/spring-petclinic-rest-report.html)!

Expand All @@ -29,12 +29,13 @@ If you use an old JDK release of your chosen Java version, you may encounter iss
## There are several ways to run the analysis on your codebase:

### From The Command Line As an HTML Report
Run the following command from the root of your project (the source code does not need to be built):
Run the following command from the root of your project (the source code does not need to be built), or simply by clicking on the Play icon (a green triangle) in the gutter of IntelliJ IDEA (if you are looking at the source of the README):

```bash
mvn org.hjug.refactorfirst.plugin:refactor-first-maven-plugin:0.7.1:htmlReport
```
View the report at ```target/site/refactor-first-report.html```

View the report [here](target/site/refactor-first-report.html)

### [As Part of GitHub Actions Output](https://github.blog/news-insights/product-news/supercharging-github-actions-with-job-summaries/)
This will generate a simplified HTML report (no graphs or images) as the output of a GitHub Action step
Expand All @@ -53,7 +54,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.7.1</version>
<version>0.7.1</version>
<!-- optional -->
<configuration>
<showDetails>false</showDetails>
Expand All @@ -74,14 +75,14 @@ A RefactorFirst report will show up in the site report when you run ```mvn site`
<plugin>
<groupId>org.hjug.refactorfirst.plugin</groupId>
<artifactId>refactor-first-maven-plugin</artifactId>
<version>0.7.1</version>
<version>0.7.1</version>
</plugin>
...
</plugins>
</reporting>
```

## Configuraiton Options
## Configuration Options
Care has been taken to use sensible defaults, though if you wish to override these defaults you can specify the following parameters.
Specify with -D if running on the command line. e.g. ```-DbackEdgeAnalysisCount=0 `DanalyzeCycles=false``` or in the configuration section (as in the above examples) if including in a Maven build.

Expand All @@ -100,40 +101,44 @@ Specify with -D if running on the command line. e.g. ```-DbackEdgeAnalysisCount

### Seeing Errors?

#### Maven Site
If you see an error similar to
```
Execution default-site of goal org.apache.maven.plugins:maven-site-plugin:3.3:site failed: A required class was missing while executing org.apache.maven.plugins:maven-site-plugin:3.3:site: org/apache/maven/doxia/siterenderer/DocumentContent
```
you will need to add the following to your pom.xml:
```xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.4.5</version>
</plugin>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.4.5</version>
</plugin>
</plugins>
</build>
</build>
```

#### Lombok

You _may_ see errors during the build process if you haven't installed (and enabled) the Lombok plugin. Make sure to also enable Java Annotation Processing.

## 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:

```xml
<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>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
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>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
```
and then (assuming Maven is installed) run
Expand All @@ -155,7 +160,7 @@ If you have IntelliJ Ultimate, you can install the [Method Reference Diagram](ht
## Additional Details
This plugin will work on both single module and multi-module Maven projects that have a typical Maven project layout.

This tool is based on the paper **[Prioritizing Design Debt Investment Opportunities](https://dl.acm.org/doi/10.1145/1985362.1985372)** by Nico Zazworka, Carolyn Seaman, and Forrest Shull. The presentation based on the paper is available at https://resources.sei.cmu.edu/asset_files/Presentation/2011_017_001_516911.pdf
This tool is based on the paper **[Prioritizing Design Debt Investment Opportunities](https://dl.acm.org/doi/10.1145/1985362.1985372)** by Nico Zazworka, Carolyn Seaman, and Forrest Shull. The presentation based on the paper is available [here](07-Investigating the Impact of Design Debt on Software Quality.pdf).

## Limitations
* My time. This is a passion project and is developed in my spare time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,61 +48,11 @@ public void close() throws Exception {
git.close();
}

// Based on
// https://github.com/Cosium/git-code-format-maven-plugin/blob/master/src/main/java/com/cosium/code/format/AbstractMavenGitCodeFormatMojo.java
// MIT License
// Move to a provider?
public Repository gitRepository(File basedir) throws IOException {
Repository gitRepository;
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder().findGitDir(basedir);
String gitIndexFileEnvVariable = System.getenv("GIT_INDEX_FILE");
if (Objects.nonNull(gitIndexFileEnvVariable)
&& !gitIndexFileEnvVariable.trim().isEmpty()) {
log.debug("Setting Index File based on Env Variable GIT_INDEX_FILE {}", gitIndexFileEnvVariable);
repositoryBuilder = repositoryBuilder.setIndexFile(new File(gitIndexFileEnvVariable));
}
gitRepository = repositoryBuilder.build();

return gitRepository;
}

public File getGitDir(File basedir) {
FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder().findGitDir(basedir);
return repositoryBuilder.getGitDir();
}

// https://stackoverflow.com/a/19950970/346247
// and
// https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/api/ReadFileFromCommit.java
public Map<String, ByteArrayOutputStream> listRepositoryContentsAtHEAD(Repository repository) throws IOException {
Ref head = repository.exactRef("HEAD");
// a RevWalk allows us to walk over commits based on some filtering that is defined
RevWalk walk = new RevWalk(repository);
RevCommit commit = walk.parseCommit(head.getObjectId());
RevTree tree = commit.getTree();

TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(false);

// TODO: extract rest of this method to test it
Map<String, ByteArrayOutputStream> fileContentsCollection = new HashMap<>();
while (treeWalk.next()) {
if (treeWalk.isSubtree()) {
treeWalk.enterSubtree();
} else {
if (treeWalk.getPathString().endsWith(JAVA_FILE_TYPE)) {
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
loader.copyTo(outputStream);
fileContentsCollection.put(treeWalk.getPathString(), outputStream);
}
}
}
return fileContentsCollection;
}

// log --follow implementation may be worth adopting in the future
// https://github.com/spearce/jgit/blob/master/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/RevWalkTextBuiltin.java

Expand Down