Commit 85b9ab57 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩
Browse files

Generate java files for wrapper in package name directories

parent a820e2ad
......@@ -214,9 +214,9 @@ class JavaTranslator(object):
##########################################################################
class JavaEnum(object):
def __init__(self, _enum, translator):
def __init__(self, package, _enum, translator):
self._class = translator.translate_enum(_enum)
self.packageName = "org.linphone"
self.packageName = package
self.className = _enum.name.to_camel_case()
self.filename = self.className + ".java"
self.values = self._class['values']
......@@ -224,9 +224,9 @@ class JavaEnum(object):
self.jniMethods = []
class JavaInterface(object):
def __init__(self, _interface, translator):
def __init__(self, package, _interface, translator):
self._class = translator.translate_interface(_interface)
self.packageName = "org.linphone"
self.packageName = package
self.className = _interface.name.to_camel_case()
self.filename = self.className + ".java"
self.imports = []
......@@ -243,10 +243,10 @@ class JavaInterfaceStub(object):
self.methods = _interface.methods
class JavaClass(object):
def __init__(self, _class, translator):
def __init__(self, package, _class, translator):
self._class = translator.translate_class(_class)
self.isLinphoneFactory = self._class['isLinphoneFactory']
self.packageName = "org.linphone"
self.packageName = package
self.className = _class.name.to_camel_case()
self.classImplName = self.className + "Impl"
self.filename = self.className + ".java"
......@@ -272,9 +272,10 @@ class Jni(object):
##########################################################################
class GenWrapper(object):
def __init__(self, srcdir, javadir, xmldir):
def __init__(self, srcdir, javadir, package, xmldir):
self.srcdir = srcdir
self.javadir = javadir
self.package = package
project = CApi.Project()
project.initFromDir(xmldir)
......@@ -354,7 +355,7 @@ class GenWrapper(object):
def render_java_enum(self, _class):
if _class is not None:
try:
javaenum = JavaEnum(_class, self.translator)
javaenum = JavaEnum(self.package, _class, self.translator)
self.enums[javaenum.className] = javaenum
except AbsApi.Error as e:
print('Could not translate {0}: {1}'.format(_class.name.to_camel_case(fullName=True), e.args[0]))
......@@ -363,7 +364,7 @@ class GenWrapper(object):
def render_java_interface(self, _class):
if _class is not None:
try:
javainterface = JavaInterface(_class, self.translator)
javainterface = JavaInterface(self.package, _class, self.translator)
self.interfaces[javainterface.className] = javainterface
javaInterfaceStub = JavaInterfaceStub(javainterface)
self.interfaces[javaInterfaceStub.classNameStub] = javaInterfaceStub
......@@ -374,7 +375,7 @@ class GenWrapper(object):
def render_java_class(self, _class):
if _class is not None:
try:
javaclass = JavaClass(_class, self.translator)
javaclass = JavaClass(self.package, _class, self.translator)
self.classes[javaclass.className] = javaclass
except AbsApi.Error as e:
print('Could not translate {0}: {1}'.format(_class.name.to_camel_case(fullName=True), e.args[0]))
......@@ -386,11 +387,15 @@ def main():
argparser = argparse.ArgumentParser(description='Generate source files for the Java wrapper')
argparser.add_argument('xmldir', type=str, help='Directory where the XML documentation of the Linphone\'s API generated by Doxygen is placed')
argparser.add_argument('-o --output', type=str, help='the directory where to generate the source files', dest='outputdir', default='.')
argparser.add_argument('-n --name', type=str, help='the name of the genarated source file', dest='outputfile', default='linphone_jni.cc')
argparser.add_argument('-p --package', type=str, help='the package name for the wrapper', dest='package', default='org.linphone')
argparser.add_argument('-n --name', type=str, help='the name of the genarated source file', dest='name', default='linphone_jni.cc')
args = argparser.parse_args()
srcdir = args.outputdir + '/src'
javadir = args.outputdir + '/java'
package_dirs = args.package.split('.')
for directory in package_dirs:
javadir += '/' + directory
try:
os.makedirs(srcdir)
......@@ -406,7 +411,7 @@ def main():
print("Cannot create '{0}' dircetory: {1}".format(javadir, e.strerror))
sys.exit(1)
genwrapper = GenWrapper(srcdir, javadir, args.xmldir)
genwrapper = GenWrapper(srcdir, javadir, args.package, args.xmldir)
genwrapper.render_all()
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment