Search in sources :

Example 1 with ArchiveExtractor

use of org.wso2.carbon.automation.extensions.servers.utils.ArchiveExtractor in project product-iots by wso2.

the class CarbonServerManagerExtension method setUpCarbonHome.

/**
 * Unzip carbon zip file and return the carbon home. Based on the coverage configuration in automation.xml
 * This method will inject jacoco agent to the carbon server startup scripts.
 *
 * @param carbonServerZipFile - Carbon zip file, which should be specified in test module pom
 * @return - carbonHome - carbon home
 * @throws IOException - If pack extraction fails
 */
public synchronized String setUpCarbonHome(String carbonServerZipFile) throws IOException, AutomationFrameworkException {
    if (this.process != null) {
        return this.carbonHome;
    } else {
        int indexOfZip = carbonServerZipFile.lastIndexOf(".zip");
        if (indexOfZip == -1) {
            throw new IllegalArgumentException(carbonServerZipFile + " is not a zip file");
        } else {
            String fileSeparator = File.separator.equals("\\") ? "\\" : "/";
            if (fileSeparator.equals("\\")) {
                carbonServerZipFile = carbonServerZipFile.replace("/", "\\");
            }
            String extractedCarbonDir = carbonServerZipFile.substring(carbonServerZipFile.lastIndexOf(fileSeparator) + 1, indexOfZip);
            FileManipulator.deleteDir(extractedCarbonDir);
            String extractDir = "carbontmp" + System.currentTimeMillis();
            String baseDir = System.getProperty("basedir", ".") + File.separator + "target";
            log.info("Extracting carbon zip file.. ");
            (new ArchiveExtractor()).extractFile(carbonServerZipFile, baseDir + File.separator + extractDir);
            this.carbonHome = (new File(baseDir)).getAbsolutePath() + File.separator + extractDir + File.separator + extractedCarbonDir;
            try {
                this.isCoverageEnable = Boolean.parseBoolean(this.automationContext.getConfigurationValue("//coverage"));
            } catch (XPathExpressionException var8) {
                throw new AutomationFrameworkException("Coverage configuration not found in automation.xml", var8);
            }
            if (this.isCoverageEnable) {
                this.instrumentForCoverage();
            }
            return this.carbonHome;
        }
    }
}
Also used : AutomationFrameworkException(org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ArchiveExtractor(org.wso2.carbon.automation.extensions.servers.utils.ArchiveExtractor) File(java.io.File)

Aggregations

File (java.io.File)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 AutomationFrameworkException (org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException)1 ArchiveExtractor (org.wso2.carbon.automation.extensions.servers.utils.ArchiveExtractor)1