use of org.netbeans.api.sendopts.CommandException in project blue by kunstmusik.
the class CompileProcessor method process.
@Override
protected void process(Env env, Map<Option, String[]> optionValues) throws CommandException {
String compileFileName = null;
String outFileName = null;
if (optionValues.containsKey(c)) {
compileFileName = optionValues.get(c)[0];
}
if (optionValues.containsKey(o)) {
outFileName = optionValues.get(o)[0];
}
if (compileFileName == null && outFileName == null) {
return;
}
if (compileFileName == null && outFileName != null) {
throw new CommandException(1, ".blue project not given as argument");
}
File in = new File(compileFileName);
if (!in.exists() || !in.isFile()) {
throw new CommandException(1, "Could not open .blue file: " + in.getAbsolutePath());
}
if (outFileName == null) {
outFileName = compileFileName.substring(0, compileFileName.indexOf(".blue")) + ".csd";
}
OpenProjectAction.open(in);
PrintWriter out = null;
try {
BlueData tempData = BlueProjectManager.getInstance().getCurrentBlueData();
out = new PrintWriter(new BufferedWriter(new FileWriter(outFileName)));
CsdRenderResult renderResult = CSDRenderService.getDefault().generateCSD(tempData, 0.0F, -1.0F, false, false);
out.print(renderResult.getCsdText());
out.close();
throw new CommandException(0, compileFileName + " " + BlueSystem.getString("blue.compiledTo") + " " + outFileName);
} catch (IOException | ScoreGenerationException | CommandException e) {
if (out != null) {
out.close();
}
if (e instanceof CommandException) {
throw (CommandException) e;
}
throw new CommandException(1, BlueSystem.getString("message.errorLabel") + " " + BlueSystem.getString("blue.csdCompileError") + e.getMessage());
}
}
use of org.netbeans.api.sendopts.CommandException in project gephi by gephi.
the class CommandLineProcessor method process.
@Override
public void process(Env env, Map values) throws CommandException {
List<String> filenameList = new ArrayList<>();
Object obj = values.get(openOption);
if (obj != null) {
filenameList.addAll(Arrays.asList((String[]) obj));
}
obj = values.get(openOption2);
if (obj != null) {
filenameList.addAll(Arrays.asList((String[]) obj));
}
try {
for (int i = 0; i < filenameList.size(); i++) {
File file = new File(filenameList.get(i));
if (!file.isAbsolute()) {
file = new File(env.getCurrentDirectory(), filenameList.get(i));
}
FileObject fileObject = FileUtil.toFileObject(file);
if (!file.exists()) {
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotFound", file.getName()), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
return;
}
if (fileObject.hasExt(GEPHI_EXTENSION)) {
ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
try {
pc.openProject(file);
} catch (Exception ew) {
Exceptions.printStackTrace(ew);
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
return;
} else {
ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
importController.importFile(fileObject);
} else {
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotSupported"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
}
}
} catch (OutOfMemoryError ex) {
System.gc();
NotifyDescriptor nd = new NotifyDescriptor.Message(MEMORY_ERROR, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
NotifyDescriptor nd = new NotifyDescriptor.Message("CommandLineParsing " + ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
}
}
use of org.netbeans.api.sendopts.CommandException in project Universal-G-Code-Sender by winder.
the class startup method process.
@Override
protected void process(Env env, Map<Option, String[]> maps) throws CommandException {
BackendAPI backend = CentralLookup.getDefault().lookup(BackendAPI.class);
String inputFile = null;
int count = 0;
for (String[] files : maps.values()) {
for (String file : files) {
count++;
inputFile = file;
}
}
if (count == 0 || count > 1) {
throw new CommandException(1, "Too many input files provided.");
}
System.out.println("File to open: " + inputFile);
try {
backend.setGcodeFile(new File(inputFile));
} catch (Exception e) {
throw new CommandException(1, "Unable to open input file: " + e.getMessage());
}
}
Aggregations