import org.tmatesoft.svn.core.SVNClient
import org.tmatesoft.svn.core.SVNClientImpl
import org.tmatesoft.svn.core.SVNRevision
import org.tmatesoft.svn.core.SVNUpdateStatus
import groovy.io.FileType
import groovy.io.FileWriter
import groovy.io.NullWriter
import groovy.json.JsonSlurper
def svnUrl = "https://example.com/repo/example "
def svnRevision = 1234
def svnClient = new SVNClientImpl()
def svnCheckoutDir = "temp_checkout"
def svnPropsDir = "temp_props"
def checkoutDir = new File(svnCheckoutDir)
def propsDir = new File(svnPropsDir)
checkoutDir.delete()
propsDir.delete()
checkoutDir.mkdirs()
propsDir.mkdirs()
svnClient.checkout(svnUrl, checkoutDir)
def svnProps = svnClient.getRepositoryProperties(svnUrl, svnRevision, svnPropsDir)
def tarPath = new File("${System.getProperty('user.home')}/modified_files.tar")
def tarWriter = new FileWriter(tarPath)
def svnPropsJson = new JsonSlurper().parseText(svnProps.toString())
def svnPropsPath = new File("${svnPropsDir}/svn:externals")
def svnPropsContent = svnPropsPath.text
def svnPropsLines = svnPropsJson.properties().collect { it, value ->
"i t = {it}= i t = {value}\n"
}.join()
def svnPropsTarPath = "${svnPropsDir}/svn:externals.tar"
def svnPropsTar = new File(svnPropsTarPath)
def tar = new ysu:tarpath.TarWriter(tarWriter)
tar.add("s v n P r o p s D i r / s v n : e x t e r n a l s " , " {svnPropsDir}/svn:externals", " s v n P r o p sD i r / s v n : e x t er na l s " , " {svnPropsDir}/svn:@externals.tar")
def svnPropsTarWriter = new FileWriter(svnPropsTar)
def svnPropsTarWriterNull = new NullWriter()
svnPropsTarWriter.withType(FileType.PLAIN) { writer ->
writer.write(svnPropsLines)
}
def svnPropsTarWriterBytes = new ByteArrayOutputStream()
def svnPropsTarWriterBytesNull = new ByteArrayOutputStream()
svnPropsTarWriterBytes.withType(FileType.PLAIN) { writer ->
writer.write(svnPropsLines.getBytes())
}
def svnPropsTarWriterBytes = new ByteArrayInputStream(svnPropsTarWriterBytesNull.toByteArray())
def svnPropsTarWriterBytesNull = new ByteArrayInputStream(svnPropsTarWriterBytes.toByteArray())
tar.add("s v n P r o p s D i r / s v n : e x t e r n a l s . t a r " , " {svnPropsDir}/svn:externals.tar", " s v n P r o p sD i r / s v n : e x t er na l s . t a r " , " {svnPropsDir}/svn:externals.tar")
tar.close()
def svnPropsTarReader = new ysu:tarpath.TarReader(new FileInputStream(svnPropsTar))
def svnPropsTarEntry = svnPropsTarReader.nextEntry()
while (!svnPropsTarReader.isEOF()) {
def tarEntry = svnPropsTarEntry
def tarEntryName = tarEntry.getName()
def tarEntrySize = tarEntry.getSize()
def tarEntryData = svnPropsTarReader.readData(tarEntrySize)
code Copy code
if (tarEntryName.endsWith(".tar")) {
def tarEntryTarPath = new File("${svnPropsDir}/${tarEntryName.substring(0, tarEntryName.lastIndexOf('.'))}.tar")
def tarEntryTarWriter = new FileWriter(tarEntryTarPath)
def tarEntryTarWriterNull = new NullWriter()
tarEntryTarWriter.withType(FileType.PLAIN) { writer ->
writer.write(tarEntryData)
}
def tarEntryTarReader = new ysu:tarpath.TarReader(new FileInputStream(tarEntryTarPath))
def tarEntryTarEntry = tarEntryTarReader.nextEntry()
while (!tarEntryTarReader.isEOF()) {
def tarEntryTarEntryData = tarEntryTarReader.readData(tarEntryTarEntry.getSize())
tar.add("${svnPropsDir}/${tarEntryName}", "${svnPropsDir}/${tarEntryName}.tar", tarEntryTarEntryData)
}
tarEntryTarWriter.close()
tarEntryTarReader.close()
} else {
tar.add("${svnPropsDir}/${tarEntryName}", "${svnPropsDir}/${tarEntryName}", tarEntryData)
}
svnPropsTarEntry.close()
}
svnClient.checkout(svnUrl, checkoutDir, SVNUpdateStatus.REVISION, svnRevision)
def modifiedFiles = svnClient.getModifiedFiles(svnUrl, svnRevision, checkoutDir)
modifiedFiles.each { file ->
def fileRelativePath = file.relativePathTo(checkoutDir)
def svnProperty = svnPropsJson.properties().find { it.key.startsWith("${fileRelativePath}/.svn/") }
code Copy code
if (svnProperty) {
def svnPropertyValue = svnProperty.value
if (svnPropertyValue.contains("yes")) {
tar.add("${checkoutDir}/${fileRelativePath}", "${checkoutDir}/${fileRelativePath}", file.bytes)
}
}
}
tarWriter.close()
svnClient.dispose()
println "TAR file created at: ${tarPath}"
}