congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
StreamTaskListener.<init>
Code IndexAdd Tabnine to your IDE (free)

How to use
hudson.util.StreamTaskListener
constructor

Best Java code snippets using hudson.util.StreamTaskListener.<init> (Showing top 20 results out of 315)

origin: jenkinsci/jenkins

private StreamTaskListener cast(TaskListener listener) {
  if (listener instanceof StreamTaskListener)
    return (StreamTaskListener) listener;
  return new StreamTaskListener(listener.getLogger());
}
origin: jenkinsci/jenkins

public static StreamTaskListener fromStderr() {
  return new StreamTaskListener(System.err,Charset.defaultCharset());
}
origin: jenkinsci/jenkins

public static StreamTaskListener fromStdout() {
  return new StreamTaskListener(System.out,Charset.defaultCharset());
}
origin: jenkinsci/jenkins

  /**
   * Creates one that's backed by a file. 
   */
  public static ListenerAndText forFile(File f, TaskAction context) throws IOException {
    return new ListenerAndText(
      new StreamTaskListener(f),
      new AnnotatedLargeText<TaskAction>(f,Charset.defaultCharset(),false,context)
    );
  }
}
origin: jenkinsci/jenkins

public LogTaskListener(Logger logger, Level level) {
  delegate = new StreamTaskListener(new LogOutputStream(logger, level, new Throwable().getStackTrace()[1]));
}
origin: jenkinsci/jenkins

/**
 * Creates one that's backed by memory.
 */
public static ListenerAndText forMemory(TaskAction context) {
  // StringWriter is synchronized
  ByteBuffer log = new ByteBuffer();
  return new ListenerAndText(
    new StreamTaskListener(log),
    new AnnotatedLargeText<TaskAction>(log,Charset.defaultCharset(),false,context)
  );
}
origin: jenkinsci/jenkins

/**
 * Returns true if the executable exists.
 */
