use of com.google.common.io.Files in project mzmine2 by mzmine.
the class KovatsIndexExtractionDialog method initRawDataFileSelection.
/**
* Init raw data selection to last used raw data file or "kovats" or "dro"
*/
private void initRawDataFileSelection() {
if (dataFiles != null && dataFiles.length <= 0)
return;
RawDataFilesSelection select = parameterSet.getParameter(KovatsIndexExtractionParameters.dataFiles).getValue();
RawDataFile[] raw = null;
// set to parameters files - if they exist in this project
if (select != null && select.getMatchingRawDataFiles().length > 0) {
RawDataFile[] exists = Arrays.stream(select.getMatchingRawDataFiles()).filter(r -> Arrays.stream(dataFiles).anyMatch(d -> r.getName().equals(d.getName()))).toArray(RawDataFile[]::new);
if (exists.length > 0)
raw = exists;
}
if (raw == null) {
// find kovats or dro file
// first use all kovats named files and then dro (max 2)
RawDataFile[] kovats = Arrays.stream(dataFiles).filter(d -> d.getName().toLowerCase().contains("kovats")).toArray(RawDataFile[]::new);
RawDataFile[] dro = Arrays.stream(dataFiles).filter(d -> d.getName().toLowerCase().contains("dro")).toArray(RawDataFile[]::new);
// maximum of two files are chosen (0,1,2)
int size = Math.min(2, kovats.length + dro.length);
raw = new RawDataFile[size];
for (int i = 0; i < raw.length; i++) {
if (i < kovats.length)
raw[i] = kovats[i];
else
raw[i] = dro[i - kovats.length];
}
}
if (raw.length > 0) {
selectedDataFile = raw;
comboDataFileName.setSelectedItem(selectedDataFile[0]);
if (raw.length > 1) {
comboDataFileName2.setSelectedItem(selectedDataFile[1]);
}
}
}
use of com.google.common.io.Files in project sonar-java by SonarSource.
the class XmlFileSensorTest method test_no_issues_but_xml_file_still_published.
@Test
public void test_no_issues_but_xml_file_still_published() throws Exception {
SensorContextTester context = SensorContextTester.create(new File("src/test/files/maven2/").getAbsoluteFile());
DefaultFileSystem fs = context.fileSystem();
final File file = new File("src/test/files/maven2/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, never()).reportIssue(Mockito.argThat(argument -> file.getAbsolutePath().equals(argument.getFile().getAbsolutePath())));
}
use of com.google.common.io.Files in project closure-compiler by google.
the class RefasterJsTestUtils method assertFileRefactoring.
/**
* Performs refactoring using a RefasterJs template and asserts that result is as expected.
*
* @param refasterJsTemplate path of the file or resource containing the RefasterJs template to
* apply
* @param testDataPathPrefix path prefix of the directory from which input and expected-output
* file will be read
* @param originalFile file name of the JavaScript source file to apply the refaster template to
* @param additionalSourceFiles list of additional source files to provide to the compiler (e.g.
* dependencies)
* @param expectedFileChoices the expected result options of applying the specified template to
* {@code originalFile}
* @throws IOException
*/
public static void assertFileRefactoring(String refasterJsTemplate, String testDataPathPrefix, String originalFile, List<String> additionalSourceFiles, String... expectedFileChoices) throws IOException {
RefasterJsScanner scanner = new RefasterJsScanner();
scanner.loadRefasterJsTemplate(refasterJsTemplate);
final String originalFilePath = testDataPathPrefix + File.separator + originalFile;
ImmutableList.Builder<String> expectedCodeBuilder = ImmutableList.builder();
for (String expectedFile : expectedFileChoices) {
expectedCodeBuilder.add(slurpFile(testDataPathPrefix + File.separator + expectedFile));
}
final ImmutableList<String> expectedCode = expectedCodeBuilder.build();
RefactoringDriver.Builder driverBuilder = new RefactoringDriver.Builder().addExterns(CommandLineRunner.getBuiltinExterns(CompilerOptions.Environment.BROWSER));
for (String additionalSource : additionalSourceFiles) {
driverBuilder.addInputsFromFile(testDataPathPrefix + File.separator + additionalSource);
}
RefactoringDriver driver = driverBuilder.addInputsFromFile(originalFilePath).build();
List<SuggestedFix> fixes = driver.drive(scanner);
assertThat(driver.getCompiler().getErrors()).isEmpty();
assertThat(driver.getCompiler().getWarnings()).isEmpty();
ImmutableList<String> newCode = ApplySuggestedFixes.applyAllSuggestedFixChoicesToCode(fixes, ImmutableMap.of(originalFilePath, slurpFile(originalFilePath))).stream().map(m -> m.get(originalFilePath)).collect(ImmutableList.toImmutableList());
assertThat(newCode).comparingElementsUsing(new IgnoringWhitespaceCorrespondence()).containsExactlyElementsIn(expectedCode);
}
use of com.google.common.io.Files in project alluxio by Alluxio.
the class PinCommandMultipleMediaIntegrationTest method pinToMediumForceEviction.
@Test
public void pinToMediumForceEviction() throws Exception {
FileSystem fileSystem = sLocalAlluxioClusterResource.get().getClient();
FileSystemShell fsShell = new FileSystemShell(ServerConfiguration.global());
AlluxioURI filePathA = new AlluxioURI("/testFileA");
AlluxioURI dirPath = new AlluxioURI("/testDirA");
AlluxioURI filePathB = new AlluxioURI(dirPath.getPath() + "/testFileB");
AlluxioURI filePathC = new AlluxioURI("/testFileC");
int fileSize = SIZE_BYTES / 2;
FileSystemTestUtils.createByteFile(fileSystem, filePathA, WritePType.CACHE_THROUGH, fileSize);
assertTrue(fileExists(fileSystem, filePathA));
assertEquals(0, fsShell.run("pin", filePathA.toString(), "MEM"));
URIStatus status = fileSystem.getStatus(filePathA);
assertTrue(status.isPinned());
assertTrue(status.getPinnedMediumTypes().contains("MEM"));
fileSystem.createDirectory(dirPath);
assertEquals(0, fsShell.run("pin", dirPath.toString(), "MEM"));
FileSystemTestUtils.createByteFile(fileSystem, filePathB, WritePType.CACHE_THROUGH, fileSize);
assertTrue(fileExists(fileSystem, filePathB));
URIStatus statusB = fileSystem.getStatus(filePathB);
assertTrue(statusB.isPinned());
assertTrue(statusB.getPinnedMediumTypes().contains("MEM"));
FileSystemTestUtils.createByteFile(fileSystem, filePathC, WritePType.THROUGH, fileSize);
assertEquals(100, fileSystem.getStatus(filePathA).getInAlluxioPercentage());
assertEquals(100, fileSystem.getStatus(filePathB).getInAlluxioPercentage());
assertEquals(0, fileSystem.getStatus(filePathC).getInAlluxioPercentage());
assertEquals(0, fsShell.run("pin", filePathC.toString(), "SSD"));
// Verify files are replicated into the correct tier through job service
CommonUtils.waitFor("File being loaded", () -> sJobCluster.getMaster().getJobMaster().listDetailed().stream().anyMatch(x -> x.getStatus().equals(Status.COMPLETED) && x.getName().equals("Replicate") && x.getAffectedPaths().contains(filePathC.getPath())), sWaitOptions);
assertEquals(100, fileSystem.getStatus(filePathC).getInAlluxioPercentage());
assertEquals(Constants.MEDIUM_MEM, fileSystem.getStatus(filePathA).getFileBlockInfos().get(0).getBlockInfo().getLocations().get(0).getMediumType());
assertEquals(Constants.MEDIUM_MEM, fileSystem.getStatus(filePathB).getFileBlockInfos().get(0).getBlockInfo().getLocations().get(0).getMediumType());
assertEquals(Constants.MEDIUM_SSD, fileSystem.getStatus(filePathC).getFileBlockInfos().get(0).getBlockInfo().getLocations().get(0).getMediumType());
assertEquals(0, fsShell.run("unpin", filePathA.toString()));
assertEquals(0, fsShell.run("pin", filePathC.toString(), "MEM"));
status = fileSystem.getStatus(filePathA);
assertFalse(status.isPinned());
assertTrue(status.getPinnedMediumTypes().isEmpty());
// Verify files are migrated from another tier into the correct tier through job service
// Also verify that eviction works
CommonUtils.waitFor("File being moved", () -> sJobCluster.getMaster().getJobMaster().listDetailed().stream().anyMatch(x -> x.getStatus().equals(Status.COMPLETED) && x.getName().equals("Move") && x.getAffectedPaths().contains(filePathC.getPath())), sWaitOptions);
assertEquals(0, fileSystem.getStatus(filePathA).getInAlluxioPercentage());
assertEquals(Constants.MEDIUM_MEM, fileSystem.getStatus(filePathC).getFileBlockInfos().get(0).getBlockInfo().getLocations().get(0).getMediumType());
}
use of com.google.common.io.Files in project controller by opendaylight.
the class JMXGeneratorTest method generateMBEsTest.
@Test
public void generateMBEsTest() throws Exception {
// default value for module factory file is true
map.put(JMXGenerator.MODULE_FACTORY_FILE_BOOLEAN, "randomValue");
jmxGenerator.setAdditionalConfig(map);
Collection<File> files = jmxGenerator.generateSources(context, outputBaseDir, Collections.singleton(threadsJavaModule), m -> Optional.empty());
assertEquals(expectedModuleFileNames, toFileNames(files));
for (File file : files) {
final String name = file.getName();
if (!name.endsWith("java")) {
continue;
}
MbeASTVisitor visitor = new MbeASTVisitor(EXPECTED_PACKAGE_PREFIX + ".threads.java", name);
verifyFile(file, visitor);
switch(name) {
case "AbstractDynamicThreadPoolModule.java":
assertAbstractDynamicThreadPoolModule(visitor);
break;
case "AsyncEventBusModuleMXBean.java":
assertEquals("Incorrenct number of generated methods", 4, visitor.methods.size());
break;
case "AbstractNamingThreadFactoryModuleFactory.java":
assertAbstractNamingThreadFactoryModuleFactory(visitor);
break;
case "AsyncEventBusModule.java":
assertContains(visitor.extnds, EXPECTED_PACKAGE_PREFIX + ".threads.java.AbstractAsyncEventBusModule");
visitor.assertFields(0);
assertEquals("Incorrenct number of generated methods", 2, visitor.methods.size());
visitor.assertConstructors(2);
visitor.assertMethodDescriptions(0);
visitor.assertMethodJavadocs(0);
break;
case "EventBusModuleFactory.java":
assertContains(visitor.extnds, EXPECTED_PACKAGE_PREFIX + ".threads.java.AbstractEventBusModuleFactory");
visitor.assertFields(0);
assertEquals("Incorrenct number of generated methods", 0, visitor.methods.size());
visitor.assertConstructors(0);
visitor.assertMethodDescriptions(0);
visitor.assertMethodJavadocs(0);
break;
}
}
verifyXmlFiles(Collections2.filter(files, input -> input.getName().endsWith("xml")));
// verify ModuleFactory file
File moduleFactoryFile = JMXGenerator.concatFolders(generatedResourcesDir, "META-INF", "services", ModuleFactory.class.getName());
assertTrue(moduleFactoryFile.exists());
Set<String> lines = ImmutableSet.copyOf(Files.readLines(moduleFactoryFile, StandardCharsets.UTF_8));
Set<String> expectedLines = ImmutableSet.of(EXPECTED_PACKAGE_PREFIX + ".threads.java.EventBusModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.AsyncEventBusModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.DynamicThreadPoolModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.NamingThreadFactoryModuleFactory", EXPECTED_PACKAGE_PREFIX + ".threads.java.ThreadPoolRegistryImplModuleFactory");
assertEquals(expectedLines, lines);
}
Aggregations