Skip to content

Commit

Permalink
Rename widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Surya Gaddipati committed Jan 30, 2015
1 parent d0c1646 commit df92da1
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 46 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;


public class BuildHistoryTab { public class BuildHistoryTab extends HistoryTab {

private boolean active;
private String url; private String url;
private String font; private String font;
private String state; private String state;
Expand Down Expand Up @@ -75,7 +73,7 @@ private DynamicBuildRepository getDynamicBuildRepository(){


public Iterable<BuildHistoryRow> getBuilds() { public Iterable<BuildHistoryRow> getBuilds() {
String branch = getUrl().equals("all")?null:getUrl(); String branch = getUrl().equals("all")?null:getUrl();
Iterable<BuildHistoryRow> processedBuilds = Iterables.transform(filterSkipped(isMyBuilds() ? getDynamicBuildRepository().<DynamicBuild>getCurrentUserBuilds(project, BranchHistoryWidget.BUILD_COUNT) : getDynamicBuildRepository().<DynamicBuild>getLast(project, BranchHistoryWidget.BUILD_COUNT, branch)), getBuildTransformer()); Iterable<BuildHistoryRow> processedBuilds = Iterables.transform(filterSkipped(isMyBuilds() ? getDynamicBuildRepository().<DynamicBuild>getCurrentUserBuilds(project, JobHistoryWidget.BUILD_COUNT) : getDynamicBuildRepository().<DynamicBuild>getLast(project, JobHistoryWidget.BUILD_COUNT, branch)), getBuildTransformer());
return Iterables.concat(getQueuedBuilds(),processedBuilds); return Iterables.concat(getQueuedBuilds(),processedBuilds);
} }


Expand All @@ -86,7 +84,7 @@ private Iterable<BuildHistoryRow> getQueuedBuilds() {
int number = queuedItems.size() == 1 ? project.getNextBuildNumber() : project.getNextBuildNumber() + queuedItems.size() - i - 1; int number = queuedItems.size() == 1 ? project.getNextBuildNumber() : project.getNextBuildNumber() + queuedItems.size() - i - 1;
queuedBuilds.add(new QueuedBuildHistoryRow(queuedItems.get(i),number)); queuedBuilds.add(new QueuedBuildHistoryRow(queuedItems.get(i),number));
} }
return queuedBuilds; return queuedBuilds;
} }


private Function<DynamicBuild, BuildHistoryRow> getBuildTransformer() { private Function<DynamicBuild, BuildHistoryRow> getBuildTransformer() {
Expand All @@ -106,9 +104,7 @@ public boolean apply(DynamicBuild build) {
} }
}); });
} }
public boolean isActive(){
return active;
}
public String getUrl(){ public String getUrl(){
return url; return url;
} }
Expand All @@ -126,8 +122,8 @@ public boolean isRemovable(){
return removable; return removable;
} }


