118 lines
4.2 KiB
Java
118 lines
4.2 KiB
Java
|
|
package Visual_DVM_2021.Passes.All;
|
|||
|
|
import Common.Constants;
|
|||
|
|
import Common.Current;
|
|||
|
|
import Common.Utils.Files.VDirectoryChooser;
|
|||
|
|
import Common.Utils.Utils;
|
|||
|
|
import ProjectData.Files.ProjectFile;
|
|||
|
|
import ProjectData.LanguageName;
|
|||
|
|
import TestingSystem.Common.Test.Test;
|
|||
|
|
import Visual_DVM_2021.Passes.Pass_2021;
|
|||
|
|
|
|||
|
|
import java.io.File;
|
|||
|
|
import java.util.Vector;
|
|||
|
|
public class CreateTestFromFolder extends Pass_2021<Test> {
|
|||
|
|
VDirectoryChooser directoryChooser = new VDirectoryChooser("Выбор домашней папки теста");
|
|||
|
|
@Override
|
|||
|
|
public String getIconPath() {
|
|||
|
|
return "/icons/OpenProject.png";
|
|||
|
|
}
|
|||
|
|
@Override
|
|||
|
|
public String getButtonText() {
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
@Override
|
|||
|
|
protected boolean needsAnimation() {
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
File dir = null;
|
|||
|
|
Vector<ProjectFile> project_files = new Vector<>();
|
|||
|
|
@Override
|
|||
|
|
protected boolean canStart(Object... args) throws Exception {
|
|||
|
|
if (args.length == 0) {
|
|||
|
|
if (!Current.Check(Log, Current.Group))
|
|||
|
|
return false;
|
|||
|
|
dir = directoryChooser.ShowDialog();
|
|||
|
|
} else {
|
|||
|
|
dir = (File) args[0];
|
|||
|
|
}
|
|||
|
|
if (dir ==null) {
|
|||
|
|
Log.Writeln_("Папка не выбрана.");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
//---
|
|||
|
|
File[] files = dir.listFiles();
|
|||
|
|
project_files = new Vector<>();
|
|||
|
|
int subdirs = 0;
|
|||
|
|
int bad = 0;
|
|||
|
|
int fortran_programs = 0;
|
|||
|
|
int headers = 0;
|
|||
|
|
int other_project_files = 0;
|
|||
|
|
//---
|
|||
|
|
if (dir.getName().equalsIgnoreCase(Constants.data)) {
|
|||
|
|
Log.Writeln_("Папка " + Utils.Brackets(dir) + " является служебной папкой визуализатора.");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
//--
|
|||
|
|
if (files == null) {
|
|||
|
|
Log.Writeln_("Не удалось получить список файлов для папки " + Utils.Brackets(dir) + ".");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
//--
|
|||
|
|
for (File file : files) {
|
|||
|
|
if (!Utils.validateProjectFile(file, Log)) {
|
|||
|
|
Log.Writeln_("Имя файла " + Utils.Brackets(file.getName())
|
|||
|
|
+ " содержит запрещённые символы " + Constants.all_forbidden_characters_string + ", или кириллицу."
|
|||
|
|
);
|
|||
|
|
bad++;
|
|||
|
|
}
|
|||
|
|
if (file.isDirectory() && !file.getName().equalsIgnoreCase(Constants.data)) {
|
|||
|
|
subdirs++;
|
|||
|
|
}
|
|||
|
|
if (file.isFile()) {
|
|||
|
|
ProjectFile projectFile = new ProjectFile(file);
|
|||
|
|
project_files.add(projectFile);
|
|||
|
|
switch (projectFile.fileType) {
|
|||
|
|
case program:
|
|||
|
|
if (projectFile.languageName.equals(LanguageName.fortran))
|
|||
|
|
fortran_programs++;
|
|||
|
|
else
|
|||
|
|
other_project_files++;
|
|||
|
|
break;
|
|||
|
|
case header:
|
|||
|
|
headers++;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
other_project_files++;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//--
|
|||
|
|
if (subdirs > 0) {
|
|||
|
|
Log.Writeln_("Папка " + Utils.Brackets(dir) + " содержит вложенные подпапки.");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
if (bad > 0) {
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
if (fortran_programs == 0) {
|
|||
|
|
Log.Writeln_("Папка не содержит ни одной программы на языке FORTRAN.");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
if (other_project_files > 0) {
|
|||
|
|
Log.Writeln_("Папка содержит файлы, не являющиеся программами на языке FORTRAN, или заголовочными.");
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
@Override
|
|||
|
|
protected void body() throws Exception {
|
|||
|
|
System.out.println("found " + project_files.size());
|
|||
|
|
for (ProjectFile projectFile : project_files) {
|
|||
|
|
System.out.println(projectFile.file.getAbsolutePath());
|
|||
|
|
}
|
|||
|
|
System.out.println("===================");
|
|||
|
|
//--
|
|||
|
|
}
|
|||
|
|
}
|