use of com.teamscale.client.CommitDescriptor in project teamscale-jacoco-agent by cqse.
the class ArtifactoryConfig method parseGitProperties.
/**
* Parses the commit information form a git.properties file.
*/
public static CommitInfo parseGitProperties(File jarFile, DateTimeFormatter gitPropertiesCommitTimeFormat) throws IOException, InvalidGitPropertiesException {
Pair<String, Properties> entryWithProperties = GitPropertiesLocatorUtils.findGitPropertiesInFile(jarFile, true);
if (entryWithProperties == null) {
return null;
}
String entry = entryWithProperties.getFirst();
Properties properties = entryWithProperties.getSecond();
String revision = GitPropertiesLocatorUtils.getGitPropertiesValue(properties, GitPropertiesLocatorUtils.GIT_PROPERTIES_GIT_COMMIT_ID, entry, jarFile);
String branchName = GitPropertiesLocatorUtils.getGitPropertiesValue(properties, GitPropertiesLocator.GIT_PROPERTIES_GIT_BRANCH, entry, jarFile);
long timestamp = ZonedDateTime.parse(GitPropertiesLocatorUtils.getGitPropertiesValue(properties, GitPropertiesLocator.GIT_PROPERTIES_GIT_COMMIT_TIME, entry, jarFile), gitPropertiesCommitTimeFormat).toInstant().toEpochMilli();
return new CommitInfo(revision, new CommitDescriptor(branchName, timestamp));
}
use of com.teamscale.client.CommitDescriptor in project teamscale-jacoco-agent by cqse.
the class TeamscaleConfig method getCommitFromManifest.
/**
* Reads `Branch` and `Timestamp` entries from the given jar/war file's manifest and builds a commit descriptor out
* of it.
*/
private CommitDescriptor getCommitFromManifest(File jarFile) throws AgentOptionParseException {
Manifest manifest = getManifestFromJarFile(jarFile);
String branch = manifest.getMainAttributes().getValue("Branch");
String timestamp = manifest.getMainAttributes().getValue("Timestamp");
if (StringUtils.isEmpty(branch)) {
throw new AgentOptionParseException("No entry 'Branch' in MANIFEST");
} else if (StringUtils.isEmpty(timestamp)) {
throw new AgentOptionParseException("No entry 'Timestamp' in MANIFEST");
}
logger.debug("Found commit " + branch + ":" + timestamp + " in file " + jarFile);
return new CommitDescriptor(branch, timestamp);
}
use of com.teamscale.client.CommitDescriptor in project teamscale-jacoco-agent by cqse.
the class CoverageToTeamscaleStrategyTest method mockOptions.
private AgentOptions mockOptions() throws IOException {
AgentOptions options = mock(AgentOptions.class);
when(options.createTeamscaleClient()).thenReturn(client);
when(options.createTempFile(any(), any())).thenReturn(new File(tempDir, "test"));
TeamscaleServer server = new TeamscaleServer();
server.commit = new CommitDescriptor("branch", "12345");
server.url = HttpUrl.get("http://doesnt-exist.io");
server.userName = "build";
server.userAccessToken = "token";
server.partition = "partition";
when(options.getTeamscaleServerOptions()).thenReturn(server);
when(options.createTeamscaleClient()).thenReturn(client);
return options;
}
use of com.teamscale.client.CommitDescriptor in project teamscale-jacoco-agent by cqse.
the class TestwiseCoverageAgentTest method mockOptions.
private AgentOptions mockOptions(int port) {
AgentOptions options = mock(AgentOptions.class);
when(options.createTeamscaleClient()).thenReturn(client);
TeamscaleServer server = new TeamscaleServer();
server.commit = new CommitDescriptor("branch", "12345");
server.url = HttpUrl.get("http://doesnt-exist.io");
server.userName = "build";
server.userAccessToken = "token";
server.partition = "partition";
when(options.getTeamscaleServerOptions()).thenReturn(server);
when(options.getHttpServerPort()).thenReturn(port);
when(options.getTestwiseCoverageMode()).thenReturn(ETestwiseCoverageMode.TEAMSCALE_UPLOAD);
when(options.createTeamscaleClient()).thenReturn(client);
return options;
}
use of com.teamscale.client.CommitDescriptor in project teamscale-jacoco-agent by cqse.
the class NwdiMarkerClassLocatingTransformer method transform.
@Override
public byte[] transform(ClassLoader classLoader, String className, Class<?> aClass, ProtectionDomain protectionDomain, byte[] classFileContent) {
if (protectionDomain == null) {
// happens for e.g. java.lang. We can ignore these classes
return null;
}
if (StringUtils.isEmpty(className) || !locationIncludeFilter.isIncluded(className)) {
// only search in jar files of included classes
return null;
}
if (!this.markerClassesToApplications.containsKey(className)) {
// only kick off search if the marker class was found.
return null;
}
try {
CodeSource codeSource = protectionDomain.getCodeSource();
if (codeSource == null) {
// but there's nothing else we can do here in either case
return null;
}
URL jarOrClassFolderUrl = codeSource.getLocation();
logger.debug("Found " + className + " in " + jarOrClassFolderUrl);
if (jarOrClassFolderUrl.getProtocol().toLowerCase().equals("file")) {
Path file = Paths.get(jarOrClassFolderUrl.toURI());
BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);
SapNwdiApplications.SapNwdiApplication application = markerClassesToApplications.get(className);
CommitDescriptor commitDescriptor = new CommitDescriptor(DTR_BRIDGE_DEFAULT_BRANCH, attr.lastModifiedTime().toMillis());
store.setCommitForApplication(commitDescriptor, application);
}
} catch (Throwable e) {
// we catch Throwable to be sure that we log all errors as anything thrown from this method is
// silently discarded by the JVM
logger.error("Failed to process class {} trying to determine its last modification timestamp.", className, e);
}
return null;
}
Aggregations