Skip to content

Commit 172441f

Browse files
committed
working draft
1 parent 980469e commit 172441f

35 files changed

+857
-784
lines changed

build-caching/pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,24 @@
2525
<artifactId>guava</artifactId>
2626
</dependency>
2727

28+
<dependency>
29+
<groupId>org.jspecify</groupId>
30+
<artifactId>jspecify</artifactId>
31+
<version>0.2.0</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>org.javassist</groupId>
36+
<artifactId>javassist</artifactId>
37+
<version>3.28.0-GA</version>
38+
</dependency>
39+
40+
2841
<!-- watch service -->
2942
<dependency>
3043
<groupId>io.methvin</groupId>
3144
<artifactId>directory-watcher</artifactId>
32-
<version>0.15.0</version>
45+
<version>0.15.1</version>
3346
</dependency>
3447

3548
<!-- Test -->

build-caching/src/main/java/com/vertispan/j2cl/build/BuildMap.java

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
11
package com.vertispan.j2cl.build;
22

3-
import java.io.BufferedReader;
4-
import java.io.File;
5-
import java.io.FileReader;
3+
import com.google.common.collect.Streams;
4+
65
import java.io.IOException;
76
import java.nio.file.Files;
87
import java.nio.file.Path;
9-
import java.nio.file.Paths;
10-
import java.nio.file.attribute.FileTime;
118
import java.util.ArrayList;
129
import java.util.Collection;
1310
import java.util.HashMap;
1411
import java.util.HashSet;
15-
import java.util.Iterator;
1612
import java.util.List;
1713
import java.util.Map;
1814
import java.util.Set;
1915
import java.util.stream.Collectors;
20-
import java.util.stream.Stream;
21-
22-
import com.google.common.base.Splitter;
23-
import com.google.common.collect.Streams;
2416

