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

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

Introduction

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

Prototype

public static void copyFileToDirectory(File srcFile, File destDir) throws IOException 

Source Link

Document

Copies a file to a directory preserving the file date.

Usage

From source file:org.artifactory.logging.LoggingServiceImpl.java

@Override
public void importFrom(ImportSettings settings) {
    File logFileToImport = new File(settings.getBaseDir(), "etc/logback.xml");
    if (logFileToImport.exists()) {
        try {// www. j a  v  a  2  s.  c o m
            // Backup the target logback file
            File targetEtcDir = ArtifactoryHome.get().getEtcDir();
            File existingLogbackFile = new File(targetEtcDir, "logback.xml");
            if (existingLogbackFile.exists()) {
                FileUtils.copyFile(existingLogbackFile, new File(targetEtcDir, "logback.original.xml"));
            }
            // Copy file into a temporary working directory
            File workFile = new File(FileUtils.getTempDirectory(), logFileToImport.getName());
            FileUtils.copyFile(logFileToImport, workFile);
            convertAndSave(workFile, settings);
            // Copy the converted file to the target dir
            FileUtils.copyFileToDirectory(workFile, targetEtcDir);
            FileUtils.deleteQuietly(workFile);
        } catch (IOException e) {
            settings.getStatusHolder().error("Failed to import and convert logback file", e, log);
        }
    }
}

From source file:org.artifactory.spring.ArtifactoryApplicationContext.java

private void exportArtifactoryProperties(ExportSettings settings) {
    MutableStatusHolder status = settings.getStatusHolder();
    File artifactoryPropFile = artifactoryHome.getHomeArtifactoryPropertiesFile();
    if (artifactoryPropFile.exists()) {
        try {// w ww . j a  va2  s .  c  o m
            FileUtils.copyFileToDirectory(artifactoryPropFile, settings.getBaseDir());
        } catch (IOException e) {
            status.error("Failed to copy artifactory.properties file", e, log);
        }
    } else {
        status.status("No KeyVal defined no export done", log);
    }
}

From source file:org.asqatasun.referential.creator.CodeGeneratorMojo.java

/**
 * This method sets the working directory and copies the static context
 * files such as log4j or xmlDataSet (needed by HsqlDb) to the appropriate
 * path.//from   w  w w  .java2s.  c  o  m
 *
 * @throws IOException
 */
private void initializeContext() throws IOException {
    String workingDir = System.getProperty("user.dir");
    File dataset = FileUtils.getFile(workingDir + "/src/main/resources/dataset/emptyFlatXmlDataSet.xml");
    File log4jFile = FileUtils.getFile(workingDir + "/src/main/resources/log4j/log4j.properties");
    File datasetFolder = new File(destinationFolder + "/src/test/resources/dataSets");
    File log4jFolder = new File(destinationFolder + "/src/test/resources");
    dataset.mkdirs();
    log4jFile.mkdirs();
    FileUtils.copyFileToDirectory(dataset, datasetFolder);
    FileUtils.copyFileToDirectory(log4jFile, log4jFolder);
}

From source file:org.ballerinalang.docgen.docs.BallerinaDocGenerator.java

/**
 * API to generate Ballerina API documentation.
 *  @param sourceRoot    project root//from w w  w . j  ava  2s . co m
 * @param output        path to the output directory where the API documentation will be written to.
 * @param packageFilter comma separated list of package names to be filtered from the documentation.
 * @param isNative      whether the given packages are native or not.
 * @param offline       is offline generation
 * @param sources       either the path to the directories where Ballerina source files reside or a
 */
