Skip to content

Commit cdee973

Browse files
committed
Merge branch 'master' into stream-foreach-ifelse-logic
2 parents 9b6a043 + 2224e72 commit cdee973

285 files changed

Lines changed: 5184 additions & 1498 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎algorithms/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@
2424
- [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity)
2525
- [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element)
2626
- [An Introduction to the Theory of Big-O Notation](http://www.baeldung.com/big-o-notation)
27+
- [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap)
28+
- [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points)
29+
- [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines)
30+
- [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters)

‎asciidoctor/README.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
### Relevant articles
22

3-
- [Introduction to Asciidoctor](http://www.baeldung.com/introduction-to-asciidoctor)
43
- [Generating a Book with Asciidoctor](http://www.baeldung.com/asciidoctor-book)
54
- [Introduction to Asciidoctor in Java](http://www.baeldung.com/asciidoctor)

‎asciidoctor/pom.xml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@
6161
</build>
6262

6363
<properties>
64-
<asciidoctor-maven-plugin.version>1.5.5</asciidoctor-maven-plugin.version>
65-
<asciidoctorj.version>1.5.4</asciidoctorj.version>
66-
<asciidoctorj-pdf.src.version>1.5.0-alpha.11</asciidoctorj-pdf.src.version>
64+
<asciidoctor-maven-plugin.version>1.5.6</asciidoctor-maven-plugin.version>
65+
<asciidoctorj.version>1.5.6</asciidoctorj.version>
66+
67+
<asciidoctorj-pdf.version>1.5.0-alpha.15</asciidoctorj-pdf.version>
6768
<asciidoctorj-pdf.plugin.version>1.5.0-alpha.15</asciidoctorj-pdf.plugin.version>
6869
</properties>
6970

asciidoctor/src/test/java/com/baeldung/asciidoctor/AsciidoctorDemoTest.java renamed to asciidoctor/src/test/java/com/baeldung/asciidoctor/AsciidoctorDemoIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import org.junit.Assert;
44
import org.junit.Test;
55

6-
public class AsciidoctorDemoTest {
6+
public class AsciidoctorDemoIntegrationTest {
77

88
@Test
99
public void givenString_whenConverting_thenResultingHTMLCode() {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<artifactId>flyway-cdi</artifactId>
8+
9+
<parent>
10+
<groupId>com.baeldung</groupId>
11+
<artifactId>cdi-portable-extension</artifactId>
12+
<version>1.0-SNAPSHOT</version>
13+
</parent>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>javax.enterprise</groupId>
18+
<artifactId>cdi-api</artifactId>
19+
<version>2.0.SP1</version>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.flywaydb</groupId>
23+
<artifactId>flyway-core</artifactId>
24+
<version>5.1.4</version>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.apache.tomcat</groupId>
28+
<artifactId>tomcat-jdbc</artifactId>
29+
<version>8.5.33</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>javax.annotation</groupId>
33+
<artifactId>javax.annotation-api</artifactId>
34+
<version>1.3.2</version>
35+
</dependency>
36+
</dependencies>
37+
38+
</project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.baeldung.cdi.extension;
2+
3+
import org.apache.tomcat.jdbc.pool.DataSource;
4+
import org.flywaydb.core.Flyway;
5+
6+
import javax.annotation.sql.DataSourceDefinition;
7+
import javax.enterprise.context.ApplicationScoped;
8+
import javax.enterprise.event.Observes;
9+
import javax.enterprise.inject.Any;
10+
import javax.enterprise.inject.Default;
11+
import javax.enterprise.inject.literal.InjectLiteral;
12+
import javax.enterprise.inject.spi.*;
13+
import javax.enterprise.util.AnnotationLiteral;
14+
15+
16+
/**
17+
* Flyway is now under CDI container like:
18+
*
19+
* @ApplicationScoped
20+
* @FlywayType public class Flyway{
21+
* @Inject setDataSource(DataSource dataSource){
22+
* //...
23+
* }
24+
* }
25+
*/
26+
27+
public class FlywayExtension implements Extension {
28+
29+
DataSourceDefinition dataSourceDefinition = null;
30+
31+
public void registerFlywayType(@Observes BeforeBeanDiscovery bbdEvent) {
32+
bbdEvent.addAnnotatedType(Flyway.class, Flyway.class.getName());
33+
}
34+
35+
public void detectDataSourceDefinition(@Observes @WithAnnotations(DataSourceDefinition.class) ProcessAnnotatedType<?> patEvent) {
36+
AnnotatedType at = patEvent.getAnnotatedType();
37+
dataSourceDefinition = at.getAnnotation(DataSourceDefinition.class);
38+
}
39+
40+
public void processAnnotatedType(@Observes ProcessAnnotatedType<Flyway> patEvent) {
41+
patEvent.configureAnnotatedType()
42+
//Add Scope
43+
.add(ApplicationScoped.Literal.INSTANCE)
44+
//Add Qualifier
45+
.add(new AnnotationLiteral<FlywayType>() {
46+
})
47+
//Decorate setDataSource(DataSource dataSource){} with @Inject
48+
.filterMethods(annotatedMethod -> {
49+
return annotatedMethod.getParameters().size() == 1 &&
50+
annotatedMethod.getParameters().get(0).getBaseType().equals(javax.sql.DataSource.class);
51+
})
52+
.findFirst().get().add(InjectLiteral.INSTANCE);
53+
}
54+
55+
void afterBeanDiscovery(@Observes AfterBeanDiscovery abdEvent, BeanManager bm) {
56+
abdEvent.addBean()
57+
.types(javax.sql.DataSource.class, DataSource.class)
58+
.qualifiers(new AnnotationLiteral<Default>() {}, new AnnotationLiteral<Any>() {})
59+
.scope(ApplicationScoped.class)
60+
.name(DataSource.class.getName())
61+
.beanClass(DataSource.class)
62+
.createWith(creationalContext -> {
63+
DataSource instance = new DataSource();
64+
instance.setUrl(dataSourceDefinition.url());
65+
instance.setDriverClassName(dataSourceDefinition.className());
66+
return instance;
67+
});
68+
}
69+
70+
void runFlywayMigration(@Observes AfterDeploymentValidation adv, BeanManager manager) {
71+
Flyway flyway = manager.createInstance().select(Flyway.class, new AnnotationLiteral<FlywayType>() {}).get();
72+
flyway.migrate();
73+
}
74+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.cdi.extension;
2+
3+
import javax.inject.Qualifier;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
import static java.lang.annotation.ElementType.*;
9+
10+
@Retention(RetentionPolicy.RUNTIME)
11+
@Target({FIELD, METHOD, PARAMETER, TYPE})
12+
@Qualifier
13+
public @interface FlywayType {
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<beans version="2.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
4+
http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
5+
bean-discovery-mode="annotated">
6+
</beans>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
com.baeldung.cdi.extension.FlywayExtension
2+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<artifactId>main-app</artifactId>
8+
<packaging>jar</packaging>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>cdi-portable-extension</artifactId>
13+
<version>1.0-SNAPSHOT</version>
14+
</parent>
15+
16+
<dependencies>
17+
18+
<dependency>
19+
<groupId>javax.enterprise</groupId>
20+
<artifactId>cdi-api</artifactId>
21+
<version>2.0.SP1</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.jboss.weld.se</groupId>
25+
<artifactId>weld-se-core</artifactId>
26+
<version>3.0.5.Final</version>
27+
<scope>runtime</scope>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>com.baeldung</groupId>
32+
<artifactId>flyway-cdi</artifactId>
33+
<version>1.0-SNAPSHOT</version>
34+
<scope>runtime</scope>
35+
</dependency>
36+
37+
<dependency>
38+
<groupId>com.h2database</groupId>
39+
<artifactId>h2</artifactId>
40+
<version>1.4.197</version>
41+
<scope>runtime</scope>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>javax.annotation</groupId>
46+
<artifactId>javax.annotation-api</artifactId>
47+
<version>1.3.2</version>
48+
</dependency>
49+
50+
</dependencies>
51+
52+
</project>

0 commit comments

Comments
 (0)