From: Dan Timoney Date: Fri, 9 Aug 2019 21:49:29 +0000 (+0000) Subject: Merge "Add declarative acceptance tests" X-Git-Tag: 0.5.2~8 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=4001ac13397c082ee97c7ff440fa2ead5d50b421;hp=-c;p=ccsdk%2Fcds.git Merge "Add declarative acceptance tests" --- 4001ac13397c082ee97c7ff440fa2ead5d50b421 diff --combined components/parent/pom.xml index 233aa586b,034ed6098..ef030cde5 --- a/components/parent/pom.xml +++ b/components/parent/pom.xml @@@ -28,11 -28,15 +28,11 @@@ Components Parent pom - 1.8 - 1.18.0 - 3.6.1 1.0.0 27.0.1-jre 2.9.2 1.4.197 1.2.2 - 1.9 1.7 2.5.1 @@@ -81,11 -85,6 +81,6 @@@ commons-io 2.6 - - org.apache.commons - commons-compress - 1.15 - org.apache.velocity velocity @@@ -236,10 -235,6 +231,6 @@@ commons-io commons-io - - org.apache.commons - commons-compress - com.jayway.jsonpath json-path diff --combined ms/blueprintsprocessor/parent/pom.xml index 5bc4d3645,57d24a26b..ec8bfd816 --- a/ms/blueprintsprocessor/parent/pom.xml +++ b/ms/blueprintsprocessor/parent/pom.xml @@@ -27,8 -27,11 +27,8 @@@ Blueprints Processor Parent Blueprints Processor Parent - 1.8 - 1.18.0 2.2.0 0.1.55 - 3.6.1 2.2.6.RELEASE 2.2.0 1.0.0 @@@ -41,6 -44,7 +41,6 @@@ 1.4.197 1.2.2 1.7.4 - 1.9 1.1.5 2.5.1 1.7 @@@ -121,11 -125,6 +121,6 @@@ commons-io 2.6 - - org.apache.commons - commons-compress - 1.15 - org.apache.velocity velocity @@@ -530,10 -529,6 +525,6 @@@ commons-io commons-io - - org.apache.commons - commons-compress - com.jayway.jsonpath json-path diff --combined ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt index 8517be843,dcfa07feb..2f082db9c --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/utils/BluePrintArchiveUtils.kt @@@ -1,6 -1,7 +1,7 @@@ /* * Copyright © 2017-2018 AT&T Intellectual Property. * Modifications Copyright © 2019 Bell Canada. + * Modifications Copyright © 2019 Nordix Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@@ -17,17 -18,26 +18,26 @@@ package org.onap.ccsdk.cds.controllerblueprints.core.utils - import org.apache.commons.compress.archivers.zip.ZipArchiveEntry - import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream - import org.apache.commons.io.IOUtils + import com.google.common.base.Predicates import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException import org.slf4j.LoggerFactory import java.io.BufferedInputStream + import java.io.ByteArrayOutputStream import java.io.File - import java.io.FileInputStream + import java.io.FileOutputStream import java.io.IOException + import java.io.OutputStream import java.nio.charset.Charset + import java.nio.file.FileVisitResult + import java.nio.file.Files + import java.nio.file.Path + import java.nio.file.SimpleFileVisitor + import java.nio.file.attribute.BasicFileAttributes + import java.util.function.Predicate + import java.util.zip.Deflater + import java.util.zip.ZipEntry import java.util.zip.ZipFile + import java.util.zip.ZipOutputStream class BluePrintArchiveUtils { @@@ -39,17 -49,14 +49,17 @@@ * * @param source the base directory * @param destination the output filename - * @param absolute store absolute filepath (from directory) or only filename * @return True if OK */ - fun compress(source: File, destination: File, absolute: Boolean): Boolean { + fun compress(source: File, destination: File): Boolean { try { + if(!destination.parentFile.exists()) { + destination.parentFile.mkdirs() + } destination.createNewFile() - ZipArchiveOutputStream(destination).use { - recurseFiles(source, source, it, absolute) + val ignoreZipFiles = Predicate { path -> !path.endsWith(".zip") && !path.endsWith(".ZIP") } + FileOutputStream(destination).use { out -> + compressFolder(source.toPath(), out, pathFilter = ignoreZipFiles) } } catch (e: Exception) { log.error("Fail to compress folder($source) to path(${destination.path})", e) @@@ -59,40 -66,61 +69,61 @@@ } /** - * Recursive traversal to add files - * - * @param root - * @param file - * @param zaos - * @param absolute - * @throws IOException + * In-memory compress an entire folder. */ - @Throws(IOException::class) - private fun recurseFiles(root: File, file: File, zaos: ZipArchiveOutputStream, - absolute: Boolean) { - if (file.isDirectory) { - // recursive call - val files = file.listFiles() - for (fileChild in files!!) { - recurseFiles(root, fileChild, zaos, absolute) - } - } else if (!file.name.endsWith(".zip") && !file.name.endsWith(".ZIP")) { - val filename = if (absolute) { - file.absolutePath.substring(root.absolutePath.length) - } else { - file.name - } - val zae = ZipArchiveEntry(filename) - zae.size = file.length() - zaos.putArchiveEntry(zae) - FileInputStream(file).use { - IOUtils.copy(it, zaos) - it.close() - } - zaos.closeArchiveEntry() - } + fun compressToBytes(baseDir: Path, compressionLevel: Int = Deflater.NO_COMPRESSION): ByteArray { + return compressFolder(baseDir, ByteArrayOutputStream(), compressionLevel = compressionLevel) + .toByteArray() } + /** + * Compress an entire folder. + * + * @param baseDir path of base folder to be packaged. + * @param output the output stream + * @param pathFilter filter to ignore files based on its path. + * @param compressionLevel the wanted compression level. + * @param fixedModificationTime to force every entry to have this modification time. + * Useful for reproducible operations, like tests, for example. + */ + private fun compressFolder(baseDir: Path, output: T, + pathFilter: Predicate = Predicates.alwaysTrue(), + compressionLevel: Int = Deflater.DEFAULT_COMPRESSION, + fixedModificationTime: Long? = null): T + where T : OutputStream { + ZipOutputStream(output) + .apply { setLevel(compressionLevel) } + .use { zos -> + Files.walkFileTree(baseDir, object : SimpleFileVisitor() { + @Throws(IOException::class) + override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult { + if (pathFilter.test(file)) { + val zipEntry = ZipEntry(baseDir.relativize(file).toString()) + fixedModificationTime?.let { + zipEntry.time = it + } + zipEntry.time = 0; + zos.putNextEntry(zipEntry) + Files.copy(file, zos) + zos.closeEntry() + } + return FileVisitResult.CONTINUE + } + + @Throws(IOException::class) + override fun preVisitDirectory(dir: Path, attrs: BasicFileAttributes): FileVisitResult { + val zipEntry = ZipEntry(baseDir.relativize(dir).toString() + "/") + fixedModificationTime?.let { + zipEntry.time = it + } + zos.putNextEntry(zipEntry) + zos.closeEntry() + return FileVisitResult.CONTINUE + } + }) + } + return output + } fun deCompress(zipFile: File, targetPath: String): File { val zip = ZipFile(zipFile, Charset.defaultCharset()) diff --combined ms/controllerblueprints/parent/pom.xml index a16783f75,43208b914..2e9dcb243 --- a/ms/controllerblueprints/parent/pom.xml +++ b/ms/controllerblueprints/parent/pom.xml @@@ -28,12 -28,16 +28,12 @@@ Controller Blueprints Parent pom - 1.8 - 1.18.0 - 3.6.1 1.0.0 27.0.1-jre 2.9.2 1.4.197 1.2.2 1.7.4 - 1.9 2.5.1 1.7 @@@ -93,11 -97,6 +93,6 @@@ commons-io 2.6 - - org.apache.commons - commons-compress - 1.15 - org.apache.velocity velocity @@@ -293,10 -292,6 +288,6 @@@ commons-io commons-io - - org.apache.commons - commons-compress - com.jayway.jsonpath json-path