Install & uninstall set of files into a war


(dev) #1

I want to take a set of files (or a jar) and add them to an existing war. That may be fairly straight forward but I would also like to: 1) Write an audit log into the war with a list of the files I added or updated. 2) Read the audit log from the war at a later date so that I can uninstall those changes.

Any suggestions on how to go about this?


(Luke Daley) #2

Where do the files to add and the war come from?


(dev) #3

The files come from a zip or jar file (which is a custom dependency). So I can wrap it in a zipTree().

I’m wondering what approach to use to “record” the changes in log file which can be used to uninstall the changes later.


(Luke Daley) #4

Something like this:

task additionsManifest {
  destination = file("$buildDir/manifest.txt")
  source = zipTree(someJarFile)
    // for incremental build
  inputs.files { source }
  outputs.file { destination }
    doLast {
    destination.withPrintWriter { writer ->
      source.files.each { file ->
        writer.println(file.name)
      }
    }
  }
}
  war {
  from additionsManifest
  from additionsManifest.source
}
  task extractAdditionsManifest(type: Copy) {
  dependsOn war
      // added properties to remove duplication
  manifestFileName = "manifest.txt"
  destination = file("$buildDir/manifest")
  manifestFile file("$destination/$manifestFileName")
      from zipTree(war.archivePath)
  include manifestFileName
  into destination
}
  task extractedWar(type: Copy) {
  dependsOn extractAdditionsManifest
  from war
  doFirst {
    toExclude = extractAdditionsManifest.manifestFile.readLines()
  }
      eachFile { FileCopyDetails file ->
    if (file.name in toExclude) {
      file.exclude()
    }
  }
}

That’s untested and probably not exactly what you want, but hopefully gives you some ideas on how to start.


(dev) #5

Thanks Luke, I’ll give it go.


(dev) #6

I’ve decided to extract both the source zip and destination war to working directories. Essentially, I want to do a “diff” between the 2 directories. If a source file is new then its an “addition”, if it exists then I’ll “update” it. I see Gradle has a “sync” task but I’m guessing no “diff”.


(Luke Daley) #7

right, you’d have to roll your own.