hudson.FilePath.installIfNecessaryFrom()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(14.7k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中hudson.FilePath.installIfNecessaryFrom()方法的一些代码示例,展示了FilePath.installIfNecessaryFrom()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FilePath.installIfNecessaryFrom()方法的具体详情如下:
包路径:hudson.FilePath
类名称:FilePath
方法名:installIfNecessaryFrom

FilePath.installIfNecessaryFrom介绍

[英]Given a tgz/zip file, extracts it to the given target directory, if necessary.

This method is a convenience method designed for installing a binary package to a location that supports upgrade and downgrade. Specifically,

  • If the target directory doesn't exist #mkdirs().
  • The timestamp of the .tgz file is left in the installation directory upon extraction.
  • If the timestamp left in the directory doesn't match with the timestamp of the current archive file, the directory contents will be discarded and the archive file will be re-extracted.
  • If the connection is refused but the target directory already exists, it is left alone.
    [中]

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Given a tgz/zip file, extracts it to the given target directory, if necessary.
 *
 * <p>
 * This method is a convenience method designed for installing a binary package to a location
 * that supports upgrade and downgrade. Specifically,
 *
 * <ul>
 * <li>If the target directory doesn't exist {@linkplain #mkdirs() it will be created}.
 * <li>The timestamp of the archive is left in the installation directory upon extraction.
 * <li>If the timestamp left in the directory does not match the timestamp of the current archive file,
 *     the directory contents will be discarded and the archive file will be re-extracted.
 * <li>If the connection is refused but the target directory already exists, it is left alone.
 * </ul>
 *
 * @param archive
 *      The resource that represents the tgz/zip file. This URL must support the {@code Last-Modified} header.
 *      (For example, you could use {@link ClassLoader#getResource}.)
 * @param listener
 *      If non-null, a message will be printed to this listener once this method decides to
 *      extract an archive, or if there is any issue.
 * @param message a message to be printed in case extraction will proceed.
 * @return
 *      true if the archive was extracted. false if the extraction was skipped because the target directory
 *      was considered up to date.
 * @since 1.299
 */
public boolean installIfNecessaryFrom(@Nonnull URL archive, @CheckForNull TaskListener listener, @Nonnull String message) throws IOException, InterruptedException {
  return installIfNecessaryFrom(archive, listener, message, MAX_REDIRECTS);
}

代码示例来源:origin: jenkinsci/jenkins

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath dir = preferredLocation(tool, node);
  if (dir.installIfNecessaryFrom(new URL(url), log, "Unpacking " + url + " to " + dir + " on " + node.getDisplayName())) {
    dir.act(new ChmodRecAPlusX());
  }
  if (subdir == null) {
    return dir;
  } else {
    return dir.child(subdir);
  }
}

代码示例来源:origin: jenkinsci/jenkins

String location = httpCon.getHeaderField("Location");
  listener.getLogger().println("Following redirect " + archive.toExternalForm() + " -> " + location);
  return installIfNecessaryFrom(getUrlFactory().newURL(location), listener, message, maxRedirects - 1);
} else {
  listener.getLogger().println("Skipping installation of " + archive + " to " + remote + " due to too many redirects.");

代码示例来源:origin: jenkinsci/jenkins

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath expected = preferredLocation(tool, node);
  Installable inst = getInstallable();
  if(inst==null) {
    log.getLogger().println("Invalid tool ID "+id);
    return expected;
  }
  if (inst instanceof NodeSpecific) {
    inst = (Installable) ((NodeSpecific) inst).forNode(node, log);
  }
  if(isUpToDate(expected,inst))
    return expected;
  if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
    expected.child(".timestamp").delete(); // we don't use the timestamp
    FilePath base = findPullUpDirectory(expected);
    if(base!=null && base!=expected)
      base.moveAllChildrenTo(expected);
    // leave a record for the next up-to-date check
    expected.child(".installedFrom").write(inst.url,"UTF-8");
    expected.act(new ZipExtractionInstaller.ChmodRecAPlusX());
  }
  return expected;
}

代码示例来源:origin: jenkinsci/android-emulator-plugin