public boolean getExists() {
  try {
    return getExecutable(new LocalLauncher(new StreamTaskListener(new NullStream())))!=null;
  } catch (IOException | InterruptedException e) {
    return false;
  }
}
origin: jenkinsci/jenkins

  return new StreamTaskListener(f, true, null);
} catch (IOException e) {
  throw new Error(e);
origin: jenkinsci/jenkins

  return new StreamTaskListener(f, true, null);
} catch (IOException e) {
  throw new Error(e);
origin: jenkinsci/jenkins

private boolean runPolling() {
  try {
    // to make sure that the log file contains up-to-date text,
    // don't do buffering.
    StreamTaskListener listener = new StreamTaskListener(getLogFile());
    try {
      PrintStream logger = listener.getLogger();
      long start = System.currentTimeMillis();
      logger.println("Started on "+ DateFormat.getDateTimeInstance().format(new Date()));
      boolean result = job().poll(listener).hasChanges();
      logger.println("Done. Took "+ Util.getTimeSpanString(System.currentTimeMillis()-start));
      if(result)
        logger.println("Changes found");
      else
        logger.println("No changes");
      return result;
    } catch (Error | RuntimeException e) {
      Functions.printStackTrace(e, listener.error("Failed to record SCM polling for " + job));
      LOGGER.log(Level.SEVERE,"Failed to record SCM polling for "+job,e);
      throw e;
    } finally {
      listener.close();
    }
  } catch (IOException e) {
    LOGGER.log(Level.SEVERE,"Failed to record SCM polling for "+job,e);
    return false;
  }
}
origin: jenkinsci/jenkins

static void writeSymlink(File cache, String target) throws IOException, InterruptedException {
  LOGGER.log(Level.FINE, "writeSymlink {0} → {1}", new Object[] {cache, target});
  synchronized (symlinks) {
    symlinks.put(cache, target);
  }
  StringWriter w = new StringWriter();
  StreamTaskListener listener = new StreamTaskListener(w);
  Util.createSymlink(cache.getParentFile(),target,cache.getName(),listener);
  // Avoid calling resolveSymlink on a nonexistent file as it will probably throw an IOException:
  if (!exists(cache) || Util.resolveSymlink(cache)==null) {
   // symlink not supported. use a regular file
   AtomicFileWriter cw = new AtomicFileWriter(cache);
   try {
     cw.write(target);
     cw.commit();
   } finally {
     cw.abort();
   }
  }
}
origin: jenkinsci/jenkins

public SlaveComputer(Slave slave) {
  super(slave);
  this.log = new RewindableRotatingFileOutputStream(getLogFile(), 10);
  this.taskListener = new StreamTaskListener(decorate(this.log));
  assert slave.getNumExecutors()!=0 : "Computer created with 0 executors";
}
origin: jenkinsci/jenkins

/**
 * Releases and removes this agent.
 */
public void terminate() throws InterruptedException, IOException {
  final Computer computer = toComputer();
  if (computer != null) {
    computer.recordTermination();
  }
  try {
    // TODO: send the output to somewhere real
    _terminate(new StreamTaskListener(System.out, Charset.defaultCharset()));
  } finally {
    try {
      Jenkins.get().removeNode(this);
    } catch (IOException e) {
      LOGGER.log(Level.WARNING, "Failed to remove "+name,e);
    }
  }
}
origin: jenkinsci/jenkins

@Override
public void restart() throws IOException, InterruptedException {
  Jenkins jenkins = Jenkins.getInstanceOrNull();
  try {
    if (jenkins != null) {
      jenkins.cleanUp();
    }
  } catch (Exception e) {
    LOGGER.log(Level.SEVERE, "Failed to clean up. Restart will continue.", e);
  }
  File me = getHudsonWar();
  File home = me.getParentFile();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  StreamTaskListener task = new StreamTaskListener(baos);
  task.getLogger().println("Restarting a service");
  String exe = System.getenv("WINSW_EXECUTABLE");
  File executable;
  if (exe!=null)   executable = new File(exe);
  else            executable = new File(home, "hudson.exe");
  if (!executable.exists())   executable = new File(home, "jenkins.exe");
  // use restart! to run hudson/jenkins.exe restart in a separate process, so it doesn't kill itself
  int r = new LocalLauncher(task).launch().cmds(executable, "restart!")
      .stdout(task).pwd(home).join();
  if(r!=0)
    throw new IOException(baos.toString());
}

origin: jenkinsci/jenkins

StreamTaskListener task = new StreamTaskListener(baos);
task.getLogger().println("Installing a service");
int r = runElevated(new File(dir, "jenkins.exe"), "install", task, dir);
origin: jenkinsci/jenkins

try (StreamTaskListener listener = new StreamTaskListener(getLogFile())) {
  listener.getLogger().println(
      "Skipping polling on " + DateFormat.getDateTimeInstance().format(new Date())
origin: jenkinsci/jenkins

@Override
public void run() {
  ACL.impersonate(ACL.SYSTEM);
  StreamTaskListener listener = null;
  try {
    listener = new StreamTaskListener(getLogFile());
    try {
      doRun(listener);
    } finally {
      listener.close();
    }
  } catch (IOException ex) {
    if (listener == null) {
      LOGGER.log(Level.SEVERE, "Cannot create listener for " + getName(), ex);
      //TODO: throw IllegalStateException?
    } else {
      LOGGER.log(Level.WARNING, "Cannot close listener for " + getName(), ex);
    }
  }
 }
origin: jenkinsci/jenkins

/**
 * Performs an installation.
 */
private int install(ToolInstallation t, BuildIDs id, AbstractProject p) throws IOException, InterruptedException {
  Run b = p.getBuildByNumber(Integer.parseInt(id.number));
  if (b==null)
    throw new IllegalStateException("No such build: "+id.number);
  Executor exec = b.getExecutor();
  if (exec==null)
    throw new IllegalStateException(b.getFullDisplayName()+" is not building");
  Node node = exec.getOwner().getNode();
  if (node == null) {
    throw new IllegalStateException("The node " + exec.getOwner().getDisplayName() + " has been deleted");
  }
  t = t.translate(node, EnvVars.getRemote(checkChannel()), new StreamTaskListener(stderr));
  stdout.println(t.getHome());
  return 0;
}
origin: jenkinsci/jenkins

@Extension
public static AdministrativeMonitor init() {
  String migrationTarget = SystemProperties.getString(ZFSInstaller.class.getName() + ".migrate");
  if(migrationTarget!=null) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    StreamTaskListener listener = new StreamTaskListener(new ForkOutputStream(System.out, out));
    try {
      if(migrate(listener,migrationTarget)) {
        // completed successfully
        return new MigrationCompleteNotice();
      }
    } catch (Exception e) {
      // if we let any exception from here, it will prevent Hudson from starting.
      Functions.printStackTrace(e, listener.error("Migration failed"));
    }
    // migration failed
    return new MigrationFailedNotice(out);
  }
  // install the monitor if applicable
  ZFSInstaller zi = new ZFSInstaller();
  if(zi.isActivated())
    return zi;
  return null;
}
origin: jenkinsci/jenkins

/**
 * Checks if "java" is in PATH on the given node.
 *
 * <p>
 * If it's not, then the user must specify a configured JDK,
 * so this is often useful for form field validation.
 */
public static boolean isDefaultJDKValid(Node n) {
  try {
    TaskListener listener = new StreamTaskListener(new NullStream());
    Launcher launcher = n.createLauncher(listener);
    return launcher.launch().cmds("java","-fullversion").stdout(listener).join()==0;
  } catch (IOException e) {
    return false;
  } catch (InterruptedException e) {
    return false;
  }
}
hudson.utilStreamTaskListener<init>

Popular methods of StreamTaskListener

  • fromStdout
  • getLogger
  • closeQuietly
    Closes this listener and swallows any exceptions, if raised.
  • error
  • close
  • fatalError
  • _error
  • annotate
  • fromStderr
  • asPath

Popular in Java

  • Updating database using SQL prepared statement
  • notifyDataSetChanged (ArrayAdapter)
  • getApplicationContext (Context)
  • scheduleAtFixedRate (Timer)
  • RandomAccessFile (java.io)
    Allows reading from and writing to a file in a random-access manner. This is different from the uni-
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • Runner (org.openjdk.jmh.runner)
  • 21 Best Atom Packages for 2021
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now