/** * Parses a version identifier from the specified string. * * <p> * See {@link #Version(String)} for the format of the version string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A {@code Version} object representing the version identifier. If * {@code version} is {@code null} or the empty string then * {@link #emptyVersion} will be returned. * @throws IllegalArgumentException If {@code version} is improperly * formatted. */ public static Version parseVersion(String version) { if (version == null) { return emptyVersion; } return valueOf(version); }
/** * 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.valueOf(version); } catch (IllegalArgumentException e) { IllegalArgumentException iae = new IllegalArgumentException("invalid range \"" + range + "\": " + e.getMessage()); iae.initCause(e); throw iae; } }
/** * Parses a version identifier from the specified string. * * <p> * See {@link #Version(String)} for the format of the version string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A {@code Version} object representing the version identifier. If * {@code version} is {@code null} or the empty string then * {@link #emptyVersion} will be returned. * @throws IllegalArgumentException If {@code version} is improperly * formatted. */ public static Version parseVersion(String version) { if (version == null) { return emptyVersion; } return valueOf(version); }
/** * Parses a version identifier from the specified string. * * <p> * See {@link #Version(String)} for the format of the version string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A {@code Version} object representing the version identifier. If * {@code version} is {@code null} or the empty string then * {@link #emptyVersion} will be returned. * @throws IllegalArgumentException If {@code version} is improperly * formatted. */ public static Version parseVersion(String version) { if (version == null) { return emptyVersion; } return valueOf(version); }
/** * Parses a version identifier from the specified string. * * <p> * See {@link #Version(String)} for the format of the version string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A {@code Version} object representing the version identifier. If * {@code version} is {@code null} or the empty string then * {@link #emptyVersion} will be returned. * @throws IllegalArgumentException If {@code version} is improperly * formatted. */ public static Version parseVersion(String version) { if (version == null) { return emptyVersion; } return valueOf(version); }
/** * Parses a version identifier from the specified string. * * <p> * See {@link #Version(String)} for the format of the version string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A {@code Version} object representing the version identifier. If * {@code version} is {@code null} or the empty string then * {@link #emptyVersion} will be returned. * @throws IllegalArgumentException If {@code version} is improperly * formatted. */ public static Version parseVersion(String version) { if (version == null) { return emptyVersion; } return valueOf(version); }
/** * Parses a version identifier from the specified string. * * <p> * See {@link #Version(String)} for the format of the version string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A {@code Version} object representing the version identifier. If * {@code version} is {@code null} or the empty string then * {@link #emptyVersion} will be returned. * @throws IllegalArgumentException If {@code version} is improperly * formatted. */ public static Version parseVersion(String version) { if (version == null) { return emptyVersion; } return valueOf(version); }
/** * Parses a version identifier from the specified string. * * <p> * See {@link #Version(String)} for the format of the version string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A {@code Version} object representing the version identifier. If * {@code version} is {@code null} or the empty string then * {@link #emptyVersion} will be returned. * @throws IllegalArgumentException If {@code version} is improperly * formatted. */ public static Version parseVersion(String version) { if (version == null) { return emptyVersion; } return valueOf(version); }
/** * Parses a version identifier from the specified string. * * <p> * See {@link #Version(String)} for the format of the version string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A {@code Version} object representing the version identifier. If * {@code version} is {@code null} or the empty string then * {@link #emptyVersion} will be returned. * @throws IllegalArgumentException If {@code version} is improperly * formatted. */ public static Version parseVersion(String version) { if (version == null) { return emptyVersion; } return valueOf(version); }
/** * 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.valueOf(version); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "invalid range \"" + range + "\": " + e.getMessage(), e); } }
/** * 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.valueOf(version); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "invalid range \"" + range + "\": " + e.getMessage(), e); } }
/** * 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.valueOf(version); } catch (IllegalArgumentException e) { throw new IllegalArgumentException( "invalid range \"" + range + "\": " + e.getMessage(), e); } }
/** * 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.valueOf(version); } catch (IllegalArgumentException e) { IllegalArgumentException iae = new IllegalArgumentException("invalid range \"" + range + "\": " + e.getMessage()); iae.initCause(e); throw iae; } }
/** * 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.valueOf(version); } catch (IllegalArgumentException e) { IllegalArgumentException iae = new IllegalArgumentException("invalid range \"" + range + "\": " + e.getMessage()); iae.initCause(e); throw iae; } }
/** * 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.valueOf(version); } catch (IllegalArgumentException e) { IllegalArgumentException iae = new IllegalArgumentException("invalid range \"" + range + "\": " + e.getMessage()); iae.initCause(e); throw iae; } }
/** * 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.valueOf(version); } catch (IllegalArgumentException e) { IllegalArgumentException iae = new IllegalArgumentException("invalid range \"" + range + "\": " + e.getMessage()); iae.initCause(e); throw iae; } }
/** * 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.valueOf(version); } catch (IllegalArgumentException e) { IllegalArgumentException iae = new IllegalArgumentException("invalid range \"" + range + "\": " + e.getMessage()); iae.initCause(e); throw iae; } }
@Test public void testGetPrefixWithWhitelistedBundle() throws Exception { final Bundle bundle = Mockito.mock(Bundle.class); Mockito.when(bundle.getSymbolicName()).thenReturn("org.apache.brooklyn.my-bundle"); Mockito.when(bundle.getVersion()).thenReturn(Version.valueOf(BrooklynVersion.getOsgiVersion())); Function<Class<?>, Optional<Bundle>> bundleRetriever = new Function<Class<?>, Optional<Bundle>>() { @Override public Optional<Bundle> apply(Class<?> input) { return Optional.of(bundle); } }; OsgiClassPrefixer prefixer = new OsgiClassPrefixer(bundleRetriever); assertPresent(prefixer.getPrefix(String.class), "org.apache.brooklyn.my-bundle:"); }
@Test public void testGetPrefixWithBundle() throws Exception { final Class<?> classInBundle = String.class; final Bundle bundle = Mockito.mock(Bundle.class); Mockito.when(bundle.getSymbolicName()).thenReturn("my.symbolic.name"); Mockito.when(bundle.getVersion()).thenReturn(Version.valueOf("1.2.3")); Function<Class<?>, Optional<Bundle>> bundleRetriever = new Function<Class<?>, Optional<Bundle>>() { @Override public Optional<Bundle> apply(Class<?> input) { return (classInBundle.equals(input)) ? Optional.of(bundle) : Optional.<Bundle>absent(); } }; OsgiClassPrefixer prefixer = new OsgiClassPrefixer(bundleRetriever); assertAbsent(prefixer.getPrefix(Number.class)); assertPresent(prefixer.getPrefix(String.class), "my.symbolic.name:"); }
@Test public void testStringPrefix() throws Exception { Bundle bundle = Mockito.mock(Bundle.class); Mockito.when(bundle.getSymbolicName()).thenReturn("my.symbolic.name"); Mockito.when(bundle.getVersion()).thenReturn(Version.valueOf("1.2.3")); OsgiClassPrefixer prefixer = new OsgiClassPrefixer(); assertAbsent(prefixer.stripMatchingPrefix(bundle, "my.package.MyClass")); assertAbsent(prefixer.stripMatchingPrefix(bundle, "different.symbolic.name:my.package.MyClass")); assertAbsent(prefixer.stripMatchingPrefix(bundle, "different.symbolic.name:1.2.3:my.package.MyClass")); assertPresent(prefixer.stripMatchingPrefix(bundle, "my.symbolic.name:my.package.MyClass"), "my.package.MyClass"); assertPresent(prefixer.stripMatchingPrefix(bundle, "my.symbolic.name:1.2.3:my.package.MyClass"), "my.package.MyClass"); // TODO Will match any version - is that good enough? // Is it the right thing to do, to make upgrades simpler?! assertPresent(prefixer.stripMatchingPrefix(bundle, "my.symbolic.name:1.0.0:my.package.MyClass"), "my.package.MyClass"); }