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 common-mrw repo, Removal of hard code default #51

Open
wants to merge 1 commit 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
11 changes: 9 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,9 @@ 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 getVersionString() {
return VERSION_MAJOR+"."+VERSION_MINOR;
}
Expand All @@ -54,6 +54,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 @@ -149,6 +150,9 @@ private static void getPreferencesForUpdateMode() {
try {
Properties p = new Properties();
File f = new File(ServerWizard2.PROPERTIES_FILE);
Display display = new Display();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, these directory dialogs are not needed anymore. What purpose were they achieving?

Shell shell = new Shell(display);
DirectoryDialog fdlg = new DirectoryDialog(shell, SWT.OPEN);
if (!f.exists()) {
//File doesn't exist, so create;
ServerWizard2.LOGGER.info("Preferences file doesn't exist, creating...");
Expand Down Expand Up @@ -186,6 +190,7 @@ private static void getPreferences() {
try {
Properties p = new Properties();
File f = new File(ServerWizard2.PROPERTIES_FILE);
DirectoryDialog fdlg = new DirectoryDialog(shell, SWT.OPEN);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this change

if (!f.exists()) {
//File doesn't exist, so create; prompt user for git location
ServerWizard2.LOGGER.info("Preferences file doesn't exist, creating...");
Expand All @@ -197,6 +202,7 @@ private static void getPreferences() {
ServerWizard2.LOGGER.warning("No directory selected; exiting...");
System.exit(0);
}

p.setProperty("git_location", libPath);
p.setProperty("repositories", ServerWizard2.DEFAULT_REMOTE_URL);
p.setProperty("needs_password", "false");
Expand All @@ -205,6 +211,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
4 changes: 3 additions & 1 deletion 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 @@ -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) {
Expand Down
24 changes: 18 additions & 6 deletions src/com/ibm/ServerWizard2/view/GitDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -212,11 +213,17 @@ public void widgetSelected(SelectionEvent arg0) {
GithubRepository g = (GithubRepository) listViewer
.getElementAt(listViewer.getList().getSelectionIndex());
try {
ServerWizard2.DEFAULT_REMOTE_URL = g.getRemoteUrl();
boolean Alert = false;
if (!g.isCloned()) {
g.cloneRepository();
}
else if(g.getRemoteUrl().contains("common-mrw"))
{
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(Alert) {
if (!status.isClean()) {
boolean reset = MessageDialog.openQuestion(null, "Repository is Modified",
"The local repository for:\n" + g.getRemoteUrl() + "\n"
Expand All @@ -230,6 +237,8 @@ public void widgetSelected(SelectionEvent arg0) {
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 +271,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");
Expand Down Expand Up @@ -327,7 +332,14 @@ public void widgetSelected(SelectionEvent arg0) {
}
try {
g.checkRemote();
g.cloneRepository();
boolean Alert = false;
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