public List<PermissionGroup> getGroups(String typeString) { AclType type = AclType.parseAclType(typeString); List<PermissionGroup> groups; switch (type) { case GLOBAL: { groups = new ArrayList<PermissionGroup>( PermissionGroup.getAll()); groups.remove(PermissionGroup.get(Permission.class)); break; } case PROJECT: { groups = new ArrayList<PermissionGroup>( PermissionGroup.getAll()); groups.remove(PermissionGroup.get(Permission.class)); groups.remove(PermissionGroup.get(Jenkins.class)); groups.remove(PermissionGroup.get(Computer.class)); groups.remove(PermissionGroup.get(View.class)); break; } default: groups = null; } return groups; }
@Override public List<TopLevelItem> filter(List<TopLevelItem> added, List<TopLevelItem> all, View filteringView) { List<Pattern> patterns = getCompiled(); List<TopLevelItem> workList = added.isEmpty() ? all : added; List<TopLevelItem> filtered = new LinkedList<TopLevelItem>(); for (TopLevelItem item : workList) { if (item instanceof ParameterizedJobMixIn.ParameterizedJob) { DockerHubTrigger trigger = DockerHubTrigger.getTrigger((ParameterizedJobMixIn.ParameterizedJob)item); if (trigger != null) { if (patterns.isEmpty()) { filtered.add(item); } else { for (String name : trigger.getAllRepoNames()) { if(matches(name)) { filtered.add(item); } } } } } } return filtered; }
@Test public void testBindView_simpleWithJob() throws Exception { JSONObject json = (JSONObject) JSONSerializer.toJSON(EMPTY_LIST_VIEW); json.put("name", NAME); // Add our job to the list view json.put(project.getName(), true); View view = underTest.bindView(viewGroupMixIn, NAME, json); assertNotNull(view); assertThat(view, instanceOf(ListView.class)); assertEquals(NAME, view.getViewName()); assertTrue(views.contains(view)); ListView listView = (ListView) view; assertTrue(listView.jobNamesContains(project)); }
@Test public void testBindView_simpleWithJobAndColumns() throws Exception { JSONObject json = (JSONObject) JSONSerializer.toJSON(EMPTY_LIST_VIEW); json.put("name", NAME); // Add our job to the list view json.put(project.getName(), true); // Add some columns to the view. JSONArray columns = (JSONArray) JSONSerializer.toJSON(COLUMNS_JSON); json.put("columns", columns); View view = underTest.bindView(viewGroupMixIn, NAME, json); assertNotNull(view); assertThat(view, instanceOf(ListView.class)); assertEquals(NAME, view.getViewName()); assertTrue(views.contains(view)); ListView listView = (ListView) view; assertTrue(listView.jobNamesContains(project)); assertEquals(2, listView.getColumns().size()); }
private void initPython() { if (pexec == null) { pexec = new PythonExecutor(this); String[] jMethods = new String[1]; jMethods[0] = "filter"; String[] pFuncs = new String[1]; pFuncs[0] = "filter"; Class[][] argTypes = new Class[1][]; argTypes[0] = new Class[3]; argTypes[0][0] = List.class; argTypes[0][1] = List.class; argTypes[0][2] = View.class; pexec.checkAbstrMethods(jMethods, pFuncs, argTypes); String[] functions = new String[1]; functions[0] = "get_descriptor"; int[] argsCount = new int[1]; argsCount[0] = 0; pexec.registerFunctions(functions, argsCount); } }
public void doSearchSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, UnsupportedEncodingException, ServletException, Descriptor.FormException { Hudson.getInstance().checkPermission(View.READ); SearchAction action = SearchAction.fromRequest(req); switch (action) { case runSearchButton: JobsFilter filter = new JobsFilter(req, this); updateSearchCache(filter); rsp.sendRedirect("."); break; case resetDefaultsButton: updateSearchCache(getDefaultFilters()); rsp.sendRedirect("."); break; default: throw new IOException("Action "+action+" is not supported"); } }
@Override public List<TopLevelItem> filter(List<TopLevelItem> added, List<TopLevelItem> all, View filteringView) { for (TopLevelItem item : all) { if (added.contains(item)) { continue; } if (SCMHead.HeadByItem.findHead(item) instanceof GitLabSCMTagHead) { added.add(item); } } return added; }
@Override public List<TopLevelItem> filter(List<TopLevelItem> added, List<TopLevelItem> all, View filteringView) { for (TopLevelItem item : all) { if (added.contains(item)) { continue; } SCMHead head = SCMHead.HeadByItem.findHead(item); if (head instanceof GitLabSCMMergeRequestHead && (!originOnly || ((GitLabSCMMergeRequestHead) head).fromOrigin())) { added.add(item); } } return added; }
@Override public List<TopLevelItem> filter(List<TopLevelItem> added, List<TopLevelItem> all, View filteringView) { for (TopLevelItem item : all) { if (added.contains(item)) { continue; } SCMHead head = SCMHead.HeadByItem.findHead(item); if (head instanceof GitLabSCMBranchHead && filter(item) && filter((GitLabSCMBranchHead) head)) { added.add(item); } } return added; }
private Collection<View> getViewsAffectedBy(Run<?, ?> run) { Collection<View> views = Jenkins.getInstance().getViews(); List<View> affected = new ArrayList<>(views.size()); TopLevelItem parent = getTopLevelParent(run); if (parent != null) { for (View view : views) { if (view.contains(parent)) { affected.add(view); } } } else { LOG.log(Level.WARNING, run.getParent().getClass() + " not instanceof TopLevelItem"); } return affected; }
public void trackViews(Run<?, ?> run) { Collection<View> affectedViews = getViewsAffectedBy(run); if (run.isBuilding()) { ensureInitialState(affectedViews); } else { fireDifference(affectedViews); } }
private void fireDifference(Collection<View> affectedViews) { for (View view : affectedViews) { String key = key(view); Result newResult = getResult(view); Result oldResult = results.get(key); if(oldResult != null && !oldResult.equals(newResult)) { results.put(key, newResult); fireViewChanged(view, oldResult, newResult); } } }
private Result getResult(View view) { Result ret = Result.SUCCESS; for (TopLevelItem item : view.getAllItems()) { for (Job<?,?> job : item.getAllJobs()) { Run<?, ?> build = job.getLastCompletedBuild(); if(build != null) { Result result = build.getResult(); if(result.isBetterOrEqualTo(Result.FAILURE)) ret = ret.combine(result); } } } return ret; }
private void ensureInitialState(Collection<View> affectedViews) { for (View view : affectedViews) { String key = key(view); if (!results.containsKey(key)) { results.put(key, getResult(view)); } } }
@Override public ACL getACL(final View item) { return new ACL() { @Override public boolean hasPermission(Authentication a, Permission permission) { ACL base = item.getOwner().getACL(); CloudProject cloudProject = cloudProjects.get(AclType.PROJECT); if(item == null || null == cloudProject){ return true; } Set<Project> matchedViewProjects = cloudProject .getMatchedViewsProjects(item.getViewName()); String currentUserId = DescriptorImpl.getCurrentUser(); for (Project project : matchedViewProjects) { Set<String> members = cloudProject .listProjectMembers(project.getProjectName()); if (members.contains(currentUserId)) { if (permission == View.READ) { return base.hasPermission(a, View.CONFIGURE) || !item.getItems().isEmpty(); } return base.hasPermission(a, permission); } } return false; } }; }
/** * Overrides view initialization to use BranchListView instead of AllView. * <br> * {@inheritDoc} */ @Override protected void initViews(List<View> views) throws IOException { BranchListView v = new BranchListView("All", this); v.setIncludeRegex(".*"); views.add(v); v.save(); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); project = jenkins.createFreeStyleProject("test"); final AbstractRestriction restriction = new NoRestriction(); underTest = new Binder.Default(restriction.getClassLoader( new RestrictedProject<AbstractProject>() { @Override public AbstractProject asProject() { return project; } @Override public AbstractRestriction getRestriction() { return restriction; } })); views = Lists.newArrayList(); viewGroupMixIn = new ViewGroupMixIn(Jenkins.getInstance()) { /** {@inheritDoc} */ @Override protected List<View> views() { return views; } /** {@inheritDoc} */ @Override protected String primaryView() { throw new UnsupportedOperationException(); } /** {@inheritDoc} */ @Override protected void primaryView(String name) { throw new UnsupportedOperationException(); } }; }
@Test public void testBindView_simple() throws Exception { JSONObject json = (JSONObject) JSONSerializer.toJSON(EMPTY_LIST_VIEW); json.put("name", NAME); View view = underTest.bindView(viewGroupMixIn, NAME, json); assertNotNull(view); assertThat(view, instanceOf(ListView.class)); assertEquals(NAME, view.getViewName()); assertTrue(views.contains(view)); }
public TestImpl(ItemGroup parent, String name, ViewsTabBar tabBar, List<View> views, ViewGroupMixIn mixIn) throws IOException { super(parent, name); this.viewsTabBar = tabBar; this.views = views; views.add(new AllView("foo", this)); this.primaryViewName = PRIMARY_VIEW_NAME; super.init(); this.viewGroupMixIn = mixIn; }
private void init(final String name) { if (this.icon == null) { this.icon = new OrganizationGravatarIcon(name); } this.mixin = new MixInImpl(this); if (this.views == null) { this.views = new CopyOnWriteArrayList<>(); } if (this.views.size() == 0) { final AllListView lv = new AllListView(this); this.views.add(lv); } if (this.viewsTabBar == null) { this.viewsTabBar = new DefaultViewsTabBar(); } if (this.primaryView == null) { this.primaryView = this.views.get(0).getViewName(); } this.mixin = new MixInImpl(this); this.viewGroupMixIn = new ViewGroupMixIn(this) { @Override protected List<View> views() { return OrganizationContainer.this.views; } @Override protected String primaryView() { return OrganizationContainer.this.primaryView; } @Override protected void primaryView(final String name) { OrganizationContainer.this.primaryView = name; } }; this.items = new CopyOnWriteMap.Tree<>(CaseInsensitiveComparator.INSTANCE); this.items = getJobsForThisContainer(); }
public String name() { ItemGroup ig = null; StaplerRequest request = Stapler.getCurrentRequest(); for( Ancestor a : request.getAncestors() ) { if(a.getObject() instanceof BuildMonitorView) { ig = ((View) a.getObject()).getOwnerItemGroup(); } } return Functions.getRelativeDisplayNameFrom(job, ig); }
private void notifyView(Item item, String oldName, String newName) { Collection<View> views = JenkinsUtil.getInstance().getViews(); for (View view : views) { if (view instanceof DeliveryPipelineView) { ((DeliveryPipelineView) view).onProjectRenamed(item, oldName, newName); } } }
@Test @Ignore public void defaultView() throws Exception { FreeStyleProject projectA = jenkins.createFreeStyleProject("A"); jenkins.createFreeStyleProject("B"); projectA.getPublishersList().add(new BuildPipelineTrigger("B", null)); DeliveryPipelineView view = new DeliveryPipelineView("Pipeline"); List<DeliveryPipelineView.ComponentSpec> specs = new ArrayList<>(); specs.add(new DeliveryPipelineView.ComponentSpec("Component", "A", NONE, DO_NOT_SHOW_UPSTREAM)); view.setComponentSpecs(specs); view.setAllowManualTriggers(true); view.setAllowRebuild(true); jenkins.getInstance().rebuildDependencyGraph(); jenkins.getInstance().addView(view); jenkins.getInstance().setPrimaryView(view); View all = jenkins.getInstance().getView("All"); jenkins.getInstance().deleteView(all); projectA.scheduleBuild(0, null); jenkins.waitUntilNoActivity(); NewJobPage newJobPage = new NewJobPage(webDriver, jenkins.getURL() + "view/Pipeline"); newJobPage.open(); newJobPage.setJobName("NewJob"); newJobPage.setFreeStyle(); ConfigureJobPage configureJobPage = newJobPage.submit(); configureJobPage.submit(); assertNotNull(jenkins.getInstance().getItemByFullName("NewJob")); }
@Test public void createACopyOfView() throws Exception { view("SrcView").add(project); assertThat(command.invoke("view/SrcView", "view/DstView1", "view/DstView2"), succeeded()); View dstView1 = j.jenkins.getView("DstView1"); assertTrue(dstView1.contains(project)); View dstView2 = j.jenkins.getView("DstView2"); assertTrue(dstView2.contains(project)); }
@Test public void createACopyOfViewOverwritingDestination() throws Exception { view("SrcView").add(project); view("DstView1"); view("DstView2"); assertThat(command.opts("-f").invoke("view/SrcView", "view/DstView1", "view/DstView2"), succeeded()); View dstView1 = j.jenkins.getView("DstView1"); assertTrue(dstView1.contains(project)); View dstView2 = j.jenkins.getView("DstView2"); assertTrue(dstView2.contains(project)); }
@Test public void abortCloningSinceTheDestinationAlreadyExists() throws Exception { view("SrcView").add(project); view("DstView"); assertThat(command.invoke("view/SrcView", "view/DstView"), not(succeeded())); View dstView = j.jenkins.getView("DstView"); assertFalse(dstView.contains(project)); }
@Test @Ignore(value="TODO: Update CreateViewCommand to create view in arbitrary ViewGroup") public void cloneNestedView() throws IOException { NestedView group = viewGroup("group"); ListView srcView = view("SrcView", group); srcView.add(project); assertThat(command.invoke("view/group/view/SrcView", "view/TopLevelView", "view/group/view/NestedView"), succeeded()); View topLevelView = j.jenkins.getView("TopLevelView"); assertTrue(topLevelView.contains(project)); View nestedView = ((NestedView) j.jenkins.getView("group")).getView("NostedView"); assertTrue(nestedView.contains(project)); }
@Test public void performTransformation() throws Exception { ListView view = view("SrcView"); view.setIncludeRegex("originalRegex"); view.add(project); assertThat(command.opts("-e", "s/original/replaced/").invoke("view/SrcView", "view/DstView"), succeeded()); View dstView = j.jenkins.getView("DstView"); assertTrue(dstView.contains(project)); }
@Test public void overwriteDryRun() throws Exception { view("SrcView").add(project); view("DstView"); assertThat(command.opts("--force", "--dry-run").invoke("view/SrcView", "view/DstView"), succeeded()); View dstView = j.jenkins.getView("DstView"); assertFalse("Destination should not be overwritten", dstView.contains(project)); }
/** * Constructs a filter using specified default values. */ JobsFilter(View owner, Collection<? extends ViewJobFilter> jobFilters, String includeRegex, Boolean statusFilter) throws PatternSyntaxException { this.jobFilters = (jobFilters != null) ? new DescribableList<ViewJobFilter, Descriptor<ViewJobFilter>>(owner, jobFilters) : new DescribableList<ViewJobFilter, Descriptor<ViewJobFilter>>(owner); this.includeRegex = includeRegex; this.statusFilter = statusFilter; this.includePattern = (includeRegex != null) ? Pattern.compile(includeRegex) : null; }
/** * Constructs a filter from the StaplerRequest. This constructor is just a * modified copy of ListView's configure method. * * @param req Stapler Request * @param parentView Parent View, which has created filter */ JobsFilter(StaplerRequest req, View parentView) throws Descriptor.FormException, IOException, ServletException { jobFilters = new DescribableList<ViewJobFilter, Descriptor<ViewJobFilter>>(parentView); jobFilters.rebuildHetero(req, req.getSubmittedForm(), ViewJobFilter.all(), "jobFilters"); includeRegex = Util.nullify(req.getParameter("_.includeRegex")); this.includePattern = (includeRegex != null) ? Pattern.compile(includeRegex) : null; String filter = Util.fixEmpty(req.getParameter("statusFilter")); statusFilter = filter != null ? "1".equals(filter) : null; }
public View getOwner() { StaplerRequest request = Stapler.getCurrentRequest(); if (request != null) { View view = request.findAncestorObject(View.class); if (view != null) { return view; } } return Hudson.getInstance().getView("All"); }
@Override public void fireViewChanged(View view, Result oldResult, Result newResult) { chat(format("view/%s, %s -> %s", view.getDisplayName(), oldResult, newResult)); }
private void fireViewChanged(View view, Result oldResult, Result newResult) { for (ViewListener viewListener : listeners) { viewListener.fireViewChanged(view, oldResult, newResult); } }
private String key(View view) { return view.getDisplayName(); }
@Override public Collection<PermissionGroup> getApplicablePermissionGroups() { return asList(PermissionGroup.get(Item.class), PermissionGroup.get(View.class)); }
/** {@inheritDoc} */ @Override public void onViewRenamed(View view, String oldName, String newName) { throw new UnsupportedOperationException(); }
/** {@inheritDoc} */ @Override public void deleteView(View view) { throw new UnsupportedOperationException(); }
/** {@inheritDoc} */ @Override public boolean canDelete(View view) { return false; }
/** The action of newView.jelly */ public synchronized void doCreateView(StaplerRequest req, StaplerResponse rsp) throws FormException, IOException, ServletException { addView(View.create(req, rsp, this)); }