From 506f7989e04e48bf36663f126ef7d66e333092e3 Mon Sep 17 00:00:00 2001 From: peter Date: Mon, 14 Jan 2019 22:16:43 +0100 Subject: [PATCH] Revert "IDEA-201136 Update velocity library to 2.0" it's too troublesome and has no clear benefits for now we can return to this when we have more convincing reasons to upgrade than just "it's too old" --- .idea/libraries/Velocity.xml | 12 +- .idea/libraries/commons_lang3.xml | 12 - .idea/libraries/maven_model.xml | 8 +- ...intellij.java.aetherDependencyResolver.iml | 17 +- .../VelocityIncludesClassLoader.java | 6 +- .../bytecodeAnalysis/src/Example.java | 4 +- ...tecodeAnalysisResultsHighlightingTest.java | 2 +- .../build/CommunityLibraryLicenses.groovy | 7 +- .../intellij.platform.buildScripts.iml | 1 - .../lang-impl/intellij.platform.lang.impl.iml | 13 - .../ide/fileTemplates/FileTemplateUtil.java | 7 +- .../fileTemplates/Velocity17StringUtils.java | 652 ------------------ .../ide/fileTemplates/VelocityWrapper.java | 40 +- .../copyright/pattern/VelocityHelper.java | 20 +- .../generate/velocity/VelocityFactory.java | 19 +- .../plugins/ipnb/format/IpnbParser.java | 5 +- 16 files changed, 85 insertions(+), 740 deletions(-) delete mode 100644 .idea/libraries/commons_lang3.xml delete mode 100644 platform/lang-impl/src/com/intellij/ide/fileTemplates/Velocity17StringUtils.java diff --git a/.idea/libraries/Velocity.xml b/.idea/libraries/Velocity.xml index f543e3027744..8552bfe306b3 100644 --- a/.idea/libraries/Velocity.xml +++ b/.idea/libraries/Velocity.xml @@ -1,18 +1,18 @@ - + - + - - + + - - + + \ No newline at end of file diff --git a/.idea/libraries/commons_lang3.xml b/.idea/libraries/commons_lang3.xml deleted file mode 100644 index da610d526aad..000000000000 --- a/.idea/libraries/commons_lang3.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/maven_model.xml b/.idea/libraries/maven_model.xml index c35416c6688e..a0440149d5a9 100644 --- a/.idea/libraries/maven_model.xml +++ b/.idea/libraries/maven_model.xml @@ -1,18 +1,16 @@ - - - - - + + + \ No newline at end of file diff --git a/aether-dependency-resolver/intellij.java.aetherDependencyResolver.iml b/aether-dependency-resolver/intellij.java.aetherDependencyResolver.iml index 56b8be06b883..3647a288b4cc 100644 --- a/aether-dependency-resolver/intellij.java.aetherDependencyResolver.iml +++ b/aether-dependency-resolver/intellij.java.aetherDependencyResolver.iml @@ -119,19 +119,17 @@ - - - - - + + + @@ -151,19 +149,17 @@ - - - - - + + + @@ -191,6 +187,5 @@ - \ No newline at end of file diff --git a/java/java-impl/src/com/intellij/codeInsight/generation/VelocityIncludesClassLoader.java b/java/java-impl/src/com/intellij/codeInsight/generation/VelocityIncludesClassLoader.java index d396667b1e69..0266e86d3d36 100644 --- a/java/java-impl/src/com/intellij/codeInsight/generation/VelocityIncludesClassLoader.java +++ b/java/java-impl/src/com/intellij/codeInsight/generation/VelocityIncludesClassLoader.java @@ -18,11 +18,11 @@ package com.intellij.codeInsight.generation; import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; -import java.io.Reader; +import java.io.InputStream; public class VelocityIncludesClassLoader extends ClasspathResourceLoader { @Override - public Reader getResourceReader(String name, String encoding) throws ResourceNotFoundException { - return super.getResourceReader("com/intellij/codeInsight/generation/" + name, encoding); + public InputStream getResourceStream(String name) throws ResourceNotFoundException { + return super.getResourceStream("com/intellij/codeInsight/generation/" + name); } } diff --git a/java/java-tests/testData/codeInspection/bytecodeAnalysis/src/Example.java b/java/java-tests/testData/codeInspection/bytecodeAnalysis/src/Example.java index 529881c7a0b3..12e69260125f 100644 --- a/java/java-tests/testData/codeInspection/bytecodeAnalysis/src/Example.java +++ b/java/java-tests/testData/codeInspection/bytecodeAnalysis/src/Example.java @@ -14,8 +14,8 @@ * limitations under the License. */ -import org.apache.commons.lang3.ArrayUtils; -import org.apache.commons.lang3.ClassUtils; +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.ClassUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/java/java-tests/testSrc/com/intellij/java/codeInspection/bytecodeAnalysis/BytecodeAnalysisResultsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/java/codeInspection/bytecodeAnalysis/BytecodeAnalysisResultsHighlightingTest.java index 17b11fd3b559..143b81ab9749 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInspection/bytecodeAnalysis/BytecodeAnalysisResultsHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInspection/bytecodeAnalysis/BytecodeAnalysisResultsHighlightingTest.java @@ -23,7 +23,7 @@ public class BytecodeAnalysisResultsHighlightingTest extends DataFlowInspectionT @Override public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) { super.configureModule(module, model, contentEntry); - PsiTestUtil.addProjectLibrary(model, "lang", IntelliJProjectConfiguration.getProjectLibraryClassesRootPaths("commons-lang3")); + PsiTestUtil.addProjectLibrary(model, "velocity", IntelliJProjectConfiguration.getProjectLibraryClassesRootPaths("Velocity")); } }; } diff --git a/platform/build-scripts/groovy/org/jetbrains/intellij/build/CommunityLibraryLicenses.groovy b/platform/build-scripts/groovy/org/jetbrains/intellij/build/CommunityLibraryLicenses.groovy index 23cba77e0eed..566448951f91 100644 --- a/platform/build-scripts/groovy/org/jetbrains/intellij/build/CommunityLibraryLicenses.groovy +++ b/platform/build-scripts/groovy/org/jetbrains/intellij/build/CommunityLibraryLicenses.groovy @@ -96,13 +96,8 @@ class CommunityLibraryLicenses { license: "Apache 2.0", url: "https://github.com/JetBrains/intellij-deps-commons-imaging"), new LibraryLicense(name: "Apache Commons IO", libraryName: "commons-io", version: "2.6", license: "Apache 2.0", url: "http://commons.apache.org/io/"), - new LibraryLicense(name: "Apache Commons Lang", libraryName: "commons-lang2", version: "2.6", - attachedTo: "intellij.platform.lang.impl", url: "http://commons.apache.org/proper/commons-lang/", - license: "Apache 2.0", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0.txt"), new LibraryLicense(name: "Apache Commons Lang 3", libraryName: "commons-lang3-3.2.1.jar", version: "3.2.1", license: "Apache 2.0", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0.txt", url: "http://commons.apache.org/proper/commons-lang/"), - new LibraryLicense(name: "Apache Commons Lang 3", libraryName: "commons-lang3", version: "3.5", license: "Apache 2.0", - licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0.txt", url: "http://commons.apache.org/proper/commons-lang/"), new LibraryLicense(name: "Apache Commons Logging", libraryName: "commons-logging", version: "1.1.1", license: "Apache 2.0", url: "http://commons.apache.org/logging/"), new LibraryLicense(name: "Apache Commons Net", libraryName: "commons-net", version: "3.3", license: "Apache 2.0", @@ -454,7 +449,7 @@ class CommunityLibraryLicenses { license: "BSD style (see LICENSE.txt in trilead-ssh2-build213.jar)", url: "http://www.trilead.com/SSH_Library/"), new LibraryLicense(name: "Trove4j", version: "1.1 (with patches by JetBrains)", license: "LGPL", url: "http://trove4j.sourceforge.net/", licenseUrl: "http://trove4j.sourceforge.net/html/license.html"), - new LibraryLicense(name: "Velocity", version: "2.0", license: "Apache 2.0", url: "http://velocity.apache.org/", + new LibraryLicense(name: "Velocity", version: "1.7", license: "Apache 2.0", url: "http://velocity.apache.org/", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0.txt"), new LibraryLicense(name: "weberknecht", libraryName: "weberknecht-0.1.5.jar", version: "0.1.5", license: "Apache 2.0", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0", url: "https://github.com/pelotoncycle/weberknecht"), diff --git a/platform/build-scripts/intellij.platform.buildScripts.iml b/platform/build-scripts/intellij.platform.buildScripts.iml index c5f761c6d8cf..f65026912943 100644 --- a/platform/build-scripts/intellij.platform.buildScripts.iml +++ b/platform/build-scripts/intellij.platform.buildScripts.iml @@ -31,6 +31,5 @@ - \ No newline at end of file diff --git a/platform/lang-impl/intellij.platform.lang.impl.iml b/platform/lang-impl/intellij.platform.lang.impl.iml index d24b0d387774..f0ee6f873368 100644 --- a/platform/lang-impl/intellij.platform.lang.impl.iml +++ b/platform/lang-impl/intellij.platform.lang.impl.iml @@ -35,18 +35,5 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java index 214401e67b77..8812869f8e42 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/FileTemplateUtil.java @@ -30,6 +30,7 @@ import org.apache.velocity.exception.VelocityException; import org.apache.velocity.runtime.parser.ParseException; import org.apache.velocity.runtime.parser.Token; import org.apache.velocity.runtime.parser.node.*; +import org.apache.velocity.util.StringUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -64,7 +65,7 @@ public class FileTemplateUtil { private static String[] calculateAttributes(@NotNull String templateContent, @NotNull Set propertiesNames, boolean includeDummies, @NotNull Project project) throws ParseException { final Set unsetAttributes = new LinkedHashSet<>(); final Set definedAttributes = new HashSet<>(); - SimpleNode template = VelocityWrapper.parse(new StringReader(templateContent)); + SimpleNode template = VelocityWrapper.parse(new StringReader(templateContent), "MyTemplate"); collectAttributes(unsetAttributes, definedAttributes, template, propertiesNames, includeDummies, new HashSet<>(), project); for (String definedAttribute : definedAttributes) { unsetAttributes.remove(definedAttribute); @@ -110,7 +111,7 @@ public class FileTemplateUtil { includedTemplate = templateManager.getPattern(s); } if (includedTemplate != null && visitedIncludes.add(s)) { - SimpleNode template = VelocityWrapper.parse(new StringReader(includedTemplate.getText())); + SimpleNode template = VelocityWrapper.parse(new StringReader(includedTemplate.getText()), "MyTemplate"); collectAttributes(referenced, defined, template, propertiesNames, includeDummies, visitedIncludes, project); } } @@ -185,7 +186,7 @@ public class FileTemplateUtil { @NotNull private static VelocityContext createVelocityContext() { VelocityContext context = new VelocityContext(); - context.put("StringUtils", Velocity17StringUtils.class); + context.put("StringUtils", StringUtils.class); return context; } diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/Velocity17StringUtils.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/Velocity17StringUtils.java deleted file mode 100644 index 9c8fd4c9414c..000000000000 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/Velocity17StringUtils.java +++ /dev/null @@ -1,652 +0,0 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.ide.fileTemplates; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileReader; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; - -// JB: Copied from Velocity 1.7 for user template backward compatibility (https://youtrack.jetbrains.com/issue/IDEA-107709) - -/** - * This class provides some methods for dynamically - * invoking methods in objects, and some string - * manipulation methods used by torque. The string - * methods will soon be moved into the turbine - * string utilities class. - * - * @author Jason van Zyl - * @author Daniel Rall - * @version $Id: StringUtils.java 685685 2008-08-13 21:43:27Z nbubna $ - */ -@SuppressWarnings({"unused", "StringBufferMayBeStringBuilder", "ForLoopReplaceableByForEach", "MissingDeprecatedAnnotation", - "UnusedAssignment", "StringToUpperCaseOrToLowerCaseWithoutLocale", "unchecked", "SSBasedInspection", "UseOfObsoleteCollectionType", - "SwitchStatementWithTooFewBranches", "AssignmentToForLoopParameter", "IOResourceOpenedButNotSafelyClosed", "CallToPrintStackTrace", - "UnnecessaryFullyQualifiedName", "ToArrayCallWithZeroLengthArrayArgument", "FinalStaticMethod"}) -public class Velocity17StringUtils -{ - /** - * Line separator for the OS we are operating on. - */ - private static final String EOL = System.getProperty("line.separator"); - - /** - * Concatenates a list of objects as a String. - * - * @param list The list of objects to concatenate. - * @return A text representation of the concatenated objects. - */ - public String concat(List list) - { - StringBuffer sb = new StringBuffer(); - int size = list.size(); - - for (int i = 0; i < size; i++) - { - sb.append(list.get(i).toString()); - } - return sb.toString(); - } - - /** - * Return a package name as a relative path name - * - * @param pckge package name to convert to a directory. - * @return String directory path. - */ - static public String getPackageAsPath(String pckge) - { - return pckge.replace( '.', File.separator.charAt(0) ) + File.separator; - } - - /** - *

