Skip to content

Commit

Permalink
executor packageObject
Browse files Browse the repository at this point in the history
  • Loading branch information
bukarevd committed Feb 4, 2019
1 parent 9f1cc68 commit 51f899a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/main/java/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void getCommandObject(Socket socket) {
}
if (commandsObject instanceof PackageObject) {
System.out.println(((PackageObject) commandsObject).getName());
// ((PackageObject) commandsObject).execute();
((PackageObject) commandsObject).execute();
}
}
socket.close();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/CommandObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void setValue(HashMap<String, String> ValuesHashMap) {
setExec(ValuesHashMap.get("exec"));
}

@Override
public void execute(){
ExecutorCommand executorCommand = new ExecutorCommand();
String str = getExec();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/CommandsObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

abstract public class CommandsObject implements Serializable {
public abstract void setValue(HashMap<String, String> valueHashMap);
public abstract void execute();

}
36 changes: 1 addition & 35 deletions src/main/java/ExecutorCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,6 @@
import java.util.Scanner;

public class ExecutorCommand {
// public void execute(String[] command){
// StringBuilder sb = new StringBuilder();
// try{
// Process proc = new ProcessBuilder(command).start();
// BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
// BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
// OutputStreamWriter output = new OutputStreamWriter(proc.getOutputStream());
// String s;
// while ((s = stdInput.readLine()) != null){
// System.out.println(s);
// if (s.contains("Password:")){
// System.out.println("pass");
// }
// sb.append(s);
// sb.append("\n");
//
// }
//
// while ((s = stdError.readLine()) != null){
// System.out.println(s);
// if (s.contains("Password:")){
// System.out.println("pass");
// }
// sb.append(s);
// sb.append("\n");
// }
//// int i = proc.waitFor();
// // System.out.println(sb.toString());
//// System.out.println(i);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }

public void execute(String[] command) {
InputStreamReader stdInput;
InputStreamReader errInput;
Expand All @@ -62,7 +28,7 @@ public void execute(String[] command) {
tryes++;
}
}
while ((stdBytes = stdInput.read(stdBuffer, 0, 1024)) != -1){
while ((stdBytes = stdInput.read(stdBuffer, 0, 1024)) != -1) {
if (stdBytes == 0) continue;
String stdData = String.valueOf(stdBuffer, 0, stdBytes);
System.out.println(stdData);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/FileObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void setValue(HashMap<String, String> ValuesHashMap) {
setChmod(Integer.parseInt(ValuesHashMap.get("chown")));
}

@Override
public void execute() {
// дописать проверку на пустоту Getter, установку владельца и прав на файл
ExecutorCommand executorCommand = new ExecutorCommand();
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/PackageObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ public String getName() {
return name;
}

public String getVersion() {
return version;
}

public String getDependence() {
return dependence;
}

public void setVersion(String version) {
this.version = version;
}
Expand Down Expand Up @@ -42,4 +50,18 @@ public void setValue(HashMap<String, String> ValuesHashMap) {
setVersion(ValuesHashMap.get("version"));
setDependence(ValuesHashMap.get("dependence"));
}

@Override
public void execute(){
ExecutorCommand executorCommand = new ExecutorCommand();
String str;
if (getVersion() != null)
str = "sudo -S apt-get install" + getName() + "=" + getVersion();
else
str = "sudo -S apt-get install" + getName();
System.out.println(str);
String[] command = new String[]{"/bin/sh", "-c", str};
executorCommand.execute(command);

}
}

0 comments on commit 51f899a

Please sign in to comment.