diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/ibm/ServerWizard2/utility/GitProgressMonitor.java | 37 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/utility/Github.java | 50 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/utility/GithubRepository.java | 212 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/GitDialog.java | 392 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/MainDialog.java | 168 | ||||
-rw-r--r-- | src/com/ibm/ServerWizard2/view/PasswordPrompt.java | 92 |
6 files changed, 871 insertions, 80 deletions
diff --git a/src/com/ibm/ServerWizard2/utility/GitProgressMonitor.java b/src/com/ibm/ServerWizard2/utility/GitProgressMonitor.java new file mode 100644 index 0000000..232424d --- /dev/null +++ b/src/com/ibm/ServerWizard2/utility/GitProgressMonitor.java @@ -0,0 +1,37 @@ +package com.ibm.ServerWizard2.utility;
+
+public class GitProgressMonitor implements org.eclipse.jgit.lib.ProgressMonitor {
+
+ javax.swing.ProgressMonitor pim;
+ private int progress = 0;
+ public GitProgressMonitor(javax.swing.ProgressMonitor pim) {
+ this.pim = pim;
+ }
+
+ public void beginTask(String arg0, int arg1) {
+ progress = 0;
+ pim.setNote(arg0);
+ pim.setMaximum(arg1);
+ }
+
+ @Override
+ public void endTask() {
+ pim.close();
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return pim.isCanceled();
+ }
+
+ @Override
+ public void start(int arg0) {
+ progress = 0;
+ }
+
+ @Override
+ public void update(int arg0) {
+ progress = progress+arg0;
+ pim.setProgress(progress);
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/utility/Github.java b/src/com/ibm/ServerWizard2/utility/Github.java new file mode 100644 index 0000000..b990118 --- /dev/null +++ b/src/com/ibm/ServerWizard2/utility/Github.java @@ -0,0 +1,50 @@ +package com.ibm.ServerWizard2.utility;
+
+import java.io.File;
+import java.util.Vector;
+
+public class Github {
+ private Vector<GithubRepository> repositories = new Vector<GithubRepository>();
+
+ public Github() {
+ File f = new File(GithubRepository.GIT_LOCAL_LOCATION);
+ if (!f.exists()) {
+ f.mkdirs();
+ }
+ }
+
+ 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;
+ }
+
+ public String getRepositoriesStr() {
+ String repos[] = new String[this.repositories.size()];
+ for (int i = 0; i < this.repositories.size(); i++) {
+ repos[i] = this.repositories.get(i).getRemoteUrl();
+ }
+ return String.join(",", repos);
+ }
+
+ public String getPasswordStr() {
+ String repos[] = new String[this.repositories.size()];
+ for (int i = 0; i < this.repositories.size(); i++) {
+ repos[i] = this.repositories.get(i).needsPasswordStr();
+ }
+ return String.join(",", repos);
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/utility/GithubRepository.java b/src/com/ibm/ServerWizard2/utility/GithubRepository.java new file mode 100644 index 0000000..fc94f1d --- /dev/null +++ b/src/com/ibm/ServerWizard2/utility/GithubRepository.java @@ -0,0 +1,212 @@ +package com.ibm.ServerWizard2.utility;
+
+import java.io.File;
+import java.util.Collection;
+
+import javax.swing.ProgressMonitor;
+
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.RebaseResult;
+import org.eclipse.jgit.api.ResetCommand.ResetType;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.lib.RepositoryCache;
+import org.eclipse.jgit.transport.FetchResult;
+import org.eclipse.jgit.transport.RefSpec;
+import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
+import org.eclipse.jgit.util.FS;
+
+import com.ibm.ServerWizard2.ServerWizard2;
+import com.ibm.ServerWizard2.view.PasswordPrompt;
+
+public class GithubRepository implements Comparable<GithubRepository> {
+ private String remoteUrl;
+ private File rootDirectory;
+ private File gitDirectory;
+ 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) {
+ this.remoteUrl = remoteUrl;
+ this.needsPassword = needsPassword;
+ File f = new File(remoteUrl);
+ String localPath = GIT_LOCAL_LOCATION + File.separator + f.getName().replace(".git", "");
+ rootDirectory = new File(localPath);
+ gitDirectory = new File(localPath + File.separator + ".git");
+ cloned = false;
+ if (RepositoryCache.FileKey.isGitRepository(this.getGitDirectory(), FS.DETECTED)) {
+ cloned = true;
+ }
+ }
+
+ public File getRootDirectory() {
+ return rootDirectory;
+ }
+
+ public File getGitDirectory() {
+ return gitDirectory;
+ }
+
+ public void getPassword() {
+ if (!this.needsPassword) {
+ credentials = new UsernamePasswordCredentialsProvider("", "");
+ return;
+ }
+ PasswordPrompt dlg = new PasswordPrompt(null, this.remoteUrl);
+ dlg.open();
+ credentials = new UsernamePasswordCredentialsProvider("", dlg.passwd);
+ passwordValidated = false;
+ }
+
+ public String getRemoteUrl() {
+ return this.remoteUrl;
+ }
+ public boolean needsPassword() {
+ return this.needsPassword;
+ }
+ public String needsPasswordStr() {
+ if (this.needsPassword) {
+ return "true";
+ }
+ return "false";
+ }
+
+ public void checkRemote() throws Exception {
+ if (!passwordValidated) {
+ this.getPassword();
+ }
+
+ Collection<Ref> refs;
+ boolean found = false;
+
+ try {
+ refs = Git.lsRemoteRepository().setCredentialsProvider(credentials).setHeads(true).setTags(true)
+ .setRemote(this.remoteUrl).call();
+ if (!refs.isEmpty()) {
+ found = true;
+ passwordValidated = true;
+ for (Ref ref : refs) {
+ ServerWizard2.LOGGER.info("Ref: " + ref);
+ }
+ }
+ } catch (Exception e) {
+ ServerWizard2.LOGGER.severe(e.getMessage());
+ }
+ if (!found) {
+ passwordValidated = false;
+ throw new Exception("Invalid Remote Repository or bad Password:\n" + this.getRemoteUrl());
+ }
+ }
+
+ public void cloneRepository() throws Exception {
+ if (!passwordValidated) {
+ this.getPassword();
+ }
+ if (isCloned()) {
+ return;
+ }
+ ServerWizard2.LOGGER.info("Cloning " + this.remoteUrl + " into " + this.getRootDirectory().getAbsolutePath());
+ cloned = false;
+ try {
+ ProgressMonitor pim = new ProgressMonitor(null, "Cloning...", "", 0, 1);
+ GitProgressMonitor gpim = new GitProgressMonitor(pim);
+ Git result = Git.cloneRepository()
+ .setCredentialsProvider(credentials)
+ .setProgressMonitor(gpim)
+ .setURI(this.getRemoteUrl()).setDirectory(this.getRootDirectory()).call();
+
+ cloned = true;
+ result.close();
+ } catch (Exception e1) {
+ ServerWizard2.LOGGER.severe(e1.getMessage());
+ passwordValidated = false;
+ throw new Exception("Unable to clone");
+ }
+ }
+
+ public void fetch(boolean reset) {
+ if (!passwordValidated) {
+ this.getPassword();
+ }
+
+ ServerWizard2.LOGGER.info("Fetching " + this.rootDirectory.getAbsolutePath());
+
+ try {
+ ProgressMonitor pim = new ProgressMonitor(null, "Fetching...", "", 0, 1);
+ GitProgressMonitor gpim = new GitProgressMonitor(pim);
+ Git result = Git.open(this.rootDirectory);
+ FetchResult fetch = result.fetch().setRemote(this.getRemoteUrl()).setCredentialsProvider(credentials)
+ .setProgressMonitor(gpim).setRefSpecs(refSpec).call();
+
+ ServerWizard2.LOGGER.info(fetch.getMessages());
+ if (reset) {
+ ServerWizard2.LOGGER.info("Resetting to head: " + this.getRemoteUrl());
+ result.reset().setMode(ResetType.HARD).call();
+ } else {
+ ServerWizard2.LOGGER.info("Rebase: " + this.getRemoteUrl());
+ RebaseResult r = result.rebase().setUpstream("refs/remotes/origin/master").call();
+ ServerWizard2.LOGGER.info(r.getStatus().toString());
+ }
+ result.close();
+ } catch (Exception e1) {
+ passwordValidated = false;
+ ServerWizard2.LOGGER.severe(e1.getMessage());
+ }
+ }
+
+ public org.eclipse.jgit.api.Status status() {
+ org.eclipse.jgit.api.Status status = null;
+ try {
+ ProgressMonitor pim = new ProgressMonitor(null, "Fetching...", "", 0, 1);
+ GitProgressMonitor gpim = new GitProgressMonitor(pim);
+ Git result = Git.open(this.getRootDirectory());
+ status = result.status().setProgressMonitor(gpim).call();
+
+ result.close();
+ } catch (Exception e1) {
+ ServerWizard2.LOGGER.severe(e1.getMessage());
+ status = null;
+ }
+ return status;
+ }
+
+ public boolean isCloned() {
+ return cloned;
+ }
+
+ public void clear() {
+ // make sure stored password is destroyed
+ credentials.clear();
+ }
+
+ public String toString() {
+ return this.remoteUrl + "; " + this.getGitDirectory().getAbsolutePath() + "; " + this.needsPasswordStr();
+ }
+
+ @Override
+ public int compareTo(GithubRepository o) {
+ return this.getRemoteUrl().compareTo(o.getRemoteUrl());
+ }
+
+ public boolean equals(Object o) {
+ if (o == null)
+ return false;
+ if (o == this)
+ return true;
+
+ if (o instanceof String) {
+ String s = (String) o;
+ if (this.getRemoteUrl().equals(s)) {
+ return true;
+ }
+ return false;
+ } else if (o instanceof GithubRepository) {
+ GithubRepository p = (GithubRepository) o;
+ return this.compareTo(p) == 0 ? true : false;
+ }
+ return false;
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/view/GitDialog.java b/src/com/ibm/ServerWizard2/view/GitDialog.java new file mode 100644 index 0000000..1725b15 --- /dev/null +++ b/src/com/ibm/ServerWizard2/view/GitDialog.java @@ -0,0 +1,392 @@ +package com.ibm.ServerWizard2.view;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+import java.util.Set;
+import java.util.Vector;
+
+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.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.List;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import com.ibm.ServerWizard2.ServerWizard2;
+import com.ibm.ServerWizard2.utility.Github;
+import com.ibm.ServerWizard2.utility.GithubRepository;
+
+public class GitDialog extends Dialog {
+ private Text txtNewRepo;
+ Github git = new Github();
+
+ 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;
+ private Button btnRemoved;
+ private Button btnChanged;
+ private Button btnConflicting;
+ private Button btnUntracked;
+ private Button btnMissing;
+ private Button btnNeedsPassword;
+ private Button btnRefresh;
+
+ /**
+ * Create the dialog.
+ *
+ * @param parentShell
+ */
+ public GitDialog(Shell parentShell) {
+ super(parentShell);
+ StatusLogger.getLogger().setLevel(Level.FATAL);
+ }
+
+ private boolean isStatusSet(Set<String> status) {
+ if (status.size() > 0) {
+ for (String s : status) {
+ ServerWizard2.LOGGER.info(s);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Create contents of the dialog.
+ *
+ * @param parent
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite container = (Composite) super.createDialogArea(parent);
+ listViewer = new ListViewer(container, SWT.BORDER | SWT.V_SCROLL);
+
+ List repositoryList = listViewer.getList();
+ repositoryList.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ if (listViewer.getList().getSelectionCount() == 0) {
+ return;
+ }
+ GithubRepository g = (GithubRepository) listViewer
+ .getElementAt(listViewer.getList().getSelectionIndex());
+ txtNewRepo.setText(g.getRemoteUrl());
+ btnNeedsPassword.setSelection(g.needsPassword());
+ if (g.isCloned()) {
+ btnCloned.setSelection(true);
+ org.eclipse.jgit.api.Status status = g.status();
+ if (status != null) {
+ btnAdded.setSelection(isStatusSet(status.getAdded()));
+ btnRemoved.setSelection(isStatusSet(status.getRemoved()));
+ btnChanged.setSelection(isStatusSet(status.getChanged()) | isStatusSet(status.getModified()));
+ btnConflicting.setSelection(isStatusSet(status.getConflicting()));
+ btnUntracked.setSelection(isStatusSet(status.getUntracked()));
+ btnMissing.setSelection(isStatusSet(status.getMissing()));
+ } else {
+ MessageDialog.openError(null, "Git Error",
+ "The Git Repository has been modified. Please restart Serverwiz." + g.getRemoteUrl());
+ }
+ } else {
+ btnCloned.setSelection(false);
+ }
+ }
+ });
+ GridData gd_repositoryList = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_repositoryList.widthHint = 314;
+ gd_repositoryList.heightHint = 164;
+ repositoryList.setLayoutData(gd_repositoryList);
+
+ Composite composite = new Composite(container, SWT.NONE);
+ composite.setLayout(new GridLayout(5, false));
+ GridData gd_composite = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_composite.widthHint = 355;
+ gd_composite.heightHint = 48;
+ composite.setLayoutData(gd_composite);
+ composite.setEnabled(false);
+
+ Label lblNewLabel = new Label(composite, SWT.NONE);
+ lblNewLabel.setText("Status:");
+
+ btnCloned = new Button(composite, SWT.CHECK);
+ btnCloned.setText("Cloned");
+
+ btnAdded = new Button(composite, SWT.CHECK);
+ btnAdded.setText("Added");
+
+ btnRemoved = new Button(composite, SWT.CHECK);
+ btnRemoved.setText("Removed");
+
+ btnChanged = new Button(composite, SWT.CHECK);
+ btnChanged.setText("Changed");
+ new Label(composite, SWT.NONE);
+ new Label(composite, SWT.NONE);
+
+ btnConflicting = new Button(composite, SWT.CHECK);
+ btnConflicting.setText("Conflicting");
+
+ btnUntracked = new Button(composite, SWT.CHECK);
+ btnUntracked.setText("Untracked");
+
+ btnMissing = new Button(composite, SWT.CHECK);
+ btnMissing.setText("Missing");
+
+ Composite composite_3 = new Composite(container, SWT.NONE);
+ composite_3.setLayout(new RowLayout(SWT.HORIZONTAL));
+ GridData gd_composite_3 = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+ gd_composite_3.widthHint = 194;
+ gd_composite_3.heightHint = 36;
+ composite_3.setLayoutData(gd_composite_3);
+
+ btnRefresh = new Button(composite_3, SWT.NONE);
+ btnRefresh.setLayoutData(new RowData(80, SWT.DEFAULT));
+ btnRefresh.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ if (listViewer.getList().getSelectionCount() == 0) {
+ return;
+ }
+ GithubRepository g = (GithubRepository) listViewer
+ .getElementAt(listViewer.getList().getSelectionIndex());
+ try {
+ if (!g.isCloned()) {
+ g.cloneRepository();
+ }
+ org.eclipse.jgit.api.Status status = g.status();
+ if (!status.isClean()) {
+ boolean reset = MessageDialog.openConfirm(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) {
+ g.fetch(true);
+ MessageDialog.openInformation(null, "Refresh Complete", "Refresh Complete");
+
+ }
+ } else {
+ g.fetch(false);
+ MessageDialog.openInformation(null, "Refresh Complete", "Refresh Complete");
+ }
+ } catch (Exception e) {
+ MessageDialog.openError(null, "Git Refresh Error", "Unable to refresh: " + g.getRemoteUrl());
+ }
+ }
+ });
+
+ btnRefresh.setText("Refresh");
+
+ Button btnDummy = new Button(composite_3, SWT.NONE);
+ btnDummy.setLayoutData(new RowData(14, SWT.DEFAULT));
+ btnDummy.setVisible(false);
+ btnDummy.setText("New Button");
+
+ Button btnDelete = new Button(composite_3, SWT.NONE);
+ btnDelete.setLayoutData(new RowData(80, SWT.DEFAULT));
+ btnDelete.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ if (listViewer.getList().getSelectionCount() == 0) {
+ return;
+ }
+ GithubRepository g = (GithubRepository) listViewer
+ .getElementAt(listViewer.getList().getSelectionIndex());
+ if (g.getRemoteUrl().equals(DEFAULT_REPO)) {
+ MessageDialog.openError(null, "Error", "Deleting of default repository is not allowed");
+ } else {
+ git.getRepositories().remove(g);
+ listViewer.refresh();
+ }
+ }
+ });
+ btnDelete.setText("Delete");
+
+ Label label = new Label(container, SWT.SEPARATOR | SWT.HORIZONTAL);
+ GridData gd_label = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
+ gd_label.widthHint = 353;
+ label.setLayoutData(gd_label);
+
+ Composite composite_2 = new Composite(container, SWT.NONE);
+ composite_2.setLayout(new RowLayout(SWT.HORIZONTAL));
+ GridData gd_composite_2 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+ gd_composite_2.widthHint = 354;
+ gd_composite_2.heightHint = 31;
+ composite_2.setLayoutData(gd_composite_2);
+
+ Label lblNewRepository = new Label(composite_2, SWT.NONE);
+ lblNewRepository.setText("New Repository:");
+
+ txtNewRepo = new Text(composite_2, SWT.BORDER);
+ txtNewRepo.setLayoutData(new RowData(249, SWT.DEFAULT));
+
+ Composite composite_1 = new Composite(container, SWT.NONE);
+ RowLayout rl_composite_1 = new RowLayout(SWT.HORIZONTAL);
+ rl_composite_1.center = true;
+ composite_1.setLayout(rl_composite_1);
+ GridData gd_composite_1 = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
+ gd_composite_1.widthHint = 252;
+ gd_composite_1.heightHint = 30;
+ composite_1.setLayoutData(gd_composite_1);
+
+ btnNeedsPassword = new Button(composite_1, SWT.CHECK);
+ btnNeedsPassword.setLayoutData(new RowData(148, SWT.DEFAULT));
+ btnNeedsPassword.setText("Needs Password?");
+
+ Button btnAddRemote = new Button(composite_1, SWT.NONE);
+ btnAddRemote.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ String repo = txtNewRepo.getText();
+ if (repo.isEmpty()) {
+ MessageDialog.openError(null, "Error", "Repository URL is blank");
+ return;
+ }
+ GithubRepository g = new GithubRepository(repo, btnNeedsPassword.getSelection());
+ if (git.isRepository(g)) {
+ MessageDialog.openError(null, "Error", "Repository already exists");
+ }
+ try {
+ g.checkRemote();
+ g.cloneRepository();
+ git.getRepositories().add(g);
+ txtNewRepo.setText("");
+ listViewer.refresh();
+ } catch (Exception e) {
+ MessageDialog.openError(null, "Error", e.getMessage());
+ }
+ }
+ });
+ btnAddRemote.setText("Add Remote");
+
+ listViewer.setLabelProvider(new LabelProvider() {
+ public Image getImage(Object element) {
+ return null;
+ }
+
+ public String getText(Object element) {
+ GithubRepository g = (GithubRepository) element;
+ return g.getRemoteUrl();
+ }
+ });
+ listViewer.setContentProvider(new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ @SuppressWarnings("rawtypes")
+ Vector v = (Vector) inputElement;
+ return v.toArray();
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void inputChanged(Viewer arg0, Object arg1, Object arg2) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+ listViewer.setInput(git.getRepositories());
+ this.getRepositories();
+ listViewer.refresh();
+ return container;
+ }
+
+ /**
+ * Create contents of the button bar.
+ *
+ * @param parent
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ Button button = createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ button.setText("Exit");
+ }
+
+ /**
+ * Return the initial size of the dialog.
+ */
+ @Override
+ protected Point getInitialSize() {
+ return new Point(382, 457);
+ }
+
+ public void getRepositories() {
+ try {
+ boolean newFile = false;
+ File f = new File(PROPERTIES_FILE);
+ if (!f.exists()) {
+ ServerWizard2.LOGGER.info("Preferences file doesn't exist, creating...");
+ f.createNewFile();
+ newFile = true;
+ }
+ FileInputStream propFile = new FileInputStream(PROPERTIES_FILE);
+ Properties p = new Properties();
+ p.load(propFile);
+ propFile.close();
+
+ if (newFile) {
+ p.setProperty("repositories", DEFAULT_REPO);
+ p.setProperty("needs_password", "false");
+ }
+ String repos = p.getProperty("repositories");
+ String pass = p.getProperty("needs_password");
+ String repo[] = repos.split(",");
+ String needsPass[] = pass.split(",");
+ git.getRepositories().removeAllElements();
+
+ for (int i = 0; i < repo.length; i++) {
+ boolean n = false;
+ if (needsPass[i].equals("true")) {
+ n = true;
+ }
+ git.addRepository(repo[i], n);
+ }
+ } catch (Exception e) {
+ ServerWizard2.LOGGER.severe(e.getMessage());
+ }
+ }
+
+ public boolean close() {
+ Properties p = new Properties();
+ try {
+ FileOutputStream out = new FileOutputStream(PROPERTIES_FILE);
+ String repo = git.getRepositoriesStr();
+ String pass = git.getPasswordStr();
+ p.setProperty("repositories", repo);
+ p.setProperty("needs_password", pass);
+ p.store(out, "");
+ out.close();
+ } catch (IOException e) {
+ ServerWizard2.LOGGER.severe("Unable to write preferences file");
+ }
+ return super.close();
+ }
+
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText("Manage Git Repositories");
+ }
+}
diff --git a/src/com/ibm/ServerWizard2/view/MainDialog.java b/src/com/ibm/ServerWizard2/view/MainDialog.java index bb472a6..3e7549f 100644 --- a/src/com/ibm/ServerWizard2/view/MainDialog.java +++ b/src/com/ibm/ServerWizard2/view/MainDialog.java @@ -1,8 +1,10 @@ package com.ibm.ServerWizard2.view; -import java.util.Map; +import java.io.File; import java.util.Vector; +import javax.swing.ProgressMonitor; + import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -48,13 +50,29 @@ import org.eclipse.wb.swt.SWTResourceManager; import com.ibm.ServerWizard2.ServerWizard2; import com.ibm.ServerWizard2.controller.TargetWizardController; -import com.ibm.ServerWizard2.model.Attribute; import com.ibm.ServerWizard2.model.Connection; import com.ibm.ServerWizard2.model.ConnectionEndpoint; import com.ibm.ServerWizard2.model.Field; import com.ibm.ServerWizard2.model.Target; +import com.ibm.ServerWizard2.utility.GitProgressMonitor; +import com.ibm.ServerWizard2.utility.Github; import com.ibm.ServerWizard2.utility.GithubFile; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.RebaseResult; +import org.eclipse.jgit.api.ResetCommand; +import org.eclipse.jgit.api.ResetCommand.ResetType; +import org.eclipse.jgit.api.StatusCommand; +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.lib.TextProgressMonitor; +import org.eclipse.jgit.transport.FetchResult; +import org.eclipse.jgit.transport.RefSpec; + + + public class MainDialog extends Dialog { private TableViewer viewer; private Tree tree; @@ -79,6 +97,7 @@ public class MainDialog extends Dialog { private Button btnDeleteTarget; private Button btnSave; private Button btnOpen; + private Button btnClone; private Button btnOpenLib; private Button btnDeleteConnection; private Button btnSaveAs; @@ -169,7 +188,7 @@ public class MainDialog extends Dialog { buttonRow1 = new Composite(container, SWT.NONE); GridData gd_buttonRow1 = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1); - gd_buttonRow1.widthHint = 789; + gd_buttonRow1.widthHint = 850; buttonRow1.setLayoutData(gd_buttonRow1); GridLayout rl_buttonRow1 = new GridLayout(18, false); buttonRow1.setLayout(rl_buttonRow1); @@ -243,11 +262,11 @@ public class MainDialog extends Dialog { btnDeleteTarget.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); btnDeleteTarget.setText("Delete Instance"); - btnShowHidden = new Button(compositeInstance, SWT.CHECK); - GridData gd_btnShowHidden = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); - gd_btnShowHidden.heightHint = 20; - btnShowHidden.setLayoutData(gd_btnShowHidden); - btnShowHidden.setText(" Show Hidden"); + btnShowHidden = new Button(compositeInstance, SWT.CHECK); + GridData gd_btnShowHidden = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnShowHidden.heightHint = 20; + btnShowHidden.setLayoutData(gd_btnShowHidden); + btnShowHidden.setText(" Show Hidden"); btnCopyInstance = new Button(compositeInstance, SWT.NONE); btnCopyInstance.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1)); @@ -332,10 +351,8 @@ public class MainDialog extends Dialog { listBusses = new List(sashForm, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); this.addEvents(); - - controller.init(); - this.setDirtyState(false); + // load file if passed on command line if (!mrwFilename.isEmpty()) { controller.readXML(mrwFilename); @@ -345,8 +362,8 @@ public class MainDialog extends Dialog { cmbBusses.add(t.getType()); cmbBusses.setData(t.getType(), t); } + attributes = new Vector<Field>(); this.initInstanceMode(); - // columnName.setWidth(200); sashForm.setWeights(new int[] { 1, 1 }); columnName.pack(); @@ -380,12 +397,8 @@ public class MainDialog extends Dialog { try { controller.initModel(); setFilename(""); - initAll(); + initInstanceMode(); setDirtyState(false); - refreshInstanceTree(); - refreshConnections(); - updateView(); - } catch (Exception e1) { e1.printStackTrace(); } @@ -417,7 +430,7 @@ public class MainDialog extends Dialog { } Boolean dirty = controller.readXML(filename); setFilename(filename); - initAll(); + initInstanceMode(); setDirtyState(dirty); } }); @@ -481,6 +494,22 @@ public class MainDialog extends Dialog { gd_sep.widthHint = 30; label.setLayoutData(gd_sep); + btnClone = createButton(row1, IDialogConstants.NO_ID, "Manage Git", false); + GridData gd_btnClone = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); + gd_btnClone.widthHint = 90; + + btnClone.setLayoutData(gd_btnClone); + btnClone.setFont(SWTResourceManager.getFont("Arial", 9, SWT.NORMAL)); + btnClone.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + GitDialog dlg = new GitDialog(btnClone.getShell()); + dlg.open(); + } + }); + btnClone.setToolTipText("Retrieves Library from github"); + + btnOpenLib = createButton(row1, IDialogConstants.NO_ID, "Open Lib", false); GridData gd_btnOpenLib = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); gd_btnOpenLib.widthHint = 90; @@ -569,11 +598,6 @@ public class MainDialog extends Dialog { return null; } - private void initAll() { - tabFolder.setSelection(0); - initInstanceMode(); - } - private void initBusMode() { busMode = true; this.lblBusDirections.setEnabled(true); @@ -590,24 +614,24 @@ public class MainDialog extends Dialog { } if (cmbCards.getItemCount() > 0) { cmbCards.select(-1); - //this.targetForConnections = (Target)cmbCards.getData(); } for (TreeItem item : tree.getItems()) { Target target = (Target) item.getData(); - // controller.getRootTarget().hideBusses(); controller.hideBusses(target); } - - this.source = null; this.dest = null; this.selectedEndpoint = null; refreshInstanceTree(); refreshConnections(); + attributes.clear(); + viewer.setInput(attributes); + viewer.refresh(); this.updateView(); } private void initInstanceMode() { + tabFolder.setSelection(0); busMode = false; this.lblInstanceDirections.setEnabled(true); this.lblInstanceDirections.setVisible(true); @@ -618,6 +642,10 @@ public class MainDialog extends Dialog { this.targetForConnections = null; this.refreshInstanceTree(); this.listBusses.removeAll(); + refreshConnections(); + attributes.clear(); + viewer.setInput(attributes); + viewer.refresh(); this.updateView(); } @@ -637,6 +665,10 @@ public class MainDialog extends Dialog { } } + /* + * Updates button enabled states based on if target is selected + * Also updates attribute table based on selected target + */ private void updateView() { Target targetInstance = getSelectedTarget(); if (targetInstance == null) { @@ -650,10 +682,13 @@ public class MainDialog extends Dialog { updatePopupMenu(targetInstance); updateChildCombo(targetInstance); + //A target is selected so show the associated attributes TreeItem item = tree.getSelection()[0]; ConnectionEndpoint ep = this.getEndpoint(item, null); - refreshAttributes(targetInstance,ep); - + attributes = controller.getAttributesAndGlobals(targetInstance, "/"+ep.getName()); + viewer.setInput(attributes); + viewer.refresh(); + if (targetInstance.isSystem()) { btnDeleteTarget.setEnabled(false); } else { @@ -667,7 +702,10 @@ public class MainDialog extends Dialog { btnDefaults.setEnabled(true); } - + /* + * Creates right-click popup menu for adding connections + * + */ private void updatePopupMenu(Target selectedTarget) { if (selectedTarget == null || tree.getSelectionCount()==0) { return; @@ -819,36 +857,6 @@ public class MainDialog extends Dialog { this.setFontStyle(item, SWT.BOLD | SWT.ITALIC, true); selectedEndpoint = item; } - - private void refreshAttributes(Target targetInstance,ConnectionEndpoint ep) { - attributes.clear(); - for (Map.Entry<String, Attribute> entry : targetInstance.getAttributes().entrySet()) { - - Attribute attribute = entry.getValue(); - if (!attribute.isHidden()) { - if (attribute.isGlobal() && !controller.getModelCreationMode()) { - if (ep !=null) { - String path="/"+ep.getName(); - Field field = controller.getGlobalSetting(path, attribute.name); - if (field==null) { - controller.setGlobalSetting(path, attribute.name, ""); - field = controller.getGlobalSetting(path, attribute.name); - } - field.type = attribute.getValue().getType(); - if (field.type.equals("enumeration")) { - field.enumerator = attribute.getValue().getFields().get(0).enumerator; - } - attributes.add(field); - } - } else { - for (Field field : attribute.getValue().getFields()) - attributes.add(field); - } - } - } - viewer.refresh(); - } - private void clearTreeAll() { if (tree.getItemCount() > 0) { clearTree(tree.getItem(0)); @@ -997,6 +1005,23 @@ public class MainDialog extends Dialog { } } + private void addConnection(Boolean cabled) { + Target busTarget = (Target) cmbBusses.getData(cmbBusses.getText()); + Connection conn = targetForConnections.addConnection(busTarget, source, dest, cabled); + this.addConnection(conn); + setDirtyState(true); + } + + private void deleteConnection() { + if (targetForConnections == null || listBusses.getSelectionCount() == 0) { + return; + } + Connection conn = (Connection) listBusses.getData(listBusses.getSelection()[0]); + controller.deleteConnection(targetForConnections, conn.busTarget, conn); + this.refreshConnections(); + setDirtyState(true); + } + private void setFontStyle(TreeItem item, int style, boolean selected) { if (item.isDisposed()) { return; @@ -1023,23 +1048,6 @@ public class MainDialog extends Dialog { return super.close(); } - private void addConnection(Boolean cabled) { - Target busTarget = (Target) cmbBusses.getData(cmbBusses.getText()); - Connection conn = targetForConnections.addConnection(busTarget, source, dest, cabled); - this.addConnection(conn); - setDirtyState(true); - } - - private void deleteConnection() { - if (targetForConnections == null || listBusses.getSelectionCount() == 0) { - return; - } - Connection conn = (Connection) listBusses.getData(listBusses.getSelection()[0]); - controller.deleteConnection(targetForConnections, conn.busTarget, conn); - this.refreshConnections(); - setDirtyState(true); - } - public void setDirtyState(Boolean dirty) { this.dirty = dirty; if (this.btnSave != null) { @@ -1196,7 +1204,9 @@ public class MainDialog extends Dialog { public void widgetSelected(SelectionEvent arg0) { if (listBusses.getSelectionCount() > 0) { Connection conn = (Connection) listBusses.getData(listBusses.getSelection()[0]); - refreshAttributes(conn.busTarget,null); + attributes = controller.getAttributesAndGlobals(conn.busTarget, ""); + viewer.setInput(attributes); + viewer.refresh(); } } }); @@ -1288,7 +1298,5 @@ public class MainDialog extends Dialog { }); viewer.setContentProvider(ArrayContentProvider.getInstance()); - attributes = new Vector<Field>(); - viewer.setInput(attributes); } } diff --git a/src/com/ibm/ServerWizard2/view/PasswordPrompt.java b/src/com/ibm/ServerWizard2/view/PasswordPrompt.java new file mode 100644 index 0000000..c8e6deb --- /dev/null +++ b/src/com/ibm/ServerWizard2/view/PasswordPrompt.java @@ -0,0 +1,92 @@ +package com.ibm.ServerWizard2.view;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+
+public class PasswordPrompt extends Dialog {
+ private Text text;
+ public char passwd[];
+ private String label;
+
+ /**
+ * Create the dialog.
+ * @param parentShell
+ */
+ public PasswordPrompt(Shell parentShell,String label) {
+ super(parentShell);
+ this.label = label;
+ }
+
+ /**
+ * Create contents of the dialog.
+ * @param parent
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ Composite container = (Composite) super.createDialogArea(parent);
+ GridLayout gridLayout = (GridLayout) container.getLayout();
+
+ Label lblEnterPasswordFor = new Label(container, SWT.NONE);
+ GridData gd_lblEnterPasswordFor = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_lblEnterPasswordFor.widthHint = 352;
+ gd_lblEnterPasswordFor.heightHint = 21;
+ lblEnterPasswordFor.setLayoutData(gd_lblEnterPasswordFor);
+ lblEnterPasswordFor.setText("Enter Password For:");
+
+ Label lblRepository = new Label(container, SWT.NONE);
+ GridData gd_lblRepository = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_lblRepository.widthHint = 419;
+ gd_lblRepository.heightHint = 20;
+ lblRepository.setLayoutData(gd_lblRepository);
+ lblRepository.setText(this.label);
+
+ Composite composite_1 = new Composite(container, SWT.NONE);
+ GridData gd_composite_1 = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
+ gd_composite_1.widthHint = 418;
+ gd_composite_1.heightHint = 38;
+ composite_1.setLayoutData(gd_composite_1);
+
+ text = new Text(composite_1, SWT.BORDER | SWT.PASSWORD);
+ text.setBounds(10, 10, 115, 21);
+
+ Button btnOk = new Button(composite_1, SWT.NONE);
+ btnOk.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ passwd = text.getTextChars();
+ close();
+ }
+ });
+ btnOk.setBounds(143, 6, 75, 25);
+ btnOk.setText("Ok");
+
+ return container;
+ }
+
+ /**
+ * Create contents of the button bar.
+ * @param parent
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ }
+
+ /**
+ * Return the initial size of the dialog.
+ */
+ @Override
+ protected Point getInitialSize() {
+ return new Point(447, 174);
+ }
+}
|