Java Jar File Find findJarsDir(String sparkHome, String scalaVersion, boolean failIfNotFound)

Here you can find the source of findJarsDir(String sparkHome, String scalaVersion, boolean failIfNotFound)

Description

Find the location of the Spark jars dir, depending on whether we're looking at a build or a distribution directory.

License

Apache License

Declaration

static String findJarsDir(String sparkHome, String scalaVersion, boolean failIfNotFound) 

Method Source Code


//package com.java2s;
/*//from   ww  w. j a  va  2s .com
 * 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.
 */

import java.io.File;

public class Main {
    /**
     * Find the location of the Spark jars dir, depending on whether we're looking at a build
     * or a distribution directory.
     */
    static String findJarsDir(String sparkHome, String scalaVersion, boolean failIfNotFound) {
        // TODO: change to the correct directory once the assembly build is changed.
        File libdir;
        if (new File(sparkHome, "RELEASE").isFile()) {
            libdir = new File(sparkHome, "jars");
            checkState(!failIfNotFound || libdir.isDirectory(), "Library directory '%s' does not exist.",
                    libdir.getAbsolutePath());
        } else {
            libdir = new File(sparkHome, String.format("assembly/target/scala-%s/jars", scalaVersion));
            if (!libdir.isDirectory()) {
                checkState(!failIfNotFound, "Library directory '%s' does not exist; make sure Spark is built.",
                        libdir.getAbsolutePath());
                libdir = null;
            }
        }
        return libdir != null ? libdir.getAbsolutePath() : null;
    }

    /** Throws IllegalStateException with the given message if the check is false. */
    static void checkState(boolean check, String msg, Object... args) {
        if (!check) {
            throw new IllegalStateException(String.format(msg, args));
        }
    }
}

Related

  1. findJarContaining(Class c)
  2. findJarEntry(String entryName, JarInputStream jarFile)
  3. findJarFiles(String[] classPathLines)
  4. findJars(File folder)
  5. findJars(File libDir)
  6. findJarsFromDirectory(File targetDirectory)
  7. findJarsNamesInPath(String path)
  8. getJarFile(@Nonnull Class clazz)
  9. getJarFile(Class clazz)