hawq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [18/51] [abbrv] [partial] incubator-hawq git commit: HAWQ-735. Import thrift-0.9.3 into depends/thirdparty/thrift folder
Date Wed, 18 May 2016 02:50:31 GMT
http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/AbstractThriftMojo.java
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/AbstractThriftMojo.java b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/AbstractThriftMojo.java
new file mode 100644
index 0000000..63451c3
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/AbstractThriftMojo.java
@@ -0,0 +1,377 @@
+/*
+ * 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.thrift.maven;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableSet;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.io.RawInputStreamFacade;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.collect.Sets.newHashSet;
+import static java.lang.String.format;
+import static java.util.Arrays.asList;
+import static java.util.Collections.list;
+import static org.codehaus.plexus.util.FileUtils.cleanDirectory;
+import static org.codehaus.plexus.util.FileUtils.copyStreamToFile;
+import static org.codehaus.plexus.util.FileUtils.getFiles;
+
+/**
+ * Abstract Mojo implementation.
+ * <p/>
+ * This class is extended by {@link org.apache.thrift.maven.ThriftCompileMojo} and
+ * {@link org.apache.thrift.maven.ThriftTestCompileMojo} in order to override the specific configuration for
+ * compiling the main or test classes respectively.
+ */
+abstract class AbstractThriftMojo extends AbstractMojo {
+
+    private static final String THRIFT_FILE_SUFFIX = ".thrift";
+
+    private static final String DEFAULT_INCLUDES = "**/*" + THRIFT_FILE_SUFFIX;
+
+    /**
+     * The current Maven project.
+     *
+     * @parameter default-value="${project}"
+     * @readonly
+     * @required
+     */
+    protected MavenProject project;
+
+    /**
+     * A helper used to add resources to the project.
+     *
+     * @component
+     * @required
+     */
+    protected MavenProjectHelper projectHelper;
+
+    /**
+     * This is the path to the {@code thrift} executable. By default it will search the {@code $PATH}.
+     *
+     * @parameter default-value="thrift"
+     * @required
+     */
+    private String thriftExecutable;
+
+    /**
+     * This string is passed to the {@code --gen} option of the {@code thrift} parameter. By default
+     * it will generate Java output. The main reason for this option is to be able to add options
+     * to the Java generator - if you generate something else, you're on your own.
+     *
+     * @parameter default-value="java:hashcode"
+     */
+    private String generator;
+
+    /**
+     * @parameter
+     */
+    private File[] additionalThriftPathElements = new File[]{};
+
+    /**
+     * Since {@code thrift} cannot access jars, thrift files in dependencies are extracted to this location
+     * and deleted on exit. This directory is always cleaned during execution.
+     *
+     * @parameter property="${project.build.directory}/thrift-dependencies"
+     * @required
+     */
+    private File temporaryThriftFileDirectory;
+
+    /**
+     * This is the path to the local maven {@code repository}.
+     *
+     * @parameter default-value="${localRepository}"
+     * @required
+     */
+    private ArtifactRepository localRepository;
+
+    /**
+     * Set this to {@code false} to disable hashing of dependent jar paths.
+     * <p/>
+     * This plugin expands jars on the classpath looking for embedded .thrift files.
+     * Normally these paths are hashed (MD5) to avoid issues with long file names on windows.
+     * However if this property is set to {@code false} longer paths will be used.
+     *
+     * @parameter default-value="true"
+     * @required
+     */
+    private boolean hashDependentPaths;
+
+    /**
+     * @parameter
+     */
+    private Set<String> includes = ImmutableSet.of(DEFAULT_INCLUDES);
+
+    /**
+     * @parameter
+     */
+    private Set<String> excludes = ImmutableSet.of();
+
+    /**
+     * @parameter
+     */
+    private long staleMillis = 0;
+
+    /**
+     * @parameter
+     */
+    private boolean checkStaleness = false;
+
+    /**
+     * Executes the mojo.
+     */
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        checkParameters();
+        final File thriftSourceRoot = getThriftSourceRoot();
+        if (thriftSourceRoot.exists()) {
+            try {
+                ImmutableSet<File> thriftFiles = findThriftFilesInDirectory(thriftSourceRoot);
+                final File outputDirectory = getOutputDirectory();
+                ImmutableSet<File> outputFiles = findGeneratedFilesInDirectory(getOutputDirectory());
+
+                if (thriftFiles.isEmpty()) {
+                    getLog().info("No thrift files to compile.");
+                } else if (checkStaleness && ((lastModified(thriftFiles) + staleMillis) < lastModified(outputFiles))) {
+                    getLog().info("Skipping compilation because target directory newer than sources.");
+                    attachFiles();
+                } else {
+                    ImmutableSet<File> derivedThriftPathElements =
+                            makeThriftPathFromJars(temporaryThriftFileDirectory, getDependencyArtifactFiles());
+                    outputDirectory.mkdirs();
+
+                    // Quick fix to fix issues with two mvn installs in a row (ie no clean)
+                    // cleanDirectory(outputDirectory);
+
+                    Thrift thrift = new Thrift.Builder(thriftExecutable, outputDirectory)
+                            .setGenerator(generator)
+                            .addThriftPathElement(thriftSourceRoot)
+                            .addThriftPathElements(derivedThriftPathElements)
+                            .addThriftPathElements(asList(additionalThriftPathElements))
+                            .addThriftFiles(thriftFiles)
+                            .build();
+                    final int exitStatus = thrift.compile();
+                    if (exitStatus != 0) {
+                        getLog().error("thrift failed output: " + thrift.getOutput());
+                        getLog().error("thrift failed error: " + thrift.getError());
+                        throw new MojoFailureException(
+                                "thrift did not exit cleanly. Review output for more information.");
+                    }
+                    attachFiles();
+                }
+            } catch (IOException e) {
+                throw new MojoExecutionException("An IO error occurred", e);
+            } catch (IllegalArgumentException e) {
+                throw new MojoFailureException("thrift failed to execute because: " + e.getMessage(), e);
+            } catch (CommandLineException e) {
+                throw new MojoExecutionException("An error occurred while invoking thrift.", e);
+            }
+        } else {
+            getLog().info(format("%s does not exist. Review the configuration or consider disabling the plugin.",
+                    thriftSourceRoot));
+        }
+    }
+
+    ImmutableSet<File> findGeneratedFilesInDirectory(File directory) throws IOException {
+        if (directory == null || !directory.isDirectory())
+            return ImmutableSet.of();
+
+        List<File> javaFilesInDirectory = getFiles(directory, "**/*.java", null);
+        return ImmutableSet.copyOf(javaFilesInDirectory);
+    }
+
+    private long lastModified(ImmutableSet<File> files) {
+        long result = 0;
+        for (File file : files) {
+            if (file.lastModified() > result)
+                result = file.lastModified();
+        }
+        return result;
+    }
+
+    private void checkParameters() {
+        checkNotNull(project, "project");
+        checkNotNull(projectHelper, "projectHelper");
+        checkNotNull(thriftExecutable, "thriftExecutable");
+        checkNotNull(generator, "generator");
+        final File thriftSourceRoot = getThriftSourceRoot();
+        checkNotNull(thriftSourceRoot);
+        checkArgument(!thriftSourceRoot.isFile(), "thriftSourceRoot is a file, not a diretory");
+        checkNotNull(temporaryThriftFileDirectory, "temporaryThriftFileDirectory");
+        checkState(!temporaryThriftFileDirectory.isFile(), "temporaryThriftFileDirectory is a file, not a directory");
+        final File outputDirectory = getOutputDirectory();
+        checkNotNull(outputDirectory);
+        checkState(!outputDirectory.isFile(), "the outputDirectory is a file, not a directory");
+    }
+
+    protected abstract File getThriftSourceRoot();
+
+    protected abstract List<Artifact> getDependencyArtifacts();
+
+    protected abstract File getOutputDirectory();
+
+    protected abstract void attachFiles();
+
+    /**
+     * Gets the {@link File} for each dependency artifact.
+     *
+     * @return A set of all dependency artifacts.
+     */
+    private ImmutableSet<File> getDependencyArtifactFiles() {
+        Set<File> dependencyArtifactFiles = newHashSet();
+        for (Artifact artifact : getDependencyArtifacts()) {
+            dependencyArtifactFiles.add(artifact.getFile());
+        }
+        return ImmutableSet.copyOf(dependencyArtifactFiles);
+    }
+
+    /**
+     * @throws IOException
+     */
+    ImmutableSet<File> makeThriftPathFromJars(File temporaryThriftFileDirectory, Iterable<File> classpathElementFiles)
+            throws IOException, MojoExecutionException {
+        checkNotNull(classpathElementFiles, "classpathElementFiles");
+        // clean the temporary directory to ensure that stale files aren't used
+        if (temporaryThriftFileDirectory.exists()) {
+            cleanDirectory(temporaryThriftFileDirectory);
+        }
+        Set<File> thriftDirectories = newHashSet();
+        for (File classpathElementFile : classpathElementFiles) {
+            // for some reason under IAM, we receive poms as dependent files
+            // I am excluding .xml rather than including .jar as there may be other extensions in use (sar, har, zip)
+            if (classpathElementFile.isFile() && classpathElementFile.canRead() &&
+                    !classpathElementFile.getName().endsWith(".xml")) {
+
+                // create the jar file. the constructor validates.
+                JarFile classpathJar;
+                try {
+                    classpathJar = new JarFile(classpathElementFile);
+                } catch (IOException e) {
+                    throw new IllegalArgumentException(format(
+                            "%s was not a readable artifact", classpathElementFile));
+                }
+                for (JarEntry jarEntry : list(classpathJar.entries())) {
+                    final String jarEntryName = jarEntry.getName();
+                    if (jarEntry.getName().endsWith(THRIFT_FILE_SUFFIX)) {
+                        final File uncompressedCopy =
+                                new File(new File(temporaryThriftFileDirectory,
+                                        truncatePath(classpathJar.getName())), jarEntryName);
+                        uncompressedCopy.getParentFile().mkdirs();
+                        copyStreamToFile(new RawInputStreamFacade(classpathJar
+                                .getInputStream(jarEntry)), uncompressedCopy);
+                        thriftDirectories.add(uncompressedCopy.getParentFile());
+                    }
+                }
+            } else if (classpathElementFile.isDirectory()) {
+                File[] thriftFiles = classpathElementFile.listFiles(new FilenameFilter() {
+                    public boolean accept(File dir, String name) {
+                        return name.endsWith(THRIFT_FILE_SUFFIX);
+                    }
+                });
+
+                if (thriftFiles.length > 0) {
+                    thriftDirectories.add(classpathElementFile);
+                }
+            }
+        }
+        return ImmutableSet.copyOf(thriftDirectories);
+    }
+
+    ImmutableSet<File> findThriftFilesInDirectory(File directory) throws IOException {
+        checkNotNull(directory);
+        checkArgument(directory.isDirectory(), "%s is not a directory", directory);
+        List<File> thriftFilesInDirectory = getFiles(directory, 
+        		Joiner.on(",").join(includes),
+        		Joiner.on(",").join(excludes));
+        return ImmutableSet.copyOf(thriftFilesInDirectory);
+    }
+
+    ImmutableSet<File> findThriftFilesInDirectories(Iterable<File> directories) throws IOException {
+        checkNotNull(directories);
+        Set<File> thriftFiles = newHashSet();
+        for (File directory : directories) {
+            thriftFiles.addAll(findThriftFilesInDirectory(directory));
+        }
+        return ImmutableSet.copyOf(thriftFiles);
+    }
+
+    /**
+     * Truncates the path of jar files so that they are relative to the local repository.
+     *
+     * @param jarPath the full path of a jar file.
+     * @return the truncated path relative to the local repository or root of the drive.
+     */
+    String truncatePath(final String jarPath) throws MojoExecutionException {
+
+        if (hashDependentPaths) {
+            try {
+                return toHexString(MessageDigest.getInstance("MD5").digest(jarPath.getBytes()));
+            } catch (NoSuchAlgorithmException e) {
+                throw new MojoExecutionException("Failed to expand dependent jar", e);
+            }
+        }
+
+        String repository = localRepository.getBasedir().replace('\\', '/');
+        if (!repository.endsWith("/")) {
+            repository += "/";
+        }
+
+        String path = jarPath.replace('\\', '/');
+        int repositoryIndex = path.indexOf(repository);
+        if (repositoryIndex != -1) {
+            path = path.substring(repositoryIndex + repository.length());
+        }
+
+        // By now the path should be good, but do a final check to fix windows machines.
+        int colonIndex = path.indexOf(':');
+        if (colonIndex != -1) {
+            // 2 = :\ in C:\
+            path = path.substring(colonIndex + 2);
+        }
+
+        return path;
+    }
+
+    private static final char[] HEX_CHARS = "0123456789abcdef".toCharArray();
+
+    public static String toHexString(byte[] byteArray) {
+        final StringBuilder hexString = new StringBuilder(2 * byteArray.length);
+        for (final byte b : byteArray) {
+            hexString.append(HEX_CHARS[(b & 0xF0) >> 4]).append(HEX_CHARS[b & 0x0F]);
+        }
+        return hexString.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/Thrift.java
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/Thrift.java b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/Thrift.java
new file mode 100644
index 0000000..6eea954
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/Thrift.java
@@ -0,0 +1,262 @@
+/*
+ * 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.thrift.maven;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import java.io.File;
+import java.util.List;
+import java.util.Set;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Preconditions.checkState;
+import static com.google.common.collect.Lists.newLinkedList;
+import static com.google.common.collect.Sets.newHashSet;
+
+/**
+ * This class represents an invokable configuration of the {@code thrift}
+ * compiler. The actual executable is invoked using the plexus
+ * {@link Commandline}.
+ * <p/>
+ * This class currently only supports generating java source files.
+ */
+final class Thrift {
+
+    final static String GENERATED_JAVA = "gen-java";
+
+    private final String executable;
+    private final String generator;
+    private final ImmutableSet<File> thriftPathElements;
+    private final ImmutableSet<File> thriftFiles;
+    private final File javaOutputDirectory;
+    private final CommandLineUtils.StringStreamConsumer output;
+    private final CommandLineUtils.StringStreamConsumer error;
+
+    /**
+     * Constructs a new instance. This should only be used by the {@link Builder}.
+     *
+     * @param executable          The path to the {@code thrift} executable.
+     * @param generator           The value for the {@code --gen} option.
+     * @param thriftPath          The directories in which to search for imports.
+     * @param thriftFiles         The thrift source files to compile.
+     * @param javaOutputDirectory The directory into which the java source files
+     *                            will be generated.
+     */
+    private Thrift(String executable, String generator, ImmutableSet<File> thriftPath,
+                   ImmutableSet<File> thriftFiles, File javaOutputDirectory) {
+        this.executable = checkNotNull(executable, "executable");
+        this.generator = checkNotNull(generator, "generator");
+        this.thriftPathElements = checkNotNull(thriftPath, "thriftPath");
+        this.thriftFiles = checkNotNull(thriftFiles, "thriftFiles");
+        this.javaOutputDirectory = checkNotNull(javaOutputDirectory, "javaOutputDirectory");
+        this.error = new CommandLineUtils.StringStreamConsumer();
+        this.output = new CommandLineUtils.StringStreamConsumer();
+    }
+
+    /**
+     * Invokes the {@code thrift} compiler using the configuration specified at
+     * construction.
+     *
+     * @return The exit status of {@code thrift}.
+     * @throws CommandLineException
+     */
+    public int compile() throws CommandLineException {
+
+        for (File thriftFile : thriftFiles) {
+            Commandline cl = new Commandline();
+            cl.setExecutable(executable);
+            cl.addArguments(buildThriftCommand(thriftFile).toArray(new String[]{}));
+            final int result = CommandLineUtils.executeCommandLine(cl, null, output, error);
+
+            if (result != 0) {
+                return result;
+            }
+        }
+
+        // result will always be 0 here.
+        return 0;
+    }
+
+    /**
+     * Creates the command line arguments.
+     * <p/>
+     * This method has been made visible for testing only.
+     *
+     * @param thriftFile
+     * @return A list consisting of the executable followed by any arguments.
+     */
+    ImmutableList<String> buildThriftCommand(final File thriftFile) {
+        final List<String> command = newLinkedList();
+        // add the executable
+        for (File thriftPathElement : thriftPathElements) {
+            command.add("-I");
+            command.add(thriftPathElement.toString());
+        }
+        command.add("-out");
+        command.add(javaOutputDirectory.toString());
+        command.add("--gen");
+        command.add(generator);
+        command.add(thriftFile.toString());
+        return ImmutableList.copyOf(command);
+    }
+
+    /**
+     * @return the output
+     */
+    public String getOutput() {
+        return output.getOutput();
+    }
+
+    /**
+     * @return the error
+     */
+    public String getError() {
+        return error.getOutput();
+    }
+
+    /**
+     * This class builds {@link Thrift} instances.
+     */
+    static final class Builder {
+        private final String executable;
+        private final File javaOutputDirectory;
+        private Set<File> thriftPathElements;
+        private Set<File> thriftFiles;
+        private String generator;
+
+        /**
+         * Constructs a new builder. The two parameters are present as they are
+         * required for all {@link Thrift} instances.
+         *
+         * @param executable          The path to the {@code thrift} executable.
+         * @param javaOutputDirectory The directory into which the java source files
+         *                            will be generated.
+         * @throws NullPointerException     If either of the arguments are {@code null}.
+         * @throws IllegalArgumentException If the {@code javaOutputDirectory} is
+         *                                  not a directory.
+         */
+        public Builder(String executable, File javaOutputDirectory) {
+            this.executable = checkNotNull(executable, "executable");
+            this.javaOutputDirectory = checkNotNull(javaOutputDirectory);
+            checkArgument(javaOutputDirectory.isDirectory());
+            this.thriftFiles = newHashSet();
+            this.thriftPathElements = newHashSet();
+        }
+
+        /**
+         * Adds a thrift file to be compiled. Thrift files must be on the thriftpath
+         * and this method will fail if a thrift file is added without first adding a
+         * parent directory to the thriftpath.
+         *
+         * @param thriftFile
+         * @return The builder.
+         * @throws IllegalStateException If a thrift file is added without first
+         *                               adding a parent directory to the thriftpath.
+         * @throws NullPointerException  If {@code thriftFile} is {@code null}.
+         */
+        public Builder addThriftFile(File thriftFile) {
+            checkNotNull(thriftFile);
+            checkArgument(thriftFile.isFile());
+            checkArgument(thriftFile.getName().endsWith(".thrift"));
+            checkThriftFileIsInThriftPath(thriftFile);
+            thriftFiles.add(thriftFile);
+            return this;
+        }
+
+        /**
+         * Adds the option string for the Thrift executable's {@code --gen} parameter.
+         *
+         * @param generator
+         * @return The builder
+         * @throws NullPointerException If {@code generator} is {@code null}.
+         */
+        public Builder setGenerator(String generator) {
+            checkNotNull(generator);
+            this.generator = generator;
+            return this;
+        }
+
+        private void checkThriftFileIsInThriftPath(File thriftFile) {
+            assert thriftFile.isFile();
+            checkState(checkThriftFileIsInThriftPathHelper(thriftFile.getParentFile()));
+        }
+
+        private boolean checkThriftFileIsInThriftPathHelper(File directory) {
+            assert directory.isDirectory();
+            if (thriftPathElements.contains(directory)) {
+                return true;
+            } else {
+                final File parentDirectory = directory.getParentFile();
+                return (parentDirectory == null) ? false
+                        : checkThriftFileIsInThriftPathHelper(parentDirectory);
+            }
+        }
+
+        /**
+         * @see #addThriftFile(File)
+         */
+        public Builder addThriftFiles(Iterable<File> thriftFiles) {
+            for (File thriftFile : thriftFiles) {
+                addThriftFile(thriftFile);
+            }
+            return this;
+        }
+
+        /**
+         * Adds the {@code thriftPathElement} to the thriftPath.
+         *
+         * @param thriftPathElement A directory to be searched for imported thrift message
+         *                          buffer definitions.
+         * @return The builder.
+         * @throws NullPointerException     If {@code thriftPathElement} is {@code null}.
+         * @throws IllegalArgumentException If {@code thriftPathElement} is not a
+         *                                  directory.
+         */
+        public Builder addThriftPathElement(File thriftPathElement) {
+            checkNotNull(thriftPathElement);
+            checkArgument(thriftPathElement.isDirectory());
+            thriftPathElements.add(thriftPathElement);
+            return this;
+        }
+
+        /**
+         * @see #addThriftPathElement(File)
+         */
+        public Builder addThriftPathElements(Iterable<File> thriftPathElements) {
+            for (File thriftPathElement : thriftPathElements) {
+                addThriftPathElement(thriftPathElement);
+            }
+            return this;
+        }
+
+        /**
+         * @return A configured {@link Thrift} instance.
+         * @throws IllegalStateException If no thrift files have been added.
+         */
+        public Thrift build() {
+            checkState(!thriftFiles.isEmpty());
+            return new Thrift(executable, generator, ImmutableSet.copyOf(thriftPathElements),
+                    ImmutableSet.copyOf(thriftFiles), javaOutputDirectory);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/ThriftCompileMojo.java
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/ThriftCompileMojo.java b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/ThriftCompileMojo.java
new file mode 100644
index 0000000..b4f7571
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/ThriftCompileMojo.java
@@ -0,0 +1,78 @@
+/*
+ * 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.thrift.maven;
+
+import java.io.File;
+import java.util.List;
+import org.apache.maven.artifact.Artifact;
+import com.google.common.collect.ImmutableList;
+
+/**
+ * This mojo executes the {@code thrift} compiler for generating java sources
+ * from thrift definitions. It also searches dependency artifacts for
+ * thrift files and includes them in the thriftPath so that they can be
+ * referenced. Finally, it adds the thrift files to the project as resources so
+ * that they are included in the final artifact.
+ *
+ * @phase generate-sources
+ * @goal compile
+ * @requiresDependencyResolution compile
+ */
+public final class ThriftCompileMojo extends AbstractThriftMojo {
+
+    /**
+     * The source directories containing the sources to be compiled.
+     *
+     * @parameter default-value="${basedir}/src/main/thrift"
+     * @required
+     */
+    private File thriftSourceRoot;
+
+    /**
+     * This is the directory into which the {@code .java} will be created.
+     *
+     * @parameter default-value="${project.build.directory}/generated-sources/thrift"
+     * @required
+     */
+    private File outputDirectory;
+
+    @Override
+    protected List<Artifact> getDependencyArtifacts() {
+        List<Artifact> compileArtifacts = project.getCompileArtifacts();
+        return compileArtifacts;
+    }
+
+    @Override
+    protected File getOutputDirectory() {
+        return outputDirectory;
+    }
+
+    @Override
+    protected File getThriftSourceRoot() {
+        return thriftSourceRoot;
+    }
+
+    @Override
+    protected void attachFiles() {
+        project.addCompileSourceRoot(outputDirectory.getAbsolutePath());
+        projectHelper.addResource(project, thriftSourceRoot.getAbsolutePath(),
+        		ImmutableList.of("**/*.thrift"), null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/ThriftTestCompileMojo.java
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/ThriftTestCompileMojo.java b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/ThriftTestCompileMojo.java
new file mode 100644
index 0000000..fb89d96
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/main/java/org/apache/thrift/maven/ThriftTestCompileMojo.java
@@ -0,0 +1,74 @@
+/*
+ * 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.thrift.maven;
+
+import java.io.File;
+import java.util.List;
+import org.apache.maven.artifact.Artifact;
+import com.google.common.collect.ImmutableList;
+
+/**
+ * @phase generate-test-sources
+ * @goal testCompile
+ * @requiresDependencyResolution test
+ */
+public final class ThriftTestCompileMojo extends AbstractThriftMojo {
+
+    /**
+     * The source directories containing the sources to be compiled.
+     *
+     * @parameter default-value="${basedir}/src/test/thrift"
+     * @required
+     */
+    private File thriftTestSourceRoot;
+
+    /**
+     * This is the directory into which the {@code .java} will be created.
+     *
+     * @parameter default-value="${project.build.directory}/generated-test-sources/thrift"
+     * @required
+     */
+    private File outputDirectory;
+
+    @Override
+    protected void attachFiles() {
+        project.addTestCompileSourceRoot(outputDirectory.getAbsolutePath());
+        projectHelper.addTestResource(project, thriftTestSourceRoot.getAbsolutePath(),
+        		ImmutableList.of("**/*.thrift"), null);
+    }
+
+    @Override
+    protected List<Artifact> getDependencyArtifacts() {
+        // TODO(gak): maven-project needs generics
+        @SuppressWarnings("unchecked")
+        List<Artifact> testArtifacts = project.getTestArtifacts();
+        return testArtifacts;
+    }
+
+    @Override
+    protected File getOutputDirectory() {
+        return outputDirectory;
+    }
+
+    @Override
+    protected File getThriftSourceRoot() {
+        return thriftTestSourceRoot;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/java/org/apache/thrift/maven/TestThrift.java
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/java/org/apache/thrift/maven/TestThrift.java b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/java/org/apache/thrift/maven/TestThrift.java
new file mode 100644
index 0000000..3ecd094
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/java/org/apache/thrift/maven/TestThrift.java
@@ -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.thrift.maven;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class TestThrift {
+
+    private File testRootDir;
+    private File idlDir;
+    private File genJavaDir;
+    private Thrift.Builder builder;
+
+    @Before
+    public void setup() throws Exception {
+        final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
+        testRootDir = new File(tmpDir, "thrift-test");
+
+        if (testRootDir.exists()) {
+            FileUtils.cleanDirectory(testRootDir);
+        } else {
+            assertTrue("Failed to create output directory for test: " + testRootDir.getPath(), testRootDir.mkdir());
+        }
+
+        File testResourceDir = new File("src/test/resources");
+        assertTrue("Unable to find test resources", testRootDir.exists());
+
+        String thriftExecutable = System.getProperty("thriftExecutable", "thrift");
+        if (!(new File(thriftExecutable).exists())) {
+            thriftExecutable = "thrift";
+        }
+        System.out.println("Thrift compiler: " + thriftExecutable);
+
+        idlDir = new File(testResourceDir, "idl");
+        genJavaDir = new File(testRootDir, Thrift.GENERATED_JAVA);
+        builder = new Thrift.Builder(thriftExecutable, testRootDir);
+        builder
+            .setGenerator("java")
+            .addThriftPathElement(idlDir);
+    }
+
+    @Test
+    public void testThriftCompile() throws Exception {
+        executeThriftCompile();
+    }
+
+    @Test
+    public void testThriftCompileWithGeneratorOption() throws Exception {
+        builder.setGenerator("java:private-members,hashcode");
+        executeThriftCompile();
+    }
+
+    private void executeThriftCompile() throws CommandLineException {
+        final File thriftFile = new File(idlDir, "shared.thrift");
+
+        builder.addThriftFile(thriftFile);
+
+        final Thrift thrift = builder.build();
+
+        assertTrue("File not found: shared.thrift", thriftFile.exists());
+        assertFalse("gen-java directory should not exist", genJavaDir.exists());
+
+        // execute the compile
+        final int result = thrift.compile();
+        assertEquals(0, result);
+
+        assertFalse("gen-java directory was not removed", genJavaDir.exists());
+        assertTrue("generated java code doesn't exist",
+            new File(testRootDir, "shared/SharedService.java").exists());
+    }
+
+    @Test
+    public void testThriftMultipleFileCompile() throws Exception {
+        final File sharedThrift = new File(idlDir, "shared.thrift");
+        final File tutorialThrift = new File(idlDir, "tutorial.thrift");
+
+        builder.addThriftFile(sharedThrift);
+        builder.addThriftFile(tutorialThrift);
+
+        final Thrift thrift = builder.build();
+
+        assertTrue("File not found: shared.thrift", sharedThrift.exists());
+        assertFalse("gen-java directory should not exist", genJavaDir.exists());
+
+        // execute the compile
+        final int result = thrift.compile();
+        assertEquals(0, result);
+
+        assertFalse("gen-java directory was not removed", genJavaDir.exists());
+        assertTrue("generated java code doesn't exist",
+            new File(testRootDir, "shared/SharedService.java").exists());
+        assertTrue("generated java code doesn't exist",
+            new File(testRootDir, "tutorial/InvalidOperation.java").exists());
+    }
+
+    @Test
+    public void testBadCompile() throws Exception {
+        final File thriftFile = new File(testRootDir, "missing.thrift");
+        builder.addThriftPathElement(testRootDir);
+
+        // Hacking around checks in addThrift file.
+        assertTrue(thriftFile.createNewFile());
+        builder.addThriftFile(thriftFile);
+        assertTrue(thriftFile.delete());
+
+        final Thrift thrift = builder.build();
+
+        assertTrue(!thriftFile.exists());
+        assertFalse("gen-java directory should not exist", genJavaDir.exists());
+
+        // execute the compile
+        final int result = thrift.compile();
+        assertEquals(1, result);
+    }
+
+    @Test
+    public void testFileInPathPreCondition() throws Exception {
+        final File thriftFile = new File(testRootDir, "missing.thrift");
+
+        // Hacking around checks in addThrift file.
+        assertTrue(thriftFile.createNewFile());
+        try {
+            builder.addThriftFile(thriftFile);
+            fail("Expected IllegalStateException");
+        } catch (IllegalStateException e) {
+        }
+    }
+
+    @After
+    public void cleanup() throws Exception {
+        if (testRootDir.exists()) {
+            FileUtils.cleanDirectory(testRootDir);
+            assertTrue("Failed to delete output directory for test: " + testRootDir.getPath(), testRootDir.delete());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/resources/idl/shared.thrift
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/resources/idl/shared.thrift b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/resources/idl/shared.thrift
new file mode 100644
index 0000000..475e7f8
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/resources/idl/shared.thrift
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+/**
+ * This Thrift file can be included by other Thrift files that want to share
+ * these definitions.
+ */
+
+namespace cpp shared
+namespace java shared
+namespace perl shared
+
+struct SharedStruct {
+  1: i32 key
+  2: string value
+}
+
+service SharedService {
+  SharedStruct getStruct(1: i32 key)
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/resources/idl/tutorial.thrift
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/resources/idl/tutorial.thrift b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/resources/idl/tutorial.thrift
new file mode 100644
index 0000000..86e433d
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift-maven-plugin/src/test/resources/idl/tutorial.thrift
@@ -0,0 +1,152 @@
+/*
+ * 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.
+ */
+
+# Thrift Tutorial
+# Mark Slee (mcslee@facebook.com)
+#
+# This file aims to teach you how to use Thrift, in a .thrift file. Neato. The
+# first thing to notice is that .thrift files support standard shell comments.
+# This lets you make your thrift file executable and include your Thrift build
+# step on the top line. And you can place comments like this anywhere you like.
+#
+# Before running this file, you will need to have installed the thrift compiler
+# into /usr/local/bin.
+
+/**
+ * The first thing to know about are types. The available types in Thrift are:
+ *
+ *  bool        Boolean, one byte
+ *  byte        Signed byte
+ *  i16         Signed 16-bit integer
+ *  i32         Signed 32-bit integer
+ *  i64         Signed 64-bit integer
+ *  double      64-bit floating point value
+ *  string      String
+ *  binary      Blob (byte array)
+ *  map<t1,t2>  Map from one type to another
+ *  list<t1>    Ordered list of one type
+ *  set<t1>     Set of unique elements of one type
+ *
+ * Did you also notice that Thrift supports C style comments?
+ */
+
+// Just in case you were wondering... yes. We support simple C comments too.
+
+/**
+ * Thrift files can reference other Thrift files to include common struct
+ * and service definitions. These are found using the current path, or by
+ * searching relative to any paths specified with the -I compiler flag.
+ *
+ * Included objects are accessed using the name of the .thrift file as a
+ * prefix. i.e. shared.SharedObject
+ */
+include "shared.thrift"
+
+/**
+ * Thrift files can namespace, package, or prefix their output in various
+ * target languages.
+ */
+namespace cpp tutorial
+namespace java tutorial
+namespace php tutorial
+namespace perl tutorial
+namespace smalltalk.category Thrift.Tutorial
+
+/**
+ * Thrift lets you do typedefs to get pretty names for your types. Standard
+ * C style here.
+ */
+typedef i32 MyInteger
+
+/**
+ * Thrift also lets you define constants for use across languages. Complex
+ * types and structs are specified using JSON notation.
+ */
+const i32 INT32CONSTANT = 9853
+const map<string,string> MAPCONSTANT = {'hello':'world', 'goodnight':'moon'}
+
+/**
+ * You can define enums, which are just 32 bit integers. Values are optional
+ * and start at 1 if not supplied, C style again.
+ */
+enum Operation {
+  ADD = 1,
+  SUBTRACT = 2,
+  MULTIPLY = 3,
+  DIVIDE = 4
+}
+
+/**
+ * Structs are the basic complex data structures. They are comprised of fields
+ * which each have an integer identifier, a type, a symbolic name, and an
+ * optional default value.
+ *
+ * Fields can be declared "optional", which ensures they will not be included
+ * in the serialized output if they aren't set.  Note that this requires some
+ * manual management in some languages.
+ */
+struct Work {
+  1: i32 num1 = 0,
+  2: i32 num2,
+  3: Operation op,
+  4: optional string comment,
+}
+
+/**
+ * Structs can also be exceptions, if they are nasty.
+ */
+exception InvalidOperation {
+  1: i32 what,
+  2: string why
+}
+
+/**
+ * Ahh, now onto the cool part, defining a service. Services just need a name
+ * and can optionally inherit from another service using the extends keyword.
+ */
+service Calculator extends shared.SharedService {
+
+  /**
+   * A method definition looks like C code. It has a return type, arguments,
+   * and optionally a list of exceptions that it may throw. Note that argument
+   * lists and exception lists are specified using the exact same syntax as
+   * field lists in struct or exception definitions.
+   */
+
+   void ping(),
+
+   i32 add(1:i32 num1, 2:i32 num2),
+
+   i32 calculate(1:i32 logid, 2:Work w) throws (1:InvalidOperation ouch),
+
+   /**
+    * This method has a oneway modifier. That means the client only makes
+    * a request and does not listen for any response at all. Oneway methods
+    * must be void.
+    */
+   oneway void zip()
+
+}
+
+/**
+ * That just about covers the basics. Take a look in the test/ folder for more
+ * detailed examples. After you run this file, your generated code shows up
+ * in folders with names gen-<language>. The generated code isn't too scary
+ * to look at. It even has pretty indentation.
+ */

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift.el
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift.el b/depends/thirdparty/thrift/contrib/thrift.el
new file mode 100644
index 0000000..941a99f
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift.el
@@ -0,0 +1,140 @@
+;;; thrift.el --- Major mode for Apache Thrift files
+
+;; Keywords: files
+
+;; 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.
+;;
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'font-lock)
+
+(defvar thrift-mode-hook nil)
+;;;###autoload
+(add-to-list 'auto-mode-alist '("\\.thrift\\'" . thrift-mode))
+
+(defvar thrift-indent-level 2
+  "Defines 2 spaces for thrift indentation.")
+
+;; syntax coloring
+(defconst thrift-font-lock-keywords
+  (list
+   '("\\<\\(include\\|struct\\|exception\\|typedef\\|const\\|enum\\|service\\|extends\\|void\\|oneway\\|throws\\|optional\\|required\\)\\>" . font-lock-keyword-face)  ;; keywords
+   '("\\<\\(bool\\|byte\\|i16\\|i32\\|i64\\|double\\|string\\|binary\\|map\\|list\\|set\\)\\>" . font-lock-type-face)  ;; built-in types
+   '("\\<\\([0-9]+\\)\\>" . font-lock-variable-name-face)   ;; ordinals
+   '("\\<\\(\\w+\\)\\s-*(" (1 font-lock-function-name-face))  ;; functions
+   )
+  "Thrift Keywords.")
+
+;; indentation
+(defun thrift-indent-line ()
+  "Indent current line as Thrift code."
+  (interactive)
+  (beginning-of-line)
+  (if (bobp)
+      (indent-line-to 0)
+    (let ((not-indented t) cur-indent)
+      (if (looking-at "^[ \t]*\\(}\\|throws\\)")
+          (if (looking-at "^[ \t]*}")
+              (progn
+                (save-excursion
+                  (forward-line -1)
+                  (setq cur-indent (- (current-indentation) thrift-indent-level)))
+                (if (< cur-indent 0)
+                    (setq cur-indent 0)))
+            (progn
+              (save-excursion
+                (forward-line -1)
+                (if (looking-at "^[ \t]*[\\.<>[:word:]]+[ \t]+[\\.<>[:word:]]+[ \t]*(")
+                    (setq cur-indent (+ (current-indentation) thrift-indent-level))
+                  (setq cur-indent (current-indentation))))))
+        (save-excursion
+          (while not-indented
+            (forward-line -1)
+            (if (looking-at "^[ \t]*}")
+                (progn
+                  (setq cur-indent (current-indentation))
+                  (setq not-indented nil))
+              (if (looking-at "^.*{[^}]*$")
+                  (progn
+                    (setq cur-indent (+ (current-indentation) thrift-indent-level))
+                    (setq not-indented nil))
+                (if (bobp)
+                    (setq not-indented nil)))
+              (if (looking-at "^[ \t]*throws")
+                  (progn
+                    (setq cur-indent (- (current-indentation) thrift-indent-level))
+                    (if (< cur-indent 0)
+                        (setq cur-indent 0))
+                    (setq not-indented nil))
+                (if (bobp)
+                    (setq not-indented nil)))
+              (if (looking-at "^[ \t]*[\\.<>[:word:]]+[ \t]+[\\.<>[:word:]]+[ \t]*([^)]*$")
+                  (progn
+                    (setq cur-indent (+ (current-indentation) thrift-indent-level))
+                    (setq not-indented nil))
+                (if (bobp)
+                    (setq not-indented nil)))
+              (if (looking-at "^[ \t]*\\/\\*")
+                  (progn
+                    (setq cur-indent (+ (current-indentation) 1))
+                    (setq not-indented nil))
+                (if (bobp)
+                    (setq not-indented nil)))
+              (if (looking-at "^[ \t]*\\*\\/")
+                  (progn
+                    (setq cur-indent (- (current-indentation) 1))
+                    (setq not-indented nil))
+                (if (bobp)
+                    (setq not-indented nil)))
+              ))))
+      (if cur-indent
+          (indent-line-to cur-indent)
+        (indent-line-to 0)))))
+
+;; C/C++- and sh-style comments; also allowing underscore in words
+(defvar thrift-mode-syntax-table
+  (let ((thrift-mode-syntax-table (make-syntax-table)))
+    (modify-syntax-entry ?_ "w" thrift-mode-syntax-table)
+    (modify-syntax-entry ?# "<" thrift-mode-syntax-table) ; sh-style comments
+    (modify-syntax-entry ?/ ". 124" thrift-mode-syntax-table) ; c/c++-style comments
+    (modify-syntax-entry ?* ". 23b" thrift-mode-syntax-table)
+    (modify-syntax-entry ?\n ">" thrift-mode-syntax-table)
+    thrift-mode-syntax-table)
+  "Syntax table for thrift-mode")
+
+;;;###autoload
+(defun thrift-mode ()
+  "Mode for editing Thrift files."
+  (interactive)
+  (kill-all-local-variables)
+  (set-syntax-table thrift-mode-syntax-table)
+  (set (make-local-variable 'font-lock-defaults) '(thrift-font-lock-keywords))
+  (setq major-mode 'thrift-mode)
+  (setq mode-name "Thrift")
+  (run-hooks 'thrift-mode-hook)
+  (set (make-local-variable 'indent-line-function) 'thrift-indent-line)
+  )
+
+(provide 'thrift)
+;;; thrift.el ends here
+

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift.spec
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift.spec b/depends/thirdparty/thrift/contrib/thrift.spec
new file mode 100644
index 0000000..dab3275
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift.spec
@@ -0,0 +1,238 @@
+#
+# 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.
+#
+
+%define without_java 1
+%define without_python 1
+%define without_tests 1
+
+%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
+%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
+
+Name:           thrift
+License:        Apache License v2.0
+Group:          Development
+Summary:        RPC and serialization framework
+Version:        0.9.3
+Release:        0
+URL:            http://thrift.apache.org
+Packager:       Thrift Developers <dev@thrift.apache.org>
+Source0:        %{name}-%{version}.tar.gz
+
+BuildRequires:  gcc >= 3.4.6
+BuildRequires:  gcc-c++
+
+%if 0%{!?without_java:1}
+BuildRequires:  java-devel >= 0:1.5.0
+BuildRequires:  ant >= 0:1.6.5
+%endif
+
+%if 0%{!?without_python:1}
+BuildRequires:  python-devel
+%endif
+
+%if 0%{!?without_ruby:1}
+%define gem_name %{name}
+BuildRequires:  ruby-devel
+BuildRequires:  rubygems-devel
+%endif
+
+BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+
+%description
+Thrift is a software framework for scalable cross-language services
+development. It combines a powerful software stack with a code generation
+engine to build services that work efficiently and seamlessly between C++,
+Java, C#, Python, Ruby, Perl, PHP, Objective C/Cocoa, Smalltalk, Erlang,
+Objective Caml, and Haskell.
+
+%files
+%defattr(-,root,root)
+%{_bindir}/thrift
+
+
+%package lib-cpp
+Summary: Thrift C++ library
+Group:   Libraries
+
+%description lib-cpp
+C++ libraries for Thrift.
+
+%files lib-cpp
+%defattr(-,root,root)
+%{_libdir}/libthrift*.so.*
+%{_libdir}/libthrift*.so
+
+
+%package lib-cpp-devel
+Summary:   Thrift C++ library development files
+Group:     Libraries
+Requires:  %{name} = %{version}-%{release}
+Requires:  boost-devel
+%if 0%{!?without_libevent:1}
+Requires:  libevent-devel >= 1.2
+%endif
+%if 0%{!?without_zlib:1}
+Requires:  zlib-devel
+%endif
+
+%description lib-cpp-devel
+C++ static libraries and headers for Thrift.
+
+%files lib-cpp-devel
+%defattr(-,root,root)
+%{_includedir}/thrift/
+%{_libdir}/libthrift*.*a
+%{_libdir}/pkgconfig/thrift*.pc
+
+
+%if 0%{!?without_java:1}
+%package lib-java
+Summary:   Thrift Java library
+Group:     Libraries
+Requires:  java >= 0:1.5.0
+
+%description lib-java
+Java libraries for Thrift.
+
+%files lib-java
+%defattr(-,root,root)
+%{_javadir}/*
+%endif
+
+
+%if 0%{!?without_python:1}
+%package lib-python
+Summary: Thrift Python library
+Group:   Libraries
+
+%description lib-python
+Python libraries for Thrift.
+
+%files lib-python
+%defattr(-,root,root)
+%{python_sitearch}/*
+%endif
+
+
+%if 0%{!?without_ruby:1}
+%package -n rubygem-%{gem_name}
+Summary: Thrift Ruby library
+Group:   Libraries
+Obsoletes: %{name}-lib-ruby
+
+%description -n rubygem-%{gem_name}
+Ruby libraries for Thrift.
+
+%files -n rubygem-%{gem_name}
+%defattr(-,root,root)
+%{gem_dir}/*
+%endif
+
+
+%if 0%{!?without_php:1}
+%package lib-php
+Summary: Thrift PHP library
+Group:   Libraries
+
+%description lib-php
+PHP libraries for Thrift.
+
+%files lib-php
+%defattr(-,root,root)
+/usr/lib/php/*
+%endif
+
+
+%prep
+%setup -q
+
+%build
+[[ -e Makefile.in ]] || ./bootstrap.sh
+export GEM_HOME=${PWD}/.gem-home
+export RUBYLIB=${PWD}/lib/rb/lib
+%configure \
+  %{?without_libevent: --without-libevent } \
+  %{?without_zlib:     --without-zlib     } \
+  %{?without_tests:    --without-tests    } \
+  %{?without_java:     --without-java     } \
+  %{?without_python:   --without-python   } \
+  %{?without_ruby:     --without-ruby     } \
+  %{?without_php:      --without-php      } \
+  %{!?without_php:     PHP_PREFIX=${RPM_BUILD_ROOT}/usr/lib/php } \
+  --without-csharp \
+  --without-erlang \
+
+make %{?_smp_mflags}
+
+%if 0%{!?without_java:1}
+cd lib/java
+%ant
+cd ../..
+%endif
+
+%if 0%{!?without_python:1}
+cd lib/py
+CFLAGS="%{optflags}" %{__python} setup.py build
+cd ../..
+%endif
+
+%if 0%{!?without_ruby:1}
+%gem_install -n lib/rb/thrift*.gem
+%endif
+
+%install
+export GEM_HOME=${PWD}/.gem-home
+export RUBYLIB=${PWD}/lib/rb/lib
+%makeinstall
+ln -s libthrift-%{version}.so ${RPM_BUILD_ROOT}%{_libdir}/libthrift.so.0
+ln -s libthriftnb-%{version}.so ${RPM_BUILD_ROOT}%{_libdir}/libthriftnb.so.0
+ln -s libthriftz-%{version}.so ${RPM_BUILD_ROOT}%{_libdir}/libthriftz.so.0
+
+%if 0%{!?without_java:1}
+mkdir -p $RPM_BUILD_ROOT%{_javadir}
+cp -p lib/java/build/*.jar $RPM_BUILD_ROOT%{_javadir}
+%endif
+
+%if 0%{!?without_python:1}
+cd lib/py
+%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT
+cd ../..
+%endif
+
+%if 0%{!?without_ruby:1}
+mkdir -p %{buildroot}%{gem_dir}
+cp -a ./%{gem_dir}/* %{buildroot}%{gem_dir}/
+%endif
+
+%clean
+rm -rf ${RPM_BUILD_ROOT}
+
+
+%post
+umask 007
+/sbin/ldconfig > /dev/null 2>&1
+
+
+%postun
+umask 007
+/sbin/ldconfig > /dev/null 2>&1
+
+%changelog
+* Wed Sept 25 2015 Thrift Dev <dev@thrift.apache.org>
+- Thrift 0.9.3 release.

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift.vim
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift.vim b/depends/thirdparty/thrift/contrib/thrift.vim
new file mode 100644
index 0000000..3000b46
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift.vim
@@ -0,0 +1,91 @@
+" Vim syntax file
+" Language: Thrift
+" Maintainer: Martin Smith <martin@facebook.com>
+" Last Change: $Date: $
+" Copy to ~/.vim/
+" Add to ~/.vimrc
+"  au BufRead,BufNewFile *.thrift set filetype=thrift
+"  au! Syntax thrift source ~/.vim/thrift.vim
+"
+" $Id: $
+"
+" 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.
+"
+
+if version < 600
+  syntax clear
+elseif exists("b:current_syntax")
+  finish
+endif
+
+" Todo
+syn keyword thriftTodo TODO todo FIXME fixme XXX xxx contained
+
+" Comments
+syn match thriftComment "#.*" contains=thriftTodo
+syn region thriftComment start="/\*" end="\*/" contains=thriftTodo
+syn match thriftComment "//.\{-}\(?>\|$\)\@="
+
+" String
+syn region thriftStringDouble matchgroup=None start=+"+  end=+"+
+
+" Number
+syn match thriftNumber "-\=\<\d\+\>" contained
+
+" Keywords
+syn keyword thriftKeyword namespace
+syn keyword thriftKeyword xsd_all xsd_optional xsd_nillable xsd_attrs
+syn keyword thriftKeyword include cpp_include cpp_type const optional required
+syn keyword thriftBasicTypes void bool byte i16 i32 i64 double string binary
+syn keyword thriftStructure map list set struct typedef exception enum throws union
+
+" Special
+syn match thriftSpecial "\d\+:"
+
+" Structure
+syn keyword thriftStructure service oneway extends
+"async"         { return tok_async;         }
+"exception"     { return tok_xception;      }
+"extends"       { return tok_extends;       }
+"throws"        { return tok_throws;        }
+"service"       { return tok_service;       }
+"enum"          { return tok_enum;          }
+"const"         { return tok_const;         }
+
+if version >= 508 || !exists("did_thrift_syn_inits")
+  if version < 508
+    let did_thrift_syn_inits = 1
+    command! -nargs=+ HiLink hi link <args>
+  else
+    command! -nargs=+ HiLink hi def link <args>
+  endif
+
+  HiLink thriftComment Comment
+  HiLink thriftKeyword Special
+  HiLink thriftBasicTypes Type
+  HiLink thriftStructure StorageClass
+  HiLink thriftTodo Todo
+  HiLink thriftString String
+  HiLink thriftNumber Number
+  HiLink thriftSpecial Special
+  HiLink thriftStructure Structure
+
+  delcommand HiLink
+endif
+
+let b:current_syntax = "thrift"

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/thrift_dump.cpp
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/thrift_dump.cpp b/depends/thirdparty/thrift/contrib/thrift_dump.cpp
new file mode 100644
index 0000000..59c8ac8
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/thrift_dump.cpp
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+
+#include <cstdlib>
+#include <iostream>
+
+#include <thrift/transport/TBufferTransports.h>
+#include <thrift/transport/TFDTransport.h>
+#include <thrift/protocol/TBinaryProtocol.h>
+#include <thrift/protocol/TDebugProtocol.h>
+#include <thrift/protocol/TProtocolTap.h>
+
+using namespace std;
+using boost::shared_ptr;
+using namespace apache::thrift::transport;
+using namespace apache::thrift::protocol;
+
+void usage() {
+  fprintf(stderr,
+      "usage: thrift_dump {-b|-f|-s} < input > ouput\n"
+      "  -b TBufferedTransport messages\n"
+      "  -f TFramedTransport messages\n"
+      "  -s Raw structures\n");
+  exit(EXIT_FAILURE);
+}
+
+int main(int argc, char *argv[]) {
+  if (argc != 2) {
+    usage();
+  }
+
+  shared_ptr<TTransport> stdin_trans(new TFDTransport(STDIN_FILENO));
+  shared_ptr<TTransport> itrans;
+
+  if (argv[1] == std::string("-b") || argv[1] == std::string("-s")) {
+    itrans.reset(new TBufferedTransport(stdin_trans));
+  } else if (argv[1] == std::string("-f")) {
+    itrans.reset(new TFramedTransport(stdin_trans));
+  } else {
+    usage();
+  }
+
+  shared_ptr<TProtocol> iprot(new TBinaryProtocol(itrans));
+  shared_ptr<TProtocol> oprot(
+      new TDebugProtocol(
+        shared_ptr<TTransport>(new TBufferedTransport(
+          shared_ptr<TTransport>(new TFDTransport(STDOUT_FILENO))))));
+
+  TProtocolTap tap(iprot, oprot);
+
+  try {
+    if (argv[1] == std::string("-s")) {
+      for (;;) {
+        tap.skip(T_STRUCT);
+      }
+    } else {
+      std::string name;
+      TMessageType messageType;
+      int32_t seqid;
+      for (;;) {
+        tap.readMessageBegin(name, messageType, seqid);
+        tap.skip(T_STRUCT);
+        tap.readMessageEnd();
+      }
+    }
+  } catch (TProtocolException exn) {
+    cout << "Protocol Exception: " << exn.what() << endl;
+  } catch (...) {
+    oprot->getTransport()->flush();
+  }
+
+  cout << endl;
+
+  return 0;
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/transport-sample/README.md
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/transport-sample/README.md b/depends/thirdparty/thrift/contrib/transport-sample/README.md
new file mode 100644
index 0000000..a1dfc0a
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/transport-sample/README.md
@@ -0,0 +1,61 @@
+Thrift transport sample project
+-------------------------------
+
+This cross-platform project has been built with Windows Visual Studio 10 and 
+OSX 10.7.1's g++.  The client and server support socket and pipe transports 
+through command-line switches.
+
+Windows supports both named & anonymous pipes; *NIX gets only named 
+'pipes' at this time.
+
+Windows-only at this time:
+The client & server are double-ended. Both sides run a server and client to 
+enable full duplex bidirectional event signaling. They are simple command 
+line apps. The server runs until it's aborted (Ctl-C). The client connects to
+the server, informs the server of its listening pipe/port, runs some more RPCs 
+and exits. The server also makes RPC calls to the client to demonstrate 
+bidirectional operation.
+
+Prequisites:
+Boost -- tested with Boost 1.47, other versions may work.
+libthrift library -- build the library under "thrift/lib/cpp/"
+thrift IDL compiler -- download from http://thrift.apache.org/download/ 
+   or build from "thrift/compiler/cpp".  The IDL compiler version should
+   match the thrift source distribution's version. For instance, thrift-0.9.0
+   has a different directory structure than thrift-0.8.0 and the generated
+   files are not compatible.
+
+Note: Bulding the thrift IDL compiler and library are beyond the scope
+of this article. Please refer to the Thrift documentation in the respective
+directories and online.
+
+
+Microsoft Windows with Visual Studio 10
+----------------------------------------
+Copy the IDL compiler 'thrift.exe' to this project folder or to a location in the path.
+Run thriftme.bat to generate the interface source from the thrift files.
+
+Open transport-sample.sln and...
+Adapt the Boost paths for the client and server projects. Right-click on each project, select
+Properties, then:
+Configuration Properties -> C/C++ -> General -> Additional Include Directories
+Configuration Properties -> Linker -> General -> Additional Include Directories
+
+The stock path assumes that Boost is located at the same level as the thrift repo root.
+
+Run the following in separate command prompts from the Release or Debug 
+build folder:
+ server.exe -np test
+ client.exe -np test
+
+
+*NIX flavors
+------------
+Build the thrift cpp library.
+Build the IDL compiler and copy it to this project folder.
+Run thriftme.sh to generate the interface source from the thrift files.
+Run 'make'
+
+Run the following in separate shells:
+ server/server -np /tmp/test
+ client/client -np /tmp/test

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/transport-sample/Sample.thrift
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/transport-sample/Sample.thrift b/depends/thirdparty/thrift/contrib/transport-sample/Sample.thrift
new file mode 100644
index 0000000..3040e25
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/transport-sample/Sample.thrift
@@ -0,0 +1,39 @@
+/*
+ transport-sample thrift IDL file .
+ Execute thriftme.bat under Windows to generate the cpp stubs from this IDL.
+ */
+
+// See thrift/tutorial/tutorial.thrift and shared.thrift for more extensive examples.
+
+
+namespace cpp Sample
+namespace java Sample
+namespace perl Sample
+
+//This struct is not used in the sample. Shown here for illustrative purposes only.
+//
+struct SampleStruct
+{
+  1: i32 key
+  2: string value
+}
+
+
+//A service contains the RPC(s).
+//
+service SampleService
+{
+  string HelloThere(1:string HelloString),
+  void ServerDoSomething(),
+
+  //Client calls this to tell server which port to connect back on.
+  void ClientSideListenPort(1:i16 Port),
+  //Named pipe version
+  void ClientSidePipeName(1:string name),
+}
+
+//Sample RPC on the 'client' side that the master server can call.
+service SampleCallback
+{
+  void pingclient(),
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/transport-sample/ThriftCommon.cpp
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/transport-sample/ThriftCommon.cpp b/depends/thirdparty/thrift/contrib/transport-sample/ThriftCommon.cpp
new file mode 100644
index 0000000..60ebf7a
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/transport-sample/ThriftCommon.cpp
@@ -0,0 +1,37 @@
+// ThriftCommon.cpp : Common functions for sample Thrift client and server
+//
+
+#include "ThriftCommon.h"
+
+namespace thriftcommon
+{
+	//----------------------------------------------------------------------------
+	//Launch child process and pass R/W anonymous pipe handles on cmd line.
+	//This is a simple example and does not include elevation or other 
+	//advanced features.
+	//
+	bool LaunchAnonPipeChild(std::string app, boost::shared_ptr<TServerTransport> transport)
+	{
+#ifdef _WIN32
+		PROCESS_INFORMATION pi;
+		STARTUPINFOA si;
+		GetStartupInfoA(&si);  //set startupinfo for the spawned process
+		char handles[MAX_PATH];  //Stores pipe handles converted to text
+
+		sprintf(handles, "%s %d %d", app.c_str(),
+			(int)boost::shared_dynamic_cast<TPipeServer>(transport)->getClientRdPipeHandle(),
+			(int)boost::shared_dynamic_cast<TPipeServer>(transport)->getClientWrtPipeHandle());
+
+		//spawn the child process
+		if (!CreateProcessA(NULL, handles, NULL,NULL,TRUE,0,NULL,NULL,&si,&pi))
+		{
+			GlobalOutput.perror("TPipeServer CreateProcess failed, GLE=", GetLastError());
+			return false;
+		}
+
+		CloseHandle(pi.hThread);
+		CloseHandle(pi.hProcess);
+#endif
+		return true;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/transport-sample/ThriftCommon.h
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/transport-sample/ThriftCommon.h b/depends/thirdparty/thrift/contrib/transport-sample/ThriftCommon.h
new file mode 100644
index 0000000..d24d1a7
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/transport-sample/ThriftCommon.h
@@ -0,0 +1,207 @@
+// ThriftCommon.h : Common includes, namespaces and templates 
+// for sample Thrift client and server
+//
+// Add the following paths to the Project's properties:
+//
+// Configuration Properties -> C/C++ -> General-> Additional Include Directories --
+// ../;../../../lib/cpp/src;../../../../boost;../../../../boost/boost/tr1;
+//
+// Configuration Properties -> Linker -> General -> Additional Library Directories --
+// ../../../lib/cpp/$(Configuration);../../../../Boost/lib
+//
+// Configuration Properties -> Linker -> Input -> Additional Dependencies --
+// libthrift.lib
+//
+// ... adjust relative paths as necessary.
+//
+
+#ifdef _WIN32 //thrift is crashing when using boost threads on Mac OSX
+#  define USE_BOOST_THREAD 1
+#  include <boost/thread.hpp>
+#else
+#  include <sys/socket.h>
+#  include <netinet/in.h>
+#endif
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Required Includes
+//'server' side #includes
+#include <thrift/concurrency/ThreadManager.h>
+#include <thrift/concurrency/PlatformThreadFactory.h>
+#include <thrift/server/TThreadPoolServer.h>
+#include <thrift/server/TSimpleServer.h>
+//'client' side #includes
+#include <thrift/transport/TPipeServer.h>
+#include <thrift/transport/TPipe.h>
+#include <thrift/transport/TBufferTransports.h>
+#include <thrift/transport/TSocket.h>
+#include <thrift/transport/TTransport.h>
+
+#include <thrift/protocol/TBinaryProtocol.h>
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+// Required Namespaces
+//'server' side namespaces
+using namespace apache::thrift::server;
+using namespace apache::thrift::concurrency;
+//common namespaces
+using namespace apache::thrift;
+using namespace apache::thrift::protocol;
+using namespace apache::thrift::transport;
+//using namespace boost; //using ns boost can introduce type conflicts
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+namespace thriftcommon
+{
+	//----------------------------------------------------------------------------
+	//
+	//Start the thrift 'server' (both server & client side run one for bidir event signaling)
+	// *** This function template will block ***
+	//
+	template <class MyHandler, class MyProcessor>
+	void RunThriftServer (boost::shared_ptr<MyHandler> hndlr, 
+		                  int NumThreads, 
+						  boost::shared_ptr<TServerTransport> transport,
+						  boost::shared_ptr<TServer> &server)
+	{
+#ifdef _WIN32
+		if (!hndlr.get())
+			throw std::exception("RunThriftServer() invalid handler");
+		if (!transport.get())
+			throw std::exception("RunThriftServer() invalid transport");
+#else
+		if ( !hndlr.get() || !transport.get() )
+			throw std::exception();
+#endif
+
+		boost::shared_ptr<MyHandler> handler(hndlr);
+		boost::shared_ptr<TProcessor> processor(new MyProcessor(handler));
+		boost::shared_ptr<TTransportFactory> tfactory(new TBufferedTransportFactory());
+		boost::shared_ptr<TProtocolFactory> pfactory(new TBinaryProtocolFactory());
+
+		if(NumThreads <= 1)
+		{	//Single-threaded server
+			server.reset(new TSimpleServer(processor, transport, tfactory, pfactory));
+		}
+		else
+		{	//Multi-threaded server
+			boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(NumThreads);
+			boost::shared_ptr<PlatformThreadFactory> threadFactory = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory());
+			threadManager->threadFactory(threadFactory);
+			threadManager->start();
+			server.reset(new TThreadPoolServer(processor, transport, tfactory, pfactory, threadManager));
+		}
+
+		printf("Starting the 'server'...\n");
+		server->serve();
+		printf("done.\n");
+	}
+
+	// Thrift server wrapper function that accepts a pipe name.
+	// A handler must be passed in to this version.
+	template <class MyHandler, class MyProcessor>
+	void RunThriftServer (boost::shared_ptr<MyHandler> hndlr, int NumThreads, std::string pipename, boost::shared_ptr<TServer> &svr)
+	{
+#ifndef _WIN32  //Mac, *nix
+		unlink(pipename.c_str());
+#endif
+		boost::shared_ptr<TServerTransport> transport(new TPipeServer(pipename, 1024, NumThreads)); //Named pipe
+		RunThriftServer<MyHandler, MyProcessor>(hndlr, NumThreads, transport, svr);
+	}
+
+	// Thrift server wrapper function that accepts a pipe name.
+	// This version instantiates its own handler.
+	template <class MyHandler, class MyProcessor>
+	void RunThriftServer (int NumThreads, std::string pipename)
+	{
+		boost::shared_ptr<MyHandler> handler(new MyHandler());
+		boost::shared_ptr<TServer> server;
+
+		RunThriftServer<MyHandler, MyProcessor>(handler, NumThreads, pipename, server);
+	}
+
+	// Thrift server wrapper function that accepts a socket port number.
+	// A handler must be passed in to this version.
+	template <class MyHandler, class MyProcessor>
+	void RunThriftServer (boost::shared_ptr<MyHandler> hndlr, int NumThreads, int Port)
+	{
+		boost::shared_ptr<TServerTransport> transport(new TServerSocket(Port));
+		boost::shared_ptr<TServer> server;
+		RunThriftServer<MyHandler, MyProcessor>(hndlr, NumThreads, transport, server);
+	}
+
+	// Thrift server wrapper function that accepts a socket port number.
+	// This version instantiates its own handler.
+	template <class MyHandler, class MyProcessor>
+	void RunThriftServer (int NumThreads, int Port)
+	{
+		boost::shared_ptr<MyHandler> handler(new MyHandler());
+
+		RunThriftServer<MyHandler, MyProcessor>(handler, NumThreads, Port);
+	}
+
+	//
+	template <class MyHandler, class MyProcessor>
+	void RunThriftServer (boost::shared_ptr<MyHandler> hndlr, int NumThreads, boost::shared_ptr<TServerTransport> transport)
+	{
+		boost::shared_ptr<TServer> server;
+		RunThriftServer<MyHandler, MyProcessor>(hndlr, NumThreads, transport, server);
+	}
+
+	//----------------------------------------------------------------------------
+	//Connect to thrift 'server' - Socket version
+	//(both server & client side run one for bidir event signaling)
+	//
+	template <class MyClient, class MyTransport>
+	void ConnectToServer (boost::shared_ptr<MyClient> &client, boost::shared_ptr<MyTransport> &transport, int Port)
+	{
+		//Client side connection using sockets transport.
+		boost::shared_ptr<TTransport> socket(new TSocket("localhost", Port));
+		transport.reset(new TBufferedTransport(socket));
+		boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
+
+		client.reset(new MyClient(protocol));
+	}
+
+	//Connect to thrift 'server' - Named Pipe version
+	template <class MyClient, class MyTransport>
+	void ConnectToServer (boost::shared_ptr<MyClient> &client, boost::shared_ptr<MyTransport> &transport, std::string pipename)
+	{
+		//Client side connection using Named Pipe transport.
+		boost::shared_ptr<TTransport> pipe(new TPipe(pipename));
+		transport.reset(new TBufferedTransport(pipe));
+		boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
+
+		client.reset(new MyClient(protocol));
+	}
+
+	//Connect to thrift 'server' - Anonymous Pipe version
+	//Currently only supported under Windows
+#ifdef _WIN32
+	template <class MyClient, class MyTransport>
+	void ConnectToServer (boost::shared_ptr<MyClient> &client, boost::shared_ptr<MyTransport> &transport, HANDLE RdPipe, HANDLE WrtPipe)
+	{
+		//Client side connection using sockets transport.
+#ifdef _WIN32
+		boost::shared_ptr<TTransport> pipe(new TPipe((int)RdPipe, (int)WrtPipe));
+		transport.reset(new TBufferedTransport(pipe));
+#else
+		boost::shared_ptr<TTransport> socket(new TSocket("localhost"));
+		transport.reset(new TBufferedTransport(socket));
+#endif
+		boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
+
+		client.reset(new MyClient(protocol));
+	}
+#endif
+
+	//----------------------------------------------------------------------------
+	//Launch child process and pass R/W anonymous pipe handles on cmd line.
+	//Currently only supported under Windows
+#ifdef _WIN32
+	bool LaunchAnonPipeChild(std::string app, boost::shared_ptr<TServerTransport> transport);
+#endif
+}

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/transport-sample/client/ReadMe.txt
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/transport-sample/client/ReadMe.txt b/depends/thirdparty/thrift/contrib/transport-sample/client/ReadMe.txt
new file mode 100644
index 0000000..6c49a96
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/transport-sample/client/ReadMe.txt
@@ -0,0 +1,40 @@
+========================================================================
+    CONSOLE APPLICATION : client Project Overview
+========================================================================
+
+AppWizard has created this client application for you.
+
+This file contains a summary of what you will find in each of the files that
+make up your client application.
+
+
+client.vcxproj
+    This is the main project file for VC++ projects generated using an Application Wizard.
+    It contains information about the version of Visual C++ that generated the file, and
+    information about the platforms, configurations, and project features selected with the
+    Application Wizard.
+
+client.vcxproj.filters
+    This is the filters file for VC++ projects generated using an Application Wizard. 
+    It contains information about the association between the files in your project 
+    and the filters. This association is used in the IDE to show grouping of files with
+    similar extensions under a specific node (for e.g. ".cpp" files are associated with the
+    "Source Files" filter).
+
+client.cpp
+    This is the main application source file.
+
+/////////////////////////////////////////////////////////////////////////////
+Other standard files:
+
+StdAfx.h, StdAfx.cpp
+    These files are used to build a precompiled header (PCH) file
+    named client.pch and a precompiled types file named StdAfx.obj.
+
+/////////////////////////////////////////////////////////////////////////////
+Other notes:
+
+AppWizard uses "TODO:" comments to indicate parts of the source code you
+should add to or customize.
+
+/////////////////////////////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/d709f67d/depends/thirdparty/thrift/contrib/transport-sample/client/client.cpp
----------------------------------------------------------------------
diff --git a/depends/thirdparty/thrift/contrib/transport-sample/client/client.cpp b/depends/thirdparty/thrift/contrib/transport-sample/client/client.cpp
new file mode 100644
index 0000000..45fbef1
--- /dev/null
+++ b/depends/thirdparty/thrift/contrib/transport-sample/client/client.cpp
@@ -0,0 +1,195 @@
+// client->cpp : Defines the entry point for the console application.
+//
+// sample client command line app using Thrift IPC.
+// Quick n Dirty example, may not have very robust error handling
+// for the sake of simplicity.
+
+#ifdef _WIN32
+#  include "stdafx.h"
+#else
+#  include "config.h"
+#endif
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//Include this before the generated includes
+#include "ThriftCommon.h"
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//Tailor these to your generated files
+#include "../gen-cpp/SampleService.h"
+#include "../gen-cpp/SampleCallback.h"
+
+using namespace Sample; //declared in .thrift file
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+void ClientListenerThreadProc();
+bool bSocket = false;
+bool bAnonPipe = false;
+int srvPort;
+std::string pipename;
+std::string pipename_client;
+#ifdef _WIN32
+ HANDLE hConsole;
+#endif
+
+//Customized version of printf that changes the text color
+//This depends on hConsole global being initialized
+void hlprintf(const char* _Format, ...)
+{
+#ifdef _WIN32
+	SetConsoleTextAttribute(hConsole, 0xE);
+#endif
+	va_list ap;
+	int r;
+	va_start (ap, _Format);
+	r = vprintf (_Format, ap);
+	va_end (ap);
+#ifdef _WIN32
+	SetConsoleTextAttribute(hConsole, 7);
+#endif
+}
+
+//-----------------------------------------------------------------------------
+// Client-side RPC implementations: Called by the server to the client for 
+// bidirectional eventing.
+//
+class SampleCallbackHandler : virtual public SampleCallbackIf {
+ public:
+  SampleCallbackHandler() {
+    // initialization goes here
+  }
+
+  void pingclient()
+  {
+    hlprintf("<<<Ping received from server (server-to-client event).\n");
+  }
+
+};
+//-----------------------------------------------------------------------------
+
+
+#ifdef _WIN32
+int _tmain(int argc, _TCHAR* argv[])
+#else
+int main(int argc, char **argv)
+#endif
+{
+	//Process cmd line args to determine named vs anon pipes.
+	bool usage = false;
+#ifdef _WIN32
+	HANDLE ReadPipe, WritePipe;
+	hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+#endif
+
+	//Process command line params
+	if(argc > 1)
+	{
+		if(_tcscmp(argv[1], TEXT("-sp")) == 0)
+		{	//Socket Port specified
+			srvPort = _tstoi(argv[2]);
+			bSocket = true;
+		}
+		else if(_tcscmp(argv[1], TEXT("-np")) == 0)
+		{	//Named Pipe specified
+#ifdef _WIN32
+                        std::wstring wpipe(argv[2]);
+                        pipename.resize(wpipe.length());
+                        std::copy(wpipe.begin(), wpipe.end(), pipename.begin());
+#else
+                        pipename = argv[2];
+#endif
+			pipename_client = pipename + "_client";
+		}
+		else if(argc == 3)
+		{	//Anonymous Pipe specified
+#ifdef _WIN32
+			ReadPipe  = (HANDLE)_tstoi(argv[1]);
+			WritePipe = (HANDLE)_tstoi(argv[2]);
+			bAnonPipe = true;
+#else
+                        printf("Anonymous pipes not (yet) supported under *NIX\n");
+#endif
+		}
+		else
+			usage = true;
+	}
+	else
+		usage = true;
+
+	if(usage)
+	{
+		hlprintf("Thrift sample client usage:\n\n");
+		hlprintf("Socket Port to connect to: -sp <port#>\n");
+		hlprintf("Named Pipe to connect to:  -np <pipename> (e.g. affpipe)\n");
+		hlprintf("Anonymous Pipe (must be launched by anon pipe creator):\n");
+		hlprintf("                           <Read Handle> <Write Handle>\n");
+		return 0;
+	}
+
+	//Client side connection to server.
+	boost::shared_ptr<SampleServiceClient> client; //Client class from Thrift-generated code.
+	boost::shared_ptr<TTransport> transport;
+
+	if(bSocket)
+	{	//Socket transport
+#ifdef _WIN32
+		TWinsockSingleton::create();
+#endif
+		hlprintf("Using socket transport port %d\n", srvPort);
+		thriftcommon::ConnectToServer<SampleServiceClient, TTransport>(client, transport, srvPort);
+	}
+	else if(!bAnonPipe)
+	{
+		hlprintf("Using Named Pipe %s\n", pipename.c_str());
+		thriftcommon::ConnectToServer<SampleServiceClient, TTransport>(client, transport, pipename);
+	}
+	else
+	{
+#ifdef _WIN32
+		hlprintf("Using Anonymous Pipe transport\n");
+		thriftcommon::ConnectToServer<SampleServiceClient, TTransport>(client, transport, ReadPipe, WritePipe);
+#endif
+	}
+
+#ifdef _WIN32
+	//Start a thread to receive inbound connection from server for 2-way event signaling.
+	boost::thread ClientListenerThread(ClientListenerThreadProc);
+#endif
+
+	try {
+		transport->open();
+
+		//Notify server what to connect back on.
+		if(bSocket)
+			client->ClientSideListenPort(srvPort + 1); //Socket
+		else if(!bAnonPipe)
+			client->ClientSidePipeName(pipename_client); //Named Pipe
+
+		//Run some more RPCs
+		std::string hellostr = "Hello how are you?";
+		std::string returnstr;
+		client->HelloThere(returnstr, hellostr);
+		hlprintf("\n>>>Sent: %s\n", hellostr.c_str());
+		hlprintf("<<<Received: %s\n", returnstr.c_str());
+
+		hlprintf("\n>>>Calling ServerDoSomething() which delays for 5 seconds.\n");
+		client->ServerDoSomething();
+		hlprintf(">>>ServerDoSomething() done.\n\n");
+
+		transport->close();
+	} catch (TException &tx) {
+		hlprintf("ERROR: %s\n", tx.what());
+	}
+
+	return 0;
+}
+
+
+//Thread Routine
+void ClientListenerThreadProc()
+{
+	if(bSocket)
+		thriftcommon::RunThriftServer<SampleCallbackHandler, SampleCallbackProcessor>(1, srvPort + 1);
+	else if(!bAnonPipe)
+		thriftcommon::RunThriftServer<SampleCallbackHandler, SampleCallbackProcessor>(1, pipename_client);
+}



Mime
View raw message