Search in sources :

Example 36 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class ApplicationSourceTreeItems method loadImageStreams.

private Collection<IApplicationSource> loadImageStreams(IProject project, Connection conn) {
    final Collection<IImageStream> streams = conn.getResources(ResourceKind.IMAGE_STREAM, project.getNamespaceName());
    try {
        if (StringUtils.isNotBlank(conn.getClusterNamespace())) {
            Collection<IImageStream> commonStreams = conn.getResources(ResourceKind.IMAGE_STREAM, (String) conn.getClusterNamespace());
            commonStreams.stream().filter(s -> !streams.contains(s)).forEach(s -> streams.add(s));
        }
    } catch (OpenShiftException e) {
        OpenShiftUIActivator.log(IStatus.ERROR, e.getLocalizedMessage(), e);
    }
    Collection<IApplicationSource> sources = new ArrayList<>();
    for (IImageStream is : streams) {
        List<ITagReference> tags = is.getTags().stream().filter(t -> t.isAnnotatedWith(OpenShiftAPIAnnotations.TAGS) && ArrayUtils.contains(t.getAnnotation(OpenShiftAPIAnnotations.TAGS).split(","), BUILDER_TAG)).collect(Collectors.toList());
        if (!tags.isEmpty()) {
            tags.forEach(t -> sources.add(new ImageStreamApplicationSource(is, t)));
        }
    }
    return sources;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) IImageStream(com.openshift.restclient.model.IImageStream) OpenShiftException(com.openshift.restclient.OpenShiftException) TemplateApplicationSource(org.jboss.tools.openshift.internal.ui.wizard.newapp.fromtemplate.TemplateApplicationSource) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) IStatus(org.eclipse.core.runtime.IStatus) IModelFactory(org.jboss.tools.openshift.internal.ui.treeitem.IModelFactory) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) ResourceKind(com.openshift.restclient.ResourceKind) ITagReference(com.openshift.restclient.model.image.ITagReference) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Connection(org.jboss.tools.openshift.core.connection.Connection) List(java.util.List) ICommonAttributes(org.jboss.tools.openshift.core.ICommonAttributes) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) IProjectTemplateList(com.openshift.restclient.capability.resources.IProjectTemplateList) ITemplate(com.openshift.restclient.model.template.ITemplate) ImageStreamApplicationSource(org.jboss.tools.openshift.internal.ui.wizard.newapp.fromimage.ImageStreamApplicationSource) Collections(java.util.Collections) ArrayUtils(org.apache.commons.lang.ArrayUtils) ITagReference(com.openshift.restclient.model.image.ITagReference) OpenShiftException(com.openshift.restclient.OpenShiftException) ArrayList(java.util.ArrayList) IImageStream(com.openshift.restclient.model.IImageStream) ImageStreamApplicationSource(org.jboss.tools.openshift.internal.ui.wizard.newapp.fromimage.ImageStreamApplicationSource)

Example 37 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class RefreshTest method stubProject.

private IProject stubProject(String name, int version) {
    StubInvocationHandler handler = new StubInvocationHandler();
    IProject instance = (IProject) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { IProject.class }, handler);
    handler.stub((proxy, method, args) -> instance).when(instance.getProject());
    handler.stub((proxy, method, args) -> name).when(instance.getNamespaceName());
    stubResource(handler, instance, ResourceKind.PROJECT, name, version);
    return instance;
}
Also used : Arrays(java.util.Arrays) Proxy(java.lang.reflect.Proxy) TimeoutException(java.util.concurrent.TimeoutException) IConnectionWrapper(org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper) IProject(com.openshift.restclient.model.IProject) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) UITestUtils(org.jboss.tools.openshift.test.util.UITestUtils) ConnectionsRegistry(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry) Before(org.junit.Before) LoadingState(org.jboss.tools.openshift.internal.ui.models.LoadingState) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) ConnectionProperties(org.jboss.tools.openshift.core.connection.ConnectionProperties) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) OpenshiftUIModel(org.jboss.tools.openshift.internal.ui.models.OpenshiftUIModel) IExceptionHandler(org.jboss.tools.openshift.internal.ui.models.IExceptionHandler) Mockito.verify(org.mockito.Mockito.verify) IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) Optional(java.util.Optional) IElementListener(org.jboss.tools.openshift.internal.ui.models.IElementListener) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) IProject(com.openshift.restclient.model.IProject)

Example 38 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class RefreshTest method testRefreshConnection.

