diff --git a/gradle.properties b/gradle.properties index cc0c15f08d..61ecfd8f7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,6 @@ collections_version=0.3.4 intellij_plugin_version=0.6.4 jacoco_version=0.8.5 commons_lang_version=3.11 -commons_io_version=2.8.0 kotlin_logging_version=1.8.3 ktor_version=1.4.1 clikt_version=3.2.0 diff --git a/utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt b/utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt index cab4e7ff33..45e1a0248c 100644 --- a/utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt +++ b/utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt @@ -223,6 +223,15 @@ object FileUtil { this.parentFile.mkdirs() this.createNewFile() } + + // https://stackoverflow.com/a/68822715 + fun byteCountToDisplaySize(bytes: Long): String = + when { + bytes >= 1 shl 30 -> "%.1f GB".format(bytes / (1 shl 30)) + bytes >= 1 shl 20 -> "%.1f MB".format(bytes / (1 shl 20)) + bytes >= 1 shl 10 -> "%.0f kB".format(bytes / (1 shl 10)) + else -> "$bytes bytes" + } } /** diff --git a/utbot-framework/build.gradle b/utbot-framework/build.gradle index 526110da95..211b9f1132 100644 --- a/utbot-framework/build.gradle +++ b/utbot-framework/build.gradle @@ -37,16 +37,12 @@ dependencies { testImplementation project(':utbot-analytics') // used for testing code generation - testImplementation group: 'commons-io', name: 'commons-io', version: commons_io_version testImplementation group: 'junit', name: 'junit', version: junit4_version testImplementation group: 'org.junit.platform', name: 'junit-platform-console-standalone', version: junit4_platform_version testImplementation group: 'org.mockito', name: 'mockito-core', version: mockito_version testImplementation group: 'org.testng', name: 'testng', version: testng_version testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockito_inline_version - testCompile group: 'org.mockito', name: 'mockito-inline', version: mockito_inline_version - testCompile group: 'org.apache.logging.log4j', name: 'log4j-core', version: log4j2_version - z3native group: 'com.microsoft.z3', name: 'z3-native-win64', version: z3_version, ext: 'zip' z3native group: 'com.microsoft.z3', name: 'z3-native-linux64', version: z3_version, ext: 'zip' z3native group: 'com.microsoft.z3', name: 'z3-native-osx', version: z3_version, ext: 'zip' diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/selectors/strategies/GraphViz.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/selectors/strategies/GraphViz.kt index 057fc70977..489b665f7c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/selectors/strategies/GraphViz.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/selectors/strategies/GraphViz.kt @@ -1,24 +1,23 @@ package org.utbot.engine.selectors.strategies +import mu.KotlinLogging +import org.utbot.common.FileUtil.createNewFileWithParentDirectories import org.utbot.engine.CALL_DECISION_NUM import org.utbot.engine.Edge import org.utbot.engine.ExecutionState import org.utbot.engine.InterProceduralUnitGraph +import org.utbot.engine.isLibraryNonOverriddenClass import org.utbot.engine.isReturn import org.utbot.engine.selectors.PathSelector import org.utbot.engine.stmts import org.utbot.framework.UtSettings.copyVisualizationPathToClipboard +import soot.jimple.Stmt +import soot.toolkits.graph.ExceptionalUnitGraph import java.awt.Toolkit import java.awt.datatransfer.StringSelection import java.io.FileWriter import java.nio.file.Files import java.nio.file.Paths -import mu.KotlinLogging -import org.apache.commons.io.FileUtils -import org.utbot.engine.isLibraryNonOverriddenClass -import org.utbot.engine.isOverridden -import soot.jimple.Stmt -import soot.toolkits.graph.ExceptionalUnitGraph private val logger = KotlinLogging.logger {} @@ -51,10 +50,17 @@ class GraphViz( val classLoader = GraphViz::class.java.classLoader for (file in requiredFileNames) { - FileUtils.copyInputStreamToFile( - classLoader.getResourceAsStream("html/$file"), - Paths.get(graphVisDirectory.toString(), file).toFile() - ) + classLoader.getResourceAsStream("html/$file").use { inputStream -> + val path = Paths.get(graphVisDirectory.toString(), file) + val targetFile = path.toFile() + targetFile.createNewFileWithParentDirectories() + + targetFile.outputStream().use { targetOutputStream -> + inputStream?.copyTo(targetOutputStream) ?: logger.error { + "Could not start a visualization because of missing resource html/$file" + } + } + } } FileWriter(graphJs).use { it.write( diff --git a/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/CompilationAndRunUtils.kt b/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/CompilationAndRunUtils.kt index abe6b7805d..ac27d92c7b 100644 --- a/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/CompilationAndRunUtils.kt +++ b/utbot-framework/src/test/kotlin/org/utbot/framework/codegen/CompilationAndRunUtils.kt @@ -4,7 +4,7 @@ import org.utbot.framework.plugin.api.CodegenLanguage import java.io.File import java.nio.file.Path import mu.KotlinLogging -import org.apache.commons.io.FileUtils +import org.utbot.common.FileUtil data class ClassUnderTest( val testClassSimpleName: String, @@ -29,7 +29,7 @@ fun writeTest( val targetDir = classUnderTest.generatedTestFile.parentFile targetDir.mkdirs() logger.info { - "File size for ${classUnderTest.testClassSimpleName}: ${FileUtils.byteCountToDisplaySize(testContents.length.toLong())}" + "File size for ${classUnderTest.testClassSimpleName}: ${FileUtil.byteCountToDisplaySize(testContents.length.toLong())}" } classUnderTest.generatedTestFile.writeText(testContents) return classUnderTest.generatedTestFile diff --git a/utbot-junit-contest/build.gradle b/utbot-junit-contest/build.gradle index 82dd1e1cb9..92c678f76c 100644 --- a/utbot-junit-contest/build.gradle +++ b/utbot-junit-contest/build.gradle @@ -56,7 +56,6 @@ dependencies { implementation "com.github.UnitTestBot:soot:${soot_commit_hash}" implementation group: 'org.apache.commons', name: 'commons-exec', version: '1.2' - implementation group: 'commons-io', name: 'commons-io', version: commons_io_version implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlin_logging_version implementation group: 'org.jsoup', name: 'jsoup', version: '1.6.2' testImplementation fileTree(dir: 'src/main/resources/projects/', include: '*/*.jar') diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt index 4b563a31c4..0a2d36f670 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt @@ -16,7 +16,7 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withTimeoutOrNull import kotlinx.coroutines.yield import mu.KotlinLogging -import org.apache.commons.io.FileUtils +import org.utbot.common.FileUtil import org.utbot.common.bracket import org.utbot.common.info import org.utbot.engine.EngineController @@ -453,7 +453,7 @@ private fun prepareClass(kotlinClass: KClass<*>, methodNameFilter: String?): Lis } fun writeTestClass(cut: ClassUnderTest, testSetsAsString: String) { - logger.info { "File size for ${cut.testClassSimpleName}: ${FileUtils.byteCountToDisplaySize(testSetsAsString.length.toLong())}" } + logger.info { "File size for ${cut.testClassSimpleName}: ${FileUtil.byteCountToDisplaySize(testSetsAsString.length.toLong())}" } cut.generatedTestFile.parentFile.mkdirs() cut.generatedTestFile.writeText(testSetsAsString, charset) } diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/TestClassWriter.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/TestClassWriter.kt index 645d9339d3..53b6c7bff2 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/TestClassWriter.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/TestClassWriter.kt @@ -4,7 +4,7 @@ import org.utbot.framework.codegen.Import import org.utbot.framework.codegen.StaticImport import org.utbot.framework.plugin.api.UtMethod import mu.KotlinLogging -import org.apache.commons.io.FileUtils +import org.utbot.common.FileUtil private val logger = KotlinLogging.logger {} @@ -91,7 +91,7 @@ class TestClassWriter( insert(lastIndexOf("}"), tests) insert(lastIndexOf("}"), utils) } - logger.info { "File size for ${cut.testClassSimpleName}: ${FileUtils.byteCountToDisplaySize(codeBuilder.length.toLong())}" } + logger.info { "File size for ${cut.testClassSimpleName}: ${FileUtil.byteCountToDisplaySize(codeBuilder.length.toLong())}" } cut.generatedTestFile.writeText(codeBuilder.toString(), charset) } diff --git a/utbot-sample/build.gradle b/utbot-sample/build.gradle index 7a5d55d38b..add9e2f5c1 100644 --- a/utbot-sample/build.gradle +++ b/utbot-sample/build.gradle @@ -20,7 +20,6 @@ dependencies { // testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.5.13' testImplementation group: 'org.mockito', name: 'mockito-inline', version: '4.0.0' - testCompile "org.mockito:mockito-inline:+" } java {