Subversion Repositories DevTools

Rev

Rev 814 | Rev 864 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.erggroup.buildtool.ripple;

import java.util.Iterator;

import org.apache.log4j.Logger;

/**entity class representing how derived files are produced on a platform
 * recognises that a package may have different build standards on different platforms
 * for example, jats may be used to build production code on a win32 build machine and debug code on a solaris build machine
 * potentially supports mixing build standards
 * for example, jats may be used to build code on one build machine, and erg ant on another
 * this is not supported in the release manager 
 */
public class BuildStandard
{
  /**Logger
   * @attribute
   */
  private static final Logger mLogger = Logger.getLogger(BuildStandard.class);

  /**engine associated with the baseline in which this packages build standard is owned
   * @aggregation composite
   */
  private RippleEngine mRippleEngine;

  /**when true, the intent is to deliver Win32 derived content
   * in a daemon world, will be built on all Win32 based build machines associated with the baseline
   * will be accessed by Package::isWin32Built
   * @attribute
   */
  private boolean mWin32 = true;

  /**when true, the intent is to deliver Solaris derived content
   * in a daemon world, will be built on all Solaris based build machines associated with the baseline
   * will be accessed by Package::isSolarisBuilt
   * @attribute
   */
  private boolean mSolaris = false;

  /**when true, the intent is to deliver Linux derived content
   * in a daemon world, will be built on all Linux based build machines associated with the baseline
   * will be accessed by Package::isLinuxBuilt
   * @attribute
   */
  private boolean mLinux = false;

  /**when true, the intent is to deliver generic content
   * in a daemon build, will be built only on the build machine configured to run the Master build thread associated with the baseline
   * @attribute
   */
  private boolean mGeneric = false;

  /**when true, the intent is to deliver production code using jats
   * @attribute
   */
  private boolean mProduction = true;

  /**when true, the intent is to deliver debug code using jats
   * @attribute
   */
  private boolean mDebug = false;

  /**when true, the intent is to deliver java 1.4 built code
   * this is realized by using java 1.4 to launch ant
   * @attribute
   */
  private boolean mJava1_4 = false;

  /**when true, the intent is to deliver java 1.5 built code
   * this is realized by using java 1.5 to launch ant
   * @attribute
   */
  private boolean mJava1_5 = false;

  /**when true, the intent is to deliver java 1.6 built code
   * this is realized by using java 1.6 to launch ant
   * @attribute
   */
  private boolean mJava1_6 = false;
  
  private boolean mJatsNone = false;
  
  private boolean mAntNone = false;

  /**constructor
   */
  BuildStandard(RippleEngine rippleEngine)
  {
    mLogger.debug("BuildStandard");
    mRippleEngine = rippleEngine;
  }

  /**returns "<platform gbe_machtype="win32"/>",
   *         "<platform gbe_machtype="solaris10_sparc32"/>"
   *         "<platform gbe_machtype="solaris10_x86"/>"
   *         "<platform gbe_machtype="sparc"/>"
   *         "<platform gbe_machtype="linux_i386"/>"
   */
  String getPlatform(boolean utf)
  {
     mLogger.debug("getPlatform");  
     String retVal = new String();
     
     if (mGeneric && mRippleEngine.mDaemon)
     {
       mLogger.info("getPlatform mGeneric && mRippleEngine.mDaemon");
       retVal = "  <platform gbe_machtype=\"";
       
       if ( utf )
       {
         mLogger.info("getPlatform utf");
         // avoid reliance on environment variables
         retVal += "win32\"/>";
       }
       else
       {
         // Package.mGenericMachtype has been checked to be not null
         if ( Package.mGenericMachtype.compareTo("win32") == 0
           || Package.mGenericMachtype.compareTo("solaris10_sparc32") == 0
           || Package.mGenericMachtype.compareTo("solaris10_x86") == 0
           || Package.mGenericMachtype.compareTo("sparc") == 0
           || Package.mGenericMachtype.compareTo("linux_i386") == 0 )
         {
           retVal += Package.mGenericMachtype;
           retVal += "\"/>";
         }
       }
     }
     else if (mGeneric)
     {
       mLogger.info("getPlatform mGeneric");
       for (Iterator it = mRippleEngine.mGbeMachtypeCollection.iterator(); it.hasNext(); )
       {
         String gbemachtype = (String) it.next();

         if ( gbemachtype.compareTo("win32") == 0 ||
              gbemachtype.compareTo("linux_i386") == 0 ||
              gbemachtype.compareTo("sparc") == 0 ||
              gbemachtype.compareTo("solaris10_x86") == 0 ||
              gbemachtype.compareTo("solaris10_sparc32") == 0 )
         {
           if ( retVal.length() > 0 )
           {
             retVal += System.getProperty("line.separator");
           }
           retVal += "  <platform gbe_machtype=\"";
           retVal += gbemachtype;
           retVal += "\"/>";
         }
       }
     }
     else if (mWin32)
     {
       mLogger.info("getPlatform mWin32");
       for (Iterator it = mRippleEngine.mGbeMachtypeCollection.iterator(); it.hasNext(); )
       {
         String gbemachtype = (String) it.next();

         if ( gbemachtype.compareTo("win32") == 0 )
         {
           retVal = "  <platform gbe_machtype=\"win32\"/>";
           break;
         }
       }
     }
     else if (mSolaris)
     {
       mLogger.info("getPlatform mSolaris");
       for (Iterator it = mRippleEngine.mGbeMachtypeCollection.iterator(); it.hasNext(); )
       {
         String gbemachtype = (String) it.next();

         if ( gbemachtype.compareTo("sparc") == 0 || gbemachtype.compareTo("solaris10_x86") == 0 || gbemachtype.compareTo("solaris10_sparc32") == 0 )
         {
           if ( retVal.length() > 0 )
           {
             retVal += System.getProperty("line.separator");
           }
           retVal += "  <platform gbe_machtype=\"";
           retVal += gbemachtype;
           retVal += "\"/>";
         }
       }
     }
     else
     {
       mLogger.info("getPlatform mLinux");
       for (Iterator it = mRippleEngine.mGbeMachtypeCollection.iterator(); it.hasNext(); )
       {
         String gbemachtype = (String) it.next();

         if ( gbemachtype.compareTo("linux_i386") == 0 )
         {
           retVal = "  <platform gbe_machtype=\"linux_i386\"/>";
           break;
         }
       }
     }
     
     mLogger.info("getPlatform returned " + retVal);
     return retVal;
   }

  /**returns "<ant java="1.4"/>,
   *         "<ant java="1.5"/>,
   *         "<ant java="1.6"/>,
   *         "<ant java="none"/>,
   *         "<jats target="production"/>,
   *         "<jats target="debug"/>,
   *         "<jats target="all"/>
   *         "<jats target="none"/>
   */
  String getBuildStandard(boolean utf)
  {
    mLogger.debug("getBuildStandard");
    boolean validPlatform = false;
    int numberOfPlatforms = 0;
    String retVal = new String();
     
    if (mGeneric && mRippleEngine.mDaemon)
    {
      mLogger.info("getBuildStandard mGeneric && mRippleEngine.mDaemon");
     
      if ( utf )
      {
        mLogger.info("getBuildStandard utf");
        // avoid reliance on environment variables
        validPlatform = true;
        numberOfPlatforms = 1;
      }
      else
      {
        // Package.mGenericMachtype has been checked to be not null
        if ( Package.mGenericMachtype.compareTo("win32") == 0
          || Package.mGenericMachtype.compareTo("solaris10_sparc32") == 0
          || Package.mGenericMachtype.compareTo("solaris10_x86") == 0
          || Package.mGenericMachtype.compareTo("sparc") == 0
          || Package.mGenericMachtype.compareTo("linux_i386") == 0 )
        {
          validPlatform = true;
          numberOfPlatforms = 1;
        }
      }
    }
    else if (mGeneric)
    {
      mLogger.info("getBuildStandard mGeneric");
      for (Iterator it = mRippleEngine.mGbeMachtypeCollection.iterator(); it.hasNext(); )
      {
        String gbemachtype = (String) it.next();

        if ( gbemachtype.compareTo("win32") == 0 ||
             gbemachtype.compareTo("linux_i386") == 0 ||
             gbemachtype.compareTo("sparc") == 0 ||
             gbemachtype.compareTo("solaris10_x86") == 0 ||
             gbemachtype.compareTo("solaris10_sparc32") == 0 )
        {
          validPlatform = true;
          numberOfPlatforms++;
        }
      }
    }
    else if (mWin32)
    {
      mLogger.info("getBuildStandard mWin32");
      for (Iterator it = mRippleEngine.mGbeMachtypeCollection.iterator(); it.hasNext(); )
      {
        String gbemachtype = (String) it.next();

        if ( gbemachtype.compareTo("win32") == 0 )
        {
          validPlatform = true;
          numberOfPlatforms = 1;
          break;
        }
      }
    }
    else if (mSolaris)
    {
      mLogger.info("getBuildStandard mSolaris");
      for (Iterator it = mRippleEngine.mGbeMachtypeCollection.iterator(); it.hasNext(); )
      {
        String gbemachtype = (String) it.next();

        if ( gbemachtype.compareTo("sparc") == 0 || gbemachtype.compareTo("solaris10_x86") == 0 || gbemachtype.compareTo("solaris10_sparc32") == 0 )
        {
          validPlatform = true;
          numberOfPlatforms++;
        }
      }
    }
    else
    {
      mLogger.info("getBuildStandard mLinux");
      for (Iterator it = mRippleEngine.mGbeMachtypeCollection.iterator(); it.hasNext(); )
      {
        String gbemachtype = (String) it.next();

        if ( gbemachtype.compareTo("linux_i386") == 0 )
        {
          validPlatform = true;
          numberOfPlatforms = 1;
          break;
        }
      }
    }
     
    if (validPlatform)
    {
     
      if (mJava1_4)
      {
        retVal = "  <ant java=\"1.4\"/>";
      }
      else if (mJava1_5)
      {
        retVal = "  <ant java=\"1.5\"/>";
      }
      else if (mJava1_6)
      {
        retVal = "  <ant java=\"1.6\"/>";
      }
      else if (mAntNone)
      {
        retVal = "  <ant java=\"none\"/>";
      }
      else if (mJatsNone)
      {
        retVal = "  <jats target=\"none\"/>";
      }
      else
      {
        if (mProduction)
        {
          if (mDebug)
          {
            retVal = "  <jats target=\"all\"/>";
          }
          else
          {
            retVal = "  <jats target=\"production\"/>";
          }
        }
        else
        {
          retVal = "  <jats target=\"debug\"/>";
        }
      }
  
      String line = new String(retVal);
       
      for ( int i = 1; i < numberOfPlatforms; i++ )
      {
        retVal += System.getProperty("line.separator");
        retVal += line;
      }
    }
     
    mLogger.info("getBuildStandard returned " + retVal);
    return retVal;
  }

  /**sets mDebug true, mProduction false, mJava1_4 false, mJava1_5 false, mJava1_6 false
   */
  void setDebug()
  {
    mLogger.debug("setDebug");
    mDebug = true;
    mProduction = false;
    mJava1_4 = false;
    mJava1_5 = false;
    mJava1_6 = false;
    mAntNone = false;
    mJatsNone = false;
  }

  /**sets mDebug false, mProduction true, mJava1_4 false, mJava1_5 false, mJava1_6 false
   */
  void setProduction()
  {
    mLogger.debug("setProduction");
    mDebug = false;
    mProduction = true;
    mJava1_4 = false;
    mJava1_5 = false;
    mJava1_6 = false;
    mAntNone = false;
    mJatsNone = false;
  }

