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:28:08 UTC
svn commit: r1504047 [13/17] - in /uima/sandbox/ruta/trunk/ruta-ep-ide-ui:
./ icons/ schema/ src/ src/main/ src/main/java/ src/main/java/org/
src/main/java/org/apache/ src/main/java/org/apache/uima/
src/main/java/org/apache/uima/ruta/ src/main/java/org...
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/text/folding/RutaFoldingStructureProvider.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/text/folding/RutaFoldingStructureProvider.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/text/folding/RutaFoldingStructureProvider.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/text/folding/RutaFoldingStructureProvider.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,298 @@
+/*
+ * 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.ui.text.folding;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.ruta.ide.RutaIdeUIPlugin;
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.apache.uima.ruta.ide.parser.ast.RutaStatement;
+import org.apache.uima.ruta.ide.ui.RutaPartitions;
+import org.apache.uima.ruta.ide.ui.RutaPreferenceConstants;
+import org.apache.uima.ruta.ide.ui.text.RutaPartitionScanner;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.declarations.MethodDeclaration;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.declarations.TypeDeclaration;
+import org.eclipse.dltk.ast.parser.ISourceParser;
+import org.eclipse.dltk.ast.references.SimpleReference;
+import org.eclipse.dltk.ast.statements.Statement;
+import org.eclipse.dltk.compiler.env.ModuleSource;
+import org.eclipse.dltk.core.DLTKLanguageManager;
+import org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;
+
+public class RutaFoldingStructureProvider extends AbstractASTFoldingStructureProvider {
+
+ // ~ Instance fields
+
+ private List fBlockExcludeList = new ArrayList();
+
+ /* preferences */
+ private int fBlockFolding = 0;
+
+ private List fBlockIncludeList = new ArrayList();
+
+ private boolean fInitCollapseBlocks = true;
+
+ private boolean fInitCollapseComments = true;
+
+ private boolean fInitCollapseNamespaces = true;
+
+ // ~ Methods
+
+ @Override
+ protected CodeBlock[] getCodeBlocks(String code, int offset) {
+ /*
+ * if an ASTVisitor implementation is created for this, just override getFoldingVisitor() and
+ * remove this method
+ */
+ ISourceParser pp = null;
+ pp = DLTKLanguageManager.getSourceParser(RutaNature.NATURE_ID);
+ ModuleDeclaration md = (ModuleDeclaration) pp.parse(new ModuleSource(code), null);
+ List statements = md.getStatements();
+ if (statements == null) {
+ return new CodeBlock[0];
+ }
+
+ List result = new ArrayList();
+ traverse(result, statements, offset, code);
+
+ return (CodeBlock[]) result.toArray(new CodeBlock[result.size()]);
+ }
+
+ private void checkStatement(String code, int offset, List result, Statement sst) {
+ if (sst instanceof RutaStatement) {
+ RutaStatement statement = (RutaStatement) sst;
+ result.add(new CodeBlock(statement, new Region(offset + statement.sourceStart(), statement
+ .sourceEnd() - statement.sourceStart())));
+
+ Iterator si = statement.getExpressions().iterator();
+ // while (si.hasNext()) {
+ // Expression ex = (Expression) si.next();
+ // if (ex instanceof BlockDeclaration) {
+ // BlockDeclaration be = (BlockDeclaration) ex;
+ // try {
+ // String newContents = code.substring(
+ // be.sourceStart() + 1, be.sourceEnd() - 1);
+ // CodeBlock[] cb = getCodeBlocks(newContents, offset
+ // + be.sourceStart() + 1);
+ // for (int j = 0; j < cb.length; j++) {
+ // result.add(cb[j]);
+ // }
+ // } catch (StringIndexOutOfBoundsException e) {
+ // }
+ // }
+ // }
+ }
+ }
+
+ private void traverse(List result, List statements, int offset, String code) {
+ for (Iterator iterator = statements.iterator(); iterator.hasNext();) {
+ ASTNode node = (ASTNode) iterator.next();
+ if (node instanceof RutaStatement) {
+ checkStatement(code, offset, result, (Statement) node);
+ } else if (node instanceof TypeDeclaration) {
+ TypeDeclaration statement = (TypeDeclaration) node;
+ result.add(new CodeBlock(statement, new Region(offset + statement.sourceStart(), statement
+ .sourceEnd() - statement.sourceStart())));
+ traverse(result, statement.getStatements(), offset, code);
+ } else if (node instanceof MethodDeclaration) {
+ MethodDeclaration statement = (MethodDeclaration) node;
+ result.add(new CodeBlock(statement, new Region(offset + statement.sourceStart(), statement
+ .sourceEnd() - statement.sourceStart())));
+ traverse(result, statement.getStatements(), offset, code);
+ }
+ }
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider#getCommentPartition()
+ */
+ @Override
+ protected String getCommentPartition() {
+ return RutaPartitions.RUTA_COMMENT;
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider#getLog()
+ */
+ @Override
+ protected ILog getLog() {
+ return RutaIdeUIPlugin.getDefault().getLog();
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider#getPartition()
+ */
+ @Override
+ protected String getPartition() {
+ return RutaPartitions.RUTA_PARTITIONING;
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider#getPartitionScanner()
+ */
+ @Override
+ protected IPartitionTokenScanner getPartitionScanner() {
+ return new RutaPartitionScanner();
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider#getPartitionTypes()
+ */
+ @Override
+ protected String[] getPartitionTypes() {
+ return RutaPartitions.RUTA_PARTITION_TYPES;
+ }
+
+ /*
+ * @see org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider#getNatureId()
+ */
+ @Override
+ protected String getNatureId() {
+ return RutaNature.NATURE_ID;
+ }
+
+ /*
+ * @see
+ * org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider#initializePreferences(
+ * org.eclipse.jface.preference.IPreferenceStore)
+ */
+ @Override
+ protected void initializePreferences(IPreferenceStore store) {
+ super.initializePreferences(store);
+ fBlockFolding = store.getInt(RutaPreferenceConstants.EDITOR_FOLDING_BLOCKS);
+
+ String t = store.getString(RutaPreferenceConstants.EDITOR_FOLDING_EXCLUDE_LIST);
+ String[] items = t.split(",");
+ fBlockExcludeList.clear();
+ for (int i = 0; i < items.length; i++) {
+ if (items[i].trim().length() > 0) {
+ fBlockExcludeList.add(items[i]);
+ }
+ }
+
+ t = store.getString(RutaPreferenceConstants.EDITOR_FOLDING_INCLUDE_LIST);
+ items = t.split(",");
+ fBlockIncludeList.clear();
+ for (int i = 0; i < items.length; i++) {
+ if (items[i].trim().length() > 0) {
+ fBlockIncludeList.add(items[i]);
+ }
+ }
+
+ fFoldNewLines = store.getBoolean(RutaPreferenceConstants.EDITOR_FOLDING_COMMENTS_WITH_NEWLINES);
+ fInitCollapseBlocks = store.getBoolean(RutaPreferenceConstants.EDITOR_FOLDING_INIT_BLOCKS);
+ fInitCollapseComments = store.getBoolean(RutaPreferenceConstants.EDITOR_FOLDING_INIT_COMMENTS);
+ fInitCollapseNamespaces = store
+ .getBoolean(RutaPreferenceConstants.EDITOR_FOLDING_INIT_NAMESPACES);
+ }
+
+ @Override
+ protected boolean initiallyCollapse(ASTNode s, FoldingStructureComputationContext ctx) {
+ if (s instanceof RutaStatement) {
+ RutaStatement statement = (RutaStatement) s;
+ if (!(statement.getAt(0) instanceof SimpleReference)) {
+ return false;
+ }
+
+ String name = null;
+ name = ((SimpleReference) statement.getAt(0)).getName();
+ if (name.equals("namespace")) {
+ return ctx.allowCollapsing() && fInitCollapseNamespaces;
+ }
+
+ return ctx.allowCollapsing() && fInitCollapseBlocks;
+ }
+
+ return false;
+ }
+
+ /*
+ * @see
+ * org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider#initiallyCollapseComments
+ * (org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider.
+ * FoldingStructureComputationContext)
+ */
+ protected boolean initiallyCollapseComments(FoldingStructureComputationContext ctx) {
+ return ctx.allowCollapsing() && fInitCollapseComments;
+ }
+
+ /*
+ * @see
+ * org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider#mayCollapse(org.eclipse
+ * .dltk.ast.statements.Statement,
+ * org.eclipse.dltk.ui.text.folding.AbstractASTFoldingStructureProvider
+ * .FoldingStructureComputationContext)
+ */
+ protected boolean canFold(String name) {
+ switch (fBlockFolding) {
+ case RutaPreferenceConstants.EDITOR_FOLDING_BLOCKS_OFF: {
+ if (name.equals("proc") || name.equals("namespace")) {
+ return true;
+ }
+
+ return false;
+ }
+ case RutaPreferenceConstants.EDITOR_FOLDING_BLOCKS_INCLUDE: {
+ if (fBlockIncludeList.contains(name)) {
+ return true;
+ }
+
+ return false;
+ }
+ case RutaPreferenceConstants.EDITOR_FOLDING_BLOCKS_EXCLUDE: {
+ if (fBlockExcludeList.contains(name)) {
+ return false;
+ }
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected boolean mayCollapse(ASTNode s, FoldingStructureComputationContext ctx) {
+ if (s instanceof TypeDeclaration) {
+ return canFold("namespace");
+ } else if (s instanceof MethodDeclaration) {
+ return canFold("proc");
+ } else if (s instanceof RutaStatement) {
+ RutaStatement statement = (RutaStatement) s;
+ if (!(statement.getAt(0) instanceof SimpleReference)) {
+ return false;
+ }
+
+ String name = null;
+ name = ((SimpleReference) statement.getAt(0)).getName();
+ return canFold(name);
+ }
+
+ return false;
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaFileCreationPage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaFileCreationPage.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaFileCreationPage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaFileCreationPage.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,103 @@
+/*
+ * 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.ui.wizards;
+
+import java.util.List;
+
+import org.apache.uima.ruta.ide.RutaIdeUIPlugin;
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.apache.uima.ruta.ide.core.builder.RutaProjectUtils;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.dltk.core.IBuildpathEntry;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.IScriptFolder;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ModelException;
+import org.eclipse.dltk.ui.wizards.NewSourceModulePage;
+
+public class RutaFileCreationPage extends NewSourceModulePage {
+
+ @Override
+ protected String getPageDescription() {
+ return "This wizard creates a new Ruta script file.";
+ }
+
+ @Override
+ protected String getFileContent() {
+ StringBuilder sb = new StringBuilder();
+ IScriptFolder scriptFolder = getScriptFolder();
+ IScriptProject scriptProject = scriptFolder.getScriptProject();
+
+
+ IFolder folder = null;
+ try {
+ folder = getScriptFolderOf(scriptFolder, scriptProject);
+ } catch (ModelException e) {
+ RutaIdeUIPlugin.error(e);
+ }
+ if(folder == null) {
+ return "";
+ }
+
+ IPath path = scriptFolder.getPath();
+ IPath fullPath = folder.getFullPath();
+ IPath relativeTo = path.makeRelativeTo(fullPath);
+ if(!relativeTo.isEmpty()) {
+ sb.append("PACKAGE ");
+ String pathString = "";
+ for (int i = 0; i < relativeTo.segments().length; i++) {
+ pathString += relativeTo.segments()[i];
+ if (i < relativeTo.segments().length - 1) {
+ pathString += ".";
+ }
+ }
+ sb.append(pathString);
+ sb.append(";\n");
+ }
+ return sb.toString();
+ }
+
+ private IFolder getScriptFolderOf(IScriptFolder scriptFolder, IScriptProject scriptProject) throws ModelException {
+ List<IFolder> scriptFolders = RutaProjectUtils.getScriptFolders(scriptProject);
+ for (IFolder each : scriptFolders) {
+ if(each.equals(scriptFolder.getResource())) {
+ return each;
+ }
+ IPath path = scriptFolder.getPath().makeRelativeTo(each.getFullPath());
+ IResource findMember = each.findMember(path);
+ if(findMember != null && findMember instanceof IFolder) {
+ return each;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected String getRequiredNature() {
+ return RutaNature.NATURE_ID;
+ }
+
+ @Override
+ protected String getPageTitle() {
+ return "Create a new Ruta script file";
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaFileCreationWizard.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaFileCreationWizard.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaFileCreationWizard.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaFileCreationWizard.java Wed Jul 17 08:28:02 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.ui.wizards;
+
+import org.apache.uima.ruta.ide.ui.RutaImages;
+import org.eclipse.dltk.ui.DLTKUIPlugin;
+import org.eclipse.dltk.ui.wizards.NewSourceModulePage;
+import org.eclipse.dltk.ui.wizards.NewSourceModuleWizard;
+
+public class RutaFileCreationWizard extends NewSourceModuleWizard {
+ public static final String ID_WIZARD = "org.apache.uima.ruta.ide.ui.wizards.RutaFileCreationWizard";
+
+ public RutaFileCreationWizard() {
+ setDefaultPageImageDescriptor(RutaImages.DESC_WIZBAN_FILE_CREATION);
+ setDialogSettings(DLTKUIPlugin.getDefault().getDialogSettings());
+ setWindowTitle("Create Ruta File");
+ }
+
+ @Override
+ protected NewSourceModulePage createNewSourceModulePage() {
+ return new RutaFileCreationPage();
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaJavaContainerPage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaJavaContainerPage.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaJavaContainerPage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaJavaContainerPage.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,55 @@
+/*
+ * 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.ui.wizards;
+
+import org.eclipse.dltk.core.IBuildpathEntry;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.internal.ui.wizards.IBuildpathContainerPage;
+import org.eclipse.dltk.ui.wizards.IBuildpathContainerPageExtension;
+import org.eclipse.dltk.ui.wizards.NewElementWizardPage;
+import org.eclipse.swt.widgets.Composite;
+
+public class RutaJavaContainerPage extends NewElementWizardPage implements IBuildpathContainerPage,
+ IBuildpathContainerPageExtension {
+
+ public RutaJavaContainerPage() {
+ super("RutaJavaContainerPage");
+ }
+
+ public void createControl(Composite composite) {
+
+ }
+
+ public void initialize(IScriptProject project, IBuildpathEntry[] currentEntries) {
+
+ }
+
+ public boolean finish() {
+ return false;
+ }
+
+ public IBuildpathEntry getSelection() {
+ return null;
+ }
+
+ public void setSelection(IBuildpathEntry containerEntry) {
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaPackageCreationWizard.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaPackageCreationWizard.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaPackageCreationWizard.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaPackageCreationWizard.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,64 @@
+/*
+ * 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.ui.wizards;
+
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.dltk.core.IProjectFragment;
+import org.eclipse.dltk.ui.wizards.NewPackageCreationWizard;
+import org.eclipse.dltk.ui.wizards.NewPackageWizardPage;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+public class RutaPackageCreationWizard extends NewPackageCreationWizard {
+ public static final String ID_WIZARD = "org.apache.uima.ruta.ide.ui.wizards.NewPackageCreationWizard";
+
+ @Override
+ protected NewPackageWizardPage createNewPackageWizardPage() {
+ return new NewPackageWizardPage() {
+ @Override
+ public void createPackage(IProgressMonitor monitor) throws CoreException,
+ InterruptedException {
+ if (monitor == null) {
+ monitor = new NullProgressMonitor();
+ }
+ IProjectFragment root = getProjectFragment();
+ String packName = getPackageText();
+ packName = packName.replaceAll("[.]", "/");
+ fCreatedScriptFolder = root.createScriptFolder(packName, true, monitor);
+ if (monitor.isCanceled()) {
+ throw new InterruptedException();
+ }
+ }
+
+ @Override
+ protected String getRequiredNature() {
+ return RutaNature.NATURE_ID;
+ }
+
+ @Override
+ public void init(IStructuredSelection selection) {
+ super.init(selection);
+ setPackageText("", true);
+ }
+ };
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectCreationWizard.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectCreationWizard.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectCreationWizard.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectCreationWizard.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,232 @@
+/*
+ * 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.ui.wizards;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.ruta.engine.RutaEngine;
+import org.apache.uima.ruta.ide.core.RutaNature;
+import org.apache.uima.ruta.ide.core.builder.RutaProjectUtils;
+import org.apache.uima.ruta.ide.ui.RutaImages;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IBuildpathEntry;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.internal.ui.util.CoreUtility;
+import org.eclipse.dltk.internal.ui.wizards.buildpath.BPListElement;
+import org.eclipse.dltk.ui.DLTKUIPlugin;
+import org.eclipse.dltk.ui.wizards.BuildpathsBlock;
+import org.eclipse.dltk.ui.wizards.ProjectWizard;
+import org.eclipse.dltk.ui.wizards.ProjectWizardFirstPage;
+import org.eclipse.dltk.ui.wizards.ProjectWizardSecondPage;
+import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard;
+
+public class RutaProjectCreationWizard extends ProjectWizard {
+
+ public static final String ID_WIZARD = "org.apache.uima.ruta.ide.ui.wizards.RutaProjectWizard"; //$NON-NLS-1$
+
+ private ProjectWizardFirstPage fFirstPage;
+
+ private ProjectWizardSecondPage fSecondPage;
+
+ private IConfigurationElement fConfigElement;
+
+ public RutaProjectCreationWizard() {
+ setDefaultPageImageDescriptor(RutaImages.DESC_WIZBAN_PROJECT_CREATION);
+ setDialogSettings(DLTKUIPlugin.getDefault().getDialogSettings());
+ setWindowTitle(RutaWizardMessages.ProjectCreationWizard_title);
+ }
+
+ @Override
+ public void addPages() {
+ super.addPages();
+ fFirstPage = new RutaProjectWizardFirstPage();
+
+ fFirstPage.setTitle(RutaWizardMessages.ProjectCreationWizardFirstPage_title);
+ fFirstPage.setDescription(RutaWizardMessages.ProjectCreationWizardFirstPage_description);
+ addPage(fFirstPage);
+ fSecondPage = new RutaProjectWizardSecondPage(fFirstPage);
+ addPage(fSecondPage);
+ }
+
+ @Override
+ protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException {
+ super.finishPage(monitor);
+ createProject(monitor);
+ }
+
+ public void createProject(IProgressMonitor monitor) throws CoreException {
+ IScriptProject scriptProject = fSecondPage.getScriptProject();
+ createRutaProject(scriptProject, fSecondPage.getRawBuildPath(), monitor);
+ }
+
+ public static void createRutaProject(IScriptProject scriptProject, IBuildpathEntry[] buildPath,
+ IProgressMonitor monitor) throws CoreException {
+ IProject project = scriptProject.getProject();
+ IFolder folder = project.getFolder(RutaProjectUtils.getDefaultInputLocation());
+ if (!folder.exists()) {
+ CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
+ }
+ folder = project.getFolder(RutaProjectUtils.getDefaultOutputLocation());
+ if (!folder.exists()) {
+ CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
+ }
+ folder = project.getFolder(RutaProjectUtils.getDefaultTestLocation());
+ if (!folder.exists()) {
+ CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
+ }
+ IFolder descFolder = project.getFolder(RutaProjectUtils.getDefaultDescriptorLocation());
+ if (!descFolder.exists()) {
+ CoreUtility.createFolder(descFolder, true, true, new SubProgressMonitor(monitor, 1));
+ }
+ IFolder srcFolder = project.getFolder(RutaProjectUtils.getDefaultScriptLocation());
+ if (!srcFolder.exists()) {
+ CoreUtility.createFolder(srcFolder, true, true, new SubProgressMonitor(monitor, 1));
+ }
+ IFolder rsrcFolder = project.getFolder(RutaProjectUtils.getDefaultResourcesLocation());
+ if (!rsrcFolder.exists()) {
+ CoreUtility.createFolder(rsrcFolder, true, true, new SubProgressMonitor(monitor, 1));
+ }
+
+ IFolder utilsFolder = descFolder.getFolder("utils");
+ if (!utilsFolder.exists()) {
+ CoreUtility.createFolder(utilsFolder, true, true, new SubProgressMonitor(monitor, 1));
+ }
+
+ List<BPListElement> buildpathEntries = new ArrayList<BPListElement>();
+ if (buildPath != null) {
+ for (IBuildpathEntry buildpathEntry : buildPath) {
+ BPListElement createFromExisting = BPListElement.createFromExisting(buildpathEntry,
+ scriptProject);
+ if (createFromExisting.getBuildpathEntry().getEntryKind() != IBuildpathEntry.BPE_SOURCE) {
+ buildpathEntries.add(createFromExisting);
+ }
+ }
+ }
+ IBuildpathEntry newSourceEntry = DLTKCore.newSourceEntry(srcFolder.getFullPath());
+ buildpathEntries.add(BPListElement.createFromExisting(newSourceEntry, scriptProject));
+
+ BuildpathsBlock.flush(buildpathEntries, scriptProject, monitor);
+ copyDescriptors(descFolder);
+
+ RutaProjectUtils.addProjectDataPath(project, descFolder);
+
+ descFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ }
+
+ public static void copyDescriptors(IFolder descFolder) {
+ File descDir = descFolder.getLocation().toFile();
+ File utilsDir = new File(descFolder.getLocation().toFile(), "utils/");
+ utilsDir.mkdirs();
+ copy(descDir, "BasicTypeSystem.xml");
+ copy(descDir, "BasicEngine.xml");
+ copy(descDir, "InternalTypeSystem.xml");
+
+ copy(utilsDir, "Modifier.xml");
+ copy(utilsDir, "AnnotationWriter.xml");
+ copy(utilsDir, "StyleMapCreator.xml");
+ copy(utilsDir, "XMIWriter.xml");
+ copy(utilsDir, "SourceDocumentInformation.xml");
+ copy(utilsDir, "PlainTextAnnotator.xml");
+ copy(utilsDir, "PlainTextTypeSystem.xml");
+ copy(utilsDir, "HtmlAnnotator.xml");
+ copy(utilsDir, "HtmlTypeSystem.xml");
+ copy(utilsDir, "HtmlConverter.xml");
+ copy(utilsDir, "Cutter.xml");
+ copy(utilsDir, "ViewWriter.xml");
+ }
+
+ private static void copy(File dir, String fileName) {
+ InputStream in = null;
+ OutputStream out = null;
+ in = RutaEngine.class.getResourceAsStream(fileName);
+ try {
+ out = new FileOutputStream(new File(dir, fileName));
+ } catch (FileNotFoundException e) {
+ System.err.println(e);
+ }
+ if (in != null && out != null) {
+ copy(in, out);
+ }
+
+ }
+
+ static void copy(InputStream fis, OutputStream fos) {
+ try {
+ byte[] buffer = new byte[0xFFFF];
+ for (int len; (len = fis.read(buffer)) != -1;)
+ fos.write(buffer, 0, len);
+ } catch (IOException e) {
+ System.err.println(e);
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ System.err.println(e);
+ }
+ }
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ System.err.println(e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean performFinish() {
+ boolean res = super.performFinish();
+ if (res) {
+ BasicNewProjectResourceWizard.updatePerspective(fConfigElement);
+ selectAndReveal(fSecondPage.getScriptProject().getProject());
+ }
+ return res;
+ }
+
+ public void setInitializationData(IConfigurationElement cfig, String propertyName, Object data) {
+ fConfigElement = cfig;
+ }
+
+ @Override
+ public boolean performCancel() {
+ return super.performCancel();
+ }
+
+ @Override
+ public String getScriptNature() {
+ return RutaNature.NATURE_ID;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardFirstPage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardFirstPage.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardFirstPage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardFirstPage.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,91 @@
+/*
+ * 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.ui.wizards;
+
+import org.eclipse.dltk.ui.wizards.ProjectWizardFirstPage;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+
+final class RutaProjectWizardFirstPage extends ProjectWizardFirstPage {
+
+ private Button useAnalysis;
+
+ private Group packagesGroup;
+
+ private Label labelElement;
+
+ public RutaProjectWizardFirstPage() {
+ setTitle(RutaWizardMessages.ProjectCreationWizardFirstPage_title);
+ setDescription(RutaWizardMessages.ProjectCreationWizardFirstPage_description);
+ }
+
+ @Override
+ protected IInterpreterGroup createInterpreterGroup(Composite parent) {
+ return new DefaultInterpreterGroup(parent);
+ }
+
+ @Override
+ protected boolean interpeterRequired() {
+ /* Specially allow to create TCL project without interpreter */
+ return false;
+ }
+
+ // protected void createCustomGroups(Composite composite) {
+ // super.createCustomGroups(composite);
+ //
+ // packagesGroup = new Group(composite, SWT.NONE);
+ // GridData gridData = new GridData(GridData.FILL, SWT.FILL, true, false);
+ // gridData.widthHint = convertWidthInCharsToPixels(50);
+ // packagesGroup.setLayoutData(gridData);
+ // packagesGroup.setLayout(new GridLayout(1, false));
+ // packagesGroup
+ // .setText(RutaWizardMessages.RutaProjectWizardFirstPage_packageDetector);
+ // this.useAnalysis = new Button(packagesGroup, SWT.CHECK);
+ // this.useAnalysis
+ // .setText(RutaWizardMessages.RutaProjectWizardFirstPage_packageDetector_checkbox);
+ // this.useAnalysis.setSelection(true);
+ // labelElement = new Label(packagesGroup, SWT.NONE);
+ // labelElement
+ // .setText(RutaWizardMessages.RutaProjectWizardFirstPage_packageDetector_description);
+ // Observer o = new Observer() {
+ // public void update(Observable o, Object arg) {
+ // boolean inWorkspace = fLocationGroup.isInWorkspace();
+ // packagesGroup.setEnabled(!inWorkspace);
+ // useAnalysis.setEnabled(!inWorkspace);
+ // labelElement.setEnabled(!inWorkspace);
+ // }
+ // };
+ // fLocationGroup.addObserver(o);
+ // ((RutaInterpreterGroup) getInterpreterGroup()).addObserver(o);
+ // }
+
+ public boolean useAnalysis() {
+ final boolean result[] = { false };
+ useAnalysis.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ result[0] = useAnalysis.getSelection();
+ }
+ });
+ return result[0];
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardSecondPage.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardSecondPage.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardSecondPage.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaProjectWizardSecondPage.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,65 @@
+/*
+ * 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.ui.wizards;
+
+import org.apache.uima.ruta.ide.ui.preferences.RutaBuildPathsBlock;
+import org.eclipse.dltk.ui.util.BusyIndicatorRunnableContext;
+import org.eclipse.dltk.ui.util.IStatusChangeListener;
+import org.eclipse.dltk.ui.wizards.BuildpathsBlock;
+import org.eclipse.dltk.ui.wizards.ProjectWizardFirstPage;
+import org.eclipse.dltk.ui.wizards.ProjectWizardSecondPage;
+
+final class RutaProjectWizardSecondPage extends ProjectWizardSecondPage {
+ RutaProjectWizardSecondPage(ProjectWizardFirstPage mainPage) {
+ super(mainPage);
+ }
+
+ @Override
+ protected BuildpathsBlock createBuildpathBlock(IStatusChangeListener listener) {
+ return new RutaBuildPathsBlock(new BusyIndicatorRunnableContext(), listener, 0,
+ useNewSourcePage(), null);
+ }
+
+ // protected BuildpathDetector createBuildpathDetector(
+ // IProgressMonitor monitor, IDLTKLanguageToolkit toolkit)
+ // throws CoreException {
+ // RutaBuildpathDetector detector = new RutaBuildpathDetector(
+ // getCurrProject(), toolkit);
+ //
+ // RutaProjectWizardFirstPage page = (RutaProjectWizardFirstPage) this
+ // .getFirstPage();
+ // detector.setUseAnalysis(page.useAnalysis());
+ // detector.detectBuildpath(new SubProgressMonitor(monitor, 20));
+ // return detector;
+ // }
+
+ // protected void postConfigureProject() throws CoreException {
+ // final IProject project = getCurrProject();
+ // final IEnvironment environment = EnvironmentManager
+ // .getEnvironment(project);
+ // if (environment != null && !environment.isLocal()) {
+ // final Map options = new HashMap();
+ // options.put(DLTKCore.INDEXER_ENABLED, DLTKCore.DISABLED);
+ // options.put(DLTKCore.BUILDER_ENABLED, DLTKCore.DISABLED);
+ // DLTKCore.create(project).setOptions(options);
+ // }
+ // }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaWizardMessages.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaWizardMessages.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaWizardMessages.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/ui/wizards/RutaWizardMessages.java Wed Jul 17 08:28:02 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.ui.wizards;
+
+import org.eclipse.osgi.util.NLS;
+
+public class RutaWizardMessages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.apache.uima.ruta.ide.ui.wizards.RutaWizardMessages";//$NON-NLS-1$
+
+ private RutaWizardMessages() {
+ }
+
+ public static String ProjectCreationWizard_title;
+
+ public static String ProjectCreationWizardFirstPage_title;
+
+ public static String ProjectCreationWizardFirstPage_description;
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, RutaWizardMessages.class);
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/CheckValidator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/CheckValidator.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/CheckValidator.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/CheckValidator.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,38 @@
+/*
+ * 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.validator;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.builder.AbstractBuildParticipantType;
+import org.eclipse.dltk.core.builder.IBuildParticipant;
+
+public class CheckValidator extends AbstractBuildParticipantType {
+
+ private static final String ID = "org.apache.uima.ruta.ide.validator.checkvalidator"; //$NON-NLS-1$
+
+ private static final String NAME = "Ruta Checker"; //$NON-NLS-1$
+
+ @Override
+ public IBuildParticipant createBuildParticipant(IScriptProject project) throws CoreException {
+ return new RutaChecker(project);
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaChecker.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaChecker.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaChecker.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaChecker.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,89 @@
+/*
+ * 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.validator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.SourceParserUtil;
+import org.eclipse.dltk.core.builder.IBuildContext;
+import org.eclipse.dltk.core.builder.IBuildParticipant;
+import org.eclipse.dltk.core.builder.IBuildParticipantExtension;
+
+public class RutaChecker implements IBuildParticipant, IBuildParticipantExtension {
+ List<IBuildParticipant> buildParticipants = null;
+
+ public RutaChecker(IScriptProject project) {
+ buildParticipants = new ArrayList<IBuildParticipant>();
+ try {
+ buildParticipants.add(new RutaTypeChecker(project));
+ buildParticipants.add(new RutaVarRefChecker());
+ buildParticipants.add(new RutaEngineAndCallChecker(project));
+ buildParticipants.add(new RutaRessourceChecker(project));
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.dltk.core.builder.IBuildParticipant#build(org.eclipse.dltk
+ * .core.builder.IBuildContext)
+ */
+ public void build(IBuildContext context) throws CoreException {
+ // if ast not declared in context ..
+ Object mdObj = context.get(IBuildContext.ATTR_MODULE_DECLARATION);
+ if (!(mdObj instanceof ModuleDeclaration)) {
+ // ...temporary inefficient hack to get live error msgs
+ // TODO refactor
+ ISourceModule sourceModule = context.getSourceModule();
+ ModuleDeclaration md = SourceParserUtil.getModuleDeclaration(sourceModule, null);
+ context.set(IBuildContext.ATTR_MODULE_DECLARATION, md);
+ }
+ for (IBuildParticipant buildP : buildParticipants) {
+ buildP.build(context);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.dltk.core.builder.IBuildParticipantExtension#beginBuild(int)
+ */
+ public boolean beginBuild(int buildType) {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.dltk.core.builder.IBuildParticipantExtension#endBuild(org
+ * .eclipse.core.runtime.IProgressMonitor)
+ */
+ public void endBuild(IProgressMonitor monitor) {
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerDefaultProblem.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerDefaultProblem.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerDefaultProblem.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerDefaultProblem.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,51 @@
+/*
+ * 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.validator;
+
+import org.apache.uima.ruta.ide.parser.ast.RutaAbstractDeclaration;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.compiler.problem.DefaultProblem;
+import org.eclipse.dltk.compiler.problem.ProblemSeverity;
+
+public class RutaCheckerDefaultProblem extends DefaultProblem {
+
+ public RutaCheckerDefaultProblem(String fileName, String message, RutaAbstractDeclaration node,
+ int line, int column, ProblemSeverity severity) {
+ super(fileName, message, RutaProblemIdentifier.PROBLEM, new String[] {}, severity, node
+ .getNameStart(), node.getNameEnd(), line, column);
+ }
+
+ public RutaCheckerDefaultProblem(String fileName, String message, RutaAbstractDeclaration node,
+ int line) {
+ super(fileName, message, 0, new String[] {}, ProblemSeverity.ERROR, node.getNameStart(), node
+ .getNameEnd(), line);
+ }
+
+ public RutaCheckerDefaultProblem(String fileName, String message, ASTNode node, int line) {
+ this(fileName, message, node, line, ProblemSeverity.ERROR);
+ }
+
+ public RutaCheckerDefaultProblem(String fileName, String message, ASTNode node, int line,
+ ProblemSeverity severity) {
+ super(fileName, message, 0, new String[] {}, severity, node.sourceStart(), node.sourceEnd(),
+ line);
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerProblemFactory.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,191 @@
+/*
+ * 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.validator;
+
+import java.util.List;
+
+import org.apache.uima.ruta.ide.core.extensions.IRutaCheckerProblemFactory;
+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.ASTListNode;
+import org.eclipse.dltk.ast.ASTNode;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.expressions.StringLiteral;
+import org.eclipse.dltk.compiler.problem.IProblem;
+import org.eclipse.dltk.compiler.problem.ProblemSeverity;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.builder.ISourceLineTracker;
+
+public class RutaCheckerProblemFactory implements IRutaCheckerProblemFactory{
+ private ISourceLineTracker linetracker;
+
+ private String fileName;
+
+ public RutaCheckerProblemFactory(String fileName, ISourceLineTracker linetracker) {
+ this.fileName = fileName;
+ this.linetracker = linetracker;
+ }
+
+ public IProblem createIdConflictsWithVariableProblem(RutaAbstractDeclaration varRef) {
+ String message = generateVarAlreadyDeclaredProblemMsg(varRef);
+ return new RutaCheckerDefaultProblem(this.fileName, message, varRef, getLine(varRef));
+ }
+
+ public IProblem createIdConflictsWithTypeProblem(RutaAbstractDeclaration varRef) {
+ String message = generateVarConflictsWithTypeProblem(varRef);
+ return new RutaCheckerDefaultProblem(this.fileName, message, varRef, getLine(varRef));
+ }
+
+ public IProblem createFileNotFoundProblem(ASTNode node, String localPath) {
+ return new RutaCheckerDefaultProblem(this.fileName, generateFileNotFoundProblemMsg(localPath),
+ node, getLine(node));
+ }
+
+ public IProblem createFileNotFoundProblem(ASTNode fileNode) {
+ return createFileNotFoundProblem(fileNode, fileNode.toString());
+ // generateFileNotFoundProblemMsg(fileNode));
+ }
+
+ public IProblem createDuplicateShortNameInImported(ASTNode node, String localPath,
+ List<String> checkDuplicateShortNames, ProblemSeverity severity) {
+ StringBuilder sb = new StringBuilder();
+ for (String string : checkDuplicateShortNames) {
+ sb.append(string);
+ sb.append(", ");
+ }
+
+ return new RutaCheckerDefaultProblem(this.fileName, "Types in " + localPath
+ + " share same short name, but with different namespaces: " + sb.toString(), node,
+ getLine(node), severity);
+ }
+
+ public IProblem createDuplicateShortName(RutaAbstractDeclaration var, ProblemSeverity severity) {
+ return new RutaCheckerDefaultProblem(this.fileName, "The type " + var.getName()
+ + " conflicts with other types with same short name, but different namespace.", var,
+ getLine(var), severity);
+ }
+
+ public IProblem createXMLProblem(ASTNode node, String localPath) {
+ return new RutaCheckerDefaultProblem(this.fileName, generateXMLProblemMsg(localPath), node,
+ getLine(node));
+ }
+
+ public IProblem createTypeProblem(RutaVariableReference ref, ISourceModule currentFile) {
+
+ String errMsgHead = "Type \"";
+
+ String errMsgTailDefault = " \" not defined in this script/block!";
+ String errMsg = errMsgHead + ref.getName() + errMsgTailDefault;
+ IProblem problem = new RutaCheckerDefaultProblem(currentFile.getElementName(), errMsg, ref,
+ linetracker.getLineNumberOfOffset(ref.sourceStart()));
+ return problem;
+ }
+
+ private String generateFileNotFoundProblemMsg(ASTNode node) {
+ return generateFileNotFoundProblemMsg(node.toString());
+ }
+
+ private String generateFileNotFoundProblemMsg(String fileName) {
+ return "error: \"" + fileName + "\" not found.";
+ }
+
+ private String generateXMLProblemMsg(String fileName) {
+ return "error: " + fileName + " causes xml problem.";
+ }
+
+ private int getLine(ASTNode varRef) {
+ return this.linetracker.getLineNumberOfOffset(varRef.sourceStart());
+ }
+
+ private String generateVarAlreadyDeclaredProblemMsg(RutaAbstractDeclaration var) {
+ return "error: Id \"" + var.getName() + "\" conflicts with already declared variable.";
+ }
+
+ private String generateVarConflictsWithTypeProblem(RutaAbstractDeclaration var) {
+ return "error: Identifier \"" + var.getName()
+ + "\" conflicts with already declared annotation type.";
+ }
+
+ public IProblem createUnknownFeatureTypeProblem(RutaFeatureDeclaration var) {
+ String message = "error: Type \"" + var.getType() + "\" of Feature \"" + var.getName()
+ + "\" is not defined.";
+ return new RutaCheckerDefaultProblem(this.fileName, message, var, getLine(var));
+ }
+
+ public IProblem createUnknownFeatureProblem(Expression var, String matchedType) {
+ // TODO refactor and find better solution
+ String feat = var.toString();
+ List childs = var.getChilds();
+ if (childs != null && !childs.isEmpty()) {
+ Object object = childs.get(0);
+ if (object instanceof ASTListNode) {
+ List childs2 = ((ASTListNode) object).getChilds();
+ if (childs2 != null && !childs2.isEmpty()) {
+ Object object2 = childs2.get(0);
+ if (object2 instanceof StringLiteral) {
+ StringLiteral sl = (StringLiteral) object2;
+ feat = sl.getValue().replaceAll("\"", "");
+ }
+ }
+ }
+ }
+ String message = "error: Feature \"" + feat + "\" is not defined.";
+ if (matchedType != null) {
+ message = "error: Feature \"" + feat + "\" is not defined for type \"" + matchedType + "\".";
+ }
+ return new RutaCheckerDefaultProblem(this.fileName, message, var, getLine(var));
+ }
+
+ public IProblem createWrongArgumentTypeProblem(Expression was, String expected) {
+ String message = "Wrong kind of argument: expected " + expected;
+ return new RutaCheckerDefaultProblem(this.fileName, message, was, getLine(was));
+ }
+
+ public IProblem createInheritenceFinalProblem(RutaVariableReference parent) {
+ String message = "Type \"" + parent.getName()
+ + "\" is final and cannot be used as a parent type.";
+ return new RutaCheckerDefaultProblem(this.fileName, message, parent, getLine(parent));
+ }
+
+ public IProblem createUnknownConditionProblem(RutaCondition cond) {
+ String message = "error: Condition \"" + cond.getName() + "\" is not defined.";
+ return new RutaCheckerDefaultProblem(this.fileName, message, cond, getLine(cond));
+ }
+
+ public IProblem createUnknownActionProblem(RutaAction action) {
+ String message = "error: Action \"" + action.getName() + "\" is not defined.";
+ return new RutaCheckerDefaultProblem(this.fileName, message, action, getLine(action));
+ }
+
+ public IProblem createWrongNumberOfArgumentsProblem(String name, Expression element, int expected) {
+ String message = "error: The element " + name + " expects " + expected + " arguments.";
+ return new RutaCheckerDefaultProblem(this.fileName, message, element, getLine(element));
+ }
+
+ public IProblem createUnknownFunctionProblem(RutaFunction f) {
+ String message = "error: Function \"" + f.getName() + "\" is not defined.";
+ return new RutaCheckerDefaultProblem(this.fileName, message, f, getLine(f));
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaCheckerUtils.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,298 @@
+/*
+ * 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.validator;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.Stack;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_component.AnalysisComponent;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.resource.metadata.ConfigurationParameterSettings;
+import org.apache.uima.ruta.engine.RutaEngine;
+import org.apache.uima.ruta.ide.core.builder.RutaProjectUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.dltk.core.DLTKCore;
+import org.eclipse.dltk.core.IMethod;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.IScriptFolder;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.ModelException;
+
+public class RutaCheckerUtils {
+
+ public static Set<String> importScript(String path, int type, IScriptProject project)
+ throws InvalidXMLException, IOException, ModelException {
+ return importScript(path, type, project, false);
+ }
+
+ /**
+ * @param path
+ * relative to script folder of the project.<br>
+ * i.e.: "org.apache.uima.MyScript"
+ * @param type
+ * i.e. IModelElement.FIELD for fields to be collected and returned
+ * @return
+ * @throws InvalidXMLException
+ * @throws IOException
+ * @throws ModelException
+ */
+ public static Set<String> importScript(String path, int type, IScriptProject project,
+ boolean appendPath) throws InvalidXMLException, IOException, ModelException {
+ Stack<String> namespaceStack = new Stack<String>();
+
+ final Set<String> imports = new HashSet<String>();
+ List<IFolder> scriptFolders = null;
+ try {
+ scriptFolders = RutaProjectUtils.getAllScriptFolders(project);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ String fileNameWithoutExtension = path.substring(path.lastIndexOf('.') + 1);
+ String fileNameWithExtension = fileNameWithoutExtension + RutaEngine.SCRIPT_FILE_EXTENSION;
+ ISourceModule sourceModule = null;
+ boolean found = false;
+ for (IFolder eachFolder : scriptFolders) {
+
+ IScriptProject sp = DLTKCore.create(eachFolder.getProject());
+ IScriptFolder[] scriptFolders2 = sp.getScriptFolders();
+ for (IScriptFolder iScriptFolder : scriptFolders2) {
+ sourceModule = iScriptFolder.getSourceModule(fileNameWithExtension);
+ if (sourceModule.exists() && sourceModule.getResource() != null
+ && sourceModule.getResource().exists()) {
+ found = true;
+ break;
+ }
+ if (found)
+ break;
+ }
+ }
+ IModelElement elements[] = null;
+ namespaceStack.push(fileNameWithoutExtension);
+ try {
+ elements = sourceModule.getChildren();
+ for (int i = 0; i < elements.length; i++) {
+ IModelElement modelElement = elements[i];
+ int elementType = modelElement.getElementType();
+ if (elementType == type) {
+ if (elementType == IModelElement.METHOD) {
+ imports.add(namespaceStack.peek() + "." + modelElement.getElementName());
+ } else if (appendPath) {
+ imports.add(path + "." + modelElement.getElementName());
+ } else {
+ imports.add(modelElement.getElementName());
+ }
+ }
+ if (elementType == IModelElement.METHOD) {
+ String nSpace = namespaceStack.empty() ? modelElement.getElementName() : namespaceStack
+ .peek() + "." + modelElement.getElementName();
+ namespaceStack.push(nSpace);
+ imports.addAll(collectElements((IMethod) modelElement, type, namespaceStack));
+ namespaceStack.pop();
+ }
+ }
+ } catch (ModelException e) {
+ throw new FileNotFoundException();
+ }
+ return imports;
+ }
+
+ private static Set<String> collectElements(IMethod element, int type, Stack stack)
+ throws ModelException {
+ Set<String> fieldsCollection = new HashSet<String>();
+ IModelElement elements[] = element.getChildren();
+ if (elements == null) {
+ return fieldsCollection;
+ }
+ for (int i = 0; i < elements.length; i++) {
+ IModelElement modelElement = elements[i];
+ int elementType = modelElement.getElementType();
+ if (elementType == type) {
+ if (elementType == IModelElement.FIELD) {
+ fieldsCollection.add(modelElement.getElementName());
+ }
+ fieldsCollection.add(stack.peek() + "." + modelElement.getElementName());
+ }
+ if (elementType == IModelElement.METHOD) {
+ stack.push(stack.peek() + "." + modelElement.getElementName());
+ fieldsCollection.addAll(collectElements((IMethod) modelElement, type, stack));
+ stack.pop();
+ }
+ }
+ return fieldsCollection;
+ }
+
+ public static IFile getFile(IFolder folder, String filePath) {
+ int lastDot = filePath.lastIndexOf('.');
+ int sndLastDot = filePath.lastIndexOf('.', lastDot - 1);
+ String fName = filePath;
+ if (sndLastDot >= 0) {
+ String subFolder = filePath.substring(0, sndLastDot);
+ folder = folder.getFolder(subFolder);
+ fName = filePath.substring(sndLastDot + 1);
+ }
+ return folder.getFile(fName);
+ }
+
+ /**
+ * @param xmlFilePath
+ * absolute full path. i.e.: "org.apache.uima.myengine" ".xml" will be added.
+ * @return file.exists
+ */
+ public static boolean checkEngineImport(String xmlFilePath, IScriptProject project) {
+ boolean result = false;
+ List<IFolder> allDescriptorFolders;
+ try {
+ allDescriptorFolders = RutaProjectUtils.getAllDescriptorFolders(project.getProject());
+ } catch (Exception e) {
+ return false;
+ }
+ for (IFolder folder : allDescriptorFolders) {
+ String fileExtended = xmlFilePath.replaceAll("[.]", "/") + ".xml";
+ IFile iFile = RutaCheckerUtils.getFile(folder, fileExtended);
+ result |= iFile.exists();
+ }
+ return result;
+ }
+
+ @SuppressWarnings({ "unchecked", "unused" })
+ public static boolean checkEngineOnClasspath(String clazz, IScriptProject project,
+ ClassLoader classloader) {
+ if (classloader != null) {
+ try {
+ Class<?> loadClass = classloader.loadClass(clazz);
+ Class<?> loadClass2 = classloader.loadClass(AnalysisComponent.class.getName());
+ boolean assignableFrom = loadClass2.isAssignableFrom(loadClass);
+ if (loadClass != null && loadClass2.isAssignableFrom(loadClass)) {
+ return true;
+ }
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ return false;
+ } else {
+ try {
+ Class<?> forName = Class.forName(clazz);
+ try {
+ Class<? extends AnalysisComponent> uimafit = (Class<? extends AnalysisComponent>) forName;
+ } catch (Exception e) {
+ return false;
+ }
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean checkScriptImport(String xmlFilePath, IScriptProject project) {
+ boolean result = false;
+ List<IFolder> allDescriptorFolders;
+ try {
+ allDescriptorFolders = RutaProjectUtils.getAllScriptFolders(project);
+ } catch (CoreException e) {
+ return false;
+ }
+ for (IFolder folder : allDescriptorFolders) {
+ String fileExtended = xmlFilePath.replaceAll("[.]", "/") + RutaEngine.SCRIPT_FILE_EXTENSION;
+ IFile iFile = RutaCheckerUtils.getFile(folder, fileExtended);
+ result |= iFile.exists();
+ }
+ return result;
+ }
+
+ /**
+ * @param resourceFilePath
+ * absolute full path. i.e.: "org.apache.uima.TestList.txt"
+ * @return file.exists
+ */
+ public static boolean checkRessourceExistence(String resourceFilePath, IScriptProject project) {
+ IFolder ddlFolder = project.getProject().getFolder(
+ RutaProjectUtils.getDefaultDescriptorLocation());
+ final String basicXML = "BasicEngine.xml";
+ IFile file = getFile(ddlFolder, basicXML);
+ AnalysisEngineDescription aed;
+ try {
+ URL url = file.getLocationURI().toURL();
+ aed = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(new XMLInputSource(url));
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ ConfigurationParameterSettings configurationParameterSettings = aed.getAnalysisEngineMetaData()
+ .getConfigurationParameterSettings();
+ String[] paths = (String[]) configurationParameterSettings
+ .getParameterValue(RutaEngine.RESOURCE_PATHS);
+ if (paths == null) {
+ IFolder folder = project.getProject().getFolder(
+ RutaProjectUtils.getDefaultResourcesLocation());
+ String defaultPath = folder.getLocation().toPortableString();
+ paths = new String[] { defaultPath };
+ }
+ for (String string : paths) {
+ File iFile = new File(string, resourceFilePath);
+ // IFile iFile = getFile(folder, ressourceFilePath);
+ if (iFile.exists()) {
+ return true;
+ }
+
+ }
+ return false;
+ }
+
+ /**
+ * @param xmlFilePath
+ * absolute full path. i.e.: "org.apache.uima.myengine" ".xml" will be added.
+ * @return file.exists
+ */
+ public static IFile getEngine(String xmlFilePath, IScriptProject project) {
+ IFolder folder = project.getProject()
+ .getFolder(RutaProjectUtils.getDefaultDescriptorLocation());
+ String fileExtended = xmlFilePath + ".xml";
+ return getFile(folder, fileExtended);
+ }
+
+ public static boolean checkTypeSystemImport(String localPath, IScriptProject project) {
+ boolean result = false;
+ List<IFolder> allDescriptorFolders;
+ try {
+ allDescriptorFolders = RutaProjectUtils.getAllDescriptorFolders(project.getProject());
+ } catch (Exception e) {
+ return false;
+ }
+ for (IFolder folder : allDescriptorFolders) {
+ String fileExtended = localPath.replaceAll("[.]", "/") + ".xml";
+ IFile iFile = RutaCheckerUtils.getFile(folder, fileExtended);
+ result |= iFile.exists();
+ }
+ return result;
+ }
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaEngineAndCallChecker.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaEngineAndCallChecker.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaEngineAndCallChecker.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaEngineAndCallChecker.java Wed Jul 17 08:28:02 2013
@@ -0,0 +1,246 @@
+/*
+ * 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.validator;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.uima.ruta.ide.RutaIdeUIPlugin;
+import org.apache.uima.ruta.ide.launching.RutaLaunchConfigurationDelegate;
+import org.apache.uima.ruta.ide.parser.ast.RutaAction;
+import org.apache.uima.ruta.ide.parser.ast.RutaActionConstants;
+import org.apache.uima.ruta.ide.parser.ast.RutaImportStatement;
+import org.apache.uima.ruta.ide.parser.ast.RutaStatementConstants;
+import org.apache.uima.util.InvalidXMLException;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.dltk.ast.ASTVisitor;
+import org.eclipse.dltk.ast.declarations.MethodDeclaration;
+import org.eclipse.dltk.ast.declarations.ModuleDeclaration;
+import org.eclipse.dltk.ast.declarations.TypeDeclaration;
+import org.eclipse.dltk.ast.expressions.Expression;
+import org.eclipse.dltk.ast.references.SimpleReference;
+import org.eclipse.dltk.ast.statements.Statement;
+import org.eclipse.dltk.compiler.problem.IProblem;
+import org.eclipse.dltk.compiler.problem.IProblemReporter;
+import org.eclipse.dltk.core.IModelElement;
+import org.eclipse.dltk.core.IScriptProject;
+import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.ModelException;
+import org.eclipse.dltk.core.builder.IBuildContext;
+import org.eclipse.dltk.core.builder.IBuildParticipant;
+import org.eclipse.dltk.core.builder.IBuildParticipantExtension;
+import org.eclipse.dltk.core.builder.ISourceLineTracker;
+
+public class RutaEngineAndCallChecker implements IBuildParticipant, IBuildParticipantExtension {
+
+ private class EngineAndCallCheckerVisitor extends ASTVisitor {
+ private IProblemReporter rep;
+
+ private RutaCheckerProblemFactory problemFactory;
+
+ private Set<String> engines;
+
+ private Set<String> scripts;
+
+ private String curFile;
+
+ private HashSet<String> scriptsInnerBlocks;
+
+ private URLClassLoader classloader;
+
+ public EngineAndCallCheckerVisitor(IProblemReporter rep, ISourceLineTracker linetracker,
+ String curFile) {
+ this.problemFactory = new RutaCheckerProblemFactory(curFile, linetracker);
+ this.rep = rep;
+ this.engines = new HashSet<String>();
+ this.scripts = new HashSet<String>();
+ this.scriptsInnerBlocks = new HashSet<String>();
+ this.curFile = curFile;
+
+ if (curFile != null && curFile.endsWith(".ruta")) {
+ scripts.add(curFile.substring(0, curFile.length() - 5));
+ }
+ try {
+ String fnwe = curFile.substring(0, curFile.length() - 5);
+ scriptsInnerBlocks.addAll(RutaCheckerUtils
+ .importScript(fnwe, IModelElement.METHOD, project));
+ } catch (InvalidXMLException e) {
+ } catch (IOException e) {
+ } catch (ModelException e) {
+ }
+
+ try {
+ Collection<String> dependencies = RutaLaunchConfigurationDelegate.getClassPath(project);
+ URL[] urls = new URL[dependencies.size()];
+ int counter = 0;
+ for (String dep : dependencies) {
+ urls[counter] = new File(dep).toURL();
+ counter++;
+ }
+ classloader = new URLClassLoader(urls);
+ } catch (CoreException e) {
+ RutaIdeUIPlugin.error(e);
+ } catch (MalformedURLException e) {
+ RutaIdeUIPlugin.error(e);
+ }
+
+ }
+
+ @Override
+ public boolean visit(Statement s) throws Exception {
+ if (s instanceof RutaImportStatement) {
+ // handle engine imports
+ if (((RutaImportStatement) s).getType() == RutaStatementConstants.S_IMPORT_ENGINE) {
+ SimpleReference sRef = (SimpleReference) ((RutaImportStatement) s).getExpression();
+ if (RutaCheckerUtils.checkEngineImport(sRef.getName(), project)) {
+ importEngine(sRef.getName());
+ } else {
+ IProblem problem = problemFactory.createFileNotFoundProblem(sRef);
+ rep.reportProblem(problem);
+ }
+ }
+ if (((RutaImportStatement) s).getType() == RutaStatementConstants.S_IMPORT_UIMAFIT_ENGINE) {
+ SimpleReference sRef = (SimpleReference) ((RutaImportStatement) s).getExpression();
+ if (RutaCheckerUtils.checkEngineOnClasspath(sRef.getName(), project, classloader)) {
+ importEngine(sRef.getName());
+ } else {
+ IProblem problem = problemFactory.createFileNotFoundProblem(sRef);
+ rep.reportProblem(problem);
+ }
+ }
+ // handle script imports
+ if (((RutaImportStatement) s).getType() == RutaStatementConstants.S_IMPORT_SCRIPT) {
+ SimpleReference stRef = (SimpleReference) ((RutaImportStatement) s).getExpression();
+ String sRefName = stRef.getName();
+ try {
+ Set<String> blocks = RutaCheckerUtils.importScript(sRefName, IModelElement.METHOD,
+ project);
+ scripts.add(sRefName);
+ if (!blocks.isEmpty()) {
+ scriptsInnerBlocks.addAll(blocks);
+ }
+ } catch (Exception e) {
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+
+ private void importEngine(String name) {
+ engines.add(name);
+ int i = name.lastIndexOf('.');
+ if (i > 1) {
+ // TODO emit errors for doublettes (names in scripts and
+ // engines)
+ String lastPart = name.substring(i + 1);
+ if (lastPart != null && lastPart.length() != 0) {
+ engines.add(lastPart);
+ }
+ }
+ }
+
+ @Override
+ public boolean visit(Expression s) throws Exception {
+ if (s instanceof RutaAction) {
+ RutaAction action = (RutaAction) s;
+ if (action.getKind() == RutaActionConstants.A_CALL) {
+ // TODO see antlr grammar: no viable child defined!
+ if (action.getChilds().size() > 0) {
+ SimpleReference ref = (SimpleReference) action.getChilds().get(0);
+ if (ref != null && !engines.contains(ref.getName())) {
+ String required = ref.getName();
+ for (String script : scripts) {
+ // check direct script-call
+ boolean a = script.endsWith(required);
+ if (a) {
+ return false;
+ }
+ }
+ for (String block : scriptsInnerBlocks) {
+ boolean b = block.equals(required);
+ if (b) {
+ return false;
+ }
+ }
+ IProblem problem = problemFactory.createFileNotFoundProblem(ref);
+ rep.reportProblem(problem);
+ }
+ }
+ return false;
+ }
+ return true;
+ }
+ return true;
+ }
+
+ @Override
+ public boolean visit(MethodDeclaration s) throws Exception {
+ return true;
+ }
+
+ @Override
+ public boolean visit(TypeDeclaration s) throws Exception {
+ return false;
+ }
+ }
+
+ public RutaEngineAndCallChecker(IScriptProject project) throws CoreException {
+ this.project = project;
+ }
+
+ private IScriptProject project;
+
+ public boolean beginBuild(int buildType) {
+ return true;
+ }
+
+ public void endBuild(IProgressMonitor monitor) {
+ }
+
+ public void build(IBuildContext context) throws CoreException {
+ // getAST:
+ Object mdObj = context.get(IBuildContext.ATTR_MODULE_DECLARATION);
+ if (!(mdObj instanceof ModuleDeclaration)) {
+ return;
+ }
+ ModuleDeclaration md = (ModuleDeclaration) mdObj;
+ IProblemReporter problemReporter = context.getProblemReporter();
+ ISourceModule smod = context.getSourceModule();
+
+ // traverse:
+ ISourceLineTracker linetracker = context.getLineTracker();
+ String fileName = smod.getElementName();
+ try {
+ ASTVisitor visitor = new EngineAndCallCheckerVisitor(problemReporter, linetracker, fileName);
+ md.traverse(visitor);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
Added: uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaProblemIdentifier.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaProblemIdentifier.java?rev=1504047&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaProblemIdentifier.java (added)
+++ uima/sandbox/ruta/trunk/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/RutaProblemIdentifier.java Wed Jul 17 08:28:02 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.validator;
+
+import org.apache.uima.ruta.ide.RutaIdeUIPlugin;
+import org.eclipse.dltk.compiler.problem.IProblemIdentifier;
+
+public enum RutaProblemIdentifier implements IProblemIdentifier {
+
+ PROBLEM;
+
+ public String contributor() {
+ return RutaIdeUIPlugin.PLUGIN_ID;
+ }
+
+}