Search in sources :

Example 1 with AbstractFolder

use of com.cloudbees.hudson.plugins.folder.AbstractFolder in project blueocean-plugin by jenkinsci.

the class FavoriteContainerImpl method iterator.

@Override
public Iterator<BlueFavorite> iterator(int start, int limit) {
    List<BlueFavorite> favorites = new ArrayList<>();
    Iterator<Item> favoritesIterator = Favorites.getFavorites(user.user).iterator();
    Utils.skip(favoritesIterator, start);
    int count = 0;
    while (count < limit && favoritesIterator.hasNext()) {
        Item item = favoritesIterator.next();
        if (item instanceof AbstractFolder) {
            continue;
        }
        BlueFavorite blueFavorite = FavoriteUtil.getFavorite(item);
        if (blueFavorite != null) {
            favorites.add(blueFavorite);
            count++;
        }
    }
    return favorites.iterator();
}
Also used : Item(hudson.model.Item) BlueFavorite(io.jenkins.blueocean.rest.model.BlueFavorite) AbstractFolder(com.cloudbees.hudson.plugins.folder.AbstractFolder) ArrayList(java.util.ArrayList)

Example 2 with AbstractFolder

use of com.cloudbees.hudson.plugins.folder.AbstractFolder in project blueocean-plugin by jenkinsci.

the class GithubIssueTest method changeSetJobParentNotMultibranch.

@Test
public void changeSetJobParentNotMultibranch() throws Exception {
    AbstractFolder project = mock(AbstractFolder.class);
    Job job = mock(MockJob.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);
    when(project.getProperties()).thenReturn(new DescribableList(project));
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    when(job.getParent()).thenReturn(project);
    when(entry.getMsg()).thenReturn("Closed #123 #124");
    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(0, resolved.size());
}
Also used : AbstractFolder(com.cloudbees.hudson.plugins.folder.AbstractFolder) ChangeLogSet(hudson.scm.ChangeLogSet) DescribableList(hudson.util.DescribableList) Run(hudson.model.Run) Job(hudson.model.Job) BlueIssue(io.jenkins.blueocean.rest.model.BlueIssue) Test(org.junit.Test)

Example 3 with AbstractFolder

use of com.cloudbees.hudson.plugins.folder.AbstractFolder in project hubot-steps-plugin by jenkinsci.

the class HubotSite method get.

public static HubotSite get(final Job<?, ?> job, final TaskListener listener, final String siteName) {
    HubotSite hubotSite = null;
    HubotSite defaultSite = null;
    ItemGroup parent = job.getParent();
    String folderName = null;
    // Site from folder(s).
    try {
        while (parent != null) {
            if (parent instanceof AbstractFolder) {
                AbstractFolder folder = (AbstractFolder) parent;
                if (folderName == null) {
                    folderName = folder.getName();
                }
                HubotFolderProperty jfp = (HubotFolderProperty) folder.getProperties().get(HubotFolderProperty.class);
                if (jfp != null) {
                    HubotSite[] sites = jfp.getSites();
                    if (sites != null && sites.length > 0) {
                        for (HubotSite site : sites) {
                            HubotSite cloneSite = site.clone();
                            if (cloneSite.isUseFolderName()) {
                                cloneSite.setRoom(folder.getName());
                            }
                            if (siteName != null) {
                                if (cloneSite.getName().equalsIgnoreCase(siteName) && hubotSite == null) {
                                    hubotSite = cloneSite;
                                }
                            } else {
                                if (cloneSite.isDefaultSite() && defaultSite == null) {
                                    defaultSite = cloneSite;
                                }
                            }
                        }
                    }
                }
            }
            if (parent instanceof Item) {
                parent = ((Item) parent).getParent();
            } else {
                parent = null;
            }
        }
        // Global Sites.
        if (hubotSite == null && defaultSite == null) {
            for (HubotSite site : new GlobalConfig().getSites()) {
                HubotSite cloneSite = site.clone();
                if (site.isUseFolderName()) {
                    if (folderName != null) {
                        cloneSite.setRoom(folderName);
                    }
                }
                if (siteName != null) {
                    if (cloneSite.getName().equalsIgnoreCase(siteName) && hubotSite == null) {
                        hubotSite = cloneSite;
                    }
                } else {
                    if (cloneSite.isDefaultSite() && defaultSite == null) {
                        defaultSite = cloneSite;
                    }
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("Unable to get hubot site", e);
    }
    return hubotSite == null ? defaultSite : hubotSite;
}
Also used : Item(hudson.model.Item) AbstractFolder(com.cloudbees.hudson.plugins.folder.AbstractFolder) ItemGroup(hudson.model.ItemGroup) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

AbstractFolder (com.cloudbees.hudson.plugins.folder.AbstractFolder)3 Item (hudson.model.Item)2 ItemGroup (hudson.model.ItemGroup)1 Job (hudson.model.Job)1 Run (hudson.model.Run)1 ChangeLogSet (hudson.scm.ChangeLogSet)1 DescribableList (hudson.util.DescribableList)1 BlueFavorite (io.jenkins.blueocean.rest.model.BlueFavorite)1 BlueIssue (io.jenkins.blueocean.rest.model.BlueIssue)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1