org.openide.windows.OutputWriter Java Examples

The following examples show how to use org.openide.windows.OutputWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TerminalInputOutput.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
    * Stream to write to stuff being output by the process destined for the
    * terminal.
    * @return the writer.
    */
   @Override
   public OutputWriter getOut() {
// Ensure we  don't get two of them due to requests on
// different threads.
synchronized (this) {
    if (outputWriter == null) {
	ValueTask<Writer> task = new Task.GetOut(terminal);
	task.post();
	Writer writer = task.get();
	outputWriter = new TermOutputWriter(terminal, writer);
    }
}
terminal.setOutConnected(true);
       return outputWriter;
   }
 
Example #2
Source File: DebuggerChecker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String classToSourceURL (FileObject fo, OutputWriter logger) {
        ClassPath cp = ClassPath.getClassPath (fo, ClassPath.EXECUTE);
        if (cp == null) {
            return null;
        }
        FileObject root = cp.findOwnerRoot (fo);
        String resourceName = cp.getResourceName (fo, '/', false);
        if (resourceName == null) {
            logger.println("Can not find classpath resource for "+fo+", skipping...");
            return null;
        }
        int i = resourceName.indexOf ('$');
        if (i > 0) {
            resourceName = resourceName.substring (0, i);
        }
        FileObject[] sRoots = SourceForBinaryQuery.findSourceRoots 
            (root.toURL ()).getRoots ();
        ClassPath sourcePath = ClassPathSupport.createClassPath (sRoots);
        FileObject rfo = sourcePath.findResource (resourceName + ".java");
        if (rfo == null) {
            return null;
        }
        return rfo.toURL ().toExternalForm ();
}
 
Example #3
Source File: DebuggerChecker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
protected void doReload(final RunConfig config, final String cname) {
    DebuggerTabMaintainer otm = getOutputTabMaintainer(config.getExecutionName());
    
    InputOutput io = otm.getInputOutput();
    io.select();
    OutputWriter ow = io.getOut();
    try {
        ow.reset();
    } catch (IOException ex) { }
    
    try {
        reload(config.getProject(), ow, cname);
    } finally {
        io.getOut().close();
        otm.markTab();
    }
}
 
Example #4
Source File: JavaHudsonLogger.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public boolean handle(String line, OutputWriter stream) {
    Matcher m = STACK_TRACE.matcher(line);
    if (!m.matches()) {
        return false;
    }
    String pkg = m.group(1);
    String filename = m.group(2);
    String resource = pkg.replace('.', '/') + filename;
    int lineNumber = Integer.parseInt(m.group(3));
    try {
        stream.println(line, new Hyperlink(resource, lineNumber));
        return true;
    } catch (IOException x) {
        LOG.log(Level.INFO, null, x);
    }
    stream.println(line);
    return true;
}
 
Example #5
Source File: SQLExecutionLoggerImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({
    "# {0} - line number", 
    "# {1} - column number", 
    "LBL_LineColumn=Line {0}, column {1}"})
private void printLineColumn(OutputWriter writer, SQLExecutionResult result, boolean hyperlink) {
    int[] errorCoords = result.getRawErrorLocation();
    int errLine = errorCoords[0];
    int errCol = errorCoords[1];
    
    String lineColumn = "  " + LBL_LineColumn(errLine + 1, errCol + 1);

    try {
        if (hyperlink) {
            Hyperlink errLink = new Hyperlink(errLine, errCol);
            writer.println(lineColumn, errLink);
        } else {
            writer.println(lineColumn);
        }
    } catch (IOException e) {
        Exceptions.printStackTrace(e);
    }
}
 
