Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Struckmann2014-10-27 12:54:37 +0000
committerSebastian Struckmann2014-10-27 12:55:04 +0000
commit30c5412c978fdf9ba95865b7fa5bb69893d356ee (patch)
tree82c6cbe7346fdba951613f5ccfc4610f3acbbd2a /org.eclipse.jubula.client.api.converter.ui
parent9425ec8f0b6c69390b4a04049c821110ba6f1a68 (diff)
downloadorg.eclipse.jubula.core-30c5412c978fdf9ba95865b7fa5bb69893d356ee.tar.gz
org.eclipse.jubula.core-30c5412c978fdf9ba95865b7fa5bb69893d356ee.tar.xz
org.eclipse.jubula.core-30c5412c978fdf9ba95865b7fa5bb69893d356ee.zip
Sprint task - Java API - Added handler for converting a project; handler is only able to convert categories into directories
Diffstat (limited to 'org.eclipse.jubula.client.api.converter.ui')
-rw-r--r--org.eclipse.jubula.client.api.converter.ui/.checkstyle3
-rw-r--r--org.eclipse.jubula.client.api.converter.ui/META-INF/MANIFEST.MF12
-rw-r--r--org.eclipse.jubula.client.api.converter.ui/build.properties4
-rw-r--r--org.eclipse.jubula.client.api.converter.ui/icons/export.gifbin0 -> 587 bytes
-rw-r--r--org.eclipse.jubula.client.api.converter.ui/icons/export_disabled.gifbin0 -> 383 bytes
-rw-r--r--org.eclipse.jubula.client.api.converter.ui/plugin.xml58
-rw-r--r--org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/.keep0
-rw-r--r--org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/handlers/ConvertProjectHandler.java235
-rw-r--r--org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/i18n/Messages.java41
-rw-r--r--org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/i18n/messages.properties14
10 files changed, 364 insertions, 3 deletions
diff --git a/org.eclipse.jubula.client.api.converter.ui/.checkstyle b/org.eclipse.jubula.client.api.converter.ui/.checkstyle
index f69a865d7..e0a263bd7 100644
--- a/org.eclipse.jubula.client.api.converter.ui/.checkstyle
+++ b/org.eclipse.jubula.client.api.converter.ui/.checkstyle
@@ -4,4 +4,7 @@
<fileset name="all" enabled="true" check-config-name="Jubula" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
+ <filter name="FilesFromPackage" enabled="true">
+ <filter-data value="src/org/eclipse/jubula/client/api/converter/ui/i18n"/>
+ </filter>
</fileset-config>
diff --git a/org.eclipse.jubula.client.api.converter.ui/META-INF/MANIFEST.MF b/org.eclipse.jubula.client.api.converter.ui/META-INF/MANIFEST.MF
index 806b8ca12..7ca744a5a 100644
--- a/org.eclipse.jubula.client.api.converter.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.jubula.client.api.converter.ui/META-INF/MANIFEST.MF
@@ -4,7 +4,15 @@ Bundle-Name: Jubula API - Converter UI
Bundle-SymbolicName: org.eclipse.jubula.client.api.converter.ui;singleton:=true
Bundle-Version: 2.4.0.qualifier
Bundle-Vendor: Eclipse Jubula
-Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
- org.eclipse.jubula.client.api.converter;bundle-version="[2.4.0,2.5.0)"
+Require-Bundle: org.eclipse.jubula.tools;bundle-version="[2.4.0,2.5.0)",
+ org.eclipse.jface;bundle-version="[3.6.1,4.0.0)",
+ org.eclipse.ui.workbench;bundle-version="[3.6.1,4.0.0)",
+ org.eclipse.jubula.client.ui;bundle-version="[2.4.0,2.5.0)",
+ org.eclipse.core.runtime;bundle-version="[3.6.0,4.0.0)",
+ org.eclipse.core.commands;bundle-version="[3.6.0,4.0.0)",
+ org.eclipse.jubula.client.core;bundle-version="[2.4.0,2.5.0)",
+ org.eclipse.jubula.client.api.converter;bundle-version="[2.4.0,2.5.0)",
+ org.eclipse.jubula.rc.rcp.common,
+ org.eclipse.jubula.client.ui.rcp
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
diff --git a/org.eclipse.jubula.client.api.converter.ui/build.properties b/org.eclipse.jubula.client.api.converter.ui/build.properties
index 5cdc8bd2d..93f6b7619 100644
--- a/org.eclipse.jubula.client.api.converter.ui/build.properties
+++ b/org.eclipse.jubula.client.api.converter.ui/build.properties
@@ -9,4 +9,6 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
- about.html
+ about.html,\
+ plugin.xml,\
+ icons/
diff --git a/org.eclipse.jubula.client.api.converter.ui/icons/export.gif b/org.eclipse.jubula.client.api.converter.ui/icons/export.gif
new file mode 100644
index 000000000..8530e46ba
--- /dev/null
+++ b/org.eclipse.jubula.client.api.converter.ui/icons/export.gif
Binary files differ
diff --git a/org.eclipse.jubula.client.api.converter.ui/icons/export_disabled.gif b/org.eclipse.jubula.client.api.converter.ui/icons/export_disabled.gif
new file mode 100644
index 000000000..14872b983
--- /dev/null
+++ b/org.eclipse.jubula.client.api.converter.ui/icons/export_disabled.gif
Binary files differ
diff --git a/org.eclipse.jubula.client.api.converter.ui/plugin.xml b/org.eclipse.jubula.client.api.converter.ui/plugin.xml
new file mode 100644
index 000000000..b3316187d
--- /dev/null
+++ b/org.eclipse.jubula.client.api.converter.ui/plugin.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?><!--
+ Copyright (c) 2014 BREDEX GmbH.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+ -->
+
+<plugin>
+ <extension point="org.eclipse.ui.commands">
+ <command
+ categoryId="org.eclipse.jubula.client.ui.rcp.commands"
+ id="org.eclipse.jubula.client.api.converter.ui.commands.ConvertProjectCommand"
+ name="Convert project to Java for use in API" />
+ </extension>
+
+ <extension
+ id="ExportObjectMappingHandler"
+ name="ExportObjectMappingHandler"
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.jubula.client.api.converter.ui.handlers.ConvertProjectHandler"
+ commandId="org.eclipse.jubula.client.api.converter.ui.commands.ConvertProjectCommand">
+ <enabledWhen>
+ <with variable="org.eclipse.jubula.client.ui.rcp.variable.isProjectActive">
+ <equals value="true" />
+ </with>
+ </enabledWhen>
+ </handler>
+ </extension>
+
+ <extension point="org.eclipse.ui.menus">
+ <menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
+ <toolbar id="org.eclipse.jubula.client.ui.rcp.toolbar.ConvertProjectToolbar">
+ <separator
+ name="toolbar:org.eclipse.ui.main.toolbar.separatorConvert"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.jubula.client.api.converter.ui.commands.ConvertProjectCommand"
+ style="push">
+ <visibleWhen checkEnabled="false">
+ <reference
+ definitionId="org.eclipse.jubula.client.ui.rcp.expression.isTestPerspectiveActive" />
+ </visibleWhen>
+ </command>
+ </toolbar>
+ </menuContribution>
+ </extension>
+
+ <extension point="org.eclipse.ui.commandImages">
+ <image
+ commandId="org.eclipse.jubula.client.api.converter.ui.commands.ConvertProjectCommand"
+ disabledIcon="platform:/plugin/org.eclipse.jubula.client.api.converter.ui/icons/export_disabled.gif"
+ icon="platform:/plugin/org.eclipse.jubula.client.api.converter.ui/icons/export.gif" />
+ </extension>
+</plugin>
diff --git a/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/.keep b/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/.keep
deleted file mode 100644
index e69de29bb..000000000
--- a/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/.keep
+++ /dev/null
diff --git a/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/handlers/ConvertProjectHandler.java b/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/handlers/ConvertProjectHandler.java
new file mode 100644
index 000000000..6fca8ac06
--- /dev/null
+++ b/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/handlers/ConvertProjectHandler.java
@@ -0,0 +1,235 @@
+/*******************************************************************************
+ * Copyright (c) 2014 BREDEX GmbH.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * BREDEX GmbH - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.jubula.client.api.converter.ui.handlers;
+
+import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Iterator;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.window.Window;
+import org.eclipse.jubula.client.api.converter.ui.i18n.Messages;
+import org.eclipse.jubula.client.core.errorhandling.ErrorMessagePresenter;
+import org.eclipse.jubula.client.core.model.ICategoryPO;
+import org.eclipse.jubula.client.core.model.INodePO;
+import org.eclipse.jubula.client.core.model.IProjectPO;
+import org.eclipse.jubula.client.core.persistence.GeneralStorage;
+import org.eclipse.jubula.client.core.persistence.IExecPersistable;
+import org.eclipse.jubula.client.core.persistence.ISpecPersistable;
+import org.eclipse.jubula.client.ui.handlers.AbstractHandler;
+import org.eclipse.jubula.client.ui.rcp.utils.Utils;
+import org.eclipse.jubula.client.ui.utils.ErrorHandlingUtil;
+import org.eclipse.jubula.tools.internal.constants.StringConstants;
+import org.eclipse.jubula.tools.internal.exception.JBException;
+import org.eclipse.jubula.tools.internal.messagehandling.MessageIDs;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.PlatformUI;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author BREDEX GmbH
+ * @created 24.10.2014
+ */
+public class ConvertProjectHandler extends AbstractHandler {
+
+ /** the logger */
+ private static final Logger LOG = LoggerFactory
+ .getLogger(ConvertProjectHandler.class);
+
+ /** specific path for executables */
+ private static final String EXEC_PATH = "testsuites"; //$NON-NLS-1$
+
+ /** specific path for specifications */
+ private static final String SPEC_PATH = "testcases"; //$NON-NLS-1$
+
+ /** target path of conversion */
+ private static String genPath;
+
+ /** target package name space */
+ private static String genPackage;
+
+ /** the project */
+ private static IProjectPO project;
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object executeImpl(ExecutionEvent event) {
+
+ DirectoryDialog directoryDialog = createDirectoryDialog();
+ genPath = directoryDialog.open();
+ if (genPath != null) {
+ Utils.storeLastDirPath(directoryDialog.getFilterPath());
+ File directory = new File(genPath);
+ if (directory.list().length == 0) {
+ InputDialog inputDialog = new InputDialog(getActiveShell(),
+ Messages.InputDialogName, Messages.InputDialogMessage,
+ StringConstants.EMPTY, new PackageNameValidator());
+ if (inputDialog.open() == Window.OK) {
+ genPackage = inputDialog.getValue();
+ IWorkbench workbench = PlatformUI.getWorkbench();
+ try {
+ workbench.getProgressService().run(true, true,
+ new ConvertProjectOperation());
+ } catch (InvocationTargetException
+ | InterruptedException e) {
+ LOG.error(Messages.ErrorWhileConverting, e);
+ }
+ }
+ } else {
+ ErrorHandlingUtil.createMessageDialog(
+ MessageIDs.E_NON_EMPTY_DIRECTORY);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return a directory dialog
+ */
+ private DirectoryDialog createDirectoryDialog() {
+ DirectoryDialog directoryDialog =
+ new DirectoryDialog(getActiveShell(), SWT.SAVE);
+ String filterPath = Utils.getLastDirPath();
+ directoryDialog.setFilterPath(filterPath);
+ return directoryDialog;
+ }
+
+ /**
+ * @created 24.10.2014
+ */
+ private static class ConvertProjectOperation implements
+ IRunnableWithProgress {
+
+ /** {@inheritDoc} */
+ public void run(IProgressMonitor monitor) {
+ project = GeneralStorage.getInstance().getProject();
+ monitor.beginTask(NLS.bind(Messages.ConvertProjectTaskName,
+ project.getName()), IProgressMonitor.UNKNOWN);
+ String basePath = genPath + StringConstants.SLASH
+ + genPackage.replace(StringConstants.DOT,
+ StringConstants.SLASH);
+
+ if (project != null) {
+ for (IExecPersistable node : project.getExecObjCont()
+ .getExecObjList()) {
+ String path = basePath + StringConstants.SLASH
+ + EXEC_PATH + StringConstants.SLASH;
+ createFileOrDir(monitor, node, new File(path));
+ }
+ for (ISpecPersistable node : project.getSpecObjCont()
+ .getSpecObjList()) {
+ String path = basePath + StringConstants.SLASH
+ + SPEC_PATH + StringConstants.SLASH;
+ createFileOrDir(monitor, node, new File(path));
+ }
+ }
+ monitor.done();
+ }
+
+ /**
+ * Creates a file for a node and a folder with its content for a category
+ * @param monitor the monitor
+ * @param node the node
+ * @param parentDir the parent directory
+ */
+ private void createFileOrDir(IProgressMonitor monitor,
+ INodePO node, File parentDir) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ if (node instanceof ICategoryPO) {
+ ICategoryPO category = (ICategoryPO) node;
+ File dir = createDir(parentDir, category);
+ if (dir.exists()) {
+ String fqCategoryName = getFullyQualifiedName(category);
+ ErrorMessagePresenter.getPresenter().showErrorMessage(
+ new JBException(
+ NLS.bind(Messages.DuplicateCategory,
+ new String[] {fqCategoryName,
+ project.getName()}),
+ MessageIDs.E_DUPLICATE_CATEGORY),
+ new String [] {fqCategoryName},
+ null);
+ monitor.setCanceled(true);
+ return;
+ }
+ dir.mkdirs();
+
+ Iterator iterator = category.getNodeListIterator();
+ while (iterator.hasNext()) {
+ INodePO child = (INodePO) iterator.next();
+ if (child instanceof IExecPersistable) {
+ createFileOrDir(monitor, child, dir);
+ }
+ }
+ }
+ }
+
+ /**
+ * Creates a directory for a category with given parent directory
+ * @param parentDir the parent directory
+ * @param category the category
+ * @return the directory
+ */
+ private File createDir(File parentDir, ICategoryPO category) {
+ String dirPath = parentDir.getAbsolutePath() + StringConstants.SLASH
+ + category.getName();
+ File dir = new File(dirPath);
+ return dir;
+ }
+
+ /**
+ * Returns the fully qualified name of a node involving
+ * all of its super category names
+ * @param node the node
+ * @return the fully qualified name
+ */
+ private String getFullyQualifiedName(INodePO node) {
+ String name = node.getName();
+ INodePO parentNode = node.getParentNode();
+ if (parentNode != null) {
+ name = getFullyQualifiedName(parentNode)
+ + StringConstants.SLASH + name;
+ }
+ return name;
+ }
+ }
+
+ /**
+ * @created 27.10.2014
+ */
+ private static class PackageNameValidator implements IInputValidator {
+
+ /** {@inheritDoc} */
+ public String isValid(String newText) {
+ if (newText.isEmpty()) {
+ return Messages.NoPackageNameSpecified;
+ }
+ Pattern p = Pattern.compile(
+ "^[a-zA-Z_][\\w]*(\\.[a-zA-Z_][\\w]*)*$"); //$NON-NLS-1$
+ if (!p.matcher(newText).matches()) {
+ return Messages.InvalidPackageName;
+ }
+ return null;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/i18n/Messages.java b/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/i18n/Messages.java
new file mode 100644
index 000000000..b3a5ab0f0
--- /dev/null
+++ b/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/i18n/Messages.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2014 BREDEX GmbH.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * BREDEX GmbH - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+package org.eclipse.jubula.client.api.converter.ui.i18n;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author BREDEX GmbH
+ * @created 27.10.2014
+ */
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.eclipse.jubula.client.api.converter.ui.i18n.messages"; //$NON-NLS-1$
+
+ public static String ConvertProjectTaskName;
+ public static String DuplicateCategory;
+ public static String ErrorWhileConverting;
+ public static String InputDialogName;
+ public static String InputDialogMessage;
+ public static String InvalidPackageName;
+ public static String NoPackageNameSpecified;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ /**
+ * Constructor
+ */
+ private Messages() {
+ // hide
+ }
+}
diff --git a/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/i18n/messages.properties b/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/i18n/messages.properties
new file mode 100644
index 000000000..c72e9ae4e
--- /dev/null
+++ b/org.eclipse.jubula.client.api.converter.ui/src/org/eclipse/jubula/client/api/converter/ui/i18n/messages.properties
@@ -0,0 +1,14 @@
+###############################################################################
+# Copyright (c) 2014 BREDEX GmbH.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+ConvertProjectTaskName=Converting project "{0}".
+ErrorWhileConverting=Error while converting a project.
+DuplicateCategory=Duplicate category "{0}" occurred while converting the project "{1}".
+InputDialogName=Choose package name
+InputDialogMessage=Please type the name of the package which should be the target of the project conversion.
+InvalidPackageName=The given string is no valid package name.
+NoPackageNameSpecified=The given string must not be empty.

Back to the top