public Boolean invoke(File f, VirtualChannel channel)
    throws InterruptedException, IOException {
  String msg = Messages.DOWNLOADING_SDK_FROM(downloadUrl);
  return toolsSubdir.installIfNecessaryFrom(downloadUrl, listener, msg);
}
private static final long serialVersionUID = 1L;

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Given a tgz/zip file, extracts it to the given target directory, if necessary.
 *
 * <p>
 * This method is a convenience method designed for installing a binary package to a location
 * that supports upgrade and downgrade. Specifically,
 *
 * <ul>
 * <li>If the target directory doesn't exist {@linkplain #mkdirs() it will be created}.
 * <li>The timestamp of the archive is left in the installation directory upon extraction.
 * <li>If the timestamp left in the directory does not match the timestamp of the current archive file,
 *     the directory contents will be discarded and the archive file will be re-extracted.
 * <li>If the connection is refused but the target directory already exists, it is left alone.
 * </ul>
 *
 * @param archive
 *      The resource that represents the tgz/zip file. This URL must support the {@code Last-Modified} header.
 *      (For example, you could use {@link ClassLoader#getResource}.)
 * @param listener
 *      If non-null, a message will be printed to this listener once this method decides to
 *      extract an archive, or if there is any issue.
 * @param message a message to be printed in case extraction will proceed.
 * @return
 *      true if the archive was extracted. false if the extraction was skipped because the target directory
 *      was considered up to date.
 * @since 1.299
 */
public boolean installIfNecessaryFrom(@Nonnull URL archive, @CheckForNull TaskListener listener, @Nonnull String message) throws IOException, InterruptedException {
  return installIfNecessaryFrom(archive, listener, message, MAX_REDIRECTS);
}

代码示例来源:origin: org.jvnet.hudson.main/maven3-plugin

private boolean install(final FilePath root, TaskListener listener) throws IOException, InterruptedException {
  assert root != null;
  if (listener == null) {
    listener = TaskListener.NULL;
  }
  String resource = BUNDLE_ARCHIVE;
  URL url = SlaveBundleInstaller.class.getResource(resource);
  if (url == null) {
    throw new RuntimeException("Unable to install Maven 3 slave " +
        "bundle; missing resource: " + resource);
  }
  FilePath dir = new FilePath(root, BASE_PATH);
  dir.mkdirs();
  log.debug("Maven slave bundle installation directory: {}", dir);
  return dir.installIfNecessaryFrom(url, listener, "Installing: " + resource);
}

代码示例来源:origin: hudson/hudson-2.x

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath dir = preferredLocation(tool, node);
  if (dir.installIfNecessaryFrom(new URL(url), log, "Unpacking " + url + " to " + dir + " on " + node.getDisplayName())) {
    dir.act(new ChmodRecAPlusX());
  }
  if (subdir == null) {
    return dir;
  } else {
    return dir.child(subdir);
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath dir = preferredLocation(tool, node);
  if (dir.installIfNecessaryFrom(new URL(url), log, "Unpacking " + url + " to " + dir + " on " + node.getDisplayName())) {
    dir.act(new ChmodRecAPlusX());
  }
  if (subdir == null) {
    return dir;
  } else {
    return dir.child(subdir);
  }
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath dir = preferredLocation(tool, node);
  if (dir.installIfNecessaryFrom(new URL(url), log, "Unpacking " + url + " to " + dir + " on " + node.getDisplayName())) {
    dir.act(new ChmodRecAPlusX());
  }
  if (subdir == null) {
    return dir;
  } else {
    return dir.child(subdir);
  }
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath dir = preferredLocation(tool, node);
  if (dir.installIfNecessaryFrom(new URL(url), log, "Unpacking " + url + " to " + dir + " on " + node.getDisplayName())) {
    dir.act(new ChmodRecAPlusX());
  }
  if (subdir == null) {
    return dir;
  } else {
    return dir.child(subdir);
  }
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath dir = preferredLocation(tool, node);
  if (dir.installIfNecessaryFrom(new URL(url), log, "Unpacking " + url + " to " + dir + " on " + node.getDisplayName())) {
    dir.act(new ChmodRecAPlusX());
  }
  if (subdir == null) {
    return dir;
  } else {
    return dir.child(subdir);
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

String location = httpCon.getHeaderField("Location");
  listener.getLogger().println("Following redirect " + archive.toExternalForm() + " -> " + location);
  return installIfNecessaryFrom(getUrlFactory().newURL(location), listener, message, maxRedirects - 1);
} else {
  listener.getLogger().println("Skipping installation of " + archive + " to " + remote + " due to too many redirects.");

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath expected = preferredLocation(tool, node);
  Installable inst = getInstallable();
  if(inst==null) {
    log.getLogger().println("Invalid tool ID "+id);
    return expected;
  }
  if(isUpToDate(expected,inst))
    return expected;
  if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
    expected.child(".timestamp").delete(); // we don't use the timestamp
    FilePath base = findPullUpDirectory(expected);
    if(base!=null && base!=expected)
      base.moveAllChildrenTo(expected);
    // leave a record for the next up-to-date check
    expected.child(".installedFrom").write(inst.url,"UTF-8");
    expected.act(new ZipExtractionInstaller.ChmodRecAPlusX());
  }
  return expected;
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath expected = preferredLocation(tool, node);
  Installable inst = getInstallable();
  if(inst==null) {
    log.getLogger().println("Invalid tool ID "+id);
    return expected;
  }
  if(isUpToDate(expected,inst))
    return expected;
  if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
    expected.child(".timestamp").delete(); // we don't use the timestamp
    FilePath base = findPullUpDirectory(expected);
    if(base!=null && base!=expected)
      base.moveAllChildrenTo(expected);
    // leave a record for the next up-to-date check
    expected.child(".installedFrom").write(inst.url,"UTF-8");
    expected.act(new ZipExtractionInstaller.ChmodRecAPlusX());
  }
  return expected;
}

代码示例来源:origin: hudson/hudson-2.x

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath expected = preferredLocation(tool, node);
  Installable inst = getInstallable();
  if(inst==null) {
    log.getLogger().println("Invalid tool ID "+id);
    return expected;
  }
  if(isUpToDate(expected,inst))
    return expected;
  if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
    expected.child(".timestamp").delete(); // we don't use the timestamp
    FilePath base = findPullUpDirectory(expected);
    if(base!=null && base!=expected)
      base.moveAllChildrenTo(expected);
    // leave a record for the next up-to-date check
    expected.child(".installedFrom").write(inst.url,"UTF-8");
    expected.act(new ZipExtractionInstaller.ChmodRecAPlusX());
  }
  return expected;
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath expected = preferredLocation(tool, node);
  Installable inst = getInstallable();
  if (inst == null) {
    log.getLogger().println("Invalid tool ID " + id);
    return expected;
  }
  if (isUpToDate(expected, inst)) {
    return expected;
  }
  if (expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
    expected.child(".timestamp").delete(); // we don't use the timestamp
    FilePath base = findPullUpDirectory(expected);
    if (base != null && base != expected) {
      base.moveAllChildrenTo(expected);
    }
    // leave a record for the next up-to-date check
    expected.child(".installedFrom").write(inst.url, "UTF-8");
    expected.act(new ZipExtractionInstaller.ChmodRecAPlusX());
  }
  return expected;
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
  FilePath expected = preferredLocation(tool, node);
  Installable inst = getInstallable();
  if(inst==null) {
    log.getLogger().println("Invalid tool ID "+id);
    return expected;
  }
  if (inst instanceof NodeSpecific) {
    inst = (Installable) ((NodeSpecific) inst).forNode(node, log);
  }
  if(isUpToDate(expected,inst))
    return expected;
  if(expected.installIfNecessaryFrom(new URL(inst.url), log, "Unpacking " + inst.url + " to " + expected + " on " + node.getDisplayName())) {
    expected.child(".timestamp").delete(); // we don't use the timestamp
    FilePath base = findPullUpDirectory(expected);
    if(base!=null && base!=expected)
      base.moveAllChildrenTo(expected);
    // leave a record for the next up-to-date check
    expected.child(".installedFrom").write(inst.url,"UTF-8");
    expected.act(new ZipExtractionInstaller.ChmodRecAPlusX());
  }
  return expected;
}

