From 4879ea86dbd8e1e8d341ec5ef20aacae46fc301e Mon Sep 17 00:00:00 2001 From: Jago Gyselinck Date: Fri, 28 May 2021 18:24:49 +0200 Subject: [PATCH] Prevent artifact locations that are directories from being opened as zip files --- .../android/gms/oss/licenses/plugin/LicensesTask.groovy | 4 ++++ .../gms/oss/licenses/plugin/LicensesTaskTest.java | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/oss-licenses-plugin/src/main/groovy/com/google/android/gms/oss/licenses/plugin/LicensesTask.groovy b/oss-licenses-plugin/src/main/groovy/com/google/android/gms/oss/licenses/plugin/LicensesTask.groovy index 3df808a3..408782a1 100644 --- a/oss-licenses-plugin/src/main/groovy/com/google/android/gms/oss/licenses/plugin/LicensesTask.groovy +++ b/oss-licenses-plugin/src/main/groovy/com/google/android/gms/oss/licenses/plugin/LicensesTask.groovy @@ -138,6 +138,10 @@ class LicensesTask extends DefaultTask { } protected void addGooglePlayServiceLicenses(File artifactFile) { + if (artifactFile.isDirectory()) { + return + } + ZipFile licensesZip = new ZipFile(artifactFile) JsonSlurper jsonSlurper = new JsonSlurper() diff --git a/oss-licenses-plugin/src/test/java/com/google/android/gms/oss/licenses/plugin/LicensesTaskTest.java b/oss-licenses-plugin/src/test/java/com/google/android/gms/oss/licenses/plugin/LicensesTaskTest.java index 18c72aec..66f63a8c 100644 --- a/oss-licenses-plugin/src/test/java/com/google/android/gms/oss/licenses/plugin/LicensesTaskTest.java +++ b/oss-licenses-plugin/src/test/java/com/google/android/gms/oss/licenses/plugin/LicensesTaskTest.java @@ -282,6 +282,15 @@ public void testAddGooglePlayServiceLicenses_withoutDuplicate() throws IOExcepti assertTrue(licensesTask.licensesMap.containsKey("JSR 305")); } + @Test + public void testAddGooglePlayServiceLicenses_artifactLocationIsDirectory() throws IOException { + try { + licensesTask.addGooglePlayServiceLicenses(licensesTask.getOutputDir()); + } catch (Exception e) { + fail("This test should not throw an Exception."); + } + } + @Test public void testAppendLicense() throws IOException { licensesTask.appendLicense("license1", "test".getBytes(UTF_8));