#12 -- Fix directory methods
This commit is contained in:
parent
8d3e7f4e2e
commit
f83d78e763
@ -9,6 +9,7 @@ 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.service.DetectorService;
|
||||
import ru.ulstu.extractor.util.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -43,16 +44,19 @@ public abstract class StructuralUnitIdentifier {
|
||||
|
||||
protected abstract boolean isBusinessLogicClass(File file);
|
||||
|
||||
protected Optional<ProgrammingLanguage> getMainProgrammingLanguage(List<File> projectFiles) {
|
||||
protected Optional<ProgrammingLanguage> getMainProgrammingLanguage(String projectPath, List<File> projectFiles, List<File> rootProjectFiles) {
|
||||
String subDirectory = getSourceDirectory(rootProjectFiles);
|
||||
Map<String, Integer> projectFileLanguageFrequency = new HashMap<>();
|
||||
projectFiles.forEach(projectFile -> {
|
||||
try {
|
||||
String detectedLanguage = getDetectorService().getDetectedLanguage(new String(Files.readAllBytes(projectFile.toPath())));
|
||||
projectFileLanguageFrequency.put(detectedLanguage, projectFileLanguageFrequency.getOrDefault(detectedLanguage, 0) + 1);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
projectFiles.stream()
|
||||
.filter(file -> StringUtils.fileInSubdirectory(file.getPath(), projectPath, subDirectory))
|
||||
.forEach(projectFile -> {
|
||||
try {
|
||||
String detectedLanguage = getDetectorService().getDetectedLanguage(new String(Files.readAllBytes(projectFile.toPath())));
|
||||
projectFileLanguageFrequency.put(detectedLanguage, projectFileLanguageFrequency.getOrDefault(detectedLanguage, 0) + 1);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
Optional<Map.Entry<String, Integer>> mostFrequentLanguageEntry = projectFileLanguageFrequency
|
||||
.entrySet()
|
||||
@ -68,5 +72,5 @@ public abstract class StructuralUnitIdentifier {
|
||||
: Optional.empty();
|
||||
}
|
||||
|
||||
public abstract boolean canAppliedToProject(List<File> projectFiles);
|
||||
public abstract boolean canAppliedToProject(String projectPath, List<File> projectFiles, List<File> rootProjectFiles);
|
||||
}
|
||||
|
@ -11,9 +11,7 @@ import com.github.javaparser.ast.CompilationUnit;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier;
|
||||
import ru.ulstu.extractor.heuristic.component.BuildTool;
|
||||
import ru.ulstu.extractor.heuristic.component.GradleBuildTool;
|
||||
import ru.ulstu.extractor.heuristic.component.JavaProgrammingLanguage;
|
||||
import ru.ulstu.extractor.heuristic.component.MavenBuildTool;
|
||||
import ru.ulstu.extractor.heuristic.component.ProgrammingLanguage;
|
||||
import ru.ulstu.extractor.heuristic.model.EntityUnit;
|
||||
import ru.ulstu.extractor.heuristic.model.StructuralUnit;
|
||||
@ -37,9 +35,9 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAppliedToProject(List<File> projectFiles) {
|
||||
public boolean canAppliedToProject(String projectPath, List<File> projectFiles, List<File> rootProjectFiles) {
|
||||
return /*getBuildTool() instanceof GradleBuildTool
|
||||
&&*/ getMainProgrammingLanguage(projectFiles).orElse(null) instanceof JavaProgrammingLanguage;
|
||||
&&*/ getMainProgrammingLanguage(projectPath, projectFiles, rootProjectFiles).orElse(null) instanceof JavaProgrammingLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,18 +60,8 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional getBuildTool(List<File> rootDirectoryFiles) {
|
||||
//Todo: refactoring is highly recommended
|
||||
Optional<GradleBuildTool> maybeGradleBuildTool = rootDirectoryFiles.stream()
|
||||
.filter(file -> file.getName().equals("build.gradle"))
|
||||
.findAny().map(file -> new GradleBuildTool());
|
||||
|
||||
if (maybeGradleBuildTool.isPresent()) {
|
||||
return maybeGradleBuildTool;
|
||||
}
|
||||
return rootDirectoryFiles.stream()
|
||||
.filter(file -> file.getName().equals("pom.xml"))
|
||||
.findAny().map(file -> new MavenBuildTool());
|
||||
public Optional<BuildTool> getBuildTool(List<File> rootDirectoryFiles) {
|
||||
return buildToolService.getProjectBuildTool(rootDirectoryFiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -33,7 +33,7 @@ public class StructuralUnitService {
|
||||
List<File> projectFiles = directoryService.getFilesRecursively(rootPath);
|
||||
List<File> rootProjectFiles = directoryService.getDirectoryFiles(rootPath.toPath());
|
||||
StructuralUnitIdentifier selectedIdentifier = structuralUnitIdentifiers.stream()
|
||||
.filter(structuralUnitIdentifier -> structuralUnitIdentifier.canAppliedToProject(projectFiles))
|
||||
.filter(structuralUnitIdentifier -> structuralUnitIdentifier.canAppliedToProject(rootPath.getPath(), projectFiles, rootProjectFiles))
|
||||
.findAny()
|
||||
.orElseThrow(() -> new RuntimeException("Identifier not found"));
|
||||
return selectedIdentifier.getEntityClasses(rootPath.getPath(), projectFiles, rootProjectFiles);
|
||||
|
Loading…
Reference in New Issue
Block a user