From 9fcc14ae6f15429b2db28a2c6fc3e3589e679ade Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 12 Apr 2021 12:12:24 +0400 Subject: [PATCH 001/163] #20 -- Get business logic classes --- .../api/StructuralUnitIdentifier.java | 14 ++++++--- .../controller/StructuralUnitController.java | 11 +++++-- .../heuristic/model/BusinessLogicUnit.java | 15 ++++++++++ .../heuristic/service/JavaIdentifier.java | 29 +++++++++++++------ .../service/StructuralUnitService.java | 17 +++++++++-- 5 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/heuristic/model/BusinessLogicUnit.java diff --git a/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java b/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java index 5956542..9ea3355 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/api/StructuralUnitIdentifier.java @@ -7,7 +7,8 @@ package ru.ulstu.extractor.heuristic.api; import ru.ulstu.extractor.heuristic.component.BuildTool; import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage; -import ru.ulstu.extractor.heuristic.model.StructuralUnit; +import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit; +import ru.ulstu.extractor.heuristic.model.EntityUnit; import ru.ulstu.extractor.heuristic.service.DetectorService; import ru.ulstu.extractor.heuristic.service.ProgrammingLanguageService; import ru.ulstu.extractor.util.StringUtils; @@ -24,11 +25,16 @@ import static ru.ulstu.extractor.heuristic.service.DetectorService.LangDetectScr import static ru.ulstu.extractor.heuristic.service.DetectorService.LangDetectScrupulousness.LOW; public abstract class StructuralUnitIdentifier { - public List getEntityClasses(String projectPath, List projectFiles, List rootProjectFiles) { + public List getEntityClasses(String projectPath, List projectFiles, List rootProjectFiles) { String subDirectory = getSourceDirectory(rootProjectFiles); return getEntityClasses(projectPath, subDirectory, projectFiles); } + public List getBusinessLogicClasses(String projectPath, List projectFiles, List rootProjectFiles) { + String subDirectory = getSourceDirectory(rootProjectFiles); + return getBusinessLogicClasses(projectPath, subDirectory, projectFiles); + } + public abstract boolean canAppliedToCode(String sourceCode); public abstract boolean canAppliedToFile(File projectFile); @@ -41,13 +47,13 @@ public abstract class StructuralUnitIdentifier { protected abstract boolean isBusinessLogicClass(File file); - public abstract List getBusinessLogicClasses(); + public abstract List getBusinessLogicClasses(String projectPath, String subDirectory, List projectFiles); public abstract boolean isMultiModuleProject(); public abstract Optional getBuildTool(List rootDirectoryFiles); - protected abstract List getEntityClasses(String projectPath, String subDirectory, List projectFiles); + protected abstract List getEntityClasses(String projectPath, String subDirectory, List projectFiles); protected abstract String getSourceDirectory(List rootProjectFiles); diff --git a/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java b/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java index ff9b7fa..7024d56 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/controller/StructuralUnitController.java @@ -8,7 +8,8 @@ package ru.ulstu.extractor.heuristic.controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import ru.ulstu.extractor.heuristic.model.StructuralUnit; +import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit; +import ru.ulstu.extractor.heuristic.model.EntityUnit; import ru.ulstu.extractor.heuristic.service.StructuralUnitService; import ru.ulstu.extractor.service.GitRepositoryService; @@ -29,8 +30,14 @@ public class StructuralUnitController { } @GetMapping("get-entities") - public List getEntities(String repositoryUrl) throws IOException { + public List getEntities(String repositoryUrl) throws IOException { File rootPath = gitRepositoryService.getProjectDirectoryFile(repositoryUrl); return structuralUnitService.getEntities(rootPath); } + + @GetMapping("get-business-logic") + public List getBusinessLogic(String repositoryUrl) throws IOException { + File rootPath = gitRepositoryService.getProjectDirectoryFile(repositoryUrl); + return structuralUnitService.getBusinessLogic(rootPath); + } } diff --git a/src/main/java/ru/ulstu/extractor/heuristic/model/BusinessLogicUnit.java b/src/main/java/ru/ulstu/extractor/heuristic/model/BusinessLogicUnit.java new file mode 100644 index 0000000..9d8e132 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/heuristic/model/BusinessLogicUnit.java @@ -0,0 +1,15 @@ +/* + * Copyright (C) 2021 Anton Romanov - All Rights Reserved + * You may use, distribute and modify this code, please write to: romanov73@gmail.com. + */ + +package ru.ulstu.extractor.heuristic.model; + +import java.io.File; + +public class BusinessLogicUnit extends StructuralUnit { + + public BusinessLogicUnit(String projectPath, File file) { + super(projectPath, file); + } +} diff --git a/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java b/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java index 438ed33..ef2a70a 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/service/JavaIdentifier.java @@ -13,8 +13,8 @@ import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier; import ru.ulstu.extractor.heuristic.component.BuildTool; import ru.ulstu.extractor.heuristic.component.JavaProgrammingLanguage; import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage; +import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit; import ru.ulstu.extractor.heuristic.model.EntityUnit; -import ru.ulstu.extractor.heuristic.model.StructuralUnit; import ru.ulstu.extractor.util.StringUtils; import java.io.File; @@ -29,6 +29,7 @@ import static ru.ulstu.extractor.heuristic.service.DetectorService.LangDetectScr @Service public class JavaIdentifier extends StructuralUnitIdentifier { private static final String ENTITY_ANNOTATION = "@Entity"; + private static final String SERVICE_ANNOTATION = "@Service"; private final DetectorService detectorService; private final BuildToolService buildToolService; private final ProgrammingLanguageService programmingLanguageService; @@ -56,7 +57,7 @@ public class JavaIdentifier extends StructuralUnitIdentifier { } @Override - public List getEntityClasses(String projectPath, String subDirectory, List projectFiles) { + public List getEntityClasses(String projectPath, String subDirectory, List projectFiles) { return projectFiles.stream() .filter(file -> StringUtils.fileInSubdirectory(file.getPath(), projectPath, subDirectory)) .filter(this::isEntityClass) @@ -64,15 +65,14 @@ public class JavaIdentifier extends StructuralUnitIdentifier { .collect(Collectors.toList()); } - protected Optional getMainProgrammingLanguage(String sourceCode) { - return sourceCodeContainsClass(sourceCode) - ? Optional.of(getProgrammingLanguage()) - : Optional.empty(); - } @Override - public List getBusinessLogicClasses() { - return null; + public List getBusinessLogicClasses(String projectPath, String subDirectory, List projectFiles) { + return projectFiles.stream() + .filter(file -> StringUtils.fileInSubdirectory(file.getPath(), projectPath, subDirectory)) + .filter(this::isBusinessLogicClass) + .map(file -> new BusinessLogicUnit(projectPath, file)) + .collect(Collectors.toList()); } @Override @@ -85,6 +85,12 @@ public class JavaIdentifier extends StructuralUnitIdentifier { return buildToolService.getProjectBuildTool(rootDirectoryFiles); } + protected Optional getMainProgrammingLanguage(String sourceCode) { + return sourceCodeContainsClass(sourceCode) + ? Optional.of(getProgrammingLanguage()) + : Optional.empty(); + } + @Override protected DetectorService getDetectorService() { return detectorService; @@ -152,6 +158,11 @@ public class JavaIdentifier extends StructuralUnitIdentifier { @Override protected boolean isBusinessLogicClass(File file) { + try { + return file.getName().endsWith("java") && classContainsAnnotation(file, SERVICE_ANNOTATION); + } catch (Exception ex) { + ex.printStackTrace(); + } return false; } } diff --git a/src/main/java/ru/ulstu/extractor/heuristic/service/StructuralUnitService.java b/src/main/java/ru/ulstu/extractor/heuristic/service/StructuralUnitService.java index c7bdfcc..83dc150 100644 --- a/src/main/java/ru/ulstu/extractor/heuristic/service/StructuralUnitService.java +++ b/src/main/java/ru/ulstu/extractor/heuristic/service/StructuralUnitService.java @@ -7,7 +7,8 @@ package ru.ulstu.extractor.heuristic.service; import org.springframework.stereotype.Service; import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier; -import ru.ulstu.extractor.heuristic.model.StructuralUnit; +import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit; +import ru.ulstu.extractor.heuristic.model.EntityUnit; import java.io.File; import java.io.IOException; @@ -26,7 +27,7 @@ public class StructuralUnitService { this.structuralUnitIdentifiers = structuralUnitIdentifiers; } - public List getEntities(File rootPath) throws IOException { + public List getEntities(File rootPath) throws IOException { List projectFiles = directoryService.getFilesRecursively(rootPath); List rootProjectFiles = directoryService.getDirectoryFiles(rootPath.toPath()); return getStructuralUnitIdentifier( @@ -38,6 +39,18 @@ public class StructuralUnitService { .getEntityClasses(rootPath.getPath(), projectFiles, rootProjectFiles); } + public List getBusinessLogic(File rootPath) throws IOException { + List projectFiles = directoryService.getFilesRecursively(rootPath); + List rootProjectFiles = directoryService.getDirectoryFiles(rootPath.toPath()); + return getStructuralUnitIdentifier( + structuralUnitIdentifier -> structuralUnitIdentifier.canAppliedToProject( + rootPath.getPath(), + projectFiles, + rootProjectFiles)) + .orElseThrow(() -> new RuntimeException("Identifier not found")) + .getBusinessLogicClasses(rootPath.getPath(), projectFiles, rootProjectFiles); + } + public boolean containsEntity(File projectFile) { return getStructuralUnitIdentifier( structuralUnitIdentifier -> structuralUnitIdentifier.canAppliedToFile(projectFile)) -- 2.34.1 From 6c6e8fdc3bad455073024c7e0709417e503313bd Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 12 Apr 2021 16:38:01 +0400 Subject: [PATCH 002/163] #21 -- Add entity filter --- .../controller/GitFilteringController.java | 4 +++- .../controller/StatisticController.java | 5 +++++ .../model/CommitEntityStatistic.java | 20 +++++++++++++++++++ .../ulstu/extractor/model/mvc/FilterForm.java | 10 ++++++++++ .../repository/CommitRepository.java | 6 ++++-- .../extractor/service/FilteringService.java | 4 +++- .../resources/templates/filterCommits.html | 6 ++++++ 7 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java diff --git a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java index e172698..0e69083 100644 --- a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java +++ b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java @@ -40,7 +40,8 @@ public class GitFilteringController { @RequestParam Optional repositoryUrl, @RequestParam Optional branchName, @RequestParam Optional author, - @RequestParam Optional filter) { + @RequestParam Optional filter, + @RequestParam Optional entity) { int currentPage = page.orElse(1); int pageSize = size.orElse(DEFAULT_PAGE_SIZE); @@ -51,6 +52,7 @@ public class GitFilteringController { notEmptyBranchName, author.orElse(null), filter.orElse(null), + entity.orElse(null), new OffsetablePageRequest(currentPage - 1, pageSize)); int totalPages = commitsPage.getTotalPages(); if (totalPages > 0) { diff --git a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java index 55f1f33..18044bd 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java @@ -48,6 +48,11 @@ public class StatisticController { } model.addAttribute("urls", url); +// List entityCommits = commitRepository.getCommitEntityStatistic().stream() +// .map(stat -> new Object[]{stat.getEntity(), stat.getCountCommit()}) +// .collect(Collectors.toList()); +// model.addAttribute("commitTimeData", timeCommits); + return STATISTIC; } } diff --git a/src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java b/src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java new file mode 100644 index 0000000..61dc428 --- /dev/null +++ b/src/main/java/ru/ulstu/extractor/model/CommitEntityStatistic.java @@ -0,0 +1,20 @@ +package ru.ulstu.extractor.model; + +public class CommitEntityStatistic { + private Boolean entity; + private Long countCommit; + + public CommitEntityStatistic(Boolean entity, Long countCommit) { + this.entity = entity; + this.countCommit = countCommit; + } + + public Boolean getEntity() { + return entity; + } + + public Long getCountCommit() { + return countCommit; + } + +} diff --git a/src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java b/src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java index 2d42b74..7d8b436 100644 --- a/src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java +++ b/src/main/java/ru/ulstu/extractor/model/mvc/FilterForm.java @@ -13,6 +13,7 @@ public class FilterForm { private String repositoryUrl; private String branchName; private String author; + private boolean entity; private Page commitsPage; public FilterForm() { @@ -62,6 +63,14 @@ public class FilterForm { this.branchName = branchName; } + public boolean getEntity() { + return entity; + } + + public void setEntity(boolean entity) { + this.entity = entity; + } + @Override public String toString() { return "FilterForm{" + @@ -70,6 +79,7 @@ public class FilterForm { ", branchName='" + branchName + '\'' + ", author='" + author + '\'' + ", commitsPage=" + commitsPage + + ", entity='" + entity + '}'; } } diff --git a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java index 00fde10..55c7b13 100644 --- a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java +++ b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java @@ -19,8 +19,8 @@ import ru.ulstu.extractor.model.Repository; import java.util.List; public interface CommitRepository extends JpaRepository { - @Query("SELECT c FROM Commit c, Repository r, Branch b, Author a WHERE c.branch = b AND r = b.repository AND a = c.author AND r = :repository AND b.name = :branchName AND (:author IS NULL OR :author = '' OR a.name = :author) AND (:filter IS NULL OR :filter = '' OR lower(c.message) LIKE lower(concat('%', :filter,'%')))") - Page findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author, @Param("filter") String filter); + @Query("SELECT c FROM Commit c, Repository r, Branch b, Author a, FileChange f WHERE c.branch = b AND r = b.repository AND a = c.author AND f MEMBER OF c.fileChanges AND r = :repository AND b.name = :branchName AND (:author IS NULL OR :author = '' OR a.name = :author) AND (:filter IS NULL OR :filter = '' OR lower(c.message) LIKE lower(concat('%', :filter,'%'))) AND (:entity IS NULL OR f.containsEntity = :entity)") + Page findByRepositoryAndBranch(Pageable pageable, @Param("repository") Repository repository, @Param("branchName") String branchName, @Param("author") String author, @Param("filter") String filter, @Param("entity") Boolean entity); @Query("SELECT new ru.ulstu.extractor.model.CommitAuthorStatistic(c.author.name, COUNT(DISTINCT c.hash)) FROM Commit c GROUP by c.author.name") List getCommitAuthorStatistic(); @@ -31,4 +31,6 @@ public interface CommitRepository extends JpaRepository { @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(cast(c.date as date), COUNT(DISTINCT c.hash)) FROM Commit c GROUP by cast(c.date as date) ORDER by cast(c.date as date)") List getCommitTimeStatistic(); +// @Query("SELECT new ru.ulstu.extractor.model.CommitEntityStatistic(f.containsEntity, COUNT(DISTINCT f.commit.hash)) FROM FileChange f GROUP by f.containsEntity") +// List getCommitEntityStatistic(); } diff --git a/src/main/java/ru/ulstu/extractor/service/FilteringService.java b/src/main/java/ru/ulstu/extractor/service/FilteringService.java index f85f3fb..c22cfae 100644 --- a/src/main/java/ru/ulstu/extractor/service/FilteringService.java +++ b/src/main/java/ru/ulstu/extractor/service/FilteringService.java @@ -42,13 +42,15 @@ public class FilteringService { @NotNull String branchName, String author, String filter, + Boolean entity, Pageable pageable) { return commitRepository.findByRepositoryAndBranch( pageable, repositoryRepository.findByUrl(repositoryUrl), branchName, author, - filter + filter, + entity ); } } diff --git a/src/main/resources/templates/filterCommits.html b/src/main/resources/templates/filterCommits.html index 0a44875..7f06b73 100644 --- a/src/main/resources/templates/filterCommits.html +++ b/src/main/resources/templates/filterCommits.html @@ -73,6 +73,12 @@
+
+ Содержит сущность: +
+
+ +
-- 2.34.1 From b32bad1edafb460131b9d73d24f29b916348f18a Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 12 Apr 2021 17:10:23 +0400 Subject: [PATCH 003/163] #21 -- Clean filter --- .../ru/ulstu/extractor/controller/StatisticController.java | 6 ------ .../ru/ulstu/extractor/repository/CommitRepository.java | 2 -- 2 files changed, 8 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java index 18044bd..13595ee 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java @@ -47,12 +47,6 @@ public class StatisticController { url[i] = urlCommits.get(i)[0].toString().substring(urlCommits.get(i)[0].toString().lastIndexOf("/") + 1); } model.addAttribute("urls", url); - -// List entityCommits = commitRepository.getCommitEntityStatistic().stream() -// .map(stat -> new Object[]{stat.getEntity(), stat.getCountCommit()}) -// .collect(Collectors.toList()); -// model.addAttribute("commitTimeData", timeCommits); - return STATISTIC; } } diff --git a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java index 55c7b13..9435847 100644 --- a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java +++ b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java @@ -31,6 +31,4 @@ public interface CommitRepository extends JpaRepository { @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(cast(c.date as date), COUNT(DISTINCT c.hash)) FROM Commit c GROUP by cast(c.date as date) ORDER by cast(c.date as date)") List getCommitTimeStatistic(); -// @Query("SELECT new ru.ulstu.extractor.model.CommitEntityStatistic(f.containsEntity, COUNT(DISTINCT f.commit.hash)) FROM FileChange f GROUP by f.containsEntity") -// List getCommitEntityStatistic(); } -- 2.34.1 From 0b0b8193b4a883eea129f097cd553f4f33b043a9 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 13 Apr 2021 16:52:10 +0400 Subject: [PATCH 004/163] Add check entity --- .../ulstu/extractor/controller/GitFilteringController.java | 1 + src/main/resources/templates/filterCommits.html | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java index 0e69083..f683699 100644 --- a/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java +++ b/src/main/java/ru/ulstu/extractor/controller/GitFilteringController.java @@ -67,6 +67,7 @@ public class GitFilteringController { filterForm.setRepositoryUrl(notEmptyRepositoryUrl); filterForm.setAuthor(author.orElse(null)); filterForm.setFilter(filter.orElse(null)); + filterForm.setEntity(entity.orElse(false)); model.addAttribute("filterForm", filterForm); model.addAttribute("authors", filteringService.getRepositoryAuthors( notEmptyRepositoryUrl, diff --git a/src/main/resources/templates/filterCommits.html b/src/main/resources/templates/filterCommits.html index 7f06b73..63d8057 100644 --- a/src/main/resources/templates/filterCommits.html +++ b/src/main/resources/templates/filterCommits.html @@ -77,7 +77,7 @@ Содержит сущность:
- +
@@ -117,7 +117,8 @@ repositoryUrl=${filterForm.repositoryUrl}, branchName=${filterForm.branchName}, author=${filterForm.author}, - filter=${filterForm.filter})}" + filter=${filterForm.filter}, + entity=${filterForm.entity})}" th:text=${pageNumber} th:class="${pageNumber == filterForm.commitsPage.number} ? active">
-- 2.34.1 From e61e13e3428c1af88ef277297072dc58c73c2979 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 14 Apr 2021 11:42:10 +0400 Subject: [PATCH 005/163] Delete extra file --- .../ru/ulstu/extractor/model/NewClass.java | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 src/main/java/ru/ulstu/extractor/model/NewClass.java diff --git a/src/main/java/ru/ulstu/extractor/model/NewClass.java b/src/main/java/ru/ulstu/extractor/model/NewClass.java deleted file mode 100644 index e363be7..0000000 --- a/src/main/java/ru/ulstu/extractor/model/NewClass.java +++ /dev/null @@ -1,55 +0,0 @@ -package ru.ulstu.extractor.model; - -import org.eclipse.jgit.diff.DiffEntry; -import org.eclipse.jgit.diff.DiffFormatter; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.revwalk.RevWalk; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class NewClass { - - private final RevWalk revWalk; - private final DiffFormatter diffFormatter; - - private NewClass(RevWalk revWalk, DiffFormatter diffFormatter) { - this.revWalk = revWalk; - this.diffFormatter = diffFormatter; - } - - public Set getModified(final RevCommit commit) throws IOException { - final RevCommit[] parents = commit.getParents(); - final Set result = new HashSet<>(); - if (parents.length == 1) { // merge commit if length > 1 - final RevCommit parent = revWalk.parseCommit(parents[0].getId()); - // get diff of this commit to its parent, as list of paths - final List diffs = getDiffEntries(commit, parent); - for (final DiffEntry diff : diffs) { - final String changePath = diff.getChangeType().equals(DiffEntry.ChangeType.DELETE) ? diff.getOldPath() : diff.getNewPath(); - result.add(changePath); - } - } - return result; - } - - private List getDiffEntries(final RevCommit commit, final RevCommit parent) { - try { - return diffFormatter.scan(parent.getTree(), commit.getTree()); - } catch (Exception e) { - e.printStackTrace(); - } - return Collections.emptyList(); - } -} - -// Первая основная таблица: коммит, автор, дата -// Вторая таблица : коммит, имя файла, добавленные строки, удаленные строки - -// Фильтрация коммитов по автору(только основная таблица) -// Фильтрация коммитов по дате -// Фильтрация коммитов по именни файла, или добавленные строки. - -- 2.34.1 From 339b51cef9f6fdc9634971f521b1f32b63a0b15d Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 14 Apr 2021 12:38:05 +0400 Subject: [PATCH 006/163] fix gradle version --- build.gradle | 48 ++++++++++++------------ gradle/wrapper/gradle-wrapper.properties | 7 +++- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/build.gradle b/build.gradle index b061bd3..1d713ee 100644 --- a/build.gradle +++ b/build.gradle @@ -43,37 +43,37 @@ repositories { } configurations { - compile.exclude module: "spring-boot-starter-tomcat" - compile.exclude module: "follow-redirects" - compile.exclude module: "is-buffer" + implementation.exclude module: "spring-boot-starter-tomcat" + implementation.exclude module: "follow-redirects" + implementation.exclude module: "is-buffer" } dependencies { - compile group: 'org.springframework.boot', name: 'spring-boot-starter-web' - compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty' - compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf' - compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa' - compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect' - compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner' - compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5' - compile group: 'org.postgresql', name: 'postgresql', version: '9.4.1212' - compile group: 'org.liquibase', name: 'liquibase-core', version: '4.3.1' - compile group: 'commons-io', name: 'commons-io', version: '2.6' - compile group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.35.0' - compile group: 'com.github.javaparser', name: 'javaparser-core', version: '3.20.2' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jetty' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa' + implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect' + implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner' + implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5' + implementation group: 'org.postgresql', name: 'postgresql', version: '9.4.1212' + implementation group: 'org.liquibase', name: 'liquibase-core', version: '4.3.1' + implementation group: 'commons-io', name: 'commons-io', version: '2.6' + implementation group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.35.0' + implementation group: 'com.github.javaparser', name: 'javaparser-core', version: '3.20.2' - compile group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0' + implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0' - compile group: 'com.ibm.icu', name: 'icu4j', version: '63.1' - compile group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '5.9.0.202009080501-r' + implementation group: 'com.ibm.icu', name: 'icu4j', version: '63.1' + implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '5.9.0.202009080501-r' - compile group: 'org.webjars', name: 'jquery', version: '3.6.0' - compile group: 'org.webjars', name: 'bootstrap', version: '4.6.0' - compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.8' - compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0' - compile group: 'org.webjars', name: 'highcharts', version: '7.0.0' + implementation group: 'org.webjars', name: 'jquery', version: '3.6.0' + implementation group: 'org.webjars', name: 'bootstrap', version: '4.6.0' + implementation group: 'org.webjars', name: 'bootstrap-select', version: '1.13.8' + implementation group: 'org.webjars', name: 'font-awesome', version: '4.7.0' + implementation group: 'org.webjars', name: 'highcharts', version: '7.0.0' - testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' + implementation group: 'org.springframework.boot', name: 'spring-boot-starter-test' } wrapper { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2a56324..6c6f3a6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,10 @@ +# +# Copyright (C) 2021 Anton Romanov - All Rights Reserved +# You may use, distribute and modify this code, please write to: romanov73@gmail.com. +# + distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -- 2.34.1 From 2cb0ad15ba3768a69104e8327a928537a5bcd954 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 14 Apr 2021 13:24:59 +0400 Subject: [PATCH 007/163] #22 - Add new statistic pie --- .../controller/StatisticController.java | 4 ++ .../repository/CommitRepository.java | 4 ++ src/main/resources/templates/statistic.html | 39 +++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java index 13595ee..7952aba 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java @@ -47,6 +47,10 @@ public class StatisticController { url[i] = urlCommits.get(i)[0].toString().substring(urlCommits.get(i)[0].toString().lastIndexOf("/") + 1); } model.addAttribute("urls", url); + List entityCommits = commitRepository.getCommitEntityStatistic().stream() + .map(stat -> new Object[]{stat.getEntity(), stat.getCountCommit()}) + .collect(Collectors.toList()); + model.addAttribute("commitEntityData", entityCommits); return STATISTIC; } } diff --git a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java index 9435847..9b92756 100644 --- a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java +++ b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java @@ -12,6 +12,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import ru.ulstu.extractor.model.Commit; import ru.ulstu.extractor.model.CommitAuthorStatistic; +import ru.ulstu.extractor.model.CommitEntityStatistic; import ru.ulstu.extractor.model.CommitTimeStatistic; import ru.ulstu.extractor.model.CommitUrlStatistic; import ru.ulstu.extractor.model.Repository; @@ -31,4 +32,7 @@ public interface CommitRepository extends JpaRepository { @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(cast(c.date as date), COUNT(DISTINCT c.hash)) FROM Commit c GROUP by cast(c.date as date) ORDER by cast(c.date as date)") List getCommitTimeStatistic(); + @Query("SELECT new ru.ulstu.extractor.model.CommitEntityStatistic(f.containsEntity, COUNT(DISTINCT c.hash)) FROM FileChange f, Commit c WHERE f MEMBER OF c.fileChanges GROUP by f.containsEntity") + List getCommitEntityStatistic(); + } diff --git a/src/main/resources/templates/statistic.html b/src/main/resources/templates/statistic.html index fd2107b..2ed8f82 100644 --- a/src/main/resources/templates/statistic.html +++ b/src/main/resources/templates/statistic.html @@ -174,10 +174,49 @@ }); +
+
-- 2.34.1 From 8b9822de19cfdec1f07606f86c4172a88bfdb0b5 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 14 Apr 2021 16:56:47 +0400 Subject: [PATCH 008/163] #22 - Change statistic pie --- .../extractor/controller/StatisticController.java | 11 +++++++++++ .../ulstu/extractor/repository/CommitRepository.java | 3 +++ src/main/resources/templates/statistic.html | 10 +++++----- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java index 7952aba..eaa2340 100644 --- a/src/main/java/ru/ulstu/extractor/controller/StatisticController.java +++ b/src/main/java/ru/ulstu/extractor/controller/StatisticController.java @@ -50,7 +50,18 @@ public class StatisticController { List entityCommits = commitRepository.getCommitEntityStatistic().stream() .map(stat -> new Object[]{stat.getEntity(), stat.getCountCommit()}) .collect(Collectors.toList()); + for (int i = 0; i < entityCommits.size(); i++) { + entityCommits.get(i)[0] = Boolean.TRUE.equals(entityCommits.get(i)[0]) + ? "Есть сущности" + : (entityCommits.get(i)[0] == null + ? "Нет данных" + : "Нет сущностей"); + } model.addAttribute("commitEntityData", entityCommits); + List timeEntityCommits = commitRepository.getCommitTimeEntityStatistic().stream() + .map(stat -> new Object[]{stat.getDate(), stat.getCountCommit()}) + .collect(Collectors.toList()); + model.addAttribute("commitTimeEntityData", timeEntityCommits); return STATISTIC; } } diff --git a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java index 9b92756..f7fe48a 100644 --- a/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java +++ b/src/main/java/ru/ulstu/extractor/repository/CommitRepository.java @@ -35,4 +35,7 @@ public interface CommitRepository extends JpaRepository { @Query("SELECT new ru.ulstu.extractor.model.CommitEntityStatistic(f.containsEntity, COUNT(DISTINCT c.hash)) FROM FileChange f, Commit c WHERE f MEMBER OF c.fileChanges GROUP by f.containsEntity") List getCommitEntityStatistic(); + @Query("SELECT new ru.ulstu.extractor.model.CommitTimeStatistic(cast(c.date as date), COUNT(DISTINCT c.hash)) FROM Commit c, FileChange f WHERE f MEMBER OF c.fileChanges AND f.containsEntity = true GROUP by cast(c.date as date) ORDER by cast(c.date as date)") + List getCommitTimeEntityStatistic(); + } diff --git a/src/main/resources/templates/statistic.html b/src/main/resources/templates/statistic.html index 2ed8f82..a1f9c9a 100644 --- a/src/main/resources/templates/statistic.html +++ b/src/main/resources/templates/statistic.html @@ -15,10 +15,6 @@ - - + +