List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:org.jenkinsci.plugins.workflow.steps.scm.GitStepTest.java
@Test public void basicCloneAndUpdate() throws Exception { WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo"); r.createOnlineSlave(Label.get("remote")); p.setDefinition(/*from w ww . j a va2 s. c o m*/ new CpsFlowDefinition("node('remote') {\n" + " ws {\n" + " git(url: $/" + sampleRepo + "/$, poll: false, changelog: false)\n" + " archive '**'\n" + " }\n" + "}")); WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); r.assertLogContains("Cloning the remote Git repository", b); // GitSCM.retrieveChanges assertTrue(b.getArtifactManager().root().child("file").isFile()); FileUtils.touch(new File(sampleRepo, "nextfile")); git(sampleRepo, "add", "nextfile"); git(sampleRepo, "commit", "--message=next"); b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); r.assertLogContains("Fetching changes from the remote Git repository", b); // GitSCM.retrieveChanges assertTrue(b.getArtifactManager().root().child("nextfile").isFile()); }
From source file:org.jenkinsci.plugins.workflow.steps.scm.GitStepTest.java
@Test public void changelogAndPolling() throws Exception { WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo"); p.addTrigger(new SCMTrigger("")); // no schedule, use notifyCommit only r.createOnlineSlave(Label.get("remote")); p.setDefinition(new CpsFlowDefinition( "node('remote') {\n" + " ws {\n" + " git($/" + sampleRepo + "/$)\n" + " }\n" + "}")); WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); r.assertLogContains("Cloning the remote Git repository", b); FileUtils.touch(new File(sampleRepo, "nextfile")); git(sampleRepo, "add", "nextfile"); git(sampleRepo, "commit", "--message=next"); System.out/* w w w. jav a 2 s . co m*/ .println( r.createWebClient() .goTo("git/notifyCommit?url=" + URLEncoder.encode(sampleRepo.getAbsolutePath(), "UTF-8"), "text/plain") .getWebResponse().getContentAsString()); r.waitUntilNoActivity(); b = p.getLastBuild(); assertEquals(2, b.number); r.assertLogContains("Fetching changes from the remote Git repository", b); List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b.getChangeSets(); assertEquals(1, changeSets.size()); ChangeLogSet<? extends ChangeLogSet.Entry> changeSet = changeSets.get(0); assertEquals(b, changeSet.getRun()); assertEquals("git", changeSet.getKind()); Iterator<? extends ChangeLogSet.Entry> iterator = changeSet.iterator(); assertTrue(iterator.hasNext()); ChangeLogSet.Entry entry = iterator.next(); assertEquals("[nextfile]", entry.getAffectedPaths().toString()); assertFalse(iterator.hasNext()); }
From source file:org.jenkinsci.plugins.workflow.steps.scm.GitStepTest.java
@Test public void multipleSCMs() throws Exception { File otherRepo = tmp.newFolder(); git(otherRepo, "init"); FileUtils.touch(new File(otherRepo, "otherfile")); git(otherRepo, "add", "otherfile"); git(otherRepo, "commit", "--message=init"); WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo"); p.addTrigger(new SCMTrigger("")); p.setQuietPeriod(3); // so it only does one build p.setDefinition(//w ww. j av a 2s.c o m new CpsFlowDefinition("node {\n" + " ws {\n" + " dir('main') {\n" + " git($/" + sampleRepo + "/$)\n" + " }\n" + " dir('other') {\n" + " git($/" + otherRepo + "/$)\n" + " }\n" + " archive '**'\n" + " }\n" + "}")); WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); VirtualFile artifacts = b.getArtifactManager().root(); assertTrue(artifacts.child("main/file").isFile()); assertTrue(artifacts.child("other/otherfile").isFile()); FileUtils.touch(new File(sampleRepo, "file2")); git(sampleRepo, "add", "file2"); git(sampleRepo, "commit", "--message=file2"); FileUtils.touch(new File(otherRepo, "otherfile2")); git(otherRepo, "add", "otherfile2"); git(otherRepo, "commit", "--message=otherfile2"); System.out .println( r.createWebClient() .goTo("git/notifyCommit?url=" + URLEncoder.encode(sampleRepo.getAbsolutePath(), "UTF-8"), "text/plain") .getWebResponse().getContentAsString()); System.out .println( r.createWebClient() .goTo("git/notifyCommit?url=" + URLEncoder.encode(otherRepo.getAbsolutePath(), "UTF-8"), "text/plain") .getWebResponse().getContentAsString()); r.waitUntilNoActivity(); b = p.getLastBuild(); assertEquals(2, b.number); artifacts = b.getArtifactManager().root(); assertTrue(artifacts.child("main/file2").isFile()); assertTrue(artifacts.child("other/otherfile2").isFile()); Iterator<? extends SCM> scms = p.getSCMs().iterator(); assertTrue(scms.hasNext()); assertEquals(sampleRepo.getAbsolutePath(), ((GitSCM) scms.next()).getRepositories().get(0).getURIs().get(0).toString()); assertTrue(scms.hasNext()); assertEquals(otherRepo.getAbsolutePath(), ((GitSCM) scms.next()).getRepositories().get(0).getURIs().get(0).toString()); assertFalse(scms.hasNext()); List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b.getChangeSets(); assertEquals(2, changeSets.size()); ChangeLogSet<? extends ChangeLogSet.Entry> changeSet = changeSets.get(0); assertEquals(b, changeSet.getRun()); assertEquals("git", changeSet.getKind()); Iterator<? extends ChangeLogSet.Entry> iterator = changeSet.iterator(); assertTrue(iterator.hasNext()); ChangeLogSet.Entry entry = iterator.next(); assertEquals("[file2]", entry.getAffectedPaths().toString()); assertFalse(iterator.hasNext()); changeSet = changeSets.get(1); iterator = changeSet.iterator(); assertTrue(iterator.hasNext()); entry = iterator.next(); assertEquals("[otherfile2]", entry.getAffectedPaths().toString()); assertFalse(iterator.hasNext()); }
From source file:org.jenkinsci.plugins.workflow.steps.scm.SubversionStepTest.java
@Test public void multipleSCMs() throws Exception { File sampleRepo = tmp.newFolder(); URI u = sampleRepo.toURI();/*from w w w. j a va2 s. c o m*/ String sampleRepoU = new URI(u.getScheme(), "", u.getPath(), u.getFragment()).toString(); // TODO SVN rejects File.toUri syntax (requires blank authority field) run(sampleRepo, "svnadmin", "create", "--compatible-version=1.5", sampleRepo.getAbsolutePath()); File sampleWc = tmp.newFolder(); run(sampleWc, "svn", "co", sampleRepoU, "."); FileUtils.touch(new File(sampleWc, "file")); run(sampleWc, "svn", "add", "file"); run(sampleWc, "svn", "commit", "--message=init"); File otherRepo = tmp.newFolder(); u = otherRepo.toURI(); String otherRepoU = new URI(u.getScheme(), "", u.getPath(), u.getFragment()).toString(); run(otherRepo, "svnadmin", "create", "--compatible-version=1.5", otherRepo.getAbsolutePath()); File otherWc = tmp.newFolder(); run(otherWc, "svn", "co", otherRepoU, "."); FileUtils.touch(new File(otherWc, "otherfile")); run(otherWc, "svn", "add", "otherfile"); run(otherWc, "svn", "commit", "--message=init"); WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "demo"); p.addTrigger(new SCMTrigger("")); p.setQuietPeriod(3); // so it only does one build p.setDefinition(new CpsFlowDefinition( "node {\n" + " ws {\n" + " dir('main') {\n" + " svn(url: '" + sampleRepoU + "')\n" + " }\n" + " dir('other') {\n" + " svn(url: '" + otherRepoU + "')\n" + " }\n" + " archive '**'\n" + " }\n" + "}")); WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); VirtualFile artifacts = b.getArtifactManager().root(); assertTrue(artifacts.child("main/file").isFile()); assertTrue(artifacts.child("other/otherfile").isFile()); FileUtils.touch(new File(sampleWc, "file2")); run(sampleWc, "svn", "add", "file2"); run(sampleWc, "svn", "commit", "--message=+file2"); FileUtils.touch(new File(otherWc, "otherfile2")); run(otherWc, "svn", "add", "otherfile2"); run(otherWc, "svn", "commit", "--message=+otherfile2"); notifyCommit(uuid(sampleRepoU), "file2"); notifyCommit(uuid(otherRepoU), "otherfile2"); r.waitUntilNoActivity(); b = p.getLastBuild(); assertEquals(2, b.number); artifacts = b.getArtifactManager().root(); assertTrue(artifacts.child("main/file2").isFile()); assertTrue(artifacts.child("other/otherfile2").isFile()); Iterator<? extends SCM> scms = p.getSCMs().iterator(); assertTrue(scms.hasNext()); assertEquals(sampleRepoU.replaceFirst("/$", ""), ((SubversionSCM) scms.next()).getLocations()[0].getURL()); assertTrue(scms.hasNext()); assertEquals(otherRepoU.replaceFirst("/$", ""), ((SubversionSCM) scms.next()).getLocations()[0].getURL()); assertFalse(scms.hasNext()); List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b.getChangeSets(); assertEquals(2, changeSets.size()); ChangeLogSet<? extends ChangeLogSet.Entry> changeSet = changeSets.get(0); assertEquals(b, changeSet.getRun()); assertEquals("svn", changeSet.getKind()); Iterator<? extends ChangeLogSet.Entry> iterator = changeSet.iterator(); assertTrue(iterator.hasNext()); ChangeLogSet.Entry entry = iterator.next(); assertEquals("[/file2]", entry.getAffectedPaths().toString()); assertFalse(iterator.hasNext()); changeSet = changeSets.get(1); iterator = changeSet.iterator(); assertTrue(iterator.hasNext()); entry = iterator.next(); assertEquals("[/otherfile2]", entry.getAffectedPaths().toString()); assertFalse(iterator.hasNext()); }
From source file:org.jenkinsci.test.acceptance.utils.pluginreporter.TextFileExercisedPluginReporter.java
private TextFileExercisedPluginReporter() { file = new File(System.getProperty("basedir") + "/target/exercised-plugins.properties"); if (file.exists()) { LOGGER.info("Deleting " + file.getAbsolutePath()); file.delete();/*from www . j a v a 2 s.co m*/ } try { FileUtils.touch(file); } catch (IOException e) { LOGGER.error(e.getMessage()); return; } }
From source file:org.jeo.data.DirectoryRepositoryTest.java
@Before public void setUp() throws Exception { File dir = Tests.newTmpDir("dir", "repo"); FileUtils.touch(new File(dir, "foo.json")); FileUtils.touch(new File(dir, "bar.json")); repo = new DirectoryRepository(dir); }
From source file:org.jeo.data.DirectoryRepositoryTest.java
@Test public void testMetaFile() throws Exception { FileUtils.touch(new File(repo.getDirectory(), "baz.foo")); createBazMetaFile();// ww w . j a v a 2 s . co m assertEquals(3, Iterables.size(repo.query(Filters.all()))); assertNotNull(repo.get("baz", Workspace.class)); }
From source file:org.jeo.data.DirectoryRepositoryTest.java
@Test public void testStyles() throws Exception { final Driver<?> d = createNiceMock(Driver.class); expect(d.getName()).andReturn("css").anyTimes(); expect(d.getType()).andReturn((Class) Style.class).anyTimes(); replay(d);/* w w w. j av a2s.c o m*/ DirectoryRepository repo2 = new DirectoryRepository(repo.getDirectory(), new DriverRegistry() { @Override public Iterator<Driver<?>> list() { return (Iterator) Iterators.singletonIterator(d); } }, "css"); FileUtils.touch(new File(repo2.getDirectory(), "baz.css")); assertEquals(1, Iterables.size(repo2.query(Filters.all()))); Iterables.find(repo2.query(Filters.all()), new Predicate<Handle<?>>() { @Override public boolean apply(Handle<?> input) { return "baz".equals(input.getName()) && Style.class.isAssignableFrom(input.getType()); } }); repo2.close(); }
From source file:org.jodconverter.cli.CliConverterTest.java
@Test public void convert_FilenamesToFilenamesWithoutOverwrite_NoTaskExecuted() throws Exception { final File targetFile1 = new File(testFolder.getRoot(), TARGET_FILENAME_1); final File targetFile2 = new File(testFolder.getRoot(), TARGET_FILENAME_2); FileUtils.touch(targetFile1); FileUtils.touch(targetFile2);/* ww w . java 2 s .c o m*/ converter.convert(new String[] { SOURCE_FILE_1.getPath(), SOURCE_FILE_2.getPath() }, new String[] { TARGET_FILENAME_1, TARGET_FILENAME_2 }, testFolder.getRoot().getPath(), false); verify(officeManager, times(0)).execute(isA(LocalConversionTask.class)); FileUtils.deleteQuietly(targetFile1); FileUtils.deleteQuietly(targetFile2); }
From source file:org.jolokia.docker.maven.assembly.MappingTrackArchiverTest.java
@Test public void simple() throws Exception { archiver.setDestFile(new File("target/test-data/maven.tracker")); new File(archiver.getDestFile(), "maven").mkdirs(); File tempFile = File.createTempFile("tracker", "txt"); File destination = new File("target/test-data/maven/test.txt"); org.codehaus.plexus.util.FileUtils.copyFile(tempFile, destination); archiver.addFile(tempFile, "test.txt"); AssemblyFiles files = archiver.getAssemblyFiles(); assertNotNull(files);/*from ww w . j a v a 2s . c o m*/ List<AssemblyFiles.Entry> entries = files.getUpdatedEntriesAndRefresh(); assertEquals(0, entries.size()); Thread.sleep(1000); FileUtils.touch(tempFile); entries = files.getUpdatedEntriesAndRefresh(); assertEquals(1, entries.size()); AssemblyFiles.Entry entry = entries.get(0); assertEquals(tempFile, entry.getSrcFile()); assertEquals(destination, entry.getDestFile()); }