From 16bb9a99810270c94ccc11178c40b0ac9a69c4f3 Mon Sep 17 00:00:00 2001 From: xristosoik Date: Sat, 30 May 2015 16:16:56 +0300 Subject: [PATCH 01/10] Addition of package DisplayDocs --- .../groovy/DisplayDocs/DocStructure.java | 130 ++++++++++++++++++ .../groovy/DisplayDocs/ImportJavadocs.java | 100 ++++++++++++++ .../groovy/DisplayDocs/MethodStructure.java | 54 ++++++++ 3 files changed, 284 insertions(+) create mode 100644 gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java create mode 100644 gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java create mode 100644 gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java new file mode 100644 index 00000000000..5e79b9b3a4a --- /dev/null +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java @@ -0,0 +1,130 @@ +/* + * 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. + */ + +package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; + +/** + * + * @author xristosoik (https://github.com/xristosoik) + */ +import java.util.TreeMap; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +public class DocStructure { + + private String className; + private String classPath; + private TreeMap methodList; + private final String methodSeparator = ""; + + public DocStructure (String path, String name) throws Exception { + className = name; + classPath = path; + loadMethodsInfo(path); + } + + protected void loadMethodsInfo (String path) { + methodList = new TreeMap(); + boolean find, finishReading = false; + String temp = "", name; + MethodStructure temporary; + int position = 0, counter = 0; + try { + BufferedReader in = new BufferedReader(new FileReader("target/apache-gremlin-console-3.0.0-SNAPSHOT-standalone/javadocs/" + path)); + String str; + while ((str = in.readLine()) != null) { + if (finishReading) + break; + find = str.contains(methodSeparator); + if (find) { + while ((str = in.readLine()) != null) { + if (position == 0 && str.contains("")) { + position++; + continue; + } + if (position == 1) { + if (str.contains("")) { + position++; + continue; + } else { + position = 0; + } + } + if (position == 2) { + if (str.contains("
    ")) { + position++; + continue; + } else if (str.contains("
      ")) { + position++; + finishReading = true; + continue; + } else { + position = 0; + } + } + if (position == 3) { + if (str.contains("
    • ")) { + position++; + continue; + } else { + position = 0; + } + } + if (position == 4 && str.contains("

      ")) { + name = str; + while ((str = in.readLine()) != null) { + if (str.contains("

    ")) { + position = 0; + break; + } + temp += str; + } + name = MethodStructure.cleanName(name); + if (methodList.containsKey(name)) { + name += counter; + counter++; + } else + counter = 0; + temporary = new MethodStructure(name, temp); + methodList.put(temporary.getMethodName(), temporary); + } else { + position =0; + } + } + } + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + } + + public String getClassName() { + return(className); + } + + public String getClassPath() { + return(classPath); + } + + public TreeMap getMethodList() { + return(methodList); + } +} diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java new file mode 100644 index 00000000000..18d30141ff6 --- /dev/null +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java @@ -0,0 +1,100 @@ +/* + * 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. + */ + +package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; + +//import java.util.*; +import java.io.*; + +/** + * + * @author xristosoik (https://github.com/xristosoik) + */ +public class ImportJavadocs { + + static protected DocStructure currentDoc; + + /*public static void main(String[] args) { + System.out.println(findClass(">" + "Client" + "<")); + System.out.println(currentDoc.getMethodList().size()); + }*/ + + /* + * This function findes the target fill to the javadocs of the Class that is specifies + * by the className. + */ + + public static boolean findClass (String className) { + try { + currentDoc = new DocStructure(findPath2TheJavadoc(className), className); + } catch (Exception e) { + System.out.println("sgbddbb"); + return(false); + } + return(true); + } + + /* + * Clean up the line keeping only the path. + */ + + protected static String findPath2TheJavadoc (String className) { + String path[] = findPath2CorrectLine(className); + path[1] = path[1].split("href=\"")[1]; + path[1] = path[1].split("\" title")[0]; + return(path[0] + "/" + path[1]); + } + + /* + * Τhis method search all directories for the correct line of html. + */ + + protected static String[] findPath2CorrectLine (String className) { + boolean find = false; + String line = ""; + String path[] = new String[2]; + try { + File javadocDirectory = new File ("target/apache-gremlin-console-3.0.0-SNAPSHOT-standalone/javadocs"); + String[] folders = javadocDirectory.list(); + for (String dir : folders) { + BufferedReader in = new BufferedReader( + new FileReader("target/apache-gremlin-console-3.0.0-SNAPSHOT-standalone/javadocs/" + dir + + "/allclasses-noframe.html")); + String str; + while ((str = in.readLine()) != null) { + find = str.contains(className); + if (find) { + line = str; + break; + } + } + path[0] = dir; + in.close(); + if (find) { + break; + } + } + } catch (Exception e) { + System.out.println("xhbdxzfhn"); + } + path[1] = line; + return(path); + } + +} \ No newline at end of file diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java new file mode 100644 index 00000000000..3fd2209d605 --- /dev/null +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java @@ -0,0 +1,54 @@ +/* + * 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. + */ + +package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; + +/** + * + * @author xristosoik (https://github.com/xristosoik) + */ +public class MethodStructure { + + private String methodName; + private String documentation; + private static int counter = 0; + + public MethodStructure (String name, String Block) { + String temp; + methodName = name; + documentation = Block; + } + + + public static String cleanName(String name){ + name = name.split("

    ")[1]; + name = name.split("

    ")[0]; + return(name); + } + + + private static String cleanBlock(String block){ + return(block); + } + + + public String getMethodName() { + return(methodName); + } +} \ No newline at end of file From 00a06367bf25eb95cea36a2103278392529a69a7 Mon Sep 17 00:00:00 2001 From: xristosoik Date: Sun, 31 May 2015 10:36:43 +0300 Subject: [PATCH 02/10] Addition of Javadocs --- .../groovy/DisplayDocs/DocStructure.java | 21 ++++++++++---- .../groovy/DisplayDocs/ImportJavadocs.java | 29 ++++++++++--------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java index 5e79b9b3a4a..fff923701e8 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java @@ -26,7 +26,6 @@ import java.util.TreeMap; import java.io.BufferedReader; import java.io.FileReader; -import java.io.IOException; public class DocStructure { private String className; @@ -39,7 +38,10 @@ public DocStructure (String path, String name) throws Exception { classPath = path; loadMethodsInfo(path); } - + /** + * This method loads the documentation of class's all methods. + * @param path + */ protected void loadMethodsInfo (String path) { methodList = new TreeMap(); boolean find, finishReading = false; @@ -115,15 +117,24 @@ protected void loadMethodsInfo (String path) { } } - + /** + * + * @return the name of the class + */ public String getClassName() { return(className); } - + /** + * + * @return the path to the class + */ public String getClassPath() { return(classPath); } - + /** + * + * @return the Map of the class methods + */ public TreeMap getMethodList() { return(methodList); } diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java index 18d30141ff6..126a5c647e7 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java @@ -19,7 +19,6 @@ package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; -//import java.util.*; import java.io.*; /** @@ -35,11 +34,11 @@ public class ImportJavadocs { System.out.println(currentDoc.getMethodList().size()); }*/ - /* - * This function findes the target fill to the javadocs of the Class that is specifies - * by the className. - */ - + /** + * This method find the target fill to the javadocs of the Class that is specifies by the className. + * @param className The name of a class whom javadocs we want to import. + * @return true if this class exists and false if not. + */ public static boolean findClass (String className) { try { currentDoc = new DocStructure(findPath2TheJavadoc(className), className); @@ -50,10 +49,11 @@ public static boolean findClass (String className) { return(true); } - /* - * Clean up the line keeping only the path. - */ - + /** + * Clean up the line keeping only the path. + * @param className + * @return + */ protected static String findPath2TheJavadoc (String className) { String path[] = findPath2CorrectLine(className); path[1] = path[1].split("href=\"")[1]; @@ -61,10 +61,11 @@ protected static String findPath2TheJavadoc (String className) { return(path[0] + "/" + path[1]); } - /* - * Τhis method search all directories for the correct line of html. - */ - + /** + * Τhis method search all directories for the correct line of html. + * @param className + * @return correct line html free. + */ protected static String[] findPath2CorrectLine (String className) { boolean find = false; String line = ""; From def7dfd428f01314645bf0e3c79fe42e209b5629 Mon Sep 17 00:00:00 2001 From: xristosoik Date: Thu, 4 Jun 2015 05:14:31 +0300 Subject: [PATCH 03/10] Correct parsing of documentation --- .../console/commands/ImportDocsCommand.groovy | 41 +++++++++++++++++++ .../groovy/DisplayDocs/DocStructure.java | 25 ++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/ImportDocsCommand.groovy diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/ImportDocsCommand.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/ImportDocsCommand.groovy new file mode 100644 index 00000000000..7fd750d54d8 --- /dev/null +++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/ImportDocsCommand.groovy @@ -0,0 +1,41 @@ +/* + * 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. + */ + +package org.apache.tinkerpop.gremlin.console.commands + +import org.apache.tinkerpop.gremlin.console.Mediator +import org.codehaus.groovy.tools.shell.Groovysh +import org.codehaus.groovy.tools.shell.CommandSupport + +//import org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs.* + +class ImportDocsCommand extends CommandSupport { + + public ImportDocsCommand(final Groovysh shell, final Mediator mediator) { + super(shell, ":importdocs", ":idcs") + this.mediator = mediator + } + + @Override + def Object execute(final List arguments) { + io.println argument.get(0); + } +} + + diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java index fff923701e8..bb249c8bd18 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java @@ -96,7 +96,12 @@ protected void loadMethodsInfo (String path) { position = 0; break; } - temp += str; + if (str.contains("")) { + str += "\n"; + } + str = str.replaceAll("
    ", "\n"); + temp += cleanHtmlEntities( + str.replaceAll("\\<.*?>","")); } name = MethodStructure.cleanName(name); if (methodList.containsKey(name)) { @@ -138,4 +143,22 @@ public String getClassPath() { public TreeMap getMethodList() { return(methodList); } + /** + * + * @param str + * @return returns the line of html with the correct characters + */ + public String cleanHtmlEntities (String str) { + str = str.replaceAll(" ", " "); + str = str.replaceAll("<", "<"); + str = str.replaceAll(">", ">"); + str = str.replaceAll("&", "&"); + str = str.replaceAll("¢", "¢"); + str = str.replaceAll("£", "£"); + str = str.replaceAll("¥", "¥"); + str = str.replaceAll("€", "€"); + str = str.replaceAll("©", "©"); + str = str.replaceAll("®", "®"); + return(str); + } } From 140b8466115ad0b6e09903df1c51b9d05732d665 Mon Sep 17 00:00:00 2001 From: xristosoik Date: Sun, 7 Jun 2015 00:06:55 +0300 Subject: [PATCH 04/10] Addition of commands for the main functionality --- .../tinkerpop/gremlin/console/Console.groovy | 15 +++++- .../console/commands/DocsCommand.groovy | 46 ++++++++++++++++ .../console/commands/ImportDocsCommand.groovy | 8 ++- .../groovy/DisplayDocs/DocStructure.java | 24 +++++++-- .../groovy/DisplayDocs/ImportJavadocs.java | 31 ++++++----- .../groovy/DisplayDocs/MethodStructure.java | 52 +++++++++---------- 6 files changed, 130 insertions(+), 46 deletions(-) create mode 100644 gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/DocsCommand.groovy diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy index b101a9a948f..6943e896808 100644 --- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy +++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy @@ -35,6 +35,7 @@ import java.nio.charset.Charset import java.util.concurrent.TimeUnit import java.util.prefs.PreferenceChangeEvent import java.util.prefs.PreferenceChangeListener +import org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs.* /** * @author Stephen Mallette (http://stephen.genoprime.com) @@ -56,6 +57,7 @@ class Console { private static final String IMPORT_STATIC_SPACE = "import static " private static final String NULL = "null" private static final String ELLIPSIS = "..." + protected static DocStructure currdocs = ImportJavadocs.findClass("AbstractChannelizer") private Iterator tempIterator = Collections.emptyIterator() @@ -67,7 +69,6 @@ class Console { io.out.println(" \\,,,/") io.out.println(" (o o)") io.out.println("-----oOOo-(3)-oOOo-----") - maxIteration = Integer.parseInt(Preferences.get(PREFERENCE_ITERATION_MAX, Integer.toString(DEFAULT_ITERATION_MAX))) Preferences.addChangeListener(new PreferenceChangeListener() { @Override @@ -76,7 +77,7 @@ class Console { maxIteration = Integer.parseInt(evt.newValue) } }) - + //static PreferenceChangeListener doc = new PreferenceChangeListener(); final Mediator mediator = new Mediator(this) def commandsToRemove = groovy.getRegistry().commands().findAll{it instanceof SetCommand} commandsToRemove.each {groovy.getRegistry().remove(it)} @@ -86,6 +87,8 @@ class Console { groovy.register(new PluginCommand(groovy, mediator)) groovy.register(new RemoteCommand(groovy, mediator)) groovy.register(new SubmitCommand(groovy, mediator)) + groovy.register(new ImportDocsCommand(groovy, mediator)) + groovy.register(new DocsCommand(groovy, mediator)) // hide output temporarily while imports execute showShellEvaluationOutput(false) @@ -287,6 +290,14 @@ class Console { System.exit(1) } } + + public static void updateCurrdocs(final DocStructure importedDocs) { + currdocs = importedDocs + } + + public static DocStructure getCurrdocs() { + return(currdocs) + } public static void main(final String[] args) { new Console(args.length == 1 ? args[0] : null) diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/DocsCommand.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/DocsCommand.groovy new file mode 100644 index 00000000000..db313969222 --- /dev/null +++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/DocsCommand.groovy @@ -0,0 +1,46 @@ +/* + * 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. + */ + +package org.apache.tinkerpop.gremlin.console.commands + +import org.apache.tinkerpop.gremlin.console.Mediator +import org.apache.tinkerpop.gremlin.console.Console +import org.codehaus.groovy.tools.shell.Groovysh +import org.codehaus.groovy.tools.shell.CommandSupport + +import org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs.* + +class DocsCommand extends CommandSupport { + + private final Mediator mediator + + public DocsCommand(final Groovysh shell, final Mediator mediator) { + super(shell, ":docs", ":dc") + this.mediator = mediator + } + + @Override + def Object execute(final List arguments) { + def method = arguments as String[] + def doc = Console.getCurrdocs() + io.out.println(doc.getAllDocumentation(method[0])) + } +} + + diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/ImportDocsCommand.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/ImportDocsCommand.groovy index 7fd750d54d8..caca2582e09 100644 --- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/ImportDocsCommand.groovy +++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/ImportDocsCommand.groovy @@ -20,13 +20,16 @@ package org.apache.tinkerpop.gremlin.console.commands import org.apache.tinkerpop.gremlin.console.Mediator +import org.apache.tinkerpop.gremlin.console.Console import org.codehaus.groovy.tools.shell.Groovysh import org.codehaus.groovy.tools.shell.CommandSupport -//import org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs.* +import org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs.* class ImportDocsCommand extends CommandSupport { + private final Mediator mediator + public ImportDocsCommand(final Groovysh shell, final Mediator mediator) { super(shell, ":importdocs", ":idcs") this.mediator = mediator @@ -34,7 +37,8 @@ class ImportDocsCommand extends CommandSupport { @Override def Object execute(final List arguments) { - io.println argument.get(0); + def classes = arguments as String[] + Console.updateCurrdocs(ImportJavadocs.findClass(classes[0])) } } diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java index bb249c8bd18..1708040013f 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java @@ -28,7 +28,7 @@ import java.io.FileReader; public class DocStructure { - private String className; + private String className = "Not initalized"; private String classPath; private TreeMap methodList; private final String methodSeparator = ""; @@ -49,7 +49,7 @@ protected void loadMethodsInfo (String path) { MethodStructure temporary; int position = 0, counter = 0; try { - BufferedReader in = new BufferedReader(new FileReader("target/apache-gremlin-console-3.0.0-SNAPSHOT-standalone/javadocs/" + path)); + BufferedReader in = new BufferedReader(new FileReader(path)); String str; while ((str = in.readLine()) != null) { if (finishReading) @@ -99,6 +99,11 @@ protected void loadMethodsInfo (String path) { if (str.contains("")) { str += "\n"; } + if (str.contains("") || + str.contains("
    ") || + str.contains("")) { + str = "\n" + str + "\n"; + } str = str.replaceAll("
    ", "\n"); temp += cleanHtmlEntities( str.replaceAll("\\<.*?>","")); @@ -111,13 +116,14 @@ protected void loadMethodsInfo (String path) { counter = 0; temporary = new MethodStructure(name, temp); methodList.put(temporary.getMethodName(), temporary); + temp = ""; } else { position =0; } } } } - } catch (Exception e) { + } catch (Exception e) { System.out.println(e.getMessage()); } @@ -161,4 +167,16 @@ public String cleanHtmlEntities (String str) { str = str.replaceAll("®", "®"); return(str); } + + public String getAllDocumentation(String name) { + name = name.replaceAll("\"", ""); + MethodStructure temp = methodList.get(name); + String displayedDoc; + if (temp != null) + displayedDoc = temp.getMethodName() + "\n" + temp.getMethodDoc(); + else + displayedDoc = "There is not method with that name in" + + className + "plase use \":importdocs\" to import the correct Class"; + return(displayedDoc); + } } diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java index 126a5c647e7..f984f236e48 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java @@ -39,14 +39,16 @@ public class ImportJavadocs { * @param className The name of a class whom javadocs we want to import. * @return true if this class exists and false if not. */ - public static boolean findClass (String className) { + public static DocStructure findClass (String className) { try { - currentDoc = new DocStructure(findPath2TheJavadoc(className), className); + className = className.replaceAll("\"", ""); + String path = findPath2TheJavadoc(">" + className + "<"); + DocStructure tempDoc = new DocStructure(path, className); + currentDoc = tempDoc; } catch (Exception e) { - System.out.println("sgbddbb"); - return(false); + System.out.println("Unsuccesful import!"); } - return(true); + return(currentDoc); } /** @@ -70,14 +72,18 @@ protected static String[] findPath2CorrectLine (String className) { boolean find = false; String line = ""; String path[] = new String[2]; + path[0] = "."; + int i = 0; try { - File javadocDirectory = new File ("target/apache-gremlin-console-3.0.0-SNAPSHOT-standalone/javadocs"); - String[] folders = javadocDirectory.list(); + File pathDefinition = new File("."); + path[0] = pathDefinition.getCanonicalPath().replace("bin", "target/site/apidocs"); + File javadocDirectory = new File (path[0]); + String[] folders = {"/core", "/full"}; for (String dir : folders) { BufferedReader in = new BufferedReader( - new FileReader("target/apache-gremlin-console-3.0.0-SNAPSHOT-standalone/javadocs/" + dir + + new FileReader(path[0] + dir + "/allclasses-noframe.html")); - String str; + String str; while ((str = in.readLine()) != null) { find = str.contains(className); if (find) { @@ -85,17 +91,16 @@ protected static String[] findPath2CorrectLine (String className) { break; } } - path[0] = dir; in.close(); if (find) { - break; + path[0] += dir; + break; } } } catch (Exception e) { - System.out.println("xhbdxzfhn"); + System.out.println(e.getMessage()); } path[1] = line; return(path); } - } \ No newline at end of file diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java index 3fd2209d605..75970d9f84c 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java @@ -25,30 +25,30 @@ */ public class MethodStructure { - private String methodName; - private String documentation; - private static int counter = 0; - - public MethodStructure (String name, String Block) { - String temp; - methodName = name; - documentation = Block; - } - - - public static String cleanName(String name){ - name = name.split("

    ")[1]; - name = name.split("

    ")[0]; - return(name); - } - - - private static String cleanBlock(String block){ - return(block); - } - - - public String getMethodName() { - return(methodName); - } + private String methodName; + private String documentation; + private static int counter = 0; + + public MethodStructure (String name, String Block) { + methodName = name; + documentation = Block; + } + + public static String cleanName(String name){ + name = name.split("

    ")[1]; + name = name.split("

    ")[0]; + return(name); + } + + public String getMethodName() { + return(methodName); + } + + /** + * + * @return + */ + public String getMethodDoc() { + return(documentation); + } } \ No newline at end of file From 1c84a49dbf31acf3ac9f75bd913db96457cad74a Mon Sep 17 00:00:00 2001 From: xristosoik Date: Sun, 7 Jun 2015 05:36:30 +0300 Subject: [PATCH 05/10] Fixing the displaying of methods --- .../groovy/DisplayDocs/DocStructure.java | 28 +++++++++--- .../groovy/DisplayDocs/ImportJavadocs.java | 2 +- .../groovy/DisplayDocs/MethodStructure.java | 45 ++++++++++++++++++- .../DisplayDocs/ImportJavadocsTest.java | 27 +++++++++++ 4 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java index 1708040013f..99fb7a024dc 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java @@ -97,7 +97,7 @@ protected void loadMethodsInfo (String path) { break; } if (str.contains("")) { - str += "\n"; + str += "\n\n"; } if (str.contains("") || str.contains("
    ") || @@ -109,8 +109,12 @@ protected void loadMethodsInfo (String path) { str.replaceAll("\\<.*?>","")); } name = MethodStructure.cleanName(name); + /* + I the key exists i add in the end of the name + the char - and a number of a counter. + */ if (methodList.containsKey(name)) { - name += counter; + name += "-" + counter; counter++; } else counter = 0; @@ -171,10 +175,22 @@ public String cleanHtmlEntities (String str) { public String getAllDocumentation(String name) { name = name.replaceAll("\"", ""); MethodStructure temp = methodList.get(name); - String displayedDoc; - if (temp != null) - displayedDoc = temp.getMethodName() + "\n" + temp.getMethodDoc(); - else + String displayedDoc = "", tempName; + int counter = 0; + if (temp != null) { + displayedDoc += temp; + tempName = name + "-" + counter; + temp = methodList.get(tempName); + /* + The purpose of this loop is to add all the overloaded methods. + */ + while (temp != null) { + displayedDoc += temp; + counter++; + tempName = name + "-" + counter; + temp = methodList.get(tempName); + } + } else displayedDoc = "There is not method with that name in" + className + "plase use \":importdocs\" to import the correct Class"; return(displayedDoc); diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java index f984f236e48..8cdc2b3f811 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java @@ -37,7 +37,7 @@ public class ImportJavadocs { /** * This method find the target fill to the javadocs of the Class that is specifies by the className. * @param className The name of a class whom javadocs we want to import. - * @return true if this class exists and false if not. + * @return The DocStructure of the class. */ public static DocStructure findClass (String className) { try { diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java index 75970d9f84c..962c0d0b33c 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java @@ -34,21 +34,62 @@ public MethodStructure (String name, String Block) { documentation = Block; } + /** + * + * @param name The name of the Method in html code + * @return The name of the method without + */ + public static String cleanName(String name){ name = name.split("

    ")[1]; name = name.split("

    ")[0]; return(name); } + /** + * + * @return Returns the method name + */ public String getMethodName() { return(methodName); } /** - * - * @return + * + * @return Return the method documentation */ public String getMethodDoc() { return(documentation); } + /** + * This method has as a purpose to create a separator based on the length of + * the method name. + * @param name the name of a method + * @return the separator + */ + public String createNameSeparator(String name) { + String sep = ""; + int nameLength; + /* + I am identify the length of the method name + */ + nameLength = name.toCharArray().length; + + for (int i = 0; i < nameLength; i++) { + sep += "="; + } + sep += "\n"; + return(sep); + } + + @Override + public String toString() { + String finalText = "", separator; + separator = createNameSeparator(methodName.split("-")[0]); + finalText += separator; + finalText += methodName.split("-")[0] + "\n"; + finalText += separator; + finalText += documentation + "\n"; + return(finalText); + } } \ No newline at end of file diff --git a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java new file mode 100644 index 00000000000..5ebf42509d4 --- /dev/null +++ b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java @@ -0,0 +1,27 @@ +/* + * 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. + */ +package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; + +/** + * + * @author xristosoik (https://github.com/xristosoik) + */ +public class ImportJavadocsTest { + +} From f30e142ab19c17fabda6bdc5448d61018e179db0 Mon Sep 17 00:00:00 2001 From: xristosoik Date: Sun, 7 Jun 2015 12:54:10 +0300 Subject: [PATCH 06/10] Addition of web parsing functionality --- .../tinkerpop/gremlin/console/Console.groovy | 2 +- .../groovy/DisplayDocs/DocStructure.java | 111 ++++++++++++++- .../groovy/DisplayDocs/ImportJavadocs.java | 128 ++++++++++++++++-- .../groovy/DisplayDocs/DocStructureTest.java | 27 ++++ .../DisplayDocs/ImportJavadocsTest.java | 3 + 5 files changed, 258 insertions(+), 13 deletions(-) create mode 100644 gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructureTest.java diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy index 6943e896808..a0b0768bc71 100644 --- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy +++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy @@ -57,7 +57,7 @@ class Console { private static final String IMPORT_STATIC_SPACE = "import static " private static final String NULL = "null" private static final String ELLIPSIS = "..." - protected static DocStructure currdocs = ImportJavadocs.findClass("AbstractChannelizer") + protected static DocStructure currdocs = ImportJavadocs.findClass("Graph") private Iterator tempIterator = Collections.emptyIterator() diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java index 99fb7a024dc..0b96e9d7d7d 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java @@ -26,6 +26,9 @@ import java.util.TreeMap; import java.io.BufferedReader; import java.io.FileReader; +import java.io.InputStreamReader; +import java.net.URL; +import java.net.URLConnection; public class DocStructure { private String className = "Not initalized"; @@ -36,7 +39,10 @@ public class DocStructure { public DocStructure (String path, String name) throws Exception { className = name; classPath = path; - loadMethodsInfo(path); + if (ImportJavadocs.getWebpage()) + loadMethodsInfoWeb(path); + else + loadMethodsInfo(path); } /** * This method loads the documentation of class's all methods. @@ -132,6 +138,105 @@ protected void loadMethodsInfo (String path) { } } + + /** + * Loads the method info from url page + * @param path The url to the class page. + */ + protected void loadMethodsInfoWeb (String path) { + methodList = new TreeMap(); + boolean find, finishReading = false; + String temp = "", name; + MethodStructure temporary; + int position = 0, counter = 0; + try { + URL javadoc = new URL(path); + URLConnection connection = javadoc.openConnection(); + BufferedReader in = new BufferedReader(new InputStreamReader( + connection.getInputStream(), "UTF-8")); + String str; + while ((str = in.readLine()) != null) { + if (finishReading) + break; + find = str.contains(methodSeparator); + if (find) { + while ((str = in.readLine()) != null) { + if (position == 0 && str.contains("")) { + position++; + continue; + } + if (position == 1) { + if (str.contains("")) { + position++; + continue; + } else { + position = 0; + } + } + if (position == 2) { + if (str.contains("
      ")) { + position++; + continue; + } else if (str.contains("
        ")) { + position++; + finishReading = true; + continue; + } else { + position = 0; + } + } + if (position == 3) { + if (str.contains("
      • ")) { + position++; + continue; + } else { + position = 0; + } + } + if (position == 4 && str.contains("

        ")) { + name = str; + while ((str = in.readLine()) != null) { + if (str.contains("

      ")) { + position = 0; + break; + } + if (str.contains("")) { + str += "\n\n"; + } + if (str.contains("") || + str.contains("
      ") || + str.contains("")) { + str = "\n" + str + "\n"; + } + str = str.replaceAll("
      ", "\n"); + temp += cleanHtmlEntities( + str.replaceAll("\\<.*?>","")); + } + name = MethodStructure.cleanName(name); + /* + I the key exists i add in the end of the name + the char - and a number of a counter. + */ + if (methodList.containsKey(name)) { + name += "-" + counter; + counter++; + } else + counter = 0; + temporary = new MethodStructure(name, temp); + methodList.put(temporary.getMethodName(), temporary); + temp = ""; + } else { + position =0; + } + } + } + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + } + /** * * @return the name of the class @@ -191,8 +296,8 @@ public String getAllDocumentation(String name) { temp = methodList.get(tempName); } } else - displayedDoc = "There is not method with that name in" + - className + "plase use \":importdocs\" to import the correct Class"; + displayedDoc = "There is not method with that name in " + + className + " please use \":importdocs\" to import the correct Class"; return(displayedDoc); } } diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java index 8cdc2b3f811..4522000efbf 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java @@ -20,6 +20,8 @@ package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; import java.io.*; +import java.net.URL; +import java.net.URLConnection; /** * @@ -28,11 +30,7 @@ public class ImportJavadocs { static protected DocStructure currentDoc; - - /*public static void main(String[] args) { - System.out.println(findClass(">" + "Client" + "<")); - System.out.println(currentDoc.getMethodList().size()); - }*/ + static private boolean webpage = false; /** * This method find the target fill to the javadocs of the Class that is specifies by the className. @@ -75,9 +73,10 @@ protected static String[] findPath2CorrectLine (String className) { path[0] = "."; int i = 0; try { - File pathDefinition = new File("."); - path[0] = pathDefinition.getCanonicalPath().replace("bin", "target/site/apidocs"); - File javadocDirectory = new File (path[0]); + webpage = false; + path[0] = findCorrectPath2Javadocs (); + if (path[0].equals("")) + throw new Exception(); String[] folders = {"/core", "/full"}; for (String dir : folders) { BufferedReader in = new BufferedReader( @@ -97,10 +96,121 @@ protected static String[] findPath2CorrectLine (String className) { break; } } + path[1] = line; } catch (Exception e) { + if (path[0].equals("")) { + System.out.println("ATTENTION!!! It was not able to access the local javadoc folder"); + path = findPath2CorrectLineWeb(className); + } else System.out.println(e.getMessage()); + } finally { + return(path); + } + } + + /** + * Search all the possible paths to identify which is the + * available one. + * @return + */ + public static String findCorrectPath2Javadocs () { + String path; + try { + File pathDefinition = new File("."); + + path = pathDefinition.getCanonicalPath().replace("bin", "javadocs"); + File javadocDirectory = new File (path); + if (javadocDirectory.list() != null) + return(path); + + path = pathDefinition.getCanonicalPath().replace("bin", "target/site/apidocs"); + javadocDirectory = new File (path); + if (javadocDirectory.list() != null) + return(path); + } catch (Exception e) { + + } + return(""); + } + + /** + * Find the specific url to the class javadoc. + * @param className The name the class. + * @return a string array of the 2 parts of the specific url + */ + protected static String[] findPath2CorrectLineWeb (String className) { + boolean find = false; + String line = ""; + String path[] = new String[2]; + path[0] = "."; + int i = 0; + try { + System.out.println("We will search for javadocs online!!!!"); + path[0] = findCorrectURL(); + String[] folders = {"/core", "/full"}; + URL tinkerpop; + URLConnection connection; + for (String dir : folders) { + tinkerpop = new URL(path[0] + dir + + "/allclasses-noframe.html"); + connection = tinkerpop.openConnection(); + BufferedReader in = new BufferedReader( + new InputStreamReader( + connection.getInputStream(), "UTF-8")); + String str; + while ((str = in.readLine()) != null) { + find = str.contains(className); + if (find) { + line = str; + break; + } + } + in.close(); + if (find) { + path[0] += dir; + webpage = true; + break; + } + } + } catch (Exception e) { + System.out.println(e.getMessage()); } path[1] = line; - return(path); + return(path); } + + /** + * Search for the current url to the javadocs + * @return the correct url + */ + public static String findCorrectURL () { + String path = ""; + try { + URL tinkerpop = new URL("http://tinkerpop.incubator.apache.org/"); + URLConnection connection = tinkerpop.openConnection(); + BufferedReader in = new BufferedReader(new InputStreamReader( + connection.getInputStream(), "UTF-8")); + String line; + while ((line = in.readLine()) != null) { + if (line.contains("http://tinkerpop.incubator.apache.org/javadocs/")) { + path = line; + path = path.split("href=\"")[1]; + path = path.split("/\">")[0]; + break; + } + } + in.close(); + path = path.split("/core")[0]; + path = path.split("/full")[0]; + return (path); + } catch (Exception e) { + + } + return(""); + } + + + public static Boolean getWebpage() { + return(webpage); + } } \ No newline at end of file diff --git a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructureTest.java b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructureTest.java new file mode 100644 index 00000000000..abcf40ac3c7 --- /dev/null +++ b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructureTest.java @@ -0,0 +1,27 @@ +/* + * 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. + */ +package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; + +/** + * + * @author xristosoik (https://github.com/xristosoik) + */ +public class DocStructureTest { + +} diff --git a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java index 5ebf42509d4..a409a4a2c12 100644 --- a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java +++ b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java @@ -22,6 +22,9 @@ * * @author xristosoik (https://github.com/xristosoik) */ + +import static org.junit.Assert.*; + public class ImportJavadocsTest { } From f3d59cac1a82ec2188018e8771f3aa9040512dcf Mon Sep 17 00:00:00 2001 From: xristosoik Date: Sun, 7 Jun 2015 13:28:53 +0300 Subject: [PATCH 07/10] Addition of CurrDocsCommand.groovy --- .../tinkerpop/gremlin/console/Console.groovy | 1 + .../console/commands/CurrDocsCommand.groovy | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/CurrDocsCommand.groovy diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy index a0b0768bc71..aa0932e945b 100644 --- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy +++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy @@ -89,6 +89,7 @@ class Console { groovy.register(new SubmitCommand(groovy, mediator)) groovy.register(new ImportDocsCommand(groovy, mediator)) groovy.register(new DocsCommand(groovy, mediator)) + groovy.register(new CurrDocsCommand(groovy, mediator)) // hide output temporarily while imports execute showShellEvaluationOutput(false) diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/CurrDocsCommand.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/CurrDocsCommand.groovy new file mode 100644 index 00000000000..228aa35fa7a --- /dev/null +++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/commands/CurrDocsCommand.groovy @@ -0,0 +1,44 @@ +/* + * 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. + */ + +package org.apache.tinkerpop.gremlin.console.commands + +import org.apache.tinkerpop.gremlin.console.Mediator +import org.apache.tinkerpop.gremlin.console.Console +import org.codehaus.groovy.tools.shell.Groovysh +import org.codehaus.groovy.tools.shell.CommandSupport + +import org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs.* + +class CurrDocsCommand extends CommandSupport { + + private final Mediator mediator + + public CurrDocsCommand(final Groovysh shell, final Mediator mediator) { + super(shell, ":currdocs", ":crrdc") + this.mediator = mediator + } + + @Override + def Object execute(final List arguments) { + io.out.println(Console.getCurrdocs().getClassName()) + } +} + + From 816ee053f18cdf78c39692d138b9eadfe47f07ff Mon Sep 17 00:00:00 2001 From: xristosoik Date: Sun, 7 Jun 2015 18:35:14 +0300 Subject: [PATCH 08/10] Fixing bugs and add unit tests --- .../groovy/DisplayDocs/ImportJavadocs.java | 20 +++------ .../groovy/DisplayDocs/DocStructureTest.java | 27 ------------ .../DisplayDocs/ImportJavadocsTest.java | 43 +++++++++++++++++++ 3 files changed, 50 insertions(+), 40 deletions(-) delete mode 100644 gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructureTest.java diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java index 4522000efbf..6f5f5771455 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java @@ -45,8 +45,9 @@ public static DocStructure findClass (String className) { currentDoc = tempDoc; } catch (Exception e) { System.out.println("Unsuccesful import!"); - } - return(currentDoc); + } finally { + return(currentDoc); + } } /** @@ -71,6 +72,7 @@ protected static String[] findPath2CorrectLine (String className) { String line = ""; String path[] = new String[2]; path[0] = "."; + path[1] = ""; int i = 0; try { webpage = false; @@ -98,11 +100,8 @@ protected static String[] findPath2CorrectLine (String className) { } path[1] = line; } catch (Exception e) { - if (path[0].equals("")) { - System.out.println("ATTENTION!!! It was not able to access the local javadoc folder"); - path = findPath2CorrectLineWeb(className); - } else - System.out.println(e.getMessage()); + System.out.println("ATTENTION!!! It was not able to access the local javadoc folder"); + path = findPath2CorrectLineWeb(className); } finally { return(path); } @@ -122,13 +121,8 @@ public static String findCorrectPath2Javadocs () { File javadocDirectory = new File (path); if (javadocDirectory.list() != null) return(path); - - path = pathDefinition.getCanonicalPath().replace("bin", "target/site/apidocs"); - javadocDirectory = new File (path); - if (javadocDirectory.list() != null) - return(path); } catch (Exception e) { - + return(""); } return(""); } diff --git a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructureTest.java b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructureTest.java deleted file mode 100644 index abcf40ac3c7..00000000000 --- a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructureTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - */ -package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; - -/** - * - * @author xristosoik (https://github.com/xristosoik) - */ -public class DocStructureTest { - -} diff --git a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java index a409a4a2c12..e4757857e3b 100644 --- a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java +++ b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java @@ -24,7 +24,50 @@ */ import static org.junit.Assert.*; +import org.junit.Test; public class ImportJavadocsTest { + @Test + public void behaviorFindPath2CorrectLineWeb () throws Exception { + String[] url = ImportJavadocs.findPath2CorrectLineWeb(">" + "Graph" + "<"); + assertTrue(url[0].contains("http://tinkerpop.incubator.apache.org/javadocs")); + assertTrue(url[0].contains("core")); + assertTrue(url[1].contains("org/apache/tinkerpop/gremlin/structure/Graph.html")); + } + @Test + public void behaviorFindPath2CorrectLineWebATNotExistanceSituation () throws Exception { + String[] url = ImportJavadocs.findPath2CorrectLineWeb(">" + "something" + "<"); + + assertFalse(url[0] == null); + assertFalse(url[1] == null); + } + + @Test + public void behaviorOfFindCorrectPath2Javadocs () throws Exception { + String url = ImportJavadocs.findCorrectPath2Javadocs (); + assertNotNull(url); + } + + @Test + public void behaviorOfFindPath2CorrectLineATNotExistanceSituation () throws Exception { + String[] path = ImportJavadocs.findPath2CorrectLineWeb(">" + "something" + "<"); + assertNotNull(path[0]); + assertNotNull(path[1]); + } + + @Test + public void behaviorOfFindClass() throws Exception { + DocStructure doc = ImportJavadocs.findClass("Graph"); + assertNotNull(doc); + assertTrue(doc.getMethodList().size() > 0); + } + + @Test + public void behaviorOfFindClassNotExistanceSituation() throws Exception { + DocStructure doc = ImportJavadocs.findClass("Graph"); + doc = ImportJavadocs.findClass("Something"); + assertNotNull(doc); + assertTrue(doc.getMethodList().size() > 0); + } } From 8f94b13ce47fe594a78270b87941d3b6d03df1a2 Mon Sep 17 00:00:00 2001 From: xristosoik Date: Tue, 9 Jun 2015 11:46:38 +0300 Subject: [PATCH 09/10] File separator and format changes --- .../tinkerpop/gremlin/console/Console.groovy | 2 +- .../groovy/DisplayDocs/DocStructure.java | 524 +++++++++--------- .../groovy/DisplayDocs/ImportJavadocs.java | 346 ++++++------ .../groovy/DisplayDocs/MethodStructure.java | 36 +- .../DisplayDocs/ImportJavadocsTest.java | 24 +- 5 files changed, 477 insertions(+), 455 deletions(-) diff --git a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy index aa0932e945b..76498995dec 100644 --- a/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy +++ b/gremlin-console/src/main/groovy/org/apache/tinkerpop/gremlin/console/Console.groovy @@ -77,7 +77,7 @@ class Console { maxIteration = Integer.parseInt(evt.newValue) } }) - //static PreferenceChangeListener doc = new PreferenceChangeListener(); + final Mediator mediator = new Mediator(this) def commandsToRemove = groovy.getRegistry().commands().findAll{it instanceof SetCommand} commandsToRemove.each {groovy.getRegistry().remove(it)} diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java index 0b96e9d7d7d..7ef5ef2a8dd 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/DocStructure.java @@ -16,12 +16,11 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; /** * - * @author xristosoik (https://github.com/xristosoik) + * @author xristosoik (https://github.com/xristosoik) */ import java.util.TreeMap; import java.io.BufferedReader; @@ -29,275 +28,288 @@ import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; + public class DocStructure { - private String className = "Not initalized"; - private String classPath; - private TreeMap methodList; - private final String methodSeparator = ""; + private String className = "Not initalized"; + private String classPath; + private TreeMap methodList; + private final String methodSeparator = ""; - public DocStructure (String path, String name) throws Exception { - className = name; - classPath = path; - if (ImportJavadocs.getWebpage()) - loadMethodsInfoWeb(path); - else - loadMethodsInfo(path); - } - /** - * This method loads the documentation of class's all methods. - * @param path - */ - protected void loadMethodsInfo (String path) { - methodList = new TreeMap(); - boolean find, finishReading = false; - String temp = "", name; - MethodStructure temporary; - int position = 0, counter = 0; - try { - BufferedReader in = new BufferedReader(new FileReader(path)); - String str; - while ((str = in.readLine()) != null) { - if (finishReading) - break; - find = str.contains(methodSeparator); - if (find) { - while ((str = in.readLine()) != null) { - if (position == 0 && str.contains("")) { - position++; - continue; - } - if (position == 1) { - if (str.contains("")) { - position++; - continue; - } else { - position = 0; - } - } - if (position == 2) { - if (str.contains("
        ")) { - position++; - continue; - } else if (str.contains("
          ")) { - position++; - finishReading = true; - continue; - } else { - position = 0; - } - } - if (position == 3) { - if (str.contains("
        • ")) { - position++; - continue; - } else { - position = 0; - } - } - if (position == 4 && str.contains("

          ")) { - name = str; - while ((str = in.readLine()) != null) { - if (str.contains("

        ")) { - position = 0; - break; - } - if (str.contains("")) { - str += "\n\n"; - } - if (str.contains("") || - str.contains("
        ") || - str.contains("")) { - str = "\n" + str + "\n"; - } - str = str.replaceAll("
        ", "\n"); - temp += cleanHtmlEntities( - str.replaceAll("\\<.*?>","")); - } - name = MethodStructure.cleanName(name); - /* - I the key exists i add in the end of the name - the char - and a number of a counter. - */ - if (methodList.containsKey(name)) { - name += "-" + counter; - counter++; - } else - counter = 0; - temporary = new MethodStructure(name, temp); - methodList.put(temporary.getMethodName(), temporary); - temp = ""; - } else { - position =0; - } + public DocStructure(String path, String name) throws Exception { + className = name; + classPath = path; + if (ImportJavadocs.getWebpage()) { + loadMethodsInfoWeb(path); + } else { + loadMethodsInfo(path); + } + } + + /** + * This method loads the documentation of class's all methods. + * + * @param path + */ + protected void loadMethodsInfo(String path) { + methodList = new TreeMap(); + boolean find, finishReading = false; + String temp = "", name; + MethodStructure temporary; + int position = 0, counter = 0; + try { + BufferedReader in = new BufferedReader(new FileReader(path)); + String str; + while ((str = in.readLine()) != null) { + if (finishReading) { + break; + } + find = str.contains(methodSeparator); + if (find) { + while ((str = in.readLine()) != null) { + if (position == 0 && str.contains("")) { + position++; + continue; + } + if (position == 1) { + if (str.contains("")) { + position++; + continue; + } else { + position = 0; + } + } + if (position == 2) { + if (str.contains("
          ")) { + position++; + continue; + } else if (str.contains("
            ")) { + position++; + finishReading = true; + continue; + } else { + position = 0; + } + } + if (position == 3) { + if (str.contains("
          • ")) { + position++; + continue; + } else { + position = 0; + } + } + if (position == 4 && str.contains("

            ")) { + name = str; + while ((str = in.readLine()) != null) { + if (str.contains("

          ")) { + position = 0; + break; + } + if (str.contains("")) { + str += "\n\n"; } + if (str.contains("") + || str.contains("
          ") + || str.contains("")) { + str = "\n" + str + "\n"; + } + str = str.replaceAll("
          ", "\n"); + temp += cleanHtmlEntities( + str.replaceAll("\\<.*?>", "")); + } + name = MethodStructure.cleanName(name); + /* + I the key exists i add in the end of the name + the char - and a number of a counter. + */ + if (methodList.containsKey(name)) { + name += "-" + counter; + counter++; + } else { + counter = 0; } + temporary = new MethodStructure(name, temp); + methodList.put(temporary.getMethodName(), temporary); + temp = ""; + } else { + position = 0; } - } catch (Exception e) { - System.out.println(e.getMessage()); + } } + } + } catch (Exception e) { + System.out.println(e.getMessage()); + } + + } - } - - /** - * Loads the method info from url page - * @param path The url to the class page. - */ - protected void loadMethodsInfoWeb (String path) { - methodList = new TreeMap(); - boolean find, finishReading = false; - String temp = "", name; - MethodStructure temporary; - int position = 0, counter = 0; - try { - URL javadoc = new URL(path); - URLConnection connection = javadoc.openConnection(); - BufferedReader in = new BufferedReader(new InputStreamReader( - connection.getInputStream(), "UTF-8")); - String str; - while ((str = in.readLine()) != null) { - if (finishReading) - break; - find = str.contains(methodSeparator); - if (find) { - while ((str = in.readLine()) != null) { - if (position == 0 && str.contains("")) { - position++; - continue; - } - if (position == 1) { - if (str.contains("")) { - position++; - continue; - } else { - position = 0; - } - } - if (position == 2) { - if (str.contains("
            ")) { - position++; - continue; - } else if (str.contains("
              ")) { - position++; - finishReading = true; - continue; - } else { - position = 0; - } - } - if (position == 3) { - if (str.contains("
            • ")) { - position++; - continue; - } else { - position = 0; - } - } - if (position == 4 && str.contains("

              ")) { - name = str; - while ((str = in.readLine()) != null) { - if (str.contains("

            ")) { - position = 0; - break; - } - if (str.contains("")) { - str += "\n\n"; - } - if (str.contains("") || - str.contains("
            ") || - str.contains("")) { - str = "\n" + str + "\n"; - } - str = str.replaceAll("
            ", "\n"); - temp += cleanHtmlEntities( - str.replaceAll("\\<.*?>","")); - } - name = MethodStructure.cleanName(name); - /* - I the key exists i add in the end of the name - the char - and a number of a counter. - */ - if (methodList.containsKey(name)) { - name += "-" + counter; - counter++; - } else - counter = 0; - temporary = new MethodStructure(name, temp); - methodList.put(temporary.getMethodName(), temporary); - temp = ""; - } else { - position =0; - } + /** + * Loads the method info from url page + * + * @param path The url to the class page. + */ + protected void loadMethodsInfoWeb(String path) { + methodList = new TreeMap(); + boolean find, finishReading = false; + String temp = "", name; + MethodStructure temporary; + int position = 0, counter = 0; + try { + URL javadoc = new URL(path); + URLConnection connection = javadoc.openConnection(); + BufferedReader in = new BufferedReader(new InputStreamReader( + connection.getInputStream(), "UTF-8")); + String str; + while ((str = in.readLine()) != null) { + if (finishReading) { + break; + } + find = str.contains(methodSeparator); + if (find) { + while ((str = in.readLine()) != null) { + if (position == 0 && str.contains("")) { + position++; + continue; + } + if (position == 1) { + if (str.contains("")) { + position++; + continue; + } else { + position = 0; + } + } + if (position == 2) { + if (str.contains("
              ")) { + position++; + continue; + } else if (str.contains("
                ")) { + position++; + finishReading = true; + continue; + } else { + position = 0; + } + } + if (position == 3) { + if (str.contains("
              • ")) { + position++; + continue; + } else { + position = 0; + } + } + if (position == 4 && str.contains("

                ")) { + name = str; + while ((str = in.readLine()) != null) { + if (str.contains("

              ")) { + position = 0; + break; } + if (str.contains("")) { + str += "\n\n"; + } + if (str.contains("") + || str.contains("
              ") + || str.contains("")) { + str = "\n" + str + "\n"; + } + str = str.replaceAll("
              ", "\n"); + temp += cleanHtmlEntities( + str.replaceAll("\\<.*?>", "")); + } + name = MethodStructure.cleanName(name); + /* + I the key exists i add in the end of the name + the char - and a number of a counter. + */ + if (methodList.containsKey(name)) { + name += "-" + counter; + counter++; + } else { + counter = 0; } + temporary = new MethodStructure(name, temp); + methodList.put(temporary.getMethodName(), temporary); + temp = ""; + } else { + position = 0; } - } catch (Exception e) { - System.out.println(e.getMessage()); + } } - - } - - /** - * - * @return the name of the class - */ - public String getClassName() { - return(className); - } - /** - * - * @return the path to the class - */ - public String getClassPath() { - return(classPath); + } + } catch (Exception e) { + System.out.println(e.getMessage()); } - /** - * - * @return the Map of the class methods - */ - public TreeMap getMethodList() { - return(methodList); - } - /** - * - * @param str - * @return returns the line of html with the correct characters - */ - public String cleanHtmlEntities (String str) { - str = str.replaceAll(" ", " "); - str = str.replaceAll("<", "<"); - str = str.replaceAll(">", ">"); - str = str.replaceAll("&", "&"); - str = str.replaceAll("¢", "¢"); - str = str.replaceAll("£", "£"); - str = str.replaceAll("¥", "¥"); - str = str.replaceAll("€", "€"); - str = str.replaceAll("©", "©"); - str = str.replaceAll("®", "®"); - return(str); - } - - public String getAllDocumentation(String name) { - name = name.replaceAll("\"", ""); - MethodStructure temp = methodList.get(name); - String displayedDoc = "", tempName; - int counter = 0; - if (temp != null) { + + } + + /** + * + * @return the name of the class + */ + public String getClassName() { + return (className); + } + + /** + * + * @return the path to the class + */ + public String getClassPath() { + return (classPath); + } + + /** + * + * @return the Map of the class methods + */ + public TreeMap getMethodList() { + return (methodList); + } + + /** + * + * @param str + * @return returns the line of html with the correct characters + */ + public String cleanHtmlEntities(String str) { + str = str.replaceAll(" ", " "); + str = str.replaceAll("<", "<"); + str = str.replaceAll(">", ">"); + str = str.replaceAll("&", "&"); + str = str.replaceAll("¢", "¢"); + str = str.replaceAll("£", "£"); + str = str.replaceAll("¥", "¥"); + str = str.replaceAll("€", "€"); + str = str.replaceAll("©", "©"); + str = str.replaceAll("®", "®"); + return (str); + } + + public String getAllDocumentation(String name) { + name = name.replaceAll("\"", ""); + MethodStructure temp = methodList.get(name); + String displayedDoc = "", tempName; + int counter = 0; + if (temp != null) { + displayedDoc += temp; + tempName = name + "-" + counter; + temp = methodList.get(tempName); + /* + The purpose of this loop is to add all the overloaded methods. + */ + while (temp != null) { displayedDoc += temp; + counter++; tempName = name + "-" + counter; temp = methodList.get(tempName); - /* - The purpose of this loop is to add all the overloaded methods. - */ - while (temp != null) { - displayedDoc += temp; - counter++; - tempName = name + "-" + counter; - temp = methodList.get(tempName); - } - } else - displayedDoc = "There is not method with that name in " + - className + " please use \":importdocs\" to import the correct Class"; - return(displayedDoc); + } + } else { + displayedDoc = "There is not method with that name in " + + className + " please use \":importdocs\" to import the correct Class"; } + return (displayedDoc); + } } diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java index 6f5f5771455..cc05af6a154 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; import java.io.*; @@ -28,183 +27,194 @@ * @author xristosoik (https://github.com/xristosoik) */ public class ImportJavadocs { - - static protected DocStructure currentDoc; - static private boolean webpage = false; - /** - * This method find the target fill to the javadocs of the Class that is specifies by the className. - * @param className The name of a class whom javadocs we want to import. - * @return The DocStructure of the class. - */ - public static DocStructure findClass (String className) { - try { - className = className.replaceAll("\"", ""); - String path = findPath2TheJavadoc(">" + className + "<"); - DocStructure tempDoc = new DocStructure(path, className); - currentDoc = tempDoc; - } catch (Exception e) { - System.out.println("Unsuccesful import!"); - } finally { - return(currentDoc); - } - } - - /** - * Clean up the line keeping only the path. - * @param className - * @return - */ - protected static String findPath2TheJavadoc (String className) { - String path[] = findPath2CorrectLine(className); - path[1] = path[1].split("href=\"")[1]; - path[1] = path[1].split("\" title")[0]; - return(path[0] + "/" + path[1]); - } + static protected DocStructure currentDoc; + static private boolean webpage = false; + + /** + * This method find the target fill to the javadocs of the Class that is + * specifies by the className. + * + * @param className The name of a class whom javadocs we want to import. + * @return The DocStructure of the class. + */ + public static DocStructure findClass(String className) { + try { + className = className.replaceAll("\"", ""); + String path = findPath2TheJavadoc(">" + className + "<"); + DocStructure tempDoc = new DocStructure(path, className); + currentDoc = tempDoc; + } catch (Exception e) { + System.out.println("Unsuccesful import!"); + } finally { + return (currentDoc); + } + } + + /** + * Clean up the line keeping only the path. + * + * @param className + * @return + */ + protected static String findPath2TheJavadoc(String className) { + String path[] = findPath2CorrectLine(className); + path[1] = path[1].split("href=\"")[1]; + path[1] = path[1].split("\" title")[0]; + if (!webpage) { + return (path[0] + File.separator + path[1]); + } else { + return (path[0] + "/" + path[1]); + } + } - /** - * Τhis method search all directories for the correct line of html. - * @param className - * @return correct line html free. - */ - protected static String[] findPath2CorrectLine (String className) { - boolean find = false; - String line = ""; - String path[] = new String[2]; - path[0] = "."; - path[1] = ""; - int i = 0; - try { - webpage = false; - path[0] = findCorrectPath2Javadocs (); - if (path[0].equals("")) - throw new Exception(); - String[] folders = {"/core", "/full"}; - for (String dir : folders) { - BufferedReader in = new BufferedReader( - new FileReader(path[0] + dir + - "/allclasses-noframe.html")); - String str; - while ((str = in.readLine()) != null) { - find = str.contains(className); - if (find) { - line = str; - break; - } - } - in.close(); - if (find) { - path[0] += dir; - break; - } - } - path[1] = line; - } catch (Exception e) { - System.out.println("ATTENTION!!! It was not able to access the local javadoc folder"); - path = findPath2CorrectLineWeb(className); - } finally { - return(path); + /** + * Τhis method search all directories for the correct line of html. + * + * @param className + * @return correct line html free. + */ + protected static String[] findPath2CorrectLine(String className) { + boolean find = false; + String line = ""; + String path[] = new String[2]; + path[0] = "."; + path[1] = ""; + int i = 0; + try { + webpage = false; + path[0] = findCorrectPath2Javadocs(); + if (path[0].equals("")) { + throw new Exception(); + } + String[] folders = {"/core", "/full"}; + for (String dir : folders) { + BufferedReader in = new BufferedReader( + new FileReader(path[0] + dir + + "/allclasses-noframe.html")); + String str; + while ((str = in.readLine()) != null) { + find = str.contains(className); + if (find) { + line = str; + break; + } } - } - - /** - * Search all the possible paths to identify which is the - * available one. - * @return - */ - public static String findCorrectPath2Javadocs () { - String path; - try { - File pathDefinition = new File("."); + in.close(); + if (find) { + path[0] += dir; + break; + } + } + path[1] = line; + } catch (Exception e) { + System.out.println("ATTENTION!!! It was not able to access the local javadoc folder"); + path = findPath2CorrectLineWeb(className); + } finally { + return (path); + } + } + + /** + * Search all the possible paths to identify which is the available one. + * + * @return + */ + public static String findCorrectPath2Javadocs() { + String path; + try { + File pathDefinition = new File("."); - path = pathDefinition.getCanonicalPath().replace("bin", "javadocs"); - File javadocDirectory = new File (path); - if (javadocDirectory.list() != null) - return(path); - } catch (Exception e) { - return(""); + path = pathDefinition.getCanonicalPath().replace("bin", "javadocs"); + File javadocDirectory = new File(path); + if (javadocDirectory.list() != null) { + return (path); } - return(""); + } catch (Exception e) { + return (""); } - - /** - * Find the specific url to the class javadoc. - * @param className The name the class. - * @return a string array of the 2 parts of the specific url - */ - protected static String[] findPath2CorrectLineWeb (String className) { - boolean find = false; - String line = ""; - String path[] = new String[2]; - path[0] = "."; - int i = 0; - try { - System.out.println("We will search for javadocs online!!!!"); - path[0] = findCorrectURL(); - String[] folders = {"/core", "/full"}; - URL tinkerpop; - URLConnection connection; - for (String dir : folders) { - tinkerpop = new URL(path[0] + dir + - "/allclasses-noframe.html"); - connection = tinkerpop.openConnection(); - BufferedReader in = new BufferedReader( - new InputStreamReader( - connection.getInputStream(), "UTF-8")); - String str; - while ((str = in.readLine()) != null) { - find = str.contains(className); - if (find) { - line = str; - break; - } - } - in.close(); - if (find) { - path[0] += dir; - webpage = true; - break; - } - } - } catch (Exception e) { - System.out.println(e.getMessage()); - } - path[1] = line; - return(path); - } - - /** - * Search for the current url to the javadocs - * @return the correct url - */ - public static String findCorrectURL () { - String path = ""; - try { - URL tinkerpop = new URL("http://tinkerpop.incubator.apache.org/"); - URLConnection connection = tinkerpop.openConnection(); - BufferedReader in = new BufferedReader(new InputStreamReader( - connection.getInputStream(), "UTF-8")); - String line; - while ((line = in.readLine()) != null) { - if (line.contains("http://tinkerpop.incubator.apache.org/javadocs/")) { - path = line; - path = path.split("href=\"")[1]; - path = path.split("/\">")[0]; + return (""); + } + + /** + * Find the specific url to the class javadoc. + * + * @param className The name the class. + * @return a string array of the 2 parts of the specific url + */ + protected static String[] findPath2CorrectLineWeb(String className) { + boolean find = false; + String line = ""; + String path[] = new String[2]; + path[0] = "."; + int i = 0; + try { + System.out.println("We will search for javadocs online!!!!"); + path[0] = findCorrectURL(); + String[] folders = {"/core", "/full"}; + URL tinkerpop; + URLConnection connection; + for (String dir : folders) { + tinkerpop = new URL(path[0] + dir + + "/allclasses-noframe.html"); + connection = tinkerpop.openConnection(); + BufferedReader in = new BufferedReader( + new InputStreamReader( + connection.getInputStream(), "UTF-8")); + String str; + while ((str = in.readLine()) != null) { + find = str.contains(className); + if (find) { + line = str; break; } } in.close(); - path = path.split("/core")[0]; - path = path.split("/full")[0]; - return (path); - } catch (Exception e) { - + if (find) { + path[0] += dir; + webpage = true; + break; + } } - return(""); + } catch (Exception e) { + System.out.println(e.getMessage()); } - - - public static Boolean getWebpage() { - return(webpage); + path[1] = line; + return (path); + } + + /** + * Search for the current url to the javadocs + * + * @return the correct url + */ + public static String findCorrectURL() { + String path = ""; + try { + URL tinkerpop = new URL("http://tinkerpop.incubator.apache.org/"); + URLConnection connection = tinkerpop.openConnection(); + BufferedReader in = new BufferedReader(new InputStreamReader( + connection.getInputStream(), "UTF-8")); + String line; + while ((line = in.readLine()) != null) { + if (line.contains("http://tinkerpop.incubator.apache.org/javadocs/")) { + path = line; + path = path.split("href=\"")[1]; + path = path.split("/\">")[0]; + break; + } + } + in.close(); + path = path.split("/core")[0]; + path = path.split("/full")[0]; + return (path); + } catch (Exception e) { + } -} \ No newline at end of file + return (""); + } + + public static Boolean getWebpage() { + return (webpage); + } +} diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java index 962c0d0b33c..6381230cac6 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/MethodStructure.java @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ - package org.apache.tinkerpop.gremlin.console.groovy.DisplayDocs; /** @@ -24,64 +23,65 @@ * @author xristosoik (https://github.com/xristosoik) */ public class MethodStructure { - + private String methodName; private String documentation; private static int counter = 0; - public MethodStructure (String name, String Block) { + public MethodStructure(String name, String Block) { methodName = name; documentation = Block; } /** - * + * * @param name The name of the Method in html code * @return The name of the method without */ - - public static String cleanName(String name){ + public static String cleanName(String name) { name = name.split("

              ")[1]; name = name.split("

              ")[0]; - return(name); + return (name); } /** - * + * * @return Returns the method name */ public String getMethodName() { - return(methodName); + return (methodName); } /** - * + * * @return Return the method documentation */ public String getMethodDoc() { - return(documentation); + return (documentation); } + /** * This method has as a purpose to create a separator based on the length of * the method name. + * * @param name the name of a method * @return the separator - */ + */ public String createNameSeparator(String name) { String sep = ""; int nameLength; /* - I am identify the length of the method name - */ + I am identify the length of the method name + */ nameLength = name.toCharArray().length; for (int i = 0; i < nameLength; i++) { sep += "="; } sep += "\n"; - return(sep); + return (sep); } - + @Override public String toString() { String finalText = "", separator; @@ -90,6 +90,6 @@ public String toString() { finalText += methodName.split("-")[0] + "\n"; finalText += separator; finalText += documentation + "\n"; - return(finalText); + return (finalText); } -} \ No newline at end of file +} diff --git a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java index e4757857e3b..58a937fd112 100644 --- a/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java +++ b/gremlin-console/src/test/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocsTest.java @@ -22,47 +22,47 @@ * * @author xristosoik (https://github.com/xristosoik) */ - import static org.junit.Assert.*; import org.junit.Test; public class ImportJavadocsTest { + @Test - public void behaviorFindPath2CorrectLineWeb () throws Exception { + public void behaviorFindPath2CorrectLineWeb() throws Exception { String[] url = ImportJavadocs.findPath2CorrectLineWeb(">" + "Graph" + "<"); assertTrue(url[0].contains("http://tinkerpop.incubator.apache.org/javadocs")); assertTrue(url[0].contains("core")); assertTrue(url[1].contains("org/apache/tinkerpop/gremlin/structure/Graph.html")); } - + @Test - public void behaviorFindPath2CorrectLineWebATNotExistanceSituation () throws Exception { + public void behaviorFindPath2CorrectLineWebATNotExistanceSituation() throws Exception { String[] url = ImportJavadocs.findPath2CorrectLineWeb(">" + "something" + "<"); - + assertFalse(url[0] == null); assertFalse(url[1] == null); } - + @Test - public void behaviorOfFindCorrectPath2Javadocs () throws Exception { - String url = ImportJavadocs.findCorrectPath2Javadocs (); + public void behaviorOfFindCorrectPath2Javadocs() throws Exception { + String url = ImportJavadocs.findCorrectPath2Javadocs(); assertNotNull(url); } - + @Test - public void behaviorOfFindPath2CorrectLineATNotExistanceSituation () throws Exception { + public void behaviorOfFindPath2CorrectLineATNotExistanceSituation() throws Exception { String[] path = ImportJavadocs.findPath2CorrectLineWeb(">" + "something" + "<"); assertNotNull(path[0]); assertNotNull(path[1]); } - + @Test public void behaviorOfFindClass() throws Exception { DocStructure doc = ImportJavadocs.findClass("Graph"); assertNotNull(doc); assertTrue(doc.getMethodList().size() > 0); } - + @Test public void behaviorOfFindClassNotExistanceSituation() throws Exception { DocStructure doc = ImportJavadocs.findClass("Graph"); From 5d611956da439c03513ccd4dca45b6f0439bacd7 Mon Sep 17 00:00:00 2001 From: xristosoik Date: Tue, 9 Jun 2015 12:14:55 +0300 Subject: [PATCH 10/10] General solution for separator --- .../gremlin/console/groovy/DisplayDocs/ImportJavadocs.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java index cc05af6a154..f36500b4346 100644 --- a/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java +++ b/gremlin-console/src/main/java/org/apache/tinkerpop/gremlin/console/groovy/DisplayDocs/ImportJavadocs.java @@ -62,6 +62,7 @@ protected static String findPath2TheJavadoc(String className) { path[1] = path[1].split("href=\"")[1]; path[1] = path[1].split("\" title")[0]; if (!webpage) { + path[1].replaceAll("/", File.separator); return (path[0] + File.separator + path[1]); } else { return (path[0] + "/" + path[1]); @@ -87,11 +88,11 @@ protected static String[] findPath2CorrectLine(String className) { if (path[0].equals("")) { throw new Exception(); } - String[] folders = {"/core", "/full"}; + String[] folders = {File.separator + "core", File.separator + "full"}; for (String dir : folders) { BufferedReader in = new BufferedReader( new FileReader(path[0] + dir - + "/allclasses-noframe.html")); + + File.separator + "allclasses-noframe.html")); String str; while ((str = in.readLine()) != null) { find = str.contains(className);