Subversion Repositories DevTools

Rev

Rev 7082 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6914 dpurdie 1
package com.erggroup.buildtool.ripple;
2
 
3
import java.util.ArrayList;
4
 
7033 dpurdie 5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
6914 dpurdie 7
 
8
import com.erggroup.buildtool.utilities.XmlBuilder;
9
 
10
/**
11
 * entity class representing how derived files are produced on a platform
12
 * Recognizes that a package may have different build standards on different platforms
13
 * for example, Jats may be used to build production code on a win32 build machine and debug code on a solaris build
14
 * machine
15
 * potentially supports mixing build standards
16
 * for example, Jats may be used to build code on one build machine, and ERG ant on another
17
 * this is not supported in the release manager 
18
 *  
19
 * This package maps the BuildStandard Family (Windows,Linux,Solaris) to the underlying 
20
 * Machine Types based on information provided by the Release Manager Database
21
 *  
22
 */
23
public class BuildStandard
24
{
25
    /**
26
     * Logger
27
     * 
28
     * @attribute
29
     */
7033 dpurdie 30
    private static final Logger mLogger     = LoggerFactory.getLogger(BuildStandard.class);
6914 dpurdie 31
 
32
    /**
33
     * engine associated with the baseline in which this packages build standard is owned
34
     * 
35
     * @aggregation composite
36
     */
37
    private RippleEngine        mRippleEngine;
38
 
39
    /**
40
     * 
41
     * @attribute
42
     */
43
    private boolean             mGeneric    = false;
44
 
45
    /**
46
     * When true the package can be built using one of the known standards
47
     * 
48
     */
49
    private boolean             mSupported  = true;
50
 
51
    /**
52
     * build Family: Linux, Win32, Solaris, ...
53
     */
54
    public String mMachClass = null;
55
 
56
    /**
57
     * Array of build machine types: win32, solaris, solaris10_x86 ....
58
     */
59
    public ArrayList<String>   mMachTypes =  null;
60
 
61
    /**
62
     * Items to assist in creating platform and standard descriptions
63
     */
64
    String mType = null;
65
    String mData = null;
66
    String mFriendly = null;
67
 
68
 
69
    /**
70
     * Constructor
71
     * The only method to create and modify the Build Standard Information
72
     * Once set it cannot be modified - this greatly simplifies its implementation
73
     * 
74
     * Since the class captures data from the Ripple Engine the data is only valid for the duration of a
75
     * build cycle. When the machine information is refreshed from database the data in this class 
76
     * will be stale. This is not an issue as the package data is discarded on every planning cycle.
77
     */
78
    public BuildStandard(RippleEngine rippleEngine, String buildMachineFamily, String buildStandardAddendum)
79
    {
80
        mLogger.debug("BuildStandard");
81
        mRippleEngine = rippleEngine;
82
        mMachClass = buildMachineFamily;
83
 
84
        //
85
        //  Convert the provided Machine Class into an array of Machine Types
86
        //  Generic is special
87
        //      EscrowMode:     Generic is treated as all known (in the buildset) platforms
88
        //      DeaemonMode:    Generic is treated as the master machine type
89
        //
90
        if (buildMachineFamily.compareTo("Generic") == 0)
91
        {
92
            mGeneric = true;
93
 
94
            if(mRippleEngine.mDaemon)
95
            {
96
                mMachTypes = new ArrayList<String>();
97
                mMachTypes.add(Package.mGenericMachtype);
98
            }
99
            else
100
            {
101
                mMachTypes = mRippleEngine.mReleaseManager.mReleaseConfigCollection.mMachineTypes;
102
            }
103
        }
104
        else
105
        {
106
            // Not Generic
107
            //  Create a list of machine types based on the conversion from machClass to the machTypes in 
108
            //  the current build set
109
            //  
110
            mMachTypes = mRippleEngine.mReleaseManager.mReleaseConfigCollection.mMachineHash.get(mMachClass);
111
        }
112
 
113
        if (mMachTypes == null || mMachTypes.size() == 0)
114
        {
115
            mSupported = false;
116
        }
117
 
118
        if (buildStandardAddendum.compareTo("Production") == 0)
119
        {
120
            mType = "jats";
121
            mData = "production";
122
            mFriendly = "Jats Production";
123
        }
124
        else if (buildStandardAddendum.compareTo("Debug") == 0)
125
        {
126
            mType = "jats";
127
            mData = "debug";
128
            mFriendly = "Jats Debug";
129
        }
130
        else if (buildStandardAddendum.compareTo("Production and Debug") == 0)
131
        {
132
            mType = "jats";
133
            mData = "all";
134
            mFriendly = "Jats All";
135
        }
136
        else if (buildStandardAddendum.startsWith("Java "))
137
        {
138
            mType = "ant";
139
            mData = buildStandardAddendum.substring(5);
140
            mFriendly = "Ant Java " + mData;
141
        }
142
        else
143
        {
144
            mSupported = false;
145
            mType = "jats";
146
            mData = "unknown";
147
            mFriendly = "Jats Unknown";
148
        }
149
    }
150
 
151
 
152
    /**
153
     * returns for xml purposes
154
     * "<platform machtype="win32"             method="jats" arg="all"/>",
155
     * "<platform machtype="solaris10_sparc32" method="ant"  arg="java 1.6"/>"
156
     * "<platform machtype="solaris10_x86"     method="ant"  arg="java 1.6"/>"
157
     * "<platform machtype="sparc"             method="ant"  arg="java 1.6"/>"
158
     * "<platform machtype="linux_i386"        method="jats" arg="prod"/>"
159
     * 
160
     * May return multiple lines
161
     */
162
 
163
    public void getBuildStandardXml(XmlBuilder xml)
164
    {
165
        mLogger.debug("getBuildStandardXml");
166
        if (mMachTypes != null && mSupported)
167
        {
168
            for (String item : mMachTypes)
169
            {
170
            	XmlBuilder entry = xml.addNewElement("buildinfo");
171
            	entry.addAttribute("machtype", item);
172
            	entry.addAttribute("method", mType);
173
            	if (mData != null)
174
                {
175
            		entry.addAttribute("arg", mData);
176
                }
177
            }
178
        }
179
 
7176 dpurdie 180
        mLogger.debug("getBuildStandardXml returned {}", xml.toString());
6914 dpurdie 181
    }
182
 
183
    /**
184
     * returns for text (email) purposes
185
     * win32: jats all
186
     * solaris10_sparc32: ant java 1.6
187
     * solaris10_x86: ant java 1.6
188
     * sparc: ant java 1.6
189
     * linux_i386: jats prod
190
     * 
191
     * May return multiple lines, separated by <br> as the string is intended for use in email
192
     */
193
 
194
    public String getBuildStandard()
195
    {
196
        mLogger.debug("getBuildStandard");
197
        String retVal = new String();
198
        if (mMachTypes != null && mSupported)
199
        {
200
            String joiner1 = "";
201
            for (String item : mMachTypes)
202
            {
203
                retVal += joiner1 + item + ":" + mFriendly;
204
                joiner1 = "<br>";
205
            }
206
        }
207
 
7176 dpurdie 208
        mLogger.debug("getBuildStandard returned {}", retVal);
6914 dpurdie 209
        return retVal;
210
    }
211
 
212
    /**
213
     * Get a string that describes the Build Standard
214
     * It will be used within emails and info within XML files.
215
     * 
216
     * Expected format:
217
     *      machineClass:standard
218
     *      
219
     * May be an empty string - if there is no build standard.
220
     */
221
    public String getBuildStandardText()
222
    {
223
        String  rv = "";
224
 
225
        // No build standard
226
        if (!mSupported)
227
        {
228
            return rv;
229
        }
230
 
231
        rv += mMachClass + ":" + mFriendly;
232
        return rv;
233
    }
234
 
235
    /**
236
     * accessor method
237
     */
238
    public boolean isGeneric()
239
    {
7176 dpurdie 240
        mLogger.debug("getGeneric returned {}", mGeneric);
6914 dpurdie 241
        return mGeneric;
242
    }
243
 
244
    /**
245
     * accessor method
246
     */
247
    public boolean supportedBuildStandard()
248
    {
7176 dpurdie 249
        mLogger.debug("supportedBuildStandard returned {}", mSupported);
6914 dpurdie 250
        return mSupported;
251
    }
252
    /**
253
     * 
254
     * @return true if the Build Standard is active
255
     *         ie: This build standard will participate in the building of the package
256
     *        
257
     */
258
    public boolean isActive()
259
    {
260
        return (mSupported);
261
    }
262
 
263
}