Skip to content

Optimized module dependencies #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

/**
Expand Down
4 changes: 0 additions & 4 deletions utbot-framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {}

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion utbot-junit-contest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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)
}

Expand Down
1 change: 0 additions & 1 deletion utbot-sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down