You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/07/17 10:23:19 UTC
svn commit: r1504044 [8/12] - in /uima/sandbox/ruta/trunk/ruta-ep-ide: ./
schema/ src/ src/main/ src/main/antlr3/ src/main/antlr3/org/
src/main/antlr3/org/apache/ src/main/antlr3/org/apache/uima/
src/main/antlr3/org/apache/uima/ruta/ src/main/antlr3/or...
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnKeywordOrFunction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnKeywordOrFunction.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnKeywordOrFunction.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnKeywordOrFunction.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.uima.ruta.ide.core.codeassist;
+
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.references.SimpleReference;
+
+public class SelectionOnKeywordOrFunction extends SimpleReference {
+ private ASTNode originalNode;
+
+ public SelectionOnKeywordOrFunction(String completionToken, ASTNode completionNode, ASTNode node) {
+ super(completionNode.sourceStart(), completionNode.sourceEnd(), completionToken);
+ this.originalNode = node;
+ }
+
+ public ASTNode getOriginalNode() {
+ return this.originalNode;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnNode.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnNode.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnNode.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/SelectionOnNode.java Wed Jul 17 08:23:15 2013
@@ -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.uima.ruta.ide.core.codeassist;
+
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.references.SimpleReference;
+
+public class SelectionOnNode extends SimpleReference {
+ private ASTNode node;
+
+ private int position;
+
+ public SelectionOnNode(ASTNode token) {
+ super(token.sourceStart(), token.sourceEnd(), "");
+ this.node = token;
+ }
+
+ public ASTNode getNode() {
+ return this.node;
+ }
+
+ public void setPosition(int position) {
+ this.position = position;
+ }
+
+ public int getPosition() {
+ return this.position;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/TMAutoCompletionToolkit.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/TMAutoCompletionToolkit.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/TMAutoCompletionToolkit.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/codeassist/TMAutoCompletionToolkit.java Wed Jul 17 08:23:15 2013
@@ -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.uima.ruta.ide.core.codeassist;
+
+public class TMAutoCompletionToolkit {
+
+ private int wordOffset;
+
+ private int currentOffset;
+
+ private int relativeReplacementStart;
+
+ private String wordPrefix;
+
+ public TMAutoCompletionToolkit(String text, int offset) {
+ this.currentOffset = offset;
+ wordOffset = getWordOffset(text, offset) + 1;
+ wordPrefix = text.substring(wordOffset, offset);
+ relativeReplacementStart = offset - wordOffset;
+
+ }
+
+ private int getWordOffset(String text, int offset) {
+ for (int i = offset - 1; i > 0; i--) {
+ switch (text.charAt(i)) {
+ case ' ': {
+ return i;
+ }
+ case '\n': {
+ return i;
+ }
+ case '\r': {
+ return i;
+ }
+ case '\t': {
+ return i;
+ }
+ case '[': {
+ return i;
+ }
+ case ']': {
+ return i;
+ }
+ case '(': {
+ return i;
+ }
+ case ')': {
+ return i;
+ }
+ case '{': {
+ return i;
+ }
+ case '}': {
+ return i;
+ }
+ case ',': {
+ return i;
+ }
+ case ';': {
+ return i;
+ }
+ }
+ }
+ return -1;
+ }
+
+ public int getWordOffset() {
+ return this.wordOffset;
+ }
+
+ public int getCurrentOffset() {
+ return this.currentOffset;
+ }
+
+ public int getRelativeReplacementStart() {
+ return relativeReplacementStart;
+ }
+
+ public String getWordPrefix() {
+ return wordPrefix;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ICompletionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ICompletionExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ICompletionExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ICompletionExtension.java Wed Jul 17 08:23:15 2013
@@ -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.uima.ruta.ide.core.extensions;
+
+import java.util.Set;
+
+import org.apache.uima.ruta.ide.core.codeassist.CompletionOnKeywordArgumentOrFunctionArgument;
+import org.apache.uima.ruta.ide.core.codeassist.CompletionOnKeywordOrFunction;
+import org.apache.uima.ruta.ide.core.codeassist.RutaCompletionEngine;
+import org.apache.uima.ruta.ide.core.codeassist.RutaCompletionParser;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.statements.Statement;
+import org.eclipse.dltk.core.CompletionRequestor;
+
+public interface ICompletionExtension {
+ boolean visit(Expression s, RutaCompletionParser parser, int position);
+
+ boolean visit(Statement s, RutaCompletionParser parser, int position);
+
+ void completeOnKeywordOrFunction(CompletionOnKeywordOrFunction key, ASTNode astNodeParent,
+ RutaCompletionEngine engine);
+
+ void completeOnKeywordArgumentsOne(String name,
+ CompletionOnKeywordArgumentOrFunctionArgument compl, Set methodNames, Statement st,
+ RutaCompletionEngine tmCompletionEngine);
+
+ void setRequestor(CompletionRequestor requestor);
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEActionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEActionExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEActionExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEActionExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,24 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+public interface IIDEActionExtension extends IRutaExtension {
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEBooleanFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEBooleanFunctionExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEBooleanFunctionExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEBooleanFunctionExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,24 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+public interface IIDEBooleanFunctionExtension extends IRutaExtension {
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEConditionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEConditionExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEConditionExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEConditionExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,24 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+public interface IIDEConditionExtension extends IRutaExtension {
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDENumberFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDENumberFunctionExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDENumberFunctionExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDENumberFunctionExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,24 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+public interface IIDENumberFunctionExtension extends IRutaExtension {
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEStringFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEStringFunctionExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEStringFunctionExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDEStringFunctionExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,24 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+public interface IIDEStringFunctionExtension extends IRutaExtension {
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDETypeFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDETypeFunctionExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDETypeFunctionExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IIDETypeFunctionExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,24 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+public interface IIDETypeFunctionExtension extends IRutaExtension {
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMatchLocatorExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMatchLocatorExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMatchLocatorExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMatchLocatorExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,30 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.core.search.matching.PatternLocator;
+import org.eclipse.dltk.internal.core.search.matching.MatchingNodeSet;
+
+public interface IMatchLocatorExtension {
+ // This is match locator feature extension
+ public void visitGeneral(ASTNode node, PatternLocator locator, MatchingNodeSet nodeSet);
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMixinBuildVisitorExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMixinBuildVisitorExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMixinBuildVisitorExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IMixinBuildVisitorExtension.java Wed Jul 17 08:23:15 2013
@@ -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.uima.ruta.ide.core.extensions;
+
+public interface IMixinBuildVisitorExtension {
+ //
+ // /**
+ // * If method return true, then other checks will not be provided and
+ // * original visit will return true
+ // */
+ // boolean visit(MethodDeclaration s, RutaMixinBuildVisitor original);
+ //
+ // /**
+ // * If method return true, then other checks will not be provided and
+ // * original visit will return true
+ // */
+ // boolean visit(TypeDeclaration s, RutaMixinBuildVisitor
+ // tmMixinBuildVisitor);
+ //
+ // /**
+ // * If method return true, then other checks will not be provided and
+ // * original visit will return <b>false</b>
+ // */
+ // boolean visit(Statement s, RutaMixinBuildVisitor
+ // tmMixinBuildVisitor);
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaCheckerProblemFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaCheckerProblemFactory.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaCheckerProblemFactory.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaCheckerProblemFactory.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,56 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+import java.util.List;
+
+import org.apache.uima.ruta.ide.parser.ast.RutaAbstractDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaAction;
+import org.apache.uima.ruta.ide.parser.ast.RutaCondition;
+import org.apache.uima.ruta.ide.parser.ast.RutaFeatureDeclaration;
+import org.apache.uima.ruta.ide.parser.ast.RutaFunction;
+import org.apache.uima.ruta.ide.parser.ast.RutaVariableReference;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.compiler.problem.IProblem;
+import org.eclipse.dltk.compiler.problem.ProblemSeverity;
+import org.eclipse.dltk.core.ISourceModule;
+
+public interface IRutaCheckerProblemFactory {
+
+ IProblem createIdConflictsWithVariableProblem(RutaAbstractDeclaration varRef);
+ IProblem createIdConflictsWithTypeProblem(RutaAbstractDeclaration varRef);
+ IProblem createFileNotFoundProblem(ASTNode node, String localPath);
+ IProblem createFileNotFoundProblem(ASTNode fileNode);
+ IProblem createDuplicateShortNameInImported(ASTNode node, String localPath,
+ List<String> checkDuplicateShortNames, ProblemSeverity severity);
+ IProblem createDuplicateShortName(RutaAbstractDeclaration var, ProblemSeverity severity) ;
+ IProblem createXMLProblem(ASTNode node, String localPath);
+ IProblem createTypeProblem(RutaVariableReference ref, ISourceModule currentFile);
+ IProblem createUnknownFeatureTypeProblem(RutaFeatureDeclaration var);
+ IProblem createUnknownFeatureProblem(Expression var, String matchedType);
+ IProblem createWrongArgumentTypeProblem(Expression was, String expected);
+ IProblem createInheritenceFinalProblem(RutaVariableReference parent);
+ IProblem createUnknownConditionProblem(RutaCondition cond);
+ IProblem createUnknownActionProblem(RutaAction action);
+ IProblem createWrongNumberOfArgumentsProblem(String name, Expression element, int expected);
+ IProblem createUnknownFunctionProblem(RutaFunction f);
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,33 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+import org.antlr.runtime.RecognitionException;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.compiler.problem.IProblemReporter;
+
+public interface IRutaExtension {
+
+ String[] getKnownExtensions();
+
+ boolean checkSyntax(Expression element, IRutaCheckerProblemFactory problemFactory,
+ IProblemReporter rep) throws RecognitionException;
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaLanguageExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaLanguageExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaLanguageExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/IRutaLanguageExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,34 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+public interface IRutaLanguageExtension {
+ String getName();
+
+ ISourceElementRequestVisitorExtension createSourceElementRequestVisitorExtension();
+
+ IMixinBuildVisitorExtension createMixinBuildVisitorExtension();
+
+ IMatchLocatorExtension createMatchLocatorExtension();
+
+ ICompletionExtension createCompletionExtension();
+
+ ISelectionExtension createSelectionExtension();
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISelectionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISelectionExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISelectionExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISelectionExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,35 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+import org.apache.uima.ruta.ide.core.codeassist.RutaSelectionEngine;
+import org.apache.uima.ruta.ide.core.codeassist.SelectionOnKeywordOrFunction;
+import org.eclipse.dltk.ast.ASTNode;
+
+public interface ISelectionExtension {
+
+ void selectionOnKeywordOrFunction(SelectionOnKeywordOrFunction key,
+ RutaSelectionEngine tmSelectionEngine);
+
+ void selectionOnAST(ASTNode node, RutaSelectionEngine tmSelectionEngine);
+
+ void selectionOnNode(ASTNode node, int position, RutaSelectionEngine tmSelectionEngine);
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISourceElementRequestVisitorExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISourceElementRequestVisitorExtension.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISourceElementRequestVisitorExtension.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/ISourceElementRequestVisitorExtension.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,40 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+import org.eclipse.dltk.ast.declarations.Declaration;
+
+public interface ISourceElementRequestVisitorExtension {
+
+ int getModifiers(Declaration s);
+
+ // boolean visit(Statement statement, RutaSourceElementRequestVisitor
+ // original);
+ //
+ // boolean extendedExitRequired(MethodDeclaration method,
+ // RutaSourceElementRequestVisitor tmSourceElementRequestVisitor);
+ //
+ // ExitFromType getExitExtended(MethodDeclaration method,
+ // RutaSourceElementRequestVisitor tmSourceElementRequestVisitor);
+ //
+ // ExitFromType processField(FieldDeclaration decl,
+ // RutaSourceElementRequestVisitor tmSourceElementRequestVisitor);
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/RutaExternalFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/RutaExternalFactory.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/RutaExternalFactory.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/extensions/RutaExternalFactory.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,69 @@
+/*
+ * 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.uima.ruta.ide.core.extensions;
+
+import java.util.List;
+
+import org.antlr.runtime.RecognitionException;
+import org.antlr.runtime.Token;
+import org.apache.uima.ruta.ide.parser.ast.ActionFactory;
+import org.apache.uima.ruta.ide.parser.ast.ConditionFactory;
+import org.apache.uima.ruta.ide.parser.ast.ExpressionFactory;
+import org.apache.uima.ruta.ide.parser.ast.RutaAction;
+import org.apache.uima.ruta.ide.parser.ast.RutaCondition;
+import org.eclipse.dltk.ast.expressions.Expression;
+
+public class RutaExternalFactory {
+
+ public RutaExternalFactory() {
+ super();
+ }
+
+ public RutaCondition createExternalCondition(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ConditionFactory.createCondition(id, args);
+ }
+
+ public RutaAction createExternalAction(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ActionFactory.createAction(id, args);
+ }
+
+ public Expression createExternalNumberFunction(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ExpressionFactory.createNumberFunction(id, args);
+ }
+
+ public Expression createExternalBooleanFunction(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ExpressionFactory.createBooleanFunction(id, args);
+ }
+
+ public Expression createExternalStringFunction(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ExpressionFactory.createStringFunction(id, args);
+ }
+
+ public Expression createExternalTypeFunction(Token id, List<Expression> args)
+ throws RecognitionException {
+ return ExpressionFactory.createTypeFunction(id, args);
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/DLTKRutaHelper.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/DLTKRutaHelper.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/DLTKRutaHelper.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/DLTKRutaHelper.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,416 @@
+/*
+ * 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.uima.ruta.ide.core.packages;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.uima.ruta.engine.RutaEngine;
+import org.apache.uima.ruta.ide.RutaIdeCorePlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.environment.IDeployment;
+import org.eclipse.dltk.core.environment.IExecutionEnvironment;
+import org.eclipse.dltk.core.environment.IFileHandle;
+import org.eclipse.dltk.launching.EnvironmentVariable;
+import org.eclipse.dltk.launching.IInterpreterInstall;
+import org.eclipse.dltk.launching.InterpreterConfig;
+import org.eclipse.dltk.launching.ScriptLaunchUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class DLTKRutaHelper {
+
+ private static final String DLTK_TM = "scripts/dltk" + RutaEngine.SCRIPT_FILE_EXTENSION; //$NON-NLS-1$
+
+ public static List getScriptOutput(InputStream stream) {
+ final List elements = new ArrayList();
+ final BufferedReader input = new BufferedReader(new InputStreamReader(stream));
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ try {
+ while (true) {
+ String line;
+ line = input.readLine();
+ if (line == null) {
+ break;
+ }
+ elements.add(line);
+ }
+ } catch (IOException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ }
+ });
+ t.start();
+ try {
+ t.join(50000);// No more then 50 seconds
+ } catch (InterruptedException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ return elements;
+ }
+
+ private static List deployExecute(IExecutionEnvironment exeEnv, String installLocation,
+ String[] arguments, EnvironmentVariable[] env) {
+ IDeployment deployment = exeEnv.createDeployment();
+ IFileHandle script = deploy(deployment);
+ if (script == null) {
+ return null;
+ }
+
+ IFileHandle workingDir = script.getParent();
+ InterpreterConfig config = ScriptLaunchUtil.createInterpreterConfig(exeEnv, script, workingDir,
+ env);
+ // For wish
+ config.removeEnvVar("DISPLAY"); //$NON-NLS-1$
+
+ if (arguments != null) {
+ config.addScriptArgs(arguments);
+ }
+
+ Process process = null;
+ try {
+ process = ScriptLaunchUtil.runScriptWithInterpreter(exeEnv, installLocation, config);
+ } catch (CoreException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ if (process == null) {
+ return new ArrayList();
+ }
+ List output = getScriptOutput(process.getInputStream());
+ getScriptOutput(process.getErrorStream());
+ process.destroy();
+ deployment.dispose();
+ return output;
+ }
+
+ private static IFileHandle deploy(IDeployment deployment) {
+ IFileHandle script;
+ try {
+ IPath path = deployment.add(RutaIdeCorePlugin.getDefault().getBundle(), DLTK_TM);
+ script = deployment.getFile(path);
+ } catch (IOException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+ return script;
+ }
+
+ public static String[] getDefaultPath(IFileHandle installLocation,
+ EnvironmentVariable[] environment) {
+ // Process process = deployExecute(installLocation.getAbsolutePath(),
+ // new String[] { "get-paths" }, environment);
+ // List content = getScriptOutput(process);
+ // String[] autoPath = getAutoPath(content);
+ // for (int i = 0; i < autoPath.length; i++) {
+ // Path p = new Path(autoPath[i]);
+ // if (p.lastSegment().startsWith("tcl8.")) {
+ // return new String[] { autoPath[i] };
+ // }
+ // }
+ // process.destroy();
+ return new String[0];
+ // return autoPath;
+ }
+
+ public static RutaPackage[] getSrcs(IExecutionEnvironment exeEnv, IFileHandle installLocation,
+ EnvironmentVariable[] environment, String packageName) {
+ IDeployment deployment = exeEnv.createDeployment();
+ IFileHandle script = deploy(deployment);
+ if (script == null) {
+ return null;
+ }
+
+ IFileHandle workingDir = script.getParent();
+ InterpreterConfig config = ScriptLaunchUtil.createInterpreterConfig(exeEnv, script, workingDir,
+ environment);
+ String names = packageName;
+ ByteArrayInputStream bais = new ByteArrayInputStream(names.getBytes());
+ IPath packagesPath = null;
+ try {
+ packagesPath = deployment.add(bais, "packages.txt"); //$NON-NLS-1$
+ } catch (IOException e1) {
+ if (DLTKCore.DEBUG) {
+ e1.printStackTrace();
+ }
+ return null;
+ }
+ IFileHandle file = deployment.getFile(packagesPath);
+ // For wish
+ config.removeEnvVar("DISPLAY"); //$NON-NLS-1$
+ String[] arguments = new String[] { "get-srcs", "-fpkgs", //$NON-NLS-1$ //$NON-NLS-2$
+ file.toOSString() };
+
+ config.addScriptArgs(arguments);
+
+ Process process = null;
+ try {
+ process = ScriptLaunchUtil.runScriptWithInterpreter(exeEnv, installLocation.toOSString(),
+ config);
+ } catch (CoreException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ if (process == null) {
+ return null;
+ }
+ List output = getScriptOutput(process.getInputStream());
+ getScriptOutput(process.getErrorStream());
+ process.destroy();
+ deployment.dispose();
+ return getPackagePath(output);
+ }
+
+ private static boolean isElementName(Node nde, String name) {
+ if (nde != null) {
+ if (nde.getNodeType() == Node.ELEMENT_NODE) {
+ if (name.equalsIgnoreCase(nde.getNodeName())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static String[] getAutoPath(List content) {
+ String text = getXMLContent(content);
+ Document document = getDocument(text);
+
+ Set paths = new HashSet();
+ if (document != null) {
+ Element element = document.getDocumentElement();
+ NodeList childNodes = element.getChildNodes();
+ int len = childNodes.getLength();
+ for (int i = 0; i < len; i++) {
+ Node nde = childNodes.item(i);
+ if (isElementName(nde, "path")) { //$NON-NLS-1$
+ Element el = (Element) nde;
+ String path = el.getAttribute("name"); //$NON-NLS-1$
+ if (path.length() > 0) {
+ paths.add(path);
+ }
+ }
+ }
+ }
+ return (String[]) paths.toArray(new String[paths.size()]);
+ }
+
+ public static class RutaPackage {
+ private String name;
+
+ private Set paths = new HashSet();
+
+ private Set dependencies = new HashSet();
+
+ public RutaPackage(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ RutaPackage other = (RutaPackage) obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Set getPaths() {
+ return paths;
+ }
+
+ public void setPaths(Set paths) {
+ this.paths = paths;
+ }
+
+ public Set getDependencies() {
+ return dependencies;
+ }
+
+ public void setDependencies(Set dependencies) {
+ this.dependencies = dependencies;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer(128);
+ sb.append("RutaPackage"); //$NON-NLS-1$
+ sb.append('{');
+ sb.append("name=").append(name); //$NON-NLS-1$
+ sb.append(' ');
+ sb.append("paths=").append(paths); //$NON-NLS-1$
+ sb.append(' ');
+ sb.append("dependencies=").append(dependencies); //$NON-NLS-1$
+ sb.append('}');
+ return sb.toString();
+ }
+ };
+
+ public static RutaPackage[] getPackagePath(List content) {
+ String text = getXMLContent(content);
+ Document document = getDocument(text);
+
+ Map packages = new HashMap();
+ if (document != null) {
+ Element element = document.getDocumentElement();
+ NodeList childNodes = element.getChildNodes();
+ int len = childNodes.getLength();
+ for (int i = 0; i < len; i++) {
+ Node nde = childNodes.item(i);
+ if (isElementName(nde, "path")) { //$NON-NLS-1$
+ Element el = (Element) nde;
+ NodeList elChilds = el.getChildNodes();
+ for (int j = 0; j < elChilds.getLength(); j++) {
+ Node pkgNde = elChilds.item(j);
+ if (isElementName(pkgNde, "package")) { //$NON-NLS-1$
+ populatePackage(packages, pkgNde);
+ }
+ }
+ }
+ }
+ }
+ return (RutaPackage[]) packages.values().toArray(new RutaPackage[packages.size()]);
+ }
+
+ private static void populatePackage(Map packages, Node pkgNde) {
+ Element pkg = (Element) pkgNde;
+ String pkgName = pkg.getAttribute("name"); //$NON-NLS-1$
+ RutaPackage tclPackage = new RutaPackage(pkgName);
+ if (packages.containsKey(tclPackage)) {
+ tclPackage = (RutaPackage) packages.get(tclPackage);
+ } else {
+ packages.put(tclPackage, tclPackage);
+ }
+ NodeList childs = pkg.getChildNodes();
+ for (int i = 0; i < childs.getLength(); i++) {
+ Node nde = childs.item(i);
+ if (isElementName(nde, "source")) { //$NON-NLS-1$
+ Element el = (Element) nde;
+ String name = el.getAttribute("name"); //$NON-NLS-1$
+ IPath path = new Path(name).removeLastSegments(1);
+ tclPackage.getPaths().add(path);
+ } else if (isElementName(nde, "require")) { //$NON-NLS-1$
+ Element el = (Element) nde;
+ String name = el.getAttribute("name"); //$NON-NLS-1$
+ tclPackage.getDependencies().add(name);
+ }
+ }
+ }
+
+ private static Document getDocument(String text) {
+ try {
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ parser.setErrorHandler(new DefaultHandler());
+ Document document = parser.parse(new ByteArrayInputStream(text.getBytes()));
+ return document;
+ } catch (IOException e) {
+
+ } catch (ParserConfigurationException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ } catch (SAXException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ return null;
+ }
+
+ private static String getXMLContent(List content) {
+ StringBuffer newList = new StringBuffer();
+ if (content != null) {
+ for (Iterator iterator = content.iterator(); iterator.hasNext();) {
+ String line = (String) iterator.next();
+ if (line.trim().startsWith("<")) { //$NON-NLS-1$
+ newList.append(line).append("\n"); //$NON-NLS-1$
+ }
+ }
+ }
+ return newList.toString();
+ }
+
+ public static Set getPackages(IInterpreterInstall install) {
+ IExecutionEnvironment exeEnv = install.getExecEnvironment();
+ List content = deployExecute(exeEnv, install.getInstallLocation().toOSString(),
+ new String[] { "get-pkgs" }, install //$NON-NLS-1$
+ .getEnvironmentVariables());
+ Set packages = new HashSet();
+ RutaPackage[] packagePath = getPackagePath(content);
+ for (int i = 0; i < packagePath.length; i++) {
+ packages.add(packagePath[i].getName());
+ }
+ return packages;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/Messages.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/Messages.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/Messages.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/Messages.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,43 @@
+/*
+ * 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.uima.ruta.ide.core.packages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.apache.uima.ruta.ide.core.packages.messages"; //$NON-NLS-1$
+
+ public static String RutaCheckBuilder_interpreterNotFound;
+
+ public static String RutaCheckBuilder_processing;
+
+ public static String RutaCheckBuilder_retrievePackages;
+
+ public static String RutaCheckBuilder_unknownPackage;
+
+ public static String RutaCheckBuilder_unresolvedDependencies;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/PackagesManager.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/PackagesManager.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/PackagesManager.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/PackagesManager.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,618 @@
+/*
+ * 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.uima.ruta.ide.core.packages;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.uima.ruta.ide.RutaIdeCorePlugin;
+import org.apache.uima.ruta.ide.core.packages.DLTKRutaHelper.RutaPackage;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.launching.IInterpreterInstall;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * This class persistently holds all required information for specified interpreter package to path
+ * associations.
+ */
+public class PackagesManager {
+ private static final String DEPENDENCY_TAG = "dependency"; //$NON-NLS-1$
+
+ private static final String INTERPRETER_TAG = "interpreter"; //$NON-NLS-1$
+
+ private static final String VALUE_ATTR = "value"; //$NON-NLS-1$
+
+ private static final String PACKAGES_FILE = "packages.txt"; //$NON-NLS-1$
+
+ private static final String PACKAGES_TAG = "packages"; //$NON-NLS-1$
+
+ private static final String PACKAGE_TAG = "package"; //$NON-NLS-1$
+
+ private static final String INTERPRETER_ATTR = INTERPRETER_TAG;
+
+ private static final String NAME_ATTR = "name"; //$NON-NLS-1$
+
+ private static final String PATH_TAG = "path"; //$NON-NLS-1$
+
+ private static PackagesManager manager;
+
+ /**
+ * Contains association of PackageKey to PackageInformation
+ */
+ private Map packages = new HashMap();
+
+ /**
+ * Contains set of interpreter to list of packages association.
+ */
+ private Map interpreterToPackages = new HashMap();
+
+ private Map packsWithDeps = new HashMap();
+
+ public static PackagesManager getInstance() {
+ if (manager == null) {
+ manager = new PackagesManager();
+ }
+ return manager;
+ }
+
+ private PackagesManager() {
+ initialize();
+ }
+
+ private static class PackageKey {
+ private String packageName;
+
+ private String interpreterPath;
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((interpreterPath == null) ? 0 : interpreterPath.hashCode());
+ result = prime * result + ((packageName == null) ? 0 : packageName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ PackageKey other = (PackageKey) obj;
+ if (interpreterPath == null) {
+ if (other.interpreterPath != null)
+ return false;
+ } else if (!interpreterPath.equals(other.interpreterPath))
+ return false;
+ if (packageName == null) {
+ if (other.packageName != null)
+ return false;
+ } else if (!packageName.equals(other.packageName))
+ return false;
+ return true;
+ }
+
+ public String getPackageName() {
+ return packageName;
+ }
+
+ public void setPackageName(String packageName) {
+ this.packageName = packageName;
+ }
+
+ public String getInterpreterPath() {
+ return interpreterPath;
+ }
+
+ public void setInterpreterPath(String interpreterPath) {
+ this.interpreterPath = interpreterPath;
+ }
+ }
+
+ public static class PackageInformation {
+ private final Set paths = new HashSet();
+
+ private final Set dependencies = new HashSet();
+
+ public Set getPaths() {
+ return paths;
+ }
+
+ public Set getDependencies() {
+ return dependencies;
+ }
+ }
+
+ private void initialize() {
+ IPath packagesPath = RutaIdeCorePlugin.getDefault().getStateLocation().append(PACKAGES_FILE);
+ File packagesFile = packagesPath.toFile();
+ if (packagesFile.exists()) {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder;
+ try {
+ builder = factory.newDocumentBuilder();
+ Document document = builder.parse(new BufferedInputStream(
+ new FileInputStream(packagesFile), 2048));
+ populate(document.getDocumentElement());
+ } catch (ParserConfigurationException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ } catch (FileNotFoundException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ } catch (SAXException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ } catch (IOException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private void save() {
+ IPath packagesPath = RutaIdeCorePlugin.getDefault().getStateLocation().append(PACKAGES_FILE);
+ File packagesFile = packagesPath.toFile();
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder;
+ try {
+ builder = factory.newDocumentBuilder();
+ Document document = builder.newDocument();
+ save(document);
+
+ FileOutputStream fos = new FileOutputStream(packagesFile, false);
+ BufferedOutputStream bos = new BufferedOutputStream(fos, 2048);
+
+ TransformerFactory serFactory = TransformerFactory.newInstance();
+ Transformer transformer = serFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+
+ DOMSource source = new DOMSource(document);
+ StreamResult outputTarget = new StreamResult(bos);
+ transformer.transform(source, outputTarget);
+ bos.close();
+ fos.close();
+
+ } catch (ParserConfigurationException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ } catch (FileNotFoundException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ } catch (IOException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ } catch (TransformerException e) {
+ if (DLTKCore.DEBUG) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private synchronized void save(Document doc) {
+ Element packagesElement = doc.createElement(PACKAGES_TAG);
+ doc.appendChild(packagesElement);
+ for (Iterator iterator = this.packages.keySet().iterator(); iterator.hasNext();) {
+ PackageKey key = (PackageKey) iterator.next();
+
+ Element packageElement = doc.createElement(PACKAGE_TAG);
+ packageElement.setAttribute(NAME_ATTR, key.getPackageName());
+ packageElement.setAttribute(INTERPRETER_ATTR, key.getInterpreterPath());
+
+ PackageInformation info = (PackageInformation) this.packages.get(key);
+ Set paths = info.getPaths();
+ for (Iterator iterator2 = paths.iterator(); iterator2.hasNext();) {
+ IPath path = (IPath) iterator2.next();
+ Element pathElement = doc.createElement(PATH_TAG);
+ pathElement.setAttribute(VALUE_ATTR, path.toOSString());
+ packageElement.appendChild(pathElement);
+ }
+ Set deps = info.getDependencies();
+ for (Iterator iterator2 = deps.iterator(); iterator2.hasNext();) {
+ String pkgName = (String) iterator2.next();
+ Element pkgElement = doc.createElement(DEPENDENCY_TAG);
+ pkgElement.setAttribute(NAME_ATTR, pkgName);
+ packageElement.appendChild(pkgElement);
+ }
+ packagesElement.appendChild(packageElement);
+ }
+ for (Iterator iterator = this.interpreterToPackages.keySet().iterator(); iterator.hasNext();) {
+ String interpreter = (String) iterator.next();
+
+ Element interpreterElement = doc.createElement(INTERPRETER_TAG);
+ interpreterElement.setAttribute(NAME_ATTR, interpreter);
+ Set pkgs = (Set) this.interpreterToPackages.get(interpreter);
+ for (Iterator iterator2 = pkgs.iterator(); iterator2.hasNext();) {
+ String pkgName = (String) iterator2.next();
+ Element pathElement = doc.createElement(PACKAGE_TAG);
+ pathElement.setAttribute(VALUE_ATTR, pkgName);
+ interpreterElement.appendChild(pathElement);
+ }
+ packagesElement.appendChild(interpreterElement);
+ }
+ }
+
+ private synchronized void populate(Element documentElement) {
+ NodeList childNodes = documentElement.getChildNodes();
+ int length = childNodes.getLength();
+ for (int i = 0; i < length; i++) {
+ Node child = childNodes.item(i);
+ if (child.getNodeType() == Node.ELEMENT_NODE) {
+ if (child.getNodeName().equalsIgnoreCase(PACKAGE_TAG)) {
+ Element e = (Element) child;
+ String packageName = e.getAttribute(NAME_ATTR);
+ String interpreter = e.getAttribute(INTERPRETER_ATTR);
+ PackageInformation packageInfo = new PackageInformation();
+ NodeList childrens = e.getChildNodes();
+ for (int j = 0; j < childrens.getLength(); j++) {
+ Node path = childrens.item(j);
+ if (path.getNodeType() == Node.ELEMENT_NODE) {
+ if (path.getNodeName().equalsIgnoreCase(PATH_TAG)) {
+ String pathValue = ((Element) path).getAttribute(VALUE_ATTR);
+ packageInfo.getPaths().add(new Path(pathValue));
+ } else if (path.getNodeName().equalsIgnoreCase(DEPENDENCY_TAG)) {
+ String pkgName = ((Element) path).getAttribute(NAME_ATTR);
+ packageInfo.getDependencies().add(pkgName);
+ }
+ }
+ }
+ this.packages.put(makeKey(packageName, interpreter), packageInfo);
+ } else if (child.getNodeName().equalsIgnoreCase(INTERPRETER_TAG)) {
+ Element e = (Element) child;
+ String interpreter = e.getAttribute(NAME_ATTR);
+ NodeList paths = e.getChildNodes();
+ Set packagesSet = new HashSet();
+ for (int j = 0; j < paths.getLength(); j++) {
+ Node packageNode = paths.item(j);
+ if (packageNode.getNodeType() == Node.ELEMENT_NODE) {
+ if (packageNode.getNodeName().equalsIgnoreCase(PACKAGE_TAG)) {
+ String packageNameValue = ((Element) packageNode).getAttribute(VALUE_ATTR);
+ packagesSet.add(packageNameValue);
+ }
+ }
+ }
+ this.interpreterToPackages.put(interpreter, packagesSet);
+ }
+ }
+ }
+ }
+
+ private PackageKey makeKey(String packageName, String interpreter) {
+ PackageKey key = new PackageKey();
+ key.setPackageName(packageName);
+ key.setInterpreterPath(interpreter);
+ return key;
+ }
+
+ /**
+ * Return paths specific only for selected package.
+ */
+ public synchronized IPath[] getPathsForPackage(IInterpreterInstall install, String packageName) {
+ PackageKey key = makeKey(packageName, getInterpreterKey(install));
+ if (this.packages.containsKey(key)) {
+ PackageInformation info = (PackageInformation) this.packages.get(key);
+ Set els = info.getPaths();
+ return (IPath[]) els.toArray(new IPath[els.size()]);
+ }
+ // Retrieve paths from interpreter with all dependencies.
+ RutaPackage[] srcs = DLTKRutaHelper.getSrcs(install.getExecEnvironment(),
+ install.getInstallLocation(), install.getEnvironmentVariables(), packageName);
+
+ PackageInformation resultInfo = null;
+ for (int i = 0; i < srcs.length; i++) {
+ Set paths2 = srcs[i].getPaths();
+ PackageKey okey = makeKey(srcs[i].getName(), getInterpreterKey(install));
+ PackageInformation info;
+ if (this.packages.containsKey(okey)) {
+ info = (PackageInformation) this.packages.get(okey);
+ } else {
+ info = new PackageInformation();
+ }
+ info.getPaths().addAll(paths2);
+ info.getDependencies().addAll(srcs[i].getDependencies());
+ this.packages.put(okey, info);
+ if (okey.equals(key)) {
+ resultInfo = info;
+ }
+ }
+ // Follow all dependencies
+ if (resultInfo == null) {
+ this.packages.put(key, new PackageInformation());
+ return new IPath[0];
+ }
+
+ Set resultPaths = new HashSet();
+ resultPaths.addAll(resultInfo.getPaths());
+
+ save();
+ return (IPath[]) resultPaths.toArray(new IPath[resultPaths.size()]);
+ }
+
+ public synchronized Map getDependencies(String pkgName, IInterpreterInstall install) {
+ Set checkedPackages = new HashSet();
+ Map packagesSet = new HashMap();
+ PackageKey key = makeKey(pkgName, install);
+ PackageInformation info = (PackageInformation) this.packages.get(key);
+ if (info != null) {
+ traverseDependencies(packagesSet, checkedPackages, info, install);
+ }
+ return packagesSet;
+ }
+
+ private PackageKey makeKey(String pkgName, IInterpreterInstall install) {
+ return makeKey(pkgName, getInterpreterKey(install));
+ }
+
+ private synchronized void traverseDependencies(Map packagesSet, Set checkedPackages,
+ PackageInformation resultInfo, IInterpreterInstall install) {
+ Set dependencies = resultInfo.getDependencies();
+ for (Iterator iterator = dependencies.iterator(); iterator.hasNext();) {
+ String pkgName = (String) iterator.next();
+ if (!checkedPackages.contains(pkgName)) {
+ checkedPackages.add(pkgName);
+ PackageKey pkgKey = makeKey(pkgName, getInterpreterKey(install));
+ if (this.packages.containsKey(pkgKey)) {
+ PackageInformation depInfo = (PackageInformation) this.packages.get(pkgKey);
+ packagesSet.put(pkgName, depInfo);
+ traverseDependencies(packagesSet, checkedPackages, depInfo, install);
+ }
+ }
+ }
+ }
+
+ public synchronized Set getPackageNames(IInterpreterInstall install) {
+ String key = getInterpreterKey(install);
+ if (this.interpreterToPackages.containsKey(key)) {
+ Set set = (Set) this.interpreterToPackages.get(key);
+ return set;
+ }
+ // Evaluate
+ Set packs = DLTKRutaHelper.getPackages(install);
+ this.interpreterToPackages.put(key, packs);
+ save();
+ return packs;
+ }
+
+ private String getInterpreterKey(IInterpreterInstall install) {
+ if (install == null) {
+ return "";
+ }
+ return install.getInstallLocation().toOSString() + ":" //$NON-NLS-1$
+ + install.getEnvironment().getId();
+ }
+
+ private String getInterpreterProjectKey(IInterpreterInstall install, String projectName) {
+ return "internal|||" + projectName + "|||" //$NON-NLS-1$ //$NON-NLS-2$
+ + getInterpreterKey(install);
+ }
+
+ public Set getInternalPackageNames(IInterpreterInstall install, IScriptProject project) {
+ return getInternalPackageNames(install, project.getElementName());
+ }
+
+ public Set getInternalPackageNames(IInterpreterInstall install, IProject project) {
+ return getInternalPackageNames(install, project.getName());
+ }
+
+ public synchronized Set getInternalPackageNames(IInterpreterInstall install, String projectName) {
+ final String key = getInterpreterProjectKey(install, projectName);
+ if (this.interpreterToPackages.containsKey(key)) {
+ return (Set) this.interpreterToPackages.get(key);
+ }
+ return Collections.EMPTY_SET;
+ }
+
+ public synchronized void setInternalPackageNames(IInterpreterInstall install,
+ IScriptProject project, Set names) {
+ String key = getInterpreterProjectKey(install, project.getElementName());
+ // TODO compare and save only if there are changes
+ this.interpreterToPackages.put(key, new HashSet(names));
+ save();
+ }
+
+ /**
+ * Return all packages paths in one call.
+ */
+ public synchronized IPath[] getPathsForPackages(IInterpreterInstall install, Set packagesInBuild) {
+
+ StringBuffer buf = new StringBuffer();
+ String[] pkgs = (String[]) packagesInBuild.toArray(new String[packagesInBuild.size()]);
+ for (int i = 0; i < pkgs.length; i++) {
+ buf.append(pkgs[i]).append(" "); //$NON-NLS-1$
+ }
+ PackageKey key = makeKey(buf.toString(), getInterpreterKey(install));
+
+ if (this.packages.containsKey(key)) {
+ PackageInformation info = (PackageInformation) this.packages.get(key);
+ Set paths = info.getPaths();
+ return (IPath[]) paths.toArray(new IPath[paths.size()]);
+ }
+ // Retrieve paths from interpreter with all dependencies.
+ RutaPackage[] srcs = DLTKRutaHelper.getSrcs(install.getExecEnvironment(),
+ install.getInstallLocation(), install.getEnvironmentVariables(), buf.toString());
+ Set result = new HashSet();
+ if (srcs == null) {
+ return new IPath[0];
+ }
+ for (int i = 0; i < srcs.length; i++) {
+ Set paths2 = srcs[i].getPaths();
+ PackageKey okey = makeKey(srcs[i].getName(), getInterpreterKey(install));
+ PackageInformation info = null;
+ if (this.packages.containsKey(okey)) {
+ info = (PackageInformation) this.packages.get(okey);
+ } else {
+ info = new PackageInformation();
+ }
+ result.addAll(paths2);
+ info.getPaths().addAll(paths2);
+ info.getDependencies().addAll(srcs[i].getDependencies());
+ this.packages.put(okey, info);
+ }
+
+ PackageInformation info = new PackageInformation();
+ info.getPaths().addAll(result);
+ this.packages.put(key, info);
+
+ for (int i = 0; i < pkgs.length; i++) {
+ PackageKey lkey = makeKey(pkgs[i], getInterpreterKey(install));
+ if (!this.packages.containsKey(lkey)) {
+ this.packages.put(lkey, new PackageInformation());
+ }
+ }
+ save();
+
+ return (IPath[]) result.toArray(new IPath[result.size()]);
+ }
+
+ public IPath[] getAllPaths(String pkgName, IInterpreterInstall install) {
+ Set result = new HashSet();
+ IPath[] paths = this.getPathsForPackage(install, pkgName);
+ result.addAll(Arrays.asList(paths));
+ Map dependencies = this.getDependencies(pkgName, install);
+ for (Iterator iterator = dependencies.keySet().iterator(); iterator.hasNext();) {
+ String packageName = (String) iterator.next();
+ PackageInformation info = (PackageInformation) dependencies.get(packageName);
+ result.addAll(info.getPaths());
+ }
+ return (IPath[]) result.toArray(new IPath[result.size()]);
+ }
+
+ /**
+ * This method removes all information about specified interpreter.
+ *
+ * @param install
+ */
+ public synchronized void removeInterprterInfo(IInterpreterInstall install) {
+ // Remove interpreter to packages set
+ String interpreterPath = getInterpreterKey(install);
+ this.interpreterToPackages.remove(interpreterPath);
+ // Remove all values stored for interpreter packages
+ for (Iterator iterator = this.packages.keySet().iterator(); iterator.hasNext();) {
+ PackageKey key = (PackageKey) iterator.next();
+ String path = key.getInterpreterPath();
+ if (path.equals(interpreterPath)) {
+ iterator.remove();
+ }
+ }
+ save();
+ }
+
+ /**
+ * Clears all cached information.
+ */
+ public synchronized void clearCache() {
+ this.interpreterToPackages.clear();
+ this.packages.clear();
+ this.packsWithDeps.clear();
+ save();
+ }
+
+ public IPath[] getPathsForPackageWithDeps(IInterpreterInstall install, String name) {
+ Set result = new HashSet();
+ IPath[] paths = this.getPathsForPackage(install, name);
+ result.addAll(Arrays.asList(paths));
+
+ Map dependencies = getDependencies(name, install);
+ for (Iterator iterator = dependencies.keySet().iterator(); iterator.hasNext();) {
+ String pkgName = (String) iterator.next();
+ result.addAll(Arrays.asList(getPathsForPackage(install, pkgName)));
+ }
+ return (IPath[]) result.toArray(new IPath[result.size()]);
+ }
+
+ public IPath[] getPathsForPackagesWithDeps(IInterpreterInstall install, Set packagesSet) {
+
+ String pkey = makePKey(packagesSet);
+ if (this.packsWithDeps.containsKey(pkey)) {
+ return (IPath[]) this.packsWithDeps.get(pkey);
+ }
+
+ Set result = new HashSet();
+ IPath[] paths = this.getPathsForPackages(install, packagesSet);
+ result.addAll(Arrays.asList(paths));
+
+ for (Iterator jiterator = packagesSet.iterator(); jiterator.hasNext();) {
+ String name = (String) jiterator.next();
+ Map dependencies = getDependencies(name, install);
+ for (Iterator iterator = dependencies.keySet().iterator(); iterator.hasNext();) {
+ String pkgName = (String) iterator.next();
+ result.addAll(Arrays.asList(getPathsForPackage(install, pkgName)));
+ }
+ }
+ IPath[] array = (IPath[]) result.toArray(new IPath[result.size()]);
+ this.packsWithDeps.put(pkey, array);
+ return array;
+ }
+
+ private String makePKey(Set packagesSet) {
+ StringBuffer buffer = new StringBuffer();
+ List l = new ArrayList();
+ l.addAll(packagesSet);
+ Collections.sort(l);
+ for (Iterator iterator = l.iterator(); iterator.hasNext();) {
+ String object = (String) iterator.next();
+ buffer.append(object);
+ }
+ return buffer.toString();
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaBuildPathPackageCollector.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaBuildPathPackageCollector.java?rev=1504044&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaBuildPathPackageCollector.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide/src/main/java/org/apache/uima/ruta/ide/core/packages/RutaBuildPathPackageCollector.java Wed Jul 17 08:23:15 2013
@@ -0,0 +1,80 @@
+/*
+ * 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.uima.ruta.ide.core.packages;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.uima.ruta.ide.RutaIdeCorePlugin;
+import org.apache.uima.ruta.ide.parser.ast.RutaPackageDeclaration;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.statements.Statement;
+
+public class RutaBuildPathPackageCollector extends ASTVisitor {
+
+ private final List requireDirectives = new ArrayList();
+
+ private final Set packagesRequired = new HashSet();
+
+ private final Set packagesProvided = new HashSet();
+
+ public void process(ModuleDeclaration declaration) {
+ try {
+ declaration.traverse(this);
+ } catch (Exception e) {
+ RutaIdeCorePlugin.error(e);
+ }
+ }
+
+ @Override
+ public boolean visit(Statement s) throws Exception {
+ if (s instanceof RutaPackageDeclaration) {
+ final RutaPackageDeclaration pkg = (RutaPackageDeclaration) s;
+ packagesProvided.add(pkg.getName());
+ return false;
+ }
+ return super.visit(s);
+ }
+
+ /**
+ * @return the requireDirectives
+ */
+ public List getRequireDirectives() {
+ return requireDirectives;
+ }
+
+ /**
+ * @return the packagesRequired
+ */
+ public Set getPackagesRequired() {
+ return packagesRequired;
+ }
+
+ /**
+ * @return the packagesProvided
+ */
+ public Set getPackagesProvided() {
+ return packagesProvided;
+ }
+
+}