# Install & uninstall set of files into a war

**URL:** <https://discuss.gradle.org/t/install-uninstall-set-of-files-into-a-war/6751>\
**Category:** Old Forum Archive\
**Created:** [January 25, 2012, 4:28pm UTC](https://discuss.gradle.org/t/install-uninstall-set-of-files-into-a-war/6751 "2012-01-25T16:28:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![covolution](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@covolution](https://discuss.gradle.org/u/covolution)\
**Post date:** [January 25, 2012, 4:28pm UTC](https://discuss.gradle.org/t/install-uninstall-set-of-files-into-a-war/6751/1 "2012-01-25T16:28:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [January 26, 2012, 3:43pm UTC](https://discuss.gradle.org/t/install-uninstall-set-of-files-into-a-war/6751/2 "2012-01-26T15:43:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![covolution](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@covolution](https://discuss.gradle.org/u/covolution)\
**Post date:** [January 26, 2012, 4:09pm UTC](https://discuss.gradle.org/t/install-uninstall-set-of-files-into-a-war/6751/3 "2012-01-26T16:09:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [January 26, 2012, 4:26pm UTC](https://discuss.gradle.org/t/install-uninstall-set-of-files-into-a-war/6751/4 "2012-01-26T16:26:00Z")

</div>

Something _like_ this:

```gradle
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.

---

<div class="post-metadata">

**Author:** ![covolution](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@covolution](https://discuss.gradle.org/u/covolution)\
**Post date:** [January 26, 2012, 4:40pm UTC](https://discuss.gradle.org/t/install-uninstall-set-of-files-into-a-war/6751/5 "2012-01-26T16:40:00Z")

</div>

Thanks Luke, I’ll give it go.

---

<div class="post-metadata">

**Author:** ![covolution](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@covolution](https://discuss.gradle.org/u/covolution)\
**Post date:** [January 26, 2012, 5:40pm UTC](https://discuss.gradle.org/t/install-uninstall-set-of-files-into-a-war/6751/6 "2012-01-26T17:40:00Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [January 26, 2012, 5:41pm UTC](https://discuss.gradle.org/t/install-uninstall-set-of-files-into-a-war/6751/7 "2012-01-26T17:41:00Z")

</div>

right, you’d have to roll your own.
