no message
This commit is contained in:
219
src/_VisualDVM/Passes/All/CreateTestFromDirectory.java
Normal file
219
src/_VisualDVM/Passes/All/CreateTestFromDirectory.java
Normal file
@@ -0,0 +1,219 @@
|
||||
package _VisualDVM.Passes.All;
|
||||
import Common.Utils.Utils_;
|
||||
import _VisualDVM.Constants;
|
||||
import _VisualDVM.Current;
|
||||
import Common.Visual.Windows.Dialog.VDirectoryChooser;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Utils;
|
||||
import _VisualDVM.GlobalData.Settings.SettingName;
|
||||
import _VisualDVM.ProjectData.Files.ProjectFile;
|
||||
import _VisualDVM.ProjectData.LanguageName;
|
||||
import _VisualDVM.Repository.Component.Sapfor.Sapfor;
|
||||
import _VisualDVM.TestingSystem.Common.Group.Group;
|
||||
import _VisualDVM.TestingSystem.Common.Test.Test;
|
||||
import _VisualDVM.Passes.PassCode;
|
||||
import Common.Passes.PassException;
|
||||
import Common.Passes.Pass;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Vector;
|
||||
public class CreateTestFromDirectory extends Pass<Test> {
|
||||
@Override
|
||||
public String getIconPath() {
|
||||
return "/icons/OpenProject.png";
|
||||
}
|
||||
@Override
|
||||
public String getButtonText() {
|
||||
return "";
|
||||
}
|
||||
@Override
|
||||
protected boolean needsAnimation() {
|
||||
return true;
|
||||
}
|
||||
Group group = null;
|
||||
File dir = null;
|
||||
boolean from_files_chooser = false;
|
||||
//--
|
||||
void saveDirectory() {
|
||||
Global.mainModule.getPass(PassCode.UpdateSetting).Do(SettingName.ProjectsSearchDirectory,
|
||||
(dir.getParentFile() == null) ? dir.getAbsolutePath() : dir.getParent()
|
||||
);
|
||||
}
|
||||
Vector<File> files = null;
|
||||
protected boolean selectFiles() {
|
||||
VDirectoryChooser directoryChooser = new VDirectoryChooser("Выбор домашней папки теста");
|
||||
Utils.RestoreSelectedDirectory(directoryChooser);
|
||||
dir = directoryChooser.ShowDialog();
|
||||
if (dir == null) {
|
||||
Log.Writeln_("Папка не выбрана.");
|
||||
return false;
|
||||
} else {
|
||||
files = new Vector<>(Arrays.asList(dir.listFiles()));
|
||||
saveDirectory();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//--
|
||||
Vector<ProjectFile> project_files = new Vector<>();
|
||||
protected boolean initTarget() throws Exception {
|
||||
target = new Test();
|
||||
target.sender_address = Global.mainModule.getAccount().email;
|
||||
target.sender_name = Global.mainModule.getAccount().name;
|
||||
target.group_id = group.id;
|
||||
target.description = dir.getName();
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
files = null;
|
||||
if (args.length == 0) {
|
||||
//--
|
||||
from_files_chooser = true;
|
||||
if (!Global.mainModule.Check(Log, Current.Group))
|
||||
return false;
|
||||
group = Global.mainModule.getGroup();
|
||||
if (!selectFiles())
|
||||
return false;
|
||||
//-
|
||||
} else {
|
||||
from_files_chooser = false;
|
||||
dir = (File) args[0];
|
||||
group = (Group) args[1];
|
||||
files = new Vector<>(Arrays.asList(dir.listFiles()));
|
||||
}
|
||||
//---
|
||||
int subdirs = 0;
|
||||
int bad = 0;
|
||||
int active_programs = 0;
|
||||
int headers = 0;
|
||||
int other_project_files = 0;
|
||||
//---
|
||||
if (dir.getName().equalsIgnoreCase(Constants.data)) {
|
||||
Log.Writeln_("Папка " + Utils_.Brackets(dir) + " является служебной папкой визуализатора.");
|
||||
return false;
|
||||
}
|
||||
//--
|
||||
if (Utils_.ContainsCyrillic(dir.getName()) || Utils_.ContainsForbiddenName(dir.getName())) {
|
||||
Log.Writeln_("Имя папки " + Utils_.Brackets(dir.getName())
|
||||
+ " содержит запрещённые символы "
|
||||
+ Utils_.printAllForbiddenCharacters() + ", или кириллицу.");
|
||||
return false;
|
||||
}
|
||||
//--
|
||||
if (files == null) {
|
||||
Log.Writeln_("Не удалось получить список файлов для папки " + Utils_.Brackets(dir) + ".");
|
||||
return false;
|
||||
}
|
||||
//---
|
||||
project_files = new Vector<>();
|
||||
//--
|
||||
for (File file : files) {
|
||||
//-----
|
||||
if (file.isDirectory()) {
|
||||
//если это подпапка нам все равно на каком она языке. не версия и не служебная. ее наличие уже не допустимо.
|
||||
if (!file.getName().equalsIgnoreCase(Constants.data) &&
|
||||
!Utils.isVersion(file)) {
|
||||
subdirs++;
|
||||
}
|
||||
} else if (file.isFile() && !Utils_.ContainsCyrillic(file.getName()) && !Utils_.ContainsForbiddenName(file.getName())) {
|
||||
//если файл. все недопустимые файлы просто игнорируются.
|
||||
ProjectFile projectFile = new ProjectFile(file);
|
||||
if (isNotExcluded(projectFile)) {
|
||||
switch (projectFile.fileType) {
|
||||
case program:
|
||||
if (projectFile.languageName.equals(group.language)) {
|
||||
active_programs++;
|
||||
project_files.add(projectFile);
|
||||
} else
|
||||
other_project_files++;
|
||||
break;
|
||||
case header:
|
||||
headers++;
|
||||
project_files.add(projectFile);
|
||||
break;
|
||||
case none:
|
||||
project_files.add(projectFile);
|
||||
other_project_files++;
|
||||
break;
|
||||
default:
|
||||
other_project_files++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//--
|
||||
if (subdirs > 0) {
|
||||
Log.Writeln_("Папка " + Utils_.Brackets(dir) + " содержит вложенные подпапки,\n" +
|
||||
"не являющиеся версиями или данными визуализатора");
|
||||
return false;
|
||||
}
|
||||
if (active_programs == 0) {
|
||||
Log.Writeln_("Папка не содержит ни одной программы на языке " + group.language.getDescription() + ".");
|
||||
return false;
|
||||
}
|
||||
if (project_files.isEmpty()) {
|
||||
Log.Writeln_("В папке не найдено файлов с допустимыми расширениями для языка " +
|
||||
group.language.getDescription() + "\n" +
|
||||
group.language.PrintExtensions()
|
||||
);
|
||||
}
|
||||
//----
|
||||
if (!initTarget()) return false;
|
||||
//----
|
||||
Vector<String> filesNames = new Vector<>();
|
||||
for (ProjectFile projectFile : project_files)
|
||||
filesNames.add(projectFile.file.getName());
|
||||
target.files = String.join("\n", filesNames);
|
||||
return true;
|
||||
}
|
||||
public boolean isNotExcluded(ProjectFile projectFile) {
|
||||
return true;
|
||||
}
|
||||
//-
|
||||
public File packTestCode() throws Exception {
|
||||
target.temp_project_name = Utils_.getDateName("test");
|
||||
//-
|
||||
File tempProject = target.getTempProject();
|
||||
File tempArchive = target.getTempArchive();
|
||||
//- создать бд.
|
||||
FileUtils.forceMkdir(tempProject);
|
||||
//--
|
||||
for (ProjectFile projectFile : project_files) {
|
||||
File dst = new File(tempProject, projectFile.file.getName());
|
||||
FileUtils.copyFile(projectFile.file, dst);
|
||||
}
|
||||
//---
|
||||
Utils.ClearProjectData(tempProject);
|
||||
//--
|
||||
ZipFolderPass zip = new ZipFolderPass();
|
||||
if (zip.Do(tempProject.getAbsolutePath(), tempArchive.getAbsolutePath())) {
|
||||
target.project_archive_bytes = Utils_.fileToBytes(tempArchive);
|
||||
} else throw new PassException("Не удалось создать архив папки с кодом.");
|
||||
return tempProject;
|
||||
}
|
||||
//-
|
||||
@Override
|
||||
protected void body() throws Exception {
|
||||
ShowMessage1(dir.getName());
|
||||
//--
|
||||
File tempProject = packTestCode(); //создание копии папки, и архивация.
|
||||
//-- получить размерность консольным сапфором. папка уже отправлена и чистить ее не нужно!!
|
||||
ShowMessage2("Синтаксический анализ и определение размерности");
|
||||
if (group.language == LanguageName.fortran) {//если не определит, будут нули.
|
||||
Sapfor.getMinMaxDim(Sapfor.getTempCopy(Global.mainModule.getSapfor().getFile()), tempProject, target);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected boolean validate() {
|
||||
return Log.isEmpty();
|
||||
}
|
||||
@Override
|
||||
protected void performDone() throws Exception {
|
||||
super.performDone();
|
||||
if (from_files_chooser)
|
||||
Global.mainModule.getPass(PassCode.PublishTest).Do(target);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user