*/
package org.sonar.batch.scan.filesystem;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.HiddenFileFilter;
Progress progress = new Progress();
InputFileBuilder inputFileBuilder = inputFileBuilderFactory.create(fileSystem);
- executorService = Executors.newFixedThreadPool(Math.max(1, Runtime.getRuntime().availableProcessors() - 1));
+ int threads = Math.max(1, Runtime.getRuntime().availableProcessors() - 1);
+ executorService = Executors.newFixedThreadPool(threads, new ThreadFactoryBuilder().setNameFormat("FileIndexer-%d").build());
tasks = new ArrayList<>();
indexFiles(fileSystem, progress, inputFileBuilder, fileSystem.sources(), InputFile.Type.MAIN);
indexFiles(fileSystem, progress, inputFileBuilder, fileSystem.tests(), InputFile.Type.TEST);
package org.sonar.batch.scan.measure;
import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.measure.MetricFinder;
import org.sonar.api.measures.Metric.ValueType;
import org.sonar.batch.protocol.input.GlobalRepositories;
import java.util.Collection;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class DefaultMetricFinder implements MetricFinder {
- private Map<String, Metric> metricsByKey = Maps.newLinkedHashMap();
+ private Map<String, Metric> metricsByKey = new LinkedHashMap<>();
public DefaultMetricFinder(GlobalRepositories globalReferentials) {
for (org.sonar.batch.protocol.input.Metric metric : globalReferentials.metrics()) {
import static java.nio.file.StandardOpenOption.WRITE;
public class PersistentCache {
-
+ private static final char[] hexArray = "0123456789ABCDEF".toCharArray();
private static final Charset ENCODING = StandardCharsets.UTF_8;
private static final String DIGEST_ALGO = "MD5";
private static final String LOCK_FNAME = ".lock";
return null;
}
-
+
public synchronized void put(@Nonnull String obj, @Nonnull InputStream stream) throws IOException {
String key = getKey(obj);
try {
Path cachePath = getCacheEntryPath(key);
Files.write(cachePath, value, CREATE, WRITE, TRUNCATE_EXISTING);
}
-
+
private void putCache(String key, InputStream stream) throws IOException {
Path cachePath = getCacheEntryPath(key);
- Files.copy(stream, cachePath, StandardCopyOption.REPLACE_EXISTING);
+ Files.copy(stream, cachePath, StandardCopyOption.REPLACE_EXISTING);
}
private byte[] getCache(String key) throws IOException {
return baseDir.resolve(key);
}
- private static String byteArrayToHex(byte[] a) {
- StringBuilder sb = new StringBuilder(a.length * 2);
- for (byte b : a) {
- sb.append(String.format("%02x", b & 0xff));
+ public static String byteArrayToHex(byte[] bytes) {
+ char[] hexChars = new char[bytes.length * 2];
+ for (int j = 0; j < bytes.length; j++) {
+ int v = bytes[j] & 0xFF;
+ hexChars[j * 2] = hexArray[v >>> 4];
+ hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
- return sb.toString();
+ return new String(hexChars);
}
}
}
protected List<File> createElements() {
- List<File> elements = Lists.newArrayList();
+ List<File> e = Lists.newArrayList();
for (String path : def.getBinaries()) {
- elements.add(projectFileSystem.resolvePath(path));
+ e.add(projectFileSystem.resolvePath(path));
}
for (String path : def.getLibraries()) {
- elements.add(projectFileSystem.resolvePath(path));
+ e.add(projectFileSystem.resolvePath(path));
}
- return elements;
+ return e;
}
}