瀏覽代碼

Remove bytebuddy library dependency

Only used to generate random strings for tests and creates too many Dependabot PRs.
Let's just use Kotlin for that.

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 年之前
父節點
當前提交
41639cf654

+ 1 - 5
app/build.gradle

@@ -328,11 +328,7 @@ dependencies {
     androidTestImplementation 'com.github.tmurakami:dexopener:2.0.5' // required to allow mocking on API 27 and older
     androidTestImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion"
     androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
-    androidTestImplementation("org.mockito:mockito-android:$mockitoVersion") {
-        exclude group: "net.bytebuddy", module: "byte-buddy-android"
-    }
-    androidTestImplementation "net.bytebuddy:byte-buddy:$byteBuddyVersion"
-    androidTestImplementation "net.bytebuddy:byte-buddy-android:$byteBuddyVersion"
+    androidTestImplementation("org.mockito:mockito-android:$mockitoVersion")
     androidTestImplementation "io.mockk:mockk-android:$mockkVersion"
     androidTestImplementation 'androidx.arch.core:core-testing:2.0.1'
     androidTestImplementation "com.facebook.testing.screenshot:core:0.15.0"

+ 4 - 5
app/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java

@@ -24,6 +24,7 @@ package com.nextcloud.client;
 
 import android.accounts.AccountManager;
 
+import com.nextcloud.test.RandomStringGenerator;
 import com.owncloud.android.AbstractOnServerIT;
 import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.OCFile;
@@ -48,8 +49,6 @@ import com.owncloud.android.utils.CsrHelper;
 import com.owncloud.android.utils.EncryptionUtils;
 import com.owncloud.android.utils.FileStorageUtils;
 
-import net.bytebuddy.utility.RandomString;
-
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Rule;
@@ -242,7 +241,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
     private void init() throws Exception {
         // create folder
         createFolder(rootEncFolder);
-        OCFile encFolder = createFolder(rootEncFolder + RandomString.make(5) + "/");
+        OCFile encFolder = createFolder(rootEncFolder + RandomStringGenerator.make(5) + "/");
 
         // encrypt it
         assertTrue(new ToggleEncryptionRemoteOperation(encFolder.getLocalId(),
@@ -259,7 +258,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
     }
 
     private OCFile createFolder(int i) {
-        String path = currentFolder.getDecryptedRemotePath() + RandomString.make(5) + "/";
+        String path = currentFolder.getDecryptedRemotePath() + RandomStringGenerator.make(5) + "/";
         Log_OC.d(this, "[" + i + "/" + actionCount + "] " + "Create folder: " + path);
 
         return createFolder(path);
@@ -300,7 +299,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
     }
 
     private void uploadFile(int i) throws IOException {
-        String fileName = RandomString.make(5) + ".txt";
+        String fileName = RandomStringGenerator.make(5) + ".txt";
 
         File file;
         if (new Random().nextBoolean()) {

+ 35 - 0
app/src/androidTest/java/com/nextcloud/test/RandomStringGenerator.kt

@@ -0,0 +1,35 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Álvaro Brey Vilas
+ * Copyright (C) 2022 Álvaro Brey Vilas
+ * Copyright (C) 2022 Nextcloud GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.test
+
+object RandomStringGenerator {
+    private const val DEFAULT_LENGTH = 8
+    private val ALLOWED_CHARACTERS = ('A'..'Z') + ('a'..'z') + ('0'..'9')
+
+    @JvmOverloads
+    @JvmStatic
+    fun make(length: Int = DEFAULT_LENGTH): String {
+        return (1..length)
+            .map { ALLOWED_CHARACTERS.random() }
+            .joinToString("")
+    }
+}

+ 2 - 3
app/src/androidTest/java/com/owncloud/android/datamodel/UploadStorageManagerTest.java

@@ -10,6 +10,7 @@ import com.nextcloud.client.account.CurrentAccountProvider;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.account.UserAccountManagerImpl;
+import com.nextcloud.test.RandomStringGenerator;
 import com.owncloud.android.AbstractIT;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.db.OCUpload;
@@ -18,8 +19,6 @@ import com.owncloud.android.files.services.NameCollisionPolicy;
 import com.owncloud.android.lib.common.accounts.AccountUtils;
 import com.owncloud.android.operations.UploadFileOperation;
 
-import net.bytebuddy.utility.RandomString;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -196,7 +195,7 @@ public class UploadStorageManagerTest extends AbstractIT {
         upload.setCreatedBy(UploadFileOperation.CREATED_BY_USER);
         upload.setUseWifiOnly(true);
         upload.setWhileChargingOnly(false);
-        upload.setFolderUnlockToken(RandomString.make(10));
+        upload.setFolderUnlockToken(RandomStringGenerator.make(10));
 
         return upload;
     }

+ 7 - 7
app/src/androidTest/java/com/owncloud/android/providers/DocumentsStorageProviderIT.kt

@@ -3,6 +3,7 @@ package com.owncloud.android.providers
 import android.provider.DocumentsContract
 import android.util.Log
 import androidx.documentfile.provider.DocumentFile
+import com.nextcloud.test.RandomStringGenerator
 import com.owncloud.android.AbstractOnServerIT
 import com.owncloud.android.R
 import com.owncloud.android.datamodel.OCFile.ROOT_PATH
@@ -17,7 +18,6 @@ import com.owncloud.android.providers.DocumentsProviderUtils.getOCFile
 import com.owncloud.android.providers.DocumentsProviderUtils.listFilesBlocking
 import com.owncloud.android.providers.DocumentsStorageProvider.DOCUMENTID_SEPARATOR
 import kotlinx.coroutines.runBlocking
-import net.bytebuddy.utility.RandomString
 import org.apache.commons.httpclient.HttpStatus
 import org.apache.commons.httpclient.methods.ByteArrayRequestEntity
 import org.apache.jackrabbit.webdav.client.methods.PutMethod
@@ -71,7 +71,7 @@ class DocumentsStorageProviderIT : AbstractOnServerIT() {
         assertListFilesEquals(emptyList(), rootDir.listFilesBlocking(context))
 
         // create first file
-        val name1 = RandomString.make()
+        val name1 = RandomStringGenerator.make()
         val type1 = "text/html"
         val file1 = rootDir.createFile(type1, name1)!!
 
@@ -88,7 +88,7 @@ class DocumentsStorageProviderIT : AbstractOnServerIT() {
         assertExistsOnServer(client, ocFile1.remotePath, true)
 
         // create second long file with long file name
-        val name2 = RandomString.make(MAX_FILE_NAME_LENGTH)
+        val name2 = RandomStringGenerator.make(MAX_FILE_NAME_LENGTH)
         val type2 = "application/octet-stream"
         val file2 = rootDir.createFile(type2, name2)!!
 
@@ -123,7 +123,7 @@ class DocumentsStorageProviderIT : AbstractOnServerIT() {
     @Test
     fun testReadWriteFiles() {
         // create random file
-        val file1 = rootDir.createFile("application/octet-stream", RandomString.make())!!
+        val file1 = rootDir.createFile("application/octet-stream", RandomStringGenerator.make())!!
         file1.assertRegularFile(size = 0L)
 
         // write random bytes to file
@@ -144,7 +144,7 @@ class DocumentsStorageProviderIT : AbstractOnServerIT() {
     @Test
     fun testCreateDeleteFolders() = runBlocking {
         // create a new folder
-        val dirName1 = RandomString.make()
+        val dirName1 = RandomStringGenerator.make()
         val dir1 = rootDir.createDirectory(dirName1)!!
         dir1.assertRegularFolder(dirName1, rootDir)
         // FIXME about a minute gets lost somewhere after CFO sets the correct time
@@ -157,7 +157,7 @@ class DocumentsStorageProviderIT : AbstractOnServerIT() {
         assertExistsOnServer(client, ocDir1.remotePath, true)
 
         // create file in folder
-        val file1 = dir1.createFile("text/html", RandomString.make())!!
+        val file1 = dir1.createFile("text/html", RandomStringGenerator.make())!!
         file1.assertRegularFile(parent = dir1)
         val ocFile1 = file1.getOCFile(storageManager)!!
         assertExistsOnServer(client, ocFile1.remotePath, true)
@@ -180,7 +180,7 @@ class DocumentsStorageProviderIT : AbstractOnServerIT() {
     @Test(timeout = 5 * 60 * 1000)
     fun testServerChangedFileContent() {
         // create random file
-        val file1 = rootDir.createFile("text/plain", RandomString.make())!!
+        val file1 = rootDir.createFile("text/plain", RandomStringGenerator.make())!!
         file1.assertRegularFile(size = 0L)
 
         val createdETag = file1.getOCFile(storageManager)!!.etagOnServer

+ 2 - 3
app/src/androidTest/java/com/owncloud/android/util/EncryptionTestIT.java

@@ -27,14 +27,13 @@ import com.google.gson.JsonElement;
 import com.google.gson.JsonParser;
 import com.google.gson.reflect.TypeToken;
 import com.nextcloud.client.RetryTestRule;
+import com.nextcloud.test.RandomStringGenerator;
 import com.owncloud.android.datamodel.DecryptedFolderMetadata;
 import com.owncloud.android.datamodel.EncryptedFolderMetadata;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.utils.CsrHelper;
 import com.owncloud.android.utils.EncryptionUtils;
 
-import net.bytebuddy.utility.RandomString;
-
 import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.io.FileUtils;
 import org.junit.Rule;
@@ -410,7 +409,7 @@ public class EncryptionTestIT {
         file.setMetadataKey(0);
         file.setAuthenticationTag(EncryptionUtils.encodeBytesToBase64String(authTag));
 
-        decryptedFolderMetadata.getFiles().put(RandomString.make(20), file);
+        decryptedFolderMetadata.getFiles().put(RandomStringGenerator.make(20), file);
     }
 
     /**

+ 0 - 1
build.gradle

@@ -10,7 +10,6 @@ buildscript {
         mockitoVersion = "4.6.1"
         mockitoKotlinVersion = "4.0.0"
         mockkVersion = "1.12.4"
-        byteBuddyVersion = "1.12.12"
         espressoVersion = "3.4.0"
         workRuntime = "2.7.1"
         fidoVersion = "4.1.0"