代码示例来源:origin: jenkinsci/golang-plugin

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException,
    InterruptedException {
  FilePath expectedPath = preferredLocation(tool, node);
  Installable installable;
  try {
    installable = getInstallable(node);
  } catch (InstallationFailedException e) {
    throw new InstallationFailedException(Messages.CouldNotInstallGo(e.getMessage()));
  }
  if (installable == null) {
    log.getLogger().println(Messages.UnrecognisedReleaseId(id));
    return expectedPath;
  }
  if (isUpToDate(expectedPath, installable)) {
    return expectedPath;
  }
  String message = Messages.InstallingGoOnNode(installable.url, expectedPath, node.getDisplayName());
  if (expectedPath.installIfNecessaryFrom(new URL(installable.url), log, message)) {
    expectedPath.child(".timestamp").delete(); // we don't use the timestamp
    FilePath base = findPullUpDirectory(expectedPath);
    if (base != null && base != expectedPath)
      base.moveAllChildrenTo(expectedPath);
    // leave a record for the next up-to-date check
    expectedPath.child(".installedFrom").write(installable.url, "UTF-8");
  }
  return expectedPath;
}

代码示例来源:origin: jenkinsci/docker-commons-plugin

install.installIfNecessaryFrom(tgz, listener, "Unpacking " + tgz + " to " + install + " on " + node.getDisplayName());

相关文章