use of java.nio.file.Path in project cas by apereo.
the class ServiceRegistryConfigWatcher method handleEvent.
/**
* Handle event.
*
* @param key the key
*/
private void handleEvent(final WatchKey key) {
this.readLock.lock();
try {
//The filename is the context of the event.
key.pollEvents().stream().filter(event -> event.count() <= 1).forEach(event -> {
final WatchEvent.Kind kind = event.kind();
final WatchEvent<Path> ev = (WatchEvent<Path>) event;
final Path filename = ev.context();
final Path parent = (Path) key.watchable();
final Path fullPath = parent.resolve(filename);
final File file = fullPath.toFile();
LOGGER.trace("Detected event [{}] on file [{}]. Loading change...", kind, file);
if (kind.name().equals(ENTRY_CREATE.name()) && file.exists()) {
handleCreateEvent(file);
} else if (kind.name().equals(ENTRY_DELETE.name())) {
handleDeleteEvent();
} else if (kind.name().equals(ENTRY_MODIFY.name()) && file.exists()) {
handleModifyEvent(file);
}
});
} finally {
this.readLock.unlock();
}
}
use of java.nio.file.Path in project checkstyle by checkstyle.
the class XdocsPagesTest method testAllStyleRules.
@Test
public void testAllStyleRules() throws Exception {
for (Path path : XdocUtil.getXdocsStyleFilePaths(XdocUtil.getXdocsFilePaths())) {
final String fileName = path.getFileName().toString();
final String input = new String(Files.readAllBytes(path), UTF_8);
final Document document = XmlUtil.getRawXml(fileName, input, input);
final NodeList sources = document.getElementsByTagName("tr");
Set<String> styleChecks = null;
if (path.toFile().getName().contains("google")) {
styleChecks = new HashSet<>(GOOGLE_MODULES);
} else if (path.toFile().getName().contains("sun")) {
styleChecks = new HashSet<>();
}
String lastRuleName = null;
for (int position = 0; position < sources.getLength(); position++) {
final Node row = sources.item(position);
final List<Node> columns = new ArrayList<>(XmlUtil.findChildElementsByTag(row, "td"));
if (columns.isEmpty()) {
continue;
}
final String ruleName = columns.get(1).getTextContent().trim();
if (lastRuleName != null) {
Assert.assertTrue(fileName + " rule '" + ruleName + "' is out of order compared to '" + lastRuleName + "'", ruleName.toLowerCase(Locale.ENGLISH).compareTo(lastRuleName.toLowerCase(Locale.ENGLISH)) >= 0);
}
if (!"--".equals(ruleName)) {
validateStyleAnchors(XmlUtil.findChildElementsByTag(columns.get(0), "a"), fileName, ruleName);
}
validateStyleModules(XmlUtil.findChildElementsByTag(columns.get(2), "a"), XmlUtil.findChildElementsByTag(columns.get(3), "a"), styleChecks, fileName, ruleName);
lastRuleName = ruleName;
}
// these modules aren't documented, but are added to the config
styleChecks.remove("TreeWalker");
styleChecks.remove("Checker");
Assert.assertTrue(fileName + " requires the following check(s) to appear: " + styleChecks, styleChecks.isEmpty());
}
}
use of java.nio.file.Path in project checkstyle by checkstyle.
the class XdocsPagesTest method testAllCheckSections.
@Test
public void testAllCheckSections() throws Exception {
final ModuleFactory moduleFactory = TestUtils.getPackageObjectFactory();
for (Path path : XdocUtil.getXdocsConfigFilePaths(XdocUtil.getXdocsFilePaths())) {
final String fileName = path.getFileName().toString();
if ("config_reporting.xml".equals(fileName)) {
continue;
}
final String input = new String(Files.readAllBytes(path), UTF_8);
final Document document = XmlUtil.getRawXml(fileName, input, input);
final NodeList sources = document.getElementsByTagName("section");
String lastSectioName = null;
for (int position = 0; position < sources.getLength(); position++) {
final Node section = sources.item(position);
final String sectionName = section.getAttributes().getNamedItem("name").getNodeValue();
if ("Content".equals(sectionName) || "Overview".equals(sectionName)) {
Assert.assertNull(fileName + " section '" + sectionName + "' should be first", lastSectioName);
continue;
}
Assert.assertTrue(fileName + " section '" + sectionName + "' shouldn't end with 'Check'", !sectionName.endsWith("Check"));
if (lastSectioName != null) {
Assert.assertTrue(fileName + " section '" + sectionName + "' is out of order compared to '" + lastSectioName + "'", sectionName.toLowerCase(Locale.ENGLISH).compareTo(lastSectioName.toLowerCase(Locale.ENGLISH)) >= 0);
}
validateCheckSection(moduleFactory, fileName, sectionName, section);
lastSectioName = sectionName;
}
}
}
use of java.nio.file.Path in project crate by crate.
the class SigarExtendedNodeInfoTest method prepare.
@Before
public void prepare() throws Exception {
NodeEnvironment nodeEnvironment = mock(NodeEnvironment.class);
when(nodeEnvironment.hasNodeFile()).thenReturn(true);
Path tempDir = createTempDir();
NodeEnvironment.NodePath[] dataLocations = new NodeEnvironment.NodePath[] { new NodeEnvironment.NodePath(tempDir, mock(Environment.class)) };
when(nodeEnvironment.nodePaths()).thenReturn(dataLocations);
NodeEnvironmentModule nodeEnvironmentModule = new NodeEnvironmentModule(nodeEnvironment);
MonitorModule monitorModule = new MonitorModule(NODE_SETTINGS);
monitorModule.addExtendedNodeInfoType(SigarPlugin.NODE_INFO_EXTENDED_TYPE, SigarExtendedNodeInfo.class);
Injector injector = new ModulesBuilder().add(new SettingsModule(NODE_SETTINGS), monitorModule, nodeEnvironmentModule, new SigarModule(new SigarService(NODE_SETTINGS))).createInjector();
extendedNodeInfo = injector.getInstance(ExtendedNodeInfo.class);
}
use of java.nio.file.Path in project crate by crate.
the class ObjectTemplateMappingBWCTest method loadLegacy.
@Before
public void loadLegacy() throws IOException {
Path zippedIndexDir = getDataPath("/indices/bwc/bwc-object_template_mapping-0.54.9.zip");
Settings nodeSettings = prepareBackwardsDataDir(zippedIndexDir);
internalCluster().startNode(nodeSettings);
ensureYellow();
}
Aggregations