mirror of
https://github.com/corda/corda.git
synced 2024-12-20 05:28:21 +00:00
CORDA-3651: addManifest now uses separate files for reading and writing. (#6026)
* CORDA-3651: addManifest now uses separate files for reading and writing. * CORDA-3651: The jar scanning loader now closes itsself. Co-authored-by: Adel El-Beik <adelel-beik@19LDN-MAC108.local>
This commit is contained in:
parent
e5a8888232
commit
5b50ef49bc
@ -18,6 +18,7 @@ import java.io.FileOutputStream
|
|||||||
import java.lang.IllegalStateException
|
import java.lang.IllegalStateException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
|
import java.util.Arrays.asList
|
||||||
import java.util.jar.JarOutputStream
|
import java.util.jar.JarOutputStream
|
||||||
import java.util.zip.Deflater.NO_COMPRESSION
|
import java.util.zip.Deflater.NO_COMPRESSION
|
||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
@ -200,8 +201,11 @@ class CordappProviderImplTests {
|
|||||||
val duplicateJarPath = signedJarPath.parent.resolve("duplicate-" + signedJarPath.fileName)
|
val duplicateJarPath = signedJarPath.parent.resolve("duplicate-" + signedJarPath.fileName)
|
||||||
|
|
||||||
Files.copy(signedJarPath, duplicateJarPath)
|
Files.copy(signedJarPath, duplicateJarPath)
|
||||||
|
val urls = asList(signedJarPath.toUri().toURL(), duplicateJarPath.toUri().toURL())
|
||||||
|
JarScanningCordappLoader.fromJarUrls(urls, VersionInfo.UNKNOWN).use {
|
||||||
assertFailsWith<IllegalStateException> {
|
assertFailsWith<IllegalStateException> {
|
||||||
newCordappProvider(signedJarPath.toUri().toURL(), duplicateJarPath.toUri().toURL())
|
CordappProviderImpl(it, stubConfigProvider, attachmentStore).apply { start() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,8 +216,11 @@ class CordappProviderImplTests {
|
|||||||
SelfCleaningDir().use { file ->
|
SelfCleaningDir().use { file ->
|
||||||
val jarA = ContractJarTestUtils.makeTestContractJar(file.path, listOf("com.example.MyContract", "com.example.AnotherContractForA"), generateManifest = false, jarFileName = "sampleA.jar")
|
val jarA = ContractJarTestUtils.makeTestContractJar(file.path, listOf("com.example.MyContract", "com.example.AnotherContractForA"), generateManifest = false, jarFileName = "sampleA.jar")
|
||||||
val jarB = ContractJarTestUtils.makeTestContractJar(file.path, listOf("com.example.MyContract", "com.example.AnotherContractForB"), generateManifest = false, jarFileName = "sampleB.jar")
|
val jarB = ContractJarTestUtils.makeTestContractJar(file.path, listOf("com.example.MyContract", "com.example.AnotherContractForB"), generateManifest = false, jarFileName = "sampleB.jar")
|
||||||
|
val urls = asList(jarA.toUri().toURL(), jarB.toUri().toURL())
|
||||||
|
JarScanningCordappLoader.fromJarUrls(urls, VersionInfo.UNKNOWN).use {
|
||||||
assertFailsWith<IllegalStateException> {
|
assertFailsWith<IllegalStateException> {
|
||||||
newCordappProvider(jarA.toUri().toURL(), jarB.toUri().toURL())
|
CordappProviderImpl(it, stubConfigProvider, attachmentStore).apply { start() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import java.nio.file.Files
|
|||||||
import java.nio.file.NoSuchFileException
|
import java.nio.file.NoSuchFileException
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
|
||||||
import java.security.PublicKey
|
import java.security.PublicKey
|
||||||
import java.util.jar.Attributes
|
import java.util.jar.Attributes
|
||||||
import java.util.jar.JarInputStream
|
import java.util.jar.JarInputStream
|
||||||
@ -88,12 +89,13 @@ object JarSignatureTestUtils {
|
|||||||
JarInputStream(FileInputStream((this / fileName).toFile())).use(JarSignatureCollector::collectSigners)
|
JarInputStream(FileInputStream((this / fileName).toFile())).use(JarSignatureCollector::collectSigners)
|
||||||
|
|
||||||
fun Path.addManifest(fileName: String, vararg entries: Pair<Attributes.Name, String>) {
|
fun Path.addManifest(fileName: String, vararg entries: Pair<Attributes.Name, String>) {
|
||||||
|
val outputFile = this / (fileName + "Output")
|
||||||
JarInputStream(FileInputStream((this / fileName).toFile())).use { input ->
|
JarInputStream(FileInputStream((this / fileName).toFile())).use { input ->
|
||||||
val manifest = input.manifest ?: Manifest()
|
val manifest = input.manifest ?: Manifest()
|
||||||
entries.forEach { (attributeName, value) ->
|
entries.forEach { (attributeName, value) ->
|
||||||
manifest.mainAttributes[attributeName] = value
|
manifest.mainAttributes[attributeName] = value
|
||||||
}
|
}
|
||||||
val output = JarOutputStream(FileOutputStream((this / fileName).toFile()), manifest)
|
val output = JarOutputStream(FileOutputStream(outputFile.toFile()), manifest)
|
||||||
var entry = input.nextEntry
|
var entry = input.nextEntry
|
||||||
val buffer = ByteArray(1 shl 14)
|
val buffer = ByteArray(1 shl 14)
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -108,5 +110,6 @@ object JarSignatureTestUtils {
|
|||||||
}
|
}
|
||||||
output.close()
|
output.close()
|
||||||
}
|
}
|
||||||
|
Files.copy(outputFile, this / fileName, REPLACE_EXISTING)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user