Skip to content

Commit

Permalink
Added check of Options and Input in DesktopService
Browse files Browse the repository at this point in the history
  • Loading branch information
dave90 authored and dave90 committed Mar 9, 2017
1 parent ca6e51d commit 7071394
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ public class OptionDescriptor {

public OptionDescriptor() {
options = new String();
separator = new String();
}

public OptionDescriptor(final String initial_option) {
this();
options = new String(initial_option);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,25 @@ public void run() {
public Output startSync(final List<InputProgram> programs, final List<OptionDescriptor> options) {

String option = new String();
for (final OptionDescriptor o : options) {
if (!option.isEmpty())
for (final OptionDescriptor o : options)
if(o!=null){
option += o.getOptions();
option += o.getSeparator();
option += o.getOptions();
}
}else
System.err.println("Warning : wrong "+OptionDescriptor.class.getName());

String files_paths = new String();
String final_program = new String();

for (final InputProgram p : programs) {
final_program += p.getPrograms();
final String program_file = p.getStringOfFilesPaths();
if (program_file != null)
files_paths += program_file;
}
for (final InputProgram p : programs)
if(p!=null){
final_program += p.getPrograms();
final String program_file = p.getStringOfFilesPaths();
if (program_file != null)
files_paths += program_file;
}else
System.err.println("Warning : wrong "+InputProgram.class.getName());


final StringBuffer solverOutput = new StringBuffer();
final StringBuffer solverError = new StringBuffer();
Expand All @@ -92,8 +96,19 @@ public Output startSync(final List<InputProgram> programs, final List<OptionDesc

final long startTime = System.nanoTime();

final Process solver_process = Runtime.getRuntime().exec(exe_path + " " + option + files_paths + load_from_STDIN_option);

StringBuffer stringBuffer = new StringBuffer();
if(exe_path==null)
return new Output("", "Error: executable not found");
stringBuffer.append(exe_path).append(" ").append(option).append(files_paths);
if(!final_program.isEmpty())
stringBuffer.append(" ").append(load_from_STDIN_option);



System.err.println(stringBuffer.toString());
final Process solver_process = Runtime.getRuntime().exec(stringBuffer.toString());


new Thread() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import it.unical.mat.embasp.platforms.desktop.DesktopService;
import it.unical.mat.embasp.specializations.dlv2.DLV2AnswerSets;

/** is an extention of {@link DesktopService} for Clingo 's solver */
/** is an extention of {@link DesktopService} for DLV2 's solver */

public class DLV2DesktopService extends DesktopService {

private final OptionDescriptor competitionOutputOption;

public DLV2DesktopService(final String exe_path) {
super(exe_path);
load_from_STDIN_option = "";
competitionOutputOption = new OptionDescriptor(" --competition-output ");
load_from_STDIN_option = "--stdin";
competitionOutputOption = new OptionDescriptor("--competition-output");
}

@Override
Expand All @@ -28,7 +28,6 @@ protected Output getOutput(final String output, final String error) {

@Override
public void startAsync(final Callback callback, final List<InputProgram> programs, final List<OptionDescriptor> options) {
options.add(competitionOutputOption);
super.startAsync(callback, programs, options);
}

Expand Down

0 comments on commit 7071394

Please sign in to comment.