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.jwatch.util.SettingsUtil.java

public static List loadConfig() {
    List instances = new ArrayList();
    String configPath = SettingsUtil.getConfigPath();
    InputStream inputStream = null;
    try {/*from ww  w  .j av  a  2 s .  c  om*/
        File configFile = new File(configPath);
        if (!configFile.exists()) {
            log.info("Settings file not found! Creating new file at " + configPath);
            FileUtils.touch(configFile);
            log.info("Settings file created at " + configPath);
        } else {
            inputStream = new FileInputStream(configFile);
        }

        if (configFile.length() > 0) {
            XStream xStream = new XStream(new JettisonMappedXmlDriver());
            xStream.setMode(XStream.NO_REFERENCES);
            xStream.alias(GlobalConstants.JSON_DATA_ROOT_KEY, ArrayList.class);
            instances = ((List) xStream.fromXML(inputStream));
        }
    } catch (Throwable t) {
        log.error(t);
    } finally {
        try {
            if (inputStream != null) {
                inputStream.close();
            }
        } catch (IOException ioe) {
            log.error("Unable to close config file handle at " + configPath, ioe);
        }
    }
    return instances;
}

From source file:org.kuali.kfs.module.purap.service.impl.ElectronicInvoiceHelperServiceImpl.java

@Override
@NonTransactional/* w ww  .j  a  v a 2  s.c o  m*/
public ElectronicInvoiceLoad loadElectronicInvoices() {

    //add a step to check for directory paths
    prepareDirectories(getRequiredDirectoryNames());

    String rejectDirName = getRejectDirName();
    String acceptDirName = getAcceptDirName();
    emailTextErrorList = new StringBuffer();

    boolean moveFiles = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(
            ElectronicInvoiceStep.class,
            PurapParameterConstants.ElectronicInvoiceParameters.FILE_MOVE_AFTER_LOAD_IND);

    int failedCnt = 0;

    if (LOG.isInfoEnabled()) {
        LOG.info("Invoice Base Directory - " + electronicInvoiceInputFileType.getDirectoryPath());
        LOG.info("Invoice Accept Directory - " + acceptDirName);
        LOG.info("Invoice Reject Directory - " + rejectDirName);
        LOG.info("Is moving files allowed - " + moveFiles);
    }

    if (StringUtils.isBlank(rejectDirName)) {
        throw new RuntimeException("Reject directory name should not be empty");
    }

    if (StringUtils.isBlank(acceptDirName)) {
        throw new RuntimeException("Accept directory name should not be empty");
    }

    File[] filesToBeProcessed = getFilesToBeProcessed();
    ElectronicInvoiceLoad eInvoiceLoad = new ElectronicInvoiceLoad();

    if (filesToBeProcessed == null || filesToBeProcessed.length == 0) {

        StringBuffer mailText = new StringBuffer();

        mailText.append("\n\n");
        mailText.append(PurapConstants.ElectronicInvoice.NO_FILES_PROCESSED_EMAIL_MESSAGE);
        mailText.append("\n\n");

        sendSummary(mailText);
        return eInvoiceLoad;
    }

    try {
        /**
         * Create, if not there
         */
        FileUtils.forceMkdir(new File(acceptDirName));
        FileUtils.forceMkdir(new File(rejectDirName));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    if (LOG.isInfoEnabled()) {
        LOG.info(filesToBeProcessed.length + " file(s) available for processing");
    }

    StringBuilder emailMsg = new StringBuilder();

    for (int i = 0; i < filesToBeProcessed.length; i++) {

        File xmlFile = filesToBeProcessed[i];
        LOG.info("Processing " + xmlFile.getName() + "....");

        byte[] modifiedXML = null;
        //process only if file exists and not empty
        if (xmlFile.length() != 0L) {
            modifiedXML = addNamespaceDefinition(eInvoiceLoad, xmlFile);
        }

        boolean isRejected = false;

        if (modifiedXML == null) {//Not able to parse the xml
            isRejected = true;
        } else {
            try {
                isRejected = processElectronicInvoice(eInvoiceLoad, xmlFile, modifiedXML);
            } catch (Exception e) {
                String msg = xmlFile.getName() + "\n";
                LOG.error(msg);

                //since getMessage() is empty we'll compose the stack trace and nicely format it.
                StackTraceElement[] elements = e.getStackTrace();
                StringBuffer trace = new StringBuffer();
                trace.append(e.getClass().getName());
                if (e.getMessage() != null) {
                    trace.append(": ");
                    trace.append(e.getMessage());
                }
                trace.append("\n");
                for (int j = 0; j < elements.length; ++j) {
                    StackTraceElement element = elements[j];

                    trace.append("    at ");
                    trace.append(describeStackTraceElement(element));
                    trace.append("\n");
                }

                LOG.error(trace);
                emailMsg.append(msg);
                msg += "\n--------------------------------------------------------------------------------------\n"
                        + trace;
                logProcessElectronicInvoiceError(msg);
                failedCnt++;

                /**
                 * Clear the error map, so that subsequent EIRT routing isn't prevented since rice
                 * is throwing a ValidationException if the error map is not empty before routing the doc.
                 */
                GlobalVariables.getMessageMap().clearErrorMessages();

                //Do not execute rest of code below
                continue;
            }
        }

        /**
         * If there is a single order has rejects and the remainings are accepted in a invoice file,
         * then the entire file has been moved to the reject dir.
         */
        if (isRejected) {
            if (LOG.isInfoEnabled()) {
                LOG.info(xmlFile.getName() + " has been rejected");
            }
            if (moveFiles) {
                if (LOG.isInfoEnabled()) {
                    LOG.info(xmlFile.getName() + " has been marked to move to " + rejectDirName);
                }
                eInvoiceLoad.addRejectFileToMove(xmlFile, rejectDirName);
            }
        } else {
            if (LOG.isInfoEnabled()) {
                LOG.info(xmlFile.getName() + " has been accepted");
            }
            if (moveFiles) {
                if (!moveFile(xmlFile, acceptDirName)) {
                    String msg = xmlFile.getName() + " unable to move";
                    LOG.error(msg);
                    throw new PurError(msg);
                }
            }
        }

        if (!moveFiles) {
            String fullPath = FilenameUtils.getFullPath(xmlFile.getAbsolutePath());
            String fileName = FilenameUtils.getBaseName(xmlFile.getAbsolutePath());
            File processedFile = new File(fullPath + File.separator + fileName + ".processed");
            try {
                FileUtils.touch(processedFile);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        //  delete the .done file
        deleteDoneFile(xmlFile);
    }

    emailTextErrorList.append("\nFAILED FILES\n");
    emailTextErrorList.append("-----------------------------------------------------------\n\n");
    emailTextErrorList.append(emailMsg);
    emailTextErrorList.append("\nTOTAL COUNT\n");
    emailTextErrorList.append("===========================\n");
    emailTextErrorList.append("      " + failedCnt + " FAILED\n");
    emailTextErrorList.append("===========================\n");

    StringBuffer summaryText = saveLoadSummary(eInvoiceLoad);

    StringBuffer finalText = new StringBuffer();
    finalText.append(summaryText);
    finalText.append("\n");
    finalText.append(emailTextErrorList);
    sendSummary(finalText);

    LOG.info("Processing completed");

    return eInvoiceLoad;

}

From source file:org.kuali.ole.module.purap.service.impl.ElectronicInvoiceHelperServiceImpl.java

@Override
public ElectronicInvoiceLoad loadElectronicInvoices() {

    //add a step to check for directory paths
    prepareDirectories(getRequiredDirectoryNames());

    String baseDirName = getBaseDirName();
    String rejectDirName = getRejectDirName();
    String acceptDirName = getAcceptDirName();
    emailTextErrorList = new StringBuffer();

    boolean moveFiles = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(
            ElectronicInvoiceStep.class,
            PurapParameterConstants.ElectronicInvoiceParameters.FILE_MOVE_AFTER_LOAD_IND);

    int failedCnt = 0;

    if (LOG.isInfoEnabled()) {
        LOG.info("Invoice Base Directory - " + electronicInvoiceInputFileType.getDirectoryPath());
        LOG.info("Invoice Accept Directory - " + acceptDirName);
        LOG.info("Invoice Reject Directory - " + rejectDirName);
        LOG.info("Is moving files allowed - " + moveFiles);
    }/*w  ww.  jav  a  2  s  . c  om*/

    if (StringUtils.isBlank(rejectDirName)) {
        throw new RuntimeException("Reject directory name should not be empty");
    }

    if (StringUtils.isBlank(acceptDirName)) {
        throw new RuntimeException("Accept directory name should not be empty");
    }

    File baseDir = new File(baseDirName);
    if (!baseDir.exists()) {
        throw new RuntimeException("Base dir [" + baseDirName + "] doesn't exists in the system");
    }

    File[] filesToBeProcessed = baseDir.listFiles(new FileFilter() {
        @Override
        public boolean accept(File file) {
            String fullPath = FilenameUtils.getFullPath(file.getAbsolutePath());
            String fileName = FilenameUtils.getBaseName(file.getAbsolutePath());
            File processedFile = new File(fullPath + File.separator + fileName + ".processed");
            return (!file.isDirectory() && file.getName().endsWith(".xml") && !processedFile.exists());
        }
    });

    ElectronicInvoiceLoad eInvoiceLoad = new ElectronicInvoiceLoad();

    if (filesToBeProcessed == null || filesToBeProcessed.length == 0) {

        StringBuffer mailText = new StringBuffer();

        mailText.append("\n\n");
        mailText.append(PurapConstants.ElectronicInvoice.NO_FILES_PROCESSED_EMAIL_MESSAGE);
        mailText.append("\n\n");

        sendSummary(mailText);
        return eInvoiceLoad;
    }

    try {
        /**
         * Create, if not there
         */
        FileUtils.forceMkdir(new File(acceptDirName));
        FileUtils.forceMkdir(new File(rejectDirName));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    if (LOG.isInfoEnabled()) {
        LOG.info(filesToBeProcessed.length + " file(s) available for processing");
    }

    StringBuilder emailMsg = new StringBuilder();

    for (File element2 : filesToBeProcessed) {

        // MSU Contribution DTT-3014 OLEMI-8483 OLECNTRB-974
        File xmlFile = element2;
        LOG.info("Processing " + xmlFile.getName() + "....");

        byte[] modifiedXML = null;
        // process only if file exists and not empty
        if (xmlFile.length() != 0L) {
            modifiedXML = addNamespaceDefinition(eInvoiceLoad, xmlFile);
        }

        boolean isRejected = false;

        if (modifiedXML == null) {//Not able to parse the xml
            isRejected = true;
        } else {
            try {
                isRejected = processElectronicInvoice(eInvoiceLoad, xmlFile, modifiedXML);
            } catch (Exception e) {
                String msg = xmlFile.getName() + "\n";
                LOG.error(msg);

                //since getMessage() is empty we'll compose the stack trace and nicely format it.
                StackTraceElement[] elements = e.getStackTrace();
                StringBuffer trace = new StringBuffer();
                trace.append(e.getClass().getName());
                if (e.getMessage() != null) {
                    trace.append(": ");
                    trace.append(e.getMessage());
                }
                trace.append("\n");
                for (StackTraceElement element : elements) {
                    trace.append("    at ");
                    trace.append(describeStackTraceElement(element));
                    trace.append("\n");
                }

                LOG.error(trace);
                emailMsg.append(msg);
                msg += "\n--------------------------------------------------------------------------------------\n"
                        + trace;
                logProcessElectronicInvoiceError(msg);
                failedCnt++;

                /**
                 * Clear the error map, so that subsequent EIRT routing isn't prevented since rice is throwing a
                 * ValidationException if the error map is not empty before routing the doc.
                 */
                GlobalVariables.getMessageMap().clearErrorMessages();

                //Do not execute rest of code below
                continue;
            }
        }

        /**
         * If there is a single order has rejects and the remainings are accepted in a invoice file,
         * then the entire file has been moved to the reject dir.
         */
        if (isRejected) {
            if (LOG.isInfoEnabled()) {
                LOG.info(xmlFile.getName() + " has been rejected");
            }
            if (moveFiles) {
                if (LOG.isInfoEnabled()) {
                    LOG.info(xmlFile.getName() + " has been marked to move to " + rejectDirName);
                }
                eInvoiceLoad.addRejectFileToMove(xmlFile, rejectDirName);
            }
        } else {
            if (LOG.isInfoEnabled()) {
                LOG.info(xmlFile.getName() + " has been accepted");
            }
            if (moveFiles) {
                if (!moveFile(xmlFile, acceptDirName)) {
                    String msg = xmlFile.getName() + " unable to move";
                    LOG.error(msg);
                    throw new PurError(msg);
                }
            }
        }

        if (!moveFiles) {
            String fullPath = FilenameUtils.getFullPath(xmlFile.getAbsolutePath());
            String fileName = FilenameUtils.getBaseName(xmlFile.getAbsolutePath());
            File processedFile = new File(fullPath + File.separator + fileName + ".processed");
            try {
                FileUtils.touch(processedFile);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        //  delete the .done file
        deleteDoneFile(xmlFile);
    }

    emailTextErrorList.append("\nFAILED FILES\n");
    emailTextErrorList.append("-----------------------------------------------------------\n\n");
    emailTextErrorList.append(emailMsg);
    emailTextErrorList.append("\nTOTAL COUNT\n");
    emailTextErrorList.append("===========================\n");
    emailTextErrorList.append("      " + failedCnt + " FAILED\n");
    emailTextErrorList.append("===========================\n");

    StringBuffer summaryText = saveLoadSummary(eInvoiceLoad);

    StringBuffer finalText = new StringBuffer();
    finalText.append(summaryText);
    finalText.append("\n");
    finalText.append(emailTextErrorList);
    sendSummary(finalText);

    LOG.info("Processing completed");

    return eInvoiceLoad;

}

From source file:org.kuali.rice.kew.plugin.HotDeployTest.java

@Test
public void testReloader() throws Exception {
    // Grab the ServerPluginRegistry
    PluginRegistry theRegistry = PluginUtils.getPluginRegistry();
    assertNotNull("PluginRegistry should exist.", theRegistry);
    assertTrue(theRegistry instanceof ServerPluginRegistry);
    ServerPluginRegistry registry = (ServerPluginRegistry) theRegistry;

    // Let's shut down the asynchronous reloader and hot deployer because we want to do this synchronously.
    HotDeployer hotDeployer = registry.getHotDeployer();
    Reloader reloader = registry.getReloader();
    registry.stopHotDeployer();/*w ww  .  j a v a  2 s  . co m*/
    registry.stopReloader();

    // Assert that there are currently no plugins
    assertEquals("There should be no plugins.", 0, registry.getPluginEnvironments().size());
    assertEquals("Resource loader should have no children.", 0, registry.getResourceLoaders().size());

    // now let's copy a plugin over and run the hot deployer
    String pluginZipFileLocation = new ClasspathOrFileResourceLoader()
            .getResource("classpath:org/kuali/rice/kew/plugin/ziptest.zip").getURL().getPath();
    File pluginZipFile = new File(pluginZipFileLocation);
    assertTrue("Plugin file '" + pluginZipFileLocation + "' should exist", pluginZipFile.exists());
    assertTrue("Plugin file '" + pluginZipFileLocation + "' should be a file", pluginZipFile.isFile());
    FileUtils.copyFileToDirectory(pluginZipFile, pluginDir);

    // update pluginZipFile to point to the copy
    pluginZipFile = new File(pluginDir, pluginZipFile.getName());
    assertTrue(pluginZipFile.exists());

    // execute a hot deploy
    hotDeployer.run();

    // the plugin should have been hot deployed
    assertEquals("Plugin should have been hot deployed.", 1, registry.getPluginEnvironments().size());
    assertEquals("Resource loader should have 1 plugin child.", 1, registry.getResourceLoaders().size());
    PluginEnvironment environment = registry.getPluginEnvironments().get(0);
    Plugin plugin = environment.getPlugin();
    assertTrue(environment.isReloadable());
    assertFalse(environment.isReloadNeeded());

    // let's attempt to execute a Reload
    reloader.run();

    // a reload should not have occurred here since nothing was updated
    assertTrue("Original plugin should still be running.", plugin.isStarted());
    assertEquals("Plugin should not have changed.", plugin,
            registry.getPluginEnvironments().get(0).getPlugin());

    // touch the plugin file and then reload
    FileUtils.touch(pluginZipFile);
    assertTrue("A reload should be needed now.", environment.isReloadNeeded());
    reloader.run();

    // the original plugin should now be stopped
    assertTrue("original plugin should be stopped.", !plugin.isStarted());
    assertEquals("There should only be one Plugin.", 1, registry.getResourceLoaders().size());

    PluginEnvironment newPluginEnvironment = registry.getPluginEnvironments().get(0);
    Plugin newPlugin = newPluginEnvironment.getPlugin();
    assertEquals("There should still only be one environment.", 1, registry.getPluginEnvironments().size());
    assertEquals("The plugin environments should still be the same.", environment,
            registry.getPluginEnvironments().get(0));

    assertFalse("The old and new plugins should be different.", newPlugin.equals(plugin));

    // verify that the resource loader was updated
    assertEquals("The resource loaders should have been updated with the new plugin.", newPlugin,
            registry.getResourceLoaders().get(0));

}

From source file:org.kuali.rice.kew.plugin.ZipFilePluginLoaderTest.java

@Before
// public void setUp() throws Exception {
// super.setUp();
// Config config = ConfigContext.getCurrentContextConfig();
// if (config == null) {
// // because of previously running tests, the config might already be initialized
// config = new SimpleConfig();
// config.getProperties().put(Config.SERVICE_NAMESPACE, "KEW");
// ConfigContext.init(config);
// }// w  w w.  j a v a2  s  . c o  m
// // from RiceTestCase if this ever get put into that hierarchy
//
// }
//
// @After
// public void tearDown() throws Exception {
// super.setUp();
// try {
// plugin.stop();
// } catch (Exception e) {
// e.printStackTrace();
// }
// try {
// FileUtils.deleteDirectory(pluginDir);
// } catch (Exception e) {
//
// }
// }
@Test
public void testLoad() throws Exception {
    Config config = ConfigContext.getCurrentContextConfig();
    if (config == null) {
        // because of previously running tests, the config might already be initialized
        config = new JAXBConfigImpl();
        config.putProperty(CoreConstants.Config.APPLICATION_ID, "KEW");
        ConfigContext.init(config);
    }

    File pluginZipFile = new ClasspathOrFileResourceLoader()
            .getResource("classpath:org/kuali/rice/kew/plugin/ziptest.zip").getFile();
    assertTrue(pluginZipFile.exists());
    assertTrue(pluginZipFile.isFile());

    // create a temp directory to copy the zip file into
    pluginDir = TestUtilities.createTempDir();

    // copy the zip file
    FileUtils.copyFileToDirectory(pluginZipFile, pluginDir);
    pluginZipFile = new File(pluginDir, pluginZipFile.getName());
    assertTrue(pluginZipFile.exists());
    pluginZipFile.deleteOnExit();

    // create the ZipFilePluginLoader and load the plugin
    ZipFilePluginLoader loader = new ZipFilePluginLoader(pluginZipFile, null,
            ClassLoaderUtils.getDefaultClassLoader(), ConfigContext.getCurrentContextConfig());
    this.plugin = loader.load();
    assertNotNull("Plugin should have been successfully loaded.", plugin);
    // check the plugin name, it's QName should be '{KUALI}ziptest', it's plugin name should be 'ziptest'
    assertEquals("Plugin QName should be '{KUALI}ziptest'", new QName("KUALI", "ziptest"), plugin.getName());

    // start the plugin
    this.plugin.start();

    // verify that the plugin was extracted, should be in a directory named the same as the local part of the
    // QName
    File extractedDirectory = new File(pluginDir, plugin.getName().getLocalPart());
    assertTrue("Plugin should have been extracted.", extractedDirectory.exists());
    assertTrue(extractedDirectory.isDirectory());
    File[] files = extractedDirectory.listFiles();
    assertEquals("Should be 3 files", 3, files.length);

    // try loading some classes and checking that things got loaded properly
    assertNotNull("Resource should exist.", plugin.getClassLoader().getResource("lib-test.txt"));
    assertNotNull("Resource should exist.", plugin.getClassLoader().getResource("classes-test.txt"));

    // check the config values
    assertEquals(plugin.getConfig().getProperty("test.param.1"), "test.value.1");
    assertEquals(plugin.getConfig().getProperty("test.param.2"), "test.value.2");
    assertEquals(plugin.getConfig().getProperty("test.param.3"), "test.value.3");

    // verify the modification checks on the plugin which drive hot deployment
    assertFalse("Plugin should not be modifed at this point.", loader.isModified());
    // record the last modified date of the extracted directory
    long lastModified = pluginDir.lastModified();

    // sleep for a milliseconds before touching the file, this will help our last modified check so we don't
    // get the same value
    Thread.sleep(1000);

    // touch the zip file
    FileUtils.touch(pluginZipFile);
    assertTrue("Plugin should be modifed after zip file is touched.", loader.isModified());
    plugin.stop();

    // reload the plugin
    this.plugin = loader.load();

    this.plugin.start();
    assertFalse("After reload, plugin should no longer be modifed.", loader.isModified());

    // check the last modified date of the extracted directory
    assertTrue("The extracted directory should have been modified.", pluginDir.lastModified() > lastModified);

    try {
        plugin.stop();
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        FileUtils.deleteDirectory(pluginDir);
    } catch (Exception e) {

    }
}

From source file:org.lexgrid.valuesets.helper.compiler.FileSystemCachingValueSetDefinitionCompilerDecorator.java

/**
 * Retrieve coded node set./*from  www.  j  av a 2s . co m*/
 * 
 * @param md5 the md5
 * 
 * @return the coded node set
 * 
 * @throws Exception the exception
 */
protected CodedNodeSet retrieveCodedNodeSet(String md5) {

    try {

        File cachedCnsFile = new File(this.getDiskStorePath() + File.separator + this.getFileName(md5));
        if (!cachedCnsFile.exists()) {
            LoggerFactory.getLogger().info("Compiled Value Set Definition cache miss.");

            return null;
        } else {
            LoggerFactory.getLogger().info("Compiled Value Set Definition cache hit.");

            FileUtils.touch(cachedCnsFile);
        }

        ObjectInput in = new ObjectInputStream(new FileInputStream(cachedCnsFile));
        CodedNodeSetImpl cns;
        try {
            cns = (CodedNodeSetImpl) in.readObject();
        } catch (Exception e) {
            LoggerFactory.getLogger().warn(
                    "Compiled Value Set Definition was found, but it is invalid or corrupted. Removing...", e);
            if (!FileUtils.deleteQuietly(cachedCnsFile)) {
                FileUtils.forceDeleteOnExit(cachedCnsFile);
            }

            throw e;
        }

        in.close();

        if (cns == null) {
            return null;
        } else {
            return cns;
        }
    } catch (Exception e) {
        LoggerFactory.getLogger()
                .warn("There was an error retrieving the Compiled Value Set Definition from the Cache."
                        + " Caching will not be used for this Value Set Definition.", e);

        return null;
    }
}

From source file:org.limy.lrd.repository.file.LrdFileRepository.java

public void addFile(String lrdPath) throws LrdException {
    File file = getRealFile(lrdPath);
    if (file.exists()) {
        throw new LrdException(lrdPath + " ???????");
    }//from ww  w  .  jav a 2  s. c  om
    try {
        file.getParentFile().mkdirs();
        FileUtils.touch(file);
    } catch (IOException e) {
        throw new LrdException(e);
    }
}

From source file:org.lorislab.maven.jboss.server.DeploymentMojo.java

/**
 * The deploy the file to the server./*from w  w  w . j  a  va2  s  . co m*/
 *
 * @throws MojoExecutionException
 * @throws MojoFailureException
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    File targetDir = getTargetDir();

    if (exploded) {
        try {
            getLog().info("Deploy the directory: " + targetDirName + " to the server: "
                    + targetDir.getAbsolutePath());

            File target = new File(targetDir, targetDirName);

            FileUtils.deleteDirectory(target);

            // create target directory
            if (!target.exists()) {
                target.mkdir();
            }

            // copy directory
            FileUtils.copyDirectory(deployDir, target);

            // redeploy the application
            FileUtils.touch(new File(targetDir, targetDirName + ".dodeploy"));
            getLog().info("Exploded deployed finished!");
        } catch (IOException ex) {
            throw new MojoExecutionException("Error to copy the deploy final " + deployFile.getAbsolutePath(),
                    ex);
        }
    } else {
        try {
            getLog().info("Deploy the file: " + deployFile.getAbsolutePath() + " to the server: "
                    + targetDir.getAbsolutePath());
            FileUtils.copyFileToDirectory(deployFile, targetDir);
            getLog().info("Deployed finished!");
        } catch (IOException ex) {
            throw new MojoExecutionException("Error to copy the deploy final " + deployFile.getAbsolutePath(),
                    ex);
        }
    }
}

From source file:org.mule.module.git.GitConnectorTest.java

@Test
public void testAddAndCommit() throws IOException {
    gitConnector.cloneRepository(REMOTE_REPO, false, "origin", "HEAD", null);

    FileUtils.touch(new File(location, "new-file"));
    gitConnector.add("new-file", null);

    gitConnector.commit("new file added", "test guy", "test@mail.com", "test guy", "test@mail.com", null);
}

From source file:org.opencastproject.capture.impl.SchedulerImplTest.java

public void setupFakeMediaPackageWithoutMediaFiles() {
    // Create the configuration manager
    configurationManager = new ConfigurationManager();
    // Setup the configuration manager with a tmp storage directory.
    File recordingDir = new File("./target", directory);
    Properties p;// w  w w .  ja  v  a2s .  com
    try {
        p = loadProperties("config/capture.properties");
        p.put(CaptureParameters.RECORDING_ROOT_URL, recordingDir.getAbsolutePath());
        p.put(CaptureParameters.RECORDING_ID, "2nd-Capture");
        p.put("org.opencastproject.server.url", "http://localhost:8080");
        p.put(CaptureParameters.CAPTURE_SCHEDULE_REMOTE_POLLING_INTERVAL, -1);
        p.put("M2_REPO", getClass().getClassLoader().getResource("m2_repo").getFile());
        p.put(CaptureParameters.CAPTURE_DEVICE_NAMES,
                "capture.device.names=MOCK_SCREEN,MOCK_PRESENTER,MOCK_MICROPHONE");
        configurationManager.updated(p);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail();
    } catch (ConfigurationException e) {
        e.printStackTrace();
        Assert.fail();
    }

    File uidFile = new File(recordingDir, "2nd-Capture");
    try {
        FileUtils.forceMkdir(uidFile);
        FileUtils.touch(new File(uidFile.getAbsolutePath(), "episode.xml"));
        FileUtils.touch(new File(uidFile.getAbsolutePath(), "manifest.xml"));
        FileUtils.touch(new File(uidFile.getAbsolutePath(), "org.opencastproject.capture.agent.properties"));
        FileUtils.touch(new File(uidFile.getAbsolutePath(), "capture.stopped"));
        FileUtils.touch(new File(uidFile.getAbsolutePath(), "series.xml"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}