2517
public class BuildMap {
26-
private Project project;
18+
private Project project;
2719

2820

29-
private Map<String, TypeInfo> typeInfos = new HashMap<>();
21+
private Map<String, TypeInfo> typeInfos = new HashMap<>();
3022

31-
private Map<String, String> pathToQualifiedSourceName = new HashMap<>();
32-
private Map<String, String> qualifiedSourceNameToPath = new HashMap<>();
23+
private Map<String, String> pathToQualifiedSourceName = new HashMap<>();
24+
private Map<String, String> qualifiedSourceNameToPath = new HashMap<>();
3325

34-
private List<String> childrenChangedFiles = new ArrayList<>();;
26+
private List<String> childrenChangedFiles = new ArrayList<>();
27+
;
3528

36-
private Set<String> changedFiles = new HashSet<>();;
29+
private Set<String> changedFiles = new HashSet<>();
30+
;
3731

38-
private Set<String> expandedFiles = new HashSet<>();
32+
private Set<String> expandedFiles = new HashSet<>();
3933

40-
private List<String> filesToDelete = new ArrayList<>();
34+
private List<String> filesToDelete = new ArrayList<>();
4135

4236
private Map<String, ProjectFiles> dirToprojectFiles;
4337

@@ -63,7 +57,6 @@ public Map<String, ProjectFiles> getDirToprojectFiles() {
6357
}
6458

6559
/**
66-
*
6760
* @param dir
6861
*/
6962
public void build(Path dir) {
@@ -72,7 +65,7 @@ public void build(Path dir) {
7265
}
7366

7467
private void populateFilesToDelete() {
75-
// Merge all except added - which by it's nature has nothing nothing needed deleting
68+
// Merge all except added - which by it's nature has nothing needed deleting
7669
for (ProjectFiles p : dirToprojectFiles.values()) {
7770
filesToDelete.addAll(p.getRemoved());
7871
filesToDelete.addAll(p.getUpdated());
@@ -86,7 +79,7 @@ private void buildAndProcessChangedFiles(Path dir) {
8679
expandChangedFiles();
8780

8881
// Populate the complete list of potentially changed files
89-
for(ProjectFiles projectFiles : dirToprojectFiles.values()) {
82+
for (ProjectFiles projectFiles : dirToprojectFiles.values()) {
9083
changedFiles.addAll(projectFiles.getUpdated());
9184
changedFiles.addAll(projectFiles.getAdded());
9285
}
@@ -98,42 +91,45 @@ public List<String> getFilesToDelete() {
9891
}
9992

10093
public void expandChangedFiles() {
101-
for(ProjectFiles projectFiles : dirToprojectFiles.values()) {
94+
for (ProjectFiles projectFiles : dirToprojectFiles.values()) {
10295
expandChangedFiles(projectFiles.getUpdated(), expandedFiles);
10396
}
10497
expandChangedFiles(childrenChangedFiles, expandedFiles);
10598
}
99+
106100
public void expandChangedFiles(Collection<String> files, Set<String> expanded) {
107101
for (String file : files) {
108102
if (!file.endsWith(".java")) {
109103
continue;
110104
}
111-
String typeName = pathToQualifiedSourceName.get(file);
105+
String typeName = pathToQualifiedSourceName.get(file);
112106
TypeInfo typeInfo = typeInfos.get(typeName);
113107
expandChangedFiles(typeInfo, expanded);
114108
}
115109
}
116110

117111
private void expandChangedFiles(TypeInfo typeInfo, Set<String> changedFiles) {
118112
// Anything that extends this is added to the set, and it also recurses through the extends
119-
for (TypeDependency dep : typeInfo.getSuperIn() ) {
113+
for (TypeDependency dep : typeInfo.getSuperIn()) {
120114
maybeAddNativeFile(dep.outgoing);
121115
changedFiles.add(qualifiedSourceNameToPath.get(dep.outgoing.getQualifiedSourceName()));
122116
expandChangedFiles(dep.outgoing, changedFiles);
123117
}
124118

125119
// Anything that implements (or extends) this interface, is added to the set.
126120
// TODO Does this need to be done for transitive interface impl? (mdp)
127-
for (TypeDependency dep : typeInfo.getInterfacesIn() ) {
121+
for (TypeDependency dep : typeInfo.getInterfacesIn()) {
128122
maybeAddNativeFile(dep.outgoing);
129123
changedFiles.add(qualifiedSourceNameToPath.get(dep.outgoing.getQualifiedSourceName()));
130-
131124
// Recurse the ancestors, as the interface may have default methods
132125
// that changes the call hieararchy of the implementor.
133126
expandChangedFiles(dep.outgoing, changedFiles);
134127
}
135128

129+
136130
// Now add all the dependencies
131+
132+
137133
for (TypeDependency dep : typeInfo.getMethodFieldIn()) {
138134
maybeAddNativeFile(dep.outgoing);
139135
changedFiles.add(qualifiedSourceNameToPath.get(dep.outgoing.getQualifiedSourceName()));
@@ -189,12 +185,11 @@ private void createBuildMaps(Map<String, TypeInfoDescr> typeInfoDescrs) {
189185
incoming.getInterfacesIn().add(d);
190186
}
191187
}
192-
193188
// Add dependencies, that are not one of the above.
194189
for (String type : typeInfoDescr.dependencies) {
195190
TypeInfo incoming = getType(type);
196191
if (incoming != null) {
197-
TypeDependency d = new TypeDependency(incoming,outgoing);
192+
TypeDependency d = new TypeDependency(incoming, outgoing);
198193
outgoing.getMethodFieldOut().add(d);
199194
incoming.getMethodFieldIn().add(d);
200195
}
@@ -208,7 +203,7 @@ private Map<String, TypeInfoDescr> readBuildMapDescrForAllFiles(Path dir, Map<St
208203
// need to handle references.
209204
// Must also put in stuff that was just deleted, so we can handle the actual deletion.
210205
for (String javaFileName : Streams.concat(projectFiles.getAll().stream(),
211-
projectFiles.getRemoved().stream()).collect(Collectors.toList())) {
206+
projectFiles.getRemoved().stream()).collect(Collectors.toList())) {
212207
if (projectFiles.getAdded().contains(javaFileName)) {
213208
// ignore just added files, they won't have a build.map yet
214209
continue;
@@ -221,10 +216,13 @@ private Map<String, TypeInfoDescr> readBuildMapDescrForAllFiles(Path dir, Map<St
221216
}
222217

223218
private void readBuildMapDescrForFileName(String javaFileName, Map<String, TypeInfoDescr> typeInfoDescrs, Path dir) {
219+
220+
224221
if (javaFileName.endsWith(".java")) {
225222
String fileName = javaFileName.substring(0, javaFileName.lastIndexOf(".java"));
226223
String buildMapFileName = fileName + ".build.map";
227-
Path buildMapPath = dir.resolve("results").resolve(buildMapFileName);
224+
Path buildMapPath = dir.resolve(buildMapFileName);
225+
228226
if (Files.notExists(buildMapPath)) {
229227
throw new RuntimeException("build.map files must exist for all changed .java files");
230228
}
@@ -305,7 +303,7 @@ String getAndInc() {
305303

306304
// skip any empty lines
307305
while (lineNbr < lines.size() &&
308-
lines.get(lineNbr).trim().isEmpty()) {
306+
lines.get(lineNbr).trim().isEmpty()) {
309307
lineNbr++;
310308
}
311309

@@ -334,7 +332,7 @@ static class TypeInfoDescr {
334332

335333
public TypeInfoDescr(String qualifiedSourceName, String qualifiedBinaryName, String nativePathName) {
336334
this.qualifiedSourceName = qualifiedSourceName;
337-
this.qualifiedBinaryName = qualifiedBinaryName != null && !qualifiedBinaryName.trim().isEmpty() ? qualifiedBinaryName : qualifiedSourceName;
335+
this.qualifiedBinaryName = qualifiedBinaryName != null && !qualifiedBinaryName.trim().isEmpty() ? qualifiedBinaryName : qualifiedSourceName;
338336
this.nativePathName = nativePathName;
339337

340338
this.innerTypes = new ArrayList<>();
@@ -346,17 +344,18 @@ public List<String> dependencies() {
346344
return dependencies;
347345
}
348346

349-
@Override public String toString() {
347+
@Override
348+
public String toString() {
350349
return "TypeInfoDescr{" +
351-
"qualifiedSourceName='" + qualifiedSourceName + '\'' +
352-
", qualifiedBinaryName='" + qualifiedBinaryName + '\'' +
353-
", superTypeName='" + superTypeName + '\'' +
354-
", nativePathName='" + nativePathName + '\'' +
355-
", enclosingType='" + enclosingType + '\'' +
356-
", innerTypes=" + innerTypes +
357-
", interfaces=" + interfaces +
358-
", dependencies=" + dependencies +
359-
'}';
350+
"qualifiedSourceName='" + qualifiedSourceName + '\'' +
351+
", qualifiedBinaryName='" + qualifiedBinaryName + '\'' +
352+
", superTypeName='" + superTypeName + '\'' +
353+
", nativePathName='" + nativePathName + '\'' +
354+
", enclosingType='" + enclosingType + '\'' +
355+
", innerTypes=" + innerTypes +
356+
", interfaces=" + interfaces +
357+
", dependencies=" + dependencies +
358+
'}';
360359
}
361360
}
362361

@@ -374,7 +373,7 @@ TypeInfoDescr readBuildMapSources(LineReader reader, Map<String, TypeInfoDescr>
374373
}
375374

376375
String nativePathName = null; // optional
377-
if (!reader.peekNext().startsWith("-") ) {
376+
if (!reader.peekNext().startsWith("-")) {
378377
// native file specified
379378
nativePathName = reader.getAndInc();
380379
}
@@ -390,7 +389,7 @@ public void readHierarchyAndInnerTypes(LineReader reader, TypeInfoDescr typeInfo
390389
if (!line.startsWith("- hierarchy")) {
391390
throw new RuntimeException("Illegal File Format, the next element must be '-hierarchy' at line " + reader.lineNbr);
392391
}
393-
if (!reader.peekNext().startsWith("-") ) {
392+
if (!reader.peekNext().startsWith("-")) {
394393
line = reader.getAndInc();
395394
String[] segments = line.split(":", -1);
396395
if (segments.length != 2) {
@@ -415,7 +414,7 @@ public void readHierarchyAndInnerTypes(LineReader reader, TypeInfoDescr typeInfo
415414
if (!line.startsWith("- innerTypes")) {
416415
throw new RuntimeException("Illegal File Format, the next element must be '-innerTypes' at line " + reader.lineNbr);
417416
}
418-
if (!reader.peekNext().startsWith("-") ) {
417+
if (!reader.peekNext().startsWith("-")) {
419418
String[] innerTypes = reader.getAndInc().split(":", -1);
420419

421420
String ext = ".build.map";
@@ -432,9 +431,9 @@ public void readHierarchyAndInnerTypes(LineReader reader, TypeInfoDescr typeInfo
432431
// String fileName = innerTypeName.substring(penDot+1) + "$" + innerTypeName.substring(lastDot+1) + ext;
433432

434433
String fileName = buildMapPath.getFileName().toString();
435-
fileName = fileName.substring(0, fileName.length() -ext.length()) + "$" + innerTypeName.substring(lastDot+1) + ext;
436-
437-
Path innerBuildMapPath = buildMapPath.getParent().resolve( fileName );
434+
//fileName = fileName.substring(0, fileName.length() -ext.length()) + "$" + innerTypeName.substring(lastDot+1) + ext;
435+
fileName = innerTypeName.substring(lastDot + 1) + ext;
436+
Path innerBuildMapPath = buildMapPath.getParent().resolve(fileName);
438437
if (!Files.exists(innerBuildMapPath)) {
439438
throw new RuntimeException("InnerType .build.map file must exist: " + innerBuildMapPath);
440439
}
@@ -447,15 +446,15 @@ public void readHierarchyAndInnerTypes(LineReader reader, TypeInfoDescr typeInfo
447446
}
448447

449448
void readBuildMapInterfaces(LineReader reader, TypeInfoDescr typeInfoDescr) {
450-
451-
while( reader.hasNext() && !reader.peekNext().startsWith("- ")) {
449+
450+
while (reader.hasNext() && !reader.peekNext().startsWith("- ")) {
452451
String typeName = reader.getAndInc();
453452
typeInfoDescr.interfaces.add(typeName);
454453
}
455454
}
456455

457456
void readBuildMapDependencies(LineReader reader, TypeInfoDescr typeInfoDescr) {
458-
while(reader.hasNext() && !reader.peekNext().startsWith("-")) {
457+
while (reader.hasNext() && !reader.peekNext().startsWith("-")) {
459458
String typeName = reader.getAndInc();
460459
typeInfoDescr.dependencies.add(typeName);
461460
}
@@ -475,6 +474,7 @@ private void checkFileFormat(String str, int i) {
475474
/**
476475
* Clone the SourceMap to the TargetMap. Exclude MethodField TypeDependency references, these are not relevant to the parent
477476
* projects that consume this BuildMap.
477+
*
478478
* @param target
479479
*/
480480
public void cloneToTargetBuildMap(BuildMap target) {
@@ -490,7 +490,7 @@ public void cloneToTargetBuildMap(BuildMap target) {
490490
target.pathToQualifiedSourceName.putAll(pathToQualifiedSourceName);
491491
target.qualifiedSourceNameToPath.putAll(qualifiedSourceNameToPath);
492492

493-
for(ProjectFiles projectFiles : dirToprojectFiles.values()) {
493+
for (ProjectFiles projectFiles : dirToprojectFiles.values()) {
494494
target.childrenChangedFiles.addAll(projectFiles.getUpdated());
495495
}
496496

0 commit comments

Comments
 (0)