-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakeReferencePropsFile.java
127 lines (116 loc) · 3.77 KB
/
MakeReferencePropsFile.java
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
public class MakeReferencePropsFile {
public static void main(String[] args) throws IOException{
ArrayList<File> files = new ArrayList<File>();
listAllFiles("E:\\code\\aspnet\\aspnetcore\\src", files);
ArrayList<File> extFiles = new ArrayList<File>();
listAllFiles("E:\\code\\aspnet\\extensions\\src", extFiles);
//Maps AspNetCore projects to ProjectReferences
HashMap<String, HashSet<String>> refs = new HashMap<String, HashSet<String>>();
for (File f: files){
Scanner fileScan = new Scanner(f);
String k = fileScan.nextLine();
HashSet<String> v = new HashSet<String>();
while (fileScan.hasNextLine()){
String line = fileScan.nextLine();
if (!line.isEmpty()){
String[] parts = line.split(";");
for (String ding: parts){
v.add(ding);
}
}
}
refs.put(k, v);
}
//Maps Extensions projects to projectReferences
HashMap<String, HashSet<String>> extRefs = new HashMap<String, HashSet<String>>();
for (File f: extFiles){
Scanner fileScan = new Scanner(f);
String k2 = fileScan.nextLine();
HashSet<String> v2 = new HashSet<String>();
while (fileScan.hasNextLine()){
String line = fileScan.nextLine();
if (!line.isEmpty()){
String[] parts = line.split(";");
for (String ding: parts){
v2.add(ding);
}
}
}
extRefs.put(k2, v2);
}
//If an AspNetCore proj references an Extensions proj, add the Extensions proj's refs to the AspNetCore proj's refs
for (String s1: refs.keySet()){
HashSet<String> temp = new HashSet<String>();
for (String s2: refs.get(s1)){
if (extRefs.containsKey(s2)){
temp.addAll(extRefs.get(s2));
}
}
refs.get(s1).addAll(temp);
}
//If an AspNetCore proj references another AspNetCore proj, add the child proj's refs to the parent proj's refs
for (String s1: refs.keySet()){
HashSet<String> temp = new HashSet<String>();
for (String s2: refs.get(s1)){
if (refs.containsKey(s2)){
temp.addAll(refs.get(s2));
}
}
refs.get(s1).addAll(temp);
}
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(
"E:\\code\\scratch\\IndirectReferences.props"), true));
bw.write("<Project>");
bw.newLine();
for (String s: refs.keySet()){
HashSet<String> v = refs.get(s);
bw.write("\t<ItemGroup Condition=\"@(Reference->AnyHaveMetadataValue(\'Identity\', \'" + s + "\'))\">");
bw.newLine();
for (String ref: v){
bw.write("\t\t<IndirectReference Include=\"" + ref + "\" KeepDuplicates=\"false\" />");
bw.newLine();
}
bw.write("\t</ItemGroup>");
bw.newLine();
}
for (String s: extRefs.keySet()){
HashSet<String> v = extRefs.get(s);
bw.write("\t<ItemGroup Condition=\"@(Reference->AnyHaveMetadataValue(\'Identity\', \'" + s + "\'))\">");
bw.newLine();
for (String ref: v){
bw.write("\t\t<IndirectReference Include=\"" + ref + "\" KeepDuplicates=\"false\" />");
bw.newLine();
}
bw.write("\t</ItemGroup>");
bw.newLine();
}
bw.write("</Project>");
bw.newLine();
bw.flush();
bw.close();
}
public static void listAllFiles(String path, ArrayList<File> files){
File root = new File(path);
File[] list = root.listFiles();
if (list != null) { // In case of access error, list is null
for (File f : list) {
if (f.isDirectory()) {
listAllFiles(f.getAbsolutePath(), files);
} else {
if (f.getName().equals("ImportMe.props")){
files.add(f);
}
}
}
}
}
}