当前位置: 首页>>代码示例>>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;未经允许,请勿转载。