public static void generateApiDocs(String sourceRoot, String output, String packageFilter, boolean isNative,
        boolean offline, String... sources) {
    out.println("docerina: API documentation generation for sources - " + Arrays.toString(sources));
    List<Link> primitives = primitives();

    // generate package docs
    Map<String, PackageDoc> docsMap = generatePackageDocsMap(sourceRoot, packageFilter, isNative, sources,
            offline);

    if (docsMap.size() == 0) {
        out.println("docerina: no module definitions found!");
        return;
    }

    if (BallerinaDocUtils.isDebugEnabled()) {
        out.println("docerina: generating HTML API documentation...");
    }

    // validate output path
    String userDir = System.getProperty("user.dir");
    // If output directory is empty
    if (output == null) {
        output = System.getProperty(BallerinaDocConstants.HTML_OUTPUT_PATH_KEY,
                userDir + File.separator + ProjectDirConstants.TARGET_DIR_NAME + File.separator + "api-docs");
    }

    if (BallerinaDocUtils.isDebugEnabled()) {
        out.println("docerina: creating output directory: " + output);
    }

    try {
        // Create output directory
        Files.createDirectories(Paths.get(output));
    } catch (IOException e) {
        out.println(String.format("docerina: API documentation generation failed. Couldn't create the [output "
                + "directory] %s. Cause: %s", output, e.getMessage()));
        log.error(
                String.format("API documentation generation failed. Couldn't create the [output directory] %s. "
                        + "" + "" + "Cause: %s", output, e.getMessage()),
                e);
        return;
    }

    if (BallerinaDocUtils.isDebugEnabled()) {
        out.println("docerina: successfully created the output directory: " + output);
    }

    // Sort packages by package path
    List<PackageDoc> packageList = new ArrayList<>(docsMap.values());
    packageList.sort(Comparator.comparing(pkg -> pkg.bLangPackage.packageID.toString()));

    // Sort the package names
    List<String> packageNames = new ArrayList<>(docsMap.keySet());
    Collections.sort(packageNames);

    List<Link> packageNameList = PackageName.convertList(packageNames);

    String packageTemplateName = System.getProperty(BallerinaDocConstants.MODULE_TEMPLATE_NAME_KEY, "page");
    String packageToCTemplateName = System.getProperty(BallerinaDocConstants.MODULE_TOC_TEMPLATE_NAME_KEY,
            "toc");

    List<Path> resources = new ArrayList<>();

    //Iterate over the packages to generate the pages
    for (PackageDoc packageDoc : packageList) {

        try {
            BLangPackage bLangPackage = packageDoc.bLangPackage;
            String pkgDescription = packageDoc.description;

            // Sort functions, connectors, structs, type mappers and annotationDefs
            sortPackageConstructs(bLangPackage);

            String packagePath = refinePackagePath(bLangPackage);
            if (BallerinaDocUtils.isDebugEnabled()) {
                out.println("docerina: starting to generate docs for module: " + packagePath);
            }

            // other normal packages
            Page page = Generator.generatePage(bLangPackage, packageNameList, pkgDescription, primitives);
            String filePath = output + File.separator + packagePath + HTML;
            Writer.writeHtmlDocument(page, packageTemplateName, filePath);

            if (ConfigRegistry.getInstance().getAsBoolean(BallerinaDocConstants.GENERATE_TOC)) {
                // generates ToC into a separate HTML - requirement of Central
                out.println(
                        "docerina: generating toc: " + output + File.separator + packagePath + "-toc" + HTML);
                String tocFilePath = output + File.separator + packagePath + "-toc" + HTML;
                Writer.writeHtmlDocument(page, packageToCTemplateName, tocFilePath);
            }

            if (Names.BUILTIN_PACKAGE.getValue().equals(packagePath)) {
                // primitives are in builtin package
                Page primitivesPage = Generator.generatePageForPrimitives(bLangPackage, packageNameList,
                        primitives);
                String primitivesFilePath = output + File.separator + "primitive-types" + HTML;
                Writer.writeHtmlDocument(primitivesPage, packageTemplateName, primitivesFilePath);
            }

            // collect package resources
            resources.addAll(packageDoc.resources);

            if (BallerinaDocUtils.isDebugEnabled()) {
                out.println("docerina: generated docs for module: " + packagePath);
            }
        } catch (IOException e) {
            out.println(String.format("docerina: API documentation generation failed for module %s: %s",
                    packageDoc.bLangPackage.packageID.toString(), e.getMessage()));
            log.error(String.format("API documentation generation failed for %s",
                    packageDoc.bLangPackage.packageID.toString()), e);
        }
    }

    if (BallerinaDocUtils.isDebugEnabled()) {
        out.println("docerina: copying HTML theme into " + output);
    }
    try {
        BallerinaDocUtils.copyResources("docerina-theme", output);
    } catch (IOException e) {
        out.println(String.format("docerina: failed to copy the docerina-theme resource. Cause: %s",
                e.getMessage()));
        log.error("Failed to copy the docerina-theme resource.", e);
    }
    if (BallerinaDocUtils.isDebugEnabled()) {
        out.println("docerina: successfully copied HTML theme into " + output);
    }

    if (!resources.isEmpty()) {
        String resourcesDir = output + File.separator + "resources";
        File resourcesDirFile = new File(resourcesDir);
        if (BallerinaDocUtils.isDebugEnabled()) {
            out.println("docerina: copying project resources into " + resourcesDir);
        }
        resources.parallelStream().forEach(path -> {
            try {
                FileUtils.copyFileToDirectory(path.toFile(), resourcesDirFile);
            } catch (IOException e) {
                out.println(String.format(
                        "docerina: failed to copy [resource] %s into [resources directory] " + "%s. Cause: %s",
                        path.toString(), resourcesDir, e.getMessage()));
                log.error(String.format(
                        "docerina: failed to copy [resource] %s into [resources directory] " + "%s. Cause: %s",
                        path.toString(), resourcesDir, e.getMessage()), e);
            }
        });
        if (BallerinaDocUtils.isDebugEnabled()) {
            out.println("docerina: successfully copied project resources into " + resourcesDir);
        }
    }

    if (BallerinaDocUtils.isDebugEnabled()) {
        out.println("docerina: generating the index HTML file.");
    }

    try {
        //Generate the index file with the list of all modules
        String indexTemplateName = System.getProperty(BallerinaDocConstants.MODULE_TEMPLATE_NAME_KEY, "index");
        String indexFilePath = output + File.separator + "index" + HTML;
        Writer.writeHtmlDocument(packageNameList, indexTemplateName, indexFilePath);
    } catch (IOException e) {
        out.println(String.format("docerina: failed to create the index.html. Cause: %s", e.getMessage()));
        log.error("Failed to create the index.html file.", e);
    }

    if (BallerinaDocUtils.isDebugEnabled()) {
        out.println("docerina: successfully generated the index HTML file.");
        out.println("docerina: generating the module-list HTML file.");
    }

    try {
        // Generate module-list.html file which prints the list of processed packages
        String pkgListTemplateName = System.getProperty(BallerinaDocConstants.MODULE_LIST_TEMPLATE_NAME_KEY,
                "module-list");

        String pkgListFilePath = output + File.separator + "module-list" + HTML;
        Writer.writeHtmlDocument(packageNameList, pkgListTemplateName, pkgListFilePath);
    } catch (IOException e) {
        out.println(
                String.format("docerina: failed to create the module-list.html. Cause: %s", e.getMessage()));
        log.error("Failed to create the module-list.html file.", e);
    }

    if (BallerinaDocUtils.isDebugEnabled()) {
        out.println("docerina: successfully generated the module-list HTML file.");
    }

    try {
        String zipPath = System.getProperty(BallerinaDocConstants.OUTPUT_ZIP_PATH);
        if (zipPath != null) {
            if (BallerinaDocUtils.isDebugEnabled()) {
                out.println("docerina: generating the documentation zip file.");
            }
            BallerinaDocUtils.packageToZipFile(output, zipPath);
            if (BallerinaDocUtils.isDebugEnabled()) {
                out.println("docerina: successfully generated the documentation zip file.");
            }
        }
    } catch (IOException e) {
        out.println(String.format("docerina: API documentation zip packaging failed for %s: %s", output,
                e.getMessage()));
        log.error(String.format("API documentation zip packaging failed for %s", output), e);
    }

    if (BallerinaDocUtils.isDebugEnabled()) {
        out.println("docerina: documentation generation is done.");
    }
}

