diff --git a/apache-cxf-modules/cxf-spring/pom.xml b/apache-cxf-modules/cxf-spring/pom.xml index 1c87ae4bfb..67a61e8200 100644 --- a/apache-cxf-modules/cxf-spring/pom.xml +++ b/apache-cxf-modules/cxf-spring/pom.xml @@ -43,19 +43,19 @@ <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-ri</artifactId> - <version>2.3.3</version> + <version>${jaxws-ri.version}</version> <type>pom</type> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> - <version>4.0.1</version> + <version>${javax.servlet-api.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> - <version>1.2</version> + <version>${jstl.version}</version> </dependency> </dependencies> @@ -117,7 +117,9 @@ <properties> <spring.version>5.3.25</spring.version> <cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> + <jstl.version>1.2</jstl.version> + <javax.servlet-api.version>4.0.1</javax.servlet-api.version> + <jaxws-ri.version>2.3.3</jaxws-ri.version> </properties> </project> \ No newline at end of file diff --git a/apache-httpclient4/pom.xml b/apache-httpclient4/pom.xml index 21c675db35..f4c213687e 100644 --- a/apache-httpclient4/pom.xml +++ b/apache-httpclient4/pom.xml @@ -241,8 +241,6 @@ <httpcore.version>4.4.16</httpcore.version> <httpclient.version>4.5.14</httpclient.version> <mockserver.version>5.11.2</mockserver.version> - <!-- maven plugins --> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/apache-libraries-2/pom.xml b/apache-libraries-2/pom.xml index 618ff4a188..d188204208 100644 --- a/apache-libraries-2/pom.xml +++ b/apache-libraries-2/pom.xml @@ -21,7 +21,6 @@ </dependency> </dependencies> - <properties> <javax.validation.validation-api.version>2.0.1.Final</javax.validation.validation-api.version> </properties> diff --git a/apache-libraries-2/src/main/java/com/baeldung/xsltProcessing/XSLTProcessorWithParametersAndOption.java b/apache-libraries-2/src/main/java/com/baeldung/xsltProcessing/XSLTProcessorWithParametersAndOption.java new file mode 100644 index 0000000000..07efab080d --- /dev/null +++ b/apache-libraries-2/src/main/java/com/baeldung/xsltProcessing/XSLTProcessorWithParametersAndOption.java @@ -0,0 +1,31 @@ +package com.baeldung.xsltProcessing; + +import javax.xml.transform.*; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import java.io.File; + +public class XSLTProcessorWithParametersAndOption { + public static void transformXMLWithParametersAndOption( + String inputXMLPath, + String xsltPath, + String outputHTMLPath, + String companyName, + boolean enableIndentation + ) throws TransformerException { + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Source xsltSource = new StreamSource(new File(xsltPath)); + Transformer transformer = transformerFactory.newTransformer(xsltSource); + + transformer.setParameter("companyName", companyName); + + if (enableIndentation) { + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + } + + Source xmlSource = new StreamSource(new File(inputXMLPath)); + Result outputResult = new StreamResult(new File(outputHTMLPath)); + + transformer.transform(xmlSource, outputResult); + } +} diff --git a/apache-libraries-2/src/main/java/com/baeldung/xsltProcessing/XSLTProcessorWithTemplate.java b/apache-libraries-2/src/main/java/com/baeldung/xsltProcessing/XSLTProcessorWithTemplate.java new file mode 100644 index 0000000000..017fc0db8b --- /dev/null +++ b/apache-libraries-2/src/main/java/com/baeldung/xsltProcessing/XSLTProcessorWithTemplate.java @@ -0,0 +1,21 @@ +package com.baeldung.xsltProcessing; + +import javax.xml.transform.*; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import java.io.File; + +public class XSLTProcessorWithTemplate { + public static void transformXMLUsingTemplate(String inputXMLPath, String xsltPath, String outputHTMLPath) throws TransformerException { + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + Source xsltSource = new StreamSource(new File(xsltPath)); + Templates templates = transformerFactory.newTemplates(xsltSource); + + Transformer transformer = templates.newTransformer(); + + Source xmlSource = new StreamSource(new File(inputXMLPath)); + Result outputResult = new StreamResult(new File(outputHTMLPath)); + + transformer.transform(xmlSource, outputResult); + } +} diff --git a/apache-velocity/pom.xml b/apache-velocity/pom.xml index a562ebeec0..f4b6de8872 100644 --- a/apache-velocity/pom.xml +++ b/apache-velocity/pom.xml @@ -63,7 +63,6 @@ <org.apache.httpcomponents.version>4.5.2</org.apache.httpcomponents.version> <velocity-version>1.7</velocity-version> <velocity-tools-version>2.0</velocity-tools-version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/asm/pom.xml b/asm/pom.xml index f1e60d2560..4edfe86ae5 100644 --- a/asm/pom.xml +++ b/asm/pom.xml @@ -49,7 +49,6 @@ <properties> <asm.version>5.2</asm.version> - <maven-jar-plugin.version>2.4</maven-jar-plugin.version> </properties> </project> \ No newline at end of file diff --git a/aws-modules/aws-s3-update-object/pom.xml b/aws-modules/aws-s3-update-object/pom.xml index 574a63977b..3cf7b657b0 100644 --- a/aws-modules/aws-s3-update-object/pom.xml +++ b/aws-modules/aws-s3-update-object/pom.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>aws-s3-update-object</artifactId> <version>0.0.1-SNAPSHOT</version> diff --git a/aws-modules/aws-s3/pom.xml b/aws-modules/aws-s3/pom.xml index 157aeb671d..e2bc04964a 100644 --- a/aws-modules/aws-s3/pom.xml +++ b/aws-modules/aws-s3/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>aws-s3</artifactId> <version>0.1.0-SNAPSHOT</version> diff --git a/azure/pom.xml b/azure/pom.xml index aae84db0c6..6a06282a71 100644 --- a/azure/pom.xml +++ b/azure/pom.xml @@ -122,7 +122,6 @@ <docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix> <docker-maven-plugin.version>1.1.0</docker-maven-plugin.version> <azure-webapp-maven-plugin.version>1.1.0</azure-webapp-maven-plugin.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/core-groovy-modules/pom.xml b/core-groovy-modules/pom.xml index 6faa7f94c8..4fdaf3ee7a 100644 --- a/core-groovy-modules/pom.xml +++ b/core-groovy-modules/pom.xml @@ -27,6 +27,7 @@ <hsqldb.version>2.7.1</hsqldb.version> <spock-core.version>2.3-groovy-3.0</spock-core.version> <gmavenplus-plugin.version>2.1.0</gmavenplus-plugin.version> + <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version> </properties> </project> diff --git a/core-java-modules/core-java-14/pom.xml b/core-java-modules/core-java-14/pom.xml index 9f48c0b8b2..55c50b2a5c 100644 --- a/core-java-modules/core-java-14/pom.xml +++ b/core-java-modules/core-java-14/pom.xml @@ -48,7 +48,6 @@ <properties> <maven.compiler.release>14</maven.compiler.release> - <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version> <surefire.plugin.version>3.0.0-M3</surefire.plugin.version> </properties> diff --git a/core-java-modules/core-java-15/pom.xml b/core-java-modules/core-java-15/pom.xml index 059e2cc8f3..3ac45d26ba 100644 --- a/core-java-modules/core-java-15/pom.xml +++ b/core-java-modules/core-java-15/pom.xml @@ -53,7 +53,6 @@ <properties> <maven.compiler.release>15</maven.compiler.release> - <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version> <surefire.plugin.version>3.0.0-M3</surefire.plugin.version> </properties> diff --git a/core-java-modules/core-java-9-new-features/pom.xml b/core-java-modules/core-java-9-new-features/pom.xml index 6821c9c340..9c897f1cea 100644 --- a/core-java-modules/core-java-9-new-features/pom.xml +++ b/core-java-modules/core-java-9-new-features/pom.xml @@ -152,7 +152,6 @@ <awaitility.version>4.0.2</awaitility.version> <maven.compiler.source>1.9</maven.compiler.source> <maven.compiler.target>1.9</maven.compiler.target> - <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version> </properties> </project> \ No newline at end of file diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java b/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java new file mode 100644 index 0000000000..f389893209 --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraymiddle/MiddleOfArray.java @@ -0,0 +1,65 @@ +package com.baeldung.arraymiddle; + +import java.util.Arrays; + +import org.apache.commons.lang3.ObjectUtils; + +public class MiddleOfArray { + int[] middleOfArray(int[] array) { + if (ObjectUtils.isEmpty(array) || array.length < 3) + return array; + int n = array.length; + int mid = n / 2; + if (n % 2 == 0) { + int mid2 = mid - 1; + return new int[] { array[mid2], array[mid] }; + } else { + return new int[] { array[mid] }; + } + } + + int[] middleOfArrayWithStartEndNaive(int[] array, int start, int end) { + int mid = (start + end) / 2; + int n = end - start; + if (n % 2 == 0) { + int mid2 = mid - 1; + return new int[] { array[mid2], array[mid] }; + } else { + return new int[] { array[mid] }; + } + } + + int[] middleOfArrayWithStartEnd(int[] array, int start, int end) { + int mid = start + (end - start) / 2; + int n = end - start; + if (n % 2 == 0) { + int mid2 = mid - 1; + return new int[] { array[mid2], array[mid] }; + } else { + return new int[] { array[mid] }; + } + } + + int[] middleOfArrayWithStartEndBitwise(int[] array, int start, int end) { + int mid = (start + end) >>> 1; + int n = end - start; + if (n % 2 == 0) { + int mid2 = mid - 1; + return new int[] { array[mid2], array[mid] }; + } else { + return new int[] { array[mid] }; + } + } + + int medianOfArray(int[] array, int start, int end) { + Arrays.sort(array); // for safety. This can be ignored + int mid = (start + end) >>> 1; + int n = end - start; + if (n % 2 == 0) { + int mid2 = mid - 1; + return (array[mid2] + array[mid]) / 2; + } else { + return array[mid]; + } + } +} diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java new file mode 100644 index 0000000000..706412d83e --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraymiddle/MiddleOfArrayUnitTest.java @@ -0,0 +1,89 @@ +package com.baeldung.arraymiddle; + +import org.junit.Assert; +import org.junit.Test; + +public class MiddleOfArrayUnitTest { + + @Test + public void givenArrayOfEvenLength_whenMiddleOfArray_thenReturn2Values() { + int[] array = new int[100]; + for (int i = 0; i < array.length; i++) { + array[i] = i + 1; + } + int[] expectedMidArray = { 50, 51 }; + MiddleOfArray middleOfArray = new MiddleOfArray(); + Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArray(array)); + } + + @Test + public void givenArrayOfEdgeCaseLength_whenMiddleOfArray_thenReturn2Values() { + int[] array = new int[0]; + int[] expectedMidArray = new int[0]; + MiddleOfArray middleOfArray = new MiddleOfArray(); + Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArray(array)); + + array = new int[] { 1, 2 }; + expectedMidArray = new int[] { 1, 2 }; + + Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArray(array)); + } + + @Test + public void givenArrayOfOddLength_whenMiddleOfArray_thenReturnMid() { + int[] array = new int[99]; + for (int i = 0; i < array.length; i++) { + array[i] = i + 1; + } + int[] expectedMidArray = { 50 }; + MiddleOfArray middleOfArray = new MiddleOfArray(); + Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArray(array)); + } + + @Test + public void givenArrayWithStartAndEnd_whenMiddleOfArray_thenReturnMid() { + int[] array = new int[100]; + for (int i = 0; i < array.length; i++) { + array[i] = i + 1; + } + int[] expectedMidArray = { 58 }; + MiddleOfArray middleOfArray = new MiddleOfArray(); + Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArrayWithStartEndNaive(array, 55, 60)); + + expectedMidArray = new int[] { 58, 59 }; + Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArrayWithStartEndNaive(array, 56, 60)); + } + + @Test + public void givenArrayWithStartAndEndOptimized_whenMiddleOfArray_thenReturnMid() { + int[] array = new int[100]; + for (int i = 0; i < array.length; i++) { + array[i] = i + 1; + } + int[] expectedMidArray = { 78 }; + MiddleOfArray middleOfArray = new MiddleOfArray(); + Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArrayWithStartEnd(array, 55, 100)); + } + + @Test + public void givenArrayWithStartAndEndBitwise_whenMiddleOfArray_thenReturnMid() { + int[] array = new int[100]; + for (int i = 0; i < array.length; i++) { + array[i] = i + 1; + } + int[] expectedMidArray = { 78 }; + MiddleOfArray middleOfArray = new MiddleOfArray(); + Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArrayWithStartEndBitwise(array, 55, 100)); + } + + @Test + public void givenArrayWithStartAndEnd_whenMedianOfArray_thenReturnMid() { + int[] array = new int[100]; + for (int i = 0; i < array.length; i++) { + array[i] = i + 1; + } + int expectMedian = 50; + MiddleOfArray middleOfArray = new MiddleOfArray(); + Assert.assertEquals(expectMedian, middleOfArray.medianOfArray(array, 0, 100)); + } +} diff --git a/core-java-modules/core-java-collections-list-5/pom.xml b/core-java-modules/core-java-collections-list-5/pom.xml index bcdb6824ed..2b4b0041b3 100644 --- a/core-java-modules/core-java-collections-list-5/pom.xml +++ b/core-java-modules/core-java-collections-list-5/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>core-java-collections-list-5</artifactId> <name>core-java-collections-list-5</name> diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/DataQueue.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/DataQueue.java index 8867ddeb63..8b6f02b529 100644 --- a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/DataQueue.java +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/DataQueue.java @@ -58,4 +58,8 @@ public class DataQueue { return queue.poll(); } } + + public Integer getSize() { + return queue.size(); + } } diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Producer.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Producer.java index 5ca60a29e4..069476bbd1 100644 --- a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Producer.java +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/Producer.java @@ -1,12 +1,13 @@ package com.baeldung.producerconsumer; +import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Logger; public class Producer implements Runnable { private static final Logger log = Logger.getLogger(Producer.class.getCanonicalName()); private final DataQueue dataQueue; - private static int idSequence = 0; + final ReentrantLock lock = new ReentrantLock(); public Producer(DataQueue dataQueue) { this.dataQueue = dataQueue; @@ -19,22 +20,38 @@ public class Producer implements Runnable { public void produce() { while (dataQueue.runFlag) { - while (dataQueue.isFull() && dataQueue.runFlag) { - try { - dataQueue.waitOnFull(); - } catch (InterruptedException e) { - e.printStackTrace(); + + try { + lock.lock(); + + while (dataQueue.isFull() && dataQueue.runFlag) { + try { + dataQueue.waitOnFull(); + } catch (InterruptedException e) { + e.printStackTrace(); + break; + } + } + + if (!dataQueue.runFlag) { break; } - } - if (!dataQueue.runFlag) { - break; - } - Message message = generateMessage(); - dataQueue.add(message); - dataQueue.notifyAllForEmpty(); + Message message = generateMessage(); + dataQueue.add(message); + dataQueue.notifyAllForEmpty(); + + log.info("Size of the queue is: " + dataQueue.getSize()); + + } + finally{ + lock.unlock(); + } + + //Sleeping on random time to make it realistic + ThreadUtil.sleep((long) (Math.random() * 100)); } + log.info("Producer Stopped"); } @@ -43,9 +60,6 @@ public class Producer implements Runnable { log.info(String.format("[%s] Generated Message. Id: %d, Data: %f%n", Thread.currentThread().getName(), message.getId(), message.getData())); - //Sleeping on random time to make it realistic - ThreadUtil.sleep((long) (message.getData() * 100)); - return message; } diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/ProducerConsumerDemonstrator.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/ProducerConsumerDemonstrator.java index 96d7b9f865..eac026536d 100644 --- a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/ProducerConsumerDemonstrator.java +++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/ProducerConsumerDemonstrator.java @@ -36,8 +36,8 @@ public class ProducerConsumerDemonstrator { public static void demoMultipleProducersAndMultipleConsumers() { DataQueue dataQueue = new DataQueue(MAX_QUEUE_CAPACITY); - int producerCount = 3; - int consumerCount = 3; + int producerCount = 5; + int consumerCount = 5; List<Thread> threads = new ArrayList<>(); Producer producer = new Producer(dataQueue); for(int i = 0; i < producerCount; i++) { @@ -45,6 +45,7 @@ public class ProducerConsumerDemonstrator { producerThread.start(); threads.add(producerThread); } + Consumer consumer = new Consumer(dataQueue); for(int i = 0; i < consumerCount; i++) { Thread consumerThread = new Thread(consumer); @@ -52,8 +53,8 @@ public class ProducerConsumerDemonstrator { threads.add(consumerThread); } - // let threads run for two seconds - sleep(2000); + // let threads run for ten seconds + sleep(10000); // Stop threads producer.stop(); diff --git a/core-java-modules/core-java-conditionals/pom.xml b/core-java-modules/core-java-conditionals/pom.xml index 2a1290c98e..811f183e99 100644 --- a/core-java-modules/core-java-conditionals/pom.xml +++ b/core-java-modules/core-java-conditionals/pom.xml @@ -37,20 +37,19 @@ <compilerArgs>--enable-preview</compilerArgs> </configuration> </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>${surefire.plugin.version}</version> - <configuration> - <argLine>--enable-preview</argLine> - </configuration> - </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>${surefire.plugin.version}</version> + <configuration> + <argLine>--enable-preview</argLine> + </configuration> + </plugin> </plugins> </build> <properties> <maven.compiler.source.version>14</maven.compiler.source.version> - <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version> <maven.compiler.target.version>14</maven.compiler.target.version> <surefire.plugin.version>3.0.0-M3</surefire.plugin.version> </properties> diff --git a/core-java-modules/core-java-date-operations-3/pom.xml b/core-java-modules/core-java-date-operations-3/pom.xml index 19760ca357..9b7be18b85 100644 --- a/core-java-modules/core-java-date-operations-3/pom.xml +++ b/core-java-modules/core-java-date-operations-3/pom.xml @@ -12,7 +12,7 @@ <artifactId>core-java-modules</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> - + <dependencies> <dependency> <groupId>joda-time</groupId> @@ -25,7 +25,7 @@ <version>${commons-lang3.version}</version> </dependency> </dependencies> - + <properties> <joda-time.version>2.12.5</joda-time.version> <commons-lang3.version>3.12.0</commons-lang3.version> diff --git a/core-java-modules/core-java-date-operations-3/src/main/java/com/baeldung/epochconversion/EpochToLocalDate.java b/core-java-modules/core-java-date-operations-3/src/main/java/com/baeldung/epochconversion/EpochToLocalDate.java new file mode 100644 index 0000000000..574693355d --- /dev/null +++ b/core-java-modules/core-java-date-operations-3/src/main/java/com/baeldung/epochconversion/EpochToLocalDate.java @@ -0,0 +1,24 @@ +package com.baeldung.epochconversion; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; + +public class EpochToLocalDate { + + public static void main(String[] args) { + long millisSinceEpoch = 2131242L; + ZoneId zoneId = ZoneId.of("Europe/Amsterdam"); // or: ZoneId.systemDefault(); + // to get All Zone Ids available, we can use the function below + // Set<String> allZoneIds = ZoneId.getAvailableZoneIds(); + LocalDate date = + Instant.ofEpochMilli(millisSinceEpoch) + .atZone(zoneId) + .toLocalDate(); + LocalDateTime time = + Instant.ofEpochMilli(millisSinceEpoch) + .atZone(zoneId) + .toLocalDateTime(); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-date-operations-3/src/main/java/com/baeldung/epochconversion/LocalDateToEpoch.java b/core-java-modules/core-java-date-operations-3/src/main/java/com/baeldung/epochconversion/LocalDateToEpoch.java new file mode 100644 index 0000000000..b84cd5c1a7 --- /dev/null +++ b/core-java-modules/core-java-date-operations-3/src/main/java/com/baeldung/epochconversion/LocalDateToEpoch.java @@ -0,0 +1,18 @@ +package com.baeldung.epochconversion; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; + +public class LocalDateToEpoch { + + public static void main(String[] args) { + ZoneId zoneId = ZoneId.of("Europe/Amsterdam"); // or: ZoneId.systemDefault() + LocalDate date = LocalDate.now(); + long epochMilliSecondsAtDate = date.atStartOfDay(zoneId).toInstant().toEpochMilli(); + + // epoch for time + LocalDateTime time = LocalDateTime.parse("2019-11-15T13:15:30"); + long epochMilliSecondsAtTime = time.atZone(zoneId).toInstant().toEpochMilli(); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-date-operations-3/src/test/java/com/baeldung/epochconversion/EpochToLocalDateUnitTest.java b/core-java-modules/core-java-date-operations-3/src/test/java/com/baeldung/epochconversion/EpochToLocalDateUnitTest.java new file mode 100644 index 0000000000..90ab056511 --- /dev/null +++ b/core-java-modules/core-java-date-operations-3/src/test/java/com/baeldung/epochconversion/EpochToLocalDateUnitTest.java @@ -0,0 +1,39 @@ +package com.baeldung.epochconversion; + +import org.junit.jupiter.api.Test; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class EpochToLocalDateUnitTest { + + @Test + void givenEpoch_thenComputeLocalDateCorrectly() { + ZoneId zoneId = ZoneId.systemDefault(); + LocalDate expectedDate = LocalDate.of(1995, 4, 15); + long date = expectedDate.atStartOfDay(zoneId).toInstant().toEpochMilli(); + + LocalDate actualDate = + Instant.ofEpochMilli(date) + .atZone(zoneId) + .toLocalDate(); + assertEquals(expectedDate, actualDate); + } + + @Test + void givenEpoch_thenComputeLocalDateTimeCorrectly() { + ZoneId zoneId = ZoneId.systemDefault(); + LocalDateTime expectedTime = LocalDateTime.parse("2019-11-15T13:15:30"); + long time = expectedTime.atZone(zoneId).toInstant().toEpochMilli(); + + LocalDateTime actualTime = + Instant.ofEpochMilli(time) + .atZone(zoneId) + .toLocalDateTime(); + assertEquals(expectedTime, actualTime); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-date-operations-3/src/test/java/com/baeldung/epochconversion/LocalDateTimeToEpochUnitTest.java b/core-java-modules/core-java-date-operations-3/src/test/java/com/baeldung/epochconversion/LocalDateTimeToEpochUnitTest.java new file mode 100644 index 0000000000..8e9a4b01d0 --- /dev/null +++ b/core-java-modules/core-java-date-operations-3/src/test/java/com/baeldung/epochconversion/LocalDateTimeToEpochUnitTest.java @@ -0,0 +1,37 @@ +package com.baeldung.epochconversion; + +import org.junit.jupiter.api.Test; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class LocalDateTimeToEpochUnitTest { + + @Test + void givenDate_thenComputeEpochCorrectly() { + ZoneId zoneId = ZoneId.of("Europe/Tallinn"); + long expectedEpoch = LocalDate.now().toEpochDay(); + LocalDateTime givenDate = Instant.ofEpochMilli(expectedEpoch) + .atZone(zoneId) + .toLocalDateTime(); + + long actualEpoch = givenDate.atZone(zoneId).toInstant().toEpochMilli(); + assertEquals(expectedEpoch, actualEpoch); + } + + @Test + void givenTime_thenComputeEpochCorrectly() { + ZoneId zoneId = ZoneId.of("Europe/Amsterdam"); + long expectedEpoch = Instant.now().toEpochMilli(); + LocalDateTime givenTime = Instant.ofEpochMilli(expectedEpoch) + .atZone(zoneId) + .toLocalDateTime(); + + long actualEpoch = givenTime.atZone(zoneId).toInstant().toEpochMilli(); + assertEquals(expectedEpoch, actualEpoch); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml index 8364f36874..59952c2d9e 100644 --- a/core-java-modules/core-java-io/pom.xml +++ b/core-java-modules/core-java-io/pom.xml @@ -132,7 +132,6 @@ <!-- Mime Type Libraries --> <tika.version>2.8.0</tika.version> <jmime-magic.version>0.1.5</jmime-magic.version> - <maven-jar-plugin.version>3.3.0</maven-jar-plugin.version> <fscontext.version>4.4.2</fscontext.version> <jakarta-activation-api.version>2.1.2</jakarta-activation-api.version> <angus-activation.version>2.0.1</angus-activation.version> diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml index ec88abe444..a46299c669 100644 --- a/core-java-modules/core-java-jar/pom.xml +++ b/core-java-modules/core-java-jar/pom.xml @@ -275,7 +275,6 @@ <!-- maven plugins --> <javamoney.moneta.version>1.1</javamoney.moneta.version> <maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version> - <maven-jar-plugin.version>3.0.2</maven-jar-plugin.version> <onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version> <maven-shade-plugin.version>3.1.1</maven-shade-plugin.version> <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version> diff --git a/core-java-modules/core-java-lang-6/pom.xml b/core-java-modules/core-java-lang-6/pom.xml index 86121e0a7f..53ef36a898 100644 --- a/core-java-modules/core-java-lang-6/pom.xml +++ b/core-java-modules/core-java-lang-6/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://maven.apache.org/POM/4.0.0" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.baeldung.core-java-modules</groupId> diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/stopexecution/InterruptThread.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/stopexecution/InterruptThread.java new file mode 100644 index 0000000000..7964ad9f52 --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/stopexecution/InterruptThread.java @@ -0,0 +1,13 @@ +package com.baeldung.stopexecution; + +public class InterruptThread extends Thread { + @Override + public void run() { + while (!isInterrupted()) { + if (isInterrupted()) { + break; + } + // business logic + } + } +} diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/stopexecution/StopExecutionFurtherCode.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/stopexecution/StopExecutionFurtherCode.java new file mode 100644 index 0000000000..81abe15b5c --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/stopexecution/StopExecutionFurtherCode.java @@ -0,0 +1,87 @@ +package com.baeldung.stopexecution; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Locale; + +public class StopExecutionFurtherCode { + + boolean shouldContinue = true; + + int performTask(int a, int b) { + if (!shouldContinue) { + System.exit(0); + } + return a + b; + } + + void stop() { + this.shouldContinue = false; + } + + int calculateFactorial(int n) { + if (n <= 1) { + return 1; // base case + } + + return n * calculateFactorial(n - 1); + } + + int calculateSum(int[] x) { + int sum = 0; + for (int i = 0; i < 10; i++) { + if (x[i] < 0) { + break; + } + sum += x[i]; + } + return sum; + } + + <T> T stopExecutionUsingException(T object) { + if (object instanceof Number) { + throw new IllegalArgumentException("Parameter can not be number."); + } + T upperCase = (T) String.valueOf(object) + .toUpperCase(Locale.ENGLISH); + return upperCase; + } + + int processLines(String[] lines) { + int statusCode = 0; + parser: + for (String line : lines) { + System.out.println("Processing line: " + line); + if (line.equals("stop")) { + System.out.println("Stopping parsing..."); + statusCode = -1; + break parser; // Stop parsing and exit the loop + } + System.out.println("Line processed."); + } + return statusCode; + } + + void download(String fileUrl, String destinationPath) throws MalformedURLException { + if (fileUrl == null || fileUrl.isEmpty() || destinationPath == null || destinationPath.isEmpty()) { + return; + } + // execute downloading + URL url = new URL(fileUrl); + try (InputStream in = url.openStream(); FileOutputStream out = new FileOutputStream(destinationPath)) { + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = in.read(buffer)) != -1) { + out.write(buffer, 0, bytesRead); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + + +} diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/stopexecution/StopExecutionFurtherCodeUnitTest.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/stopexecution/StopExecutionFurtherCodeUnitTest.java new file mode 100644 index 0000000000..9cdb1e71aa --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/stopexecution/StopExecutionFurtherCodeUnitTest.java @@ -0,0 +1,90 @@ +package com.baeldung.stopexecution; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +import java.net.MalformedURLException; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.jupiter.api.Test; +import org.junit.runners.MethodSorters; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class StopExecutionFurtherCodeUnitTest { + + + @Test + void givenExecution_whenStopIsNotCalled_thenTaskIsPerformed() { + StopExecutionFurtherCode stopExecution = new StopExecutionFurtherCode(); + int performedTask = stopExecution.performTask(10, 20); + Assert.assertEquals(30, performedTask); + } + + // This test case have been commented because, otherwise, the program will exit since System.exit(statusCode) is being used. + /*@Test + void givenExecution_whenStopIsCalled_thenTaskNotPerformed() { + StopExecutionFurtherCode stopExecution = new StopExecutionFurtherCode(); + stopExecution.stop(); + int performedTask = stopExecution.performTask(10, 20); + Assert.assertEquals(30, performedTask); + }*/ + + @Test + void givenWrongUrlAndPath_whenDownloadCalled_thenExecutionIsStopped() throws MalformedURLException { + StopExecutionFurtherCode stopExecutionFurtherCode = new StopExecutionFurtherCode(); + stopExecutionFurtherCode.download("", ""); + } + + @Test + void givenName_whenStopExecutionUsingExceptionCalled_thenNameIsConvertedToUpper() { + StopExecutionFurtherCode stopExecutionFurtherCode = new StopExecutionFurtherCode(); + String name = "John"; + String result1 = stopExecutionFurtherCode.stopExecutionUsingException(name); + Assert.assertEquals("JOHN", result1); + try { + Integer number1 = 10; + Assert.assertThrows(IllegalArgumentException.class, () -> { + int result = stopExecutionFurtherCode.stopExecutionUsingException(number1); + }); + } catch (Exception e) { + Assert.fail("Unexpected exception thrown: " + e.getMessage()); + } + } + + @Test + void givenBaseCase_whenStopExecutionWhenBaseCaseKnownCalled_thenFactorialIsCalculated() throws MalformedURLException { + StopExecutionFurtherCode stopExecutionFurtherCode = new StopExecutionFurtherCode(); + int factorial = stopExecutionFurtherCode.calculateFactorial(1); + Assert.assertEquals(1, factorial); + } + + @Test + void givenArrayWithNegative_whenStopExecutionInLoopCalled_thenSumIsCalculatedIgnoringNegatives() { + StopExecutionFurtherCode stopExecutionFurtherCode = new StopExecutionFurtherCode(); + int[] nums = { 1, 2, 3, -1, 1, 2, 3 }; + int sum = stopExecutionFurtherCode.calculateSum(nums); + Assert.assertEquals(6, sum); + } + + @Test + void givenThreadRunning_whenInterrupted_thenThreadExecutionIsStopped() throws InterruptedException { + InterruptThread stopExecution = new InterruptThread(); + stopExecution.start(); + Thread.sleep(2000); + stopExecution.interrupt(); + stopExecution.join(); + Assert.assertTrue(!stopExecution.isAlive()); + } + + @Test + void givenLinesWithStopLabel_whenStopExecutionLabeledLoopCalled_thenLoopExecutionIsStopped() { + StopExecutionFurtherCode furtherCode = new StopExecutionFurtherCode(); + final String[] lines = { "Line 1", "Line 2", "Line 3", "stop", "Line 4", "Line 5" }; + int statusCode = furtherCode.processLines(lines); + Assert.assertEquals(-1, statusCode); + } + +} diff --git a/core-java-modules/core-java-lang-math-3/src/main/java/com/baeldung/clampfunction/Clamp.java b/core-java-modules/core-java-lang-math-3/src/main/java/com/baeldung/clampfunction/Clamp.java new file mode 100644 index 0000000000..4c62c0560e --- /dev/null +++ b/core-java-modules/core-java-lang-math-3/src/main/java/com/baeldung/clampfunction/Clamp.java @@ -0,0 +1,23 @@ +package com.baeldung.clampfunction; + +public class Clamp { + + public int clamp(int value, int min, int max) { + return Math.max(min, Math.min(max, value)); + } + + public double clamp(double value, double min, double max) { + return Math.max(min, Math.min(max, value)); + } + + public static <T extends Comparable<T>> T clamp(T value, T min, T max) { + if (value.compareTo(min) < 0) { + return min; + } else if (value.compareTo(max) > 0) { + return max; + } else { + return value; + } + } + +} diff --git a/core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/clampfunction/ClampFunctionUnitTest.java b/core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/clampfunction/ClampFunctionUnitTest.java new file mode 100644 index 0000000000..7bcf676dd0 --- /dev/null +++ b/core-java-modules/core-java-lang-math-3/src/test/java/com/baeldung/clampfunction/ClampFunctionUnitTest.java @@ -0,0 +1,40 @@ +package com.baeldung.clampfunction; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class ClampFunctionUnitTest { + + Clamp clampValue = new Clamp(); + + @Test + public void givenValueOutsideRange_whenClamp_thenReturnLowerValue() { + assertEquals(15, clampValue.clamp(10, 15, 35)); + } + + @Test + public void givenValueWithinRange_whenClamp_thenReturnValue() { + assertEquals(20, clampValue.clamp(20, 15, 35)); + } + + @Test + public void givenValueOutsideRange_whenClamp_thenReturnMaximumValue() { + assertEquals(35, clampValue.clamp(50, 15, 35)); + } + + @Test + public void givenDoubleValueOutsideRange_whenClamp_thenReturnMaximumValue() { + assertEquals(60.5, clampValue.clamp(75.6, 25.5, 60.5)); + } + + /* + * This method uses the clamp() method introduced in Java 21 + @Test + public void givenValueWithinRange_whenClamp_thenReturnValue() { + assertEquals(20, Math.clamp(20, 67,98)); + } + */ + +} diff --git a/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/Identifiable.java b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/Identifiable.java new file mode 100644 index 0000000000..080f63b295 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/Identifiable.java @@ -0,0 +1,5 @@ +package com.baeldung.interfaces.namingconventions; + +public interface Identifiable { + void identify(); +} diff --git a/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/RegularUser.java b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/RegularUser.java new file mode 100644 index 0000000000..e75d01e365 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/RegularUser.java @@ -0,0 +1,13 @@ +package com.baeldung.interfaces.namingconventions; + +public class RegularUser implements User { + @Override + public void identify() { + // some implementation + } + + @Override + public void authorize() { + // some implementation + } +} diff --git a/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/RootUser.java b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/RootUser.java new file mode 100644 index 0000000000..a02804d0b3 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/RootUser.java @@ -0,0 +1,13 @@ +package com.baeldung.interfaces.namingconventions; + +public class RootUser implements User { + @Override + public void identify() { + // some implementation + } + + @Override + public void authorize() { + // some implementation + } +} diff --git a/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/User.java b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/User.java new file mode 100644 index 0000000000..2891126ddd --- /dev/null +++ b/core-java-modules/core-java-lang-oop-others/src/main/java/com/baeldung/interfaces/namingconventions/User.java @@ -0,0 +1,5 @@ +package com.baeldung.interfaces.namingconventions; + +public interface User extends Identifiable { + void authorize(); +} diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/inttolong/IntToLongUnitTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/inttolong/IntToLongUnitTest.java new file mode 100644 index 0000000000..bc4109b42a --- /dev/null +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/inttolong/IntToLongUnitTest.java @@ -0,0 +1,36 @@ +package com.baeldung.inttolong; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class IntToLongUnitTest { + + @Test + void whenUsingTheAutoboxing_thenGetTheExpectedLong() { + int intTen = 10; + Long longTen = (long) intTen; + assertEquals(intTen, longTen); + } + + @Test + void whenUsingTheValueOf_thenGetTheExpectedLong() { + int intTen = 10; + Long longTen = Long.valueOf(intTen); + assertEquals(intTen, longTen); + } + + @Test + void whenUsingTheConstructor_thenGetTheExpectedLong() { + int intTen = 10; + Long longTen = new Long(intTen); + assertEquals(intTen, longTen); + } + + @Test + void whenUsingTheParseLong_thenGetTheExpectedLong() { + int intTen = 10; + Long longTen = Long.parseLong(String.valueOf(intTen)); + assertEquals(intTen, longTen); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-scanner/pom.xml b/core-java-modules/core-java-scanner/pom.xml index f149f51955..bb5c7dca78 100644 --- a/core-java-modules/core-java-scanner/pom.xml +++ b/core-java-modules/core-java-scanner/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://maven.apache.org/POM/4.0.0" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>core-java-scanner</artifactId> <name>core-java-scanner</name> diff --git a/core-java-modules/core-java-security-4/README.md b/core-java-modules/core-java-security-4/README.md new file mode 100644 index 0000000000..e850841d2b --- /dev/null +++ b/core-java-modules/core-java-security-4/README.md @@ -0,0 +1,7 @@ +## Core Java Security + +This module contains articles about core Java Security + +### Relevant Articles: + +- More articles: [[<-- prev]](/core-java-modules/core-java-security-3) diff --git a/core-java-modules/core-java-security-4/pom.xml b/core-java-modules/core-java-security-4/pom.xml new file mode 100644 index 0000000000..cca86d804a --- /dev/null +++ b/core-java-modules/core-java-security-4/pom.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>core-java-security-4</artifactId> + <name>core-java-security-4</name> + <packaging>jar</packaging> + + <parent> + <groupId>com.baeldung.core-java-modules</groupId> + <artifactId>core-java-modules</artifactId> + <version>0.0.1-SNAPSHOT</version> + </parent> + +</project> \ No newline at end of file diff --git a/core-java-modules/core-java-security-4/src/main/java/com/baeldung/certificate/RootCertificateUtil.java b/core-java-modules/core-java-security-4/src/main/java/com/baeldung/certificate/RootCertificateUtil.java new file mode 100644 index 0000000000..3e8445971f --- /dev/null +++ b/core-java-modules/core-java-security-4/src/main/java/com/baeldung/certificate/RootCertificateUtil.java @@ -0,0 +1,51 @@ +package com.baeldung.certificate; + +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.cert.Certificate; +import java.security.cert.X509Certificate; +import java.util.Enumeration; + +public class RootCertificateUtil { + + private RootCertificateUtil() { + } + + public static X509Certificate getRootCertificate(X509Certificate endEntityCertificate, KeyStore trustStore) + throws Exception { + X509Certificate issuerCertificate = findIssuerCertificate(endEntityCertificate, trustStore); + if (issuerCertificate != null) { + if (isRoot(issuerCertificate)) { + return issuerCertificate; + } else { + return getRootCertificate(issuerCertificate, trustStore); + } + } + return null; + } + + private static X509Certificate findIssuerCertificate(X509Certificate certificate, KeyStore trustStore) + throws KeyStoreException { + Enumeration<String> aliases = trustStore.aliases(); + while (aliases.hasMoreElements()) { + String alias = aliases.nextElement(); + Certificate cert = trustStore.getCertificate(alias); + if (cert instanceof X509Certificate) { + X509Certificate x509Cert = (X509Certificate) cert; + if (x509Cert.getSubjectX500Principal().equals(certificate.getIssuerX500Principal())) { + return x509Cert; + } + } + } + return null; + } + + private static boolean isRoot(X509Certificate certificate) { + try { + certificate.verify(certificate.getPublicKey()); + return certificate.getKeyUsage() != null && certificate.getKeyUsage()[5]; + } catch (Exception e) { + return false; + } + } +} diff --git a/core-java-modules/core-java-security-4/src/main/resources/keystore.jks b/core-java-modules/core-java-security-4/src/main/resources/keystore.jks new file mode 100644 index 0000000000..656c6c17d3 Binary files /dev/null and b/core-java-modules/core-java-security-4/src/main/resources/keystore.jks differ diff --git a/core-java-modules/core-java-security-4/src/main/resources/truststore.jks b/core-java-modules/core-java-security-4/src/main/resources/truststore.jks new file mode 100644 index 0000000000..5e1a9b4ce1 Binary files /dev/null and b/core-java-modules/core-java-security-4/src/main/resources/truststore.jks differ diff --git a/core-java-modules/core-java-security-4/src/test/java/com/baeldung/certificate/SignedCertificateUnitTest.java b/core-java-modules/core-java-security-4/src/test/java/com/baeldung/certificate/SignedCertificateUnitTest.java new file mode 100644 index 0000000000..f5ea3c1b87 --- /dev/null +++ b/core-java-modules/core-java-security-4/src/test/java/com/baeldung/certificate/SignedCertificateUnitTest.java @@ -0,0 +1,76 @@ +package com.baeldung.certificate; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.security.KeyStore; +import java.security.SignatureException; +import java.security.cert.X509Certificate; + +import static com.baeldung.certificate.RootCertificateUtil.getRootCertificate; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class SignedCertificateUnitTest { + + private KeyStore keyStore; + + private KeyStore trustStore; + + @BeforeEach + public void setUp() throws Exception { + char[] passwd = "changeit".toCharArray(); + keyStore = KeyStore.getInstance("JKS"); + keyStore.load(this.getClass().getClassLoader().getResourceAsStream("keystore.jks"), passwd); + trustStore = KeyStore.getInstance("JKS"); + trustStore.load(this.getClass().getClassLoader().getResourceAsStream("truststore.jks"), passwd); + } + + @Test + void whenCertificateIsSelfSigned_thenSubjectIsEqualToIssuer() throws Exception { + X509Certificate certificate = (X509Certificate) keyStore.getCertificate("selfsigned"); + assertEquals(certificate.getSubjectDN(), certificate.getIssuerDN()); + } + + @Test + void whenCertificateIsSelfSigned_thenItCanBeVerifiedWithItsOwnPublicKey() throws Exception { + X509Certificate certificate = (X509Certificate) keyStore.getCertificate("selfsigned"); + assertDoesNotThrow(() -> certificate.verify(certificate.getPublicKey())); + } + + @Test + void whenCertificateIsCASigned_thenItCantBeVerifiedWithItsOwnPublicKey() throws Exception { + X509Certificate certificate = (X509Certificate) keyStore.getCertificate("baeldung"); + assertThrows(SignatureException.class, () -> certificate.verify(certificate.getPublicKey())); + } + + @Test + void whenCertificateIsCASigned_thenRootCanBeFoundInTruststore() throws Exception { + X509Certificate endEntityCertificate = (X509Certificate) keyStore.getCertificate("baeldung"); + X509Certificate rootCertificate = getRootCertificate(endEntityCertificate, trustStore); + assertNotNull(rootCertificate); + } + + @Test + void whenCertificateIsCA_thenItCanBeUsedToSignOtherCertificates() throws Exception { + X509Certificate certificate = (X509Certificate) keyStore.getCertificate("cloudflare"); + assertTrue(certificate.getKeyUsage()[5]); + } + + @Test + void whenCertificateIsCA_thenBasicConstrainsReturnsZeroOrGreaterThanZero() throws Exception { + X509Certificate certificate = (X509Certificate) keyStore.getCertificate("cloudflare"); + assertNotEquals(-1, certificate.getBasicConstraints()); + } + + @Test + void whenCertificateIsSelfSigned_thenItCantBeUsedToSignOtherCertificates() throws Exception { + X509Certificate certificate = (X509Certificate) keyStore.getCertificate("selfsigned"); + assertNull(certificate.getKeyUsage()); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-streams-4/pom.xml b/core-java-modules/core-java-streams-4/pom.xml index 0b9b3569f1..e832cc1616 100644 --- a/core-java-modules/core-java-streams-4/pom.xml +++ b/core-java-modules/core-java-streams-4/pom.xml @@ -115,7 +115,6 @@ <properties> <!-- testing --> <assertj.version>3.23.1</assertj.version> - <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version> <maven.compiler.source>12</maven.compiler.source> <maven.compiler.target>12</maven.compiler.target> <rx.java.version>1.2.5</rx.java.version> diff --git a/core-java-modules/core-java-streams-5/pom.xml b/core-java-modules/core-java-streams-5/pom.xml index d1f8af6461..dc97d81b3d 100644 --- a/core-java-modules/core-java-streams-5/pom.xml +++ b/core-java-modules/core-java-streams-5/pom.xml @@ -38,6 +38,11 @@ <version>3.12.0</version> <scope>test</scope> </dependency> + <dependency> + <groupId>io.vavr</groupId> + <artifactId>vavr</artifactId> + <version>${vavr.version}</version> + </dependency> </dependencies> <build> @@ -64,9 +69,9 @@ <properties> <!-- testing --> - <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version> <maven.compiler.source>12</maven.compiler.source> <maven.compiler.target>12</maven.compiler.target> + <vavr.version>0.10.2</vavr.version> </properties> </project> \ No newline at end of file diff --git a/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/aggregateexception/CustomCollector.java b/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/aggregateexception/CustomCollector.java new file mode 100644 index 0000000000..dea3d3f44c --- /dev/null +++ b/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/aggregateexception/CustomCollector.java @@ -0,0 +1,38 @@ +package com.baeldung.aggregateexception; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collector; + +public class CustomCollector<T, R> { + private final List<R> results = new ArrayList<>(); + private final List<Throwable> exceptions = new ArrayList<>(); + + public static <T, R> Collector<T, ?, CustomCollector<T, R>> of(Function<T, R> mapper) { + return Collector.of( + CustomCollector::new, + (collector, item) -> { + try { + R result = mapper.apply(item); + collector.results.add(result); + } catch (Exception e) { + collector.exceptions.add(e); + } + }, + (left, right) -> { + left.results.addAll(right.results); + left.exceptions.addAll(right.exceptions); + return left; + } + ); + } + + public List<R> getResults() { + return results; + } + + public List<Throwable> getExceptions() { + return exceptions; + } +} diff --git a/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/aggregateexception/CustomMapper.java b/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/aggregateexception/CustomMapper.java new file mode 100644 index 0000000000..920c963337 --- /dev/null +++ b/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/aggregateexception/CustomMapper.java @@ -0,0 +1,17 @@ +package com.baeldung.aggregateexception; + +import com.baeldung.aggregateexception.entity.Result; + +import java.util.function.Function; + +public class CustomMapper { + public static <T, R> Function<T, Result<R, Throwable>> mapper(Function<T, R> func) { + return arg -> { + try { + return new Result(func.apply(arg)); + } catch (Exception e) { + return new Result(e); + } + }; + } +} diff --git a/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/aggregateexception/entity/Result.java b/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/aggregateexception/entity/Result.java new file mode 100644 index 0000000000..b723c3e510 --- /dev/null +++ b/core-java-modules/core-java-streams-5/src/main/java/com/baeldung/aggregateexception/entity/Result.java @@ -0,0 +1,26 @@ +package com.baeldung.aggregateexception.entity; + +import java.util.Optional; + +public class Result<R, E extends Throwable> { + private Optional<R> result; + private Optional<E> exception; + + public Result(R result) { + this.result = Optional.of(result); + this.exception = Optional.empty(); + } + + public Result(E exception) { + this.exception = Optional.of(exception); + this.result = Optional.empty(); + } + + public Optional<R> getResult() { + return result; + } + + public Optional<E> getException() { + return exception; + } +} diff --git a/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/aggregateexception/AggregateExceptionHandlerUnitTest.java b/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/aggregateexception/AggregateExceptionHandlerUnitTest.java new file mode 100644 index 0000000000..6410645d2a --- /dev/null +++ b/core-java-modules/core-java-streams-5/src/test/java/com/baeldung/aggregateexception/AggregateExceptionHandlerUnitTest.java @@ -0,0 +1,150 @@ +package com.baeldung.aggregateexception; + +import com.baeldung.aggregateexception.entity.Result; +import io.vavr.control.Either; +import io.vavr.control.Try; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; + + +public class AggregateExceptionHandlerUnitTest { + private static final Logger logger = LoggerFactory.getLogger(AggregateExceptionHandlerUnitTest.class); + + @Test + public void givenExtractedMethod_whenFoundEx_thenSuppressExIntoRuntimeEx() { + String[] strings = {"1", "2", "3", "a", "b", "c"}; + RuntimeException runEx = Arrays.stream(strings) + .map(str -> callProcessThrowsExAndNoOutput(str)) + .filter(Objects::nonNull) + .reduce(new RuntimeException("Errors Occurred"), (o1, o2) -> { + o1.addSuppressed(o2); + return o1; + }); + processExceptions(runEx); + assertEquals("Errors Occurred", runEx.getMessage()); + assertEquals(3, runEx.getSuppressed().length); + } + @Test + public void givenTryCatchInPipeline_whenFoundEx_thenSuppressExIntoRuntimeEx() { + String[] strings = {"1", "2", "3", "a", "b", "c"}; + RuntimeException runEx = Arrays.stream(strings).map(str -> { + try { + processThrowsExAndNoOutput(str); + return null; + } catch (RuntimeException e) { + return e; + } + }).filter(Objects::nonNull) + .collect(Collectors.collectingAndThen(Collectors.toList(), list -> { + RuntimeException runtimeException = new RuntimeException("Errors Occurred"); + list.forEach(runtimeException::addSuppressed); + return runtimeException; + })); + processExceptions(runEx); + assertEquals("Errors Occurred", runEx.getMessage()); + assertEquals(3, runEx.getSuppressed().length); + } + + @Test + public void givenProcessMethod_whenStreamResultHasExAndOutput_thenHandleExceptionListAndOutputList() { + List<String> strings = List.of("1", "2", "3", "a", "b", "c"); + Map map = strings.stream() + .map(s -> processReturnsExAndOutput(s)) + .collect(Collectors.partitioningBy(o -> o instanceof RuntimeException, Collectors.toList())); + + List<RuntimeException> exceptions = (List<RuntimeException>)map.getOrDefault(Boolean.TRUE, List.of()); + List<Integer> results = (List<Integer>)map.getOrDefault(Boolean.FALSE, List.of()); + handleExceptionsAndOutputs(exceptions, results); + } + + @Test + public void givenCustomMapper_whenStreamResultHasExAndSuccess_thenHandleExceptionListAndOutputList() { + List<String> strings = List.of("1", "2", "3", "a", "b", "c"); + strings.stream() + .map(CustomMapper.mapper(Integer::parseInt)) + .collect(Collectors.collectingAndThen(Collectors.toList(), list -> handleErrorsAndOutputForResult(list))); + } + + @Test + public void givenCustomCollector_whenStreamResultHasExAndSuccess_thenHandleAggrExceptionAndResults() { + String[] strings = {"1", "2", "3", "a", "b", "c"}; + Arrays.stream(strings) + .collect(Collectors.collectingAndThen(CustomCollector.of(Integer::parseInt), + col -> handleExAndResults(col.getExceptions(), col.getResults()))); + } + + @Test + public void givenVavrEitherAndTry_whenStreamResultHasExAndSuccess_thenHandleExceptionListAndOutputList() { + List<String> strings = List.of("1", "2", "3", "a", "b", "c"); + strings.stream() + .map(str -> Try.of(() -> Integer.parseInt(str)).toEither()) + .collect(Collectors.collectingAndThen(Collectors.partitioningBy(Either::isLeft, Collectors.toList()), + map -> handleErrorsAndOutputForEither(map))); + } + + private static void processThrowsExAndNoOutput(String input) { + //throw exception when input is "a", "b", "c" + if (input.matches("[a-c]")) { + throw new RuntimeException("Downstream method throws exception for " + input); + } + } + private static RuntimeException callProcessThrowsExAndNoOutput(String input) { + try { + processThrowsExAndNoOutput(input); + return null; + } catch (RuntimeException e) { + return e; + } + } + + private static Object processReturnsExAndOutput(String input) { + logger.info("call a downstream method that returns an Integer"); + try { + return Integer.parseInt(input); + } catch (Exception e) { + return new RuntimeException("Exception in processWithReturnOutput for " + input, e); + } + } + + private static void processExceptions(Throwable throwable) { + logger.error("Process Exception" + throwable.getMessage()); + } + + private static void handleExceptionsAndOutputs(List<RuntimeException> exs, List<Integer> output) { + logger.info("number of exceptions " + exs.size() + " number of outputs " + output.size()); + } + + private static String handleExAndResults(List<Throwable> ex, List<Integer> results ) { + logger.info("handle aggregated exceptions and results" + ex.size() + " " + results.size()); + return "Exceptions and Results Handled"; + } + + private static String handleErrorsAndOutputForEither(Map<Boolean, List<Either<Throwable, Integer>>> map) { + logger.info("handle errors and output"); + map.getOrDefault(Boolean.TRUE, List.of()).forEach(either -> logger.error("Process Exception " + either.getLeft())); + + map.getOrDefault(Boolean.FALSE, List.of()).forEach(either -> logger.info("Process Result " + either.get())); + return "Errors and Output Handled"; + } + + private static String handleErrorsAndOutputForResult(List<Result<Integer, Throwable>> successAndErrors) { + logger.info("handle errors and output"); + successAndErrors.forEach(result -> { + if (result.getException().isPresent()) { + logger.error("Process Exception " + result.getException().get()); + } else { + logger.info("Process Result" + result.getResult().get()); + } + }); + return "Errors and Output Handled"; + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-streams-maps/pom.xml b/core-java-modules/core-java-streams-maps/pom.xml index 66e1fedd87..6b04897a29 100644 --- a/core-java-modules/core-java-streams-maps/pom.xml +++ b/core-java-modules/core-java-streams-maps/pom.xml @@ -58,7 +58,6 @@ <properties> <!-- testing --> - <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> diff --git a/core-java-modules/core-java-string-operations-5/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java b/core-java-modules/core-java-string-operations-5/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java new file mode 100644 index 0000000000..081ffabab1 --- /dev/null +++ b/core-java-modules/core-java-string-operations-5/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.replace; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class ReplaceStringUnitTest { + private final String ORIGINAL_STRING = "This is 'Baeldung' tutorial."; + private final String EXPECTED_STRING = "This is \\'Baeldung\\' tutorial."; + + @Test + public void givenString_thenReplaceUsinReplaceAllMethod() { + String modifiedString = ORIGINAL_STRING.replaceAll("'", "\\\\'"); + assertEquals(EXPECTED_STRING, modifiedString); + } + + @Test + public void givenString_thenReplaceUsinReplaceMethod() { + String modifiedString = ORIGINAL_STRING.replace("'", "\\'"); + assertEquals(EXPECTED_STRING, modifiedString); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-string-operations-6/pom.xml b/core-java-modules/core-java-string-operations-6/pom.xml index 0ec32d91b1..ca9a7a9297 100644 --- a/core-java-modules/core-java-string-operations-6/pom.xml +++ b/core-java-modules/core-java-string-operations-6/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>core-java-string-operations-6</artifactId> <name>core-java-string-operations-6</name> diff --git a/core-java-modules/core-java-string-operations/pom.xml b/core-java-modules/core-java-string-operations/pom.xml index 577736a324..601d0341a3 100644 --- a/core-java-modules/core-java-string-operations/pom.xml +++ b/core-java-modules/core-java-string-operations/pom.xml @@ -15,30 +15,20 @@ <dependencies> <dependency> - <groupId>javax.xml.bind</groupId> - <artifactId>jaxb-api</artifactId> - <version>2.4.0-b180725.0427</version> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + <version>${jakarta.xml.bind-api.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>${commons-lang3.version}</version> </dependency> - <dependency> - <groupId>org.openjdk.jmh</groupId> - <artifactId>jmh-core</artifactId> - <version>${jmh-core.version}</version> - </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> - <dependency> - <groupId>org.openjdk.jmh</groupId> - <artifactId>jmh-generator-annprocess</artifactId> - <version>${jmh-generator.version}</version> - </dependency> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> @@ -57,7 +47,8 @@ </build> <properties> - <commons-codec.version>1.15</commons-codec.version> + <commons-codec.version>1.16.0</commons-codec.version> + <jakarta.xml.bind-api.version>4.0.0</jakarta.xml.bind-api.version> </properties> </project> \ No newline at end of file diff --git a/core-java-modules/core-java-string-operations/src/test/java/com/baeldung/base64encodinganddecoding/StringToByteArrayUnitTest.java b/core-java-modules/core-java-string-operations/src/test/java/com/baeldung/base64encodinganddecoding/StringToByteArrayUnitTest.java index 6f8a17e316..491574f0f1 100644 --- a/core-java-modules/core-java-string-operations/src/test/java/com/baeldung/base64encodinganddecoding/StringToByteArrayUnitTest.java +++ b/core-java-modules/core-java-string-operations/src/test/java/com/baeldung/base64encodinganddecoding/StringToByteArrayUnitTest.java @@ -2,7 +2,7 @@ package com.baeldung.base64encodinganddecoding; import org.junit.Test; -import javax.xml.bind.DatatypeConverter; +import jakarta.xml.bind.DatatypeConverter; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.Arrays; diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index e9bb86e500..4f21da40f5 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -127,6 +127,7 @@ <module>core-java-scanner</module> <module>core-java-security-2</module> <module>core-java-security-3</module> + <module>core-java-security-4</module> <module>core-java-security-algorithms</module> <module>core-java-streams</module> <module>core-java-streams-3</module> diff --git a/di-modules/avaje/pom.xml b/di-modules/avaje/pom.xml index 7ffe14bd72..49162c518e 100644 --- a/di-modules/avaje/pom.xml +++ b/di-modules/avaje/pom.xml @@ -1,37 +1,37 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>com.baeldung</groupId> - <artifactId>inject-intro</artifactId> - <version>0.0.1-SNAPSHOT</version> - <name>avaje-inject-intro</name> - <properties> - <maven.compiler.source>11</maven.compiler.source> - <maven.compiler.target>11</maven.compiler.target> - <avaje.inject.version>9.5</avaje.inject.version> - </properties> - <dependencies> - <dependency> - <groupId>io.avaje</groupId> - <artifactId>avaje-inject</artifactId> - <version>${avaje.inject.version}</version> - </dependency> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>com.baeldung</groupId> + <artifactId>inject-intro</artifactId> + <version>0.0.1-SNAPSHOT</version> + <name>avaje-inject-intro</name> + <properties> + <maven.compiler.source>11</maven.compiler.source> + <maven.compiler.target>11</maven.compiler.target> + <avaje.inject.version>9.5</avaje.inject.version> + </properties> + <dependencies> + <dependency> + <groupId>io.avaje</groupId> + <artifactId>avaje-inject</artifactId> + <version>${avaje.inject.version}</version> + </dependency> - <dependency> - <groupId>io.avaje</groupId> - <artifactId>avaje-inject-test</artifactId> - <version>${avaje.inject.version}</version> - <scope>test</scope> - </dependency> + <dependency> + <groupId>io.avaje</groupId> + <artifactId>avaje-inject-test</artifactId> + <version>${avaje.inject.version}</version> + <scope>test</scope> + </dependency> - <!-- Annotation processors --> - <dependency> - <groupId>io.avaje</groupId> - <artifactId>avaje-inject-generator</artifactId> - <version>${avaje.inject.version}</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - </dependencies> + <!-- Annotation processors --> + <dependency> + <groupId>io.avaje</groupId> + <artifactId>avaje-inject-generator</artifactId> + <version>${avaje.inject.version}</version> + <scope>provided</scope> + <optional>true</optional> + </dependency> + </dependencies> </project> \ No newline at end of file diff --git a/disruptor/pom.xml b/disruptor/pom.xml index 75e783e935..b3b065d67e 100644 --- a/disruptor/pom.xml +++ b/disruptor/pom.xml @@ -119,7 +119,6 @@ <disruptor.version>3.3.6</disruptor.version> <!-- testing --> <maven-shade-plugin.version>2.4.3</maven-shade-plugin.version> - <maven-jar-plugin.version>3.0.2</maven-jar-plugin.version> <onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version> </properties> diff --git a/jackson-modules/jackson-polymorphic-deserialization/pom.xml b/jackson-modules/jackson-polymorphic-deserialization/pom.xml index afa9cab82f..0d88c19500 100644 --- a/jackson-modules/jackson-polymorphic-deserialization/pom.xml +++ b/jackson-modules/jackson-polymorphic-deserialization/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>jackson-polymorphic-deserialization</artifactId> <name>jackson-polymorphic-deserialization</name> diff --git a/java-websocket/pom.xml b/java-websocket/pom.xml index 7c5c006aa9..d529b32022 100644 --- a/java-websocket/pom.xml +++ b/java-websocket/pom.xml @@ -30,7 +30,6 @@ <properties> <javax.websocket-api.version>1.1</javax.websocket-api.version> <gson.version>2.8.0</gson.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/jersey/pom.xml b/jersey/pom.xml index 005fa85077..c2b37f7118 100644 --- a/jersey/pom.xml +++ b/jersey/pom.xml @@ -100,7 +100,6 @@ <properties> <jersey.version>3.1.1</jersey.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/jhipster-modules/jhipster-microservice/car-app/pom.xml b/jhipster-modules/jhipster-microservice/car-app/pom.xml index f345688939..9ecf471bc2 100644 --- a/jhipster-modules/jhipster-microservice/car-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/car-app/pom.xml @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -45,8 +47,8 @@ <metrics-spring.version>3.1.3</metrics-spring.version> <node.version>v6.10.0</node.version> <!-- These remain empty unless the corresponding profile is active --> - <profile.no-liquibase /> - <profile.swagger /> + <profile.no-liquibase/> + <profile.swagger/> <!-- Sonar properties --> <project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory> <prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version> @@ -440,7 +442,7 @@ </goals> </pluginExecutionFilter> <action> - <ignore /> + <ignore/> </action> </pluginExecution> </pluginExecutions> @@ -634,9 +636,9 @@ <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile> <driver>org.h2.Driver</driver> <url>jdbc:h2:file:./target/h2db/db/carapp</url> - <defaultSchemaName /> + <defaultSchemaName/> <username>carapp</username> - <password /> + <password/> <referenceUrl>hibernate:spring:com.car.app.domain?dialect=org.hibernate.dialect.H2Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl> <verbose>true</verbose> <logging>debug</logging> @@ -683,7 +685,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> - <configuration /> + <configuration/> </plugin> </plugins> </build> @@ -722,7 +724,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> - <configuration /> + <configuration/> </plugin> <plugin> <groupId>org.springframework.boot</groupId> diff --git a/jhipster-modules/jhipster-microservice/dealer-app/pom.xml b/jhipster-modules/jhipster-microservice/dealer-app/pom.xml index 056bd60f33..33a238c96c 100644 --- a/jhipster-modules/jhipster-microservice/dealer-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/dealer-app/pom.xml @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -44,8 +46,8 @@ <metrics-spring.version>3.1.3</metrics-spring.version> <node.version>v6.10.0</node.version> <!-- These remain empty unless the corresponding profile is active --> - <profile.no-liquibase /> - <profile.swagger /> + <profile.no-liquibase/> + <profile.swagger/> <!-- Sonar properties --> <project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory> <prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version> @@ -439,7 +441,7 @@ </goals> </pluginExecutionFilter> <action> - <ignore /> + <ignore/> </action> </pluginExecution> </pluginExecutions> @@ -633,9 +635,9 @@ <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile> <driver>org.h2.Driver</driver> <url>jdbc:h2:file:./target/h2db/db/dealerapp</url> - <defaultSchemaName /> + <defaultSchemaName/> <username>dealerapp</username> - <password /> + <password/> <referenceUrl>hibernate:spring:com.dealer.app.domain?dialect=org.hibernate.dialect.H2Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl> <verbose>true</verbose> <logging>debug</logging> @@ -682,7 +684,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> - <configuration /> + <configuration/> </plugin> </plugins> </build> @@ -721,7 +723,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> - <configuration /> + <configuration/> </plugin> <plugin> <groupId>org.springframework.boot</groupId> diff --git a/jhipster-modules/jhipster-microservice/gateway-app/pom.xml b/jhipster-modules/jhipster-microservice/gateway-app/pom.xml index b90f22f009..3956475380 100644 --- a/jhipster-modules/jhipster-microservice/gateway-app/pom.xml +++ b/jhipster-modules/jhipster-microservice/gateway-app/pom.xml @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -48,8 +50,8 @@ <metrics-spring.version>3.1.3</metrics-spring.version> <node.version>v6.10.0</node.version> <!-- These remain empty unless the corresponding profile is active --> - <profile.no-liquibase /> - <profile.swagger /> + <profile.no-liquibase/> + <profile.swagger/> <!-- Sonar properties --> <project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory> <prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version> @@ -481,7 +483,7 @@ </goals> </pluginExecutionFilter> <action> - <ignore /> + <ignore/> </action> </pluginExecution> <pluginExecution> @@ -497,7 +499,7 @@ </goals> </pluginExecutionFilter> <action> - <ignore /> + <ignore/> </action> </pluginExecution> </pluginExecutions> @@ -691,9 +693,9 @@ <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile> <driver>org.h2.Driver</driver> <url>jdbc:h2:file:./target/h2db/db/gateway</url> - <defaultSchemaName /> + <defaultSchemaName/> <username>gateway</username> - <password /> + <password/> <referenceUrl>hibernate:spring:com.gateway.domain?dialect=org.hibernate.dialect.H2Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl> <verbose>true</verbose> <logging>debug</logging> diff --git a/jmh/pom.xml b/jmh/pom.xml index e5e0f46044..e8a88bf301 100644 --- a/jmh/pom.xml +++ b/jmh/pom.xml @@ -83,10 +83,8 @@ </build> <properties> - <maven-jar-plugin.version>3.3.0</maven-jar-plugin.version> <jol-core.version>0.17</jol-core.version> <maven-assembly-plugin.version>3.5.0</maven-assembly-plugin.version> - <maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version> </properties> </project> \ No newline at end of file diff --git a/jsf/pom.xml b/jsf/pom.xml index 81030537fb..09dea98f65 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -76,8 +76,6 @@ <!-- JSF --> <com.sun.faces.version>2.2.14</com.sun.faces.version> <javax.el.version>3.0.0</javax.el.version> - <!-- Maven War plugin --> - <maven-war-plugin.version>3.3.1</maven-war-plugin.version> <!-- Other --> <javax.annotation-api.version>1.3.1</javax.annotation-api.version> </properties> diff --git a/json-modules/json-conversion/pom.xml b/json-modules/json-conversion/pom.xml index 1af13cbbcb..680f27fa38 100644 --- a/json-modules/json-conversion/pom.xml +++ b/json-modules/json-conversion/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.baeldung</groupId> <artifactId>json-conversion</artifactId> @@ -29,11 +29,17 @@ <artifactId>jackson-databind</artifactId> <version>${jackson.version}</version> </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>${guava.version}</version> + </dependency> </dependencies> <properties> <json.version>20211205</json.version> <gson.version>2.10.1</gson.version> + <guava.version>32.1.2-jre</guava.version> </properties> </project> diff --git a/json-modules/json-conversion/src/main/java/com/baeldung/jsontomap/FlattenUtils.java b/json-modules/json-conversion/src/main/java/com/baeldung/jsontomap/FlattenUtils.java new file mode 100644 index 0000000000..2fd49d99ad --- /dev/null +++ b/json-modules/json-conversion/src/main/java/com/baeldung/jsontomap/FlattenUtils.java @@ -0,0 +1,36 @@ +package com.baeldung.jsontomap; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class FlattenUtils { + public static Map<String, Object> flatten(Map<String, Object> map) { + return flatten(map, null); + } + + private static Map<String, Object> flatten(Map<String, Object> map, String prefix) { + Map<String, Object> flatMap = new HashMap<>(); + map.forEach((key, value) -> { + String newKey = prefix != null ? prefix + "." + key : key; + if (value instanceof Map) { + flatMap.putAll(flatten((Map<String, Object>) value, newKey)); + } else if (value instanceof List) { + // check for list of primitives + Object element = ((List<?>) value).get(0); + if (element instanceof String || element instanceof Number || element instanceof Boolean) { + flatMap.put(newKey, value); + } else { + // check for list of objects + List<Map<String, Object>> list = (List<Map<String, Object>>) value; + for (int i = 0; i < list.size(); i++) { + flatMap.putAll(flatten(list.get(i), newKey + "[" + i + "]")); + } + } + } else { + flatMap.put(newKey, value); + } + }); + return flatMap; + } +} \ No newline at end of file diff --git a/json-modules/json-conversion/src/main/java/com/baeldung/jsontomap/JsonUtils.java b/json-modules/json-conversion/src/main/java/com/baeldung/jsontomap/JsonUtils.java new file mode 100644 index 0000000000..35339494fb --- /dev/null +++ b/json-modules/json-conversion/src/main/java/com/baeldung/jsontomap/JsonUtils.java @@ -0,0 +1,23 @@ +package com.baeldung.jsontomap; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Map; + +public class JsonUtils { + public static Map<String, Object> jsonFileToMap(String path) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(new File(path), new TypeReference<Map<String, Object>>() {}); + } + + public static Map<String, Object> jsonFileToMapGson(String path) throws IOException { + Gson gson = new Gson(); + return gson.fromJson(new FileReader(path), new TypeToken<Map<String, Object>>() {}.getType()); + } +} diff --git a/json-modules/json-conversion/src/test/java/com/baeldung/jsontomap/JSONComparisonUnitTest.java b/json-modules/json-conversion/src/test/java/com/baeldung/jsontomap/JSONComparisonUnitTest.java new file mode 100644 index 0000000000..908161c258 --- /dev/null +++ b/json-modules/json-conversion/src/test/java/com/baeldung/jsontomap/JSONComparisonUnitTest.java @@ -0,0 +1,37 @@ +package com.baeldung.jsontomap; + +import com.google.common.collect.MapDifference; +import com.google.common.collect.Maps; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class JSONComparisonUnitTest { + + @Test + void givenTwoJsonFiles_whenCompared_thenTheyAreDifferent() throws IOException { + Map<String, Object> firstMap = JsonUtils.jsonFileToMap("src/test/resources/first.json"); + Map<String, Object> secondMap = JsonUtils.jsonFileToMap("src/test/resources/second.json"); + + MapDifference<String, Object> difference = Maps.difference(firstMap, secondMap); + difference.entriesDiffering().forEach((key, value) -> { + System.out.println(key + ": " + value.leftValue() + " - " + value.rightValue()); + }); + assertThat(difference.areEqual()).isFalse(); + } + + @Test + void givenTwoJsonFiles_whenFlattenedAndCompared_thenTheyAreDifferent() throws IOException { + Map<String, Object> firstFlatMap = FlattenUtils.flatten(JsonUtils.jsonFileToMap("src/test/resources/first.json")); + Map<String, Object> secondFlatMap = FlattenUtils.flatten(JsonUtils.jsonFileToMap("src/test/resources/second.json")); + + MapDifference<String, Object> difference = Maps.difference(firstFlatMap, secondFlatMap); + difference.entriesDiffering().forEach((key, value) -> { + System.out.println(key + ": " + value.leftValue() + " - " + value.rightValue()); + }); + assertThat(difference.areEqual()).isFalse(); + } +} diff --git a/json-modules/json-conversion/src/test/resources/first.json b/json-modules/json-conversion/src/test/resources/first.json new file mode 100644 index 0000000000..905859c59f --- /dev/null +++ b/json-modules/json-conversion/src/test/resources/first.json @@ -0,0 +1,22 @@ +{ + "name": "John", + "age": 30, + "cars": [ + "Ford", + "BMW" + ], + "address": { + "street": "Second Street", + "city": "New York" + }, + "children": [ + { + "name": "Sara", + "age": 5 + }, + { + "name": "Alex", + "age": 3 + } + ] +} \ No newline at end of file diff --git a/json-modules/json-conversion/src/test/resources/second.json b/json-modules/json-conversion/src/test/resources/second.json new file mode 100644 index 0000000000..503228519f --- /dev/null +++ b/json-modules/json-conversion/src/test/resources/second.json @@ -0,0 +1,22 @@ +{ + "name": "John", + "age": 30, + "cars": [ + "Ford", + "Audi" + ], + "address": { + "street": "Main Street", + "city": "New York" + }, + "children": [ + { + "name": "Peter", + "age": 5 + }, + { + "name": "Cathy", + "age": 10 + } + ] +} \ No newline at end of file diff --git a/jws/pom.xml b/jws/pom.xml index 2f01f90721..12aa76127c 100644 --- a/jws/pom.xml +++ b/jws/pom.xml @@ -61,8 +61,4 @@ </plugins> </build> - <properties> - <maven-jar-plugin.version>3.0.2</maven-jar-plugin.version> - </properties> - </project> diff --git a/kubernetes-modules/jkube-demo/pom.xml b/kubernetes-modules/jkube-demo/pom.xml index 7bb662c4a3..6fedc0f24a 100644 --- a/kubernetes-modules/jkube-demo/pom.xml +++ b/kubernetes-modules/jkube-demo/pom.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.baeldung</groupId> diff --git a/libraries-data-2/pom.xml b/libraries-data-2/pom.xml index e19067daa3..0620dd69ea 100644 --- a/libraries-data-2/pom.xml +++ b/libraries-data-2/pom.xml @@ -92,7 +92,7 @@ <artifactId>suanshu</artifactId> <version>${suanshu.version}</version> </dependency> - --> + --> <dependency> <groupId>org.derive4j</groupId> <artifactId>derive4j</artifactId> @@ -162,7 +162,7 @@ </plugin> </plugins> </build> - + <!-- JAVA-24004 <repositories> <repository> diff --git a/libraries-server-2/pom.xml b/libraries-server-2/pom.xml index cf5d016d9f..7377fa3fa9 100644 --- a/libraries-server-2/pom.xml +++ b/libraries-server-2/pom.xml @@ -73,7 +73,6 @@ <properties> <jetty.version>9.4.27.v20200227</jetty.version> <alpn.version>8.1.11.v20170118</alpn.version> - <maven-war-plugin.version>3.2.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/libraries/pom.xml b/libraries/pom.xml index 2ab345c469..07a4853728 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -291,7 +291,6 @@ <quartz.version>2.3.0</quartz.version> <javaassist.version>3.29.2-GA</javaassist.version> <jool.version>0.9.12</jool.version> - <maven-jar-plugin.version>3.0.2</maven-jar-plugin.version> <commons-net.version>3.6</commons-net.version> <commonsio.version>2.6</commonsio.version> </properties> diff --git a/logging-modules/logback/pom.xml b/logging-modules/logback/pom.xml index cddc2e72ea..8df95c18bb 100644 --- a/logging-modules/logback/pom.xml +++ b/logging-modules/logback/pom.xml @@ -71,11 +71,11 @@ <scope>runtime</scope> </dependency> <dependency> - <groupId>org.projectlombok</groupId> - <artifactId>lombok</artifactId> - <scope>provided</scope> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <scope>provided</scope> <version>${lombok.version}</version> - </dependency> + </dependency> </dependencies> <profiles> diff --git a/maven-modules/maven-build-optimization/pom.xml b/maven-modules/maven-build-optimization/pom.xml index f0da31ceda..69533b4ef2 100644 --- a/maven-modules/maven-build-optimization/pom.xml +++ b/maven-modules/maven-build-optimization/pom.xml @@ -7,8 +7,8 @@ <version>0.0.1-SNAPSHOT</version> <name>maven-build-optimization</name> <packaging>pom</packaging> - - <parent> + + <parent> <groupId>com.baeldung</groupId> <artifactId>maven-modules</artifactId> <version>0.0.1-SNAPSHOT</version> @@ -53,10 +53,10 @@ </build> </profile> </profiles> - + <properties> <failsafe.version>3.1.2</failsafe.version> - <profiler.version>1.7</profiler.version> - </properties> + <profiler.version>1.7</profiler.version> + </properties> </project> \ No newline at end of file diff --git a/maven-modules/resume-from/business/pom.xml b/maven-modules/resume-from/business/pom.xml index 189be12a0f..6c5db6cbe1 100644 --- a/maven-modules/resume-from/business/pom.xml +++ b/maven-modules/resume-from/business/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://maven.apache.org/POM/4.0.0" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>business</artifactId> <version>1.0-SNAPSHOT</version> @@ -24,5 +24,4 @@ <maven.compiler.target>11</maven.compiler.target> </properties> - </project> \ No newline at end of file diff --git a/maven-modules/resume-from/pom.xml b/maven-modules/resume-from/pom.xml index 972395cbf2..d653d00d3b 100644 --- a/maven-modules/resume-from/pom.xml +++ b/maven-modules/resume-from/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://maven.apache.org/POM/4.0.0" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.baeldung</groupId> <artifactId>resume-from</artifactId> diff --git a/messaging-modules/pom.xml b/messaging-modules/pom.xml index 6fd14f7c64..27524637ab 100644 --- a/messaging-modules/pom.xml +++ b/messaging-modules/pom.xml @@ -22,7 +22,7 @@ <module>spring-amqp</module> <module>spring-apache-camel</module> <module>spring-jms</module> - <module>postgres-notify</module> + <module>postgres-notify</module> </modules> </project> \ No newline at end of file diff --git a/messaging-modules/postgres-notify/pom.xml b/messaging-modules/postgres-notify/pom.xml index 174d66b7f5..876519f40c 100644 --- a/messaging-modules/postgres-notify/pom.xml +++ b/messaging-modules/postgres-notify/pom.xml @@ -42,37 +42,36 @@ <artifactId>lombok</artifactId> <optional>true</optional> </dependency> - + </dependencies> + <properties> + <java.version>1.8</java.version> + </properties> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + </plugin> + </plugins> + </build> - <properties> - <java.version>1.8</java.version> - </properties> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - - <profiles> - <profile> - <id>instance1</id> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <configuration> - <jvmArguments>-Dserver.port=8081</jvmArguments> - </configuration> - </plugin> - </plugins> - </build> - </profile> - - </profiles> + <profiles> + <profile> + <id>instance1</id> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <jvmArguments>-Dserver.port=8081</jvmArguments> + </configuration> + </plugin> + </plugins> + </build> + </profile> + + </profiles> </project> \ No newline at end of file diff --git a/microservices-modules/pom.xml b/microservices-modules/pom.xml index 2111390481..a9cd8d2cd9 100644 --- a/microservices-modules/pom.xml +++ b/microservices-modules/pom.xml @@ -22,8 +22,4 @@ <module>rest-express</module> </modules> - <properties> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> - </properties> - </project> \ No newline at end of file diff --git a/microservices-modules/rest-express/pom.xml b/microservices-modules/rest-express/pom.xml index da697fdc56..182d14cfbf 100644 --- a/microservices-modules/rest-express/pom.xml +++ b/microservices-modules/rest-express/pom.xml @@ -144,7 +144,6 @@ <Syntaxe.version>1.0</Syntaxe.version> <repoexpress-mongodb.version>0.4.8</repoexpress-mongodb.version> <junit4.version>4.11</junit4.version> - <exec-maven-plugin.version>1.2.1</exec-maven-plugin.version> <maven-shade-plugin.version>2.4.1</maven-shade-plugin.version> <versions-maven-plugin.version>2.0</versions-maven-plugin.version> </properties> diff --git a/muleesb/pom.xml b/muleesb/pom.xml index a2204c15b7..8cdd3400e9 100644 --- a/muleesb/pom.xml +++ b/muleesb/pom.xml @@ -217,6 +217,8 @@ <munit.version>1.3.6</munit.version> <build-helper-maven-plugin.version>1.10</build-helper-maven-plugin.version> <mule-maven-plugin.version>2.2.1</mule-maven-plugin.version> + <maven-war-plugin.version>3.3.2</maven-war-plugin.version> + <maven-install-plugin.version>2.5.2</maven-install-plugin.version> </properties> </project> \ No newline at end of file diff --git a/persistence-modules/hibernate-libraries/pom.xml b/persistence-modules/hibernate-libraries/pom.xml index 031d55c17d..3f4da28296 100644 --- a/persistence-modules/hibernate-libraries/pom.xml +++ b/persistence-modules/hibernate-libraries/pom.xml @@ -166,7 +166,6 @@ <javassist.version>3.27.0-GA</javassist.version> <jaxb.version>2.3.1</jaxb.version> <log4jdbc.version>2.0.0</log4jdbc.version> - <maven-jar-plugin.version>3.0.2</maven-jar-plugin.version> <maven.compiler.version>3.8.1</maven.compiler.version> <maven.version>3.8.1</maven.version> <mysql.version>8.0.19</mysql.version> diff --git a/persistence-modules/java-jpa-2/pom.xml b/persistence-modules/java-jpa-2/pom.xml index 34e7f9f349..77d9590d65 100644 --- a/persistence-modules/java-jpa-2/pom.xml +++ b/persistence-modules/java-jpa-2/pom.xml @@ -156,7 +156,6 @@ <properties> <eclipselink.version>4.0.1</eclipselink.version> <javax.persistence-api.version>2.2</javax.persistence-api.version> - <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> <maven-processor-plugin.version>3.3.3</maven-processor-plugin.version> <build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version> <querydsl.version>5.0.0</querydsl.version> diff --git a/persistence-modules/java-jpa-3/pom.xml b/persistence-modules/java-jpa-3/pom.xml index 20143af9f0..0237da7ece 100644 --- a/persistence-modules/java-jpa-3/pom.xml +++ b/persistence-modules/java-jpa-3/pom.xml @@ -88,7 +88,6 @@ <eclipselink.version>2.7.4</eclipselink.version> <mysql.version>8.0.21</mysql.version> <javax.persistence-api.version>2.2</javax.persistence-api.version> - <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> <maven-processor-plugin.version>3.3.3</maven-processor-plugin.version> <build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version> <h2.version>2.1.214</h2.version> diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 24a55491d3..ee4699ecd8 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -85,7 +85,7 @@ <module>spring-data-jpa-query-3</module> <module>spring-data-jpa-repo</module> <module>spring-data-jpa-repo-2</module> - <module>spring-data-jpa-repo-4</module> + <module>spring-data-jpa-repo-4</module> <module>spring-data-jdbc</module> <module>spring-data-keyvalue</module> <module>spring-data-mongodb</module> diff --git a/persistence-modules/spring-boot-persistence-4/pom.xml b/persistence-modules/spring-boot-persistence-4/pom.xml index 99c39e205d..7a6c2d2b17 100644 --- a/persistence-modules/spring-boot-persistence-4/pom.xml +++ b/persistence-modules/spring-boot-persistence-4/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.baeldung.boot.persistence</groupId> <artifactId>spring-boot-persistence-4</artifactId> diff --git a/persistence-modules/spring-data-shardingsphere/pom.xml b/persistence-modules/spring-data-shardingsphere/pom.xml index 1f37bed4cc..c1ca313038 100644 --- a/persistence-modules/spring-data-shardingsphere/pom.xml +++ b/persistence-modules/spring-data-shardingsphere/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://maven.apache.org/POM/4.0.0" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>spring-data-shardingsphere</artifactId> <version>1.0</version> diff --git a/persistence-modules/spring-data-yugabytedb/pom.xml b/persistence-modules/spring-data-yugabytedb/pom.xml index cf85988ac3..d7f7576cfe 100644 --- a/persistence-modules/spring-data-yugabytedb/pom.xml +++ b/persistence-modules/spring-data-yugabytedb/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns="http://maven.apache.org/POM/4.0.0" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>spring-data-yugabytedb</artifactId> <version>1.0</version> diff --git a/pom.xml b/pom.xml index a8c24c7f78..a8c4416117 100644 --- a/pom.xml +++ b/pom.xml @@ -474,7 +474,6 @@ <module>apache-spark</module> <module>jenkins-modules</module> - <module>jhipster-6</module> <module>jhipster-modules</module> </modules> </profile> @@ -633,7 +632,6 @@ <module>apache-spark</module> <module>jenkins-modules</module> - <module>jhipster-6</module> <module>jhipster-modules</module> </modules> @@ -788,6 +786,7 @@ <module>guava-modules</module> <module>kubernetes-modules</module> <module>libraries-concurrency</module> + <module>jhipster-6</module> <module>libraries-testing</module> <module>maven-modules</module> <module>optaplanner</module> @@ -869,7 +868,7 @@ <module>libraries-apache-commons-2</module> <module>libraries-apache-commons-collections</module> <module>libraries-apache-commons-io</module> - <!--<module>libraries-data-2</module>--> <!-- Fixing in JAVA-24007 --> + <module>libraries-data-2</module> <!-- Fixing in JAVA-24007 --> <module>libraries-data-io</module> <module>libraries-files</module> <module>libraries-http</module> @@ -1059,6 +1058,7 @@ <module>guava-modules</module> <module>kubernetes-modules</module> <module>libraries-concurrency</module> + <module>jhipster-6</module> <module>libraries-testing</module> <module>maven-modules</module> <module>optaplanner</module> @@ -1140,7 +1140,7 @@ <module>libraries-apache-commons-2</module> <module>libraries-apache-commons-collections</module> <module>libraries-apache-commons-io</module> - <!--<module>libraries-data-2</module>--> <!-- Fixing in JAVA-24007 --> + <module>libraries-data-2</module> <!-- Fixing in JAVA-24007 --> <module>libraries-data-io</module> <module>libraries-files</module> <module>libraries-http</module> @@ -1270,19 +1270,19 @@ <!-- plugins --> <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version> - <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version> - <exec-maven-plugin.version>3.0.0</exec-maven-plugin.version> + <maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version> + <exec-maven-plugin.version>3.1.0</exec-maven-plugin.version> <java.version>1.8</java.version> <log4j.version>1.2.17</log4j.version> <jmh-core.version>1.36</jmh-core.version> <jmh-generator.version>1.36</jmh-generator.version> - <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version> + <maven-failsafe-plugin.version>3.1.2</maven-failsafe-plugin.version> <commons-collections4.version>4.4</commons-collections4.version> <commons-io.version>2.13.0</commons-io.version> <commons-lang.version>2.6</commons-lang.version> <commons-lang3.version>3.13.0</commons-lang3.version> <commons-cli.version>1.5.0</commons-cli.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> + <maven-war-plugin.version>3.4.0</maven-war-plugin.version> <javax.servlet-api.version>4.0.1</javax.servlet-api.version> <jstl-api.version>1.2</jstl-api.version> <javax.servlet.jsp-api.version>2.3.3</javax.servlet.jsp-api.version> @@ -1292,16 +1292,16 @@ <junit-platform.version>1.9.2</junit-platform.version> <junit-jupiter.version>5.9.2</junit-jupiter.version> <junit-platform-surefire-provider.version>1.3.2</junit-platform-surefire-provider.version> - <directory-maven-plugin.version>0.3.1</directory-maven-plugin.version> - <maven-install-plugin.version>2.5.2</maven-install-plugin.version> + <directory-maven-plugin.version>1.0</directory-maven-plugin.version> + <maven-install-plugin.version>3.1.1</maven-install-plugin.version> <custom-pmd.version>0.0.1</custom-pmd.version> <gitflow-incremental-builder.version>3.12.2</gitflow-incremental-builder.version> - <maven-jxr-plugin.version>3.0.0</maven-jxr-plugin.version> - <maven-pmd-plugin.version>3.19.0</maven-pmd-plugin.version> + <maven-jxr-plugin.version>3.3.0</maven-jxr-plugin.version> + <maven-pmd-plugin.version>3.21.0</maven-pmd-plugin.version> <lombok.version>1.18.28</lombok.version> <h2.version>2.1.214</h2.version> <guava.version>32.1.2-jre</guava.version> - <maven-jar-plugin.version>3.2.2</maven-jar-plugin.version> + <maven-jar-plugin.version>3.3.0</maven-jar-plugin.version> </properties> </project> diff --git a/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml b/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml index df3eca8a4f..74deab3558 100644 --- a/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml +++ b/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml @@ -255,7 +255,6 @@ <testcontainers-bom.version>1.17.2</testcontainers-bom.version> <java.version>11</java.version> <spring-native.version>0.12.1</spring-native.version> - <maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version> <maven.compiler.source.version>11</maven.compiler.source.version> <maven.compiler.target.version>11</maven.compiler.target.version> <maven-surefire-plugin.version>3.1.0</maven-surefire-plugin.version> diff --git a/saas-modules/sentry-servlet/pom.xml b/saas-modules/sentry-servlet/pom.xml index 4f9e37ebd5..70f6876dee 100644 --- a/saas-modules/sentry-servlet/pom.xml +++ b/saas-modules/sentry-servlet/pom.xml @@ -46,6 +46,5 @@ <properties> <sentry.version>6.11.0</sentry.version> <cargo-maven3-plugin.version>1.10.4</cargo-maven3-plugin.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/saas-modules/slack/pom.xml b/saas-modules/slack/pom.xml index 326167c055..d9e7abb4a2 100644 --- a/saas-modules/slack/pom.xml +++ b/saas-modules/slack/pom.xml @@ -55,7 +55,6 @@ <properties> <slack.version>1.4</slack.version> - <maven-jar-plugin.version>2.4</maven-jar-plugin.version> </properties> </project> \ No newline at end of file diff --git a/security-modules/jwt/src/test/java/com/baeldung/jwt/auth0/Auth0JsonWebTokenUnitTest.java b/security-modules/jwt/src/test/java/com/baeldung/jwt/auth0/Auth0JsonWebTokenUnitTest.java index a9c3b4185d..29fb832bd9 100644 --- a/security-modules/jwt/src/test/java/com/baeldung/jwt/auth0/Auth0JsonWebTokenUnitTest.java +++ b/security-modules/jwt/src/test/java/com/baeldung/jwt/auth0/Auth0JsonWebTokenUnitTest.java @@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Date; +import org.junit.Ignore; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -97,13 +98,14 @@ public class Auth0JsonWebTokenUnitTest { assertEquals(DATA, claim.asString()); } - @Test + //Need to fix with JAVA-24552 + @Ignore public void givenJWT_whenCreatedWithNotBefore_thenThrowException() { jwtToken = JWT.create() .withIssuer(ISSUER) .withClaim(DATA_CLAIM, DATA) - .withNotBefore(new Date(System.currentTimeMillis() + 1000L)) + .withNotBefore(new Date(System.currentTimeMillis() + 10000L)) .sign(algorithm); assertThrows(IncorrectClaimException.class, () -> { diff --git a/security-modules/pom.xml b/security-modules/pom.xml index b779c0d46d..864b1a7fcc 100644 --- a/security-modules/pom.xml +++ b/security-modules/pom.xml @@ -25,8 +25,4 @@ <module>sql-injection-samples</module> </modules> - <properties> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> - </properties> - </project> diff --git a/server-modules/undertow/pom.xml b/server-modules/undertow/pom.xml index 42a46d9508..a73771485c 100644 --- a/server-modules/undertow/pom.xml +++ b/server-modules/undertow/pom.xml @@ -46,7 +46,6 @@ <properties> <undertow-servlet.version>1.4.18.Final</undertow-servlet.version> <!--<maven-shade-plugin.version>2.4.3</maven-shade-plugin.version> --> - <maven-jar-plugin.version>3.0.2</maven-jar-plugin.version> </properties> </project> \ No newline at end of file diff --git a/spring-aop-2/pom.xml b/spring-aop-2/pom.xml index 056e248a3c..206e1d7d7c 100644 --- a/spring-aop-2/pom.xml +++ b/spring-aop-2/pom.xml @@ -51,4 +51,119 @@ </plugins> </build> + <profiles> + <profile> + <id>no-weaving</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <excludes> + <exclude>com.baeldung.selfinvocation.CompileTimeWeavingIntegrationTest</exclude> + <exclude>com.baeldung.selfinvocation.LoadTimeWeavingIntegrationTest</exclude> + </excludes> + </configuration> + </plugin> + </plugins> + </build> + </profile> + +<profile> + <id>compile-time-weaving</id> + + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aspects</artifactId> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <includes> + <include>com.baeldung.selfinvocation.CompileTimeWeavingIntegrationTest</include> + </includes> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>aspectj-maven-plugin</artifactId> + <version>${aspectj-plugin.version}</version> + <configuration> + <source>${java.version}</source> + <target>${java.version}</target> + <complianceLevel>${java.version}</complianceLevel> + <Xlint>ignore</Xlint> + <encoding>UTF-8</encoding> + <aspectLibraries> + <aspectLibrary> + <groupId>org.springframework</groupId> + <artifactId>spring-aspects</artifactId> + </aspectLibrary> + </aspectLibraries> + </configuration> + <executions> + <execution> + <goals> + <goal>compile</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</profile> + + <profile> + <id>load-time-weaving</id> + + <dependencies> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aspects</artifactId> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-tx</artifactId> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>${maven-surefire-plugin.version}</version> + <configuration> + <argLine> + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + -javaagent:"${settings.localRepository}"/org/aspectj/aspectjweaver/${aspectjweaver.version}/aspectjweaver-${aspectjweaver.version}.jar + -javaagent:"${settings.localRepository}"/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar + </argLine> + <useSystemClassLoader>true</useSystemClassLoader> + <forkMode>always</forkMode> + <includes> + <include>com.baeldung.selfinvocation.LoadTimeWeavingIntegrationTest</include> + </includes> + </configuration> + </plugin> + </plugins> + </build> + </profile> + </profiles> + + <properties> + <aspectj-plugin.version>1.14.0</aspectj-plugin.version> + <spring.version>5.3.27</spring.version> + </properties> + </project> \ No newline at end of file diff --git a/spring-aop-2/src/main/java/com/baeldung/Application.java b/spring-aop-2/src/main/java/com/baeldung/Application.java index c0490d50c6..cc64447264 100644 --- a/spring-aop-2/src/main/java/com/baeldung/Application.java +++ b/spring-aop-2/src/main/java/com/baeldung/Application.java @@ -2,8 +2,16 @@ package com.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; @SpringBootApplication +@ComponentScan(basePackages = { "com.baeldung" }, excludeFilters = { + @ComponentScan.Filter(type = FilterType.ANNOTATION, + value = { SpringBootApplication.class}) +}) +@EnableCaching public class Application { public static void main(String[] args) { diff --git a/spring-aop-2/src/main/java/com/baeldung/selfinvocation/CompileTimeWeavingApplication.java b/spring-aop-2/src/main/java/com/baeldung/selfinvocation/CompileTimeWeavingApplication.java new file mode 100644 index 0000000000..03995dd53b --- /dev/null +++ b/spring-aop-2/src/main/java/com/baeldung/selfinvocation/CompileTimeWeavingApplication.java @@ -0,0 +1,20 @@ +package com.baeldung.selfinvocation; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.AdviceMode; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; + +@SpringBootApplication +@EnableCaching(mode = AdviceMode.ASPECTJ) +@ComponentScan(basePackages = { "com.baeldung" }, excludeFilters = { + @ComponentScan.Filter(type = FilterType.ANNOTATION, + value = { SpringBootApplication.class}) +}) +public class CompileTimeWeavingApplication { + public static void main(String[] args) { + SpringApplication.run(CompileTimeWeavingApplication.class, args); + } +} \ No newline at end of file diff --git a/spring-aop-2/src/main/java/com/baeldung/selfinvocation/LoadTimeWeavingApplication.java b/spring-aop-2/src/main/java/com/baeldung/selfinvocation/LoadTimeWeavingApplication.java new file mode 100644 index 0000000000..a3dcc161b3 --- /dev/null +++ b/spring-aop-2/src/main/java/com/baeldung/selfinvocation/LoadTimeWeavingApplication.java @@ -0,0 +1,16 @@ +package com.baeldung.selfinvocation; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.AdviceMode; +import org.springframework.context.annotation.EnableLoadTimeWeaving; + +@SpringBootApplication +@EnableCaching(mode = AdviceMode.ASPECTJ) +@EnableLoadTimeWeaving +public class LoadTimeWeavingApplication { + public static void main(String[] args) { + SpringApplication.run(LoadTimeWeavingApplication.class, args); + } +} \ No newline at end of file diff --git a/spring-aop-2/src/main/java/com/baeldung/selfinvocation/MathService.java b/spring-aop-2/src/main/java/com/baeldung/selfinvocation/MathService.java new file mode 100644 index 0000000000..993b73295f --- /dev/null +++ b/spring-aop-2/src/main/java/com/baeldung/selfinvocation/MathService.java @@ -0,0 +1,43 @@ +package com.baeldung.selfinvocation; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.CacheConfig; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; +import org.springframework.stereotype.Service; + +import java.util.concurrent.atomic.AtomicInteger; + +@Service +@CacheConfig(cacheNames = "square") +@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS) +public class MathService { + + @Autowired + private MathService self; + private final AtomicInteger counter = new AtomicInteger(); + + @CacheEvict(allEntries = true) + public AtomicInteger resetCounter() { + counter.set(0); + return counter; + } + + @Cacheable(key = "#n") + public double square(double n) { + counter.incrementAndGet(); + return n * n; + } + + public double sumOfSquareOf2() { + return this.square(2) + this.square(2); + } + + public double sumOfSquareOf3() { + return self.square(3) + self.square(3); + } + +} + diff --git a/spring-aop-2/src/main/resources/logback.xml b/spring-aop-2/src/main/resources/logback.xml index 4eaa556705..d63707a9da 100644 --- a/spring-aop-2/src/main/resources/logback.xml +++ b/spring-aop-2/src/main/resources/logback.xml @@ -17,6 +17,8 @@ <logger name="org.springframework.aop.interceptor.PerformanceMonitorInterceptor" level="TRACE" /> + <logger name="org.aspectj.weaver" level="WARN" /> + <root level="TRACE"> <appender-ref ref="STDOUT" /> </root> diff --git a/spring-aop-2/src/test/java/com/baeldung/selfinvocation/CompileTimeWeavingIntegrationTest.java b/spring-aop-2/src/test/java/com/baeldung/selfinvocation/CompileTimeWeavingIntegrationTest.java new file mode 100644 index 0000000000..d0522f67e5 --- /dev/null +++ b/spring-aop-2/src/test/java/com/baeldung/selfinvocation/CompileTimeWeavingIntegrationTest.java @@ -0,0 +1,24 @@ +package com.baeldung.selfinvocation; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.Resource; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = CompileTimeWeavingApplication.class) +class CompileTimeWeavingIntegrationTest { + + @Resource + private MathService mathService; + + @Test + void givenCacheableMethod_whenInvokingByInternalCall_thenCacheIsTriggered() { + AtomicInteger counter = mathService.resetCounter(); + + assertThat(mathService.sumOfSquareOf2()).isEqualTo(8); + assertThat(counter.get()).isEqualTo(1); + } +} \ No newline at end of file diff --git a/spring-aop-2/src/test/java/com/baeldung/selfinvocation/LoadTimeWeavingIntegrationTest.java b/spring-aop-2/src/test/java/com/baeldung/selfinvocation/LoadTimeWeavingIntegrationTest.java new file mode 100644 index 0000000000..93c57699d6 --- /dev/null +++ b/spring-aop-2/src/test/java/com/baeldung/selfinvocation/LoadTimeWeavingIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.selfinvocation; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.Resource; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = LoadTimeWeavingApplication.class) +class LoadTimeWeavingIntegrationTest { + + @Resource + private MathService mathService; + + @Test + void givenCacheableMethod_whenInvokingByInternalCall_thenCacheIsTriggered() { + AtomicInteger counter = mathService.resetCounter(); + + assertThat(mathService.sumOfSquareOf2()).isEqualTo(8); + assertThat(counter.get()).isEqualTo(1); + } + +} \ No newline at end of file diff --git a/spring-aop-2/src/test/java/com/baeldung/selfinvocation/MathServiceIntegrationTest.java b/spring-aop-2/src/test/java/com/baeldung/selfinvocation/MathServiceIntegrationTest.java new file mode 100644 index 0000000000..24b829fa07 --- /dev/null +++ b/spring-aop-2/src/test/java/com/baeldung/selfinvocation/MathServiceIntegrationTest.java @@ -0,0 +1,47 @@ +package com.baeldung.selfinvocation; + +import com.baeldung.Application; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import javax.annotation.Resource; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest(classes = Application.class) +class MathServiceIntegrationTest { + + @Resource + private MathService mathService; + + @Test + void givenCacheableMethod_whenInvokedForSecondTime_thenCounterShouldNotIncrease() { + AtomicInteger counter = mathService.resetCounter(); + assertThat(mathService.square(2)).isEqualTo(4); + assertThat(counter.get()).isEqualTo(1); + + mathService.square(2); + assertThat(counter.get()).isEqualTo(1); + + mathService.square(3); + assertThat(counter.get()).isEqualTo(2); + } + + @Test + void givenCacheableMethod_whenInvokingByInternalCall_thenCacheIsNotTriggered() { + AtomicInteger counter = mathService.resetCounter(); + + assertThat(mathService.sumOfSquareOf2()).isEqualTo(8); + assertThat(counter.get()).isEqualTo(2); + } + + @Test + void givenCacheableMethod_whenInvokingByExternalCall_thenCacheIsTriggered() { + AtomicInteger counter = mathService.resetCounter(); + + assertThat(mathService.sumOfSquareOf3()).isEqualTo(18); + assertThat(counter.get()).isEqualTo(1); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 251dba0316..f87446b413 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -120,8 +120,4 @@ </dependencies> </dependencyManagement> - <properties> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> - </properties> - </project> diff --git a/spring-boot-modules/spring-boot-3-testcontainers/src/main/java/com/baeldung/testcontainers/Application.java b/spring-boot-modules/spring-boot-3-testcontainers/src/main/java/com/baeldung/testcontainers/Application.java index 9a00bfebf2..afe987a313 100644 --- a/spring-boot-modules/spring-boot-3-testcontainers/src/main/java/com/baeldung/testcontainers/Application.java +++ b/spring-boot-modules/spring-boot-3-testcontainers/src/main/java/com/baeldung/testcontainers/Application.java @@ -2,7 +2,6 @@ package com.baeldung.testcontainers; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; @SpringBootApplication public class Application { diff --git a/spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/DynamicPropertiesIntegrationTest.java b/spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/DynamicPropertiesLiveTest.java similarity index 95% rename from spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/DynamicPropertiesIntegrationTest.java rename to spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/DynamicPropertiesLiveTest.java index 8689b10110..e8818c1019 100644 --- a/spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/DynamicPropertiesIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/DynamicPropertiesLiveTest.java @@ -25,7 +25,7 @@ import com.baeldung.testcontainers.support.MiddleEarthCharactersRepository; @Testcontainers @SpringBootTest(webEnvironment = DEFINED_PORT) @DirtiesContext(classMode = AFTER_CLASS) -class DynamicPropertiesIntegrationTest { +class DynamicPropertiesLiveTest { @Container static MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10")); @@ -48,7 +48,7 @@ class DynamicPropertiesIntegrationTest { new MiddleEarthCharacter("Frodo", "hobbit"), new MiddleEarthCharacter("Samwise", "hobbit"), new MiddleEarthCharacter("Aragon", "human"), - new MiddleEarthCharacter("Gandalf", "wizzard") + new MiddleEarthCharacter("Gandalf", "wizard") )); when().get("/characters?race=hobbit") diff --git a/spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/ServiceConnectionIntegrationTest.java b/spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/ServiceConnectionLiveTest.java similarity index 94% rename from spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/ServiceConnectionIntegrationTest.java rename to spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/ServiceConnectionLiveTest.java index 500d6d2e61..838ee127f6 100644 --- a/spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/ServiceConnectionIntegrationTest.java +++ b/spring-boot-modules/spring-boot-3-testcontainers/src/test/java/com/baeldung/testcontainers/ServiceConnectionLiveTest.java @@ -24,7 +24,7 @@ import com.baeldung.testcontainers.support.MiddleEarthCharactersRepository; @Testcontainers @SpringBootTest(webEnvironment = DEFINED_PORT) @DirtiesContext(classMode = AFTER_CLASS) -class ServiceConnectionIntegrationTest { +class ServiceConnectionLiveTest { @Container @ServiceConnection @@ -44,7 +44,7 @@ class ServiceConnectionIntegrationTest { new MiddleEarthCharacter("Frodo", "hobbit"), new MiddleEarthCharacter("Samwise", "hobbit"), new MiddleEarthCharacter("Aragon", "human"), - new MiddleEarthCharacter("Gandalf", "wizzard") + new MiddleEarthCharacter("Gandalf", "wizard") )); when().get("/characters?race=hobbit") diff --git a/spring-boot-modules/spring-boot-3/pom.xml b/spring-boot-modules/spring-boot-3/pom.xml index 32c69801ca..3b3f9dbdb0 100644 --- a/spring-boot-modules/spring-boot-3/pom.xml +++ b/spring-boot-modules/spring-boot-3/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>spring-boot-3</artifactId> <version>0.0.1-SNAPSHOT</version> diff --git a/spring-boot-modules/spring-boot-artifacts/pom.xml b/spring-boot-modules/spring-boot-artifacts/pom.xml index dedeb0ab2a..e39ddb5af1 100644 --- a/spring-boot-modules/spring-boot-artifacts/pom.xml +++ b/spring-boot-modules/spring-boot-artifacts/pom.xml @@ -193,7 +193,6 @@ <git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version> <subethasmtp.version>3.1.7</subethasmtp.version> <httpclient.version>4.5.8</httpclient.version> - <maven-failsafe-plugin.version>2.18</maven-failsafe-plugin.version> </properties> </project> \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization/pom.xml b/spring-boot-modules/spring-boot-basic-customization/pom.xml index 4b1009d38a..581a7fec06 100644 --- a/spring-boot-modules/spring-boot-basic-customization/pom.xml +++ b/spring-boot-modules/spring-boot-basic-customization/pom.xml @@ -86,5 +86,4 @@ <start-class>com.baeldung.changeport.CustomApplication</start-class> </properties> - </project> \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-documentation/pom.xml b/spring-boot-modules/spring-boot-documentation/pom.xml index 587ad8473b..513c5678d5 100644 --- a/spring-boot-modules/spring-boot-documentation/pom.xml +++ b/spring-boot-modules/spring-boot-documentation/pom.xml @@ -92,7 +92,6 @@ </build> <properties> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> <swagger-core.version>2.2.11</swagger-core.version> <springwolf-kafka.version>0.12.1</springwolf-kafka.version> <springwolf-ui.version>0.8.0</springwolf-ui.version> diff --git a/spring-boot-modules/spring-boot-resilience4j/src/test/java/com/baeldung/resilience4j/eventendpoints/ResilientAppControllerIntegrationTest.java b/spring-boot-modules/spring-boot-resilience4j/src/test/java/com/baeldung/resilience4j/eventendpoints/ResilientAppControllerIntegrationTest.java index b4378a9248..a1173f40ae 100644 --- a/spring-boot-modules/spring-boot-resilience4j/src/test/java/com/baeldung/resilience4j/eventendpoints/ResilientAppControllerIntegrationTest.java +++ b/spring-boot-modules/spring-boot-resilience4j/src/test/java/com/baeldung/resilience4j/eventendpoints/ResilientAppControllerIntegrationTest.java @@ -31,9 +31,13 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; +/** + * This was failing as a unit test in integrated environment + * probably due to parallel execution of tests. + */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -class ResilientAppControllerIntegrationTest { +class ResilientAppControllerManualTest { private final Logger LOGGER = LoggerFactory.getLogger(getClass()); diff --git a/spring-boot-modules/spring-boot-testing-spock/pom.xml b/spring-boot-modules/spring-boot-testing-spock/pom.xml index c82d88ccfb..db78143cb8 100644 --- a/spring-boot-modules/spring-boot-testing-spock/pom.xml +++ b/spring-boot-modules/spring-boot-testing-spock/pom.xml @@ -96,7 +96,6 @@ <start-class>com.baeldung.boot.Application</start-class> <spock.version>2.4-M1-groovy-4.0</spock.version> <gmavenplus-plugin.version>3.0.0</gmavenplus-plugin.version> - <maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version> <log4j2.version>2.17.1</log4j2.version> </properties> diff --git a/spring-boot-modules/spring-boot-testing/pom.xml b/spring-boot-modules/spring-boot-testing/pom.xml index 2098ac767d..41783ebd7d 100644 --- a/spring-boot-modules/spring-boot-testing/pom.xml +++ b/spring-boot-modules/spring-boot-testing/pom.xml @@ -121,7 +121,6 @@ <git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version> <spock.version>2.4-M1-groovy-4.0</spock.version> <gmavenplus-plugin.version>3.0.0</gmavenplus-plugin.version> - <maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version> <redis.version>0.7.2</redis.version> <spring-boot.version>2.5.0</spring-boot.version> <log4j2.version>2.17.1</log4j2.version> diff --git a/spring-boot-rest/pom.xml b/spring-boot-rest/pom.xml index 74d46f0651..d4d7cd9c1a 100644 --- a/spring-boot-rest/pom.xml +++ b/spring-boot-rest/pom.xml @@ -163,7 +163,6 @@ <start-class>com.baeldung.SpringBootRestApplication</start-class> <xstream.version>1.4.11.1</xstream.version> <modelmapper.version>3.1.0</modelmapper.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> <jaxb-runtime.version>2.3.7</jaxb-runtime.version> </properties> </project> diff --git a/spring-cloud-modules/spring-cloud-zuul-fallback/pom.xml b/spring-cloud-modules/spring-cloud-zuul-fallback/pom.xml index ff62a99a00..fcf216cd6e 100644 --- a/spring-cloud-modules/spring-cloud-zuul-fallback/pom.xml +++ b/spring-cloud-modules/spring-cloud-zuul-fallback/pom.xml @@ -22,7 +22,6 @@ <properties> <spring-cloud-dependencies.version>2020.0.3</spring-cloud-dependencies.version> <spring-cloud-netflix-zuul.version>2.2.7.RELEASE</spring-cloud-netflix-zuul.version> - <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version> </properties> </project> \ No newline at end of file diff --git a/spring-core-4/pom.xml b/spring-core-4/pom.xml index 492a2ec5a2..2d11cc701b 100644 --- a/spring-core-4/pom.xml +++ b/spring-core-4/pom.xml @@ -84,7 +84,6 @@ <awaitility.version>4.0.2</awaitility.version> <servlet-api.version>4.0.0</servlet-api.version> <annotation-api.version>1.3.2</annotation-api.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> <apache-commons-text.version>1.10.0</apache-commons-text.version> </properties> diff --git a/spring-core/pom.xml b/spring-core/pom.xml index d1c155b92a..e369bc24d0 100644 --- a/spring-core/pom.xml +++ b/spring-core/pom.xml @@ -88,7 +88,6 @@ <spring-boot.version>1.5.2.RELEASE</spring-boot.version> <mockito.version>1.10.19</mockito.version> <annotation-api.version>1.3.2</annotation-api.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/spring-di/pom.xml b/spring-di/pom.xml index cf3703096c..af0601deb6 100644 --- a/spring-di/pom.xml +++ b/spring-di/pom.xml @@ -149,7 +149,6 @@ <spring-boot.version>1.5.2.RELEASE</spring-boot.version> <mockito.version>1.10.19</mockito.version> <aspectjweaver.version>1.9.5</aspectjweaver.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/spring-ejb-modules/pom.xml b/spring-ejb-modules/pom.xml index c5d04dab25..1b6c0ffc30 100755 --- a/spring-ejb-modules/pom.xml +++ b/spring-ejb-modules/pom.xml @@ -20,7 +20,7 @@ <!--<module>ejb-beans</module> JAVA-22440 need to upgrade to java 17 --> <module>spring-ejb-remote</module> <module>spring-ejb-client</module> - <module>wildfly</module> + <module>wildfly-mdb</module> </modules> <dependencyManagement> @@ -76,6 +76,7 @@ <wildfly-ejb.version>12.0.0.Final</wildfly-ejb.version> <maven-ejb-plugin.version>2.4</maven-ejb-plugin.version> <ejb.version>3.2</ejb.version> + <javaee-api.version>7.0</javaee-api.version> </properties> </project> \ No newline at end of file diff --git a/spring-ejb-modules/wildfly/wildfly-mdb/README.md b/spring-ejb-modules/wildfly-mdb/README.md similarity index 100% rename from spring-ejb-modules/wildfly/wildfly-mdb/README.md rename to spring-ejb-modules/wildfly-mdb/README.md diff --git a/spring-ejb-modules/wildfly/wildfly-mdb/pom.xml b/spring-ejb-modules/wildfly-mdb/pom.xml similarity index 81% rename from spring-ejb-modules/wildfly/wildfly-mdb/pom.xml rename to spring-ejb-modules/wildfly-mdb/pom.xml index 0784725cde..7498379ef9 100644 --- a/spring-ejb-modules/wildfly/wildfly-mdb/pom.xml +++ b/spring-ejb-modules/wildfly-mdb/pom.xml @@ -7,9 +7,9 @@ <name>wildfly-mdb</name> <parent> - <groupId>com.baeldung.wildfly</groupId> - <artifactId>wildfly</artifactId> - <version>0.0.1-SNAPSHOT</version> + <groupId>com.baeldung.spring.ejb</groupId> + <artifactId>spring-ejb-modules</artifactId> + <version>1.0.0-SNAPSHOT</version> </parent> <dependencies> diff --git a/spring-ejb-modules/wildfly/wildfly-mdb/src/com/baeldung/wildfly/mdb/ReadMessageMDB.java b/spring-ejb-modules/wildfly-mdb/src/com/baeldung/wildfly/mdb/ReadMessageMDB.java similarity index 100% rename from spring-ejb-modules/wildfly/wildfly-mdb/src/com/baeldung/wildfly/mdb/ReadMessageMDB.java rename to spring-ejb-modules/wildfly-mdb/src/com/baeldung/wildfly/mdb/ReadMessageMDB.java diff --git a/spring-ejb-modules/wildfly/wildfly-mdb/src/com/baeldung/wildfly/mdb/SendMessageServlet.java b/spring-ejb-modules/wildfly-mdb/src/com/baeldung/wildfly/mdb/SendMessageServlet.java similarity index 100% rename from spring-ejb-modules/wildfly/wildfly-mdb/src/com/baeldung/wildfly/mdb/SendMessageServlet.java rename to spring-ejb-modules/wildfly-mdb/src/com/baeldung/wildfly/mdb/SendMessageServlet.java diff --git a/spring-ejb-modules/wildfly/pom.xml b/spring-ejb-modules/wildfly/pom.xml deleted file mode 100644 index 412fa1b244..0000000000 --- a/spring-ejb-modules/wildfly/pom.xml +++ /dev/null @@ -1,89 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>com.baeldung.wildfly</groupId> - <artifactId>wildfly</artifactId> - <version>0.0.1-SNAPSHOT</version> - <name>wildfly</name> - <packaging>pom</packaging> - - <parent> - <groupId>com.baeldung.spring.ejb</groupId> - <artifactId>spring-ejb-modules</artifactId> - <version>1.0.0-SNAPSHOT</version> - </parent> - - <modules> - <module>wildfly-mdb</module> - </modules> - - <dependencyManagement> - <dependencies> - <!-- Dependencies for other libraries --> - <!-- Dependency for java ee --> - <dependency> - <groupId>javax</groupId> - <artifactId>javaee-api</artifactId> - <version>${javaee-api.version}</version> - <scope>provided</scope> - </dependency> - <!-- Dependency for wildfly --> - <dependency> - <groupId>org.wildfly.bom</groupId> - <artifactId>wildfly-javaee7</artifactId> - <version>${wildfly-javaee7.version}</version> - <scope>import</scope> - <type>pom</type> - </dependency> - <!-- Dependency on Hibernate --> - <dependency> - <groupId>org.hibernate</groupId> - <artifactId>hibernate-core</artifactId> - <version>${hibernate-core.version}</version> - <scope>provided</scope> - </dependency> - <!-- Dependency for ear module --> - <dependency> - <groupId>com.baeldung.wildfly</groupId> - <artifactId>wildlfy-ear</artifactId> - <version>${wildlfy.version}</version> - <type>ear</type> - </dependency> - <!-- Dependency for web module --> - <dependency> - <groupId>com.baeldung.wildfly</groupId> - <artifactId>wildlfy-web</artifactId> - <version>${wildlfy.version}</version> - <type>war</type> - </dependency> - <!-- Dependency for jpa module --> - <dependency> - <groupId>com.baeldung.wildfly</groupId> - <artifactId>wildlfy-jpa</artifactId> - <version>${wildlfy.version}</version> - </dependency> - <!-- Dependency for EJB --> - <dependency> - <groupId>com.baeldung.wildfly</groupId> - <artifactId>wildfly-ejb</artifactId> - <version>${wildlfy.version}</version> - </dependency> - <!-- Dependency for EJB interfaces --> - <dependency> - <groupId>com.baeldung.wildfly</groupId> - <artifactId>wildfly-ejb-interfaces</artifactId> - <version>${wildlfy.version}</version> - </dependency> - </dependencies> - </dependencyManagement> - - <properties> - <javaee-api.version>7.0</javaee-api.version> - <wildfly-javaee7.version>10.1.0.Final</wildfly-javaee7.version> - <hibernate-core.version>5.2.3.Final</hibernate-core.version> - <wildlfy.version>0.0.1-SNAPSHOT</wildlfy.version> - </properties> - -</project> \ No newline at end of file diff --git a/spring-exceptions/pom.xml b/spring-exceptions/pom.xml index 8912cad674..49c44f88f2 100644 --- a/spring-exceptions/pom.xml +++ b/spring-exceptions/pom.xml @@ -181,7 +181,6 @@ <!-- maven plugins --> <maven-resources-plugin.version>2.7</maven-resources-plugin.version> <cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/spring-jersey/pom.xml b/spring-jersey/pom.xml index 17d527ca6a..32f75aa676 100644 --- a/spring-jersey/pom.xml +++ b/spring-jersey/pom.xml @@ -221,7 +221,6 @@ <httpclient.version>4.5.5</httpclient.version> <wiremock.version>2.27.2</wiremock.version> <spring-boot.version>1.5.10.RELEASE</spring-boot.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/spring-katharsis/pom.xml b/spring-katharsis/pom.xml index 82be0555c3..b836a42bca 100644 --- a/spring-katharsis/pom.xml +++ b/spring-katharsis/pom.xml @@ -135,7 +135,6 @@ <katharsis.version>3.0.2</katharsis.version> <reflections.version>0.9.10</reflections.version> <cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/spring-mobile/pom.xml b/spring-mobile/pom.xml index 0c279c0d62..a7effc31be 100644 --- a/spring-mobile/pom.xml +++ b/spring-mobile/pom.xml @@ -58,7 +58,6 @@ <spring-mobile-device.version>1.1.5.RELEASE</spring-mobile-device.version> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/spring-pulsar/pom.xml b/spring-pulsar/pom.xml index 4c2fc0d9b4..df1959c84e 100644 --- a/spring-pulsar/pom.xml +++ b/spring-pulsar/pom.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>spring-pulsar</artifactId> <version>0.0.1-SNAPSHOT</version> diff --git a/spring-reactive-modules/spring-5-data-reactive-2/pom.xml b/spring-reactive-modules/spring-5-data-reactive-2/pom.xml index e5447ac038..3d88e672eb 100644 --- a/spring-reactive-modules/spring-5-data-reactive-2/pom.xml +++ b/spring-reactive-modules/spring-5-data-reactive-2/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>spring-5-data-reactive-2</artifactId> <name>spring-5-data-reactive-2</name> @@ -13,7 +13,6 @@ <version>1.0.0-SNAPSHOT</version> </parent> - <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> diff --git a/spring-security-modules/spring-security-web-mvc-custom/pom.xml b/spring-security-modules/spring-security-web-mvc-custom/pom.xml index f21c6dbe40..41f24050b2 100644 --- a/spring-security-modules/spring-security-web-mvc-custom/pom.xml +++ b/spring-security-modules/spring-security-web-mvc-custom/pom.xml @@ -172,7 +172,6 @@ <properties> <!-- Maven plugins --> - <maven-war-plugin.version>3.2.2</maven-war-plugin.version> <cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version> <javax.annotation-api.version>1.3.2</javax.annotation-api.version> </properties> diff --git a/spring-shell/pom.xml b/spring-shell/pom.xml index 506884b413..952920fd1e 100644 --- a/spring-shell/pom.xml +++ b/spring-shell/pom.xml @@ -39,7 +39,6 @@ <properties> <spring-shell.version>1.2.0.RELEASE</spring-shell.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/spring-web-modules/spring-thymeleaf-attributes/accessing-session-attributes/pom.xml b/spring-web-modules/spring-thymeleaf-attributes/accessing-session-attributes/pom.xml index 38d019c683..d4fff21605 100644 --- a/spring-web-modules/spring-thymeleaf-attributes/accessing-session-attributes/pom.xml +++ b/spring-web-modules/spring-thymeleaf-attributes/accessing-session-attributes/pom.xml @@ -1,84 +1,84 @@ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> - <groupId>com.baeldung.spring-thymeleaf-attributes.module</groupId> - <artifactId>accessing-session-attributes</artifactId> - <version>0.0.1-SNAPSHOT</version> - <packaging>war</packaging> - - <parent> - <groupId>com.baeldung.spring-thymeleaf-attributes</groupId> - <artifactId>spring-thymeleaf-attributes</artifactId> + <groupId>com.baeldung.spring-thymeleaf-attributes.module</groupId> + <artifactId>accessing-session-attributes</artifactId> <version>0.0.1-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + <packaging>war</packaging> - <dependencies> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-web</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-thymeleaf</artifactId> - <version>${spring.boot.starter.thymeleaf}</version> - </dependency> - <!-- test scoped --> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-engine</artifactId> - <version>${junit.jupiter.engine.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <version>${mockito.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-junit-jupiter</artifactId> - <version>${mockito.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.junit.jupiter</groupId> - <artifactId>junit-jupiter-api</artifactId> - <version>${junit.jupiter.engine.version}</version> - <scope>test</scope> - </dependency> - </dependencies> + <parent> + <groupId>com.baeldung.spring-thymeleaf-attributes</groupId> + <artifactId>spring-thymeleaf-attributes</artifactId> + <version>0.0.1-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <build> - <plugins> - <plugin> - <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-maven-plugin</artifactId> - <configuration> - <jvmArguments> - -Dfile.encoding="UTF-8" -Xdebug - -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 - </jvmArguments> - </configuration> - </plugin> - </plugins> - </build> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-web</artifactId> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-thymeleaf</artifactId> + <version>${spring.boot.starter.thymeleaf}</version> + </dependency> + <!-- test scoped --> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <version>${junit.jupiter.engine.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>${mockito.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-junit-jupiter</artifactId> + <version>${mockito.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <version>${junit.jupiter.engine.version}</version> + <scope>test</scope> + </dependency> + </dependencies> - <properties> - <start-class>com.baeldung.accesing_session_attributes.SpringWebApplicationInitializer</start-class> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> - <file.encoding>UTF-8</file.encoding> - <downloadSources>true</downloadSources> - <downloadJavadocs>true</downloadJavadocs> - <junit.jupiter.engine.version>5.9.3</junit.jupiter.engine.version> - <mockito.version>5.3.1</mockito.version> - <thymeleaf.spring6.version>3.1.1.RELEASE</thymeleaf.spring6.version> - <spring.boot.starter.thymeleaf>3.1.1</spring.boot.starter.thymeleaf> - </properties> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <configuration> + <jvmArguments> + -Dfile.encoding="UTF-8" -Xdebug + -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 + </jvmArguments> + </configuration> + </plugin> + </plugins> + </build> + + <properties> + <start-class>com.baeldung.accesing_session_attributes.SpringWebApplicationInitializer</start-class> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <file.encoding>UTF-8</file.encoding> + <downloadSources>true</downloadSources> + <downloadJavadocs>true</downloadJavadocs> + <junit.jupiter.engine.version>5.9.3</junit.jupiter.engine.version> + <mockito.version>5.3.1</mockito.version> + <thymeleaf.spring6.version>3.1.1.RELEASE</thymeleaf.spring6.version> + <spring.boot.starter.thymeleaf>3.1.1</spring.boot.starter.thymeleaf> + </properties> </project> \ No newline at end of file diff --git a/spring-websockets/pom.xml b/spring-websockets/pom.xml index c13d1cff33..a28ef8749a 100644 --- a/spring-websockets/pom.xml +++ b/spring-websockets/pom.xml @@ -44,8 +44,4 @@ </resources> </build> - <properties> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> - </properties> - </project> \ No newline at end of file diff --git a/testing-modules/cucumber/pom.xml b/testing-modules/cucumber/pom.xml index ffa5c0d250..6d178b86a3 100644 --- a/testing-modules/cucumber/pom.xml +++ b/testing-modules/cucumber/pom.xml @@ -124,7 +124,6 @@ <maven.compiler.target>14</maven.compiler.target> <cucumber.version>6.10.3</cucumber.version> <cucumber-reporting.version>5.4.0</cucumber-reporting.version> - <maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version> <selenium.version>3.141.59</selenium.version> <webdrivermanager.version>4.3.1</webdrivermanager.version> <webjars-locator.version>0.40</webjars-locator.version> diff --git a/testing-modules/testing-libraries-2/pom.xml b/testing-modules/testing-libraries-2/pom.xml index d74ede07db..4cc3ea8428 100644 --- a/testing-modules/testing-libraries-2/pom.xml +++ b/testing-modules/testing-libraries-2/pom.xml @@ -1,6 +1,6 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>testing-libraries-2</artifactId> <name>testing-libraries-2</name> diff --git a/testing-modules/testng/pom.xml b/testing-modules/testng/pom.xml index 62e2b2e578..b0a10b131c 100644 --- a/testing-modules/testng/pom.xml +++ b/testing-modules/testng/pom.xml @@ -25,15 +25,9 @@ <build> <finalName>testng</finalName> - <resources> - <resource> - <directory>src/main/resources</directory> - <filtering>true</filtering> - </resource> - </resources> <testResources> <testResource> - <directory>src/main/resources</directory> + <directory>src/test/resources</directory> <filtering>true</filtering> </testResource> </testResources> diff --git a/testing-modules/zerocode/pom.xml b/testing-modules/zerocode/pom.xml index 15ef45be63..c0aa370096 100644 --- a/testing-modules/zerocode/pom.xml +++ b/testing-modules/zerocode/pom.xml @@ -91,7 +91,6 @@ </build> <properties> - <maven-failsafe-plugin.version>3.0.0-M5</maven-failsafe-plugin.version> <surefire-junit47.version>3.0.0-M5</surefire-junit47.version> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> diff --git a/vaadin/pom.xml b/vaadin/pom.xml index 777ab2551c..aa37a2392a 100644 --- a/vaadin/pom.xml +++ b/vaadin/pom.xml @@ -187,7 +187,6 @@ <vaadin.widgetset.mode>local</vaadin.widgetset.mode> <vaadin.theme>mytheme</vaadin.theme> <maven-clean-plugin.version>3.0.0</maven-clean-plugin.version> - <maven-war-plugin.version>3.3.2</maven-war-plugin.version> </properties> </project> \ No newline at end of file diff --git a/web-modules/blade/pom.xml b/web-modules/blade/pom.xml index 0733556c20..2748c05663 100644 --- a/web-modules/blade/pom.xml +++ b/web-modules/blade/pom.xml @@ -112,7 +112,6 @@ <httpclient.version>4.5.6</httpclient.version> <httpmime.version>4.5.6</httpmime.version> <httpcore.version>4.4.10</httpcore.version> - <maven-failsafe-plugin.version>3.0.0-M3</maven-failsafe-plugin.version> <process-exec-maven-plugin.version>0.7</process-exec-maven-plugin.version> <assembly.plugin.version>3.1.0</assembly.plugin.version> </properties> diff --git a/web-modules/wicket/pom.xml b/web-modules/wicket/pom.xml index 9348e15cdb..244d176e25 100644 --- a/web-modules/wicket/pom.xml +++ b/web-modules/wicket/pom.xml @@ -84,7 +84,6 @@ <properties> <wicket.version>7.5.0</wicket.version> <jetty9.version>9.2.13.v20150730</jetty9.version> - <maven-war-plugin.version>3.3.1</maven-war-plugin.version> </properties> </project> \ No newline at end of file