├── softwaremill-conf ├── src │ ├── test │ │ ├── resources │ │ │ ├── test2.conf │ │ │ └── test1.conf │ │ └── java │ │ │ └── com │ │ │ └── softwaremill │ │ │ └── common │ │ │ └── conf │ │ │ └── encoding │ │ │ └── ConfigurationValueCoderTest.java │ └── main │ │ └── java │ │ └── com │ │ └── softwaremill │ │ └── common │ │ └── conf │ │ ├── PropertiesProvider.java │ │ ├── Config.java │ │ ├── SystemPropertiesMapWrapper.java │ │ ├── JBoss7DeployPropertiesProvider.java │ │ ├── encoding │ │ ├── ConfigurationValueCoder.java │ │ ├── MasterPasswordStore.java │ │ ├── server │ │ │ └── MasterPasswordSetterClient.java │ │ └── CodingConsole.java │ │ └── ClasspathPropertiesProvider.java ├── README.txt └── pom.xml ├── gp.sh ├── softwaremill-cdi └── src │ ├── test │ ├── resources │ │ ├── conftest.conf │ │ └── hibernate.test.cfg.xml │ └── java │ │ └── com │ │ └── softwaremill │ │ └── common │ │ └── cdi │ │ ├── objectservice │ │ ├── A.java │ │ ├── auto │ │ │ ├── IAuto.java │ │ │ ├── MySpecialString.java │ │ │ ├── ExecutionMock.java │ │ │ ├── MyString.java │ │ │ ├── AutoMyString.java │ │ │ └── AutoString.java │ │ ├── Service1.java │ │ ├── Service2.java │ │ ├── AbstractService3.java │ │ ├── Service3.java │ │ ├── C.java │ │ ├── B.java │ │ ├── Service1B.java │ │ ├── Service1C.java │ │ ├── Service3B.java │ │ ├── Service3C.java │ │ ├── Service2C.java │ │ └── Service2B.java │ │ ├── autofactory │ │ ├── qualifier │ │ │ ├── QualifiedDependency.java │ │ │ ├── ExampleStringQualifier.java │ │ │ └── PriceCalculatorQualifiedDependencyImpl.java │ │ ├── Discounts.java │ │ ├── instance │ │ │ ├── InstanceBean.java │ │ │ ├── InstanceBean2.java │ │ │ └── InjectDataAndInstanceConstructor.java │ │ ├── BulkOrderDiscounts.java │ │ ├── PriceCalculator.java │ │ ├── Product.java │ │ ├── TotalPriceCalculator.java │ │ ├── producer │ │ │ ├── ExampleProductQualifier.java │ │ │ └── ExamplePriceCalculatorProducer.java │ │ ├── mixed │ │ │ ├── PriceCalculatorMixedConstructorImpl.java │ │ │ └── AutoFactoryMixedConstructorTest.java │ │ ├── logger │ │ │ ├── InjectDataAndLoggerField.java │ │ │ └── InjectDataAndLoggerConstructor.java │ │ ├── field │ │ │ ├── PriceCalculatorFieldInjectionImpl.java │ │ │ ├── AutoFactoryFieldInjectionTest.java │ │ │ └── TotalPriceCalculatorFixedInjectionImpl.java │ │ └── multipleconstructors │ │ │ └── BeanWithAdditionalDefaultConstructor.java │ │ ├── security │ │ ├── SecureBeanGlobal.java │ │ ├── SecureResultBean.java │ │ ├── SecureBeanStacked.java │ │ ├── SecureBeanSecureVar.java │ │ ├── SecureBeanSecureVarExp.java │ │ ├── SecureBeanDirect.java │ │ ├── StringHolder.java │ │ ├── SecureBeanCompoundContextual.java │ │ ├── NoAccess.java │ │ ├── AccessIfVar1Set.java │ │ ├── AllowWithFlagsBean.java │ │ └── SecureResultTest.java │ │ ├── el │ │ └── StringHoldingBean.java │ │ ├── interceptor │ │ └── BeanToIntercept.java │ │ ├── persistence │ │ ├── MockEntityManagerProducers.java │ │ ├── EntityWithLazySubentity.java │ │ └── AbstractHibernateTest.java │ │ ├── util │ │ └── ArquillianUtil.java │ │ └── conf │ │ └── ConfValueTest.java │ └── main │ ├── resources │ └── META-INF │ │ ├── services │ │ └── javax.enterprise.inject.spi.Extension │ │ └── beans.xml │ └── java │ └── com │ └── softwaremill │ └── common │ └── cdi │ ├── el │ ├── ELEvaluator.java │ ├── ELEvaluatorUtil.java │ ├── ELEvaluatorProducer.java │ ├── FacesContextELEvaluator.java │ └── AbstractELEvaluator.java │ ├── security │ ├── LoginBean.java │ ├── SecurityConditionException.java │ ├── SecureBinding.java │ ├── AllowWithFlag.java │ ├── Secure.java │ ├── SecureVar.java │ ├── InterceptSecure.java │ ├── SecurityFlags.java │ ├── SecureResult.java │ └── SecurityResultInterceptor.java │ ├── objectservice │ ├── OS.java │ ├── auto │ │ ├── OS.java │ │ ├── AutoOSException.java │ │ └── OSImpl.java │ ├── OSP.java │ └── extension │ │ ├── PureWildcardType.java │ │ └── OSPImpl.java │ ├── autofactory │ ├── extension │ │ ├── parameter │ │ │ ├── converter │ │ │ │ └── ConstructorToParameterValuesConverter.java │ │ │ ├── ParameterValue.java │ │ │ └── FactoryParameterParameterValue.java │ │ ├── QualifierAnnotationsFilter.java │ │ ├── MethodParameterIndexer.java │ │ └── AutoFactoryExtension.java │ ├── FactoryParameter.java │ └── CreatedWith.java │ ├── transaction │ ├── Transactional.java │ └── TransactionTimeout.java │ ├── persistence │ ├── Writeable.java │ ├── ReadOnly.java │ ├── QueryCreator.java │ ├── EntityManagerUtil.java │ └── EntityManagerFactoryProducer.java │ ├── config │ └── Configuration.java │ ├── conf │ ├── ConfValue.java │ └── ConfValueProducer.java │ ├── interceptor │ ├── NullToEmptyStringParams.java │ └── NullToEmptyStringParamsInterceptor.java │ ├── logger │ └── LoggerProducer.java │ ├── sysprops │ └── SystemProperty.java │ └── validation │ ├── NoSpecialCharsValidator.java │ ├── NoSpecialChars.java │ └── Length.java ├── softwaremill-backup ├── src │ ├── test │ │ └── resources │ │ │ └── backuptest.conf │ └── main │ │ └── java │ │ └── com │ │ └── softwaremill │ │ └── common │ │ └── backup │ │ └── SimpleDBRegion.java └── scripts │ ├── restore_sdb.sh │ ├── backup_conf.sh │ ├── backup_sdb_and_upload.sh │ └── backup_mysql_and_upload.sh ├── softwaremill-debug └── src │ └── main │ ├── resources │ └── META-INF │ │ ├── services │ │ └── javax.enterprise.inject.spi.Extension │ │ └── beans.xml │ └── java │ └── com │ └── softwaremill │ └── common │ └── debug │ └── timing │ ├── Timed.java │ ├── TimingOutputFilter.java │ ├── TimingInterceptor.java │ └── TimingProxy.java ├── softwaremill-test ├── softwaremill-test-db │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── jndi.properties │ │ │ │ ├── bitronix-default-config.properties │ │ │ │ └── hibernate.test.cfg.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── softwaremill │ │ │ │ └── common │ │ │ │ └── dbtest │ │ │ │ ├── util │ │ │ │ ├── SqlFileResolver.java │ │ │ │ └── DbMode.java │ │ │ │ └── UtxDependencyProvider.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── softwaremill │ │ │ └── common │ │ │ └── dbtest │ │ │ ├── TestOfDBTest.sql │ │ │ ├── EntityDAO.java │ │ │ ├── Entity.java │ │ │ ├── TestEntity1Reader.java │ │ │ ├── TestEntity1Manager.java │ │ │ └── util │ │ │ └── SqlFileResolverTest.java │ └── README.md ├── softwaremill-test-server │ └── src │ │ └── main │ │ ├── resources │ │ ├── dummy.keystore │ │ └── logback.xml │ │ └── java │ │ └── com │ │ └── softwaremill │ │ └── common │ │ └── testserver │ │ └── Responder.java ├── softwaremill-test-ui-web │ ├── README.md │ └── src │ │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── softwaremill │ │ │ └── common │ │ │ └── test │ │ │ └── web │ │ │ └── selenium │ │ │ └── screenshots │ │ │ ├── AnTest.java │ │ │ └── AnSeleniumTest.java │ │ └── main │ │ └── java │ │ └── com │ │ └── softwaremill │ │ └── common │ │ └── test │ │ └── web │ │ ├── jboss │ │ ├── SysoutLog.java │ │ ├── Deployment.java │ │ ├── server │ │ │ ├── JBossAS.java │ │ │ └── JBossASProvider.java │ │ └── DeployementProperties.java │ │ ├── selenium │ │ ├── screenshots │ │ │ └── Screenshotter.java │ │ ├── SMLSelenium.java │ │ └── SeleniumBrowserProperties.java │ │ └── email │ │ ├── EmailHeader.java │ │ └── AbstractEmailServerRunner.java ├── softwaremill-test-ui-swing │ ├── README.MD │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── softwaremill │ │ │ │ └── test │ │ │ │ └── swing │ │ │ │ ├── AbstractGUITest.java │ │ │ │ ├── TeamCityScreenShotOnFailureListener.java │ │ │ │ └── FileNameBuilder.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── softwaremill │ │ │ └── test │ │ │ └── swing │ │ │ └── AppTest.java │ └── pom.xml ├── softwaremill-test-arquillian │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── softwaremill │ │ └── common │ │ └── arquillian │ │ ├── ArchiveUtil.java │ │ ├── ManifestUtil.java │ │ └── BetterArquillian.java ├── softwaremill-test-util │ ├── src │ │ ├── main │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── softwaremill │ │ │ │ └── common │ │ │ │ └── test │ │ │ │ └── util │ │ │ │ ├── Execution.java │ │ │ │ ├── ExtMockito.java │ │ │ │ ├── reorder │ │ │ │ ├── LastTest.java │ │ │ │ ├── TestOrder.java │ │ │ │ └── FirstTest.java │ │ │ │ └── MessageWaiter.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── softwaremill │ │ │ └── common │ │ │ └── test │ │ │ └── util │ │ │ ├── ExtMockitoTest.java │ │ │ ├── MockitoTestNGListenerTest.java │ │ │ └── ExecutionTest.java │ └── README.md └── pom.xml ├── .gitignore ├── softwaremill-sqs ├── src │ ├── test │ │ └── resources │ │ │ └── sqs.conf │ └── main │ │ ├── java │ │ └── com │ │ │ └── softwaremill │ │ │ └── common │ │ │ ├── task │ │ │ ├── TaskExecutor.java │ │ │ ├── Task.java │ │ │ ├── OneTimeTask.java │ │ │ └── ExecuteWithRequestContext.java │ │ │ └── sqs │ │ │ ├── task │ │ │ └── SQSTaskTimer.java │ │ │ ├── exception │ │ │ └── SQSRuntimeException.java │ │ │ ├── email │ │ │ ├── SendEmailTaskExecutor.java │ │ │ └── SendEmailTask.java │ │ │ ├── util │ │ │ ├── AttachmentDescription.java │ │ │ └── SQSAnswer.java │ │ │ ├── ReceivedMessage.java │ │ │ ├── MessageId.java │ │ │ └── ReceiptHandle.java │ │ └── resources │ │ └── META-INF │ │ └── beans.xml └── README.md ├── softwaremill-scripts └── jsf-view-generator │ ├── README.md │ └── pom.xml ├── softwaremill-util ├── src │ ├── test │ │ ├── java │ │ │ └── com │ │ │ │ └── softwaremill │ │ │ │ └── common │ │ │ │ └── util │ │ │ │ ├── dependency │ │ │ │ ├── FooAnnotatedClass.java │ │ │ │ ├── RequestScopedService.java │ │ │ │ ├── TestQualifier.java │ │ │ │ └── AnotherTestQualifier.java │ │ │ │ ├── RichStringTest.java │ │ │ │ └── stringsorting │ │ │ │ └── ByteByByteStringComparatorTest.java │ │ └── resources │ │ │ ├── simple.etemplate │ │ │ └── advanced.etemplate │ └── main │ │ └── java │ │ └── com │ │ └── softwaremill │ │ └── common │ │ └── util │ │ ├── persistance │ │ └── Identifiable.java │ │ ├── Sleeper.java │ │ ├── time │ │ ├── Clock.java │ │ ├── RealTimeClock.java │ │ └── FixtureTimeClock.java │ │ ├── InfiniteSleeper.java │ │ ├── io │ │ ├── FileFilenameFilter.java │ │ ├── DirFilenameFilter.java │ │ ├── InputStreamInputSupplier.java │ │ └── Shell.java │ │ ├── dependency │ │ ├── DependencyProvider.java │ │ └── GlobalDependencyProvider.java │ │ ├── SecsToMills.java │ │ ├── templates │ │ └── TemplateContentData.java │ │ ├── stringsorting │ │ ├── ByteByByteStringComparator.java │ │ └── SortedCharsToConsecutiveCharsAssigner.java │ │ ├── IncrementalSleeper.java │ │ ├── RichList.java │ │ ├── tuples │ │ └── LexicographicPair.java │ │ ├── NameValuePairBuilder.java │ │ ├── validation │ │ └── NotJustWhitespace.java │ │ └── system │ │ └── ProcessKiller.java └── README.md ├── softwaremill-paypal ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── softwaremill │ │ │ └── common │ │ │ └── paypal │ │ │ ├── process │ │ │ ├── status │ │ │ │ ├── VerificationException.java │ │ │ │ ├── PayPalStatusVerifier.java │ │ │ │ └── PayPalStatus.java │ │ │ └── processors │ │ │ │ ├── VerifiedPayPalProcessor.java │ │ │ │ ├── PayPalProcessor.java │ │ │ │ ├── InvalidPayPalProcessor.java │ │ │ │ ├── UnknownPayPalProcessor.java │ │ │ │ └── AbstractPayPalProcessor.java │ │ │ └── button │ │ │ └── PaypalCartItem.java │ └── test │ │ └── java │ │ └── com │ │ └── softwaremill │ │ └── common │ │ └── paypal │ │ └── process │ │ ├── TestErrorHandler.java │ │ ├── processors │ │ └── MockVerifiedPayPalProcessor.java │ │ └── status │ │ └── MockStatusVerifier.java └── pom.xml └── softwaremill-faces └── src └── main ├── resources └── META-INF │ ├── beans.xml │ └── smlComponents.taglib.xml └── java └── com └── softwaremill └── common └── faces ├── navigation ├── Page.java ├── CurrentPage.java └── ViewIdPage.java ├── validator ├── DelegatingValidator.java └── AbstractDelgatingValidator.java ├── messages └── FacesMessagesListener.java ├── transaction └── TransactionExceptionObserver.java └── fileupload └── FileUpload.java /softwaremill-conf/src/test/resources/test2.conf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /gp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | git fetch 3 | git rebase origin 4 | git push 5 | 6 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/resources/conftest.conf: -------------------------------------------------------------------------------- 1 | key1=value1 2 | key2=value2 -------------------------------------------------------------------------------- /softwaremill-conf/src/test/resources/test1.conf: -------------------------------------------------------------------------------- 1 | a=b 2 | c=d 3 | x=encoded.AjVEqbmwIvk= -------------------------------------------------------------------------------- /softwaremill-backup/src/test/resources/backuptest.conf: -------------------------------------------------------------------------------- 1 | AWSAccessKeyId=${AWSAccessKeyId} 2 | SecretAccessKey=${SecretAccessKey} -------------------------------------------------------------------------------- /softwaremill-debug/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | com.softwaremill.common.debug.timing.TimingExtension 2 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/main/resources/jndi.properties: -------------------------------------------------------------------------------- 1 | java.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | temp 3 | log 4 | target 5 | .classpath 6 | .project 7 | .settings 8 | *~ 9 | *.tmp 10 | *.iml 11 | *.ipr 12 | *.iws 13 | .idea 14 | 15 | # Mac specific 16 | .DS_Store 17 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/main/resources/bitronix-default-config.properties: -------------------------------------------------------------------------------- 1 | bitronix.tm.journal.disk.logPart1Filename=target/btm1.tlog 2 | bitronix.tm.journal.disk.logPart2Filename=target/btm2.tlog 3 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-server/src/main/resources/dummy.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softwaremill/softwaremill-common/HEAD/softwaremill-test/softwaremill-test-server/src/main/resources/dummy.keystore -------------------------------------------------------------------------------- /softwaremill-sqs/src/test/resources/sqs.conf: -------------------------------------------------------------------------------- 1 | AWSAccessKeyId=${AWSAccessKeyId} 2 | SecretAccessKey=${SecretAccessKey} 3 | smtpHost=localhost 4 | smtpPort=9025 5 | queue=sqs-email-test 6 | from=test@example.org 7 | encoding=UTF-8 -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/test/java/com/softwaremill/common/dbtest/TestOfDBTest.sql: -------------------------------------------------------------------------------- 1 | insert into test_entity_1(id, data_c) values (0, 'data1'); 2 | insert into test_entity_1(id, data_c) values (1, 'data2'); 3 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/A.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public abstract class A { 7 | } 8 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/qualifier/QualifiedDependency.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.qualifier; 2 | 3 | @ExampleStringQualifier 4 | public class QualifiedDependency { 5 | } 6 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/README.md: -------------------------------------------------------------------------------- 1 | Maven dependency: 2 | 3 | 4 | com.softwaremill.common 5 | softwaremill-test-ui-web 6 | 18 7 | 8 | -------------------------------------------------------------------------------- /softwaremill-scripts/jsf-view-generator/README.md: -------------------------------------------------------------------------------- 1 | Quick and dirty Scala script to create simple JSF view of fields of entity. It is necessary to add .jar with entity to the classpath (add it as dependency to pom.xml, and your IDE should do the rest). 2 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/auto/IAuto.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.auto; 2 | 3 | @OS 4 | public interface IAuto { 5 | 6 | void doSomething(String bom, T object, Integer bim); 7 | } 8 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-swing/README.MD: -------------------------------------------------------------------------------- 1 | Maven dependency: 2 | 3 | 4 | com.softwaremill.common 5 | softwaremill-test-ui-swing 6 | ${current.version} 7 | 8 | -------------------------------------------------------------------------------- /softwaremill-util/src/test/java/com/softwaremill/common/util/dependency/FooAnnotatedClass.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.dependency; 2 | 3 | /** 4 | * Class to get the "real" qualifier from 5 | */ 6 | @TestQualifier 7 | public class FooAnnotatedClass { 8 | } 9 | -------------------------------------------------------------------------------- /softwaremill-util/src/test/java/com/softwaremill/common/util/dependency/RequestScopedService.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.dependency; 2 | 3 | import javax.enterprise.context.RequestScoped; 4 | 5 | @RequestScoped 6 | public class RequestScopedService { 7 | } 8 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/task/TaskExecutor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.task; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public interface TaskExecutor> { 7 | void execute(T task); 8 | } 9 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/Service1.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public interface Service1 extends OS { 7 | Object get(); 8 | } 9 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/Service2.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public interface Service2 extends OS { 7 | Object get(); 8 | } 9 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/SecureBeanGlobal.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | @Secure("#{false}") 7 | public class SecureBeanGlobal { 8 | public void method1() { } 9 | } -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/AbstractService3.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public abstract class AbstractService3 implements Service3 { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/test/java/com/softwaremill/common/test/web/selenium/screenshots/AnTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.selenium.screenshots; 2 | 3 | /** 4 | * It isn't a real test class, it's used in {@link FailureTestListenerTest} 5 | */ 6 | public class AnTest {} 7 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/persistance/Identifiable.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.persistance; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public interface Identifiable { 7 | T getId(); 8 | void setId(T id); 9 | } 10 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/Discounts.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class Discounts { 7 | public int getNormalDiscount() { 8 | return 10; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/SecureResultBean.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class SecureResultBean { 7 | @SecureResult("#{result == 'a'}") 8 | public String method1(String p) { return p; } 9 | } -------------------------------------------------------------------------------- /softwaremill-util/src/test/resources/simple.etemplate: -------------------------------------------------------------------------------- 1 | # This is a comment line - begins with # 2 | # 3 | # Simple template: subject, no arguments 4 | # 5 | # Subject can be putted in a line prefixed with %subject% - rest of line is trimmed 6 | # Rest of file is email body 7 | 8 | %subject% Hello World! 9 | 10 | This is a sample email. -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/instance/InstanceBean.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.instance; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class InstanceBean { 7 | public String getData() { 8 | return "a"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/instance/InstanceBean2.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.instance; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class InstanceBean2 { 7 | public String getData() { 8 | return "b"; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/SecureBeanStacked.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class SecureBeanStacked { 7 | public void method1() { } 8 | 9 | @NoAccess 10 | public void method2() { } 11 | } -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/test/java/com/softwaremill/common/dbtest/EntityDAO.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.dbtest; 2 | 3 | /** 4 | * @author Maciej Bilas 5 | * @since 15/12/11 12:45 6 | */ 7 | public interface EntityDAO { 8 | Entity persist(Entity entity); 9 | 10 | Entity reload(Entity entity); 11 | } 12 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/SecureBeanSecureVar.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class SecureBeanSecureVar { 7 | @Secure("#{var1 == true}") 8 | public void method1(@SecureVar("var1") boolean var1) { } 9 | } -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/BulkOrderDiscounts.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class BulkOrderDiscounts { 7 | public int getDiscountForBulkOrderSize(int size) { 8 | return size/2; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/task/Task.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.task; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public interface Task> extends Serializable { 9 | Class> getExecutorBeanClass(); 10 | } 11 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/el/StringHoldingBean.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.el; 2 | 3 | import javax.inject.Named; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | @Named 9 | public class StringHoldingBean { 10 | public String getValue() { 11 | return "test value"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/main/java/com/softwaremill/common/test/web/jboss/SysoutLog.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.jboss; 2 | 3 | /** 4 | * @author Pawel Wrzeszcz (pawel [at] softwaremill . com) 5 | */ 6 | public class SysoutLog { 7 | 8 | public void info(String msg) { 9 | System.out.println("--- " + msg); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/Service3.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * A service for which implementations inherit from an abtract service. 5 | * @author Adam Warski (adam at warski dot org) 6 | */ 7 | public interface Service3 extends OS { 8 | Object get(); 9 | } 10 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/SecureBeanSecureVarExp.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class SecureBeanSecureVarExp { 7 | @Secure("#{var1 == 'a'}") 8 | public void method1(@SecureVar(value = "var1", exp = "#{p.content}") StringHolder sh) { } 9 | } -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/Sleeper.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util; 2 | 3 | public class Sleeper { 4 | public static void sleepFor(long millis) { 5 | try { 6 | Thread.sleep(millis); 7 | } catch (InterruptedException e) { 8 | throw new RuntimeException(e); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/time/Clock.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.time; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | /** 6 | * Interface providing current system time. 7 | */ 8 | public interface Clock { 9 | 10 | DateTime currentDateTime(); 11 | DateTime currentDateTimeUTC(); 12 | long currentTimeMillis(); 13 | } -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/SecureBeanDirect.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class SecureBeanDirect { 7 | @Secure("#{true}") 8 | public void method1() { } 9 | 10 | @Secure("#{false}") 11 | public void method2() { } 12 | } 13 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/InfiniteSleeper.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util; 2 | 3 | /** 4 | * @author Pawel Wrzeszcz (pawel [at] softwaremill . com) 5 | */ 6 | public class InfiniteSleeper { 7 | 8 | public synchronized void sleepInfinitely() throws InterruptedException { 9 | wait(); // Never expected to be notified 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/PriceCalculator.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public interface PriceCalculator { 7 | int getFinalPrice(); 8 | 9 | interface Factory { 10 | PriceCalculator create(Product product); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/main/java/com/softwaremill/common/test/web/selenium/screenshots/Screenshotter.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.selenium.screenshots; 2 | 3 | /** 4 | * Screenshotter 5 | * 6 | * User: szimano 7 | */ 8 | public interface Screenshotter { 9 | 10 | /** 11 | * Performs screenshot 12 | */ 13 | void doScreenshot(); 14 | } 15 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-server/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/auto/MySpecialString.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.auto; 2 | 3 | /** 4 | * Class that extends MyString for inheritance checks 5 | */ 6 | public class MySpecialString extends MyString{ 7 | 8 | public MySpecialString(String someString) { 9 | super(someString + "ButVerySpecial"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /softwaremill-conf/src/main/java/com/softwaremill/common/conf/PropertiesProvider.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.conf; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public interface PropertiesProvider { 9 | ImmutableMap lookupProperties(String name); 10 | 11 | boolean providerAvailable(); 12 | } 13 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/auto/ExecutionMock.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.auto; 2 | 3 | import javax.enterprise.context.ApplicationScoped; 4 | import java.io.Serializable; 5 | 6 | @ApplicationScoped 7 | public class ExecutionMock implements Serializable{ 8 | 9 | Integer myStringExecs = 0; 10 | 11 | Integer stringExecs = 0; 12 | } 13 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | com.softwaremill.common.cdi.security.SecurityExtension 2 | com.softwaremill.common.cdi.config.ConfigExtension 3 | com.softwaremill.common.cdi.objectservice.extension.ObjectServiceExtension 4 | com.softwaremill.common.cdi.autofactory.extension.AutoFactoryExtension 5 | com.softwaremill.common.cdi.objectservice.auto.AutoObjectServiceExtension 6 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/C.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class C extends A { 7 | private String value; 8 | 9 | public C(String value) { 10 | this.value = value; 11 | } 12 | 13 | public String getValue() { 14 | return value; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/B.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class B extends A { 7 | private Integer value; 8 | 9 | public B(Integer value) { 10 | this.value = value; 11 | } 12 | 13 | public Integer getValue() { 14 | return value; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/el/ELEvaluator.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.el; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public interface ELEvaluator { 9 | T evaluate(String expression, Class expectedResultType); 10 | 11 | T evaluate(String expression, Class expectedResultType, Map parameters); 12 | } 13 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/security/LoginBean.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * Should be implemented by the bean which controls the logged-in status of the user. 5 | * @author Adam Warski (adam at warski dot org) 6 | */ 7 | public interface LoginBean { 8 | /** 9 | * @return True iff a user is currently logged in. 10 | */ 11 | boolean isLoggedIn(); 12 | } 13 | -------------------------------------------------------------------------------- /softwaremill-conf/README.txt: -------------------------------------------------------------------------------- 1 | # Configuration reader 2 | 3 | Maven dependency: 4 | 5 | 6 | com.softwaremill.common 7 | softwaremill-conf 8 | 5 9 | 10 | 11 | See the javadocs for the [Configuration](/softwaremill/softwaremill-common/blob/master/softwaremill-conf/src/main/java/pl/softwaremill/common/conf/Configuration.java) class. -------------------------------------------------------------------------------- /softwaremill-paypal/src/main/java/com/softwaremill/common/paypal/process/status/VerificationException.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process.status; 2 | 3 | /** 4 | * @Author: lukasz.zuchowski at gmail dot com 5 | * Date: 05.04.12 6 | * Time: 13:18 7 | */ 8 | public class VerificationException extends RuntimeException { 9 | 10 | public VerificationException(Throwable cause) { 11 | super(cause); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /softwaremill-backup/scripts/restore_sdb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ $# -ne 2 ] 4 | then 5 | echo "Usage: restrore_sdb [domain name] [file name]" 6 | exit 1 7 | fi 8 | 9 | # Configuration 10 | ############### 11 | 12 | source backup_conf.sh 13 | 14 | ######### 15 | 16 | # Creating backup files 17 | java -cp $SDB_BACKUP_PATH com.softwaremill.common.backup.RunRestore $SIMPLEDB_ACCESS_KEY_ID $SIMPLEDB_SECRET_ACCESS_KEY $SIMPLEDB_REGION $1 $2 18 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/Product.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class Product { 7 | private int basePrice; 8 | 9 | public Product(int basePrice) { 10 | this.basePrice = basePrice; 11 | } 12 | 13 | public int getBasePrice() { 14 | return basePrice; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/auto/MyString.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.auto; 2 | 3 | /** 4 | * String wrapper 5 | */ 6 | public class MyString { 7 | 8 | public String someString; 9 | 10 | public MyString(String someString) { 11 | this.someString = someString; 12 | } 13 | 14 | public String getSomeString() { 15 | return someString; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/TotalPriceCalculator.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public interface TotalPriceCalculator { 9 | int getTotalPrice(); 10 | 11 | interface Factory { 12 | TotalPriceCalculator create(List products, int specialDiscount); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/StringHolder.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class StringHolder { 7 | private final String content; 8 | 9 | public StringHolder(String content) { 10 | this.content = content; 11 | } 12 | 13 | public String getContent() { 14 | return content; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /softwaremill-paypal/src/main/java/com/softwaremill/common/paypal/process/processors/VerifiedPayPalProcessor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process.processors; 2 | 3 | import com.softwaremill.common.paypal.process.status.PayPalStatus; 4 | 5 | public abstract class VerifiedPayPalProcessor extends AbstractPayPalProcessor { 6 | 7 | @Override 8 | public boolean accept(PayPalStatus status) { 9 | return status.isVerified(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/objectservice/OS.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * A marker interface for services for particular type of objects. 5 | * @author Adam Warski (adam at warski dot org) 6 | */ 7 | public interface OS { 8 | /** 9 | * Sets the object, that is being serviced. 10 | * @param serviced The serviced object. 11 | */ 12 | void setServiced(T serviced); 13 | } 14 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/main/java/com/softwaremill/common/test/web/jboss/Deployment.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.jboss; 2 | 3 | /** 4 | * @author Pawel Wrzeszcz (pawel . wrzeszcz [at] gmail . com) 5 | */ 6 | public interface Deployment { 7 | void deploy(String deployDir) throws Exception; 8 | 9 | void undeploy(String deployDir) throws Exception; 10 | 11 | String getWaitForMessage(); 12 | 13 | long getWaitMillis(); 14 | } 15 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/task/OneTimeTask.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.task; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public interface OneTimeTask> extends Task { 7 | /** 8 | * @return Number of seconds after which the task execution will be retried. Return {@code null} for the default 9 | * interval (30 seconds). 10 | */ 11 | Integer getTaskTimeout(); 12 | } 13 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/autofactory/extension/parameter/converter/ConstructorToParameterValuesConverter.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.extension.parameter.converter; 2 | 3 | import com.softwaremill.common.cdi.autofactory.extension.parameter.ParameterValue; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public interface ConstructorToParameterValuesConverter { 9 | ParameterValue[] convert(); 10 | } 11 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/SecureBeanCompoundContextual.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | @Secure("#{var3 == true}") 7 | public class SecureBeanCompoundContextual { 8 | @AccessIfVar1Set 9 | @Secure("#{var2 == true}") 10 | public void method1(@SecureVar("var1") boolean var1, @SecureVar("var2") boolean var2, @SecureVar("var3") boolean var3) { } 11 | } -------------------------------------------------------------------------------- /softwaremill-paypal/src/main/java/com/softwaremill/common/paypal/process/status/PayPalStatusVerifier.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process.status; 2 | 3 | import com.softwaremill.common.paypal.process.RequestParameters; 4 | 5 | /** 6 | * @Author: lukasz.zuchowski at gmail dot com 7 | * Date: 05.04.12 8 | * Time: 13:16 9 | */ 10 | public interface PayPalStatusVerifier { 11 | 12 | public PayPalStatus verify(String url, RequestParameters requestParameters); 13 | } 14 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /softwaremill-debug/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /softwaremill-faces/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 11 | 12 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-server/src/main/java/com/softwaremill/common/testserver/Responder.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.testserver; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | import java.io.IOException; 6 | 7 | public interface Responder { 8 | 9 | boolean canRespond(HttpServletRequest request); 10 | 11 | void respond(HttpServletRequest request, HttpServletResponse response) throws IOException; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /softwaremill-util/src/test/resources/advanced.etemplate: -------------------------------------------------------------------------------- 1 | # Advanced template: some parameters used 2 | # 3 | # {0} - username 4 | # {1} - email 5 | # {2} - organization name 6 | # {3} - organization subdomain 7 | 8 | 9 | %subject% Welcome to Company! 10 | 11 | Welcome {0}, 12 | You have registered in our service your organization: {2}. 13 | Your new e-service can be accessed on http://{3}.example.org 14 | Your account data: 15 | Username: {0} 16 | Email: {1} 17 | 18 | Best regards, 19 | Company Team -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/objectservice/auto/OS.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.auto; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.TYPE; 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | /** 10 | * Used to mark interface for Object Service 11 | */ 12 | @Target({ TYPE }) 13 | @Retention(RUNTIME) 14 | public @interface OS { 15 | } 16 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-arquillian/src/main/java/com/softwaremill/common/arquillian/ArchiveUtil.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.arquillian; 2 | 3 | import org.jboss.shrinkwrap.api.ShrinkWrap; 4 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 5 | 6 | /** 7 | * @author Pawel Wrzeszcz (pawel [at] softwaremill . com) 8 | */ 9 | public class ArchiveUtil { 10 | 11 | public static JavaArchive createArchive() { 12 | return ShrinkWrap.create(JavaArchive.class, "test.jar"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/main/java/com/softwaremill/common/test/web/jboss/server/JBossAS.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.jboss.server; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * @author Pawel Wrzeszcz (pawel [at] softwaremill . com) 7 | */ 8 | public interface JBossAS { 9 | 10 | Process start() throws Exception; 11 | 12 | void shutdown() throws IOException, InterruptedException; 13 | 14 | String getDeployDir(); 15 | 16 | String getServerLogPath(); 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-faces/src/main/java/com/softwaremill/common/faces/navigation/Page.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.faces.navigation; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public interface Page { 7 | Page redirect(); 8 | Page includeViewParams(); 9 | Page includeViewParam(String name); 10 | Page includeParam(String name, String value); 11 | 12 | String s(); 13 | String getS(); 14 | 15 | boolean isRequiresLogin(); 16 | String getSecurityEL(); 17 | } -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/Service1B.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class Service1B implements Service1 { 7 | private B serviced; 8 | 9 | @Override 10 | public void setServiced(B serviced) { 11 | this.serviced = serviced; 12 | } 13 | 14 | @Override 15 | public Object get() { 16 | return serviced.getValue(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/Service1C.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class Service1C implements Service1 { 7 | private C serviced; 8 | 9 | @Override 10 | public void setServiced(C serviced) { 11 | this.serviced = serviced; 12 | } 13 | 14 | @Override 15 | public Object get() { 16 | return serviced.getValue(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/Service3B.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class Service3B extends AbstractService3 { 7 | private B serviced; 8 | 9 | @Override 10 | public void setServiced(B serviced) { 11 | this.serviced = serviced; 12 | } 13 | 14 | @Override 15 | public Object get() { 16 | return serviced.getValue(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/Service3C.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class Service3C extends AbstractService3 { 7 | private C serviced; 8 | 9 | @Override 10 | public void setServiced(C serviced) { 11 | this.serviced = serviced; 12 | } 13 | 14 | @Override 15 | public Object get() { 16 | return serviced.getValue(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/sqs/task/SQSTaskTimer.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.sqs.task; 2 | 3 | import javax.ejb.Local; 4 | import javax.ejb.Timer; 5 | 6 | /** 7 | * Local interface for the task timer. 8 | * 9 | * @author Jaroslaw Kijanowski - jarek@softwaremill.pl 10 | * Date: Aug 24, 2010 11 | */ 12 | @Local 13 | public interface SQSTaskTimer { 14 | public void startTimer(int interval); 15 | 16 | public void timeout(Timer timer); 17 | 18 | public void destroyTimer(); 19 | } 20 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/io/FileFilenameFilter.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.io; 2 | 3 | import java.io.File; 4 | import java.io.FilenameFilter; 5 | 6 | /** 7 | * A filename filter which accepts only files. 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | public class FileFilenameFilter implements FilenameFilter { 11 | @Override 12 | public boolean accept(File dir, String name) { 13 | return new RichFile(dir).createChildFile(name).isFile(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/main/java/com/softwaremill/common/dbtest/util/SqlFileResolver.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.dbtest.util; 2 | 3 | /** 4 | * @author Pawel Wrzeszcz (pawel . wrzeszcz [at] gmail . com) 5 | */ 6 | public class SqlFileResolver { 7 | 8 | private Class clazz; 9 | 10 | public SqlFileResolver(Class clazz) { 11 | this.clazz = clazz; 12 | } 13 | 14 | public String getSqlFilePath() { 15 | return clazz.getPackage().getName().replace(".","/") + "/" + clazz.getSimpleName() + ".sql"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/io/DirFilenameFilter.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.io; 2 | 3 | import java.io.File; 4 | import java.io.FilenameFilter; 5 | 6 | /** 7 | * A filename filter which accepts only directories. 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | public class DirFilenameFilter implements FilenameFilter { 11 | @Override 12 | public boolean accept(File dir, String name) { 13 | return new RichFile(dir).createChildFile(name).isDirectory(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/transaction/Transactional.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.transaction; 2 | 3 | import javax.interceptor.InterceptorBinding; 4 | import java.lang.annotation.*; 5 | 6 | /** 7 | * Surrounds a method call with a transaction, if one is not yet running. 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | @Inherited 11 | @InterceptorBinding 12 | @Target({ElementType.TYPE, ElementType.METHOD}) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface Transactional { 15 | } 16 | 17 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/interceptor/BeanToIntercept.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.interceptor; 2 | 3 | /** 4 | * @author Pawel Wrzeszcz (pawel [at] softwaremill . com) 5 | */ 6 | public class BeanToIntercept { 7 | 8 | @NullToEmptyStringParams 9 | public String[] method(String param1, String param2) { 10 | return new String[] {param1, param2}; 11 | } 12 | 13 | @NullToEmptyStringParams 14 | public Object[] method2(Object param1, String param2) { 15 | return new Object[] {param1, param2}; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/NoAccess.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | @Target({ ElementType.TYPE, ElementType.METHOD }) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @SecureBinding 14 | @Secure("#{false}") 15 | public @interface NoAccess { 16 | } 17 | -------------------------------------------------------------------------------- /softwaremill-paypal/src/main/java/com/softwaremill/common/paypal/process/processors/PayPalProcessor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process.processors; 2 | 3 | import com.softwaremill.common.paypal.process.PayPalParameters; 4 | import com.softwaremill.common.paypal.process.status.PayPalStatus; 5 | 6 | public interface PayPalProcessor { 7 | 8 | boolean accept(PayPalStatus status); 9 | 10 | void process(PayPalStatus status, PayPalParameters parameters); 11 | 12 | boolean isError(); 13 | 14 | String getErrorMessage(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/persistence/Writeable.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.persistence; 2 | 3 | import javax.inject.Qualifier; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import static java.lang.annotation.ElementType.*; 8 | import static java.lang.annotation.RetentionPolicy.*; 9 | 10 | /** 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | @Qualifier 14 | @Retention(RUNTIME) 15 | @Target({TYPE, METHOD, FIELD, PARAMETER}) 16 | public @interface Writeable { 17 | } -------------------------------------------------------------------------------- /softwaremill-conf/src/main/java/com/softwaremill/common/conf/Config.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.conf; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Created by Pawel Stawicki on Feb 24, 2011 12:20:43 PM 7 | */ 8 | public interface Config extends Map { 9 | 10 | V get(K key, V defaultValue); 11 | 12 | int getAsInt(K key, int defaultValue); 13 | 14 | double getAsDouble(K key, double defaultValue); 15 | 16 | boolean getAsBoolean(K key, boolean defaultValue); 17 | 18 | long getAsLong(K key, long defaultValue); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/persistence/ReadOnly.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.persistence; 2 | 3 | import javax.inject.Qualifier; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import static java.lang.annotation.ElementType.*; 8 | import static java.lang.annotation.RetentionPolicy.*; 9 | 10 | /** 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | @Qualifier 14 | @Retention(RUNTIME) 15 | @Target({TYPE, METHOD, FIELD, PARAMETER}) 16 | public @interface ReadOnly { 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-util/src/test/java/com/softwaremill/common/util/dependency/TestQualifier.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.dependency; 2 | 3 | import javax.inject.Qualifier; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import static java.lang.annotation.ElementType.*; 8 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 9 | 10 | /** 11 | * Qualifier used for tests 12 | */ 13 | @Qualifier 14 | @Retention(RUNTIME) 15 | @Target({TYPE, METHOD, FIELD, PARAMETER}) 16 | public @interface TestQualifier { 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/AccessIfVar1Set.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | @Target({ ElementType.TYPE, ElementType.METHOD }) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @SecureBinding 14 | @Secure("#{var1 == true}") 15 | public @interface AccessIfVar1Set { 16 | } -------------------------------------------------------------------------------- /softwaremill-util/src/test/java/com/softwaremill/common/util/dependency/AnotherTestQualifier.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.dependency; 2 | 3 | import javax.inject.Qualifier; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import static java.lang.annotation.ElementType.*; 8 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 9 | 10 | /** 11 | * Qualifier used for tests 12 | */ 13 | @Qualifier 14 | @Retention(RUNTIME) 15 | @Target({TYPE, METHOD, FIELD, PARAMETER}) 16 | public @interface AnotherTestQualifier { 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/config/Configuration.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.config; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.TYPE; 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | /** 10 | * Mark simple any class as configuration class 11 | * User: krzysztof.grajek 'at' googlemail.com 12 | * Date: 17/05/2012 13 | */ 14 | @Retention(RUNTIME) 15 | @Target({TYPE}) 16 | public @interface Configuration { 17 | } 18 | 19 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/auto/AutoMyString.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.auto; 2 | 3 | import javax.inject.Inject; 4 | 5 | @OSImpl 6 | public class AutoMyString implements IAuto { 7 | 8 | ExecutionMock execMock; 9 | 10 | @Inject 11 | public AutoMyString(ExecutionMock execMock) { 12 | this.execMock = execMock; 13 | } 14 | 15 | @Override 16 | public void doSomething(String bim, MyString object, Integer bom) { 17 | execMock.myStringExecs += 1; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /softwaremill-debug/src/main/java/com/softwaremill/common/debug/timing/Timed.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.debug.timing; 2 | 3 | import javax.interceptor.InterceptorBinding; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | @InterceptorBinding 13 | @Target({ ElementType.TYPE, ElementType.METHOD }) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface Timed { 16 | } 17 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/qualifier/ExampleStringQualifier.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.qualifier; 2 | 3 | import javax.inject.Qualifier; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Qualifier 12 | public @interface ExampleStringQualifier { 13 | } 14 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/objectservice/auto/AutoOSException.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.auto; 2 | 3 | public class AutoOSException extends RuntimeException { 4 | 5 | public AutoOSException() { 6 | super(); 7 | } 8 | 9 | public AutoOSException(String message) { 10 | super(message); 11 | } 12 | 13 | public AutoOSException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public AutoOSException(Throwable cause) { 18 | super(cause); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/dependency/DependencyProvider.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.dependency; 2 | 3 | import java.lang.annotation.Annotation; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public interface DependencyProvider { 9 | /** 10 | * @param cls Class of the dependency. 11 | * @param qualifiers Qualifiers of the dependency. 12 | * @return Dependency with the given class and qualifiers or {@code null} if no dependency is found. 13 | */ 14 | T inject(Class cls, Annotation... qualifiers); 15 | } 16 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/conf/ConfValue.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.conf; 2 | 3 | import javax.enterprise.util.Nonbinding; 4 | import javax.inject.Qualifier; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import static java.lang.annotation.ElementType.*; 10 | 11 | @Qualifier 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target({METHOD, FIELD, PARAMETER, TYPE}) 14 | public @interface ConfValue { 15 | @Nonbinding String confName(); 16 | @Nonbinding String confKey(); 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/AllowWithFlagsBean.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class AllowWithFlagsBean { 7 | @AllowWithFlag("flag1") 8 | @Secure("#{false}") 9 | public void testSingleFlagOnly() { } 10 | 11 | @AllowWithFlag({ "flag1", "flag2" }) 12 | @Secure("#{false}") 13 | public void testDoubleFlagOnly() { } 14 | 15 | @AllowWithFlag("flag1") 16 | @Secure("#{var1}") 17 | public void testFlagWithSecure(@SecureVar("var1") boolean var1) { } 18 | } 19 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/autofactory/FactoryParameter.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.*; 7 | import static java.lang.annotation.RetentionPolicy.*; 8 | 9 | /** 10 | * Specifies that the annotated constructor parameter should map to a parameter of the factory method. 11 | * 12 | * @author Adam Warski (adam at warski dot org) 13 | */ 14 | @Target({ PARAMETER }) 15 | @Retention(RUNTIME) 16 | public @interface FactoryParameter { 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-swing/src/main/java/com/softwaremill/test/swing/AbstractGUITest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.test.swing; 2 | 3 | import org.assertj.swing.annotation.GUITest; 4 | import org.testng.annotations.Listeners; 5 | 6 | @GUITest 7 | @Listeners({TeamCityScreenShotOnFailureListener.class}) 8 | public class AbstractGUITest { 9 | 10 | private GuiScreenShotTaker screenShot; 11 | 12 | protected AbstractGUITest() { 13 | screenShot = new GuiScreenShotTaker(); 14 | } 15 | 16 | protected void screenShot() { 17 | screenShot.take(getClass().getName()); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/objectservice/auto/OSImpl.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.auto; 2 | 3 | import javax.inject.Qualifier; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import static java.lang.annotation.ElementType.TYPE; 8 | import static java.lang.annotation.ElementType.FIELD; 9 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 10 | 11 | /** 12 | * Used to mark implementation of Object Service. 13 | */ 14 | @Qualifier 15 | @Target({ TYPE, FIELD }) 16 | @Retention(RUNTIME) 17 | public @interface OSImpl { 18 | } 19 | -------------------------------------------------------------------------------- /softwaremill-conf/src/main/java/com/softwaremill/common/conf/SystemPropertiesMapWrapper.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.conf; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Map Wrapper returning System Property if value is null 7 | */ 8 | public class SystemPropertiesMapWrapper extends MapWrapper { 9 | 10 | public SystemPropertiesMapWrapper(Map props) { 11 | super(props); 12 | } 13 | 14 | @Override 15 | public String get(Object key) { 16 | final String fromMap = delegate.get(key); 17 | return fromMap != null ? fromMap : System.getProperty(key.toString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /softwaremill-backup/scripts/backup_conf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Configuration 4 | ############### 5 | 6 | # where the backups will be uploaded 7 | S3_ACCESS_KEY_ID= 8 | S3_SECRET_ACCESS_KEY= 9 | S3_BUCKET= 10 | S3_PREFIX= 11 | 12 | # what to backup - SimpleDB 13 | SIMPLEDB_ACCESS_KEY_ID= 14 | SIMPLEDB_SECRET_ACCESS_KEY= 15 | SIMPLEDB_REGION=EUROPE_WEST 16 | # * for all 17 | SIMPLEDB_DOMAINS= 18 | 19 | # what to backup - MySQL 20 | MYSQL_USER= 21 | MYSQL_PASSWORD= 22 | MYSQL_HOST= 23 | # * for all 24 | MYSQL_DB= 25 | 26 | # path to the backup jar 27 | SDB_BACKUP_PATH=softwaremill-backup-45-SNAPSHOT-jar-with-dependencies.jar 28 | 29 | ######### -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/autofactory/extension/parameter/ParameterValue.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.extension.parameter; 2 | 3 | import javax.enterprise.inject.spi.BeanManager; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public interface ParameterValue { 9 | /** 10 | * Obtains a value of the argument that this class represents. Either uses the bean manager to obtain it, 11 | * or the provided array of arguments, that were passed to the factory method. 12 | */ 13 | Object getValue(BeanManager bm, Object[] factoryParameters); 14 | } 15 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/test/java/com/softwaremill/common/dbtest/Entity.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.dbtest; 2 | 3 | import javax.validation.constraints.NotNull; 4 | 5 | /** 6 | * @author Maciej Bilas 7 | * @since 15/12/11 12:46 8 | */ 9 | public class Entity { 10 | 11 | @NotNull 12 | private String field; 13 | 14 | Entity() { 15 | } 16 | 17 | Entity(String field) { 18 | this.field = field; 19 | } 20 | 21 | public String getField() { 22 | return field; 23 | } 24 | 25 | public void setField(String field) { 26 | this.field = field; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /softwaremill-backup/src/main/java/com/softwaremill/common/backup/SimpleDBRegion.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.backup; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public enum SimpleDBRegion { 7 | EUROPE_WEST("sdb.eu-west-1.amazonaws.com"), 8 | US_EAST("sdb.amazonaws.com"), 9 | US_WEST("sdb.us-west-1.amazonaws.com"), 10 | ASIA_SOUTHEAST("sdb.ap-southeast-1.amazonaws.com"); 11 | 12 | private final String address; 13 | 14 | SimpleDBRegion(String address) { 15 | this.address = address; 16 | } 17 | 18 | public String getAddress() { 19 | return address; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/SecsToMills.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util; 2 | 3 | /** 4 | * Constants to avoid code comments like 5 | * private static long TIMEOUT = 10000l; // 10s 6 | * 7 | * @author Pawel Wrzeszcz (pawel [at] softwaremill . com) 8 | */ 9 | public class SecsToMills { 10 | 11 | public static final long ONE_SECOND = 1000L; 12 | public static final long TWO_SECONDS = 2 * ONE_SECOND; 13 | public static final long TEN_SECONDS = 10 * ONE_SECOND; 14 | 15 | public static final long ONE_MINUTE = 60 * ONE_SECOND; 16 | public static final long TWO_MINUTES = 2 * ONE_MINUTE; 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/producer/ExampleProductQualifier.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.producer; 2 | 3 | import javax.inject.Qualifier; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER }) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Qualifier 15 | public @interface ExampleProductQualifier { 16 | } 17 | -------------------------------------------------------------------------------- /softwaremill-conf/src/main/java/com/softwaremill/common/conf/JBoss7DeployPropertiesProvider.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.conf; 2 | 3 | /** 4 | * JBoss 7 configuration provider 5 | */ 6 | public class JBoss7DeployPropertiesProvider extends FolderPropertiesProvider { 7 | public static final String JBOSS_CONFIG_DIR_PROPERTY = "jboss.server.config.dir"; 8 | 9 | @Override 10 | public String lookupConfigDirectory() { 11 | return "file:///" + System.getProperty(JBOSS_CONFIG_DIR_PROPERTY); 12 | } 13 | 14 | @Override 15 | public boolean providerAvailable() { 16 | return System.getProperty(JBOSS_CONFIG_DIR_PROPERTY) != null; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /softwaremill-faces/src/main/java/com/softwaremill/common/faces/validator/DelegatingValidator.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.faces.validator; 2 | 3 | import javax.faces.component.UIComponent; 4 | import javax.faces.context.FacesContext; 5 | import javax.faces.validator.FacesValidator; 6 | import javax.faces.validator.Validator; 7 | import javax.faces.validator.ValidatorException; 8 | 9 | /** 10 | * Allow dynamically pass validatorId and delegates validation to validator marked by that id 11 | * Check README.md in softwaremill-faces for an example 12 | */ 13 | @FacesValidator("delegatingValidator") 14 | public class DelegatingValidator extends AbstractDelgatingValidator { } 15 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-util/src/main/java/com/softwaremill/common/test/util/Execution.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.util; 2 | 3 | /** 4 | * Used in tests to get exception thrown by the closure provided in the execute method. 5 | * 6 | * @author Pawel Wrzeszcz (pawel . wrzeszcz [at] gmail . com) 7 | */ 8 | public abstract class Execution { 9 | 10 | private Exception e; 11 | 12 | protected abstract void execute() throws Exception; 13 | 14 | public Exception getException() { 15 | if (e == null) { 16 | try { 17 | execute(); 18 | } catch (Exception ex) { 19 | e = ex; 20 | } 21 | } 22 | 23 | return e; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/security/SecurityConditionException.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class SecurityConditionException extends RuntimeException { 7 | public SecurityConditionException() { 8 | } 9 | 10 | public SecurityConditionException(String message) { 11 | super(message); 12 | } 13 | 14 | public SecurityConditionException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public SecurityConditionException(Throwable cause) { 19 | super(cause); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/security/SecureBinding.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * A meta-annotations which should be placed on annotations that specify security constraints using @{@link Secure}, 10 | * or other secure binding annotations. 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | @Target({ ElementType.TYPE, ElementType.METHOD }) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface SecureBinding { 16 | } 17 | 18 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/time/RealTimeClock.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.time; 2 | 3 | import org.joda.time.DateTime; 4 | import org.joda.time.DateTimeZone; 5 | 6 | /** 7 | * Provides time basing on system clock. 8 | */ 9 | public class RealTimeClock implements Clock { 10 | 11 | @Override 12 | public DateTime currentDateTime() { 13 | return DateTime.now(); 14 | } 15 | 16 | @Override 17 | public DateTime currentDateTimeUTC() { 18 | return DateTime.now(DateTimeZone.UTC); 19 | } 20 | 21 | @Override 22 | public long currentTimeMillis() { 23 | return System.currentTimeMillis(); 24 | } 25 | } -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/autofactory/extension/parameter/FactoryParameterParameterValue.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.extension.parameter; 2 | 3 | import javax.enterprise.inject.spi.BeanManager; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public class FactoryParameterParameterValue implements ParameterValue { 9 | private final int idx; 10 | 11 | public FactoryParameterParameterValue(int idx) { 12 | this.idx = idx; 13 | } 14 | 15 | 16 | @Override 17 | public Object getValue(BeanManager bm, Object[] factoryParameters) { 18 | return factoryParameters[idx]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/main/java/com/softwaremill/common/dbtest/util/DbMode.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.dbtest.util; 2 | 3 | /** 4 | * Created by Pawel Stawicki on Mar 31, 2011 9:38:46 PM 5 | */ 6 | public enum DbMode { 7 | 8 | DB2("DB2"), Derby("Derby"), HSQLDB("HSQLDB"), MSSQL("MSSQLServer"), 9 | MySQL("MySQL"), Oracle("Oracle"), PostgreSQL("PostgreSQL"); 10 | 11 | private DbMode(String compatibilityParamValue) { 12 | this.compatibilityParamValue = compatibilityParamValue; 13 | } 14 | 15 | private String compatibilityParamValue; 16 | 17 | public String getParameterValue() { 18 | return compatibilityParamValue; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/el/ELEvaluatorUtil.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.el; 2 | 3 | import javax.el.ELContext; 4 | import javax.el.ExpressionFactory; 5 | 6 | /** 7 | * @author Adam Warski (adam at warski dot org) 8 | */ 9 | public class ELEvaluatorUtil { 10 | @SuppressWarnings({"unchecked"}) 11 | public static T evaluate(ELContext elContext, ExpressionFactory expressionFactory, String expression, 12 | Class expectedResultType) { 13 | return (T) expressionFactory 14 | .createValueExpression(elContext, expression, expectedResultType) 15 | .getValue(elContext); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/persistence/QueryCreator.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.persistence; 2 | 3 | import javax.persistence.EntityManager; 4 | import javax.persistence.Query; 5 | 6 | /** 7 | * Creates a query. Can be used to properly execute bulk update queries using 8 | * {@link com.softwaremill.common.cdi.persistence.EntityWriter#executeUpdate(QueryCreator)}. 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | public interface QueryCreator { 12 | /** 13 | * Given an entity manager, creates a query to execute. 14 | * @param em Entity manager 15 | * @return Query to execute. 16 | */ 17 | Query createQuery(EntityManager em); 18 | } 19 | -------------------------------------------------------------------------------- /softwaremill-paypal/src/main/java/com/softwaremill/common/paypal/process/processors/InvalidPayPalProcessor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process.processors; 2 | 3 | import com.softwaremill.common.paypal.process.PayPalParameters; 4 | import com.softwaremill.common.paypal.process.status.PayPalStatus; 5 | 6 | public class InvalidPayPalProcessor extends AbstractPayPalProcessor { 7 | 8 | @Override 9 | public boolean accept(PayPalStatus status) { 10 | return status.isInvalid(); 11 | } 12 | 13 | @Override 14 | public void process(PayPalStatus status, PayPalParameters parameters) { 15 | setErrorHappened(); 16 | appendError("Paypal replied INVALID for a request.\n\n"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/transaction/TransactionTimeout.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.transaction; 2 | 3 | import javax.enterprise.util.Nonbinding; 4 | import javax.interceptor.InterceptorBinding; 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * Changes current trancation timeout 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | @Inherited 12 | @InterceptorBinding 13 | @Target({ElementType.TYPE, ElementType.METHOD}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface TransactionTimeout { 16 | /** 17 | * New value of the transaction timeout in seconds 18 | * 19 | * @return Transaction timeout 20 | */ 21 | @Nonbinding int timeout(); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-swing/src/main/java/com/softwaremill/test/swing/TeamCityScreenShotOnFailureListener.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.test.swing; 2 | 3 | import org.assertj.swing.testng.listener.AbstractTestListener; 4 | import org.testng.ITestNGListener; 5 | import org.testng.ITestResult; 6 | 7 | class TeamCityScreenShotOnFailureListener extends AbstractTestListener implements ITestNGListener { 8 | 9 | private GuiScreenShotTaker screenshot; 10 | 11 | TeamCityScreenShotOnFailureListener() { 12 | screenshot = new GuiScreenShotTaker(); 13 | } 14 | 15 | @Override 16 | public void onTestFailure(ITestResult result) { 17 | screenshot.take(result.getTestClass().getName()); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-util/src/main/java/com/softwaremill/common/test/util/ExtMockito.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.util; 2 | 3 | import org.mockito.cglib.proxy.Factory; 4 | 5 | import static com.google.common.base.Preconditions.checkNotNull; 6 | 7 | /** 8 | * Extensions to Mockito mocking framework. 9 | * 10 | * @author Maciej Bilas 11 | * @since 15/12/11 13:05 12 | */ 13 | public class ExtMockito { 14 | 15 | /** 16 | * Checks if the given object is a mock. 17 | * 18 | * @param o 19 | * @return 20 | * @throws NullPointerException if {@code o} is {@code null} 21 | */ 22 | public static boolean isAMock(Object o) { 23 | return checkNotNull(o) instanceof Factory; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-arquillian/src/main/java/com/softwaremill/common/arquillian/ManifestUtil.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.arquillian; 2 | 3 | import com.google.common.base.Charsets; 4 | import org.jboss.shrinkwrap.api.Archive; 5 | import org.jboss.shrinkwrap.api.ArchivePaths; 6 | import org.jboss.shrinkwrap.api.asset.ByteArrayAsset; 7 | import org.jboss.shrinkwrap.api.container.ManifestContainer; 8 | 9 | public class ManifestUtil { 10 | public static & ManifestContainer> T addEmptyBeansXml(T archive) { 11 | return archive.addAsManifestResource( 12 | new ByteArrayAsset("".getBytes(Charsets.UTF_8)), 13 | ArchivePaths.create("META-INF/beans.xml")); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-util/src/main/java/com/softwaremill/common/test/util/reorder/LastTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.util.reorder; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.METHOD; 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | /** 10 | * Marker to place test method as a last to run in its class. 11 | * 12 | * Beware that not all methods can be reordered, only those which don't have any methods depended upon 13 | * (for more see javadoc for org.testng.IMethodInterceptor) 14 | * 15 | * @author Tomasz Dziurko 16 | */ 17 | @Target(METHOD) 18 | @Retention(RUNTIME) 19 | public @interface LastTest { 20 | } 21 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/io/InputStreamInputSupplier.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.io; 2 | 3 | import com.google.common.io.InputSupplier; 4 | 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | 8 | /** 9 | * An input supplier which holds a reference to an input stream. 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | public class InputStreamInputSupplier implements InputSupplier { 13 | private final InputStream stream; 14 | 15 | public InputStreamInputSupplier(InputStream stream) { 16 | this.stream = stream; 17 | } 18 | 19 | @Override 20 | public InputStream getInput() throws IOException { 21 | return stream; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/security/AllowWithFlag.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.*; 7 | import static java.lang.annotation.RetentionPolicy.*; 8 | 9 | /** 10 | * Allows access when any of the given security flags are set. 11 | * Has higher priority than restrictions specified with @{@link Secure}, that is when access is granted basing 12 | * on security flags, other restrictions are not checked. 13 | * @author Adam Warski (adam at warski dot org) 14 | */ 15 | @Retention(RUNTIME) 16 | @Target({TYPE, METHOD}) 17 | public @interface AllowWithFlag { 18 | String[] value(); 19 | } 20 | -------------------------------------------------------------------------------- /softwaremill-paypal/src/test/java/com/softwaremill/common/paypal/process/TestErrorHandler.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process; 2 | 3 | import java.util.logging.Logger; 4 | 5 | /** 6 | * @Author: lukasz.zuchowski at gmail dot com 7 | * Date: 05.04.12 8 | * Time: 12:38 9 | */ 10 | public class TestErrorHandler extends PayPalErrorHandler { 11 | 12 | private Logger logger = Logger.getLogger(TestErrorHandler.class.getName()); 13 | 14 | @Override 15 | public PayPalErrorHandler.ErrorMessage prepareErrorMessage() { 16 | return new ErrorMessage(); 17 | } 18 | 19 | @Override 20 | public void processErrorMessage(PayPalErrorHandler.ErrorMessage errorMessage) { 21 | logger.info(errorMessage.toString()); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/sqs/exception/SQSRuntimeException.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.sqs.exception; 2 | 3 | /** 4 | * Runtime Exception wrapping SQS exceptions 5 | * 6 | * @author Jaroslaw Kijanowski - jarek@softwaremill.pl 7 | * Date: Aug 17, 2010 8 | */ 9 | public class SQSRuntimeException extends RuntimeException{ 10 | 11 | public SQSRuntimeException() { 12 | super(); 13 | } 14 | 15 | public SQSRuntimeException(String message) { 16 | super(message); 17 | } 18 | 19 | public SQSRuntimeException(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | 23 | public SQSRuntimeException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/interceptor/NullToEmptyStringParams.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.interceptor; 2 | 3 | import javax.interceptor.InterceptorBinding; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.Target; 6 | 7 | import static java.lang.annotation.ElementType.*; 8 | import static java.lang.annotation.RetentionPolicy.*; 9 | 10 | /** 11 | * Method annotated with @NullToEmptyStringParams will never receive null values for String parameters. 12 | * Parameter values will be converted to empty Strings instead. 13 | * 14 | * @author Pawel Wrzeszcz (pawel [at] softwaremill . com) 15 | */ 16 | @InterceptorBinding 17 | @Target({METHOD, TYPE}) 18 | @Retention(RUNTIME) 19 | public @interface NullToEmptyStringParams {} 20 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/templates/TemplateContentData.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.templates; 2 | 3 | /** 4 | * Object with String data: subject and content 5 | * 6 | * @author maciek 7 | */ 8 | public class TemplateContentData { 9 | 10 | private String subject; 11 | private String content; 12 | 13 | public TemplateContentData() { 14 | 15 | } 16 | 17 | public String getSubject() { 18 | return subject; 19 | } 20 | 21 | public void setSubject(String subject) { 22 | this.subject = subject; 23 | } 24 | 25 | public String getContent() { 26 | return content; 27 | } 28 | 29 | public void setContent(String content) { 30 | this.content = content; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /softwaremill-paypal/src/main/java/com/softwaremill/common/paypal/process/processors/UnknownPayPalProcessor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process.processors; 2 | 3 | import com.softwaremill.common.paypal.process.PayPalParameters; 4 | import com.softwaremill.common.paypal.process.status.PayPalStatus; 5 | 6 | public class UnknownPayPalProcessor extends AbstractPayPalProcessor { 7 | 8 | @Override 9 | public boolean accept(PayPalStatus status) { 10 | return status.isUnknown(); 11 | } 12 | 13 | @Override 14 | public void process(PayPalStatus status, PayPalParameters parameters) { 15 | setErrorHappened().appendError("Paypal replied some unknown response: ") 16 | .appendError(status.toString()).appendError(" for a request.\n\n"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/main/java/com/softwaremill/common/dbtest/UtxDependencyProvider.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.dbtest; 2 | 3 | import bitronix.tm.TransactionManagerServices; 4 | import com.softwaremill.common.util.dependency.DependencyProvider; 5 | 6 | import javax.transaction.UserTransaction; 7 | import java.lang.annotation.Annotation; 8 | 9 | /** 10 | * Provides wrapping class to inject UserTransaction 11 | */ 12 | public class UtxDependencyProvider implements DependencyProvider { 13 | 14 | @Override 15 | public T inject(Class cls, Annotation... qualifiers) { 16 | if (cls.isAssignableFrom(UserTransaction.class)) { 17 | return (T) TransactionManagerServices.getTransactionManager(); 18 | } 19 | return null; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-util/src/main/java/com/softwaremill/common/test/util/reorder/TestOrder.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.util.reorder; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.METHOD; 7 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 8 | 9 | /** 10 | * Marker to define order in which test methods in class should be run 11 | * 12 | * Beware that not all methods can be reordered, only those which don't have any methods depended upon 13 | * (for more see javadoc for org.testng.IMethodInterceptor) 14 | * 15 | * @author Tomasz Dziurko 16 | */ 17 | @Target(METHOD) 18 | @Retention(RUNTIME) 19 | public @interface TestOrder { 20 | 21 | int order() default 0; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /softwaremill-faces/src/main/java/com/softwaremill/common/faces/messages/FacesMessagesListener.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.faces.messages; 2 | 3 | import com.softwaremill.common.cdi.util.BeanInject; 4 | 5 | import javax.faces.event.AbortProcessingException; 6 | import javax.faces.event.SystemEvent; 7 | import javax.faces.event.SystemEventListener; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | public class FacesMessagesListener implements SystemEventListener { 13 | @Override 14 | public void processEvent(SystemEvent event) throws AbortProcessingException { 15 | BeanInject.lookup(FacesMessages.class).beforeRenderResponse(); 16 | } 17 | 18 | @Override 19 | public boolean isListenerForSource(Object source) { 20 | return true; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /softwaremill-conf/src/main/java/com/softwaremill/common/conf/encoding/ConfigurationValueCoder.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.conf.encoding; 2 | 3 | /** 4 | * Encodes and decodes configuration values. 5 | * @author Adam Warski (adam at warski dot org) 6 | */ 7 | public class ConfigurationValueCoder { 8 | private final static String ENCODED_VALUE_PREFIX = "encoded."; 9 | 10 | private TextCoder coder = new TextCoder(); 11 | 12 | public String encode(String value) { 13 | return ENCODED_VALUE_PREFIX + coder.encode(value); 14 | } 15 | 16 | public String decode(String value) { 17 | return coder.decode(value.substring(ENCODED_VALUE_PREFIX.length())); 18 | } 19 | 20 | public boolean isEncoded(String value) { 21 | return value.startsWith(ENCODED_VALUE_PREFIX); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/test/java/com/softwaremill/common/dbtest/TestEntity1Reader.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.dbtest; 2 | 3 | import com.softwaremill.common.cdi.persistence.ReadOnly; 4 | 5 | import javax.enterprise.context.RequestScoped; 6 | import javax.inject.Inject; 7 | import javax.persistence.EntityManager; 8 | import java.util.List; 9 | 10 | /** 11 | * A helper bean for reading test entities. 12 | * @author Adam Warski (adam at warski dot org) 13 | */ 14 | @RequestScoped 15 | public class TestEntity1Reader { 16 | @Inject 17 | @ReadOnly 18 | private EntityManager em; 19 | 20 | @SuppressWarnings({"unchecked"}) 21 | public List getCurrentData() { 22 | return em.createQuery("select t from TestEntity1 t order by t.id").getResultList(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /softwaremill-debug/src/main/java/com/softwaremill/common/debug/timing/TimingOutputFilter.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.debug.timing; 2 | 3 | import javax.servlet.*; 4 | import java.io.IOException; 5 | 6 | /** 7 | * @author Adam Warski (adam at warski dot org) 8 | */ 9 | public class TimingOutputFilter implements Filter { 10 | @Override 11 | public void init(FilterConfig filterConfig) throws ServletException { } 12 | 13 | @Override 14 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 15 | throws IOException, ServletException { 16 | try { 17 | chain.doFilter(request, response); 18 | } finally { 19 | TimingResults.instance.dumpCurrent(); 20 | } 21 | } 22 | 23 | @Override 24 | public void destroy() { } 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/sqs/email/SendEmailTaskExecutor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.sqs.email; 2 | 3 | import com.softwaremill.common.task.TaskExecutor; 4 | 5 | import javax.mail.MessagingException; 6 | 7 | import static com.softwaremill.common.sqs.SQSConfiguration.*; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | public class SendEmailTaskExecutor implements TaskExecutor { 13 | @Override 14 | public void execute(SendEmailTask task) { 15 | try { 16 | EmailSender.send(EMAIL_SMTP_HOST, EMAIL_SMTP_PORT, EMAIL_SMTP_USERNAME, EMAIL_SMTP_PASSWORD, 17 | EMAIL_FROM, ENCODING, task.getEmail()); 18 | } catch (MessagingException e) { 19 | throw new RuntimeException(e); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/main/java/com/softwaremill/common/test/web/email/EmailHeader.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.email; 2 | 3 | /** 4 | * Most common headers available in email 5 | * 6 | * @author maciek 7 | */ 8 | public enum EmailHeader { 9 | 10 | MIME_VERSION("MIME-Version"), 11 | 12 | MESSAGE_ID("Message-ID"), 13 | 14 | SUBJECT("Subject"), 15 | 16 | DATE("Date"), 17 | 18 | CONTENT_TRANSFER_ENCODING("Content-Transfer-Encoding"), 19 | 20 | TO("To"), 21 | 22 | CONTENT_TYPE("Content-Type"), 23 | 24 | FROM("From"), 25 | 26 | REPLY_TO("Reply-To"); 27 | 28 | private String value; 29 | 30 | EmailHeader(String headerName){ 31 | this.value = headerName; 32 | } 33 | 34 | public String getValue() { 35 | return value; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/logger/LoggerProducer.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.logger; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import javax.enterprise.inject.Produces; 7 | import javax.enterprise.inject.spi.Bean; 8 | import javax.enterprise.inject.spi.InjectionPoint; 9 | 10 | /** 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | public class LoggerProducer { 14 | 15 | @Produces 16 | public Logger produceLog(InjectionPoint injectionPoint) { 17 | Bean bean = injectionPoint.getBean(); 18 | if (bean == null) { 19 | return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass()); 20 | } else { 21 | return LoggerFactory.getLogger(bean.getBeanClass()); 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/sqs/util/AttachmentDescription.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.sqs.util; 2 | 3 | /** 4 | * @author Adam Warski (adam at warski dot org) 5 | */ 6 | public class AttachmentDescription { 7 | private final byte[] content; 8 | private final String filename; 9 | private final String contentType; 10 | 11 | public AttachmentDescription(byte[] content, String filename, String contentType) { 12 | this.content = content; 13 | this.filename = filename; 14 | this.contentType = contentType; 15 | } 16 | 17 | public byte[] getContent() { 18 | return content; 19 | } 20 | 21 | public String getFilename() { 22 | return filename; 23 | } 24 | 25 | public String getContentType() { 26 | return contentType; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/time/FixtureTimeClock.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.time; 2 | 3 | import org.joda.time.DateTime; 4 | import org.joda.time.DateTimeZone; 5 | 6 | /** 7 | * Class responsible for providing arbitrary fixed current time value. 8 | */ 9 | public class FixtureTimeClock implements Clock { 10 | 11 | private long millis; 12 | 13 | public FixtureTimeClock(long millis) { 14 | this.millis = millis; 15 | } 16 | 17 | @Override 18 | public DateTime currentDateTime() { 19 | return new DateTime(millis); 20 | } 21 | 22 | @Override 23 | public DateTime currentDateTimeUTC() { 24 | return new DateTime(millis, DateTimeZone.UTC); 25 | } 26 | 27 | @Override 28 | public long currentTimeMillis() { 29 | return millis; 30 | } 31 | } -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/el/ELEvaluatorProducer.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.el; 2 | 3 | import javax.enterprise.context.RequestScoped; 4 | import javax.enterprise.inject.Produces; 5 | import javax.enterprise.inject.spi.BeanManager; 6 | import javax.faces.context.FacesContext; 7 | import javax.inject.Inject; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | public class ELEvaluatorProducer { 13 | @Inject 14 | private BeanManager beanManager; 15 | 16 | @Produces @RequestScoped 17 | public ELEvaluator getEvaluator() { 18 | if (FacesContext.getCurrentInstance() != null) { 19 | return new FacesContextELEvaluator(FacesContext.getCurrentInstance()); 20 | } else { 21 | return new TemporaryContextELEvaluator(beanManager); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /softwaremill-paypal/src/main/java/com/softwaremill/common/paypal/process/processors/AbstractPayPalProcessor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process.processors; 2 | 3 | public abstract class AbstractPayPalProcessor implements PayPalProcessor { 4 | 5 | private StringBuilder errorMessage = new StringBuilder(); 6 | private boolean error = false; 7 | 8 | @Override 9 | public boolean isError() { 10 | return error; 11 | } 12 | 13 | @Override 14 | public String getErrorMessage() { 15 | return errorMessage.toString(); 16 | } 17 | 18 | protected AbstractPayPalProcessor appendError(String message) { 19 | errorMessage.append(message); 20 | return this; 21 | } 22 | 23 | protected AbstractPayPalProcessor setErrorHappened() { 24 | error = true; 25 | return this; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/objectservice/OSP.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * An object service provider. 7 | * @author Adam Warski (adam at warski dot org) 8 | */ 9 | public interface OSP> extends Serializable { 10 | /** 11 | * Finds the appropriate object service for the given object, that is, finds a bean implementing the service 12 | * interface (as specified in the type parameter {@link S}), for which the type parameter corresponds to the 13 | * class of the bean passed. 14 | * 15 | * A new instance of an object service is created on each invocation. 16 | * 17 | * @param o The object for which to get the object service. 18 | * @return An object service for the given object. 19 | */ 20 | S f(O o); 21 | } 22 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/sqs/util/SQSAnswer.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.sqs.util; 2 | 3 | /** 4 | * Wrapper class for message received from a SQS queue and converted to an object 5 | * and the SQS Message handle for further reference (to delete or modify (timeout) a message) 6 | * 7 | * @author Jaroslaw Kijanowski - jarek@softwaremill.pl 8 | * Date: Aug 16, 2010 9 | */ 10 | public class SQSAnswer { 11 | 12 | private final Object message; 13 | private final String receiptHandle; 14 | 15 | public SQSAnswer(Object message, String receiptHandle) { 16 | this.message = message; 17 | this.receiptHandle = receiptHandle; 18 | } 19 | 20 | public Object getMessage() { 21 | return message; 22 | } 23 | 24 | public String getReceiptHandle() { 25 | return receiptHandle; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/stringsorting/ByteByByteStringComparator.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.stringsorting; 2 | 3 | import com.google.common.primitives.UnsignedBytes; 4 | 5 | import java.io.Serializable; 6 | import java.nio.charset.Charset; 7 | import java.util.Comparator; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | public class ByteByByteStringComparator implements Comparator, Serializable { 13 | @Override 14 | public int compare(String o1, String o2) { 15 | if (o1 == null) { 16 | return o2 == null ? 0 : -1; 17 | } 18 | 19 | if (o2 == null) { 20 | return 1; 21 | } 22 | 23 | return UnsignedBytes.lexicographicalComparator().compare(o1.getBytes(Charset.defaultCharset()), o2.getBytes(Charset.defaultCharset())); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/persistence/EntityManagerUtil.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.persistence; 2 | 3 | import org.hibernate.FlushMode; 4 | import org.hibernate.Session; 5 | 6 | import javax.persistence.EntityManager; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | public class EntityManagerUtil { 12 | /** 13 | * Changes the given entity manager to be read only. No changes will be flushed automatically. Also all entities 14 | * will be marked as read only by Hibernate. 15 | * @param em The entity manager to make read only. 16 | */ 17 | public static void makeEntityManagerReadOnly(EntityManager em) { 18 | Session readOnlySession = (Session) em.getDelegate(); 19 | readOnlySession.setDefaultReadOnly(true); 20 | readOnlySession.setFlushMode(FlushMode.MANUAL); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/sysprops/SystemProperty.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.sysprops; 2 | 3 | import javax.enterprise.util.Nonbinding; 4 | import javax.inject.Qualifier; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import static java.lang.annotation.ElementType.*; 10 | 11 | /** 12 | * @author Maciej Bilas 13 | * @since 14/9/12 16:33 14 | */ 15 | @Qualifier 16 | @Retention(RetentionPolicy.RUNTIME) 17 | @Target({METHOD, FIELD, PARAMETER, TYPE}) 18 | public @interface SystemProperty { 19 | public static final String NOT_SET = "[no default set]"; 20 | 21 | @Nonbinding public String value() default NOT_SET; 22 | 23 | @Nonbinding public String key() default NOT_SET; 24 | 25 | @Nonbinding public String defaultValue() default NOT_SET; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /softwaremill-conf/src/main/java/com/softwaremill/common/conf/encoding/MasterPasswordStore.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.conf.encoding; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public class MasterPasswordStore { 9 | private static String masterPassword; 10 | 11 | public static String getMasterPassword() { 12 | if (masterPassword == null) { 13 | throw new IllegalStateException("Master password not set!"); 14 | } 15 | 16 | return masterPassword; 17 | } 18 | 19 | public static void setMasterPassword(String masterPassword) { 20 | MasterPasswordStore.masterPassword = masterPassword; 21 | } 22 | 23 | public static void readFromConsole() throws IOException { 24 | masterPassword = new String(System.console().readPassword("Master password: ")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/validation/NoSpecialCharsValidator.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.validation; 2 | 3 | import javax.validation.ConstraintValidator; 4 | import javax.validation.ConstraintValidatorContext; 5 | import java.util.regex.Pattern; 6 | 7 | /** 8 | * Created by amorfis on Dec 3, 2010 1:34:27 PM 9 | */ 10 | public class NoSpecialCharsValidator implements ConstraintValidator { 11 | 12 | Pattern regex; 13 | 14 | public void initialize(NoSpecialChars constraint) { 15 | String charsAllowed = constraint.charsAllowed(); 16 | regex = Pattern.compile("^[A-Za-z0-9" + charsAllowed + "]*$"); 17 | } 18 | 19 | public boolean isValid(String value, ConstraintValidatorContext context) { 20 | if (value == null) return true; 21 | 22 | return regex.matcher(value).matches(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /softwaremill-conf/src/main/java/com/softwaremill/common/conf/ClasspathPropertiesProvider.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.conf; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | import com.google.common.io.Resources; 5 | 6 | import java.net.URL; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | public class ClasspathPropertiesProvider implements PropertiesProvider { 12 | @Override 13 | public ImmutableMap lookupProperties(String name) { 14 | try { 15 | URL resource = Resources.getResource(name + ".conf"); 16 | return Configuration.loadFromURL(resource); 17 | } catch (IllegalArgumentException e) { 18 | // Resource not found. 19 | return null; 20 | } 21 | } 22 | 23 | @Override 24 | public boolean providerAvailable() { 25 | return true; 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/sqs/ReceivedMessage.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.sqs; 2 | 3 | /** 4 | * @author Maciej Bilas 5 | * @since 11/10/12 12:43 6 | */ 7 | public class ReceivedMessage { 8 | 9 | private final Object message; 10 | private final ReceiptHandle receiptHandle; 11 | private final MessageId messageId; 12 | 13 | public ReceivedMessage(Object message, ReceiptHandle receiptHandle, 14 | MessageId messageId) { 15 | this.message = message; 16 | this.receiptHandle = receiptHandle; 17 | this.messageId = messageId; 18 | } 19 | 20 | public Object getMessage() { 21 | return message; 22 | } 23 | 24 | public ReceiptHandle getReceiptHandle() { 25 | return receiptHandle; 26 | } 27 | 28 | public MessageId getMessageId() { 29 | return messageId; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/test/java/com/softwaremill/common/dbtest/TestEntity1Manager.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.dbtest; 2 | 3 | import com.softwaremill.common.cdi.persistence.EntityWriter; 4 | import com.softwaremill.common.cdi.transaction.Transactional; 5 | 6 | import javax.inject.Inject; 7 | import java.util.List; 8 | 9 | /** 10 | * A manager for the test entity: enables reads (via an injected bean) and writes via entity writer. 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | @Transactional 14 | public class TestEntity1Manager { 15 | @Inject 16 | private TestEntity1Reader reader; 17 | 18 | @Inject 19 | private EntityWriter writer; 20 | 21 | public List getCurrentData() { 22 | return reader.getCurrentData(); 23 | } 24 | 25 | public void addEntity(TestEntity1 te) { 26 | writer.write(te); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-swing/src/test/java/com/softwaremill/test/swing/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.test.swing; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/security/Secure.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.*; 7 | import static java.lang.annotation.RetentionPolicy.*; 8 | 9 | /** 10 | * Checks a condition before executing a method (pre-condition). 11 | * TODO: add an internationalized message 12 | * @author Adam Warski (adam at warski dot org) 13 | */ 14 | @Retention(RUNTIME) 15 | @Target({TYPE, METHOD}) 16 | public @interface Secure { 17 | /** 18 | * @return The EL expression that should be evaluated. If it evaluates to {@code true}, access will be granted. 19 | * The EL expression may reference any objects that are in any context, as well as any parameters named with 20 | * @{@link SecureVar}. 21 | */ 22 | String value(); 23 | } 24 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/mixed/PriceCalculatorMixedConstructorImpl.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.mixed; 2 | 3 | import com.softwaremill.common.cdi.autofactory.*; 4 | 5 | import javax.inject.Inject; 6 | 7 | /** 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | @CreatedWith(PriceCalculator.Factory.class) 11 | public class PriceCalculatorMixedConstructorImpl implements PriceCalculator { 12 | private final Product product; 13 | private final Discounts discounts; 14 | 15 | @Inject 16 | public PriceCalculatorMixedConstructorImpl(@FactoryParameter Product product, Discounts discounts) { 17 | this.product = product; 18 | this.discounts = discounts; 19 | } 20 | 21 | @Override 22 | public int getFinalPrice() { 23 | return product.getBasePrice() - discounts.getNormalDiscount(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/persistence/MockEntityManagerProducers.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.persistence; 2 | 3 | import javax.enterprise.context.RequestScoped; 4 | import javax.enterprise.inject.Produces; 5 | import java.io.Serializable; 6 | 7 | /** 8 | * The produced entity managers simple delegate to an underlying entity manager, which must be explicitly 9 | * set before using. 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | public class MockEntityManagerProducers implements Serializable { 13 | @Produces @RequestScoped @ReadOnly 14 | public EntityManagerDelegator getReadOnlyEntityManager() { 15 | return new EntityManagerDelegator(null); 16 | } 17 | 18 | @Produces @RequestScoped @Writeable 19 | public EntityManagerDelegator getWriteableEntityManager() { 20 | return new EntityManagerDelegator(null); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/conf/ConfValueProducer.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.conf; 2 | 3 | import com.softwaremill.common.conf.Configuration; 4 | 5 | import javax.enterprise.inject.Produces; 6 | import javax.enterprise.inject.spi.InjectionPoint; 7 | import java.util.Map; 8 | 9 | public class ConfValueProducer { 10 | @Produces 11 | @ConfValue(confName = "", confKey = "") 12 | public String getConfigurationValue(InjectionPoint ip) { 13 | ConfValue confValue = ip.getAnnotated().getAnnotation(ConfValue.class); 14 | return Configuration.get(confValue.confName()).get(confValue.confKey()); 15 | } 16 | 17 | public static String from(InjectionPoint ip, Map configuration) { 18 | ConfValue confValue = ip.getAnnotated().getAnnotation(ConfValue.class); 19 | return configuration.get(confValue.confKey()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/security/SecureVar.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | @Target({ ElementType.PARAMETER }) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface SecureVar { 14 | /** 15 | * @return Name of the variable, which will be available when checking security constraints. 16 | */ 17 | String value(); 18 | 19 | /** 20 | * @return An optional EL expression which will be evaluated to get the value of the variable. The name 21 | * of the paramter during the evaluation is p, so the expression can be e.g.: #{p.attribute}. 22 | */ 23 | String exp() default ""; 24 | } 25 | -------------------------------------------------------------------------------- /softwaremill-paypal/src/test/java/com/softwaremill/common/paypal/process/processors/MockVerifiedPayPalProcessor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process.processors; 2 | 3 | import com.softwaremill.common.paypal.process.PayPalParameters; 4 | import com.softwaremill.common.paypal.process.status.PayPalStatus; 5 | import com.softwaremill.common.paypal.service.PayPalVerificationServiceTest; 6 | 7 | import java.util.logging.Logger; 8 | 9 | /** 10 | * @Author: lukasz.zuchowski at gmail dot com 11 | * Date: 05.04.12 12 | * Time: 15:36 13 | */ 14 | public class MockVerifiedPayPalProcessor extends VerifiedPayPalProcessor { 15 | 16 | private Logger logger = Logger.getLogger(MockVerifiedPayPalProcessor.class.getName()); 17 | 18 | @Override 19 | public void process(PayPalStatus status, PayPalParameters parameters) { 20 | logger.info("process with:" + status + "\n and PayPalParameters"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/resources/hibernate.test.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | create-drop 9 | 10 | false 11 | true 12 | 13 | org.hibernate.dialect.H2Dialect 14 | jdbc:h2:mem:cdiext 15 | org.h2.Driver 16 | sa 17 | 18 | 19 | -------------------------------------------------------------------------------- /softwaremill-paypal/src/main/java/com/softwaremill/common/paypal/process/status/PayPalStatus.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process.status; 2 | 3 | public class PayPalStatus { 4 | 5 | private String status; 6 | 7 | PayPalStatus(String status) { 8 | this.status = status; 9 | } 10 | 11 | public boolean isVerified() { 12 | return "VERIFIED".equals(status); 13 | } 14 | 15 | public boolean isValidCurrency(String paymentCurrency) { 16 | return "AUD".equals(paymentCurrency); 17 | } 18 | 19 | public boolean isInvalid() { 20 | return "INVALID".equals(status); 21 | } 22 | 23 | public boolean isUnknown() { 24 | return !isVerified() && !isInvalid(); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return "PayPalStatus{" + 30 | "status='" + status + '\'' + 31 | '}'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/objectservice/extension/PureWildcardType.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.extension; 2 | 3 | import java.lang.reflect.Type; 4 | import java.lang.reflect.WildcardType; 5 | 6 | /** 7 | * A {@code ?} wildcard. 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | public class PureWildcardType implements WildcardType { 11 | private static final Type[] EMPTY_TYPE_ARRAY = new Type[0]; 12 | 13 | public static final PureWildcardType INSTANCE = new PureWildcardType(); 14 | 15 | private PureWildcardType() { 16 | } 17 | 18 | @Override 19 | public Type[] getUpperBounds() { 20 | return EMPTY_TYPE_ARRAY; 21 | } 22 | 23 | @Override 24 | public Type[] getLowerBounds() { 25 | return EMPTY_TYPE_ARRAY; 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return "?"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/logger/InjectDataAndLoggerField.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.logger; 2 | 3 | import org.slf4j.Logger; 4 | import com.softwaremill.common.cdi.autofactory.CreatedWith; 5 | 6 | import javax.inject.Inject; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | @CreatedWith(InjectDataAndLoggerField.Factory.class) 12 | public class InjectDataAndLoggerField { 13 | private final String data; 14 | 15 | @Inject 16 | private Logger logger; 17 | 18 | public InjectDataAndLoggerField(String data) { 19 | this.data = data; 20 | } 21 | 22 | public String getData() { 23 | return data; 24 | } 25 | 26 | public Logger getLogger() { 27 | return logger; 28 | } 29 | 30 | public static interface Factory { 31 | InjectDataAndLoggerField create(String data); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/security/InterceptSecure.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import javax.enterprise.util.Nonbinding; 4 | import javax.interceptor.InterceptorBinding; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * The annotation the is generated by the {@link com.softwaremill.common.cdi.security.SecurityExtension}, which contains 12 | * all security constraints to be checked. 13 | * @author Adam Warski (adam at warski dot org) 14 | */ 15 | @InterceptorBinding 16 | @Target({ ElementType.TYPE, ElementType.METHOD }) 17 | @Retention(RetentionPolicy.RUNTIME) 18 | public @interface InterceptSecure { 19 | @Nonbinding 20 | Secure[] value(); 21 | 22 | @Nonbinding 23 | AllowWithFlag[] flags() default {}; 24 | } 25 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/producer/ExamplePriceCalculatorProducer.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.producer; 2 | 3 | import com.softwaremill.common.cdi.autofactory.PriceCalculator; 4 | import com.softwaremill.common.cdi.autofactory.Product; 5 | 6 | import javax.enterprise.inject.Produces; 7 | import javax.inject.Inject; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | public class ExamplePriceCalculatorProducer { 13 | private final PriceCalculator.Factory priceCalculatorFactory; 14 | 15 | @Inject 16 | public ExamplePriceCalculatorProducer(PriceCalculator.Factory priceCalculatorFactory) { 17 | this.priceCalculatorFactory = priceCalculatorFactory; 18 | } 19 | 20 | @Produces @ExampleProductQualifier 21 | public PriceCalculator create() { 22 | return priceCalculatorFactory.create(new Product(0)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /softwaremill-debug/src/main/java/com/softwaremill/common/debug/timing/TimingInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.debug.timing; 2 | 3 | import javax.interceptor.AroundInvoke; 4 | import javax.interceptor.Interceptor; 5 | import javax.interceptor.InvocationContext; 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @link http://seamframework.org/Community/SeamPerformanceProblemRewardingWorkaround 10 | * @author Tobias Hill 11 | * @author Adam Warski 12 | */ 13 | @Interceptor 14 | @Timed 15 | public class TimingInterceptor implements Serializable { 16 | @AroundInvoke 17 | public Object timeCall(InvocationContext invocation) throws Exception { 18 | long t0 = System.nanoTime(); 19 | try { 20 | return invocation.proceed(); 21 | } finally { 22 | long dt = System.nanoTime() - t0; 23 | TimingResults.instance.addInvocation(invocation, dt); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/objectservice/extension/OSPImpl.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.extension; 2 | 3 | import com.softwaremill.common.cdi.objectservice.OS; 4 | import com.softwaremill.common.cdi.objectservice.OSP; 5 | 6 | /** 7 | * @author Adam Warski (adam at warski dot org) 8 | */ 9 | public class OSPImpl implements OSP { 10 | private final ObjectServiceExtension extension; 11 | private final Class serviceClass; 12 | 13 | public OSPImpl(ObjectServiceExtension extension, Class serviceClass) { 14 | this.extension = extension; 15 | this.serviceClass = serviceClass; 16 | } 17 | 18 | @Override 19 | public OS f(Object obj) { 20 | OS objectService = (OS) extension.serviceForObject(obj.getClass(), serviceClass); 21 | //noinspection unchecked 22 | objectService.setServiced(obj); 23 | return objectService; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/sqs/email/SendEmailTask.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.sqs.email; 2 | 3 | import com.softwaremill.common.sqs.util.EmailDescription; 4 | import com.softwaremill.common.task.OneTimeTask; 5 | import com.softwaremill.common.task.TaskExecutor; 6 | 7 | /** 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | public class SendEmailTask implements OneTimeTask { 11 | private final EmailDescription email; 12 | 13 | public SendEmailTask(EmailDescription email) { 14 | this.email = email; 15 | } 16 | 17 | public EmailDescription getEmail() { 18 | return email; 19 | } 20 | 21 | @Override 22 | public Integer getTaskTimeout() { 23 | return null; 24 | } 25 | 26 | @Override 27 | public Class> getExecutorBeanClass() { 28 | return SendEmailTaskExecutor.class; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /softwaremill-conf/src/main/java/com/softwaremill/common/conf/encoding/server/MasterPasswordSetterClient.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.conf.encoding.server; 2 | 3 | import com.google.common.base.Charsets; 4 | 5 | import java.io.IOException; 6 | import java.io.OutputStreamWriter; 7 | import java.io.PrintWriter; 8 | import java.net.Socket; 9 | 10 | /** 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | public class MasterPasswordSetterClient { 14 | public static void main(String[] args) throws IOException { 15 | Socket socket = new Socket("localhost", MasterPasswordSetterServer.PORT); 16 | 17 | System.out.println("Please enter the master password:"); 18 | String password = System.console().readLine(); 19 | new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true).write(password); 20 | 21 | System.out.println("Password sent"); 22 | 23 | socket.close(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-faces/src/main/resources/META-INF/smlComponents.taglib.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | http://com.softwaremill.common.faces/components 7 | 8 | multiValidator 9 | 10 | MultiValidator 11 | 12 | 13 | 14 | validator 15 | javax.faces.validator.Validator 16 | 17 | 18 | 19 | 20 | fileUpload 21 | 22 | FileUpload 23 | 24 | 25 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/main/java/com/softwaremill/common/test/web/jboss/server/JBossASProvider.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.jboss.server; 2 | 3 | import com.softwaremill.common.test.web.selenium.ServerProperties; 4 | 5 | /** 6 | * @author Pawel Wrzeszcz (pawel [at] softwaremill . com) 7 | */ 8 | public class JBossASProvider { 9 | 10 | private final ServerProperties serverProperties; 11 | 12 | public JBossASProvider(ServerProperties serverProperties) { 13 | this.serverProperties = serverProperties; 14 | } 15 | 16 | public JBossAS createJBossASInstance() { 17 | int version = serverProperties.getAsVersion(); 18 | switch (version) { 19 | case 5: return new JBossAS5or6(serverProperties); 20 | case 6: return new JBossAS5or6(serverProperties); 21 | case 7: return new JBossAS7(serverProperties); 22 | default: throw new IllegalArgumentException("Not supported JBossAS version: " + version); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/persistence/EntityWithLazySubentity.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.persistence; 2 | 3 | import com.softwaremill.common.util.persistance.Identifiable; 4 | 5 | import javax.persistence.*; 6 | 7 | /** 8 | * @author Pawel Stawicki 9 | * @since 8/13/12 5:30 PM 10 | */ 11 | @Entity 12 | public class EntityWithLazySubentity implements Identifiable { 13 | 14 | @Id 15 | @GeneratedValue 16 | private Long id; 17 | 18 | @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) 19 | private SimpleEntity subentity; 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Long id) { 26 | this.id = id; 27 | } 28 | 29 | public SimpleEntity getSubentity() { 30 | return subentity; 31 | } 32 | 33 | public void setSubentity(SimpleEntity subentity) { 34 | this.subentity = subentity; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /softwaremill-backup/scripts/backup_sdb_and_upload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Configuration 4 | ############### 5 | 6 | if [ -n $1 ]; then 7 | source $1 8 | else 9 | source backup_conf.sh 10 | fi 11 | 12 | 13 | ######### 14 | 15 | CURRENT_YEAR_MONTH=`date +"%Y_%m"` 16 | CURRENT_DATE=`date +"%d_%m_%Y"` 17 | CURRENT_DATE_WITH_HOUR=`date +"%d_%m_%Y__%H_%M"` 18 | TAR_FILE_NAME=simpledb_backup_${CURRENT_DATE_WITH_HOUR}.tar.gz 19 | 20 | # Creating backup files 21 | java -jar $SDB_BACKUP_PATH $SIMPLEDB_ACCESS_KEY_ID $SIMPLEDB_SECRET_ACCESS_KEY $SIMPLEDB_REGION "$SIMPLEDB_DOMAINS" 22 | 23 | # Packing 24 | tar -czf $TAR_FILE_NAME simpledb_backup*${CURRENT_DATE}*.txt 25 | 26 | # Removing backup files 27 | rm simpledb_backup*${CURRENT_DATE}*.txt 28 | 29 | # Uploading to S3 30 | java -cp $SDB_BACKUP_PATH com.softwaremill.common.backup.S3Upload $S3_ACCESS_KEY_ID $S3_SECRET_ACCESS_KEY $S3_BUCKET $TAR_FILE_NAME $S3_PREFIX$CURRENT_YEAR_MONTH 31 | 32 | # Cleaning up 33 | rm $TAR_FILE_NAME 34 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-swing/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | softwaremill-test 6 | com.softwaremill.common 7 | 81-SNAPSHOT 8 | 9 | 10 | softwaremill-test-ui-swing 11 | Softwaremill Swing UI Test 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | org.assertj 20 | assertj-swing-testng 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/autofactory/CreatedWith.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.*; 7 | import static java.lang.annotation.RetentionPolicy.*; 8 | 9 | /** 10 | * Creates an implementation of the specified factory class, which will return instances of the annotated class 11 | * when methods in the created implementation are invoked. 12 | * 13 | * The factory class should contain exactly one method, where the return type is a supertype of the annotated 14 | * class ((e.g. an interface implemented by the annotated class). 15 | * 16 | * The parameters of the factory method should match the arguments of the constructor. 17 | * 18 | * @author Adam Warski (adam at warski dot org) 19 | */ 20 | @Target({ TYPE }) 21 | @Retention(RUNTIME) 22 | public @interface CreatedWith { 23 | Class value(); 24 | } 25 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/main/java/com/softwaremill/common/test/web/jboss/DeployementProperties.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.jboss; 2 | 3 | /** 4 | * 5 | * @author maciek 6 | */ 7 | public class DeployementProperties { 8 | 9 | private String appVersion; 10 | 11 | private String earPath; 12 | 13 | private String rorPath; 14 | 15 | /** 16 | * @param appVersion 17 | * @param earPath 18 | * @param rorPath 19 | */ 20 | public DeployementProperties(String appVersion, String earPath, String rorPath) { 21 | this.appVersion = appVersion; 22 | this.earPath = earPath; 23 | this.rorPath = rorPath; 24 | } 25 | 26 | public String getAppVersion() { 27 | return appVersion; 28 | } 29 | 30 | public String getEarPath() { 31 | return earPath; 32 | } 33 | 34 | public String getRorPath() { 35 | return rorPath; 36 | } 37 | 38 | 39 | 40 | } 41 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/main/resources/hibernate.test.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | create-drop 10 | 11 | false 12 | true 13 | 14 | org.hibernate.dialect.H2Dialect 15 | org.h2.Driver 16 | sa 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/Service2C.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | import javax.enterprise.context.RequestScoped; 4 | import java.util.concurrent.atomic.AtomicInteger; 5 | 6 | /** 7 | * A service for which implementations are scoped beans, with instance counters. 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | @RequestScoped 11 | public class Service2C implements Service2 { 12 | private C serviced; 13 | 14 | public Service2C() { 15 | instanceCounter.incrementAndGet(); 16 | } 17 | 18 | @Override 19 | public void setServiced(C serviced) { 20 | this.serviced = serviced; 21 | } 22 | 23 | @Override 24 | public Object get() { 25 | return serviced.getValue(); 26 | } 27 | 28 | private static AtomicInteger instanceCounter = new AtomicInteger(); 29 | 30 | public static int instanceCount() { 31 | return instanceCounter.get(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/auto/AutoString.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice.auto; 2 | 3 | import javax.enterprise.context.ApplicationScoped; 4 | import javax.inject.Inject; 5 | import java.io.Serializable; 6 | 7 | @OSImpl 8 | @ApplicationScoped 9 | public class AutoString implements IAuto{ 10 | 11 | ExecutionMock execMock; 12 | 13 | Integer invCounter = 0; 14 | 15 | @Inject 16 | public AutoString(ExecutionMock execMock) { 17 | this.execMock = execMock; 18 | } 19 | 20 | public AutoString() { 21 | } 22 | 23 | 24 | @Override 25 | public void doSomething(String bim, String object, Integer bom) { 26 | execMock.stringExecs += 1; 27 | 28 | invCounter += 1; 29 | } 30 | 31 | public Integer getInvCounter() { 32 | return invCounter; 33 | } 34 | 35 | public void setInvCounter(Integer invCounter) { 36 | this.invCounter = invCounter; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/objectservice/Service2B.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.objectservice; 2 | 3 | import javax.enterprise.context.ApplicationScoped; 4 | import java.util.concurrent.atomic.AtomicInteger; 5 | 6 | /** 7 | * A service for which implementations are scoped beans, with instance counters. 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | @ApplicationScoped 11 | public class Service2B implements Service2 { 12 | private B serviced; 13 | 14 | public Service2B() { 15 | instanceCounter.incrementAndGet(); 16 | } 17 | 18 | @Override 19 | public void setServiced(B serviced) { 20 | this.serviced = serviced; 21 | } 22 | 23 | @Override 24 | public Object get() { 25 | return serviced.getValue(); 26 | } 27 | 28 | private static AtomicInteger instanceCounter = new AtomicInteger(); 29 | 30 | public static int instanceCount() { 31 | return instanceCounter.get(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /softwaremill-paypal/src/test/java/com/softwaremill/common/paypal/process/status/MockStatusVerifier.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.process.status; 2 | 3 | import com.softwaremill.common.paypal.process.RequestParameters; 4 | 5 | import java.util.logging.Logger; 6 | 7 | /** 8 | * @Author: lukasz.zuchowski at gmail dot com 9 | * Date: 05.04.12 10 | * Time: 15:13 11 | */ 12 | public class MockStatusVerifier implements PayPalStatusVerifier { 13 | 14 | private Logger logger = Logger.getLogger(MockStatusVerifier.class.getName()); 15 | 16 | @Override 17 | public PayPalStatus verify(String url, RequestParameters requestParameters) { 18 | logger.info("with PayPal url:" + url); 19 | logger.info("verifying request parameter:" + requestParameters); 20 | //this is not how payPal works. Its just mock implementation. 21 | String status = requestParameters.getParameter(RequestParameters.Parameter.payment_status); 22 | return new PayPalStatus(status); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/field/PriceCalculatorFieldInjectionImpl.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.field; 2 | 3 | import com.softwaremill.common.cdi.autofactory.CreatedWith; 4 | import com.softwaremill.common.cdi.autofactory.Discounts; 5 | import com.softwaremill.common.cdi.autofactory.PriceCalculator; 6 | import com.softwaremill.common.cdi.autofactory.Product; 7 | 8 | import javax.inject.Inject; 9 | 10 | /** 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | @CreatedWith(PriceCalculator.Factory.class) 14 | public class PriceCalculatorFieldInjectionImpl implements PriceCalculator { 15 | @Inject 16 | private Discounts discounts; 17 | 18 | private final Product product; 19 | 20 | public PriceCalculatorFieldInjectionImpl(Product product) { 21 | this.product = product; 22 | } 23 | 24 | @Override 25 | public int getFinalPrice() { 26 | return product.getBasePrice() - discounts.getNormalDiscount(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /softwaremill-faces/src/main/java/com/softwaremill/common/faces/navigation/CurrentPage.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.faces.navigation; 2 | 3 | import javax.faces.context.FacesContext; 4 | import java.util.Collections; 5 | import java.util.Map; 6 | 7 | /** 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | public class CurrentPage extends AbstractPage { 11 | 12 | public CurrentPage() { 13 | super(Collections.emptyMap(), false); 14 | } 15 | 16 | public CurrentPage(Map params, boolean requiresLogin) { 17 | super(params, requiresLogin); 18 | } 19 | 20 | @Override 21 | protected String computeViewId() { 22 | return FacesContext.getCurrentInstance().getViewRoot().getViewId(); 23 | } 24 | 25 | public Page copy(Map params, boolean requiresLogin) { 26 | return new CurrentPage(params, requiresLogin); 27 | } 28 | 29 | @Override 30 | public String getSecurityEL() { 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/dependency/GlobalDependencyProvider.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.dependency; 2 | 3 | import java.lang.annotation.Annotation; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | /** 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | public class GlobalDependencyProvider extends AbstractDependencyProvider { 11 | private final List dependencies; 12 | private final List dependenciesWithQualifiers; 13 | 14 | public GlobalDependencyProvider(List deps) { 15 | dependencies = new ArrayList(); 16 | dependenciesWithQualifiers = new ArrayList(); 17 | 18 | loadDeps(deps); 19 | } 20 | 21 | @Override 22 | protected List getDependencies() { 23 | return dependencies; 24 | } 25 | 26 | @Override 27 | protected List getDependenciesWithQualifiers() { 28 | return dependenciesWithQualifiers; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /softwaremill-faces/src/main/java/com/softwaremill/common/faces/transaction/TransactionExceptionObserver.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.faces.transaction; 2 | 3 | import javax.annotation.Resource; 4 | import javax.enterprise.event.Observes; 5 | import javax.faces.event.ExceptionQueuedEvent; 6 | import javax.transaction.Status; 7 | import javax.transaction.SystemException; 8 | import javax.transaction.UserTransaction; 9 | 10 | /** 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | public class TransactionExceptionObserver { 14 | @Resource 15 | private UserTransaction utx; 16 | 17 | /** 18 | * When an exception is thrown, the transaction is rolled back. 19 | * @param e The event. 20 | */ 21 | public void onExceptionQueued(@Observes ExceptionQueuedEvent e) { 22 | try { 23 | if (utx.getStatus() == Status.STATUS_ACTIVE) { 24 | utx.rollback(); 25 | } 26 | } catch (SystemException e1) { 27 | throw new RuntimeException(e1); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/test/java/com/softwaremill/common/test/web/selenium/screenshots/AnSeleniumTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.selenium.screenshots; 2 | 3 | import org.testng.annotations.AfterSuite; 4 | import org.testng.annotations.AfterTest; 5 | import org.testng.annotations.BeforeSuite; 6 | import org.testng.annotations.BeforeTest; 7 | import com.softwaremill.common.test.web.selenium.AbstractSeleniumTest; 8 | 9 | /** 10 | * It isn't a real test class, it's used in {@link FailureTestListenerTest} 11 | */ 12 | public class AnSeleniumTest extends AbstractSeleniumTest { 13 | 14 | @BeforeSuite 15 | @Override 16 | public void setupSelenium() throws Exception { 17 | } 18 | 19 | @AfterSuite 20 | @Override 21 | public void stopSelenium() throws Exception { 22 | } 23 | 24 | @BeforeTest 25 | @Override 26 | public void setupBrowser() throws Exception { 27 | } 28 | 29 | @AfterTest 30 | @Override 31 | public void stopBrowser() throws Exception { 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/security/SecurityFlags.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import javax.enterprise.inject.Model; 4 | import java.io.Serializable; 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | import java.util.concurrent.Callable; 8 | 9 | /** 10 | * A bean for managing security flags. 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | @Model 14 | public class SecurityFlags implements Serializable{ 15 | private Set flags = new HashSet(); 16 | 17 | public boolean hasFlag(String name) { 18 | return flags.contains(name); 19 | } 20 | 21 | public T doWithFlag(String flagName, Callable callable) { 22 | flags.add(flagName); 23 | try { 24 | return callable.call(); 25 | } catch (RuntimeException e) { 26 | throw e; 27 | } catch (Exception e) { 28 | throw new RuntimeException(e); 29 | } finally { 30 | flags.remove(flagName); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /softwaremill-conf/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | softwaremill-conf 4 | Softwaremill Configuration 5 | 6 | 7 | com.softwaremill.common 8 | softwaremill-common-parent 9 | 81-SNAPSHOT 10 | 11 | 12 | 13 | 14 | org.jboss.mx 15 | jboss-jmx 16 | provided 17 | 18 | 19 | 20 | ch.qos.logback 21 | logback-classic 22 | test 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-util/README.md: -------------------------------------------------------------------------------- 1 | # SoftwareMill Test Util 2 | 3 | Maven dependency: 4 | 5 | 6 | com.softwaremill.common 7 | softwaremill-test-util 8 | 70 9 | 10 | 11 | ## TimeAssertions 12 | 13 | Provides assertions like FEST Assert for org.joda.time.DateTime and java.util.Date classes. Examples 14 | 15 | TimeAssertions.assertTime(dateTime).isBefore(laterDateTime); 16 | 17 | Comparison methods are isBefore, isBeforeOrAt, isAfter, isAfterOrAt. It works for org.joda.time.DateTime and java.util.Date. 18 | You can freely exchange them, i.e. compare joda to joda, joda to java, java to java etc. 19 | 20 | You can also compare joda LocalDateTime, but only to instance of the same class, as it doesn't make sense to compare LocalDateTime 21 | to DateTime or java.util.Date. 22 | 23 | Method name is assertTime not assertThat so that you could statically import it. You can't statically import 24 | two methods with the same name. 25 | 26 | 27 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/security/SecureResult.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import javax.enterprise.util.Nonbinding; 4 | import javax.interceptor.InterceptorBinding; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.Target; 7 | 8 | import static java.lang.annotation.ElementType.*; 9 | import static java.lang.annotation.RetentionPolicy.*; 10 | 11 | /** 12 | * Checks a condition for a method's return value (post-condition). 13 | * TODO: add an internationalized message 14 | * @author Adam Warski (adam at warski dot org) 15 | */ 16 | @Retention(RUNTIME) 17 | @Target({METHOD, TYPE}) 18 | @InterceptorBinding 19 | public @interface SecureResult { 20 | /** 21 | * @return The EL expression that should be evaluated. If it evaluates to {@code true}, access will be granted. 22 | * The EL expression may reference any objects that are in any context, as well as the result of the method under 23 | * the name {@code result}. 24 | */ 25 | @Nonbinding 26 | String value(); 27 | } -------------------------------------------------------------------------------- /softwaremill-paypal/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | 6 | softwaremill-common-parent 7 | com.softwaremill.common 8 | 81-SNAPSHOT 9 | 10 | 11 | softwaremill-paypal 12 | SoftwareMill Paypal Integration 13 | http://maven.apache.org 14 | 15 | 16 | UTF-8 17 | 18 | 19 | 20 | 21 | org.jboss.spec 22 | jboss-javaee-6.0 23 | 1.0.0.Final 24 | pom 25 | provided 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /softwaremill-util/README.md: -------------------------------------------------------------------------------- 1 | Maven dependency: 2 | 3 | 4 | com.softwaremill.common 5 | softwaremill-util 6 | [VERSION] 7 | 8 | 9 | ## CDIInjector 10 | 11 | Sets values of fields that are annotated with @Inject basing on types of injected objects. 12 | 13 | Mainly a test utility, makes it easier to test beans which use field injection. Instead of manually setting values 14 | of fields (having to provide the field name), it is enough to provide the target of the injection and the objects 15 | to be injected. For example: 16 | 17 | import static com.softwaremill.common.util.CDIInjector.*; 18 | 19 | @Test 20 | public void testSomething() { 21 | // ... 22 | 23 | into(testedBean) 24 | .inject(mockService1, mockService2) 25 | .injectWithQualifier(LoggedIn.class, mockUser); 26 | 27 | // ... 28 | } 29 | 30 | Of course the `CDIInjector` doesn't have to be used in tests, it can be used stand-alone also. 31 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/IncrementalSleeper.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util; 2 | 3 | /** 4 | * Suspends the current thread for exponentially increasing intervals of time, until the maximum sleep interval is 5 | * reached. 6 | */ 7 | public class IncrementalSleeper { 8 | private final long initialInterval; 9 | private final long maxInterval; 10 | 11 | private long currentInterval; 12 | 13 | public IncrementalSleeper(long initialInterval, long maxInterval) { 14 | this.initialInterval = initialInterval; 15 | this.maxInterval = maxInterval; 16 | 17 | this.currentInterval = initialInterval; 18 | } 19 | 20 | public long getCurrentInterval() { 21 | return currentInterval; 22 | } 23 | 24 | public void sleep() { 25 | Sleeper.sleepFor(currentInterval); 26 | if (currentInterval < maxInterval) { 27 | currentInterval *= 2; 28 | } 29 | } 30 | 31 | public void reset() { 32 | currentInterval = initialInterval; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /softwaremill-util/src/test/java/com/softwaremill/common/util/RichStringTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util; 2 | 3 | import org.testng.annotations.DataProvider; 4 | import org.testng.annotations.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | public class RichStringTest { 12 | @Test(dataProvider = "getReplacePolishCharactersStrings") 13 | public void shouldReplacePolishCharacters(String string, String expectedResult) throws Exception { 14 | // When 15 | String replaced = new RichString(string).replacePolishChars(); 16 | 17 | // Then 18 | assertThat(replaced).isEqualTo(expectedResult); 19 | } 20 | 21 | @DataProvider 22 | public Object[][] getReplacePolishCharactersStrings() { 23 | return new Object[][] { 24 | { "abcd", "abcd" }, 25 | { "ab cd", "ab cd" }, 26 | { "łąka", "laka" }, 27 | { "żubr ćma mrówka", "zubr cma mrowka" }, 28 | { "Żubr ćma MRÓWKA", "Zubr cma MROWKA" }, 29 | }; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/validation/NoSpecialChars.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.validation; 2 | 3 | import javax.validation.Constraint; 4 | import javax.validation.Payload; 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * Checks if string contains special characters. By default allows only upper and lowercase letters 9 | * and numbers. Additional characters can be allowed by charsAllowed 10 | */ 11 | @Documented 12 | @Constraint(validatedBy = NoSpecialCharsValidator.class) 13 | @Target( {ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER }) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface NoSpecialChars { 16 | 17 | /** 18 | * Additional allowed characters. Not separated by anything. 19 | * @return 20 | */ 21 | String charsAllowed() default ""; 22 | 23 | String message() default "Not allowed special characters found"; 24 | 25 | Class[] groups() default { }; 26 | 27 | Class[] payload() default { }; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/src/test/java/com/softwaremill/common/dbtest/util/SqlFileResolverTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.dbtest.util; 2 | 3 | import org.testng.annotations.DataProvider; 4 | import org.testng.annotations.Test; 5 | import com.softwaremill.common.dbtest.AbstractDBTest; 6 | 7 | import static org.assertj.core.api.Assertions.assertThat; 8 | 9 | /** 10 | * @author Pawel Wrzeszcz (pawel . wrzeszcz [at] gmail . com) 11 | */ 12 | public class SqlFileResolverTest { 13 | 14 | @Test(dataProvider = "getClasses") 15 | public void testResolveSqlFile(Class clazz, String expectedPath) throws Exception { 16 | final String filePath = new SqlFileResolver(clazz).getSqlFilePath(); 17 | assertThat(filePath).isEqualTo(expectedPath); 18 | } 19 | 20 | @DataProvider 21 | public Object[][] getClasses() { 22 | return new Object[][] { 23 | {AbstractDBTest.class, "com/softwaremill/common/dbtest/AbstractDBTest.sql"}, 24 | {SqlFileResolverTest.class, "com/softwaremill/common/dbtest/util/SqlFileResolverTest.sql"}, 25 | }; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/validation/Length.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.validation; 2 | 3 | import javax.validation.Constraint; 4 | import javax.validation.Payload; 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * Checks if length is greater than {@code min}, and less than {@code max}. 9 | * Two different error messages for strings that are either too short or two long can be supplied. 10 | */ 11 | @Documented 12 | @Constraint(validatedBy = LengthValidator.class) 13 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface Length { 16 | 17 | String tooLongMessage() default "Value is too long"; 18 | 19 | String tooShortMessage() default "Value is too short"; 20 | 21 | int min() default 0; 22 | 23 | int max() default Integer.MAX_VALUE; 24 | 25 | String message() default "Something is wrong"; 26 | 27 | Class[] groups() default {}; 28 | 29 | Class[] payload() default {}; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/logger/InjectDataAndLoggerConstructor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.logger; 2 | 3 | import org.slf4j.Logger; 4 | import com.softwaremill.common.cdi.autofactory.CreatedWith; 5 | import com.softwaremill.common.cdi.autofactory.FactoryParameter; 6 | 7 | import javax.inject.Inject; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | @CreatedWith(InjectDataAndLoggerConstructor.Factory.class) 13 | public class InjectDataAndLoggerConstructor { 14 | private final String data; 15 | private final Logger logger; 16 | 17 | @Inject 18 | public InjectDataAndLoggerConstructor(@FactoryParameter String data, Logger logger) { 19 | this.data = data; 20 | this.logger = logger; 21 | } 22 | 23 | public String getData() { 24 | return data; 25 | } 26 | 27 | public Logger getLogger() { 28 | return logger; 29 | } 30 | 31 | public static interface Factory { 32 | InjectDataAndLoggerConstructor create(String data); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-util/src/main/java/com/softwaremill/common/test/util/MessageWaiter.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.util; 2 | 3 | import com.google.common.base.Charsets; 4 | 5 | import java.io.InputStream; 6 | import java.util.Scanner; 7 | import java.util.regex.Pattern; 8 | 9 | /** 10 | * Warning: do not use with {@code FileInputStream}. If you want to tail a file and wait for a message, 11 | * use {@link FileMessageWaiter}. 12 | * @author Pawel Wrzeszcz (pawel [at] softwaremill . com) 13 | */ 14 | public class MessageWaiter { 15 | private final InputStream inputStream; 16 | 17 | public MessageWaiter(Process process) { 18 | this(process.getInputStream()); 19 | } 20 | 21 | public MessageWaiter(InputStream inputStream) { 22 | this.inputStream = inputStream; 23 | } 24 | 25 | public void waitFor(String message) { 26 | System.out.println("Waiting for message: [" + message + "]"); 27 | final Scanner scanner = new Scanner(inputStream, Charsets.UTF_8.name()).useDelimiter(Pattern.quote(message)); 28 | scanner.next(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /softwaremill-faces/src/main/java/com/softwaremill/common/faces/validator/AbstractDelgatingValidator.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.faces.validator; 2 | 3 | import javax.faces.component.UIComponent; 4 | import javax.faces.context.FacesContext; 5 | import javax.faces.validator.Validator; 6 | import javax.faces.validator.ValidatorException; 7 | 8 | /** 9 | * Common code for delegating validator 10 | */ 11 | public abstract class AbstractDelgatingValidator implements Validator{ 12 | 13 | protected static final String VALIDATOR_ID = "validatorId"; 14 | 15 | @Override 16 | public void validate(FacesContext facesContext, UIComponent uiComponent, Object value) throws ValidatorException { 17 | String validatorId = (String) uiComponent.getAttributes().get(VALIDATOR_ID); 18 | Validator validator = lookup(facesContext, validatorId); 19 | validator.validate(facesContext, uiComponent, value); 20 | } 21 | 22 | private Validator lookup(FacesContext facesContext, String validatorId) { 23 | return facesContext.getApplication().createValidator(validatorId); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/io/Shell.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.io; 2 | 3 | import java.io.IOException; 4 | import java.nio.charset.Charset; 5 | import java.util.List; 6 | 7 | import static com.google.common.io.CharStreams.*; 8 | 9 | public class Shell { 10 | public static Process runShellCommand(String command) throws IOException { 11 | return Runtime.getRuntime().exec(new String[] { "sh", "-c", command }); 12 | } 13 | 14 | public static List readProcessPids(String... processGrepStrings) throws IOException { 15 | StringBuilder cmd = new StringBuilder("ps ax"); 16 | for (String processGrepString : processGrepStrings) { 17 | cmd.append(" | grep ").append(processGrepString); 18 | } 19 | cmd.append(" | grep -v grep | cut -c1-5"); 20 | 21 | Process getPidProcess = runShellCommand(cmd.toString()); 22 | return readLines(newReaderSupplier( 23 | new InputStreamInputSupplier(getPidProcess.getInputStream()), 24 | Charset.defaultCharset())); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /softwaremill-scripts/jsf-view-generator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | jsf-view-generator 8 | jsf-view-generator 9 | 0.1-SNAPSHOT 10 | 11 | 12 | 13 | za.co.fnb.commercial.dms 14 | dms-entities 15 | 0.1-SNAPSHOT 16 | 17 | 18 | org.hibernate.javax.persistence 19 | hibernate-jpa-2.0-api 20 | 1.0.0.Final 21 | 22 | 23 | org.scala-lang 24 | scala-library 25 | 2.8.1 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/sqs/MessageId.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.sqs; 2 | 3 | /** 4 | * A wrapper object around an SQS MessageID. 5 | * 6 | * @author Maciej Bilas 7 | * @since 11/10/12 16:23 8 | */ 9 | public class MessageId { 10 | 11 | private final String messageId; 12 | 13 | public MessageId(String messageId) { 14 | this.messageId = messageId; 15 | } 16 | 17 | public String get() { 18 | return messageId; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return get(); 24 | } 25 | 26 | @Override 27 | public boolean equals(Object o) { 28 | if (this == o) return true; 29 | if (!(o instanceof MessageId)) return false; 30 | 31 | MessageId messageId1 = (MessageId) o; 32 | 33 | if (messageId != null ? !messageId.equals(messageId1.messageId) : messageId1.messageId != null) return false; 34 | 35 | return true; 36 | } 37 | 38 | @Override 39 | public int hashCode() { 40 | return messageId != null ? messageId.hashCode() : 0; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/RichList.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util; 2 | 3 | import com.google.common.base.Function; 4 | import com.google.common.base.Predicate; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | public class RichList { 13 | private final List wrapped; 14 | 15 | public RichList(List wrapped) { 16 | this.wrapped = wrapped; 17 | } 18 | 19 | public List flatMap(Function> mappingFunction) { 20 | List result = new ArrayList(); 21 | for (T element : wrapped) { 22 | result.addAll(mappingFunction.apply(element)); 23 | } 24 | 25 | return result; 26 | } 27 | 28 | public List filter(Predicate predicate) { 29 | List result = new ArrayList(); 30 | for (T element : wrapped) { 31 | if (predicate.apply(element)) { 32 | result.add(element); 33 | } 34 | } 35 | 36 | return result; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/field/AutoFactoryFieldInjectionTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.field; 2 | 3 | import org.jboss.arquillian.container.test.api.Deployment; 4 | import org.jboss.shrinkwrap.api.ShrinkWrap; 5 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 6 | import com.softwaremill.common.arquillian.ManifestUtil; 7 | import com.softwaremill.common.cdi.autofactory.AbstractAutoFactoryTest; 8 | import com.softwaremill.common.cdi.autofactory.CreatedWith; 9 | 10 | /** 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | public class AutoFactoryFieldInjectionTest extends AbstractAutoFactoryTest { 14 | @Deployment 15 | public static JavaArchive createTestArchive() { 16 | JavaArchive ar = ShrinkWrap.create(JavaArchive.class, "test.jar") 17 | .addClass(PriceCalculatorFieldInjectionImpl.class) 18 | .addClass(TotalPriceCalculatorFixedInjectionImpl.class) 19 | .addPackage(CreatedWith.class.getPackage()); 20 | 21 | return ManifestUtil.addEmptyBeansXml(ar); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/mixed/AutoFactoryMixedConstructorTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.mixed; 2 | 3 | import org.jboss.arquillian.container.test.api.Deployment; 4 | import org.jboss.shrinkwrap.api.ShrinkWrap; 5 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 6 | import com.softwaremill.common.arquillian.ManifestUtil; 7 | import com.softwaremill.common.cdi.autofactory.AbstractAutoFactoryTest; 8 | import com.softwaremill.common.cdi.autofactory.CreatedWith; 9 | 10 | /** 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | public class AutoFactoryMixedConstructorTest extends AbstractAutoFactoryTest { 14 | @Deployment 15 | public static JavaArchive createTestArchive() { 16 | JavaArchive ar = ShrinkWrap.create(JavaArchive.class, "test.jar") 17 | .addClass(PriceCalculatorMixedConstructorImpl.class) 18 | .addClass(TotalPriceCalculatorMixedConstructorImpl.class) 19 | .addPackage(CreatedWith.class.getPackage()); 20 | 21 | return ManifestUtil.addEmptyBeansXml(ar); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/main/java/com/softwaremill/common/test/web/selenium/SMLSelenium.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.selenium; 2 | 3 | import com.thoughtworks.selenium.DefaultSelenium; 4 | import com.softwaremill.common.test.web.selenium.screenshots.ScreenshotHttpCommandProcessor; 5 | import com.softwaremill.common.test.web.selenium.screenshots.Screenshotter; 6 | 7 | /** 8 | * Selenium capable of doing screenshots 9 | * 10 | * User: szimano 11 | */ 12 | public class SMLSelenium extends DefaultSelenium { 13 | 14 | public SMLSelenium(String serverHost, int serverPort, String browserStartCommand, String browserURL, 15 | Screenshotter screenshotter) { 16 | super(serverHost, serverPort, browserStartCommand, browserURL); 17 | 18 | // use our command processor 19 | this.commandProcessor = new ScreenshotHttpCommandProcessor(serverHost, serverPort, browserStartCommand, browserURL, 20 | screenshotter); 21 | } 22 | 23 | public void open(String url) { 24 | commandProcessor.doCommand("open", new String[] {url,"true"}); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-util/src/test/java/com/softwaremill/common/test/util/ExtMockitoTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.util; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import java.util.List; 6 | 7 | import static org.mockito.Mockito.mock; 8 | import static org.testng.Assert.assertFalse; 9 | import static org.testng.Assert.assertTrue; 10 | import static com.softwaremill.common.test.util.ExtMockito.isAMock; 11 | 12 | /** 13 | * @author Maciej Bilas 14 | * @since 15/12/11 13:06 15 | */ 16 | public class ExtMockitoTest { 17 | 18 | private static final List A_MOCK = mock(List.class); 19 | private static final int NOT_A_MOCK = 1; 20 | 21 | @Test 22 | public void isAMockShouldReturnTrueWhenAMockIsPassedToIt() { 23 | assertTrue(isAMock(A_MOCK)); 24 | } 25 | 26 | @Test(expectedExceptions = NullPointerException.class) 27 | public void isAMockShouldThrowAnNPEIfTheObjectPassedToItIsNull() { 28 | isAMock(null); 29 | } 30 | 31 | @Test 32 | public void isAMockShouldReturnFalseIfTheObjectIsNotAMock() { 33 | assertFalse(isAMock(NOT_A_MOCK)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-db/README.md: -------------------------------------------------------------------------------- 1 | # Test-with-DB framework using Arquillian 2 | 3 | Maven dependency: 4 | 5 | 6 | com.softwaremill.common 7 | softwaremill-test-db 8 | [VERSION] 9 | 10 | 11 | Lets you run tests that use a database. Great for: 12 | * validating entity configuration (annotations, hibernate.cfg.xml) in a test 13 | * testing query syntax (named and regualar queries) 14 | * testing methods which heavily use the `EntityManager` and would be hard to test otherwise. 15 | 16 | All test methods are surrounded with a JTA transaction, using a very simple JTA transaction manager. 17 | 18 | By default each test has a private in-memory H2 database. However this can be overriden in the `configureEntities` 19 | method. 20 | 21 | Moreover, before each test an sql is executed, which can be used to populate the DB with test data. The name of the 22 | sql file is the same as of the test class. 23 | 24 | See an example test: [TestOfDBTest](../softwaremill-test-db/src/test/java/com/softwaremill/common/dbtest/TestOfDBTest.java). 25 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-arquillian/src/main/java/com/softwaremill/common/arquillian/BetterArquillian.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.arquillian; 2 | 3 | import org.jboss.arquillian.testng.Arquillian; 4 | import org.testng.IHookCallBack; 5 | import org.testng.ITestResult; 6 | 7 | public abstract class BetterArquillian extends Arquillian { 8 | protected void beforeMethodWithDependencies() { } 9 | protected void afterMethodWithDependencies() { } 10 | 11 | @Override 12 | public void run(final IHookCallBack callback, ITestResult testResult) { 13 | super.run(new IHookCallBack() { 14 | @Override 15 | public void runTestMethod(ITestResult testResult) { 16 | beforeMethodWithDependencies(); 17 | try { 18 | callback.runTestMethod(testResult); 19 | } finally { 20 | afterMethodWithDependencies(); 21 | } 22 | } 23 | 24 | @Override 25 | public Object[] getParameters() { 26 | return callback.getParameters(); 27 | } 28 | }, testResult); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/qualifier/PriceCalculatorQualifiedDependencyImpl.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.qualifier; 2 | 3 | import com.softwaremill.common.cdi.autofactory.CreatedWith; 4 | import com.softwaremill.common.cdi.autofactory.FactoryParameter; 5 | import com.softwaremill.common.cdi.autofactory.PriceCalculator; 6 | import com.softwaremill.common.cdi.autofactory.Product; 7 | 8 | import javax.inject.Inject; 9 | 10 | @CreatedWith(PriceCalculator.Factory.class) 11 | public class PriceCalculatorQualifiedDependencyImpl implements PriceCalculator { 12 | private final Product product; 13 | private final QualifiedDependency qualifiedDependency; 14 | 15 | @Inject 16 | public PriceCalculatorQualifiedDependencyImpl(@FactoryParameter Product product, 17 | @ExampleStringQualifier QualifiedDependency qualifiedDependency) { 18 | this.product = product; 19 | this.qualifiedDependency = qualifiedDependency; 20 | } 21 | 22 | @Override 23 | public int getFinalPrice() { 24 | return product.getBasePrice()-1; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-util/src/main/java/com/softwaremill/common/test/util/reorder/FirstTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.util.reorder; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | 6 | import static java.lang.annotation.ElementType.METHOD; 7 | import static java.lang.annotation.ElementType.TYPE; 8 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 9 | 10 | /** 11 | * Marker to move method or class as a first to run. 12 | * 13 | * 1. It moves method to be run as a first in its class. 14 | * It can not be used with dependsOnMethods parameter (from @Test) as in such situation TestNG will execute method 15 | * specified in this parameter before one marked with @FirstTest. 16 | * 17 | * 2. It moves class to be run as a first among not depending upon other test classes 18 | * 19 | * Beware that not all methods and classes can be reordered, only those which don't have any methods depended upon 20 | * (for more see javadoc for org.testng.IMethodInterceptor) 21 | * 22 | * @author Tomasz Dziurko 23 | */ 24 | @Target({METHOD, TYPE}) 25 | @Retention(RUNTIME) 26 | public @interface FirstTest { 27 | } 28 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-util/src/test/java/com/softwaremill/common/test/util/MockitoTestNGListenerTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.util; 2 | 3 | import org.mockito.Mock; 4 | import org.mockito.internal.util.MockUtil; 5 | import org.testng.annotations.Listeners; 6 | import org.testng.annotations.Test; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | /** 11 | * @author Pawel Wrzeszcz (pawel . wrzeszcz [at] gmail . com) 12 | */ 13 | @Listeners(MockitoTestNGListener.class) 14 | public class MockitoTestNGListenerTest { 15 | 16 | @Mock 17 | private Object mock; 18 | 19 | @Test 20 | public void shouldCreateMock() throws Exception { 21 | assertThat(new MockUtil().isMock(mock)).isTrue(); 22 | } 23 | 24 | private Object mockFromPreviousMethod; 25 | 26 | @Test 27 | public void shouldCreateNewMockForEachTestMethod_Part1() throws Exception { 28 | mockFromPreviousMethod = mock; 29 | } 30 | 31 | @Test(dependsOnMethods = "shouldCreateNewMockForEachTestMethod_Part1") 32 | public void shouldCreateNewMockForEachTestMethod_Part2() throws Exception { 33 | assertThat(mockFromPreviousMethod).isNotEqualTo(mock); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /softwaremill-backup/scripts/backup_mysql_and_upload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Configuration 4 | ############### 5 | 6 | if [ -n $1 ]; then 7 | source $1 8 | else 9 | source backup_conf.sh 10 | fi 11 | 12 | ######### 13 | 14 | CURRENT_YEAR_MONTH=`date +"%Y_%m"` 15 | CURRENT_DATE_WITH_HOUR=`date +"%d_%m_%Y__%H_%M"` 16 | DUMP_FILE_NAME=mysql_${MYSQL_DB}_backup_${CURRENT_DATE_WITH_HOUR}.sql 17 | TAR_FILE_NAME=mysql_${MYSQL_DB}_backup_${CURRENT_DATE_WITH_HOUR}.tar.gz 18 | 19 | # Creating backup files 20 | if [ "x$MYSQL_DB" = "x*" ]; then 21 | MYSQL_DB="--all-databases" 22 | DUMP_FILE_NAME=mysql_all_backup_${CURRENT_DATE_WITH_HOUR}.sql 23 | TAR_FILE_NAME=mysql_all_backup_${CURRENT_DATE_WITH_HOUR}.tar.gz 24 | fi 25 | 26 | mysqldump -u $MYSQL_USER -h $MYSQL_HOST --password=$MYSQL_PASSWORD $MYSQL_DB > $DUMP_FILE_NAME 27 | 28 | # Packing 29 | tar -czf $TAR_FILE_NAME $DUMP_FILE_NAME 30 | 31 | # Removing backup files 32 | rm $DUMP_FILE_NAME 33 | 34 | # Uploading to S3 35 | java -cp $SDB_BACKUP_PATH com.softwaremill.common.backup.S3Upload $S3_ACCESS_KEY_ID $S3_SECRET_ACCESS_KEY $S3_BUCKET $TAR_FILE_NAME $S3_PREFIX$CURRENT_YEAR_MONTH 36 | 37 | # Cleaning up 38 | rm $TAR_FILE_NAME -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/autofactory/extension/QualifierAnnotationsFilter.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.extension; 2 | 3 | import com.google.common.base.Predicate; 4 | import com.google.common.collect.Collections2; 5 | 6 | import javax.enterprise.inject.spi.BeanManager; 7 | import java.lang.annotation.Annotation; 8 | import java.util.Collection; 9 | import java.util.Set; 10 | 11 | /** 12 | * @author Adam Warski (adam at warski dot org) 13 | */ 14 | public class QualifierAnnotationsFilter { 15 | private final BeanManager beanManager; 16 | 17 | public QualifierAnnotationsFilter(BeanManager beanManager) { 18 | this.beanManager = beanManager; 19 | } 20 | 21 | public Annotation[] filter(Set annotations) { 22 | Collection filtered = Collections2.filter(annotations, new Predicate() { 23 | @Override 24 | public boolean apply(Annotation input) { 25 | return beanManager.isQualifier(input.annotationType()); 26 | } 27 | }); 28 | 29 | return filtered.toArray(new Annotation[filtered.size()]); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/tuples/LexicographicPair.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.tuples; 2 | 3 | import com.google.common.collect.Ordering; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public class LexicographicPair 9 | extends Pair 10 | implements Comparable> { 11 | private final static Ordering ordering = Ordering.natural().nullsFirst(); 12 | 13 | private LexicographicPair(A left, B right) { 14 | super(left, right); 15 | } 16 | 17 | @SuppressWarnings({"unchecked"}) 18 | @Override 19 | public int compareTo(LexicographicPair other) { 20 | int result = ordering.compare(getLeft(), other.getLeft()); 21 | if (result == 0) { 22 | return ordering.compare(getRight(), other.getRight()); 23 | } else { 24 | return result; 25 | } 26 | } 27 | 28 | public static , B extends Comparable> LexicographicPair pair(A left, B right) { 29 | return new LexicographicPair(left, right); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/el/FacesContextELEvaluator.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.el; 2 | 3 | import javax.el.ELContext; 4 | import javax.faces.context.FacesContext; 5 | 6 | /** 7 | * @author Adam Warski (adam at warski dot org) 8 | */ 9 | public class FacesContextELEvaluator extends AbstractELEvaluator { 10 | private final FacesContext facesContext; 11 | 12 | public FacesContextELEvaluator(FacesContext facesContext) { 13 | this.facesContext = facesContext; 14 | } 15 | 16 | @SuppressWarnings({"unchecked"}) 17 | public T evaluate(String expression, Class expectedResultType) { 18 | ELContext elContext = facesContext.getELContext(); 19 | return ELEvaluatorUtil.evaluate(elContext, facesContext.getApplication().getExpressionFactory(), 20 | expression, expectedResultType); 21 | } 22 | 23 | public void setParameter(String name, Object value) { 24 | facesContext.getExternalContext().getRequestMap().put(name, value); 25 | } 26 | 27 | public void clearParameter(String name) { 28 | facesContext.getExternalContext().getRequestMap().remove(name); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/sqs/ReceiptHandle.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.sqs; 2 | 3 | import static com.google.common.base.Preconditions.checkNotNull; 4 | 5 | /** 6 | * @author Maciej Bilas 7 | * @since 12/10/12 12:27 8 | */ 9 | public class ReceiptHandle { 10 | 11 | private final String receiptHandle; 12 | 13 | public ReceiptHandle(String receiptHandle) { 14 | this.receiptHandle = checkNotNull(receiptHandle); 15 | } 16 | 17 | public String get() { 18 | return receiptHandle; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return get(); 24 | } 25 | 26 | @Override 27 | public boolean equals(Object o) { 28 | if (this == o) return true; 29 | if (!(o instanceof ReceiptHandle)) return false; 30 | 31 | ReceiptHandle that = (ReceiptHandle) o; 32 | 33 | if (receiptHandle != null ? !receiptHandle.equals(that.receiptHandle) : that.receiptHandle != null) 34 | return false; 35 | 36 | return true; 37 | } 38 | 39 | @Override 40 | public int hashCode() { 41 | return receiptHandle != null ? receiptHandle.hashCode() : 0; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/NameValuePairBuilder.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util; 2 | 3 | import com.google.common.collect.Maps; 4 | import org.apache.http.NameValuePair; 5 | import org.apache.http.message.BasicNameValuePair; 6 | 7 | import java.util.Map; 8 | 9 | public class NameValuePairBuilder { 10 | 11 | public static final String NOT_UNIQUE_KEY_ERROR = "Map already contains key with name "; 12 | 13 | private Map nameValueMap = Maps.newHashMap(); 14 | 15 | public NameValuePairBuilder addPair(String name, String value) { 16 | if(nameValueMap.containsKey(name)) { 17 | throw new RuntimeException(NOT_UNIQUE_KEY_ERROR + name); 18 | } 19 | nameValueMap.put(name, value); 20 | return this; 21 | } 22 | 23 | public NameValuePair[] build() { 24 | 25 | NameValuePair[] array = new NameValuePair[nameValueMap.keySet().size()]; 26 | 27 | int index = 0; 28 | for (String name : nameValueMap.keySet()) { 29 | String value = nameValueMap.get(name); 30 | array[index++]= new BasicNameValuePair(name, value); 31 | } 32 | return array; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/instance/InjectDataAndInstanceConstructor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.instance; 2 | 3 | import com.softwaremill.common.cdi.autofactory.CreatedWith; 4 | import com.softwaremill.common.cdi.autofactory.FactoryParameter; 5 | 6 | import javax.enterprise.inject.Instance; 7 | import javax.inject.Inject; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | @CreatedWith(InjectDataAndInstanceConstructor.Factory.class) 13 | public class InjectDataAndInstanceConstructor { 14 | private final String data; 15 | private final Instance bean; 16 | private final Instance bean2; 17 | 18 | @Inject 19 | public InjectDataAndInstanceConstructor(Instance bean, Instance bean2, @FactoryParameter String data) { 20 | this.bean = bean; 21 | this.bean2 = bean2; 22 | this.data = data; 23 | } 24 | 25 | public String getData() { 26 | return data + bean.get().getData() + bean2.get().getData(); 27 | } 28 | 29 | public static interface Factory { 30 | InjectDataAndInstanceConstructor create(String data); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/util/ArquillianUtil.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.util; 2 | 3 | import org.jboss.shrinkwrap.api.Archive; 4 | import org.jboss.shrinkwrap.api.ArchivePaths; 5 | import org.jboss.shrinkwrap.api.asset.ByteArrayAsset; 6 | import org.jboss.shrinkwrap.api.container.ResourceContainer; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | public class ArquillianUtil { 12 | public static & ResourceContainer> T addTestBeansXml(T archive) { 13 | StringBuilder beansXmlBuilder = new StringBuilder(); 14 | beansXmlBuilder.append(""); 15 | beansXmlBuilder.append(""); 16 | beansXmlBuilder.append("com.softwaremill.common.cdi.security.SecurityInterceptor"); 17 | beansXmlBuilder.append("com.softwaremill.common.cdi.security.SecurityResultInterceptor"); 18 | beansXmlBuilder.append(""); 19 | beansXmlBuilder.append(""); 20 | 21 | return archive.addAsResource( 22 | new ByteArrayAsset(beansXmlBuilder.toString().getBytes()), 23 | ArchivePaths.create("META-INF/beans.xml")); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /softwaremill-sqs/src/main/java/com/softwaremill/common/task/ExecuteWithRequestContext.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.task; 2 | 3 | import org.jboss.weld.context.bound.BoundRequestContext; 4 | import com.softwaremill.common.util.dependency.D; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | public class ExecuteWithRequestContext { 13 | private final Task task; 14 | 15 | public ExecuteWithRequestContext(Task task) { 16 | this.task = task; 17 | } 18 | 19 | public void execute() { 20 | doExecute(task); 21 | } 22 | 23 | private > void doExecute(T task) { 24 | BoundRequestContext requestContext = D.inject(BoundRequestContext.class); 25 | 26 | Map context = new HashMap(); 27 | try { 28 | requestContext.associate(context); 29 | requestContext.activate(); 30 | 31 | D.inject(task.getExecutorBeanClass()).execute(task); 32 | } finally { 33 | requestContext.invalidate(); 34 | requestContext.deactivate(); 35 | requestContext.dissociate(context); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/interceptor/NullToEmptyStringParamsInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.interceptor; 2 | 3 | import com.google.common.base.Strings; 4 | 5 | import javax.interceptor.AroundInvoke; 6 | import javax.interceptor.Interceptor; 7 | import javax.interceptor.InvocationContext; 8 | 9 | /** 10 | * @author Pawel Wrzeszcz (pawel [at] softwaremill . com) 11 | */ 12 | @NullToEmptyStringParams 13 | @Interceptor 14 | public class NullToEmptyStringParamsInterceptor { 15 | @AroundInvoke 16 | public Object convertEmptyStringParameters(InvocationContext ctx) throws Exception { 17 | 18 | Object[] parameters = ctx.getParameters(); 19 | Object[] convertedParameters = new Object[parameters.length]; 20 | 21 | int i = 0; 22 | for (Class parameterType : ctx.getMethod().getParameterTypes()) { 23 | convertedParameters[i] = convertParamValue(parameterType, parameters[i]); 24 | i++; 25 | } 26 | 27 | ctx.setParameters(convertedParameters); 28 | 29 | return ctx.proceed(); 30 | } 31 | 32 | private Object convertParamValue(Class parameterType, Object parameter) { 33 | return parameterType.equals(String.class) ? Strings.nullToEmpty((String) parameter) : parameter; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/validation/NotJustWhitespace.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.validation; 2 | 3 | import org.hibernate.validator.constraints.NotEmpty; 4 | 5 | import javax.validation.Constraint; 6 | import javax.validation.Payload; 7 | import javax.validation.constraints.Pattern; 8 | import java.lang.annotation.Documented; 9 | import java.lang.annotation.Retention; 10 | import java.lang.annotation.Target; 11 | 12 | import static java.lang.annotation.ElementType.*; 13 | import static java.lang.annotation.RetentionPolicy.*; 14 | 15 | /** 16 | * Checks that a string is not empty and has at least one non-whitespace character - so string is not empty after trim. 17 | * 18 | * @author maciek 19 | */ 20 | @Documented 21 | @Constraint(validatedBy = { }) 22 | @Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER }) 23 | @Retention(RUNTIME) 24 | @NotEmpty 25 | @Pattern(regexp = "(?s).*?\\S+.*") // (?s) makes . match all - also newlines 26 | public @interface NotJustWhitespace { 27 | String message() default "{com.softwaremill.common.validator.NotJustWhitespace.message}"; 28 | 29 | Class[] groups() default { }; 30 | 31 | Class[] payload() default { }; 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/el/AbstractELEvaluator.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.el; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public abstract class AbstractELEvaluator implements ELEvaluator { 9 | public abstract T evaluate(String expression, Class expectedResultType); 10 | 11 | @SuppressWarnings({"unchecked"}) 12 | public T evaluate(String expression, Class expectedResultType, Map parameters) { 13 | try { 14 | // Setting parameters 15 | for (Map.Entry parameter : parameters.entrySet()) { 16 | setParameter(parameter.getKey(), parameter.getValue()); 17 | } 18 | 19 | // Evaluating expression 20 | return evaluate(expression, expectedResultType); 21 | } finally { 22 | // Clearing up parameters 23 | for (String parameterName : parameters.keySet()) { 24 | clearParameter(parameterName); 25 | } 26 | } 27 | } 28 | 29 | public abstract void setParameter(String name, Object value); 30 | 31 | public abstract void clearParameter(String name); 32 | } 33 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/multipleconstructors/BeanWithAdditionalDefaultConstructor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.multipleconstructors; 2 | 3 | import com.softwaremill.common.cdi.autofactory.CreatedWith; 4 | import com.softwaremill.common.cdi.autofactory.Discounts; 5 | import com.softwaremill.common.cdi.autofactory.FactoryParameter; 6 | import com.softwaremill.common.cdi.autofactory.Product; 7 | 8 | import javax.inject.Inject; 9 | 10 | /** 11 | * @author Maciej Bilas 12 | * @since 16/4/12 12:40 13 | */ 14 | @CreatedWith(BeanWithAdditionalDefaultConstructor.Factory.class) 15 | public class BeanWithAdditionalDefaultConstructor { 16 | 17 | private final Discounts discounts; 18 | private final Product product; 19 | 20 | public interface Factory { 21 | public BeanWithAdditionalDefaultConstructor create(Product product); 22 | } 23 | 24 | public BeanWithAdditionalDefaultConstructor() { 25 | discounts = null; 26 | product = null; 27 | } 28 | 29 | @Inject 30 | public BeanWithAdditionalDefaultConstructor(Discounts discounts, @FactoryParameter Product product) { 31 | this.discounts = discounts; 32 | this.product = product; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /softwaremill-debug/src/main/java/com/softwaremill/common/debug/timing/TimingProxy.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.debug.timing; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | import java.lang.reflect.Method; 5 | import java.lang.reflect.Proxy; 6 | 7 | /** 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | public class TimingProxy { 11 | @SuppressWarnings({"unchecked"}) 12 | public static T createFor(final U instance, Class _interface) { 13 | return (T) Proxy.newProxyInstance(instance.getClass().getClassLoader(), new Class[]{ _interface }, 14 | new InvocationHandler() { 15 | @SuppressWarnings({"unchecked"}) 16 | @Override 17 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 18 | long t0 = System.nanoTime(); 19 | try { 20 | return method.invoke(instance, args); 21 | } finally { 22 | long dt = System.nanoTime() - t0; 23 | TimingResults.instance.addInvocation(method, dt); 24 | } 25 | } 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/main/java/com/softwaremill/common/test/web/email/AbstractEmailServerRunner.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.email; 2 | 3 | import com.dumbster.smtp.SimpleSmtpServer; 4 | import org.testng.annotations.AfterSuite; 5 | import org.testng.annotations.BeforeSuite; 6 | import com.softwaremill.common.test.util.SimpleSmtpServerStarter; 7 | 8 | 9 | /** 10 | * Starts and stops mock email server before/after test suite. 11 | * The 'inbox' is common for all tests. 12 | * 13 | * Method to return smtp port needs to be implemented 14 | * 15 | * @author maciek 16 | */ 17 | public abstract class AbstractEmailServerRunner { 18 | 19 | protected static SimpleSmtpServer emailServer; 20 | 21 | @BeforeSuite(alwaysRun = true) 22 | public void startEmailServer() { 23 | int port = getSmtpServerPort(); 24 | System.out.println("--- Starting email server on port " + port); 25 | emailServer = SimpleSmtpServerStarter.start(port); 26 | } 27 | 28 | @AfterSuite(alwaysRun = true) 29 | public void stopEmailServer() { 30 | System.out.println("--- Stopping email server"); 31 | emailServer.stop(); 32 | } 33 | 34 | /** 35 | * @return smtp port used by tested app 36 | */ 37 | protected abstract int getSmtpServerPort(); 38 | } 39 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-util/src/test/java/com/softwaremill/common/test/util/ExecutionTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.util; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | /** 8 | * @author Pawel Wrzeszcz (pawel . wrzeszcz [at] gmail . com) 9 | */ 10 | public class ExecutionTest { 11 | 12 | @Test 13 | public void shouldReturnExceptionForClosureWithException() throws Exception { 14 | // Given 15 | final Exception exception = new Exception("msg"); 16 | 17 | Execution execution = new Execution() { 18 | 19 | @Override 20 | protected void execute() throws Exception { 21 | throw exception; 22 | } 23 | }; 24 | 25 | // When 26 | Exception result = execution.getException(); 27 | 28 | // Then 29 | assertThat(result).isEqualTo(exception); 30 | } 31 | 32 | @Test 33 | public void shouldReturnNullForClosureWithoutException() throws Exception { 34 | // Given 35 | Execution execution = new Execution() { 36 | 37 | @Override 38 | protected void execute() throws Exception { 39 | // Valid code here 40 | } 41 | }; 42 | 43 | // When 44 | Exception result = execution.getException(); 45 | 46 | // Then 47 | assertThat(result).isNull(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/autofactory/field/TotalPriceCalculatorFixedInjectionImpl.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.field; 2 | 3 | import com.softwaremill.common.cdi.autofactory.*; 4 | 5 | import javax.inject.Inject; 6 | import java.util.List; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | @CreatedWith(TotalPriceCalculator.Factory.class) 12 | public class TotalPriceCalculatorFixedInjectionImpl implements TotalPriceCalculator { 13 | @Inject 14 | private PriceCalculator.Factory priceCalculatorFactory; 15 | 16 | @Inject 17 | private BulkOrderDiscounts bulkOrderDiscounts; 18 | 19 | private final List products; 20 | private final int specialDiscount; 21 | 22 | public TotalPriceCalculatorFixedInjectionImpl(List products, int specialDiscount) { 23 | this.products = products; 24 | this.specialDiscount = specialDiscount; 25 | } 26 | 27 | @Override 28 | public int getTotalPrice() { 29 | int sum = 0; 30 | for (Product product : products) { 31 | sum += priceCalculatorFactory.create(product).getFinalPrice(); 32 | } 33 | 34 | return sum - specialDiscount - bulkOrderDiscounts.getDiscountForBulkOrderSize(products.size()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /softwaremill-conf/src/main/java/com/softwaremill/common/conf/encoding/CodingConsole.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.conf.encoding; 2 | 3 | import java.io.Console; 4 | import java.io.IOException; 5 | 6 | /** 7 | * @author Adam Warski (adam at warski dot org) 8 | */ 9 | public class CodingConsole { 10 | public static void main(String[] args) throws IOException { 11 | System.out.println("Welcome to the coding console!"); 12 | MasterPasswordStore.readFromConsole(); 13 | ConfigurationValueCoder valueCoder = new ConfigurationValueCoder(); 14 | 15 | Console console = System.console(); 16 | while (true) { 17 | System.out.println("1. encode values"); 18 | System.out.println("2. decode values"); 19 | System.out.println("3. exit"); 20 | String choice = console.readLine(); 21 | if ("1".equals(choice)) { 22 | String text = console.readLine("Text: "); 23 | System.out.println(valueCoder.encode(text)); 24 | } else if ("2".equals(choice)) { 25 | String text = console.readLine("Text: "); 26 | System.out.println(valueCoder.decode(text)); 27 | } if ("3".equals(choice)) { 28 | return; 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/persistence/EntityManagerFactoryProducer.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.persistence; 2 | 3 | import javax.enterprise.context.RequestScoped; 4 | import javax.enterprise.inject.Produces; 5 | import javax.persistence.EntityManagerFactory; 6 | import javax.persistence.PersistenceUnit; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | public class EntityManagerFactoryProducer { 12 | private static EntityManagerFactory staticEntityManagerFactory; 13 | 14 | @PersistenceUnit 15 | private EntityManagerFactory entityManagerFactory; 16 | 17 | @Produces 18 | @RequestScoped 19 | public EntityManagerFactory getEntityManagerFactory() { 20 | if (staticEntityManagerFactory != null) { 21 | return staticEntityManagerFactory; 22 | } 23 | 24 | return entityManagerFactory; 25 | } 26 | 27 | /** 28 | * Set an entity manager factory for testing. 29 | * @param staticEntityManagerFactory Entity manager factory that will be returned by this producer. 30 | */ 31 | public static void setStaticEntityManagerFactory(EntityManagerFactory staticEntityManagerFactory) { 32 | EntityManagerFactoryProducer.staticEntityManagerFactory = staticEntityManagerFactory; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/autofactory/extension/MethodParameterIndexer.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.extension; 2 | 3 | import java.lang.reflect.Method; 4 | import java.lang.reflect.Type; 5 | import java.util.Map; 6 | 7 | import static com.google.common.collect.Maps.*; 8 | 9 | /** 10 | * @author Adam Warski (adam at warski dot org) 11 | */ 12 | public class MethodParameterIndexer { 13 | private final Method factoryMethod; 14 | private final Map parameterTypeToIndex; 15 | 16 | public MethodParameterIndexer(Method factoryMethod) { 17 | this.factoryMethod = factoryMethod; 18 | 19 | parameterTypeToIndex = newHashMap(); 20 | 21 | Type[] parameterTypes = factoryMethod.getGenericParameterTypes(); 22 | for (int i = 0; i < parameterTypes.length; i++) { 23 | Type parameterType = parameterTypes[i]; 24 | parameterTypeToIndex.put(parameterType, i); 25 | } 26 | } 27 | 28 | public int getIndexForArgument(Type parameterType) { 29 | if (!parameterTypeToIndex.containsKey(parameterType)) { 30 | throw new RuntimeException("No parameter of class: " + parameterType + " in the factory method: " + factoryMethod); 31 | } 32 | 33 | return parameterTypeToIndex.get(parameterType); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/system/ProcessKiller.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.system; 2 | 3 | import java.io.IOException; 4 | import java.lang.reflect.Field; 5 | 6 | /** 7 | * @author Adam Warski (adam at warski dot org) 8 | */ 9 | public class ProcessKiller { 10 | /** 11 | * Tries to kill the given process. Will send kill -9 on UNIX. On Windows uses process.destroy(). 12 | * @param process The process to kill. 13 | */ 14 | public void kill(Process process) { 15 | // Hack: Getting the PID. 16 | if (process.getClass().getName().contains("UNIX")) { 17 | try { 18 | Field pidField = process.getClass().getDeclaredField("pid"); 19 | pidField.setAccessible(true); 20 | int pid = (Integer) pidField.get(process); 21 | Runtime.getRuntime().exec("kill -9 " + pid); 22 | } catch (NoSuchFieldException e) { 23 | throw new RuntimeException(e); 24 | } catch (IOException e) { 25 | throw new RuntimeException(e); 26 | } catch (IllegalAccessException e) { 27 | throw new RuntimeException(e); 28 | } 29 | } else { 30 | // Fall-back for non-windows systems 31 | process.destroy(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /softwaremill-paypal/src/main/java/com/softwaremill/common/paypal/button/PaypalCartItem.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.paypal.button; 2 | 3 | /** 4 | * Cart item, uploaded to paypal 5 | */ 6 | public class PaypalCartItem { 7 | 8 | private final String itemName; 9 | private final String itemAmount; 10 | private final String itemShippingAmount; 11 | private final String itemTaxAmount; 12 | 13 | public PaypalCartItem(String itemName, String itemAmount, String itemShippingAmount, String itemTaxAmount) 14 | throws NumberFormatException { 15 | 16 | this.itemName = itemName; 17 | this.itemAmount = itemAmount; 18 | this.itemShippingAmount = itemShippingAmount; 19 | this.itemTaxAmount = itemTaxAmount; 20 | 21 | checkAmount(itemAmount); 22 | checkAmount(itemShippingAmount); 23 | checkAmount(itemTaxAmount); 24 | } 25 | 26 | private void checkAmount(String amount) { 27 | new Double(amount); 28 | } 29 | 30 | public String getItemName() { 31 | return itemName; 32 | } 33 | 34 | public String getItemAmount() { 35 | return itemAmount; 36 | } 37 | 38 | public String getItemShippingAmount() { 39 | return itemShippingAmount; 40 | } 41 | 42 | public String getItemTaxAmount() { 43 | return itemTaxAmount; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-swing/src/main/java/com/softwaremill/test/swing/FileNameBuilder.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.test.swing; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.io.File; 7 | import java.util.Random; 8 | 9 | class FileNameBuilder { 10 | 11 | private static final Logger LOG = LoggerFactory.getLogger(FileNameBuilder.class); 12 | 13 | private Random random; 14 | 15 | public FileNameBuilder() { 16 | random = new Random(); 17 | } 18 | 19 | String createTmpFileName(String className) { 20 | String tmpFolder = readTmpDirPath(); 21 | String prefix = className; 22 | if (className.indexOf(".") != -1) { 23 | prefix = className.substring(className.lastIndexOf(".") + 1); 24 | } 25 | String fileName = tmpFolder + prefix + "-" + random.nextInt(Integer.MAX_VALUE) + ".png"; 26 | LOG.debug("Created temporary file name [" + fileName + "]"); 27 | return fileName; 28 | } 29 | 30 | private String readTmpDirPath() { 31 | String tmp = System.getProperty("java.io.tmpdir"); 32 | if (tmp == null) { 33 | tmp = File.separator; 34 | } 35 | if (tmp.endsWith(File.separator) == false) { 36 | tmp = tmp + File.separator; 37 | } 38 | return tmp; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /softwaremill-conf/src/test/java/com/softwaremill/common/conf/encoding/ConfigurationValueCoderTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.conf.encoding; 2 | 3 | import org.testng.annotations.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | /** 8 | * @author Adam Warski (adam at warski dot org) 9 | */ 10 | public class ConfigurationValueCoderTest { 11 | @Test 12 | public void shouldEncodeAndDecode() { 13 | // Given 14 | MasterPasswordStore.setMasterPassword("top-secret-passw0rd"); 15 | String text = "ABCDE12345!@#$%"; 16 | ConfigurationValueCoder coder = new ConfigurationValueCoder(); 17 | 18 | // When 19 | String encoded = coder.encode(text); 20 | String decoded = coder.decode(encoded); 21 | 22 | // Then 23 | assertThat(decoded).isEqualTo(text); 24 | } 25 | 26 | @Test 27 | public void shouldCorrectlyVerifyThatAValueIsEncoded() { 28 | // Given 29 | MasterPasswordStore.setMasterPassword("top-secret-passw0rd"); 30 | String text = "ABCDE12345!@#$%"; 31 | ConfigurationValueCoder coder = new ConfigurationValueCoder(); 32 | 33 | // When 34 | String encoded = coder.encode(text); 35 | 36 | // Then 37 | assertThat(coder.isEncoded(encoded)).isTrue(); 38 | assertThat(coder.isEncoded(text)).isFalse(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/conf/ConfValueTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.conf; 2 | 3 | import org.jboss.arquillian.container.test.api.Deployment; 4 | import org.jboss.arquillian.testng.Arquillian; 5 | import org.jboss.shrinkwrap.api.ShrinkWrap; 6 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 7 | import org.testng.annotations.Test; 8 | import com.softwaremill.common.arquillian.ManifestUtil; 9 | 10 | import javax.inject.Inject; 11 | 12 | import static org.assertj.core.api.Assertions.assertThat; 13 | 14 | public class ConfValueTest extends Arquillian { 15 | @Deployment 16 | public static JavaArchive createTestArchive() { 17 | JavaArchive ar = ShrinkWrap.create(JavaArchive.class, "test.jar") 18 | .addPackage(ConfValueProducer.class.getPackage()); 19 | 20 | ar = ManifestUtil.addEmptyBeansXml(ar); 21 | 22 | return ar; 23 | } 24 | 25 | @Inject 26 | @ConfValue(confName = "conftest", confKey = "key1") 27 | private String key1; 28 | 29 | @Inject 30 | @ConfValue(confName = "conftest", confKey = "key2") 31 | private String key2; 32 | 33 | @Test 34 | public void shouldInjectKey1() { 35 | assertThat(key1).isEqualTo("value1"); 36 | } 37 | 38 | @Test 39 | public void shouldInjectKey2() { 40 | assertThat(key2).isEqualTo("value2"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /softwaremill-faces/src/main/java/com/softwaremill/common/faces/navigation/ViewIdPage.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.faces.navigation; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public class ViewIdPage extends AbstractPage { 9 | private final String viewId; 10 | private final String securityEL; 11 | 12 | public ViewIdPage(String viewId, Map params, boolean requiresLogin, String securityEL) { 13 | super(params, requiresLogin); 14 | this.viewId = viewId; 15 | this.securityEL = securityEL; 16 | } 17 | 18 | @Override 19 | protected String computeViewId() { 20 | return viewId; 21 | } 22 | 23 | public Page copy(Map params, boolean requiresLogin) { 24 | return new ViewIdPage(viewId, params, requiresLogin, securityEL); 25 | } 26 | 27 | public String getSecurityEL() { 28 | return securityEL; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object o) { 33 | if (this == o) return true; 34 | if (o == null || getClass() != o.getClass()) return false; 35 | 36 | ViewIdPage that = (ViewIdPage) o; 37 | 38 | if (!viewId.equals(that.viewId)) return false; 39 | 40 | return true; 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | return viewId.hashCode(); 46 | } 47 | } -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/persistence/AbstractHibernateTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.persistence; 2 | 3 | import org.hibernate.ejb.Ejb3Configuration; 4 | import org.jboss.arquillian.testng.Arquillian; 5 | import org.testng.annotations.AfterClass; 6 | import org.testng.annotations.BeforeClass; 7 | 8 | import javax.persistence.EntityManager; 9 | import javax.persistence.EntityManagerFactory; 10 | import java.io.IOException; 11 | 12 | /** 13 | * @author Adam Warski (adam at warski dot org) 14 | */ 15 | public abstract class AbstractHibernateTest extends Arquillian { 16 | private EntityManagerFactory emf; 17 | private Ejb3Configuration cfg; 18 | 19 | @BeforeClass 20 | public void init() throws IOException { 21 | cfg = new Ejb3Configuration(); 22 | cfg.configure("hibernate.test.cfg.xml"); 23 | configure(cfg); 24 | emf = cfg.buildEntityManagerFactory(); 25 | } 26 | 27 | protected abstract void configure(Ejb3Configuration cfg); 28 | 29 | @AfterClass 30 | public void close() { 31 | emf.close(); 32 | } 33 | 34 | public EntityManager newEntityManager() { 35 | return emf.createEntityManager(); 36 | } 37 | 38 | public EntityManager newReadOnlyEntityManager() { 39 | EntityManager em = newEntityManager(); 40 | EntityManagerUtil.makeEntityManagerReadOnly(em); 41 | 42 | return em; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/autofactory/extension/AutoFactoryExtension.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.autofactory.extension; 2 | 3 | import com.softwaremill.common.cdi.autofactory.CreatedWith; 4 | 5 | import javax.enterprise.event.Observes; 6 | import javax.enterprise.inject.spi.*; 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | /** 11 | * @author Adam Warski (adam at warski dot org) 12 | */ 13 | public class AutoFactoryExtension implements Extension { 14 | private Set factoryBeansToAdd = new HashSet(); 15 | 16 | public void processAnnotatedType(@Observes ProcessAnnotatedType event, BeanManager beanManager) { 17 | CreatedWith createdWithAnnotation = event.getAnnotatedType().getAnnotation(CreatedWith.class); 18 | if (createdWithAnnotation != null) { 19 | factoryBeansToAdd.add(new AutoFactoryFromCreatedWithCreator(beanManager, createdWithAnnotation, event) 20 | .create()); 21 | 22 | // This class shouldn't be treated normally, as it contains a constructor with @Inject, where 23 | // not all of the arguments can be injected from the bean manager. 24 | event.veto(); 25 | } 26 | } 27 | 28 | public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd) { 29 | for (Bean bean : factoryBeansToAdd) { 30 | abd.addBean(bean); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /softwaremill-util/src/main/java/com/softwaremill/common/util/stringsorting/SortedCharsToConsecutiveCharsAssigner.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.stringsorting; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | /** 6 | * @author Adam Warski (adam at warski dot org) 7 | */ 8 | public class SortedCharsToConsecutiveCharsAssigner { 9 | public static void main(String[] args) { 10 | String sortedChars = "!@#$%^&*()_+-={}[]:|\";'\\,./<>?~`0123456789aąäbcćdeęfghijklłmnńoóöpqrsśßtuüvwxyzżź"; 11 | 12 | // Starting character from which we will start assigning the sorted chars consecutive characters 13 | byte current = 32; 14 | int max_c = 0; 15 | StringBuilder sb = new StringBuilder(); 16 | Charset charset = Charset.forName("UTF-8"); 17 | 18 | for (char c : sortedChars.toCharArray()) { 19 | if (c > max_c) max_c = c; 20 | sb.append("CONVERSION[") 21 | .append((int) c) 22 | .append("] = '") 23 | .append(new String(new byte[]{current}, charset)) 24 | .append("'; // ") 25 | .append(c) 26 | .append(" = ") 27 | .append(current) 28 | .append("\n"); 29 | current++; 30 | } 31 | 32 | System.out.println("char[] CONVERSION = new char[" + (max_c+1) + "];"); 33 | System.out.println(sb.toString()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /softwaremill-sqs/README.md: -------------------------------------------------------------------------------- 1 | # SQS utilities 2 | 3 | Maven dependency: 4 | 5 | 6 | com.softwaremill.common 7 | softwaremill-sqs 8 | ... 9 | 10 | 11 | ## Background job executor 12 | 13 | A utility for scheduling and executing background jobs. The messaging system used is SQS. 14 | 15 | To use, first implement a `Task` and `TaskExecutor` (describing what the job is and how to run it). See `SendEmailTask` 16 | for an example. Instances of `Task` are serialized and sent to the queue. During execution, they are passed to the 17 | appropriate `TaskExecutor`. 18 | 19 | Second, create an EJB: 20 | 21 | @Stateless 22 | @LocalBinding(jndiBinding = "MyAppSQSTaskTimerBean") 23 | public class MyAppSQSTaskTimerBean extends SQSTaskTimerBean { } 24 | 25 | You will need to run the `startTimer()` method on this EJB when your application starts, to kick off the timer. This can 26 | be done for example in a `web.xml` servlet context listener. 27 | 28 | You can now schedule jobs by running: 29 | 30 | MyAppSQSTaskTimerBean.scheduleTask(task) 31 | 32 | Configuration of SQS access is done through the `sqs.conf` file. Minimal contents of this file: 33 | 34 | AWSAccessKeyId= 35 | SecretAccessKey= 36 | queue= 37 | 38 | To additionaly send e-mails using the `SendEmailTask`: 39 | 40 | smtpHost= 41 | smtpPort= 42 | from= 43 | encoding=UTF-8 -------------------------------------------------------------------------------- /softwaremill-test/softwaremill-test-ui-web/src/main/java/com/softwaremill/common/test/web/selenium/SeleniumBrowserProperties.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.test.web.selenium; 2 | 3 | /** 4 | * Properties for selenium browser 5 | * 6 | * @author maciek 7 | */ 8 | public class SeleniumBrowserProperties { 9 | 10 | private String browserCommand; 11 | 12 | private String browserURL; 13 | 14 | private String browserPort; 15 | 16 | /** 17 | * @param browserCommand For example "*firefox" 18 | * @param browserURL 19 | * @param browserPort 20 | */ 21 | public SeleniumBrowserProperties(String browserCommand, String browserURL, String browserPort) { 22 | this.browserCommand = browserCommand; 23 | this.browserURL = browserURL; 24 | this.browserPort = browserPort; 25 | } 26 | 27 | public String getBrowserCommand() { 28 | return browserCommand; 29 | } 30 | 31 | public void setBrowserCommand(String browserCommand) { 32 | this.browserCommand = browserCommand; 33 | } 34 | 35 | public String getBrowserURL() { 36 | return browserURL; 37 | } 38 | 39 | public void setBrowserURL(String browserURL) { 40 | this.browserURL = browserURL; 41 | } 42 | 43 | public String getBrowserPort() { 44 | return browserPort; 45 | } 46 | 47 | public void setBrowserPort(String browserPort) { 48 | this.browserPort = browserPort; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /softwaremill-faces/src/main/java/com/softwaremill/common/faces/fileupload/FileUpload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * net/balusc/jsf/component/html/HtmlInputFile.java 3 | * 4 | * Copyright (C) 2009 BalusC 5 | * 6 | * This program is free software: you can redistribute it and/or modify it under the terms of the 7 | * GNU Lesser General Public License as published by the Free Software Foundation, either version 3 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 11 | * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public License along with this library. 15 | * If not, see . 16 | */ 17 | 18 | package com.softwaremill.common.faces.fileupload; 19 | 20 | import javax.faces.component.FacesComponent; 21 | import javax.faces.component.html.HtmlInputText; 22 | 23 | /** 24 | * Faces component for input type="file" field. 25 | * 26 | * @author BalusC 27 | * @link http://balusc.blogspot.com/2009/12/uploading-files-with-jsf-20-and-servlet.html 28 | */ 29 | @FacesComponent("FileUpload") 30 | public class FileUpload extends HtmlInputText { 31 | 32 | @Override 33 | public String getRendererType() { 34 | return "javax.faces.File"; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /softwaremill-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | softwaremill-common-parent 6 | com.softwaremill.common 7 | 81-SNAPSHOT 8 | 9 | 10 | softwaremill-test 11 | Softwaremill Test 12 | pom 13 | 14 | 15 | UTF-8 16 | 17 | 18 | 19 | softwaremill-test-util 20 | softwaremill-test-db 21 | softwaremill-test-ui-web 22 | softwaremill-test-ui-swing 23 | softwaremill-test-arquillian 24 | softwaremill-test-server 25 | 26 | 27 | 28 | 29 | org.testng 30 | testng 31 | 32 | 33 | org.mockito 34 | mockito-core 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/test/java/com/softwaremill/common/cdi/security/SecureResultTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import org.jboss.arquillian.container.test.api.Deployment; 4 | import org.jboss.arquillian.testng.Arquillian; 5 | import org.jboss.shrinkwrap.api.ShrinkWrap; 6 | import org.jboss.shrinkwrap.api.spec.JavaArchive; 7 | import org.testng.annotations.Test; 8 | import com.softwaremill.common.cdi.el.ELEvaluator; 9 | import com.softwaremill.common.cdi.util.ArquillianUtil; 10 | 11 | import javax.inject.Inject; 12 | 13 | /** 14 | * @author Adam Warski (adam at warski dot org) 15 | */ 16 | public class SecureResultTest extends Arquillian { 17 | @Deployment 18 | public static JavaArchive createTestArchive() { 19 | JavaArchive ar = ShrinkWrap.create(JavaArchive.class, "test.jar") 20 | .addPackage(SecureResultTest.class.getPackage()) 21 | .addPackage(SecureResult.class.getPackage()) 22 | .addPackage(ELEvaluator.class.getPackage()); 23 | 24 | ar = ArquillianUtil.addTestBeansXml(ar); 25 | 26 | return ar; 27 | } 28 | 29 | @Inject 30 | private SecureResultBean secureResultBean; 31 | 32 | @Test 33 | public void testDirectSecurePass() { 34 | secureResultBean.method1("a"); 35 | } 36 | 37 | @Test(expectedExceptions = SecurityConditionException.class) 38 | public void testDirectSecureFail() { 39 | secureResultBean.method1("b"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /softwaremill-cdi/src/main/java/com/softwaremill/common/cdi/security/SecurityResultInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.cdi.security; 2 | 3 | import com.google.common.collect.ImmutableMap; 4 | import com.softwaremill.common.cdi.el.ELEvaluator; 5 | 6 | import javax.inject.Inject; 7 | import javax.interceptor.AroundInvoke; 8 | import javax.interceptor.Interceptor; 9 | import javax.interceptor.InvocationContext; 10 | import java.io.Serializable; 11 | 12 | /** 13 | * @author Adam Warski (adam at warski dot org) 14 | */ 15 | @Interceptor 16 | @SecureResult("") 17 | public class SecurityResultInterceptor implements Serializable { 18 | @Inject 19 | private ELEvaluator elEvaluator; 20 | 21 | @AroundInvoke 22 | public Object invoke(InvocationContext ctx) throws Exception { 23 | 24 | // Getting the result 25 | Object result = ctx.proceed(); 26 | 27 | // And checking the condition 28 | SecureResult sr = ctx.getMethod().getAnnotation(SecureResult.class); 29 | Boolean expressionValue = evaluateSecureResultExp(result, sr); 30 | 31 | if (expressionValue == null || !expressionValue) { 32 | // TODO: message 33 | throw new SecurityConditionException(); 34 | } 35 | 36 | return result; 37 | } 38 | 39 | public Boolean evaluateSecureResultExp(Object base, SecureResult secureResult) { 40 | return elEvaluator.evaluate(secureResult.value(), Boolean.class, ImmutableMap.of("result", base)); 41 | } 42 | } -------------------------------------------------------------------------------- /softwaremill-util/src/test/java/com/softwaremill/common/util/stringsorting/ByteByByteStringComparatorTest.java: -------------------------------------------------------------------------------- 1 | package com.softwaremill.common.util.stringsorting; 2 | 3 | import org.testng.annotations.DataProvider; 4 | import org.testng.annotations.Test; 5 | 6 | import static org.assertj.core.api.Assertions.assertThat; 7 | 8 | /** 9 | * @author Adam Warski (adam at warski dot org) 10 | */ 11 | public class ByteByByteStringComparatorTest { 12 | @Test(dataProvider="CompareSortableStringRepresentationsData") 13 | public void testCompareSortableStringRepresentations(String s1, String s2, int expectedResult) { 14 | // Given 15 | String rep1 = new StringToByteSortableRepresentationConverter(s1).convertWithLowercase(); 16 | String rep2 = new StringToByteSortableRepresentationConverter(s2).convertWithLowercase(); 17 | 18 | // When 19 | int result = new ByteByByteStringComparator().compare(rep1, rep2); 20 | 21 | // Then 22 | assertThat(Integer.signum(result)).isEqualTo(expectedResult); 23 | } 24 | 25 | @DataProvider(name = "CompareSortableStringRepresentationsData") 26 | public Object[][] getCompareSortableStringRepresentationsData() { 27 | return new Object[][] { 28 | new Object[] { "a", "a", 0 }, 29 | new Object[] { "aaa", "a", 1 }, 30 | new Object[] { "Ż", "ź", -1 }, 31 | new Object[] { "źa", "źb", -1 }, 32 | new Object[] { "£", "a", -1 }, 33 | }; 34 | } 35 | } 36 | --------------------------------------------------------------------------------