This repository was archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDirectoryMaintainer.java
More file actions
52 lines (45 loc) · 1.73 KB
/
DirectoryMaintainer.java
File metadata and controls
52 lines (45 loc) · 1.73 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
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.lang.Process;
import java.lang.Runtime;
import java.lang.StringBuilder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.util.Scanner;
import java.util.regex.Pattern;
class DirectoryMaintainer{
public static void main(String[]a)throws Exception{
final StringBuilder builder=new StringBuilder();
final File file=new File("CONTRIBUTING.md");
try(final FileChannel channel=new FileInputStream(file).getChannel()){
final MappedByteBuffer buffer=channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
String in=Charset.forName("UTF-8").decode(buffer).toString();
builder.append(in.substring(0, in.indexOf("```shell")+8)).append("\n");
in=in.substring(in.indexOf("```shell")+8);
in=in.substring(in.indexOf("```"));
final Process proc=Runtime.getRuntime().exec("tree -a -I .git --noreport "+System.getProperty("user.dir")+"/..");
try{
proc.waitFor();
}catch(Exception e){}
try(final BufferedReader outputReader=new BufferedReader(new InputStreamReader(proc.getInputStream()))){
final Pattern dirHeader=Pattern.compile("^/.*");
String line;
while((line=outputReader.readLine())!=null){
line=dirHeader.matcher(line).replaceAll("");
if(!line.isEmpty())
builder.append(" ").append(line).append("\n");
}
}
builder.append(in);
}
file.delete();
file.createNewFile();
try(final FileWriter writer=new FileWriter(file)){
writer.write(builder.toString());
}
}
}