Example usage for org.apache.commons.io FileUtils touch

List of usage examples for org.apache.commons.io FileUtils touch

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils touch.

Prototype

public static void touch(File file) throws IOException 

Source Link

Document

Implements the same behaviour as the "touch" utility on Unix.

Usage

From source file:org.apache.hyracks.maven.license.SourcePointerResolver.java

private void ensureCDDLSourcesPointer(Collection<Project> projects, ArtifactRepository central,
        ArtifactResolutionRequest request) throws ProjectBuildingException, IOException {
    for (Project p : projects) {
        if (p.getSourcePointer() != null) {
            continue;
        }/*from w w w  .  java 2s  . c  o  m*/
        mojo.getLog().debug("finding sources for artifact: " + p);
        Artifact sourcesArtifact = new DefaultArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(),
                Artifact.SCOPE_COMPILE, "jar", "sources", null);
        MavenProject mavenProject = mojo.resolveDependency(sourcesArtifact);
        sourcesArtifact.setArtifactHandler(mavenProject.getArtifact().getArtifactHandler());
        final ArtifactRepository localRepo = mojo.getSession().getLocalRepository();
        final File marker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".oncentral");
        final File antimarker = new File(localRepo.getBasedir(),
                localRepo.pathOf(sourcesArtifact) + ".nocentral");
        boolean onCentral;
        if (marker.exists() || antimarker.exists()) {
            onCentral = marker.exists();
        } else {
            request.setArtifact(sourcesArtifact);
            ArtifactResolutionResult result = mojo.getArtifactResolver().resolve(request);
            mojo.getLog().debug("result: " + result);
            onCentral = result.isSuccess();
            if (onCentral) {
                FileUtils.touch(marker);
            } else {
                FileUtils.touch(antimarker);
            }
        }
        StringBuilder noticeBuilder = new StringBuilder("You may obtain ");
        noticeBuilder.append(p.getName()).append(" in Source Code form code here:\n");
        if (onCentral) {
            noticeBuilder.append(central.getUrl()).append("/").append(central.pathOf(sourcesArtifact));
        } else {
            mojo.getLog().warn("Unable to find sources in 'central' for " + p
                    + ", falling back to project url: " + p.getUrl());
            noticeBuilder.append(p.getUrl() != null ? p.getUrl() : "MISSING SOURCE POINTER");
        }
        p.setSourcePointer(noticeBuilder.toString());
    }
}

From source file:org.apache.jackrabbit.oak.plugins.blob.datastore.OakFileDataStoreTest.java

@Test
public void testGetAllIdentifiers() throws Exception {
    File testDir = new File("./target", "oak-fds-test");
    FileUtils.touch(new File(testDir, "ab/cd/ef/abcdef"));
    FileUtils.touch(new File(testDir, "bc/de/fg/bcdefg"));
    FileUtils.touch(new File(testDir, "cd/ef/gh/cdefgh"));
    FileUtils.touch(new File(testDir, "c"));

    FileDataStore fds = new OakFileDataStore();
    fds.setPath(testDir.getAbsolutePath());
    fds.init(null);//from  www . j  a  va  2  s . c  o m

    Iterator<DataIdentifier> dis = fds.getAllIdentifiers();
    Set<String> fileNames = Sets.newHashSet(Iterators.transform(dis, new Function<DataIdentifier, String>() {
        @Override
        public String apply(@Nullable DataIdentifier input) {
            return input.toString();
        }
    }));

    Set<String> expectedNames = Sets.newHashSet("abcdef", "bcdefg", "cdefgh");
    assertEquals(expectedNames, fileNames);
    FileUtils.cleanDirectory(testDir);
}

From source file:org.apache.kylin.rest.service.AdminServiceTest.java

@Test
public void testGetPublicConfig() throws IOException {
    //set ../examples/test_metadata/kylin.properties empty
    File file = FileUtils.getFile(LOCALMETA_TEMP_DATA + "kylin.properties");
    FileUtils.deleteQuietly(file);/*from www . j ava2s. co  m*/
    FileUtils.touch(file);
    String path = Thread.currentThread().getContextClassLoader().getResource("kylin.properties").getPath();
    KylinConfig.setKylinConfigThreadLocal(KylinConfig.createInstanceFromUri(path));

    String publicConfig = adminService.getPublicConfig();

    Assert.assertFalse(publicConfig.contains("kylin.metadata.data-model-manager-impl"));
    Assert.assertFalse(publicConfig.contains("kylin.dictionary.use-forest-trie"));
    Assert.assertFalse(publicConfig.contains("kylin.cube.segment-advisor"));
    Assert.assertFalse(publicConfig.contains("kylin.job.use-remote-cli"));
    Assert.assertFalse(publicConfig.contains("kylin.job.scheduler.provider"));
    Assert.assertFalse(publicConfig.contains("kylin.engine.mr.job-jar"));
    Assert.assertFalse(publicConfig.contains("kylin.engine.spark.sanity-check-enabled"));
    Assert.assertFalse(publicConfig.contains("kylin.storage.provider"));
    Assert.assertFalse(publicConfig.contains("kylin.query.convert-create-table-to-with"));
    Assert.assertFalse(publicConfig.contains("kylin.server.init-tasks"));
}

