рефакторинг команд ssh
v++ динамическая смена названия прохода Анализ Кода
This commit is contained in:
@@ -2,7 +2,6 @@ package TestingSystem.DVM;
|
||||
import Common.Constants;
|
||||
import Common.Global;
|
||||
import Common.Utils.Utils;
|
||||
import Common.Utils.Validators.ShellParser;
|
||||
import GlobalData.Machine.Machine;
|
||||
import GlobalData.RemoteFile.RemoteFile;
|
||||
import GlobalData.User.User;
|
||||
@@ -46,6 +45,7 @@ public class UserConnection {
|
||||
shellChannel = (ChannelShell) session.openChannel("shell");
|
||||
in = new PipedInputStream();
|
||||
out = new PipedOutputStream();
|
||||
/*
|
||||
shellChannel.setInputStream(in);
|
||||
shellChannel.setOutputStream(out);
|
||||
pin = new PipedOutputStream(in);
|
||||
@@ -55,6 +55,7 @@ public class UserConnection {
|
||||
fromServer = new InputStreamReader(pout);
|
||||
ShellParser.setUserName(user.login);
|
||||
ShellParser.ReadInvitation(fromServer); //прочитать первое приглашение от машины.
|
||||
*/
|
||||
}
|
||||
public void Disconnect() {
|
||||
if (in != null) {
|
||||
@@ -114,6 +115,8 @@ public class UserConnection {
|
||||
//--
|
||||
//todo из за мусора результатом пользоваться в общем случае невозможно.
|
||||
//следует перенаправлять вывод в какой нибудь временный файл на сервере.
|
||||
|
||||
/*
|
||||
public String ShellCommand(String command) throws Exception {
|
||||
StringBuilder result = new StringBuilder();
|
||||
pin.write((command + "\r\n").getBytes());
|
||||
@@ -122,6 +125,7 @@ public class UserConnection {
|
||||
String[] data = result.toString().split("\n");
|
||||
return (data.length > 0) ? data[data.length - 1] : result.toString();
|
||||
}
|
||||
*/
|
||||
public void getSingleFile(String src, String dst) throws Exception {
|
||||
sftpChannel.get(src, dst);
|
||||
}
|
||||
@@ -146,7 +150,7 @@ public class UserConnection {
|
||||
//-
|
||||
public void RMDIR(String dir) throws Exception {
|
||||
if (!dir.isEmpty() && !dir.equals("/") && !dir.equals("\\") && !dir.equals("*")) {
|
||||
ShellCommand("rm -rf " + Utils.DQuotes(dir));
|
||||
Command("rm -rf " + Utils.DQuotes(dir));
|
||||
} else throw new PassException("Недопустимый путь для удаления папки " + Utils.DQuotes(dir));
|
||||
}
|
||||
//-
|
||||
@@ -237,7 +241,7 @@ public class UserConnection {
|
||||
//--
|
||||
writeToFile("cd " + Utils.DQuotes(directory.full_name) + "\n" + String.join("\n", commands), script_file);
|
||||
//--
|
||||
ShellCommand(Utils.DQuotes(script_file.full_name) + " 1>" + Utils.DQuotes(out.full_name) + " 2>" + Utils.DQuotes(err.full_name));
|
||||
Command(Utils.DQuotes(script_file.full_name) + " 1>" + Utils.DQuotes(out.full_name) + " 2>" + Utils.DQuotes(err.full_name));
|
||||
return new Pair<>(out, err);
|
||||
}
|
||||
public void putResource(RemoteFile dstDirectory, String resource_name) throws Exception {
|
||||
@@ -273,23 +277,23 @@ public class UserConnection {
|
||||
sftpChannel.rename(outFile.full_name, cppVersionsInfo.full_name);
|
||||
//--
|
||||
String[] data = out.split("\n");
|
||||
boolean cpp_17=false;
|
||||
boolean cpp_11=false;
|
||||
boolean cpp_17 = false;
|
||||
boolean cpp_11 = false;
|
||||
//определить какие есть версии.
|
||||
for (String version : data) {
|
||||
switch (version){
|
||||
switch (version) {
|
||||
case "c++17":
|
||||
cpp_17=true;
|
||||
cpp_17 = true;
|
||||
break;
|
||||
case "c++11":
|
||||
cpp_11=true;
|
||||
cpp_11 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cpp_17)
|
||||
res = "-std=c++17";
|
||||
else if (cpp_11)
|
||||
res= "-std=c++11";
|
||||
res = "-std=c++11";
|
||||
RemoteFile cppFlag = new RemoteFile(scriptDirectory, "current_ccp_version");
|
||||
writeToFile(res, cppFlag);
|
||||
return res;
|
||||
@@ -308,9 +312,8 @@ public class UserConnection {
|
||||
}
|
||||
//--
|
||||
public void tryRM(RemoteFile file) throws Exception {
|
||||
if (Exists(file)) {
|
||||
if (Exists(file))
|
||||
sftpChannel.rm(file.full_name);
|
||||
}
|
||||
}
|
||||
//с проверкой.
|
||||
public boolean tryGetSingleFileWithMaxSize(RemoteFile src, File dst, int maxSize) throws Exception {
|
||||
@@ -326,7 +329,7 @@ public class UserConnection {
|
||||
}
|
||||
//--
|
||||
public void SynchronizeProjectSubDirsR(db_project_info project, File local_dir, RemoteFile remote_dir, boolean data) throws Exception {
|
||||
// ShowMessage2("синхронизация: " + local_dir.getName());
|
||||
// ShowMessage2("синхронизация: " + local_dir.getName());
|
||||
Vector<File> local_subdirs = project.getSubdirectoriesSimple(local_dir);
|
||||
Vector<File> local_files = project.getActiveFilesForSynchronization(local_dir, data);
|
||||
//------------------------------------------------------------------------
|
||||
@@ -354,12 +357,12 @@ public class UserConnection {
|
||||
RemoteFile rf = null;
|
||||
if (!remote_files.containsKey(lf.getName())) {
|
||||
rf = new RemoteFile(remote_dir.full_name, lf.getName());
|
||||
// ShowMessage2(lf.getName());
|
||||
// ShowMessage2(lf.getName());
|
||||
putSingleFile(lf, rf);
|
||||
} else {
|
||||
rf = remote_files.get(lf.getName());
|
||||
if (lf.lastModified() > rf.updateTime) {
|
||||
// ShowMessage2(lf.getName());
|
||||
// ShowMessage2(lf.getName());
|
||||
putSingleFile(lf, rf);
|
||||
}
|
||||
}
|
||||
@@ -386,7 +389,6 @@ public class UserConnection {
|
||||
for (RemoteFile file : to_delete)
|
||||
sftpChannel.rm(file.full_name);
|
||||
}
|
||||
|
||||
public void Command(String... commands) throws Exception {
|
||||
if (commands.length > 0) {
|
||||
String command = String.join("\n", commands);
|
||||
@@ -397,10 +399,25 @@ public class UserConnection {
|
||||
execChannel.setCommand(command);
|
||||
execChannel.connect();
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(execChannel.getInputStream()));
|
||||
while (in.readLine() != null) ;
|
||||
String line = null;
|
||||
while ((line = in.readLine()) != null) {
|
||||
System.out.println(Utils.Brackets(line));
|
||||
}
|
||||
}
|
||||
execChannel.disconnect();
|
||||
}
|
||||
public void CommandNoRead(String... commands) throws Exception {
|
||||
if (commands.length > 0) {
|
||||
String command = String.join("\n", commands);
|
||||
execChannel = (ChannelExec) session.openChannel("exec");
|
||||
execChannel.setErrStream(System.err);
|
||||
execChannel.setCommand(command);
|
||||
execChannel.connect();
|
||||
execChannel.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public String CommandWithAnswer(char end, String... commands) throws Exception {
|
||||
String output = "";
|
||||
if (commands.length > 0) {
|
||||
@@ -421,7 +438,10 @@ public class UserConnection {
|
||||
// System.out.println(Utils.Brackets(output));
|
||||
return output;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
public void copy(RemoteFile src, RemoteFile dst) throws Exception {
|
||||
ShellCommand("cp " + Utils.DQuotes(src.full_name) + " " + Utils.DQuotes(dst.full_name));
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user