File tree 4 files changed +49
-0
lines changed
Chapter06/BONUS_1_GetCurrentProjectRootDirectory
src/main/java/modern/challenge
4 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Converting ` Date ` to ` YearMonth `
2
+ Write a program that converts an ` Date ` to ` YearMonth ` and vice-versa.
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
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/xsd/maven-4.0.0.xsd" >
3
+ <modelVersion >4.0.0</modelVersion >
4
+ <groupId >com.app</groupId >
5
+ <artifactId >BONUS_1_GetCurrentProjectRootDirectory</artifactId >
6
+ <version >1.0-SNAPSHOT</version >
7
+ <packaging >jar</packaging >
8
+ <properties >
9
+ <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
10
+ <maven .compiler.source>13</maven .compiler.source>
11
+ <maven .compiler.target>13</maven .compiler.target>
12
+ </properties >
13
+ <name >BONUS_1_GetCurrentProjectRootDirectory</name >
14
+ </project >
Original file line number Diff line number Diff line change
1
+ package modern .challenge ;
2
+
3
+ public class MainApplication {
4
+
5
+ public static void main (String [] args ) {
6
+
7
+ System .out .println ("The root directory of this project is:\n "
8
+ + Roots .getCurrentProjectRootDirectory ());
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ package modern .challenge ;
2
+
3
+ import java .nio .file .Path ;
4
+ import java .nio .file .Paths ;
5
+
6
+ public class Roots {
7
+
8
+ private Roots () {
9
+ throw new AssertionError ("Cannot be instantiatied" );
10
+ }
11
+
12
+ public static String getCurrentProjectRootDirectory () {
13
+
14
+ String userDirectory = System .getProperty ("user.dir" );
15
+ Path rootDirectory = Paths .get ("." ).normalize ().toAbsolutePath ();
16
+
17
+ if (rootDirectory .startsWith (userDirectory )) {
18
+ return rootDirectory .toString ();
19
+ } else {
20
+ throw new RuntimeException ("Cannot find the current project root directory" );
21
+ }
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments