This is an automated email from the ASF dual-hosted git repository.

hansva pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hop.git


The following commit(s) were added to refs/heads/master by this push:
     new 4b8f975  HOP-3187: fix missing shell in VCS.java
     new 74ff9b5  Merge pull request #1021 from hansva/master
4b8f975 is described below

commit 4b8f9754312c5420ff4317bfef5412328c00e0a2
Author: Hans Van Akelyen <[email protected]>
AuthorDate: Wed Aug 25 23:07:51 2021 +0200

    HOP-3187: fix missing shell in VCS.java
---
 .../main/java/org/apache/hop/git/model/UIGit.java  | 113 +++++++--------------
 .../main/java/org/apache/hop/git/model/VCS.java    |  30 ++----
 2 files changed, 42 insertions(+), 101 deletions(-)

diff --git a/plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java 
b/plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java
index 0085c27..8ac9ab9 100644
--- a/plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java
+++ b/plugins/misc/git/src/main/java/org/apache/hop/git/model/UIGit.java
@@ -28,6 +28,7 @@ import org.apache.hop.git.model.revision.GitObjectRevision;
 import org.apache.hop.git.model.revision.ObjectRevision;
 import org.apache.hop.i18n.BaseMessages;
 import org.apache.hop.ui.core.dialog.EnterSelectionDialog;
+import org.apache.hop.ui.hopgui.HopGui;
 import org.eclipse.jgit.api.*;
 import org.eclipse.jgit.api.ListBranchCommand.ListMode;
 import org.eclipse.jgit.api.MergeResult.MergeStatus;
