Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Find out version of GWT and SmartGWT in deployed application

    Hi Isomorphic,

    I just started to try GWT 2.6.0-rc3 out of curiosity during the Christmas holidays.
    As I still have 2.5.1 installed I wanted to be sure which version I'm using and put that information in my manifest file, but didn't succeed there so far.
    I then thought that it should be enough to display the version number in some information window inside of my app.
    I found code for this under http://stackoverflow.com/questions/1...unning-on-site, so I'll write my first JSNI method soon :).
    I also thought that it might be useful to show the SmartGWT version in use as well (only the version number and not the whole console), and looked in http://www.smartclient.com/smartgwte...t/util/SC.html, as the Console, which is called from there, also shows the version number, but didn't succeed.
    My next step was to look in the source of SC in http://code.google.com/p/smartgwt/so...t/util/SC.java.

    My first question: Is this the place to look for the SmartGWT source? Is the LGPL version downloadable from http://www.smartclient.com/product/download.jsp build from this code?

    I saw in the source of SC.java that showConsole() is just a wrapped call to isc.showConsole(). So I downloaded the LGPL version (SmartClient_v90p_2013-12-29_LGPL.zip) of SmartClient from here and searched the source for "showConsole" in order to find out how the console window is created and how it displays the version number, but did not succeed here.

    So my second question is: How do I get the version number of the used version in my java code?

    Thank you & Best regards,
    Blama

    #2
    Hi all,

    I remembered that the Version is in the lower left of the Client Showcase, so I searched the Showcase source for "Version:" and found the class Version (http://www.smartclient.com/smartgwte...t/Version.html) with the static methods needed.

    Best regards,
    Blama
    Last edited by Blama; 29 Dec 2013, 11:22.

    Comment


      #3
      JSNI method for the GWT version string is
      Code:
      private static native String getGWTVersion() /*-{
      	return $gwt_version;
      }-*/;

      Comment


        #4
        The code to get the build date of your code in the app is the following:

        Code:
        import java.util.Date;
        
        import com.google.gwt.i18n.client.LocaleInfo;
        import com.google.gwt.i18n.shared.DateTimeFormat;
        import com.google.gwt.i18n.shared.DateTimeFormatInfo;
        
        public class BuildDate {
        	private static String buildDate = "2014-01-02 14:58";
        
        	public static String getBuildDate() {
        		DateTimeFormat parseFormat = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm");
        		Date buildDateAsDate = parseFormat.parse(buildDate);
        
        		LocaleInfo li = LocaleInfo.getCurrentLocale();
        		DateTimeFormatInfo dtfi = li.getDateTimeFormatInfo();
        		DateTimeFormat returnFormat = DateTimeFormat.getFormat(dtfi.dateFormatMedium() + " " + dtfi.timeFormatShort());
        		return returnFormat.format(buildDateAsDate);
        	}
        }
        I change the constant before GWT'ing with the following Ant-task:

        Code:
        	<target name="setBuildDate" description="Set the builddate in BuildDate.java">
        		<tstamp>
        			<format property="current.time" locale="en,US" pattern="yyyy-MM-dd HH:mm" />
        		</tstamp>
        		<echo>${current.time}</echo>
        		<replaceregexp file="src/com/mycompany/myproj/client/BuildDate.java"
        			match="buildDate = &quot;.*&quot;" replace="buildDate = &quot;${current.time}&quot;" byline="true" />
        	</target>
        Another nice addition would be to check the User's JS code build date against the deployed code's build date in order to find stale User code (because of not working cache mechanisms).

        Best regards,
        Blama

        Comment


          #5
          Hi,

          I implemented the comparison between client and server build dates using following code:

          build.xml target:
          Code:
          	<tstamp prefix="build-info">
          		<format property="current-datetime" pattern="yyyy-MM-dd HH:mm" locale="en,US" />
          		<format property="current-date" pattern="d-MMMM-yyyy" locale="en,US" />
          		<format property="current-time" pattern="hh:mm:ss a z" locale="en,US" />
          		<format property="year-month-day" pattern="yyyy-MM-dd" locale="en,US" />
          	</tstamp>
          	<target name="setBuildDate" description="Set the builddate in BuildDate.java">
          		<echo>${current-datetime}</echo>
          		<replaceregexp file="src/com/.../client/BuildDate.java"
          			match="buildDate = &quot;.*&quot;" replace="buildDate = &quot;${current-datetime}&quot;" byline="true" />
          		<replaceregexp file="src/com/.../server/BuildDate.java"
          			match="buildDate = &quot;.*&quot;" replace="buildDate = &quot;${current-datetime}&quot;" byline="true" />
          	</target>
          Client Class:
          Code:
          import java.util.Date;
          
          import com.google.gwt.i18n.client.LocaleInfo;
          import com.google.gwt.i18n.shared.DateTimeFormat;
          import com.google.gwt.i18n.shared.DateTimeFormatInfo;
          
          public class BuildDate {
          	private static String buildDate = "2014-01-08 11:41";
          
          	public static String getBuildDateAsString() {
          		DateTimeFormat parseFormat = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm");
          		Date buildDateAsDate = parseFormat.parse(buildDate);
          
          		LocaleInfo li = LocaleInfo.getCurrentLocale();
          		DateTimeFormatInfo dtfi = li.getDateTimeFormatInfo();
          		DateTimeFormat returnFormat = DateTimeFormat.getFormat(dtfi.dateFormatMedium() + " " + dtfi.timeFormatShort());
          		return returnFormat.format(buildDateAsDate);
          	}
          
          	public static long getBuildDate() {
          		DateTimeFormat parseFormat = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm");
          		Date buildDateAsDate = parseFormat.parse(buildDate);
          		return buildDateAsDate.getTime();
          	}
          }
          Server Class:
          Code:
          import java.text.ParseException;
          import java.text.SimpleDateFormat;
          import java.util.Date;
          
          public class BuildDate {
          	private static String buildDate = "2014-01-08 11:41";
          
          	public static Long getBuildDate() {
          		SimpleDateFormat parseFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
          		Date buildDateAsDate = null;
          		try {
          			buildDateAsDate = parseFormat.parse(buildDate);
          		} catch (ParseException e) {
          			buildDateAsDate = new Date();
          		}
          		return buildDateAsDate.getTime();
          	}
          }
          In my ServletLogin.java, which transfers some data in JSON format to the client after successful Login, I add (server.)BuildDate.getBuildDate(). In my onModuleLoad I have:
          Code:
          // Check for current version of the JS code, User is a Helper class feeded with the reply from LoginServlet.
          if (BuildDate.getBuildDate() < User.getServerCompileDate().longValue()) {
          	final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm");
          
          	Date clientBuildDate = new Date(BuildDate.getBuildDate());
          	Date serverBuildDate = new Date(User.getServerCompileDate());
          	SC.warn(
          			"Attention",
          			"Server build: "
          					+ dateFormatter.format(serverBuildDate)
          					+ ", Client build: "
          					+ dateFormatter.format(clientBuildDate)
          					+ ". Please refresh the client by reloading it (Ctrl-F5 or deleting the browser cache). Otherwise several malfunctions will occur!");
          }
          Obviously this can be further improved and does NOT discharge you from configuring caching correctly, but is a great help in development, as it prevents weird issues.

          Best regards,
          Blama

          Comment

          Working...
          X