public static String versionString(World world) { // don't use class.getPackage().getSpecificationVersion() because META-INF/META.MF // 1) is not available in Webapps (in particular: dashboard) // 2) is not available in test cases try { return world.resource("stool.version").readString().trim(); } catch (IOException e) { throw new IllegalStateException("cannot determine version", e); } }
public void fileNormal(Node left, Node right, String relative, StringBuilder result) throws IOException { String str; if (!left.exists()) { right.checkFile(); header("###", relative, result); result.append(Strings.indent(right.readString(), "+ ")); } else { str = net.oneandone.sushi.util.Diff.diff(left.readString(), right.readString()); if (str.length() > 0) { header("###", relative, result); result.append(str); } } }
private String file(String name) throws IOException { return dir.getWorld().resource(name).readString(); }
/** @return image ids */ public List<String> imageList(Map<String, String> labels) throws IOException { String filters; Node node; JsonArray array; List<String> result; String id; node = root.join("images/json"); filters = labels.isEmpty()? "" : "&filters=" + enc("{\"label\" : [" + labelsToJsonArray(labels) + "] }"); node = node.getRoot().node(node.getPath(), "all=true" + filters); array = parser.parse(node.readString()).getAsJsonArray(); result = new ArrayList<>(array.size()); for (JsonElement element : array) { id = element.getAsJsonObject().get("Id").getAsString(); id = Strings.removeLeft(id, "sha256:"); result.add(id); } return result; }
/** * @param image may be null * @return container ids */ public List<String> containerList(String image) throws IOException { String filters; Node node; JsonArray array; List<String> result; String id; node = root.join("containers/json"); filters = image == null? "" : "&filters=" + enc("{\"ancestor\" : [\"" + image + "\"] }"); node = node.getRoot().node(node.getPath(), "all=true" + filters); array = parser.parse(node.readString()).getAsJsonArray(); result = new ArrayList<>(array.size()); for (JsonElement element : array) { id = element.getAsJsonObject().get("Id").getAsString(); result.add(id); } return result; }
/** @return stage url or null if not a stage */ public static String probe(FileNode directory) throws IOException { Node artifactGav; directory.checkDirectory(); artifactGav = ArtifactStage.urlFile(directory); if (artifactGav.exists()) { return artifactGav.readString().trim(); } return Scm.checkoutUrlOpt(directory); }
private void downloadFile(String url, FileNode dest) throws IOException { String sha512Expected; String sha512Found; console.info.println("downloading " + url + " ..."); try { dest.getWorld().validNode(url).copyFile(dest); } catch (IOException e) { dest.deleteFileOpt(); throw new IOException("download failed: " + url + "\nAs a work-around, you can download it manually an place it at " + dest.getAbsolute() + "\nDetails: " + e.getMessage(), e); } try { sha512Expected = dest.getWorld().validNode(url + ".sha512").readString(); } catch (IOException e) { dest.deleteFile(); throw new IOException("failed to download " + url + ".sha512", e); } sha512Expected = sha512Expected.substring(0, sha512Expected.indexOf(' ')); try { sha512Found = dest.digest("SHA-512"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e); } if (!sha512Expected.equals(sha512Found)) { dest.deleteFile(); throw new IOException("sha512 digest mismatch: " + sha512Expected + " vs" + sha512Found); } }
/** @param passphrase null to try to load passphrase from ~/.ssh/passphrase file */ public void addDefaultIdentity(String passphrase) throws IOException, JSchException { Node dir; Node file; Node key; dir = getWorld().getHome().join(".ssh"); file = dir.join("passphrase"); if (passphrase == null && file.exists()) { passphrase = file.readString().trim(); } key = dir.join("id_dsa"); if (!key.exists()) { key = dir.join("id_rsa"); if (!key.exists()) { key = dir.join("identity"); } } if (!key.isFile()) { throw new IOException("private key not found: " + key); } addIdentity(key, passphrase); }
src.node.copyFile(dest); } else { dest.writeString(content.apply(src.node.readString(), childVariables));