コード例 #1
0
ファイル: AbstractItem.java プロジェクト: hanf1983/jenkins
    /**
     * Updates Job by its XML definition.
     * @since 1.473
     */
    public void updateByXml(Source source) throws IOException {
        checkPermission(CONFIGURE);
        XmlFile configXmlFile = getConfigFile();
        AtomicFileWriter out = new AtomicFileWriter(configXmlFile.getFile());
        try {
            try {
                // this allows us to use UTF-8 for storing data,
                // plus it checks any well-formedness issue in the submitted
                // data
                Transformer t = TransformerFactory.newInstance()
                        .newTransformer();
                t.transform(source,
                        new StreamResult(out));
                out.close();
            } catch (TransformerException e) {
                throw new IOException("Failed to persist config.xml", e);
            }

            // try to reflect the changes by reloading
            new XmlFile(Items.XSTREAM, out.getTemporaryFile()).unmarshal(this);
            Items.whileUpdatingByXml(new Callable<Void,IOException>() {
                @Override public Void call() throws IOException {
                    onLoad(getParent(), getRootDir().getName());
                    return null;
                }
            });
            Jenkins.getInstance().rebuildDependencyGraphAsync();

            // if everything went well, commit this new version
            out.commit();
            SaveableListener.fireOnChange(this, getConfigFile());
        } finally {
            out.abort(); // don't leave anything behind
        }
    }
コード例 #2
0
ファイル: AbstractItem.java プロジェクト: hanf1983/jenkins
    /**
     * Accepts <tt>config.xml</tt> submission, as well as serve it.
     */
    @WebMethod(name = "config.xml")
    public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp)
            throws IOException {
        if (req.getMethod().equals("GET")) {
            // read
            checkPermission(EXTENDED_READ);
            rsp.setContentType("application/xml");
            IOUtils.copy(getConfigFile().getFile(),rsp.getOutputStream());
            return;
        }
        if (req.getMethod().equals("POST")) {
            // submission
            updateByXml((Source)new StreamSource(req.getReader()));
            return;
        }

        // huh?
        rsp.sendError(SC_BAD_REQUEST);
    }
コード例 #3
0
ファイル: AbstractItem.java プロジェクト: hanf1983/jenkins
    /**
     * Deletes this item.
     *
     * <p>
     * Any exception indicates the deletion has failed, but {@link AbortException} would prevent the caller
     * from showing the stack trace. This
     */
    public synchronized void delete() throws IOException, InterruptedException {
        checkPermission(DELETE);
        performDelete();

        // defer the notification to avoid the lock ordering problem. See JENKINS-19446.
        MasterComputer.threadPoolForRemoting.submit(new java.util.concurrent.Callable<Void>() {
            @Override
            public Void call() throws Exception {
                invokeOnDeleted();
                Jenkins.getInstance().rebuildDependencyGraphAsync();
                return null;
            }

            /**
             * A pointless function to work around what appears to be a HotSpot problem. See JENKINS-5756 and bug 6933067
             * on BugParade for more details.
             */
            private void invokeOnDeleted() throws IOException {
                getParent().onDeleted(AbstractItem.this);
            }
        });
    }
コード例 #4
0
ファイル: AbstractItem.java プロジェクト: hanf1983/jenkins
    /**
     * Accepts the new description.
     */
    public synchronized void doSubmitDescription( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
        checkPermission(CONFIGURE);

        setDescription(req.getParameter("description"));
        rsp.sendRedirect(".");  // go to the top page
    }