промежуточный. частичный рефакторинг инициализации. еще не готов.
This commit is contained in:
@@ -2,68 +2,95 @@ package Visual_DVM_2021.Passes.All;
|
||||
import Common.Current;
|
||||
import Common.Utils.Utils;
|
||||
import GlobalData.RemoteFile.RemoteFile;
|
||||
import Visual_DVM_2021.Passes.SSH.CurrentConnectionPass;
|
||||
import Visual_DVM_2021.Passes.PassException;
|
||||
import Visual_DVM_2021.Passes.SSH.ConnectionPass_2023;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
public class RemoteInitialiseUser extends CurrentConnectionPass<String> {
|
||||
import java.util.Vector;
|
||||
public class RemoteInitialiseUser extends ConnectionPass_2023<RemoteFile> {
|
||||
RemoteFile modulesDirectory;
|
||||
@Override
|
||||
protected boolean needsInitialize() {
|
||||
return false;
|
||||
protected boolean needsAnimation() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) {
|
||||
return Current.Check(Log, Current.User);
|
||||
}
|
||||
@Override
|
||||
protected void Connect() throws Exception {
|
||||
machine = Current.getMachine();
|
||||
user = Current.getUser();
|
||||
super.Connect();
|
||||
}
|
||||
void put_resource(String res_name, RemoteFile dst_directory) throws Exception {
|
||||
user.connection.putSingleFile(Utils.CreateTempResourceFile(res_name), new RemoteFile(dst_directory, res_name));
|
||||
}
|
||||
void compileModule(String module_name) throws Exception{
|
||||
user.connection.performScript(modulesDirectory,
|
||||
"g++ " +
|
||||
Utils.DQuotes(module_name + ".cpp") + " -o "+ Utils.DQuotes(module_name));
|
||||
RemoteFile binary = new RemoteFile(modulesDirectory, module_name);
|
||||
if (!user.connection.Exists(binary)){
|
||||
throw new PassException("Не удалось собрать модуль "+Utils.Brackets(module_name));
|
||||
}else {
|
||||
user.connection.sftpChannel.chmod(0777, binary.full_name);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void ServerAction() throws Exception {
|
||||
String workspace_name = Utils.getDateName("visual_sapfor_workspace");
|
||||
target = Utils.toU(Paths.get(sftpChannel.getHome(), workspace_name).toString());
|
||||
ShowMessage1("Создание рабочих папок...");
|
||||
ShowMessage1("Создание рабочего пространства...");
|
||||
target = new RemoteFile(user.connection.sftpChannel.getHome(), workspace_name);
|
||||
user.connection.sftpChannel.mkdir(target.full_name);
|
||||
Vector<RemoteFile> subdirectories = new Vector<>();
|
||||
subdirectories.add(new RemoteFile(target, "projects"));
|
||||
subdirectories.add(modulesDirectory = new RemoteFile(target, "modules"));
|
||||
subdirectories.add(new RemoteFile(target, "tests"));
|
||||
//-------------------------------------
|
||||
sftpChannel.mkdir(target);
|
||||
sftpChannel.cd(target);
|
||||
sftpChannel.mkdir(projects);
|
||||
sftpChannel.mkdir(modules);
|
||||
sftpChannel.mkdir(compilers);
|
||||
sftpChannel.mkdir(tests);
|
||||
//------------------------------------
|
||||
sftpChannel.cd(modules);
|
||||
ShowMessage1("Закачка модулей...");
|
||||
put_resource(launcher_code);
|
||||
put_resource(starter_code);
|
||||
put_resource(Process_r_header);
|
||||
for (RemoteFile remoteFile : subdirectories)
|
||||
user.connection.sftpChannel.mkdir(remoteFile.full_name);
|
||||
//----------------------------------
|
||||
String [] planner_files = new String[]{
|
||||
"Array.h",
|
||||
|
||||
"CompilationSupervisor.h",
|
||||
"CompilationTask.h",
|
||||
|
||||
"File.h",
|
||||
"Global.h",
|
||||
|
||||
"Planner.cpp",
|
||||
|
||||
"RunSupervisor.h",
|
||||
"RunTask.h",
|
||||
|
||||
"String.h",
|
||||
"Supervisor.h",
|
||||
|
||||
"Task.h",
|
||||
"Text.h",
|
||||
"Utils.h"
|
||||
String[] resourses_names = new String[]{
|
||||
//--
|
||||
"Process_r.h",
|
||||
"starter.cpp",
|
||||
"launcher.cpp",
|
||||
//--
|
||||
"Array.h",
|
||||
"CompilationSupervisor.h",
|
||||
"CompilationTask.h",
|
||||
"File.h",
|
||||
"Global.h",
|
||||
"Planner.cpp",
|
||||
"RunSupervisor.h",
|
||||
"RunTask.h",
|
||||
"String.h",
|
||||
"Supervisor.h",
|
||||
"Task.h",
|
||||
"Text.h",
|
||||
"Utils.h"
|
||||
};
|
||||
for (String p: planner_files){
|
||||
File local_p = Utils.getTempFileName(p);
|
||||
URL u = Utils.class.getResource("/files/Planner/" + p);
|
||||
InputStream i = u.openStream();
|
||||
Files.copy(i, local_p.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
putSingleFile(local_p.getAbsolutePath(), p);
|
||||
ShowMessage1("Закачка модулей...");
|
||||
for (String resource_name : resourses_names) {
|
||||
ShowMessage2(resource_name);
|
||||
File src = Utils.CreateTempResourceFile(resource_name);
|
||||
RemoteFile dst = new RemoteFile(modulesDirectory, resource_name);
|
||||
user.connection.putSingleFile(src, dst);
|
||||
}
|
||||
//-------------------------------------
|
||||
ShowMessage1("Сборка модулей...");
|
||||
String [] modules_names = new String[]{
|
||||
"launcher",
|
||||
"starter",
|
||||
"planner"
|
||||
};
|
||||
for (String module_name: modules_names){
|
||||
ShowMessage2(module_name);
|
||||
compileModule(module_name);
|
||||
}
|
||||
/*
|
||||
|
||||
//канал на исполнение независим, поэтому переход в папку отдельный
|
||||
Command(
|
||||
"cd " + Utils.DQuotes(sftpChannel.pwd()), //нужны ли тут кавычки?
|
||||
@@ -74,8 +101,9 @@ public class RemoteInitialiseUser extends CurrentConnectionPass<String> {
|
||||
"chmod 0777 " + launcher,
|
||||
"chmod 0777 " + planner
|
||||
);
|
||||
*/
|
||||
//--------------------------------------
|
||||
RemoteFile info = new RemoteFile(target, Current.getAccount().email);
|
||||
writeToFile("", info);
|
||||
user.connection.writeToFile("", info);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user