@Test public void testCommand() throws FactoryException { assertEquals("cd /a; zip -qr /a/b.zip b", Archive.ZIP.getCompressCommand(new Path("/a", EnumSet.of(Path.Type.directory)), Collections.singletonList(new Path("/a/b", EnumSet.of(Path.Type.file))))); assertEquals("cd /a; zip -qr /a/b\\ c.zip b\\ c", Archive.ZIP.getCompressCommand(new Path("/a", EnumSet.of(Path.Type.directory)), Collections.singletonList(new Path("/a/b c", EnumSet.of(Path.Type.file))))); assertEquals("cd /a; tar -cpPf /a/b.tar b", Archive.TAR.getCompressCommand(new Path("/a", EnumSet.of(Path.Type.directory)), Collections.singletonList(new Path("/a/b", EnumSet.of(Path.Type.file))))); }
public String getCompressCommand(final Path workdir, final List<Path> files) { final StringBuilder archive = new StringBuilder(); if(files.size() == 1) { archive.append(this.escape(files.get(0).getAbsolute())); } else { archive.append(this.escape(files.get(0).getParent().getAbsolute())).append(Path.DELIMITER).append("Archive"); } final List<String> command = new ArrayList<String>(); for(Path path : files) { command.add(this.escape(PathRelativizer.relativize(workdir.getAbsolute(), path.getAbsolute()))); } return MessageFormat.format(preferences.getProperty(String.format("archive.command.create.%s", this.getIdentifier())), archive.toString(), StringUtils.join(command, " "), this.escape(workdir.getAbsolute())); }
Archive { public String getCompressCommand(final Path workdir, final List<Path> files) { final StringBuilder archive = new StringBuilder(); if(files.size() == 1) { archive.append(this.escape(files.get(0).getAbsolute())); } else { archive.append(this.escape(files.get(0).getParent().getAbsolute())).append(Path.DELIMITER).append("Archive"); } final List<String> command = new ArrayList<String>(); for(Path path : files) { command.add(this.escape(PathRelativizer.relativize(workdir.getAbsolute(), path.getAbsolute()))); } return MessageFormat.format(preferences.getProperty(String.format("archive.command.create.%s", this.getIdentifier())), archive.toString(), StringUtils.join(command, " "), this.escape(workdir.getAbsolute())); } }
Archive { public String getCompressCommand(final Path workdir, final List<Path> files) { final StringBuilder archive = new StringBuilder(); if(files.size() == 1) { archive.append(this.escape(files.get(0).getAbsolute())); } else { archive.append(this.escape(files.get(0).getParent().getAbsolute())).append(Path.DELIMITER).append("Archive"); } final List<String> command = new ArrayList<String>(); for(Path path : files) { command.add(this.escape(PathRelativizer.relativize(workdir.getAbsolute(), path.getAbsolute()))); } return MessageFormat.format(preferences.getProperty(String.format("archive.command.create.%s", this.getIdentifier())), archive.toString(), StringUtils.join(command, " "), this.escape(workdir.getAbsolute())); } private  Archive(final String extension); }
Archive { public String getCompressCommand(final Path workdir, final List<Path> files) { final StringBuilder archive = new StringBuilder(); if(files.size() == 1) { archive.append(this.escape(files.get(0).getAbsolute())); } else { archive.append(this.escape(files.get(0).getParent().getAbsolute())).append(Path.DELIMITER).append("Archive"); } final List<String> command = new ArrayList<String>(); for(Path path : files) { command.add(this.escape(PathRelativizer.relativize(workdir.getAbsolute(), path.getAbsolute()))); } return MessageFormat.format(preferences.getProperty(String.format("archive.command.create.%s", this.getIdentifier())), archive.toString(), StringUtils.join(command, " "), this.escape(workdir.getAbsolute())); } private  Archive(final String extension); static Archive getDefault(); static Archive[] getKnownArchives(); static Archive forName(final String name); String[] getExtensions(); String getIdentifier(); abstract String getDescription(); Path getArchive(final List<Path> files); List<Path> getExpanded(final List<Path> files); String getTitle(final List<Path> files); String getCompressCommand(final Path workdir, final List<Path> files); String getDecompressCommand(final Path path); static boolean isArchive(final String filename); }
Archive { public String getCompressCommand(final Path workdir, final List<Path> files) { final StringBuilder archive = new StringBuilder(); if(files.size() == 1) { archive.append(this.escape(files.get(0).getAbsolute())); } else { archive.append(this.escape(files.get(0).getParent().getAbsolute())).append(Path.DELIMITER).append("Archive"); } final List<String> command = new ArrayList<String>(); for(Path path : files) { command.add(this.escape(PathRelativizer.relativize(workdir.getAbsolute(), path.getAbsolute()))); } return MessageFormat.format(preferences.getProperty(String.format("archive.command.create.%s", this.getIdentifier())), archive.toString(), StringUtils.join(command, " "), this.escape(workdir.getAbsolute())); } private  Archive(final String extension); static Archive getDefault(); static Archive[] getKnownArchives(); static Archive forName(final String name); String[] getExtensions(); String getIdentifier(); abstract String getDescription(); Path getArchive(final List<Path> files); List<Path> getExpanded(final List<Path> files); String getTitle(final List<Path> files); String getCompressCommand(final Path workdir, final List<Path> files); String getDecompressCommand(final Path path); static boolean isArchive(final String filename); static final Archive TAR; static final Archive TARGZ; static final Archive TARBZ2; static final Archive ZIP; static final Archive GZIP; static final Archive BZ2; }