Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.1.3 #5

Merged
merged 2 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/on-push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: ./gradlew clean build

- name: Zip JAR file
run: zip -r Baekjoon-java-starter.zip build/libs/*.jar
run: zip -r -j Baekjoon-java-starter.zip build/libs/*.jar

- run: echo "##[set-output name=version;]$(echo '${{ github.event.head_commit.message }}' | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')"
id: extract_version_name
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/kr/huni/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.Scanner;
import kr.huni.code.generator.CodeGenerator;
import kr.huni.code.runner.IntellijRunManager;
import kr.huni.problem_parser.ProblemParser;

public class Main {
Expand All @@ -15,7 +16,8 @@ public static void main(String[] args) throws IllegalArgumentException, IOExcept

CodeGenerator generator = new CodeGenerator(parser.getProblem());
generator.generate();
generator.runIdea();
IntellijRunManager runManager = new IntellijRunManager();
runManager.run(parser.getProblem().getDirectory());

scanner.close();
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/kr/huni/code/generator/CodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,4 @@ public void generate() throws IOException {
fileUtil.write(codeTemplate, testCodeTemplate);
logger.info("소스코드 생성 완료");
}

public void runIdea() throws IOException {
String command = "idea " + this.problem.getDirectory();
Runtime.getRuntime().exec(command);
}
}
20 changes: 20 additions & 0 deletions src/main/java/kr/huni/code/os/OperatingSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package kr.huni.code.os;

public enum OperatingSystem {
WINDOWS,
LINUX,
MAC;

public static OperatingSystem getOperatingSystem() {
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("win")) {
return WINDOWS;
} else if (osName.contains("nix") || osName.contains("nux") || osName.contains("aix")) {
return LINUX;
} else if (osName.contains("mac")) {
return MAC;
} else {
throw new RuntimeException("지원하지 않는 운영체제입니다. (현재 운영체제: " + osName + ")");
}
}
}
40 changes: 40 additions & 0 deletions src/main/java/kr/huni/code/runner/IntellijRunManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package kr.huni.code.runner;

import java.io.IOException;
import kr.huni.code.os.OperatingSystem;

public class IntellijRunManager {

private final OperatingSystem operatingSystem;

public IntellijRunManager() {
this.operatingSystem = OperatingSystem.getOperatingSystem();
}

public void run(String codePath) throws IOException {
Command command = switch (this.operatingSystem) {
case WINDOWS -> new Command("where idea", "idea");
case LINUX, MAC -> new Command("which idea", "idea");
};

boolean ideaExist = Runtime.getRuntime().exec(command.existCheckCommand).exitValue() == 0;
if (ideaExist) {
Runtime.getRuntime().exec(command.ideaFileName + " " + codePath);
return;
}

System.out.printf("""
[ERROR]
IntelliJ IDEA의 idea 명령어가 설치되어 있지 않습니다.
직접 IntelliJ IDEA를 실행해서 프로젝트를 열어주세요.
생성된 프로젝트 경로 : %s
%n""", codePath);
}

private record Command(
String existCheckCommand,
String ideaFileName
) {

}
}
Loading