- * Remove underscores from a string and replaces first - * letters with capitals. Other letters are changed to lower case. - *

- * - *

- * For example foo_bar becomes FooBar - * but foo_barBar becomes FooBarbar. - *

- * - * @param data string to remove underscores from. - * @return String - * @deprecated Use the org.apache.commons.util.StringUtils class - * instead. Using its firstLetterCaps() method in conjunction - * with a StringTokenizer will achieve the same result. - */ - static public String removeUnderScores (String data) - { - String temp = null; - StringBuffer out = new StringBuffer(); - temp = data; - - StringTokenizer st = new StringTokenizer(temp, "_"); - - while (st.hasMoreTokens()) - { - String element = (String) st.nextElement(); - out.append ( firstLetterCaps(element)); - } - - return out.toString(); - } - - /** - *

- * 'Camels Hump' replacement of underscores. - *

- * - *

- * Remove underscores from a string but leave the capitalization of the - * other letters unchanged. - *

- * - *

- * For example foo_barBar becomes FooBarBar. - *

- * - * @param data string to hump - * @return String - */ - static public String removeAndHump (String data) - { - return removeAndHump(data,"_"); - } - - /** - *

- * 'Camels Hump' replacement. - *

- * - *

- * Remove one string from another string but leave the capitalization of the - * other letters unchanged. - *

- * - *

- * For example, removing "_" from foo_barBar becomes FooBarBar. - *

- * - * @param data string to hump - * @param replaceThis string to be replaced - * @return String - */ - static public String removeAndHump (String data,String replaceThis) - { - String temp = null; - StringBuffer out = new StringBuffer(); - temp = data; - - StringTokenizer st = new StringTokenizer(temp, replaceThis); - - while (st.hasMoreTokens()) - { - String element = (String) st.nextElement(); - out.append ( capitalizeFirstLetter(element)); - }//while - - return out.toString(); - } - - /** - *

- * Makes the first letter caps and the rest lowercase. - *

- * - *

- * For example fooBar becomes Foobar. - *

- * - * @param data capitalize this - * @return String - */ - static public String firstLetterCaps ( String data ) - { - String firstLetter = data.substring(0,1).toUpperCase(); - String restLetters = data.substring(1).toLowerCase(); - return firstLetter + restLetters; - } - - /** - *

- * Capitalize the first letter but leave the rest as they are. - *

- * - *

- * For example fooBar becomes FooBar. - *

- * - * @param data capitalize this - * @return String - */ - static public String capitalizeFirstLetter ( String data ) - { - String firstLetter = data.substring(0,1).toUpperCase(); - String restLetters = data.substring(1); - return firstLetter + restLetters; - } - - /** - * Create a string array from a string separated by delim - * - * @param line the line to split - * @param delim the delimter to split by - * @return a string array of the split fields - */ - public static String [] split(String line, String delim) - { - List list = new ArrayList(); - StringTokenizer t = new StringTokenizer(line, delim); - while (t.hasMoreTokens()) - { - list.add(t.nextToken()); - } - return (String []) list.toArray(new String[list.size()]); - } - - /** - * Chop i characters off the end of a string. - * This method assumes that any EOL characters in String s - * and the platform EOL will be the same. - * A 2 character EOL will count as 1 character. - * - * @param s String to chop. - * @param i Number of characters to chop. - * @return String with processed answer. - */ - public static String chop(String s, int i) - { - return chop(s, i, EOL); - } - - /** - * Chop i characters off the end of a string. - * A 2 character EOL will count as 1 character. - * - * @param s String to chop. - * @param i Number of characters to chop. - * @param eol A String representing the EOL (end of line). - * @return String with processed answer. - */ - public static String chop(String s, int i, String eol) - { - if ( i == 0 || s == null || eol == null ) - { - return s; - } - - int length = s.length(); - - /* - * if it is a 2 char EOL and the string ends with - * it, nip it off. The EOL in this case is treated like 1 character - */ - if ( eol.length() == 2 && s.endsWith(eol )) - { - length -= 2; - i -= 1; - } - - if ( i > 0) - { - length -= i; - } - - if ( length < 0) - { - length = 0; - } - - return s.substring( 0, length); - } - - /** - * @param argStr - * @param vars - * @return Substituted String. - */ - public static StringBuffer stringSubstitution( String argStr, - Hashtable vars ) - { - return stringSubstitution( argStr, (Map) vars ); - } - - /** - * Perform a series of substitutions. The substitions - * are performed by replacing $variable in the target - * string with the value of provided by the key "variable" - * in the provided hashtable. - * - * @param argStr target string - * @param vars name/value pairs used for substitution - * @return String target string with replacements. - */ - public static StringBuffer stringSubstitution(String argStr, - Map vars) - { - StringBuffer argBuf = new StringBuffer(); - - for (int cIdx = 0 ; cIdx < argStr.length();) - { - char ch = argStr.charAt(cIdx); - - switch (ch) - { - case '$': - StringBuffer nameBuf = new StringBuffer(); - for (++cIdx ; cIdx < argStr.length(); ++cIdx) - { - ch = argStr.charAt(cIdx); - if (ch == '_' || Character.isLetterOrDigit(ch)) - nameBuf.append(ch); - else - break; - } - - if (nameBuf.length() > 0) - { - String value = - (String) vars.get(nameBuf.toString()); - - if (value != null) - { - argBuf.append(value); - } - } - break; - - default: - argBuf.append(ch); - ++cIdx; - break; - } - } - - return argBuf; - } - - /** - * Read the contents of a file and place them in - * a string object. - * - * @param file path to file. - * @return String contents of the file. - */ - public static String fileContentsToString(String file) - { - String contents = ""; - - File f = null; - try - { - f = new File(file); - - if (f.exists()) - { - FileReader fr = null; - try - { - fr = new FileReader(f); - char[] template = new char[(int) f.length()]; - fr.read(template); - contents = new String(template); - } - catch (Exception e) - { - e.printStackTrace(); - } - finally - { - if (fr != null) - { - fr.close(); - } - } - } - } - catch (Exception e) - { - e.printStackTrace(); - } - return contents; - } - - /** - * Remove/collapse multiple newline characters. - * - * @param argStr string to collapse newlines in. - * @return String - */ - public static String collapseNewlines(String argStr) - { - char last = argStr.charAt(0); - StringBuffer argBuf = new StringBuffer(); - - for (int cIdx = 0 ; cIdx < argStr.length(); cIdx++) - { - char ch = argStr.charAt(cIdx); - if (ch != '\n' || last != '\n') - { - argBuf.append(ch); - last = ch; - } - } - - return argBuf.toString(); - } - - /** - * Remove/collapse multiple spaces. - * - * @param argStr string to remove multiple spaces from. - * @return String - */ - public static String collapseSpaces(String argStr) - { - char last = argStr.charAt(0); - StringBuffer argBuf = new StringBuffer(); - - for (int cIdx = 0 ; cIdx < argStr.length(); cIdx++) - { - char ch = argStr.charAt(cIdx); - if (ch != ' ' || last != ' ') - { - argBuf.append(ch); - last = ch; - } - } - - return argBuf.toString(); - } - - /** - * Replaces all instances of oldString with newString in line. - * Taken from the Jive forum package. - * - * @param line original string. - * @param oldString string in line to replace. - * @param newString replace oldString with this. - * @return String string with replacements. - */ - public static final String sub(String line, String oldString, - String newString) - { - int i = 0; - if ((i = line.indexOf(oldString, i)) >= 0) - { - char [] line2 = line.toCharArray(); - char [] newString2 = newString.toCharArray(); - int oLength = oldString.length(); - StringBuffer buf = new StringBuffer(line2.length); - buf.append(line2, 0, i).append(newString2); - i += oLength; - int j = i; - while ((i = line.indexOf(oldString, i)) > 0) - { - buf.append(line2, j, i - j).append(newString2); - i += oLength; - j = i; - } - buf.append(line2, j, line2.length - j); - return buf.toString(); - } - return line; - } - - /** - * Returns the output of printStackTrace as a String. - * - * @param e A Throwable. - * @return A String. - */ - public static final String stackTrace(Throwable e) - { - String foo = null; - try - { - // And show the Error Screen. - ByteArrayOutputStream ostr = new ByteArrayOutputStream(); - e.printStackTrace( new PrintWriter(ostr,true) ); - foo = ostr.toString(); - } - catch (Exception f) - { - // Do nothing. - } - return foo; - } - - /** - * Return a context-relative path, beginning with a "/", that represents - * the canonical version of the specified path after ".." and "." elements - * are resolved out. If the specified path attempts to go outside the - * boundaries of the current context (i.e. too many ".." path elements - * are present), return null instead. - * - * @param path Path to be normalized - * @return String normalized path - */ - public static final String normalizePath(String path) - { - // Normalize the slashes and add leading slash if necessary - String normalized = path; - if (normalized.indexOf('\\') >= 0) - { - normalized = normalized.replace('\\', '/'); - } - - if (!normalized.startsWith("/")) - { - normalized = "/" + normalized; - } - - // Resolve occurrences of "//" in the normalized path - while (true) - { - int index = normalized.indexOf("//"); - if (index < 0) - break; - normalized = normalized.substring(0, index) + - normalized.substring(index + 1); - } - - // Resolve occurrences of "%20" in the normalized path - while (true) - { - int index = normalized.indexOf("%20"); - if (index < 0) - break; - normalized = normalized.substring(0, index) + " " + - normalized.substring(index + 3); - } - - // Resolve occurrences of "/./" in the normalized path - while (true) - { - int index = normalized.indexOf("/./"); - if (index < 0) - break; - normalized = normalized.substring(0, index) + - normalized.substring(index + 2); - } - - // Resolve occurrences of "/../" in the normalized path - while (true) - { - int index = normalized.indexOf("/../"); - if (index < 0) - break; - if (index == 0) - return (null); // Trying to go outside our context - int index2 = normalized.lastIndexOf('/', index - 1); - normalized = normalized.substring(0, index2) + - normalized.substring(index + 3); - } - - // Return the normalized path that we have completed - return (normalized); - } - - /** - * If state is true then return the trueString, else - * return the falseString. - * - * @param state - * @param trueString - * @param falseString - * @return Selected result. - */ - public String select(boolean state, String trueString, String falseString) - { - if (state) - { - return trueString; - } - else - { - return falseString; - } - } - - /** - * Check to see if all the string objects passed - * in are empty. - * - * @param list A list of {@link java.lang.String} objects. - * @return Whether all strings are empty. - */ - public boolean allEmpty(List list) - { - int size = list.size(); - - for (int i = 0; i < size; i++) - { - if (list.get(i) != null && list.get(i).toString().length() > 0) - { - return false; - } - } - return true; - } - - /** - * Trim all strings in a List. Changes the strings in the existing list. - * @param list - * @return List of trimmed strings. - * @since 1.5 - */ - public static List trimStrings(List list) - { - if (list == null) - return null; - - int sz = list.size(); - for (int i = 0; i < sz; i++) - list.set(i,nullTrim((String) list.get(i))); - return list; - } - - /** - * Trim the string, but pass a null through. - * @param s - * @return List of trimmed Strings. - * @since 1.5 - */ - public static String nullTrim(String s) - { - if (s == null) - { - return null; - } - else - { - return s.trim(); - } - } -} diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/VelocityWrapper.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/VelocityWrapper.java index 85f4b1b6f682..6bf26eefb427 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/VelocityWrapper.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/VelocityWrapper.java @@ -4,27 +4,26 @@ package com.intellij.ide.fileTemplates; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; -import org.apache.velocity.Template; +import org.apache.commons.collections.ExtendedProperties; import org.apache.velocity.app.Velocity; import org.apache.velocity.context.Context; import org.apache.velocity.exception.MethodInvocationException; import org.apache.velocity.exception.ParseErrorException; import org.apache.velocity.exception.ResourceNotFoundException; import org.apache.velocity.runtime.RuntimeConstants; +import org.apache.velocity.runtime.RuntimeServices; import org.apache.velocity.runtime.RuntimeSingleton; +import org.apache.velocity.runtime.log.LogSystem; import org.apache.velocity.runtime.parser.ParseException; import org.apache.velocity.runtime.parser.node.SimpleNode; import org.apache.velocity.runtime.resource.Resource; import org.apache.velocity.runtime.resource.ResourceManager; import org.apache.velocity.runtime.resource.ResourceManagerImpl; import org.apache.velocity.runtime.resource.loader.ResourceLoader; -import org.apache.velocity.util.ExtProperties; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.Reader; -import java.io.StringReader; -import java.io.Writer; +import java.io.*; /** * Initializes Velocity when it's actually needed. All interaction with Velocity should go through this class. @@ -44,23 +43,40 @@ class VelocityWrapper { ", ResourceManagerImpl in " + PathManager.getJarPathForClass(ResourceManagerImpl.class)); } + LogSystem emptyLogSystem = new LogSystem() { + @Override + public void init(RuntimeServices runtimeServices) throws Exception { + } + + @Override + public void logVelocityMessage(int i, String s) { + //todo[myakovlev] log somethere? + } + }; + Velocity.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, emptyLogSystem); Velocity.setProperty(RuntimeConstants.INPUT_ENCODING, FileTemplate.ourEncoding); Velocity.setProperty(RuntimeConstants.PARSER_POOL_SIZE, 3); Velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "includes"); Velocity.setProperty("includes.resource.loader.instance", new ResourceLoader() { @Override - public void init(ExtProperties configuration) { + public void init(ExtendedProperties configuration) { } @Override - public Reader getResourceReader(String resourceName, String encoding) throws ResourceNotFoundException { + public InputStream getResourceStream(String resourceName) throws ResourceNotFoundException { FileTemplateManager templateManager = ourTemplateManager.get(); if (templateManager == null) templateManager = FileTemplateManager.getDefaultInstance(); final FileTemplate include = templateManager.getPattern(resourceName); if (include == null) { throw new ResourceNotFoundException("Template not found: " + resourceName); } - return new StringReader(include.getText()); + final String text = include.getText(); + try { + return new ByteArrayInputStream(text.getBytes(FileTemplate.ourEncoding)); + } + catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } } @Override @@ -82,15 +98,15 @@ class VelocityWrapper { } @NotNull - static SimpleNode parse(@NotNull Reader reader) throws ParseException { - return RuntimeSingleton.parse(reader, new Template()); + static SimpleNode parse(@NotNull Reader reader, @NotNull String templateName) throws ParseException { + return RuntimeSingleton.parse(reader, templateName); } - static void evaluate(@Nullable Project project, Context context, @NotNull Writer writer, String templateContent) + static boolean evaluate(@Nullable Project project, Context context, @NotNull Writer writer, String templateContent) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException { try { ourTemplateManager.set(project == null ? FileTemplateManager.getDefaultInstance() : FileTemplateManager.getInstance(project)); - Velocity.evaluate(context, writer, "", templateContent); + return Velocity.evaluate(context, writer, "", templateContent); } finally { ourTemplateManager.set(null); diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java index 586b9539689c..94fe8871cfd9 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java @@ -24,9 +24,11 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiUtilCore; +import org.apache.commons.collections.ExtendedProperties; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.runtime.RuntimeConstants; +import org.apache.velocity.runtime.log.SimpleLog4JLogSystem; import java.io.StringWriter; import java.util.HashMap; @@ -82,7 +84,8 @@ public class VelocityHelper return "\n"; } - public static void verify(String text) { + public static void verify(String text) throws Exception + { VelocityEngine engine = getEngine(); VelocityContext vc = new VelocityContext(); @@ -101,15 +104,20 @@ public class VelocityHelper try { VelocityEngine engine = new VelocityEngine(); + ExtendedProperties extendedProperties = new ExtendedProperties(); - engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file"); - engine.setProperty(RuntimeConstants.PARSER_POOL_SIZE, "1"); + extendedProperties.addProperty(RuntimeConstants.RESOURCE_LOADER, "file"); + extendedProperties.addProperty(RuntimeConstants.PARSER_POOL_SIZE, "1"); - engine.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); - engine.setProperty("file.resource.loader.path", PathManager.getPluginsPath() + "/Copyright/resources"); + extendedProperties.addProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader"); + extendedProperties.addProperty("file.resource.loader.path", PathManager.getPluginsPath() + "/Copyright/resources"); - engine.setProperty(RuntimeConstants.RUNTIME_LOG_NAME, CopyrightManager.class.getName()); + extendedProperties.addProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, + SimpleLog4JLogSystem.class.getName()); + extendedProperties + .addProperty("runtime.log.logsystem.log4j.category", CopyrightManager.class.getName()); + engine.setExtendedProperties(extendedProperties); engine.init(); instance = engine; diff --git a/plugins/generate-tostring/src/org/jetbrains/java/generate/velocity/VelocityFactory.java b/plugins/generate-tostring/src/org/jetbrains/java/generate/velocity/VelocityFactory.java index bc12a6694cbe..7c163af065c1 100644 --- a/plugins/generate-tostring/src/org/jetbrains/java/generate/velocity/VelocityFactory.java +++ b/plugins/generate-tostring/src/org/jetbrains/java/generate/velocity/VelocityFactory.java @@ -16,8 +16,10 @@ package org.jetbrains.java.generate.velocity; import com.intellij.codeInsight.generation.VelocityIncludesClassLoader; +import org.apache.commons.collections.ExtendedProperties; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.runtime.RuntimeConstants; +import org.apache.velocity.runtime.log.SimpleLog4JLogSystem; /** * Velocity factory. @@ -29,6 +31,12 @@ public class VelocityFactory { private static final VelocityEngine engine = newVelocityEngine(); } + /** + * Privte constructor. + */ + private VelocityFactory() { + } + /** * Returns a new instance of the VelocityEngine. *

@@ -37,11 +45,14 @@ public class VelocityFactory { * @return a new velocity engine that is initialized. */ private static VelocityEngine newVelocityEngine() { + ExtendedProperties prop = new ExtendedProperties(); + prop.addProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, SimpleLog4JLogSystem.class.getName()); + prop.addProperty("runtime.log.logsystem.log4j.category", "GenerateToString"); + prop.addProperty(RuntimeConstants.RESOURCE_LOADER, "includes"); + prop.addProperty("includes.resource.loader.class", VelocityIncludesClassLoader.class.getName()); + prop.addProperty(RuntimeConstants.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, "true"); VelocityEngine velocity = new VelocityEngine(); - velocity.setProperty(RuntimeConstants.RUNTIME_LOG_NAME, "GenerateToString"); - velocity.setProperty(RuntimeConstants.RESOURCE_LOADER, "includes"); - velocity.setProperty("includes.resource.loader.class", VelocityIncludesClassLoader.class.getName()); - velocity.setProperty(RuntimeConstants.VM_PERM_ALLOW_INLINE_REPLACE_GLOBAL, "true"); + velocity.setExtendedProperties(prop); velocity.init(); return velocity; } diff --git a/python/ipnb/src/org/jetbrains/plugins/ipnb/format/IpnbParser.java b/python/ipnb/src/org/jetbrains/plugins/ipnb/format/IpnbParser.java index 068051bded15..efaa2b49a075 100644 --- a/python/ipnb/src/org/jetbrains/plugins/ipnb/format/IpnbParser.java +++ b/python/ipnb/src/org/jetbrains/plugins/ipnb/format/IpnbParser.java @@ -1,4 +1,3 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.ipnb.format; import com.google.common.collect.Lists; @@ -21,7 +20,7 @@ import com.intellij.util.text.VersionComparatorUtil; import com.jetbrains.python.packaging.PyPackage; import com.jetbrains.python.packaging.PyPackageUtil; import com.jetbrains.python.sdk.PythonSdkType; -import org.apache.commons.lang3.math.NumberUtils; +import org.apache.commons.lang.math.NumberUtils; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel; @@ -575,7 +574,7 @@ public class IpnbParser { if (codemirrorModeMap.containsKey("version")) { String version = (String)codemirrorModeMap.get("version"); - if (NumberUtils.isCreatable(version)) { + if (NumberUtils.isNumber(version)) { try { codemirrorModeMap.put("version", Integer.parseInt(version)); }