accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [5/6] accumulo git commit: Merge branch '1.6' into 1.7
Date Thu, 02 Jul 2015 22:17:22 GMT
Merge branch '1.6' into 1.7

Conflicts:
	shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/acef2e5d
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/acef2e5d
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/acef2e5d

Branch: refs/heads/1.7
Commit: acef2e5d4a72c0dcd372ce0d35da4fc307b74496
Parents: ba300ba 62e3b0f
Author: Josh Elser <elserj@apache.org>
Authored: Thu Jul 2 17:57:11 2015 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Thu Jul 2 18:17:02 2015 -0400

----------------------------------------------------------------------
 .../java/org/apache/accumulo/shell/mock/MockShell.java   | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/acef2e5d/shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java
----------------------------------------------------------------------
diff --cc shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java
index c11aed5,0000000..609f23f
mode 100644,000000..100644
--- a/shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/mock/MockShell.java
@@@ -1,146 -1,0 +1,157 @@@
 +/*
 + * 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.accumulo.shell.mock;
 +
 +import static java.nio.charset.StandardCharsets.UTF_8;
 +
 +import java.io.ByteArrayInputStream;
 +import java.io.IOException;
 +import java.io.InputStream;
 +import java.io.OutputStream;
 +
 +import jline.console.ConsoleReader;
 +
++import org.apache.accumulo.core.client.AccumuloException;
++import org.apache.accumulo.core.client.AccumuloSecurityException;
++import org.apache.accumulo.core.client.TableNotFoundException;
 +import org.apache.accumulo.core.client.mock.MockInstance;
 +import org.apache.accumulo.shell.Shell;
 +import org.apache.accumulo.shell.ShellOptionsJC;
++import org.apache.commons.cli.CommandLine;
++import org.apache.commons.vfs2.FileSystemException;
 +
 +/**
 + * An Accumulo Shell implementation that allows a developer to attach an InputStream and
Writer to the Shell for testing purposes.
 + */
 +public class MockShell extends Shell {
 +  private static final String NEWLINE = "\n";
 +
 +  protected InputStream in;
 +  protected OutputStream out;
 +
 +  public MockShell(InputStream in, OutputStream out) throws IOException {
 +    super();
 +    this.in = in;
 +    this.out = out;
 +  }
 +
 +  @Override
 +  public boolean config(String... args) {
 +    // If configuring the shell failed, fail quickly
 +    if (!super.config(args)) {
 +      return false;
 +    }
 +
 +    // Update the ConsoleReader with the input and output "redirected"
 +    try {
 +      this.reader = new ConsoleReader(in, out);
 +    } catch (Exception e) {
 +      printException(e);
 +      return false;
 +    }
 +
 +    // Don't need this for testing purposes
 +    this.reader.setHistoryEnabled(false);
 +    this.reader.setPaginationEnabled(false);
 +
 +    // Make the parsing from the client easier;
 +    this.verbose = false;
 +    return true;
 +  }
 +
 +  @Override
 +  protected void setInstance(ShellOptionsJC options) {
 +    // We always want a MockInstance for this test
 +    instance = new MockInstance();
 +  }
 +
 +  @Override
 +  public int start() throws IOException {
 +    String input;
 +    if (isVerbose())
 +      printInfo();
 +
 +    if (execFile != null) {
 +      java.util.Scanner scanner = new java.util.Scanner(execFile, UTF_8.name());
 +      try {
 +        while (scanner.hasNextLine() && !hasExited()) {
 +          execCommand(scanner.nextLine(), true, isVerbose());
 +        }
 +      } finally {
 +        scanner.close();
 +      }
 +    } else if (execCommand != null) {
 +      for (String command : execCommand.split("\n")) {
 +        execCommand(command, true, isVerbose());
 +      }
 +      return exitCode;
 +    }
 +
 +    while (true) {
 +      if (hasExited())
 +        return exitCode;
 +
 +      reader.setPrompt(getDefaultPrompt());
 +      input = reader.readLine();
 +      if (input == null) {
 +        reader.println();
 +        return exitCode;
 +      } // user canceled
 +
 +      execCommand(input, false, false);
 +    }
 +  }
 +
 +  /**
 +   * @param in
 +   *          the in to set
 +   */
 +  public void setConsoleInputStream(InputStream in) {
 +    this.in = in;
 +  }
 +
 +  /**
 +   * @param out
 +   *          the output stream to set
 +   */
 +  public void setConsoleWriter(OutputStream out) {
 +    this.out = out;
 +  }
 +
++  @Override
++  public ClassLoader getClassLoader(final CommandLine cl, final Shell shellState) throws
AccumuloException, TableNotFoundException, AccumuloSecurityException,
++      IOException, FileSystemException {
++    return MockShell.class.getClassLoader();
++  }
++
 +  /**
 +   * Convenience method to create the byte-array to hand to the console
 +   *
 +   * @param commands
 +   *          An array of commands to run
 +   * @return A byte[] input stream which can be handed to the console.
 +   */
 +  public static ByteArrayInputStream makeCommands(String... commands) {
 +    StringBuilder sb = new StringBuilder(commands.length * 8);
 +
 +    for (String command : commands) {
 +      sb.append(command).append(NEWLINE);
 +    }
 +
 +    return new ByteArrayInputStream(sb.toString().getBytes(UTF_8));
 +  }
 +}


Mime
View raw message