use of com.google.common.io.Files in project sonar-java by SonarSource.
the class XmlFileSensorTest method test_issues_creation.
@Test
public void test_issues_creation() throws Exception {
SensorContextTester context = SensorContextTester.create(new File("src/test/files/maven/").getAbsoluteFile());
DefaultFileSystem fs = context.fileSystem();
final File file = new File("src/test/files/maven/pom.xml");
DefaultInputFile inputFile = new TestInputFileBuilder("", "pom.xml").setModuleBaseDir(fs.baseDirPath()).setPublish(false).build();
fs.add(inputFile);
SonarComponents sonarComponents = createSonarComponentsMock(fs, file);
XmlFileSensor sensor = new XmlFileSensor(sonarComponents, fs);
assertThat(inputFile.isPublished()).isFalse();
sensor.execute(context);
assertThat(inputFile.isPublished()).isTrue();
verify(sonarComponents, times(1)).reportIssue(Mockito.argThat(argument -> file.getAbsolutePath().equals(argument.getFile().getAbsolutePath())));
}
use of com.google.common.io.Files in project j2objc by google.
the class Options method getPathArgument.
private List<String> getPathArgument(String argument, boolean expandAarFiles, boolean expandWildcard) {
List<String> entries = new ArrayList<>();
for (String entry : Splitter.on(File.pathSeparatorChar).split(argument)) {
if (entry.startsWith("~/")) {
// Expand bash/csh tildes, which don't get expanded by the shell
// first if in the middle of a path string.
entry = System.getProperty("user.home") + entry.substring(1);
}
File f = new File(entry);
if (f.getName().equals("*") && expandWildcard) {
File parent = f.getParentFile() == null ? new File(".") : f.getParentFile();
FileFilter jarFilter = file -> file.getName().endsWith(".jar");
File[] files = parent.listFiles(jarFilter);
if (files != null) {
for (File jar : files) {
entries.add(jar.toString());
}
}
continue;
}
if (entry.endsWith(".aar") && expandAarFiles) {
// Extract classes.jar from Android library AAR file.
f = fileUtil().extractClassesJarFromAarFile(f);
}
if (f.exists()) {
entries.add(f.toString());
}
}
return entries;
}
use of com.google.common.io.Files in project knime-core by knime.
the class NodeViewManagerTest method testGetNodeViewPageUrl.
/**
* Tests {@link NodeViewManager#getNodeViewPageUrl(NativeNodeContainer)}.
*
* @throws URISyntaxException
* @throws IOException
*/
@Test
public void testGetNodeViewPageUrl() throws URISyntaxException, IOException {
var staticPage = Page.builder(BUNDLE_ID, "files", "page.html").addResourceFile("resource.html").build();
var dynamicPage = Page.builder(() -> "page content", "page.html").addResourceFromString(() -> "resource content", "resource.html").build();
NativeNodeContainer nnc = createNodeWithNodeView(m_wfm, m -> createNodeView(staticPage));
NativeNodeContainer nnc2 = createNodeWithNodeView(m_wfm, m -> createNodeView(staticPage));
NativeNodeContainer nnc3 = createNodeWithNodeView(m_wfm, m -> createNodeView(dynamicPage));
var nodeViewManager = NodeViewManager.getInstance();
String url = nodeViewManager.getNodeViewPageUrl(nnc).orElse("");
String url2 = nodeViewManager.getNodeViewPageUrl(nnc2).orElse(null);
String url3 = nodeViewManager.getNodeViewPageUrl(nnc3).orElse(null);
String url4 = nodeViewManager.getNodeViewPageUrl(nnc3).orElse(null);
assertThat("file url of static pages not expected to change", url, is(url2));
assertThat("file url of dynamic pages expected to change between node instances", url, is(not(url3)));
assertThat("file url of dynamic pages not expected for same node instance (without node state change)", url3, is(url4));
assertThat("resource files are expected to be written, too", new File(new URI(url.replace("page.html", "resource.html"))).exists(), is(true));
assertThat(new File(new URI(url)).exists(), is(true));
assertThat(new File(new URI(url3)).exists(), is(true));
String pageContent = Files.readLines(new File(new URI(url3)), StandardCharsets.UTF_8).get(0);
assertThat(pageContent, is("page content"));
// impose node state changes
m_wfm.executeAllAndWaitUntilDone();
var dynamicPage2 = Page.builder(() -> "new page content", "page.html").addResourceFromString(() -> "resource content", "resource.html").build();
nnc = createNodeWithNodeView(m_wfm, m -> createNodeView(dynamicPage2));
String url5 = nodeViewManager.getNodeViewPageUrl(nnc).orElse(null);
pageContent = Files.readLines(new File(new URI(url5)), StandardCharsets.UTF_8).get(0);
assertThat(pageContent, is("new page content"));
runOnExecutor(() -> assertThat(nodeViewManager.getNodeViewPageUrl(nnc2).isEmpty(), is(true)));
}
use of com.google.common.io.Files in project ArachneCentralAPI by OHDSI.
the class BaseSubmissionController method getResultFiles.
@ApiOperation("Get result files of the submission.")
@GetMapping("/api/v1/analysis-management/submissions/{submissionId}/results")
public List<ResultFileDTO> getResultFiles(Principal principal, @PathVariable("submissionId") Long submissionId, @RequestParam(value = "path", required = false, defaultValue = "") String path, @RequestParam(value = "real-name", required = false) String realName) throws PermissionDeniedException, IOException {
IUser user = userService.getByUsername(principal.getName());
ResultFileSearch resultFileSearch = new ResultFileSearch();
resultFileSearch.setPath(path);
resultFileSearch.setRealName(realName);
List<? extends ArachneFileMeta> resultFileList = submissionService.getResultFiles(user, submissionId, resultFileSearch);
String resultFilesPath = contentStorageHelper.getResultFilesDir(Submission.class, submissionId, null);
return resultFileList.stream().map(rf -> {
ResultFileDTO rfDto = conversionService.convert(rf, ResultFileDTO.class);
rfDto.setSubmissionId(submissionId);
rfDto.setRelativePath(contentStorageHelper.getRelativePath(resultFilesPath, rfDto.getPath()));
return rfDto;
}).collect(Collectors.toList());
}
use of com.google.common.io.Files in project presto by prestodb.
the class TestHivePageSink method writeTestFile.
private static long writeTestFile(HiveClientConfig config, MetastoreClientConfig metastoreClientConfig, ExtendedHiveMetastore metastore, String outputPath) {
HiveTransactionHandle transaction = new HiveTransactionHandle();
HiveWriterStats stats = new HiveWriterStats();
ConnectorPageSink pageSink = createPageSink(transaction, config, metastoreClientConfig, metastore, new Path("file:///" + outputPath), stats);
List<LineItemColumn> columns = getTestColumns();
List<Type> columnTypes = columns.stream().map(LineItemColumn::getType).map(TestHivePageSink::getHiveType).map(hiveType -> hiveType.getType(FUNCTION_AND_TYPE_MANAGER)).collect(toList());
PageBuilder pageBuilder = new PageBuilder(columnTypes);
int rows = 0;
for (LineItem lineItem : new LineItemGenerator(0.01, 1, 1)) {
rows++;
if (rows >= NUM_ROWS) {
break;
}
pageBuilder.declarePosition();
for (int i = 0; i < columns.size(); i++) {
LineItemColumn column = columns.get(i);
BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
switch(column.getType().getBase()) {
case IDENTIFIER:
BIGINT.writeLong(blockBuilder, column.getIdentifier(lineItem));
break;
case INTEGER:
INTEGER.writeLong(blockBuilder, column.getInteger(lineItem));
break;
case DATE:
DATE.writeLong(blockBuilder, column.getDate(lineItem));
break;
case DOUBLE:
DOUBLE.writeDouble(blockBuilder, column.getDouble(lineItem));
break;
case VARCHAR:
createUnboundedVarcharType().writeSlice(blockBuilder, Slices.utf8Slice(column.getString(lineItem)));
break;
default:
throw new IllegalArgumentException("Unsupported type " + column.getType());
}
}
}
Page page = pageBuilder.build();
pageSink.appendPage(page);
getFutureValue(pageSink.finish());
File outputDir = new File(outputPath);
List<File> files = ImmutableList.copyOf(outputDir.listFiles((dir, name) -> !name.endsWith(".crc")));
File outputFile = getOnlyElement(files);
long length = outputFile.length();
ConnectorPageSource pageSource = createPageSource(transaction, config, metastoreClientConfig, outputFile);
List<Page> pages = new ArrayList<>();
while (!pageSource.isFinished()) {
Page nextPage = pageSource.getNextPage();
if (nextPage != null) {
pages.add(nextPage.getLoadedPage());
}
}
MaterializedResult expectedResults = toMaterializedResult(getSession(config), columnTypes, ImmutableList.of(page));
MaterializedResult results = toMaterializedResult(getSession(config), columnTypes, pages);
assertEquals(results, expectedResults);
assertEquals(stats.getInputPageSizeInBytes().getAllTime().getMax(), page.getRetainedSizeInBytes());
return length;
}
Aggregations