Unzip fails with file permissions error


(Peter Butkovic) #1

I’m getting no permissions error on unzipping using copy task. However error occurs on subsequent runs only (not on the 1.st one). (I’m running Fedora linux + oracle jdk 1.7 + gradle 1.11)

My build.gradle file contents:

import java.io.File;
  apply plugin: 'java'
  repositories { mavenCentral() }
  task unpackContainer(type: Copy) {
  from { zipTree( retrieveContainer("http://download.java.net/glassfish/3.1.2.2/release/glassfish-3.1.2.2.zip") )}
  into 'build/unpack'
}
  File retrieveContainer(String url) {
  String fileName = url.substring(url.lastIndexOf("/"))
  File downloadDir = new File("downloads")
  ant.mkdir(dir : downloadDir.getAbsolutePath())
  ant.get(src: url, dest: downloadDir.getAbsolutePath(), skipexisting: "true")
  new File(downloadDir.getAbsolutePath(), fileName)
}
  test.dependsOn unpackContainer

1.st run output:

$ gradle check
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:unpackContainer
:test UP-TO-DATE
:check UP-TO-DATE
  BUILD SUCCESSFUL

every next run output:

$ gradle check --stacktrace
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:unpackContainer
  FAILURE: Build failed with an exception.
  * What went wrong:
Could not expand ZIP '/home/peterb/all/prg/oss/gradle_filepermissions_bug/downloads/glassfish-3.1.2.2.zip'.
> Could not copy zip entry /home/peterb/all/prg/oss/gradle_filepermissions_bug/downloads/glassfish-3.1.2.2.zip!glassfish3/mq/bin/imqadmin to '/home/peterb/all/prg/oss/gradle_filepermissions_bug/build/tmp/exp
andedArchives/glassfish-3.1.2.2.zip_398r0qepmdsnp2gonkcjkaui3b/glassfish3/mq/bin/imqadmin'.
  * Try:
Run with --info or --debug option to get more log output.
  * Exception is:
org.gradle.api.GradleException: Could not expand ZIP '/home/peterb/all/prg/oss/gradle_filepermissions_bug/downloads/glassfish-3.1.2.2.zip'.
        at org.gradle.api.internal.file.archive.ZipFileTree.visit(ZipFileTree.java:98)
        at org.gradle.api.internal.file.collections.FileTreeAdapter.visit(FileTreeAdapter.java:96)
        at org.gradle.api.internal.file.AbstractFileTree$FilteredFileTree.visit(AbstractFileTree.java:136)
        at org.gradle.api.internal.file.AbstractFileTree.getFiles(AbstractFileTree.java:37)
        at org.gradle.api.internal.file.CompositeFileCollection.getFiles(CompositeFileCollection.java:39)
        at org.gradle.api.internal.changedetection.state.DefaultFileSnapshotter.snapshot(DefaultFileSnapshotter.java:44)
        at org.gradle.api.internal.changedetection.rules.InputFilesStateChangeRule.create(InputFilesStateChangeRule.java:33)
                                        at org.gradle.api.internal.changedetection.rules.TaskUpToDateState.<init>(TaskUpToDateState.java:46)
        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.getStates(DefaultTaskArtifactStateRepository.java:126)
        at org.gradle.api.internal.changedetection.changes.DefaultTaskArtifactStateRepository$TaskArtifactStateImpl.isUpToDate(DefaultTaskArtifactStateRepository.java:69)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:46)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.Main.main(Main.java:37)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: org.gradle.api.GradleException: Could not copy zip entry /home/peterb/all/prg/oss/gradle_filepermissions_bug/downloads/glassfish-3.1.2.2.zip!glassfish3/mq/bin/imqadmin to '/home/peterb/all/prg/oss
/gradle_filepermissions_bug/build/tmp/expandedArchives/glassfish-3.1.2.2.zip_398r0qepmdsnp2gonkcjkaui3b/glassfish3/mq/bin/imqadmin'.
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:70)
        at org.gradle.api.internal.file.archive.ZipFileTree$DetailsImpl.getFile(ZipFileTree.java:125)
        at org.gradle.api.internal.file.AbstractFileTree$1.visitFile(AbstractFileTree.java:39)
        at org.gradle.api.internal.file.AbstractFileTree$FilteredFileTree$1.visitFile(AbstractFileTree.java:145)
        at org.gradle.api.internal.file.archive.ZipFileTree.visit(ZipFileTree.java:91)
        ... 50 more
Caused by: java.io.FileNotFoundException: /home/peterb/all/prg/oss/gradle_filepermissions_bug/build/tmp/expandedArchives/glassfish-3.1.2.2.zip_398r0qepmdsnp2gonkcjkaui3b/glassfish3/mq/bin/imqadmin (Keine Ber
echtigung)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyFile(AbstractFileTreeElement.java:86)
        at org.gradle.api.internal.file.AbstractFileTreeElement.copyTo(AbstractFileTreeElement.java:65)
        ... 54 more
    BUILD FAILED
  Total time: 9.439 secs