@Override public String getOsgiVersionString() { return version==null ? version : BrooklynVersionSyntax.toValidOsgiVersion(version); }
/** @see BrooklynVersionSyntax#isGoodBrooklynVersion(String) */ public static boolean isGoodBrooklynVersion(String candidate) { return BrooklynVersionSyntax.isGoodBrooklynVersion(candidate); }
public static boolean isSnapshot(String version) { return BrooklynVersionSyntax.isSnapshot(version); }
private void assertVersion(String candidate, boolean isUsable, boolean isOsgi, boolean isGood) { Assert.assertEquals(BrooklynVersionSyntax.isUsableVersion(candidate), isUsable, "usable version '"+candidate+"'"); Assert.assertEquals(BrooklynVersionSyntax.isValidOsgiVersion(candidate), isOsgi, "osgi version '"+candidate+"'"); Assert.assertEquals(BrooklynVersionSyntax.isGoodBrooklynVersion(candidate), isGood, "good version '"+candidate+"'"); }
private void assertConverts(String input, String bklyn, String osgi) { Assert.assertEquals(BrooklynVersionSyntax.toGoodBrooklynVersion(input), bklyn, "conversion to good brooklyn"); Assert.assertEquals(BrooklynVersionSyntax.toValidOsgiVersion(input), osgi, "conversion to valid osgi"); }
/** @see BrooklynVersionSyntax#isUsableVersion(String) */ public static boolean isUsableVersion(String candidate) { return BrooklynVersionSyntax.isUsableVersion(candidate); }
/** @see BrooklynVersionSyntax#isValidOsgiVersion(String) */ public static boolean isValidOsgiVersion(String candidate) { return BrooklynVersionSyntax.isValidOsgiVersion(candidate); }
private Object readResolve() { if (symbolicName!=null || version!=null) { // remove legacy fields, and convert to brooklyn recommended version in the process // (might be slightly weird if bundles are persisted, but code will forgive that, // and if types were persisted this will do the right thing) return new VersionedName(symbolicName, BrooklynVersionSyntax.toGoodBrooklynVersion( version.toString() )); } return this; }
/** Creates a string satisfying {@link #isGoodBrooklynVersion(String)} based on the input. * For input satisfying {@link #isGoodBrooklynVersion(String)} the input will be returned unchanged. * For input satisfying {@link #isValidOsgiVersion(String)} the qualifier separator will be changed to "-", * and {@link #toValidOsgiVersion(String)} can be used to reverse the input (modulo insertion of "0"'s for minor/patch numbers if missing). * Precise behaviour for other input is not guaranteed but callers can expect output which resembles the input, * with any major/minor/patch string at the front preserved and internal contiguous alphanumeric sequences preserved. */ public static String toGoodBrooklynVersion(String input) { return toGoodVersion(input, "-", false); }
/** * For versions we currently work with any non-empty string that does not contain a ':' or whitespace. * However we discourage things that are not OSGi versions; see {@link #isValidOsgiVersion(String)}. * In some places (eg bundles) the use of OSGi version syntax may be enforced. */ public static boolean isUsableVersion(String candidate) { return isUsable(candidate); }
/** true if the supplied name and version are complete; updates if the known data is incomplete; * throws if there is a mismatch; false if the supplied data is incomplete */ private boolean matchSetOrFail(String source, String name, String version) { boolean suppliedIsComplete = true; if (Strings.isBlank(name)) { suppliedIsComplete = false; } else if (Strings.isBlank(inferredMetadata.getSymbolicName())) { ((BasicManagedBundle)inferredMetadata).setSymbolicName(name); } else if (!Objects.equal(inferredMetadata.getSymbolicName(), name)){ throw new IllegalArgumentException("Symbolic name mismatch '"+name+"' from "+source+" (expected '"+inferredMetadata.getSymbolicName()+"')"); } if (Strings.isBlank(version)) { suppliedIsComplete = false; } else if (Strings.isBlank(inferredMetadata.getSuppliedVersionString())) { ((BasicManagedBundle)inferredMetadata).setVersion(version); } else if (!BrooklynVersionSyntax.equalAsOsgiVersions(inferredMetadata.getSuppliedVersionString(), version)) { throw new IllegalArgumentException("Bundle version mismatch '"+version+"' from "+source+" (expected '"+inferredMetadata.getSuppliedVersionString()+"')"); } return suppliedIsComplete; }
/** Creates a string satisfying {@link #isValidOsgiVersion(String)} based on the input. * For input satisfying {@link #isGoodBrooklynVersion(String)} the only change will be in the qualifer separator * (from "-" to ".") and making any "0" minor/patch token explicit (so "1-x" becomes "1.0.0.x"), * and the change can be reversed using {@link #toGoodBrooklynVersion(String)} (modulo insertion of "0"'s for minor/patch numbers if missing). * For input satisfying {@link #isValidOsgiVersion(String)}, the only change will be insertions of 0 for minor/patch. * Precise behaviour for other input is not guaranteed but callers can expect output which resembles the input, * with any major/minor/patch string at the front preserved and internal contiguous alphanumeric sequences preserved. */ public static String toValidOsgiVersion(String input) { Preconditions.checkNotNull(input); return toGoodVersion(input, ".", true); /* Note Maven has and used: DefaultMaven2OsgiConverter * from https://github.com/apache/felix/blob/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/maven/shared/osgi/DefaultMaven2OsgiConverter.java * but it (a) is more complicated, and (b) doesn't aggressively find numbers e.g. "1beta" goes to "0.0.0.1beta" instead of "1.0.0.beta" */ }
@Override public String getOsgiVersionString() { return version==null ? null : BrooklynVersionSyntax.toValidOsgiVersion(version); }
@Beta // API is stabilising public void addToLocalUnpersistedTypeRegistry(RegisteredType type, boolean canForce) { Preconditions.checkNotNull(type); Preconditions.checkNotNull(type.getSymbolicName()); Preconditions.checkNotNull(type.getVersion()); Preconditions.checkNotNull(type.getId()); if (!type.getId().equals(type.getSymbolicName()+":"+type.getVersion())) Asserts.fail("Registered type "+type+" has ID / symname mismatch"); RegisteredType oldType = mgmt.getTypeRegistry().get(type.getId()); if (oldType==null || canForce || BrooklynVersionSyntax.isSnapshot(oldType.getVersion())) { log.debug("Inserting "+type+" into "+this); localRegisteredTypes.put(type.getId(), type); } else { assertSameEnoughToAllowReplacing(oldType, type); } }
@Override public String getOsgiVersionString() { return version==null ? version : BrooklynVersionSyntax.toValidOsgiVersion(version); }
/** Returns true if the given strings are equal when mapped according to {@link #toValidOsgiVersion(String)} */ public static boolean equalAsOsgiVersions(String v1, String v2) { if (v1==null || v2==null) return (v1==null && v2==null); return toValidOsgiVersion(v1).equals(toValidOsgiVersion(v2)); }
public CatalogBundleDto(String name, String version, String url) { if (name == null && version == null) { Preconditions.checkNotNull(url, "url to an OSGi bundle is required"); } else { Preconditions.checkNotNull(name, "both name and version are required"); Preconditions.checkNotNull(version, "both name and version are required"); } this.symbolicName = name; this.version = version==null ? null : BrooklynVersionSyntax.toValidOsgiVersion(version); this.url = url; }
@Nullable public Version getOsgiVersion() { if (cachedOsgiVersion==null && v!=null) { cachedOsgiVersion = v==null ? null : Version.parseVersion(BrooklynVersionSyntax.toValidOsgiVersion(v)); } return cachedOsgiVersion; }
public static String getOsgiVersion() { return BrooklynVersionSyntax.toValidOsgiVersion(get()); } }
private void assertOsgiVersion(String input, String osgi) { Assert.assertEquals(BrooklynVersionSyntax.toValidOsgiVersion(input), osgi, "conversion to valid osgi"); }