#12 -- Add build tool components
This commit is contained in:
parent
5153270239
commit
8d3e7f4e2e
@ -5,8 +5,8 @@
|
||||
|
||||
package ru.ulstu.extractor.heuristic.api;
|
||||
|
||||
import ru.ulstu.extractor.heuristic.model.BuildTool;
|
||||
import ru.ulstu.extractor.heuristic.model.ProgrammingLanguage;
|
||||
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;
|
||||
|
||||
@ -21,11 +21,11 @@ import java.util.Optional;
|
||||
|
||||
public abstract class StructuralUnitIdentifier {
|
||||
public List<StructuralUnit> getEntityClasses(String projectPath, List<File> projectFiles, List<File> rootProjectFiles) {
|
||||
String subDirectory = getSourceDirectory(projectFiles, rootProjectFiles);
|
||||
String subDirectory = getSourceDirectory(rootProjectFiles);
|
||||
return getEntityClasses(projectPath, subDirectory, projectFiles);
|
||||
}
|
||||
|
||||
protected abstract String getSourceDirectory(List<File> projectFiles, List<File> rootProjectFiles);
|
||||
protected abstract String getSourceDirectory(List<File> rootProjectFiles);
|
||||
|
||||
public abstract List<StructuralUnit> getEntityClasses(String projectPath, String subDirectory, List<File> projectFiles);
|
||||
|
||||
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.component;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BuildTool {
|
||||
private final String name;
|
||||
|
||||
public BuildTool(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public abstract boolean canAppliedToProject(List<File> rootProjectFiles);
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public abstract String getSourceDirectoryPath();
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.component;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class GradleBuildTool extends BuildTool {
|
||||
|
||||
public GradleBuildTool() {
|
||||
super("Gradle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAppliedToProject(List<File> rootProjectFiles) {
|
||||
return rootProjectFiles.stream()
|
||||
.anyMatch(file -> file.getName().equals("build.gradle") || file.getName().equals("settings.gradle"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceDirectoryPath() {
|
||||
return "src";
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* 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.component;
|
||||
|
||||
public class JavaProgrammingLanguage extends ProgrammingLanguage {
|
||||
public JavaProgrammingLanguage() {
|
||||
super("java");
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.component;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class MavenBuildTool extends BuildTool {
|
||||
|
||||
public MavenBuildTool() {
|
||||
super("Maven");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAppliedToProject(List<File> rootProjectFiles) {
|
||||
return rootProjectFiles.stream()
|
||||
.anyMatch(file -> file.getName().equals("pom.xml"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceDirectoryPath() {
|
||||
return "src";
|
||||
}
|
||||
}
|
@ -1,4 +1,9 @@
|
||||
package ru.ulstu.extractor.heuristic.model;
|
||||
/*
|
||||
* 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.component;
|
||||
|
||||
public abstract class ProgrammingLanguage {
|
||||
private final String name;
|
@ -1,16 +0,0 @@
|
||||
package ru.ulstu.extractor.heuristic.model;
|
||||
|
||||
public abstract class BuildTool {
|
||||
private final String name;
|
||||
|
||||
public BuildTool(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected abstract boolean canAppliedToProject();
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package ru.ulstu.extractor.heuristic.model;
|
||||
|
||||
public class GradleBuildTool extends BuildTool {
|
||||
|
||||
public GradleBuildTool() {
|
||||
super("Gradle");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canAppliedToProject() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package ru.ulstu.extractor.heuristic.model;
|
||||
|
||||
public class JavaProgrammingLanguage extends ProgrammingLanguage {
|
||||
public JavaProgrammingLanguage() {
|
||||
super("java");
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class MavenBuildTool extends BuildTool {
|
||||
|
||||
public MavenBuildTool() {
|
||||
super("Gradle");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canAppliedToProject() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.heuristic.component.BuildTool;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class BuildToolService {
|
||||
private final List<BuildTool> buildTools;
|
||||
|
||||
public BuildToolService(List<BuildTool> buildTools) {
|
||||
this.buildTools = buildTools;
|
||||
}
|
||||
|
||||
public Optional<BuildTool> getProjectBuildTool(List<File> rootProjectFiles) {
|
||||
return buildTools.stream().filter(buildTool -> buildTool.canAppliedToProject(rootProjectFiles)).findAny();
|
||||
}
|
||||
}
|
@ -10,12 +10,12 @@ import com.github.javaparser.ParseResult;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.ulstu.extractor.heuristic.api.StructuralUnitIdentifier;
|
||||
import ru.ulstu.extractor.heuristic.model.BuildTool;
|
||||
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.GradleBuildTool;
|
||||
import ru.ulstu.extractor.heuristic.model.JavaProgrammingLanguage;
|
||||
import ru.ulstu.extractor.heuristic.model.MavenBuildTool;
|
||||
import ru.ulstu.extractor.heuristic.model.ProgrammingLanguage;
|
||||
import ru.ulstu.extractor.heuristic.model.StructuralUnit;
|
||||
import ru.ulstu.extractor.util.StringUtils;
|
||||
|
||||
@ -28,9 +28,12 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class JavaIdentifier extends StructuralUnitIdentifier {
|
||||
private final DetectorService detectorService;
|
||||
private final BuildToolService buildToolService;
|
||||
|
||||
public JavaIdentifier(DetectorService detectorService) {
|
||||
public JavaIdentifier(DetectorService detectorService,
|
||||
BuildToolService buildToolService) {
|
||||
this.detectorService = detectorService;
|
||||
this.buildToolService = buildToolService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,15 +107,10 @@ public class JavaIdentifier extends StructuralUnitIdentifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSourceDirectory(List<File> projectFiles, List<File> rootDirectoryFiles) {
|
||||
Optional<BuildTool> buildTool = getBuildTool(rootDirectoryFiles);
|
||||
if (buildTool.isPresent()) {
|
||||
if (buildTool.get() instanceof GradleBuildTool ||
|
||||
buildTool.get() instanceof MavenBuildTool) {
|
||||
return "src";
|
||||
}
|
||||
}
|
||||
return "src";
|
||||
protected String getSourceDirectory(List<File> rootDirectoryFiles) {
|
||||
return buildToolService.getProjectBuildTool(rootDirectoryFiles)
|
||||
.map(BuildTool::getSourceDirectoryPath)
|
||||
.orElse("src");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user