You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by tr...@apache.org on 2013/08/10 07:53:54 UTC
svn commit: r1512568 [7/39] - in /jackrabbit/commons/filevault/trunk: ./
parent/ vault-cli/ vault-cli/src/ vault-cli/src/main/
vault-cli/src/main/appassembler/ vault-cli/src/main/assembly/
vault-cli/src/main/java/ vault-cli/src/main/java/org/ vault-cli...
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/examples/HelloWorldApp.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/examples/HelloWorldApp.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/examples/HelloWorldApp.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/examples/HelloWorldApp.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.examples;
+
+import org.apache.jackrabbit.vault.util.console.AbstractApplication;
+import org.apache.jackrabbit.vault.util.console.Console;
+import org.apache.jackrabbit.vault.util.console.ExecutionContext;
+
+/**
+ * <code>HelloWorldApp</code>...
+ */
+public class HelloWorldApp extends AbstractApplication {
+
+ private ExecutionContext ctx;
+
+
+ public HelloWorldApp() {
+ }
+
+ public String getSVNVersion() {
+ return "$Revision: 29457 $";
+ }
+
+ public String getApplicationName() {
+ return "Hello World Example";
+ }
+
+ public String getShellCommand() {
+ return "hello";
+ }
+
+ protected ExecutionContext getDefaultContext() {
+ if (ctx == null) {
+ ctx = new ExecutionContext(this);
+ ctx.installCommand(new CmdHello());
+ }
+ return ctx;
+ }
+
+ public Console getConsole() {
+ // we do not have interactive console
+ return null;
+ }
+
+ public static void main(String[] args) {
+ new HelloWorldApp().run(args);
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/CmdCd.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/CmdCd.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/CmdCd.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/CmdCd.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.platform;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+import org.apache.jackrabbit.vault.util.console.commands.AbstractConsoleCommand;
+
+/**
+ * <code>CmdCd</code>...
+ */
+public class CmdCd extends AbstractConsoleCommand {
+
+ private Option argPath;
+
+ protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl) throws Exception {
+ String path = (String) cl.getValue(argPath, "/");
+ ctx.cd(path);
+ }
+
+ public String getShortDescription() {
+ return "change the current work directory";
+ }
+
+ protected Command createCommand() {
+ return new CommandBuilder()
+ .withName("cd")
+ .withDescription(getShortDescription())
+ .withChildren(new GroupBuilder()
+ .withName("Options:")
+ .withOption(argPath = new ArgumentBuilder()
+ .withName("path")
+ .withDescription("destination path. changes to root directory if missing.")
+ .withMinimum(0)
+ .withMaximum(1)
+ .create())
+ .create())
+ .create();
+ }
+
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/CmdLs.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/CmdLs.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/CmdLs.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/CmdLs.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.platform;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.option.Command;
+import org.apache.commons.cli2.validation.NumberValidator;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+import org.apache.jackrabbit.vault.util.console.ConsoleFile;
+import org.apache.jackrabbit.vault.util.console.ExecutionException;
+import org.apache.jackrabbit.vault.util.console.commands.AbstractConsoleCommand;
+import org.apache.jackrabbit.vault.util.console.util.Table;
+
+/**
+ * <code>CmdLs</code>...
+ */
+public class CmdLs extends AbstractConsoleCommand {
+
+ private static final SimpleDateFormat dateFmt = new SimpleDateFormat("yyyy MMM dd HH:mm");
+
+ // format flags
+ private static int F_FLAG_TIME = 0x01;
+ private static int F_FLAG_SIZE = 0x02;
+ private static int F_FLAG_LONG = 0x03;
+ private static int F_MASK = 0x0f;
+
+ // list switches
+ private static int L_FLAG_ALL = 0x10;
+
+ private Option optLong;
+
+ private Option optTime;
+
+ private Option optSize;
+
+ private Option optAll;
+
+ private Option optRecursive;
+
+ private Option argPath;
+
+ protected void doExecute(ConsoleExecutionContext ctx, CommandLine cl)
+ throws Exception {
+ int fmtFlag = 0;
+ fmtFlag |= cl.hasOption(optTime) ? F_FLAG_TIME : 0;
+ fmtFlag |= cl.hasOption(optSize) ? F_FLAG_SIZE : 0;
+ fmtFlag |= cl.hasOption(optLong) ? F_FLAG_LONG : 0;
+ fmtFlag |= cl.hasOption(optAll) ? L_FLAG_ALL : 0;
+ int depth = 0;
+ if (cl.hasOption(optRecursive)) {
+ depth = Integer.parseInt((String) cl.getValue(optRecursive, "10000"));
+ }
+ String path = (String) cl.getValue(argPath);
+ ConsoleFile file = ctx.getFile(path, true);
+ if (!(file instanceof PlatformFile)) {
+ throw new ExecutionException("wrong file system.");
+ }
+ ls((PlatformFile) file, fmtFlag, depth);
+ }
+
+ public String getShortDescription() {
+ return "print a list of files and directories";
+ }
+
+
+ public String getExample() {
+ return "$ ls -al";
+ }
+
+ protected Command createCommand() {
+ return new CommandBuilder()
+ .withName("ls")
+ .withDescription(getShortDescription())
+ .withChildren(new GroupBuilder()
+ .withName("Options:")
+ .withOption(optAll = new DefaultOptionBuilder()
+ .withShortName("a")
+ .withDescription("display hidden files")
+ .create())
+ .withOption(optTime = new DefaultOptionBuilder()
+ .withShortName("t")
+ .withDescription("display the last modification date")
+ .create())
+ .withOption(optSize = new DefaultOptionBuilder()
+ .withShortName("s")
+ .withDescription("display the file size")
+ .create())
+ .withOption(optLong = new DefaultOptionBuilder()
+ .withShortName("l")
+ .withDescription("combines the flags 't' and 's'")
+ .create())
+ .withOption(optRecursive = new DefaultOptionBuilder()
+ .withShortName("r")
+ .withDescription("do a recursive listing")
+ .withArgument(new ArgumentBuilder()
+ .withName("depth")
+ .withDescription("the depth of the recursion.")
+ .withMinimum(0)
+ .withMaximum(1)
+ .withValidator(NumberValidator.getIntegerInstance())
+ .create())
+ .create())
+ .withOption(argPath = new ArgumentBuilder()
+ .withName("path")
+ .withDescription("the path to list")
+ .withMinimum(0)
+ .withMaximum(1)
+ .create())
+ .create())
+ .create();
+ }
+
+ private void ls(PlatformFile file, int flags, int maxDepth) throws IOException {
+ int numCols = 1;
+ int f = flags & F_MASK;
+ while (f != 0) {
+ if ((f & 1) == 1) {
+ numCols++;
+ }
+ f >>= 1;
+ }
+ Table t = new Table(numCols);
+ ls(t, (File) file.unwrap(), flags, 0, maxDepth);
+ t.print();
+ }
+
+ private void ls(Table t, File file, int flags, int indent, int maxDepth) throws IOException {
+ File[] files = file.listFiles();
+ if (files == null) {
+ return;
+ }
+ for (int i=0; i<files.length; i++) {
+ File f = files[i];
+ if (f.getName().charAt(0) == '.' && !((flags & L_FLAG_ALL) > 0)) {
+ continue;
+ }
+ Table.Row r = t.createRow();
+ if ((flags & F_FLAG_TIME) > 0) {
+ r.addCol(dateFmt.format(new Date(f.lastModified())));
+ }
+ if ((flags & F_FLAG_SIZE) > 0) {
+ r.addCol(String.valueOf(f.length()), true);
+ }
+ String name = f.getName();
+ if (f.isDirectory()) {
+ name += "/";
+ }
+ r.addCol(name);
+ t.addRow(r);
+ if (maxDepth > 0) {
+ ls(t, f, flags, indent + 1, maxDepth -1);
+ }
+ }
+ }
+
+
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/PlatformFile.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/PlatformFile.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/PlatformFile.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/PlatformFile.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.platform;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.jackrabbit.vault.util.console.ConsoleFile;
+import org.apache.jackrabbit.vault.util.console.ExecutionException;
+
+/**
+ * <code>PlatformFile</code>...
+ */
+public class PlatformFile implements ConsoleFile {
+
+ private final URI uri;
+
+ private final File file;
+
+ public PlatformFile(File file) {
+ if (file == null) {
+ throw new NullPointerException();
+ }
+ this.file = file;
+ try {
+ this.uri = new URI("file", file.getPath(), null);
+ } catch (URISyntaxException e) {
+ throw new ExecutionException(e);
+ }
+ }
+
+
+ public Object unwrap() {
+ return file;
+ }
+
+ public ConsoleFile getFile(String path, boolean mustExist)
+ throws IOException {
+ File newFile = new File(path);
+ if (newFile.isAbsolute()) {
+ newFile = newFile.getCanonicalFile();
+ } else {
+ newFile = new File(file, path).getCanonicalFile();
+ }
+ if (!newFile.exists() && mustExist) {
+ throw new FileNotFoundException(newFile.getPath());
+ }
+ return new PlatformFile(newFile);
+ }
+
+ public String getPath() {
+ return file.getPath();
+ }
+
+ public String getName() {
+ return file.getName();
+ }
+
+ public ConsoleFile[] listFiles() throws IOException {
+ File[] files = file.listFiles();
+ if (files.length == 0) {
+ return ConsoleFile.EMPTY_ARRAY;
+ } else {
+ PlatformFile[] ret = new PlatformFile[files.length];
+ for (int i=0; i<files.length; i++) {
+ ret[i] = new PlatformFile(files[i]);
+ }
+ return ret;
+ }
+ }
+
+ public boolean allowsChildren() {
+ return file.isDirectory();
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/ShellApp.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/ShellApp.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/ShellApp.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/platform/ShellApp.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.platform;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.jackrabbit.vault.util.console.AbstractApplication;
+import org.apache.jackrabbit.vault.util.console.Console;
+import org.apache.jackrabbit.vault.util.console.ConsoleExecutionContext;
+import org.apache.jackrabbit.vault.util.console.ExecutionContext;
+import org.apache.jackrabbit.vault.util.console.ExecutionException;
+import org.apache.jackrabbit.vault.util.console.commands.CmdConsole;
+import org.apache.jackrabbit.vault.util.console.commands.CmdCtx;
+import org.apache.jackrabbit.vault.util.console.examples.CmdHello;
+
+/**
+ * <code>HelloWorldApp</code>...
+ */
+public class ShellApp extends AbstractApplication {
+
+ private ExecutionContext ctx;
+
+ private ConsoleExecutionContext iCtx;
+
+ private Console console;
+
+ public ShellApp() {
+ }
+
+ public String getSVNVersion() {
+ return "$Revision: 29457 $";
+ }
+
+ public String getApplicationName() {
+ return "Shell Console Example";
+ }
+
+ public String getShellCommand() {
+ return "jash";
+ }
+
+ protected ExecutionContext getDefaultContext() {
+ if (ctx == null) {
+ ctx = new ExecutionContext(this);
+ ctx.installCommand(new CmdHello());
+ ctx.installCommand(new CmdConsole());
+ }
+ return ctx;
+ }
+
+ public Console getConsole() {
+ if (console == null) {
+ console = new Console(this);
+ iCtx = new ConsoleExecutionContext(this);
+ iCtx.installCommand(new CmdLs());
+ iCtx.installCommand(new CmdCd());
+ iCtx.installCommand(new CmdCtx());
+ try {
+ iCtx.setFileSystem(new PlatformFile(new File(".").getCanonicalFile()));
+ } catch (IOException e) {
+ throw new ExecutionException(e);
+ }
+ console.addContext(iCtx);
+ }
+ return console;
+ }
+
+ public static void main(String[] args) {
+ new ShellApp().run(args);
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/CliHelpFormatter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/CliHelpFormatter.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/CliHelpFormatter.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/CliHelpFormatter.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.util;
+
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.cli2.DisplaySetting;
+import org.apache.commons.cli2.HelpLine;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.util.HelpFormatter;
+import org.apache.jackrabbit.vault.util.console.CliCommand;
+
+/**
+ * Highly customized help formatter to work with {@link CliCommand}s.
+ */
+public class CliHelpFormatter extends HelpFormatter {
+
+ public static final String SYS_PROP_TERM_WIDTH = "env.term.width";
+
+ private String description;
+
+ private String example;
+
+ private CliCommand cmd;
+
+ private boolean showUsage = true;
+
+ private boolean skipToplevel = false;
+
+
+ public CliHelpFormatter(final String gutterLeft, final String gutterCenter, final String gutterRight, final int fullWidth) {
+ super(gutterLeft, gutterCenter, gutterRight, fullWidth);
+ }
+
+ public static CliHelpFormatter create() {
+ return new CliHelpFormatter(HelpFormatter.DEFAULT_GUTTER_LEFT,
+ HelpFormatter.DEFAULT_GUTTER_CENTER,
+ HelpFormatter.DEFAULT_GUTTER_RIGHT,
+ getDefaultWidth());
+ }
+
+ private static int getDefaultWidth() {
+ int w = Integer.getInteger(SYS_PROP_TERM_WIDTH, HelpFormatter.DEFAULT_FULL_WIDTH).intValue();
+ return Math.max(w, HelpFormatter.DEFAULT_FULL_WIDTH);
+ }
+
+ public CliCommand getCmd() {
+ return cmd;
+ }
+
+ public void setCmd(CliCommand cmd) {
+ this.cmd = cmd;
+ setDescription(cmd.getLongDescription());
+ setExample(cmd.getExample());
+ //setShellCommand(cmd.getName());
+ // we need a fake group for the command
+ setGroup(new GroupBuilder().withOption(cmd.getCommand()).create());
+ getFullUsageSettings().remove(DisplaySetting.DISPLAY_OPTIONAL);
+ setSkipToplevel(true);
+ //getDisplaySettings().remove(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
+ }
+
+ public void printUsage() {
+ if (showUsage) {
+ super.printUsage();
+ }
+ }
+
+ public boolean isSkipToplevel() {
+ return skipToplevel;
+ }
+
+ public void setSkipToplevel(boolean skipToplevel) {
+ this.skipToplevel = skipToplevel;
+ }
+
+ public boolean isShowUsage() {
+ return showUsage;
+ }
+
+ public void setShowUsage(boolean showUsage) {
+ this.showUsage = showUsage;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getExample() {
+ return example;
+ }
+
+ public void setExample(String example) {
+ this.example = example;
+ }
+
+ /**
+ * Prints detailed help per option.
+ */
+ public void printHelp() {
+ printDivider();
+
+ printDescription();
+
+ final Option option;
+ final PrintWriter out = getPrintWriter();
+
+ if ((getException() != null) && (getException().getOption() != null)) {
+ option = getException().getOption();
+ } else if (cmd != null) {
+ option = cmd.getCommand();
+ } else {
+ option = getGroup();
+ }
+
+ // grab the HelpLines to display
+ final List helpLines = option.helpLines(
+ skipToplevel ? -1 : 0, getDisplaySettings(), getComparator());
+ if (skipToplevel) {
+ helpLines.remove(0);
+ }
+
+ // calculate the maximum width of the usage strings
+ int usageWidth = 0;
+
+ for (final Iterator i = helpLines.iterator(); i.hasNext();) {
+ final HelpLine helpLine = (HelpLine) i.next();
+ final String usage = helpLine.usage(getLineUsageSettings(), getComparator());
+ usageWidth = Math.max(usageWidth, usage.length());
+ }
+
+ // build a blank string to pad wrapped descriptions
+ final StringBuffer blankBuffer = new StringBuffer();
+
+ for (int i = 0; i < usageWidth; i++) {
+ blankBuffer.append(' ');
+ }
+
+ // print a blank line
+ out.println();
+
+ // determine the width available for descriptions
+ final int descriptionWidth = Math.max(1, getPageWidth() - getGutterCenter().length() - usageWidth);
+
+ // display each HelpLine
+ for (final Iterator i = helpLines.iterator(); i.hasNext();) {
+ // grab the HelpLine
+ final HelpLine helpLine = (HelpLine) i.next();
+
+ // wrap the description
+ final List descList = wrap(helpLine.getDescription(), descriptionWidth);
+ final Iterator descriptionIterator = descList.iterator();
+
+ // display usage + first line of description
+ printGutterLeft();
+ pad(helpLine.usage(getLineUsageSettings(), getComparator()), usageWidth, out);
+ out.print(getGutterCenter());
+ pad((String) descriptionIterator.next(), descriptionWidth, out);
+ printGutterRight();
+ out.println();
+
+ // display padding + remaining lines of description
+ while (descriptionIterator.hasNext()) {
+ printGutterLeft();
+
+ //pad(helpLine.getUsage(),usageWidth,out);
+ out.print(blankBuffer);
+ out.print(getGutterCenter());
+ pad((String) descriptionIterator.next(), descriptionWidth, out);
+ printGutterRight();
+ out.println();
+ }
+ }
+ printExample();
+
+ printDivider();
+ }
+
+ public void printDescription() {
+ if (description != null) {
+ getPrintWriter().println();
+ getPrintWriter().println("Description:");
+ for (final Iterator i = wrap(description, getPageWidth() - 2).iterator(); i.hasNext();) {
+ printGutterLeft();
+ getPrintWriter().print(" ");
+ pad((String) i.next(), getPageWidth()-2, getPrintWriter());
+ printGutterRight();
+ getPrintWriter().println();
+ }
+ }
+ }
+
+ public void printExample() {
+ if (example != null) {
+ getPrintWriter().println();
+ getPrintWriter().println("Example:");
+ for (final Iterator i = wrap(example, getPageWidth() - 2).iterator(); i.hasNext();) {
+ printGutterLeft();
+ getPrintWriter().print(" ");
+ pad((String) i.next(), getPageWidth()-2, getPrintWriter());
+ printGutterRight();
+ getPrintWriter().println();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Log4JConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Log4JConfig.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Log4JConfig.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Log4JConfig.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.util;
+
+import java.net.URL;
+
+import org.apache.jackrabbit.vault.util.console.ExecutionException;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.PropertyConfigurator;
+
+/**
+ * <code>Log4JConfig</code>...
+ */
+public class Log4JConfig {
+
+ public static void init(String log4jConfig) {
+ URL url = Log4JConfig.class.getResource(log4jConfig);
+ PropertyConfigurator.configure(url);
+ }
+
+ public static void setLevel(String level) {
+ Level l = Level.toLevel(level);
+ if (l == null) {
+ throw new ExecutionException("Invalid log level " + level);
+ }
+ LogManager.getRootLogger().setLevel(l);
+ }
+
+ public static String getLevel() {
+ return LogManager.getRootLogger().getLevel().toString();
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/PomProperties.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/PomProperties.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/PomProperties.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/PomProperties.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * <code>PomProperties</code>...
+ */
+public class PomProperties {
+
+ public static String PROPS_PREFIX = "META-INF/maven/";
+
+ public static String PROPS_SUFFIX = "/pom.properties";
+
+ private final String groupId;
+
+ private final String artifactId;
+
+ private String pomPropsPath;
+
+ private Properties props;
+
+ public PomProperties(String groupId, String artifactId) {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ pomPropsPath = PROPS_PREFIX + groupId + "/" + artifactId + PROPS_SUFFIX;
+ }
+
+ public Properties getProperties() {
+ if (props == null) {
+ props = new Properties();
+ try {
+ InputStream in = PomProperties.class.getClassLoader().getResourceAsStream(pomPropsPath);
+ if (in != null) {
+ props.load(in);
+ in.close();
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return props;
+ }
+
+ public String getVersion() {
+ return getProperties().getProperty("version", "0.0.0");
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Table.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Table.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Table.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Table.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.util;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * <code>Table</code>...
+ */
+public class Table {
+ private int numCols;
+ private int[] lengths;
+ private LinkedList rows = new LinkedList();
+
+ public Table(int numCols) {
+ this.numCols = numCols;
+ lengths = new int[numCols];
+ }
+
+ public Row createRow() {
+ return new Row(numCols);
+ }
+
+ public void addRow(String c1, String c2) {
+ Row r = createRow();
+ r.addCol(c1);
+ r.addCol(c2);
+ addRow(r);
+ }
+
+ public void addRow(Row row) {
+ rows.add(row);
+ for (int i=0; i<row.cols.length; i++) {
+ if (row.cols[i] != null) {
+ int l = row.cols[i].value.length();
+ if (l > lengths[i]) {
+ lengths[i] = l;
+ }
+ }
+ }
+ }
+
+ public void print() {
+ Iterator iter = rows.iterator();
+ while (iter.hasNext()) {
+ Row r = (Row) iter.next();
+ StringBuffer buf = new StringBuffer();
+ r.print(buf, lengths);
+ System.out.println(buf);
+ }
+ }
+
+ public void sort(final int col) {
+ Collections.sort(rows, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ Row r1 = (Row) o1;
+ Row r2 = (Row) o2;
+ return r1.cols[col].value.compareTo(r2.cols[col].value);
+ }
+ });
+ }
+
+ public static class Row {
+ private Table.Col[] cols;
+
+ private int pos = 0;
+ public Row(int numCols) {
+ cols = new Table.Col[numCols];
+ }
+
+ public void addCol(String value) {
+ addCol(value, false);
+ }
+
+ public void addCol(String value, boolean align) {
+ cols[pos++] = new Table.Col(value, align);
+ }
+
+ public void print(StringBuffer buf, int[] lengths) {
+ for (int i=0; i<cols.length; i++) {
+ if (cols[i] != null) {
+ cols[i].print(buf, lengths[i]);
+ }
+ }
+ }
+ }
+
+ public static class Col {
+ public static final String SPACES = " "+
+ " "+
+ " "+
+ " "+
+ " "+
+ " "+
+ " ";
+ String value="";
+
+ private boolean alignRight;
+
+ public Col(String value) {
+ this.value = value;
+ }
+
+ public Col(String value, boolean align) {
+ this.value = value;
+ this.alignRight = align;
+ }
+
+ public void print(StringBuffer buf, int maxLength) {
+ if (value.length()>maxLength) {
+ buf.append(value.substring(0, maxLength));
+ } else {
+ if (alignRight) {
+ buf.append(SPACES.substring(0, maxLength - value.length()));
+ }
+ buf.append(value);
+ if (!alignRight) {
+ buf.append(SPACES.substring(0, maxLength - value.length()));
+ }
+ }
+ buf.append(" ");
+ }
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Text.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Text.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Text.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/java/org/apache/jackrabbit/vault/util/console/util/Text.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console.util;
+
+import java.util.ArrayList;
+
+/**
+ * <code>Text</code>...
+ */
+public class Text {
+
+ public static String[] parseLine(String line) {
+ ArrayList tokens = new ArrayList();
+ StringBuffer buf = new StringBuffer();
+ int quote = 0;
+ for (int i = 0; i < line.length(); i++) {
+ char c = line.charAt(i);
+ if (Character.isWhitespace(c)) {
+ if (quote == 0) {
+ if (buf.length() > 0) {
+ tokens.add(buf.toString());
+ buf = new StringBuffer();
+ }
+ } else {
+ buf.append(c);
+ }
+ } else if (c == '\'') {
+ if (quote == 1) {
+ quote = 0;
+ } else if (quote == 0) {
+ quote = 1;
+ } else {
+ buf.append(c);
+ }
+ } else if (c == '\"') {
+ if (quote == 2) {
+ quote = 0;
+ } else if (quote == 0) {
+ quote = 2;
+ } else {
+ buf.append(c);
+ }
+ } else {
+ buf.append(c);
+ }
+ }
+ if (buf.length() > 0) {
+ tokens.add(buf.toString());
+ }
+ return (String[]) tokens.toArray(new String[tokens.size()]);
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/resources/org/apache/jackrabbit/vault/cli/log4j.properties
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/resources/org/apache/jackrabbit/vault/cli/log4j.properties?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/resources/org/apache/jackrabbit/vault/cli/log4j.properties (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/resources/org/apache/jackrabbit/vault/cli/log4j.properties Sat Aug 10 05:53:42 2013
@@ -0,0 +1,26 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Set root logger level to WARN and its only appender to A1.
+log4j.rootLogger=WARN, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=[%-5p] %m%n
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/main/resources/org/apache/jackrabbit/vault/util/console/log4j.properties
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/main/resources/org/apache/jackrabbit/vault/util/console/log4j.properties?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/main/resources/org/apache/jackrabbit/vault/util/console/log4j.properties (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/main/resources/org/apache/jackrabbit/vault/util/console/log4j.properties Sat Aug 10 05:53:42 2013
@@ -0,0 +1,26 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Set root logger level to INFO and its only appender to A1.
+log4j.rootLogger=INFO, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=[%-5p] %m%n
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/test/java/org/apache/jackrabbit/vault/util/console/Test.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/test/java/org/apache/jackrabbit/vault/util/console/Test.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/test/java/org/apache/jackrabbit/vault/util/console/Test.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/test/java/org/apache/jackrabbit/vault/util/console/Test.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+import org.apache.commons.cli2.CommandLine;
+import org.apache.commons.cli2.DisplaySetting;
+import org.apache.commons.cli2.Group;
+import org.apache.commons.cli2.Option;
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.commons.cli2.commandline.Parser;
+import org.apache.commons.cli2.option.Command;
+import org.apache.commons.cli2.util.HelpFormatter;
+
+/**
+ * <code>Test</code>...
+ */
+public class Test {
+
+ public static void main(String[] args) throws Exception {
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+ final ArgumentBuilder abuilder = new ArgumentBuilder();
+ final CommandBuilder cbuilder = new CommandBuilder();
+ final GroupBuilder gbuilder = new GroupBuilder();
+
+ Option recursive =
+ obuilder
+ .withShortName("r")
+ .withLongName("recursive")
+ .withDescription("do recursively")
+ .create();
+ Command update =
+ cbuilder
+ .withName("update")
+ .withName("up")
+ .withDescription("update the work directory")
+ /*
+ .withChildren(new GroupBuilder()
+ .withName("options")
+ .withOption(recursive)
+ .create())
+ .withArgument(abuilder
+ .withName("path")
+ .withMinimum(0)
+ .create()
+ )
+ */
+ .create();
+ Option projecthelp =
+ obuilder
+ .withShortName("projecthelp")
+ .withShortName("p")
+ .withDescription("print project help information")
+ .create();
+ Option version =
+ obuilder
+ .withShortName("v")
+ .withDescription("print the version information and exit")
+ .create();
+
+ Group options =
+ gbuilder
+ .withName("Global options:")
+ .withOption(projecthelp)
+ .withOption(version)
+ .withMinimum(0)
+ .create();
+
+ Option command = abuilder.withName("command").withMinimum(1).withMaximum(1).create();
+ Option targets = abuilder.withName("arg").create();
+
+ CliCommand exit = new org.apache.jackrabbit.vault.util.console.commands.CmdExit();
+ CliCommand help = new org.apache.jackrabbit.vault.util.console.commands.CmdHelp();
+ CliCommand setenv = new org.apache.jackrabbit.vault.util.console.commands.CmdSet();
+ Group commands =
+ gbuilder
+ .withName("Commands:")
+ .withOption(help.getCommand())
+ .withOption(exit.getCommand())
+ .withOption(setenv.getCommand())
+ .withOption(update)
+ .withMinimum(0)
+ .withMaximum(1)
+ .create();
+
+ Group main =
+ gbuilder
+ .withName("")
+ .withOption(options)
+ .withOption(commands)
+ .withMinimum(0)
+ .create();
+
+ HelpFormatter hf = new HelpFormatter();
+ StringBuffer sep = new StringBuffer(hf.getPageWidth());
+ while (sep.length() < hf.getPageWidth()) {
+ sep.append("-");
+ }
+ hf.setHeader("File Vault version 1.0");
+ hf.setDivider(sep.toString());
+ hf.setShellCommand("vlt [options] <command> [arg1 [arg2 [arg3] ..]]");
+ hf.setGroup(main);
+ //hf.setHeader("bla bla version vla");
+ //displayHelp();
+ hf.getFullUsageSettings().removeAll(DisplaySetting.ALL);
+
+ //hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
+ //hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+
+ //hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_OPTIONAL);
+ hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
+ hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
+
+ hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
+ hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+ hf.getDisplaySettings().add(DisplaySetting.DISPLAY_OPTIONAL);
+
+ //hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
+ //hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
+ //hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_GROUP_NAME);
+ //hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+ //hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
+ //hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
+ //hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+ //hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+
+ hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
+ hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
+ hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
+
+ Parser parser = new Parser();
+ parser.setHelpFormatter(hf);
+ parser.setGroup(main);
+ System.out.println(main);
+
+ CommandLine cl = parser.parseAndHelp(args);
+ if (cl != null) {
+ if (exit.execute(null, cl)) {
+ System.out.println("exit executed");
+ } else if (help.execute(null, cl)) {
+ System.out.println("help executed.");
+ } else {
+ hf.print();
+ }
+ }
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-cli/src/test/java/org/apache/jackrabbit/vault/util/console/TestSubHelp.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-cli/src/test/java/org/apache/jackrabbit/vault/util/console/TestSubHelp.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-cli/src/test/java/org/apache/jackrabbit/vault/util/console/TestSubHelp.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-cli/src/test/java/org/apache/jackrabbit/vault/util/console/TestSubHelp.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.vault.util.console;
+
+import org.apache.commons.cli2.builder.ArgumentBuilder;
+import org.apache.commons.cli2.builder.CommandBuilder;
+import org.apache.commons.cli2.builder.DefaultOptionBuilder;
+import org.apache.commons.cli2.builder.GroupBuilder;
+import org.apache.jackrabbit.vault.util.console.commands.CmdSet;
+import org.apache.jackrabbit.vault.util.console.util.CliHelpFormatter;
+
+/**
+ * <code>Test</code>...
+ */
+public class TestSubHelp {
+
+ public static void main(String[] args) throws Exception {
+ final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
+ final ArgumentBuilder abuilder = new ArgumentBuilder();
+ final CommandBuilder cbuilder = new CommandBuilder();
+ final GroupBuilder gbuilder = new GroupBuilder();
+
+ CmdSet set = new CmdSet();
+
+ CliHelpFormatter hf = CliHelpFormatter.create();
+ hf.setCmd(set);
+ //hf.setHeader("bla bla version vla");
+ //displayHelp();
+ //hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_OPTIONAL);
+
+ //hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
+ //hf.getDisplaySettings().add(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+
+ //hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_OPTIONAL);
+ //hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
+ //hf.getFullUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
+
+ //hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
+ //hf.getDisplaySettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+ //hf.getDisplaySettings().add(DisplaySetting.DISPLAY_OPTIONAL);
+
+ //hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
+ //hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
+ //hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_GROUP_NAME);
+ //hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+ //hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_GROUP_ARGUMENT);
+ //hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_GROUP_EXPANDED);
+ //hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+ //hf.getLineUsageSettings().remove(DisplaySetting.DISPLAY_PARENT_CHILDREN);
+
+ //hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PROPERTY_OPTION);
+ //hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_PARENT_ARGUMENT);
+ //hf.getLineUsageSettings().add(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
+
+ hf.print();
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/pom.xml?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/pom.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/pom.xml Sat Aug 10 05:53:42 2013
@@ -0,0 +1,202 @@
+<?xml version="1.0"?><!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd ">
+ <modelVersion>4.0.0</modelVersion>
+ <!-- ====================================================================== -->
+ <!-- P A R E N T P R O J E C T D E S C R I P T I O N -->
+ <!-- ====================================================================== -->
+ <parent>
+ <groupId>org.apache.jackrabbit.vault</groupId>
+ <artifactId>parent</artifactId>
+ <relativePath>../parent/pom.xml</relativePath>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <!-- ====================================================================== -->
+ <!-- P R O J E C T D E S C R I P T I O N -->
+ <!-- ====================================================================== -->
+ <artifactId>org.apache.jackrabbit.vault</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <packaging>bundle</packaging>
+
+ <name>Apache Jackrabbit FileVault Core Bundle</name>
+ <description>
+ Builds an OSGi bundle for the file vault parts
+ </description>
+
+ <!-- ====================================================================== -->
+ <!-- S C M D E F I N I T I O N -->
+ <!-- ====================================================================== -->
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/jackrabbit/commons/filevault/trunk/vault-core</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/jackrabbit/commons/filevault/trunk/vault-core</developerConnection>
+ <url>http://svn.apache.org/viewvc/asf/jackrabbit/commons/filevault/trunk/vault-core</url>
+ </scm>
+
+ <!-- ====================================================================== -->
+ <!-- B U I L D -->
+ <!-- ====================================================================== -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>maven-sling-plugin</artifactId>
+ <configuration>
+ <slingUrlSuffix>/libs/system/install/</slingUrlSuffix>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-Build>${buildNumber}</Bundle-Build>
+ <Bundle-Category>jcr,granite</Bundle-Category>
+ <Export-Package>
+ org.apache.jackrabbit.vault.fs;version=2.4.0,
+ org.apache.jackrabbit.vault.fs.api;version=2.4.0,
+ org.apache.jackrabbit.vault.fs.spi;version=2.4.0,
+ org.apache.jackrabbit.vault.fs.config;version=2.4.0,
+ org.apache.jackrabbit.vault.fs.filter;version=2.4.0,
+ org.apache.jackrabbit.vault.fs.io;version=2.4.0,
+ org.apache.jackrabbit.vault.util.*;version=2.4.0,
+ org.apache.jackrabbit.vault.packaging;version=2.4.0
+ </Export-Package>
+ <Private-Package>
+ org.apache.jackrabbit.vault.fs.impl.*,
+ org.apache.jackrabbit.vault.fs.spi.impl.*,
+ org.apache.jackrabbit.vault.packaging.impl.*,
+ org.apache.jackrabbit.vault.packaging.hotfix.*
+ </Private-Package>
+ <Import-Package>
+ org.apache.jackrabbit.*;version=!,
+ org.apache.jackrabbit.api.security;version=!,
+ org.apache.sling.jcr.api;resolution:=optional,
+ javax.jcr,
+ javax.jcr.lock,
+ javax.jcr.nodetype,
+ javax.jcr.observation,
+ javax.jcr.query,
+ javax.jcr.query.qom,
+ javax.jcr.retention,
+ javax.jcr.security,
+ javax.jcr.util,
+ javax.jcr.version,
+ *
+ </Import-Package>
+ <Embed-Dependency>
+ jackrabbit-spi-commons,
+ jackrabbit-spi
+ </Embed-Dependency>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- ====================================================================== -->
+ <!-- D E P E N D E N C I E S -->
+ <!-- ====================================================================== -->
+ <dependencies>
+ <!-- jackrabbit -->
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-commons</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-spi-commons</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-spi</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- JCR Stuff -->
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- SLF4j / Log4j -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- osgi stuff -->
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <!-- used to retrieve the sling repository for JMX support -->
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.jcr.api</artifactId>
+ <version>2.0.4</version>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+
+ <!-- test deps -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>1.5.8</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.9.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-core</artifactId>
+ <version>${jackrabbit.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Added: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/DirectoryArtifact.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/DirectoryArtifact.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/DirectoryArtifact.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/DirectoryArtifact.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.fs;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.vault.fs.api.AccessType;
+import org.apache.jackrabbit.vault.fs.api.ArtifactType;
+import org.apache.jackrabbit.vault.fs.api.ExportArtifact;
+import org.apache.jackrabbit.vault.fs.api.ImportArtifact;
+import org.apache.jackrabbit.vault.fs.api.SerializationType;
+import org.apache.jackrabbit.vault.fs.api.VaultInputSource;
+import org.apache.jackrabbit.vault.fs.impl.AbstractArtifact;
+
+/**
+ * Implements a generic directory artifact.
+ *
+ */
+public class DirectoryArtifact extends AbstractArtifact
+ implements ExportArtifact, ImportArtifact {
+
+ /**
+ * Constructs a new directory type artifact with the given repository name.
+ *
+ * @param name the repository name for this artifact.
+ */
+ public DirectoryArtifact(String name) {
+ super(null, name, "", ArtifactType.DIRECTORY);
+ }
+
+ /**
+ * Constructs a new directory type artifact with the given repository name
+ * and extension
+ *
+ * @param name the repository name for this artifact.
+ * @param extension the extension for this artifact
+ */
+ public DirectoryArtifact(String name, String extension) {
+ super(null, name, extension, ArtifactType.DIRECTORY);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SerializationType getSerializationType() {
+ return SerializationType.NONE;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return always {@link AccessType#NONE}
+ */
+ public AccessType getPreferredAccess() {
+ return AccessType.NONE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void spool(OutputStream out) throws IOException, RepositoryException {
+ throw new UnsupportedOperationException("Illegall access method for " + this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public InputStream getInputStream() throws IOException, RepositoryException {
+ throw new UnsupportedOperationException("Illegall access method for " + this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public VaultInputSource getInputSource() throws IOException, RepositoryException {
+ throw new UnsupportedOperationException("Illegall access method for " + this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getContentLength() {
+ return -1;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getLastModified() {
+ return 0;
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/HintArtifact.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/HintArtifact.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/HintArtifact.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/HintArtifact.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.fs;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.vault.fs.api.AccessType;
+import org.apache.jackrabbit.vault.fs.api.ArtifactType;
+import org.apache.jackrabbit.vault.fs.api.ExportArtifact;
+import org.apache.jackrabbit.vault.fs.api.ImportArtifact;
+import org.apache.jackrabbit.vault.fs.api.SerializationType;
+import org.apache.jackrabbit.vault.fs.api.VaultInputSource;
+import org.apache.jackrabbit.vault.fs.impl.AbstractArtifact;
+
+/**
+ * Implements a generic hint artifact.
+ */
+public class HintArtifact extends AbstractArtifact
+ implements ExportArtifact, ImportArtifact {
+
+ /**
+ * Constructs a new directory type artifact with the given repository name.
+ *
+ * @param name the repository name for this artifact.
+ */
+ public HintArtifact(String name) {
+ super(null, name, "", ArtifactType.HINT);
+ }
+
+ /**
+ * Constructs a new directory type artifact with the given repository name
+ * and extension
+ *
+ * @param name the repository name for this artifact.
+ * @param extension the extension for this artifact
+ */
+ public HintArtifact(String name, String extension) {
+ super(null, name, extension, ArtifactType.HINT);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SerializationType getSerializationType() {
+ return SerializationType.NONE;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return always {@link AccessType#NONE}
+ */
+ public AccessType getPreferredAccess() {
+ return AccessType.NONE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void spool(OutputStream out) throws IOException, RepositoryException {
+ throw new UnsupportedOperationException("Illegall access method for " + this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public InputStream getInputStream() throws IOException, RepositoryException {
+ throw new UnsupportedOperationException("Illegall access method for " + this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public VaultInputSource getInputSource() throws IOException, RepositoryException {
+ throw new UnsupportedOperationException("Illegall access method for " + this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getContentLength() {
+ return -1;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getLastModified() {
+ return 0;
+ }
+}
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/Mounter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/Mounter.java?rev=1512568&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/Mounter.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/Mounter.java Sat Aug 10 05:53:42 2013
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jackrabbit.vault.fs;
+
+import java.io.IOException;
+
+import javax.jcr.Credentials;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.vault.fs.api.RepositoryAddress;
+import org.apache.jackrabbit.vault.fs.api.VaultFileSystem;
+import org.apache.jackrabbit.vault.fs.api.VaultFsConfig;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.impl.AggregateManagerImpl;
+import org.apache.jackrabbit.vault.fs.impl.VaultFileSystemImpl;
+
+/**
+ * Utility method to mount a JCR FS.
+ * The filesystem is mounted relative to the given <code>mountpoint</code> and rooted at <code>rootPath</code>.
+ * For example if the mountpoint is http://.../test/export and the rootPath is /foo, then the filesystem's root node
+ * has a internal repository path "/foo" that corresponds to the "real" repository node at "/test/export".
+ * The workspace filter will be matched against the filesystem paths (e.g. /foo).
+ */
+public final class Mounter {
+
+ /**
+ * Mounts a new Vault filesystem on the given repository node.
+ *
+ * @param config vault fs config
+ * @param wspFilter the workspace filter
+ * @param mountpoint the address of the mountpoint
+ * @param rootPath path of root file. used for remapping
+ * @param session the repository session
+ * @return a Vault filesystem
+ * @throws RepositoryException if an error occurs.
+ * @throws IOException if an I/O error occurs.
+ */
+ public static VaultFileSystem mount(VaultFsConfig config,
+ WorkspaceFilter wspFilter,
+ RepositoryAddress mountpoint,
+ String rootPath,
+ Session session)
+ throws RepositoryException, IOException {
+ return new VaultFileSystemImpl(
+ AggregateManagerImpl.mount(
+ config, wspFilter, mountpoint, session
+ ).getRoot(),
+ rootPath,
+ true
+ );
+ }
+
+ /**
+ * Mounts a new Vault filesystem that is rooted at the given path using
+ * the provided repository, credentials and workspace to create the
+ * session.
+ *
+ * @param config vault fs config
+ * @param wspFilter the workspace filter
+ * @param rep the jcr repository
+ * @param credentials the credentials
+ * @param mountpoint the repository address of the mountpoint
+ * @param rootPath path of root file. used for remapping
+ * @return an aggregate manager
+ * @throws RepositoryException if an error occurs.
+ * @throws IOException if an I/O error occurs.
+ */
+ public static VaultFileSystem mount(VaultFsConfig config,
+ WorkspaceFilter wspFilter,
+ Repository rep,
+ Credentials credentials,
+ RepositoryAddress mountpoint,
+ String rootPath)
+ throws RepositoryException, IOException {
+ return new VaultFileSystemImpl(
+ AggregateManagerImpl.mount(config, wspFilter, rep, credentials,
+ mountpoint).getRoot(),
+ rootPath, true);
+ }
+
+
+}
\ No newline at end of file