From source file:org.ballproject.knime.nodegeneration.NodeGenerator.java

/**
 * Copies the java sources needed to invoke a tool (described by a
 * {@link CTDFile}) to the specified {@link NodesBuildKnimeNodesDirectory}.
 * /*from   w ww  .  j  ava2 s. com*/
 * @param ctdFile
 *            which described the wrapped tool
 * @param iconsDir
 *            location where node icons reside
 * @param nodesDir
 *            location where to create a sub directory containing the
 *            generated sources
 * @param pluginMeta
 *            meta information used to adapt the java files
 * @return the fully qualified name of the {@link NodeFactory} class able to
 *         build instances of the node.
 * @throws IOException
 * @throws UnknownMimeTypeException
 */
public static String copyNodeSources(CTDFile ctdFile, IconsDirectory iconsDir,
        NodesBuildKnimeNodesDirectory nodesDir, KNIMEPluginMeta pluginMeta)
        throws IOException, UnknownMimeTypeException {

    INodeConfiguration nodeConfiguration = ctdFile.getNodeConfiguration();
    String nodeName = Utils.fixKNIMENodeName(nodeConfiguration.getName());

    File nodeSourceDir = new File(nodesDir, nodeName);
    nodeSourceDir.mkdirs();

    File nodeIcon = iconsDir.getNodeIcon(nodeConfiguration);
    if (nodeIcon != null)
        FileUtils.copyFileToDirectory(nodeIcon, nodeSourceDir);

    /*
     * all files placed into src/[PACKAGE]/knime/nodes/[NODE_NAME]
     */
    new NodeDialogTemplate(pluginMeta.getPackageRoot(), nodeName)
            .write(new File(nodeSourceDir, nodeName + "NodeDialog.java"));
    new NodeViewTemplate(pluginMeta.getPackageRoot(), nodeName)
            .write(new File(nodeSourceDir, nodeName + "NodeView.java"));
    new NodeModelTemplate(pluginMeta.getPackageRoot(), nodeName, nodeConfiguration)
            .write(new File(nodeSourceDir, nodeName + "NodeModel.java"));
    new NodeFactoryXMLTemplate(nodeName, nodeConfiguration,
            (nodeIcon != null) ? nodeIcon.getName() : "./default.png")
                    .write(new File(nodeSourceDir, nodeName + "NodeFactory.xml"));
    new NodeFactoryTemplate(pluginMeta.getPackageRoot(), nodeName)
            .write(new File(nodeSourceDir, nodeName + "NodeFactory.java"));

    File nodeConfigDir = new File(nodeSourceDir, "config");
    nodeConfigDir.mkdirs();

    /*
     * all files placed into src/[PACKAGE]/knime/nodes/[NODE_NAME]/config
     */
    Helper.copyFile(ctdFile, new File(nodeConfigDir, "config.xml"));

    return pluginMeta.getPackageRoot() + ".knime.nodes." + nodeName + "." + nodeName + "NodeFactory";
}

