Skip to content

Commit 852454f

Browse files
committed
Fixed load keywords
1 parent caada42 commit 852454f

File tree

1 file changed

+8
-44
lines changed

1 file changed

+8
-44
lines changed

java/src/processing/mode/java/JavaMode.java

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -68,53 +68,17 @@ public String getTitle() {
6868
public File[] getKeywordFiles() {
6969
var url = JavaMode.class.getClassLoader().getResource("keywords.txt");
7070
if(url != null) {
71-
if(resourcesFolder == null){
72-
try {
73-
resourcesFolder = Files.createTempDirectory("processing").toFile();
74-
copyFromJar("/", resourcesFolder.toPath());
75-
return new File[] { new File(resourcesFolder, "keywords.txt") };
76-
} catch (IOException | URISyntaxException e) {
77-
e.printStackTrace();
78-
}
79-
}else{
80-
return new File[] { new File(resourcesFolder, "keywords.txt") };
81-
}
82-
83-
return new File[] { new File(url.getFile()) };
84-
}
85-
return new File[] { new File(folder, "keywords.txt") };
86-
}
87-
@Deprecated
88-
public static void copyFromJar(String source, final Path target) throws URISyntaxException, IOException {
89-
var resource = JavaMode.class.getResource("").toURI();
90-
var fileSystem = FileSystems.newFileSystem(
91-
resource,
92-
Collections.<String, String>emptyMap()
93-
);
94-
95-
96-
final Path jarPath = fileSystem.getPath(source);
71+
try{
72+
var target = Files.createTempFile("processing", "keywords.txt");
73+
Files.copy(url.openStream(), target, StandardCopyOption.REPLACE_EXISTING);
9774

98-
Files.walkFileTree(jarPath, new SimpleFileVisitor<Path>() {
99-
100-
private Path currentTarget;
101-
102-
@Override
103-
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
104-
currentTarget = target.resolve(jarPath.relativize(dir).toString());
105-
Files.createDirectories(currentTarget);
106-
return FileVisitResult.CONTINUE;
107-
}
108-
109-
@Override
110-
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
111-
Files.copy(file, target.resolve(jarPath.relativize(file).toString()), StandardCopyOption.REPLACE_EXISTING);
112-
return FileVisitResult.CONTINUE;
75+
return new File[] { target.toFile() };
76+
}catch (IOException e){
77+
e.printStackTrace();
11378
}
114-
115-
});
79+
}
80+
return super.getKeywordFiles();
11681
}
117-
11882
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11983

12084

0 commit comments

Comments
 (0)