Search in sources :

Example 86 with FileSystem

use of java.nio.file.FileSystem in project android by JetBrains.

the class PatchInstallerUtil method setupPatchDir.

/**
   * Create and populate the directory that we'll look in during startup for pending patches.
   * This includes copying the patch zip there, and then adding the patcher jar into the zip (so it can be run by the update runner).
   */
private static boolean setupPatchDir(@NotNull File patchFile, @NotNull File patcherFile, @NotNull RepoPackage toInstallOrDelete, @NotNull RepoManager mgr, @NotNull FileOp fop, @NotNull ProgressIndicator progress) {
    File patchesDir = new File(mgr.getLocalPath(), PATCHES_DIR_NAME);
    File patchDir;
    for (int i = 1; ; i++) {
        patchDir = new File(patchesDir, PATCH_DIR_PREFIX + i);
        if (!fop.exists(patchDir)) {
            fop.mkdirs(patchDir);
            break;
        }
    }
    try {
        File completePatch = new File(patchDir, PATCH_JAR_FN);
        fop.copyFile(patcherFile, completePatch);
        try (FileSystem completeFs = FileSystems.newFileSystem(URI.create("jar:" + completePatch.toURI()), new HashMap<>());
            FileSystem patchFs = FileSystems.newFileSystem(URI.create("jar:" + patchFile.toURI()), new HashMap<>())) {
            Files.copy(patchFs.getPath(PATCH_ZIP_FN), completeFs.getPath(PATCH_ZIP_FN));
        }
        InstallerUtil.writePendingPackageXml(toInstallOrDelete, patchDir, mgr, fop, progress);
    } catch (IOException e) {
        progress.logWarning("Error while setting up patch.", e);
        return false;
    }
    return true;
}
Also used : FileSystem(java.nio.file.FileSystem) IOException(java.io.IOException) File(java.io.File)

Example 87 with FileSystem

use of java.nio.file.FileSystem in project Voxel_Game by ASasseCreations.

the class AssetLoader method getItems.

private static final List<String> getItems(final String path, final String ext) throws URISyntaxException, IOException {
    final List<String> itemFileNames = new ArrayList<>();
    final URI uri = AssetLoader.class.getResource(path).toURI();
    Path myPath;
    if (uri.getScheme().equals("jar")) {
        final FileSystem fileSystem = getFileSystem(uri);
        myPath = fileSystem.getPath(path);
    } else
        myPath = Paths.get(uri);
    final Stream<Path> walk = Files.walk(myPath, 1);
    for (final Iterator<Path> it = walk.iterator(); it.hasNext(); ) {
        final String next = it.next().toString();
        if (next.endsWith("." + ext))
            itemFileNames.add(next);
    }
    walk.close();
    return itemFileNames;
}
Also used : Path(java.nio.file.Path) FileSystem(java.nio.file.FileSystem) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 88 with FileSystem

use of java.nio.file.FileSystem in project jPOS by jpos.

the class Q2 method run.

