use of org.archicontribs.modelrepository.dialogs.NewModelRepoDialog in project archi-modelrepository-plugin by archi-contribs.
the class CreateRepoFromModelAction method run.
@Override
public void run() {
NewModelRepoDialog dialog = new NewModelRepoDialog(fWindow.getShell());
if (dialog.open() != Window.OK) {
return;
}
final String repoURL = dialog.getURL();
final String userName = dialog.getUsername();
final String userPassword = dialog.getPassword();
if (!StringUtils.isSet(repoURL) && !StringUtils.isSet(userName) && !StringUtils.isSet(userPassword)) {
return;
}
File localRepoFolder = new File(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(), GraficoUtils.getLocalGitFolderName(repoURL));
// Folder is not empty
if (localRepoFolder.exists() && localRepoFolder.isDirectory() && localRepoFolder.list().length > 0) {
MessageDialog.openError(fWindow.getShell(), Messages.CreateRepoFromModelAction_1, Messages.CreateRepoFromModelAction_2 + " " + // $NON-NLS-1$
localRepoFolder.getAbsolutePath());
return;
}
setRepository(new ArchiRepository(localRepoFolder));
/**
* Wrapper class to handle progress monitor
*/
class CreateRepoProgressHandler extends ProgressHandler {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
super.run(monitor);
try {
monitor.beginTask(Messages.CreateRepoFromModelAction_3, IProgressMonitor.UNKNOWN);
// Proxy check
ProxyAuthenticater.update(repoURL);
// Create a new repo
try (Git git = getRepository().createNewLocalGitRepository(repoURL)) {
}
// TODO: If the model has not been saved yet this is fine but if the model already exists
// We should tell the user this is the case
// Set new file location
fModel.setFile(getRepository().getTempModelFile());
// And Save it
IEditorModelManager.INSTANCE.saveModel(fModel);
// Export to Grafico
getRepository().exportModelToGraficoFiles();
monitor.subTask(Messages.CreateRepoFromModelAction_4);
// Commit changes
getRepository().commitChanges(Messages.CreateRepoFromModelAction_5, false);
monitor.subTask(Messages.CreateRepoFromModelAction_6);
// Push
getRepository().pushToRemote(userName, userPassword, null);
// Store repo credentials if option is set
if (ModelRepositoryPlugin.INSTANCE.getPreferenceStore().getBoolean(IPreferenceConstants.PREFS_STORE_REPO_CREDENTIALS)) {
SimpleCredentialsStorage sc = new SimpleCredentialsStorage(new File(getRepository().getLocalGitFolder(), IGraficoConstants.REPO_CREDENTIALS_FILE));
sc.store(userName, userPassword);
}
// Save the checksum
getRepository().saveChecksum();
} catch (GitAPIException | IOException | NoSuchAlgorithmException | URISyntaxException ex) {
displayErrorDialog(Messages.CreateRepoFromModelAction_7, ex);
} finally {
monitor.done();
}
}
}
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
try {
ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
pmDialog.run(false, true, new CreateRepoProgressHandler());
} catch (InvocationTargetException | InterruptedException ex) {
ex.printStackTrace();
}
}
});
}
Aggregations