зеркало из https://github.com/mozilla/pjs.git
more 170006 - extension manager web service work not visible yet
This commit is contained in:
Родитель
de3697d303
Коммит
f761a07fc5
|
@ -1,63 +1,133 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Extension Manager.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Ben Goodger.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2004
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <ben@bengoodger.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
package org.mozilla.update.extensions;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class VersionCheck
|
||||
{
|
||||
public VersionCheck()
|
||||
{
|
||||
}
|
||||
|
||||
protected Connection getConnection()
|
||||
{
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
return DriverManager.getConnection("jdbc:mysql://localhost/", "", "");
|
||||
}
|
||||
|
||||
public class VersionResult
|
||||
{
|
||||
public String xpiURL;
|
||||
public int version;
|
||||
}
|
||||
|
||||
public VersionResult checkVersion(String aExtensionGUID, String aInstalledVersion, String aTargetApp, String aTargetAppVersion)
|
||||
{
|
||||
int extensionVersionParts = getPartCount(aInstalledVersion);
|
||||
int extensionVersion = parseVersion(aInstalledVersion, extensionVersionParts);
|
||||
int targetAppVersionParts = getPartCount(aTargetAppVersion);
|
||||
int targetAppVersion = parseVersion(aTargetAppVersion, targetAppVersionParts);
|
||||
|
||||
Connection c = getConnection();
|
||||
|
||||
Statement s = c.createStatement();
|
||||
|
||||
// We need to find all rows matching aExtensionGUID, and filter like so:
|
||||
// 1) version > extensionVersion
|
||||
// 2) targetapp == aTargetApp
|
||||
// 3) mintargetappversion <= targetAppVersion <= maxtargetappversion
|
||||
String sql = "SELECT * FROM extensions WHERE targetapp = '" + aTargetAppVersion + "'AND guid = '" + aExtensionGUID + "'";
|
||||
|
||||
ResultSet rs = s.executeQuery(sql);
|
||||
|
||||
String xpiURL = "";
|
||||
int newestExtensionVersion = extensionVersion;
|
||||
|
||||
while (rs.next())
|
||||
Connection c = null;
|
||||
try
|
||||
{
|
||||
int minTargetAppVersion = parseVersion(rs.getObject("mintargetappversion").toString(), targetAppVersionParts);
|
||||
int maxTargetAppVersion = parseVersion(rs.getObject("maxtargetappversion").toString(), targetAppVersionParts);
|
||||
|
||||
int version = parseVersion(rs.getObject("version").toString(), extensionVersionParts);
|
||||
if (version > extensionVersion &&
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
c = DriverManager.getConnection("jdbc:mysql://localhost/", "", "");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
public String getProperty(int aRowID, String aProperty)
|
||||
{
|
||||
String result = null;
|
||||
try
|
||||
{
|
||||
Connection c = getConnection();
|
||||
Statement s = c.createStatement();
|
||||
|
||||
String sql = "SELECT * FROM extensions WHERE id = '" + aRowID + "'";
|
||||
ResultSet rs = s.executeQuery(sql);
|
||||
|
||||
result = rs.next() ? rs.getString(aProperty) : null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getNewestExtension(String aExtensionGUID,
|
||||
String aInstalledVersion,
|
||||
String aTargetApp,
|
||||
String aTargetAppVersion)
|
||||
{
|
||||
int id = -1;
|
||||
try
|
||||
{
|
||||
int extensionVersionParts = getPartCount(aInstalledVersion);
|
||||
int targetAppVersionParts = getPartCount(aTargetAppVersion);
|
||||
|
||||
int extensionVersion = parseVersion(aInstalledVersion, extensionVersionParts);
|
||||
int targetAppVersion = parseVersion(aTargetAppVersion, targetAppVersionParts);
|
||||
|
||||
Connection c = getConnection();
|
||||
|
||||
Statement s = c.createStatement();
|
||||
|
||||
// We need to find all rows matching aExtensionGUID, and filter like so:
|
||||
// 1) version > extensionVersion
|
||||
// 2) targetapp == aTargetApp
|
||||
// 3) mintargetappversion <= targetAppVersion <= maxtargetappversion
|
||||
String sql = "SELECT * FROM extensions WHERE targetapp = '" + aTargetAppVersion + "'AND guid = '" + aExtensionGUID + "'";
|
||||
|
||||
ResultSet rs = s.executeQuery(sql);
|
||||
|
||||
int newestExtensionVersion = extensionVersion;
|
||||
|
||||
while (rs.next())
|
||||
{
|
||||
int minTargetAppVersion = parseVersion(rs.getString("mintargetappversion"), targetAppVersionParts);
|
||||
int maxTargetAppVersion = parseVersion(rs.getString("maxtargetappversion"), targetAppVersionParts);
|
||||
|
||||
int version = parseVersion(rs.getString("version"), extensionVersionParts);
|
||||
if (version > extensionVersion &&
|
||||
version > newestExtensionVersion &&
|
||||
minTargetAppVersion <= targetAppVersion &&
|
||||
targetAppVersion < maxTargetAppVersion)
|
||||
{
|
||||
newestExtensionVersion = version;
|
||||
xpiURL = rs.getObject("xpiurl").toString();
|
||||
{
|
||||
newestExtensionVersion = version;
|
||||
id = rs.getInt("id");
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
rs.close();
|
||||
|
||||
VersionResult vr = new VersionResult();
|
||||
vr.xpiURL = xpiURL;
|
||||
vr.version = newestExtensionVersion;
|
||||
|
||||
return vr;
|
||||
return id;
|
||||
}
|
||||
|
||||
protected int parseVersion(String aVersionString, int aPower)
|
||||
|
@ -75,6 +145,7 @@ public class VersionCheck
|
|||
version += Integer.parseInt(parts[i]) * Math.pow(10, aPower - i);
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
protected int getPartCount(String aVersionString)
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
#!/bin/sh
|
||||
|
||||
clear
|
||||
|
||||
pkg="org.mozilla"
|
||||
|
||||
name=$1
|
||||
if [ "x$name" = "x" ]; then
|
||||
echo "usage: $(basename $0) <webservice-name> [pkg-name]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f $name.java ]; then
|
||||
echo "$name.java not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "x$2" != "x" ]; then
|
||||
pkg=$2
|
||||
fi
|
||||
|
||||
pkg_dir=$(echo $pkg | sed 's/\./\//g')
|
||||
echo "pkg_dir = $AXIS_HOME/$pkg_dir"
|
||||
rm -rf "$AXIS_HOME/$pkg_dir/*"
|
||||
interface="$pkg_dir/$name.java"
|
||||
|
||||
srcdir=$(pwd)
|
||||
cd "$AXIS_HOME"
|
||||
|
||||
#
|
||||
# create standard interface file, and compile it.
|
||||
#
|
||||
#mkdir -p $pkg_dir || exit 1
|
||||
cp -f $srcdir/$name.java $interface
|
||||
javac $interface || exit 1
|
||||
|
||||
#
|
||||
# create WSDL and supporting files from generated interface file.
|
||||
#
|
||||
java org.apache.axis.wsdl.Java2WSDL -o $pkg_dir/$name.wsdl \
|
||||
-l"http://localhost:8080/axis/services/$name" -n "urn:$name" \
|
||||
-p"$pkg" "urn:$name" $pkg.$name || exit 1
|
||||
cp $pkg_dir/$name.wsdl "$CATALINA_HOME/webapps/axis/$name.wsdl"
|
||||
|
||||
java org.apache.axis.wsdl.WSDL2Java -o . \
|
||||
-d Session -s -S true -Nurn:$name $pkg $name.wsdl || exit 1
|
||||
|
||||
#
|
||||
# verify results! ;-)
|
||||
#
|
||||
if [ ! -f "$name.wsdl" -o ! -f "$pkg_dir/"$name"SoapBindingImpl.java" ]; then
|
||||
echo "something went wrong!"
|
||||
exit 1
|
||||
fi
|
||||
echo "ok, now add your implementation code to $pkg_dir/$nameSoapBindingImpl.java"
|
||||
|
||||
#
|
||||
# Now compile the bindings and deploy the web service.
|
||||
#
|
||||
cp $srcdir/$name.java $pkg_dir/${name}SoapBindingImpl.java
|
||||
|
||||
#
|
||||
# Replace $name with $nameSoapBindingImpl in the class definition
|
||||
#
|
||||
regexp="s/$name/${name}SoapBindingImpl/g"
|
||||
echo "regexp = $regexp"
|
||||
sed -e $regexp $pkg_dir/${name}SoapBindingImpl.java > $pkg_dir/temp.java
|
||||
mv $pkg_dir/temp.java $pkg_dir/${name}SoapBindingImpl.java
|
||||
|
||||
echo "sed -e 's/public class ${name}SoapBindingImpl/public class ${name}SoapBindingImpl implements ${pkg}.${name}/g' $pkg_dir/${name}SoapBindingImpl.java > $pkg_dir/temp.java"
|
||||
sed -e 's/public class ${name}SoapBindingImpl/public class ${name}SoapBindingImpl implements ${pkg}.${name}/g' $pkg_dir/${name}SoapBindingImpl.java > $pkg_dir/temp.java
|
||||
mv $pkg_dir/temp.java $pkg_dir/${name}SoapBindingImpl.java
|
||||
|
||||
javac $pkg_dir/*.java || exit 1
|
||||
cp $name.class ${name}SoapBindingImpl.class ${name}SoapBindingSkeleton.class \
|
||||
"$CATALINA_HOME/webapps/axis/WEB-INF/classes/$pkg_dir"
|
||||
|
||||
java org.apache.axis.client.AdminClient -p 8080 $pkg_dir/deploy.wsdd
|
||||
|
||||
cd $srcdir
|
|
@ -101,17 +101,22 @@ nsExtensionManager.prototype = {
|
|||
|
||||
updateExtension: function (aExtensionID)
|
||||
{
|
||||
var pref = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
var appID = pref.getCharPref(PREF_EM_APP_ID);
|
||||
var appVersion = pref.getCharPref(PREF_EM_APP_VERSION);
|
||||
|
||||
var extensionVersion = this._ds.getExtensionProperty(aExtensionID, "version");
|
||||
|
||||
var os = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
var itemCount = 0;
|
||||
|
||||
var proxy = null;
|
||||
function getResults()
|
||||
function getExtensionUpdateURL(aExtensionGUID, aInstalledVersion,
|
||||
aTargetApp, aTargetAppVersion)
|
||||
{
|
||||
if (proxy) {
|
||||
proxy.count();
|
||||
proxy.contents();
|
||||
}
|
||||
proxy.getNewestExtension(aExtensionGUID, aInstalledVersion, aTargetApp, aTargetAppVersion);
|
||||
}
|
||||
|
||||
if (!proxy) {
|
||||
|
@ -120,7 +125,7 @@ nsExtensionManager.prototype = {
|
|||
{
|
||||
proxy = aProxy;
|
||||
proxy.setListener(this);
|
||||
getResults();
|
||||
getExtensionUpdateURL(aExtensionID, extensionVersion, appID, appVersion);
|
||||
},
|
||||
|
||||
onError: function (aError)
|
||||
|
@ -128,25 +133,27 @@ nsExtensionManager.prototype = {
|
|||
dump("*** onError ERROR = " + aError + "\n");
|
||||
},
|
||||
|
||||
countCallback: function (aResult)
|
||||
getNewestExtensionCallback: function (aResult)
|
||||
{
|
||||
this._count = aResult;
|
||||
this._newestID = aResult;
|
||||
|
||||
if (this._newestID != -1)
|
||||
proxy.getProperty(this._newestID, "xpiurl");
|
||||
},
|
||||
|
||||
contentsCallback: function (aResult)
|
||||
getPropertyCallback: function (aResult)
|
||||
{
|
||||
for (var i = 0; i < this._count; ++i)
|
||||
dump("*** quote " + i + " = " + aResult[i] + "\n");
|
||||
dump("*** UPDATE URL = " + aResult + "\n");
|
||||
},
|
||||
};
|
||||
|
||||
var wspFactory = Components.classes["@mozilla.org/xmlextras/proxy/webserviceproxyfactory;1"]
|
||||
.getService(Components.interfaces.nsIWebServiceProxyFactory);
|
||||
wspFactory.createProxyAsync("http://localhost:8080/axis/quote.wsdl",
|
||||
"Quote", "", true, listener);
|
||||
wspFactory.createProxyAsync("http://localhost:8080/axis/VersionCheck.wsdl",
|
||||
"VersionCheck", "", true, listener);
|
||||
}
|
||||
else
|
||||
getResults();
|
||||
getExtensionUpdateURL(aExtensionID, extensionVersion, appID, appVersion);
|
||||
|
||||
return;
|
||||
|
||||
|
@ -257,6 +264,7 @@ nsExtensionManager.prototype = {
|
|||
|
||||
const PREF_EM_DEFAULTUPDATEURL = "update.url.extensions";
|
||||
const PREF_EM_APP_ID = "app.id";
|
||||
const PREF_EM_APP_VERSION = "general.useragent.vendorSub";
|
||||
|
||||
function EM_NS(aProperty)
|
||||
{
|
||||
|
@ -291,6 +299,12 @@ nsExtensionsDataSource.prototype = {
|
|||
aDS.Assert(aSource, aProperty, aNewValue, true);
|
||||
},
|
||||
|
||||
getExtensionProperty: function (aExtensionID, aProperty)
|
||||
{
|
||||
var extension = this._rdf.GetResource("urn:mozilla:extension:" + aExtensionID);
|
||||
return this.GetTarget(extension, this._emR(aProperty), true).QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
||||
},
|
||||
|
||||
_setExtensionProperty: function (aExtensionID, aPropertyArc, aPropertyValue)
|
||||
{
|
||||
var extension = this._rdf.GetResource("urn:mozilla:extension:" + aExtensionID);
|
||||
|
|
Загрузка…
Ссылка в новой задаче