  /**sets mDebug true, mProduction true, mJava1_4 false, mJava1_5 false, mJava1_6 false
   */
  void setAll()
  {
    mLogger.debug("setAll");
    mDebug = true;
    mProduction = true;
    mJava1_4 = false;
    mJava1_5 = false;
    mJava1_6 = false;
    mAntNone = false;
    mJatsNone = false;
  }

  /**sets mDebug false, mProduction false, mJava1_4 true, mJava1_5 false, mJava1_6 false
   */
  void set1_4()
  {
    mLogger.debug("set1_4");
    mDebug = false;
    mProduction = false;
    mJava1_4 = true;
    mJava1_5 = false;
    mJava1_6 = false;
    mAntNone = false;
    mJatsNone = false;
  }

  /**sets mDebug false, mProduction false, mJava1_4 false, mJava1_5 true, mJava1_6 false
   */
  void set1_5()
  {
    mLogger.debug("set1_5");
    mDebug = false;
    mProduction = false;
    mJava1_4 = false;
    mJava1_5 = true;
    mJava1_6 = false;
    mAntNone = false;
    mJatsNone = false;
  }

  /**sets mDebug false, mProduction false, mJava1_4 false, mJava1_5 false, mJava1_6 true
   */
   void set1_6()
   {
     mLogger.debug("set1_6");
     mDebug = false;
     mProduction = false;
     mJava1_4 = false;
     mJava1_5 = false;
     mJava1_6 = true;
     mAntNone = false;
     mJatsNone = false;
   }

  void setAntNone()
  {
    mLogger.debug("setAntNone");
    mDebug = false;
    mProduction = false;
    mJava1_4 = false;
    mJava1_5 = false;
    mJava1_6 = false;
    mAntNone = true;
    mJatsNone = false;
  }
  
  void setJatsNone()
  {
    mLogger.debug("setJatsNone");
    mDebug = false;
    mProduction = false;
    mJava1_4 = false;
    mJava1_5 = false;
    mJava1_6 = false;
    mAntNone = false;
    mJatsNone = true;
  }
  
  /**sets mGeneric true
   */
  void setGeneric()
  {
    mLogger.debug("setGeneric");
    mLinux = false;
    mSolaris = false;
    mWin32 = false;
    mGeneric = true;
  }

  /**sets mLinux true, mSolaris false, mWin32 false
   */
  void setLinux()
  {
    mLogger.debug("setLinux");
    mLinux = true;
    mSolaris = false;
    mWin32 = false;
  }

  /**sets mLinux false, mSolaris true, mWin32 false
   */
  void setSolaris()
  {
    mLogger.debug("setSolaris");
    mLinux = false;
    mSolaris = true;
    mWin32 = false;
  }

  /**sets mLinux false, mSolaris false, mWin32 true
   */
  void setWin32()
  {
    mLogger.debug("setWin32");
    mLinux = false;
    mSolaris = false;
    mWin32 = true;
  }

  /**sets mGeneric false
   */
  void clearGeneric()
  {
    mLogger.debug("clearGeneric");
    mGeneric = false;
  }

  /**accessor method
   */
  boolean getWin32()
  {
    mLogger.debug("getWin32");
    mLogger.info("getWin32 returned " + mWin32);
    return mWin32;
  }

  /**accessor method
   */
  boolean getGeneric()
  {
    mLogger.debug("getGeneric");
    mLogger.info("getGeneric returned " + mGeneric);
    return mGeneric;
  }

  /**accessor method
   */
  boolean getSolaris()
  {
    mLogger.debug("getSolaris");
    mLogger.info("getSolaris returned " + mSolaris);
    return mSolaris;
  }

  /**accessor method
   */
  boolean getLinux()
  {
    mLogger.debug("getLinux");
    mLogger.info("getLinux returned " + mLinux);
    return mLinux;
  }
}