Package hudson.model

Examples of hudson.model.TopLevelItem


        String rootUrl = Jenkins.getInstance().getRootUrl() == null ? "/" : Jenkins.getInstance().getRootUrl();
        response.sendRedirect(rootUrl + getUrlName());
    }

    private TopLevelItem cloneJob(AbstractProject jobToClone, String newName, Map<String, String> variableValues) throws IOException, ServletException {
        TopLevelItem result = null;

        TemplateBuildWrapper templateBuildWrapper = BuildWrapperUtils.findBuildWrapper(TemplateBuildWrapper.class, jobToClone);
        if (templateBuildWrapper != null) {
            if (jobToClone instanceof TopLevelItem) {
                @SuppressWarnings("RedundantCast") //Need to cast to get the generics to work properly
                        Class<? extends TopLevelItem> jobClass = ((TopLevelItem) jobToClone).getClass();
                TopLevelItem newJob = Jenkins.getInstance().createProject(jobClass, newName);

                if (newJob != null && newJob instanceof BuildableItemWithBuildWrappers) {
                    // If the target job (jobToClone) is actually a template, let's implement it rather than just clone it.

                    BuildableItemWithBuildWrappers buildable = (BuildableItemWithBuildWrappers) newJob;
                    DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappersList = buildable.getBuildWrappersList();
                    TemplateBuildWrapper toRemove = BuildWrapperUtils.findBuildWrapper(TemplateBuildWrapper.class, buildable);
                    buildWrappersList.remove(toRemove);

                    String variablesAsPropertiesFile = squashVariables(variableValues);
                    ImplementationBuildWrapper implementationBuildWrapper = new ImplementationBuildWrapper(jobToClone.getName(), newJob.getName(), variablesAsPropertiesFile);
                    buildWrappersList.add(implementationBuildWrapper);
                    newJob.save();
                    result = newJob;
                    implementationBuildWrapper.sync();

                }
            }
View Full Code Here


     * <p>
     * This is a short cut for deleting an existing job and adding a new one.
     */
    public synchronized void putItem(TopLevelItem item) throws IOException, InterruptedException {
        String name = item.getName();
        TopLevelItem old = items.get(name);
        if (old ==itemreturn; // noop

        checkPermission(Item.CREATE);
        if (old!=null)
            old.delete();
        items.put(name,item);
        ItemListener.fireOnCreated(item);
    }
View Full Code Here

        });

        for (final File subdir : subdirs) {
            g.requires(loadHudson).attains(JOB_LOADED).notFatal().add("Loading job "+subdir.getName(),new Executable() {
                public void run(Reactor session) throws Exception {
                    TopLevelItem item = (TopLevelItem) Items.load(Jenkins.this, subdir);
                    items.put(item.getName(), item);
                }
            });
        }

        g.requires(JOB_LOADED).add("Finalizing set up",new Executable() {
View Full Code Here

    @SuppressWarnings("rawtypes")
    public int parseArguments(Parameters params) throws CmdLineException {
        Jenkins h = Jenkins.getInstance();
        String src = params.getParameter(0);

        TopLevelItem s = h.getItem(src);
        if (s==null) {
            AbstractProject nearest = AbstractProject.findNearest(src);
            if (nearest!=null)
                throw new CmdLineException(owner, "No such job '"+src+"' perhaps you meant '"+ nearest.getFullName() +"'?");
            else
View Full Code Here

     *
     * Note that the look up is case-insensitive.
     */
    public TopLevelItem getItem(String name) {
        if (name==null)    return null;
      TopLevelItem item = items.get(name);
        if (item==null)
            return null;
        if (!item.hasPermission(Item.READ)) {
            if (item.hasPermission(Item.DISCOVER)) {
                throw new AccessDeniedException("Please login to access job " + name);
            }
            return null;
        }
        return item;
View Full Code Here

                } else {
                    throw new NoMetadataException("The node " + node + " has no associated metadata.");
                }
            }
        } else if (job != null && !job.isEmpty()) {
            TopLevelItem item = Hudson.getInstance().getItem(job);
            if (item != null && item instanceof AbstractProject) {
                AbstractProject project = (AbstractProject)item;
                if (build != null && build >= 0) {
                    Run buildByNumber = project.getBuildByNumber(build);
                    if (buildByNumber != null) {
View Full Code Here

        name = new StringMetadataValue("name", "description", "somc");
        list.add(name);
        MetadataJobProperty property2 = project2.getProperty(MetadataJobProperty.class);
        property2.addChildren(list);
        MetadataQuerySearch mqs = MetadataQuerySearch.parseQuery("name=somc && dept=tool");
        TopLevelItem tli1 = project;
        TopLevelItem tli2 = project2;
        List itemList = new ArrayList();
        itemList.add(tli1);
        itemList.add(tli2);
       assertEquals(1, mqs.searchQuery(itemList).size());
    }
View Full Code Here

        name = new StringMetadataValue("name", "description", "somc");
        list.add(name);
        MetadataJobProperty property2 = project2.getProperty(MetadataJobProperty.class);
        property2.addChildren(list);
        MetadataQuerySearch mqs = MetadataQuerySearch.parseQuery("name=somc || dept=tool");
        TopLevelItem tli1 = project;
        TopLevelItem tli2 = project2;
        List itemList = new ArrayList();
        itemList.add(tli1);
        itemList.add(tli2);
        assertEquals(2, mqs.searchQuery(itemList).size());
    }
View Full Code Here

        name = new StringMetadataValue("name", "description", "somc");
        list.add(name);
        MetadataJobProperty property2 = project2.getProperty(MetadataJobProperty.class);
        property2.addChildren(list);
        MetadataQuerySearch mqs = MetadataQuerySearch.parseQuery("dept=tool");
        TopLevelItem tli1 = project;
        TopLevelItem tli2 = project2;
        List itemList = new ArrayList();
        itemList.add(tli1);
        itemList.add(tli2);
       assertEquals(1, mqs.searchQuery(itemList).size());
    }
View Full Code Here

        number = new NumberMetadataValue("number", "description", NUMBR_VAL2, false);
        list.add(number);
        MetadataJobProperty property2 = project2.getProperty(MetadataJobProperty.class);
        property2.addChildren(list);
        MetadataQuerySearch mqs = MetadataQuerySearch.parseQuery("number>=5");
        TopLevelItem tli1 = project;
        TopLevelItem tli2 = project2;
        List itemList = new ArrayList();
        itemList.add(tli1);
        itemList.add(tli2);
       assertEquals(2, mqs.searchQuery(itemList).size());
    }
View Full Code Here

TOP

Related Classes of hudson.model.TopLevelItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.