@Test
public void testRefreshConnection() throws InterruptedException, TimeoutException {
    IProject project1 = stubProject("test1", 1);
    IProject project2 = stubProject("test2", 1);
    IProject project2prime = stubProject("test2", 2);
    when(getConnectionMock().getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project1));
    IConnectionWrapper connection = getConnection();
    getConnection().load(IExceptionHandler.NULL_HANDLER);
    UITestUtils.waitForState(connection, LoadingState.LOADED);
    assertEquals(1, connection.getResources().size());
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project1.equals(projectWrapper.getWrapped())));
    registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project1, project2));
    verify(listener).elementChanged(connection);
    assertEquals(2, connection.getResources().size());
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project1.equals(projectWrapper.getWrapped())));
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> project2.equals(projectWrapper.getWrapped())));
    registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project2));
    verify(listener, times(2)).elementChanged(connection);
    assertEquals(1, connection.getResources().size());
    Optional<IResourceWrapper<?, ?>> project2Wrapper = connection.getResources().stream().filter(projectWrapper -> project2.equals(projectWrapper.getWrapped())).findFirst();
    assertTrue(project2Wrapper.isPresent());
    registry.fireConnectionChanged(getConnectionMock(), ConnectionProperties.PROPERTY_PROJECTS, null, Arrays.asList(project2prime));
    verify(listener, times(2)).elementChanged(connection);
    verify(listener).elementChanged(project2Wrapper.get());
    assertEquals(1, connection.getResources().size());
    assertTrue(connection.getResources().stream().anyMatch(projectWrapper -> {
        IResource resource = projectWrapper.getWrapped();
        String version = resource.getResourceVersion();
        return project2.equals(resource) && version.equals("2");
    }));
}
Also used : Arrays(java.util.Arrays) Proxy(java.lang.reflect.Proxy) TimeoutException(java.util.concurrent.TimeoutException) IConnectionWrapper(org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper) IProject(com.openshift.restclient.model.IProject) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) UITestUtils(org.jboss.tools.openshift.test.util.UITestUtils) ConnectionsRegistry(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistry) Before(org.junit.Before) LoadingState(org.jboss.tools.openshift.internal.ui.models.LoadingState) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) ConnectionProperties(org.jboss.tools.openshift.core.connection.ConnectionProperties) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) OpenshiftUIModel(org.jboss.tools.openshift.internal.ui.models.OpenshiftUIModel) IExceptionHandler(org.jboss.tools.openshift.internal.ui.models.IExceptionHandler) Mockito.verify(org.mockito.Mockito.verify) IOpenShiftConnection(org.jboss.tools.openshift.core.connection.IOpenShiftConnection) Optional(java.util.Optional) IElementListener(org.jboss.tools.openshift.internal.ui.models.IElementListener) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IConnectionWrapper(org.jboss.tools.openshift.internal.ui.models.IConnectionWrapper) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 39 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class DeleteProjectJob method doRun.

@Override
protected IStatus doRun(IProgressMonitor monitor) {
    final IProject project = (IProject) resource;
    Connection connection = ConnectionsRegistryUtil.getConnectionFor(project);
    WatchManager.getInstance().stopWatch(project, connection);
    List<IProject> oldProjects = connection.getResources(ResourceKind.PROJECT);
    IStatus status = super.doRun(monitor);
    if (status.isOK() && waitForServerToReconcileProjectDelete(connection, project)) {
        List<IProject> newProjects = new ArrayList<>(oldProjects);
        newProjects.remove(project);
        ConnectionsRegistrySingleton.getInstance().fireConnectionChanged(connection, ConnectionProperties.PROPERTY_PROJECTS, oldProjects, newProjects);
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Connection(org.jboss.tools.openshift.core.connection.Connection) ArrayList(java.util.ArrayList) IProject(com.openshift.restclient.model.IProject)

Example 40 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class SelectedRoutePreference method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final Shell shell = HandlerUtil.getActiveShell(event);
    ISelection currentSelection = UIUtils.getCurrentSelection(event);
    final IRoute route = UIUtils.getFirstElement(currentSelection, IRoute.class);
    // Open route
    if (route != null) {
        return openBrowser(shell, route);
    }
    IServiceWrapper service = UIUtils.getFirstElement(currentSelection, IServiceWrapper.class);
    if (service != null) {
        new RouteOpenerJob(service.getWrapped().getNamespaceName(), shell) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                this.routes = service.getResourcesOfKind(ResourceKind.ROUTE).stream().map(r -> (IRoute) r.getWrapped()).collect(Collectors.toList());
                return Status.OK_STATUS;
            }
        }.schedule();
        return Status.OK_STATUS;
    }
    // Open Project
    final IProject project = UIUtils.getFirstElement(currentSelection, IProject.class);
    if (project != null) {
        new RouteOpenerJob(project.getName(), shell) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                this.routes = project.getResources(ResourceKind.ROUTE);
                return Status.OK_STATUS;
            }
        }.schedule();
        return Status.OK_STATUS;
    }
    // Open Connection
    final IConnection connection = UIUtils.getFirstElement(currentSelection, IConnection.class);
    if (connection != null) {
        return openBrowser(shell, connection.getHost());
    }
    return nothingToOpenDialog(shell);
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) StringUtils(org.apache.commons.lang.StringUtils) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) IStatus(org.eclipse.core.runtime.IStatus) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) Map(java.util.Map) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) Shell(org.eclipse.swt.widgets.Shell) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility) SelectRouteDialog(org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Dialog(org.eclipse.jface.dialogs.Dialog) IRoute(com.openshift.restclient.model.route.IRoute) UIUpdatingJob(org.jboss.tools.openshift.internal.common.ui.job.UIUpdatingJob) ISelection(org.eclipse.jface.viewers.ISelection) AbstractHandler(org.eclipse.core.commands.AbstractHandler) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) ISelection(org.eclipse.jface.viewers.ISelection) IRoute(com.openshift.restclient.model.route.IRoute) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IProject(com.openshift.restclient.model.IProject)

Aggregations

IProject (com.openshift.restclient.model.IProject)49 Test (org.junit.Test)18 Connection (org.jboss.tools.openshift.core.connection.Connection)16 IResource (com.openshift.restclient.model.IResource)13 ArrayList (java.util.ArrayList)8 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)7 ResourceKind (com.openshift.restclient.ResourceKind)6 IStatus (org.eclipse.core.runtime.IStatus)6 ObservableTreeItem (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem)6 List (java.util.List)5 ISelection (org.eclipse.jface.viewers.ISelection)5 IService (com.openshift.restclient.model.IService)4 IRoute (com.openshift.restclient.model.route.IRoute)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 OpenShiftException (com.openshift.restclient.OpenShiftException)3 IBuildConfig (com.openshift.restclient.model.IBuildConfig)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3