FreeStyleProject.java 3.8 KB
Newer Older
K
kohsuke 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * The MIT License
 * 
 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, id:cactusman
 * 
 * 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.
 */
24 25
package hudson.model;

K
kohsuke 已提交
26
import hudson.Extension;
27

28 29 30 31 32 33 34 35
import java.io.File;
import java.io.IOException;

import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import javax.servlet.ServletException;

36 37 38 39 40 41
/**
 * Free-style software project.
 * 
 * @author Kohsuke Kawaguchi
 */
public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> implements TopLevelItem {
42
    /**
43
     * See {@link #setCustomWorkspace(String)}.
44 45 46 47
     *
     * @since 1.216
     */
    private String customWorkspace;
48

49 50 51
    /**
     * @deprecated as of 1.390
     */
52 53 54 55
    public FreeStyleProject(Hudson parent, String name) {
        super(parent, name);
    }

56 57
    public FreeStyleProject(ItemGroup parent, String name) {
        super(parent, name);
58 59 60
    }

    @Override
61 62
    protected Class<FreeStyleBuild> getBuildClass() {
        return FreeStyleBuild.class;
63 64
    }

65 66 67 68
    public String getCustomWorkspace() {
        return customWorkspace;
    }

69 70 71 72 73 74 75 76 77 78 79 80
    /**
     * User-specified workspace directory, or null if it's up to Hudson.
     *
     * <p>
     * Normally a free-style project uses the workspace location assigned by its parent container,
     * but sometimes people have builds that have hard-coded paths (which can be only built in
     * certain locations. see http://www.nabble.com/Customize-Workspace-directory-tt17194310.html for
     * one such discussion.)
     *
     * <p>
     * This is not {@link File} because it may have to hold a path representation on another OS.
     *
81 82 83 84
     * <p>
     * If this path is relative, it's resolved against {@link Node#getRootPath()} on the node where this workspace
     * is prepared. 
     *
85 86 87 88 89 90 91
     * @since 1.320
     */
    public void setCustomWorkspace(String customWorkspace) throws IOException {
        this.customWorkspace= customWorkspace;
        save();
    }

92
    @Override
93 94 95 96 97 98 99 100 101
    protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException {
        if(req.hasParameter("customWorkspace"))
            customWorkspace = req.getParameter("customWorkspace.directory");
        else
            customWorkspace = null;

        super.submit(req, rsp);
    }

102 103 104 105
    public DescriptorImpl getDescriptor() {
        return DESCRIPTOR;
    }

106
    @Extension(ordinal=1000)
107 108
    public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();

109
    public static final class DescriptorImpl extends AbstractProjectDescriptor {
110
        public String getDisplayName() {
C
cactusman 已提交
111
            return Messages.FreeStyleProject_DisplayName();
112 113
        }

114 115
        public FreeStyleProject newInstance(ItemGroup parent, String name) {
            return new FreeStyleProject(parent,name);
116 117 118
        }
    }
}