Skip to content

Commit 5bbdabb

Browse files
committed
TS-38628 Rework
1 parent 124834d commit 5bbdabb

47 files changed

Lines changed: 157 additions & 224 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agent/src/main/kotlin/com/teamscale/jacoco/agent/Agent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Agent(options: AgentOptions, instrumentation: Instrumentation?) : AgentBas
8282
try {
8383
val properties = FileSystemUtils.readProperties(file)
8484
val coverageFile = CoverageFile(
85-
File(StringUtils.stripSuffix(file.absolutePath, TeamscaleUploader.RETRY_UPLOAD_FILE_SUFFIX))
85+
File(file.absolutePath.removeSuffix(TeamscaleUploader.RETRY_UPLOAD_FILE_SUFFIX))
8686
)
8787

8888
if (uploader is IUploadRetry) {

agent/src/main/kotlin/com/teamscale/jacoco/agent/AgentBase.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ import java.lang.management.ManagementFactory
2222
*/
2323
abstract class AgentBase(
2424
/** The agent options. */
25-
@JvmField var options: AgentOptions
25+
var options: AgentOptions
2626
) {
2727
/** The logger. */
2828
val logger: Logger = LoggingUtils.getLogger(this)
2929

30-
/** Controls the JaCoCo runtime. */
31-
@JvmField
30+
/** Controls the JaCoCo runtime. */
3231
val controller: JacocoRuntimeController
3332

3433
private lateinit var server: Server

agent/src/main/kotlin/com/teamscale/jacoco/agent/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ object Main {
7676
private class DefaultArguments {
7777
/** Shows the help message. */
7878
@Parameter(names = ["--help"], help = true, description = "Shows all available command line arguments.")
79-
val help = false
79+
var help = false
8080
}
8181
}

agent/src/main/kotlin/com/teamscale/jacoco/agent/PreMain.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ object PreMain {
4646
/**
4747
* Entry point for the agent, called by the JVM.
4848
*/
49-
@JvmStatic
5049
@Throws(Exception::class)
51-
fun premain(options: String, instrumentation: Instrumentation?) {
50+
@JvmStatic
51+
fun premain(options: String?, instrumentation: Instrumentation?) {
5252
if (System.getProperty(LOCKING_SYSTEM_PROPERTY) != null) return
5353
System.setProperty(LOCKING_SYSTEM_PROPERTY, "true")
5454

5555
val environmentConfigId = System.getenv(CONFIG_ID_ENVIRONMENT_VARIABLE)
5656
val environmentConfigFile = System.getenv(CONFIG_FILE_ENVIRONMENT_VARIABLE)
57-
if (StringUtils.isEmpty(options) && environmentConfigId == null && environmentConfigFile == null) {
57+
if (options.isNullOrEmpty() && environmentConfigId == null && environmentConfigFile == null) {
5858
// profiler was registered globally, and no config was set explicitly by the user, thus ignore this process
5959
// and don't profile anything
6060
return
@@ -81,8 +81,9 @@ object PreMain {
8181
// Unregister the profiler from Teamscale.
8282
agentOptions?.configurationViaTeamscale?.unregisterProfiler()
8383

84-
// Configuration errors must be visible to the user; let the JVM report them.
85-
throw e
84+
// Don't crash the profiled application due to a configuration error
85+
// (see TS-43260). The error has already been logged in getAndApplyAgentOptions.
86+
return
8687
} catch (_: AgentOptionReceiveException) {
8788
// When Teamscale is not available, we don't want to fail hard to still allow for testing even if no
8889
// coverage is collected (see TS-33237)
@@ -131,7 +132,7 @@ object PreMain {
131132

132133
@Throws(AgentOptionParseException::class, IOException::class, AgentOptionReceiveException::class)
133134
private fun getAndApplyAgentOptions(
134-
options: String,
135+
options: String?,
135136
environmentConfigId: String?,
136137
environmentConfigFile: String?
137138
): Pair<AgentOptions, List<Exception>> {
@@ -291,7 +292,7 @@ object PreMain {
291292
val configFile = FilePatternResolver(delayedLogger).parsePath(
292293
AgentOptionsParser.CONFIG_FILE_OPTION, configFileValue
293294
).toFile()
294-
loggingConfigLine = FileSystemUtils.readLinesUTF8(configFile)
295+
loggingConfigLine = configFile.readLines()
295296
.firstOrNull { it.startsWith(AgentOptionsParser.LOGGING_CONFIG_OPTION + "=") }
296297
} catch (e: IOException) {
297298
delayedLogger.error("Failed to load configuration from $configFileValue: ${e.message}", e)

agent/src/main/kotlin/com/teamscale/jacoco/agent/ResourceBase.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import javax.ws.rs.core.Response
1515
*/
1616
abstract class ResourceBase {
1717
/** The logger. */
18-
@JvmField
1918
protected val logger: Logger = LoggingUtils.getLogger(this)
2019

2120
companion object {

agent/src/main/kotlin/com/teamscale/jacoco/agent/commandline/Validator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ class Validator {
1515
try {
1616
validation.validate()
1717
} catch (e: Exception) {
18-
e.message?.let { messages.add(it) }
18+
messages.add(e.message ?: "No error message")
1919
} catch (e: AssertionError) {
20-
e.message?.let { messages.add(it) }
20+
messages.add(e.message ?: "No error message")
2121
}
2222
}
2323

agent/src/main/kotlin/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatingTransformer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class GitPropertiesLocatingTransformer(
2020

2121
override fun transform(
2222
classLoader: ClassLoader?,
23-
className: String,
23+
className: String?,
2424
aClass: Class<*>?,
2525
protectionDomain: ProtectionDomain?,
2626
classFileContent: ByteArray?
@@ -30,7 +30,7 @@ class GitPropertiesLocatingTransformer(
3030
return null
3131
}
3232

33-
if (className.isEmpty() || !locationIncludeFilter.isIncluded(className)) {
33+
if (className.isNullOrEmpty() || !locationIncludeFilter.isIncluded(className)) {
3434
// only search in jar files of included classes
3535
return null
3636
}

agent/src/main/kotlin/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorUtils.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ object GitPropertiesLocatorUtils {
8282
* @throws IOException If reading the jar file fails.
8383
* @throws InvalidGitPropertiesException If a git.properties file is found but it is malformed.
8484
*/
85-
@JvmStatic
8685
@Throws(IOException::class, InvalidGitPropertiesException::class)
8786
fun getCommitInfoFromGitProperties(
8887
file: File,
@@ -103,7 +102,6 @@ object GitPropertiesLocatorUtils {
103102
* @throws URISyntaxException under certain circumstances if parsing the URL fails. This should be treated the same
104103
* as a null search result but the exception is preserved so it can be logged.
105104
*/
106-
@JvmStatic
107105
@Throws(
108106
URISyntaxException::class,
109107
IOException::class,
@@ -167,7 +165,8 @@ object GitPropertiesLocatorUtils {
167165
// vfs:/content/helloworld.war/WEB-INF/classes
168166
// Next, we try to extract the artefact URL from it, e.g., vfs:/content/helloworld.war
169167
val artefactUrl = extractArtefactUrl(jarOrClassFolderUrl)
170-
val virtualFile = URI.create(artefactUrl).toURL().openConnection().getContent()
168+
val path = artefactUrl.substringAfter(':')
169+
val virtualFile = URI("vfs", null, path, null).toURL().openConnection().getContent()
171170
// obtain the physical location of the class file. It is created on demand in <jboss-installation-dir>/standalone/tmp/vfs
172171
val getPhysicalFileMethod = virtualFile.javaClass.getMethod("getPhysicalFile")
173172
val file = getPhysicalFileMethod.invoke(virtualFile) as File
@@ -209,7 +208,6 @@ object GitPropertiesLocatorUtils {
209208
* @throws IOException If reading the jar file fails.
210209
* @throws InvalidGitPropertiesException If a git.properties file is found but it is malformed.
211210
*/
212-
@JvmStatic
213211
@Throws(IOException::class, InvalidGitPropertiesException::class)
214212
fun getProjectRevisionsFromGitProperties(
215213
file: File,
@@ -237,7 +235,6 @@ object GitPropertiesLocatorUtils {
237235
* Returns pairs of paths to git.properties files and their parsed properties found in the provided folder or
238236
* archive file. Nested jar files will also be searched recursively if specified.
239237
*/
240-
@JvmStatic
241238
@Throws(IOException::class)
242239
fun findGitPropertiesInFile(
243240
file: File, isJarFile: Boolean, recursiveSearch: Boolean
@@ -328,8 +325,6 @@ object GitPropertiesLocatorUtils {
328325
* Returns pairs of paths to git.properties files and their parsed properties found in the provided JarInputStream.
329326
* Nested jar files will also be searched recursively if specified.
330327
*/
331-
@JvmStatic
332-
@JvmOverloads
333328
@Throws(IOException::class)
334329
fun findGitPropertiesInArchive(
335330
inputStream: JarInputStream,
@@ -379,7 +374,6 @@ object GitPropertiesLocatorUtils {
379374
* [GIT_PROPERTIES_DEFAULT_MAVEN_DATE_FORMAT]. An additional format can be given with
380375
* `dateTimeFormatter`
381376
*/
382-
@JvmStatic
383377
@Throws(InvalidGitPropertiesException::class)
384378
fun getCommitInfoFromGitProperties(
385379
gitProperties: Properties, entryName: String?, jarFile: File?,

agent/src/main/kotlin/com/teamscale/jacoco/agent/configuration/ConfigurationViaTeamscale.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ class ConfigurationViaTeamscale(
9797
* Tries to retrieve the profiler configuration from Teamscale. In case retrieval fails the method throws a
9898
* [AgentOptionReceiveException].
9999
*/
100-
@JvmStatic
101100
@Throws(AgentOptionReceiveException::class)
102101
fun retrieve(
103102
logger: ILogger,

agent/src/main/kotlin/com/teamscale/jacoco/agent/convert/ConvertCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class ConvertCommand : ICommand {
102102
names = ["--split-after", "-s"], required = false, arity = 1, description = "After how many tests " +
103103
"testwise coverage should be split into multiple reports (Default is 5000)."
104104
)
105-
val splitAfter = 5000
105+
var splitAfter = 5000
106106

107107
@Throws(IOException::class)
108108
fun getClassDirectoriesOrZips(): List<File> = ClasspathUtils

0 commit comments

Comments
 (0)