From c90d0caca0dd3a18bac034074367edc9b0b9e6d5 Mon Sep 17 00:00:00 2001 From: Giridhari Krishnan Date: Thu, 3 Oct 2019 13:28:41 +0530 Subject: [PATCH 1/2] Addition/Deletion/Updation of common-mrw/, Removal and Alert for users while overlaying over the base repo. --- .../controller/TargetWizardController.java | 4 +- .../ibm/ServerWizard2/model/SystemModel.java | 1 + .../utility/GithubRepository.java | 4 +- src/com/ibm/ServerWizard2/view/GitDialog.java | 53 +++++++++++++------ 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/com/ibm/ServerWizard2/controller/TargetWizardController.java b/src/com/ibm/ServerWizard2/controller/TargetWizardController.java index d0a95ed..7b0d507 100644 --- a/src/com/ibm/ServerWizard2/controller/TargetWizardController.java +++ b/src/com/ibm/ServerWizard2/controller/TargetWizardController.java @@ -54,7 +54,7 @@ public void init() { try { String libraryLocation = ServerWizard2.GIT_LOCATION + File.separator + this.LIBRARY_NAME; File chk = new File(libraryLocation); - if (!chk.exists()) { + if (!chk.exists() && !ServerWizard2.DEFAULT_REMOTE_URL.isBlank()) { ServerWizard2.LOGGER.info("XML library does not exist so cloning: "+libraryLocation); StatusLogger.getLogger().setLevel(Level.FATAL); GithubRepository git = new GithubRepository(ServerWizard2.DEFAULT_REMOTE_URL, ServerWizard2.GIT_LOCATION, false); @@ -80,7 +80,7 @@ public void init() { String curRepo = repo[i].substring(repo[i].lastIndexOf('/') + 1); curRepo = ServerWizard2.GIT_LOCATION + File.separator + curRepo; chk = new File(curRepo); - if(!chk.exists()) { + if(!chk.exists() && !ServerWizard2.DEFAULT_REMOTE_URL.isBlank()) { ServerWizard2.LOGGER.info("XML library does not exist so cloning: " + curRepo); GithubRepository git = new GithubRepository( repo[i], ServerWizard2.GIT_LOCATION, false); diff --git a/src/com/ibm/ServerWizard2/model/SystemModel.java b/src/com/ibm/ServerWizard2/model/SystemModel.java index d23a288..fc7e22a 100644 --- a/src/com/ibm/ServerWizard2/model/SystemModel.java +++ b/src/com/ibm/ServerWizard2/model/SystemModel.java @@ -221,6 +221,7 @@ public void loadLibrary(String path) throws Exception { String[] filesStr = xmlDir.list(); if (filesStr == null) { ServerWizard2.LOGGER.warning("No library loaded"); + ServerWizard2.DEFAULT_REMOTE_URL = ""; } else { Arrays.sort(filesStr); diff --git a/src/com/ibm/ServerWizard2/utility/GithubRepository.java b/src/com/ibm/ServerWizard2/utility/GithubRepository.java index 40dfbd3..9eceda1 100644 --- a/src/com/ibm/ServerWizard2/utility/GithubRepository.java +++ b/src/com/ibm/ServerWizard2/utility/GithubRepository.java @@ -19,6 +19,7 @@ import com.ibm.ServerWizard2.ServerWizard2; import com.ibm.ServerWizard2.view.PasswordPrompt; +import com.jcraft.jsch.JSch; public class GithubRepository implements Comparable { private String remoteUrl; @@ -35,6 +36,7 @@ public class GithubRepository implements Comparable { public GithubRepository(String remoteUrl, String localDir, boolean needsPassword) { this.remoteUrl = remoteUrl; this.needsPassword = needsPassword; + JSch.setConfig("StrictHostKeyChecking", "no"); File f = new File(remoteUrl); String localPath = localDir + File.separator + f.getName().replace(".git", ""); rootDirectory = new File(localPath); @@ -125,7 +127,7 @@ public void cloneRepository() throws Exception { .setCredentialsProvider(credentials) .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))) .setURI(this.getRemoteUrl()).setDirectory(this.getRootDirectory()).call(); - + cloned = true; result.close(); } catch (Exception e1) { diff --git a/src/com/ibm/ServerWizard2/view/GitDialog.java b/src/com/ibm/ServerWizard2/view/GitDialog.java index 27e78c0..3a8c7eb 100644 --- a/src/com/ibm/ServerWizard2/view/GitDialog.java +++ b/src/com/ibm/ServerWizard2/view/GitDialog.java @@ -13,6 +13,7 @@ import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.ListViewer; @@ -212,23 +213,37 @@ public void widgetSelected(SelectionEvent arg0) { GithubRepository g = (GithubRepository) listViewer .getElementAt(listViewer.getList().getSelectionIndex()); try { + boolean Alert = false; + boolean cmnMrwUrl = g.getRemoteUrl().contains("common-mrw"); if (!g.isCloned()) { + if(cmnMrwUrl){ + ServerWizard2.DEFAULT_REMOTE_URL = g.getRemoteUrl(); + } g.cloneRepository(); } + else if(cmnMrwUrl) + { + Alert = MessageDialog.openConfirm(null, "ALERT", "A Common mrw Repo already exists in disk.\n" + +"It will overlay on the existing repo in disk.\n" + +"Please delete it in disk and reload with this " + +"if need this as base, Confirm to Overlay"); + } org.eclipse.jgit.api.Status status = g.status(); - - if (!status.isClean()) { - boolean reset = MessageDialog.openQuestion(null, "Repository is Modified", - "The local repository for:\n" + g.getRemoteUrl() + "\n" + if(Alert || !cmnMrwUrl) { + if (!status.isClean()) { + boolean reset = MessageDialog.openQuestion(null, "Repository is Modified", + "The local repository for:\n" + g.getRemoteUrl() + "\n" + "has been modified. Would you like to ignore changes and reset?"); - if (reset) { - String r = g.fetch(true); - ServerwizMessageDialog.openInformation(null, "Refresh Complete", "Reset Successful"); - + if (reset) { + String r = g.fetch(true); + ServerwizMessageDialog.openInformation(null, "Refresh Complete", "Reset Successful"); + + } + } else { + String r = g.fetch(false); + ServerwizMessageDialog.openInformation(null, "Refresh Complete", "Message: " + r); } - } else { - String r = g.fetch(false); - ServerwizMessageDialog.openInformation(null, "Refresh Complete", "Message: " + r); + MessageDialog.openInformation(null, "Alert!!", "Please rerun the project for model to load"); } } catch (Exception e) { ServerwizMessageDialog.openError(null, "Git Refresh: " + g.getRemoteUrl(), e.getMessage()); @@ -262,12 +277,8 @@ public void widgetSelected(SelectionEvent arg0) { if (!delete) { return; } - if (g.getRemoteUrl().equals(ServerWizard2.DEFAULT_REMOTE_URL)) { - ServerwizMessageDialog.openError(null, "Error", "Deleting of default repository is not allowed"); - } else { git.getRepositories().remove(g); listViewer.refresh(); - } } }); btnDelete.setText("Delete"); @@ -327,7 +338,17 @@ public void widgetSelected(SelectionEvent arg0) { } try { g.checkRemote(); - g.cloneRepository(); + boolean Alert = true; + if((!ServerWizard2.DEFAULT_REMOTE_URL.isEmpty()) && (g.getRemoteUrl().contains("common-mrw"))) + { + Alert = MessageDialog.openConfirm(null, "ALERT", "A Common mrw Repo already exists in disk.\n " + +"It will be overlaid on the repo existing in disk.\n " + +"Please delete it in disk and refresh with this if need this as base, Confirm to Overlay!!!!"); + } + if(Alert) + { + g.cloneRepository(); + } git.getRepositories().add(g); txtNewRepo.setText(""); listViewer.refresh(); From 296b8e6e4fb57f513ad01cdb819ca7bd422dd9d5 Mon Sep 17 00:00:00 2001 From: Giridhari Krishnan Date: Thu, 3 Oct 2019 16:07:23 +0530 Subject: [PATCH 2/2] Option for cloning from any branch --- src/com/ibm/ServerWizard2/ServerWizard2.java | 9 ++- .../utility/GithubRepository.java | 2 +- src/com/ibm/ServerWizard2/view/GitDialog.java | 75 ++++++++++++------- 3 files changed, 58 insertions(+), 28 deletions(-) diff --git a/src/com/ibm/ServerWizard2/ServerWizard2.java b/src/com/ibm/ServerWizard2/ServerWizard2.java index 63bc0e7..dddaa9f 100644 --- a/src/com/ibm/ServerWizard2/ServerWizard2.java +++ b/src/com/ibm/ServerWizard2/ServerWizard2.java @@ -19,6 +19,7 @@ import com.ibm.ServerWizard2.utility.GithubRepository; import com.ibm.ServerWizard2.utility.MyLogFormatter; import com.ibm.ServerWizard2.utility.ServerwizMessageDialog; +import com.jcraft.jsch.JSch; import com.ibm.ServerWizard2.view.MainDialog; public class ServerWizard2 { @@ -31,10 +32,10 @@ public class ServerWizard2 { public final static String PROPERTIES_FILE = "serverwiz.preferences"; public static String GIT_LOCATION = ""; - public final static String DEFAULT_REMOTE_URL = "https://github.com/open-power/common-mrw-xml.git"; + public static String DEFAULT_REMOTE_URL = ""; public static Boolean updateOnlyMode = false; - + public static String branchName= "master"; public static String getVersionString() { return VERSION_MAJOR+"."+VERSION_MINOR; } @@ -54,6 +55,7 @@ private static void printUsage() { System.out.println(" -h = print this usage"); } public static void main(String[] args) { + JSch.setConfig("StrictHostKeyChecking", "no"); String inputFilename=""; String outputFilename=""; Boolean cleanupMode = false; @@ -155,6 +157,7 @@ private static void getPreferencesForUpdateMode() { p.setProperty("git_location", getWorkingDir()); p.setProperty("repositories", ServerWizard2.DEFAULT_REMOTE_URL); p.setProperty("needs_password", "false"); + p.setProperty("branch_name", ServerWizard2.branchName); FileOutputStream out = new FileOutputStream(ServerWizard2.PROPERTIES_FILE); p.store(out, ""); @@ -197,6 +200,7 @@ private static void getPreferences() { ServerWizard2.LOGGER.warning("No directory selected; exiting..."); System.exit(0); } + p.setProperty("branch_name", ServerWizard2.branchName); p.setProperty("git_location", libPath); p.setProperty("repositories", ServerWizard2.DEFAULT_REMOTE_URL); p.setProperty("needs_password", "false"); @@ -205,6 +209,7 @@ private static void getPreferences() { p.store(out, ""); out.close(); } + FileInputStream propFile = new FileInputStream(ServerWizard2.PROPERTIES_FILE); p.load(propFile); propFile.close(); diff --git a/src/com/ibm/ServerWizard2/utility/GithubRepository.java b/src/com/ibm/ServerWizard2/utility/GithubRepository.java index 9eceda1..3201df7 100644 --- a/src/com/ibm/ServerWizard2/utility/GithubRepository.java +++ b/src/com/ibm/ServerWizard2/utility/GithubRepository.java @@ -126,7 +126,7 @@ public void cloneRepository() throws Exception { Git result = Git.cloneRepository() .setCredentialsProvider(credentials) .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out))) - .setURI(this.getRemoteUrl()).setDirectory(this.getRootDirectory()).call(); + .setURI(this.getRemoteUrl()).setDirectory(this.getRootDirectory()).setBranch(ServerWizard2.branchName).call(); cloned = true; result.close(); diff --git a/src/com/ibm/ServerWizard2/view/GitDialog.java b/src/com/ibm/ServerWizard2/view/GitDialog.java index 3a8c7eb..a7137ab 100644 --- a/src/com/ibm/ServerWizard2/view/GitDialog.java +++ b/src/com/ibm/ServerWizard2/view/GitDialog.java @@ -8,12 +8,13 @@ import java.util.Set; import java.util.Vector; +import javax.swing.JTextField; + import org.apache.logging.log4j.Level; import org.apache.logging.log4j.status.StatusLogger; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.ListViewer; @@ -42,7 +43,7 @@ import org.eclipse.wb.swt.SWTResourceManager; -public class GitDialog extends Dialog { +public class GitDialog extends Dialog { private Text txtNewRepo; Github git = new Github(ServerWizard2.GIT_LOCATION); @@ -57,6 +58,8 @@ public class GitDialog extends Dialog { private Button btnNeedsPassword; private Button btnRefresh; private Text txtLocation; + JTextField Jtext; + private Text txtBranch; /** * Create the dialog. @@ -93,7 +96,6 @@ protected Control createDialogArea(Composite parent) { lblGitRepositoryUrl.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); lblGitRepositoryUrl.setText("Git Repository URL:"); listViewer = new ListViewer(container, SWT.BORDER | SWT.V_SCROLL); - List repositoryList = listViewer.getList(); repositoryList.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); repositoryList.addSelectionListener(new SelectionAdapter() { @@ -214,36 +216,36 @@ public void widgetSelected(SelectionEvent arg0) { .getElementAt(listViewer.getList().getSelectionIndex()); try { boolean Alert = false; - boolean cmnMrwUrl = g.getRemoteUrl().contains("common-mrw"); + boolean cmnMrwUrl = g.getRemoteUrl().contains("common-mrw"); if (!g.isCloned()) { - if(cmnMrwUrl){ + g.cloneRepository(); + if(cmnMrwUrl) { ServerWizard2.DEFAULT_REMOTE_URL = g.getRemoteUrl(); } - g.cloneRepository(); } else if(cmnMrwUrl) { Alert = MessageDialog.openConfirm(null, "ALERT", "A Common mrw Repo already exists in disk.\n" +"It will overlay on the existing repo in disk.\n" - +"Please delete it in disk and reload with this " - +"if need this as base, Confirm to Overlay"); + + "Please delete it in disk and reload with this "+ + " if need this as base, Confirm to Overlay"); } org.eclipse.jgit.api.Status status = g.status(); if(Alert || !cmnMrwUrl) { - if (!status.isClean()) { - boolean reset = MessageDialog.openQuestion(null, "Repository is Modified", - "The local repository for:\n" + g.getRemoteUrl() + "\n" + if (!status.isClean()) { + boolean reset = MessageDialog.openQuestion(null, "Repository is Modified", + "The local repository for:\n" + g.getRemoteUrl() + "\n" + "has been modified. Would you like to ignore changes and reset?"); - if (reset) { - String r = g.fetch(true); + if (reset) { + String r = g.fetch(true); ServerwizMessageDialog.openInformation(null, "Refresh Complete", "Reset Successful"); - } - } else { - String r = g.fetch(false); - ServerwizMessageDialog.openInformation(null, "Refresh Complete", "Message: " + r); - } - MessageDialog.openInformation(null, "Alert!!", "Please rerun the project for model to load"); + } + } else { + String r = g.fetch(false); + ServerwizMessageDialog.openInformation(null, "Refresh Complete", "Message: " + r); + } + MessageDialog.openInformation(null, "Alert!!", "Please rerun the project for model to load"); } } catch (Exception e) { ServerwizMessageDialog.openError(null, "Git Refresh: " + g.getRemoteUrl(), e.getMessage()); @@ -279,6 +281,12 @@ public void widgetSelected(SelectionEvent arg0) { } git.getRepositories().remove(g); listViewer.refresh(); + g = null; + if(listViewer.getList().getItemCount() == 0) + { + MessageDialog.openInformation(null, "NEW", " No items"); + git.getRepositories().removeAllElements(); + } } }); btnDelete.setText("Delete"); @@ -292,8 +300,8 @@ public void widgetSelected(SelectionEvent arg0) { Composite composite_2 = new Composite(container, SWT.NONE); composite_2.setLayout(new RowLayout(SWT.HORIZONTAL)); GridData gd_composite_2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); - gd_composite_2.widthHint = 354; - gd_composite_2.heightHint = 46; + gd_composite_2.widthHint = 370; + gd_composite_2.heightHint = 50; composite_2.setLayoutData(gd_composite_2); Label lblNewRepository = new Label(composite_2, SWT.NONE); @@ -304,6 +312,18 @@ public void widgetSelected(SelectionEvent arg0) { txtNewRepo = new Text(composite_2, SWT.BORDER); txtNewRepo.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); txtNewRepo.setLayoutData(new RowData(234, SWT.DEFAULT)); + + Label lblBranch = new Label(composite_2, SWT.NONE); + lblBranch.setLayoutData(new RowData(95, SWT.DEFAULT)); + lblBranch.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); + lblBranch.setText("Branch name:"); + + txtBranch = new Text(composite_2, SWT.BORDER); + txtBranch.setFont(SWTResourceManager.getFont("Arial", 9, SWT.ITALIC)); + txtBranch.setLayoutData(new RowData(200, SWT.DEFAULT)); + txtBranch.setText("branch name"); + + Composite composite_1 = new Composite(container, SWT.NONE); RowLayout rl_composite_1 = new RowLayout(SWT.HORIZONTAL); @@ -316,7 +336,7 @@ public void widgetSelected(SelectionEvent arg0) { btnNeedsPassword = new Button(composite_1, SWT.CHECK); btnNeedsPassword.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); - btnNeedsPassword.setLayoutData(new RowData(148, 40)); + btnNeedsPassword.setLayoutData(new RowData(148, 20)); btnNeedsPassword.setText("Needs Password?"); Button btnAddRemote = new Button(composite_1, SWT.NONE); @@ -330,6 +350,11 @@ public void widgetSelected(SelectionEvent arg0) { ServerwizMessageDialog.openError(null, "Error", "Repository URL is blank"); return; } + String branch = txtBranch.getText(); + if(!ServerWizard2.branchName.equals(branch)) + { + ServerWizard2.branchName = branch; + } GithubRepository g = new GithubRepository(repo, git.getLocation(), btnNeedsPassword.getSelection()); g.setShell(getShell()); if (git.isRepository(g)) { @@ -341,14 +366,13 @@ public void widgetSelected(SelectionEvent arg0) { boolean Alert = true; if((!ServerWizard2.DEFAULT_REMOTE_URL.isEmpty()) && (g.getRemoteUrl().contains("common-mrw"))) { - Alert = MessageDialog.openConfirm(null, "ALERT", "A Common mrw Repo already exists in disk.\n " - +"It will be overlaid on the repo existing in disk.\n " - +"Please delete it in disk and refresh with this if need this as base, Confirm to Overlay!!!!"); + Alert = MessageDialog.openConfirm(null, "ALERT", "A Common mrw Repo already exists in disk.\n It will be overlaid on the repo existing in disk.\n Please delete it in disk and refresh with this if need this as base, Confirm to Overlay!!!!"); } if(Alert) { g.cloneRepository(); } + git.getRepositories().add(g); txtNewRepo.setText(""); listViewer.refresh(); @@ -434,6 +458,7 @@ public void getRepositories() { if (newFile) { p.setProperty("repositories", ServerWizard2.DEFAULT_REMOTE_URL); + p.setProperty("branch_name", ServerWizard2.branchName); p.setProperty("needs_password", "false"); } String repos = p.getProperty("repositories");