Skip to content

Commit c963c65

Browse files
authored
Merge pull request #770 from cqse/ts/44092_remove_teamscale_commons
TS-44092 Remove teamscale commons
2 parents 03c0625 + 4fba6c8 commit c963c65

61 files changed

Lines changed: 906 additions & 522 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.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ We use [semantic versioning](http://semver.org/):
66

77
# Next version
88
- [breaking fix] _teamscale-gradle-plugin_: Adjusted to breaking API changes in Gradle 9.0
9+
- [feature] Reduced dependencies and hence the size of all artifacts
910

1011
# 35.2.2
1112
- [fix] _teamscale-gradle-plugin_: TeamscaleUpload task did not properly validate `revision` argument

agent/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ dependencies {
5151
implementation(libs.logback.classic)
5252

5353
implementation(libs.jcommander)
54-
implementation(libs.teamscaleLibCommons)
5554

5655
implementation(libs.retrofit.core)
5756

5857
implementation(libs.jackson.databind)
58+
implementation(libs.jetbrains.annotations)
5959

6060
testImplementation(project(":tia-client"))
6161
testImplementation(libs.retrofit.converter.jackson)

agent/src/main/java/com/teamscale/jacoco/agent/Agent.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,25 @@
55
+-------------------------------------------------------------------------*/
66
package com.teamscale.jacoco.agent;
77

8+
import com.teamscale.client.FileSystemUtils;
9+
import com.teamscale.client.StringUtils;
810
import com.teamscale.jacoco.agent.options.AgentOptions;
911
import com.teamscale.jacoco.agent.upload.IUploadRetry;
1012
import com.teamscale.jacoco.agent.upload.IUploader;
1113
import com.teamscale.jacoco.agent.upload.UploaderException;
1214
import com.teamscale.jacoco.agent.util.AgentUtils;
1315
import com.teamscale.jacoco.agent.util.Benchmark;
14-
import com.teamscale.jacoco.agent.util.FileSystemUtilsClone;
1516
import com.teamscale.jacoco.agent.util.Timer;
1617
import com.teamscale.report.jacoco.CoverageFile;
1718
import com.teamscale.report.jacoco.EmptyReportException;
1819
import com.teamscale.report.jacoco.JaCoCoXmlReportGenerator;
1920
import com.teamscale.report.jacoco.dump.Dump;
20-
import org.conqat.lib.commons.string.StringUtils;
2121
import org.glassfish.jersey.server.ResourceConfig;
2222
import org.glassfish.jersey.server.ServerProperties;
2323

2424
import java.io.File;
2525
import java.io.IOException;
26-
import java.io.InputStreamReader;
2726
import java.lang.instrument.Instrumentation;
28-
import java.nio.charset.StandardCharsets;
2927
import java.nio.file.Files;
3028
import java.nio.file.Path;
3129
import java.time.Duration;
@@ -91,7 +89,7 @@ private void retryUnsuccessfulUploads(AgentOptions options, IUploader uploader)
9189
return;
9290
}
9391

94-
List<File> reuploadCandidates = FileSystemUtilsClone.listFilesRecursively(parentPath.toFile(),
92+
List<File> reuploadCandidates = FileSystemUtils.listFilesRecursively(parentPath.toFile(),
9593
filepath -> filepath.getName().endsWith(RETRY_UPLOAD_FILE_SUFFIX));
9694
for (File file : reuploadCandidates) {
9795
reuploadCoverageFromPropertiesFile(file, uploader);
@@ -100,10 +98,8 @@ private void retryUnsuccessfulUploads(AgentOptions options, IUploader uploader)
10098

10199
private void reuploadCoverageFromPropertiesFile(File file, IUploader uploader) {
102100
logger.info("Retrying previously unsuccessful coverage upload for file {}.", file);
103-
try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(file.toPath()),
104-
StandardCharsets.UTF_8)) {
105-
Properties properties = new Properties();
106-
properties.load(reader);
101+
try {
102+
Properties properties = FileSystemUtils.readProperties(file);
107103
CoverageFile coverageFile = new CoverageFile(
108104
new File(StringUtils.stripSuffix(file.getAbsolutePath(), RETRY_UPLOAD_FILE_SUFFIX)));
109105

agent/src/main/java/com/teamscale/jacoco/agent/Main.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import com.beust.jcommander.JCommander.Builder;
55
import com.beust.jcommander.Parameter;
66
import com.beust.jcommander.ParameterException;
7+
import com.teamscale.client.StringUtils;
78
import com.teamscale.jacoco.agent.commandline.Validator;
89
import com.teamscale.jacoco.agent.convert.ConvertCommand;
910
import com.teamscale.jacoco.agent.logging.LoggingUtils;
1011
import com.teamscale.jacoco.agent.util.AgentUtils;
11-
import org.conqat.lib.commons.string.StringUtils;
1212
import org.jacoco.core.JaCoCo;
1313
import org.slf4j.Logger;
1414

@@ -30,8 +30,8 @@ public static void main(String[] args) throws Exception {
3030
}
3131

3232
/**
33-
* Parses the given command line arguments. Exits the program or throws an
34-
* exception if the arguments are not valid. Then runs the specified command.
33+
* Parses the given command line arguments. Exits the program or throws an exception if the arguments are not valid.
34+
* Then runs the specified command.
3535
*/
3636
private void parseCommandLineAndRun(String[] args) throws Exception {
3737
Builder builder = createJCommanderBuilder();

agent/src/main/java/com/teamscale/jacoco/agent/PreMain.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.teamscale.jacoco.agent;
22

3+
import com.teamscale.client.FileSystemUtils;
34
import com.teamscale.client.HttpUtils;
5+
import com.teamscale.client.StringUtils;
46
import com.teamscale.jacoco.agent.configuration.AgentOptionReceiveException;
57
import com.teamscale.jacoco.agent.logging.DebugLogDirectoryPropertyDefiner;
68
import com.teamscale.jacoco.agent.logging.LogDirectoryPropertyDefiner;
@@ -17,10 +19,7 @@
1719
import com.teamscale.jacoco.agent.upload.UploaderException;
1820
import com.teamscale.jacoco.agent.util.AgentUtils;
1921
import com.teamscale.report.util.ILogger;
20-
import org.conqat.lib.commons.collections.CollectionUtils;
21-
import org.conqat.lib.commons.collections.Pair;
22-
import org.conqat.lib.commons.filesystem.FileSystemUtils;
23-
import org.conqat.lib.commons.string.StringUtils;
22+
import kotlin.Pair;
2423
import org.slf4j.Logger;
2524

2625
import java.io.File;
@@ -32,6 +31,7 @@
3231
import java.nio.file.Paths;
3332
import java.util.List;
3433
import java.util.Optional;
34+
import java.util.stream.Collectors;
3535

3636
import static com.teamscale.jacoco.agent.logging.LoggingUtils.getLoggerContext;
3737

@@ -123,8 +123,8 @@ private static Pair<AgentOptions, List<Exception>> getAndApplyAgentOptions(Strin
123123
String environmentConfigFile) throws AgentOptionParseException, IOException, AgentOptionReceiveException {
124124

125125
DelayedLogger delayedLogger = new DelayedLogger();
126-
List<String> javaAgents = CollectionUtils.filter(ManagementFactory.getRuntimeMXBean().getInputArguments(),
127-
s -> s.contains("-javaagent"));
126+
List<String> javaAgents = ManagementFactory.getRuntimeMXBean().getInputArguments().stream().filter(
127+
s -> s.contains("-javaagent")).collect(Collectors.toList());
128128
// We allow multiple instances of the teamscale-jacoco-agent as we ensure with the #LOCKING_SYSTEM_PROPERTY to only use it once
129129
if (!javaAgents.stream().allMatch(javaAgent -> javaAgent.contains("teamscale-jacoco-agent.jar"))) {
130130
delayedLogger.warn("Using multiple java agents could interfere with coverage recording.");

agent/src/main/java/com/teamscale/jacoco/agent/ResourceBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.teamscale.jacoco.agent;
22

33
import com.teamscale.client.CommitDescriptor;
4+
import com.teamscale.client.StringUtils;
45
import com.teamscale.client.TeamscaleServer;
5-
import com.teamscale.jacoco.agent.testimpact.TestwiseCoverageAgent;
66
import com.teamscale.jacoco.agent.logging.LoggingUtils;
7+
import com.teamscale.jacoco.agent.testimpact.TestwiseCoverageAgent;
78
import com.teamscale.report.testwise.model.RevisionInfo;
8-
import org.conqat.lib.commons.string.StringUtils;
99
import org.jetbrains.annotations.Contract;
1010
import org.slf4j.Logger;
1111

agent/src/main/java/com/teamscale/jacoco/agent/commandline/Validator.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
+-------------------------------------------------------------------------*/
66
package com.teamscale.jacoco.agent.commandline;
77

8-
import org.conqat.lib.commons.assertion.CCSMAssert;
9-
import org.conqat.lib.commons.string.StringUtils;
8+
import com.teamscale.client.StringUtils;
9+
import com.teamscale.jacoco.agent.util.Assertions;
1010

1111
import java.util.ArrayList;
1212
import java.util.List;
@@ -35,27 +35,24 @@ public void ensure(ExceptionBasedValidation validation) {
3535
public interface ExceptionBasedValidation {
3636

3737
/**
38-
* Throws an {@link Exception} or {@link AssertionError} if the validation
39-
* fails.
38+
* Throws an {@link Exception} or {@link AssertionError} if the validation fails.
4039
*/
4140
void validate() throws Exception, AssertionError;
4241

4342
}
4443

4544
/**
46-
* Checks that the given condition is <code>true</code> or adds the given error
47-
* message.
45+
* Checks that the given condition is <code>true</code> or adds the given error message.
4846
*/
4947
public void isTrue(boolean condition, String message) {
50-
ensure(() -> CCSMAssert.isTrue(condition, message));
48+
ensure(() -> Assertions.isTrue(condition, message));
5149
}
5250

5351
/**
54-
* Checks that the given condition is <code>false</code> or adds the given error
55-
* message.
52+
* Checks that the given condition is <code>false</code> or adds the given error message.
5653
*/
5754
public void isFalse(boolean condition, String message) {
58-
ensure(() -> CCSMAssert.isFalse(condition, message));
55+
ensure(() -> Assertions.isFalse(condition, message));
5956
}
6057

6158
/** Returns <code>true</code> if the validation succeeded. */
@@ -65,7 +62,7 @@ public boolean isValid() {
6562

6663
/** Returns an error message with all validation problems that were found. */
6764
public String getErrorMessage() {
68-
return "- " + StringUtils.concat(messages, StringUtils.LINE_FEED + "- ");
65+
return "- " + String.join(StringUtils.LINE_FEED + "- ", messages);
6966
}
7067

7168
}

agent/src/main/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatingTransformer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.teamscale.jacoco.agent.commit_resolution.git_properties;
22

3+
import com.teamscale.client.StringUtils;
34
import com.teamscale.jacoco.agent.logging.LoggingUtils;
45
import com.teamscale.report.util.ClasspathWildcardIncludeFilter;
5-
import org.conqat.lib.commons.collections.Pair;
6-
import org.conqat.lib.commons.string.StringUtils;
6+
import kotlin.Pair;
77
import org.slf4j.Logger;
88

99
import java.io.File;
@@ -26,14 +26,14 @@ public class GitPropertiesLocatingTransformer implements ClassFileTransformer {
2626
private final ClasspathWildcardIncludeFilter locationIncludeFilter;
2727

2828
public GitPropertiesLocatingTransformer(IGitPropertiesLocator locator,
29-
ClasspathWildcardIncludeFilter locationIncludeFilter) {
29+
ClasspathWildcardIncludeFilter locationIncludeFilter) {
3030
this.locator = locator;
3131
this.locationIncludeFilter = locationIncludeFilter;
3232
}
3333

3434
@Override
3535
public byte[] transform(ClassLoader classLoader, String className, Class<?> aClass,
36-
ProtectionDomain protectionDomain, byte[] classFileContent) {
36+
ProtectionDomain protectionDomain, byte[] classFileContent) {
3737
if (protectionDomain == null) {
3838
// happens for e.g. java.lang. We can ignore these classes
3939
return null;
@@ -56,7 +56,8 @@ public byte[] transform(ClassLoader classLoader, String className, Class<?> aCla
5656
}
5757

5858
URL jarOrClassFolderUrl = codeSource.getLocation();
59-
Pair<File, Boolean> searchRoot = GitPropertiesLocatorUtils.extractGitPropertiesSearchRoot(jarOrClassFolderUrl);
59+
Pair<File, Boolean> searchRoot = GitPropertiesLocatorUtils.extractGitPropertiesSearchRoot(
60+
jarOrClassFolderUrl);
6061
if (searchRoot == null || searchRoot.getFirst() == null) {
6162
logger.warn("Not searching location for git.properties with unknown protocol or extension {}." +
6263
" If this location contains your git.properties, please report this warning as a" +

agent/src/main/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitPropertiesLocatorUtils.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.teamscale.client.StringUtils;
66
import com.teamscale.jacoco.agent.options.ProjectAndCommit;
77
import com.teamscale.report.util.BashFileSkippingInputStream;
8-
import org.conqat.lib.commons.collections.Pair;
8+
import kotlin.Pair;
99
import org.jetbrains.annotations.NotNull;
1010
import org.jetbrains.annotations.Nullable;
1111

@@ -127,14 +127,14 @@ public static Pair<File, Boolean> extractGitPropertiesSearchRoot(
127127
case "file":
128128
File jarOrClassFolderFile = new File(jarOrClassFolderUrl.toURI());
129129
if (jarOrClassFolderFile.isDirectory() || isJarLikeFile(jarOrClassFolderUrl.getPath())) {
130-
return Pair.createPair(new File(jarOrClassFolderUrl.toURI()), !jarOrClassFolderFile.isDirectory());
130+
return new Pair<>(new File(jarOrClassFolderUrl.toURI()), !jarOrClassFolderFile.isDirectory());
131131
}
132132
break;
133133
case "jar":
134134
// Used e.g. by Spring Boot. Example: jar:file:/home/k/demo.jar!/BOOT-INF/classes!/
135135
Matcher jarMatcher = JAR_URL_REGEX.matcher(jarOrClassFolderUrl.toString());
136136
if (jarMatcher.matches()) {
137-
return Pair.createPair(new File(jarMatcher.group(1)), true);
137+
return new Pair<>(new File(jarMatcher.group(1)), true);
138138
}
139139
// Intentionally no break to handle ear and war files
140140
case "war":
@@ -143,7 +143,7 @@ public static Pair<File, Boolean> extractGitPropertiesSearchRoot(
143143
// Example: war:file:/Users/example/apache-tomcat/webapps/demo.war*/WEB-INF/lib/demoLib-1.0-SNAPSHOT.jar
144144
Matcher nestedMatcher = NESTED_JAR_REGEX.matcher(jarOrClassFolderUrl.toString());
145145
if (nestedMatcher.matches()) {
146-
return Pair.createPair(new File(nestedMatcher.group(1)), true);
146+
return new Pair<>(new File(nestedMatcher.group(1)), true);
147147
}
148148
break;
149149
case "vfs":
@@ -170,7 +170,7 @@ private static Pair<File, Boolean> getVfsContentFolder(
170170
// obtain the physical location of the class file. It is created on demand in <jboss-installation-dir>/standalone/tmp/vfs
171171
Method getPhysicalFileMethod = virtualFileClass.getMethod("getPhysicalFile");
172172
File file = (File) getPhysicalFileMethod.invoke(virtualFile);
173-
return Pair.createPair(file, !file.isDirectory());
173+
return new Pair<>(file, !file.isDirectory());
174174
}
175175

176176
/**
@@ -198,7 +198,7 @@ private static String extractArtefactUrl(URL jarOrClassFolderUrl) {
198198
}
199199

200200
private static boolean isJarLikeFile(String segment) {
201-
return org.conqat.lib.commons.string.StringUtils.endsWithOneOf(
201+
return StringUtils.endsWithOneOf(
202202
segment.toLowerCase(), ".jar", ".war", ".ear", ".aar");
203203
}
204204

@@ -224,7 +224,6 @@ public static List<ProjectAndCommit> getProjectRevisionsFromGitProperties(
224224
"No entry or empty value for both '" + GIT_PROPERTIES_GIT_COMMIT_ID + "'/'" + GIT_PROPERTIES_GIT_COMMIT_ID_FULL +
225225
"' and '" + GIT_PROPERTIES_TEAMSCALE_PROJECT + "' in " + file + "." +
226226
"\nContents of " + GIT_PROPERTIES_FILE_NAME + ": " + entryWithProperties.getSecond()
227-
.toString()
228227
);
229228
}
230229
result.add(new ProjectAndCommit(project, commitInfo));
@@ -304,7 +303,7 @@ private static List<Pair<String, Properties>> findGitPropertiesInFolder(File dir
304303
gitProperties.load(is);
305304
String relativeFilePath = directoryFile.getName() + File.separator + directoryFile.toPath()
306305
.relativize(gitPropertiesFile.toPath());
307-
result.add(Pair.createPair(relativeFilePath, gitProperties));
306+
result.add(new Pair<>(relativeFilePath, gitProperties));
308307
} catch (IOException e) {
309308
throw new IOException(
310309
"Reading directory " + gitPropertiesFile.getAbsolutePath() + " for obtaining commit " +
@@ -330,7 +329,7 @@ static List<Pair<String, Properties>> findGitPropertiesInArchive(
330329
if (Paths.get(entry.getName()).getFileName().toString().equalsIgnoreCase(GIT_PROPERTIES_FILE_NAME)) {
331330
Properties gitProperties = new Properties();
332331
gitProperties.load(in);
333-
result.add(Pair.createPair(fullEntryName, gitProperties));
332+
result.add(new Pair<>(fullEntryName, gitProperties));
334333
} else if (isJarLikeFile(entry.getName()) && recursiveSearch) {
335334
result.addAll(findGitPropertiesInArchive(new JarInputStream(in), fullEntryName, true));
336335
}
@@ -343,9 +342,9 @@ static List<Pair<String, Properties>> findGitPropertiesInArchive(
343342
}
344343

345344
/**
346-
* Returns the CommitInfo (revision and branch + timestmap) from a git properties file. The revision can be either in
347-
* {@link #GIT_PROPERTIES_GIT_COMMIT_ID} or {@link #GIT_PROPERTIES_GIT_COMMIT_ID_FULL}. The branch and timestamp in
348-
* {@link #GIT_PROPERTIES_GIT_BRANCH} + {@link #GIT_PROPERTIES_GIT_COMMIT_TIME} or in
345+
* Returns the CommitInfo (revision and branch + timestmap) from a git properties file. The revision can be either
346+
* in {@link #GIT_PROPERTIES_GIT_COMMIT_ID} or {@link #GIT_PROPERTIES_GIT_COMMIT_ID_FULL}. The branch and timestamp
347+
* in {@link #GIT_PROPERTIES_GIT_BRANCH} + {@link #GIT_PROPERTIES_GIT_COMMIT_TIME} or in
349348
* {@link #GIT_PROPERTIES_TEAMSCALE_COMMIT_BRANCH} + {@link #GIT_PROPERTIES_TEAMSCALE_COMMIT_TIME}. By default,
350349
* times will be parsed with {@link #GIT_PROPERTIES_DEFAULT_GRADLE_DATE_FORMAT} and
351350
* {@link #GIT_PROPERTIES_DEFAULT_MAVEN_DATE_FORMAT}. An additional format can be given with

agent/src/main/java/com/teamscale/jacoco/agent/commit_resolution/git_properties/GitSingleProjectPropertiesLocator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.teamscale.jacoco.agent.logging.LoggingUtils;
44
import com.teamscale.jacoco.agent.upload.delay.DelayedUploader;
55
import com.teamscale.jacoco.agent.util.DaemonThreadFactory;
6-
import org.checkerframework.checker.nullness.qual.Nullable;
6+
import org.jetbrains.annotations.Nullable;
77
import org.slf4j.Logger;
88

99
import java.io.File;

0 commit comments

Comments
 (0)