Search in sources :

Example 96 with Path

use of java.nio.file.Path in project elasticsearch by elastic.

the class FileBasedUnicastHostsProviderTests method setupAndRunHostProvider.

// sets up the config dir, writes to the unicast hosts file in the config dir,
// and then runs the file-based unicast host provider to get the list of discovery nodes
private List<DiscoveryNode> setupAndRunHostProvider(final List<String> hostEntries) throws IOException {
    final Path homeDir = createTempDir();
    final Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), homeDir).build();
    final Path configDir = homeDir.resolve("config").resolve("discovery-file");
    Files.createDirectories(configDir);
    final Path unicastHostsPath = configDir.resolve(UNICAST_HOSTS_FILE);
    try (BufferedWriter writer = Files.newBufferedWriter(unicastHostsPath)) {
        writer.write(String.join("\n", hostEntries));
    }
    return new FileBasedUnicastHostsProvider(settings, transportService, executorService).buildDynamicNodes();
}
Also used : Path(java.nio.file.Path) Settings(org.elasticsearch.common.settings.Settings) BufferedWriter(java.io.BufferedWriter)

Example 97 with Path

use of java.nio.file.Path in project elasticsearch by elastic.

the class GeoIpProcessorFactoryTests method testLazyLoading.

public void testLazyLoading() throws Exception {
    Path configDir = createTempDir();
    Path geoIpConfigDir = configDir.resolve("ingest-geoip");
    Files.createDirectories(geoIpConfigDir);
    Files.copy(new ByteArrayInputStream(StreamsUtils.copyToBytesFromClasspath("/GeoLite2-City.mmdb.gz")), geoIpConfigDir.resolve("GeoLite2-City.mmdb.gz"));
    Files.copy(new ByteArrayInputStream(StreamsUtils.copyToBytesFromClasspath("/GeoLite2-Country.mmdb.gz")), geoIpConfigDir.resolve("GeoLite2-Country.mmdb.gz"));
    // Loading another database reader instances, because otherwise we can't test lazy loading as the the
    // database readers used at class level are reused between tests. (we want to keep that otherwise running this
    // test will take roughly 4 times more time)
    Map<String, DatabaseReaderLazyLoader> databaseReaders = IngestGeoIpPlugin.loadDatabaseReaders(geoIpConfigDir, NoCache.getInstance());
    GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseReaders);
    for (DatabaseReaderLazyLoader lazyLoader : databaseReaders.values()) {
        assertNull(lazyLoader.databaseReader.get());
    }
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("database_file", "GeoLite2-City.mmdb.gz");
    factory.create(null, "_tag", config);
    config = new HashMap<>();
    config.put("field", "_field");
    config.put("database_file", "GeoLite2-Country.mmdb.gz");
    factory.create(null, "_tag", config);
    for (DatabaseReaderLazyLoader lazyLoader : databaseReaders.values()) {
        assertNotNull(lazyLoader.databaseReader.get());
    }
}
Also used : Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap)

Example 98 with Path

use of java.nio.file.Path in project elasticsearch by elastic.

the class EvilSecurityTests method testEnsureSymlink.

public void testEnsureSymlink() throws IOException {
    Path p = createTempDir();
    Path exists = p.resolve("exists");
    Files.createDirectory(exists);
    // symlink
    Path linkExists = p.resolve("linkExists");
    try {
        Files.createSymbolicLink(linkExists, exists);
    } catch (UnsupportedOperationException | IOException e) {
        assumeNoException("test requires filesystem that supports symbolic links", e);
    } catch (SecurityException e) {
        assumeNoException("test cannot create symbolic links with security manager enabled", e);
    }
    Security.ensureDirectoryExists(linkExists);
    Files.createTempFile(linkExists, null, null);
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException)

Example 99 with Path

use of java.nio.file.Path in project che by eclipse.

the class LocalWorkspaceFolderPathProviderTest method throwsExceptionIfFileIsFoundByWorkspacesRootPath.

@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Workspace folder '.*' is not directory. Check .* configuration property")
public void throwsExceptionIfFileIsFoundByWorkspacesRootPath() throws Exception {
    Path tempFile = Files.createTempFile(getClass().getSimpleName(), null);
    LocalWorkspaceFolderPathProvider provider = new LocalWorkspaceFolderPathProvider(tempFile.toString(), null, null, workspaceManagerProvider, true, false);
    provider.init();
}
Also used : Path(java.nio.file.Path) Test(org.testng.annotations.Test)

Example 100 with Path

use of java.nio.file.Path in project che by eclipse.

the class InstallExtension method main.

public static void main(String[] args) throws IOException {
    for (String arg : args) {
        if (arg.startsWith(EXT_DIR_PARAMETER)) {
            extDirPath = Paths.get(arg.substring(EXT_DIR_PARAMETER.length()));
        } else if (arg.startsWith(EXT_RESOURCES_DIR_PARAMETER)) {
            final Path extResourcesDirPath = Paths.get(arg.substring(EXT_RESOURCES_DIR_PARAMETER.length()));
            final String tempDirName = "temp";
            extResourcesWorkDirPath = extResourcesDirPath.resolve(tempDirName);
            // delete working directory from previous build if it exist
            IoUtil.deleteRecursive(extResourcesWorkDirPath.toFile());
            Files.createDirectory(extResourcesWorkDirPath);
            IoUtil.copy(extResourcesDirPath.toFile(), extResourcesWorkDirPath.toFile(), new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return !(tempDirName.equals(name));
                }
            });
        } else {
            System.err.println("Unknown flag: " + arg);
            System.exit(1);
        }
    }
    List<Extension> extensions = findExtensionsByPath(extDirPath);
    for (Extension extension : extensions) {
        final File pom = extResourcesWorkDirPath.resolve("pom.xml").toFile();
        final Model model = Model.readFrom(pom);
        model.dependencies().add(new Dependency(extension.groupId, extension.artifactId, extension.artifactVersion));
        model.writeTo(pom);
        // Add GWT module if there is one
        if (extension.gwtModuleName != null) {
            final Path ideGwtXmlPath = IoUtil.findFile(IDE_GWT_XML_FILE_NAME, extResourcesWorkDirPath.toFile()).toPath();
            GwtXmlUtils.inheritGwtModule(ideGwtXmlPath, extension.gwtModuleName);
        }
    }
}
Also used : Path(java.nio.file.Path) FilenameFilter(java.io.FilenameFilter) Model(org.eclipse.che.ide.maven.tools.Model) Dependency(org.eclipse.che.ide.maven.tools.Dependency) File(java.io.File) ZipFile(java.util.zip.ZipFile)

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