-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile_single_file.sh
More file actions
executable file
·59 lines (48 loc) · 1.61 KB
/
Copy pathcompile_single_file.sh
File metadata and controls
executable file
·59 lines (48 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
# Check if a file path is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 <java_file_path>"
echo "Example: $0 src/arc2/maxPathSum.java"
exit 1
fi
# Get the absolute path of the file
FILE_TO_COMPILE=$(realpath "$1")
PROJECT_DIR=$(pwd)
# Check if the file exists
if [ ! -f "$FILE_TO_COMPILE" ]; then
echo "Error: File $FILE_TO_COMPILE does not exist"
exit 1
fi
# Check if it's a Java file
if [[ "$FILE_TO_COMPILE" != *.java ]]; then
echo "Error: $FILE_TO_COMPILE is not a Java file"
exit 1
fi
# Create a temporary file for the new compiler.xml
TEMP_FILE=$(mktemp)
# Start writing the new compiler.xml
cat > "$TEMP_FILE" << EOL
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<excludeFromCompile>
EOL
# Find all Java files and exclude all except the one to compile
find "$PROJECT_DIR/src" -name "*.java" | while read -r java_file; do
# Get the relative path for IntelliJ format
rel_path=${java_file#"$PROJECT_DIR/"}
# Skip the file we want to compile and TreeNode.java if compiling maxPathSum.java
if [ "$java_file" != "$FILE_TO_COMPILE" ] && ([ "$FILE_TO_COMPILE" != *"maxPathSum.java" ] || [ "$java_file" != *"TreeNode.java" ]); then
echo " <file url=\"file://\$PROJECT_DIR\$/${rel_path}\" />" >> "$TEMP_FILE"
fi
done
# Finish the compiler.xml file
cat >> "$TEMP_FILE" << EOL
</excludeFromCompile>
</component>
</project>
EOL
# Replace the original compiler.xml with our new one
cp "$TEMP_FILE" "$PROJECT_DIR/.idea/compiler.xml"
rm "$TEMP_FILE"
echo "Configuration updated. Only $1 will be compiled."