From 9fcc14ae6f15429b2db28a2c6fc3e3589e679ade Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 12 Apr 2021 12:12:24 +0400 Subject: [PATCH 001/157] #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.25.1 From 339b51cef9f6fdc9634971f521b1f32b63a0b15d Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 14 Apr 2021 12:38:05 +0400 Subject: [PATCH 002/157] fix gradle version --- build.gradle | 56 ++++++++++++------------ gradle/wrapper/gradle-wrapper.properties | 7 ++- 2 files changed, 34 insertions(+), 29 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' - - compile 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' - - 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' - - testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' + 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' + + implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0' + + 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' + + 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' + + 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.25.1 From 62b1542de56b27ebb522d5fda7db1ac60cf8a884 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 14 Apr 2021 13:05:49 +0000 Subject: [PATCH 003/157] fix resources --- gradlew | 0 .../games.css | 0 .../highlight.pack.js.Без названия | 0 .../more arrow.png | Bin .../script.js.Без названия | 0 .../vs2015.css | 0 src/main/resources/public/detector.html | 10 +++++----- 7 files changed, 5 insertions(+), 5 deletions(-) mode change 100644 => 100755 gradlew rename src/main/resources/public/{Code Detector & Formatter_files => CodeAndFormatter}/games.css (100%) rename src/main/resources/public/{Code Detector & Formatter_files => CodeAndFormatter}/highlight.pack.js.Без названия (100%) rename src/main/resources/public/{Code Detector & Formatter_files => CodeAndFormatter}/more arrow.png (100%) rename src/main/resources/public/{Code Detector & Formatter_files => CodeAndFormatter}/script.js.Без названия (100%) rename src/main/resources/public/{Code Detector & Formatter_files => CodeAndFormatter}/vs2015.css (100%) diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/resources/public/Code Detector & Formatter_files/games.css b/src/main/resources/public/CodeAndFormatter/games.css similarity index 100% rename from src/main/resources/public/Code Detector & Formatter_files/games.css rename to src/main/resources/public/CodeAndFormatter/games.css diff --git a/src/main/resources/public/Code Detector & Formatter_files/highlight.pack.js.Без названия b/src/main/resources/public/CodeAndFormatter/highlight.pack.js.Без названия similarity index 100% rename from src/main/resources/public/Code Detector & Formatter_files/highlight.pack.js.Без названия rename to src/main/resources/public/CodeAndFormatter/highlight.pack.js.Без названия diff --git a/src/main/resources/public/Code Detector & Formatter_files/more arrow.png b/src/main/resources/public/CodeAndFormatter/more arrow.png similarity index 100% rename from src/main/resources/public/Code Detector & Formatter_files/more arrow.png rename to src/main/resources/public/CodeAndFormatter/more arrow.png diff --git a/src/main/resources/public/Code Detector & Formatter_files/script.js.Без названия b/src/main/resources/public/CodeAndFormatter/script.js.Без названия similarity index 100% rename from src/main/resources/public/Code Detector & Formatter_files/script.js.Без названия rename to src/main/resources/public/CodeAndFormatter/script.js.Без названия diff --git a/src/main/resources/public/Code Detector & Formatter_files/vs2015.css b/src/main/resources/public/CodeAndFormatter/vs2015.css similarity index 100% rename from src/main/resources/public/Code Detector & Formatter_files/vs2015.css rename to src/main/resources/public/CodeAndFormatter/vs2015.css diff --git a/src/main/resources/public/detector.html b/src/main/resources/public/detector.html index 2715a53..6e53ff3 100644 --- a/src/main/resources/public/detector.html +++ b/src/main/resources/public/detector.html @@ -36,8 +36,8 @@ content="Automatically detect a programming language by pasting a snippet of code."> - - + + - \ No newline at end of file + -- 2.25.1 From 25847b16e8aee359c42a8cf59a3ee7311f9e4535 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 14 Apr 2021 13:14:28 +0000 Subject: [PATCH 004/157] fix resources --- ...ight.pack.js.Без названия => highlight.pack.js} | 0 .../{script.js.Без названия => script.js} | 0 src/main/resources/public/detector.html | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename src/main/resources/public/CodeAndFormatter/{highlight.pack.js.Без названия => highlight.pack.js} (100%) rename src/main/resources/public/CodeAndFormatter/{script.js.Без названия => script.js} (100%) diff --git a/src/main/resources/public/CodeAndFormatter/highlight.pack.js.Без названия b/src/main/resources/public/CodeAndFormatter/highlight.pack.js similarity index 100% rename from src/main/resources/public/CodeAndFormatter/highlight.pack.js.Без названия rename to src/main/resources/public/CodeAndFormatter/highlight.pack.js diff --git a/src/main/resources/public/CodeAndFormatter/script.js.Без названия b/src/main/resources/public/CodeAndFormatter/script.js similarity index 100% rename from src/main/resources/public/CodeAndFormatter/script.js.Без названия rename to src/main/resources/public/CodeAndFormatter/script.js diff --git a/src/main/resources/public/detector.html b/src/main/resources/public/detector.html index 6e53ff3..0179423 100644 --- a/src/main/resources/public/detector.html +++ b/src/main/resources/public/detector.html @@ -111,8 +111,8 @@ - - + +