переделал скачивание стандартных тестов. В дальнейшем будет полностью на сервере.

This commit is contained in:
2023-11-19 00:25:37 +03:00
parent dae90b6c5e
commit f005b5dbc9
4 changed files with 145 additions and 137 deletions

View File

@@ -3,6 +3,7 @@ import Common.Constants;
import Common.Database.DBObject;
import Common.Global;
import Common.Utils.Utils;
import GlobalData.Account.Account;
import GlobalData.Machine.Machine;
import GlobalData.RemoteFile.RemoteFile;
import GlobalData.Tasks.TaskState;
@@ -33,11 +34,13 @@ import Visual_DVM_2021.Passes.All.ZipFolderPass;
import Visual_DVM_2021.Passes.PassCode_2021;
import Visual_DVM_2021.Passes.Pass_2021;
import javafx.util.Pair;
import org.apache.commons.io.FileUtils;
import javax.swing.*;
import java.io.File;
import java.io.Serializable;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Vector;
@@ -211,68 +214,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
TimerOff();
TimerOn();
}
//->>
Group ConvertDirectoryToGroup(File src, LanguageName languageName, TestType testType) throws Exception {
Group object = new Group();
//->>
object.description = src.getName();
object.language = languageName;
object.type = testType;
//-->>
//->>
File[] testsFiles = src.listFiles(pathname ->
pathname.isFile()
&& !pathname.getName().equals("settings")
&& !pathname.getName().equals("test-analyzer.sh")
&& Utils.getExtension(pathname).startsWith(languageName.getDVMCompile()));
;
if (testsFiles != null) {
for (File testFile : testsFiles)
object.testsFiles.put(testFile.getName(), Utils.packFile(testFile));
}
//->>
return object;
}
//->>
public Vector<Group> getRepoGroupsInfo() throws Exception {
Vector<Group> groups = new Vector<>();
File testsSrc = Paths.get(
Global.RepoDirectory.getAbsolutePath(),
"dvm", "tools", "tester", "trunk", "test-suite").toFile();
LanguageName[] supportedLanguages = new LanguageName[]{LanguageName.fortran, LanguageName.c};
for (LanguageName languageName : supportedLanguages) {
for (TestType testType : TestType.values()) {
File groupsSrc = null;
switch (testType) {
case Correctness:
String languageSrcName = null;
switch (languageName) {
case fortran:
languageSrcName = "Fortran";
break;
case c:
languageSrcName = "C";
break;
}
if (languageSrcName != null) {
groupsSrc = Paths.get(testsSrc.getAbsolutePath(), "Correctness", languageSrcName).toFile();
File[] groupsDirs = groupsSrc.listFiles(File::isDirectory);
if (groupsDirs != null) {
for (File groupDir : groupsDirs)
groups.add(ConvertDirectoryToGroup(groupDir, languageName, testType));
}
}
break;
case Performance:
File groupDir = Paths.get(testsSrc.getAbsolutePath(), "Performance").toFile();
groups.add(ConvertDirectoryToGroup(groupDir, languageName, testType));
break;
}
}
}
groups.sort(Comparator.comparing(o -> o.description));
return groups;
}
@Override
protected void Session() throws Exception {
DBObject dbObject;
@@ -417,15 +358,6 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
throw new RepositoryRefuseException("Теста с именем " + request.arg + " не существует");
break;
//-------------------------------------------------------------------------------------->>>>
case RefreshDVMTests:
Print("Синхронизировать репозиторий тестов");
// временно отключить для отладки.
DownloadRepository downloadRepository = new DownloadRepository();
if (!downloadRepository.Do())
throw new RepositoryRefuseException("Не удалось обновить репозиторий");
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = getRepoGroupsInfo();
break;
case GetAccountQueueSize:
Print("Получить размер очереди для пользователя " + request.arg);
SetCurrentAccountDB(request.arg);
@@ -546,8 +478,119 @@ public class TestingServer extends RepositoryServer<TestsDatabase> {
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = sapforPackageData;
break;
//---
case RefreshDVMTests:
Print("Синхронизировать репозиторий тестов ");
response = new ServerExchangeUnit_2021(ServerCode.OK);
response.object = RefreshDVMTests((Account) request.object);
break;
//--
default:
throw new RepositoryRefuseException("Неподдерживаемый код: " + code);
}
}
//->>
//->>
Pair<Group, Vector<File>> ConvertDirectoryToGroup(File src, LanguageName languageName, TestType testType, Account account) throws Exception {
Group object = new Group();
Vector<File> groupFiles = null; //транспорт.
//->>
object.description = src.getName();
object.language = languageName;
object.type = testType;
object.sender_name = account.name;
object.sender_address = account.email;
//-->>
File[] files = src.listFiles(pathname ->
pathname.isFile()
&& !pathname.getName().equals("settings")
&& !pathname.getName().equals("test-analyzer.sh")
&& Utils.getExtension(pathname).startsWith(languageName.getDVMCompile()));
;
if (files != null) {
groupFiles = new Vector<>(Arrays.asList(files));
groupFiles.sort(Comparator.comparing(File::getName));
}
//->>
return new Pair<>(object, groupFiles);
}
public LinkedHashMap<Group, Vector<Test>> RefreshDVMTests(Account account) throws Exception {
DownloadRepository downloadRepository = new DownloadRepository();
if (!downloadRepository.Do())
throw new RepositoryRefuseException("Не удалось обновить репозиторий");
//-->>
Vector<Pair<Group, Vector<File>>> groups = new Vector<>();
LinkedHashMap<Group, Vector<Test>> res = new LinkedHashMap<>();
File testsSrc = Paths.get(
Global.RepoDirectory.getAbsolutePath(),
"dvm", "tools", "tester", "trunk", "test-suite").toFile();
LanguageName[] supportedLanguages = new LanguageName[]{LanguageName.fortran, LanguageName.c};
for (LanguageName languageName : supportedLanguages) {
for (TestType testType : TestType.values()) {
File groupsSrc = null;
switch (testType) {
case Correctness:
String languageSrcName = null;
switch (languageName) {
case fortran:
languageSrcName = "Fortran";
break;
case c:
languageSrcName = "C";
break;
}
if (languageSrcName != null) {
groupsSrc = Paths.get(testsSrc.getAbsolutePath(), "Correctness", languageSrcName).toFile();
File[] groupsDirs = groupsSrc.listFiles(File::isDirectory);
if (groupsDirs != null) {
for (File groupDir : groupsDirs)
groups.add(ConvertDirectoryToGroup(groupDir, languageName, testType, account));
}
}
break;
case Performance:
File groupDir = Paths.get(testsSrc.getAbsolutePath(), "Performance").toFile();
groups.add(ConvertDirectoryToGroup(groupDir, languageName, testType, account));
break;
}
}
}
groups.sort(Comparator.comparing(o -> o.getKey().description));
//-теперь создать тесты.
System.out.println("найдено " + groups.size() + " групп");
//--
for (Pair<Group, Vector<File>> p : groups) {
Group group = p.getKey();
//-
db.Insert(group);
Vector<Test> testsIds = new Vector<>();
res.put(group, testsIds);
//-
Vector<File> files = p.getValue();
if (!files.isEmpty()) {
//->>
for (File file : files) {
System.out.println("Создание теста " + file.getName());
Test test = new Test();
test.description = Utils.getNameWithoutExtension(file.getName()) + "_" + group.language.getDVMCompile();
test.sender_name = account.name;
test.sender_address = account.email;
test.group_id = group.id;
db.Insert(test);
testsIds.add(test);
//->>
File testProject = new File(Global.TempDirectory, String.valueOf(test.id));
Utils.CheckAndCleanDirectory(testProject);
File testFile = Paths.get(testProject.getAbsolutePath(), file.getName()).toFile();
FileUtils.copyFile(file, testFile);
//----
//архивация.
File archive = test.getArchive();
ZipFolderPass zip = new ZipFolderPass();
zip.Do(testProject.getAbsolutePath(), archive.getAbsolutePath());
}
}
}
return res;
}
}