From 637422915df61b0222c15dbb27d0ab3b3efdc4ec Mon Sep 17 00:00:00 2001 From: Joel Latino Date: Fri, 14 Nov 2014 01:45:01 +0000 Subject: [PATCH] First commit --- README.md | 6 +- checkstyle.xml | 315 +++++ pom.xml | 124 ++ resources/version.xml | 2 + src/assembly/bin.xml | 36 + .../di/trans/steps/git/GitCommandType.java | 89 ++ .../trans/steps/git/command/GitCommand.java | 23 + .../steps/git/command/GitCommandFactory.java | 157 +++ .../steps/git/command/GitInfoCommand.java | 32 + .../git/command/GitOperationsCommand.java | 25 + .../steps/git/command/impl/AddGitCommand.java | 176 +++ .../git/command/impl/CheckoutGitCommand.java | 253 ++++ .../git/command/impl/CloneGitCommand.java | 214 ++++ .../git/command/impl/CommitGitCommand.java | 346 +++++ .../command/impl/CurrentBranchGitCommand.java | 162 +++ .../git/command/impl/InitGitCommand.java | 136 ++ .../command/impl/ListBranchsGitCommand.java | 495 ++++++++ .../git/command/impl/ListTagsGitCommand.java | 459 +++++++ .../steps/git/command/impl/LogGitCommand.java | 561 +++++++++ .../git/command/impl/PullGitCommand.java | 151 +++ .../git/command/impl/PushGitCommand.java | 344 +++++ .../steps/git/command/impl/TagGitCommand.java | 254 ++++ .../steps/git/command/impl/package-info.java | 8 + .../trans/steps/git/command/package-info.java | 8 + .../git/dialog/BaseGitCommandDialog.java | 16 + .../git/dialog/GitCommandDialogFactory.java | 57 + .../trans/steps/git/dialog/package-info.java | 8 + .../di/trans/steps/git/info/GitInfoStep.java | 182 +++ .../trans/steps/git/info/GitInfoStepData.java | 31 + .../steps/git/info/GitInfoStepDialog.java | 1115 +++++++++++++++++ .../trans/steps/git/info/GitInfoStepMeta.java | 380 ++++++ .../impl/ListBranchsGitCommandDialog.java | 182 +++ .../info/dialog/impl/LogGitCommandDialog.java | 257 ++++ .../git/info/dialog/impl/package-info.java | 8 + .../di/trans/steps/git/info/package-info.java | 8 + .../git/operations/GitOperationsStep.java | 182 +++ .../git/operations/GitOperationsStepData.java | 30 + .../operations/GitOperationsStepDialog.java | 596 +++++++++ .../git/operations/GitOperationsStepMeta.java | 304 +++++ .../dialog/impl/AddGitCommandDialog.java | 202 +++ .../dialog/impl/CheckoutGitCommandDialog.java | 260 ++++ .../dialog/impl/CloneGitCommandDialog.java | 232 ++++ .../dialog/impl/CommitGitCommandDialog.java | 327 +++++ .../dialog/impl/InitGitCommandDialog.java | 168 +++ .../dialog/impl/PullGitCommandDialog.java | 168 +++ .../dialog/impl/PushGitCommandDialog.java | 318 +++++ .../dialog/impl/TagGitCommandDialog.java | 263 ++++ .../operations/dialog/impl/package-info.java | 8 + .../steps/git/operations/package-info.java | 8 + .../di/trans/steps/git/package-info.java | 8 + .../impl/messages/messages_en_US.properties | 140 +++ .../di/trans/steps/git/info/GitInfoStep.png | Bin 0 -> 1589 bytes .../impl/messages/messages_en_US.properties | 14 + .../di/trans/steps/git/info/ivyis_logo.png | Bin 0 -> 1214 bytes .../info/messages/messages_en_US.properties | 77 ++ .../git/messages/messages_en_US.properties | 14 + .../git/operations/GitOperationsStep.png | Bin 0 -> 1423 bytes .../impl/messages/messages_en_US.properties | 58 + .../impl/messages/messages_en_US.properties | 63 + .../trans/steps/git/operations/ivyis_logo.png | Bin 0 -> 1214 bytes .../messages/messages_en_US.properties | 99 ++ 61 files changed, 10157 insertions(+), 2 deletions(-) create mode 100644 checkstyle.xml create mode 100644 pom.xml create mode 100644 resources/version.xml create mode 100644 src/assembly/bin.xml create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/GitCommandType.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/GitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/GitCommandFactory.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/GitInfoCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/GitOperationsCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/AddGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/CheckoutGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/CloneGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/CommitGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/CurrentBranchGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/InitGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/ListBranchsGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/ListTagsGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/LogGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/PullGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/PushGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/TagGitCommand.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/impl/package-info.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/command/package-info.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/dialog/BaseGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/dialog/GitCommandDialogFactory.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/dialog/package-info.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStep.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepData.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepMeta.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/ListBranchsGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/LogGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/package-info.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/info/package-info.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStep.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepData.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepMeta.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/AddGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CheckoutGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CloneGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CommitGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/InitGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/PullGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/PushGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/TagGitCommandDialog.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/package-info.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/operations/package-info.java create mode 100644 src/main/java/com/ivyis/di/trans/steps/git/package-info.java create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/command/impl/messages/messages_en_US.properties create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/info/GitInfoStep.png create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/info/dialog/impl/messages/messages_en_US.properties create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/info/ivyis_logo.png create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/info/messages/messages_en_US.properties create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/messages/messages_en_US.properties create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/operations/GitOperationsStep.png create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/operations/command/impl/messages/messages_en_US.properties create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/operations/dialog/impl/messages/messages_en_US.properties create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/operations/ivyis_logo.png create mode 100644 src/main/resources/com/ivyis/di/trans/steps/git/operations/messages/messages_en_US.properties diff --git a/README.md b/README.md index b3f9e63..0d8a377 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -ivy-pdi-git-steps +Ivy PDI Git Steps ================= -Pentaho data integration plugin for repositories git +Pentaho Data Integration plugin for Git repositories + + diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000..c4443f9 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,315 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..37bdcae --- /dev/null +++ b/pom.xml @@ -0,0 +1,124 @@ + + 4.0.0 + + com.ivyis.di.trans.steps.git + ivy-pdi-git-steps + 1.0.0 + Ivy Information Systems Git steps plugin. + 2014 + + + MIT + http://opensource.org/licenses/MIT + + + + IvyGitSteps + 1.5 + 1.5 + UTF-8 + 5.0.2 + 4.4.3.1 + + + + + junit + junit + 3.8.1 + test + + + + pentaho-kettle + kettle-core + ${kettle.version} + + + pentaho-kettle + kettle-db + ${kettle.db.version} + + + pentaho-kettle + kettle-engine + ${kettle.version} + + + pentaho-kettle + kettle-dbdialog + ${kettle.version} + + + pentaho-kettle + kettle-ui-swt + ${kettle.version} + + + org.eclipse.jgit + org.eclipse.jgit + 3.2.0.201312181205-r + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + package + + checkstyle + + + + check + + check + + + + + checkstyle.xml + + + + org.apache.maven.plugins + maven-assembly-plugin + + src/assembly/bin.xml + ${plugin.name} + + + + package + + single + + + + + + + + + + jgit-repository + https://repo.eclipse.org/content/groups/releases/ + + + PentahoRepo + Pentaho repository + http://repo.pentaho.org/artifactory/repo + default + + true + never + warn + + + + diff --git a/resources/version.xml b/resources/version.xml new file mode 100644 index 0000000..e3f3939 --- /dev/null +++ b/resources/version.xml @@ -0,0 +1,2 @@ + +1.0.0 \ No newline at end of file diff --git a/src/assembly/bin.xml b/src/assembly/bin.xml new file mode 100644 index 0000000..5dd8c1d --- /dev/null +++ b/src/assembly/bin.xml @@ -0,0 +1,36 @@ + + + dir + zip + + false + + + + org.eclipse.jgit:org.eclipse.jgit + + false + runtime + ${plugin.name}/lib + + + + + resources + ${plugin.name} + + version.xml + + + + target + ${plugin.name} + + ivy-pdi-git-steps-*.jar + + + + diff --git a/src/main/java/com/ivyis/di/trans/steps/git/GitCommandType.java b/src/main/java/com/ivyis/di/trans/steps/git/GitCommandType.java new file mode 100644 index 0000000..33ecca6 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/GitCommandType.java @@ -0,0 +1,89 @@ +package com.ivyis.di.trans.steps.git; + +import org.pentaho.di.i18n.BaseMessages; + +/** + * Emun of Git commands allowed in PDI. + * + * @author Joel Latino + * @since 1.0.0 + */ +public enum GitCommandType { + CURRENT_BRANCH("currentBranch", false), LIST_BRANCHS("listBranchs", false), LIST_TAGS( + "listTags", false), LOG("log", false), INIT("init", true), ADD( + "add", true), CLONE("clone", true), COMMIT("commit", true), PULL( + "pull", true), PUSH("push", true), TAG("tag", true), CHECKOUT( + "checkout", true); + + /** for i18n purposes. **/ + private static final Class PKG = GitCommandType.class; + private static final int INFO_COMMANDS_NUMBER = 4; + private static final int OPERATION_COMMANDS_NUMBER = 8; + + private final String operationName; + private final boolean operations; + + public String getOperationName() { + return operationName; + } + + public boolean isOperations() { + return operations; + } + + public String getOperationLabel() { + return BaseMessages.getString(PKG, "Git." + operationName + ".Label"); + } + + private GitCommandType(String operationName, boolean operations) { + this.operationName = operationName; + this.operations = operations; + } + + public static GitCommandType fromValue(final String value) { + for (GitCommandType type : GitCommandType.values()) { + if (type.getOperationName().equalsIgnoreCase(value)) { + return type; + } + } + return null; + } + + public static GitCommandType fromLabel(final String label) { + if (label == null) { + return null; + } + for (GitCommandType type : GitCommandType.values()) { + if (BaseMessages.getString(PKG, + "Git." + type.getOperationName() + ".Label") + .equalsIgnoreCase(label)) { + return type; + } + } + return null; + } + + public static String[] getOperationTypesLabel() { + int i = 0; + final String[] gitOperationTypeLabels = new String[OPERATION_COMMANDS_NUMBER]; + for (GitCommandType type : GitCommandType.values()) { + if (type.isOperations()) { + gitOperationTypeLabels[i++] = BaseMessages.getString(PKG, + "Git." + type.getOperationName() + ".Label"); + } + } + return gitOperationTypeLabels; + } + + public static String[] getInfoTypesLabel() { + int i = 0; + final String[] gitOperationTypeLabels = new String[INFO_COMMANDS_NUMBER]; + for (GitCommandType type : GitCommandType.values()) { + if (!type.isOperations()) { + gitOperationTypeLabels[i++] = BaseMessages.getString(PKG, + "Git." + type.getOperationName() + ".Label"); + } + } + return gitOperationTypeLabels; + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/GitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/GitCommand.java new file mode 100644 index 0000000..48409e2 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/GitCommand.java @@ -0,0 +1,23 @@ +package com.ivyis.di.trans.steps.git.command; + +import com.ivyis.di.trans.steps.git.GitCommandType; + +/** + * Interface responsible for describe the methods of Git commands. + * + * @author Joel Latino + * @since 1.0.0 + */ +public interface GitCommand { + + static final String MAIN_NODE = "commandProperties"; + static final String COMMAND_NAME_NODE = "commandName"; + static final String DATE_FORMAT = "yyyy/MM/dd HH:mm:ss.SSS"; + + String getDescription(); + + String getXML(); + + GitCommandType getCommandType(); + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/GitCommandFactory.java b/src/main/java/com/ivyis/di/trans/steps/git/command/GitCommandFactory.java new file mode 100644 index 0000000..e3968bd --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/GitCommandFactory.java @@ -0,0 +1,157 @@ +package com.ivyis.di.trans.steps.git.command; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.pentaho.di.core.exception.KettleException; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.impl.AddGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.CheckoutGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.CloneGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.CommitGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.CurrentBranchGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.InitGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.ListBranchsGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.ListTagsGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.LogGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.PullGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.PushGitCommand; +import com.ivyis.di.trans.steps.git.command.impl.TagGitCommand; + +/** + * Git command factory. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class GitCommandFactory { + private static final Logger LOGGER = Logger + .getLogger(GitCommandFactory.class); + + public static GitCommand getGitCommand(String xml, String stepName) + throws ParserConfigurationException, SAXException, IOException { + final InputStream sbis = new ByteArrayInputStream(xml.getBytes("UTF-8")); + + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(false); + final DocumentBuilder db = dbf.newDocumentBuilder(); + final Document doc = db.parse(sbis); + + return getGitCommand(doc, stepName); + } + + public static GitCommand getGitCommand(Node node, String stepName) { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + final XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/" + GitCommand.COMMAND_NAME_NODE + "/text()"); + + final String commandName = (String) xPathExpr.evaluate(node, + XPathConstants.STRING); + + switch (GitCommandType.fromValue(commandName)) { + case LIST_BRANCHS: + return new ListBranchsGitCommand(node, stepName); + case LIST_TAGS: + return new ListTagsGitCommand(node, stepName); + case LOG: + return new LogGitCommand(node, stepName); + case CLONE: + return new CloneGitCommand(node, stepName); + case ADD: + return new AddGitCommand(node, stepName); + case COMMIT: + return new CommitGitCommand(node, stepName); + case INIT: + return new InitGitCommand(node, stepName); + case PULL: + return new PullGitCommand(node, stepName); + case PUSH: + return new PushGitCommand(node, stepName); + case TAG: + return new TagGitCommand(node, stepName); + case CHECKOUT: + return new CheckoutGitCommand(node, stepName); + case CURRENT_BRANCH: + return new CurrentBranchGitCommand(node, stepName); + default: + break; + } + + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + } + return null; + } + + public static GitInfoCommand getGitCommand(GitCommandType gitCommandType, + Map configFields) throws KettleException { + try { + switch (gitCommandType) { + case LIST_BRANCHS: + return new ListBranchsGitCommand(configFields); + case LIST_TAGS: + return new ListTagsGitCommand(configFields); + case LOG: + return new LogGitCommand(configFields); + case CURRENT_BRANCH: + return new CurrentBranchGitCommand(configFields); + default: + break; + } + + } catch (Exception e) { + throw new KettleException(e); + } + return null; + } + + public static GitOperationsCommand getGitCommand( + GitCommandType gitCommandType, String description) + throws KettleException { + try { + switch (gitCommandType) { + case CLONE: + return new CloneGitCommand(description); + case ADD: + return new AddGitCommand(description); + case COMMIT: + return new CommitGitCommand(description); + case INIT: + return new InitGitCommand(description); + case PULL: + return new PullGitCommand(description); + case PUSH: + return new PushGitCommand(description); + case TAG: + return new TagGitCommand(description); + case CHECKOUT: + return new CheckoutGitCommand(description); + default: + break; + } + + } catch (Exception e) { + throw new KettleException(e); + } + return null; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/GitInfoCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/GitInfoCommand.java new file mode 100644 index 0000000..7c3c6ac --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/GitInfoCommand.java @@ -0,0 +1,32 @@ +package com.ivyis.di.trans.steps.git.command; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidRemoteException; +import org.eclipse.jgit.api.errors.TransportException; +import org.eclipse.jgit.transport.CredentialsProvider; + +import com.ivyis.di.trans.steps.git.info.GitInfoStep; + +/** + * Interface responsible for Git commands that extract information from the repository. + * + * @author Joel Latino + * @since 1.0.0 + */ +public interface GitInfoCommand extends GitCommand { + + List call(final GitInfoStep gitInfoStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws InvalidRemoteException, TransportException, GitAPIException, + IllegalArgumentException, IOException; + + Map getConfigFields(boolean mainConfigFields); + + boolean isConfigurable(); +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/GitOperationsCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/GitOperationsCommand.java new file mode 100644 index 0000000..98c32c8 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/GitOperationsCommand.java @@ -0,0 +1,25 @@ +package com.ivyis.di.trans.steps.git.command; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.NoFilepatternException; +import org.eclipse.jgit.transport.CredentialsProvider; + +import com.ivyis.di.trans.steps.git.operations.GitOperationsStep; + +/** + * Interface that describes the methods of Git operations commands. + * + * @author Joel Latino + * @since 1.0.0 + */ +public interface GitOperationsCommand extends GitCommand { + + Git call(final GitOperationsStep gitOperationsStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolderPath) + throws IllegalArgumentException, IOException, + NoFilepatternException, GitAPIException; +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/AddGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/AddGitCommand.java new file mode 100644 index 0000000..9f5aff5 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/AddGitCommand.java @@ -0,0 +1,176 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.AddCommand; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.NoFilepatternException; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.Const; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.i18n.BaseMessages; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitOperationsCommand; +import com.ivyis.di.trans.steps.git.operations.GitOperationsStep; + +/** + * Add Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class AddGitCommand implements GitOperationsCommand { + private static final Class PKG = AddGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + + private String filepattern; + private boolean update; + + public AddGitCommand() {} + + public AddGitCommand(String description) { + if ("".equals(description)) { + throw new IllegalArgumentException("Unkomnown config fields."); + } + final String[] stringProps = description.split(" / "); + for (String stringProp : stringProps) { + if (BaseMessages.getString(PKG, "Git.FilePattern.Label").equals( + stringProp.split(":")[0].trim())) { + this.filepattern = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.Update.Label").equals( + stringProp.split(":")[0].trim())) { + this.update = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } + } + } + + public AddGitCommand(Node xml, String stepName) throws KettleException { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/filepattern/text()"); + this.filepattern = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/update/text()"); + this.update = Boolean.parseBoolean((String) xPathExpr.evaluate(xml, + XPathConstants.STRING)); + + } catch (XPathExpressionException e) { + throw new KettleException(e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.FilePattern.Label") + ": " + + (filepattern == null ? "" : filepattern) + " / " + + BaseMessages.getString(PKG, "Git.Update.Label") + ": " + + update; + } + + public GitCommandType getCommandType() { + return GitCommandType.ADD; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc.createTextNode(GitCommandType.ADD + .getOperationName())); + root.appendChild(commandName); + + final Element filepatternNode = doc.createElement("filepattern"); + filepatternNode.appendChild(doc.createTextNode(filepattern)); + root.appendChild(filepatternNode); + + final Element updateNode = doc.createElement("update"); + updateNode.appendChild(doc.createTextNode(String.valueOf(update))); + root.appendChild(updateNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public Git call(final GitOperationsStep gitOperationsStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws IllegalArgumentException, IOException, + NoFilepatternException, GitAPIException { + + AddCommand ac = git.add(); + + if (!Const.isEmpty(this.filepattern)) { + ac = ac.addFilepattern(gitOperationsStep + .environmentSubstitute(this.filepattern)); + } + + ac.setUpdate(update).call(); + return git; + } + + public String getFilepattern() { + return filepattern; + } + + public void setFilepattern(String filepattern) { + this.filepattern = filepattern; + } + + public boolean isUpdate() { + return update; + } + + public void setUpdate(boolean update) { + this.update = update; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CheckoutGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CheckoutGitCommand.java new file mode 100644 index 0000000..b4b5b6a --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CheckoutGitCommand.java @@ -0,0 +1,253 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.CheckoutCommand; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.NoFilepatternException; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.Const; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.i18n.BaseMessages; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitOperationsCommand; +import com.ivyis.di.trans.steps.git.operations.GitOperationsStep; + +/** + * Checkout Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class CheckoutGitCommand implements GitOperationsCommand { + private static final Class PKG = CheckoutGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + + private String path; + private String name; + private String startPoint; + private boolean allPaths; + private boolean force; + + public CheckoutGitCommand() {} + + public CheckoutGitCommand(String description) { + if ("".equals(description)) { + throw new IllegalArgumentException("Unkomnown config fields."); + } + final String[] stringProps = description.split(" / "); + for (String stringProp : stringProps) { + if (BaseMessages.getString(PKG, "Git.Path.Label").equals( + stringProp.split(":")[0].trim())) { + this.path = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.Name.Label").equals( + stringProp.split(":")[0].trim())) { + this.name = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.StartPoint.Label") + .equals(stringProp.split(":")[0].trim())) { + this.startPoint = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.AllPaths.Label") + .equals(stringProp.split(":")[0].trim())) { + this.allPaths = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } else if (BaseMessages.getString(PKG, "Git.Force.Label").equals( + stringProp.split(":")[0].trim())) { + this.force = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } + } + } + + public CheckoutGitCommand(Node xml, String stepName) throws KettleException { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/path/text()"); + this.path = (String) xPathExpr.evaluate(xml, XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/name/text()"); + this.name = (String) xPathExpr.evaluate(xml, XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/startPoint/text()"); + this.startPoint = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/allPaths/text()"); + this.allPaths = Boolean.parseBoolean((String) xPathExpr.evaluate( + xml, XPathConstants.STRING)); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/force/text()"); + this.force = Boolean.parseBoolean((String) xPathExpr.evaluate(xml, + XPathConstants.STRING)); + } catch (XPathExpressionException e) { + throw new KettleException(e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.Path.Label") + ": " + + (path == null ? "" : path) + " / " + + BaseMessages.getString(PKG, "Git.Name.Label") + ": " + + (name == null ? "" : name) + " / " + + BaseMessages.getString(PKG, "Git.StartPoint.Label") + ": " + + (startPoint == null ? "" : startPoint) + " / " + + BaseMessages.getString(PKG, "Git.AllPaths.Label") + ": " + + allPaths + " / " + + BaseMessages.getString(PKG, "Git.Force.Label") + ": " + force; + } + + public GitCommandType getCommandType() { + return GitCommandType.CHECKOUT; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc.createTextNode(GitCommandType.CHECKOUT + .getOperationName())); + root.appendChild(commandName); + + final Element pathNode = doc.createElement("path"); + pathNode.appendChild(doc.createTextNode(path)); + root.appendChild(pathNode); + + final Element nameNode = doc.createElement("name"); + nameNode.appendChild(doc.createTextNode(name)); + root.appendChild(nameNode); + + final Element startPointNode = doc.createElement("startPoint"); + startPointNode.appendChild(doc.createTextNode(startPoint)); + root.appendChild(startPointNode); + + final Element allPathsNode = doc.createElement("allPaths"); + allPathsNode.appendChild(doc.createTextNode(String + .valueOf(allPaths))); + root.appendChild(allPathsNode); + + final Element forceNode = doc.createElement("force"); + forceNode.appendChild(doc.createTextNode(String.valueOf(force))); + root.appendChild(forceNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public Git call(final GitOperationsStep gitOperationsStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws IllegalArgumentException, IOException, + NoFilepatternException, GitAPIException { + + CheckoutCommand cc = git.checkout().setAllPaths(this.allPaths) + .setForce(this.force); + if (!Const.isEmpty(this.path)) { + cc = cc.addPath(gitOperationsStep.environmentSubstitute(this.path)); + } + if (!Const.isEmpty(this.name)) { + cc = cc.setName(gitOperationsStep.environmentSubstitute(this.name)); + } + if (!Const.isEmpty(this.startPoint)) { + cc = cc.setStartPoint(gitOperationsStep + .environmentSubstitute(this.startPoint)); + } + + cc.call(); + + return git; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getStartPoint() { + return startPoint; + } + + public void setStartPoint(String startPoint) { + this.startPoint = startPoint; + } + + public boolean isAllPaths() { + return allPaths; + } + + public void setAllPaths(boolean allPaths) { + this.allPaths = allPaths; + } + + public boolean isForce() { + return force; + } + + public void setForce(boolean force) { + this.force = force; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CloneGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CloneGitCommand.java new file mode 100644 index 0000000..c52dc8f --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CloneGitCommand.java @@ -0,0 +1,214 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.CloneCommand; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidRemoteException; +import org.eclipse.jgit.api.errors.TransportException; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitOperationsCommand; +import com.ivyis.di.trans.steps.git.operations.GitOperationsStep; + +/** + * Clone Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class CloneGitCommand implements GitOperationsCommand { + private static final Class PKG = CloneGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + + private String branchName; + private boolean cloneSubModules; + private boolean cloneAllBranches; + + public CloneGitCommand() {} + + public CloneGitCommand(String description) { + if ("".equals(description)) { + throw new IllegalArgumentException("Unkomnown config fields."); + } + final String[] stringProps = description.split(" / "); + for (String stringProp : stringProps) { + if (BaseMessages.getString(PKG, "Git.BranchField.Label").equals( + stringProp.split(":")[0].trim())) { + this.branchName = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, + "Git.CloneSubModulesField.Label").equals( + stringProp.split(":")[0].trim())) { + this.cloneSubModules = Boolean.parseBoolean(stringProp + .split(":")[1].trim()); + } else if (BaseMessages.getString(PKG, + "Git.CloneAllBranchesField.Label").equals( + stringProp.split(":")[0].trim())) { + this.cloneAllBranches = Boolean.parseBoolean(stringProp + .split(":")[1].trim()); + } + } + } + + public CloneGitCommand(Node xml, String stepName) { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/branchName/text()"); + this.branchName = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/cloneSubModules/text()"); + this.cloneSubModules = Boolean.parseBoolean((String) xPathExpr + .evaluate(xml, XPathConstants.STRING)); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/cloneAllBranches/text()"); + this.cloneAllBranches = Boolean.parseBoolean((String) xPathExpr + .evaluate(xml, XPathConstants.STRING)); + + } catch (XPathExpressionException e) { + LOGGER.error(e.getMessage(), e); + } + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc.createTextNode(GitCommandType.CLONE + .getOperationName())); + root.appendChild(commandName); + + final Element branchNameNode = doc.createElement("branchName"); + branchNameNode.appendChild(doc.createTextNode(branchName)); + root.appendChild(branchNameNode); + + final Element cloneSubModulesNode = doc + .createElement("cloneSubModules"); + cloneSubModulesNode.appendChild(doc.createTextNode(String + .valueOf(cloneSubModules))); + root.appendChild(cloneSubModulesNode); + + final Element cloneAllBranchesNode = doc + .createElement("cloneAllBranches"); + cloneAllBranchesNode.appendChild(doc.createTextNode(String + .valueOf(cloneAllBranches))); + root.appendChild(cloneAllBranchesNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public Git call(final GitOperationsStep gitOperationsStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws InvalidRemoteException, TransportException, GitAPIException { + + CloneCommand cc = Git.cloneRepository().setURI(gitRepoUrl) + .setDirectory(gitRepoFolder); + + if (!Const.isEmpty(this.branchName)) { + cc = cc.setBranch(gitOperationsStep + .environmentSubstitute(this.branchName)); + } + cc.setCloneAllBranches(this.cloneAllBranches).setCloneSubmodules( + this.cloneSubModules); + if (cp != null) { + cc.setCredentialsProvider(cp); + } + return cc.setBare(false).call(); + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.BranchField.Label") + + ": " + + (branchName == null ? "" : branchName) + + " / " + + BaseMessages.getString(PKG, "Git.CloneSubModulesField.Label") + + ": " + + cloneSubModules + + " / " + + BaseMessages + .getString(PKG, "Git.CloneAllBranchesField.Label") + + ": " + cloneAllBranches; + } + + public String getBranchName() { + return branchName; + } + + public void setBranchName(String branchName) { + this.branchName = branchName; + } + + public boolean isCloneSubModules() { + return cloneSubModules; + } + + public void setCloneSubModules(boolean cloneSubModules) { + this.cloneSubModules = cloneSubModules; + } + + public boolean isCloneAllBranches() { + return cloneAllBranches; + } + + public void setCloneAllBranches(boolean cloneAllBranches) { + this.cloneAllBranches = cloneAllBranches; + } + + public GitCommandType getCommandType() { + return GitCommandType.CLONE; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CommitGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CommitGitCommand.java new file mode 100644 index 0000000..29d3d1b --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CommitGitCommand.java @@ -0,0 +1,346 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.CommitCommand; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.NoHeadException; +import org.eclipse.jgit.api.errors.NoMessageException; +import org.eclipse.jgit.api.errors.UnmergedPathsException; +import org.eclipse.jgit.api.errors.WrongRepositoryStateException; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitOperationsCommand; +import com.ivyis.di.trans.steps.git.operations.GitOperationsStep; + +/** + * Commit Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class CommitGitCommand implements GitOperationsCommand { + private static final Class PKG = CommitGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + + private String authorName; + private String authorEmail; + private String committerName; + private String committerEmail; + private String commitMessage; + private boolean amend; + private boolean insertChangeId; + private boolean all; + + public CommitGitCommand() {} + + public CommitGitCommand(String description) { + if ("".equals(description)) { + throw new IllegalArgumentException("Unkomnown config fields."); + } + final String[] stringProps = description.split(" / "); + for (String stringProp : stringProps) { + final String prop = stringProp.split(":")[0].trim(); + if (BaseMessages.getString(PKG, "Git.AuthorName.Label") + .equals(prop)) { + this.authorName = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.AuthorEmail.Label") + .equals(prop)) { + this.authorEmail = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.CommitterName.Label") + .equals(prop)) { + this.committerName = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.CommitterEmail.Label") + .equals(prop)) { + this.committerEmail = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.CommitMessage.Label") + .equals(prop)) { + this.commitMessage = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.Amend.Label").equals( + prop)) { + this.amend = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } else if (BaseMessages.getString(PKG, "Git.InsertChangeId.Label") + .equals(prop)) { + this.insertChangeId = Boolean.parseBoolean(stringProp + .split(":")[1].trim()); + } else if (BaseMessages.getString(PKG, "Git.All.Label") + .equals(prop)) { + this.all = Boolean + .parseBoolean(stringProp.split(":")[1].trim()); + } + } + } + + public CommitGitCommand(Node xml, String stepName) { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/authorName/text()"); + this.authorName = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/authorEmail/text()"); + this.authorEmail = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/committerName/text()"); + this.committerName = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/committerEmail/text()"); + this.committerEmail = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitMessage/text()"); + this.commitMessage = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/amend/text()"); + this.amend = Boolean.parseBoolean((String) xPathExpr.evaluate(xml, + XPathConstants.STRING)); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/insertChangeId/text()"); + this.insertChangeId = Boolean.parseBoolean((String) xPathExpr + .evaluate(xml, XPathConstants.STRING)); + + xPathExpr = xpath + .compile("//step[name='" + stepName + "']/gitCommands//" + + GitCommand.MAIN_NODE + "/all/text()"); + this.all = Boolean.parseBoolean((String) xPathExpr.evaluate(xml, + XPathConstants.STRING)); + + } catch (XPathExpressionException e) { + LOGGER.error(e.getMessage(), e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.AuthorName.Label") + ": " + + (authorName == null ? "" : authorName) + " / " + + BaseMessages.getString(PKG, "Git.AuthorEmail.Label") + ": " + + (authorEmail == null ? "" : authorEmail) + " / " + + BaseMessages.getString(PKG, "Git.CommitterName.Label") + ": " + + (committerName == null ? "" : committerName) + " / " + + BaseMessages.getString(PKG, "Git.CommitterEmail.Label") + + ": " + (committerEmail == null ? "" : committerEmail) + " / " + + BaseMessages.getString(PKG, "Git.CommitMessage.Label") + ": " + + (commitMessage == null ? "" : commitMessage) + " / " + + BaseMessages.getString(PKG, "Git.Amend.Label") + ": " + amend + + " / " + + BaseMessages.getString(PKG, "Git.InsertChangeId.Label") + + ": " + insertChangeId + " / " + + BaseMessages.getString(PKG, "Git.All.Label") + ": " + all + + " / "; + } + + public GitCommandType getCommandType() { + return GitCommandType.COMMIT; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc.createTextNode(GitCommandType.COMMIT + .getOperationName())); + root.appendChild(commandName); + + final Element authorNameNode = doc.createElement("authorName"); + authorNameNode.appendChild(doc.createTextNode(authorName)); + root.appendChild(authorNameNode); + + final Element authorEmailNode = doc.createElement("authorEmail"); + authorEmailNode.appendChild(doc.createTextNode(authorEmail)); + root.appendChild(authorEmailNode); + + final Element committerNameNode = doc + .createElement("committerName"); + committerNameNode.appendChild(doc.createTextNode(committerName)); + root.appendChild(committerNameNode); + + final Element committerEmailNode = doc + .createElement("committerEmail"); + committerEmailNode.appendChild(doc.createTextNode(committerEmail)); + root.appendChild(committerEmailNode); + + final Element commitMessageNode = doc + .createElement("commitMessage"); + commitMessageNode.appendChild(doc.createTextNode(commitMessage)); + root.appendChild(commitMessageNode); + + final Element amendNode = doc.createElement("amend"); + amendNode.appendChild(doc.createTextNode(String.valueOf(amend))); + root.appendChild(amendNode); + + final Element insertChangeIdNode = doc + .createElement("insertChangeId"); + insertChangeIdNode.appendChild(doc.createTextNode(String + .valueOf(insertChangeId))); + root.appendChild(insertChangeIdNode); + + final Element allNode = doc.createElement("all"); + allNode.appendChild(doc.createTextNode(String.valueOf(all))); + root.appendChild(allNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public Git call(final GitOperationsStep gitOperationsStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws IllegalArgumentException, IOException, NoHeadException, + NoMessageException, UnmergedPathsException, + ConcurrentRefUpdateException, WrongRepositoryStateException, + GitAPIException { + CommitCommand cc = git + .commit() + .setAuthor( + gitOperationsStep + .environmentSubstitute(this.authorName == null ? "" + : this.authorName), + gitOperationsStep + .environmentSubstitute(this.authorEmail == null ? "" + : this.authorEmail)) + .setCommitter( + gitOperationsStep + .environmentSubstitute(this.committerName == null ? "" + : this.committerName), + gitOperationsStep + .environmentSubstitute(this.committerEmail == null ? "" + : this.committerName)); + + if (!Const.isEmpty(this.commitMessage)) { + cc = cc.setMessage(gitOperationsStep + .environmentSubstitute(this.commitMessage)); + } + cc.setAll(all).setInsertChangeId(insertChangeId).setAmend(amend).call(); + return git; + } + + public String getAuthorName() { + return authorName; + } + + public void setAuthorName(String authorName) { + this.authorName = authorName; + } + + public String getAuthorEmail() { + return authorEmail; + } + + public void setAuthorEmail(String authorEmail) { + this.authorEmail = authorEmail; + } + + public String getCommitterName() { + return committerName; + } + + public void setCommitterName(String committerName) { + this.committerName = committerName; + } + + public String getCommitterEmail() { + return committerEmail; + } + + public void setCommitterEmail(String committerEmail) { + this.committerEmail = committerEmail; + } + + public String getCommitMessage() { + return commitMessage; + } + + public void setCommitMessage(String commitMessage) { + this.commitMessage = commitMessage; + } + + public boolean isAmend() { + return amend; + } + + public void setAmend(boolean amend) { + this.amend = amend; + } + + public boolean isInsertChangeId() { + return insertChangeId; + } + + public void setInsertChangeId(boolean insertChangeId) { + this.insertChangeId = insertChangeId; + } + + public boolean isAll() { + return all; + } + + public void setAll(boolean all) { + this.all = all; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CurrentBranchGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CurrentBranchGitCommand.java new file mode 100644 index 0000000..9d30930 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/CurrentBranchGitCommand.java @@ -0,0 +1,162 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.NoFilepatternException; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.ui.spoon.InstanceCreationException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitInfoCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; +import com.ivyis.di.trans.steps.git.info.GitInfoStep; + +/** + * Current Branch Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class CurrentBranchGitCommand implements GitInfoCommand { + private static final Class PKG = CurrentBranchGitCommand.class; // for + // i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + + // Fields name + private String fieldName; + + public CurrentBranchGitCommand() {} + + public CurrentBranchGitCommand(Map configFields) + throws InstanceCreationException { + this.fieldName = configFields.get(BaseMessages.getString(PKG, + "Git.NameField.Label")); + } + + public CurrentBranchGitCommand(Node xml, String stepName) + throws KettleException { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + final XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/fieldName/text()"); + this.fieldName = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + } catch (XPathExpressionException e) { + throw new KettleException(e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.NameField.Label") + ": " + + fieldName; + } + + public Map getConfigFields(boolean mainConfigFields) { + final HashMap map = new HashMap(); + if (mainConfigFields) { + return map; + } + map.put(BaseMessages.getString(PKG, "Git.NameField.Label"), fieldName); + return map; + } + + public GitCommandType getCommandType() { + return GitCommandType.CURRENT_BRANCH; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc + .createTextNode(GitCommandType.CURRENT_BRANCH + .getOperationName())); + root.appendChild(commandName); + + final Element commitNameFieldNode = doc.createElement("fieldName"); + commitNameFieldNode.appendChild(doc.createTextNode(fieldName)); + root.appendChild(commitNameFieldNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public List call(final GitInfoStep gitInfoStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws IllegalArgumentException, IOException, + NoFilepatternException, GitAPIException { + + final List resp = new ArrayList(); + + final String[] branch = new String[] {git.getRepository().getBranch()}; + resp.add(branch); + + return resp; + } + + public boolean isConfigurable() { + return BaseGitCommandDialog.NO_CONFIGURATION; + } + + public String getFieldName() { + return fieldName; + } + + public void setFieldName(String fieldName) { + this.fieldName = fieldName; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/InitGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/InitGitCommand.java new file mode 100644 index 0000000..1138349 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/InitGitCommand.java @@ -0,0 +1,136 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.i18n.BaseMessages; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitOperationsCommand; +import com.ivyis.di.trans.steps.git.operations.GitOperationsStep; + +/** + * Init Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class InitGitCommand implements GitOperationsCommand { + private static final Class PKG = InitGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + + private boolean bare; + + public InitGitCommand() {} + + public InitGitCommand(String description) { + if ("".equals(description)) { + throw new IllegalArgumentException("Unkomnown config fields."); + } + final String[] stringProps = description.split(" / "); + for (String stringProp : stringProps) { + if (BaseMessages.getString(PKG, "Git.Bare.Label").equals( + stringProp.split(":")[0].trim())) { + this.bare = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } + } + } + + public InitGitCommand(Node xml, String stepName) { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + final XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/bare/text()"); + this.bare = Boolean.parseBoolean((String) xPathExpr.evaluate(xml, + XPathConstants.STRING)); + + } catch (XPathExpressionException e) { + LOGGER.error(e.getMessage(), e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.Bare.Label") + ": " + bare; + } + + public GitCommandType getCommandType() { + return GitCommandType.INIT; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc.createTextNode(GitCommandType.INIT + .getOperationName())); + root.appendChild(commandName); + + final Element bareNode = doc.createElement("bare"); + bareNode.appendChild(doc.createTextNode(String.valueOf(bare))); + root.appendChild(bareNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public Git call(final GitOperationsStep gitOperationsStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws GitAPIException { + return Git.init().setBare(bare).setDirectory(gitRepoFolder).call(); + } + + public boolean isBare() { + return bare; + } + + public void setBare(boolean bare) { + this.bare = bare; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/ListBranchsGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/ListBranchsGitCommand.java new file mode 100644 index 0000000..12d71b7 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/ListBranchsGitCommand.java @@ -0,0 +1,495 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.ListBranchCommand; +import org.eclipse.jgit.api.ListBranchCommand.ListMode; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidRemoteException; +import org.eclipse.jgit.api.errors.TransportException; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevObject; +import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.i18n.BaseMessages; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitInfoCommand; +import com.ivyis.di.trans.steps.git.info.GitInfoStep; + +/** + * List branchs Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class ListBranchsGitCommand implements GitInfoCommand { + private static final Class PKG = ListBranchsGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + private static final SimpleDateFormat dt = new SimpleDateFormat( + GitCommand.DATE_FORMAT); + + private String listMode; + + // Fields name + private String commitIdField; + private String commitNameField; + private String commitFullMessageField; + private String commitShortMessageField; + private String commitAuthorDateField; + private String commitAuthorNameField; + private String commitAuthorEmailField; + private String commitCommiterDateField; + private String commitCommiterNameField; + private String commitCommiterEmailField; + + public ListBranchsGitCommand() {} + + public ListBranchsGitCommand(Map configFields) { + if (configFields == null) { + throw new IllegalArgumentException("Unkomnown config fields."); + } + this.listMode = configFields.get(BaseMessages.getString(PKG, + "Git.ListMode.Label")); + this.commitIdField = configFields.get(BaseMessages.getString(PKG, + "Git.IdField.Label")); + this.commitNameField = configFields.get(BaseMessages.getString(PKG, + "Git.NameField.Label")); + this.commitFullMessageField = configFields.get(BaseMessages.getString( + PKG, "Git.FullMessageField.Label")); + this.commitShortMessageField = configFields.get(BaseMessages.getString( + PKG, "Git.ShortMessageField.Label")); + this.commitAuthorDateField = configFields.get(BaseMessages.getString( + PKG, "Git.AuthorCreationDateField.Label")); + this.commitAuthorNameField = configFields.get(BaseMessages.getString( + PKG, "Git.AuthorNameField.Label")); + this.commitAuthorEmailField = configFields.get(BaseMessages.getString( + PKG, "Git.AuthorEmailField.Label")); + this.commitCommiterDateField = configFields.get(BaseMessages.getString( + PKG, "Git.CommitterCreationDateField.Label")); + this.commitCommiterNameField = configFields.get(BaseMessages.getString( + PKG, "Git.CommitterNameField.Label")); + this.commitCommiterEmailField = configFields.get(BaseMessages + .getString(PKG, "Git.CommitterEmailField.Label")); + } + + public ListBranchsGitCommand(Node xml, String stepName) + throws KettleException { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/listMode/text()"); + this.listMode = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitIdField/text()"); + this.commitIdField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitNameField/text()"); + this.commitNameField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitFullMessageField/text()"); + this.commitFullMessageField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitShortMessageField/text()"); + this.commitShortMessageField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitAuthorDateField/text()"); + this.commitAuthorDateField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitAuthorNameField/text()"); + this.commitAuthorNameField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitAuthorEmailField/text()"); + this.commitAuthorEmailField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitCommiterDateField/text()"); + this.commitCommiterDateField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitCommiterNameField/text()"); + this.commitCommiterNameField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitCommiterEmailField/text()"); + this.commitCommiterEmailField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + } catch (XPathExpressionException e) { + throw new KettleException(e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.ListMode.Label") + + ": " + + listMode + + BaseMessages.getString(PKG, "Git.IdField.Label") + + ": " + + commitIdField + + " / " + + BaseMessages.getString(PKG, "Git.NameField.Label") + + ": " + + commitNameField + + " / " + + BaseMessages.getString(PKG, "Git.FullMessageField.Label") + + ": " + + commitFullMessageField + + " / " + + BaseMessages.getString(PKG, "Git.ShortMessageField.Label") + + ": " + + commitShortMessageField + + " / " + + BaseMessages.getString(PKG, + "Git.AuthorCreationDateField.Label") + + ": " + + commitAuthorDateField + + " / " + + BaseMessages.getString(PKG, "Git.AuthorNameField.Label") + + ": " + + commitAuthorNameField + + " / " + + BaseMessages.getString(PKG, "Git.AuthorEmailField.Label") + + ": " + + commitAuthorEmailField + + " / " + + BaseMessages.getString(PKG, + "Git.CommitterCreationDateField.Label") + ": " + + commitCommiterDateField + " / " + + BaseMessages.getString(PKG, "Git.CommitterNameField.Label") + + ": " + commitCommiterNameField + + BaseMessages.getString(PKG, "Git.CommitterEmailField.Label") + + ": " + commitCommiterEmailField; + } + + public Map getConfigFields(boolean mainConfigFields) { + final HashMap map = new HashMap(); + map.put(BaseMessages.getString(PKG, "Git.ListMode.Label"), listMode); + if (mainConfigFields) { + return map; + } + map.put(BaseMessages.getString(PKG, "Git.IdField.Label"), commitIdField); + map.put(BaseMessages.getString(PKG, "Git.NameField.Label"), + commitNameField); + map.put(BaseMessages.getString(PKG, "Git.FullMessageField.Label"), + commitFullMessageField); + map.put(BaseMessages.getString(PKG, "Git.ShortMessageField.Label"), + commitShortMessageField); + map.put(BaseMessages + .getString(PKG, "Git.AuthorCreationDateField.Label"), + commitAuthorDateField); + map.put(BaseMessages.getString(PKG, "Git.AuthorNameField.Label"), + commitAuthorNameField); + map.put(BaseMessages.getString(PKG, "Git.AuthorEmailField.Label"), + commitAuthorEmailField); + map.put(BaseMessages.getString(PKG, + "Git.CommitterCreationDateField.Label"), + commitCommiterDateField); + map.put(BaseMessages.getString(PKG, "Git.CommitterNameField.Label"), + commitCommiterNameField); + map.put(BaseMessages.getString(PKG, "Git.CommitterEmailField.Label"), + commitCommiterEmailField); + return map; + } + + public GitCommandType getCommandType() { + return GitCommandType.LIST_BRANCHS; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc + .createTextNode(GitCommandType.LIST_BRANCHS + .getOperationName())); + root.appendChild(commandName); + + final Element listModeNode = doc.createElement("listMode"); + listModeNode.appendChild(doc.createTextNode(listMode)); + root.appendChild(listModeNode); + + final Element commitIdFieldNode = doc + .createElement("commitIdField"); + commitIdFieldNode.appendChild(doc.createTextNode(commitIdField)); + root.appendChild(commitIdFieldNode); + + final Element commitNameFieldNode = doc + .createElement("commitNameField"); + commitNameFieldNode + .appendChild(doc.createTextNode(commitNameField)); + root.appendChild(commitNameFieldNode); + + final Element commitFullMessageFieldNode = doc + .createElement("commitFullMessageField"); + commitFullMessageFieldNode.appendChild(doc + .createTextNode(commitFullMessageField)); + root.appendChild(commitFullMessageFieldNode); + + final Element commitShortMessageFieldNode = doc + .createElement("commitShortMessageField"); + commitShortMessageFieldNode.appendChild(doc + .createTextNode(commitShortMessageField)); + root.appendChild(commitShortMessageFieldNode); + + final Element commitAuthorDateFieldNode = doc + .createElement("commitAuthorDateField"); + commitAuthorDateFieldNode.appendChild(doc + .createTextNode(commitAuthorDateField)); + root.appendChild(commitAuthorDateFieldNode); + + final Element commitAuthorNameFieldNode = doc + .createElement("commitAuthorNameField"); + commitAuthorNameFieldNode.appendChild(doc + .createTextNode(commitAuthorNameField)); + root.appendChild(commitAuthorNameFieldNode); + + final Element commitAuthorEmailFieldNode = doc + .createElement("commitAuthorEmailField"); + commitAuthorEmailFieldNode.appendChild(doc + .createTextNode(commitAuthorEmailField)); + root.appendChild(commitAuthorEmailFieldNode); + + final Element commitCommiterDateFieldNode = doc + .createElement("commitCommiterDateField"); + commitCommiterDateFieldNode.appendChild(doc + .createTextNode(commitCommiterDateField)); + root.appendChild(commitCommiterDateFieldNode); + + final Element commitCommiterNameFieldNode = doc + .createElement("commitCommiterNameField"); + commitCommiterNameFieldNode.appendChild(doc + .createTextNode(commitCommiterNameField)); + root.appendChild(commitCommiterNameFieldNode); + + final Element commitCommiterEmailFieldNode = doc + .createElement("commitCommiterEmailField"); + commitCommiterEmailFieldNode.appendChild(doc + .createTextNode(commitCommiterEmailField)); + root.appendChild(commitCommiterEmailFieldNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public List call(final GitInfoStep gitInfoStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws InvalidRemoteException, TransportException, GitAPIException, + IllegalArgumentException, IOException { + + final List branchs = new ArrayList(); + + final ListBranchCommand ac = git + .branchList() + .setListMode( + ("remote".equalsIgnoreCase(gitInfoStep + .environmentSubstitute(this.listMode)) ? ListMode.REMOTE + : ListMode.ALL)); + final List refBranchs = ac.call(); + + for (Ref refBranch : refBranchs) { + final String[] branch = new String[] {null, null, null, null, + null, null, null, null, null, null}; + + branch[0] = refBranch.getObjectId().getName(); // Id + branch[1] = refBranch.getName(); // Name + + final RevObject object = new RevWalk(git.getRepository()) + .parseAny(refBranch.getObjectId()); + if (object instanceof RevCommit) { + branch[2] = ((RevCommit) object).getFullMessage(); // Commit + // message + branch[3] = ((RevCommit) object).getShortMessage(); // Commit + // message + branch[4] = dt.format(((RevCommit) object).getAuthorIdent() + .getWhen()); // Author Date + branch[5] = ((RevCommit) object).getAuthorIdent().getName(); // Author + // name + branch[6] = ((RevCommit) object).getAuthorIdent() + .getEmailAddress(); // Author email + branch[7] = dt.format(((RevCommit) object).getCommitterIdent() + .getWhen()); // Committer Date + branch[8] = ((RevCommit) object).getCommitterIdent().getName(); // Committer + // name + branch[9] = ((RevCommit) object).getCommitterIdent() + .getEmailAddress(); // Committer email + } + + branchs.add(branch); + } + + return branchs; + } + + public boolean isConfigurable() { + return true; + } + + public String getListMode() { + return listMode; + } + + public void setListMode(String listMode) { + this.listMode = listMode; + } + + public String getCommitIdField() { + return commitIdField; + } + + public void setCommitIdField(String commitIdField) { + this.commitIdField = commitIdField; + } + + public String getCommitNameField() { + return commitNameField; + } + + public void setCommitNameField(String commitNameField) { + this.commitNameField = commitNameField; + } + + public String getCommitFullMessageField() { + return commitFullMessageField; + } + + public void setCommitFullMessageField(String commitFullMessageField) { + this.commitFullMessageField = commitFullMessageField; + } + + public String getCommitShortMessageField() { + return commitShortMessageField; + } + + public void setCommitShortMessageField(String commitShortMessageField) { + this.commitShortMessageField = commitShortMessageField; + } + + public String getCommitAuthorDateField() { + return commitAuthorDateField; + } + + public void setCommitAuthorDateField(String commitAuthorDateField) { + this.commitAuthorDateField = commitAuthorDateField; + } + + public String getCommitAuthorNameField() { + return commitAuthorNameField; + } + + public void setCommitAuthorNameField(String commitAuthorNameField) { + this.commitAuthorNameField = commitAuthorNameField; + } + + public String getCommitAuthorEmailField() { + return commitAuthorEmailField; + } + + public void setCommitAuthorEmailField(String commitAuthorEmailField) { + this.commitAuthorEmailField = commitAuthorEmailField; + } + + public String getCommitCommiterDateField() { + return commitCommiterDateField; + } + + public void setCommitCommiterDateField(String commitCommiterDateField) { + this.commitCommiterDateField = commitCommiterDateField; + } + + public String getCommitCommiterNameField() { + return commitCommiterNameField; + } + + public void setCommitCommiterNameField(String commitCommiterNameField) { + this.commitCommiterNameField = commitCommiterNameField; + } + + public String getCommitCommiterEmailField() { + return commitCommiterEmailField; + } + + public void setCommitCommiterEmailField(String commitCommiterEmailField) { + this.commitCommiterEmailField = commitCommiterEmailField; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/ListTagsGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/ListTagsGitCommand.java new file mode 100644 index 0000000..eca1bf0 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/ListTagsGitCommand.java @@ -0,0 +1,459 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.NoFilepatternException; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevObject; +import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.ui.spoon.InstanceCreationException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitInfoCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; +import com.ivyis.di.trans.steps.git.info.GitInfoStep; + +/** + * List tags Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class ListTagsGitCommand implements GitInfoCommand { + private static final Class PKG = ListTagsGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + private static final SimpleDateFormat dt = new SimpleDateFormat( + GitCommand.DATE_FORMAT); + + // Fields name + private String commitIdField; + private String commitNameField; + private String commitFullMessageField; + private String commitShortMessageField; + private String commitAuthorDateField; + private String commitAuthorNameField; + private String commitAuthorEmailField; + private String commitCommiterDateField; + private String commitCommiterNameField; + private String commitCommiterEmailField; + + public ListTagsGitCommand() {} + + public ListTagsGitCommand(Map configFields) + throws InstanceCreationException { + this.commitIdField = configFields.get(BaseMessages.getString(PKG, + "Git.IdField.Label")); + this.commitNameField = configFields.get(BaseMessages.getString(PKG, + "Git.NameField.Label")); + this.commitFullMessageField = configFields.get(BaseMessages.getString( + PKG, "Git.FullMessageField.Label")); + this.commitShortMessageField = configFields.get(BaseMessages.getString( + PKG, "Git.ShortMessageField.Label")); + this.commitAuthorDateField = configFields.get(BaseMessages.getString( + PKG, "Git.AuthorCreationDateField.Label")); + this.commitAuthorNameField = configFields.get(BaseMessages.getString( + PKG, "Git.AuthorNameField.Label")); + this.commitAuthorEmailField = configFields.get(BaseMessages.getString( + PKG, "Git.AuthorEmailField.Label")); + this.commitCommiterDateField = configFields.get(BaseMessages.getString( + PKG, "Git.CommitterCreationDateField.Label")); + this.commitCommiterNameField = configFields.get(BaseMessages.getString( + PKG, "Git.CommitterNameField.Label")); + this.commitCommiterEmailField = configFields.get(BaseMessages + .getString(PKG, "Git.CommitterEmailField.Label")); + } + + public ListTagsGitCommand(Node xml, String stepName) throws KettleException { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitIdField/text()"); + this.commitIdField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitNameField/text()"); + this.commitNameField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitFullMessageField/text()"); + this.commitFullMessageField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitShortMessageField/text()"); + this.commitShortMessageField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitAuthorDateField/text()"); + this.commitAuthorDateField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitAuthorNameField/text()"); + this.commitAuthorNameField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitAuthorEmailField/text()"); + this.commitAuthorEmailField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitCommiterDateField/text()"); + this.commitCommiterDateField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitCommiterNameField/text()"); + this.commitCommiterNameField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitCommiterEmailField/text()"); + this.commitCommiterEmailField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + } catch (XPathExpressionException e) { + throw new KettleException(e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.IdField.Label") + + ": " + + commitIdField + + " / " + + BaseMessages.getString(PKG, "Git.NameField.Label") + + ": " + + commitNameField + + " / " + + BaseMessages.getString(PKG, "Git.FullMessageField.Label") + + ": " + + commitFullMessageField + + " / " + + BaseMessages.getString(PKG, "Git.ShortMessageField.Label") + + ": " + + commitShortMessageField + + " / " + + BaseMessages.getString(PKG, + "Git.AuthorCreationDateField.Label") + + ": " + + commitAuthorDateField + + " / " + + BaseMessages.getString(PKG, "Git.AuthorNameField.Label") + + ": " + + commitAuthorNameField + + " / " + + BaseMessages.getString(PKG, "Git.AuthorEmailField.Label") + + ": " + + commitAuthorEmailField + + " / " + + BaseMessages.getString(PKG, + "Git.CommitterCreationDateField.Label") + ": " + + commitCommiterDateField + " / " + + BaseMessages.getString(PKG, "Git.CommitterNameField.Label") + + ": " + commitCommiterNameField + + BaseMessages.getString(PKG, "Git.CommitterEmailField.Label") + + ": " + commitCommiterEmailField; + } + + public Map getConfigFields(boolean mainConfigFields) { + final HashMap map = new HashMap(); + if (mainConfigFields) { + return map; + } + map.put(BaseMessages.getString(PKG, "Git.IdField.Label"), commitIdField); + map.put(BaseMessages.getString(PKG, "Git.NameField.Label"), + commitNameField); + map.put(BaseMessages.getString(PKG, "Git.FullMessageField.Label"), + commitFullMessageField); + map.put(BaseMessages.getString(PKG, "Git.ShortMessageField.Label"), + commitShortMessageField); + map.put(BaseMessages + .getString(PKG, "Git.AuthorCreationDateField.Label"), + commitAuthorDateField); + map.put(BaseMessages.getString(PKG, "Git.AuthorNameField.Label"), + commitAuthorNameField); + map.put(BaseMessages.getString(PKG, "Git.AuthorEmailField.Label"), + commitAuthorEmailField); + map.put(BaseMessages.getString(PKG, + "Git.CommitterCreationDateField.Label"), + commitCommiterDateField); + map.put(BaseMessages.getString(PKG, "Git.CommitterNameField.Label"), + commitCommiterNameField); + map.put(BaseMessages.getString(PKG, "Git.CommitterEmailField.Label"), + commitCommiterEmailField); + return map; + } + + public GitCommandType getCommandType() { + return GitCommandType.LIST_TAGS; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc.createTextNode(GitCommandType.LIST_TAGS + .getOperationName())); + root.appendChild(commandName); + + final Element commitIdFieldNode = doc + .createElement("commitIdField"); + commitIdFieldNode.appendChild(doc.createTextNode(commitIdField)); + root.appendChild(commitIdFieldNode); + + final Element commitNameFieldNode = doc + .createElement("commitNameField"); + commitNameFieldNode + .appendChild(doc.createTextNode(commitNameField)); + root.appendChild(commitNameFieldNode); + + final Element commitFullMessageFieldNode = doc + .createElement("commitFullMessageField"); + commitFullMessageFieldNode.appendChild(doc + .createTextNode(commitFullMessageField)); + root.appendChild(commitFullMessageFieldNode); + + final Element commitShortMessageFieldNode = doc + .createElement("commitShortMessageField"); + commitShortMessageFieldNode.appendChild(doc + .createTextNode(commitShortMessageField)); + root.appendChild(commitShortMessageFieldNode); + + final Element commitAuthorDateFieldNode = doc + .createElement("commitAuthorDateField"); + commitAuthorDateFieldNode.appendChild(doc + .createTextNode(commitAuthorDateField)); + root.appendChild(commitAuthorDateFieldNode); + + final Element commitAuthorNameFieldNode = doc + .createElement("commitAuthorNameField"); + commitAuthorNameFieldNode.appendChild(doc + .createTextNode(commitAuthorNameField)); + root.appendChild(commitAuthorNameFieldNode); + + final Element commitAuthorEmailFieldNode = doc + .createElement("commitAuthorEmailField"); + commitAuthorEmailFieldNode.appendChild(doc + .createTextNode(commitAuthorEmailField)); + root.appendChild(commitAuthorEmailFieldNode); + + final Element commitCommiterDateFieldNode = doc + .createElement("commitCommiterDateField"); + commitCommiterDateFieldNode.appendChild(doc + .createTextNode(commitCommiterDateField)); + root.appendChild(commitCommiterDateFieldNode); + + final Element commitCommiterNameFieldNode = doc + .createElement("commitCommiterNameField"); + commitCommiterNameFieldNode.appendChild(doc + .createTextNode(commitCommiterNameField)); + root.appendChild(commitCommiterNameFieldNode); + + final Element commitCommiterEmailFieldNode = doc + .createElement("commitCommiterEmailField"); + commitCommiterEmailFieldNode.appendChild(doc + .createTextNode(commitCommiterEmailField)); + root.appendChild(commitCommiterEmailFieldNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public List call(final GitInfoStep gitInfoStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws IllegalArgumentException, IOException, + NoFilepatternException, GitAPIException { + + final List tags = new ArrayList(); + + final List refTags = git.tagList().call(); + for (Ref refTag : refTags) { + + final String[] tag = new String[] {null, null, null, null, null, + null, null, null, null, null}; + + tag[0] = refTag.getObjectId().getName(); // Id + tag[1] = refTag.getName(); // Name + + final RevObject object = new RevWalk(git.getRepository()) + .parseAny(refTag.getObjectId()); + if (object instanceof RevCommit) { + tag[2] = ((RevCommit) object).getFullMessage(); // Commit + // message + tag[3] = ((RevCommit) object).getShortMessage(); // Commit + // message + tag[4] = dt.format(((RevCommit) object).getAuthorIdent() + .getWhen()); // Author Date + tag[5] = ((RevCommit) object).getAuthorIdent().getName(); // Author + // name + tag[6] = ((RevCommit) object).getAuthorIdent() + .getEmailAddress(); // Author email + tag[7] = dt.format(((RevCommit) object).getCommitterIdent() + .getWhen()); // Committer Date + tag[8] = ((RevCommit) object).getCommitterIdent().getName(); // Committer + // name + tag[9] = ((RevCommit) object).getCommitterIdent() + .getEmailAddress(); // Committer email + } + + tags.add(tag); + + } + + return tags; + } + + public boolean isConfigurable() { + return BaseGitCommandDialog.NO_CONFIGURATION; + } + + public String getCommitIdField() { + return commitIdField; + } + + public void setCommitIdField(String commitIdField) { + this.commitIdField = commitIdField; + } + + public String getCommitNameField() { + return commitNameField; + } + + public void setCommitNameField(String commitNameField) { + this.commitNameField = commitNameField; + } + + public String getCommitFullMessageField() { + return commitFullMessageField; + } + + public void setCommitFullMessageField(String commitFullMessageField) { + this.commitFullMessageField = commitFullMessageField; + } + + public String getCommitShortMessageField() { + return commitShortMessageField; + } + + public void setCommitShortMessageField(String commitShortMessageField) { + this.commitShortMessageField = commitShortMessageField; + } + + public String getCommitAuthorDateField() { + return commitAuthorDateField; + } + + public void setCommitAuthorDateField(String commitAuthorDateField) { + this.commitAuthorDateField = commitAuthorDateField; + } + + public String getCommitAuthorNameField() { + return commitAuthorNameField; + } + + public void setCommitAuthorNameField(String commitAuthorNameField) { + this.commitAuthorNameField = commitAuthorNameField; + } + + public String getCommitAuthorEmailField() { + return commitAuthorEmailField; + } + + public void setCommitAuthorEmailField(String commitAuthorEmailField) { + this.commitAuthorEmailField = commitAuthorEmailField; + } + + public String getCommitCommiterDateField() { + return commitCommiterDateField; + } + + public void setCommitCommiterDateField(String commitCommiterDateField) { + this.commitCommiterDateField = commitCommiterDateField; + } + + public String getCommitCommiterNameField() { + return commitCommiterNameField; + } + + public void setCommitCommiterNameField(String commitCommiterNameField) { + this.commitCommiterNameField = commitCommiterNameField; + } + + public String getCommitCommiterEmailField() { + return commitCommiterEmailField; + } + + public void setCommitCommiterEmailField(String commitCommiterEmailField) { + this.commitCommiterEmailField = commitCommiterEmailField; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/LogGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/LogGitCommand.java new file mode 100644 index 0000000..95304ae --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/LogGitCommand.java @@ -0,0 +1,561 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.LogCommand; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidRemoteException; +import org.eclipse.jgit.api.errors.TransportException; +import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.revwalk.RevWalk; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.Const; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.i18n.BaseMessages; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitInfoCommand; +import com.ivyis.di.trans.steps.git.info.GitInfoStep; + +/** + * Log Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class LogGitCommand implements GitInfoCommand { + private static final Class PKG = LogGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + private static final SimpleDateFormat dt = new SimpleDateFormat( + GitCommand.DATE_FORMAT); + + // Properties + private String path; + private String maxCount; + private String skip; + + // Fields name + private String commitIdField; + private String commitNameField; + private String commitFullMessageField; + private String commitShortMessageField; + private String commitAuthorDateField; + private String commitAuthorNameField; + private String commitAuthorEmailField; + private String commitCommiterDateField; + private String commitCommiterNameField; + private String commitCommiterEmailField; + + public LogGitCommand() {} + + public LogGitCommand(Map configFields) { + if (configFields == null) { + throw new IllegalArgumentException("Unkomnown config fields."); + } + this.path = configFields.get(BaseMessages.getString(PKG, + "Git.Path.Label")); + this.maxCount = configFields.get(BaseMessages.getString(PKG, + "Git.MaxCount.Label")); + this.skip = configFields.get(BaseMessages.getString(PKG, + "Git.Skip.Label")); + this.commitIdField = configFields.get(BaseMessages.getString(PKG, + "Git.IdField.Label")); + this.commitNameField = configFields.get(BaseMessages.getString(PKG, + "Git.NameField.Label")); + this.commitFullMessageField = configFields.get(BaseMessages.getString( + PKG, "Git.FullMessageField.Label")); + this.commitShortMessageField = configFields.get(BaseMessages.getString( + PKG, "Git.ShortMessageField.Label")); + this.commitAuthorDateField = configFields.get(BaseMessages.getString( + PKG, "Git.AuthorCreationDateField.Label")); + this.commitAuthorNameField = configFields.get(BaseMessages.getString( + PKG, "Git.AuthorNameField.Label")); + this.commitAuthorEmailField = configFields.get(BaseMessages.getString( + PKG, "Git.AuthorEmailField.Label")); + this.commitCommiterDateField = configFields.get(BaseMessages.getString( + PKG, "Git.CommitterCreationDateField.Label")); + this.commitCommiterNameField = configFields.get(BaseMessages.getString( + PKG, "Git.CommitterNameField.Label")); + this.commitCommiterEmailField = configFields.get(BaseMessages + .getString(PKG, "Git.CommitterEmailField.Label")); + } + + public LogGitCommand(Node xml, String stepName) throws KettleException { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/path/text()"); + if (!"".equals((String) xPathExpr.evaluate(xml, + XPathConstants.STRING))) { + this.path = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + } + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "//maxCount/text()"); + if (!"".equals((String) xPathExpr.evaluate(xml, + XPathConstants.STRING))) { + this.maxCount = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + } + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/skip/text()"); + if (!"".equals((String) xPathExpr.evaluate(xml, + XPathConstants.STRING))) { + this.skip = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + } + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitIdField/text()"); + this.commitIdField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitNameField/text()"); + this.commitNameField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitFullMessageField/text()"); + this.commitFullMessageField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitShortMessageField/text()"); + this.commitShortMessageField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitAuthorDateField/text()"); + this.commitAuthorDateField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitAuthorNameField/text()"); + this.commitAuthorNameField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitAuthorEmailField/text()"); + this.commitAuthorEmailField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitCommiterDateField/text()"); + this.commitCommiterDateField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitCommiterNameField/text()"); + this.commitCommiterNameField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/commitCommiterEmailField/text()"); + this.commitCommiterEmailField = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + } catch (XPathExpressionException e) { + throw new KettleException(e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.Path.Label") + + ": " + + path + + " / " + + BaseMessages.getString(PKG, "Git.MaxCount.Label") + + ": " + + maxCount + + " / " + + BaseMessages.getString(PKG, "Git.Skip.Label") + + ": " + + skip + + " / " + + BaseMessages.getString(PKG, "Git.IdField.Label") + + ": " + + commitIdField + + " / " + + BaseMessages.getString(PKG, "Git.NameField.Label") + + ": " + + commitNameField + + " / " + + BaseMessages.getString(PKG, "Git.FullMessageField.Label") + + ": " + + commitFullMessageField + + " / " + + BaseMessages.getString(PKG, "Git.ShortMessageField.Label") + + ": " + + commitShortMessageField + + " / " + + BaseMessages.getString(PKG, + "Git.AuthorCreationDateField.Label") + + ": " + + commitAuthorDateField + + " / " + + BaseMessages.getString(PKG, "Git.AuthorNameField.Label") + + ": " + + commitAuthorNameField + + " / " + + BaseMessages.getString(PKG, "Git.AuthorEmailField.Label") + + ": " + + commitAuthorEmailField + + " / " + + BaseMessages.getString(PKG, + "Git.CommitterCreationDateField.Label") + ": " + + commitCommiterDateField + " / " + + BaseMessages.getString(PKG, "Git.CommitterNameField.Label") + + ": " + commitCommiterNameField + + BaseMessages.getString(PKG, "Git.CommitterEmailField.Label") + + ": " + commitCommiterEmailField; + } + + public Map getConfigFields(boolean mainConfigFields) { + final HashMap map = new HashMap(); + map.put(BaseMessages.getString(PKG, "Git.Path.Label"), path); + map.put(BaseMessages.getString(PKG, "Git.MaxCount.Label"), + maxCount == null ? null : maxCount.toString()); + map.put(BaseMessages.getString(PKG, "Git.Skip.Label"), + skip == null ? null : skip.toString()); + if (mainConfigFields) { + return map; + } + map.put(BaseMessages.getString(PKG, "Git.IdField.Label"), commitIdField); + map.put(BaseMessages.getString(PKG, "Git.NameField.Label"), + commitNameField); + map.put(BaseMessages.getString(PKG, "Git.FullMessageField.Label"), + commitFullMessageField); + map.put(BaseMessages.getString(PKG, "Git.ShortMessageField.Label"), + commitShortMessageField); + map.put(BaseMessages + .getString(PKG, "Git.AuthorCreationDateField.Label"), + commitAuthorDateField); + map.put(BaseMessages.getString(PKG, "Git.AuthorNameField.Label"), + commitAuthorNameField); + map.put(BaseMessages.getString(PKG, "Git.AuthorEmailField.Label"), + commitAuthorEmailField); + map.put(BaseMessages.getString(PKG, + "Git.CommitterCreationDateField.Label"), + commitCommiterDateField); + map.put(BaseMessages.getString(PKG, "Git.CommitterNameField.Label"), + commitCommiterNameField); + map.put(BaseMessages.getString(PKG, "Git.CommitterEmailField.Label"), + commitCommiterEmailField); + return map; + } + + public GitCommandType getCommandType() { + return GitCommandType.LOG; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc.createTextNode(GitCommandType.LOG + .getOperationName())); + root.appendChild(commandName); + if (path != null) { + final Element pathNode = doc.createElement("path"); + pathNode.appendChild(doc.createTextNode(path)); + root.appendChild(pathNode); + } + if (maxCount != null) { + final Element maxCountNode = doc.createElement("maxCount"); + maxCountNode + .appendChild(doc.createTextNode(maxCount.toString())); + root.appendChild(maxCountNode); + } + if (skip != null) { + final Element skipNode = doc.createElement("skip"); + skipNode.appendChild(doc.createTextNode(skip.toString())); + root.appendChild(skipNode); + } + + final Element commitIdFieldNode = doc + .createElement("commitIdField"); + commitIdFieldNode.appendChild(doc.createTextNode(commitIdField)); + root.appendChild(commitIdFieldNode); + + final Element commitNameFieldNode = doc + .createElement("commitNameField"); + commitNameFieldNode + .appendChild(doc.createTextNode(commitNameField)); + root.appendChild(commitNameFieldNode); + + final Element commitFullMessageFieldNode = doc + .createElement("commitFullMessageField"); + commitFullMessageFieldNode.appendChild(doc + .createTextNode(commitFullMessageField)); + root.appendChild(commitFullMessageFieldNode); + + final Element commitShortMessageFieldNode = doc + .createElement("commitShortMessageField"); + commitShortMessageFieldNode.appendChild(doc + .createTextNode(commitShortMessageField)); + root.appendChild(commitShortMessageFieldNode); + + final Element commitAuthorDateFieldNode = doc + .createElement("commitAuthorDateField"); + commitAuthorDateFieldNode.appendChild(doc + .createTextNode(commitAuthorDateField)); + root.appendChild(commitAuthorDateFieldNode); + + final Element commitAuthorNameFieldNode = doc + .createElement("commitAuthorNameField"); + commitAuthorNameFieldNode.appendChild(doc + .createTextNode(commitAuthorNameField)); + root.appendChild(commitAuthorNameFieldNode); + + final Element commitAuthorEmailFieldNode = doc + .createElement("commitAuthorEmailField"); + commitAuthorEmailFieldNode.appendChild(doc + .createTextNode(commitAuthorEmailField)); + root.appendChild(commitAuthorEmailFieldNode); + + final Element commitCommiterDateFieldNode = doc + .createElement("commitCommiterDateField"); + commitCommiterDateFieldNode.appendChild(doc + .createTextNode(commitCommiterDateField)); + root.appendChild(commitCommiterDateFieldNode); + + final Element commitCommiterNameFieldNode = doc + .createElement("commitCommiterNameField"); + commitCommiterNameFieldNode.appendChild(doc + .createTextNode(commitCommiterNameField)); + root.appendChild(commitCommiterNameFieldNode); + + final Element commitCommiterEmailFieldNode = doc + .createElement("commitCommiterEmailField"); + commitCommiterEmailFieldNode.appendChild(doc + .createTextNode(commitCommiterEmailField)); + root.appendChild(commitCommiterEmailFieldNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public List call(final GitInfoStep gitInfoStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws InvalidRemoteException, TransportException, GitAPIException, + IllegalArgumentException, IOException { + + final RevWalk walk = new RevWalk(git.getRepository()); + LogCommand lc = git.log(); + + if (!Const.isEmpty(this.path)) { + lc = lc.addPath(gitInfoStep.environmentSubstitute(this.path)); + } + + if (this.maxCount != null) { + lc = lc.setMaxCount(Integer.parseInt(gitInfoStep + .environmentSubstitute(this.maxCount))); + } + + if (this.skip != null) { + lc = lc.setSkip(Integer.parseInt(gitInfoStep + .environmentSubstitute(this.skip))); + } + + final Iterable logs = lc.call(); + final Iterator i = logs.iterator(); + + final List commits = new ArrayList(); + + while (i.hasNext()) { + final String[] commitRow = new String[] {null, null, null, null, + null, null, null, null, null, null}; + final RevCommit commit = walk.parseCommit(i.next()); + commitRow[0] = commit.getId().getName(); + commitRow[1] = commit.getName(); + commitRow[2] = commit.getFullMessage(); + commitRow[3] = commit.getShortMessage(); + commitRow[4] = dt.format(commit.getAuthorIdent().getWhen()); + commitRow[5] = commit.getAuthorIdent().getName(); + commitRow[6] = commit.getAuthorIdent().getEmailAddress(); + commitRow[7] = dt.format(commit.getCommitterIdent().getWhen()); + commitRow[8] = commit.getCommitterIdent().getName(); + commitRow[9] = commit.getCommitterIdent().getEmailAddress(); + + commits.add(commitRow); + + } + + return commits; + } + + public boolean isConfigurable() { + return true; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getMaxCount() { + return maxCount; + } + + public void setMaxCount(String maxCount) { + this.maxCount = maxCount; + } + + public String getSkip() { + return skip; + } + + public void setSkip(String skip) { + this.skip = skip; + } + + public String getCommitIdField() { + return commitIdField; + } + + public void setCommitIdField(String commitIdField) { + this.commitIdField = commitIdField; + } + + public String getCommitNameField() { + return commitNameField; + } + + public void setCommitNameField(String commitNameField) { + this.commitNameField = commitNameField; + } + + public String getCommitFullMessageField() { + return commitFullMessageField; + } + + public void setCommitFullMessageField(String commitFullMessageField) { + this.commitFullMessageField = commitFullMessageField; + } + + public String getCommitShortMessageField() { + return commitShortMessageField; + } + + public void setCommitShortMessageField(String commitShortMessageField) { + this.commitShortMessageField = commitShortMessageField; + } + + public String getCommitAuthorDateField() { + return commitAuthorDateField; + } + + public void setCommitAuthorDateField(String commitAuthorDateField) { + this.commitAuthorDateField = commitAuthorDateField; + } + + public String getCommitAuthorNameField() { + return commitAuthorNameField; + } + + public void setCommitAuthorNameField(String commitAuthorNameField) { + this.commitAuthorNameField = commitAuthorNameField; + } + + public String getCommitAuthorEmailField() { + return commitAuthorEmailField; + } + + public void setCommitAuthorEmailField(String commitAuthorEmailField) { + this.commitAuthorEmailField = commitAuthorEmailField; + } + + public String getCommitCommiterDateField() { + return commitCommiterDateField; + } + + public void setCommitCommiterDateField(String commitCommiterDateField) { + this.commitCommiterDateField = commitCommiterDateField; + } + + public String getCommitCommiterNameField() { + return commitCommiterNameField; + } + + public void setCommitCommiterNameField(String commitCommiterNameField) { + this.commitCommiterNameField = commitCommiterNameField; + } + + public String getCommitCommiterEmailField() { + return commitCommiterEmailField; + } + + public void setCommitCommiterEmailField(String commitCommiterEmailField) { + this.commitCommiterEmailField = commitCommiterEmailField; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/PullGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/PullGitCommand.java new file mode 100644 index 0000000..1238521 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/PullGitCommand.java @@ -0,0 +1,151 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.CanceledException; +import org.eclipse.jgit.api.errors.DetachedHeadException; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidConfigurationException; +import org.eclipse.jgit.api.errors.InvalidRemoteException; +import org.eclipse.jgit.api.errors.NoHeadException; +import org.eclipse.jgit.api.errors.RefNotFoundException; +import org.eclipse.jgit.api.errors.TransportException; +import org.eclipse.jgit.api.errors.WrongRepositoryStateException; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.i18n.BaseMessages; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitOperationsCommand; +import com.ivyis.di.trans.steps.git.operations.GitOperationsStep; + +/** + * Pull Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class PullGitCommand implements GitOperationsCommand { + private static final Class PKG = PullGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + + private boolean rebase; + + public PullGitCommand() {} + + public PullGitCommand(String description) { + if ("".equals(description)) { + throw new IllegalArgumentException("Unkomnown config fields."); + } + final String[] stringProps = description.split(" / "); + for (String stringProp : stringProps) { + if (BaseMessages.getString(PKG, "Git.Rebase.Label").equals( + stringProp.split(":")[0].trim())) { + this.rebase = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } + } + } + + public PullGitCommand(Node xml, String stepName) { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + final XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/rebase/text()"); + this.rebase = Boolean.parseBoolean((String) xPathExpr.evaluate(xml, + XPathConstants.STRING)); + + } catch (XPathExpressionException e) { + LOGGER.error(e.getMessage(), e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.Rebase.Label") + ": " + rebase; + } + + public GitCommandType getCommandType() { + return GitCommandType.PULL; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc.createTextNode(GitCommandType.PULL + .getOperationName())); + root.appendChild(commandName); + + final Element rebaseNode = doc.createElement("rebase"); + rebaseNode.appendChild(doc.createTextNode(String.valueOf(rebase))); + root.appendChild(rebaseNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public Git call(final GitOperationsStep gitOperationsStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws IllegalArgumentException, IOException, + WrongRepositoryStateException, InvalidConfigurationException, + DetachedHeadException, InvalidRemoteException, CanceledException, + RefNotFoundException, NoHeadException, TransportException, + GitAPIException { + git.pull().setCredentialsProvider(cp).setRebase(rebase).call(); + return git; + } + + public boolean isRebase() { + return rebase; + } + + public void setRebase(boolean rebase) { + this.rebase = rebase; + } + + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/PushGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/PushGitCommand.java new file mode 100644 index 0000000..a94dc1f --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/PushGitCommand.java @@ -0,0 +1,344 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.PushCommand; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidRemoteException; +import org.eclipse.jgit.api.errors.TransportException; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitOperationsCommand; +import com.ivyis.di.trans.steps.git.operations.GitOperationsStep; + +/** + * Push Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class PushGitCommand implements GitOperationsCommand { + private static final Class PKG = PushGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + + private String referenceToPush; + private String remote; + private String receivePack; + private boolean dryRun; + private boolean force; + private boolean thin; + private boolean pushAllBranches; + private boolean pushAllTags; + + public PushGitCommand() {} + + public PushGitCommand(String description) { + if ("".equals(description)) { + throw new IllegalArgumentException("Unkomnown config fields."); + } + final String[] stringProps = description.split(" / "); + for (String stringProp : stringProps) { + final String prop = stringProp.split(":")[0].trim(); + if (BaseMessages.getString(PKG, "Git.ReferenceToPush.Label") + .equals(prop)) { + this.referenceToPush = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.Remote.Label").equals( + prop)) { + this.remote = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.ReceivePack.Label") + .equals(prop)) { + this.receivePack = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.DryRun.Label").equals( + prop)) { + this.dryRun = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } else if (BaseMessages.getString(PKG, "Git.Force.Label").equals( + prop)) { + this.force = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } else if (BaseMessages.getString(PKG, "Git.Thin.Label").equals( + prop)) { + this.thin = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } else if (BaseMessages.getString(PKG, "Git.PushAllBranches.Label") + .equals(prop)) { + this.pushAllBranches = Boolean.parseBoolean(stringProp + .split(":")[1].trim()); + } else if (BaseMessages.getString(PKG, "Git.PushAllTag.Label") + .equals(prop)) { + this.pushAllTags = Boolean + .parseBoolean(stringProp.split(":")[1].trim()); + } + } + } + + public PushGitCommand(Node xml, String stepName) { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/referenceToPush/text()"); + this.referenceToPush = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/remote/text()"); + this.remote = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/receivePack/text()"); + this.receivePack = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/dryRun/text()"); + this.dryRun = Boolean.parseBoolean((String) xPathExpr.evaluate(xml, + XPathConstants.STRING)); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/force/text()"); + this.force = Boolean.parseBoolean((String) xPathExpr.evaluate(xml, + XPathConstants.STRING)); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/thin/text()"); + this.thin = Boolean.parseBoolean((String) xPathExpr.evaluate(xml, + XPathConstants.STRING)); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/pushAllBranches/text()"); + this.pushAllBranches = Boolean.parseBoolean((String) xPathExpr + .evaluate(xml, XPathConstants.STRING)); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/pushAllTag/text()"); + this.pushAllTags = Boolean.parseBoolean((String) xPathExpr + .evaluate(xml, XPathConstants.STRING)); + + } catch (XPathExpressionException e) { + LOGGER.error(e.getMessage(), e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.ReferenceToPush.Label") + ": " + + (referenceToPush == null ? "" : referenceToPush) + " / " + + BaseMessages.getString(PKG, "Git.Remote.Label") + ": " + + (remote == null ? "" : remote) + " / " + + BaseMessages.getString(PKG, "Git.ReceivePack.Label") + ": " + + (receivePack == null ? "" : receivePack) + " / " + + BaseMessages.getString(PKG, "Git.DryRun.Label") + ": " + + dryRun + " / " + + BaseMessages.getString(PKG, "Git.Force.Label") + ": " + force + + " / " + BaseMessages.getString(PKG, "Git.Thin.Label") + ": " + + thin + " / " + + BaseMessages.getString(PKG, "Git.PushAllBranches.Label") + + ": " + pushAllBranches + " / " + + BaseMessages.getString(PKG, "Git.PushAllTag.Label") + ": " + + pushAllTags; + } + + public GitCommandType getCommandType() { + return GitCommandType.PUSH; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc.createTextNode(GitCommandType.PUSH + .getOperationName())); + root.appendChild(commandName); + + final Element referenceToPushNode = doc + .createElement("referenceToPush"); + referenceToPushNode + .appendChild(doc.createTextNode(referenceToPush)); + root.appendChild(referenceToPushNode); + + final Element remoteNode = doc.createElement("remote"); + remoteNode.appendChild(doc.createTextNode(remote)); + root.appendChild(remoteNode); + + final Element receivePackNode = doc.createElement("receivePack"); + receivePackNode.appendChild(doc.createTextNode(receivePack)); + root.appendChild(receivePackNode); + + final Element dryRunNode = doc.createElement("dryRun"); + dryRunNode.appendChild(doc.createTextNode(String.valueOf(dryRun))); + root.appendChild(dryRunNode); + + final Element forceNode = doc.createElement("force"); + forceNode.appendChild(doc.createTextNode(String.valueOf(force))); + root.appendChild(forceNode); + + final Element thinNode = doc.createElement("thin"); + thinNode.appendChild(doc.createTextNode(String.valueOf(thin))); + root.appendChild(thinNode); + + final Element pushAllBranchesNode = doc + .createElement("pushAllBranches"); + pushAllBranchesNode.appendChild(doc.createTextNode(String + .valueOf(pushAllBranches))); + root.appendChild(pushAllBranchesNode); + + final Element pushAllTagNode = doc.createElement("pushAllTag"); + pushAllTagNode.appendChild(doc.createTextNode(String + .valueOf(pushAllTags))); + root.appendChild(pushAllTagNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public Git call(final GitOperationsStep gitOperationsStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws IllegalArgumentException, IOException, + InvalidRemoteException, TransportException, GitAPIException { + + PushCommand pc = git.push().setDryRun(dryRun).setForce(force) + .setThin(thin); + if (cp != null) { + pc = pc.setCredentialsProvider(cp); + } + if (!Const.isEmpty(this.receivePack)) { + pc = pc.setReceivePack(gitOperationsStep + .environmentSubstitute(receivePack)); + } + if (!Const.isEmpty(this.referenceToPush)) { + pc = pc.add(gitOperationsStep + .environmentSubstitute(this.referenceToPush)); + } + if (!Const.isEmpty(this.remote)) { + pc = pc.setRemote(gitOperationsStep + .environmentSubstitute(this.remote)); + } + if (this.pushAllBranches) { + pc = pc.setPushAll(); + } + if (this.pushAllTags) { + pc = pc.setPushTags(); + } + pc.call(); + return git; + } + + public String getReferenceToPush() { + return referenceToPush; + } + + public void setReferenceToPush(String referenceToPush) { + this.referenceToPush = referenceToPush; + } + + public String getRemote() { + return remote; + } + + public void setRemote(String remote) { + this.remote = remote; + } + + public String getReceivePack() { + return receivePack; + } + + public void setReceivePack(String receivePack) { + this.receivePack = receivePack; + } + + public boolean isDryRun() { + return dryRun; + } + + public void setDryRun(boolean dryRun) { + this.dryRun = dryRun; + } + + public boolean isForce() { + return force; + } + + public void setForce(boolean force) { + this.force = force; + } + + public boolean isThin() { + return thin; + } + + public void setThin(boolean thin) { + this.thin = thin; + } + + public boolean isPushAllBranches() { + return pushAllBranches; + } + + public void setPushAllBranches(boolean pushAllBranches) { + this.pushAllBranches = pushAllBranches; + } + + public boolean isPushAllTags() { + return pushAllTags; + } + + public void setPushAllTags(boolean pushAllTags) { + this.pushAllTags = pushAllTags; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/TagGitCommand.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/TagGitCommand.java new file mode 100644 index 0000000..f93a449 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/TagGitCommand.java @@ -0,0 +1,254 @@ +package com.ivyis.di.trans.steps.git.command.impl; + +import java.io.File; +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.log4j.Logger; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.TagCommand; +import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidTagNameException; +import org.eclipse.jgit.api.errors.NoHeadException; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitOperationsCommand; +import com.ivyis.di.trans.steps.git.operations.GitOperationsStep; + +/** + * Tag Git command implementation. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class TagGitCommand implements GitOperationsCommand { + private static final Class PKG = TagGitCommand.class; // for i18n + private static final Logger LOGGER = Logger.getLogger(PKG); + + private String message; + private String name; + private boolean annotated; + private boolean forceUpdate; + private boolean signed; + + public TagGitCommand() {} + + public TagGitCommand(String description) { + if ("".equals(description)) { + throw new IllegalArgumentException("Unkomnown config fields."); + } + final String[] stringProps = description.split(" / "); + for (String stringProp : stringProps) { + if (BaseMessages.getString(PKG, "Git.Message.Label").equals( + stringProp.split(":")[0].trim())) { + this.message = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.Name.Label").equals( + stringProp.split(":")[0].trim())) { + this.name = stringProp.split(":")[1].trim(); + } else if (BaseMessages.getString(PKG, "Git.Annotated.Label") + .equals(stringProp.split(":")[0].trim())) { + this.annotated = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } else if (BaseMessages.getString(PKG, "Git.ForceUpdate.Label") + .equals(stringProp.split(":")[0].trim())) { + this.forceUpdate = Boolean + .parseBoolean(stringProp.split(":")[1].trim()); + } else if (BaseMessages.getString(PKG, "Git.Signed.Label").equals( + stringProp.split(":")[0].trim())) { + this.signed = Boolean.parseBoolean(stringProp.split(":")[1] + .trim()); + } + } + } + + public TagGitCommand(Node xml, String stepName) { + try { + final XPathFactory xPathFactory = XPathFactory.newInstance(); + final XPath xpath = xPathFactory.newXPath(); + XPathExpression xPathExpr = xpath.compile("//step[name='" + + stepName + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/message/text()"); + this.message = (String) xPathExpr.evaluate(xml, + XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/name/text()"); + this.name = (String) xPathExpr.evaluate(xml, XPathConstants.STRING); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/annotated/text()"); + this.annotated = Boolean.parseBoolean((String) xPathExpr.evaluate( + xml, XPathConstants.STRING)); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/forceUpdate/text()"); + this.forceUpdate = Boolean.parseBoolean((String) xPathExpr + .evaluate(xml, XPathConstants.STRING)); + + xPathExpr = xpath.compile("//step[name='" + stepName + + "']/gitCommands//" + GitCommand.MAIN_NODE + + "/signed/text()"); + this.signed = Boolean.parseBoolean((String) xPathExpr.evaluate(xml, + XPathConstants.STRING)); + + } catch (XPathExpressionException e) { + LOGGER.error(e.getMessage(), e); + } + } + + public String getDescription() { + return BaseMessages.getString(PKG, "Git.Message.Label") + ": " + + (message == null ? "" : message) + " / " + + BaseMessages.getString(PKG, "Git.Name.Label") + ": " + + (name == null ? "" : name) + " / " + + BaseMessages.getString(PKG, "Git.Annotated.Label") + ": " + + annotated + " / " + + BaseMessages.getString(PKG, "Git.ForceUpdate.Label") + ": " + + forceUpdate + " / " + + BaseMessages.getString(PKG, "Git.Signed.Label") + ": " + + signed; + } + + public GitCommandType getCommandType() { + return GitCommandType.TAG; + } + + public String getXML() { + try { + final DocumentBuilderFactory dFact = DocumentBuilderFactory + .newInstance(); + final DocumentBuilder build = dFact.newDocumentBuilder(); + final Document doc = build.newDocument(); + final Element root = doc.createElement(MAIN_NODE); + doc.appendChild(root); + final Element commandName = doc.createElement(COMMAND_NAME_NODE); + commandName.appendChild(doc.createTextNode(GitCommandType.TAG + .getOperationName())); + root.appendChild(commandName); + + final Element messageNode = doc.createElement("message"); + messageNode.appendChild(doc.createTextNode(message)); + root.appendChild(messageNode); + + final Element nameNode = doc.createElement("name"); + nameNode.appendChild(doc.createTextNode(name)); + root.appendChild(nameNode); + + final Element annotatedNode = doc.createElement("annotated"); + annotatedNode.appendChild(doc.createTextNode(String + .valueOf(annotated))); + root.appendChild(annotatedNode); + + final Element forceUpdateNode = doc.createElement("forceUpdate"); + forceUpdateNode.appendChild(doc.createTextNode(String + .valueOf(forceUpdate))); + root.appendChild(forceUpdateNode); + + final Element signedNode = doc.createElement("signed"); + signedNode.appendChild(doc.createTextNode(String.valueOf(signed))); + root.appendChild(signedNode); + + final Transformer tf = TransformerFactory.newInstance() + .newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + final Writer out = new StringWriter(); + tf.transform(new DOMSource(doc), new StreamResult(out)); + return out.toString(); + + } catch (ParserConfigurationException pce) { + LOGGER.error(pce.getMessage(), pce); + return ""; + } catch (TransformerException e) { + LOGGER.error(e.getMessage(), e); + return ""; + } + } + + public Git call(final GitOperationsStep gitOperationsStep, Git git, + CredentialsProvider cp, String gitRepoUrl, File gitRepoFolder) + throws IllegalArgumentException, IOException, + ConcurrentRefUpdateException, InvalidTagNameException, + NoHeadException, GitAPIException { + TagCommand tc = git.tag().setAnnotated(annotated) + .setForceUpdate(forceUpdate).setSigned(signed); + if (!Const.isEmpty(this.message)) { + tc = tc.setMessage(gitOperationsStep + .environmentSubstitute(this.message)); + } + if (!Const.isEmpty(this.name)) { + tc = tc.setName(gitOperationsStep.environmentSubstitute(this.name)); + } + tc.call(); + return git; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isAnnotated() { + return annotated; + } + + public void setAnnotated(boolean annotated) { + this.annotated = annotated; + } + + public boolean isForceUpdate() { + return forceUpdate; + } + + public void setForceUpdate(boolean forceUpdate) { + this.forceUpdate = forceUpdate; + } + + public boolean isSigned() { + return signed; + } + + public void setSigned(boolean signed) { + this.signed = signed; + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/impl/package-info.java b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/package-info.java new file mode 100644 index 0000000..454cbcd --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/impl/package-info.java @@ -0,0 +1,8 @@ +/** + * Package with Git command implementations for PDI. + * + * @author Joel Latino + * @since 1.0.0 + */ +package com.ivyis.di.trans.steps.git.command.impl; + diff --git a/src/main/java/com/ivyis/di/trans/steps/git/command/package-info.java b/src/main/java/com/ivyis/di/trans/steps/git/command/package-info.java new file mode 100644 index 0000000..ee9851e --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/command/package-info.java @@ -0,0 +1,8 @@ +/** + * Package with generic classes of git commands. + * + * @author Joel Latino + * @since 1.0.0 + */ +package com.ivyis.di.trans.steps.git.command; + diff --git a/src/main/java/com/ivyis/di/trans/steps/git/dialog/BaseGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/dialog/BaseGitCommandDialog.java new file mode 100644 index 0000000..8efb443 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/dialog/BaseGitCommandDialog.java @@ -0,0 +1,16 @@ +package com.ivyis.di.trans.steps.git.dialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; + +/** + * Interface thats describes the methods of Git command for the UI in Spoon. + * + * @author Joel Latino + * @since 1.0.0 + */ +public interface BaseGitCommandDialog { + public static final boolean NO_CONFIGURATION = false; + + public abstract GitCommand open(); + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/dialog/GitCommandDialogFactory.java b/src/main/java/com/ivyis/di/trans/steps/git/dialog/GitCommandDialogFactory.java new file mode 100644 index 0000000..ee46dd0 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/dialog/GitCommandDialogFactory.java @@ -0,0 +1,57 @@ +package com.ivyis.di.trans.steps.git.dialog; + +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.trans.TransMeta; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.info.dialog.impl.ListBranchsGitCommandDialog; +import com.ivyis.di.trans.steps.git.info.dialog.impl.LogGitCommandDialog; +import com.ivyis.di.trans.steps.git.operations.dialog.impl.AddGitCommandDialog; +import com.ivyis.di.trans.steps.git.operations.dialog.impl.CheckoutGitCommandDialog; +import com.ivyis.di.trans.steps.git.operations.dialog.impl.CloneGitCommandDialog; +import com.ivyis.di.trans.steps.git.operations.dialog.impl.CommitGitCommandDialog; +import com.ivyis.di.trans.steps.git.operations.dialog.impl.InitGitCommandDialog; +import com.ivyis.di.trans.steps.git.operations.dialog.impl.PullGitCommandDialog; +import com.ivyis.di.trans.steps.git.operations.dialog.impl.PushGitCommandDialog; +import com.ivyis.di.trans.steps.git.operations.dialog.impl.TagGitCommandDialog; + +/** + * The Git commands factory for UI. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class GitCommandDialogFactory { + + public static BaseGitCommandDialog getGitCommandDialog(Shell parent, + TransMeta transMeta, GitCommand gitCommand, + GitCommandType gitCommandType) { + switch (gitCommandType) { + case LIST_BRANCHS: + return new ListBranchsGitCommandDialog(parent, transMeta, + gitCommand); + case LOG: + return new LogGitCommandDialog(parent, transMeta, gitCommand); + case CLONE: + return new CloneGitCommandDialog(parent, transMeta, gitCommand); + case ADD: + return new AddGitCommandDialog(parent, transMeta, gitCommand); + case INIT: + return new InitGitCommandDialog(parent, transMeta, gitCommand); + case PULL: + return new PullGitCommandDialog(parent, transMeta, gitCommand); + case COMMIT: + return new CommitGitCommandDialog(parent, transMeta, gitCommand); + case PUSH: + return new PushGitCommandDialog(parent, transMeta, gitCommand); + case TAG: + return new TagGitCommandDialog(parent, transMeta, gitCommand); + case CHECKOUT: + return new CheckoutGitCommandDialog(parent, transMeta, gitCommand); + + default: + throw new IllegalArgumentException("Unkomnown command type dialog."); + } + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/dialog/package-info.java b/src/main/java/com/ivyis/di/trans/steps/git/dialog/package-info.java new file mode 100644 index 0000000..a9edae9 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/dialog/package-info.java @@ -0,0 +1,8 @@ +/** + * Package with classes generic of UI Git commands. + * + * @author Joel Latino + * @since 1.0.0 + */ +package com.ivyis.di.trans.steps.git.dialog; + diff --git a/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStep.java b/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStep.java new file mode 100644 index 0000000..8dbff5b --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStep.java @@ -0,0 +1,182 @@ +package com.ivyis.di.trans.steps.git.info; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidRemoteException; +import org.eclipse.jgit.api.errors.TransportException; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; +import org.pentaho.di.core.Const; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.core.exception.KettleFileException; +import org.pentaho.di.core.exception.KettleStepException; +import org.pentaho.di.core.row.RowDataUtil; +import org.pentaho.di.core.row.RowMeta; +import org.pentaho.di.core.vfs.KettleVFS; +import org.pentaho.di.trans.Trans; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.trans.step.BaseStep; +import org.pentaho.di.trans.step.StepDataInterface; +import org.pentaho.di.trans.step.StepInterface; +import org.pentaho.di.trans.step.StepMeta; +import org.pentaho.di.trans.step.StepMetaInterface; + +import com.ivyis.di.trans.steps.git.command.GitInfoCommand; + +/** + * This class is responsible to processing the data rows. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class GitInfoStep extends BaseStep implements StepInterface { + + private GitInfoStepMeta meta; + private GitInfoStepData data; + + public GitInfoStep(StepMeta s, StepDataInterface stepDataInterface, int c, + TransMeta t, Trans dis) { + super(s, stepDataInterface, c, t, dis); + } + + /** + * {@inheritDoc} + * + * @throws KettleException + */ + @Override + public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) + throws KettleException { + this.meta = (GitInfoStepMeta) smi; + this.data = (GitInfoStepData) sdi; + + if (first) { + first = false; + data.outputRowMeta = new RowMeta(); + data.nrPrevFields = data.outputRowMeta.size(); + meta.getFields(data.outputRowMeta, getStepname(), null, null, this); + + try { + final Repository repository = FileRepositoryBuilder + .create(new File(data.gitRepoFolderPath, ".git")); + final Git git = new Git(repository); + logBasic("Starting, command " + + data.gitCommand.getCommandType()); + data.result = ((GitInfoCommand) data.gitCommand).call(this, + git, data.cp, data.gitRepoUrl, data.gitRepoFolderPath); + git.close(); + logBasic("Finished, command " + + data.gitCommand.getCommandType()); + } catch (InvalidRemoteException e) { + throw new KettleException(e); + } catch (TransportException e) { + throw new KettleException(e); + } catch (GitAPIException e) { + throw new KettleException(e); + } catch (IllegalArgumentException e) { + throw new KettleException(e); + } catch (IOException e) { + throw new KettleException(e); + } + cachePosition(); + } // end if first + + if (data.rowNumber >= data.result.size()) { + setOutputDone(); // signal end to receiver(s) + logDebug("Finished, processing all rows of git command " + + data.gitCommand.getCommandType()); + return false; // end of data or error. + } + + final String[] row = data.result.get(data.rowNumber++); + final Object[] outputRowData = RowDataUtil.allocateRowData(row.length); + for (int i = 0; i < row.length; i++) { + outputRowData[i] = row[i]; + } + putRow(data.outputRowMeta, outputRowData); + + if (checkFeedback(getLinesRead())) { + if (log.isBasic()) { + logBasic("Linenr " + getLinesRead()); // Some basic logging + } + } + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean init(StepMetaInterface smi, StepDataInterface sdi) { + meta = (GitInfoStepMeta) smi; + data = (GitInfoStepData) sdi; + + if (super.init(smi, sdi)) { + if (meta.getUsername() != null && meta.getPassword() != null) { + data.cp = new UsernamePasswordCredentialsProvider( + environmentSubstitute(meta.getUsername()), + environmentSubstitute(meta.getPassword())); + } + if (meta.getGitRepoUrl() != null) { + data.gitRepoUrl = environmentSubstitute(meta.getGitRepoUrl()); + } + if (meta.getGitRepoFolderPath() != null) { + try { + data.gitRepoFolderPath = new File( + KettleVFS.getFilename(KettleVFS + .getFileObject(environmentSubstitute(meta + .getGitRepoFolderPath())))); + } catch (KettleFileException e) { + logError(e.getMessage(), e); + } + } + if (meta.getGitCommand() != null) { + data.gitCommand = meta.getGitCommand(); + } + return true; + } + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose(StepMetaInterface smi, StepDataInterface sdi) { + super.dispose(smi, sdi); + } + + /** + * Run is were the action happens. + */ + public void run() { + logBasic("Starting to run..."); + try { + while (processRow(meta, data) && !isStopped()) { + continue; + } + } catch (Exception e) { + logError("Unexpected error : " + e.toString()); + logError(Const.getStackTracker(e)); + setErrors(1); + stopAll(); + } finally { + dispose(meta, data); + logBasic("Finished, processing " + getLinesRead() + " rows"); + markStop(); + } + } + + /** + * Checks the fields positions. + * + * @throws KettleStepException the kettle step exception. + */ + private void cachePosition() throws KettleStepException { + + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepData.java b/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepData.java new file mode 100644 index 0000000..f27aeb7 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepData.java @@ -0,0 +1,31 @@ +package com.ivyis.di.trans.steps.git.info; + +import java.io.File; +import java.util.List; + +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.row.RowMetaInterface; +import org.pentaho.di.trans.step.BaseStepData; +import org.pentaho.di.trans.step.StepDataInterface; + +import com.ivyis.di.trans.steps.git.command.GitCommand; + +/** + * This class contains the methods to set and retrieve the status of the step data. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class GitInfoStepData extends BaseStepData implements StepDataInterface { + RowMetaInterface outputRowMeta = null; + RowMetaInterface insertRowMeta = null; + int fieldnr = 0; + int nrPrevFields = 0; + + CredentialsProvider cp; + String gitRepoUrl = null; + File gitRepoFolderPath = null; + GitCommand gitCommand = null; + int rowNumber = 0; + List result = null; +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepDialog.java new file mode 100644 index 0000000..c56bf91 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepDialog.java @@ -0,0 +1,1115 @@ +package com.ivyis.di.trans.steps.git.info; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.custom.CTabFolder; +import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.pentaho.di.core.Const; +import org.pentaho.di.core.Props; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.core.util.StringUtil; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.trans.step.BaseStepMeta; +import org.pentaho.di.trans.step.StepDialogInterface; +import org.pentaho.di.ui.core.dialog.ErrorDialog; +import org.pentaho.di.ui.core.dialog.ShowBrowserDialog; +import org.pentaho.di.ui.core.widget.ColumnInfo; +import org.pentaho.di.ui.core.widget.LabelTextVar; +import org.pentaho.di.ui.core.widget.TableView; +import org.pentaho.di.ui.core.widget.TextVar; +import org.pentaho.di.ui.trans.step.BaseStepDialog; +import org.pentaho.di.ui.util.ImageUtil; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommandFactory; +import com.ivyis.di.trans.steps.git.command.GitInfoCommand; +import com.ivyis.di.trans.steps.git.command.impl.CurrentBranchGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; +import com.ivyis.di.trans.steps.git.dialog.GitCommandDialogFactory; + +/** + * This class is responsible for the UI in Spoon of Git information step. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class GitInfoStepDialog extends BaseStepDialog implements + StepDialogInterface { + + /** for i18n purposes. **/ + private static final Class PKG = GitInfoStepDialog.class; + private static final Logger LOGGER = Logger.getLogger(PKG); + + private GitInfoStepMeta input; + private Text wIdField, wNameField, wShortMessageField, wFullMessageField, + wAuthorCreationDateField, wAuthorNameField, wAuthorEmailField, + wCommitterCreationDateField, wCommitterNameField, + wCommitterEmailField; + private TextVar wUsernameField, wRepoUrlField, wRepoFolderPathField; + private LabelTextVar wPasswordField; + private CCombo wGitInfoCommandField; + private Map configFields = new HashMap(); + private ColumnInfo[] ciFields; + private TableView wFields; + private Button wGetFields; + private CTabFolder wTabFolder; + private CTabItem wMainOptionsTab; + private GitInfoCommand gitCommand; + + public GitInfoStepDialog(Shell parent, BaseStepMeta in, + TransMeta transMeta, String sname) { + super(parent, in, transMeta, sname); + this.input = (GitInfoStepMeta) in; + } + + /** + * Opens a step dialog window. + * + * @return the (potentially new) name of the step + */ + public String open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN + | SWT.MAX); + props.setLook(shell); + setShellImage(shell, this.input); + + final ModifyListener lsMod = new ModifyListener() { + public void modifyText(ModifyEvent arg0) { + input.setChanged(); + } + }; + backupChanged = input.hasChanged(); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Git.Shell.Title")); + + final int middle = props.getMiddlePct(); + final int margin = Const.MARGIN; + + // Stepname line + wlStepname = new Label(shell, SWT.RIGHT); + wlStepname + .setText(BaseMessages.getString(PKG, "System.Label.StepName")); + props.setLook(wlStepname); + fdlStepname = new FormData(); + fdlStepname.left = new FormAttachment(0, 0); + fdlStepname.right = new FormAttachment(middle, -margin); + fdlStepname.top = new FormAttachment(0, margin); + wlStepname.setLayoutData(fdlStepname); + + wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wStepname.setText(stepname); + props.setLook(wStepname); + wStepname.addModifyListener(lsMod); + fdStepname = new FormData(); + fdStepname.left = new FormAttachment(middle, 0); + fdStepname.top = new FormAttachment(0, margin); + fdStepname.right = new FormAttachment(100, 0); + wStepname.setLayoutData(fdStepname); + + final ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL + | SWT.V_SCROLL); + + wTabFolder = new CTabFolder(sc, SWT.BORDER); + props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB); + + // ///////////////////////////////// + // START OF Main Options TAB // + // ///////////////////////////////// + wMainOptionsTab = new CTabItem(wTabFolder, SWT.NONE); + wMainOptionsTab.setText(BaseMessages.getString(PKG, + "Git.MainOptionTab.CTabItem.Title")); + + final FormLayout mainOptionsLayout = new FormLayout(); + mainOptionsLayout.marginWidth = 3; + mainOptionsLayout.marginHeight = 3; + + final Composite wMainOptionsComp = new Composite(wTabFolder, SWT.NONE); + props.setLook(wMainOptionsComp); + wMainOptionsComp.setLayout(mainOptionsLayout); + + // //////////////////////////// + // START OF OPERATIONS GROUP // + // //////////////////////////// + final Group gBasicPropertiesFields = new Group(wMainOptionsComp, + SWT.SHADOW_NONE); + props.setLook(gBasicPropertiesFields); + gBasicPropertiesFields.setText(BaseMessages.getString(PKG, + "Git.gBasicPropertiesFields.Label")); + final FormLayout flgFieldNamesLayout = new FormLayout(); + flgFieldNamesLayout.marginWidth = 10; + flgFieldNamesLayout.marginHeight = 10; + gBasicPropertiesFields.setLayout(flgFieldNamesLayout); + + // UserName field + final Label wlUsernameField = new Label(gBasicPropertiesFields, + SWT.RIGHT); + wlUsernameField.setText(BaseMessages.getString(PKG, + "Git.UserName.Label")); + props.setLook(wlUsernameField); + final FormData fdlUsernameField = new FormData(); + fdlUsernameField.left = new FormAttachment(0, -margin); + fdlUsernameField.top = new FormAttachment(wStepname, margin); + fdlUsernameField.right = new FormAttachment(middle, -2 * margin); + wlUsernameField.setLayoutData(fdlUsernameField); + + wUsernameField = new TextVar(this.transMeta, gBasicPropertiesFields, + SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wUsernameField.setEditable(true); + props.setLook(wUsernameField); + final FormData fdUsernameField = new FormData(); + fdUsernameField.left = new FormAttachment(middle, -margin); + fdUsernameField.top = new FormAttachment(wStepname, margin); + fdUsernameField.right = new FormAttachment(100, -margin); + wUsernameField.setLayoutData(fdUsernameField); + + // Git repository password value + wPasswordField = new LabelTextVar(transMeta, gBasicPropertiesFields, + BaseMessages.getString(PKG, "Git.PasswordField.Label"), + BaseMessages.getString(PKG, "Git.PasswordField.Tooltip")); + props.setLook(wPasswordField); + wPasswordField.setEchoChar('*'); + wPasswordField.addModifyListener(lsMod); + final FormData fdCertificatePassword = new FormData(); + fdCertificatePassword.left = new FormAttachment(0, -margin); + fdCertificatePassword.top = new FormAttachment(wUsernameField, margin); + fdCertificatePassword.right = new FormAttachment(100, -margin); + wPasswordField.setLayoutData(fdCertificatePassword); + + // OK, if the password contains a variable, we don't want to have the + // password hidden... + wPasswordField.getTextWidget().addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + checkPasswordVisible(); + } + }); + + // Git Repository URL + final Label wlRepoUrlField = new Label(gBasicPropertiesFields, + SWT.RIGHT); + wlRepoUrlField.setText(BaseMessages.getString(PKG, + "Git.RepoUrlField.Label")); + props.setLook(wlRepoUrlField); + final FormData fdlRepoUrlField = new FormData(); + fdlRepoUrlField.left = new FormAttachment(0, -margin); + fdlRepoUrlField.top = new FormAttachment(wPasswordField, margin); + fdlRepoUrlField.right = new FormAttachment(middle, -2 * margin); + wlRepoUrlField.setLayoutData(fdlRepoUrlField); + + wRepoUrlField = new TextVar(transMeta, gBasicPropertiesFields, + SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wRepoUrlField); + wRepoUrlField.addModifyListener(lsMod); + final FormData fdRepoUrlField = new FormData(); + fdRepoUrlField.left = new FormAttachment(middle, -margin); + fdRepoUrlField.top = new FormAttachment(wPasswordField, margin); + fdRepoUrlField.right = new FormAttachment(100, -margin); + wRepoUrlField.setLayoutData(fdRepoUrlField); + + // Git clone repository folder + final Label wlRepoFolderPathField = new Label(gBasicPropertiesFields, + SWT.RIGHT); + wlRepoFolderPathField.setText(BaseMessages.getString(PKG, + "Git.RepoFolderPathField.Label")); + props.setLook(wlRepoFolderPathField); + final FormData fdlRepoFolderPathField = new FormData(); + fdlRepoFolderPathField.left = new FormAttachment(0, -margin); + fdlRepoFolderPathField.top = new FormAttachment(wRepoUrlField, margin); + fdlRepoFolderPathField.right = new FormAttachment(middle, -2 * margin); + wlRepoFolderPathField.setLayoutData(fdlRepoFolderPathField); + + wRepoFolderPathField = new TextVar(transMeta, gBasicPropertiesFields, + SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wRepoUrlField); + wRepoFolderPathField.addModifyListener(lsMod); + final FormData fdRepoFolderPathField = new FormData(); + fdRepoFolderPathField.left = new FormAttachment(middle, -margin); + fdRepoFolderPathField.top = new FormAttachment(wRepoUrlField, margin); + fdRepoFolderPathField.right = new FormAttachment(100, -margin); + wRepoFolderPathField.setLayoutData(fdRepoFolderPathField); + + final FormData fdOperationsFields = new FormData(); + fdOperationsFields.left = new FormAttachment(0, margin); + fdOperationsFields.top = new FormAttachment(wStepname, 2 * margin); + fdOperationsFields.right = new FormAttachment(100, -margin); + gBasicPropertiesFields.setLayoutData(fdOperationsFields); + + // ////////////////////////// + // END OF OPERATIONS GROUP // + // ////////////////////////// + + // Retrying in case of unavailability + final Label wlGitInfoCommandField = new Label(wMainOptionsComp, + SWT.RIGHT); + wlGitInfoCommandField.setText(BaseMessages.getString(PKG, + "Git.GitInfoCommands.Label")); + props.setLook(wlGitInfoCommandField); + final FormData fdlGitInfoCommandField = new FormData(); + fdlGitInfoCommandField.left = new FormAttachment(0, -margin); + fdlGitInfoCommandField.top = new FormAttachment(gBasicPropertiesFields, + margin); + fdlGitInfoCommandField.right = new FormAttachment(middle, -2 * margin); + wlGitInfoCommandField.setLayoutData(fdlGitInfoCommandField); + + wGitInfoCommandField = new CCombo(wMainOptionsComp, SWT.BORDER + | SWT.READ_ONLY); + wGitInfoCommandField.setEditable(true); + props.setLook(wGitInfoCommandField); + final FormData fdGitInfoCommandField = new FormData(); + fdGitInfoCommandField.left = new FormAttachment(middle, -margin); + fdGitInfoCommandField.top = new FormAttachment(gBasicPropertiesFields, + margin); + fdGitInfoCommandField.right = new FormAttachment(100, -margin); + wGitInfoCommandField.setLayoutData(fdGitInfoCommandField); + wGitInfoCommandField.setItems(GitCommandType.getInfoTypesLabel()); + wGitInfoCommandField.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + final String commandName = wGitInfoCommandField.getText(); + if (GitCommandType.CURRENT_BRANCH.equals(GitCommandType + .fromLabel(commandName))) { + try { + gitCommand = GitCommandFactory.getGitCommand( + GitCommandType.fromLabel(commandName), + configFields); + } catch (KettleException e1) { + LOGGER.error(e1.getMessage(), e1); + } + enableOutputFields(false); + } else { + enableOutputFields(true); + } + } + }); + + // The fields table + final Label wlFields = new Label(wMainOptionsComp, SWT.NONE); + wlFields.setText(BaseMessages.getString(PKG, "Git.ConfigFields.Label")); + props.setLook(wlFields); + final FormData fdlUpIns = new FormData(); + fdlUpIns.left = new FormAttachment(0, 0); + fdlUpIns.top = new FormAttachment(wGitInfoCommandField, margin); + wlFields.setLayoutData(fdlUpIns); + + final int tableCols = 2; + final int upInsRows = configFields != null ? configFields.size() : 1; + + ciFields = new ColumnInfo[tableCols]; + ciFields[0] = new ColumnInfo(BaseMessages.getString(PKG, + "Git.ColumnInfo.FieldName"), ColumnInfo.COLUMN_TYPE_TEXT, + new String[] {""}, true); + ciFields[1] = new ColumnInfo(BaseMessages.getString(PKG, + "Git.ColumnInfo.FieldValue"), ColumnInfo.COLUMN_TYPE_TEXT, + new String[] {""}, true); + wFields = new TableView(transMeta, wMainOptionsComp, SWT.BORDER + | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, + ciFields, upInsRows, lsMod, props); + + wGetFields = new Button(wMainOptionsComp, SWT.PUSH); + wGetFields.setText(BaseMessages.getString(PKG, + "Git.DefineFields.Button")); + final FormData fdGetFields = new FormData(); + fdGetFields.top = new FormAttachment(wlFields, margin); + fdGetFields.right = new FormAttachment(100, 0); + wGetFields.setLayoutData(fdGetFields); + + wGetFields.addListener(SWT.Selection, new Listener() { + public void handleEvent(Event e) { + final String commandName = wGitInfoCommandField.getText(); + if ("".equals(commandName)) { + wFields.clearAll(); + return; + } + + try { + gitCommand = GitCommandFactory.getGitCommand( + GitCommandType.fromLabel(commandName), configFields); + } catch (KettleException ex) { + new ErrorDialog(shell, BaseMessages.getString(PKG, + "Git.GitCommandNotFount.DialogTitle"), BaseMessages + .getString(PKG, + "Git.GitCommandNotFount.DialogMessage"), ex); + } + if (gitCommand.isConfigurable() != BaseGitCommandDialog.NO_CONFIGURATION) { + final BaseGitCommandDialog gcd = GitCommandDialogFactory + .getGitCommandDialog(shell, transMeta, gitCommand, + GitCommandType.fromLabel(commandName)); + gitCommand = (GitInfoCommand) gcd.open(); + + if (gitCommand != null) { + wFields.clearAll(); + boolean first = true; + for (Map.Entry entry : gitCommand + .getConfigFields(true).entrySet()) { + configFields.put(entry.getKey(), entry.getValue()); + if (entry.getKey() == null + || entry.getValue() == null) { + continue; + } + if (first) { + wFields.setText(entry.getKey(), 1, 0); + wFields.setText(entry.getValue(), 2, 0); + first = false; + } else { + final TableItem tableItem = new TableItem( + wFields.table, SWT.NONE); + tableItem.setText(1, entry.getKey()); + tableItem.setText(2, entry.getValue()); + } + } + input.setChanged(); + } else { + wFields.clearAll(); + } + } else { + final MessageBox mb = new MessageBox(shell, SWT.OK + | SWT.ICON_INFORMATION); + mb.setMessage(BaseMessages.getString(PKG, + "Git.Info.Nothing.Conf.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, + "System.Dialog.Info.Title")); + mb.open(); + wFields.clearAll(); + } + } + }); + + final FormData fdFields = new FormData(); + fdFields.left = new FormAttachment(0, 0); + fdFields.top = new FormAttachment(wlFields, margin); + fdFields.right = new FormAttachment(wGetFields, -margin); + fdFields.bottom = new FormAttachment(wlFields, 100); + wFields.setLayoutData(fdFields); + + // //////////////////////// + // START OF FIELDS GROUP // + // //////////////////////// + final Group gFieldNames = new Group(wMainOptionsComp, SWT.SHADOW_NONE); + props.setLook(gFieldNames); + gFieldNames.setText(BaseMessages.getString(PKG, + "Git.OutputFieldNames.Label")); + final FormLayout flgOperationsFieldsLayout = new FormLayout(); + flgOperationsFieldsLayout.marginWidth = 10; + flgOperationsFieldsLayout.marginHeight = 10; + gFieldNames.setLayout(flgOperationsFieldsLayout); + + // Id field + final Label wlIdField = new Label(gFieldNames, SWT.RIGHT); + wlIdField.setText(BaseMessages.getString(PKG, "Git.IdField.Label")); + props.setLook(wlIdField); + final FormData fdlIdField = new FormData(); + fdlIdField.left = new FormAttachment(0, -margin); + fdlIdField.top = new FormAttachment(wFields, margin); + fdlIdField.right = new FormAttachment(middle, -2 * margin); + wlIdField.setLayoutData(fdlIdField); + + wIdField = new Text(gFieldNames, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wIdField.setEditable(true); + wIdField.setText("Id"); + props.setLook(wIdField); + final FormData fdIdField = new FormData(); + fdIdField.left = new FormAttachment(middle, -margin); + fdIdField.top = new FormAttachment(wFields, margin); + fdIdField.right = new FormAttachment(100, -margin); + wIdField.setLayoutData(fdIdField); + + // Name field + final Label wlNameField = new Label(gFieldNames, SWT.RIGHT); + wlNameField.setText(BaseMessages.getString(PKG, "Git.NameField.Label")); + props.setLook(wlNameField); + final FormData fdlNameField = new FormData(); + fdlNameField.left = new FormAttachment(0, -margin); + fdlNameField.top = new FormAttachment(wIdField, margin); + fdlNameField.right = new FormAttachment(middle, -2 * margin); + wlNameField.setLayoutData(fdlNameField); + + wNameField = new Text(gFieldNames, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wNameField.setEditable(true); + wNameField.setText("Name"); + props.setLook(wNameField); + final FormData fdNameField = new FormData(); + fdNameField.left = new FormAttachment(middle, -margin); + fdNameField.top = new FormAttachment(wIdField, margin); + fdNameField.right = new FormAttachment(100, -margin); + wNameField.setLayoutData(fdNameField); + + // Full message field + final Label wlFullMessageField = new Label(gFieldNames, SWT.RIGHT); + wlFullMessageField.setText(BaseMessages.getString(PKG, + "Git.FullMessageField.Label")); + props.setLook(wlFullMessageField); + final FormData fdlFullMessageField = new FormData(); + fdlFullMessageField.left = new FormAttachment(0, -margin); + fdlFullMessageField.top = new FormAttachment(wNameField, margin); + fdlFullMessageField.right = new FormAttachment(middle, -2 * margin); + wlFullMessageField.setLayoutData(fdlFullMessageField); + + wFullMessageField = new Text(gFieldNames, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + wFullMessageField.setEditable(true); + wFullMessageField.setText("Full message"); + props.setLook(wFullMessageField); + final FormData fdFullMessageField = new FormData(); + fdFullMessageField.left = new FormAttachment(middle, -margin); + fdFullMessageField.top = new FormAttachment(wNameField, margin); + fdFullMessageField.right = new FormAttachment(100, -margin); + wFullMessageField.setLayoutData(fdFullMessageField); + + // Short message field + final Label wlShortMessageField = new Label(gFieldNames, SWT.RIGHT); + wlShortMessageField.setText(BaseMessages.getString(PKG, + "Git.ShortMessageField.Label")); + props.setLook(wlShortMessageField); + final FormData fdlShortMessageField = new FormData(); + fdlShortMessageField.left = new FormAttachment(0, -margin); + fdlShortMessageField.top = new FormAttachment(wFullMessageField, margin); + fdlShortMessageField.right = new FormAttachment(middle, -2 * margin); + wlShortMessageField.setLayoutData(fdlShortMessageField); + + wShortMessageField = new Text(gFieldNames, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + wShortMessageField.setEditable(true); + wShortMessageField.setText("Short message"); + props.setLook(wShortMessageField); + final FormData fdShortMessageField = new FormData(); + fdShortMessageField.left = new FormAttachment(middle, -margin); + fdShortMessageField.top = new FormAttachment(wFullMessageField, margin); + fdShortMessageField.right = new FormAttachment(100, -margin); + wShortMessageField.setLayoutData(fdShortMessageField); + + // Author creation date field + final Label wlAuthorCreationDateField = new Label(gFieldNames, + SWT.RIGHT); + wlAuthorCreationDateField.setText(BaseMessages.getString(PKG, + "Git.AuthorCreationDateField.Label")); + props.setLook(wlAuthorCreationDateField); + final FormData fdlAuthorCreationDateField = new FormData(); + fdlAuthorCreationDateField.left = new FormAttachment(0, -margin); + fdlAuthorCreationDateField.top = new FormAttachment(wShortMessageField, + margin); + fdlAuthorCreationDateField.right = new FormAttachment(middle, -2 + * margin); + wlAuthorCreationDateField.setLayoutData(fdlAuthorCreationDateField); + + wAuthorCreationDateField = new Text(gFieldNames, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + wAuthorCreationDateField.setEditable(true); + wAuthorCreationDateField.setText("Author creation date"); + props.setLook(wAuthorCreationDateField); + final FormData fdAuthorCreationDateField = new FormData(); + fdAuthorCreationDateField.left = new FormAttachment(middle, -margin); + fdAuthorCreationDateField.top = new FormAttachment(wShortMessageField, + margin); + fdAuthorCreationDateField.right = new FormAttachment(100, -margin); + wAuthorCreationDateField.setLayoutData(fdAuthorCreationDateField); + + // Author name field + final Label wlAuthorNameField = new Label(gFieldNames, SWT.RIGHT); + wlAuthorNameField.setText(BaseMessages.getString(PKG, + "Git.AuthorNameField.Label")); + props.setLook(wlAuthorNameField); + final FormData fdlAuthorNameField = new FormData(); + fdlAuthorNameField.left = new FormAttachment(0, -margin); + fdlAuthorNameField.top = new FormAttachment(wAuthorCreationDateField, + margin); + fdlAuthorNameField.right = new FormAttachment(middle, -2 * margin); + wlAuthorNameField.setLayoutData(fdlAuthorNameField); + + wAuthorNameField = new Text(gFieldNames, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + wAuthorNameField.setEditable(true); + wAuthorNameField.setText("Author name"); + props.setLook(wAuthorNameField); + final FormData fdAuthorNameField = new FormData(); + fdAuthorNameField.left = new FormAttachment(middle, -margin); + fdAuthorNameField.top = new FormAttachment(wAuthorCreationDateField, + margin); + fdAuthorNameField.right = new FormAttachment(100, -margin); + wAuthorNameField.setLayoutData(fdAuthorNameField); + + // Author email field + final Label wlAuthorEmailField = new Label(gFieldNames, SWT.RIGHT); + wlAuthorEmailField.setText(BaseMessages.getString(PKG, + "Git.AuthorEmailField.Label")); + props.setLook(wlAuthorEmailField); + final FormData fdlAuthorEmailField = new FormData(); + fdlAuthorEmailField.left = new FormAttachment(0, -margin); + fdlAuthorEmailField.top = new FormAttachment(wAuthorNameField, margin); + fdlAuthorEmailField.right = new FormAttachment(middle, -2 * margin); + wlAuthorEmailField.setLayoutData(fdlAuthorEmailField); + + wAuthorEmailField = new Text(gFieldNames, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + wAuthorEmailField.setEditable(true); + wAuthorEmailField.setText("Author email"); + props.setLook(wAuthorEmailField); + final FormData fdAuthorEmailField = new FormData(); + fdAuthorEmailField.left = new FormAttachment(middle, -margin); + fdAuthorEmailField.top = new FormAttachment(wAuthorNameField, margin); + fdAuthorEmailField.right = new FormAttachment(100, -margin); + wAuthorEmailField.setLayoutData(fdAuthorEmailField); + + // Committer creation date field + final Label wlCommitterCreationDateField = new Label(gFieldNames, + SWT.RIGHT); + wlCommitterCreationDateField.setText(BaseMessages.getString(PKG, + "Git.CommitterCreationDateField.Label")); + props.setLook(wlCommitterCreationDateField); + final FormData fdlCommitterCreationDateField = new FormData(); + fdlCommitterCreationDateField.left = new FormAttachment(0, -margin); + fdlCommitterCreationDateField.top = new FormAttachment( + wAuthorEmailField, margin); + fdlCommitterCreationDateField.right = new FormAttachment(middle, -2 + * margin); + wlCommitterCreationDateField + .setLayoutData(fdlCommitterCreationDateField); + + wCommitterCreationDateField = new Text(gFieldNames, SWT.SINGLE + | SWT.LEFT | SWT.BORDER); + wCommitterCreationDateField.setEditable(true); + wCommitterCreationDateField.setText("Committer creation date"); + props.setLook(wCommitterCreationDateField); + final FormData fdCommitterCreationDateField = new FormData(); + fdCommitterCreationDateField.left = new FormAttachment(middle, -margin); + fdCommitterCreationDateField.top = new FormAttachment( + wAuthorEmailField, margin); + fdCommitterCreationDateField.right = new FormAttachment(100, -margin); + wCommitterCreationDateField.setLayoutData(fdCommitterCreationDateField); + + // Committer name field + final Label wlCommitterNameField = new Label(gFieldNames, SWT.RIGHT); + wlCommitterNameField.setText(BaseMessages.getString(PKG, + "Git.CommitterNameField.Label")); + props.setLook(wlCommitterNameField); + final FormData fdlCommitterNameField = new FormData(); + fdlCommitterNameField.left = new FormAttachment(0, -margin); + fdlCommitterNameField.top = new FormAttachment( + wCommitterCreationDateField, margin); + fdlCommitterNameField.right = new FormAttachment(middle, -2 * margin); + wlCommitterNameField.setLayoutData(fdlCommitterNameField); + + wCommitterNameField = new Text(gFieldNames, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + wCommitterNameField.setEditable(true); + wCommitterNameField.setText("Committer name"); + props.setLook(wCommitterNameField); + final FormData fdCommitterNameField = new FormData(); + fdCommitterNameField.left = new FormAttachment(middle, -margin); + fdCommitterNameField.top = new FormAttachment( + wCommitterCreationDateField, margin); + fdCommitterNameField.right = new FormAttachment(100, -margin); + wCommitterNameField.setLayoutData(fdCommitterNameField); + + // Committer email field + final Label wlCommitterEmailField = new Label(gFieldNames, SWT.RIGHT); + wlCommitterEmailField.setText(BaseMessages.getString(PKG, + "Git.CommitterEmailField.Label")); + props.setLook(wlCommitterEmailField); + final FormData fdlCommitterEmailField = new FormData(); + fdlCommitterEmailField.left = new FormAttachment(0, -margin); + fdlCommitterEmailField.top = new FormAttachment(wCommitterNameField, + margin); + fdlCommitterEmailField.right = new FormAttachment(middle, -2 * margin); + wlCommitterEmailField.setLayoutData(fdlCommitterEmailField); + + wCommitterEmailField = new Text(gFieldNames, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + wCommitterEmailField.setEditable(true); + wCommitterEmailField.setText("Committer email"); + props.setLook(wCommitterEmailField); + final FormData fdCommitterEmailField = new FormData(); + fdCommitterEmailField.left = new FormAttachment(middle, -margin); + fdCommitterEmailField.top = new FormAttachment(wCommitterNameField, + margin); + fdCommitterEmailField.right = new FormAttachment(100, -margin); + wCommitterEmailField.setLayoutData(fdCommitterEmailField); + + final FormData fdFieldNames = new FormData(); + fdFieldNames.left = new FormAttachment(0, margin); + fdFieldNames.top = new FormAttachment(wFields, 2 * margin); + fdFieldNames.right = new FormAttachment(100, -margin); + gFieldNames.setLayoutData(fdFieldNames); + + // ////////////////////// + // END OF FIELDS GROUP // + // ////////////////////// + final FormData fdMainOptions = new FormData(); + fdMainOptions.left = new FormAttachment(0, 0); + fdMainOptions.top = new FormAttachment(0, 0); + fdMainOptions.right = new FormAttachment(100, 0); + fdMainOptions.bottom = new FormAttachment(100, 0); + wMainOptionsComp.setLayoutData(fdMainOptions); + + wMainOptionsComp.layout(); + wMainOptionsTab.setControl(wMainOptionsComp); + // ///////////////////////////////// + // END OF Main Options TAB // + // ///////////////////////////////// + + // OK and cancel buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + BaseStepDialog.positionBottomButtons(shell, + new Button[] {wOK, wCancel}, margin, null); + + final Button button = new Button(shell, SWT.PUSH); + button.setImage(ImageUtil.getImage(display, getClass(), + "ivyis_logo.png")); + button.setToolTipText("Ivy Information Systems"); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + final ShowBrowserDialog sbd = + new ShowBrowserDialog(shell, BaseMessages.getString(PKG, + "ExportCmdLine.CommandLine.Title"), + ""); + sbd.open(); + } + }); + + // Determine the largest button in the array + Rectangle largest = null; + button.pack(true); + final Rectangle r = button.getBounds(); + if (largest == null || r.width > largest.width) { + largest = r; + } + + // Also, set the tooltip the same as the name if we don't have one... + if (button.getToolTipText() == null) { + button.setToolTipText(Const.replace(button.getText(), "&", "")); + } + + // Make buttons a bit larger... (nicer) + largest.width += 10; + if ((largest.width % 2) == 1) { + largest.width++; + } + + BaseStepDialog.rightAlignButtons(new Button[] {button}, + largest.width, margin, null); + if (Const.isOSX()) { + final List tableViews = new ArrayList(); + getTableViews(shell, tableViews); + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + for (TableView view : tableViews) { + view.applyOSXChanges(); + } + } + }); + } + + final FormData fdMainOptionsTab = new FormData(); + fdMainOptionsTab.left = new FormAttachment(0, 0); + fdMainOptionsTab.top = new FormAttachment(wStepname, margin); + fdMainOptionsTab.right = new FormAttachment(100, 0); + fdMainOptionsTab.bottom = new FormAttachment(wOK, -margin); + wTabFolder.setLayoutData(fdMainOptionsTab); + + wTabFolder.setSelection(0); + + final FormData fdSc = new FormData(); + fdSc.left = new FormAttachment(0, 0); + fdSc.top = new FormAttachment(wStepname, margin); + fdSc.right = new FormAttachment(100, 0); + fdSc.bottom = new FormAttachment(100, -50); + sc.setLayoutData(fdSc); + + sc.setContent(wTabFolder); + + // Add listeners + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + + wCancel.addListener(SWT.Selection, lsCancel); + wOK.addListener(SWT.Selection, lsOK); + + lsDef = new SelectionAdapter() { + public void widgetDefaultSelected(SelectionEvent e) { + ok(); + } + }; + wStepname.addSelectionListener(lsDef); + + // Detect X or ALT-F4 or something that kills this window... + shell.addShellListener(new ShellAdapter() { + @Override + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + // determine scrollable area + sc.setMinSize(wTabFolder.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + sc.setExpandHorizontal(true); + sc.setExpandVertical(true); + + // Set the shell size, based upon previous time... + setSize(); + + getData(); + input.setChanged(backupChanged); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + return stepname; + } + + /** + * Gets the table views. + * + * @param parentControl the parent control + * @param tableViews the table views + * @return the table views + */ + private static final void getTableViews(Control parentControl, + List tableViews) { + if (parentControl instanceof TableView) { + tableViews.add((TableView) parentControl); + } else { + if (parentControl instanceof Composite) { + final Control[] children = ((Composite) parentControl) + .getChildren(); + for (Control child : children) { + getTableViews(child, tableViews); + } + } else { + if (parentControl instanceof Shell) { + final Control[] children = ((Shell) parentControl) + .getChildren(); + for (Control child : children) { + getTableViews(child, tableViews); + } + + } + } + } + } + + private void enableOutputFields(boolean enable) { + wIdField.setEnabled(enable); + wFullMessageField.setEnabled(enable); + wShortMessageField.setEnabled(enable); + wAuthorCreationDateField.setEnabled(enable); + wAuthorNameField.setEnabled(enable); + wAuthorEmailField.setEnabled(enable); + wCommitterCreationDateField.setEnabled(enable); + wCommitterNameField.setEnabled(enable); + wCommitterEmailField.setEnabled(enable); + input.setChanged(backupChanged); + } + + /** + * Read data and place it in the dialog. + */ + public void getData() { + wStepname.selectAll(); + if (input.getUsername() != null) { + wUsernameField.setText(Const.NVL(input.getUsername(), "")); + } + if (input.getPassword() != null) { + wPasswordField.setText(Const.NVL(input.getPassword(), "")); + } + if (input.getGitRepoFolderPath() != null) { + wRepoFolderPathField.setText(input.getGitRepoFolderPath()); + } + if (input.getGitRepoUrl() != null) { + wRepoUrlField.setText(input.getGitRepoUrl()); + } + if (input.getGitCommand() != null) { + gitCommand = (GitInfoCommand) input.getGitCommand(); + + wGitInfoCommandField.setText(BaseMessages.getString( + GitCommandType.class, "Git." + + gitCommand.getCommandType().getOperationName() + + ".Label")); + if (GitCommandType.CURRENT_BRANCH.equals(gitCommand + .getCommandType())) { + enableOutputFields(false); + } else { + enableOutputFields(true); + } + + wFields.clearAll(); + boolean first = true; + for (Map.Entry entry : gitCommand.getConfigFields( + true).entrySet()) { + configFields.put(entry.getKey(), entry.getValue()); + if (entry.getKey() == null || entry.getValue() == null) { + continue; + } + if (first) { + wFields.setText(entry.getKey(), 1, 0); + wFields.setText(entry.getValue(), 2, 0); + first = false; + } else { + final TableItem tableItem = new TableItem(wFields.table, + SWT.NONE); + tableItem.setText(1, entry.getKey()); + tableItem.setText(2, entry.getValue()); + } + } + + wIdField.setText(Const.NVL( + gitCommand.getConfigFields(false).get( + BaseMessages.getString(PKG, "Git.IdField.Label")), + "")); + wNameField + .setText(Const.NVL( + gitCommand.getConfigFields(false).get( + BaseMessages.getString(PKG, + "Git.NameField.Label")), "")); + wFullMessageField.setText(Const.NVL( + gitCommand.getConfigFields(false).get( + BaseMessages.getString(PKG, + "Git.FullMessageField.Label")), "")); + wShortMessageField.setText(Const.NVL( + gitCommand.getConfigFields(false).get( + BaseMessages.getString(PKG, + "Git.ShortMessageField.Label")), "")); + wAuthorCreationDateField.setText(Const.NVL( + gitCommand.getConfigFields(false).get( + BaseMessages.getString(PKG, + "Git.AuthorCreationDateField.Label")), "")); + wAuthorNameField.setText(Const.NVL( + gitCommand.getConfigFields(false).get( + BaseMessages.getString(PKG, + "Git.AuthorNameField.Label")), "")); + wAuthorEmailField.setText(Const.NVL( + gitCommand.getConfigFields(false).get( + BaseMessages.getString(PKG, + "Git.AuthorEmailField.Label")), "")); + wCommitterCreationDateField.setText(Const.NVL( + gitCommand.getConfigFields(false).get( + BaseMessages.getString(PKG, + "Git.CommitterCreationDateField.Label")), + "")); + wCommitterNameField.setText(Const.NVL( + gitCommand.getConfigFields(false).get( + BaseMessages.getString(PKG, + "Git.CommitterNameField.Label")), "")); + wCommitterEmailField.setText(Const.NVL( + gitCommand.getConfigFields(false).get( + BaseMessages.getString(PKG, + "Git.CommitterEmailField.Label")), "")); + } + } + + /** + * Checks the password visible. + */ + private void checkPasswordVisible() { + final String password = wPasswordField.getText(); + final List list = new ArrayList(); + StringUtil.getUsedVariables(password, list, true); + if (list.size() == 0) { + wPasswordField.setEchoChar('*'); + } else { + String variableName = null; + if (password.startsWith(StringUtil.UNIX_OPEN) + && password.endsWith(StringUtil.UNIX_CLOSE)) { + variableName = password.substring( + StringUtil.UNIX_OPEN.length(), password.length() + - StringUtil.UNIX_CLOSE.length()); + } + if (password.startsWith(StringUtil.WINDOWS_OPEN) + && password.endsWith(StringUtil.WINDOWS_CLOSE)) { + variableName = password.substring( + StringUtil.WINDOWS_OPEN.length(), password.length() + - StringUtil.WINDOWS_CLOSE.length()); + } + if (variableName != null + && System.getProperty(variableName) != null) { + wPasswordField.setEchoChar('\0'); + } else { + wPasswordField.setEchoChar('*'); + } + } + } + + /** + * Cancel. + */ + private void cancel() { + stepname = null; + input.setChanged(backupChanged); + dispose(); + } + + /** + * Let the plugin know about the entered data. + */ + private void ok() { + if (!Const.isEmpty(wStepname.getText())) { + stepname = wStepname.getText(); + getInfo(input); + } + } + + /** + * Get the information. + * + * @param info the push notification step meta data. + */ + public void getInfo(GitInfoStepMeta info) { + if (Const.isEmpty(wUsernameField.getText()) + || Const.isEmpty(wPasswordField.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK + | SWT.ICON_WARNING); + mb.setMessage(BaseMessages.getString(PKG, + "Git.Username.Password.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, + "System.Dialog.Warning.Title")); + mb.open(); + } + input.setUsername(wUsernameField.getText()); + input.setPassword(wPasswordField.getText()); + + if (Const.isEmpty(wRepoFolderPathField.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.RepoFolder.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } + input.setGitRepoFolderPath(wRepoFolderPathField.getText()); + + if (Const.isEmpty(wRepoUrlField.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.RepoUrl.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } + input.setGitRepoUrl(wRepoUrlField.getText()); + + final Map config = gitCommand.getConfigFields(true); + if (gitCommand instanceof CurrentBranchGitCommand) { + if (Const.isEmpty(wNameField.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK + | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.ConfigFields.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, + "System.Dialog.Error.Title")); + mb.open(); + return; + } + config.put(BaseMessages.getString(PKG, "Git.NameField.Label"), + wNameField.getText()); + + } else if (Const.isEmpty(wIdField.getText()) + || Const.isEmpty(wNameField.getText()) + || Const.isEmpty(wFullMessageField.getText()) + || Const.isEmpty(wShortMessageField.getText()) + || Const.isEmpty(wAuthorCreationDateField.getText()) + || Const.isEmpty(wAuthorNameField.getText()) + || Const.isEmpty(wAuthorEmailField.getText()) + || Const.isEmpty(wCommitterCreationDateField.getText()) + || Const.isEmpty(wCommitterNameField.getText()) + || Const.isEmpty(wCommitterEmailField.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.ConfigFields.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } else { + config.put(BaseMessages.getString(PKG, "Git.IdField.Label"), + wIdField.getText()); + config.put(BaseMessages.getString(PKG, "Git.NameField.Label"), + wNameField.getText()); + config.put( + BaseMessages.getString(PKG, "Git.FullMessageField.Label"), + wFullMessageField.getText()); + config.put( + BaseMessages.getString(PKG, "Git.ShortMessageField.Label"), + wShortMessageField.getText()); + config.put(BaseMessages.getString(PKG, + "Git.AuthorCreationDateField.Label"), + wAuthorCreationDateField.getText()); + config.put( + BaseMessages.getString(PKG, "Git.AuthorNameField.Label"), + wAuthorNameField.getText()); + config.put( + BaseMessages.getString(PKG, "Git.AuthorEmailField.Label"), + wAuthorEmailField.getText()); + config.put(BaseMessages.getString(PKG, + "Git.CommitterCreationDateField.Label"), + wCommitterCreationDateField.getText()); + config.put( + BaseMessages.getString(PKG, "Git.CommitterNameField.Label"), + wCommitterNameField.getText()); + config.put(BaseMessages.getString(PKG, + "Git.CommitterEmailField.Label"), wCommitterEmailField + .getText()); + } + try { + gitCommand = GitCommandFactory.getGitCommand( + gitCommand.getCommandType(), config); + } catch (KettleException e) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.Command.Not.Found.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } + input.setGitCommand(gitCommand); + + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepMeta.java b/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepMeta.java new file mode 100644 index 0000000..cff7c69 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/info/GitInfoStepMeta.java @@ -0,0 +1,380 @@ +package com.ivyis.di.trans.steps.git.info; + +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.CheckResultInterface; +import org.pentaho.di.core.Const; +import org.pentaho.di.core.Counter; +import org.pentaho.di.core.annotations.Step; +import org.pentaho.di.core.database.DatabaseMeta; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.core.exception.KettleXMLException; +import org.pentaho.di.core.row.RowMetaInterface; +import org.pentaho.di.core.row.ValueMeta; +import org.pentaho.di.core.row.ValueMetaInterface; +import org.pentaho.di.core.variables.VariableSpace; +import org.pentaho.di.core.xml.XMLHandler; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.repository.ObjectId; +import org.pentaho.di.repository.Repository; +import org.pentaho.di.trans.Trans; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.trans.step.BaseStepMeta; +import org.pentaho.di.trans.step.StepDataInterface; +import org.pentaho.di.trans.step.StepDialogInterface; +import org.pentaho.di.trans.step.StepInterface; +import org.pentaho.di.trans.step.StepMeta; +import org.pentaho.di.trans.step.StepMetaInterface; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitCommandFactory; +import com.ivyis.di.trans.steps.git.command.GitInfoCommand; + +/** + * This class is responsible for implementing functionality regarding step meta. All Kettle steps + * have an extension of this where private fields have been added with public accessors. + * + * @author Joel Latino + * @since 1.0.0 + */ +@Step(id = "GitInfoStep", name = "GitInfo.Step.Name", description = "GitInfo.Step.Description", + categoryDescription = "GitInfo.Step.Category", + image = "com/ivyis/di/trans/steps/git/info/GitInfoStep.png", + i18nPackageName = "com.ivyis.di.trans.steps.git.info", casesUrl = "https://github.com/ivylabs", + documentationUrl = "https://github.com/ivylabs", forumUrl = "https://github.com/ivylabs") +public class GitInfoStepMeta extends BaseStepMeta implements StepMetaInterface { + + /** for i18n purposes. **/ + private static final Class PKG = GitInfoStepMeta.class; + + private String username, password, gitRepoUrl, gitRepoFolderPath; + private GitCommand gitCommand; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getGitRepoUrl() { + return gitRepoUrl; + } + + public void setGitRepoUrl(String gitRepoUrl) { + this.gitRepoUrl = gitRepoUrl; + } + + public String getGitRepoFolderPath() { + return gitRepoFolderPath; + } + + public void setGitRepoFolderPath(String gitRepoFolderPath) { + this.gitRepoFolderPath = gitRepoFolderPath; + } + + public GitCommand getGitCommand() { + return gitCommand; + } + + public void setGitCommand(GitCommand gitCommand) { + this.gitCommand = gitCommand; + } + + /** + * {@inheritDoc} + */ + @Override + public String getXML() { + final StringBuilder retval = new StringBuilder(); + retval.append(" " + XMLHandler.addTagValue("username", username)); + retval.append(" " + XMLHandler.addTagValue("password", password)); + retval.append(" " + XMLHandler.addTagValue("gitRepoUrl", gitRepoUrl)); + retval.append(" " + + XMLHandler + .addTagValue("gitRepoFolderPath", gitRepoFolderPath)); + + retval.append(" ").append(Const.CR); + retval.append(" ").append(Const.CR); + retval.append(" ").append(gitCommand.getXML()); + retval.append(" ").append(Const.CR); + retval.append(" ").append(Const.CR); + + return retval.toString(); + } + + /** + * Reads data from XML transformation file. + * + * @param stepnode the step XML node. + * @throws KettleXMLException the kettle XML exception. + */ + public void readData(Node stepnode) throws KettleXMLException { + try { + username = XMLHandler.getTagValue(stepnode, "username"); + password = XMLHandler.getTagValue(stepnode, "password"); + gitRepoUrl = XMLHandler.getTagValue(stepnode, "gitRepoUrl"); + gitRepoFolderPath = XMLHandler.getTagValue(stepnode, + "gitRepoFolderPath"); + final String stepName = XMLHandler.getTagValue(stepnode, "name"); + + // Git commands + final Node gitCommands = XMLHandler.getSubNode(stepnode, + "gitCommands"); + final int nrCustomFieldsRows = XMLHandler.countNodes(gitCommands, + "gitCommand"); + for (int i = 0; i < nrCustomFieldsRows; i++) { + final Node knode = XMLHandler.getSubNodeByNr(gitCommands, + "gitCommand", i); + this.gitCommand = GitCommandFactory.getGitCommand(knode, + stepName); + } + + } catch (Exception e) { + throw new KettleXMLException(BaseMessages.getString(PKG, + "ImageResize.Exception.UnexpectedErrorInReadingStepInfo"), + e); + } + } + + /** + * {@inheritDoc} + * + * @throws KettleException + */ + @Override + public void readRep(Repository rep, ObjectId idStep, + List databases, Map counters) + throws KettleException { + try { + username = rep.getStepAttributeString(idStep, "username"); + password = rep.getStepAttributeString(idStep, "password"); + gitRepoUrl = rep.getStepAttributeString(idStep, "gitRepoUrl"); + gitRepoFolderPath = rep.getStepAttributeString(idStep, + "gitRepoFolderPath"); + final String stepName = rep.getStepAttributeString(idStep, "name"); + + final int nrRows = rep.countNrStepAttributes(idStep, "gitCommands"); + for (int i = 0; i < nrRows; i++) { + gitCommand = GitCommandFactory.getGitCommand( + rep.getStepAttributeString(idStep, i, "gitCommand"), + stepName); + } + + } catch (Exception e) { + throw new KettleException(BaseMessages.getString(PKG, + "Git.Exception.UnexpectedErrorInReadingStepInfo"), e); + } + } + + /** + * {@inheritDoc} + * + * @throws KettleException + */ + @Override + public void saveRep(Repository rep, ObjectId idTransformation, + ObjectId idStep) throws KettleException { + try { + rep.saveStepAttribute(idTransformation, idStep, "username", + username); + rep.saveStepAttribute(idTransformation, idStep, "password", + password); + rep.saveStepAttribute(idTransformation, idStep, "gitRepoUrl", + gitRepoUrl); + rep.saveStepAttribute(idTransformation, idStep, + "gitRepoFolderPath", gitRepoFolderPath); + rep.saveStepAttribute(idTransformation, idStep, 0, "gitCommand", + gitCommand.getXML()); + } catch (Exception e) { + throw new KettleException(BaseMessages.getString(PKG, + "Git.Exception.UnableToSaveStepInfoToRepository") + idStep, + e); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void getFields(RowMetaInterface r, String origin, + RowMetaInterface[] info, StepMeta nextStep, VariableSpace space) { + // Just add the response field... + if (gitCommand != null) { + final Map configFields = ((GitInfoCommand) gitCommand) + .getConfigFields(false); + if (GitCommandType.CURRENT_BRANCH.equals(gitCommand + .getCommandType())) { + final ValueMetaInterface nameField = new ValueMeta( + space.environmentSubstitute(configFields + .get(BaseMessages.getString(PKG, + "Git.NameField.Label"))), + ValueMetaInterface.TYPE_STRING); + nameField.setOrigin(origin); + r.addValueMeta(nameField); + return; + } + + final ValueMetaInterface idField = new ValueMeta( + space.environmentSubstitute(configFields.get(BaseMessages + .getString(PKG, "Git.IdField.Label"))), + ValueMetaInterface.TYPE_STRING); + idField.setOrigin(origin); + r.addValueMeta(idField); + + final ValueMetaInterface nameField = new ValueMeta( + space.environmentSubstitute(configFields.get(BaseMessages + .getString(PKG, "Git.NameField.Label"))), + ValueMetaInterface.TYPE_STRING); + nameField.setOrigin(origin); + r.addValueMeta(nameField); + + final ValueMetaInterface fullMessageField = new ValueMeta( + space.environmentSubstitute(configFields.get(BaseMessages + .getString(PKG, "Git.FullMessageField.Label"))), + ValueMetaInterface.TYPE_STRING); + fullMessageField.setOrigin(origin); + r.addValueMeta(fullMessageField); + + final ValueMetaInterface shortMessageField = new ValueMeta( + space.environmentSubstitute(configFields.get(BaseMessages + .getString(PKG, "Git.ShortMessageField.Label"))), + ValueMetaInterface.TYPE_STRING); + shortMessageField.setOrigin(origin); + r.addValueMeta(shortMessageField); + + final ValueMetaInterface authorCreationDateField = new ValueMeta( + space.environmentSubstitute(configFields.get(BaseMessages + .getString(PKG, "Git.AuthorCreationDateField.Label"))), + ValueMetaInterface.TYPE_STRING); + authorCreationDateField.setOrigin(origin); + r.addValueMeta(authorCreationDateField); + + final ValueMetaInterface authorNameField = new ValueMeta( + space.environmentSubstitute(configFields.get(BaseMessages + .getString(PKG, "Git.AuthorNameField.Label"))), + ValueMetaInterface.TYPE_STRING); + authorNameField.setOrigin(origin); + r.addValueMeta(authorNameField); + + final ValueMetaInterface authorEmailField = new ValueMeta( + space.environmentSubstitute(configFields.get(BaseMessages + .getString(PKG, "Git.AuthorEmailField.Label"))), + ValueMetaInterface.TYPE_STRING); + authorEmailField.setOrigin(origin); + r.addValueMeta(authorEmailField); + + final ValueMetaInterface committerCreationDateField = new ValueMeta( + space.environmentSubstitute(configFields.get(BaseMessages + .getString(PKG, + "Git.CommitterCreationDateField.Label"))), + ValueMetaInterface.TYPE_STRING); + committerCreationDateField.setOrigin(origin); + r.addValueMeta(committerCreationDateField); + + final ValueMetaInterface committerNameField = new ValueMeta( + space.environmentSubstitute(configFields.get(BaseMessages + .getString(PKG, "Git.CommitterNameField.Label"))), + ValueMetaInterface.TYPE_STRING); + committerNameField.setOrigin(origin); + r.addValueMeta(committerNameField); + + final ValueMetaInterface committerEmailField = new ValueMeta( + space.environmentSubstitute(configFields.get(BaseMessages + .getString(PKG, "Git.CommitterEmailField.Label"))), + ValueMetaInterface.TYPE_STRING); + committerEmailField.setOrigin(origin); + r.addValueMeta(committerEmailField); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Object clone() { + return super.clone(); + } + + /** + * {@inheritDoc} + * + * @throws KettleXMLException + */ + @Override + public void loadXML(Node stepnode, List databases, + Map counters) throws KettleXMLException { + readData(stepnode); + } + + /** + * Sets the default values. + */ + public void setDefault() {} + + /** + * {@inheritDoc} + */ + @Override + public void check(List remarks, TransMeta transmeta, + StepMeta stepMeta, RowMetaInterface prev, String[] input, + String[] output, RowMetaInterface info) {} + + /** + * Get the Step dialog, needs for configure the step. + * + * @param shell the shell. + * @param meta the associated base step metadata. + * @param transMeta the associated transformation metadata. + * @param name the step name + * @return The appropriate StepDialogInterface class. + */ + public StepDialogInterface getDialog(Shell shell, StepMetaInterface meta, + TransMeta transMeta, String name) { + return new GitInfoStepDialog(shell, (BaseStepMeta) meta, transMeta, + name); + } + + /** + * Get the executing step, needed by Trans to launch a step. + * + * @param stepMeta The step info. + * @param stepDataInterface the step data interface linked to this step. Here the step can store + * temporary data, database connections, etc. + * @param cnr The copy nr to get. + * @param transMeta The transformation info. + * @param disp The launching transformation. + * @return The appropriate StepInterface class. + */ + public StepInterface getStep(StepMeta stepMeta, + StepDataInterface stepDataInterface, int cnr, TransMeta transMeta, + Trans disp) { + return new GitInfoStep(stepMeta, stepDataInterface, cnr, transMeta, + disp); + } + + /** + * Get a new instance of the appropriate data class. This data class implements the + * StepDataInterface. It basically contains the persisting data that needs to live on, even if a + * worker thread is terminated. + * + * @return The appropriate StepDataInterface class. + */ + public StepDataInterface getStepData() { + return new GitInfoStepData(); + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/ListBranchsGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/ListBranchsGitCommandDialog.java new file mode 100644 index 0000000..694878e --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/ListBranchsGitCommandDialog.java @@ -0,0 +1,182 @@ +package com.ivyis.di.trans.steps.git.info.dialog.impl; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.ui.core.PropsUI; +import org.pentaho.di.ui.core.gui.GUIResource; +import org.pentaho.di.ui.core.gui.WindowProperty; +import org.pentaho.di.ui.core.widget.TextVar; +import org.pentaho.di.ui.trans.step.BaseStepDialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.impl.ListBranchsGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; + +/** + * List Branchs command UI class. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class ListBranchsGitCommandDialog extends Dialog implements + BaseGitCommandDialog { + private static final Class PKG = ListBranchsGitCommandDialog.class; // for i18n + + private TextVar wlistMode; + + private Shell shell; + private boolean modal; + private PropsUI props; + private TransMeta transMeta; + private Button wOK, wCancel; + private Listener lsOK, lsCancel; + private ListBranchsGitCommand listBranchsCommand; + + public Shell getShell() { + return shell; + } + + public ListBranchsGitCommandDialog(Shell parent, TransMeta transMeta, + GitCommand gitCommand) { + super(parent, SWT.NONE); + this.modal = true; + this.transMeta = transMeta; + props = PropsUI.getInstance(); + if (gitCommand != null && gitCommand instanceof ListBranchsGitCommand) { + this.listBranchsCommand = (ListBranchsGitCommand) gitCommand; + } else { + this.listBranchsCommand = new ListBranchsGitCommand(); + } + } + + public GitCommand open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM + | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE) + | SWT.RESIZE | SWT.MIN | SWT.MAX); + props.setLook(shell); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + final int margin = Const.MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, + "Git.ListBranchsCommandDialog.Title")); + shell.setImage(GUIResource.getInstance().getImageSpoon()); + + // List mode + final Label wlListMode = new Label(shell, SWT.RIGHT); + wlListMode.setText(BaseMessages.getString(PKG, "Git.ListMode.Label")); + props.setLook(wlListMode); + final FormData fdllistMode = new FormData(); + fdllistMode.left = new FormAttachment(0, 25); + fdllistMode.top = new FormAttachment(shell, margin); + wlListMode.setLayoutData(fdllistMode); + + wlistMode = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wlistMode); + final FormData fdlistMode = new FormData(); + fdlistMode.left = new FormAttachment(wlListMode, margin); + fdlistMode.top = new FormAttachment(shell, margin); + fdlistMode.right = new FormAttachment(100, 0); + wlistMode.setLayoutData(fdlistMode); + + // Some buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + wOK.addListener(SWT.Selection, lsOK); + + Button[] buttons = new Button[] {wOK}; + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + wCancel.addListener(SWT.Selection, lsCancel); + + buttons = new Button[] {wOK, wCancel}; + + BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + + // Add listeners + shell.addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + getData(); + + BaseStepDialog.setSize(shell); + + wOK.setFocus(); + + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return this.listBranchsCommand; + + } + + public void dispose() { + props.setScreen(new WindowProperty(shell)); + shell.dispose(); + } + + public void getData() { + if (!Const.isEmpty(this.listBranchsCommand.getListMode())) { + wlistMode.setText(this.listBranchsCommand.getListMode()); + } + } + + private void cancel() { + dispose(); + } + + private void ok() { + if (Const.isEmpty(wlistMode.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.ListMode.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } + this.listBranchsCommand.setListMode(wlistMode.getText()); + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/LogGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/LogGitCommandDialog.java new file mode 100644 index 0000000..0120e7e --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/LogGitCommandDialog.java @@ -0,0 +1,257 @@ +package com.ivyis.di.trans.steps.git.info.dialog.impl; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.ui.core.PropsUI; +import org.pentaho.di.ui.core.gui.GUIResource; +import org.pentaho.di.ui.core.gui.WindowProperty; +import org.pentaho.di.ui.core.widget.TextVar; +import org.pentaho.di.ui.trans.step.BaseStepDialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.impl.LogGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; + +/** + * Log command UI class. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class LogGitCommandDialog extends Dialog implements BaseGitCommandDialog { + private static final Class PKG = LogGitCommandDialog.class; // for i18n + + private TextVar wPath, wMaxCount, wSkip; + + private Shell shell; + private boolean modal; + private PropsUI props; + private TransMeta transMeta; + private Button wOK, wCancel; + private Listener lsOK, lsCancel; + private LogGitCommand logGitCommand; + + public Shell getShell() { + return shell; + } + + public LogGitCommandDialog(Shell parent, TransMeta transMeta, + GitCommand gitCommand) { + super(parent, SWT.NONE); + this.modal = true; + this.transMeta = transMeta; + props = PropsUI.getInstance(); + if (gitCommand != null && gitCommand instanceof LogGitCommand) { + this.logGitCommand = (LogGitCommand) gitCommand; + } else { + this.logGitCommand = new LogGitCommand(); + } + } + + public GitCommand open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM + | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE) + | SWT.RESIZE | SWT.MIN | SWT.MAX); + props.setLook(shell); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + final int margin = Const.MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Git.LogCommandDialog.Title")); + shell.setImage(GUIResource.getInstance().getImageSpoon()); + + // Path field + final Label wlPath = new Label(shell, SWT.RIGHT); + wlPath.setText(BaseMessages.getString(PKG, "Git.Path.Label")); + props.setLook(wlPath); + final FormData fdlPath = new FormData(); + fdlPath.left = new FormAttachment(0, 25); + fdlPath.top = new FormAttachment(shell, margin); + wlPath.setLayoutData(fdlPath); + + wPath = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wPath); + final FormData fdPath = new FormData(); + fdPath.left = new FormAttachment(wlPath, margin); + fdPath.top = new FormAttachment(shell, margin); + fdPath.right = new FormAttachment(100, 0); + wPath.setLayoutData(fdPath); + + // Max count field + final Label wlMaxCount = new Label(shell, SWT.RIGHT); + wlMaxCount.setText(BaseMessages.getString(PKG, "Git.MaxCount.Label")); + props.setLook(wlMaxCount); + final FormData fdlMaxCount = new FormData(); + fdlMaxCount.left = new FormAttachment(0, 25); + fdlMaxCount.top = new FormAttachment(wPath, margin); + wlMaxCount.setLayoutData(fdlMaxCount); + + wMaxCount = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wMaxCount); + final FormData fdMaxCount = new FormData(); + fdMaxCount.left = new FormAttachment(wlMaxCount, margin); + fdMaxCount.top = new FormAttachment(wPath, margin); + fdMaxCount.right = new FormAttachment(100, 0); + wMaxCount.setLayoutData(fdMaxCount); + + // Skip field + final Label wlSkip = new Label(shell, SWT.RIGHT); + wlSkip.setText(BaseMessages.getString(PKG, "Git.Skip.Label")); + props.setLook(wlSkip); + final FormData fdlSkip = new FormData(); + fdlSkip.left = new FormAttachment(0, 25); + fdlSkip.top = new FormAttachment(wMaxCount, margin); + wlSkip.setLayoutData(fdlSkip); + + wSkip = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wSkip); + final FormData fdSkip = new FormData(); + fdSkip.left = new FormAttachment(wlSkip, margin); + fdSkip.top = new FormAttachment(wMaxCount, margin); + fdSkip.right = new FormAttachment(100, 0); + wSkip.setLayoutData(fdSkip); + + // Some buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + wOK.addListener(SWT.Selection, lsOK); + + Button[] buttons = new Button[] {wOK}; + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + wCancel.addListener(SWT.Selection, lsCancel); + + buttons = new Button[] {wOK, wCancel}; + + BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + + // Add listeners + shell.addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + getData(); + + BaseStepDialog.setSize(shell); + + wOK.setFocus(); + + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return this.logGitCommand; + + } + + public void dispose() { + props.setScreen(new WindowProperty(shell)); + shell.dispose(); + } + + public void getData() { + if (!Const.isEmpty(this.logGitCommand.getPath())) { + wPath.setText(this.logGitCommand.getPath()); + } + if (this.logGitCommand.getMaxCount() != null) { + wMaxCount.setText(String.valueOf(this.logGitCommand.getMaxCount())); + } + if (this.logGitCommand.getMaxCount() != null) { + wSkip.setText(String.valueOf(this.logGitCommand.getSkip())); + } + } + + private void cancel() { + dispose(); + } + + private void ok() { + if (!Const.isEmpty(wPath.getText())) { + this.logGitCommand.setPath(wPath.getText()); + } else { + this.logGitCommand.setPath(null); + } + + if (!Const.isEmpty(wMaxCount.getText())) { + try { + Integer.parseInt(transMeta.environmentSubstitute(wMaxCount + .getText())); + this.logGitCommand.setMaxCount(wMaxCount.getText()); + } catch (NumberFormatException e) { + final MessageBox mb = new MessageBox(shell, SWT.OK + | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.MaxCount.NumberParseError.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, + "System.Dialog.Error.Title")); + mb.open(); + return; + } + } else { + this.logGitCommand.setMaxCount(null); + } + + if (!Const.isEmpty(wSkip.getText())) { + try { + Integer.parseInt(transMeta.environmentSubstitute(wSkip + .getText())); + this.logGitCommand.setSkip(wSkip.getText()); + } catch (NumberFormatException e) { + final MessageBox mb = new MessageBox(shell, SWT.OK + | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.Skip.NumberParseError.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, + "System.Dialog.Error.Title")); + mb.open(); + return; + } + } else { + this.logGitCommand.setSkip(null); + } + + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/package-info.java b/src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/package-info.java new file mode 100644 index 0000000..42ec947 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/info/dialog/impl/package-info.java @@ -0,0 +1,8 @@ +/** + * Package with UI classes of Git information. + * + * @author Joel Latino + * @since 1.0.0 + */ +package com.ivyis.di.trans.steps.git.info.dialog.impl; + diff --git a/src/main/java/com/ivyis/di/trans/steps/git/info/package-info.java b/src/main/java/com/ivyis/di/trans/steps/git/info/package-info.java new file mode 100644 index 0000000..f98b352 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/info/package-info.java @@ -0,0 +1,8 @@ +/** + * Package with classes of Git information step engine. + * + * @author Joel Latino + * @since 1.0.0 + */ +package com.ivyis.di.trans.steps.git.info; + diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStep.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStep.java new file mode 100644 index 0000000..f476918 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStep.java @@ -0,0 +1,182 @@ +package com.ivyis.di.trans.steps.git.operations; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidRemoteException; +import org.eclipse.jgit.api.errors.TransportException; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; +import org.pentaho.di.core.Const; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.core.exception.KettleFileException; +import org.pentaho.di.core.exception.KettleStepException; +import org.pentaho.di.core.row.RowDataUtil; +import org.pentaho.di.core.vfs.KettleVFS; +import org.pentaho.di.trans.Trans; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.trans.step.BaseStep; +import org.pentaho.di.trans.step.StepDataInterface; +import org.pentaho.di.trans.step.StepInterface; +import org.pentaho.di.trans.step.StepMeta; +import org.pentaho.di.trans.step.StepMetaInterface; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitOperationsCommand; + +/** + * This class is responsible to processing the data rows. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class GitOperationsStep extends BaseStep implements StepInterface { + + private GitOperationsStepMeta meta; + private GitOperationsStepData data; + + public GitOperationsStep(StepMeta s, StepDataInterface stepDataInterface, + int c, TransMeta t, Trans dis) { + super(s, stepDataInterface, c, t, dis); + } + + /** + * {@inheritDoc} + * + * @throws KettleException + */ + @Override + public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) + throws KettleException { + this.meta = (GitOperationsStepMeta) smi; + this.data = (GitOperationsStepData) sdi; + + final Object[] r = getRow(); + if (r == null) { + setOutputDone(); + return false; + } + + if (first) { + first = false; + data.outputRowMeta = super.getInputRowMeta(); + data.nrPrevFields = data.outputRowMeta.size(); + meta.getFields(data.outputRowMeta, getStepname(), null, null, this); + + cachePosition(); + } // end if first + + final Object[] outputRow = RowDataUtil + .allocateRowData(data.outputRowMeta.size()); + for (int i = 0; i < data.nrPrevFields; i++) { + outputRow[i] = r[i]; + } + + try { + final Repository repository = FileRepositoryBuilder + .create(new File(data.gitRepoFolderPath, ".git")); + Git git = new Git(repository); + for (GitCommand gitCommand : data.gitCommands) { + logBasic("Starting, command " + gitCommand); + git = ((GitOperationsCommand) gitCommand).call(this, git, + data.cp, data.gitRepoUrl, data.gitRepoFolderPath); + logBasic("Finished, command " + gitCommand); + } + git.close(); + } catch (InvalidRemoteException e) { + System.out.println(e.getMessage()); + } catch (TransportException e) { + throw new KettleException(e); + } catch (GitAPIException e) { + throw new KettleException(e); + } catch (IllegalArgumentException e) { + throw new KettleException(e); + } catch (IOException e) { + throw new KettleException(e); + } + putRow(data.outputRowMeta, outputRow); + + if (checkFeedback(getLinesRead())) { + if (log.isBasic()) { + logBasic("Linenr " + getLinesRead()); // Some basic logging + } + } + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean init(StepMetaInterface smi, StepDataInterface sdi) { + meta = (GitOperationsStepMeta) smi; + data = (GitOperationsStepData) sdi; + + if (super.init(smi, sdi)) { + if (meta.getUsername() != null && meta.getPassword() != null) { + data.cp = new UsernamePasswordCredentialsProvider( + environmentSubstitute(meta.getUsername()), + environmentSubstitute(meta.getPassword())); + } + if (meta.getGitRepoUrl() != null) { + data.gitRepoUrl = environmentSubstitute(meta.getGitRepoUrl()); + } + if (meta.getGitRepoFolderPath() != null) { + try { + data.gitRepoFolderPath = new File( + KettleVFS.getFilename(KettleVFS + .getFileObject(environmentSubstitute(meta + .getGitRepoFolderPath())))); + } catch (KettleFileException e) { + logError(e.getMessage(), e); + } + } + if (meta.getGitCommands().size() > 0) { + data.gitCommands = meta.getGitCommands(); + } + return true; + } + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public void dispose(StepMetaInterface smi, StepDataInterface sdi) { + super.dispose(smi, sdi); + } + + /** + * Run is were the action happens. + */ + public void run() { + logBasic("Starting to run..."); + try { + while (processRow(meta, data) && !isStopped()) { + continue; + } + } catch (Exception e) { + logError("Unexpected error : " + e.toString()); + logError(Const.getStackTracker(e)); + setErrors(1); + stopAll(); + } finally { + dispose(meta, data); + logBasic("Finished, processing " + getLinesRead() + " rows"); + markStop(); + } + } + + /** + * Checks the fields positions. + * + * @throws KettleStepException the kettle step exception. + */ + private void cachePosition() throws KettleStepException { + + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepData.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepData.java new file mode 100644 index 0000000..f6f941f --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepData.java @@ -0,0 +1,30 @@ +package com.ivyis.di.trans.steps.git.operations; + +import java.io.File; +import java.util.List; + +import org.eclipse.jgit.transport.CredentialsProvider; +import org.pentaho.di.core.row.RowMetaInterface; +import org.pentaho.di.trans.step.BaseStepData; +import org.pentaho.di.trans.step.StepDataInterface; + +import com.ivyis.di.trans.steps.git.command.GitCommand; + +/** + * This class contains the methods to set and retrieve the status of the step data. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class GitOperationsStepData extends BaseStepData implements + StepDataInterface { + RowMetaInterface outputRowMeta = null; + RowMetaInterface insertRowMeta = null; + int fieldnr = 0; + int nrPrevFields = 0; + + CredentialsProvider cp; + String gitRepoUrl = null; + File gitRepoFolderPath = null; + List gitCommands = null; +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepDialog.java new file mode 100644 index 0000000..81b9693 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepDialog.java @@ -0,0 +1,596 @@ +package com.ivyis.di.trans.steps.git.operations; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; +import org.pentaho.di.core.Const; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.core.util.StringUtil; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.trans.step.BaseStepMeta; +import org.pentaho.di.trans.step.StepDialogInterface; +import org.pentaho.di.ui.core.dialog.ErrorDialog; +import org.pentaho.di.ui.core.dialog.ShowBrowserDialog; +import org.pentaho.di.ui.core.widget.ColumnInfo; +import org.pentaho.di.ui.core.widget.LabelTextVar; +import org.pentaho.di.ui.core.widget.TableView; +import org.pentaho.di.ui.core.widget.TextVar; +import org.pentaho.di.ui.trans.step.BaseStepDialog; +import org.pentaho.di.ui.util.ImageUtil; + +import com.ivyis.di.trans.steps.git.GitCommandType; +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitCommandFactory; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; +import com.ivyis.di.trans.steps.git.dialog.GitCommandDialogFactory; + +/** + * This class is responsible for Push notification UI on Spoon. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class GitOperationsStepDialog extends BaseStepDialog implements + StepDialogInterface { + + /** for i18n purposes. **/ + private static final Class PKG = GitOperationsStepDialog.class; + + private GitOperationsStepMeta input; + private TextVar wUsernameField, wRepoUrlField, wRepoFolderPathField; + private LabelTextVar wPasswordField; + private TableView wGitCommands; + private ColumnInfo[] ciOperations; + + public GitOperationsStepDialog(Shell parent, BaseStepMeta in, + TransMeta transMeta, String sname) { + super(parent, in, transMeta, sname); + this.input = (GitOperationsStepMeta) in; + } + + /** + * Opens a step dialog window. + * + * @return the (potentially new) name of the step + */ + public String open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN + | SWT.MAX); + props.setLook(shell); + setShellImage(shell, this.input); + + final ModifyListener lsMod = new ModifyListener() { + public void modifyText(ModifyEvent arg0) { + input.setChanged(); + } + }; + backupChanged = input.hasChanged(); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Git.Shell.Title")); + + final int middle = props.getMiddlePct(); + final int margin = Const.MARGIN; + + // Stepname line + wlStepname = new Label(shell, SWT.RIGHT); + wlStepname + .setText(BaseMessages.getString(PKG, "System.Label.StepName")); + props.setLook(wlStepname); + fdlStepname = new FormData(); + fdlStepname.left = new FormAttachment(0, 0); + fdlStepname.right = new FormAttachment(middle, -margin); + fdlStepname.top = new FormAttachment(0, margin); + wlStepname.setLayoutData(fdlStepname); + + wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wStepname.setText(stepname); + props.setLook(wStepname); + wStepname.addModifyListener(lsMod); + fdStepname = new FormData(); + fdStepname.left = new FormAttachment(middle, 0); + fdStepname.top = new FormAttachment(0, margin); + fdStepname.right = new FormAttachment(100, 0); + wStepname.setLayoutData(fdStepname); + + // //////////////////////////// + // START OF OPERATIONS GROUP // + // //////////////////////////// + final Group gBasicPropertiesFields = new Group(shell, SWT.SHADOW_NONE); + props.setLook(gBasicPropertiesFields); + gBasicPropertiesFields.setText(BaseMessages.getString(PKG, + "Git.gBasicPropertiesFields.Label")); + final FormLayout flgOperationsFieldsLayout = new FormLayout(); + flgOperationsFieldsLayout.marginWidth = 10; + flgOperationsFieldsLayout.marginHeight = 10; + gBasicPropertiesFields.setLayout(flgOperationsFieldsLayout); + + // UserName field + final Label wlUsernameField = new Label(gBasicPropertiesFields, + SWT.RIGHT); + wlUsernameField.setText(BaseMessages.getString(PKG, + "Git.UserName.Label")); + props.setLook(wlUsernameField); + final FormData fdlUsernameField = new FormData(); + fdlUsernameField.left = new FormAttachment(0, -margin); + fdlUsernameField.top = new FormAttachment(wStepname, margin); + fdlUsernameField.right = new FormAttachment(middle, -2 * margin); + wlUsernameField.setLayoutData(fdlUsernameField); + + wUsernameField = new TextVar(this.transMeta, gBasicPropertiesFields, + SWT.SINGLE | SWT.LEFT | SWT.BORDER); + wUsernameField.setEditable(true); + props.setLook(wUsernameField); + final FormData fdUsernameField = new FormData(); + fdUsernameField.left = new FormAttachment(middle, -margin); + fdUsernameField.top = new FormAttachment(wStepname, margin); + fdUsernameField.right = new FormAttachment(100, -margin); + wUsernameField.setLayoutData(fdUsernameField); + + // Git repository password value + wPasswordField = new LabelTextVar(transMeta, gBasicPropertiesFields, + BaseMessages.getString(PKG, "Git.PasswordField.Label"), + BaseMessages.getString(PKG, "Git.PasswordField.Tooltip")); + props.setLook(wPasswordField); + wPasswordField.setEchoChar('*'); + wPasswordField.addModifyListener(lsMod); + final FormData fdCertificatePassword = new FormData(); + fdCertificatePassword.left = new FormAttachment(0, -margin); + fdCertificatePassword.top = new FormAttachment(wUsernameField, margin); + fdCertificatePassword.right = new FormAttachment(100, -margin); + wPasswordField.setLayoutData(fdCertificatePassword); + + // OK, if the password contains a variable, we don't want to have the + // password hidden... + wPasswordField.getTextWidget().addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent e) { + checkPasswordVisible(); + } + }); + + // Git Repository URL + final Label wlRepoUrlField = new Label(gBasicPropertiesFields, + SWT.RIGHT); + wlRepoUrlField.setText(BaseMessages.getString(PKG, + "Git.RepoUrlField.Label")); + props.setLook(wlRepoUrlField); + final FormData fdlRepoUrlField = new FormData(); + fdlRepoUrlField.left = new FormAttachment(0, -margin); + fdlRepoUrlField.top = new FormAttachment(wPasswordField, margin); + fdlRepoUrlField.right = new FormAttachment(middle, -2 * margin); + wlRepoUrlField.setLayoutData(fdlRepoUrlField); + + wRepoUrlField = new TextVar(transMeta, gBasicPropertiesFields, + SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wRepoUrlField); + wRepoUrlField.addModifyListener(lsMod); + final FormData fdRepoUrlField = new FormData(); + fdRepoUrlField.left = new FormAttachment(middle, -margin); + fdRepoUrlField.top = new FormAttachment(wPasswordField, margin); + fdRepoUrlField.right = new FormAttachment(100, -margin); + wRepoUrlField.setLayoutData(fdRepoUrlField); + + // Git clone repository folder + final Label wlRepoFolderPathField = new Label(gBasicPropertiesFields, + SWT.RIGHT); + wlRepoFolderPathField.setText(BaseMessages.getString(PKG, + "Git.RepoFolderPathField.Label")); + props.setLook(wlRepoFolderPathField); + final FormData fdlRepoFolderPathField = new FormData(); + fdlRepoFolderPathField.left = new FormAttachment(0, -margin); + fdlRepoFolderPathField.top = new FormAttachment(wRepoUrlField, margin); + fdlRepoFolderPathField.right = new FormAttachment(middle, -2 * margin); + wlRepoFolderPathField.setLayoutData(fdlRepoFolderPathField); + + wRepoFolderPathField = new TextVar(transMeta, gBasicPropertiesFields, + SWT.SINGLE | SWT.LEFT | SWT.BORDER); + props.setLook(wRepoUrlField); + wRepoFolderPathField.addModifyListener(lsMod); + final FormData fdRepoFolderPathField = new FormData(); + fdRepoFolderPathField.left = new FormAttachment(middle, -margin); + fdRepoFolderPathField.top = new FormAttachment(wRepoUrlField, margin); + fdRepoFolderPathField.right = new FormAttachment(100, -margin); + wRepoFolderPathField.setLayoutData(fdRepoFolderPathField); + + final FormData fdOperationsFields = new FormData(); + fdOperationsFields.left = new FormAttachment(0, margin); + fdOperationsFields.top = new FormAttachment(wStepname, 2 * margin); + fdOperationsFields.right = new FormAttachment(100, -margin); + gBasicPropertiesFields.setLayoutData(fdOperationsFields); + + // /////////////////////////// + // END OF OPERATIONS GROUP // + // /////////////////////////// + + // OK and cancel buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + BaseStepDialog.positionBottomButtons(shell, + new Button[] {wOK, wCancel}, margin, null); + + final Button button = new Button(shell, SWT.PUSH); + button.setImage(ImageUtil.getImage(display, getClass(), + "ivyis_logo.png")); + button.setToolTipText("Ivy Information Systems"); + button.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + final ShowBrowserDialog sbd = + new ShowBrowserDialog(shell, BaseMessages.getString(PKG, + "ExportCmdLine.CommandLine.Title"), + ""); + sbd.open(); + } + }); + + // Determine the largest button in the array + Rectangle largest = null; + button.pack(true); + final Rectangle r = button.getBounds(); + if (largest == null || r.width > largest.width) { + largest = r; + } + + // Also, set the tooltip the same as the name if we don't have one... + if (button.getToolTipText() == null) { + button.setToolTipText(Const.replace(button.getText(), "&", "")); + } + + // Make buttons a bit larger... (nicer) + largest.width += 10; + if ((largest.width % 2) == 1) { + largest.width++; + } + + BaseStepDialog.rightAlignButtons(new Button[] {button}, + largest.width, margin, null); + if (Const.isOSX()) { + final List tableViews = new ArrayList(); + getTableViews(shell, tableViews); + button.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + for (TableView view : tableViews) { + view.applyOSXChanges(); + } + } + }); + } + + // The git commands table + final Label wlOperations = new Label(shell, SWT.NONE); + wlOperations.setText(BaseMessages.getString(PKG, + "Git.DefineCommands.Label")); + props.setLook(wlOperations); + final FormData fdlOperations = new FormData(); + fdlOperations.left = new FormAttachment(0, 0); + fdlOperations.top = new FormAttachment(gBasicPropertiesFields, margin); + wlOperations.setLayoutData(fdlOperations); + + final int tableCols = 2; + final int upInsRows = input.getGitCommands() != null ? input + .getGitCommands().size() : 1; + + ciOperations = new ColumnInfo[tableCols]; + ciOperations[0] = new ColumnInfo(BaseMessages.getString(PKG, + "Git.ColumnInfo.CommandType.Label"), + ColumnInfo.COLUMN_TYPE_CCOMBO, + GitCommandType.getOperationTypesLabel(), false); + ciOperations[1] = new ColumnInfo(BaseMessages.getString(PKG, + "Git.ColumnInfo.Description.Label"), + ColumnInfo.COLUMN_TYPE_TEXT, new String[] {""}, false); + + ciOperations[1].setSelectionAdapter(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + + final String commandName = ((TableView) e.widget).getItem(e.y, + e.x - 1); + if ("".equals(commandName)) { + return; + } + + final TableView tv = (TableView) e.widget; + GitCommand gitCommand = null; + if (!"".equals(tv.getItem(e.y)[1])) { + try { + gitCommand = GitCommandFactory.getGitCommand( + GitCommandType.fromLabel(commandName), + tv.getItem(e.y)[1]); + } catch (KettleException ex) { + new ErrorDialog( + shell, + BaseMessages.getString(PKG, + "Git.GitCommandNotFount.DialogTitle"), + BaseMessages.getString(PKG, + "Git.GitCommandNotFount.DialogMessage"), + ex); + } + } + final BaseGitCommandDialog gcd = GitCommandDialogFactory + .getGitCommandDialog(shell, transMeta, gitCommand, + GitCommandType.fromLabel(commandName)); + final GitCommand gc = gcd.open(); + + if (gc != null) { + tv.setText(gc.getDescription(), e.x, e.y); + input.setChanged(); + } + } + }); + + wGitCommands = new TableView(transMeta, shell, SWT.BORDER + | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, + ciOperations, upInsRows, lsMod, props); + + final FormData fdGitCommandFields = new FormData(); + fdGitCommandFields.top = new FormAttachment(wlOperations, margin * 2); + fdGitCommandFields.bottom = new FormAttachment(wOK, -margin * 2); + fdGitCommandFields.left = new FormAttachment(0, 0); + fdGitCommandFields.right = new FormAttachment(100, 0); + wGitCommands.setLayoutData(fdGitCommandFields); + + // Add listeners + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + + wCancel.addListener(SWT.Selection, lsCancel); + wOK.addListener(SWT.Selection, lsOK); + + lsDef = new SelectionAdapter() { + public void widgetDefaultSelected(SelectionEvent e) { + ok(); + } + }; + wStepname.addSelectionListener(lsDef); + + // Detect X or ALT-F4 or something that kills this window... + shell.addShellListener(new ShellAdapter() { + @Override + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + // Set the shell size, based upon previous time... + setSize(); + + getData(); + input.setChanged(backupChanged); + + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + return stepname; + } + + /** + * Gets the table views. + * + * @param parentControl the parent control + * @param tableViews the table views + * @return the table views + */ + private static final void getTableViews(Control parentControl, + List tableViews) { + if (parentControl instanceof TableView) { + tableViews.add((TableView) parentControl); + } else { + if (parentControl instanceof Composite) { + final Control[] children = ((Composite) parentControl) + .getChildren(); + for (Control child : children) { + getTableViews(child, tableViews); + } + } else { + if (parentControl instanceof Shell) { + final Control[] children = ((Shell) parentControl) + .getChildren(); + for (Control child : children) { + getTableViews(child, tableViews); + } + + } + } + } + } + + /** + * Read data and place it in the dialog. + */ + public void getData() { + wStepname.selectAll(); + if (input.getUsername() != null) { + wUsernameField.setText(input.getUsername()); + } + if (input.getPassword() != null) { + wPasswordField.setText(input.getPassword()); + } + if (input.getGitRepoFolderPath() != null) { + wRepoFolderPathField.setText(input.getGitRepoFolderPath()); + } + if (input.getGitRepoUrl() != null) { + wRepoUrlField.setText(input.getGitRepoUrl()); + } + if (input.getGitCommands().size() > 0) { + for (int i = 0; i < input.getGitCommands().size(); i++) { + final TableItem item = wGitCommands.table.getItem(i); + if (input.getGitCommands().get(i) != null) { + item.setText(1, input.getGitCommands().get(i) + .getCommandType().getOperationLabel()); + item.setText(2, input.getGitCommands().get(i) + .getDescription()); + } + } + } + } + + /** + * Checks the password visible. + */ + private void checkPasswordVisible() { + final String password = wPasswordField.getText(); + final List list = new ArrayList(); + StringUtil.getUsedVariables(password, list, true); + if (list.size() == 0) { + wPasswordField.setEchoChar('*'); + } else { + String variableName = null; + if (password.startsWith(StringUtil.UNIX_OPEN) + && password.endsWith(StringUtil.UNIX_CLOSE)) { + variableName = password.substring( + StringUtil.UNIX_OPEN.length(), password.length() + - StringUtil.UNIX_CLOSE.length()); + } + if (password.startsWith(StringUtil.WINDOWS_OPEN) + && password.endsWith(StringUtil.WINDOWS_CLOSE)) { + variableName = password.substring( + StringUtil.WINDOWS_OPEN.length(), password.length() + - StringUtil.WINDOWS_CLOSE.length()); + } + if (variableName != null + && System.getProperty(variableName) != null) { + wPasswordField.setEchoChar('\0'); + } else { + wPasswordField.setEchoChar('*'); + } + } + } + + /** + * Cancel. + */ + private void cancel() { + stepname = null; + input.setChanged(backupChanged); + dispose(); + } + + /** + * Let the plugin know about the entered data. + */ + private void ok() { + if (!Const.isEmpty(wStepname.getText())) { + stepname = wStepname.getText(); + getInfo(input); + } + } + + /** + * Get the information. + * + * @param info the push notification step meta data. + */ + public void getInfo(GitOperationsStepMeta info) { + if (Const.isEmpty(wUsernameField.getText()) + || Const.isEmpty(wPasswordField.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK + | SWT.ICON_WARNING); + mb.setMessage(BaseMessages.getString(PKG, + "Git.Username.Password.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, + "System.Dialog.Warning.Title")); + mb.open(); + } + input.setUsername(wUsernameField.getText()); + input.setPassword(wPasswordField.getText()); + + if (Const.isEmpty(wRepoFolderPathField.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.RepoFolder.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } + input.setGitRepoFolderPath(wRepoFolderPathField.getText()); + + if (Const.isEmpty(wRepoUrlField.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.RepoUrl.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } + input.setGitRepoUrl(wRepoUrlField.getText()); + final ArrayList commands = new ArrayList(); + if (wGitCommands.getItemCount() > 0) { + try { + for (int i = 0; i < wGitCommands.getItemCount(); i++) { + if (wGitCommands.getItem(i, 1) == null + || GitCommandType.fromLabel(wGitCommands.getItem(i, + 1)) == null) { + continue; + } + final GitCommand gitCommand = GitCommandFactory + .getGitCommand(GitCommandType + .fromLabel(wGitCommands.getItem(i, 1)), + wGitCommands.getItem(i, 2)); + + if (gitCommand != null) { + commands.add(gitCommand); + } + } + } catch (KettleException e) { + new ErrorDialog(shell, BaseMessages.getString(PKG, + "Git.GitCommandNotFount.DialogTitle"), + BaseMessages.getString(PKG, + "Git.GitCommandNotFount.DialogMessage"), e); + } + } + if (commands.size() == 0) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.Min.Git.Commands.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } + input.setGitCommands(commands); + + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepMeta.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepMeta.java new file mode 100644 index 0000000..58a23da --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/GitOperationsStepMeta.java @@ -0,0 +1,304 @@ +package com.ivyis.di.trans.steps.git.operations; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.CheckResultInterface; +import org.pentaho.di.core.Const; +import org.pentaho.di.core.Counter; +import org.pentaho.di.core.annotations.Step; +import org.pentaho.di.core.database.DatabaseMeta; +import org.pentaho.di.core.exception.KettleException; +import org.pentaho.di.core.exception.KettleXMLException; +import org.pentaho.di.core.row.RowMetaInterface; +import org.pentaho.di.core.variables.VariableSpace; +import org.pentaho.di.core.xml.XMLHandler; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.repository.ObjectId; +import org.pentaho.di.repository.Repository; +import org.pentaho.di.trans.Trans; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.trans.step.BaseStepMeta; +import org.pentaho.di.trans.step.StepDataInterface; +import org.pentaho.di.trans.step.StepDialogInterface; +import org.pentaho.di.trans.step.StepInterface; +import org.pentaho.di.trans.step.StepMeta; +import org.pentaho.di.trans.step.StepMetaInterface; +import org.w3c.dom.Node; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.GitCommandFactory; + +/** + * This class is responsible for implementing functionality regarding step meta. All Kettle steps + * have an extension of this where private fields have been added with public accessors. + * + * @author Joel Latino + * @since 1.0.0 + */ +@Step(id = "GitOperationsStep", name = "GitOperations.Step.Name", + description = "GitOperations.Step.Description", + categoryDescription = "GitOperations.Step.Category", + image = "com/ivyis/di/trans/steps/git/operations/GitOperationsStep.png", + i18nPackageName = "com.ivyis.di.trans.steps.git.operations", + casesUrl = "https://github.com/ivylabs", documentationUrl = "https://github.com/ivylabs", + forumUrl = "https://github.com/ivylabs") +public class GitOperationsStepMeta extends BaseStepMeta implements + StepMetaInterface { + + /** for i18n purposes. **/ + private static final Class PKG = GitOperationsStepMeta.class; + + private String username, password, gitRepoUrl, gitRepoFolderPath; + private List gitCommands = new ArrayList(); + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getGitRepoUrl() { + return gitRepoUrl; + } + + public void setGitRepoUrl(String gitRepoUrl) { + this.gitRepoUrl = gitRepoUrl; + } + + public String getGitRepoFolderPath() { + return gitRepoFolderPath; + } + + public void setGitRepoFolderPath(String gitRepoFolderPath) { + this.gitRepoFolderPath = gitRepoFolderPath; + } + + public List getGitCommands() { + return gitCommands; + } + + public void setGitCommands(List gitCommands) { + this.gitCommands = gitCommands; + } + + /** + * {@inheritDoc} + */ + @Override + public String getXML() { + final StringBuilder retval = new StringBuilder(); + retval.append(" " + XMLHandler.addTagValue("username", username)); + retval.append(" " + XMLHandler.addTagValue("password", password)); + retval.append(" " + XMLHandler.addTagValue("gitRepoUrl", gitRepoUrl)); + retval.append(" " + + XMLHandler + .addTagValue("gitRepoFolderPath", gitRepoFolderPath)); + + retval.append(" ").append(Const.CR); + for (int i = 0; i < gitCommands.size(); i++) { + if (gitCommands.get(i) == null) { + continue; + } + retval.append(" ").append(Const.CR); + retval.append(" ").append(gitCommands.get(i).getXML()); + retval.append(" ").append(Const.CR); + } + retval.append(" ").append(Const.CR); + + return retval.toString(); + } + + /** + * Reads data from XML transformation file. + * + * @param stepnode the step XML node. + * @throws KettleXMLException the kettle XML exception. + */ + public void readData(Node stepnode) throws KettleXMLException { + try { + username = XMLHandler.getTagValue(stepnode, "username"); + password = XMLHandler.getTagValue(stepnode, "password"); + gitRepoUrl = XMLHandler.getTagValue(stepnode, "gitRepoUrl"); + gitRepoFolderPath = XMLHandler.getTagValue(stepnode, + "gitRepoFolderPath"); + final String stepName = XMLHandler.getTagValue(stepnode, "name"); + + // Git commands + final Node gitCommands = XMLHandler.getSubNode(stepnode, + "gitCommands"); + final int nrCustomFieldsRows = XMLHandler.countNodes(gitCommands, + "gitCommand"); + this.gitCommands = new ArrayList(); + for (int i = 0; i < nrCustomFieldsRows; i++) { + final Node knode = XMLHandler.getSubNodeByNr(gitCommands, + "gitCommand", i); + this.gitCommands.add(GitCommandFactory.getGitCommand(knode, + stepName)); + } + + } catch (Exception e) { + throw new KettleXMLException(BaseMessages.getString(PKG, + "ImageResize.Exception.UnexpectedErrorInReadingStepInfo"), + e); + } + } + + /** + * {@inheritDoc} + * + * @throws KettleException + */ + @Override + public void readRep(Repository rep, ObjectId idStep, + List databases, Map counters) + throws KettleException { + try { + username = rep.getStepAttributeString(idStep, "username"); + password = rep.getStepAttributeString(idStep, "password"); + gitRepoUrl = rep.getStepAttributeString(idStep, "gitRepoUrl"); + gitRepoFolderPath = rep.getStepAttributeString(idStep, + "gitRepoFolderPath"); + final String stepName = rep.getStepAttributeString(idStep, "name"); + + final int nrRows = rep.countNrStepAttributes(idStep, "gitCommand"); + gitCommands = new ArrayList(); + for (int i = 0; i < nrRows; i++) { + gitCommands.add(GitCommandFactory.getGitCommand( + rep.getStepAttributeString(idStep, i, "gitCommand"), + stepName)); + } + + } catch (Exception e) { + throw new KettleException(BaseMessages.getString(PKG, + "Git.Exception.UnexpectedErrorInReadingStepInfo"), e); + } + } + + /** + * {@inheritDoc} + * + * @throws KettleException + */ + @Override + public void saveRep(Repository rep, ObjectId idTransformation, + ObjectId idStep) throws KettleException { + try { + rep.saveStepAttribute(idTransformation, idStep, "username", + username); + rep.saveStepAttribute(idTransformation, idStep, "password", + password); + rep.saveStepAttribute(idTransformation, idStep, "gitRepoUrl", + gitRepoUrl); + rep.saveStepAttribute(idTransformation, idStep, + "gitRepoFolderPath", gitRepoFolderPath); + + for (int i = 0; i < gitCommands.size(); i++) { + rep.saveStepAttribute(idTransformation, idStep, i, + "gitCommand", gitCommands.get(i).getXML()); + } + } catch (Exception e) { + throw new KettleException(BaseMessages.getString(PKG, + "Git.Exception.UnableToSaveStepInfoToRepository") + idStep, + e); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void getFields(RowMetaInterface r, String origin, + RowMetaInterface[] info, StepMeta nextStep, VariableSpace space) { + return; + } + + /** + * {@inheritDoc} + */ + @Override + public Object clone() { + return super.clone(); + } + + /** + * {@inheritDoc} + * + * @throws KettleXMLException + */ + @Override + public void loadXML(Node stepnode, List databases, + Map counters) throws KettleXMLException { + readData(stepnode); + } + + /** + * Sets the default values. + */ + public void setDefault() {} + + /** + * {@inheritDoc} + */ + @Override + public void check(List remarks, TransMeta transmeta, + StepMeta stepMeta, RowMetaInterface prev, String[] input, + String[] output, RowMetaInterface info) {} + + /** + * Get the Step dialog, needs for configure the step. + * + * @param shell the shell. + * @param meta the associated base step metadata. + * @param transMeta the associated transformation metadata. + * @param name the step name + * @return The appropriate StepDialogInterface class. + */ + public StepDialogInterface getDialog(Shell shell, StepMetaInterface meta, + TransMeta transMeta, String name) { + return new GitOperationsStepDialog(shell, (BaseStepMeta) meta, + transMeta, name); + } + + /** + * Get the executing step, needed by Trans to launch a step. + * + * @param stepMeta The step info. + * @param stepDataInterface the step data interface linked to this step. Here the step can store + * temporary data, database connections, etc. + * @param cnr The copy nr to get. + * @param transMeta The transformation info. + * @param disp The launching transformation. + * @return The appropriate StepInterface class. + */ + public StepInterface getStep(StepMeta stepMeta, + StepDataInterface stepDataInterface, int cnr, TransMeta transMeta, + Trans disp) { + return new GitOperationsStep(stepMeta, stepDataInterface, cnr, + transMeta, disp); + } + + /** + * Get a new instance of the appropriate data class. This data class implements the + * StepDataInterface. It basically contains the persisting data that needs to live on, even if a + * worker thread is terminated. + * + * @return The appropriate StepDataInterface class. + */ + public StepDataInterface getStepData() { + return new GitOperationsStepData(); + } + +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/AddGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/AddGitCommandDialog.java new file mode 100644 index 0000000..5ba8545 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/AddGitCommandDialog.java @@ -0,0 +1,202 @@ +package com.ivyis.di.trans.steps.git.operations.dialog.impl; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.ui.core.PropsUI; +import org.pentaho.di.ui.core.gui.GUIResource; +import org.pentaho.di.ui.core.gui.WindowProperty; +import org.pentaho.di.ui.core.widget.TextVar; +import org.pentaho.di.ui.trans.step.BaseStepDialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.impl.AddGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; + +/** + * Add command UI class. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class AddGitCommandDialog extends Dialog implements BaseGitCommandDialog { + private static final Class PKG = AddGitCommandDialog.class; // for i18n + + private Button wUpdate; + private TextVar wFilepattern; + + private Shell shell; + private boolean modal; + private PropsUI props; + private TransMeta transMeta; + private Button wOK, wCancel; + private Listener lsOK, lsCancel; + private AddGitCommand addCommand; + + public Shell getShell() { + return shell; + } + + public AddGitCommandDialog(Shell parent, TransMeta transMeta, + GitCommand gitCommand) { + super(parent, SWT.NONE); + this.modal = true; + this.transMeta = transMeta; + props = PropsUI.getInstance(); + if (gitCommand != null && gitCommand instanceof AddGitCommand) { + this.addCommand = (AddGitCommand) gitCommand; + } else { + this.addCommand = new AddGitCommand(); + } + } + + public GitCommand open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM + | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE) + | SWT.RESIZE | SWT.MIN | SWT.MAX); + props.setLook(shell); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + final int margin = Const.MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Git.AddCommandDialog.Title")); + shell.setImage(GUIResource.getInstance().getImageSpoon()); + + // File pattern + final Label wlFilepattern = new Label(shell, SWT.RIGHT); + wlFilepattern.setText(BaseMessages.getString(PKG, + "Git.FilePattern.Label")); + props.setLook(wlFilepattern); + final FormData fdlFilepattern = new FormData(); + fdlFilepattern.left = new FormAttachment(0, 25); + fdlFilepattern.top = new FormAttachment(shell, margin); + wlFilepattern.setLayoutData(fdlFilepattern); + + wFilepattern = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wFilepattern); + final FormData fdFilepattern = new FormData(); + fdFilepattern.left = new FormAttachment(wlFilepattern, margin); + fdFilepattern.top = new FormAttachment(shell, margin); + fdFilepattern.right = new FormAttachment(100, 0); + wFilepattern.setLayoutData(fdFilepattern); + + // Update + final Label wlUpdate = new Label(shell, SWT.RIGHT); + wlUpdate.setText(BaseMessages.getString(PKG, "Git.Update.Label")); + props.setLook(wlUpdate); + final FormData fdlUpdate = new FormData(); + fdlUpdate.left = new FormAttachment(0, 25); + fdlUpdate.top = new FormAttachment(wFilepattern, margin); + wlUpdate.setLayoutData(fdlUpdate); + + wUpdate = new Button(shell, SWT.CHECK); + props.setLook(wUpdate); + final FormData fdUpdate = new FormData(); + fdUpdate.left = new FormAttachment(wlUpdate, margin); + fdUpdate.top = new FormAttachment(wFilepattern, margin); + fdUpdate.right = new FormAttachment(100, 0); + wUpdate.setLayoutData(fdUpdate); + + // Some buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + wOK.addListener(SWT.Selection, lsOK); + + Button[] buttons = new Button[] {wOK}; + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + wCancel.addListener(SWT.Selection, lsCancel); + + buttons = new Button[] {wOK, wCancel}; + + BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + + // Add listeners + shell.addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + getData(); + + BaseStepDialog.setSize(shell); + + wOK.setFocus(); + + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return this.addCommand; + + } + + public void dispose() { + props.setScreen(new WindowProperty(shell)); + shell.dispose(); + } + + public void getData() { + if (!Const.isEmpty(this.addCommand.getFilepattern())) { + wFilepattern.setText(this.addCommand.getFilepattern()); + } + wUpdate.setSelection(this.addCommand.isUpdate()); + } + + private void cancel() { + this.addCommand = null; + dispose(); + } + + private void ok() { + if (Const.isEmpty(wFilepattern.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.FilePattern.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } + this.addCommand.setFilepattern(wFilepattern.getText()); + this.addCommand.setUpdate(wUpdate.getSelection()); + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CheckoutGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CheckoutGitCommandDialog.java new file mode 100644 index 0000000..2012ee3 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CheckoutGitCommandDialog.java @@ -0,0 +1,260 @@ +package com.ivyis.di.trans.steps.git.operations.dialog.impl; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.ui.core.PropsUI; +import org.pentaho.di.ui.core.gui.GUIResource; +import org.pentaho.di.ui.core.gui.WindowProperty; +import org.pentaho.di.ui.core.widget.TextVar; +import org.pentaho.di.ui.trans.step.BaseStepDialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.impl.CheckoutGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; + +/** + * Checkout command UI class. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class CheckoutGitCommandDialog extends Dialog implements + BaseGitCommandDialog { + private static final Class PKG = CheckoutGitCommandDialog.class; // for i18n + + private Button wAllPaths, wForce; + private TextVar wPath, wName, wStartPoint; + + private Shell shell; + private boolean modal; + private PropsUI props; + private TransMeta transMeta; + private Button wOK, wCancel; + private Listener lsOK, lsCancel; + private CheckoutGitCommand checkoutGitCommand; + + public Shell getShell() { + return shell; + } + + public CheckoutGitCommandDialog(Shell parent, TransMeta transMeta, + GitCommand gitCommand) { + super(parent, SWT.NONE); + this.modal = true; + this.transMeta = transMeta; + props = PropsUI.getInstance(); + if (gitCommand != null && gitCommand instanceof CheckoutGitCommand) { + this.checkoutGitCommand = (CheckoutGitCommand) gitCommand; + } else { + this.checkoutGitCommand = new CheckoutGitCommand(); + } + } + + public GitCommand open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM + | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE) + | SWT.RESIZE | SWT.MIN | SWT.MAX); + props.setLook(shell); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + final int margin = Const.MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, + "Git.CheckoutCommandDialog.Title")); + shell.setImage(GUIResource.getInstance().getImageSpoon()); + + // Path field + final Label wlPath = new Label(shell, SWT.RIGHT); + wlPath.setText(BaseMessages.getString(PKG, "Git.Path.Label")); + props.setLook(wlPath); + final FormData fdlPath = new FormData(); + fdlPath.left = new FormAttachment(0, 25); + fdlPath.top = new FormAttachment(shell, margin); + wlPath.setLayoutData(fdlPath); + + wPath = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wPath); + final FormData fdPath = new FormData(); + fdPath.left = new FormAttachment(wlPath, margin); + fdPath.top = new FormAttachment(shell, margin); + fdPath.right = new FormAttachment(100, 0); + wPath.setLayoutData(fdPath); + + // Name field + final Label wlName = new Label(shell, SWT.RIGHT); + wlName.setText(BaseMessages.getString(PKG, "Git.Name.Label")); + props.setLook(wlName); + final FormData fdlName = new FormData(); + fdlName.left = new FormAttachment(0, 25); + fdlName.top = new FormAttachment(wPath, margin); + wlName.setLayoutData(fdlName); + + wName = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wName); + final FormData fdName = new FormData(); + fdName.left = new FormAttachment(wlName, margin); + fdName.top = new FormAttachment(wPath, margin); + fdName.right = new FormAttachment(100, 0); + wName.setLayoutData(fdName); + + // Start point field + final Label wlStartPoint = new Label(shell, SWT.RIGHT); + wlStartPoint.setText(BaseMessages + .getString(PKG, "Git.StartPoint.Label")); + props.setLook(wlStartPoint); + final FormData fdlStartPoint = new FormData(); + fdlStartPoint.left = new FormAttachment(0, 25); + fdlStartPoint.top = new FormAttachment(wName, margin); + wlStartPoint.setLayoutData(fdlStartPoint); + + wStartPoint = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wStartPoint); + final FormData fdStartPoint = new FormData(); + fdStartPoint.left = new FormAttachment(wlStartPoint, margin); + fdStartPoint.top = new FormAttachment(wName, margin); + fdStartPoint.right = new FormAttachment(100, 0); + wStartPoint.setLayoutData(fdStartPoint); + + // All Paths field + final Label wlAllPaths = new Label(shell, SWT.RIGHT); + wlAllPaths.setText(BaseMessages.getString(PKG, "Git.AllPaths.Label")); + props.setLook(wlAllPaths); + final FormData fdlAllPaths = new FormData(); + fdlAllPaths.left = new FormAttachment(0, 25); + fdlAllPaths.top = new FormAttachment(wStartPoint, margin); + wlAllPaths.setLayoutData(fdlAllPaths); + + wAllPaths = new Button(shell, SWT.CHECK); + props.setLook(wAllPaths); + final FormData fdAllPaths = new FormData(); + fdAllPaths.left = new FormAttachment(wlAllPaths, margin); + fdAllPaths.top = new FormAttachment(wStartPoint, margin); + fdAllPaths.right = new FormAttachment(100, 0); + wAllPaths.setLayoutData(fdAllPaths); + + // force field + final Label wlForce = new Label(shell, SWT.RIGHT); + wlForce.setText(BaseMessages.getString(PKG, "Git.Force.Label")); + props.setLook(wlForce); + final FormData fdlForce = new FormData(); + fdlForce.left = new FormAttachment(0, 25); + fdlForce.top = new FormAttachment(wAllPaths, margin); + wlForce.setLayoutData(fdlForce); + + wForce = new Button(shell, SWT.CHECK); + props.setLook(wForce); + final FormData fdForce = new FormData(); + fdForce.left = new FormAttachment(wlForce, margin); + fdForce.top = new FormAttachment(wAllPaths, margin); + fdForce.right = new FormAttachment(100, 0); + wForce.setLayoutData(fdForce); + + // Some buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + wOK.addListener(SWT.Selection, lsOK); + + Button[] buttons = new Button[] {wOK}; + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + wCancel.addListener(SWT.Selection, lsCancel); + + buttons = new Button[] {wOK, wCancel}; + + BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + + // Add listeners + shell.addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + getData(); + + BaseStepDialog.setSize(shell); + + wOK.setFocus(); + + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return this.checkoutGitCommand; + + } + + public void dispose() { + props.setScreen(new WindowProperty(shell)); + shell.dispose(); + } + + public void getData() { + if (!Const.isEmpty(this.checkoutGitCommand.getName())) { + wName.setText(this.checkoutGitCommand.getName()); + } + if (!Const.isEmpty(this.checkoutGitCommand.getPath())) { + wPath.setText(this.checkoutGitCommand.getPath()); + } + if (!Const.isEmpty(this.checkoutGitCommand.getStartPoint())) { + wStartPoint.setText(this.checkoutGitCommand.getStartPoint()); + } + wAllPaths.setSelection(this.checkoutGitCommand.isAllPaths()); + wForce.setSelection(this.checkoutGitCommand.isForce()); + } + + private void cancel() { + this.checkoutGitCommand = null; + dispose(); + } + + private void ok() { + this.checkoutGitCommand.setName(wName.getText()); + this.checkoutGitCommand.setPath(Const.isEmpty(wPath.getText()) ? "" + : wPath.getText()); + this.checkoutGitCommand.setStartPoint(Const.isEmpty(wStartPoint + .getText()) ? "" : wStartPoint.getText()); + this.checkoutGitCommand.setAllPaths(wAllPaths.getSelection()); + this.checkoutGitCommand.setForce(wForce.getSelection()); + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CloneGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CloneGitCommandDialog.java new file mode 100644 index 0000000..46d9500 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CloneGitCommandDialog.java @@ -0,0 +1,232 @@ +package com.ivyis.di.trans.steps.git.operations.dialog.impl; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.ui.core.PropsUI; +import org.pentaho.di.ui.core.gui.GUIResource; +import org.pentaho.di.ui.core.gui.WindowProperty; +import org.pentaho.di.ui.core.widget.TextVar; +import org.pentaho.di.ui.trans.step.BaseStepDialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.impl.CloneGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; + +/** + * Clone command UI class. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class CloneGitCommandDialog extends Dialog implements + BaseGitCommandDialog { + private static final Class PKG = CloneGitCommandDialog.class; // for i18n + + private Button wCloneSubModulesField, wCloneAllBranchesField; + private TextVar wBranchField; + + private Shell shell; + private boolean modal; + private PropsUI props; + private TransMeta transMeta; + private Button wOK, wCancel; + private Listener lsOK, lsCancel; + private CloneGitCommand cloneCommand; + + public Shell getShell() { + return shell; + } + + public CloneGitCommandDialog(Shell parent, TransMeta transMeta, + GitCommand gitCommand) { + super(parent, SWT.NONE); + this.modal = true; + this.transMeta = transMeta; + props = PropsUI.getInstance(); + if (gitCommand != null && gitCommand instanceof CloneGitCommand) { + this.cloneCommand = (CloneGitCommand) gitCommand; + } else { + this.cloneCommand = new CloneGitCommand(); + this.cloneCommand.setBranchName("master"); + } + } + + public GitCommand open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM + | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE) + | SWT.RESIZE | SWT.MIN | SWT.MAX); + props.setLook(shell); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + final int margin = Const.MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, + "Git.CloneCommandDialog.Title")); + shell.setImage(GUIResource.getInstance().getImageSpoon()); + + // Git branch name (optional) + final Label wlBranchField = new Label(shell, SWT.RIGHT); + wlBranchField.setText(BaseMessages.getString(PKG, + "Git.BranchField.Label")); + props.setLook(wlBranchField); + final FormData fdlBranchField = new FormData(); + fdlBranchField.left = new FormAttachment(0, 25); + fdlBranchField.top = new FormAttachment(shell, margin); + wlBranchField.setLayoutData(fdlBranchField); + + wBranchField = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wBranchField); + final FormData fdBranchField = new FormData(); + fdBranchField.left = new FormAttachment(wlBranchField, margin); + fdBranchField.top = new FormAttachment(shell, margin); + fdBranchField.right = new FormAttachment(100, 0); + wBranchField.setLayoutData(fdBranchField); + + // Clone sub modules + final Label wlCloneSubModulesField = new Label(shell, SWT.RIGHT); + wlCloneSubModulesField.setText(BaseMessages.getString(PKG, + "Git.CloneSubModulesField.Label")); + props.setLook(wlCloneSubModulesField); + final FormData fdlCloneSubModulesField = new FormData(); + fdlCloneSubModulesField.left = new FormAttachment(0, 25); + fdlCloneSubModulesField.top = new FormAttachment(wBranchField, margin); + wlCloneSubModulesField.setLayoutData(fdlCloneSubModulesField); + + wCloneSubModulesField = new Button(shell, SWT.CHECK); + props.setLook(wCloneSubModulesField); + final FormData fdCloneSubModulesField = new FormData(); + fdCloneSubModulesField.left = new FormAttachment( + wlCloneSubModulesField, margin); + fdCloneSubModulesField.top = new FormAttachment(wBranchField, margin); + fdCloneSubModulesField.right = new FormAttachment(100, 0); + wCloneSubModulesField.setLayoutData(fdCloneSubModulesField); + + // Clone sub modules + final Label wlCloneAllBranchesField = new Label(shell, SWT.RIGHT); + wlCloneAllBranchesField.setText(BaseMessages.getString(PKG, + "Git.CloneAllBranchesField.Label")); + props.setLook(wlCloneAllBranchesField); + final FormData fdlCloneAllBranchesField = new FormData(); + fdlCloneAllBranchesField.left = new FormAttachment(0, 25); + fdlCloneAllBranchesField.top = new FormAttachment( + wCloneSubModulesField, margin); + wlCloneAllBranchesField.setLayoutData(fdlCloneAllBranchesField); + + wCloneAllBranchesField = new Button(shell, SWT.CHECK); + props.setLook(wCloneAllBranchesField); + final FormData fdCloneAllBranchesField = new FormData(); + fdCloneAllBranchesField.left = new FormAttachment( + wlCloneAllBranchesField, margin); + fdCloneAllBranchesField.top = new FormAttachment(wCloneSubModulesField, + margin); + fdCloneAllBranchesField.right = new FormAttachment(100, 0); + wCloneAllBranchesField.setLayoutData(fdCloneAllBranchesField); + + // Some buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + wOK.addListener(SWT.Selection, lsOK); + + Button[] buttons = new Button[] {wOK}; + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + wCancel.addListener(SWT.Selection, lsCancel); + + buttons = new Button[] {wOK, wCancel}; + + BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + + // Add listeners + shell.addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + getData(); + + BaseStepDialog.setSize(shell); + + wOK.setFocus(); + + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return cloneCommand; + + } + + public void dispose() { + props.setScreen(new WindowProperty(shell)); + shell.dispose(); + } + + public void getData() { + if (!Const.isEmpty(this.cloneCommand.getBranchName())) { + wBranchField.setText(this.cloneCommand.getBranchName()); + } + wCloneAllBranchesField.setSelection(this.cloneCommand + .isCloneAllBranches()); + wCloneSubModulesField.setSelection(this.cloneCommand + .isCloneSubModules()); + } + + private void cancel() { + this.cloneCommand = null; + dispose(); + } + + private void ok() { + if (Const.isEmpty(wBranchField.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.Branch.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } + cloneCommand.setBranchName(wBranchField.getText()); + cloneCommand.setCloneAllBranches(wCloneAllBranchesField.getSelection()); + cloneCommand.setCloneSubModules(wCloneSubModulesField.getSelection()); + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CommitGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CommitGitCommandDialog.java new file mode 100644 index 0000000..a858b0a --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/CommitGitCommandDialog.java @@ -0,0 +1,327 @@ +package com.ivyis.di.trans.steps.git.operations.dialog.impl; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.ui.core.PropsUI; +import org.pentaho.di.ui.core.gui.GUIResource; +import org.pentaho.di.ui.core.gui.WindowProperty; +import org.pentaho.di.ui.core.widget.TextVar; +import org.pentaho.di.ui.trans.step.BaseStepDialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.impl.CommitGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; + +/** + * Commit command UI class. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class CommitGitCommandDialog extends Dialog implements + BaseGitCommandDialog { + private static final Class PKG = CommitGitCommandDialog.class; // for i18n + + private Button wAmend, wInsertChangeId, wAll; + private TextVar wAuthorName, wAuthorEmail, wCommitterName, wCommitterEmail, + wCommitMessage; + + private Shell shell; + private boolean modal; + private PropsUI props; + private TransMeta transMeta; + private Button wOK, wCancel; + private Listener lsOK, lsCancel; + private CommitGitCommand commitCommand; + + public Shell getShell() { + return shell; + } + + public CommitGitCommandDialog(Shell parent, TransMeta transMeta, + GitCommand gitCommand) { + super(parent, SWT.NONE); + this.modal = true; + this.transMeta = transMeta; + props = PropsUI.getInstance(); + if (gitCommand != null && gitCommand instanceof CommitGitCommand) { + this.commitCommand = (CommitGitCommand) gitCommand; + } else { + this.commitCommand = new CommitGitCommand(); + } + } + + public GitCommand open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM + | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE) + | SWT.RESIZE | SWT.MIN | SWT.MAX); + props.setLook(shell); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + final int margin = Const.MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, + "Git.CommitCommandDialog.Title")); + shell.setImage(GUIResource.getInstance().getImageSpoon()); + + // Git author name + final Label wlAuthorName = new Label(shell, SWT.RIGHT); + wlAuthorName.setText(BaseMessages + .getString(PKG, "Git.AuthorName.Label")); + props.setLook(wlAuthorName); + final FormData fdlAuthorName = new FormData(); + fdlAuthorName.left = new FormAttachment(0, 25); + fdlAuthorName.top = new FormAttachment(shell, margin); + wlAuthorName.setLayoutData(fdlAuthorName); + + wAuthorName = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wAuthorName); + final FormData fdAuthorName = new FormData(); + fdAuthorName.left = new FormAttachment(wlAuthorName, margin); + fdAuthorName.top = new FormAttachment(shell, margin); + fdAuthorName.right = new FormAttachment(100, 0); + wAuthorName.setLayoutData(fdAuthorName); + + // Git author email + final Label wlAuthorEmail = new Label(shell, SWT.RIGHT); + wlAuthorEmail.setText(BaseMessages.getString(PKG, + "Git.AuthorEmail.Label")); + props.setLook(wlAuthorEmail); + final FormData fdlAuthorEmail = new FormData(); + fdlAuthorEmail.left = new FormAttachment(0, 25); + fdlAuthorEmail.top = new FormAttachment(wAuthorName, margin); + wlAuthorEmail.setLayoutData(fdlAuthorEmail); + + wAuthorEmail = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wAuthorEmail); + final FormData fdAuthorEmail = new FormData(); + fdAuthorEmail.left = new FormAttachment(wlAuthorEmail, margin); + fdAuthorEmail.top = new FormAttachment(wAuthorName, margin); + fdAuthorEmail.right = new FormAttachment(100, 0); + wAuthorEmail.setLayoutData(fdAuthorEmail); + + // Git committer name + final Label wlCommitterName = new Label(shell, SWT.RIGHT); + wlCommitterName.setText(BaseMessages.getString(PKG, + "Git.CommitterName.Label")); + props.setLook(wlCommitterName); + final FormData fdlCommitterName = new FormData(); + fdlCommitterName.left = new FormAttachment(0, 25); + fdlCommitterName.top = new FormAttachment(wAuthorEmail, margin); + wlCommitterName.setLayoutData(fdlCommitterName); + + wCommitterName = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wCommitterName); + final FormData fdCommitterName = new FormData(); + fdCommitterName.left = new FormAttachment(wlCommitterName, margin); + fdCommitterName.top = new FormAttachment(wAuthorEmail, margin); + fdCommitterName.right = new FormAttachment(100, 0); + wCommitterName.setLayoutData(fdCommitterName); + + // Git committer email + final Label wlCommitterEmail = new Label(shell, SWT.RIGHT); + wlCommitterEmail.setText(BaseMessages.getString(PKG, + "Git.CommitterEmail.Label")); + props.setLook(wlCommitterEmail); + final FormData fdlCommitterEmail = new FormData(); + fdlCommitterEmail.left = new FormAttachment(0, 25); + fdlCommitterEmail.top = new FormAttachment(wCommitterName, margin); + wlCommitterEmail.setLayoutData(fdlCommitterEmail); + + wCommitterEmail = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wCommitterEmail); + final FormData fdCommitterEmail = new FormData(); + fdCommitterEmail.left = new FormAttachment(wlCommitterEmail, margin); + fdCommitterEmail.top = new FormAttachment(wCommitterName, margin); + fdCommitterEmail.right = new FormAttachment(100, 0); + wCommitterEmail.setLayoutData(fdCommitterEmail); + + // Git commit message + final Label wlCommitMessage = new Label(shell, SWT.RIGHT); + wlCommitMessage.setText(BaseMessages.getString(PKG, + "Git.CommitMessage.Label")); + props.setLook(wlCommitMessage); + final FormData fdlCommitMessage = new FormData(); + fdlCommitMessage.left = new FormAttachment(0, 25); + fdlCommitMessage.top = new FormAttachment(wCommitterEmail, margin); + wlCommitMessage.setLayoutData(fdlCommitMessage); + + wCommitMessage = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wCommitMessage); + final FormData fdCommitMessage = new FormData(); + fdCommitMessage.left = new FormAttachment(wlCommitMessage, margin); + fdCommitMessage.top = new FormAttachment(wCommitterEmail, margin); + fdCommitMessage.right = new FormAttachment(100, 0); + wCommitMessage.setLayoutData(fdCommitMessage); + + // Git Amend + final Label wlAmend = new Label(shell, SWT.RIGHT); + wlAmend.setText(BaseMessages.getString(PKG, "Git.Amend.Label")); + props.setLook(wlAmend); + final FormData fdlAmend = new FormData(); + fdlAmend.left = new FormAttachment(0, 25); + fdlAmend.top = new FormAttachment(wCommitMessage, margin); + wlAmend.setLayoutData(fdlAmend); + + wAmend = new Button(shell, SWT.CHECK); + props.setLook(wAmend); + final FormData fdAmend = new FormData(); + fdAmend.left = new FormAttachment(wlAmend, margin); + fdAmend.top = new FormAttachment(wCommitMessage, margin); + fdAmend.right = new FormAttachment(100, 0); + wAmend.setLayoutData(fdAmend); + + // Git insert change id + final Label wlInsertChangeId = new Label(shell, SWT.RIGHT); + wlInsertChangeId.setText(BaseMessages.getString(PKG, + "Git.InsertChangeId.Label")); + props.setLook(wlInsertChangeId); + final FormData fdlInsertChangeId = new FormData(); + fdlInsertChangeId.left = new FormAttachment(0, 25); + fdlInsertChangeId.top = new FormAttachment(wAmend, margin); + wlInsertChangeId.setLayoutData(fdlInsertChangeId); + + wInsertChangeId = new Button(shell, SWT.CHECK); + props.setLook(wInsertChangeId); + final FormData fdInsertChangeId = new FormData(); + fdInsertChangeId.left = new FormAttachment(wlInsertChangeId, margin); + fdInsertChangeId.top = new FormAttachment(wAmend, margin); + fdInsertChangeId.right = new FormAttachment(100, 0); + wInsertChangeId.setLayoutData(fdInsertChangeId); + + // Git all + final Label wlAll = new Label(shell, SWT.RIGHT); + wlAll.setText(BaseMessages.getString(PKG, "Git.All.Label")); + props.setLook(wlAll); + final FormData fdlAll = new FormData(); + fdlAll.left = new FormAttachment(0, 25); + fdlAll.top = new FormAttachment(wInsertChangeId, margin); + wlAll.setLayoutData(fdlAll); + + wAll = new Button(shell, SWT.CHECK); + props.setLook(wAll); + final FormData fdAll = new FormData(); + fdAll.left = new FormAttachment(wlAll, margin); + fdAll.top = new FormAttachment(wInsertChangeId, margin); + fdAll.right = new FormAttachment(100, 0); + wAll.setLayoutData(fdAll); + + // Some buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + wOK.addListener(SWT.Selection, lsOK); + + Button[] buttons = new Button[] {wOK}; + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + wCancel.addListener(SWT.Selection, lsCancel); + + buttons = new Button[] {wOK, wCancel}; + + BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + + // Add listeners + shell.addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + getData(); + + BaseStepDialog.setSize(shell); + + wOK.setFocus(); + + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return this.commitCommand; + + } + + public void dispose() { + props.setScreen(new WindowProperty(shell)); + shell.dispose(); + } + + public void getData() { + if (!Const.isEmpty(this.commitCommand.getAuthorEmail())) { + wAuthorEmail.setText(this.commitCommand.getAuthorEmail()); + } + if (!Const.isEmpty(this.commitCommand.getAuthorName())) { + wAuthorName.setText(this.commitCommand.getAuthorName()); + } + if (!Const.isEmpty(this.commitCommand.getCommitterEmail())) { + wCommitterEmail.setText(this.commitCommand.getCommitterEmail()); + } + if (!Const.isEmpty(this.commitCommand.getCommitterName())) { + wCommitterName.setText(this.commitCommand.getCommitterName()); + } + if (!Const.isEmpty(this.commitCommand.getCommitMessage())) { + wCommitMessage.setText(this.commitCommand.getCommitMessage()); + } + wAll.setSelection(this.commitCommand.isAll()); + wAmend.setSelection(this.commitCommand.isAmend()); + wInsertChangeId.setSelection(this.commitCommand.isInsertChangeId()); + } + + private void cancel() { + this.commitCommand = null; + dispose(); + } + + private void ok() { + this.commitCommand.setAuthorEmail(wAuthorEmail.getText()); + this.commitCommand.setAuthorName(wAuthorName.getText()); + this.commitCommand.setCommitterEmail(wCommitterEmail.getText()); + this.commitCommand.setCommitterName(wCommitterName.getText()); + this.commitCommand.setCommitMessage(wCommitMessage.getText()); + this.commitCommand.setAll(wAll.getSelection()); + this.commitCommand.setAmend(wAmend.getSelection()); + this.commitCommand.setInsertChangeId(wInsertChangeId.getSelection()); + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/InitGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/InitGitCommandDialog.java new file mode 100644 index 0000000..e71a55b --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/InitGitCommandDialog.java @@ -0,0 +1,168 @@ +package com.ivyis.di.trans.steps.git.operations.dialog.impl; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.ui.core.PropsUI; +import org.pentaho.di.ui.core.gui.GUIResource; +import org.pentaho.di.ui.core.gui.WindowProperty; +import org.pentaho.di.ui.trans.step.BaseStepDialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.impl.InitGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; + +/** + * Init command UI class. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class InitGitCommandDialog extends Dialog implements + BaseGitCommandDialog { + private static final Class PKG = InitGitCommandDialog.class; // for i18n + + private Button wBare; + + private Shell shell; + private boolean modal; + private PropsUI props; + private Button wOK, wCancel; + private Listener lsOK, lsCancel; + private InitGitCommand initCommand; + + public Shell getShell() { + return shell; + } + + public InitGitCommandDialog(Shell parent, TransMeta transMeta, + GitCommand gitCommand) { + super(parent, SWT.NONE); + this.modal = true; + props = PropsUI.getInstance(); + if (gitCommand != null && gitCommand instanceof InitGitCommand) { + this.initCommand = (InitGitCommand) gitCommand; + } else { + this.initCommand = new InitGitCommand(); + } + } + + public GitCommand open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM + | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE) + | SWT.RESIZE | SWT.MIN | SWT.MAX); + props.setLook(shell); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + final int margin = Const.MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages + .getString(PKG, "Git.InitCommandDialog.Title")); + shell.setImage(GUIResource.getInstance().getImageSpoon()); + + // Bare + final Label wlBare = new Label(shell, SWT.RIGHT); + wlBare.setText(BaseMessages.getString(PKG, "Git.Bare.Label")); + props.setLook(wlBare); + final FormData fdlBare = new FormData(); + fdlBare.left = new FormAttachment(0, 25); + fdlBare.top = new FormAttachment(shell, margin); + wlBare.setLayoutData(fdlBare); + + wBare = new Button(shell, SWT.CHECK); + props.setLook(wBare); + final FormData fdBare = new FormData(); + fdBare.left = new FormAttachment(wlBare, margin); + fdBare.top = new FormAttachment(shell, margin); + fdBare.right = new FormAttachment(100, 0); + wBare.setLayoutData(fdBare); + + // Some buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + wOK.addListener(SWT.Selection, lsOK); + + Button[] buttons = new Button[] {wOK}; + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + wCancel.addListener(SWT.Selection, lsCancel); + + buttons = new Button[] {wOK, wCancel}; + + BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + + // Add listeners + shell.addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + getData(); + + BaseStepDialog.setSize(shell); + + wOK.setFocus(); + + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return this.initCommand; + + } + + public void dispose() { + props.setScreen(new WindowProperty(shell)); + shell.dispose(); + } + + public void getData() { + wBare.setSelection(this.initCommand.isBare()); + } + + private void cancel() { + this.initCommand = null; + dispose(); + } + + private void ok() { + this.initCommand.setBare(wBare.getSelection()); + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/PullGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/PullGitCommandDialog.java new file mode 100644 index 0000000..7ae1f43 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/PullGitCommandDialog.java @@ -0,0 +1,168 @@ +package com.ivyis.di.trans.steps.git.operations.dialog.impl; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.ui.core.PropsUI; +import org.pentaho.di.ui.core.gui.GUIResource; +import org.pentaho.di.ui.core.gui.WindowProperty; +import org.pentaho.di.ui.trans.step.BaseStepDialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.impl.PullGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; + +/** + * Pull command UI class. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class PullGitCommandDialog extends Dialog implements + BaseGitCommandDialog { + private static final Class PKG = PullGitCommandDialog.class; // for i18n + + private Button wRebase; + + private Shell shell; + private boolean modal; + private PropsUI props; + private Button wOK, wCancel; + private Listener lsOK, lsCancel; + private PullGitCommand pullCommand; + + public Shell getShell() { + return shell; + } + + public PullGitCommandDialog(Shell parent, TransMeta transMeta, + GitCommand gitCommand) { + super(parent, SWT.NONE); + this.modal = true; + props = PropsUI.getInstance(); + if (gitCommand != null && gitCommand instanceof PullGitCommand) { + this.pullCommand = (PullGitCommand) gitCommand; + } else { + this.pullCommand = new PullGitCommand(); + } + } + + public GitCommand open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM + | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE) + | SWT.RESIZE | SWT.MIN | SWT.MAX); + props.setLook(shell); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + final int margin = Const.MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages + .getString(PKG, "Git.PullCommandDialog.Title")); + shell.setImage(GUIResource.getInstance().getImageSpoon()); + + // File pattern + final Label wlRebase = new Label(shell, SWT.RIGHT); + wlRebase.setText(BaseMessages.getString(PKG, "Git.Rebase.Label")); + props.setLook(wlRebase); + final FormData fdlRebase = new FormData(); + fdlRebase.left = new FormAttachment(0, 25); + fdlRebase.top = new FormAttachment(shell, margin); + wlRebase.setLayoutData(fdlRebase); + + wRebase = new Button(shell, SWT.CHECK); + props.setLook(wRebase); + final FormData fdRebase = new FormData(); + fdRebase.left = new FormAttachment(wlRebase, margin); + fdRebase.top = new FormAttachment(shell, margin); + fdRebase.right = new FormAttachment(100, 0); + wRebase.setLayoutData(fdRebase); + + // Some buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + wOK.addListener(SWT.Selection, lsOK); + + Button[] buttons = new Button[] {wOK}; + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + wCancel.addListener(SWT.Selection, lsCancel); + + buttons = new Button[] {wOK, wCancel}; + + BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + + // Add listeners + shell.addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + getData(); + + BaseStepDialog.setSize(shell); + + wOK.setFocus(); + + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return this.pullCommand; + + } + + public void dispose() { + props.setScreen(new WindowProperty(shell)); + shell.dispose(); + } + + public void getData() { + wRebase.setSelection(this.pullCommand.isRebase()); + } + + private void cancel() { + this.pullCommand = null; + dispose(); + } + + private void ok() { + this.pullCommand.setRebase(wRebase.getSelection()); + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/PushGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/PushGitCommandDialog.java new file mode 100644 index 0000000..0a4efb3 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/PushGitCommandDialog.java @@ -0,0 +1,318 @@ +package com.ivyis.di.trans.steps.git.operations.dialog.impl; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.ui.core.PropsUI; +import org.pentaho.di.ui.core.gui.GUIResource; +import org.pentaho.di.ui.core.gui.WindowProperty; +import org.pentaho.di.ui.core.widget.TextVar; +import org.pentaho.di.ui.trans.step.BaseStepDialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.impl.PushGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; + +/** + * Push command UI class. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class PushGitCommandDialog extends Dialog implements + BaseGitCommandDialog { + private static final Class PKG = PushGitCommandDialog.class; // for i18n + + private Button wDryRun, wForce, wThin, wPushAllBranches, wPushAllTags; + private TextVar wReferenceToPush, wRemote, wReceivePack; + + private Shell shell; + private boolean modal; + private PropsUI props; + private TransMeta transMeta; + private Button wOK, wCancel; + private Listener lsOK, lsCancel; + private PushGitCommand pushCommand; + + public Shell getShell() { + return shell; + } + + public PushGitCommandDialog(Shell parent, TransMeta transMeta, + GitCommand gitCommand) { + super(parent, SWT.NONE); + this.modal = true; + this.transMeta = transMeta; + props = PropsUI.getInstance(); + if (gitCommand != null && gitCommand instanceof PushGitCommand) { + this.pushCommand = (PushGitCommand) gitCommand; + } else { + this.pushCommand = new PushGitCommand(); + } + } + + public GitCommand open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM + | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE) + | SWT.RESIZE | SWT.MIN | SWT.MAX); + props.setLook(shell); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + final int margin = Const.MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages + .getString(PKG, "Git.PushCommandDialog.Title")); + shell.setImage(GUIResource.getInstance().getImageSpoon()); + + // Reference to push + final Label wlReferenceToPush = new Label(shell, SWT.RIGHT); + wlReferenceToPush.setText(BaseMessages.getString(PKG, + "Git.ReferenceToPush.Label")); + props.setLook(wlReferenceToPush); + final FormData fdlReferenceToPush = new FormData(); + fdlReferenceToPush.left = new FormAttachment(0, 25); + fdlReferenceToPush.top = new FormAttachment(shell, margin); + wlReferenceToPush.setLayoutData(fdlReferenceToPush); + + wReferenceToPush = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wReferenceToPush); + final FormData fdReferenceToPush = new FormData(); + fdReferenceToPush.left = new FormAttachment(wlReferenceToPush, margin); + fdReferenceToPush.top = new FormAttachment(shell, margin); + fdReferenceToPush.right = new FormAttachment(100, 0); + wReferenceToPush.setLayoutData(fdReferenceToPush); + + // Remote + final Label wlRemote = new Label(shell, SWT.RIGHT); + wlRemote.setText(BaseMessages.getString(PKG, "Git.Remote.Label")); + props.setLook(wlRemote); + final FormData fdlRemote = new FormData(); + fdlRemote.left = new FormAttachment(0, 25); + fdlRemote.top = new FormAttachment(wReferenceToPush, margin); + wlRemote.setLayoutData(fdlRemote); + + wRemote = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wRemote); + final FormData fdRemote = new FormData(); + fdRemote.left = new FormAttachment(wlRemote, margin); + fdRemote.top = new FormAttachment(wReferenceToPush, margin); + fdRemote.right = new FormAttachment(100, 0); + wRemote.setLayoutData(fdRemote); + + // Receive Pack + final Label wlReceivePack = new Label(shell, SWT.RIGHT); + wlReceivePack.setText(BaseMessages.getString(PKG, + "Git.ReceivePack.Label")); + props.setLook(wlReceivePack); + final FormData fdlReceivePack = new FormData(); + fdlReceivePack.left = new FormAttachment(0, 25); + fdlReceivePack.top = new FormAttachment(wRemote, margin); + wlReceivePack.setLayoutData(fdlReceivePack); + + wReceivePack = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wReceivePack); + final FormData fdReceivePack = new FormData(); + fdReceivePack.left = new FormAttachment(wlReceivePack, margin); + fdReceivePack.top = new FormAttachment(wRemote, margin); + fdReceivePack.right = new FormAttachment(100, 0); + wReceivePack.setLayoutData(fdReceivePack); + + // Dry Run + final Label wlDryRun = new Label(shell, SWT.RIGHT); + wlDryRun.setText(BaseMessages.getString(PKG, "Git.DryRun.Label")); + props.setLook(wlDryRun); + final FormData fdlDryRun = new FormData(); + fdlDryRun.left = new FormAttachment(0, 25); + fdlDryRun.top = new FormAttachment(wReceivePack, margin); + wlDryRun.setLayoutData(fdlDryRun); + + wDryRun = new Button(shell, SWT.CHECK); + props.setLook(wDryRun); + final FormData fdDryRun = new FormData(); + fdDryRun.left = new FormAttachment(wlDryRun, margin); + fdDryRun.top = new FormAttachment(wReceivePack, margin); + fdDryRun.right = new FormAttachment(100, 0); + wDryRun.setLayoutData(fdDryRun); + + // Force + final Label wlForce = new Label(shell, SWT.RIGHT); + wlForce.setText(BaseMessages.getString(PKG, "Git.Force.Label")); + props.setLook(wlForce); + final FormData fdlForce = new FormData(); + fdlForce.left = new FormAttachment(0, 25); + fdlForce.top = new FormAttachment(wDryRun, margin); + wlForce.setLayoutData(fdlForce); + + wForce = new Button(shell, SWT.CHECK); + props.setLook(wForce); + final FormData fdForce = new FormData(); + fdForce.left = new FormAttachment(wlForce, margin); + fdForce.top = new FormAttachment(wDryRun, margin); + fdForce.right = new FormAttachment(100, 0); + wForce.setLayoutData(fdForce); + + // Thin + final Label wlThin = new Label(shell, SWT.RIGHT); + wlThin.setText(BaseMessages.getString(PKG, "Git.Thin.Label")); + props.setLook(wlThin); + final FormData fdlThin = new FormData(); + fdlThin.left = new FormAttachment(0, 25); + fdlThin.top = new FormAttachment(wForce, margin); + wlThin.setLayoutData(fdlThin); + + wThin = new Button(shell, SWT.CHECK); + props.setLook(wThin); + final FormData fdThin = new FormData(); + fdThin.left = new FormAttachment(wlThin, margin); + fdThin.top = new FormAttachment(wForce, margin); + fdThin.right = new FormAttachment(100, 0); + wThin.setLayoutData(fdThin); + + // Push all branches + final Label wlPushAllBranches = new Label(shell, SWT.RIGHT); + wlPushAllBranches.setText(BaseMessages.getString(PKG, + "Git.PushAllBranches.Label")); + props.setLook(wlPushAllBranches); + final FormData fdlPushAllBranches = new FormData(); + fdlPushAllBranches.left = new FormAttachment(0, 25); + fdlPushAllBranches.top = new FormAttachment(wThin, margin); + wlPushAllBranches.setLayoutData(fdlPushAllBranches); + + wPushAllBranches = new Button(shell, SWT.CHECK); + props.setLook(wPushAllBranches); + final FormData fdPushAllBranches = new FormData(); + fdPushAllBranches.left = new FormAttachment(wlPushAllBranches, margin); + fdPushAllBranches.top = new FormAttachment(wThin, margin); + fdPushAllBranches.right = new FormAttachment(100, 0); + wPushAllBranches.setLayoutData(fdPushAllBranches); + + // Push All Tags + final Label wlPushAllTags = new Label(shell, SWT.RIGHT); + wlPushAllTags.setText(BaseMessages.getString(PKG, + "Git.PushAllTags.Label")); + props.setLook(wlPushAllTags); + final FormData fdlPushAllTags = new FormData(); + fdlPushAllTags.left = new FormAttachment(0, 25); + fdlPushAllTags.top = new FormAttachment(wPushAllBranches, margin); + wlPushAllTags.setLayoutData(fdlPushAllTags); + + wPushAllTags = new Button(shell, SWT.CHECK); + props.setLook(wPushAllTags); + final FormData fdPushAllTags = new FormData(); + fdPushAllTags.left = new FormAttachment(wlPushAllTags, margin); + fdPushAllTags.top = new FormAttachment(wPushAllBranches, margin); + fdPushAllTags.right = new FormAttachment(100, 0); + wPushAllTags.setLayoutData(fdPushAllTags); + + // Some buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + wOK.addListener(SWT.Selection, lsOK); + + Button[] buttons = new Button[] {wOK}; + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + wCancel.addListener(SWT.Selection, lsCancel); + + buttons = new Button[] {wOK, wCancel}; + + BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + + // Add listeners + shell.addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + getData(); + + BaseStepDialog.setSize(shell); + + wOK.setFocus(); + + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return this.pushCommand; + + } + + public void dispose() { + props.setScreen(new WindowProperty(shell)); + shell.dispose(); + } + + public void getData() { + wDryRun.setSelection(this.pushCommand.isDryRun()); + wForce.setSelection(this.pushCommand.isForce()); + wPushAllBranches.setSelection(this.pushCommand.isPushAllBranches()); + wPushAllTags.setSelection(this.pushCommand.isPushAllTags()); + wThin.setSelection(this.pushCommand.isThin()); + if (!Const.isEmpty(this.pushCommand.getReceivePack())) { + wReceivePack.setText(this.pushCommand.getReceivePack()); + } + if (!Const.isEmpty(this.pushCommand.getReferenceToPush())) { + wReferenceToPush.setText(this.pushCommand.getReferenceToPush()); + } + if (!Const.isEmpty(this.pushCommand.getRemote())) { + wRemote.setText(this.pushCommand.getRemote()); + } + } + + private void cancel() { + this.pushCommand = null; + dispose(); + } + + private void ok() { + this.pushCommand.setDryRun(wDryRun.getSelection()); + this.pushCommand.setForce(wForce.getSelection()); + this.pushCommand.setPushAllBranches(wPushAllBranches.getSelection()); + this.pushCommand.setPushAllTags(wPushAllTags.getSelection()); + this.pushCommand.setThin(wThin.getSelection()); + this.pushCommand.setReceivePack(wReceivePack.getText()); + this.pushCommand.setReferenceToPush(wReferenceToPush.getText()); + this.pushCommand.setRemote(wRemote.getText()); + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/TagGitCommandDialog.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/TagGitCommandDialog.java new file mode 100644 index 0000000..2a9a439 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/TagGitCommandDialog.java @@ -0,0 +1,263 @@ +package com.ivyis.di.trans.steps.git.operations.dialog.impl; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellAdapter; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.pentaho.di.core.Const; +import org.pentaho.di.i18n.BaseMessages; +import org.pentaho.di.trans.TransMeta; +import org.pentaho.di.ui.core.PropsUI; +import org.pentaho.di.ui.core.gui.GUIResource; +import org.pentaho.di.ui.core.gui.WindowProperty; +import org.pentaho.di.ui.core.widget.TextVar; +import org.pentaho.di.ui.trans.step.BaseStepDialog; + +import com.ivyis.di.trans.steps.git.command.GitCommand; +import com.ivyis.di.trans.steps.git.command.impl.TagGitCommand; +import com.ivyis.di.trans.steps.git.dialog.BaseGitCommandDialog; + +/** + * Tag command UI class. + * + * @author Joel Latino + * @since 1.0.0 + */ +public class TagGitCommandDialog extends Dialog implements BaseGitCommandDialog { + private static final Class PKG = TagGitCommandDialog.class; // for i18n + + private Button wAnnotated, wForceUpdate, wSigned; + private TextVar wName, wMessage; + + private Shell shell; + private boolean modal; + private PropsUI props; + private TransMeta transMeta; + private Button wOK, wCancel; + private Listener lsOK, lsCancel; + private TagGitCommand tagCommand; + + public Shell getShell() { + return shell; + } + + public TagGitCommandDialog(Shell parent, TransMeta transMeta, + GitCommand gitCommand) { + super(parent, SWT.NONE); + this.modal = true; + this.transMeta = transMeta; + props = PropsUI.getInstance(); + if (gitCommand != null && gitCommand instanceof TagGitCommand) { + this.tagCommand = (TagGitCommand) gitCommand; + } else { + this.tagCommand = new TagGitCommand(); + } + } + + public GitCommand open() { + final Shell parent = getParent(); + final Display display = parent.getDisplay(); + + shell = new Shell(parent, SWT.DIALOG_TRIM + | (modal ? SWT.APPLICATION_MODAL | SWT.SHEET : SWT.NONE) + | SWT.RESIZE | SWT.MIN | SWT.MAX); + props.setLook(shell); + + final FormLayout formLayout = new FormLayout(); + formLayout.marginWidth = Const.FORM_MARGIN; + formLayout.marginHeight = Const.FORM_MARGIN; + + final int margin = Const.MARGIN; + + shell.setLayout(formLayout); + shell.setText(BaseMessages.getString(PKG, "Git.TagCommandDialog.Title")); + shell.setImage(GUIResource.getInstance().getImageSpoon()); + + // Tag name + final Label wlName = new Label(shell, SWT.RIGHT); + wlName.setText(BaseMessages.getString(PKG, "Git.Name.Label")); + props.setLook(wlName); + final FormData fdlName = new FormData(); + fdlName.left = new FormAttachment(0, 25); + fdlName.top = new FormAttachment(shell, margin); + wlName.setLayoutData(fdlName); + + wName = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wName); + final FormData fdName = new FormData(); + fdName.left = new FormAttachment(wlName, margin); + fdName.top = new FormAttachment(shell, margin); + fdName.right = new FormAttachment(100, 0); + wName.setLayoutData(fdName); + + // Tag message + final Label wlMessage = new Label(shell, SWT.RIGHT); + wlMessage.setText(BaseMessages.getString(PKG, "Git.Message.Label")); + props.setLook(wlMessage); + final FormData fdlMessage = new FormData(); + fdlMessage.left = new FormAttachment(0, 25); + fdlMessage.top = new FormAttachment(wName, margin); + wlMessage.setLayoutData(fdlMessage); + + wMessage = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT + | SWT.BORDER); + props.setLook(wMessage); + final FormData fdMessage = new FormData(); + fdMessage.left = new FormAttachment(wlMessage, margin); + fdMessage.top = new FormAttachment(wName, margin); + fdMessage.right = new FormAttachment(100, 0); + wMessage.setLayoutData(fdMessage); + + // Annotated + final Label wlAnnotated = new Label(shell, SWT.RIGHT); + wlAnnotated.setText(BaseMessages.getString(PKG, "Git.Annotated.Label")); + props.setLook(wlAnnotated); + final FormData fdlAnnotated = new FormData(); + fdlAnnotated.left = new FormAttachment(0, 25); + fdlAnnotated.top = new FormAttachment(wMessage, margin); + wlAnnotated.setLayoutData(fdlAnnotated); + + wAnnotated = new Button(shell, SWT.CHECK); + props.setLook(wAnnotated); + final FormData fdAnnotated = new FormData(); + fdAnnotated.left = new FormAttachment(wlAnnotated, margin); + fdAnnotated.top = new FormAttachment(wMessage, margin); + fdAnnotated.right = new FormAttachment(100, 0); + wAnnotated.setLayoutData(fdAnnotated); + + // Force update + final Label wlForceUpdate = new Label(shell, SWT.RIGHT); + wlForceUpdate.setText(BaseMessages.getString(PKG, + "Git.ForceUpdate.Label")); + props.setLook(wlForceUpdate); + final FormData fdlForceUpdate = new FormData(); + fdlForceUpdate.left = new FormAttachment(0, 25); + fdlForceUpdate.top = new FormAttachment(wAnnotated, margin); + wlForceUpdate.setLayoutData(fdlForceUpdate); + + wForceUpdate = new Button(shell, SWT.CHECK); + props.setLook(wForceUpdate); + final FormData fdForceUpdate = new FormData(); + fdForceUpdate.left = new FormAttachment(wlForceUpdate, margin); + fdForceUpdate.top = new FormAttachment(wAnnotated, margin); + fdForceUpdate.right = new FormAttachment(100, 0); + wForceUpdate.setLayoutData(fdForceUpdate); + + // Signed + final Label wlSigned = new Label(shell, SWT.RIGHT); + wlSigned.setText(BaseMessages.getString(PKG, "Git.Signed.Label")); + props.setLook(wlSigned); + final FormData fdlSigned = new FormData(); + fdlSigned.left = new FormAttachment(0, 25); + fdlSigned.top = new FormAttachment(wForceUpdate, margin); + wlSigned.setLayoutData(fdlSigned); + + wSigned = new Button(shell, SWT.CHECK); + props.setLook(wSigned); + final FormData fdSigned = new FormData(); + fdSigned.left = new FormAttachment(wlSigned, margin); + fdSigned.top = new FormAttachment(wForceUpdate, margin); + fdSigned.right = new FormAttachment(100, 0); + wSigned.setLayoutData(fdSigned); + + // Some buttons + wOK = new Button(shell, SWT.PUSH); + wOK.setText(BaseMessages.getString(PKG, "System.Button.OK")); + lsOK = new Listener() { + public void handleEvent(Event e) { + ok(); + } + }; + wOK.addListener(SWT.Selection, lsOK); + + Button[] buttons = new Button[] {wOK}; + + wCancel = new Button(shell, SWT.PUSH); + wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel")); + lsCancel = new Listener() { + public void handleEvent(Event e) { + cancel(); + } + }; + wCancel.addListener(SWT.Selection, lsCancel); + + buttons = new Button[] {wOK, wCancel}; + + BaseStepDialog.positionBottomButtons(shell, buttons, margin, null); + + // Add listeners + shell.addShellListener(new ShellAdapter() { + public void shellClosed(ShellEvent e) { + cancel(); + } + }); + + getData(); + + BaseStepDialog.setSize(shell); + + wOK.setFocus(); + + shell.open(); + + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + return this.tagCommand; + + } + + public void dispose() { + props.setScreen(new WindowProperty(shell)); + shell.dispose(); + } + + public void getData() { + wAnnotated.setSelection(this.tagCommand.isAnnotated()); + wForceUpdate.setSelection(this.tagCommand.isForceUpdate()); + wSigned.setSelection(this.tagCommand.isSigned()); + if (!Const.isEmpty(this.tagCommand.getMessage())) { + wMessage.setText(this.tagCommand.getMessage()); + } + + if (!Const.isEmpty(this.tagCommand.getName())) { + wName.setText(this.tagCommand.getName()); + } + } + + private void cancel() { + this.tagCommand = null; + dispose(); + } + + private void ok() { + if (Const.isEmpty(wName.getText())) { + final MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); + mb.setMessage(BaseMessages.getString(PKG, + "Git.TagName.Mandatory.DialogMessage")); + mb.setText(BaseMessages.getString(PKG, "System.Dialog.Error.Title")); + mb.open(); + return; + } + this.tagCommand.setAnnotated(wAnnotated.getSelection()); + this.tagCommand.setForceUpdate(wForceUpdate.getSelection()); + this.tagCommand.setSigned(wSigned.getSelection()); + this.tagCommand.setMessage(wMessage.getText()); + this.tagCommand.setName(wName.getText()); + dispose(); + } +} diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/package-info.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/package-info.java new file mode 100644 index 0000000..10324ce --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/dialog/impl/package-info.java @@ -0,0 +1,8 @@ +/** + * Package with UI classes of Git operations. + * + * @author Joel Latino + * @since 1.0.0 + */ +package com.ivyis.di.trans.steps.git.operations.dialog.impl; + diff --git a/src/main/java/com/ivyis/di/trans/steps/git/operations/package-info.java b/src/main/java/com/ivyis/di/trans/steps/git/operations/package-info.java new file mode 100644 index 0000000..82c3445 --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/operations/package-info.java @@ -0,0 +1,8 @@ +/** + * Package with classes of Git operations step engine. + * + * @author Joel Latino + * @since 1.0.0 + */ +package com.ivyis.di.trans.steps.git.operations; + diff --git a/src/main/java/com/ivyis/di/trans/steps/git/package-info.java b/src/main/java/com/ivyis/di/trans/steps/git/package-info.java new file mode 100644 index 0000000..c30937d --- /dev/null +++ b/src/main/java/com/ivyis/di/trans/steps/git/package-info.java @@ -0,0 +1,8 @@ +/** + * Package with generic classes of Git steps. + * + * @author Joel Latino + * @since 1.0.0 + */ +package com.ivyis.di.trans.steps.git; + diff --git a/src/main/resources/com/ivyis/di/trans/steps/git/command/impl/messages/messages_en_US.properties b/src/main/resources/com/ivyis/di/trans/steps/git/command/impl/messages/messages_en_US.properties new file mode 100644 index 0000000..ca54c60 --- /dev/null +++ b/src/main/resources/com/ivyis/di/trans/steps/git/command/impl/messages/messages_en_US.properties @@ -0,0 +1,140 @@ +GitInfo.Step.Name=Git Info Step +GitInfo.Step.Description=Execute git info commands +GitInfo.Step.Category=Repository + + +Git.Shell.Title=Git Step +ExportCmdLine.CommandLine.Title=Ivy Information Systems Ltd + +# Fields +Git.init.Label=Init +Git.add.Label=Add +Git.clone.Label=Clone +Git.commit.Label=Commit +Git.status.Label=Status +Git.pull.Label=Pull +Git.push.Label=Push +Git.tag.Label=Tag +Git.checkout.Label=Checkout +Git.listBranchs.Label=List Branchs +Git.listTags.Label=List Tags +Git.currentBranch.Label=Current Branch +Git.log.Label=Log +Git.UserName.Label=Username +Git.PasswordField.Label=Password +Git.PasswordField.Tooltip=Provide a Git repository password +Git.gBasicPropertiesFields.Label=Basic Git Properties +Git.RadioCloneOperation.Label=Clone Repository +Git.RepoUrlField.Label=Git Repository URL +Git.RepoFolderPathField.Label=Git clone folder path +Git.DefineCommands.Label=Define Git Commands +Git.ColumnInfo.CommandType.Label=Command Type +Git.ColumnInfo.Description.Label=Command Description + +Git.GitInfoCommands.Label=Git get data commands +Git.OutputFieldNames.Label=Output Field Names +Git.IdField.Label=Field Id +Git.NameField.Label=Field name +Git.FullMessageField.Label=Field full message +Git.ShortMessageField.Label=Field short message +Git.AuthorCreationDateField.Label=Field author creation date +Git.AuthorNameField.Label=Field author name +Git.AuthorEmailField.Label=Field author email +Git.CommitterCreationDateField.Label=Field committer creation date +Git.CommitterNameField.Label=Field committer name +Git.CommitterEmailField.Label=Field committer email + +Git.MainOptionTab.CTabItem.Title=Main +Git.ConfigFields.Label=Configuration Fields +Git.ColumnInfo.FieldName=Field Name +Git.ColumnInfo.FieldValue=Field Value +Git.DefineFields.Button=Define Fields + +#List Branchs Command +Git.ListBranchsCommandDialog.Title=Git List Branchs Command +Git.ListMode.Label=List mode + +#Log Command +Git.LogCommandDialog.Title= Git Log Command +Git.Skip.Label=Skip +Git.Path.Label=Path +Git.MaxCount.Label=Max Count + +# Add Git Command +Git.AddCommandDialog.Title=Git Add Command +Git.FilePattern.Label=File pattern +Git.Update.Label=Update + +# Checkout Git Command +Git.CheckoutCommandDialog.Title=Git Checkout Command +Git.Path.Label=Path +Git.Name.Label=Name +Git.StartPoint.Label=Start Point +Git.AllPaths.Label=All Paths +Git.Force.Label=Force + +# Clone Git Command +Git.CloneCommandDialog.Title=Git Clone Command +Git.BranchField.Label=Branch +Git.CloneSubModulesField.Label=Clone sub-modules +Git.CloneAllBranchesField.Label=Clone all branches + +# Commit Git Command +Git.CommitCommandDialog.Title=Git Commit Command +Git.AuthorName.Label=Author Name +Git.AuthorEmail.Label=Author Email +Git.CommitterName.Label=Committer Name +Git.CommitterEmail.Label=Committer Email +Git.CommitMessage.Label=Commit Message +Git.Amend.Label=Amend +Git.InsertChangeId.Label=Insert Change Id +Git.All.Label=All + +# Init Git Command +Git.InitCommandDialog.Title=Git Init Command +Git.Bare.Label=Bare + +# Pull Git Command +Git.PullCommandDialog.Title=Git Pull Command +Git.Rebase.Label=Rebase + + +# Push Git Command +Git.PushCommandDialog.Title=Git Push Command +Git.ReferenceToPush.Label=Reference to push +Git.Remote.Label=Remote +Git.ReceivePack.Label=Receive Pack +Git.DryRun.Label=Dry Run +Git.Force.Label=Force +Git.Thin.Label=Thin +Git.PushAllBranches.Label=Push all branches +Git.PushAllTags.Label=Push all tags + +# Tag Git Command +Git.TagCommandDialog.Title=Git Tag Command +Git.Name.Label=Name +Git.Message.Label=Message +Git.Annotated.Label=Annotated +Git.ForceUpdate.Label=Force update +Git.Signed.Label=Signed + +# Messages errors +Git.MaxCount.NumberParseError.DialogMessage=Please, provide an integer number for Max Count field. +Git.Skip.NumberParseError.DialogMessage=Please, provide an integer number for Skip field. +Git.ListMode.Mandatory.DialogMessage=Please, provide a value for List Mode field. + +#Messages +Git.Info.Nothing.Conf.DialogMessage=This Git command doesn't have nothing to configure. +System.Dialog.Info.Title=Information +System.Dialog.Warning.Title=Warning +Git.Command.Not.Found.DialogMessage=Git command not found. +Git.Username.Password.Mandatory.DialogMessage=Username and password wasn't set. However is not mandatory. +Git.RepoFolder.Mandatory.DialogMessage=Please, provide a valid Git clone folder path. +Git.RepoUrl.Mandatory.DialogMessage=Please, provide a valid Git repo url. +Git.ConfigFields.Mandatory.DialogMessage=Please, provide names for all output fields. + +#Errors +Git.Exception.UnexpectedErrorInReadingStepInfo=Unexpected error on reading step info +Git.Exception.UnableToSaveStepInfoToRepository=Unable to save info to repository +Git.GitCommandNotFount.DialogTitle=Git command not found +Git.GitCommandNotFount.DialogMessage=Git command not found diff --git a/src/main/resources/com/ivyis/di/trans/steps/git/info/GitInfoStep.png b/src/main/resources/com/ivyis/di/trans/steps/git/info/GitInfoStep.png new file mode 100644 index 0000000000000000000000000000000000000000..7bedb16985fcfaf147190fce5368e2b2de12a488 GIT binary patch literal 1589 zcmV-52Fm$~P)}WuhSNgr467|0SP(~ED{05 z7$DWW#8?f{h)PhlL}d{ntWrfFEiOQt3;q^1zP%mK-<}_ zANrHgyYBFeC3bDFh^?jI@TjvkUkK5{MH9|BNp z`(HZUZ8~B#0&{YZ@<@S<7rq6vH4H$02%UT@fUp zDH%wSP}&*;K%MR%C!h>aHNy-?`HCI?c>!gbVG1B*>3(Okf~EUk1Xci?)BUMZ%3L52 z>tR`J%=%jo{MzYWv-w}K1KunFLW1+9K3P7yn^XWa!)ydp0pDB_aN@L^v;n=S zy_gd}52cUi%fn^cae9&yC(6?OF90tCZaYHzd5ST74#_AfI4a=TD1IPCGtA2g9ay^m zIXhiZUX^B;*_M9$5)kuZY+4|S(=Go}1iT7dd^e&|b@ULAy|JF0(#6;XYkP!NjtYPe zfm443%o_&XXE&n)%2Y(vk%RJ+C3EBEKmnS2rQ(ip3~ekSBl9doR7mkamvqR=rflOy zuGo;rzN?TW1*5rW)sy6cU;swscjcj3`D|Erh-;z)+qcSTU63>S_$2?8M1m$t0vdsZ znqe+#&w&z;DdD*NxzO&&jv=sgzZ*$CkShgy1Z3Hw7d69trCkJ;?sou9brF1)ZkSzw z5q6N56CsIqq6!3C$sPc?5BLE@R@2GaB2n!5aXF6jF%sSf#z-k+k<4#>gfzgJAVm%k z`Ad(U-2HY#a+KMkDvD;9wZP0c)=2;*r;aaJKD~zL$L(R8Cl$ceCW)G1t^l5i;hzB} z3Rq2Ds0m*fp2*wH%G%mSfb!Kv^0SporD!uuU?m_W+=FCn`MI+*(yC8#?=(PBz~!XI z-H*(i3vAueBkpZ{8dwwk|H$KI!r)z?I>40#niqO>g_K^DeU#R=6E(wJ8>%3+5B)Ml@2~vVX1+Uk^l;wAk*>@=W_jwT=y>*op zJLQ^!(KK8NljMTN1}Iowd~H{_C_hh5_8}|x?vmnajqR(hMSnHJ3|#kl5|8S1zsue; zi(@)JWdAR_Rv@ASC-xw@8K{$jhk$tkym3@#0;@E`3|k`32{KX?`OzZSbyDKVexvT8kiV?T>{DkjC||2V?6n=g)gm@S4FVs>JUX5edHoK>>XMr93xJ{JCijxA?;NH0VEC;L;Qj3OJpRq(ZU_ zydLnTfwL2zZmuEV?AP&0XzBi`c4=DB=G1I{{$d9`vjPkqD7dYkLQ0myehxUnodl`L zprwLG1E-IO;$z#|pGfbW*CM^`l4h81Sh{~LP2>1gn?29valI4@1UXg(C#xmf%EJVM zVN?ZjvV#o2+sS|tDR`1ILDj&SPB@}be;K-InFy{U?JO;p74NO)Ol2jZP!ms8K?n#2 zo2t=gU}px88N`vV|6)kNQ`Z+jYdU-UnB2E%9p7$ThxPYq!l5QG4i$vM&7*5J{J#L= n(TT(R<*w3Vgre}+Ya7HrLqrg>u3C6q00000NkvXXu0mjfm<`h; literal 0 HcmV?d00001 diff --git a/src/main/resources/com/ivyis/di/trans/steps/git/info/dialog/impl/messages/messages_en_US.properties b/src/main/resources/com/ivyis/di/trans/steps/git/info/dialog/impl/messages/messages_en_US.properties new file mode 100644 index 0000000..02bcf1a --- /dev/null +++ b/src/main/resources/com/ivyis/di/trans/steps/git/info/dialog/impl/messages/messages_en_US.properties @@ -0,0 +1,14 @@ +#List Branchs Command +Git.ListBranchsCommandDialog.Title=Git List Branchs Command +Git.ListMode.Label=List mode + +#Log Command +Git.LogCommandDialog.Title= Git Log Command +Git.Skip.Label=Skip +Git.Path.Label=Path +Git.MaxCount.Label=Max Count + +# Messages errors +Git.MaxCount.NumberParseError.DialogMessage=Please, provide an integer number for Max Count field. +Git.Skip.NumberParseError.DialogMessage=Please, provide an integer number for Skip field. +Git.ListMode.Mandatory.DialogMessage=Please, provide a value for List Mode field. diff --git a/src/main/resources/com/ivyis/di/trans/steps/git/info/ivyis_logo.png b/src/main/resources/com/ivyis/di/trans/steps/git/info/ivyis_logo.png new file mode 100644 index 0000000000000000000000000000000000000000..84825ad2af1c644b0ab9d75a7bf8838ba6aa472e GIT binary patch literal 1214 zcmV;v1VQ_WP)lGe>3m-*bg;#Yg_TcO)(21P&CjXcvAv1 zFUrh|B5wqxq|1RMq*5VsIn_lL)kTp)gkYGqfu-0;oDA2GO;K6ba&>o&Wm{K0XZL)* z(}nYHvj^9tfpeZ`{_}j#^UO;wpP!4j1VAPmJ_~dJrzODDRLgrcrvFi9`vFAPnX|>--YcnTk6xp5aMxa7H82RYYGv@!2DqV> zneIZce(`&OS-^|HcHm)P2Cx;_0K5Ub20R2b0-pkFflacuELxd)jva8yXl2^9GP50? zcgk0R9SH|sca3XgRBV& zt;`E<+v2dCquU%l9Vp<9HNXgP%d<7?eupNxy^mb9w;Sn`&gbovWJ^@FC33|frq#7l ztmG(H3pA#h5kfLrx-N31At8iBDefvA?!JiJ>v72_yy>wul!oA8(CNKI22DYC&e__+uXqna-O`MfG87^K% zAl3li0D&j}j8^7gCL7}3n%%%FllU$JtFisb;d_GT^Xx_A{_zybTjFEj;JA%+CQIc-Xv5Hq@TO zcol%nTA9PZW)EKstaIi6tfoS1wK4^HxBJt|SobRb?ZI0!*>H=Shj?w%${crmJ8;H3 z`yAK^_}}3rTA4n7jwWp&t;`Kzg$LIIZ+W_hv@-9;O{SG815ebL`q<;Q1IJ?d|EfS7 z#BpHD9YltKjd7ECdPP9pLH;k`ZTI5*JI5~DWs$8k1GZ`_1R~L3ZIl#3B9KJ3TD3$u zAtYE3LdJd47}=`0{pAq|A+12v3&eUM#lx!fK zXrNHZ(~xXpFyBooXdof$5Wq-rfcxv)7%B9Vl=VzYw~{XplTJ*fRLOJo=4qq|0B!(_ cYMlf81OD>9Xv-R5k^lez07*qoM6N<$f;SX1`~Uy| literal 0 HcmV?d00001 diff --git a/src/main/resources/com/ivyis/di/trans/steps/git/info/messages/messages_en_US.properties b/src/main/resources/com/ivyis/di/trans/steps/git/info/messages/messages_en_US.properties new file mode 100644 index 0000000..ae3db74 --- /dev/null +++ b/src/main/resources/com/ivyis/di/trans/steps/git/info/messages/messages_en_US.properties @@ -0,0 +1,77 @@ +GitInfo.Step.Name=Git Info Step +GitInfo.Step.Description=Execute git info commands +GitInfo.Step.Category=Repository + + +Git.Shell.Title=Git Step +ExportCmdLine.CommandLine.Title=Ivy Information Systems Ltd + +# Fields +Git.init.Label=Init +Git.add.Label=Add +Git.clone.Label=Clone +Git.commit.Label=Commit +Git.status.Label=Status +Git.pull.Label=Pull +Git.push.Label=Push +Git.tag.Label=Tag +Git.checkout.Label=Checkout +Git.listBranchs.Label=List Branchs +Git.listTags.Label=List Tags +Git.currentBranch.Label=Current Branch +Git.log.Label=Log +Git.UserName.Label=Username +Git.PasswordField.Label=Password +Git.PasswordField.Tooltip=Provide a Git repository password +Git.gBasicPropertiesFields.Label=Basic Git Properties +Git.RadioCloneOperation.Label=Clone Repository +Git.RepoUrlField.Label=Git Repository URL +Git.RepoFolderPathField.Label=Git clone folder path +Git.DefineCommands.Label=Define Git Commands +Git.ColumnInfo.CommandType.Label=Command Type +Git.ColumnInfo.Description.Label=Command Description + +Git.GitInfoCommands.Label=Git get data commands +Git.OutputFieldNames.Label=Output Field Names +Git.IdField.Label=Field Id +Git.NameField.Label=Field name +Git.FullMessageField.Label=Field full message +Git.ShortMessageField.Label=Field short message +Git.AuthorCreationDateField.Label=Field author creation date +Git.AuthorNameField.Label=Field author name +Git.AuthorEmailField.Label=Field author email +Git.CommitterCreationDateField.Label=Field committer creation date +Git.CommitterNameField.Label=Field committer name +Git.CommitterEmailField.Label=Field committer email + +Git.MainOptionTab.CTabItem.Title=Main +Git.ConfigFields.Label=Configuration Fields +Git.ColumnInfo.FieldName=Field Name +Git.ColumnInfo.FieldValue=Field Value +Git.DefineFields.Button=Define Fields + +#List Branchs Command +Git.ListBranchsCommandDialog.Title=Git List Branchs Command +Git.ListMode.Label=List mode + +#Log Command +Git.LogCommandDialog.Title= Git Log Command +Git.Skip.Label=Skip +Git.Path.Label=Path +Git.MaxCount.Label=Max Count + +#Messages +Git.Info.Nothing.Conf.DialogMessage=This Git command doesn't have nothing to configure. +System.Dialog.Info.Title=Information +System.Dialog.Warning.Title=Warning +Git.Command.Not.Found.DialogMessage=Git command not found. +Git.Username.Password.Mandatory.DialogMessage=Username and password wasn't set. However is not mandatory. +Git.RepoFolder.Mandatory.DialogMessage=Please, provide a valid Git clone folder path. +Git.RepoUrl.Mandatory.DialogMessage=Please, provide a valid Git repo url. +Git.ConfigFields.Mandatory.DialogMessage=Please, provide names for all output fields. + +#Errors +Git.Exception.UnexpectedErrorInReadingStepInfo=Unexpected error on reading step info +Git.Exception.UnableToSaveStepInfoToRepository=Unable to save info to repository +Git.GitCommandNotFount.DialogTitle=Git command not found +Git.GitCommandNotFount.DialogMessage=Git command not found diff --git a/src/main/resources/com/ivyis/di/trans/steps/git/messages/messages_en_US.properties b/src/main/resources/com/ivyis/di/trans/steps/git/messages/messages_en_US.properties new file mode 100644 index 0000000..84695f7 --- /dev/null +++ b/src/main/resources/com/ivyis/di/trans/steps/git/messages/messages_en_US.properties @@ -0,0 +1,14 @@ +# Fields +Git.init.Label=Init +Git.add.Label=Add +Git.clone.Label=Clone +Git.commit.Label=Commit +Git.status.Label=Status +Git.pull.Label=Pull +Git.push.Label=Push +Git.tag.Label=Tag +Git.checkout.Label=Checkout +Git.listBranchs.Label=List Branchs +Git.listTags.Label=List Tags +Git.log.Label=Log +Git.currentBranch.Label=Current Branch diff --git a/src/main/resources/com/ivyis/di/trans/steps/git/operations/GitOperationsStep.png b/src/main/resources/com/ivyis/di/trans/steps/git/operations/GitOperationsStep.png new file mode 100644 index 0000000000000000000000000000000000000000..bf8cbbbb82bf51b9428170f1d99781c97a208b48 GIT binary patch literal 1423 zcmV;A1#tR_P)#nKHvv@xmFxN#aG;sZo9 zK!7kn2~iUZLc|whOqK^@GORBo`T!bfKrmEd>YoCGG?5y_2Ngq02OmUy5XHh)5s^+y zOABT9`mlG~=`dZ}q$Hk~$((!dIp==&obMb66VEc0XPF8h!kEOf%mV+<3jMvEvvJt7 z%x8cofauk}ch-MZH2A~*tOCGWX~qyP0cpc=hiv9fDE+?&R69!EMwnzcZjtz$4=T7S z@L(cdPpr6#R9|a&*qf5a)z;*06?Pv9>V}}`vdnEj#uo9)}T-)1Wb_UfKnaN{f6V-4!+a}A<^9g*{G0tz(ODcOa+#QUcs}>dw~=%9k^mR z?o7`ztAKL=iFo}8>wE3F5(=VcnUjG(fD)~;67hN`R#}1l{0sp|9=NQ$3oY!h>!cuP zz;N6F9mR0^#?z$EpCkEYuOgFSux%g4a5miq@hnqD)OsGdgF3n_vk>S420hEH9hU*m zGK)k}s$jBKedbx_nlTyB=%;`VQ9J@9^-_~(nXB^}(1&}05`-wiuPeCfQdadEOO~D9ygNL&j7AXYU4d+ZHip@Su3W5gKjt-H~ zWtmG6RihQ%Ksu}%mjGY*^r;L~MHrE8X`ndB4Y^ln0hapoFHg_X;_tciIFW3NCgSx2 z4XtUFk5GmpQP3$+o~y!G`D`9~w3LpYFOurGgwW0V_Hqek;!q?4<@(MnwrWUqUZier zR8k#Rh*g^ybl#bXhT|&3agPDZfc{`r4#|xa#av@lQXScezE=RT`Hw+bK_&xj?*W6@ zwkOFh6# z`t|z^$5j&+fM$qAD4KyIz^h8w3cMgttTRY_RZ`8kx2GFe4;&vWB7Q2z)d~=Q&Xz1t2eiJX><) z%sInxn^EjUW$8!DRG=X@Cx=On+^6UgYY2fpD3b!Yv)!}I*Rrz^hIWd6h7CY-zEYKt z%wMQ;AUGHN4ZLDF?jhXLm>YSz;={B^pURL?KtCn7yDE&!VIykj~MuaB-; zS3_HS7u=)ZRzIope-4*VWf}ArW`9bi;+<_`hg~OQW)v9$hwEfnnYb!$P)K9|*%$oy!1KD;M z75H%%wr$IV1u!z0Z&Yl)nMLko6UIC}&z*V~+kQQN5>AX<=AV;CiE@)2cAdPDyrv2n d00#MA%D*xtlGe>3m-*bg;#Yg_TcO)(21P&CjXcvAv1 zFUrh|B5wqxq|1RMq*5VsIn_lL)kTp)gkYGqfu-0;oDA2GO;K6ba&>o&Wm{K0XZL)* z(}nYHvj^9tfpeZ`{_}j#^UO;wpP!4j1VAPmJ_~dJrzODDRLgrcrvFi9`vFAPnX|>--YcnTk6xp5aMxa7H82RYYGv@!2DqV> zneIZce(`&OS-^|HcHm)P2Cx;_0K5Ub20R2b0-pkFflacuELxd)jva8yXl2^9GP50? zcgk0R9SH|sca3XgRBV& zt;`E<+v2dCquU%l9Vp<9HNXgP%d<7?eupNxy^mb9w;Sn`&gbovWJ^@FC33|frq#7l ztmG(H3pA#h5kfLrx-N31At8iBDefvA?!JiJ>v72_yy>wul!oA8(CNKI22DYC&e__+uXqna-O`MfG87^K% zAl3li0D&j}j8^7gCL7}3n%%%FllU$JtFisb;d_GT^Xx_A{_zybTjFEj;JA%+CQIc-Xv5Hq@TO zcol%nTA9PZW)EKstaIi6tfoS1wK4^HxBJt|SobRb?ZI0!*>H=Shj?w%${crmJ8;H3 z`yAK^_}}3rTA4n7jwWp&t;`Kzg$LIIZ+W_hv@-9;O{SG815ebL`q<;Q1IJ?d|EfS7 z#BpHD9YltKjd7ECdPP9pLH;k`ZTI5*JI5~DWs$8k1GZ`_1R~L3ZIl#3B9KJ3TD3$u zAtYE3LdJd47}=`0{pAq|A+12v3&eUM#lx!fK zXrNHZ(~xXpFyBooXdof$5Wq-rfcxv)7%B9Vl=VzYw~{XplTJ*fRLOJo=4qq|0B!(_ cYMlf81OD>9Xv-R5k^lez07*qoM6N<$f;SX1`~Uy| literal 0 HcmV?d00001 diff --git a/src/main/resources/com/ivyis/di/trans/steps/git/operations/messages/messages_en_US.properties b/src/main/resources/com/ivyis/di/trans/steps/git/operations/messages/messages_en_US.properties new file mode 100644 index 0000000..7a985fc --- /dev/null +++ b/src/main/resources/com/ivyis/di/trans/steps/git/operations/messages/messages_en_US.properties @@ -0,0 +1,99 @@ +GitOperations.Step.Name=Git Operations Step +GitOperations.Step.Description=Execute git operations commands +GitOperations.Step.Category=Repository + + +Git.Shell.Title=Git Step +ExportCmdLine.CommandLine.Title=Ivy Information Systems Ltd + +# Fields +Git.init.Label=Init +Git.add.Label=Add +Git.clone.Label=Clone +Git.commit.Label=Commit +Git.status.Label=Status +Git.pull.Label=Pull +Git.push.Label=Push +Git.tag.Label=Tag +Git.checkout.Label=Checkout +Git.UserName.Label=Username +Git.PasswordField.Label=Password +Git.PasswordField.Tooltip=Provide a Git repository password +Git.gBasicPropertiesFields.Label=Basic Git Properties +Git.RadioCloneOperation.Label=Clone Repository +Git.RepoUrlField.Label=Git Repository URL +Git.RepoFolderPathField.Label=Git clone folder path +Git.DefineCommands.Label=Define Git Commands +Git.ColumnInfo.CommandType.Label=Command Type +Git.ColumnInfo.Description.Label=Command Description + +# Add Git Command +Git.AddCommandDialog.Title=Git Add Command +Git.FilePattern.Label=File pattern +Git.Update.Label=Update + +# Checkout Git Command +Git.CheckoutCommandDialog.Title=Git Checkout Command +Git.Path.Label=Path +Git.Name.Label=Name +Git.StartPoint.Label=Start Point +Git.AllPaths.Label=All Paths +Git.Force.Label=Force + +# Clone Git Command +Git.CloneCommandDialog.Title=Git Clone Command +Git.BranchField.Label=Branch +Git.CloneSubModulesField.Label=Clone sub-modules +Git.CloneAllBranchesField.Label=Clone all branches + +# Commit Git Command +Git.CommitCommandDialog.Title=Git Commit Command +Git.AuthorName.Label=Author Name +Git.AuthorEmail.Label=Author Email +Git.CommitterName.Label=Committer Name +Git.CommitterEmail.Label=Committer Email +Git.CommitMessage.Label=Commit Message +Git.Amend.Label=Amend +Git.InsertChangeId.Label=Insert Change Id +Git.All.Label=All + +# Init Git Command +Git.InitCommandDialog.Title=Git Init Command +Git.Bare.Label=Bare + +# Pull Git Command +Git.PullCommandDialog.Title=Git Pull Command +Git.Rebase.Label=Rebase + + +# Push Git Command +Git.PushCommandDialog.Title=Git Push Command +Git.ReferenceToPush.Label=Reference to push +Git.Remote.Label=Remote +Git.ReceivePack.Label=Receive Pack +Git.DryRun.Label=Dry Run +Git.Force.Label=Force +Git.Thin.Label=Thin +Git.PushAllBranches.Label=Push all branches +Git.PushAllTags.Label=Push all tags + +# Tag Git Command +Git.TagCommandDialog.Title=Git Tag Command +Git.Name.Label=Name +Git.Message.Label=Message +Git.Annotated.Label=Annotated +Git.ForceUpdate.Label=Force update +Git.Signed.Label=Signed + +#Messages +System.Dialog.Warning.Title=Warning +Git.Username.Password.Mandatory.DialogMessage=Username and password wasn't set. However is not mandatory. +Git.RepoFolder.Mandatory.DialogMessage=Please, provide a valid Git clone folder path. +Git.RepoUrl.Mandatory.DialogMessage=Please, provide a valid Git repo url. +Git.Min.Git.Commands.DialogMessage=Please, provide one command at least. + +#Errors +Git.Exception.UnexpectedErrorInReadingStepInfo=Unexpected error on reading step info +Git.Exception.UnableToSaveStepInfoToRepository=Unable to save info to repository +Git.GitCommandNotFount.DialogTitle=Git command not found +Git.GitCommandNotFount.DialogMessage=Git command not found