Example #6
Source File: TerminalInputOutput.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
    * {@inheritDoc}
    * <p>
    * Output written to this Writer may appear in a different tab (not
    * supported) or different color (easily doable).
    * <p>
    * I'm hesitant to implement this because traditionally separation of
    * stdout and stderr (as done by {@link Process#getErrorStream}) is a dead
    * end. That is why {@link ProcessBuilder}'s redirectErrorStream property is
    * false by default. It is also why
    * {@link org.netbeans.lib.termsupport.TermExecutor#start} will
    * pre-combine stderr and stdout.
    */
   @Override
   public OutputWriter getErr() {
// Ensure we  don't get two of them due to requests on
// different threads.
synchronized (this) {
    // workaround for #182063: -  UnsupportedOperationException
    if (errWriter == null) {
	ValueTask<Writer> task = new Task.GetOut(terminal);
	task.post();
	Writer writer = task.get();
	errWriter = new TermErrWriter(terminal, writer);
    }
}
terminal.setErrConnected(true);
return errWriter;
   }
 
Example #7
Source File: NbBuildLogger.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override void println(String message, boolean error, OutputListener listener) {
    verifyRunning();
    LOG.log(Level.FINEST, "println: error={0} listener={1} message={2}", new Object[] {error, listener, message});
    OutputWriter ow = error ? err : out;
    try {
        if (listener != null) {
            // Loggers wishing for more control can use getIO and do it themselves.
            boolean important = StandardLogger.isImportant(message);
            ow.println(message, listener, important);
            interestingOutputCallback.run();
        } else {
            ow.println(message);
        }
    } catch (IOException e) {
        LOG.log(Level.WARNING, null, e);
    }
}
 
Example #8
Source File: T3_HardClose_Test.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
    * Hard close, weak close, then stream close
    */
   public void testHardWeakStream() {
System.out.printf("testHardWeakStream()\r");

OutputWriter ow = io.getOut();
ow.println("Hello to Out\r");

io.closeInputOutput();
if (IOVisibility.isSupported(io))
    IOVisibility.setVisible(io, false);
ow.close();

// Additional operations should be no-ops
ow.println("Should go to bitbucket\r");
io.select();
   }
 
Example #9
Source File: T3_HardClose_Test.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
    * Weak close, hard close,then stream close
    */
   public void testWeakHardStream() {
System.out.printf("testWeakHardStream()\r");

OutputWriter ow = io.getOut();
ow.println("Hello to Out\r");

if (IOVisibility.isSupported(io))
    IOVisibility.setVisible(io, false);
io.closeInputOutput();
ow.close();

// Additional operations should be no-ops
ow.println("Should go to bitbucket\r");
io.select();
   }
 
Example #10
Source File: BridgingInputOutputProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public FoldHandle startFold(InputOutput io, OutputWriter writer,
        boolean expanded) {

    if (IOFolding.isSupported(io)) {
        synchronized (foldStack) {
            if (foldStack.isEmpty()) {
                foldStack.addLast(IOFolding.startFold(io, expanded));
            } else {
                foldStack.addLast(foldStack.getLast().startFold(expanded));
            }
            return foldStack.getLast();
        }
    } else {
        return null;
    }
}
 
Example #11
Source File: NativeExecutionService.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void out(final boolean toError, final CharSequence... cs) {
    final Action<Void> action = new Action<Void>() {
        
        @Override
        public Void run() {
            if (descriptor.inputOutput != null) {
                OutputWriter w = toError
                        ? descriptor.inputOutput.getErr()
                        : descriptor.inputOutput.getOut();
                if (w != null) {
                    for (CharSequence c : cs) {
                        w.append(c);
                    }
                }
            }
            return null;
        }
    };
    if (isUnitTestMode()) {
        action.run();
    } else {
        Mutex.EVENT.writeAccess(action);
    }
}
 
Example #12
Source File: ExecutionService.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private InputProcessor createErrProcessor(OutputWriter writer) {
    LineConvertorFactory convertorFactory = descriptor.getErrConvertorFactory();
    InputProcessor errProcessor = null;
    if (descriptor.isErrLineBased()) {
        errProcessor = InputProcessors.bridge(LineProcessors.printing(writer,
                convertorFactory != null ? convertorFactory.newLineConvertor() : null, false));
    } else {
        errProcessor = org.netbeans.api.extexecution.print.InputProcessors.printing(writer,
                convertorFactory != null ? convertorFactory.newLineConvertor() : null, false);
    }

    InputProcessorFactory descriptorErrFactory = descriptor.getErrProcessorFactory();
    if (descriptorErrFactory != null) {
        errProcessor = new BaseInputProcessor(descriptorErrFactory.newInputProcessor(
                new DelegatingInputProcessor(errProcessor)));
    } else {
        InputProcessorFactory2 descriptorErrFactory2 = descriptor.getErrProcessorFactory2();
        if (descriptorErrFactory2 != null) {
            errProcessor = descriptorErrFactory2.newInputProcessor(errProcessor);
        }
    }

    return errProcessor;
}
 
Example #13
Source File: NbIOProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public OutputWriter getStdOut() {
    if (Controller.LOG) {
        Controller.log("NbIOProvider.getStdOut");
    }
    NbIO stdout = (NbIO) getIO(STDOUT, false);
    NbWriter out = stdout.writer();

    NbIO.post(new IOEvent(stdout, IOEvent.CMD_CREATE, true));
    //ensure it is not closed
    if (out != null && out.isClosed()) {
        try {
            out.reset();
            out = (NbWriter) stdout.getOut();
        } catch (IOException e) {
            Exceptions.printStackTrace(e);
            stdout = (NbIO) getIO(STDOUT, true);
            out = (NbWriter) stdout.getOut();
        }
    } else {
        out = (NbWriter) stdout.getOut();
    }
    return out;
}
 
Example #14
Source File: PlainLogger.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public HudsonLogSession createSession(final HudsonJob job) {
        return new HudsonLogSession() {
            final PlainLoggerLogic logic = new PlainLoggerLogic(job, job.getName());
            public boolean handle(String line, OutputWriter stream) {
                OutputListener link = logic.findHyperlink(line);
                if (link != null) {
                    try {
                        stream.println(line, link);
                        return true;
                    } catch (IOException x) {
                        LOG.log(Level.INFO, null, x);
                    }
                }
                stream.println(line);
                return true;
            }
        };
    }
 
Example #15
Source File: RetrieverEngineImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void updateDownloadingInfo(RetrieveEntry rent) {
    OutputWriter opt = getOPOut();
    if(rent.getBaseAddress() != null){
        opt.println(
                NbBundle.getMessage(RetrieverEngineImpl.class,
                "MSG_retrieving_location_found_in",rent.getCurrentAddress(),
                rent.getBaseAddress())); //NOI18N
    }else{
        opt.println(
                NbBundle.getMessage(RetrieverEngineImpl.class,
                "MSG_retrieving_location",rent.getCurrentAddress())); //NOI18N
    }
    opt.flush();
}
 
Example #16
Source File: SQLExecutionLoggerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "# {0} - error code", 
    "# {1} - error sql state", 
    "# {2} - error message", 
    "LBL_WarningCodeStateMessage=[Warning, Error code {0}, SQLState {1}] {2}"})
private void writeSQLWarning(SQLWarning e, OutputWriter writer) {
    writer.println(LBL_WarningCodeStateMessage(
            e.getErrorCode(),
            e.getSQLState(),
            e.getMessage()));
}
 
Example #17
Source File: BridgingInputOutputProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Position getCurrentPosition(InputOutput io, OutputWriter writer) {
    if (IOPosition.isSupported(io)) {
        return IOPosition.currentPosition(io);
    } else {
        return null;
    }
}
 
Example #18
Source File: IOTabsController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void closeOutput() {
    Mutex.EVENT.postWriteRequest(new Runnable() {

        @Override
        public void run() {
            OutputWriter outputWriter = getOutputWriter();
            if (outputWriter != null) {
                outputWriter.close();
            }
        }
    });
}
 
Example #19
Source File: OutputLogger.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void outputLine (final String msg) {
    if(msg == null) return;
    rp.post(new Runnable() {
        @Override
        public void run() {
            OutputWriter out = getLog().getOut();
            out.println(msg);
            out.flush();
        }
    });
}
 
Example #20
Source File: BridgingInputOutputProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void endFold(InputOutput io, OutputWriter writer, FoldHandle fold) {
    synchronized (foldStack) {
        while (!foldStack.isEmpty()) {
            if (foldStack.removeLast() == fold) {
                break;
            }
        }
        fold.silentFinish();
    }
}
 
Example #21
Source File: TestSessionImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private org.netbeans.modules.gsf.testrunner.ui.api.OutputLineHandler map(final OutputLineHandler outputLineHandler) {
    return new org.netbeans.modules.gsf.testrunner.ui.api.OutputLineHandler() {
        @Override
        public void handleLine(OutputWriter out, String text) {
            outputLineHandler.handleLine(out, text);
        }
    };
}
 
Example #22
Source File: BridgingIOProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({"LBL_STDOUT=Standard output"})
@Override
public OutputWriter getStdOut() {
    IO io = providerDelegate.getIO(Bundle.LBL_STDOUT(), false, Lookup.EMPTY);
    S out = providerDelegate.getOut(io);
    return new BridgingOutputWriter(io, out);
}
 
Example #23
Source File: SQLExecutionLoggerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "# {0} - fetchtime in seconds", 
    "LBL_ExecutedFetchTime=Fetching resultset took {0,number,0.###} s.",
    "# {0} - number of affected rows", 
    "LBL_ExecutedRowsAffected={0,choice,0#no rows|1#1 row|1.0<{0,number,integer} rows} affected.",
    "# {0} - execution time",
    "LBL_ExecutedSuccessfullyTime=Executed successfully in {0,number,0.###} s."})
