-
Notifications
You must be signed in to change notification settings - Fork 22
Switch branch Action #286
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
base: master
Are you sure you want to change the base?
Switch branch Action #286
Conversation
Remove the backlog link from the description. Instead add some description of what the pull request solves.
|
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/repositories/AbapGitView.java
Outdated
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/repositories/actions/SwitchbranchAction.java
Outdated
Show resolved
Hide resolved
...bapgit/adt/ui/internal/repositories/wizards/AbapGitWizardPageBranchSelectionCredentials.java
Outdated
Show resolved
Hide resolved
...dt.ui/src/org/abapgit/adt/ui/internal/repositories/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
...i/src/org/abapgit/adt/ui/internal/repositories/wizards/AbapGitWizardPageBranchSelection.java
Outdated
Show resolved
Hide resolved
...dt.ui/src/org/abapgit/adt/ui/internal/repositories/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
...dt.ui/src/org/abapgit/adt/ui/internal/repositories/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
...dt.ui/src/org/abapgit/adt/ui/internal/repositories/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
...dt.ui/src/org/abapgit/adt/ui/internal/repositories/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
...dt.ui/src/org/abapgit/adt/ui/internal/repositories/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
@aarnapant-sap Please also test the solution in a ABAP Cloud system, involving transport requests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Aarnav,
Overall looks good.
I have added some comments and questions. Please check them.
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/repositories/actions/SwitchbranchAction.java
Outdated
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
...dt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardPageRepositoryAndCredentials.java
Outdated
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardBranchSelection.java
Outdated
Show resolved
Hide resolved
....ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardPageBranchSelectionCredentials.java
Outdated
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/repositories/actions/SwitchbranchAction.java
Outdated
Show resolved
Hide resolved
....adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardPageSwitchBranchAndPackage.java
Outdated
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardSwitchBranch.java
Outdated
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardSwitchBranch.java
Outdated
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardSwitchBranch.java
Show resolved
Hide resolved
org.abapgit.adt.ui/src/org/abapgit/adt/ui/internal/wizards/AbapGitWizardSwitchBranch.java
Outdated
Show resolved
Hide resolved
public class TestPdeAbapGitRepositoriesSelectionWizard { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- More test cases can be covered like invalid package or exception while fetching repo type.
- Also a UI test can be added to open the wizard, validate the fields in first page, then navigate to next page and validate if the branches are correctly set as input for combo viewer, and switch the branch in combo viewer. The Finish action can be skipped.
…ted check to action
public PackageRefNotFoundException(String message) { | ||
super(message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of taking any parameters, the message can be directly set here itself.
if (getPackageAndRepoType(destination)) { | ||
WizardDialog dialog = new WizardDialog(this.AbapGitView.getViewSite().getShell(), | ||
new AbapGitWizardSwitchBranch(this.project, this.selRepo, destination)); | ||
dialog.open(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (getPackageAndRepoType(destination)) { | |
WizardDialog dialog = new WizardDialog(this.AbapGitView.getViewSite().getShell(), | |
new AbapGitWizardSwitchBranch(this.project, this.selRepo, destination)); | |
dialog.open(); | |
} | |
try { | |
WizardDialog dialog = new WizardDialog(this.AbapGitView.getViewSite().getShell(), | |
new AbapGitWizardSwitchBranch(this.project, this.selRepo, destination)); | |
dialog.open(); | |
} catch (PackageRefNotFoundException | ResourceException e) { | |
MessageDialog.openError(this.AbapGitView.getViewSite().getShell(), "Switch Branch Wizard Error", | |
e.getLocalizedMessage()); | |
} |
- The idea is that the repo type and package info is retrieved while creating the object of the wizard
- This wizard also sends the new exception for package ref not found
- Also, the post call to backend can possibly throw a ResourceException, in case there is an issue in backend. This can be explicitly handled here.
- The shell to we can get from the abapgit view
private void getPackageRef(String packageName, String destination, IProgressMonitor monitor) { | ||
IAdtPackageServiceUI packageServiceUI = AdtPackageServiceUIFactory.getOrCreateAdtPackageServiceUI(); | ||
if (!packageServiceUI.packageExists(destination, packageName, monitor)) { | ||
// Throw PackageRefNotFound Exception if packagerServiceUI can't find package | ||
String error = NLS.bind(Messages.AbapGitWizardSwitch_branch_package_ref_not_found_error, packageName); | ||
throw new PackageRefNotFoundException(error); | ||
} | ||
} | ||
|
||
public boolean getPackageAndRepoType(String destination) { | ||
try { | ||
String packageName = this.selRepo.getPackage(); | ||
// checking if the package ref exsist | ||
getPackageRef(packageName, destination, null); | ||
return true; | ||
} catch (PackageRefNotFoundException e) { | ||
Throwable cause = e.getCause() != null ? e.getCause() : e; | ||
String message = (cause.getMessage() != null) ? cause.getMessage() : "An unknown error has occurred"; //$NON-NLS-1$ | ||
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); | ||
MessageDialog.openError(shell, "Error", message); //$NON-NLS-1$ | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be considered redundant as the creation of the wizard already gets the required info and performs the required checks about the package and repository type.
We can remove this logic.
private void getPackageRef(String packageName, IProgressMonitor monitor) { | ||
IAdtPackageServiceUI packageServiceUI = AdtPackageServiceUIFactory.getOrCreateAdtPackageServiceUI(); | ||
if (packageServiceUI.packageExists(AbapGitWizardSwitchBranch.this.destination, packageName, monitor)) { | ||
List<IAdtObjectReference> packageRefs = packageServiceUI.find(AbapGitWizardSwitchBranch.this.destination, packageName, monitor); | ||
AbapGitWizardSwitchBranch.this.cloneData.packageRef = packageRefs.stream().findFirst().orElse(null); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- From here itself we can throw the exception if package does not exist
- Also the progress monitor is not needed much here as the wizard is not yet started. So we can pass a null progress monitor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private void getPackageRef(String packageName, IProgressMonitor monitor) { | |
IAdtPackageServiceUI packageServiceUI = AdtPackageServiceUIFactory.getOrCreateAdtPackageServiceUI(); | |
if (packageServiceUI.packageExists(AbapGitWizardSwitchBranch.this.destination, packageName, monitor)) { | |
List<IAdtObjectReference> packageRefs = packageServiceUI.find(AbapGitWizardSwitchBranch.this.destination, packageName, monitor); | |
AbapGitWizardSwitchBranch.this.cloneData.packageRef = packageRefs.stream().findFirst().orElse(null); | |
} | |
} | |
private void getPackageRef(String packageName) throws PackageRefNotFoundException { | |
IAdtPackageServiceUI packageServiceUI = AdtPackageServiceUIFactory.getOrCreateAdtPackageServiceUI(); | |
if (packageServiceUI.packageExists(AbapGitWizardSwitchBranch.this.destination, packageName, new NullProgressMonitor())) { | |
List<IAdtObjectReference> packageRefs = packageServiceUI.find(AbapGitWizardSwitchBranch.this.destination, packageName, | |
new NullProgressMonitor()); | |
AbapGitWizardSwitchBranch.this.cloneData.packageRef = packageRefs.stream().findFirst().orElse(null); | |
} | |
else { | |
throw new PackageRefNotFoundException("Package not found"); //$NON-NLS-1$ | |
} | |
} |
public boolean getPackageAndRepoType() { | ||
|
||
try { | ||
String packageName = AbapGitWizardSwitchBranch.this.selRepoData.getPackage(); | ||
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() { | ||
|
||
@Override | ||
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | ||
monitor.beginTask(Messages.AbapGitWizardPageBranchAndPackage_task_package_validation_message, IProgressMonitor.UNKNOWN); | ||
|
||
// fetches wether the repository is PUBLIC or PRIVATE from external repo info | ||
getRepositoryAccessMode(); | ||
|
||
// fetches associated package | ||
getPackageRef(packageName, monitor); | ||
|
||
} | ||
}); | ||
// returns false in case of missing package reference | ||
return this.cloneData.packageRef != null; | ||
} catch (InterruptedException | InvocationTargetException e) { | ||
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); | ||
MessageDialog.openError(shell, "Error", e.getMessage()); //$NON-NLS-1$ | ||
return false; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to not handle any exception here.
All exceptions should be handled by the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public boolean getPackageAndRepoType() { | |
try { | |
String packageName = AbapGitWizardSwitchBranch.this.selRepoData.getPackage(); | |
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() { | |
@Override | |
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | |
monitor.beginTask(Messages.AbapGitWizardPageBranchAndPackage_task_package_validation_message, IProgressMonitor.UNKNOWN); | |
// fetches wether the repository is PUBLIC or PRIVATE from external repo info | |
getRepositoryAccessMode(); | |
// fetches associated package | |
getPackageRef(packageName, monitor); | |
} | |
}); | |
// returns false in case of missing package reference | |
return this.cloneData.packageRef != null; | |
} catch (InterruptedException | InvocationTargetException e) { | |
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); | |
MessageDialog.openError(shell, "Error", e.getMessage()); //$NON-NLS-1$ | |
return false; | |
} | |
} | |
public void getPackageAndRepoType() throws PackageRefNotFoundException { | |
String packageName = AbapGitWizardSwitchBranch.this.selRepoData.getPackage(); | |
// fetches wether the repository is PUBLIC or PRIVATE from external repo info | |
getRepositoryAccessMode(); | |
// fetches associated package | |
getPackageRef(packageName); | |
} |
AbapGitWizardPageRepositoryAndCredentials pageCredentials; | ||
AbapGitWizardPageSwitchBranchAndPackage pageBranchAndPackage; | ||
|
||
public AbapGitWizardSwitchBranch(IProject project, IRepository selRepo, String destination) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will add a throws declaration to the constructor for PackageRefNotFoundException.
Switch Branch Functionality in AbapGit