org.identityconnectors.common.Version.parse()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(133)

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

Version.parse介绍

[英]Parses the passed version string. The string can contain up to four numeric component separated by a dot, followed by an alphanumberic qualifier prepended by a dash. For example, the following are valid versions:

  • 1
  • 1.1
  • 1.1.0
  • 1.2.3-alpha
  • 1.2.3.4-SNAPSHOT
    [中]解析传递的版本字符串。该字符串最多可以包含四个由点分隔的数字成分,后跟一个字母数字限定符,前面有一个破折号。例如,以下是有效版本:
  • 1
  • 1.1
  • 1.1.0
    *1.2.3-α
    *1.2.3.4-快照

代码示例

代码示例来源:origin: Tirasa/ConnId

/**
 * Parse version component into a Version.
 *
 * @param version
 *            version component string
 * @param range
 *            Complete range string for exception message, if any
 * @return Version
 */
private static Version parseVersion(String version, String range) {
  try {
    return Version.parse(version);
  } catch (IllegalArgumentException e) {
    throw new IllegalArgumentException(
        "invalid range \"" + range + "\": " + e.getMessage(), e);
  }
}

代码示例来源:origin: net.tirasa.connid/connector-framework

/**
 * Parse version component into a Version.
 *
 * @param version
 *            version component string
 * @param range
 *            Complete range string for exception message, if any
 * @return Version
 */
private static Version parseVersion(String version, String range) {
  try {
    return Version.parse(version);
  } catch (IllegalArgumentException e) {
    throw new IllegalArgumentException(
        "invalid range \"" + range + "\": " + e.getMessage(), e);
  }
}

代码示例来源:origin: org.connid/framework

static Version getFrameworkVersion(ClassLoader loader) throws IOException {
  InputStream stream = loader.getResourceAsStream("connectors-framework.properties");
  try {
    Properties props = new Properties();
    props.load(stream);
    String version = props.getProperty(PROP_FRAMEWORK_VERSION);
    if (version == null) {
      throw new IllegalStateException("connectors-framework.properties does not contain a " + PROP_FRAMEWORK_VERSION + " property");
    }
    if (StringUtil.isBlank(version)) {
      throw new IllegalStateException("connectors-framework.properties specifies a blank version");
    }
    return Version.parse(version);
  } finally {
    IOUtil.quietClose(stream);
  }
}

代码示例来源:origin: net.tirasa.connid/connector-framework

static Version getFrameworkVersion(ClassLoader loader) throws IOException {
  InputStream stream = loader.getResourceAsStream("connectors-framework.properties");
  try {
    Properties props = new Properties();
    props.load(stream);
    String version = props.getProperty(PROP_FRAMEWORK_VERSION);
    if (version == null) {
      throw new IllegalStateException(
          "connectors-framework.properties does not contain a "
              + PROP_FRAMEWORK_VERSION + " property");
    }
    if (StringUtil.isBlank(version)) {
      throw new IllegalStateException(
          "connectors-framework.properties specifies a blank version");
    }
    return Version.parse(version);
  } finally {
    IOUtil.quietClose(stream);
  }
}

代码示例来源:origin: Tirasa/ConnId

static Version getFrameworkVersion(ClassLoader loader) throws IOException {
  InputStream stream = loader.getResourceAsStream("connectors-framework.properties");
  try {
    Properties props = new Properties();
    props.load(stream);
    String version = props.getProperty(PROP_FRAMEWORK_VERSION);
    if (version == null) {
      throw new IllegalStateException(
          "connectors-framework.properties does not contain a "
              + PROP_FRAMEWORK_VERSION + " property");
    }
    if (StringUtil.isBlank(version)) {
      throw new IllegalStateException(
          "connectors-framework.properties specifies a blank version");
    }
    return Version.parse(version);
  } finally {
    IOUtil.quietClose(stream);
  }
}

代码示例来源:origin: Tirasa/ConnId

@Test
public void testQualifiedIgnored() {
  assertEquals(Version.parse("1.2.3"), Version.parse("1.2.3-alpha"));
}

代码示例来源:origin: Tirasa/ConnId