private void logSuccess(SQLExecutionResult result) {
    try (OutputWriter writer = inputOutput.getOut()) {
        startLineColumn(writer, result, LBL_ExecutedSuccessfullyTime(result.getExecutionTime() / 1000d));
        
        List<Integer> updateCounts = result.getUpdateCounts();
        List<Long> fetchTimes = result.getFetchTimes();
        
        for (int i = 0; i < Math.max(updateCounts.size(), fetchTimes.size()); i++) {
            Integer updateCount = updateCounts.size() > i ? updateCounts.get(i) : null;
            Long fetchTime = fetchTimes.size() > i ? fetchTimes.get(i) : null;
            if (updateCount != null && updateCount >= 0) {
                writer.println(LBL_ExecutedRowsAffected(updateCount));
            }
            if (fetchTime != null) {
                writer.println(LBL_ExecutedFetchTime(fetchTime / 1000d));
            }
        }
        writer.println(""); // NOI18N
    }
}
 
Example #24
Source File: SQLExecutionLoggerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
@NbBundle.Messages("LBL_ExecutionCancelled=Execution canceled.")
public void cancel() {
    try (OutputWriter writer = inputOutput.getErr()) {
        writer.println(LBL_ExecutionCancelled());
        writer.println(""); // NOI18N
    }
}
 
