From 4a407a7c46fd91f462151cdcfa735336a2556010 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Fri, 8 Apr 2016 12:47:17 +0300 Subject: [PATCH] inspection tool window: inspection report: read and copy css&js files from resources --- platform/lang-impl/lang-impl.iml | 1 + .../resources/inspectionReport/script.js | 23 +++++ .../resources/inspectionReport/styles.css | 94 +++++++++++++++++++ .../export/InspectionTreeCss.java | 92 ------------------ .../InspectionTreeHtmlExportResources.java | 47 ++++++++++ .../export/InspectionTreeHtmlWriter.java | 23 +++-- 6 files changed, 176 insertions(+), 104 deletions(-) create mode 100644 platform/lang-impl/resources/inspectionReport/script.js create mode 100644 platform/lang-impl/resources/inspectionReport/styles.css delete mode 100644 platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeCss.java create mode 100644 platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeHtmlExportResources.java diff --git a/platform/lang-impl/lang-impl.iml b/platform/lang-impl/lang-impl.iml index 197da8ac8d8f..f3ff6f061860 100644 --- a/platform/lang-impl/lang-impl.iml +++ b/platform/lang-impl/lang-impl.iml @@ -5,6 +5,7 @@ + diff --git a/platform/lang-impl/resources/inspectionReport/script.js b/platform/lang-impl/resources/inspectionReport/script.js new file mode 100644 index 000000000000..9a267ef43c06 --- /dev/null +++ b/platform/lang-impl/resources/inspectionReport/script.js @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author: Dmitry Batkovich + */ +function navigate(an_id) { + problem_div = document.getElementById("d" + an_id); + preview_div = document.getElementById("preview"); + preview_div.innerHTML = problem_div != null ? problem_div.innerHTML : "Select a problem element in tree"; +} \ No newline at end of file diff --git a/platform/lang-impl/resources/inspectionReport/styles.css b/platform/lang-impl/resources/inspectionReport/styles.css new file mode 100644 index 000000000000..4da0d083e3a8 --- /dev/null +++ b/platform/lang-impl/resources/inspectionReport/styles.css @@ -0,0 +1,94 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +html { + font-family: \Helvetica Neue\, Helvetica, Arial, \Lucida Grande\, sans-serif; +} + +body { + color: #4C4C4C; + margin: 60px 60px 0 60px; +} + +p { + font-size: 1em; + margin: 0 0 1em 0; +} + +.grayout { + opacity: 0.6; +} + +body, input, select, textarea, th, td { + font-size: 1em; +} + +li { + position: relative; + list-style: none; +} + +label:hover { + color: #0C479D; + text-decoration: underline; +} + +li::before { + content: "\23FA"; + margin: 0; +} + +li input { + position: absolute; + left: 0; + margin-left: 0; + background: none; + opacity: 0; + z-index: 2; + cursor: pointer; + height: 1em; + width: 1em; + top: 0; +} + +li input + ol { + margin: -15px 0 0 -44px; + height: 1em; +} + +li input + ol > li { + display: none; + margin-left: -14px !important; + padding-left: 1px; +} + +li label { + padding-left: 5px; +} + +li input:checked + ol { + margin: -20px 0 0 -44px; + padding: 25px 0 0 80px; + height: auto; +} + +li input:checked + ol > li { + display: block; + margin: 0 0 2px; +} + +li input:checked + ol > li:last-child { + margin: 0 0 1px; +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeCss.java b/platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeCss.java deleted file mode 100644 index 6f6ce92e118a..000000000000 --- a/platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeCss.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.codeInspection.export; - -/** - * @author Dmitry Batkovich - */ -class InspectionTreeCss { - static final String CSS_TEXT; - - static { - CSS_TEXT = "html {\n" + - " font-family: \"Helvetica Neue\", Helvetica, Arial, \"Lucida Grande\", sans-serif;\n" + - "}\n" + - "body {\n" + - " color: #4C4C4C;\n" + - " margin: 60px 60px 0 60px;\n" + - "}\n" + - "p {\n" + - " font-size: 1em;\n" + - " margin: 0 0 1em 0;\n" + - "}\n" + - ".grayout {\n" + - " opacity: 0.6;\n" + - "}\n" + - "body, input, select, textarea, th, td {\n" + - " font-size: 1em;\n" + - "}\n" + - "li {\n" + - " position: relative;\n" + - " list-style: none;\n" + - "}\n" + - "label:hover {\n" + - " color: #0C479D;\n" + - " text-decoration: underline;\n" + - "}\n" + - "li::before {\n" + - " content: \"\\23FA\";\n" + - " margin: 0;\n" + - "}\n" + - "li input {\n" + - " position: absolute;\n" + - " left: 0;\n" + - " margin-left: 0;\n" + - " background: none;\n" + - " opacity: 0;\n" + - " z-index: 2;\n" + - " cursor: pointer;\n" + - " height: 1em;\n" + - " width: 1em;\n" + - " top: 0;\n" + - " content: \"some text>\";\n" + - "}\n" + - "li input + ol {\n" + - " margin: -15px 0 0 -44px;\n" + - " height: 1em;\n" + - "}\n" + - "li input + ol > li {\n" + - " display: none;\n" + - " margin-left: -14px !important;\n" + - " padding-left: 1px;\n" + - "}\n" + - "li label {\n" + - " padding-left: 5px;\n" + - "}\n" + - "li input:checked + ol {\n" + - " margin: -20px 0 0 -44px;\n" + - " padding: 25px 0 0 80px;\n" + - " height: auto;\n" + - "}\n" + - "li input:checked + ol > li {\n" + - " display: block;\n" + - " margin: 0 0 2px;\n" + - "}\n" + - "li input:checked + ol > li:last-child {\n" + - " margin: 0 0 1px;\n" + - "}"; - } -} diff --git a/platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeHtmlExportResources.java b/platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeHtmlExportResources.java new file mode 100644 index 000000000000..eef7e01bacd4 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeHtmlExportResources.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInspection.export; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.io.FileUtil; + +import java.io.*; +/** + * @author Dmitry Batkovich + */ +class InspectionTreeHtmlExportResources { + private static final Logger LOG = Logger.getInstance(InspectionTreeHtmlExportResources.class); + + static void copyInspectionReportResources(final String targetDirectory) { + copyInspectionReportResource("styles.css", targetDirectory); + copyInspectionReportResource("script.js", targetDirectory); + } + + private static void copyInspectionReportResource(final String resourceName, final String targetDirectory) { + final File resourceTargetFile = new File(targetDirectory, resourceName); + if (!FileUtil.createIfDoesntExist(resourceTargetFile)) { + LOG.error("Can't create file: " + resourceTargetFile.getAbsolutePath()); + } + try (InputStream input = InspectionTreeHtmlExportResources.class.getClassLoader().getResourceAsStream("/inspectionReport/" + resourceName)) { + try (OutputStream f = new FileOutputStream(resourceTargetFile)) { + FileUtil.copy(input, f); + } + } + catch (IOException e) { + LOG.error(e); + } + } +} diff --git a/platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeHtmlWriter.java b/platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeHtmlWriter.java index 53c465abe7b9..d5daa854e6f7 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeHtmlWriter.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/export/InspectionTreeHtmlWriter.java @@ -42,6 +42,7 @@ public class InspectionTreeHtmlWriter { private final StringBuffer myBuilder = new StringBuffer(); private final InspectionProfile myProfile; private final RefManager myManager; + private final ExcludedInspectionTreeNodesManager myExcludedManager; public InspectionTreeHtmlWriter(InspectionTree tree, String outputDir) { @@ -49,12 +50,16 @@ public class InspectionTreeHtmlWriter { myOutputDir = outputDir; myProfile = tree.getContext().getCurrentProfile(); myManager = tree.getContext().getRefManager(); + myExcludedManager = tree.getContext().getView().getExcludedManager(); serializeTreeToHtml(); } - private static void traverseInspectionTree(final InspectionTreeNode node, + private void traverseInspectionTree(final InspectionTreeNode node, final Consumer preAction, final Consumer postAction) { + if (node.isResolved(myExcludedManager)) { + return; + } preAction.accept(node); for (int i = 0; i < node.getChildCount(); i++) { traverseInspectionTree((InspectionTreeNode)node.getChildAt(i), preAction, postAction); @@ -104,7 +109,7 @@ public class InspectionTreeHtmlWriter { }); HTMLExportUtil.writeFile(myOutputDir, "index.html", myBuilder, myTree.getContext().getProject()); - HTMLExportUtil.writeFile(myOutputDir, "styles.css", InspectionTreeCss.CSS_TEXT, myTree.getContext().getProject()); + InspectionTreeHtmlExportResources.copyInspectionReportResources(myOutputDir); } private String convertNodeToHtml(InspectionTreeNode node) { @@ -161,17 +166,11 @@ public class InspectionTreeHtmlWriter { myBuilder.append("" + "" + "" + - "" + + "" + + "" + "") - .append(title).append("

") + .append(title) + .append("

") .append(title) .append(":

"); }