Refine search
public static File writeStringToTempFileInFolder(String directoryName, String fileName, String contents) throws Exception { File folderToCreate = tempFiles.createUniqueFolder(directoryName); File fileToCreate = new File(folderToCreate, fileName); folderToCreate.mkdirs(); FileUtils.writeStringToFile(fileToCreate, contents, UTF_8); fileToCreate.deleteOnExit(); folderToCreate.deleteOnExit(); return fileToCreate; }
@Initializer(after=JOB_LOADED) public static void init(Jenkins h) throws IOException { File userContentDir = new File(h.getRootDir(), "userContent"); if(!userContentDir.exists()) { userContentDir.mkdirs(); FileUtils.writeStringToFile(new File(userContentDir,"readme.txt"), Messages.Hudson_USER_CONTENT_README() + "\n"); } } }
private File createScript(String name, String content) throws IOException { File shellScript = new File(subFolder, name); FileUtils.writeStringToFile(shellScript, content, UTF_8); return shellScript; }
public SetupOfAgentPluginsFile withBundledPlugin(String pluginFileName, String pluginFileContent) throws IOException { FileUtils.writeStringToFile(new File(bundledPluginsDir, pluginFileName), pluginFileContent, UTF_8); return this; }
public void close() throws IOException { super.close(); final String javaSource = new String(javaSourceStream.toByteArray(), encoding); final String scalaSource = Converter.instance210().convert(javaSource, new ConversionSettings(false)); FileUtils.writeStringToFile(new File(scalaFileName), scalaSource, encoding); } };
private void createFilesForTestCopyDirectory(final File grandParentDir, final File parentDir, final File childDir) throws Exception { final File childDir2 = new File(parentDir, "child2"); final File grandChildDir = new File(childDir, "grandChild"); final File grandChild2Dir = new File(childDir2, "grandChild2"); final File file1 = new File(grandParentDir, "file1.txt"); final File file2 = new File(parentDir, "file2.txt"); final File file3 = new File(childDir, "file3.txt"); final File file4 = new File(childDir2, "file4.txt"); final File file5 = new File(grandChildDir, "file5.txt"); final File file6 = new File(grandChild2Dir, "file6.txt"); FileUtils.deleteDirectory(grandParentDir); grandChildDir.mkdirs(); grandChild2Dir.mkdirs(); FileUtils.writeStringToFile(file1, "File 1 in grandparent", "UTF8"); FileUtils.writeStringToFile(file2, "File 2 in parent", "UTF8"); FileUtils.writeStringToFile(file3, "File 3 in child", "UTF8"); FileUtils.writeStringToFile(file4, "File 4 in child2", "UTF8"); FileUtils.writeStringToFile(file5, "File 5 in grandChild", "UTF8"); FileUtils.writeStringToFile(file6, "File 6 in grandChild2", "UTF8"); }
private File createZip(String subDirectoryName) throws IOException { File first = new File(artifactDest, "first"); FileUtils.writeStringToFile(first, "First File", UTF_8); File second = new File(artifactDest, subDirectoryName + "/second"); FileUtils.writeStringToFile(second, "Second File", UTF_8); new ZipUtil().zip(artifactDest, zip, 0); return zip; }
private void enableAuthentication() throws IOException { File confFile = new File(repo.projectRepositoryRoot(), "conf/svnserve.conf"); String passwd = "[general]\n" + "anon-access = none\n" + "auth-access = read\n" + "auth-access = write\n" + "password-db = passwd\n"; FileUtils.writeStringToFile(confFile, passwd, UTF_8); }
public File writeFileWithContent(String relativePath, String content) throws Exception { File dest = new File(directory,relativePath); FileUtil.createParentFolderIfNotExist(dest); FileUtils.writeStringToFile(dest, content, UTF_8); return dest; }
@Test public void testWriteStringToFile3() throws Exception { final File file = new File(getTestDirectory(), "write.txt"); FileUtils.writeStringToFile(file, "Hello /u1234", (Charset) null); final byte[] text = "Hello /u1234".getBytes(); TestUtils.assertEqualContent(text, file); }
@Test public void testChecksumCRC32() throws Exception { // create a test file final String text = "Imagination is more important than knowledge - Einstein"; final File file = new File(getTestDirectory(), "checksum-test.txt"); FileUtils.writeStringToFile(file, text, "US-ASCII"); // compute the expected checksum final Checksum expectedChecksum = new CRC32(); expectedChecksum.update(text.getBytes("US-ASCII"), 0, text.length()); final long expectedValue = expectedChecksum.getValue(); // compute the checksum of the file final long resultValue = FileUtils.checksumCRC32(file); assertEquals(expectedValue, resultValue); }
@Test public void testWriteStringToFile1() throws Exception { final File file = new File(getTestDirectory(), "write.txt"); FileUtils.writeStringToFile(file, "Hello /u1234", "UTF8"); final byte[] text = "Hello /u1234".getBytes("UTF8"); TestUtils.assertEqualContent(text, file); }
@Test public void testWriteStringToFile2() throws Exception { final File file = new File(getTestDirectory(), "write.txt"); FileUtils.writeStringToFile(file, "Hello /u1234", (String) null); final byte[] text = "Hello /u1234".getBytes(); TestUtils.assertEqualContent(text, file); }
@Test public void shouldUploadArtifactChecksumForADirectory() throws IOException { String data = "Some text whose checksum can be asserted"; String secondData = "some more"; FileUtils.writeStringToFile(tempFile, data, UTF_8); File anotherFile = new File(artifactFolder, "bond/james_bond/another_file"); FileUtils.writeStringToFile(anotherFile, secondData, UTF_8); when(httpService.upload(eq("http://baseurl/artifacts/dest?attempt=1&buildId=build42"), eq(FileUtils.sizeOfDirectory(artifactFolder)), any(File.class), eq(expectedProperties(data, secondData)))).thenReturn(HttpServletResponse.SC_OK); artifactsRepository.upload(console, artifactFolder, "dest", "build42"); }
public void addUser(String username, String password) throws Exception { enableAuthentication(); File passwdFile = new File(repo.projectRepositoryRoot(), "conf/passwd"); String passwd = String.join(FileUtil.lineSeparator(), Files.readAllLines(passwdFile.toPath())); if (!(passwd.contains("\n[users]\n"))) { passwd = passwd + "\n[users]\n"; } passwd = passwd + String.format("\n%s = %s\n", username, password); FileUtils.writeStringToFile(passwdFile, passwd, UTF_8); }
@Test public void shouldUploadArtifactChecksumForADirectory() throws IOException { String data = "Some text whose checksum can be asserted"; String secondData = "some more"; FileUtils.writeStringToFile(tempFile, data, UTF_8); File anotherFile = new File(artifactFolder, "bond/james_bond/another_file"); FileUtils.writeStringToFile(anotherFile, secondData, UTF_8); when(httpService.upload(any(String.class), eq(FileUtils.sizeOfDirectory(artifactFolder)), any(File.class), eq(expectedProperties(data, secondData)))).thenReturn(HttpServletResponse.SC_OK); goArtifactsManipulatorStub.publish(goPublisher, "dest", artifactFolder, jobIdentifier); }
@Test public void testChecksum() throws Exception { // create a test file final String text = "Imagination is more important than knowledge - Einstein"; final File file = new File(getTestDirectory(), "checksum-test.txt"); FileUtils.writeStringToFile(file, text, "US-ASCII"); // compute the expected checksum final Checksum expectedChecksum = new CRC32(); expectedChecksum.update(text.getBytes("US-ASCII"), 0, text.length()); final long expectedValue = expectedChecksum.getValue(); // compute the checksum of the file final Checksum testChecksum = new CRC32(); final Checksum resultChecksum = FileUtils.checksum(file, testChecksum); final long resultValue = resultChecksum.getValue(); assertSame(testChecksum, resultChecksum); assertEquals(expectedValue, resultValue); }
@Test(expected = FileAccessRightsCheckException.class) public void shouldFailGracefullyWhenBundledFileCannotBeRead() throws Exception { SystemEnvironment systemEnvironmentFail = mock(SystemEnvironment.class); when(systemEnvironmentFail.get(PLUGIN_GO_PROVIDED_PATH)).thenReturn(""); when(systemEnvironmentFail.get(PLUGIN_EXTERNAL_PROVIDED_PATH)).thenReturn(externalPluginsDir.getAbsolutePath()); when(systemEnvironmentFail.get(ALL_PLUGINS_ZIP_PATH)).thenReturn(""); FileUtils.writeStringToFile(new File(externalPluginsDir, "external-task-1.jar"), "External1", UTF_8); PluginsZip pluginsZipFail = new PluginsZip(systemEnvironmentFail, pluginManager); pluginsZipFail.create(); }
@Test(expected = FileAccessRightsCheckException.class) public void shouldFailGracefullyWhenExternalFileCannotBeRead() throws Exception { File bundledPluginsDir = temporaryFolder.newFolder("plugins-bundled-ext"); SystemEnvironment systemEnvironmentFail = mock(SystemEnvironment.class); when(systemEnvironmentFail.get(PLUGIN_GO_PROVIDED_PATH)).thenReturn(bundledPluginsDir.getAbsolutePath()); when(systemEnvironmentFail.get(PLUGIN_EXTERNAL_PROVIDED_PATH)).thenReturn(""); when(systemEnvironmentFail.get(ALL_PLUGINS_ZIP_PATH)).thenReturn(""); FileUtils.writeStringToFile(new File(bundledPluginsDir, "bundled-task-1.jar"), "Bundled1", UTF_8); PluginsZip pluginsZipFail = new PluginsZip(systemEnvironmentFail, pluginManager); pluginsZipFail.create(); }
@Test public void shouldReplaceJettyXmlIfItDoesNotContainCorrespondingJettyVersionNumber() throws IOException { File jettyXml = temporaryFolder.newFile("jetty.xml"); when(systemEnvironment.getJettyConfigFile()).thenReturn(jettyXml); String originalContent = "jetty-v6.2.3\nsome other local changes"; FileUtils.writeStringToFile(jettyXml, originalContent, UTF_8); jetty9Server.replaceJettyXmlIfItBelongsToADifferentVersion(systemEnvironment.getJettyConfigFile()); assertThat(FileUtils.readFileToString(systemEnvironment.getJettyConfigFile(), UTF_8), is(FileUtils.readFileToString(new File(getClass().getResource("config/jetty.xml").getPath()), UTF_8))); }