Search in sources :

Example 1 with CommandException

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());
    }
}
Also used : BlueData(blue.BlueData) ScoreGenerationException(blue.score.ScoreGenerationException) FileWriter(java.io.FileWriter) CommandException(org.netbeans.api.sendopts.CommandException) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter) BufferedWriter(java.io.BufferedWriter) CsdRenderResult(blue.services.render.CsdRenderResult)

Example 2 with CommandException

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);
    }
}
Also used : ArrayList(java.util.ArrayList) CommandException(org.netbeans.api.sendopts.CommandException) NotifyDescriptor(org.openide.NotifyDescriptor) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) FileObject(org.openide.filesystems.FileObject) File(java.io.File) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 3 with CommandException

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());
    }
}
Also used : BackendAPI(com.willwinder.universalgcodesender.model.BackendAPI) CommandException(org.netbeans.api.sendopts.CommandException) File(java.io.File) CommandException(org.netbeans.api.sendopts.CommandException)

Aggregations

File (java.io.File)3 CommandException (org.netbeans.api.sendopts.CommandException)3 BlueData (blue.BlueData)1 ScoreGenerationException (blue.score.ScoreGenerationException)1 CsdRenderResult (blue.services.render.CsdRenderResult)1 BackendAPI (com.willwinder.universalgcodesender.model.BackendAPI)1 BufferedWriter (java.io.BufferedWriter)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 ImportControllerUI (org.gephi.desktop.importer.api.ImportControllerUI)1 ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)1 NotifyDescriptor (org.openide.NotifyDescriptor)1 FileObject (org.openide.filesystems.FileObject)1