use of org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator in project jbosstools-openshift by jbosstools.
the class OpenShiftPreferencePage method validateLocation.
private void validateLocation(final String location) {
setValid(false);
ocVersionLabel.setText("Checking OpenShift client version...");
Job validationJob = new UIUpdatingJob("Checking oc binary...") {
private OCBinaryValidator validator = new OCBinaryValidator(location);
private Version version = Version.emptyVersion;
private IStatus status = Status.OK_STATUS;
@Override
protected IStatus run(IProgressMonitor monitor) {
this.version = validator.getVersion(monitor);
this.status = validator.getStatus(version);
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
} else {
return Status.OK_STATUS;
}
}
@Override
protected IStatus updateUI(IProgressMonitor monitor) {
if (!ocMessageComposite.isDisposed() && !monitor.isCanceled()) {
ocVersionLabel.setText(getOcVersionMessage());
ocMessageLabel.setText(removePreferencesLink(status.getMessage()));
Image messageIcon = (Image) new Status2IconConverter().convert(status);
ocMessageIcon.setImage(messageIcon);
ocMessageComposite.setVisible(!status.isOK());
ocMessageComposite.layout(true);
setValid(true);
}
// always have page valid so that user can always leave the page
return Status.OK_STATUS;
}
/**
* Removes a link to the preferences that exists in the message. Does nothing
* otherwise. We already are in the preferences, so there's no use to have a
* link (that opens up the preferences in other places) to configure.
*
* @param message
* @return the message without the link-markup. Returns the unaltered message
* otherwise.
*/
private String removePreferencesLink(String message) {
if (StringUtils.isEmpty(message)) {
return message;
}
return message.replaceAll(OpenShiftCoreMessages.OCBinaryPreferencesLink, OpenShiftCoreMessages.OCBinaryPreferencesDeactivatedLink);
}
private String getOcVersionMessage() {
if (version == null || Version.emptyVersion.equals(version)) {
return "Could not determine your OpenShift client version.";
} else {
return NLS.bind("Your OpenShift client version is {0}.{1}.{2}", new Object[] { version.getMajor(), version.getMinor(), version.getMicro() });
}
}
};
validationJob.schedule();
}
use of org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator in project jbosstools-openshift by jbosstools.
the class OCBinaryValidatorTest method oc310OnNonLinuxValidatesOK.
@Test
public void oc310OnNonLinuxValidatesOK() {
// given
OCBinaryValidator validator = new TestableOCBinaryValidator("papa-smurf", Platform.OS_WIN32, false);
// when
IStatus status = validator.getStatus(Version.parseVersion("3.10.0"));
// then
assertThat(status.isOK()).isTrue();
}
use of org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator in project jbosstools-openshift by jbosstools.
the class OCBinaryValidatorTest method oc310OnLinuxValidatesKO.
@Test
public void oc310OnLinuxValidatesKO() {
// given
OCBinaryValidator validator = new TestableOCBinaryValidator("papa-smurf", Platform.OS_LINUX, false);
// when
IStatus status = validator.getStatus(Version.parseVersion("3.10.0"));
// then
assertThat(status.isOK()).isFalse();
}
use of org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator in project jbosstools-openshift by jbosstools.
the class OCBinaryValidatorTest method oc360OnWindowsWithSpaceInPathValidatesOK.
@Test
public void oc360OnWindowsWithSpaceInPathValidatesOK() {
// given
OCBinaryValidator validator = new TestableOCBinaryValidator("/my home/bin/oc", Platform.OS_WIN32, false);
// when
IStatus status = validator.getStatus(Version.parseVersion("3.6.0"));
// then
assertThat(status.isOK()).isTrue();
}
use of org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator in project jbosstools-openshift by jbosstools.
the class OCBinaryValidatorTest method oc370OnMacWithSpaceInPathValidatesOK.
@Test
public void oc370OnMacWithSpaceInPathValidatesOK() {
// given
OCBinaryValidator validator = new TestableOCBinaryValidator("/my home/bin/oc", Platform.OS_MACOSX, false);
// when
IStatus status = validator.getStatus(Version.parseVersion("3.7.0"));
// then
assertThat(status.isOK()).isTrue();
}
Aggregations