Refine search
@Override public FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener) { if (StringUtils.isEmpty(path)) { return null; } try { EnvVars env = build.getEnvironment(listener); String targetPath = Util.replaceMacro(this.path, build.getBuildVariableResolver()); targetPath = env.expand(targetPath); if (IOUtils.isAbsolute(targetPath)) { return new FilePath(new File(targetPath)); } else { FilePath mrSettings = build.getModuleRoot().child(targetPath); FilePath wsSettings = build.getWorkspace().child(targetPath); try { if (!wsSettings.exists() && mrSettings.exists()) { wsSettings = mrSettings; } } catch (Exception e) { throw new IllegalStateException("failed to find settings.xml at: " + wsSettings.getRemote()); } return wsSettings; } } catch (Exception e) { throw new IllegalStateException("failed to prepare global settings.xml"); } }
/** * Skips the encoded console note. */ public static void skip(DataInputStream in) throws IOException { byte[] preamble = new byte[PREAMBLE.length]; in.readFully(preamble); if (!Arrays.equals(preamble,PREAMBLE)) return; // not a valid preamble DataInputStream decoded = new DataInputStream(new UnbufferedBase64InputStream(in)); int macSz = - decoded.readInt(); if (macSz > 0) { // new format IOUtils.skip(decoded, macSz); int sz = decoded.readInt(); IOUtils.skip(decoded, sz); } else { // old format int sz = -macSz; IOUtils.skip(decoded, sz); } byte[] postamble = new byte[POSTAMBLE.length]; in.readFully(postamble); }
MavenInformation mavenInformation = getModuleRoot().act( new MavenVersionCallable( mvn.getHome() )); mb.setWorkspace(getModuleRoot().child(m.getRelativePath())); proxies.put(m.getModuleName(), mb.new ProxyImpl2(MavenModuleSetBuild.this,slistener)); FilePath pom = getModuleRoot().child(rootPOM); FilePath parentLoc = getWorkspace().child(rootPOM); if(!pom.exists() && parentLoc.exists()) if (IOUtils.isAbsolute(project.getAlternateSettings())) { margs.add("-s").add(project.getAlternateSettings()); } else {
public static void persistConfiguration(ArtifactoryClientConfiguration configuration, Map<String, String> env, FilePath ws, hudson.Launcher launcher) throws IOException, InterruptedException { FilePath propertiesFile = ws.createTextTempFile("buildInfo", ".properties", ""); ActionableHelper.deleteFilePathOnExit(propertiesFile); configuration.setPropertiesFile(propertiesFile.getRemote()); env.put("BUILDINFO_PROPFILE", propertiesFile.getRemote()); env.put(BuildInfoConfigProperties.PROP_PROPS_FILE, propertiesFile.getRemote()); // Jenkins prefixes env variables with 'env' but we need it clean.. System.setProperty(BuildInfoConfigProperties.PROP_PROPS_FILE, propertiesFile.getRemote()); if (!(getComputer(launcher) instanceof SlaveComputer)) { configuration.persistToPropertiesFile(); } else { try { Properties properties = new Properties(); properties.putAll(configuration.getAllRootConfig()); properties.putAll(configuration.getAllProperties()); OutputStream os = propertiesFile.write(); try { properties.store(os, ""); } finally { IOUtils.closeQuietly(os); } } catch (Exception e) { throw new RuntimeException(e); } } }
/** * Reads the given InputStream as a tar file and extracts it into this directory. * * @param _in * The stream will be closed by this method after it's fully read. * @param compression * The compression method in use. * @since 1.292 */ public void untarFrom(InputStream _in, final TarCompression compression) throws IOException, InterruptedException { try { final InputStream in = new RemoteInputStream(_in); act(new FileCallable<Void>() { public Void invoke(File dir, VirtualChannel channel) throws IOException { readFromTar("input stream",dir, compression.extract(in)); return null; } private static final long serialVersionUID = 1L; }); } finally { IOUtils.closeQuietly(_in); } }
public static void copy(File src, OutputStream out) throws IOException { FileInputStream in = new FileInputStream(src); try { copy(in,out); } finally { closeQuietly(in); } }
/** * Writes {@code config.xml} to the specified output stream. * The user must have at least {@link #EXTENDED_READ}. * If he lacks {@link #CONFIGURE}, then any {@link Secret}s detected will be masked out. */ @Restricted(NoExternalUse.class) public void writeConfigDotXml(OutputStream os) throws IOException { checkPermission(EXTENDED_READ); XmlFile configFile = getConfigFile(); if (hasPermission(CONFIGURE)) { IOUtils.copy(configFile.getFile(), os); } else { String encoding = configFile.sniffEncoding(); String xml = FileUtils.readFileToString(configFile.getFile(), encoding); Matcher matcher = SECRET_PATTERN.matcher(xml); StringBuffer cleanXml = new StringBuffer(); while (matcher.find()) { if (Secret.decrypt(matcher.group(1)) != null) { matcher.appendReplacement(cleanXml, ">********<"); } } matcher.appendTail(cleanXml); org.apache.commons.io.IOUtils.write(cleanXml.toString(), os, encoding); } }
/** * Converts the http entity to string. If entity is null, returns empty string. * @param entity * @return * @throws IOException */ public static String entityToString(HttpEntity entity) throws IOException { if (entity != null) { InputStream is = entity.getContent(); return IOUtils.toString(is, "UTF-8"); } return ""; }
public Void invoke(File f, VirtualChannel channel) throws IOException { f.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(f); Writer w; if (encoding != null) { w = new OutputStreamWriter(fos, encoding); } else { w = new OutputStreamWriter(fos); } try { w.write(content); } finally { IOUtils.closeQuietly(w); } return null; } });
private int readSmbFile(SmbFile f) throws IOException { InputStream in=null; try { in = f.getInputStream(); return Integer.parseInt(IOUtils.toString(in)); } finally { IOUtils.closeQuietly(in); } }
/** * Reads from a tar stream and stores obtained files to the base dir. */ private static void readFromTar(String name, File baseDir, InputStream in) throws IOException { TarInputStream t = new TarInputStream(in); try { TarEntry te; while ((te = t.getNextEntry()) != null) { File f = new File(baseDir,te.getName()); if(te.isDirectory()) { f.mkdirs(); } else { File parent = f.getParentFile(); if (parent != null) parent.mkdirs(); IOUtils.copy(t,f); f.setLastModified(te.getModTime().getTime()); int mode = te.getMode()&0777; if(mode!=0 && !Functions.isWindows()) // be defensive _chmod(f,mode); } } } catch(IOException e) { throw new IOException2("Failed to extract "+name,e); } finally { t.close(); } }
/** * Resolves the given path with respect to given base. If the path represents an absolute path, a file representing * it is returned, otherwise a file representing a path relative to base is returned. * <p> * It would be nice if File#File(File, String) were doing this. * @param base File that represents the parent, may be null if path is absolute * @param path Path of the file, may not be null * @return new File(name) if name represents an absolute path, new File(base, name) otherwise * @see hudson.FilePath#absolutize() */ public static File absolutize(File base, String path) { if (isAbsolute(path)) return new File(path); return new File(base, path); }
/** * {@inheritDoc} */ @NonNull @Override public byte[] getKeyStoreBytes() { try { InputStream inputStream = new FileInputStream(new File(keyStoreFile)); try { return IOUtils.toByteArray(inputStream); } finally { IOUtils.closeQuietly(inputStream); } } catch (IOException e) { LOGGER.log(Level.WARNING, "Could not read private key file " + keyStoreFile, e); return new byte[0]; } }
/** * Reads the given InputStream as a tar file and extracts it into this directory. * * @param _in * The stream will be closed by this method after it's fully read. * @param compression * The compression method in use. * @since 1.292 */ public void untarFrom(InputStream _in, final TarCompression compression) throws IOException, InterruptedException { try { final InputStream in = new RemoteInputStream(_in); act(new FileCallable<Void>() { public Void invoke(File dir, VirtualChannel channel) throws IOException { readFromTar("input stream",dir, compression.extract(in)); return null; } private static final long serialVersionUID = 1L; }); } finally { IOUtils.closeQuietly(_in); } }