Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition/Deletion/Updation of repos, Removal of default Repo #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/com/ibm/ServerWizard2/ServerWizard2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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, "");
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/com/ibm/ServerWizard2/model/SystemModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions src/com/ibm/ServerWizard2/utility/GithubRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<GithubRepository> {
private String remoteUrl;
Expand All @@ -35,6 +36,7 @@ public class GithubRepository implements Comparable<GithubRepository> {
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);
Expand Down Expand Up @@ -124,8 +126,8 @@ 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();
} catch (Exception e1) {
Expand Down
90 changes: 68 additions & 22 deletions src/com/ibm/ServerWizard2/view/GitDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
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;
Expand Down Expand Up @@ -41,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);

Expand All @@ -56,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.
Expand Down Expand Up @@ -92,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() {
Expand Down Expand Up @@ -212,23 +215,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()) {
g.cloneRepository();
if(cmnMrwUrl) {
ServerWizard2.DEFAULT_REMOTE_URL = g.getRemoteUrl();
}
}
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");

}
} else {
String r = g.fetch(false);
ServerwizMessageDialog.openInformation(null, "Refresh Complete", "Message: " + r);
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");
}
} catch (Exception e) {
ServerwizMessageDialog.openError(null, "Git Refresh: " + g.getRemoteUrl(), e.getMessage());
Expand Down Expand Up @@ -262,12 +279,14 @@ 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();
}
g = null;
if(listViewer.getList().getItemCount() == 0)
{
MessageDialog.openInformation(null, "NEW", " No items");
git.getRepositories().removeAllElements();
}
}
});
btnDelete.setText("Delete");
Expand All @@ -281,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);
Expand All @@ -293,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);
Expand All @@ -305,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);
Expand All @@ -319,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)) {
Expand All @@ -327,7 +363,16 @@ 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();
Expand Down Expand Up @@ -413,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");
Expand Down