@@ -64,6 +65,7 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 public class UIGit extends VCS {
+  protected static final Class<?> PKG = UIGit.class; // For Translator
 
   static {
     /**
@@ -118,8 +120,8 @@ public class UIGit extends VCS {
   public String getCommitMessage(String commitId) {
     if (commitId.equals(VCS.WORKINGTREE)) {
       try {
-        String merge_msg = git.getRepository().readMergeCommitMsg();
-        return merge_msg == null ? "" : merge_msg;
+        String mergeMsg = git.getRepository().readMergeCommitMsg();
+        return mergeMsg == null ? "" : mergeMsg;
       } catch (Exception e) {
         return e.getMessage();
       }
@@ -133,11 +135,7 @@ public class UIGit extends VCS {
     ObjectId id = null;
     try {
       id = git.getRepository().resolve(revstr);
-    } catch (RevisionSyntaxException e) {
-      e.printStackTrace();
-    } catch (AmbiguousObjectException e) {
-      e.printStackTrace();
-    } catch (IncorrectObjectTypeException e) {
+    } catch (RevisionSyntaxException | AmbiguousObjectException | 
IncorrectObjectTypeException e) {
       e.printStackTrace();
     } catch (IOException e) {
       e.printStackTrace();
@@ -308,30 +306,10 @@ public class UIGit extends VCS {
       e.printStackTrace();
       return files;
     }
-    status
-        .getUntracked()
-        .forEach(
-            name -> {
-              files.add(new UIFile(name, ChangeType.ADD, false));
-            });
-    status
-        .getModified()
-        .forEach(
-            name -> {
-              files.add(new UIFile(name, ChangeType.MODIFY, false));
-            });
-    status
-        .getConflicting()
-        .forEach(
-            name -> {
-              files.add(new UIFile(name, ChangeType.MODIFY, false));
-            });
-    status
-        .getMissing()
-        .forEach(
-            name -> {
-              files.add(new UIFile(name, ChangeType.DELETE, false));
-            });
+    status.getUntracked().forEach(name -> files.add(new UIFile(name, 
ChangeType.ADD, false)));
+    status.getModified().forEach(name -> files.add(new UIFile(name, 
ChangeType.MODIFY, false)));
+    status.getConflicting().forEach(name -> files.add(new UIFile(name, 
ChangeType.MODIFY, false)));
+    status.getMissing().forEach(name -> files.add(new UIFile(name, 
ChangeType.DELETE, false)));
     return files;
   }
 
@@ -344,24 +322,9 @@ public class UIGit extends VCS {
       e.printStackTrace();
       return files;
     }
-    status
-        .getAdded()
-        .forEach(
-            name -> {
-              files.add(new UIFile(name, ChangeType.ADD, true));
-            });
-    status
-        .getChanged()
-        .forEach(
-            name -> {
-              files.add(new UIFile(name, ChangeType.MODIFY, true));
-            });
-    status
-        .getRemoved()
-        .forEach(
-            name -> {
-              files.add(new UIFile(name, ChangeType.DELETE, true));
-            });
+    status.getAdded().forEach(name -> files.add(new UIFile(name, 
ChangeType.ADD, true)));
+    status.getChanged().forEach(name -> files.add(new UIFile(name, 
ChangeType.MODIFY, true)));
+    status.getRemoved().forEach(name -> files.add(new UIFile(name, 
ChangeType.DELETE, true)));
     return files;
   }
 
@@ -374,15 +337,14 @@ public class UIGit extends VCS {
       rd.addAll(diffs);
       diffs = rd.compute();
       diffs.forEach(
-          diff -> {
-            files.add(
-                new UIFile(
-                    diff.getChangeType() == ChangeType.DELETE
-                        ? diff.getOldPath()
-                        : diff.getNewPath(),
-                    diff.getChangeType(),
-                    false));
-          });
+          diff ->
+              files.add(
+                  new UIFile(
+                      diff.getChangeType() == ChangeType.DELETE
+                          ? diff.getOldPath()
+                          : diff.getNewPath(),
+                      diff.getChangeType(),
+                      false)));
     } catch (Exception e) {
       e.printStackTrace();
     }
@@ -591,16 +553,15 @@ public class UIGit extends VCS {
               .filter(update -> update.getStatus() != 
RemoteRefUpdate.Status.OK)
               .filter(update -> update.getStatus() != 
RemoteRefUpdate.Status.UP_TO_DATE)
               .forEach(
-                  update -> { // for each failed refspec
-                    sb.append(
-                        result.getURI().toString()
-                            + "\n"
-                            + update.getSrcRef().toString()
-                            + "\n"
-                            + update.getStatus().toString()
-                            + (update.getMessage() == null ? "" : "\n" + 
update.getMessage())
-                            + "\n\n");
-                  });
+                  update -> // for each failed refspec
+                  sb.append(
+                          result.getURI().toString()
+                              + "\n"
+                              + update.getSrcRef()
+                              + "\n"
+                              + update.getStatus().toString()
+                              + (update.getMessage() == null ? "" : "\n" + 
update.getMessage())
+                              + "\n\n"));
           if (sb.length() == 0) {
             showMessageBox(
                 BaseMessages.getString(PKG, "Dialog.Success"),
@@ -668,15 +629,15 @@ public class UIGit extends VCS {
     cmd.setURI(uri);
     cmd.setCredentialsProvider(credentialsProvider);
     try {
-      Git git = cmd.call();
-      git.close();
+      Git gitClone = cmd.call();
+      gitClone.close();
       return true;
     } catch (Exception e) {
       if ((e instanceof TransportException)
-          && ((e.getMessage()
+          && (e.getMessage()
                   .contains(
                       "Authentication is required but no CredentialsProvider 
has been registered")
-              || e.getMessage().contains("not authorized")))) {
+              || e.getMessage().contains("not authorized"))) {
         if (promptUsernamePassword()) {
           return cloneRepo(directory, uri);
         }
@@ -941,11 +902,7 @@ public class UIGit extends VCS {
     ObjectId id = null;
     try {
       id = git.getRepository().resolve(commitId);
-    } catch (RevisionSyntaxException e1) {
-      e1.printStackTrace();
-    } catch (AmbiguousObjectException e1) {
-      e1.printStackTrace();
-    } catch (IncorrectObjectTypeException e1) {
+    } catch (RevisionSyntaxException | AmbiguousObjectException | 
IncorrectObjectTypeException e1) {
       e1.printStackTrace();
     } catch (IOException e1) {
       e1.printStackTrace();
@@ -964,7 +921,7 @@ public class UIGit extends VCS {
 
   @VisibleForTesting
   EnterSelectionDialog getEnterSelectionDialog(String[] choices, String 
shellText, String message) {
-    return new EnterSelectionDialog(shell, choices, shellText, message);
+    return new EnterSelectionDialog(HopGui.getInstance().getShell(), choices, 
shellText, message);
   }
 
   public Set<String> getIgnored(String path) {
diff --git a/plugins/misc/git/src/main/java/org/apache/hop/git/model/VCS.java 
b/plugins/misc/git/src/main/java/org/apache/hop/git/model/VCS.java
index c24af56..f3719e4 100644
--- a/plugins/misc/git/src/main/java/org/apache/hop/git/model/VCS.java
+++ b/plugins/misc/git/src/main/java/org/apache/hop/git/model/VCS.java
@@ -15,34 +15,17 @@
  * limitations under the License.
  */
 
-/*
- * Hop : The Hop Orchestration Platform
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
 package org.apache.hop.git.model;
 
 import com.google.common.annotations.VisibleForTesting;
 import org.apache.hop.ui.core.dialog.EnterStringDialog;
-import org.apache.hop.ui.hopgui.perspective.HopPerspectivePlugin;
+import org.apache.hop.ui.hopgui.HopGui;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.MessageBox;
-import org.eclipse.swt.widgets.Shell;
 
 public abstract class VCS {
 
-  protected static final Class<?> PKG = HopPerspectivePlugin.class; // For 
Translator
+  protected static final Class<?> PKG = UIGit.class; // For Translator
 
   public static final String WORKINGTREE = "WORKINGTREE";
   public static final String INDEX = "INDEX";
@@ -50,12 +33,11 @@ public abstract class VCS {
   public static final String TYPE_BRANCH = "branch";
   public static final String TYPE_COMMIT = "commit";
 
-  protected Shell shell;
   protected String directory;
 
   @VisibleForTesting
   void showMessageBox(String title, String message) {
-    MessageBox messageBox = new MessageBox(shell, SWT.OK);
+    MessageBox messageBox = new MessageBox(HopGui.getInstance().getShell(), 
SWT.OK);
     messageBox.setText(title);
     messageBox.setMessage(message == null ? "" : message);
     messageBox.open();
@@ -68,14 +50,16 @@ public abstract class VCS {
    */
   protected boolean promptUsernamePassword() {
     EnterStringDialog userDialog =
-        new EnterStringDialog(shell, "", "Username?", "Enter the git username 
to use");
+        new EnterStringDialog(
+            HopGui.getInstance().getShell(), "", "Username?", "Enter the git 
username to use");
     String username = userDialog.open();
     if (username == null) {
       return false;
     }
 
     EnterStringDialog passDialog =
-        new EnterStringDialog(shell, "", "Password?", "Enter the git password 
to use");
+        new EnterStringDialog(
+            HopGui.getInstance().getShell(), "", "Password?", "Enter the git 
password to use");
     passDialog.setEchoChar('*');
     String password = passDialog.open();
     if (password == null) {

Reply via email to