if (ATT_FRAMEWORK_VERSION.equals(key)) {
  frameworkVersion = (String) bundleHeaders.get(key);
  if (version.compareTo(Version.parse(frameworkVersion)) < 0) {

代码示例来源:origin: Tirasa/ConnId

@Test
public void testParse() {
  assertEquals(new Version(1), Version.parse("1"));
  assertEquals(new Version(1), Version.parse("1-alpha"));
  assertEquals(new Version(1, 2), Version.parse("1.2"));
  assertEquals(new Version(1, 2), Version.parse("1.2-alpha"));
  assertEquals(new Version(1, 2, 3), Version.parse("1.2.3"));
  assertEquals(new Version(1, 2, 3), Version.parse("1.2.3-alpha"));
  assertEquals(new Version(1, 2, 3, 4), Version.parse("1.2.3.4"));
  assertEquals(new Version(1, 2, 3, 4), Version.parse("1.2.3.4-alpha"));
}

代码示例来源:origin: Tirasa/ConnId

if (FrameworkUtil.getFrameworkVersion().compareTo(Version.parse(frameworkVersion)) < 0) {
  String message =
      "Bundle " + parsed.getLocation() + " requests an unrecognized framework version "

代码示例来源:origin: Tirasa/ConnId

@Test
public void testEqualsHashCode() {
  Version v1 = Version.parse("1.0");
  Version v2 = Version.parse("1.0.0.0");
  assertEquals(v1, v2);
  assertEquals(v1.hashCode(), v2.hashCode());
}

代码示例来源:origin: Tirasa/ConnId

@Test
public void testFrameworkVersion() throws Exception {
  ClassLoader loader = new VersionClassLoader(this.getClass().getClassLoader(), "1.2.3-alpha");
  assertEquals(FrameworkUtil.getFrameworkVersion(loader), Version.parse("1.2.3"));
}

代码示例来源:origin: Tirasa/ConnId

@Test
public void testToString() {
  assertEquals(Version.parse("1.2.3").toString(), "Version[1.2.3]");
}

代码示例来源:origin: Tirasa/ConnId

@Test
public void testCompare() {
  assertCompEq(new Version(1), Version.parse("1"));
  assertCompEq(new Version(1, 2), Version.parse("1.2"));
  assertCompEq(new Version(1, 2, 3), Version.parse("1.2.3"));
  assertCompEq(new Version(1, 2, 3, 4), Version.parse("1.2.3.4"));
  assertCompEq(new Version(1), Version.parse("1.0"));
  assertCompEq(new Version(1), Version.parse("1.0.0"));
  assertCompEq(new Version(1), Version.parse("1.0.0.0"));
  assertCompEq(new Version(1, 2), Version.parse("1.2.0"));
  assertCompEq(new Version(1, 2), Version.parse("1.2.0.0"));
  assertCompEq(new Version(1, 2, 3), Version.parse("1.2.3.0"));
  assertCompLt(new Version(1, 2), Version.parse("1.3"));
  assertCompLt(new Version(1, 2, 3), Version.parse("1.2.4"));
  assertCompLt(new Version(1, 2, 3, 4), Version.parse("1.2.3.5"));
  assertCompLt(new Version(2), Version.parse("3"));
  assertCompLt(new Version(2), Version.parse("2.1"));
  assertCompLt(new Version(2, 3), Version.parse("2.3.4"));
  assertCompLt(new Version(2, 3, 4), Version.parse("2.3.4.5"));
  assertCompGt(new Version(1, 2), Version.parse("1.1"));
  assertCompGt(new Version(1, 2, 3), Version.parse("1.2.2"));
  assertCompGt(new Version(1, 2, 3, 4), Version.parse("1.2.3.3"));
  assertCompGt(new Version(2), Version.parse("1"));
  assertCompGt(new Version(2), Version.parse("1.0"));
  assertCompGt(new Version(2, 3), Version.parse("2.2.0"));
  assertCompGt(new Version(2, 3, 4), Version.parse("2.3.3.0"));
}

代码示例来源:origin: Tirasa/ConnId

@Test
public void testComponents() {
  Version v = Version.parse("1.2.3.4");
  assertEquals(v.getMajor(), Integer.valueOf(1));
  assertEquals(v.getMinor(), Integer.valueOf(2));
  assertEquals(v.getMicro(), Integer.valueOf(3));
  assertEquals(v.getRevision(), Integer.valueOf(4));
}

代码示例来源:origin: Tirasa/ConnId

@Test
public void testCornerCases() {
  Version v = Version.parse("1.0");
  assertEquals(v.getMajor(), Integer.valueOf(1));
  assertEquals(v.getMinor(), Integer.valueOf(0));
  assertNull(v.getMicro());
  assertNull(v.getRevision());
  try {
    new Version();
    fail();
  } catch (IllegalArgumentException e) {
    // OK.
  }
  try {
    Version.parse(" ");
    fail();
  } catch (IllegalArgumentException e) {
    // OK.
  }
  try {
    Version.parse("foo");
    fail();
  } catch (IllegalArgumentException e) {
    // OK.
  }
}

代码示例来源:origin: org.connid/connid-framework-internal

/**
 * Parses the manifest.
 * @return The manifest. Note that the classes/classloaders will
 * not be populated yet. That is to be done at a higher-level.
 * @throws ConfigurationException If there were any structural problems.
 */
public ConnectorBundleManifest parse() throws ConfigurationException {
  String frameworkVersion = getRequiredAttribute(ATT_FRAMEWORK_VERSION);
  String bundleName = getRequiredAttribute(ATT_BUNDLE_NAME);
  String bundleVersion =getRequiredAttribute(ATT_BUNDLE_VERSION);
  if (FrameworkUtil.getFrameworkVersion().compareTo(Version.parse(frameworkVersion)) < 0) {
    String message = "Bundle " + _fileName + " requests an unrecognized " +
        "framework version " + frameworkVersion + " but available is " +
        FrameworkUtil.getFrameworkVersion().getVersion();
    throw new ConfigurationException(message);
  }
  ConnectorBundleManifest rv = new ConnectorBundleManifest();
  rv.setFrameworkVersion(frameworkVersion);
  rv.setBundleName(bundleName);
  rv.setBundleVersion(bundleVersion);
  return rv;
}

代码示例来源:origin: Tirasa/ConnId

/**
 * Parses the manifest.
 *
 * @return The manifest. Note that the classes/classloaders will not be populated yet. That is to be done at a
 * higher-level.
 * @throws ConfigurationException if there were any structural problems.
 */
public ConnectorBundleManifest parse() throws ConfigurationException {
  String frameworkVersion = getRequiredAttribute(ATT_FRAMEWORK_VERSION);
  String bundleName = getRequiredAttribute(ATT_BUNDLE_NAME);
  String bundleVersion = getRequiredAttribute(ATT_BUNDLE_VERSION);
  if (FrameworkUtil.getFrameworkVersion().compareTo(Version.parse(frameworkVersion)) < 0) {
    String message =
        "Bundle " + fileName + " requests an unrecognized " + "framework version "
        + frameworkVersion + " but available is "
        + FrameworkUtil.getFrameworkVersion().getVersion();
    throw new ConfigurationException(message);
  }
  ConnectorBundleManifest rv = new ConnectorBundleManifest();
  rv.setFrameworkVersion(frameworkVersion);
  rv.setBundleName(bundleName);
  rv.setBundleVersion(bundleVersion);
  return rv;
}

代码示例来源:origin: net.tirasa.connid/connector-framework-internal

/**
 * Parses the manifest.
 *
 * @return The manifest. Note that the classes/classloaders will not be populated yet. That is to be done at a
 * higher-level.
 * @throws ConfigurationException if there were any structural problems.
 */
public ConnectorBundleManifest parse() throws ConfigurationException {
  String frameworkVersion = getRequiredAttribute(ATT_FRAMEWORK_VERSION);
  String bundleName = getRequiredAttribute(ATT_BUNDLE_NAME);
  String bundleVersion = getRequiredAttribute(ATT_BUNDLE_VERSION);
  if (FrameworkUtil.getFrameworkVersion().compareTo(Version.parse(frameworkVersion)) < 0) {
    String message =
        "Bundle " + fileName + " requests an unrecognized " + "framework version "
        + frameworkVersion + " but available is "
        + FrameworkUtil.getFrameworkVersion().getVersion();
    throw new ConfigurationException(message);
  }
  ConnectorBundleManifest rv = new ConnectorBundleManifest();
  rv.setFrameworkVersion(frameworkVersion);
  rv.setBundleName(bundleName);
  rv.setBundleVersion(bundleVersion);
  return rv;
}

相关文章