Search in sources :

Example 21 with Path

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();
    }
}
Also used : CasRegisteredServicesRefreshEvent(org.apereo.cas.support.events.service.CasRegisteredServicesRefreshEvent) Logger(org.slf4j.Logger) WatchEvent(java.nio.file.WatchEvent) LoggerFactory(org.slf4j.LoggerFactory) Throwables(com.google.common.base.Throwables) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) File(java.io.File) WatchKey(java.nio.file.WatchKey) IOUtils(org.apache.commons.io.IOUtils) WatchService(java.nio.file.WatchService) Lock(java.util.concurrent.locks.Lock) StandardWatchEventKinds(java.nio.file.StandardWatchEventKinds) Closeable(java.io.Closeable) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Path(java.nio.file.Path) FileSystems(java.nio.file.FileSystems) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Path(java.nio.file.Path) WatchEvent(java.nio.file.WatchEvent) File(java.io.File)

Example 22 with Path

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());
    }
}
Also used : Path(java.nio.file.Path) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 23 with Path

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;
        }
    }
}
Also used : Path(java.nio.file.Path) ModuleFactory(com.puppycrawl.tools.checkstyle.ModuleFactory) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 24 with Path

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);
}
Also used : Path(java.nio.file.Path) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) Injector(org.elasticsearch.common.inject.Injector) SettingsModule(org.elasticsearch.common.settings.SettingsModule) SigarModule(io.crate.module.SigarModule) Environment(org.elasticsearch.env.Environment) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) ModulesBuilder(org.elasticsearch.common.inject.ModulesBuilder) NodeEnvironmentModule(org.elasticsearch.env.NodeEnvironmentModule) Before(org.junit.Before)

Example 25 with Path

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();
}
Also used : Path(java.nio.file.Path) Settings(org.elasticsearch.common.settings.Settings) Before(org.junit.Before)

Aggregations

Path (java.nio.file.Path)4893 Test (org.junit.Test)1960 IOException (java.io.IOException)829 File (java.io.File)445 SourcePath (com.facebook.buck.rules.SourcePath)389 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)334 BuildTarget (com.facebook.buck.model.BuildTarget)320 ArrayList (java.util.ArrayList)313 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)250 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)231 PathSourcePath (com.facebook.buck.rules.PathSourcePath)226 InputStream (java.io.InputStream)210 ImmutableList (com.google.common.collect.ImmutableList)175 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)166 HashMap (java.util.HashMap)159 ImmutableMap (com.google.common.collect.ImmutableMap)157 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)154 Matchers.containsString (org.hamcrest.Matchers.containsString)148 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)147 Map (java.util.Map)146