Search in sources :

Example 1 with OCBinaryValidator

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();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) Version(org.osgi.framework.Version) UIUpdatingJob(org.jboss.tools.openshift.internal.common.ui.job.UIUpdatingJob) Job(org.eclipse.core.runtime.jobs.Job) UIUpdatingJob(org.jboss.tools.openshift.internal.common.ui.job.UIUpdatingJob) Image(org.eclipse.swt.graphics.Image) Status2IconConverter(org.jboss.tools.openshift.internal.common.ui.databinding.Status2IconConverter)

Example 2 with OCBinaryValidator

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();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) Test(org.junit.Test)

Example 3 with OCBinaryValidator

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();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) Test(org.junit.Test)

Example 4 with OCBinaryValidator

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();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) Test(org.junit.Test)

Example 5 with OCBinaryValidator

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();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) OCBinaryValidator(org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator) Test(org.junit.Test)

Aggregations

OCBinaryValidator (org.jboss.tools.openshift.internal.core.ocbinary.OCBinaryValidator)11 IStatus (org.eclipse.core.runtime.IStatus)10 Test (org.junit.Test)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 IBuildConfig (com.openshift.restclient.model.IBuildConfig)1 IProject (com.openshift.restclient.model.IProject)1 IResource (com.openshift.restclient.model.IResource)1 IService (com.openshift.restclient.model.IService)1 IRoute (com.openshift.restclient.model.route.IRoute)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)1 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)1