Skip to content

Commit 387b92b

Browse files
committed
Merge remote-tracking branch 'eugenp/master'
2 parents ca17030 + 717bd1d commit 387b92b

66 files changed

Lines changed: 2790 additions & 178 deletions

File tree

Some content is hidden

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

‎.gitignore‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ dependency-reduced-pom.xml
4848
*.so
4949
*.dylib
5050
*.dll
51+
52+
xml/src/test/resources/example_dom4j_new.xml
53+
xml/src/test/resources/example_dom4j_updated.xml
54+
xml/src/test/resources/example_jaxb_new.xml
55+
core-java-io/hard_link.txt
56+
core-java-io/target_link.txt
57+
core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF
58+
ethereum/logs/
59+
jmeter/src/main/resources/*-JMeter.csv

‎core-java-8/pom.xml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@
9999
<artifactId>joda-time</artifactId>
100100
<version>${joda.version}</version>
101101
</dependency>
102+
<dependency>
103+
<groupId>org.aspectj</groupId>
104+
<artifactId>aspectjrt</artifactId>
105+
<version>${asspectj.version}</version>
106+
</dependency>
107+
<dependency>
108+
<groupId>org.aspectj</groupId>
109+
<artifactId>aspectjweaver</artifactId>
110+
<version>${asspectj.version}</version>
111+
</dependency>
102112
</dependencies>
103113

104114
<build>
@@ -170,6 +180,7 @@
170180
<joda.version>2.10</joda.version>
171181
<!-- testing -->
172182
<assertj.version>3.6.1</assertj.version>
183+
<asspectj.version>1.8.9</asspectj.version>
173184
<avaitility.version>1.7.0</avaitility.version>
174185
<jmh-core.version>1.19</jmh-core.version>
175186
<jmh-generator.version>1.19</jmh-generator.version>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.baeldung.aspect;
2+
3+
public aspect ChangeCallsToCurrentTimeInMillisMethod {
4+
long around():
5+
call(public static native long java.lang.System.currentTimeMillis())
6+
&& within(user.code.base.pckg.*) {
7+
return 0;
8+
}
9+
}

‎core-java-8/src/test/java/com/baeldung/util/CurrentDateTimeUnitTest.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.baeldung.util;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertTrue;
45

56
import java.time.Clock;
67
import java.time.Instant;
@@ -9,6 +10,8 @@
910
import java.time.ZoneId;
1011
import java.time.temporal.ChronoField;
1112

13+
import org.joda.time.DateTime;
14+
import org.joda.time.DateTimeUtils;
1215
import org.junit.Test;
1316

1417
public class CurrentDateTimeUnitTest {
@@ -39,5 +42,4 @@ public void shouldReturnCurrentTimestamp() {
3942

4043
assertEquals(clock.instant().getEpochSecond(), now.getEpochSecond());
4144
}
42-
4345
}

core-java-8/src/main/java/com/baeldung/convertlisttomap/Animal.java renamed to core-java-collections/src/main/java/com/baeldung/convertlisttomap/Animal.java

File renamed without changes.

core-java-8/src/main/java/com/baeldung/convertlisttomap/ConvertListToMapService.java renamed to core-java-collections/src/main/java/com/baeldung/convertlisttomap/ConvertListToMapService.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
package com.baeldung.convertlisttomap;
22

3+
import com.google.common.collect.Maps;
4+
import org.apache.commons.collections4.MapUtils;
5+
36
import java.util.HashMap;
47
import java.util.List;
58
import java.util.Map;
69
import java.util.stream.Collectors;
710

8-
import org.apache.commons.collections4.IterableUtils;
9-
import org.apache.commons.collections4.MapUtils;
10-
import com.google.common.collect.Maps;
11-
1211
public class ConvertListToMapService {
1312

1413
public Map<Integer, Animal> convertListBeforeJava8(List<Animal> list) {
15-
Map<Integer, Animal> map = new HashMap<Integer, Animal>();
14+
15+
Map<Integer, Animal> map = new HashMap<>();
16+
1617
for (Animal animal : list) {
1718
map.put(animal.getId(), animal);
1819
}
@@ -30,20 +31,9 @@ public Map<Integer, Animal> convertListWithGuava(List<Animal> list) {
3031
return map;
3132
}
3233

33-
public Map<Integer, Animal> convertListWithApacheCommons1(List<Animal> list) {
34-
35-
Map<Integer, Animal> map = new HashMap<Integer, Animal>();
36-
37-
IterableUtils.forEach(list, animal -> {
38-
map.put(animal.getId(), animal);
39-
});
40-
41-
return map;
42-
}
43-
44-
public Map<Integer, Animal> convertListWithApacheCommons2(List<Animal> list) {
34+
public Map<Integer, Animal> convertListWithApacheCommons(List<Animal> list) {
4535

46-
Map<Integer, Animal> map = new HashMap<Integer, Animal>();
36+
Map<Integer, Animal> map = new HashMap<>();
4737

4838
MapUtils.populateMap(map, list, Animal::getId);
4939

core-java-8/src/test/java/com/baeldung/convertlisttomap/ConvertListToMapServiceUnitTest.java renamed to core-java-collections/src/test/java/com/baeldung/convertlisttomap/ConvertListToMapServiceUnitTest.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.baeldung.convertlisttomap;
22

3-
import static org.hamcrest.MatcherAssert.assertThat;
4-
import static org.hamcrest.Matchers.*;
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
56
import java.util.ArrayList;
67
import java.util.List;
78
import java.util.Map;
89

9-
import org.junit.Before;
10-
import org.junit.Test;
10+
import static org.hamcrest.MatcherAssert.assertThat;
11+
import static org.hamcrest.Matchers.containsInAnyOrder;
1112

1213
public class ConvertListToMapServiceUnitTest {
1314
List<Animal> list;
@@ -29,6 +30,7 @@ public void init() {
2930
list.add(cow);
3031
Animal goat = new Animal(5, "Goat");
3132
list.add(goat);
33+
3234
}
3335

3436
@Test
@@ -56,18 +58,11 @@ public void givenAList_whenConvertWithGuava_thenReturnMapWithTheSameElements() {
5658
}
5759

5860
@Test
59-
public void givenAList_whenConvertWithApacheCommons1_thenReturnMapWithTheSameElements() {
61+
public void givenAList_whenConvertWithApacheCommons_thenReturnMapWithTheSameElements() {
6062

61-
Map<Integer, Animal> map = convertListService.convertListWithApacheCommons1(list);
63+
Map<Integer, Animal> map = convertListService.convertListWithApacheCommons(list);
6264

6365
assertThat(map.values(), containsInAnyOrder(list.toArray()));
6466
}
6567

66-
@Test
67-
public void givenAList_whenConvertWithApacheCommons2_thenReturnMapWithTheSameElements() {
68-
69-
Map<Integer, Animal> map = convertListService.convertListWithApacheCommons2(list);
70-
71-
assertThat(map.values(), containsInAnyOrder(list.toArray()));
72-
}
7368
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.baeldung.convertlisttomap;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.Map;
9+
10+
import static org.hamcrest.MatcherAssert.assertThat;
11+
import static org.hamcrest.Matchers.hasItem;
12+
import static org.hamcrest.Matchers.hasSize;
13+
14+
public class ConvertListWithDiplicatedIdToMapServiceUnitTest {
15+
List<Animal> duplicatedIdList;
16+
17+
private ConvertListToMapService convertListService = new ConvertListToMapService();
18+
19+
@Before
20+
public void init() {
21+
22+
this.duplicatedIdList = new ArrayList<>();
23+
24+
Animal cat = new Animal(1, "Cat");
25+
duplicatedIdList.add(cat);
26+
Animal dog = new Animal(2, "Dog");
27+
duplicatedIdList.add(dog);
28+
Animal pig = new Animal(3, "Pig");
29+
duplicatedIdList.add(pig);
30+
Animal cow = new Animal(4, "Cow");
31+
duplicatedIdList.add(cow);
32+
Animal goat = new Animal(4, "Goat");
33+
duplicatedIdList.add(goat);
34+
35+
}
36+
37+
@Test
38+
public void givenADupIdList_whenConvertBeforeJava8_thenReturnMapWithRewrittenElement() {
39+
40+
Map<Integer, Animal> map = convertListService.convertListBeforeJava8(duplicatedIdList);
41+
42+
assertThat(map.values(), hasSize(4));
43+
assertThat(map.values(), hasItem(duplicatedIdList.get(4)));
44+
}
45+
46+
@Test
47+
public void givenADupIdList_whenConvertWithApacheCommons_thenReturnMapWithRewrittenElement() {
48+
49+
Map<Integer, Animal> map = convertListService.convertListWithApacheCommons(duplicatedIdList);
50+
51+
assertThat(map.values(), hasSize(4));
52+
assertThat(map.values(), hasItem(duplicatedIdList.get(4)));
53+
}
54+
55+
@Test(expected = IllegalStateException.class)
56+
public void givenADupIdList_whenConvertAfterJava8_thenException() {
57+
58+
convertListService.convertListAfterJava8(duplicatedIdList);
59+
}
60+
61+
@Test(expected = IllegalArgumentException.class)
62+
public void givenADupIdList_whenConvertWithGuava_thenException() {
63+
64+
convertListService.convertListWithGuava(duplicatedIdList);
65+
66+
}
67+
68+
}

‎core-java/pom.xml‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@
147147
<artifactId>icu4j</artifactId>
148148
<version>${icu4j.version}</version>
149149
</dependency>
150+
<!-- Mime Type Resolution Libraries -->
151+
<dependency>
152+
<groupId>org.apache.tika</groupId>
153+
<artifactId>tika-core</artifactId>
154+
<version>${tika.version}</version>
155+
</dependency>
156+
<dependency>
157+
<groupId>net.sf.jmimemagic</groupId>
158+
<artifactId>jmimemagic</artifactId>
159+
<version>${jmime-magic.version}</version>
160+
</dependency>
150161
<dependency>
151162
<groupId>org.apache.commons</groupId>
152163
<artifactId>commons-dbcp2</artifactId>
@@ -162,6 +173,19 @@
162173
<artifactId>c3p0</artifactId>
163174
<version>${c3p0.version}</version>
164175
</dependency>
176+
<!-- instrumentation -->
177+
<dependency>
178+
<groupId>org.javassist</groupId>
179+
<artifactId>javassist</artifactId>
180+
<version>${javaassist.version}</version>
181+
</dependency>
182+
<dependency>
183+
<groupId>com.sun</groupId>
184+
<artifactId>tools</artifactId>
185+
<version>1.8.0</version>
186+
<scope>system</scope>
187+
<systemPath>${java.home}/../lib/tools.jar</systemPath>
188+
</dependency>
165189
</dependencies>
166190

167191
<build>
@@ -389,6 +413,111 @@
389413
</plugins>
390414
</build>
391415
</profile>
416+
417+
<!-- java instrumentation profiles to build jars -->
418+
<profile>
419+
<id>buildAgentLoader</id>
420+
<build>
421+
<plugins>
422+
<plugin>
423+
<groupId>org.apache.maven.plugins</groupId>
424+
<artifactId>maven-jar-plugin</artifactId>
425+
<executions>
426+
<execution>
427+
<phase>package</phase>
428+
<goals>
429+
<goal>jar</goal>
430+
</goals>
431+
<configuration>
432+
<classifier>agentLoader</classifier>
433+
<classesDirectory>target/classes</classesDirectory>
434+
<archive>
435+
<manifest>
436+
<addClasspath>true</addClasspath>
437+
</manifest>
438+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
439+
</archive>
440+
441+
<includes>
442+
<include>com/baeldung/instrumentation/application/AgentLoader.class</include>
443+
<include>com/baeldung/instrumentation/application/Launcher.class</include>
444+
</includes>
445+
</configuration>
446+
</execution>
447+
</executions>
448+
</plugin>
449+
</plugins>
450+
</build>
451+
</profile>
452+
<profile>
453+
<id>buildApplication</id>
454+
<build>
455+
<plugins>
456+
<plugin>
457+
<groupId>org.apache.maven.plugins</groupId>
458+
<artifactId>maven-jar-plugin</artifactId>
459+
<executions>
460+
<execution>
461+
<phase>package</phase>
462+
<goals>
463+
<goal>jar</goal>
464+
</goals>
465+
<configuration>
466+
<classifier>application</classifier>
467+
<classesDirectory>target/classes</classesDirectory>
468+
<archive>
469+
<manifest>
470+
<addClasspath>true</addClasspath>
471+
</manifest>
472+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
473+
</archive>
474+
475+
<includes>
476+
<include>com/baeldung/instrumentation/application/MyAtm.class</include>
477+
<include>com/baeldung/instrumentation/application/MyAtmApplication.class</include>
478+
<include>com/baeldung/instrumentation/application/Launcher.class</include>
479+
</includes>
480+
</configuration>
481+
</execution>
482+
</executions>
483+
</plugin>
484+
</plugins>
485+
</build>
486+
</profile>
487+
<profile>
488+
<id>buildAgent</id>
489+
<build>
490+
<plugins>
491+
<plugin>
492+
<groupId>org.apache.maven.plugins</groupId>
493+
<artifactId>maven-jar-plugin</artifactId>
494+
<executions>
495+
<execution>
496+
<phase>package</phase>
497+
<goals>
498+
<goal>jar</goal>
499+
</goals>
500+
<configuration>
501+
<classifier>agent</classifier>
502+
<classesDirectory>target/classes</classesDirectory>
503+
<archive>
504+
<manifest>
505+
<addClasspath>true</addClasspath>
506+
</manifest>
507+
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
508+
</archive>
509+
510+
<includes>
511+
<include>com/baeldung/instrumentation/agent/AtmTransformer.class</include>
512+
<include>com/baeldung/instrumentation/agent/MyInstrumentationAgent.class</include>
513+
</includes>
514+
</configuration>
515+
</execution>
516+
</executions>
517+
</plugin>
518+
</plugins>
519+
</build>
520+
</profile>
392521
</profiles>
393522

394523
<properties>
@@ -439,6 +568,11 @@
439568
<spring-boot-maven-plugin.version>2.0.3.RELEASE</spring-boot-maven-plugin.version>
440569
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
441570
<icu4j.version>61.1</icu4j.version>
571+
<!-- Mime Type Libraries -->
572+
<tika.version>1.18</tika.version>
573+
<jmime-magic.version>0.1.5</jmime-magic.version>
574+
<!-- instrumentation -->
575+
<javaassist.version>3.21.0-GA</javaassist.version>
442576
</properties>
443577

444578
</project>

0 commit comments

Comments
 (0)