All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.teamscale.jacoco.agent.options.ClasspathUtils Maven / Gradle / Ivy

Go to download

JVM profiler that simplifies various aspects around recording and uploading test coverage

There is a newer version: 34.0.2
Show newest version
package com.teamscale.jacoco.agent.options;

import org.conqat.lib.commons.filesystem.FileSystemUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/** Handles parsing a .txt file with classpath pattern separated by newlines. */
public class ClasspathUtils {

	/** Replaces all txt files in the given list with the file names written in the txt file separated by new lines. */
	public static List resolveClasspathTextFiles(String key, FilePatternResolver filePatternResolver,
													   List patterns) throws AgentOptionParseException {
		List resolvedPaths = new ArrayList<>();
		for (String pattern : patterns) {
			resolvedPaths.addAll(filePatternResolver.resolveToMultipleFiles(key, pattern));
		}
		Map> filesByType = resolvedPaths.stream()
				.collect(Collectors.partitioningBy(file -> file.getName().endsWith(".txt")));
		List classDirOrJarFiles = new ArrayList<>(filesByType.get(false));
		for (File txtFile : filesByType.get(true)) {
			classDirOrJarFiles.addAll(resolveClassPathEntries(key, filePatternResolver, txtFile));
		}
		return classDirOrJarFiles;
	}

	private static List resolveClassPathEntries(String key, FilePatternResolver filePatternResolver,
													  File txtFile) throws AgentOptionParseException {
		List filePaths;
		try {
			filePaths = FileSystemUtils.readLinesUTF8(txtFile);
		} catch (IOException e) {
			throw new AgentOptionParseException("Failed read class path entries from the provided " + txtFile +
					" in the `" + key + "` option.", e);
		}
		List resolvedFiles = new ArrayList<>();
		for (String filePath : filePaths) {
			resolvedFiles.addAll(filePatternResolver.resolveToMultipleFiles(key, filePath));
		}
		return resolvedFiles;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy