summaryrefslogtreecommitdiffstats
path: root/src/com/ibm
diff options
context:
space:
mode:
authornjames <nkskjames@gmail.com>2016-09-04 06:13:46 -0500
committernjames <nkskjames@gmail.com>2016-09-04 06:13:46 -0500
commit0f2fb3c5a8ce5e6bbcb9024431ba845ef63207a7 (patch)
treece0cd3f08e8be69bae06de496a2e99e02b5b29c6 /src/com/ibm
parent6a8325ec13a9386d60147ee877a444b26b686be4 (diff)
downloadserverwiz-0f2fb3c5a8ce5e6bbcb9024431ba845ef63207a7.tar.gz
serverwiz-0f2fb3c5a8ce5e6bbcb9024431ba845ef63207a7.zip
Rework git interface
Signed-off-by: Norman James <nkskjames@gmail.com>
Diffstat (limited to 'src/com/ibm')
-rw-r--r--src/com/ibm/ServerWizard2/utility/Github.java23
-rw-r--r--src/com/ibm/ServerWizard2/utility/GithubRepository.java42
-rw-r--r--src/com/ibm/ServerWizard2/view/GitDialog.java28
3 files changed, 59 insertions, 34 deletions
diff --git a/src/com/ibm/ServerWizard2/utility/Github.java b/src/com/ibm/ServerWizard2/utility/Github.java
index b990118..6eef91b 100644
--- a/src/com/ibm/ServerWizard2/utility/Github.java
+++ b/src/com/ibm/ServerWizard2/utility/Github.java
@@ -3,31 +3,24 @@ package com.ibm.ServerWizard2.utility;
import java.io.File;
import java.util.Vector;
-public class Github {
+public class Github {
private Vector<GithubRepository> repositories = new Vector<GithubRepository>();
+ private String localPath;
- public Github() {
- File f = new File(GithubRepository.GIT_LOCAL_LOCATION);
+ public Github(String path) {
+ this.localPath = path;
+ File f = new File(path);
if (!f.exists()) {
f.mkdirs();
}
}
-
+ public String getLocation() {
+ return this.localPath;
+ }
public boolean isRepository(GithubRepository repo) {
return repositories.contains(repo);
}
- public boolean addRepository(String repo, boolean needsPass) {
- for (GithubRepository g : repositories) {
- if (g.getRemoteUrl().equals(repo)) {
- return false;
- }
- }
- GithubRepository g = new GithubRepository(repo,needsPass);
- repositories.add(g);
- return true;
- }
-
public Vector<GithubRepository> getRepositories() {
return repositories;
}
diff --git a/src/com/ibm/ServerWizard2/utility/GithubRepository.java b/src/com/ibm/ServerWizard2/utility/GithubRepository.java
index fc94f1d..3030a57 100644
--- a/src/com/ibm/ServerWizard2/utility/GithubRepository.java
+++ b/src/com/ibm/ServerWizard2/utility/GithubRepository.java
@@ -1,7 +1,9 @@
package com.ibm.ServerWizard2.utility;
import java.io.File;
+import java.net.UnknownHostException;
import java.util.Collection;
+import java.util.HashMap;
import javax.swing.ProgressMonitor;
@@ -25,15 +27,15 @@ public class GithubRepository implements Comparable<GithubRepository> {
private boolean needsPassword;
private boolean passwordValidated = false;
private UsernamePasswordCredentialsProvider credentials;
- public final static String GIT_LOCAL_LOCATION = "git";
+
private boolean cloned;
private final RefSpec refSpec = new RefSpec("+refs/heads/*:refs/remotes/origin/*");
- public GithubRepository(String remoteUrl, boolean needsPassword) {
+ public GithubRepository(String remoteUrl, String localDir, boolean needsPassword) {
this.remoteUrl = remoteUrl;
this.needsPassword = needsPassword;
File f = new File(remoteUrl);
- String localPath = GIT_LOCAL_LOCATION + File.separator + f.getName().replace(".git", "");
+ String localPath = localDir + File.separator + f.getName().replace(".git", "");
rootDirectory = new File(localPath);
gitDirectory = new File(localPath + File.separator + ".git");
cloned = false;
@@ -94,6 +96,7 @@ public class GithubRepository implements Comparable<GithubRepository> {
}
} catch (Exception e) {
ServerWizard2.LOGGER.severe(e.getMessage());
+ this.betterError(e);
}
if (!found) {
passwordValidated = false;
@@ -121,13 +124,12 @@ public class GithubRepository implements Comparable<GithubRepository> {
cloned = true;
result.close();
} catch (Exception e1) {
- ServerWizard2.LOGGER.severe(e1.getMessage());
passwordValidated = false;
- throw new Exception("Unable to clone");
+ this.betterError(e1);
}
}
- public void fetch(boolean reset) {
+ public void fetch(boolean reset) throws Exception {
if (!passwordValidated) {
this.getPassword();
}
@@ -153,7 +155,7 @@ public class GithubRepository implements Comparable<GithubRepository> {
result.close();
} catch (Exception e1) {
passwordValidated = false;
- ServerWizard2.LOGGER.severe(e1.getMessage());
+ this.betterError(e1);
}
}
@@ -172,6 +174,23 @@ public class GithubRepository implements Comparable<GithubRepository> {
}
return status;
}
+
+ // The chained exceptions from jgit don't explain error
+ // Need to dive down to root cause and make better error message.
+ public void betterError(Exception e) throws Exception {
+ HashMap<String,String> errorLookup = new HashMap<String,String>();
+ errorLookup.put("java.net.UnknownHostException", "Unable to connect to location:");
+ errorLookup.put("org.eclipse.jgit.errors.NoRemoteRepositoryException", "Remote Repository not found:");
+ errorLookup.put("org.eclipse.jgit.errors.TransportException", "Invalid Remote Repository or Bad Password: ");
+ ServerWizard2.LOGGER.severe(e.getCause().toString());
+ Throwable t = getCause(e);
+ ServerWizard2.LOGGER.severe(t.toString());
+ String errorMsg = t.getMessage();
+ if (errorLookup.containsKey(t.getClass().getName())) {
+ errorMsg = errorLookup.get(t.getClass().getName()) + "\n" + t.getMessage();
+ }
+ throw new Exception(errorMsg);
+ }
public boolean isCloned() {
return cloned;
@@ -209,4 +228,13 @@ public class GithubRepository implements Comparable<GithubRepository> {
}
return false;
}
+ Throwable getCause(Throwable e) {
+ Throwable cause = null;
+ Throwable result = e;
+
+ while(null != (cause = result.getCause()) && (result != cause) ) {
+ result = cause;
+ }
+ return result;
+ }
}
diff --git a/src/com/ibm/ServerWizard2/view/GitDialog.java b/src/com/ibm/ServerWizard2/view/GitDialog.java
index 1725b15..d091801 100644
--- a/src/com/ibm/ServerWizard2/view/GitDialog.java
+++ b/src/com/ibm/ServerWizard2/view/GitDialog.java
@@ -40,10 +40,8 @@ import com.ibm.ServerWizard2.utility.GithubRepository;
public class GitDialog extends Dialog {
private Text txtNewRepo;
- Github git = new Github();
+ Github git = new Github(ServerWizard2.GIT_LOCATION);
- private final String PROPERTIES_FILE = "serverwiz.preferences";
- private final String DEFAULT_REPO = "https://github.com/nkskjames/firestone-xml.git";
private ListViewer listViewer;
private Button btnCloned;
private Button btnAdded;
@@ -190,7 +188,7 @@ public class GitDialog extends Dialog {
MessageDialog.openInformation(null, "Refresh Complete", "Refresh Complete");
}
} catch (Exception e) {
- MessageDialog.openError(null, "Git Refresh Error", "Unable to refresh: " + g.getRemoteUrl());
+ MessageDialog.openError(null, "Git Refresh: "+g.getRemoteUrl(), e.getMessage());
}
}
});
@@ -212,7 +210,7 @@ public class GitDialog extends Dialog {
}
GithubRepository g = (GithubRepository) listViewer
.getElementAt(listViewer.getList().getSelectionIndex());
- if (g.getRemoteUrl().equals(DEFAULT_REPO)) {
+ if (g.getRemoteUrl().equals(ServerWizard2.DEFAULT_REMOTE_URL)) {
MessageDialog.openError(null, "Error", "Deleting of default repository is not allowed");
} else {
git.getRepositories().remove(g);
@@ -262,9 +260,10 @@ public class GitDialog extends Dialog {
MessageDialog.openError(null, "Error", "Repository URL is blank");
return;
}
- GithubRepository g = new GithubRepository(repo, btnNeedsPassword.getSelection());
+ GithubRepository g = new GithubRepository(repo, git.getLocation(), btnNeedsPassword.getSelection());
if (git.isRepository(g)) {
MessageDialog.openError(null, "Error", "Repository already exists");
+ return;
}
try {
g.checkRemote();
@@ -273,7 +272,7 @@ public class GitDialog extends Dialog {
txtNewRepo.setText("");
listViewer.refresh();
} catch (Exception e) {
- MessageDialog.openError(null, "Error", e.getMessage());
+ MessageDialog.openError(null, "Add Remote: "+g.getRemoteUrl(), e.getMessage());
}
}
});
@@ -336,19 +335,19 @@ public class GitDialog extends Dialog {
public void getRepositories() {
try {
boolean newFile = false;
- File f = new File(PROPERTIES_FILE);
+ File f = new File(ServerWizard2.PROPERTIES_FILE);
if (!f.exists()) {
ServerWizard2.LOGGER.info("Preferences file doesn't exist, creating...");
f.createNewFile();
newFile = true;
}
- FileInputStream propFile = new FileInputStream(PROPERTIES_FILE);
+ FileInputStream propFile = new FileInputStream(ServerWizard2.PROPERTIES_FILE);
Properties p = new Properties();
p.load(propFile);
propFile.close();
if (newFile) {
- p.setProperty("repositories", DEFAULT_REPO);
+ p.setProperty("repositories", ServerWizard2.DEFAULT_REMOTE_URL);
p.setProperty("needs_password", "false");
}
String repos = p.getProperty("repositories");
@@ -362,7 +361,8 @@ public class GitDialog extends Dialog {
if (needsPass[i].equals("true")) {
n = true;
}
- git.addRepository(repo[i], n);
+ GithubRepository g = new GithubRepository(repo[i],ServerWizard2.GIT_LOCATION,n);
+ git.getRepositories().add(g);
}
} catch (Exception e) {
ServerWizard2.LOGGER.severe(e.getMessage());
@@ -372,7 +372,11 @@ public class GitDialog extends Dialog {
public boolean close() {
Properties p = new Properties();
try {
- FileOutputStream out = new FileOutputStream(PROPERTIES_FILE);
+ FileInputStream propFile = new FileInputStream(ServerWizard2.PROPERTIES_FILE);
+ p.load(propFile);
+ propFile.close();
+
+ FileOutputStream out = new FileOutputStream(ServerWizard2.PROPERTIES_FILE);
String repo = git.getRepositoriesStr();
String pass = git.getPasswordStr();
p.setProperty("repositories", repo);
OpenPOWER on IntegriCloud