Example usage for org.eclipse.jgit.util StringUtils capitalize

List of usage examples for org.eclipse.jgit.util StringUtils capitalize

Introduction

In this page you can find the example usage for org.eclipse.jgit.util StringUtils capitalize.

Prototype

public static String capitalize(String str) 

Source Link

Document

Borrowed from commons-lang StringUtils.capitalize() method.

Usage

From source file:com.netflix.spinnaker.halyard.config.model.v1.node.Node.java

License:Apache License

public List<String> backupLocalFiles(String outputPath) {
    List<String> files = new ArrayList<>();

    Consumer<Node> fileFinder = n -> files.addAll(n.localFiles().stream().map(f -> {
        try {/*from   w w  w . j ava 2  s.c  o  m*/
            f.setAccessible(true);
            String fPath = (String) f.get(n);
            if (fPath == null) {
                try {
                    fPath = (String) n.getClass().getMethod("get" + StringUtils.capitalize(f.getName()))
                            .invoke(n);
                } catch (NoSuchMethodException | InvocationTargetException ignored) {
                }
            }

            if (fPath == null) {
                return null;
            }

            File fFile = new File(fPath);
            String fName = fFile.getName();

            // Hash the path to uniquely flatten all files into the output directory
            Path newName = Paths.get(outputPath, Math.abs(fPath.hashCode()) + "-" + fName);
            File parent = newName.toFile().getParentFile();
            if (!parent.exists()) {
                parent.mkdirs();
            } else if (fFile.getParent().equals(parent.toString())) {
                // Don't move paths that are already in the right folder
                return fPath;
            }
            Files.copy(Paths.get(fPath), newName, REPLACE_EXISTING);

            f.set(n, newName.toString());
            return newName.toString();
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Failed to get local files for node " + n.getNodeName(), e);
        } catch (IOException e) {
            throw new HalException(FATAL, "Failed to backup user file: " + e.getMessage(), e);
        } finally {
            f.setAccessible(false);
        }
    }).filter(Objects::nonNull).collect(Collectors.toList()));
    recursiveConsume(fileFinder);

    return files;
}