From source file:org.betaconceptframework.astroboa.test.engine.AbstractRepositoryTest.java

private void copyFilesToUnmanagedDataStore() throws IOException {

     logo = new ClassPathResource("logo.png").getFile();
     logo2 = new ClassPathResource("logo2.png").getFile();

     File unmanagedDataStore = new ClassPathResource("/repository/UnmanagedDataStore").getFile();

     FileUtils.copyFileToDirectory(logo, unmanagedDataStore);
     FileUtils.copyFileToDirectory(logo2, unmanagedDataStore);
 }

From source file:org.bimserver.tools.generators.CopyAdminAndBIMsieInterface.java

private void copyAdminInterface() {
    try {/*from  ww w .  jav a 2  s.  com*/
        FileUtils.copyFileToDirectory(new File(bootstrap, "setup.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "index.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "login.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "basicserversettings.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "serversettings.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "serverinfo.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "gettingstarted.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "plugins.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "console.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "extendeddataschemas.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "extendeddataschema.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "addextendeddataschema.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "addrepoextendeddataschema.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "main.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "migrations.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "webmodules.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "log.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "usersettings.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "basicusersettings.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "genericpluginsettingslist.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "genericpluginsettings.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "modelcheckers.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "addrepomodelchecker.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "addnewmodelchecker.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "plugin.html"), admin);
        FileUtils.copyFileToDirectory(new File(bootstrap, "modelchecker.html"), admin);

        FileUtils.copyDirectory(new File(bootstrap, "js"), new File(admin, "js"), new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                if (pathname.getName().equals("settings.js")) {
                    return false;
                }
                return true;
            }
        });
        FileUtils.copyDirectory(new File(bootstrap, "img"), new File(admin, "img"));
        FileUtils.copyDirectory(new File(bootstrap, "css"), new File(admin, "css"), new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                if (pathname.getName().equals("magic-bootstrap-min.css")) {
                    return false;
                }
                return true;
            }
        });
        FileUtils.copyDirectory(new File(bootstrap, "fonts"), new File(admin, "fonts"));
    } catch (IOException e) {
        LOGGER.error("", e);
    }
}

From source file:org.bitrepository.protocol.fileexchange.TestFileStore.java

/**
 * Constructor, where the FileStore is initialized with some files.
 * @param storeName The id for the FileStore.
 * @param initialFiles The files to copy into the FileStore during initialization.
 *//*www. ja va2  s.c o  m*/
public TestFileStore(String storeName, File... initialFiles) {
    this.storeName = storeName;
    storageDir = ROOT_STORE + "/" + storeName;

    for (File initFile : initialFiles) {
        try {
            FileUtils.copyFileToDirectory(initFile, new File(storageDir));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.bonitasoft.web.rest.model.builder.page.PageItemBuilder.java

public PageItem build(final long tenantId) throws IOException, URISyntaxException {
    final PageItem item = new PageItem();
    item.setId(id);/*from   w  ww.j  a v  a 2  s . co m*/
    item.setUrlToken(urlToken);
    item.setDisplayName(displayName);
    item.setDescription(description);
    item.setIsProvided(isProvided);
    item.setCreationDate(creation_date);
    item.setCreatedByUserId(createdBy);
    item.setLastUpdateDate(last_update_date);
    item.setUpdatedByUserId(updatedBy);
    item.setContentName(contentName);
    final URL zipFileUrl = getClass().getResource(zipFileName);
    final File zipFile = new File(zipFileUrl.toURI());

    FileUtils.copyFileToDirectory(zipFile, WebBonitaConstantsUtils.getInstance(tenantId).getTempFolder());

    item.setAttribute(PageDatastore.UNMAPPED_ATTRIBUTE_ZIP_FILE, zipFile.getName());
    return item;
}

From source file:org.bonitasoft.web.rest.server.datastore.page.PageDatastoreTest.java

private File deployZipFileToTarget(final String zipFileName) throws IOException, URISyntaxException {
    final File file = new File(getClass().getResource(zipFileName).toURI());
    assertThat(file).as("file should exists " + file.getAbsolutePath()).exists();
    FileUtils.copyFileToDirectory(file, new File("target"));
    return new File("target/" + zipFileName);
}