#78 - Add FileTS
This commit is contained in:
parent
3b7812a075
commit
4de0e37902
@ -30,6 +30,7 @@ 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.model.Commit;
|
import ru.ulstu.extractor.model.Commit;
|
||||||
|
|
||||||
|
import javax.swing.text.html.parser.Entity;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -39,10 +40,7 @@ import java.net.URL;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@ -280,80 +278,22 @@ public class GitRepositoryService {
|
|||||||
private List<FileChange> parseOutputDiff(String output, org.eclipse.jgit.lib.Repository repository, RevCommit commit) {
|
private List<FileChange> parseOutputDiff(String output, org.eclipse.jgit.lib.Repository repository, RevCommit commit) {
|
||||||
List<FileChange> changes = new ArrayList<>();
|
List<FileChange> changes = new ArrayList<>();
|
||||||
String[] strings = output.split("\n");
|
String[] strings = output.split("\n");
|
||||||
FileChange fileChange = new FileChange();
|
Map<String, List<String>> filesContent = getFilesContent(strings);
|
||||||
boolean isAdded = false;
|
System.out.println(filesContent);
|
||||||
boolean isRemoved = false;
|
for(Map.Entry<String, List<String>> fileSterings: filesContent.entrySet()) {
|
||||||
boolean isFileChanged = false;
|
FileChange fileChange = new FileChange();
|
||||||
int stringsLength = strings.length - 1;
|
fileChange.setFile(fileSterings.getKey());
|
||||||
for (int i = 0; i < strings.length; i++) {
|
Future<Boolean> futureEntity = executorService.submit(() -> structuralUnitService.containsEntity(getContent(repository, commit, fileSterings.getKey())));
|
||||||
while (i < stringsLength) {
|
Future<Boolean> futureBL = executorService.submit(() -> structuralUnitService.containsBusinessLogic(getContent(repository, commit, fileSterings.getKey())));
|
||||||
Optional<String> maybeFileName = getFileName(strings[i]);
|
try {
|
||||||
if (maybeFileName.isPresent()) {
|
fileChange.setContainsBusinessLogic(futureBL.get());
|
||||||
fileChange = new FileChange();
|
fileChange.setContainsEntity(futureEntity.get());
|
||||||
fileChange.setFile(maybeFileName.get());
|
} catch (Exception ex) {
|
||||||
Future<Boolean> futureEntity = executorService.submit(() -> structuralUnitService.containsEntity(getContent(repository, commit, maybeFileName.get())));
|
LOG.warn(ex.getMessage());
|
||||||
Future<Boolean> futureBL = executorService.submit(() -> structuralUnitService.containsBusinessLogic(getContent(repository, commit, maybeFileName.get())));
|
|
||||||
fileChange.setAdded(isAdded);
|
|
||||||
fileChange.setRemoved(isRemoved);
|
|
||||||
try {
|
|
||||||
fileChange.setContainsBusinessLogic(futureBL.get());
|
|
||||||
fileChange.setContainsEntity(futureEntity.get());
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LOG.warn(ex.getMessage());
|
|
||||||
}
|
|
||||||
/// вытащить другие изменения из коммита
|
|
||||||
changes.add(fileChange);
|
|
||||||
}
|
|
||||||
LineChange lineChange = new LineChange();
|
|
||||||
if (strings[i].startsWith("-")) {
|
|
||||||
while ((i < stringsLength) && strings[i].startsWith("-")) {
|
|
||||||
if (strings[i].startsWith("---")) {
|
|
||||||
i++;
|
|
||||||
} else {
|
|
||||||
if (lineChange.getLineFrom() == null) {
|
|
||||||
lineChange.setLineFrom(strings[i]);
|
|
||||||
i++;
|
|
||||||
} else {
|
|
||||||
lineChange.setLineFrom(lineChange.getLineFrom() + "\n" + strings[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
isRemoved = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lineChange.setRemoved(true);
|
|
||||||
}
|
|
||||||
if (strings[i].startsWith("+")) {
|
|
||||||
while ((i < stringsLength) && strings[i].startsWith("+")) {
|
|
||||||
if (strings[i].startsWith("+++")) {
|
|
||||||
i++;
|
|
||||||
} else {
|
|
||||||
if (lineChange.getLineTo() == null) {
|
|
||||||
lineChange.setLineTo(strings[i]);
|
|
||||||
i++;
|
|
||||||
} else {
|
|
||||||
lineChange.setLineTo(lineChange.getLineTo() + "\n" + strings[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
isAdded = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lineChange.setAdded(true);
|
|
||||||
}
|
|
||||||
if ((lineChange.getLineTo() != null) || (lineChange.getLineFrom() != null)
|
|
||||||
|| ((lineChange.getLineTo() != null) && (lineChange.getLineFrom() != null))) {
|
|
||||||
fileChange.getLineChanges().add(lineChange);
|
|
||||||
} else {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
fileChange = getChange(fileChange, fileSterings.getValue());
|
||||||
|
changes.add(fileChange);
|
||||||
}
|
}
|
||||||
if ((isAdded) && (isRemoved)) {
|
|
||||||
isAdded = false;
|
|
||||||
isRemoved = false;
|
|
||||||
isFileChanged = true;
|
|
||||||
}
|
|
||||||
fileChange.setAdded(isAdded);
|
|
||||||
fileChange.setRemoved(isRemoved);
|
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,6 +322,101 @@ public class GitRepositoryService {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, List<String>> getFilesContent(String[] commitStrings) {
|
||||||
|
int i = 0;
|
||||||
|
Map<String, List<String>> result = new HashMap<>();
|
||||||
|
while (i < commitStrings.length) {
|
||||||
|
Optional<String> maybeFileName = getFileName(commitStrings[i]);
|
||||||
|
if (maybeFileName.isEmpty()) {
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
i = skipLinesForNextFile(commitStrings, i);
|
||||||
|
result.put(maybeFileName.get(), getFileContent(commitStrings, i));
|
||||||
|
i += getFileContent(commitStrings, i).size() - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getFileContent(String[] commitsString, int i) {
|
||||||
|
List<String> result = new ArrayList<>();
|
||||||
|
while (i < commitsString.length && getFileName(commitsString[i]).isEmpty()) {
|
||||||
|
result.add(commitsString[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int skipLinesForNextFile(String[] commitStrings, int index) {
|
||||||
|
boolean isFilePrefixSkipped = false;
|
||||||
|
while (!isFilePrefixSkipped && (index < commitStrings.length)) {
|
||||||
|
if ((commitStrings[index].startsWith("diff --git a/"))
|
||||||
|
|| (commitStrings[index].startsWith("delete"))
|
||||||
|
|| (commitStrings[index].startsWith("new"))
|
||||||
|
|| (commitStrings[index].startsWith("index"))
|
||||||
|
|| (commitStrings[index].startsWith("@@"))
|
||||||
|
|| (commitStrings[index].startsWith("---"))
|
||||||
|
|| (commitStrings[index].startsWith("+++"))) {
|
||||||
|
index++;
|
||||||
|
} else {
|
||||||
|
isFilePrefixSkipped = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private FileChange getChange(FileChange fileChange, List<String> fileContent){
|
||||||
|
int addedLine = 0;
|
||||||
|
int removedLine = 0;
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
boolean isRemoved = false;
|
||||||
|
boolean isAdded = false;
|
||||||
|
for (String line : fileContent){
|
||||||
|
LineChange lineChange = new LineChange();
|
||||||
|
if (line.startsWith("-")){
|
||||||
|
isRemoved = true;
|
||||||
|
if (isAdded) {
|
||||||
|
isAdded = false;
|
||||||
|
lineChange = setAdded(lineChange, builder);
|
||||||
|
builder.setLength(0);
|
||||||
|
}
|
||||||
|
builder.append(line).append("\n");
|
||||||
|
removedLine++;
|
||||||
|
} else if(line.startsWith("+")){
|
||||||
|
isAdded = true;
|
||||||
|
if (isRemoved) {
|
||||||
|
isRemoved = false;
|
||||||
|
lineChange = setRemoved(lineChange, builder);
|
||||||
|
builder.setLength(0);
|
||||||
|
}
|
||||||
|
builder.append(line).append("\n");
|
||||||
|
addedLine++;
|
||||||
|
} else {
|
||||||
|
if (isRemoved) {
|
||||||
|
lineChange = setRemoved(lineChange, builder);
|
||||||
|
builder.setLength(0);
|
||||||
|
} else if (isAdded){
|
||||||
|
lineChange = setAdded(lineChange, builder);
|
||||||
|
builder.setLength(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fileChange.setRemoved(removedLine == fileContent.size() - 1);
|
||||||
|
fileChange.setAdded(addedLine == fileContent.size() - 1);
|
||||||
|
return fileChange;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LineChange setRemoved(LineChange lineChange, StringBuilder builder){
|
||||||
|
lineChange.setLineFrom(builder.toString());
|
||||||
|
lineChange.setRemoved(true);
|
||||||
|
return lineChange;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LineChange setAdded(LineChange lineChange, StringBuilder builder){
|
||||||
|
lineChange.setLineTo(builder.toString());
|
||||||
|
lineChange.setAdded(true);
|
||||||
|
return lineChange;
|
||||||
|
}
|
||||||
public Page<GitRepository> findAll(Pageable pageable) {
|
public Page<GitRepository> findAll(Pageable pageable) {
|
||||||
return gitRepositoryRepository.findAll(pageable);
|
return gitRepositoryRepository.findAll(pageable);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import ru.ulstu.extractor.gitrepository.service.GitRepositoryService;
|
|||||||
import ru.ulstu.extractor.model.Commit;
|
import ru.ulstu.extractor.model.Commit;
|
||||||
import ru.ulstu.extractor.ts.model.TimeSeries;
|
import ru.ulstu.extractor.ts.model.TimeSeries;
|
||||||
import ru.ulstu.extractor.ts.model.TimeSeriesType;
|
import ru.ulstu.extractor.ts.model.TimeSeriesType;
|
||||||
|
import ru.ulstu.extractor.ts.model.TimeSeriesValue;
|
||||||
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
import ru.ulstu.extractor.ts.service.TimeSeriesService;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -26,18 +27,30 @@ public class FileTS extends AbstractTimeSeriesCreator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
public List<TimeSeries> getTimeSeries(Integer repositoryId, String branchName) {
|
||||||
// findSum(repositoryId,branchName);
|
List<TimeSeries> timeSeriesResult = new ArrayList<>();
|
||||||
return new ArrayList<>();
|
List<Commit> commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName));
|
||||||
// return Collections.singletonList(
|
double value = 0;
|
||||||
// new TimeSeries(
|
TimeSeries timeSeries = new TimeSeries(
|
||||||
// String.format("",
|
String.format("%s %s %s",
|
||||||
// gitRepositoryService.findById(repositoryId).getName(),
|
gitRepositoryService.findById(repositoryId).getName(),
|
||||||
// branchName,
|
branchName,
|
||||||
// getTimeSeriesType().getDescription()),
|
getTimeSeriesType().getDescription()),
|
||||||
// getTimeSeriesType(),
|
getTimeSeriesType());
|
||||||
// )
|
for (Commit commit : commits) {
|
||||||
// )
|
for (FileChange fileChange : commit.getFileChanges()) {
|
||||||
// )
|
if ((fileChange.getAdded() != null) && (fileChange.getAdded())) {
|
||||||
|
value += 1;
|
||||||
|
}
|
||||||
|
if ((fileChange.getRemoved() != null) && (fileChange.getRemoved())) {
|
||||||
|
value -= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
timeSeries.getValues().add(new TimeSeriesValue(commit.getDate(), value));
|
||||||
|
}
|
||||||
|
if (!timeSeries.getValues().isEmpty()) {
|
||||||
|
timeSeriesResult.add(timeSeries);
|
||||||
|
}
|
||||||
|
return timeSeriesResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -49,20 +62,4 @@ public class FileTS extends AbstractTimeSeriesCreator {
|
|||||||
public TimeSeriesType getTimeSeriesType() {
|
public TimeSeriesType getTimeSeriesType() {
|
||||||
return TimeSeriesType.FILES;
|
return TimeSeriesType.FILES;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void findSum(Integer repositoryId, String branchName) {
|
|
||||||
List<Commit> commits = new ArrayList<>(commitService.findByRepositoryIdAndName(repositoryId, branchName));
|
|
||||||
int value = 0;
|
|
||||||
for (Commit commit : commits) {
|
|
||||||
for (FileChange fileChange : commit.getFileChanges()) {
|
|
||||||
if ((fileChange.getAdded() != null) && (fileChange.getAdded())) {
|
|
||||||
value = +1;
|
|
||||||
}
|
|
||||||
if ((fileChange.getRemoved() != null) && (fileChange.getRemoved())) {
|
|
||||||
value = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
System.out.println(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user