Here you can find the source of copyFiles()
Parameter | Description |
---|---|
IOException | an exception |
private static void copyFiles() throws Exception
//package com.java2s; /*//from w ww. j a va2 s . co m * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; public class Main { /** * Copying resource files to the carbon home location. * * @throws IOException */ private static void copyFiles() throws Exception { //Replace the existing carbon.yml file with populated carbon.yml file. copy(Paths.get("src", "test", "resources", "conf", "carbon.yml"), Paths.get(System.getProperty("carbon.home"), "conf", "carbon.yml")); //Replace the existing log4j2.xml file with populated log4j2.xml file. copy(Paths.get("src", "test", "resources", "conf", "log4j2.xml"), Paths.get("conf", "log4j2.xml")); //Replace the existing launch.properties file with populated launch.properties file. copy(Paths.get("src", "test", "resources", "conf", "osgi", "launch.properties"), Paths.get("conf", "osgi", "launch.properties")); //Copy deployment.yaml file copy(Paths .get("src", "test", "resources", "conf", "deployment.yml"), Paths.get("conf", "deployment.yml")); //Replace the existing "README.txt file with populated "README.txt file. copy(Paths.get("src", "test", "resources", "deployment", "uufapps", "README.txt"), Paths.get("deployment", "uufapps", "README.txt")); } /** * Copy files. * * @param sourcePath Path for source * @param destinationPath Path for destination * @throws IOException */ private static void copy(Path sourcePath, Path destinationPath) throws Exception { String basedir = System.getProperty("basedir"); if (basedir == null) { basedir = Paths.get(".").toString(); } sourcePath = Paths.get(basedir).resolve(sourcePath); destinationPath = getCarbonHome().resolve(destinationPath); createOutputFolderStructure(destinationPath); try { Files.copy(sourcePath, destinationPath, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new Exception("Error occurred while copying '" + sourcePath + "' file to " + destinationPath + ".", e); } } /** * Return carbon home path * * @return Path for carbon home */ private static Path getCarbonHome() { return Paths.get(System.getProperty("carbon.home")); } /** * Create the directory structure. * * @param destinationPath Path to file copying destination * @throws IOException */ private static void createOutputFolderStructure(Path destinationPath) throws Exception { Path parentPath = destinationPath.getParent(); try { Files.createDirectories(parentPath); } catch (IOException e) { throw new Exception( "Error occurred while creating the directory '" + parentPath + "'.", e); } } }