java.lang.Package类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中java.lang.Package类的一些代码示例,展示了Package类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Package类的具体详情如下:
包路径:java.lang.Package
类名称:Package

Package介绍

[英]Contains information about a Java package. This includes implementation and specification versions. Typically this information is retrieved from the manifest.

Packages are managed by class loaders. All classes loaded by the same loader from the same package share a Package instance.
[中]包含有关Java包的信息。这包括实现和规范版本。通常从清单中检索此信息。
包由类装入器管理。同一加载程序从同一个包加载的所有类共享一个包实例。

代码示例

代码示例来源:origin: redisson/redisson

/**
   * {@inheritDoc}
   */
  public String getName() {
    return aPackage.getName();
  }
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Return the full version string of the present Spring codebase,
 * or {@code null} if it cannot be determined.
 * @see Package#getImplementationVersion()
 */
@Nullable
public static String getVersion() {
  Package pkg = SpringVersion.class.getPackage();
  return (pkg != null ? pkg.getImplementationVersion() : null);
}

代码示例来源:origin: org.testng/testng

private static Ignore findAnnotation(Package testPackage) {
    if (testPackage == null) {
      return null;
    }
    Ignore result = testPackage.getAnnotation(Ignore.class);
    if (result != null) {
      return result;
    }
    String[] parts = testPackage.getName().split("\\.");
    String[] parentParts = Arrays.copyOf(parts, parts.length - 1);
    String parentPackageName = Strings.join(".", parentParts);
    if (parentPackageName.isEmpty()) {
      return null;
    }
    return findAnnotation(Package.getPackage(parentPackageName));
  }
}

代码示例来源:origin: apache/incubator-druid

/**
  * Load the unique extensions and return their implementation-versions
  *
  * @return map of extensions loaded with their respective implementation versions.
  */
 private List<ModuleVersion> getExtensionVersions(Collection<DruidModule> druidModules)
 {
  List<ModuleVersion> moduleVersions = new ArrayList<>();
  for (DruidModule module : druidModules) {
   String artifact = module.getClass().getPackage().getImplementationTitle();
   String version = module.getClass().getPackage().getImplementationVersion();
   moduleVersions.add(new ModuleVersion(module.getClass().getCanonicalName(), artifact, version));
  }
  return moduleVersions;
 }
}

代码示例来源:origin: apache/incubator-dubbo

public static String getVersion(Class<?> cls, String defaultVersion) {
  try {
    String version = cls.getPackage().getImplementationVersion();
    if (StringUtils.isEmpty(version)) {
      version = cls.getPackage().getSpecificationVersion();

代码示例来源:origin: spring-projects/spring-framework

if (outputClassPackage != null && outputClassPackage.isAnnotationPresent(XmlSchema.class)) {
  XmlSchema annotation = outputClassPackage.getAnnotation(XmlSchema.class);
  namespaceUri = annotation.namespace();

代码示例来源:origin: oblac/jodd

private boolean parseMethodAuthFlag(final Method actionMethod) {
  if (actionMethod.getAnnotation(Auth.class) != null) {
    return true;
  }
  final Class declaringClass = actionMethod.getDeclaringClass();
  if (declaringClass.getAnnotation(Auth.class) != null) {
    return true;
  }
  if (declaringClass.getPackage().getAnnotation(Auth.class) != null) {
    return true;
  }
  return false;
}

代码示例来源:origin: apache/incubator-dubbo

public static String getVersion(Class<?> cls, String defaultVersion) {
  try {
    String version = cls.getPackage().getImplementationVersion();
    if (StringUtils.isEmpty(version)) {
      version = cls.getPackage().getSpecificationVersion();

代码示例来源:origin: neo4j/neo4j

private static String name( Package location, String name )
{
  return location.getName() + "." + name;
}

代码示例来源:origin: ch.qos.logback/logback-classic

String getImplementationVersion(Class type) {
  if (type == null) {
    return "na";
  }
  Package aPackage = type.getPackage();
  if (aPackage != null) {
    String v = aPackage.getImplementationVersion();
    if (v == null) {
      return "na";
    } else {
      return v;
    }
  }
  return "na";
}

代码示例来源:origin: org.testng/testng

private static boolean isSamePackage(Package childPackage, Package classPackage) {
 boolean isSamePackage = false;
 if ((null == childPackage) && (null == classPackage)) {
  isSamePackage = true;
 }
 if ((null != childPackage) && (null != classPackage)) {
  isSamePackage = childPackage.getName().equals(classPackage.getName());
 }
 return isSamePackage;
}

代码示例来源:origin: apache/incubator-druid

private String getDruidVersion()
{
 return Status.class.getPackage().getImplementationVersion();
}

代码示例来源:origin: prestodb/presto

/**
 * @since 2.7
 */
public static String getPackageName(Class<?> cls) {
  Package pkg = cls.getPackage();
  return (pkg == null) ? null : pkg.getName();
}

代码示例来源:origin: pxb1988/dex2jar

@Override
protected String getVersionString() {
  return "reader-" + DexFileReader.class.getPackage().getImplementationVersion() + ", translator-"
      + Dex2jar.class.getPackage().getImplementationVersion() + ", ir-"
      + ET.class.getPackage().getImplementationVersion();
}

代码示例来源:origin: redisson/redisson

/**
 * @since 2.7
 */
public static String getPackageName(Class<?> cls) {
  Package pkg = cls.getPackage();
  return (pkg == null) ? null : pkg.getName();
}

代码示例来源:origin: checkstyle/checkstyle

/**
 * Returns the version string printed when the user requests version help (--version or -V).
 * @return a version string based on the package implementation version
 */
private static String getVersionString() {
  return "Checkstyle version: " + Main.class.getPackage().getImplementationVersion();
}

代码示例来源:origin: ch.qos.logback/logback-classic

/**
 * {@inheritDoc}
 */
public void setLoggerContext(LoggerContext lc) {
  this.lc = lc;
  this.logger = lc.getLogger(getClass().getPackage().getName());
}

代码示例来源:origin: hibernate/hibernate-orm

public static String getVersionString() {
    if ( version == null ) {
      version = Version.class.getPackage().getImplementationVersion();
      if ( version == null ) {
        version = "[WORKING]";
      }
    }
    return version;
  }
}

代码示例来源:origin: dropwizard/dropwizard

/**
 * Logs to org.skife.jdbi.v2 logger at the debug level
 */
public LogbackLog() {
  this((Logger) LoggerFactory.getLogger(DBI.class.getPackage().getName()));
}

代码示例来源:origin: prestodb/presto

public boolean showVersionIfRequested()
  {
    if (version) {
      String clientVersion = Presto.class.getPackage().getImplementationVersion();
      System.out.println("Presto CLI " + firstNonNull(clientVersion, "(version unknown)"));
    }
    return version;
  }
}

相关文章