Skip to content

Commit a2bccc7

Browse files
authored
Merge pull request #5 from codecrafters-io/CC-1274-java
Add Java support
2 parents 9a77e45 + 67aee12 commit a2bccc7

File tree

24 files changed

+416
-0
lines changed

24 files changed

+416
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

compiled_starters/java/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
java_shell.jar
2+
target/*
3+
target/
4+
.idea/

compiled_starters/java/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/shell.png)
2+
3+
This is a starting point for Java solutions to the
4+
["Build Your Own Shell" Challenge](https://app.codecrafters.io/courses/shell/overview).
5+
6+
In this challenge, you'll build your own POSIX compliant shell that's capable of
7+
interpreting shell commands, running external programs and builtin commands like
8+
cd, pwd, echo and more. Along the way, you'll learn about shell command parsing,
9+
REPLs, builtin commands, and more.
10+
11+
**Note**: If you're viewing this repo on GitHub, head over to
12+
[codecrafters.io](https://codecrafters.io) to try the challenge.
13+
14+
# Passing the first stage
15+
16+
The entry point for your `shell` implementation is in `src/main/java/Main.java`.
17+
Study and uncomment the relevant code, and push your changes to pass the first
18+
stage:
19+
20+
```sh
21+
git add .
22+
git commit -m "pass 1st stage" # any msg
23+
git push origin master
24+
```
25+
26+
Time to move on to the next stage!
27+
28+
# Stage 2 & beyond
29+
30+
Note: This section is for stages 2 and beyond.
31+
32+
1. Ensure you have `java (21)` installed locally
33+
1. Run `./your_shell.sh` to run your program, which is implemented in
34+
`src/main/java/Main.java`.
35+
1. Commit your changes and run `git push origin master` to submit your solution
36+
to CodeCrafters. Test output will be streamed to your terminal.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set this to true if you want debug logs.
2+
#
3+
# These can be VERY verbose, so we suggest turning them off
4+
# unless you really need them.
5+
debug: false
6+
7+
# Use this to change the Java version used to run your code
8+
# on Codecrafters.
9+
#
10+
# Available versions: java-21
11+
language_pack: java-21

compiled_starters/java/pom.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>io.codecrafters</groupId>
8+
<artifactId>build-your-own-shell</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>21</maven.compiler.source>
13+
<maven.compiler.target>21</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<java.version>21</java.version>
16+
</properties>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-assembly-plugin</artifactId>
23+
<configuration>
24+
<finalName>java_shell</finalName> <!-- Please do not change this final artifact name-->
25+
<descriptorRefs>
26+
<descriptorRef>jar-with-dependencies</descriptorRef>
27+
</descriptorRefs>
28+
<appendAssemblyId>false</appendAssemblyId>
29+
<archive>
30+
<manifest>
31+
<addClasspath>true</addClasspath>
32+
<!-- This is the main class of your program which will be executed-->
33+
<mainClass>Main</mainClass>
34+
</manifest>
35+
</archive>
36+
<outputDirectory>${dir}</outputDirectory>
37+
</configuration>
38+
39+
<executions>
40+
<execution>
41+
<id>make-assembly</id>
42+
<phase>package</phase>
43+
<goals>
44+
<goal>single</goal>
45+
</goals>
46+
</execution>
47+
</executions>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Uncomment this block to pass the first stage
2+
// import java.util.Scanner;
3+
4+
public class Main {
5+
public static void main(String[] args) throws Exception {
6+
// You can use print statements as follows for debugging, they'll be visible when running tests.
7+
System.out.println("Logs from your program will appear here!");
8+
9+
// Uncomment this block to pass the first stage
10+
// System.out.print("$ ");
11+
//
12+
// Scanner scanner = new Scanner(System.in);
13+
// String input = scanner.nextLine();
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
#
3+
# DON'T EDIT THIS!
4+
#
5+
# CodeCrafters uses this file to test your code. Don't make any changes here!
6+
#
7+
# DON'T EDIT THIS!
8+
set -e
9+
mvn -B --quiet package -Ddir=/tmp/codecrafters-shell-target
10+
exec java -jar /tmp/codecrafters-shell-target/java_shell.jar "$@"

course-definition.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ languages:
1919
- slug: "go"
2020
- slug: "python"
2121
- slug: "rust"
22+
- slug: "java"
2223
- slug: "javascript"
2324
- slug: "c"
2425

dockerfiles/java-21.Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM maven:3.9.5-eclipse-temurin-21-alpine
2+
3+
COPY pom.xml /app/pom.xml
4+
5+
WORKDIR /app
6+
7+
# Download the dependencies
8+
RUN mvn -B package -Ddir=/tmp/codecrafters-shell-target
9+
10+
# Cache Dependencies
11+
RUN mkdir -p /app-cached
12+
RUN mv /app/target /app-cached # Is this needed?
13+
14+
# Pre-compile steps
15+
RUN printf "cd \${CODECRAFTERS_SUBMISSION_DIR} && mvn -B package -Ddir=/tmp/codecrafters-shell-target && sed -i 's/^\(mvn .*\)/#\1/' ./your_shell.sh" > /codecrafters-precompile.sh
16+
RUN chmod +x /codecrafters-precompile.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

0 commit comments

Comments
 (0)