Skip to content

Commit 494bce4

Browse files
committed
1.18.1
0 parents  commit 494bce4

File tree

971 files changed

+53171
-0
lines changed

Some content is hidden

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

971 files changed

+53171
-0
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Operating System Files
2+
3+
*.DS_Store
4+
Thumbs.db
5+
*.sw?
6+
.#*
7+
*#
8+
*~
9+
*.sublime-*
10+
11+
# Build Artifacts
12+
13+
.gradle/
14+
build/
15+
target/
16+
bin/
17+
out/
18+
dependency-reduced-pom.xml
19+
20+
# Eclipse Project Files
21+
22+
.classpath
23+
.project
24+
.metadata
25+
.loadpath
26+
bin/
27+
.settings/
28+
29+
# IntelliJ IDEA Files
30+
31+
*.iml
32+
*.ipr
33+
*.iws
34+
*.idea
35+
36+
.vscode/
37+
README.html
38+

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Core Spring and Spring Boot Lab Projects
2+
3+
Labs for the Core Spring and Spring Boot courses
4+
5+
To import these labs into your IDE, import the parent pom `lab/pom.xml` as Maven projects or `lab/build.gradle` as Gradle projects.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/
19+
20+
import java.net.*;
21+
import java.io.*;
22+
import java.nio.channels.*;
23+
import java.util.Properties;
24+
25+
public class MavenWrapperDownloader {
26+
27+
/**
28+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
29+
*/
30+
private static final String DEFAULT_DOWNLOAD_URL =
31+
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
32+
33+
/**
34+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
35+
* use instead of the default one.
36+
*/
37+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
38+
".mvn/wrapper/maven-wrapper.properties";
39+
40+
/**
41+
* Path where the maven-wrapper.jar will be saved to.
42+
*/
43+
private static final String MAVEN_WRAPPER_JAR_PATH =
44+
".mvn/wrapper/maven-wrapper.jar";
45+
46+
/**
47+
* Name of the property which should be used to override the default download url for the wrapper.
48+
*/
49+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
50+
51+
public static void main(String args[]) {
52+
System.out.println("- Downloader started");
53+
File baseDirectory = new File(args[0]);
54+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
55+
56+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
57+
// wrapperUrl parameter.
58+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
59+
String url = DEFAULT_DOWNLOAD_URL;
60+
if(mavenWrapperPropertyFile.exists()) {
61+
FileInputStream mavenWrapperPropertyFileInputStream = null;
62+
try {
63+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
64+
Properties mavenWrapperProperties = new Properties();
65+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
66+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
67+
} catch (IOException e) {
68+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
69+
} finally {
70+
try {
71+
if(mavenWrapperPropertyFileInputStream != null) {
72+
mavenWrapperPropertyFileInputStream.close();
73+
}
74+
} catch (IOException e) {
75+
// Ignore ...
76+
}
77+
}
78+
}
79+
System.out.println("- Downloading from: : " + url);
80+
81+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
82+
if(!outputFile.getParentFile().exists()) {
83+
if(!outputFile.getParentFile().mkdirs()) {
84+
System.out.println(
85+
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
86+
}
87+
}
88+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
89+
try {
90+
downloadFileFromURL(url, outputFile);
91+
System.out.println("Done");
92+
System.exit(0);
93+
} catch (Throwable e) {
94+
System.out.println("- Error downloading");
95+
e.printStackTrace();
96+
System.exit(1);
97+
}
98+
}
99+
100+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
101+
URL website = new URL(urlString);
102+
ReadableByteChannel rbc;
103+
rbc = Channels.newChannel(website.openStream());
104+
FileOutputStream fos = new FileOutputStream(destination);
105+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
106+
fos.close();
107+
rbc.close();
108+
}
109+
110+
}

lab/.mvn/wrapper/maven-wrapper.jar

57.4 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar

lab/00-rewards-common/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apply plugin: 'java-library'
2+
3+
dependencies {
4+
api "org.hibernate:hibernate-entitymanager"
5+
api "com.fasterxml.jackson.core:jackson-annotations"
6+
}

