// Path: modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/es/integration/common/utils/domain/InstallationManifest.java
// public class InstallationManifest {
//     //private Collection<ResourcePackage> packages;
//     private Map<String,ResourcePackage> packages;
// 
//     public InstallationManifest() {
//         this.packages = new HashMap<>(); //new ArrayList<ResourcePackage>();
//     }
// 
//     /**
//      * Returns a string list of package names
//      * @return
//      */
//     public Collection<String> getResourcePackageNames() {
//         return packages.keySet();
//     }
// 
//     /**
//      * Returns the ResourcePackage instance with the provided package name
//      * @param packageName   The name of the package to be returned
//      * @return
//      */
//     public ResourcePackage getResourcePackage(String packageName){
//         ResourcePackage resourcePackage=null;
//         if(this.packages.containsKey(packageName)){
//                 resourcePackage = this.packages.get(packageName);
//         }
//         return resourcePackage;
//     }
// 
//     /**
//      * Returns the list of packages to be installed
//      * @return
//      */
//     public Collection<ResourcePackage> getResourcePackages() {
//         return packages.values();
//         //return packages;
//     }
// }


import org.wso2.es.integration.common.utils.domain.ResourcePackage;
import org.apache.commons.io.FileUtils;
import org.wso2.es.integration.common.utils.domain.InstallationManifest;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.es.integration.common.utils.domain.Resource;
/*
 * Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you 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.
 */

package org.wso2.es.integration.common.utils;




public class ManifestManager {

    private InstallationManifest manifest;
    private String carbonHome;
    private static final Log log = LogFactory.getLog(ManifestManager.class);

    public ManifestManager(String carbonHome) throws IOException {
        this.carbonHome = carbonHome;
        init();
    }

    /**
     * Reads the resources defined in the installation manifest and then
     * moves the resources defined
     */
    public void execute() {
        //Obtain the list of all resource packages
        Collection<String> packages = manifest.getResourcePackageNames();
        Iterator<String> packageIterator = packages.iterator();
        String packageName;
        ResourcePackage resourcePackage;
        //Go through each package and copy the resources
        while (packageIterator.hasNext()) {
            packageName = packageIterator.next();
            resourcePackage = manifest.getResourcePackage(packageName);
            copyResources(resourcePackage);
        }
    }

    public static String getManifestPath() {
        return File.separator + ManifestConstants.SAMPLE_DIR + getInstallationManifestFile();
    }

    public static String getInstallationManifestFile() {
        return File.separator + ManifestConstants.MANIFEST_FILE_NAME;
    }

    private void init() throws IOException {
        String manifestPath = this.carbonHome + ManifestManager.getManifestPath();
// Path: modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/es/integration/common/utils/domain/InstallationManifest.java
// public class InstallationManifest {
//     //private Collection<ResourcePackage> packages;
//     private Map<String,ResourcePackage> packages;
// 
//     public InstallationManifest() {
//         this.packages = new HashMap<>(); //new ArrayList<ResourcePackage>();
//     }
// 
//     /**
//      * Returns a string list of package names
//      * @return
//      */
//     public Collection<String> getResourcePackageNames() {
//         return packages.keySet();
//     }
// 
//     /**
//      * Returns the ResourcePackage instance with the provided package name
//      * @param packageName   The name of the package to be returned
//      * @return
//      */
//     public ResourcePackage getResourcePackage(String packageName){
//         ResourcePackage resourcePackage=null;
//         if(this.packages.containsKey(packageName)){
//                 resourcePackage = this.packages.get(packageName);
//         }
//         return resourcePackage;
//     }
// 
//     /**
//      * Returns the list of packages to be installed
//      * @return
//      */
//     public Collection<ResourcePackage> getResourcePackages() {
//         return packages.values();
//         //return packages;
//     }
// }


// Path: modules/integration/tests-common/integration-test-utils/src/main/java/org/wso2/es/integration/common/utils/ManifestManager.java
import org.wso2.es.integration.common.utils.domain.ResourcePackage;
import org.apache.commons.io.FileUtils;
import org.wso2.es.integration.common.utils.domain.InstallationManifest;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.es.integration.common.utils.domain.Resource;

/*
 * Copyright (c) 2005-2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you 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.
 */

package org.wso2.es.integration.common.utils;




public class ManifestManager {

    private InstallationManifest manifest;
    private String carbonHome;
    private static final Log log = LogFactory.getLog(ManifestManager.class);

    public ManifestManager(String carbonHome) throws IOException {
        this.carbonHome = carbonHome;
        init();
    }

    /**
     * Reads the resources defined in the installation manifest and then
     * moves the resources defined
     */
    public void execute() {
        //Obtain the list of all resource packages
        Collection<String> packages = manifest.getResourcePackageNames();
        Iterator<String> packageIterator = packages.iterator();
        String packageName;
        ResourcePackage resourcePackage;
        //Go through each package and copy the resources
        while (packageIterator.hasNext()) {
            packageName = packageIterator.next();
            resourcePackage = manifest.getResourcePackage(packageName);
            copyResources(resourcePackage);
        }
    }

    public static String getManifestPath() {
        return File.separator + ManifestConstants.SAMPLE_DIR + getInstallationManifestFile();
    }

    public static String getInstallationManifestFile() {
        return File.separator + ManifestConstants.MANIFEST_FILE_NAME;
    }

    private void init() throws IOException {
        String manifestPath = this.carbonHome + ManifestManager.getManifestPath();
        try {