java-spring-framework-remove-non-free.patch
| 1 | From 45ff8f9aff1ce08546b091505a706b1baf1bcb7b Mon Sep 17 00:00:00 2001 |
| 2 | From: Julien Lepiller <julien@lepiller.eu> |
| 3 | Date: Sat, 15 Sep 2018 00:09:39 +0200 |
| 4 | Subject: [PATCH] Remove dependency on jsr354 (javax.currency). |
| 5 | |
| 6 | jsr354 is a non-free package: |
| 7 | https://github.com/JavaMoney/jsr354-api/blob/master/EVALUATION-LICENCE.txt |
| 8 | --- |
| 9 | .../DefaultFormattingConversionService.java | 10 - |
| 10 | .../number/money/MoneyFormattingTests.java | 272 ------------------ |
| 11 | 2 files changed, 282 deletions(-) |
| 12 | delete mode 100644 spring-context/src/test/java/org/springframework/format/number/money/MoneyFormattingTests.java |
| 13 | |
| 14 | diff --git a/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java b/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java |
| 15 | index 2c7c60a..5e38006 100644 |
| 16 | --- a/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java |
| 17 | +++ b/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java |
| 18 | @@ -21,9 +21,6 @@ import org.springframework.format.FormatterRegistry; |
| 19 | import org.springframework.format.datetime.DateFormatterRegistrar; |
| 20 | import org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar; |
| 21 | import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; |
| 22 | -import org.springframework.format.number.money.CurrencyUnitFormatter; |
| 23 | -import org.springframework.format.number.money.Jsr354NumberFormatAnnotationFormatterFactory; |
| 24 | -import org.springframework.format.number.money.MonetaryAmountFormatter; |
| 25 | import org.springframework.format.number.NumberFormatAnnotationFormatterFactory; |
| 26 | import org.springframework.util.ClassUtils; |
| 27 | import org.springframework.util.StringValueResolver; |
| 28 | @@ -104,13 +101,6 @@ public class DefaultFormattingConversionService extends FormattingConversionServ |
| 29 | // Default handling of number values |
| 30 | formatterRegistry.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory()); |
| 31 | |
| 32 | - // Default handling of monetary values |
| 33 | - if (jsr354Present) { |
| 34 | - formatterRegistry.addFormatter(new CurrencyUnitFormatter()); |
| 35 | - formatterRegistry.addFormatter(new MonetaryAmountFormatter()); |
| 36 | - formatterRegistry.addFormatterForFieldAnnotation(new Jsr354NumberFormatAnnotationFormatterFactory()); |
| 37 | - } |
| 38 | - |
| 39 | // Default handling of date-time values |
| 40 | if (jsr310Present) { |
| 41 | // just handling JSR-310 specific date and time types |
| 42 | diff --git a/spring-context/src/test/java/org/springframework/format/number/money/MoneyFormattingTests.java b/spring-context/src/test/java/org/springframework/format/number/money/MoneyFormattingTests.java |
| 43 | deleted file mode 100644 |
| 44 | index 28df446..0000000 |
| 45 | --- a/spring-context/src/test/java/org/springframework/format/number/money/MoneyFormattingTests.java |
| 46 | +++ /dev/null |
| 47 | @@ -1,272 +0,0 @@ |
| 48 | -/* |
| 49 | - * Copyright 2002-2015 the original author or authors. |
| 50 | - * |
| 51 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
| 52 | - * you may not use this file except in compliance with the License. |
| 53 | - * You may obtain a copy of the License at |
| 54 | - * |
| 55 | - * http://www.apache.org/licenses/LICENSE-2.0 |
| 56 | - * |
| 57 | - * Unless required by applicable law or agreed to in writing, software |
| 58 | - * distributed under the License is distributed on an "AS IS" BASIS, |
| 59 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 60 | - * See the License for the specific language governing permissions and |
| 61 | - * limitations under the License. |
| 62 | - */ |
| 63 | - |
| 64 | -package org.springframework.format.number.money; |
| 65 | - |
| 66 | -import java.util.Locale; |
| 67 | -import javax.money.CurrencyUnit; |
| 68 | -import javax.money.MonetaryAmount; |
| 69 | - |
| 70 | -import org.junit.After; |
| 71 | -import org.junit.Before; |
| 72 | -import org.junit.Test; |
| 73 | - |
| 74 | -import org.springframework.beans.MutablePropertyValues; |
| 75 | -import org.springframework.context.i18n.LocaleContextHolder; |
| 76 | -import org.springframework.format.annotation.NumberFormat; |
| 77 | -import org.springframework.format.support.DefaultFormattingConversionService; |
| 78 | -import org.springframework.format.support.FormattingConversionService; |
| 79 | -import org.springframework.validation.DataBinder; |
| 80 | - |
| 81 | -import static org.junit.Assert.*; |
| 82 | - |
| 83 | -/** |
| 84 | - * @author Juergen Hoeller |
| 85 | - * @since 4.2 |
| 86 | - */ |
| 87 | -public class MoneyFormattingTests { |
| 88 | - |
| 89 | - private final FormattingConversionService conversionService = new DefaultFormattingConversionService(); |
| 90 | - |
| 91 | - |
| 92 | - @Before |
| 93 | - public void setUp() { |
| 94 | - LocaleContextHolder.setLocale(Locale.US); |
| 95 | - } |
| 96 | - |
| 97 | - @After |
| 98 | - public void tearDown() { |
| 99 | - LocaleContextHolder.setLocale(null); |
| 100 | - } |
| 101 | - |
| 102 | - |
| 103 | - @Test |
| 104 | - public void testAmountAndUnit() { |
| 105 | - MoneyHolder bean = new MoneyHolder(); |
| 106 | - DataBinder binder = new DataBinder(bean); |
| 107 | - binder.setConversionService(conversionService); |
| 108 | - |
| 109 | - MutablePropertyValues propertyValues = new MutablePropertyValues(); |
| 110 | - propertyValues.add("amount", "USD 10.50"); |
| 111 | - propertyValues.add("unit", "USD"); |
| 112 | - binder.bind(propertyValues); |
| 113 | - assertEquals(0, binder.getBindingResult().getErrorCount()); |
| 114 | - assertEquals("USD10.50", binder.getBindingResult().getFieldValue("amount")); |
| 115 | - assertEquals("USD", binder.getBindingResult().getFieldValue("unit")); |
| 116 | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); |
| 117 | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); |
| 118 | - |
| 119 | - LocaleContextHolder.setLocale(Locale.CANADA); |
| 120 | - binder.bind(propertyValues); |
| 121 | - LocaleContextHolder.setLocale(Locale.US); |
| 122 | - assertEquals(0, binder.getBindingResult().getErrorCount()); |
| 123 | - assertEquals("USD10.50", binder.getBindingResult().getFieldValue("amount")); |
| 124 | - assertEquals("USD", binder.getBindingResult().getFieldValue("unit")); |
| 125 | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); |
| 126 | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); |
| 127 | - } |
| 128 | - |
| 129 | - @Test |
| 130 | - public void testAmountWithNumberFormat1() { |
| 131 | - FormattedMoneyHolder1 bean = new FormattedMoneyHolder1(); |
| 132 | - DataBinder binder = new DataBinder(bean); |
| 133 | - binder.setConversionService(conversionService); |
| 134 | - |
| 135 | - MutablePropertyValues propertyValues = new MutablePropertyValues(); |
| 136 | - propertyValues.add("amount", "$10.50"); |
| 137 | - binder.bind(propertyValues); |
| 138 | - assertEquals(0, binder.getBindingResult().getErrorCount()); |
| 139 | - assertEquals("$10.50", binder.getBindingResult().getFieldValue("amount")); |
| 140 | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); |
| 141 | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); |
| 142 | - |
| 143 | - LocaleContextHolder.setLocale(Locale.CANADA); |
| 144 | - binder.bind(propertyValues); |
| 145 | - LocaleContextHolder.setLocale(Locale.US); |
| 146 | - assertEquals(0, binder.getBindingResult().getErrorCount()); |
| 147 | - assertEquals("$10.50", binder.getBindingResult().getFieldValue("amount")); |
| 148 | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); |
| 149 | - assertEquals("CAD", bean.getAmount().getCurrency().getCurrencyCode()); |
| 150 | - } |
| 151 | - |
| 152 | - @Test |
| 153 | - public void testAmountWithNumberFormat2() { |
| 154 | - FormattedMoneyHolder2 bean = new FormattedMoneyHolder2(); |
| 155 | - DataBinder binder = new DataBinder(bean); |
| 156 | - binder.setConversionService(conversionService); |
| 157 | - |
| 158 | - MutablePropertyValues propertyValues = new MutablePropertyValues(); |
| 159 | - propertyValues.add("amount", "10.50"); |
| 160 | - binder.bind(propertyValues); |
| 161 | - assertEquals(0, binder.getBindingResult().getErrorCount()); |
| 162 | - assertEquals("10.5", binder.getBindingResult().getFieldValue("amount")); |
| 163 | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); |
| 164 | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); |
| 165 | - } |
| 166 | - |
| 167 | - @Test |
| 168 | - public void testAmountWithNumberFormat3() { |
| 169 | - FormattedMoneyHolder3 bean = new FormattedMoneyHolder3(); |
| 170 | - DataBinder binder = new DataBinder(bean); |
| 171 | - binder.setConversionService(conversionService); |
| 172 | - |
| 173 | - MutablePropertyValues propertyValues = new MutablePropertyValues(); |
| 174 | - propertyValues.add("amount", "10%"); |
| 175 | - binder.bind(propertyValues); |
| 176 | - assertEquals(0, binder.getBindingResult().getErrorCount()); |
| 177 | - assertEquals("10%", binder.getBindingResult().getFieldValue("amount")); |
| 178 | - assertTrue(bean.getAmount().getNumber().doubleValue() == 0.1d); |
| 179 | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); |
| 180 | - } |
| 181 | - |
| 182 | - @Test |
| 183 | - public void testAmountWithNumberFormat4() { |
| 184 | - FormattedMoneyHolder4 bean = new FormattedMoneyHolder4(); |
| 185 | - DataBinder binder = new DataBinder(bean); |
| 186 | - binder.setConversionService(conversionService); |
| 187 | - |
| 188 | - MutablePropertyValues propertyValues = new MutablePropertyValues(); |
| 189 | - propertyValues.add("amount", "010.500"); |
| 190 | - binder.bind(propertyValues); |
| 191 | - assertEquals(0, binder.getBindingResult().getErrorCount()); |
| 192 | - assertEquals("010.500", binder.getBindingResult().getFieldValue("amount")); |
| 193 | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); |
| 194 | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); |
| 195 | - } |
| 196 | - |
| 197 | - @Test |
| 198 | - public void testAmountWithNumberFormat5() { |
| 199 | - FormattedMoneyHolder5 bean = new FormattedMoneyHolder5(); |
| 200 | - DataBinder binder = new DataBinder(bean); |
| 201 | - binder.setConversionService(conversionService); |
| 202 | - |
| 203 | - MutablePropertyValues propertyValues = new MutablePropertyValues(); |
| 204 | - propertyValues.add("amount", "USD 10.50"); |
| 205 | - binder.bind(propertyValues); |
| 206 | - assertEquals(0, binder.getBindingResult().getErrorCount()); |
| 207 | - assertEquals("USD 010.500", binder.getBindingResult().getFieldValue("amount")); |
| 208 | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); |
| 209 | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); |
| 210 | - |
| 211 | - LocaleContextHolder.setLocale(Locale.CANADA); |
| 212 | - binder.bind(propertyValues); |
| 213 | - LocaleContextHolder.setLocale(Locale.US); |
| 214 | - assertEquals(0, binder.getBindingResult().getErrorCount()); |
| 215 | - assertEquals("USD 010.500", binder.getBindingResult().getFieldValue("amount")); |
| 216 | - assertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d); |
| 217 | - assertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode()); |
| 218 | - } |
| 219 | - |
| 220 | - |
| 221 | - public static class MoneyHolder { |
| 222 | - |
| 223 | - private MonetaryAmount amount; |
| 224 | - |
| 225 | - private CurrencyUnit unit; |
| 226 | - |
| 227 | - public MonetaryAmount getAmount() { |
| 228 | - return amount; |
| 229 | - } |
| 230 | - |
| 231 | - public void setAmount(MonetaryAmount amount) { |
| 232 | - this.amount = amount; |
| 233 | - } |
| 234 | - |
| 235 | - public CurrencyUnit getUnit() { |
| 236 | - return unit; |
| 237 | - } |
| 238 | - |
| 239 | - public void setUnit(CurrencyUnit unit) { |
| 240 | - this.unit = unit; |
| 241 | - } |
| 242 | - } |
| 243 | - |
| 244 | - |
| 245 | - public static class FormattedMoneyHolder1 { |
| 246 | - |
| 247 | - @NumberFormat |
| 248 | - private MonetaryAmount amount; |
| 249 | - |
| 250 | - public MonetaryAmount getAmount() { |
| 251 | - return amount; |
| 252 | - } |
| 253 | - |
| 254 | - public void setAmount(MonetaryAmount amount) { |
| 255 | - this.amount = amount; |
| 256 | - } |
| 257 | - } |
| 258 | - |
| 259 | - |
| 260 | - public static class FormattedMoneyHolder2 { |
| 261 | - |
| 262 | - @NumberFormat(style = NumberFormat.Style.NUMBER) |
| 263 | - private MonetaryAmount amount; |
| 264 | - |
| 265 | - public MonetaryAmount getAmount() { |
| 266 | - return amount; |
| 267 | - } |
| 268 | - |
| 269 | - public void setAmount(MonetaryAmount amount) { |
| 270 | - this.amount = amount; |
| 271 | - } |
| 272 | - } |
| 273 | - |
| 274 | - |
| 275 | - public static class FormattedMoneyHolder3 { |
| 276 | - |
| 277 | - @NumberFormat(style = NumberFormat.Style.PERCENT) |
| 278 | - private MonetaryAmount amount; |
| 279 | - |
| 280 | - public MonetaryAmount getAmount() { |
| 281 | - return amount; |
| 282 | - } |
| 283 | - |
| 284 | - public void setAmount(MonetaryAmount amount) { |
| 285 | - this.amount = amount; |
| 286 | - } |
| 287 | - } |
| 288 | - |
| 289 | - |
| 290 | - public static class FormattedMoneyHolder4 { |
| 291 | - |
| 292 | - @NumberFormat(pattern = "#000.000#") |
| 293 | - private MonetaryAmount amount; |
| 294 | - |
| 295 | - public MonetaryAmount getAmount() { |
| 296 | - return amount; |
| 297 | - } |
| 298 | - |
| 299 | - public void setAmount(MonetaryAmount amount) { |
| 300 | - this.amount = amount; |
| 301 | - } |
| 302 | - } |
| 303 | - |
| 304 | - |
| 305 | - public static class FormattedMoneyHolder5 { |
| 306 | - |
| 307 | - @NumberFormat(pattern = "\u00A4\u00A4 #000.000#") |
| 308 | - private MonetaryAmount amount; |
| 309 | - |
| 310 | - public MonetaryAmount getAmount() { |
| 311 | - return amount; |
| 312 | - } |
| 313 | - |
| 314 | - public void setAmount(MonetaryAmount amount) { |
| 315 | - this.amount = amount; |
| 316 | - } |
| 317 | - } |
| 318 | - |
| 319 | -} |
| 320 | -- |
| 321 | 2.18.0 |
| 322 | |
| 323 |