From source file:org.apache.lens.server.session.TestSessionResource.java

/**
 * Test aux jars./*w  ww  . j av  a 2s .  c  o m*/
 *
 * @throws org.apache.lens.server.api.error.LensException the lens exception
 */
@Test(dataProvider = "mediaTypeData")
public void testAuxJars(MediaType mt) throws LensException, IOException, LenServerTestException {
    final WebTarget target = target().path("session");
    final FormDataMultiPart mp = new FormDataMultiPart();
    final LensConf sessionconf = new LensConf();

    String jarFileName = TestResourceFile.TEST_AUX_JAR.getValue();
    File jarFile = new File(jarFileName);
    FileUtils.touch(jarFile);

    try {
        sessionconf.addProperty(LensConfConstants.AUX_JARS, jarFileName);
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), "foo"));
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), "bar"));
        mp.bodyPart(new FormDataBodyPart(
                FormDataContentDisposition.name("sessionconf").fileName("sessionconf").build(), sessionconf,
                mt));

        final LensSessionHandle handle = target.request(mt)
                .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), LensSessionHandle.class);
        Assert.assertNotNull(handle);

        // verify aux jars are loaded
        HiveSessionService service = LensServices.get().getService(SessionService.NAME);
        ClassLoader loader = service.getSession(handle).getSessionState().getConf().getClassLoader();
        boolean found = false;
        for (URL path : ((URLClassLoader) loader).getURLs()) {
            if (path.toString().contains(jarFileName)) {
                found = true;
            }
        }
        Assert.assertTrue(found);

        final WebTarget resourcetarget = target().path("session/resources");
        // list all resources
        StringList listResources = resourcetarget.path("list").queryParam("sessionid", handle).request(mt)
                .get(StringList.class);
        Assert.assertEquals(listResources.getElements().size(), 1);
        Assert.assertTrue(listResources.getElements().get(0).contains(jarFileName));

        // close session
        APIResult result = target.queryParam("sessionid", handle).request(mt).delete(APIResult.class);
        Assert.assertEquals(result.getStatus(), APIResult.Status.SUCCEEDED);
    } finally {
        LensServerTestFileUtils.deleteFile(jarFile);
    }
}

From source file:org.apache.lens.server.TestServerRestart.java

@Test(dataProvider = "mediaTypeData")
public void testServerMustRestartOnManualDeletionOfAddedResources(MediaType mt)
        throws IOException, LensException, LenServerTestException {

    /* Begin: Setup */

    /* Add a resource jar to current working directory */
    File jarFile = new File(TestResourceFile.TEST_RESTART_ON_RESOURCE_MOVE_JAR.getValue());
    FileUtils.touch(jarFile);

    /* Add the created resource jar to lens server */
    LensSessionHandle sessionHandle = LensServerTestUtil.openSession(target(), "foo", "bar", new LensConf(),
            mt);/*w ww.  j av  a2  s  .  c o m*/
    LensServerTestUtil.addResource(target(), sessionHandle, "jar", jarFile.getPath(), mt);

    /* Delete resource jar from current working directory */
    LensServerTestFileUtils.deleteFile(jarFile);

    /* End: Setup */

    /* Verification Steps: server should restart without exceptions */
    restartLensServer();
    HiveSessionService service = LensServices.get().getService(SessionService.NAME);
    service.closeSession(sessionHandle);
}

From source file:org.apache.maven.plugin.surefire.booterclient.ForkConfigurationTest.java

public void testExceptionWhenCurrentDirectoryIsNotRealDirectory()
        throws IOException, SurefireBooterForkException {
    // SUREFIRE-1136
    File baseDir = new File(FileUtils.getTempDirectory(),
            "SUREFIRE-1136-" + RandomStringUtils.randomAlphabetic(3));
    baseDir.mkdirs();/*  w  ww.j av a 2 s .c om*/
    baseDir.deleteOnExit();

    File cwd = new File(baseDir, "cwd.txt");
    FileUtils.touch(cwd);
    cwd.deleteOnExit();

    ForkConfiguration config = getForkConfiguration(null, "java", cwd.getCanonicalFile());

    try {
        config.createCommandLine(Collections.<String>emptyList(), true, false, null, 1);
    } catch (SurefireBooterForkException sbfe) {
        // To handle issue with ~ expansion on Windows
        String absolutePath = cwd.getCanonicalPath();
        assertEquals("WorkingDirectory " + absolutePath + " exists and is not a directory", sbfe.getMessage());
        return;
    }

    fail();
}

