Search in sources :

Example 1 with UrlImpl

use of com.intellij.util.UrlImpl in project Intellij-Plugin by getgauge.

the class GaugeWebBrowserPreview method previewUrl.

@Nullable
private Url previewUrl(OpenInBrowserRequest request, VirtualFile virtualFile, GaugeSettingsModel settings) throws IOException, InterruptedException {
    ProcessBuilder builder = new ProcessBuilder(settings.getGaugePath(), Constants.DOCS, Spectacle.NAME, virtualFile.getPath());
    String projectName = request.getProject().getName();
    builder.environment().put("spectacle_out_dir", FileUtil.join(createOrGetTempDirectory(projectName).getPath(), "docs"));
    File gaugeModuleDir = GaugeUtil.moduleDir(GaugeUtil.moduleForPsiElement(request.getFile()));
    builder.directory(gaugeModuleDir);
    GaugeUtil.setGaugeEnvironmentsTo(builder, settings);
    Process docsProcess = builder.start();
    int exitCode = docsProcess.waitFor();
    if (exitCode != 0) {
        String docsOutput = String.format("<pre>%s</pre>", GaugeUtil.getOutput(docsProcess.getInputStream(), " ").replace("<", "&lt;").replace(">", "&gt;"));
        Notifications.Bus.notify(new Notification("Specification Preview", "Error: Specification Preview", docsOutput, NotificationType.ERROR));
        return null;
    }
    String relativePath = FileUtil.getRelativePath(gaugeModuleDir, new File(virtualFile.getParent().getPath()));
    return new UrlImpl(FileUtil.join(createOrGetTempDirectory(projectName).getPath(), "docs", "html", relativePath, virtualFile.getNameWithoutExtension() + ".html"));
}
Also used : UrlImpl(com.intellij.util.UrlImpl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Notification (com.intellij.notification.Notification)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 UrlImpl (com.intellij.util.UrlImpl)1 File (java.io.File)1 Nullable (org.jetbrains.annotations.Nullable)1