static LazyTopLevelItem newLazyTopLevelItem(TopLevelItem item) { // Don't wrap - make this method idempotent if (item instanceof LazyTopLevelItem) { return (LazyTopLevelItem) item; } return newLazyTopLevelItem(item.getParent(), item.getRootDir(), item); }
/** * Handles the configuration submission. * * <p>Load view-specific properties here. */ @Override protected void submit(StaplerRequest req) throws ServletException, FormException, IOException { jobNames.clear(); for (TopLevelItem item : Hudson.getInstance().getItems()) { if (req.getParameter(item.getName()) != null) jobNames.add(item.getName()); } if (req.getParameter("useincluderegex") != null) { includeRegex = Util.nullify(req.getParameter("includeRegex")); if (includeRegex == null) includePattern = null; else includePattern = Pattern.compile(includeRegex); } else { includeRegex = null; includePattern = null; } if (columns == null) { columns = new DescribableList<ListViewColumn, Descriptor<ListViewColumn>>(Saveable.NOOP); } columns.rebuildHetero(req, req.getSubmittedForm(), ListViewColumn.all(), "columns"); if (jobFilters == null) { jobFilters = new DescribableList<ViewJobFilter, Descriptor<ViewJobFilter>>(Saveable.NOOP); } jobFilters.rebuildHetero(req, req.getSubmittedForm(), ViewJobFilter.all(), "jobFilters"); String filter = Util.fixEmpty(req.getParameter("statusFilter")); statusFilter = filter != null ? "1".equals(filter) : null; }
/** * Returns a read-only view of all {@link Job}s in this view. * * <p>This method returns a separate copy each time to avoid concurrent modification issue. */ public synchronized List<TopLevelItem> getItems() { SortedSet<String> names = new TreeSet<String>(jobNames); if (includePattern != null) { for (TopLevelItem item : Hudson.getInstance().getItems()) { String itemName = item.getName(); if (includePattern.matcher(itemName).matches()) { names.add(itemName); } } } List<TopLevelItem> items = new ArrayList<TopLevelItem>(names.size()); for (String n : names) { TopLevelItem item = Hudson.getInstance().getItem(n); // Add if no status filter or filter matches enabled/disabled status: if (item != null && (statusFilter == null || !(item instanceof AbstractProject) || ((AbstractProject) item).isDisabled() ^ statusFilter)) items.add(item); } // check the filters Iterable<ViewJobFilter> jobFilters = getJobFilters(); List<TopLevelItem> allItems = Hudson.getInstance().getItems(); for (ViewJobFilter jobFilter : jobFilters) { items = jobFilter.filter(items, allItems, this); } return items; }
public synchronized TopLevelItem createProject( TopLevelItemDescriptor type, String name, boolean notify) throws IOException { acl.checkPermission(Job.CREATE); Jenkins.getInstance().getProjectNamingStrategy().checkName(name); if (parent.getItem(name) != null) throw new IllegalArgumentException("Project of the name " + name + " already exists"); TopLevelItem item; try { item = type.newInstance(parent, name); } catch (Exception e) { throw new IllegalArgumentException(e); } try { callOnCreatedFromScratch(item); } catch (AbstractMethodError e) { // ignore this error. Must be older plugin that doesn't have this method } item.save(); add(item); Jenkins.getInstance().rebuildDependencyGraph(); if (notify) ItemListener.fireOnCreated(item); return item; }
void addDisplayNamesToSearchIndex(SearchIndexBuilder sib, Collection<TopLevelItem> items) { for (TopLevelItem item : items) { if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine( (String.format( "Adding url=%s,displayName=%s", item.getSearchUrl(), item.getDisplayName()))); } sib.add(item.getSearchUrl(), item.getDisplayName()); } }
static LazyTopLevelItem newLazyTopLevelItem( ItemGroup parent, File configFileDir, TopLevelItem item) { // Sanity check if (item instanceof LazyTopLevelItem) { throw new IllegalStateException("Attempting to wrap LazyTopLevelItem " + item.getName()); } final XmlFile configFile = getConfigFile(configFileDir); return new LazyTopLevelItem(configFile, parent, configFileDir.getName(), item); }
public FilePath getWorkspaceFor(TopLevelItem item) { for (WorkspaceLocator l : WorkspaceLocator.all()) { FilePath workspace = l.locate(item, this); if (workspace != null) { return workspace; } } FilePath r = getWorkspaceRoot(); if (r == null) return null; // offline return r.child(item.getFullName()); }
/** Gets the encrypted usage stat data to be sent to the Hudson server. */ public String getStatData() throws IOException { Jenkins j = Jenkins.getInstance(); JSONObject o = new JSONObject(); o.put("stat", 1); o.put("install", j.getLegacyInstanceId()); o.put("servletContainer", j.servletContext.getServerInfo()); o.put("version", Jenkins.VERSION); List<JSONObject> nodes = new ArrayList<JSONObject>(); for (Computer c : j.getComputers()) { JSONObject n = new JSONObject(); if (c.getNode() == j) { n.put("master", true); n.put("jvm-vendor", System.getProperty("java.vm.vendor")); n.put("jvm-name", System.getProperty("java.vm.name")); n.put("jvm-version", System.getProperty("java.version")); } n.put("executors", c.getNumExecutors()); DescriptorImpl descriptor = j.getDescriptorByType(DescriptorImpl.class); n.put("os", descriptor.get(c)); nodes.add(n); } o.put("nodes", nodes); List<JSONObject> plugins = new ArrayList<JSONObject>(); for (PluginWrapper pw : j.getPluginManager().getPlugins()) { if (!pw.isActive()) continue; // treat disabled plugins as if they are uninstalled JSONObject p = new JSONObject(); p.put("name", pw.getShortName()); p.put("version", pw.getVersion()); plugins.add(p); } o.put("plugins", plugins); JSONObject jobs = new JSONObject(); List<TopLevelItem> items = j.getAllItems(TopLevelItem.class); for (TopLevelItemDescriptor d : Items.all()) { int cnt = 0; for (TopLevelItem item : items) { if (item.getDescriptor() == d) cnt++; } jobs.put(d.getJsonSafeClassName(), cnt); } o.put("jobs", jobs); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); // json -> UTF-8 encode -> gzip -> encrypt -> base64 -> string OutputStreamWriter w = new OutputStreamWriter( new GZIPOutputStream(new CombinedCipherOutputStream(baos, getKey(), "AES")), "UTF-8"); try { o.write(w); } finally { IOUtils.closeQuietly(w); } return new String(Base64.encode(baos.toByteArray())); } catch (GeneralSecurityException e) { throw new Error(e); // impossible } }
public boolean contains(TopLevelItem item) { return jobNames.contains(item.getName()); }
/** Pointless wrapper to avoid HotSpot problem. See JENKINS-5756 */ private void callOnCreatedFromScratch(TopLevelItem item) { item.onCreatedFromScratch(); }
/** Computes the redirection target URL for the newly created {@link TopLevelItem}. */ protected String redirectAfterCreateItem(StaplerRequest req, TopLevelItem result) throws IOException { return req.getContextPath() + '/' + result.getUrl() + "configure"; }
public ContextMenu doChildrenContextMenu(StaplerRequest request, StaplerResponse response) throws Exception { ContextMenu m = new ContextMenu(); for (TopLevelItem i : getItems()) m.add(i.getShortUrl(), i.getDisplayName()); return m; }