From source file:org.apache.maven.plugins.jacorb.JacorbPlugin.java

public void execute() throws MojoExecutionException {
    File timestampFile = new File(getTstamp());
    File schemaFile = new File(getSchema());
    if ((!timestampFile.exists())
            || (timestampFile.exists() && !FileUtils.isFileNewer(timestampFile, schemaFile))) {
        try {/*from w  w  w . j av a  2s.co m*/
            File tstampDir = new File(getTstampDirectory());
            FileUtils.forceMkdir(tstampDir);
            FileUtils.touch(timestampFile);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage());
        }
        ArrayList a = new ArrayList();
        if (!schemaHasNoValue()) {
            a.add("-i" + getSchema());
        }
        a.add("-f");
        if (!packagingHasNoValue()) {
            a.add("-package" + getPackaging());
        }
        if (!typesHasNoValue()) {
            a.add("-types" + getTypes());
        }
        if (marshal) {
            a.add("-nomarshall");
        }
        if (!destHasNoValue()) {
            a.add("-dest" + getDest());
        }
        //  SourceGenerator sourceGenerator = new SourceGenerator();
        String args[] = new String[a.size()];
        for (int i = 0; i < a.size(); i++) {
            args[i] = (String) a.get(i);
        }
        //  sourceGenerator.main( args );
    } else {
        getLog().info("Schema is up to date. Did not generate source files. Delete " + getTstamp()
                + " if you want to force source generation.");
    }
}

From source file:org.apache.myfaces.trinidadbuild.plugin.javascript.obfuscator.Obfuscator.java

protected void processFile(File in, File out) throws Exception {
    if (_obfuscate == true) {
        FileInputStream inStream = new FileInputStream(in);
        FileOutputStream outStream = new FileOutputStream(out);
        String fileName = in.getName();
        InputSource inpSource = new InputSource(inStream, _config.skipObfuscation(fileName),
                _config.skipStripComments(fileName), _config.skipStripWhitespaces(fileName),
                _config.skipStripNewlines(fileName), _config.skipStripSpecialKeywords(fileName));

        process(inpSource, outStream);//from www. ja va 2 s.c om
        inStream.close();
        outStream.close();
    } else {
        // Just copy the files over.
        FileUtils.touch(out);
        FileUtils.copyFile(in, out);
    }
}

From source file:org.apache.oodt.cas.crawl.typedetection.TestMimeExtractorConfigReader.java

@Override
public void setUp() throws Exception {
    File tmpFile = File.createTempFile("bogus", "bogus");
    tmpDir = new File(tmpFile.getParentFile(), UUID.randomUUID().toString());
    tmpFile.delete();/*from w  w  w  .  j  a va2s. c  o  m*/
    if (!tmpDir.mkdirs()) {
        throw new Exception("Failed to create temp directory");
    }
    mimeTypesFile = new File(tmpDir, "mime-types.xml");
    FileUtils.touch(mimeTypesFile);
    defaultExtractorConfig = new File(tmpDir, "default-extractor.properties");
    FileUtils.touch(defaultExtractorConfig);
}

From source file:org.apache.oodt.cas.metadata.filenaming.TestPathUtilsNamingConvention.java

public void testRename() throws IOException, NamingConventionException {
    File tmpFile = File.createTempFile("bogus", "bogus");
    File tmpDir = new File(tmpFile.getParentFile(), UUID.randomUUID().toString());
    if (!tmpDir.mkdirs()) {
        throw new IOException("Failed to create temp directory");
    }/*from ww  w.j av  a2  s  .co m*/
    tmpFile.delete();
    File testFile = new File(tmpDir, "TestProduct.txt");
    Metadata m = new Metadata();
    m.replaceMetadata("NewName", "NewProduct.txt");

    // Test failure.
    PathUtilsNamingConvention nc = new PathUtilsNamingConvention();
    nc.setNamingConv("[NewName]");
    try {
        nc.rename(testFile, m);
        fail("Should have thrown IOException");
    } catch (NamingConventionException e) {
        /* expect throw */ }

    // Test success.
    FileUtils.touch(testFile);
    File newFile = nc.rename(testFile, m);
    assertTrue(newFile.exists());
    assertEquals("NewProduct.txt", newFile.getName());
    assertFalse(testFile.exists());

    FileUtils.forceDelete(tmpDir);
}