Skip to content

Commit 33392f4

Browse files
thelsingadrienbaron
authored andcommitted
copy html to output path before building java file
1 parent 36acbaa commit 33392f4

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/main/java/com/axellience/vuegwtplugin/VueGWTFileWatcher.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.axellience.vuegwtplugin;
22

3+
import com.intellij.openapi.compiler.CompilerPaths;
4+
import com.intellij.openapi.compiler.ex.CompilerPathsEx;
5+
import com.intellij.openapi.vfs.VfsUtil;
6+
import com.intellij.openapi.vfs.VirtualFileManager;
37
import org.jetbrains.annotations.NotNull;
48
import org.jetbrains.annotations.Nullable;
59
import org.jetbrains.concurrency.Promise;
@@ -19,6 +23,11 @@
1923
import com.intellij.psi.PsiDocumentManager;
2024
import com.intellij.psi.PsiFile;
2125

26+
import java.io.IOException;
27+
import java.nio.file.Files;
28+
import java.nio.file.Path;
29+
import java.nio.file.StandardCopyOption;
30+
2231
public class VueGWTFileWatcher implements FileDocumentManagerListener {
2332

2433
private static final Logger LOGGER = Logger.getInstance(VueGWTFileWatcher.class);
@@ -67,11 +76,27 @@ private void compileComponent(VirtualFile javaComponent, VirtualFile htmlTemplat
6776
if (module == null) {
6877
return;
6978
}
79+
var sourceRoot = projectFileIndex.getSourceRootForFile(javaComponent);
80+
if(sourceRoot == null)
81+
return;
82+
83+
var htmlPath = htmlTemplate.getPath();
84+
var relativeHtmlPath = htmlPath.substring(sourceRoot.getPath().length());
85+
var outputs = CompilerPaths.getOutputPaths(new Module[] { module });
86+
if(outputs.length == 0)
87+
return;
88+
89+
var targetPath = Path.of(outputs[0], relativeHtmlPath);
90+
try {
91+
Files.copy(Path.of(htmlPath), targetPath, StandardCopyOption.REPLACE_EXISTING);
92+
} catch (IOException e) {
93+
return;
94+
}
7095

7196
CompilerManager compilerManager = CompilerManager.getInstance(project);
7297
if (!compilerManager.isCompilationActive()
7398
&& !compilerManager.isExcludedFromCompilation(javaComponent)) {
74-
compilerManager.compile(new VirtualFile[] {javaComponent, htmlTemplate}, null);
99+
compilerManager.compile(new VirtualFile[] {javaComponent}, null);
75100
}
76101
});
77102
}

0 commit comments

Comments
 (0)