in sonar-plugin-server/src/main/java/jetbrains/buildserver/sonarplugin/msbuild/tool/SimpleZipToolProviderSQMSBuild.java [149:239]
public void layoutContents(@NotNull final Path toolPath, @NotNull final Path targetPath) throws ToolException {
try (final FileSystem fs = FileSystems.newFileSystem(toolPath, (ClassLoader)null)) {
Files.walkFileTree(fs.getPath("/"), new FileVisitor<Path>() {
@NotNull private Path currentPath = targetPath;
@Override
public FileVisitResult preVisitDirectory(final Path path, final BasicFileAttributes basicFileAttributes) throws IOException {
final Path targetDir = resolve(targetPath, fs.getPath("/").relativize(path));
try {
Files.createDirectory(targetDir);
} catch (FileAlreadyExistsException ignore) {
}
currentPath = targetDir;
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(final Path path, final BasicFileAttributes basicFileAttributes) throws IOException {
Path resolve = currentPath.resolve(path.getFileName().toString());
if (!Files.exists(resolve) && resolve.startsWith(currentPath)) {
Files.copy(path, resolve);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(final Path path, final IOException e) {
Loggers.SERVER.warn(e);
return FileVisitResult.TERMINATE;
}
@Override
public FileVisitResult postVisitDirectory(final Path path, final IOException e) {
currentPath = currentPath.getParent();
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
throw new ToolException("Error", e);
}
List<Path> sonarScanners = null;
try (Stream<Path> children = Files.list(targetPath)) {
sonarScanners = children.filter(p -> p.getFileName().toString().startsWith(SONAR_SCANNER_PREFIX)).collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
}
if (sonarScanners == null) {
sonarScanners = Collections.emptyList();
}
List<Path> executablePaths = new ArrayList<>();
for (Path sonarScanner: sonarScanners) {
try (Stream<Path> bin = Files.list(sonarScanner.resolve(BIN))) {
bin.filter(Files::isRegularFile).forEach(executablePaths::add);
} catch (IOException e) {
e.printStackTrace();
}
}
try (Stream<Path> children = Files.list(targetPath)) {
children.filter(p -> p.getFileName().toString().endsWith(".exe")).forEach(executablePaths::add);
} catch (IOException e) {
e.printStackTrace();
}
final Path descriptor = targetPath.resolve(TEAMCITY_PLUGIN_XML);
try {
List<String> iterable = new ArrayList<>(Arrays.asList(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"<teamcity-agent-plugin xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
" xsi:noNamespaceSchemaLocation=\"urn:shemas-jetbrains-com:teamcity-agent-plugin-v1-xml\">",
" <tool-deployment>",
" <layout>",
" <executable-files>"));
for (Path path: executablePaths) {
iterable.add(" <include name='" + targetPath.relativize(path).toString() + "'/>");
}
iterable.addAll(Arrays.asList(
" </executable-files>",
" </layout>",
" </tool-deployment>",
"</teamcity-agent-plugin>"));
Files.write(descriptor, iterable);
} catch (IOException e) {
throw new ToolException("Cannot write teamcity-plugin.xml", e);
}
}