Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stubgenj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scripting-tools
stubgenj
Commits
bcadbeb5
Commit
bcadbeb5
authored
3 years ago
by
Michi Hostettler
Browse files
Options
Downloads
Patches
Plain Diff
avoid crash of stub generation if an inner class throws on java class loading
parent
7505adc1
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!4
avoid crash of stub generation if an inner class throws on java class loading
Pipeline
#3172912
passed
3 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
stubgenj/_stubgenj.py
+13
-3
13 additions, 3 deletions
stubgenj/_stubgenj.py
with
13 additions
and
3 deletions
stubgenj/_stubgenj.py
+
13
−
3
View file @
bcadbeb5
...
...
@@ -210,6 +210,7 @@ def generateStubsForJavaPackage(package: jpype.JPackage, outputFile: str, subpac
classesDone
=
set
()
# type: Set[str]
classesUsed
=
set
()
# type: Set[str]
classesFailed
=
set
()
# type: Set[str]
customizersUsed
=
set
()
# type: Set[Type]
while
javaClasses
:
javaClassesToGenerate
=
[
c
for
c
in
javaClasses
if
dependenciesSatisfied
(
package
,
c
,
classesDone
)]
...
...
@@ -221,6 +222,7 @@ def generateStubsForJavaPackage(package: jpype.JPackage, outputFile: str, subpac
output
=
classOutput
,
importsOutput
=
importOutput
)
except
jpype
.
JException
as
e
:
# exception during class loading e.g. missing dependencies (spark...)
log
.
warning
(
f
'
Skipping
{
cls
}
due to
{
e
}
'
)
classesFailed
.
add
(
simpleClassNameOf
(
cls
))
javaClasses
.
remove
(
cls
)
# Collect all classes in this java package which are referenced by other class stubs, but have not yet been
# generated. To avoid unsatisfied type references in the stubs, we have to generate stubs for them:
...
...
@@ -229,7 +231,12 @@ def generateStubsForJavaPackage(package: jpype.JPackage, outputFile: str, subpac
# - failing that, we generate an empty stub.
missingPrivateClasses
=
filterClassNamesInPackage
(
pkgName
,
classesUsed
)
-
classesDone
for
missingPrivateClass
in
sorted
(
missingPrivateClasses
):
cls
=
getattr
(
package
,
missingPrivateClass
,
None
)
cls
=
None
try
:
if
missingPrivateClass
not
in
classesFailed
:
cls
=
getattr
(
package
,
missingPrivateClass
,
None
)
except
jpype
.
JException
as
e
:
# exception during class loading e.g. missing dependencies (spark...)
log
.
warning
(
f
'
Skipping missing class
{
missingPrivateClass
}
due to
{
e
}
'
)
if
cls
is
not
None
:
if
cls
not
in
javaClasses
:
...
...
@@ -256,7 +263,6 @@ def generateStubsForJavaPackage(package: jpype.JPackage, outputFile: str, subpac
log
.
warning
(
f
'
reference to missing class
{
missingPrivateClass
}
- generating empty stub
'
)
classOutput
.
append
(
''
)
generateEmptyClassStub
(
missingPrivateClass
,
classesDone
=
classesDone
,
output
=
classOutput
)
generateModuleProtocol
(
pkgName
,
sorted
([
className
for
className
in
classesDone
if
'
$
'
not
in
className
]),
...
...
@@ -310,6 +316,10 @@ def generateModuleProtocol(
classOutput
.
extend
(
protocolOutput
)
def
simpleClassNameOf
(
jClass
:
jpype
.
JClass
)
->
str
:
return
str
(
jClass
.
class_
.
getName
()).
split
(
'
.
'
)[
-
1
]
def
isJavaClass
(
obj
:
type
)
->
bool
:
"""
Check if a type is a
'
real
'
Java class. This excludes synthetic/anonymous Java classes.
...
...
@@ -1008,7 +1018,7 @@ def generateJavaClassStub(package: jpype.JPackage,
for
line
in
nestedClassesOutput
:
output
.
append
(
f
'
{
line
}
'
)
classesDone
|=
classesDoneNested
classesDone
.
add
(
s
tr
(
jClass
.
class_
.
getName
()).
split
(
'
.
'
)[
-
1
]
)
classesDone
.
add
(
s
impleClassNameOf
(
jClass
)
)
def
generateEmptyClassStub
(
className
:
str
,
classesDone
:
Set
[
str
],
output
:
List
[
str
]):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment