#24-Create resource methods
This commit is contained in:
parent
942090145f
commit
8354d45a32
@ -9,6 +9,7 @@ import ru.ulstu.extractor.heuristic.component.BuildTool;
|
|||||||
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
||||||
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
||||||
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||||
|
import ru.ulstu.extractor.heuristic.model.ResourceUnit;
|
||||||
import ru.ulstu.extractor.heuristic.service.DetectorService;
|
import ru.ulstu.extractor.heuristic.service.DetectorService;
|
||||||
import ru.ulstu.extractor.heuristic.service.ProgrammingLanguageService;
|
import ru.ulstu.extractor.heuristic.service.ProgrammingLanguageService;
|
||||||
import ru.ulstu.extractor.util.StringUtils;
|
import ru.ulstu.extractor.util.StringUtils;
|
||||||
@ -35,6 +36,11 @@ public abstract class StructuralUnitIdentifier {
|
|||||||
return getBusinessLogicClasses(projectPath, subDirectory, projectFiles);
|
return getBusinessLogicClasses(projectPath, subDirectory, projectFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ResourceUnit> getResourceClasses(String projectPath, List<File> projectFiles, List<File> rootProjectFiles) {
|
||||||
|
String subDirectory = getSourceDirectory(rootProjectFiles);
|
||||||
|
return getResourceClasses(projectPath, subDirectory, projectFiles);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract boolean canAppliedToCode(String sourceCode);
|
public abstract boolean canAppliedToCode(String sourceCode);
|
||||||
|
|
||||||
public abstract boolean canAppliedToFile(File projectFile);
|
public abstract boolean canAppliedToFile(File projectFile);
|
||||||
@ -100,4 +106,10 @@ public abstract class StructuralUnitIdentifier {
|
|||||||
fileContent,
|
fileContent,
|
||||||
scrupulousness));
|
scrupulousness));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract List<ResourceUnit> getResourceClasses(String projectPath, String subDirectory, List<File> projectFiles);
|
||||||
|
|
||||||
|
public abstract boolean isResourceClass(String sourceCode);
|
||||||
|
|
||||||
|
protected abstract boolean isResourceClass(File file);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
||||||
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||||
|
import ru.ulstu.extractor.heuristic.model.ResourceUnit;
|
||||||
import ru.ulstu.extractor.heuristic.service.StructuralUnitService;
|
import ru.ulstu.extractor.heuristic.service.StructuralUnitService;
|
||||||
import ru.ulstu.extractor.service.GitRepositoryService;
|
import ru.ulstu.extractor.service.GitRepositoryService;
|
||||||
|
|
||||||
@ -40,4 +41,10 @@ public class StructuralUnitController {
|
|||||||
File rootPath = gitRepositoryService.getProjectDirectoryFile(repositoryUrl);
|
File rootPath = gitRepositoryService.getProjectDirectoryFile(repositoryUrl);
|
||||||
return structuralUnitService.getBusinessLogic(rootPath);
|
return structuralUnitService.getBusinessLogic(rootPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("get-resources")
|
||||||
|
public List<ResourceUnit> getResource(String repositoryUrl) throws IOException {
|
||||||
|
File rootPath = gitRepositoryService.getProjectDirectoryFile(repositoryUrl);
|
||||||
|
return structuralUnitService.getResource(rootPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 ResourceUnit extends StructuralUnit {
|
||||||
|
|
||||||
|
public ResourceUnit(String projectPath, File file) {
|
||||||
|
super(projectPath, file);
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ import ru.ulstu.extractor.heuristic.component.JavaProgrammingLanguage;
|
|||||||
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
||||||
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
||||||
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||||
|
import ru.ulstu.extractor.heuristic.model.ResourceUnit;
|
||||||
import ru.ulstu.extractor.util.StringUtils;
|
import ru.ulstu.extractor.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -109,6 +110,20 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|||||||
return new JavaProgrammingLanguage();
|
return new JavaProgrammingLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<ResourceUnit> getResourceClasses(String projectPath, String subDirectory, List<File> projectFiles) {
|
||||||
|
return projectFiles.stream()
|
||||||
|
.filter(file -> StringUtils.fileInSubdirectory(file.getPath(), projectPath, subDirectory))
|
||||||
|
.filter(this::isResourceClass)
|
||||||
|
.map(file -> new ResourceUnit(projectPath, file))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isResourceClass(String sourceCode) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEntityClass(File file) {
|
public boolean isEntityClass(File file) {
|
||||||
try {
|
try {
|
||||||
@ -224,4 +239,13 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isResourceClass(File file) {
|
||||||
|
try {
|
||||||
|
return file.getName().endsWith("html") || file.getName().endsWith("css");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier;
|
import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier;
|
||||||
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
import ru.ulstu.extractor.heuristic.model.BusinessLogicUnit;
|
||||||
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||||
|
import ru.ulstu.extractor.heuristic.model.ResourceUnit;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -77,4 +78,16 @@ public class StructuralUnitService {
|
|||||||
.map(identifier -> identifier.isBusinessLogicClass(sourceCode))
|
.map(identifier -> identifier.isBusinessLogicClass(sourceCode))
|
||||||
.orElse(false);
|
.orElse(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ResourceUnit> getResource(File rootPath) throws IOException {
|
||||||
|
List<File> projectFiles = directoryService.getFilesRecursively(rootPath);
|
||||||
|
List<File> rootProjectFiles = directoryService.getDirectoryFiles(rootPath.toPath());
|
||||||
|
return getStructuralUnitIdentifier(
|
||||||
|
structuralUnitIdentifier -> structuralUnitIdentifier.canAppliedToProject(
|
||||||
|
rootPath.getPath(),
|
||||||
|
projectFiles,
|
||||||
|
rootProjectFiles))
|
||||||
|
.orElseThrow(() -> new RuntimeException("Identifier not found"))
|
||||||
|
.getResourceClasses(rootPath.getPath(), projectFiles, rootProjectFiles);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user