public void run() {
    started = true;
    Thread.currentThread().setName("Q2-" + getInstanceId().toString());
    Path dir = Paths.get(deployDir.getAbsolutePath());
    FileSystem fs = dir.getFileSystem();
    try (WatchService service = fs.newWatchService()) {
        watchServiceClassname = service.getClass().getName();
        dir.register(service, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE);
        /*
            * The following code determines whether a MBeanServer exists 
            * already. If so then the first one in the list is used. 
            * I have not yet find a way to interrogate the server for 
            * information other than MBeans so to pick a specific one 
            * would be difficult.
            */
        ArrayList mbeanServerList = MBeanServerFactory.findMBeanServer(null);
        if (mbeanServerList.isEmpty()) {
            server = MBeanServerFactory.createMBeanServer(JMX_NAME);
        } else {
            server = (MBeanServer) mbeanServerList.get(0);
        }
        final ObjectName loaderName = new ObjectName(Q2_CLASS_LOADER);
        try {
            loader = (QClassLoader) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

                public Object run() {
                    return new QClassLoader(server, libDir, loaderName, mainClassLoader);
                }
            });
            if (server.isRegistered(loaderName))
                server.unregisterMBean(loaderName);
            server.registerMBean(loader, loaderName);
            loader = loader.scan(false);
        } catch (Throwable t) {
            if (log != null)
                log.error("initial-scan", t);
            else
                t.printStackTrace();
        }
        factory = new QFactory(loaderName, this);
        writePidFile();
        initSystemLogger();
        if (bundleContext == null)
            addShutdownHook();
        q2Thread = Thread.currentThread();
        q2Thread.setContextClassLoader(loader);
        if (cli != null)
            cli.start();
        initConfigDecorator();
        if (startOSGI)
            startOSGIFramework();
        if (enableSsh) {
            deployElement(SshService.createDescriptor(sshPort, sshUser, sshAuthorizedKeys, sshHostKeyFile), "05_sshd-" + getInstanceId() + ".xml", false, true);
        }
        deployInternal();
        for (int i = 1; !shutdown; i++) {
            try {
                boolean forceNewClassLoader = scan() && i > 1;
                QClassLoader oldClassLoader = loader;
                loader = loader.scan(forceNewClassLoader);
                if (loader != oldClassLoader) {
                    // We want this to be null so it gets GCed.
                    oldClassLoader = null;
                    // force a GC
                    System.gc();
                    log.info("new classloader [" + Integer.toString(loader.hashCode(), 16) + "] has been created");
                    q2Thread.setContextClassLoader(loader);
                }
                logVersion();
                deploy();
                checkModified();
                ready.countDown();
                if (!waitForChanges(service))
                    break;
            } catch (InterruptedException | IllegalAccessError ignored) {
            // NOPMD
            } catch (Throwable t) {
                log.error("start", t.getMessage());
                relax();
            }
        }
        undeploy();
        try {
            server.unregisterMBean(loaderName);
        } catch (InstanceNotFoundException e) {
            log.error(e);
        }
        if (decorator != null) {
            decorator.uninitialize();
        }
        if (exit && !shuttingDown)
            System.exit(0);
    } catch (IllegalAccessError ignored) {
    // NOPMD OK to happen
    } catch (Exception e) {
        if (log != null)
            log.error(e);
        else
            e.printStackTrace();
        System.exit(1);
    }
}
Also used : Path(java.nio.file.Path) InstanceNotFoundException(javax.management.InstanceNotFoundException) JDOMException(org.jdom2.JDOMException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) GeneralSecurityException(java.security.GeneralSecurityException) BundleException(org.osgi.framework.BundleException) UnrecognizedOptionException(org.apache.commons.cli.UnrecognizedOptionException) SAXException(org.xml.sax.SAXException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ISOException(org.jpos.iso.ISOException) MissingArgumentException(org.apache.commons.cli.MissingArgumentException) ObjectName(javax.management.ObjectName) FileSystem(java.nio.file.FileSystem) WatchService(java.nio.file.WatchService)

Example 89 with FileSystem

use of java.nio.file.FileSystem in project bndtools by bndtools.

the class IndexerWizardPage method validate.

private void validate() {
    String warning = null;
    if (baseDir == null) {
        setErrorMessage(null);
        setPageComplete(false);
        return;
    }
    if (!baseDir.exists()) {
        setErrorMessage(Messages.IndexerWizardPage_error_noSuchDir + baseDir.getAbsolutePath());
        setPageComplete(false);
        return;
    }
    if (!baseDir.isDirectory()) {
        setErrorMessage(Messages.IndexerWizardPage_error_notDir + baseDir.getAbsolutePath());
        setPageComplete(false);
        return;
    }
    try {
        FileSystem fs = FileSystems.getDefault();
        //$NON-NLS-1$
        fs.getPathMatcher("glob:" + resourcePattern);
    } catch (Exception e) {
        setErrorMessage(e.getMessage());
        setPageComplete(false);
        return;
    }
    if (outputFileName.indexOf('/') > -1) {
        setErrorMessage(Messages.IndexerWizardPage_error_noSlashes);
        setPageComplete(false);
    }
    File outputFile = new File(baseDir, outputFileName);
    if (outputFile.exists()) {
        if (outputFile.isFile())
            warning = Messages.IndexerWizardPage_warn_fileOverwrite + outputFile.getAbsolutePath();
        else {
            setErrorMessage(Messages.IndexerWizardPage_error_fileExists + outputFile.getAbsolutePath());
            setPageComplete(false);
        }
    }
    setErrorMessage(null);
    setMessage(warning, WARNING);
    setPageComplete(inputPaths != null && !inputPaths.isEmpty());
}
Also used : FileSystem(java.nio.file.FileSystem) File(java.io.File) PatternSyntaxException(java.util.regex.PatternSyntaxException) IOException(java.io.IOException)

Example 90 with FileSystem

use of java.nio.file.FileSystem in project jetty.project by eclipse.

the class PathMatchers method getMatcher.

public static PathMatcher getMatcher(final String rawpattern) {
    FileSystem fs = FileSystems.getDefault();
    String pattern = rawpattern;
    // Strip trailing slash (if present)
    int lastchar = pattern.charAt(pattern.length() - 1);
    if (lastchar == '/' || lastchar == '\\') {
        pattern = pattern.substring(0, pattern.length() - 1);
    }
    // use FileSystem default pattern behavior
    if (pattern.startsWith("glob:") || pattern.startsWith("regex:")) {
        StartLog.debug("Using Standard " + fs.getClass().getName() + " pattern: " + pattern);
        return fs.getPathMatcher(pattern);
    }
    // be a full system path
    if (isAbsolute(pattern)) {
        String pat = "glob:" + pattern;
        StartLog.debug("Using absolute path pattern: " + pat);
        return fs.getPathMatcher(pat);
    }
    // Doesn't start with filesystem root, then assume the pattern
    // is a relative file path pattern.
    String pat = "glob:**/" + pattern;
    StartLog.debug("Using relative path pattern: " + pat);
    return fs.getPathMatcher(pat);
}
Also used : FileSystem(java.nio.file.FileSystem)

Aggregations

FileSystem (java.nio.file.FileSystem)159 Path (java.nio.file.Path)112 Test (org.junit.Test)66 IOException (java.io.IOException)25 File (java.io.File)17 ArrayList (java.util.ArrayList)14 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)13 URI (java.net.URI)11 FilterPath (org.apache.lucene.mockfile.FilterPath)11 InputStream (java.io.InputStream)10 OutputStream (java.io.OutputStream)10 FileStore (java.nio.file.FileStore)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 HashMap (java.util.HashMap)6 DefaultProjectFilesystemDelegate (com.facebook.buck.io.DefaultProjectFilesystemDelegate)5 ProjectFilesystemDelegate (com.facebook.buck.io.ProjectFilesystemDelegate)5 WindowsFS (org.apache.lucene.mockfile.WindowsFS)5 FSDirectory (org.apache.lucene.store.FSDirectory)5 BuckConfig (com.facebook.buck.cli.BuckConfig)4 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)4