private static Iterable<BuildHistoryTab> getTabs(List<String> branches,DynamicProject project) { private static Iterable<HistoryTab> getTabs(List<String> branches,DynamicProject project) {
ArrayList<BuildHistoryTab> tabs = new ArrayList<BuildHistoryTab>(); ArrayList<HistoryTab> tabs = new ArrayList<HistoryTab>();
tabs.add(getAll(project)); tabs.add(getAll(project));
tabs.add(getMine(project)); tabs.add(getMine(project));
for(String branch:branches){ for(String branch:branches){
Expand All @@ -136,11 +132,9 @@ private static Iterable<BuildHistoryTab> getTabs(List<String> branches,DynamicPr
return tabs; return tabs;
} }


public void setActive() {
this.active =true;
}


public static Iterable<BuildHistoryTab> getTabs(DynamicProject project) {
public static Iterable<HistoryTab> getTabs(DynamicProject project) {
DynamicProjectBranchTabsProperty tabsProperty = getTabsProperty(project); DynamicProjectBranchTabsProperty tabsProperty = getTabsProperty(project);
List<String> branches = tabsProperty == null ? Collections.<String>emptyList() : tabsProperty.getBranches(); List<String> branches = tabsProperty == null ? Collections.<String>emptyList() : tabsProperty.getBranches();
return getTabs(branches,project); return getTabs(branches,project);
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/groupon/jenkins/branchhistory/HistoryTab.java
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2014, Groupon, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package com.groupon.jenkins.branchhistory;

public abstract class HistoryTab {
private boolean active;

public boolean isActive(){
return active;
}
public void setActive() {
this.active =true;
}

public abstract String getUrl();
}
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,33 +37,33 @@ of this software and associated documentation files (the "Software"), to deal
import java.io.IOException; import java.io.IOException;




public class BranchHistoryWidget extends Widget{ public class JobHistoryWidget extends Widget{




protected static final int BUILD_COUNT = 30; protected static final int BUILD_COUNT = 30;
public static final String TAB_SELECTION = "tabSelection"; public static final String TAB_SELECTION = "tabSelection";
private final DynamicProject project; private final DynamicProject project;
private final Iterable<BuildHistoryTab> tabs; private final Iterable<HistoryTab> tabs;
private final BuildHistoryTab currentTab; private final HistoryTab currentTab;


@Override @Override
public String getUrlName() { public String getUrlName() {
return "buildHistory"; return "buildHistory";
} }




public BranchHistoryWidget(DynamicProject project) { public JobHistoryWidget(DynamicProject project) {
this.project = project; this.project = project;
this.tabs = intializeTabs(); this.tabs = intializeTabs();
this.currentTab = getActiveTab(tabs); this.currentTab = getActiveTab(tabs);
currentTab.setActive(); currentTab.setActive();
} }


public Iterable<BuildHistoryTab> getTabs(){ public Iterable<HistoryTab> getTabs(){
return tabs; return tabs;
} }
public Iterable<BuildHistoryTab> intializeTabs(){ public Iterable<HistoryTab> intializeTabs(){
Iterable<BuildHistoryTab> tabs = BuildHistoryTab.getTabs(project); Iterable<HistoryTab> tabs = BuildHistoryTab.getTabs(project);
return tabs; return tabs;
} }


Expand All @@ -72,11 +72,11 @@ public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp)
return findTab(token); return findTab(token);
} }


private BuildHistoryTab findTab(final String tabUrl) { private HistoryTab findTab(final String tabUrl) {
return Iterables.find(tabs, new Predicate<BuildHistoryTab>() { return Iterables.find(tabs, new Predicate<HistoryTab>() {
@Override @Override
public boolean apply(BuildHistoryTab buildHistoryTab) { public boolean apply(HistoryTab historyTab) {
return buildHistoryTab.getUrl().equals(tabUrl); return historyTab.getUrl().equals(tabUrl);
} }
}); });
} }
Expand Down Expand Up @@ -111,10 +111,10 @@ private DynamicProjectBranchTabsProperty getTabsProperty() {
return project.getProperty(DynamicProjectBranchTabsProperty.class); return project.getProperty(DynamicProjectBranchTabsProperty.class);
} }


private BuildHistoryTab getActiveTab(Iterable<BuildHistoryTab> tabs) { private HistoryTab getActiveTab(Iterable<HistoryTab> tabs) {
for(BuildHistoryTab buildHistoryTab : tabs){ for(HistoryTab historyTab : tabs){
if(buildHistoryTab.getUrl().equals(getCurrentTab())){ if(historyTab.getUrl().equals(getCurrentTab())){
return buildHistoryTab; return historyTab;
} }
} }
return Iterables.get(tabs, 0); return Iterables.get(tabs, 0);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ of this software and associated documentation files (the "Software"), to deal
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.groupon.jenkins.SetupConfig; import com.groupon.jenkins.SetupConfig;
import com.groupon.jenkins.branchhistory.BranchHistoryWidget; import com.groupon.jenkins.branchhistory.JobHistoryWidget;
import com.groupon.jenkins.dynamic.buildtype.BuildType; import com.groupon.jenkins.dynamic.buildtype.BuildType;
import com.groupon.jenkins.dynamic.buildtype.BuildTypeProperty; import com.groupon.jenkins.dynamic.buildtype.BuildTypeProperty;
import com.groupon.jenkins.dynamic.organizationcontainer.OrganizationContainer; import com.groupon.jenkins.dynamic.organizationcontainer.OrganizationContainer;
Expand All @@ -38,30 +38,21 @@ of this software and associated documentation files (the "Software"), to deal
import hudson.PermalinkList; import hudson.PermalinkList;
import hudson.matrix.Combination; import hudson.matrix.Combination;
import hudson.model.*; import hudson.model.*;
import hudson.model.Queue;
import hudson.model.Queue.Task; import hudson.model.Queue.Task;
import hudson.util.CaseInsensitiveComparator; import hudson.util.CaseInsensitiveComparator;
import hudson.util.CopyOnWriteMap; import hudson.util.CopyOnWriteMap;
import hudson.widgets.HistoryWidget;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;


import hudson.widgets.Widget; import hudson.widgets.Widget;
import jenkins.model.Jenkins; import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import jenkins.util.TimeDuration;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.StaplerResponse;
import org.mongodb.morphia.annotations.PostLoad; import org.mongodb.morphia.annotations.PostLoad;
import org.mongodb.morphia.annotations.PrePersist; import org.mongodb.morphia.annotations.PrePersist;


import javax.servlet.ServletException;

public class DynamicProject extends DbBackedProject<DynamicProject, DynamicBuild> implements TopLevelItem, Saveable, IdentifableItemGroup<DynamicSubProject> { public class DynamicProject extends DbBackedProject<DynamicProject, DynamicBuild> implements TopLevelItem, Saveable, IdentifableItemGroup<DynamicSubProject> {
private transient Map<String, DynamicSubProject> items; private transient Map<String, DynamicSubProject> items;
private String containerName; private String containerName;
Expand Down Expand Up @@ -169,7 +160,7 @@ public OrganizationContainer getParent() {
@Override @Override
public List<Widget> getWidgets() { public List<Widget> getWidgets() {
List<Widget> widgets = new ArrayList<Widget>(); List<Widget> widgets = new ArrayList<Widget>();
widgets.add(new BranchHistoryWidget(this)); widgets.add(new JobHistoryWidget(this));
return widgets; return widgets;
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ of this software and associated documentation files (the "Software"), to deal
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class BranchHistoryWidgetTest { public class JobHistoryWidgetTest {


private DynamicBuildRepository buildRepo; private DynamicBuildRepository buildRepo;
private DynamicProject project; private DynamicProject project;
Expand All @@ -64,7 +64,7 @@ public void should_not_show_skipped_builds() {
DynamicBuild skippedBuild = newBuild().skipped().get(); DynamicBuild skippedBuild = newBuild().skipped().get();
when(skippedBuild.isSkipped()).thenReturn(true); when(skippedBuild.isSkipped()).thenReturn(true);
List<? extends DbBackedBuild> builds = list(skippedBuild, unSkippedBuild); List<? extends DbBackedBuild> builds = list(skippedBuild, unSkippedBuild);
when(buildRepo.getLast(project, BranchHistoryWidget.BUILD_COUNT, null)).thenReturn((Iterable<DbBackedBuild>) builds); when(buildRepo.getLast(project, JobHistoryWidget.BUILD_COUNT, null)).thenReturn((Iterable<DbBackedBuild>) builds);
assertEquals(1, Iterables.size(historyWidget.getBaseList())); assertEquals(1, Iterables.size(historyWidget.getBaseList()));
assertEquals(unSkippedBuild, Iterables.getOnlyElement(historyWidget.getBaseList())); assertEquals(unSkippedBuild, Iterables.getOnlyElement(historyWidget.getBaseList()));
} }
Expand All @@ -77,7 +77,7 @@ public void should_return_oldest_running_build() {
DynamicBuild runningBuild2 = newBuild().building().get(); DynamicBuild runningBuild2 = newBuild().building().get();
List<? extends DbBackedBuild> builds = list(finishedBuild, runningBuild, finishedBuild2, runningBuild2); List<? extends DbBackedBuild> builds = list(finishedBuild, runningBuild, finishedBuild2, runningBuild2);
String buildId = String.valueOf(runningBuild2.getNumber()); String buildId = String.valueOf(runningBuild2.getNumber());
when(buildRepo.getLast(project, BranchHistoryWidget.BUILD_COUNT, null)).thenReturn((Iterable<DbBackedBuild>) builds); when(buildRepo.getLast(project, JobHistoryWidget.BUILD_COUNT, null)).thenReturn((Iterable<DbBackedBuild>) builds);


assertEquals(buildId, historyWidget.getNextBuildToFetch((Iterable<DbBackedBuild>) builds, adapter).getBuildNumber(adapter)); assertEquals(buildId, historyWidget.getNextBuildToFetch((Iterable<DbBackedBuild>) builds, adapter).getBuildNumber(adapter));


Expand All @@ -91,7 +91,7 @@ public void should_return_most_recent_build_plus_one() {
List<? extends DbBackedBuild> builds = list(finishedBuild, finishedBuild2, finishedBuild3); List<? extends DbBackedBuild> builds = list(finishedBuild, finishedBuild2, finishedBuild3);
String buildId = String.valueOf(finishedBuild.getNumber() + 1); String buildId = String.valueOf(finishedBuild.getNumber() + 1);


when(buildRepo.getLast(project, BranchHistoryWidget.BUILD_COUNT, null)).thenReturn((Iterable<DbBackedBuild>) builds); when(buildRepo.getLast(project, JobHistoryWidget.BUILD_COUNT, null)).thenReturn((Iterable<DbBackedBuild>) builds);


assertEquals(buildId, historyWidget.getNextBuildToFetch((Iterable<DbBackedBuild>) builds, adapter).getBuildNumber(adapter)); assertEquals(buildId, historyWidget.getNextBuildToFetch((Iterable<DbBackedBuild>) builds, adapter).getBuildNumber(adapter));


Expand All @@ -101,7 +101,7 @@ public void should_return_most_recent_build_plus_one() {
public void should_return_one_for_empty_build_list() { public void should_return_one_for_empty_build_list() {
String buildId = "1"; String buildId = "1";
List<? extends DbBackedBuild> builds = Collections.emptyList(); List<? extends DbBackedBuild> builds = Collections.emptyList();
when(buildRepo.getLast(project, BranchHistoryWidget.BUILD_COUNT, null)).thenReturn((Iterable<DbBackedBuild>) builds); when(buildRepo.getLast(project, JobHistoryWidget.BUILD_COUNT, null)).thenReturn((Iterable<DbBackedBuild>) builds);


assertEquals(buildId, historyWidget.getNextBuildToFetch((Iterable<DbBackedBuild>) builds, adapter).getBuildNumber(adapter)); assertEquals(buildId, historyWidget.getNextBuildToFetch((Iterable<DbBackedBuild>) builds, adapter).getBuildNumber(adapter));


Expand Down

0 comments on commit df92da1

Please sign in to comment.