當前位置: 首頁>>代碼示例>>Java>>正文


Java CodeSource.getLocation方法代碼示例

本文整理匯總了Java中java.security.CodeSource.getLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java CodeSource.getLocation方法的具體用法?Java CodeSource.getLocation怎麽用?Java CodeSource.getLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.CodeSource的用法示例。


在下文中一共展示了CodeSource.getLocation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getClasspathForClass

import java.security.CodeSource; //導入方法依賴的package包/類
public static File getClasspathForClass(Class<?> targetClass) {
    URI location;
    try {
        CodeSource codeSource = targetClass.getProtectionDomain().getCodeSource();
        if (codeSource != null && codeSource.getLocation() != null) {
            location = codeSource.getLocation().toURI();
            if (location.getScheme().equals("file")) {
                return new File(location);
            }
        }
        if (targetClass.getClassLoader() != null) {
            String resourceName = targetClass.getName().replace('.', '/') + ".class";
            URL resource = targetClass.getClassLoader().getResource(resourceName);
            if (resource != null) {
                return getClasspathForResource(resource, resourceName);
            }
        }
        throw new GradleException(String.format("Cannot determine classpath for class %s.", targetClass.getName()));
    } catch (URISyntaxException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:23,代碼來源:ClasspathUtil.java

示例2: isLoadedFrom

import java.security.CodeSource; //導入方法依賴的package包/類
public static boolean isLoadedFrom(Class<?> clazz) {
    if (clazz == null) {
        throw new IllegalArgumentException("Need to provide valid class reference");
    }

    CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();

    if (codeSource != null) {
        URL location = codeSource.getLocation();

        if (isJarUrl(location)) {
            try {
                return findMarkerFileInJar(new File(location.toURI()));
            } catch (URISyntaxException e) {
                throw UncheckedException.throwAsUncheckedException(e);
            }
        }
    }

    return false;
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:22,代碼來源:GradleRuntimeShadedJarDetector.java

示例3: getJavacApiJarClasspath

import java.security.CodeSource; //導入方法依賴的package包/類
private static ClassPath getJavacApiJarClasspath() {
    Reference<ClassPath> r = javacApiClasspath;
    ClassPath res = r.get();
    if (res != null) {
        return res;
    }
    if (r == NONE) {
        return null;
    }
    CodeSource codeSource = Modifier.class.getProtectionDomain().getCodeSource();
    URL javacApiJar = codeSource != null ? codeSource.getLocation() : null;
    if (javacApiJar != null) {
        Logger.getLogger(DeclarativeHintsParser.class.getName()).log(Level.FINE, "javacApiJar={0}", javacApiJar);
        File aj = FileUtil.archiveOrDirForURL(javacApiJar);
        if (aj != null) {
            res = ClassPathSupport.createClassPath(FileUtil.urlForArchiveOrDir(aj));
            javacApiClasspath = new WeakReference<>(res);
            return res;
        }
    }
    javacApiClasspath = NONE;
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:DeclarativeHintsParser.java

示例4: parserDescription

import java.security.CodeSource; //導入方法依賴的package包/類
/**
 * It may be helpfull for tracing down some oddities.
 */
private String parserDescription(XMLReader parser) {

    // report which parser implementation is used
    
    Class klass = parser.getClass();
    try {
        ProtectionDomain domain = klass.getProtectionDomain();
        CodeSource source = domain.getCodeSource();
        
        if (source == null && (klass.getClassLoader() == null || klass.getClassLoader().equals(Object.class.getClassLoader()))) {
            return Util.THIS.getString("MSG_platform_parser");
        } else if (source == null) {
            return Util.THIS.getString("MSG_unknown_parser", klass.getName());
        } else {
            URL location = source.getLocation();
            return Util.THIS.getString("MSG_parser_plug", location.toExternalForm());
        }
        
    } catch (SecurityException ex) {
        return Util.THIS.getString("MSG_unknown_parser", klass.getName());
    }
    
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:SharedXMLSupport.java

示例5: findHome

import java.security.CodeSource; //導入方法依賴的package包/類
/**
 * Returns the appropriate JDK home for this usage of the FileSystemProvider.
 * When the CodeSource is null (null loader) then jrt:/ is the current runtime,
 * otherwise the JDK home is located relative to jrt-fs.jar.
 */
private static String findHome() {
    CodeSource cs = SystemImage.class.getProtectionDomain().getCodeSource();
    if (cs == null)
        return System.getProperty("java.home");

    // assume loaded from $TARGETJDK/lib/jrt-fs.jar
    URL url = cs.getLocation();
    if (!url.getProtocol().equalsIgnoreCase("file"))
        throw new InternalError(url + " loaded in unexpected way");
    try {
        Path lib = Paths.get(url.toURI()).getParent();
        if (!lib.getFileName().toString().equals("lib"))
            throw new InternalError(url + " unexpected path");

        return lib.getParent().toString();
    } catch (URISyntaxException e) {
        throw new InternalError(e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:SystemImage.java

示例6: getCodeSource

import java.security.CodeSource; //導入方法依賴的package包/類
/**
 * Get the code source file or class path of the Class passed in.
 *
 * @param clazz
 *            Class to find.
 * @return Jar file name or class path.
 */
public static String getCodeSource(Class<?> clazz) {
    ProtectionDomain protectionDomain = clazz.getProtectionDomain();
    if (protectionDomain == null || protectionDomain.getCodeSource() == null) {
        return null;
    }

    CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();
    URL location = codeSource.getLocation();
    if (location == null) {
        return null;
    }

    String path = codeSource.getLocation().toExternalForm();

    if (path.endsWith(".jar") && path.contains("/")) {
        return path.substring(path.lastIndexOf('/') + 1);
    }
    return path;
}
 
開發者ID:venus-boot,項目名稱:saluki,代碼行數:27,代碼來源:ClassUtils.java

示例7: getCodeBase

import java.security.CodeSource; //導入方法依賴的package包/類
/**
 * 得到類所在地址,可以是文件,也可以是jar包
 *
 * @param cls
 *         the cls
 * @return the code base
 */
public static String getCodeBase(Class<?> cls) {

    if (cls == null)
        return null;
    ProtectionDomain domain = cls.getProtectionDomain();
    if (domain == null)
        return null;
    CodeSource source = domain.getCodeSource();
    if (source == null)
        return null;
    URL location = source.getLocation();
    if (location == null)
        return null;
    return location.getFile();
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:23,代碼來源:ReflectUtils.java

示例8: defineClassSourceLocation

import java.security.CodeSource; //導入方法依賴的package包/類
private String defineClassSourceLocation(ProtectionDomain pd)
{
    CodeSource cs = pd.getCodeSource();
    String source = null;
    if (cs != null && cs.getLocation() != null) {
        source = cs.getLocation().toString();
    }
    return source;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:ClassLoader.java

示例9: getCodeBase

import java.security.CodeSource; //導入方法依賴的package包/類
public static String getCodeBase(Class<?> cls) {
    if (cls == null)
        return null;
    ProtectionDomain domain = cls.getProtectionDomain();
    if (domain == null)
        return null;
    CodeSource source = domain.getCodeSource();
    if (source == null)
        return null;
    URL location = source.getLocation();
    if (location == null)
           return null;
    return location.getFile();
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:15,代碼來源:ReflectUtils.java

示例10: implies

import java.security.CodeSource; //導入方法依賴的package包/類
@Override @SuppressForbidden(reason = "fast equals check is desired")
public boolean implies(ProtectionDomain domain, Permission permission) {
    CodeSource codeSource = domain.getCodeSource();
    // codesource can be null when reducing privileges via doPrivileged()
    if (codeSource == null) {
        return false;
    }

    URL location = codeSource.getLocation();
    // location can be null... ??? nobody knows
    // https://bugs.openjdk.java.net/browse/JDK-8129972
    if (location != null) {
        // run scripts with limited permissions
        if (BootstrapInfo.UNTRUSTED_CODEBASE.equals(location.getFile())) {
            return untrusted.implies(domain, permission);
        }
        // check for an additional plugin permission: plugin policy is
        // only consulted for its codesources.
        Policy plugin = plugins.get(location.getFile());
        if (plugin != null && plugin.implies(domain, permission)) {
            return true;
        }
    }

    // Special handling for broken Hadoop code: "let me execute or my classes will not load"
    // yeah right, REMOVE THIS when hadoop is fixed
    if (permission instanceof FilePermission && "<<ALL FILES>>".equals(permission.getName())) {
        for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
            if ("org.apache.hadoop.util.Shell".equals(element.getClassName()) &&
                  "runCommand".equals(element.getMethodName())) {
                // we found the horrible method: the hack begins!
                // force the hadoop code to back down, by throwing an exception that it catches.
                rethrow(new IOException("no hadoop, you cannot do this."));
            }
        }
    }

    // otherwise defer to template + dynamic file permissions
    return template.implies(domain, permission) || dynamic.implies(permission) || system.implies(domain, permission);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:41,代碼來源:ESPolicy.java

示例11: defineClassSourceLocation

import java.security.CodeSource; //導入方法依賴的package包/類
private String defineClassSourceLocation(ProtectionDomain pd) {
    CodeSource cs = pd.getCodeSource();
    String source = null;
    if (cs != null && cs.getLocation() != null) {
        source = cs.getLocation().toString();
    }
    return source;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:ClassLoader.java

示例12: getCodeBase

import java.security.CodeSource; //導入方法依賴的package包/類
public static String getCodeBase(Class<?> cls) {
  if (cls == null)
    return null;
  ProtectionDomain domain = cls.getProtectionDomain();
  if (domain == null)
    return null;
  CodeSource source = domain.getCodeSource();
  if (source == null)
    return null;
  URL location = source.getLocation();
  if (location == null)
    return null;
  return location.getFile();
}
 
開發者ID:venus-boot,項目名稱:saluki,代碼行數:15,代碼來源:ReflectUtils.java

示例13: getJarFile

import java.security.CodeSource; //導入方法依賴的package包/類
/**
 * Returns the JarFile instance corresponding to the JAR containing the
 * specified class.
 */
public static JarFile getJarFile(Class klass) {
    try {
        CodeSource src = klass.getProtectionDomain().getCodeSource();
        if (src != null) {
            URL jarUrl = src.getLocation();
            return new JarFile(new File(jarUrl.getPath()));
        } else {
            return null;
        }
    } catch (IOException ex1) {
        return null;
    }
}
 
開發者ID:mcdcorp,項目名稱:opentest,代碼行數:18,代碼來源:JarUtil.java

示例14: getTestDataRootDir

import java.security.CodeSource; //導入方法依賴的package包/類
private File getTestDataRootDir() {
  CodeSource source = getClass().getProtectionDomain().getCodeSource();

  if (source != null) {
    URL location = source.getLocation();
    try {
      File classesDir = SdkUtils.urlToFile(location);
      return classesDir.getParentFile().getAbsoluteFile().getParentFile().getParentFile();
    } catch (MalformedURLException e) {
      fail(e.getLocalizedMessage());
    }
  }

  return null;
}
 
開發者ID:ashdavies,項目名稱:dagger-lint,代碼行數:16,代碼來源:AbstractDetectorTest.java

示例15: getJarURI

import java.security.CodeSource; //導入方法依賴的package包/類
private static URI getJarURI() throws URISyntaxException
{
    final ProtectionDomain domain;
    final CodeSource source;
    final URL url;
    final URI uri;

    domain = Main.class.getProtectionDomain();
    source = domain.getCodeSource();
    url    = source.getLocation();
    uri    = url.toURI();

    return (uri);
}
 
開發者ID:Ptrk25,項目名稱:CDN-FX-2.2,代碼行數:15,代碼來源:Tools.java


注:本文中的java.security.CodeSource.getLocation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。