diff --git a/agent/src/main/java/com/teamscale/jacoco/agent/options/AgentOptionsParser.java b/agent/src/main/java/com/teamscale/jacoco/agent/options/AgentOptionsParser.java index 60327a3e..363319eb 100644 --- a/agent/src/main/java/com/teamscale/jacoco/agent/options/AgentOptionsParser.java +++ b/agent/src/main/java/com/teamscale/jacoco/agent/options/AgentOptionsParser.java @@ -489,7 +489,7 @@ private int parseInt(String key, String value) throws AgentOptionParseException * deterministic, i.e. if you run the pattern twice and get the same set of files, the same file will be picked each * time. */ - public Path parsePath(String optionName, String pattern) throws AgentOptionParseException { + public static Path parsePath(FilePatternResolver filePatternResolver, String optionName, String pattern) throws AgentOptionParseException { try { return filePatternResolver.parsePath(optionName, pattern); } catch (IOException e) { diff --git a/agent/src/main/java/com/teamscale/jacoco/agent/upload/teamscale/TeamscaleConfig.java b/agent/src/main/java/com/teamscale/jacoco/agent/upload/teamscale/TeamscaleConfig.java index bbfd50da..013391fe 100644 --- a/agent/src/main/java/com/teamscale/jacoco/agent/upload/teamscale/TeamscaleConfig.java +++ b/agent/src/main/java/com/teamscale/jacoco/agent/upload/teamscale/TeamscaleConfig.java @@ -1,11 +1,5 @@ package com.teamscale.jacoco.agent.upload.teamscale; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.util.jar.JarInputStream; -import java.util.jar.Manifest; - import com.teamscale.client.CommitDescriptor; import com.teamscale.client.StringUtils; import com.teamscale.client.TeamscaleServer; @@ -15,6 +9,14 @@ import com.teamscale.report.util.BashFileSkippingInputStream; import com.teamscale.report.util.ILogger; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.jar.JarInputStream; +import java.util.jar.Manifest; + +import static com.teamscale.jacoco.agent.options.AgentOptionsParser.parsePath; + /** Config necessary for direct Teamscale upload. */ public class TeamscaleConfig { @@ -44,7 +46,7 @@ public TeamscaleConfig(ILogger logger, FilePatternResolver filePatternResolver) * @return true if it has successfully processed the given option. */ public boolean handleTeamscaleOptions(TeamscaleServer teamscaleServer, - String key, String value) + String key, String value) throws AgentOptionParseException { switch (key) { case "teamscale-server-url": @@ -66,12 +68,8 @@ public boolean handleTeamscaleOptions(TeamscaleServer teamscaleServer, teamscaleServer.commit = parseCommit(value); return true; case TEAMSCALE_COMMIT_MANIFEST_JAR_OPTION: - try { - teamscaleServer.commit = getCommitFromManifest( - filePatternResolver.parsePath(key, value).toFile()); - } catch (IOException e) { - throw new AgentOptionParseException(e); - } + teamscaleServer.commit = getCommitFromManifest( + parsePath(filePatternResolver, key, value).toFile()); return true; case "teamscale-message": teamscaleServer.setMessage(value); @@ -83,12 +81,8 @@ public boolean handleTeamscaleOptions(TeamscaleServer teamscaleServer, teamscaleServer.repository = value; return true; case TEAMSCALE_REVISION_MANIFEST_JAR_OPTION: - try { - teamscaleServer.revision = getRevisionFromManifest( - filePatternResolver.parsePath(key, value).toFile()); - } catch (IOException e) { - throw new AgentOptionParseException(e); - } + teamscaleServer.revision = getRevisionFromManifest( + parsePath(filePatternResolver, key, value).toFile()); return true; default: return false;