Remove the duplicate Version class

We had two different com.google.gerrit.common.Version classes which
meant that under the GWT debug environment the server didn't have
access to its own version number.

Fix that by using ClientVersion from within the GWT UI, and leave
the real Version name for the rest of the runtime.

Change-Id: I3b5af1a866fb1b4a6dbe25269962fe80d8d26436
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce 2009-12-30 10:12:27 -08:00
parent e43a80361c
commit db96816b81
5 changed files with 34 additions and 34 deletions

View File

@ -2,4 +2,3 @@
/.classpath
/.project
/.settings/org.maven.ide.eclipse.prefs
/src/main/resources/com/google/gerrit/common/Version.properties

View File

@ -67,14 +67,14 @@ limitations under the License.
<phase>generate-resources</phase>
<configuration>
<tasks>
<property name="src" location="${basedir}/src/main/resources/" />
<property name="pkg" location="${src}/com/google/gerrit/common" />
<property name="dst" location="${project.build.outputDirectory}" />
<property name="pkg" location="${dst}/com/google/gerrit/common" />
<mkdir dir="${pkg}" />
<exec executable="git" outputproperty="v">
<arg value="describe"/>
<arg value="HEAD"/>
</exec>
<echo file="${pkg}/Version.properties">version=${v}</echo>
<echo file="${pkg}/Version">${v}</echo>
</tasks>
</configuration>
<goals>

View File

@ -14,13 +14,11 @@
package com.google.gerrit.common;
import com.google.gwt.i18n.client.Constants;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.TextResource;
/**
* Automatically generated version code.
* <p>
* Do not translate this constants interface.
*/
public interface Version extends Constants {
String version();
public interface ClientVersion extends ClientBundle {
/** Version number of this client software build. */
@Source("Version")
TextResource version();
}

View File

@ -20,8 +20,8 @@ import com.google.gerrit.client.rpc.GerritCallback;
import com.google.gerrit.client.ui.LinkMenuBar;
import com.google.gerrit.client.ui.LinkMenuItem;
import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.ClientVersion;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.Version;
import com.google.gerrit.common.auth.SignInMode;
import com.google.gerrit.common.data.GerritConfig;
import com.google.gerrit.common.data.HostPageData;
@ -65,7 +65,6 @@ public class Gerrit implements EntryPoint {
public static final SystemInfoService SYSTEM_SVC;
private static String myHost;
private static String myVersion;
private static GerritConfig myConfig;
private static Account myAccount;
@ -322,25 +321,22 @@ public class Gerrit implements EntryPoint {
keyHelp.setStyleName(RESOURCES.css().keyhelp());
btmmenu.add(keyHelp);
final String vs = getVersion();
String vs;
if (GWT.isScript()) {
final ClientVersion v = GWT.create(ClientVersion.class);
vs = v.version().getText();
if (vs.startsWith("v")) {
vs = vs.substring(1);
}
} else {
vs = "dev";
}
final HTML version = new HTML(M.poweredBy(vs));
version.setStyleName(RESOURCES.css().version());
btmmenu.add(version);
}
/** @return version number of the Gerrit application software */
public static String getVersion() {
if (myVersion == null) {
if (GWT.isScript()) {
final Version v = GWT.create(Version.class);
myVersion = v.version();
} else {
myVersion = "dev";
}
}
return myVersion;
}
private void onModuleLoad2(final RootPanel starting) {
refreshMenuBar();

View File

@ -14,9 +14,10 @@
package com.google.gerrit.common;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.io.InputStreamReader;
public class Version {
private static final String version;
@ -30,18 +31,24 @@ public class Version {
}
private static String loadVersion() {
InputStream in = Version.class.getResourceAsStream("Version.properties");
InputStream in = Version.class.getResourceAsStream("Version");
if (in == null) {
return null;
}
try {
final Properties p = new Properties();
BufferedReader r = new BufferedReader(new InputStreamReader(in, "UTF-8"));
try {
p.load(in);
String vs = r.readLine();
if (vs != null && vs.startsWith("v")) {
vs = vs.substring(1);
}
if (vs != null && vs.isEmpty()) {
vs = null;
}
return vs;
} finally {
in.close();
r.close();
}
return p.getProperty("version");
} catch (IOException e) {
return null;
}