Example #25
Source File: OutputWindow.java    From BART with MIT License 5 votes vote down vote up
public static void closeOutputWindowStream(final OutputWriter writer,final OutputWriter writerErr)   {
    try{
        writer.close();
        writerErr.close();
        System.setOut(stout);
        System.setErr(sterr);
    }catch(Exception ex)   {
        ErrorManager.getDefault().notify(ex);
    }
}
 
Example #26
Source File: NbIO.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public OutputWriter getOut() {
    synchronized (this) {
        if (out == null) {
            OutWriter realout = new OutWriter(this);
            out = new NbWriter(realout, this);
        }
        return out;
    }
}
 
Example #27
Source File: InputProcessors.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public PrintingInputProcessor(OutputWriter out, LineConvertor convertor,
        boolean resetEnabled) {

    assert out != null;

    this.out = out;
    this.convertor = convertor;
    this.resetEnabled = resetEnabled;
}
 
Example #28
Source File: NbIOProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Integer startFold(InputOutput io, OutputWriter writer,
        boolean expanded) {
    if (io instanceof NbIO) {
        return ((NbIO) io).startFold(expanded);
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #29
Source File: LineProcessors.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public PrintingLineProcessor(OutputWriter out, LineConvertor convertor, boolean resetEnabled) {
    assert out != null;

    this.out = out;
    this.convertor = convertor;
    this.resetEnabled = resetEnabled;
}
 
Example #30
Source File: SQLExecutionLoggerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void startLineColumn(OutputWriter writer, SQLExecutionResult result, String message) {
    int line = result.getStatementInfo().getStartLine();
    int col = result.getStatementInfo().getStartColumn();
    String text = String.format("[%d:%d] %s", line + 1, col + 1, message);
    Hyperlink link = new Hyperlink(line, col);
    
    try {
        writer.println(text, link);
    } catch (IOException e) {
        Exceptions.printStackTrace(e);
    }
}