lab/00-rewards-common/pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>00-rewards-common</artifactId>
5+
<organization>
6+
<name>Spring Training</name>
7+
<url>https://spring.io/training</url>
8+
</organization>
9+
<packaging>jar</packaging>
10+
<parent>
11+
<groupId>io.spring.training.core-spring</groupId>
12+
<artifactId>parentProject</artifactId>
13+
<version>5.3.23</version>
14+
</parent>
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.hibernate</groupId>
18+
<artifactId>hibernate-entitymanager</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>com.fasterxml.jackson.core</groupId>
22+
<artifactId>jackson-annotations</artifactId>
23+
</dependency>
24+
</dependencies>
25+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package common.datetime;
2+
3+
public class DateInterval {
4+
5+
private SimpleDate start;
6+
7+
private SimpleDate end;
8+
9+
public DateInterval(SimpleDate start, SimpleDate end) {
10+
this.start = start;
11+
this.end = end;
12+
}
13+
14+
public SimpleDate getStart() {
15+
return start;
16+
}
17+
18+
public SimpleDate getEnd() {
19+
return end;
20+
}
21+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package common.datetime;
2+
3+
import java.io.Serializable;
4+
import java.util.Calendar;
5+
import java.util.Date;
6+
import java.util.GregorianCalendar;
7+
import java.text.SimpleDateFormat;
8+
9+
/**
10+
* A simple wrapper around a calendar for working with dates like 12/29/1977. Does not consider time.
11+
*/
12+
public class SimpleDate implements Serializable {
13+
14+
private static final long serialVersionUID = 2285962420279644602L;
15+
16+
private GregorianCalendar base;
17+
18+
/**
19+
* Create a new simple date.
20+
* @param month the month
21+
* @param day the day
22+
* @param year the year
23+
*/
24+
public SimpleDate(int month, int day, int year) {
25+
init(new GregorianCalendar(year, month - 1, day));
26+
}
27+
28+
SimpleDate(long time) {
29+
GregorianCalendar cal = new GregorianCalendar();
30+
cal.setTimeInMillis(time);
31+
init(cal);
32+
}
33+
34+
private SimpleDate() {
35+
init(new GregorianCalendar());
36+
}
37+
38+
private void init(GregorianCalendar cal) {
39+
this.base = trimToDays(cal);
40+
}
41+
42+
private GregorianCalendar trimToDays(GregorianCalendar cal) {
43+
cal.set(Calendar.HOUR_OF_DAY, 0);
44+
cal.set(Calendar.MINUTE, 0);
45+
cal.set(Calendar.SECOND, 0);
46+
cal.set(Calendar.MILLISECOND, 0);
47+
return cal;
48+
}
49+
50+
/**
51+
* Returns this simple date as a <code>java.util.Date</code>
52+
* @return this simple date as a Date
53+
*/
54+
public Date asDate() {
55+
return base.getTime();
56+
}
57+
58+
/**
59+
* Returns this date in milliseconds since 1970.
60+
* @return
61+
*/
62+
public long inMilliseconds() {
63+
return asDate().getTime();
64+
}
65+
66+
public int compareTo(Object date) {
67+
SimpleDate other = (SimpleDate) date;
68+
return asDate().compareTo(other.asDate());
69+
}
70+
71+
public boolean equals(Object day) {
72+
if (!(day instanceof SimpleDate)) {
73+
return false;
74+
}
75+
SimpleDate other = (SimpleDate) day;
76+
return (base.equals(other.base));
77+
}
78+
79+
public int hashCode() {
80+
return 29 * base.hashCode();
81+
}
82+
83+
/**
84+
* Returns todays date. A convenient static factory method.
85+
*/
86+
public static SimpleDate today() {
87+
return new SimpleDate();
88+
}
89+
90+
/**
91+
* Converts the specified date to a SimpleDate. Will trim hour, minute, second, and millisecond fields.
92+
* @param date the java.util.Date
93+
* @return the simple date
94+
*/
95+
public static SimpleDate valueOf(Date date) {
96+
return valueOf(date.getTime());
97+
}
98+
99+
/**
100+
* Converts the specified long time value to a SimpleDate. Will trim hour, minute, second, and millisecond fields.
101+
* @param time time in millseconds since 1970
102+
* @return the time as a SimpleDate
103+
*/
104+
public static SimpleDate valueOf(long time) {
105+
return new SimpleDate(time);
106+
}
107+
108+
@Override
109+
public String toString() {
110+
return new SimpleDateFormat().format(base.getTime());
111+
}
112+
113+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package common.datetime;
2+
3+
import java.beans.PropertyEditorSupport;
4+
import java.text.DateFormat;
5+
import java.text.ParseException;
6+
import java.util.Locale;
7+
8+
/**
9+
* A formatter for Simple date properties. Converts object values to well-formatted strings and strings back to
10+
* values. Usable by a data binding framework for binding user input to the model.
11+
*/
12+
public class SimpleDateEditor extends PropertyEditorSupport {
13+
14+
private DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
15+
16+
@Override
17+
public String getAsText() {
18+
SimpleDate date = (SimpleDate) getValue();
19+
if (date == null) {
20+
return "";
21+
} else {
22+
return dateFormat.format(date.asDate());
23+
}
24+
}
25+
26+
@Override
27+
public void setAsText(String text) throws IllegalArgumentException {
28+
try {
29+
setValue(SimpleDate.valueOf(dateFormat.parse(text)));
30+
} catch (ParseException e) {
31+
throw new IllegalArgumentException("Unable to convert String '" + text + "' to a SimpleDate", e);
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)