update to Gradle 8.1.1, Java 17
This commit is contained in:
parent
7e942c813e
commit
372b5be77e
43 changed files with 11579 additions and 903 deletions
38
build.gradle
38
build.gradle
|
@ -1,22 +1,28 @@
|
||||||
plugins {
|
plugins {
|
||||||
id "de.marcphilipp.nexus-publish" version "0.4.0"
|
//id "checkstyle"
|
||||||
id "io.codearte.nexus-staging" version "0.21.1"
|
//id "pmd"
|
||||||
|
id 'maven-publish'
|
||||||
|
id 'signing'
|
||||||
|
id "io.github.gradle-nexus.publish-plugin" version "1.3.0"
|
||||||
|
//id "com.github.spotbugs" version "5.0.14"
|
||||||
|
id "org.cyclonedx.bom" version "1.7.2"
|
||||||
|
//id "org.xbib.gradle.plugin.asciidoctor" version "3.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper {
|
wrapper {
|
||||||
gradleVersion = "${project.property('gradle.wrapper.version')}"
|
gradleVersion = libs.versions.gradle.get()
|
||||||
distributionType = Wrapper.DistributionType.ALL
|
distributionType = Wrapper.DistributionType.ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
user = 'jprante'
|
user = 'joerg'
|
||||||
name = 'guice'
|
name = 'guice'
|
||||||
description = 'Guice implementation with named modules for Java 11+'
|
description = 'Guice implementation with named modules for Java 11+'
|
||||||
inceptionYear = '2012'
|
inceptionYear = '2012'
|
||||||
url = 'https://github.com/' + user + '/' + name
|
url = 'https://xbib.org/' + user + '/' + name
|
||||||
scmUrl = 'https://github.com/' + user + '/' + name
|
scmUrl = 'https://xbib.org/' + user + '/' + name
|
||||||
scmConnection = 'scm:git:git://github.com/' + user + '/' + name + '.git'
|
scmConnection = 'scm:git:git://xbib.org/' + user + '/' + name + '.git'
|
||||||
scmDeveloperConnection = 'scm:git:ssh://git@github.com:' + user + '/' + name + '.git'
|
scmDeveloperConnection = 'scm:git:ssh://forgejo@xbib.org:' + user + '/' + name + '.git'
|
||||||
issueManagementSystem = 'Github'
|
issueManagementSystem = 'Github'
|
||||||
issueManagementUrl = ext.scmUrl + '/issues'
|
issueManagementUrl = ext.scmUrl + '/issues'
|
||||||
licenseName = 'The Apache License, Version 2.0'
|
licenseName = 'The Apache License, Version 2.0'
|
||||||
|
@ -29,13 +35,17 @@ apply from: rootProject.file('gradle/ide/idea.gradle')
|
||||||
apply from: rootProject.file('gradle/repositories/maven.gradle')
|
apply from: rootProject.file('gradle/repositories/maven.gradle')
|
||||||
apply from: rootProject.file('gradle/compile/java.gradle')
|
apply from: rootProject.file('gradle/compile/java.gradle')
|
||||||
apply from: rootProject.file('gradle/test/junit5.gradle')
|
apply from: rootProject.file('gradle/test/junit5.gradle')
|
||||||
apply from: rootProject.file('gradle/publishing/publication.gradle')
|
apply from: rootProject.file('gradle/quality/cyclonedx.gradle')
|
||||||
apply from: rootProject.file('gradle/publishing/sonatype.gradle')
|
//apply from: rootProject.file('gradle/quality/spotbugs.gradle')
|
||||||
|
//apply from: rootProject.file('gradle/quality/checkstyle.gradle')
|
||||||
|
//apply from: rootProject.file('gradle/quality/pmd.gradle')
|
||||||
|
apply from: rootProject.file('gradle/publish/sonatype.gradle')
|
||||||
|
apply from: rootProject.file('gradle/publish/forgejo.gradle')
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api "org.xbib:javax-inject:${project.property('javax-inject.version')}"
|
api libs.javax.inject
|
||||||
api "org.xbib:guava:${project.property('guava.version')}"
|
api libs.guava
|
||||||
testImplementation "junit:junit:${project.property('junit4.version')}"
|
testImplementation libs.junit4
|
||||||
// Helper for com.google.common.testing.GcFinalization, com.google.common.testing.EqualsTester
|
// Helper for com.google.common.testing.GcFinalization, com.google.common.testing.EqualsTester
|
||||||
testImplementation "com.google.guava:guava-testlib:30.1-jre"
|
testImplementation libs.guava.testlib
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,3 @@ name = guice
|
||||||
version = 5.0.1.0
|
version = 5.0.1.0
|
||||||
|
|
||||||
org.gradle.warning.mode = ALL
|
org.gradle.warning.mode = ALL
|
||||||
gradle.wrapper.version = 6.6.1
|
|
||||||
javax-inject.version = 1
|
|
||||||
guava.version = 30.1
|
|
||||||
# test
|
|
||||||
junit.version = 5.7.2
|
|
||||||
junit4.version = 4.13.2
|
|
||||||
log4j.version = 2.14.1
|
|
||||||
|
|
|
@ -3,16 +3,18 @@ apply plugin: 'java-library'
|
||||||
|
|
||||||
java {
|
java {
|
||||||
modularity.inferModulePath.set(true)
|
modularity.inferModulePath.set(true)
|
||||||
|
withSourcesJar()
|
||||||
|
withJavadocJar()
|
||||||
}
|
}
|
||||||
|
|
||||||
compileJava {
|
compileJava {
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|
||||||
compileTestJava {
|
compileTestJava {
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
@ -21,20 +23,6 @@ jar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
|
||||||
classifier 'sources'
|
|
||||||
from sourceSets.main.allSource
|
|
||||||
}
|
|
||||||
|
|
||||||
task javadocJar(type: Jar, dependsOn: javadoc) {
|
|
||||||
classifier 'javadoc'
|
|
||||||
from javadoc.destinationDir
|
|
||||||
}
|
|
||||||
|
|
||||||
artifacts {
|
|
||||||
archives sourcesJar, javadocJar
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.encoding('UTF-8')
|
options.encoding('UTF-8')
|
||||||
options.compilerArgs << '-Xlint:all'
|
options.compilerArgs << '-Xlint:all'
|
||||||
|
|
16
gradle/publish/forgejo.gradle
Normal file
16
gradle/publish/forgejo.gradle
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
if (project.hasProperty('forgeJoToken')) {
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url 'https://xbib.org/api/packages/joerg/maven'
|
||||||
|
credentials(HttpHeaderCredentials) {
|
||||||
|
name = "Authorization"
|
||||||
|
value = "token ${project.property('forgeJoToken')}"
|
||||||
|
}
|
||||||
|
authentication {
|
||||||
|
header(HttpHeaderAuthentication)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
gradle/publish/ivy.gradle
Normal file
27
gradle/publish/ivy.gradle
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
apply plugin: 'ivy-publish'
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
repositories {
|
||||||
|
ivy {
|
||||||
|
url = "https://xbib.org/repo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
publications {
|
||||||
|
ivy(IvyPublication) {
|
||||||
|
from components.java
|
||||||
|
descriptor {
|
||||||
|
license {
|
||||||
|
name = 'The Apache License, Version 2.0'
|
||||||
|
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
|
||||||
|
}
|
||||||
|
author {
|
||||||
|
name = 'Jörg Prante'
|
||||||
|
url = 'https://xbib.org/joerg'
|
||||||
|
}
|
||||||
|
descriptor.description {
|
||||||
|
text = rootProject.ext.description
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +1,10 @@
|
||||||
|
|
||||||
apply plugin: "de.marcphilipp.nexus-publish"
|
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
"${project.name}"(MavenPublication) {
|
||||||
from components.java
|
from components.java
|
||||||
artifact sourcesJar
|
|
||||||
artifact javadocJar
|
|
||||||
pom {
|
pom {
|
||||||
|
artifactId = project.name
|
||||||
name = project.name
|
name = project.name
|
||||||
description = rootProject.ext.description
|
description = rootProject.ext.description
|
||||||
url = rootProject.ext.url
|
url = rootProject.ext.url
|
||||||
|
@ -19,10 +16,10 @@ publishing {
|
||||||
}
|
}
|
||||||
developers {
|
developers {
|
||||||
developer {
|
developer {
|
||||||
id = 'jprante'
|
id = 'joerg'
|
||||||
name = 'Jörg Prante'
|
name = 'Jörg Prante'
|
||||||
email = 'joergprante@gmail.com'
|
email = 'joergprante@gmail.com'
|
||||||
url = 'https://github.com/jprante'
|
url = 'https://xbib.org/joerg'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scm {
|
scm {
|
||||||
|
@ -49,18 +46,6 @@ publishing {
|
||||||
if (project.hasProperty("signing.keyId")) {
|
if (project.hasProperty("signing.keyId")) {
|
||||||
apply plugin: 'signing'
|
apply plugin: 'signing'
|
||||||
signing {
|
signing {
|
||||||
sign publishing.publications.mavenJava
|
sign publishing.publications."${project.name}"
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (project.hasProperty("ossrhUsername")) {
|
|
||||||
nexusPublishing {
|
|
||||||
repositories {
|
|
||||||
sonatype {
|
|
||||||
username = project.property('ossrhUsername')
|
|
||||||
password = project.property('ossrhPassword')
|
|
||||||
packageGroup = "org.xbib"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
11
gradle/publish/sonatype.gradle
Normal file
11
gradle/publish/sonatype.gradle
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {
|
||||||
|
nexusPublishing {
|
||||||
|
repositories {
|
||||||
|
sonatype {
|
||||||
|
username = project.property('ossrhUsername')
|
||||||
|
password = project.property('ossrhPassword')
|
||||||
|
packageGroup = "org.xbib"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +0,0 @@
|
||||||
|
|
||||||
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {
|
|
||||||
|
|
||||||
apply plugin: 'io.codearte.nexus-staging'
|
|
||||||
|
|
||||||
nexusStaging {
|
|
||||||
username = project.property('ossrhUsername')
|
|
||||||
password = project.property('ossrhPassword')
|
|
||||||
packageGroup = "org.xbib"
|
|
||||||
}
|
|
||||||
}
|
|
19
gradle/quality/checkstyle.gradle
Normal file
19
gradle/quality/checkstyle.gradle
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
|
||||||
|
apply plugin: 'checkstyle'
|
||||||
|
|
||||||
|
tasks.withType(Checkstyle) {
|
||||||
|
ignoreFailures = true
|
||||||
|
reports {
|
||||||
|
xml.getRequired().set(true)
|
||||||
|
html.getRequired().set(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
checkstyle {
|
||||||
|
configFile = rootProject.file('gradle/quality/checkstyle.xml')
|
||||||
|
ignoreFailures = true
|
||||||
|
showViolations = true
|
||||||
|
checkstyleMain {
|
||||||
|
source = sourceSets.main.allSource
|
||||||
|
}
|
||||||
|
}
|
333
gradle/quality/checkstyle.xml
Normal file
333
gradle/quality/checkstyle.xml
Normal file
|
@ -0,0 +1,333 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE module PUBLIC
|
||||||
|
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||||
|
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
||||||
|
|
||||||
|
<!-- This is a checkstyle configuration file. For descriptions of
|
||||||
|
what the following rules do, please see the checkstyle configuration
|
||||||
|
page at http://checkstyle.sourceforge.net/config.html -->
|
||||||
|
|
||||||
|
<module name="Checker">
|
||||||
|
|
||||||
|
<module name="BeforeExecutionExclusionFileFilter">
|
||||||
|
<property name="fileNamePattern" value=".*(Example|Test|module-info)(\$.*)?"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="FileTabCharacter">
|
||||||
|
<!-- Checks that there are no tab characters in the file.
|
||||||
|
-->
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="NewlineAtEndOfFile">
|
||||||
|
<property name="lineSeparator" value="lf"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="RegexpSingleline">
|
||||||
|
<!-- Checks that FIXME is not used in comments. TODO is preferred.
|
||||||
|
-->
|
||||||
|
<property name="format" value="((//.*)|(\*.*))FIXME" />
|
||||||
|
<property name="message" value='TODO is preferred to FIXME. e.g. "TODO(johndoe): Refactor when v2 is released."' />
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="RegexpSingleline">
|
||||||
|
<!-- Checks that TODOs are named. (Actually, just that they are followed
|
||||||
|
by an open paren.)
|
||||||
|
-->
|
||||||
|
<property name="format" value="((//.*)|(\*.*))TODO[^(]" />
|
||||||
|
<property name="message" value='All TODOs should be named. e.g. "TODO(johndoe): Refactor when v2 is released."' />
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="JavadocPackage">
|
||||||
|
<!-- Checks that each Java package has a Javadoc file used for commenting.
|
||||||
|
Only allows a package-info.java, not package.html. -->
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- All Java AST specific tests live under TreeWalker module. -->
|
||||||
|
<module name="TreeWalker">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
IMPORT CHECKS
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<module name="RedundantImport">
|
||||||
|
<!-- Checks for redundant import statements. -->
|
||||||
|
<property name="severity" value="error"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="ImportOrder">
|
||||||
|
<!-- Checks for out of order import statements. -->
|
||||||
|
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
<!-- <property name="tokens" value="IMPORT, STATIC_IMPORT"/> -->
|
||||||
|
<property name="separated" value="false"/>
|
||||||
|
<property name="groups" value="*"/>
|
||||||
|
<!-- <property name="option" value="above"/> -->
|
||||||
|
<property name="sortStaticImportsAlphabetically" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="CustomImportOrder">
|
||||||
|
<!-- <property name="customImportOrderRules" value="THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC"/> -->
|
||||||
|
<!-- <property name="specialImportsRegExp" value="^javax\."/> -->
|
||||||
|
<!-- <property name="standardPackageRegExp" value="^java\."/> -->
|
||||||
|
<property name="sortImportsInGroupAlphabetically" value="true"/>
|
||||||
|
<property name="separateLineBetweenGroups" value="false"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
JAVADOC CHECKS
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Checks for Javadoc comments. -->
|
||||||
|
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
|
||||||
|
<module name="JavadocMethod">
|
||||||
|
<property name="accessModifiers" value="protected"/>
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
<property name="allowMissingParamTags" value="true"/>
|
||||||
|
<property name="allowMissingReturnTag" value="true"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="JavadocType">
|
||||||
|
<property name="scope" value="protected"/>
|
||||||
|
<property name="severity" value="error"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="JavadocStyle">
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
NAMING CHECKS
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Item 38 - Adhere to generally accepted naming conventions -->
|
||||||
|
|
||||||
|
<module name="PackageName">
|
||||||
|
<!-- Validates identifiers for package names against the
|
||||||
|
supplied expression. -->
|
||||||
|
<!-- Here the default checkstyle rule restricts package name parts to
|
||||||
|
seven characters, this is not in line with common practice at Google.
|
||||||
|
-->
|
||||||
|
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,})*$"/>
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="TypeNameCheck">
|
||||||
|
<!-- Validates static, final fields against the
|
||||||
|
expression "^[A-Z][a-zA-Z0-9]*$". -->
|
||||||
|
<metadata name="altname" value="TypeName"/>
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="ConstantNameCheck">
|
||||||
|
<!-- Validates non-private, static, final fields against the supplied
|
||||||
|
public/package final fields "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$". -->
|
||||||
|
<metadata name="altname" value="ConstantName"/>
|
||||||
|
<property name="applyToPublic" value="true"/>
|
||||||
|
<property name="applyToProtected" value="true"/>
|
||||||
|
<property name="applyToPackage" value="true"/>
|
||||||
|
<property name="applyToPrivate" value="false"/>
|
||||||
|
<property name="format" value="^([A-Z][A-Z0-9]*(_[A-Z0-9]+)*|FLAG_.*)$"/>
|
||||||
|
<message key="name.invalidPattern"
|
||||||
|
value="Variable ''{0}'' should be in ALL_CAPS (if it is a constant) or be private (otherwise)."/>
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="StaticVariableNameCheck">
|
||||||
|
<!-- Validates static, non-final fields against the supplied
|
||||||
|
expression "^[a-z][a-zA-Z0-9]*_?$". -->
|
||||||
|
<metadata name="altname" value="StaticVariableName"/>
|
||||||
|
<property name="applyToPublic" value="true"/>
|
||||||
|
<property name="applyToProtected" value="true"/>
|
||||||
|
<property name="applyToPackage" value="true"/>
|
||||||
|
<property name="applyToPrivate" value="true"/>
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="MemberNameCheck">
|
||||||
|
<!-- Validates non-static members against the supplied expression. -->
|
||||||
|
<metadata name="altname" value="MemberName"/>
|
||||||
|
<property name="applyToPublic" value="true"/>
|
||||||
|
<property name="applyToProtected" value="true"/>
|
||||||
|
<property name="applyToPackage" value="true"/>
|
||||||
|
<property name="applyToPrivate" value="true"/>
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="MethodNameCheck">
|
||||||
|
<!-- Validates identifiers for method names. -->
|
||||||
|
<metadata name="altname" value="MethodName"/>
|
||||||
|
<property name="format" value="^[a-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$"/>
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="ParameterName">
|
||||||
|
<!-- Validates identifiers for method parameters against the
|
||||||
|
expression "^[a-z][a-zA-Z0-9]*$". -->
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="LocalFinalVariableName">
|
||||||
|
<!-- Validates identifiers for local final variables against the
|
||||||
|
expression "^[a-z][a-zA-Z0-9]*$". -->
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="LocalVariableName">
|
||||||
|
<!-- Validates identifiers for local variables against the
|
||||||
|
expression "^[a-z][a-zA-Z0-9]*$". -->
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
LENGTH and CODING CHECKS
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
<module name="LeftCurly">
|
||||||
|
<!-- Checks for placement of the left curly brace ('{'). -->
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="RightCurly">
|
||||||
|
<!-- Checks right curlies on CATCH, ELSE, and TRY blocks are on
|
||||||
|
the same line. e.g., the following example is fine:
|
||||||
|
<pre>
|
||||||
|
if {
|
||||||
|
...
|
||||||
|
} else
|
||||||
|
</pre>
|
||||||
|
-->
|
||||||
|
<!-- This next example is not fine:
|
||||||
|
<pre>
|
||||||
|
if {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
else
|
||||||
|
</pre>
|
||||||
|
-->
|
||||||
|
<property name="option" value="same"/>
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<!-- Checks for braces around if and else blocks -->
|
||||||
|
<module name="NeedBraces">
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
<property name="tokens" value="LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="UpperEll">
|
||||||
|
<!-- Checks that long constants are defined with an upper ell.-->
|
||||||
|
<property name="severity" value="error"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="FallThrough">
|
||||||
|
<!-- Warn about falling through to the next case statement. Similar to
|
||||||
|
javac -Xlint:fallthrough, but the check is suppressed if a single-line comment
|
||||||
|
on the last non-blank line preceding the fallen-into case contains 'fall through' (or
|
||||||
|
some other variants which we don't publicized to promote consistency).
|
||||||
|
-->
|
||||||
|
<property name="reliefPattern"
|
||||||
|
value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
|
||||||
|
<property name="severity" value="error"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
MODIFIERS CHECKS
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<module name="ModifierOrder">
|
||||||
|
<!-- Warn if modifier order is inconsistent with JLS3 8.1.1, 8.3.1, and
|
||||||
|
8.4.3. The prescribed order is:
|
||||||
|
public, protected, private, abstract, static, final, transient, volatile,
|
||||||
|
synchronized, native, strictfp
|
||||||
|
-->
|
||||||
|
</module>
|
||||||
|
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
WHITESPACE CHECKS
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<module name="WhitespaceAround">
|
||||||
|
<!-- Checks that various tokens are surrounded by whitespace.
|
||||||
|
This includes most binary operators and keywords followed
|
||||||
|
by regular or curly braces.
|
||||||
|
-->
|
||||||
|
<property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR,
|
||||||
|
BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN,
|
||||||
|
EQUAL, GE, GT, LAND, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
|
||||||
|
LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
|
||||||
|
LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
|
||||||
|
MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION,
|
||||||
|
SL, SL_ASSIGN, SR_ASSIGN, STAR, STAR_ASSIGN"/>
|
||||||
|
<property name="severity" value="error"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="WhitespaceAfter">
|
||||||
|
<!-- Checks that commas, semicolons and typecasts are followed by
|
||||||
|
whitespace.
|
||||||
|
-->
|
||||||
|
<property name="tokens" value="COMMA, SEMI, TYPECAST"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="NoWhitespaceAfter">
|
||||||
|
<!-- Checks that there is no whitespace after various unary operators.
|
||||||
|
Linebreaks are allowed.
|
||||||
|
-->
|
||||||
|
<property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS,
|
||||||
|
UNARY_PLUS"/>
|
||||||
|
<property name="allowLineBreaks" value="true"/>
|
||||||
|
<property name="severity" value="error"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="NoWhitespaceBefore">
|
||||||
|
<!-- Checks that there is no whitespace before various unary operators.
|
||||||
|
Linebreaks are allowed.
|
||||||
|
-->
|
||||||
|
<property name="tokens" value="SEMI, DOT, POST_DEC, POST_INC"/>
|
||||||
|
<property name="allowLineBreaks" value="true"/>
|
||||||
|
<property name="severity" value="error"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="ParenPad">
|
||||||
|
<!-- Checks that there is no whitespace before close parens or after
|
||||||
|
open parens.
|
||||||
|
-->
|
||||||
|
<property name="severity" value="warning"/>
|
||||||
|
</module>
|
||||||
|
|
||||||
|
</module>
|
||||||
|
|
||||||
|
<module name="LineLength">
|
||||||
|
<!-- Checks if a line is too long. -->
|
||||||
|
<property name="max" value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.max}" default="128"/>
|
||||||
|
<property name="severity" value="error"/>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
The default ignore pattern exempts the following elements:
|
||||||
|
- import statements
|
||||||
|
- long URLs inside comments
|
||||||
|
-->
|
||||||
|
|
||||||
|
<property name="ignorePattern"
|
||||||
|
value="${com.puppycrawl.tools.checkstyle.checks.sizes.LineLength.ignorePattern}"
|
||||||
|
default="^(package .*;\s*)|(import .*;\s*)|( *(\*|//).*https?://.*)$"/>
|
||||||
|
</module>
|
||||||
|
</module>
|
||||||
|
|
11
gradle/quality/cyclonedx.gradle
Normal file
11
gradle/quality/cyclonedx.gradle
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
cyclonedxBom {
|
||||||
|
includeConfigs = [ 'runtimeClasspath' ]
|
||||||
|
skipConfigs = [ 'compileClasspath', 'testCompileClasspath' ]
|
||||||
|
projectType = "library"
|
||||||
|
schemaVersion = "1.4"
|
||||||
|
destination = file("build/reports")
|
||||||
|
outputName = "bom"
|
||||||
|
outputFormat = "json"
|
||||||
|
includeBomSerialNumber = true
|
||||||
|
componentVersion = "2.0.0"
|
||||||
|
}
|
17
gradle/quality/pmd.gradle
Normal file
17
gradle/quality/pmd.gradle
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
apply plugin: 'pmd'
|
||||||
|
|
||||||
|
tasks.withType(Pmd) {
|
||||||
|
ignoreFailures = true
|
||||||
|
reports {
|
||||||
|
xml.getRequired().set(true)
|
||||||
|
html.getRequired().set(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pmd {
|
||||||
|
ignoreFailures = true
|
||||||
|
consoleOutput = false
|
||||||
|
toolVersion = "6.51.0"
|
||||||
|
ruleSetFiles = rootProject.files('gradle/quality/pmd/category/java/bestpractices.xml')
|
||||||
|
}
|
1650
gradle/quality/pmd/category/java/bestpractices.xml
Normal file
1650
gradle/quality/pmd/category/java/bestpractices.xml
Normal file
File diff suppressed because it is too large
Load diff
10
gradle/quality/pmd/category/java/categories.properties
Normal file
10
gradle/quality/pmd/category/java/categories.properties
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
rulesets.filenames=\
|
||||||
|
category/java/bestpractices.xml,\
|
||||||
|
category/java/codestyle.xml,\
|
||||||
|
category/java/design.xml,\
|
||||||
|
category/java/documentation.xml,\
|
||||||
|
category/java/errorprone.xml,\
|
||||||
|
category/java/multithreading.xml,\
|
||||||
|
category/java/performance.xml,\
|
||||||
|
category/java/security.xml
|
2176
gradle/quality/pmd/category/java/codestyle.xml
Normal file
2176
gradle/quality/pmd/category/java/codestyle.xml
Normal file
File diff suppressed because it is too large
Load diff
1657
gradle/quality/pmd/category/java/design.xml
Normal file
1657
gradle/quality/pmd/category/java/design.xml
Normal file
File diff suppressed because it is too large
Load diff
144
gradle/quality/pmd/category/java/documentation.xml
Normal file
144
gradle/quality/pmd/category/java/documentation.xml
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<ruleset name="Documentation"
|
||||||
|
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||||
|
|
||||||
|
<description>
|
||||||
|
Rules that are related to code documentation.
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<rule name="CommentContent"
|
||||||
|
since="5.0"
|
||||||
|
message="Invalid words or phrases found"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.documentation.CommentContentRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#commentcontent">
|
||||||
|
<description>
|
||||||
|
A rule for the politically correct... we don't want to offend anyone.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
//OMG, this is horrible, Bob is an idiot !!!
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="CommentRequired"
|
||||||
|
since="5.1"
|
||||||
|
message="Comment is required"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.documentation.CommentRequiredRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#commentrequired">
|
||||||
|
<description>
|
||||||
|
Denotes whether comments are required (or unwanted) for specific language elements.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Jon Doe
|
||||||
|
*/
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="CommentSize"
|
||||||
|
since="5.0"
|
||||||
|
message="Comment is too large"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.documentation.CommentSizeRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#commentsize">
|
||||||
|
<description>
|
||||||
|
Determines whether the dimensions of non-header comments found are within the specified limits.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* too many lines!
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="UncommentedEmptyConstructor"
|
||||||
|
language="java"
|
||||||
|
since="3.4"
|
||||||
|
message="Document empty constructor"
|
||||||
|
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||||
|
typeResolution="true"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#uncommentedemptyconstructor">
|
||||||
|
<description>
|
||||||
|
Uncommented Empty Constructor finds instances where a constructor does not
|
||||||
|
contain statements, but there is no comment. By explicitly commenting empty
|
||||||
|
constructors it is easier to distinguish between intentional (commented)
|
||||||
|
and unintentional empty constructors.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<properties>
|
||||||
|
<property name="xpath">
|
||||||
|
<value>
|
||||||
|
<![CDATA[
|
||||||
|
//ConstructorDeclaration[@Private='false']
|
||||||
|
[count(BlockStatement) = 0 and ($ignoreExplicitConstructorInvocation = 'true' or not(ExplicitConstructorInvocation)) and @containsComment = 'false']
|
||||||
|
[not(../Annotation/MarkerAnnotation/Name[pmd-java:typeIs('javax.inject.Inject')])]
|
||||||
|
]]>
|
||||||
|
</value>
|
||||||
|
</property>
|
||||||
|
<property name="ignoreExplicitConstructorInvocation" type="Boolean" description="Ignore explicit constructor invocation when deciding whether constructor is empty or not" value="false"/>
|
||||||
|
</properties>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public Foo() {
|
||||||
|
// This constructor is intentionally empty. Nothing special is needed here.
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="UncommentedEmptyMethodBody"
|
||||||
|
language="java"
|
||||||
|
since="3.4"
|
||||||
|
message="Document empty method body"
|
||||||
|
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_documentation.html#uncommentedemptymethodbody">
|
||||||
|
<description>
|
||||||
|
Uncommented Empty Method Body finds instances where a method body does not contain
|
||||||
|
statements, but there is no comment. By explicitly commenting empty method bodies
|
||||||
|
it is easier to distinguish between intentional (commented) and unintentional
|
||||||
|
empty methods.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<properties>
|
||||||
|
<property name="xpath">
|
||||||
|
<value>
|
||||||
|
<![CDATA[
|
||||||
|
//MethodDeclaration/Block[count(BlockStatement) = 0 and @containsComment = 'false']
|
||||||
|
]]>
|
||||||
|
</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public void doSomething() {
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
</ruleset>
|
3383
gradle/quality/pmd/category/java/errorprone.xml
Normal file
3383
gradle/quality/pmd/category/java/errorprone.xml
Normal file
File diff suppressed because it is too large
Load diff
393
gradle/quality/pmd/category/java/multithreading.xml
Normal file
393
gradle/quality/pmd/category/java/multithreading.xml
Normal file
|
@ -0,0 +1,393 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<ruleset name="Multithreading"
|
||||||
|
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||||
|
|
||||||
|
<description>
|
||||||
|
Rules that flag issues when dealing with multiple threads of execution.
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<rule name="AvoidSynchronizedAtMethodLevel"
|
||||||
|
language="java"
|
||||||
|
since="3.0"
|
||||||
|
message="Use block level rather than method level synchronization"
|
||||||
|
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#avoidsynchronizedatmethodlevel">
|
||||||
|
<description>
|
||||||
|
Method-level synchronization can cause problems when new code is added to the method.
|
||||||
|
Block-level synchronization helps to ensure that only the code that needs synchronization
|
||||||
|
gets it.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<properties>
|
||||||
|
<property name="xpath">
|
||||||
|
<value>//MethodDeclaration[@Synchronized='true']</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
// Try to avoid this:
|
||||||
|
synchronized void foo() {
|
||||||
|
}
|
||||||
|
// Prefer this:
|
||||||
|
void bar() {
|
||||||
|
synchronized(this) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to avoid this for static methods:
|
||||||
|
static synchronized void fooStatic() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer this:
|
||||||
|
static void barStatic() {
|
||||||
|
synchronized(Foo.class) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="AvoidThreadGroup"
|
||||||
|
language="java"
|
||||||
|
since="3.6"
|
||||||
|
message="Avoid using java.lang.ThreadGroup; it is not thread safe"
|
||||||
|
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||||
|
typeResolution="true"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#avoidthreadgroup">
|
||||||
|
<description>
|
||||||
|
Avoid using java.lang.ThreadGroup; although it is intended to be used in a threaded environment
|
||||||
|
it contains methods that are not thread-safe.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<properties>
|
||||||
|
<property name="xpath">
|
||||||
|
<value>
|
||||||
|
<![CDATA[
|
||||||
|
//AllocationExpression/ClassOrInterfaceType[pmd-java:typeIs('java.lang.ThreadGroup')]|
|
||||||
|
//PrimarySuffix[contains(@Image, 'getThreadGroup')]
|
||||||
|
]]>
|
||||||
|
</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public class Bar {
|
||||||
|
void buz() {
|
||||||
|
ThreadGroup tg = new ThreadGroup("My threadgroup");
|
||||||
|
tg = new ThreadGroup(tg, "my thread group");
|
||||||
|
tg = Thread.currentThread().getThreadGroup();
|
||||||
|
tg = System.getSecurityManager().getThreadGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="AvoidUsingVolatile"
|
||||||
|
language="java"
|
||||||
|
since="4.1"
|
||||||
|
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||||
|
message="Use of modifier volatile is not recommended."
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#avoidusingvolatile">
|
||||||
|
<description>
|
||||||
|
Use of the keyword 'volatile' is generally used to fine tune a Java application, and therefore, requires
|
||||||
|
a good expertise of the Java Memory Model. Moreover, its range of action is somewhat misknown. Therefore,
|
||||||
|
the volatile keyword should not be used for maintenance purpose and portability.
|
||||||
|
</description>
|
||||||
|
<priority>2</priority>
|
||||||
|
<properties>
|
||||||
|
<property name="xpath">
|
||||||
|
<value>//FieldDeclaration[contains(@Volatile,'true')]</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public class ThrDeux {
|
||||||
|
private volatile String var1; // not suggested
|
||||||
|
private String var2; // preferred
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="DoNotUseThreads"
|
||||||
|
language="java"
|
||||||
|
since="4.1"
|
||||||
|
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||||
|
message="To be compliant to J2EE, a webapp should not use any thread."
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#donotusethreads">
|
||||||
|
<description>
|
||||||
|
The J2EE specification explicitly forbids the use of threads.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<properties>
|
||||||
|
<property name="xpath">
|
||||||
|
<value>//ClassOrInterfaceType[@Image = 'Thread' or @Image = 'Runnable']</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
// This is not allowed
|
||||||
|
public class UsingThread extends Thread {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Neither this,
|
||||||
|
public class OtherThread implements Runnable {
|
||||||
|
// Nor this ...
|
||||||
|
public void methode() {
|
||||||
|
Runnable thread = new Thread(); thread.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="DontCallThreadRun"
|
||||||
|
language="java"
|
||||||
|
since="4.3"
|
||||||
|
message="Don't call Thread.run() explicitly, use Thread.start()"
|
||||||
|
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||||
|
typeResolution="true"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#dontcallthreadrun">
|
||||||
|
<description>
|
||||||
|
Explicitly calling Thread.run() method will execute in the caller's thread of control. Instead, call Thread.start() for the intended behavior.
|
||||||
|
</description>
|
||||||
|
<priority>4</priority>
|
||||||
|
<properties>
|
||||||
|
<property name="xpath">
|
||||||
|
<value>
|
||||||
|
<![CDATA[
|
||||||
|
//StatementExpression/PrimaryExpression
|
||||||
|
[
|
||||||
|
PrimaryPrefix
|
||||||
|
[
|
||||||
|
./Name[ends-with(@Image, '.run') or @Image = 'run']
|
||||||
|
and substring-before(Name/@Image, '.') =//VariableDeclarator/VariableDeclaratorId/@Image
|
||||||
|
[../../../Type/ReferenceType/ClassOrInterfaceType[pmd-java:typeIs('java.lang.Thread')]]
|
||||||
|
or (./AllocationExpression/ClassOrInterfaceType[pmd-java:typeIs('java.lang.Thread')]
|
||||||
|
and ../PrimarySuffix[@Image = 'run'])
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]]>
|
||||||
|
</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
Thread t = new Thread();
|
||||||
|
t.run(); // use t.start() instead
|
||||||
|
new Thread().run(); // same violation
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="DoubleCheckedLocking"
|
||||||
|
language="java"
|
||||||
|
since="1.04"
|
||||||
|
message="Double checked locking is not thread safe in Java."
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.multithreading.DoubleCheckedLockingRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#doublecheckedlocking">
|
||||||
|
<description>
|
||||||
|
Partially created objects can be returned by the Double Checked Locking pattern when used in Java.
|
||||||
|
An optimizing JRE may assign a reference to the baz variable before it calls the constructor of the object the
|
||||||
|
reference points to.
|
||||||
|
|
||||||
|
Note: With Java 5, you can make Double checked locking work, if you declare the variable to be `volatile`.
|
||||||
|
|
||||||
|
For more details refer to: <http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html>
|
||||||
|
or <http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html>
|
||||||
|
</description>
|
||||||
|
<priority>1</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
/*volatile */ Object baz = null; // fix for Java5 and later: volatile
|
||||||
|
Object bar() {
|
||||||
|
if (baz == null) { // baz may be non-null yet not fully created
|
||||||
|
synchronized(this) {
|
||||||
|
if (baz == null) {
|
||||||
|
baz = new Object();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return baz;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="NonThreadSafeSingleton"
|
||||||
|
since="3.4"
|
||||||
|
message="Singleton is not thread safe"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.multithreading.NonThreadSafeSingletonRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#nonthreadsafesingleton">
|
||||||
|
<description>
|
||||||
|
Non-thread safe singletons can result in bad state changes. Eliminate
|
||||||
|
static singletons if possible by instantiating the object directly. Static
|
||||||
|
singletons are usually not needed as only a single instance exists anyway.
|
||||||
|
Other possible fixes are to synchronize the entire method or to use an
|
||||||
|
[initialize-on-demand holder class](https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom).
|
||||||
|
|
||||||
|
Refrain from using the double-checked locking pattern. The Java Memory Model doesn't
|
||||||
|
guarantee it to work unless the variable is declared as `volatile`, adding an uneeded
|
||||||
|
performance penalty. [Reference](http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html)
|
||||||
|
|
||||||
|
See Effective Java, item 48.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
private static Foo foo = null;
|
||||||
|
|
||||||
|
//multiple simultaneous callers may see partially initialized objects
|
||||||
|
public static Foo getFoo() {
|
||||||
|
if (foo==null) {
|
||||||
|
foo = new Foo();
|
||||||
|
}
|
||||||
|
return foo;
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="UnsynchronizedStaticDateFormatter"
|
||||||
|
since="3.6"
|
||||||
|
deprecated="true"
|
||||||
|
message="Static DateFormatter objects should be accessed in a synchronized manner"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.multithreading.UnsynchronizedStaticDateFormatterRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#unsynchronizedstaticdateformatter">
|
||||||
|
<description>
|
||||||
|
SimpleDateFormat instances are not synchronized. Sun recommends using separate format instances
|
||||||
|
for each thread. If multiple threads must access a static formatter, the formatter must be
|
||||||
|
synchronized either on method or block level.
|
||||||
|
|
||||||
|
This rule has been deprecated in favor of the rule {% rule UnsynchronizedStaticFormatter %}.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
private static final SimpleDateFormat sdf = new SimpleDateFormat();
|
||||||
|
void bar() {
|
||||||
|
sdf.format(); // poor, no thread-safety
|
||||||
|
}
|
||||||
|
synchronized void foo() {
|
||||||
|
sdf.format(); // preferred
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="UnsynchronizedStaticFormatter"
|
||||||
|
since="6.11.0"
|
||||||
|
message="Static Formatter objects should be accessed in a synchronized manner"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.multithreading.UnsynchronizedStaticFormatterRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#unsynchronizedstaticformatter">
|
||||||
|
<description>
|
||||||
|
Instances of `java.text.Format` are generally not synchronized.
|
||||||
|
Sun recommends using separate format instances for each thread.
|
||||||
|
If multiple threads must access a static formatter, the formatter must be
|
||||||
|
synchronized either on method or block level.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
private static final SimpleDateFormat sdf = new SimpleDateFormat();
|
||||||
|
void bar() {
|
||||||
|
sdf.format(); // poor, no thread-safety
|
||||||
|
}
|
||||||
|
synchronized void foo() {
|
||||||
|
sdf.format(); // preferred
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="UseConcurrentHashMap"
|
||||||
|
language="java"
|
||||||
|
minimumLanguageVersion="1.5"
|
||||||
|
since="4.2.6"
|
||||||
|
message="If you run in Java5 or newer and have concurrent access, you should use the ConcurrentHashMap implementation"
|
||||||
|
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#useconcurrenthashmap">
|
||||||
|
<description>
|
||||||
|
Since Java5 brought a new implementation of the Map designed for multi-threaded access, you can
|
||||||
|
perform efficient map reads without blocking other threads.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<properties>
|
||||||
|
<property name="xpath">
|
||||||
|
<value>
|
||||||
|
<![CDATA[
|
||||||
|
//Type[../VariableDeclarator/VariableInitializer//AllocationExpression/ClassOrInterfaceType[@Image != 'ConcurrentHashMap']]
|
||||||
|
/ReferenceType/ClassOrInterfaceType[@Image = 'Map']
|
||||||
|
]]>
|
||||||
|
</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public class ConcurrentApp {
|
||||||
|
public void getMyInstance() {
|
||||||
|
Map map1 = new HashMap(); // fine for single-threaded access
|
||||||
|
Map map2 = new ConcurrentHashMap(); // preferred for use with multiple threads
|
||||||
|
|
||||||
|
// the following case will be ignored by this rule
|
||||||
|
Map map3 = someModule.methodThatReturnMap(); // might be OK, if the returned map is already thread-safe
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="UseNotifyAllInsteadOfNotify"
|
||||||
|
language="java"
|
||||||
|
since="3.0"
|
||||||
|
message="Call Thread.notifyAll() rather than Thread.notify()"
|
||||||
|
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_multithreading.html#usenotifyallinsteadofnotify">
|
||||||
|
<description>
|
||||||
|
Thread.notify() awakens a thread monitoring the object. If more than one thread is monitoring, then only
|
||||||
|
one is chosen. The thread chosen is arbitrary; thus its usually safer to call notifyAll() instead.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<properties>
|
||||||
|
<property name="xpath">
|
||||||
|
<value>
|
||||||
|
<![CDATA[
|
||||||
|
//StatementExpression/PrimaryExpression
|
||||||
|
[PrimarySuffix/Arguments[@ArgumentCount = '0']]
|
||||||
|
[
|
||||||
|
PrimaryPrefix[
|
||||||
|
./Name[@Image='notify' or ends-with(@Image,'.notify')]
|
||||||
|
or ../PrimarySuffix/@Image='notify'
|
||||||
|
or (./AllocationExpression and ../PrimarySuffix[@Image='notify'])
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]]>
|
||||||
|
</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
void bar() {
|
||||||
|
x.notify();
|
||||||
|
// If many threads are monitoring x, only one (and you won't know which) will be notified.
|
||||||
|
// use instead:
|
||||||
|
x.notifyAll();
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
</ruleset>
|
1006
gradle/quality/pmd/category/java/performance.xml
Normal file
1006
gradle/quality/pmd/category/java/performance.xml
Normal file
File diff suppressed because it is too large
Load diff
65
gradle/quality/pmd/category/java/security.xml
Normal file
65
gradle/quality/pmd/category/java/security.xml
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<ruleset name="Security" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||||
|
|
||||||
|
<description>
|
||||||
|
Rules that flag potential security flaws.
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<rule name="HardCodedCryptoKey"
|
||||||
|
since="6.4.0"
|
||||||
|
message="Do not use hard coded encryption keys"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.security.HardCodedCryptoKeyRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_security.html#hardcodedcryptokey">
|
||||||
|
<description>
|
||||||
|
Do not use hard coded values for cryptographic operations. Please store keys outside of source code.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
void good() {
|
||||||
|
SecretKeySpec secretKeySpec = new SecretKeySpec(Properties.getKey(), "AES");
|
||||||
|
}
|
||||||
|
|
||||||
|
void bad() {
|
||||||
|
SecretKeySpec secretKeySpec = new SecretKeySpec("my secret here".getBytes(), "AES");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
<rule name="InsecureCryptoIv"
|
||||||
|
since="6.3.0"
|
||||||
|
message="Do not use hard coded initialization vector in crypto operations"
|
||||||
|
class="net.sourceforge.pmd.lang.java.rule.security.InsecureCryptoIvRule"
|
||||||
|
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_security.html#insecurecryptoiv">
|
||||||
|
<description>
|
||||||
|
Do not use hard coded initialization vector in cryptographic operations. Please use a randomly generated IV.
|
||||||
|
</description>
|
||||||
|
<priority>3</priority>
|
||||||
|
<example>
|
||||||
|
<![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
void good() {
|
||||||
|
SecureRandom random = new SecureRandom();
|
||||||
|
byte iv[] = new byte[16];
|
||||||
|
random.nextBytes(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bad() {
|
||||||
|
byte[] iv = new byte[] { 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, };
|
||||||
|
}
|
||||||
|
|
||||||
|
void alsoBad() {
|
||||||
|
byte[] iv = "secret iv in here".getBytes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]>
|
||||||
|
</example>
|
||||||
|
</rule>
|
||||||
|
|
||||||
|
</ruleset>
|
37
gradle/quality/sonarqube.gradle
Normal file
37
gradle/quality/sonarqube.gradle
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
|
||||||
|
subprojects {
|
||||||
|
|
||||||
|
sonarqube {
|
||||||
|
properties {
|
||||||
|
property "sonar.projectName", "${project.group} ${project.name}"
|
||||||
|
property "sonar.sourceEncoding", "UTF-8"
|
||||||
|
property "sonar.tests", "src/test/java"
|
||||||
|
property "sonar.scm.provider", "git"
|
||||||
|
property "sonar.junit.reportsPath", "build/test-results/test/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tasks.withType(Pmd) {
|
||||||
|
ignoreFailures = true
|
||||||
|
reports {
|
||||||
|
xml.enabled = true
|
||||||
|
html.enabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
spotbugs {
|
||||||
|
effort = "max"
|
||||||
|
reportLevel = "low"
|
||||||
|
//includeFilter = file("findbugs-exclude.xml")
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(com.github.spotbugs.SpotBugsTask) {
|
||||||
|
ignoreFailures = true
|
||||||
|
reports {
|
||||||
|
xml.enabled = false
|
||||||
|
html.enabled = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,53 +1,15 @@
|
||||||
/*
|
|
||||||
|
apply plugin: 'com.github.spotbugs'
|
||||||
|
|
||||||
spotbugs {
|
spotbugs {
|
||||||
effort = "max"
|
effort = "max"
|
||||||
reportLevel = "low"
|
reportLevel = "low"
|
||||||
|
ignoreFailures = true
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(com.github.spotbugs.SpotBugsTask) {
|
spotbugsMain {
|
||||||
ignoreFailures = true
|
|
||||||
reports {
|
reports {
|
||||||
xml.enabled = false
|
xml.getRequired().set(false)
|
||||||
html.enabled = true
|
html.getRequired().set(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pmd {
|
|
||||||
toolVersion = '6.11.0'
|
|
||||||
ruleSets = ['category/java/bestpractices.xml']
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(Pmd) {
|
|
||||||
ignoreFailures = true
|
|
||||||
reports {
|
|
||||||
xml.enabled = true
|
|
||||||
html.enabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkstyle {
|
|
||||||
toolVersion = '8.26'
|
|
||||||
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
|
|
||||||
ignoreFailures = true
|
|
||||||
checkstyleMain {
|
|
||||||
source = sourceSets.main.allSource
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(Checkstyle) {
|
|
||||||
ignoreFailures = true
|
|
||||||
reports {
|
|
||||||
xml.enabled = true
|
|
||||||
html.enabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sonarqube {
|
|
||||||
properties {
|
|
||||||
property "sonar.projectName", "${project.group} ${project.name}"
|
|
||||||
property "sonar.sourceEncoding", "UTF-8"
|
|
||||||
property "sonar.tests", "src/test/java"
|
|
||||||
property "sonar.scm.provider", "git"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
|
@ -12,7 +12,7 @@ dependencies {
|
||||||
|
|
||||||
test {
|
test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
failFast = true
|
failFast = false
|
||||||
testLogging {
|
testLogging {
|
||||||
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
|
events 'STARTED', 'PASSED', 'FAILED', 'SKIPPED'
|
||||||
}
|
}
|
||||||
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,6 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip
|
||||||
|
networkTimeout=10000
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
288
gradlew
vendored
288
gradlew
vendored
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright 2015 the original author or authors.
|
# Copyright © 2015-2021 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
@ -17,67 +17,98 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##
|
#
|
||||||
## Gradle start up script for UN*X
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
##
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
PRG="$0"
|
app_path=$0
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
# Need this for daisy-chained symlinks.
|
||||||
ls=`ls -ld "$PRG"`
|
while
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
[ -h "$app_path" ]
|
||||||
PRG="$link"
|
do
|
||||||
else
|
ls=$( ls -ld "$app_path" )
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
link=${ls#*' -> '}
|
||||||
fi
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
# This is normally unused
|
||||||
APP_BASE_NAME=`basename "$0"`
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
MAX_FD=maximum
|
||||||
|
|
||||||
warn () {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
# OS specific support (must be 'true' or 'false').
|
||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "`uname`" in
|
case "$( uname )" in #(
|
||||||
CYGWIN* )
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
cygwin=true
|
Darwin* ) darwin=true ;; #(
|
||||||
;;
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
Darwin* )
|
NONSTOP* ) nonstop=true ;;
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
@ -87,9 +118,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
fi
|
fi
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
@ -98,7 +129,7 @@ Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="java"
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
@ -106,80 +137,109 @@ location of your Java installation."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
case $MAX_FD in #(
|
||||||
if [ $? -eq 0 ] ; then
|
max*)
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
# shellcheck disable=SC3045
|
||||||
fi
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
ulimit -n $MAX_FD
|
warn "Could not query maximum file descriptor limit"
|
||||||
if [ $? -ne 0 ] ; then
|
esac
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
case $MAX_FD in #(
|
||||||
fi
|
'' | soft) :;; #(
|
||||||
else
|
*)
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
fi
|
# shellcheck disable=SC3045
|
||||||
fi
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=`expr $i + 1`
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
0) set -- ;;
|
|
||||||
1) set -- "$args0" ;;
|
|
||||||
2) set -- "$args0" "$args1" ;;
|
|
||||||
3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Escape application args
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
save () {
|
# * args from the command line
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
# * the main class name
|
||||||
echo " "
|
# * -classpath
|
||||||
}
|
# * -D...appname settings
|
||||||
APP_ARGS=`save "$@"`
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command;
|
||||||
|
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||||
|
# shell script including quotes and variable substitutions, so put them in
|
||||||
|
# double quotes to make sure that they get re-expanded; and
|
||||||
|
# * put everything else in single quotes, so that it's not re-expanded.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
|
|
11
gradlew.bat
vendored
11
gradlew.bat
vendored
|
@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
|
@ -1 +1,49 @@
|
||||||
rootProject.name = name
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral {
|
||||||
|
metadataSources {
|
||||||
|
mavenPom()
|
||||||
|
artifact()
|
||||||
|
ignoreGradleMetadataRedirection()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencyResolutionManagement {
|
||||||
|
versionCatalogs {
|
||||||
|
libs {
|
||||||
|
version('gradle', '8.1.1')
|
||||||
|
version('groovy', '3.0.10')
|
||||||
|
version('junit', '5.9.2')
|
||||||
|
library('junit-jupiter-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
|
||||||
|
library('junit-jupiter-params', 'org.junit.jupiter', 'junit-jupiter-params').versionRef('junit')
|
||||||
|
library('junit-jupiter-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')
|
||||||
|
library('hamcrest', 'org.hamcrest', 'hamcrest-library').version('2.2')
|
||||||
|
library('junit4', 'junit', 'junit').version('4.13.2')
|
||||||
|
library('javax.inject', 'org.xbib', 'javax-inject').version('1')
|
||||||
|
library('guava', 'org.xbib', 'guava').version('30.1')
|
||||||
|
library('guava.testlib', 'com.google.guava', 'guava-testlib').version('30.1-jre')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
gradle.wrapper.version = 6.6.1
|
||||||
|
javax-inject.version = 1
|
||||||
|
guava.version = 30.1
|
||||||
|
# test
|
||||||
|
junit.version = 5.7.2
|
||||||
|
junit4.version = 4.13.2
|
||||||
|
log4j.version = 2.14.1
|
||||||
|
|
||||||
|
api "org.xbib:javax-inject:${project.property('javax-inject.version')}"
|
||||||
|
api "org.xbib:guava:${project.property('guava.version')}"
|
||||||
|
testImplementation "junit:junit:${project.property('junit4.version')}"
|
||||||
|
// Helper for com.google.common.testing.GcFinalization, com.google.common.testing.EqualsTester
|
||||||
|
testImplementation "com.google.guava:guava-testlib:30.1-jre"
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
|
@ -41,6 +41,6 @@ class NamedImpl implements Named {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "@" + Named.class.getName() + "(value=" + Annotations.memberValueString(value) + ")";
|
return "@" + Named.class.getName() + "(" + Annotations.memberValueString(value) + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package com.google.inject.spi;
|
package com.google.inject.spi;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.inject.internal.util.StackTraceElements;
|
|
||||||
import com.google.inject.internal.util.StackTraceElements.InMemoryStackTraceElement;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,21 +10,6 @@ import java.util.List;
|
||||||
* defines the Guice {@link Element element}. For example, if the element is created from a method
|
* defines the Guice {@link Element element}. For example, if the element is created from a method
|
||||||
* annotated by {@literal @Provides}, the declaring source of element would be the method itself.
|
* annotated by {@literal @Provides}, the declaring source of element would be the method itself.
|
||||||
*
|
*
|
||||||
* <p>The {@link #getStackTrace()} refers to the sequence of calls ends at one of {@link
|
|
||||||
* com.google.inject.Binder} {@code bindXXX()} methods and eventually defines the element. Note that
|
|
||||||
* {@link #getStackTrace()} lists {@link StackTraceElement StackTraceElements} in reverse
|
|
||||||
* chronological order. The first element (index zero) is the last method call and the last element
|
|
||||||
* is the first method invocation. By default, the stack trace is not collected. The default
|
|
||||||
* behavior can be changed by setting the {@code guice_include_stack_traces} flag value. The value
|
|
||||||
* can be either {@code OFF}, {@code ONLY_FOR_DECLARING_SOURCE} or {@code COMPLETE}. Note that
|
|
||||||
* collecting stack traces for every binding can cause a performance hit when the injector is
|
|
||||||
* created.
|
|
||||||
*
|
|
||||||
* <p>The sequence of class names of {@link com.google.inject.Module modules} involved in the
|
|
||||||
* element creation can be retrieved by {@link #getModuleClassNames()}. Similar to {@link
|
|
||||||
* #getStackTrace()}, the order is reverse chronological. The first module (index 0) is the module
|
|
||||||
* that installs the {@link Element element}. The last module is the root module.
|
|
||||||
*
|
|
||||||
* <p>In order to support the cases where a Guice {@link Element element} is created from another
|
* <p>In order to support the cases where a Guice {@link Element element} is created from another
|
||||||
* Guice {@link Element element} (original) (e.g., by {@link Element#applyTo}), it also provides a
|
* Guice {@link Element element} (original) (e.g., by {@link Element#applyTo}), it also provides a
|
||||||
* reference to the original element source ({@link #getOriginalElementSource()}).
|
* reference to the original element source ({@link #getOriginalElementSource()}).
|
||||||
|
@ -54,12 +36,6 @@ public final class ElementSource {
|
||||||
/** The {@link ModuleSource source} of module creates the element. */
|
/** The {@link ModuleSource source} of module creates the element. */
|
||||||
final ModuleSource moduleSource;
|
final ModuleSource moduleSource;
|
||||||
|
|
||||||
/**
|
|
||||||
* The partial call stack that starts at the last module {@link Module#Configure(Binder)
|
|
||||||
* configure(Binder)} call. The value is empty if stack trace collection is off.
|
|
||||||
*/
|
|
||||||
final InMemoryStackTraceElement[] partialCallStack;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refers to a single location in source code that causes the element creation. It can be any
|
* Refers to a single location in source code that causes the element creation. It can be any
|
||||||
* object such as {@link Constructor}, {@link Method}, {@link Field}, {@link StackTraceElement},
|
* object such as {@link Constructor}, {@link Method}, {@link Field}, {@link StackTraceElement},
|
||||||
|
@ -78,24 +54,19 @@ public final class ElementSource {
|
||||||
* any), otherwise {@code null}.
|
* any), otherwise {@code null}.
|
||||||
* @param declaringSource the source (in)directly declared the element.
|
* @param declaringSource the source (in)directly declared the element.
|
||||||
* @param moduleSource the moduleSource when the element is bound
|
* @param moduleSource the moduleSource when the element is bound
|
||||||
* @param partialCallStack the partial call stack from the top module to where the element is
|
|
||||||
* bound
|
|
||||||
*/
|
*/
|
||||||
ElementSource(
|
ElementSource(
|
||||||
ElementSource originalSource,
|
ElementSource originalSource,
|
||||||
boolean trustedOriginalSource,
|
boolean trustedOriginalSource,
|
||||||
Object declaringSource,
|
Object declaringSource,
|
||||||
ModuleSource moduleSource,
|
ModuleSource moduleSource,
|
||||||
StackTraceElement[] partialCallStack,
|
|
||||||
ModuleAnnotatedMethodScanner scanner) {
|
ModuleAnnotatedMethodScanner scanner) {
|
||||||
Preconditions.checkNotNull(declaringSource, "declaringSource cannot be null.");
|
Preconditions.checkNotNull(declaringSource, "declaringSource cannot be null.");
|
||||||
Preconditions.checkNotNull(moduleSource, "moduleSource cannot be null.");
|
Preconditions.checkNotNull(moduleSource, "moduleSource cannot be null.");
|
||||||
Preconditions.checkNotNull(partialCallStack, "partialCallStack cannot be null.");
|
|
||||||
this.originalElementSource = originalSource;
|
this.originalElementSource = originalSource;
|
||||||
this.trustedOriginalElementSource = trustedOriginalSource;
|
this.trustedOriginalElementSource = trustedOriginalSource;
|
||||||
this.declaringSource = declaringSource;
|
this.declaringSource = declaringSource;
|
||||||
this.moduleSource = moduleSource;
|
this.moduleSource = moduleSource;
|
||||||
this.partialCallStack = StackTraceElements.convertToInMemoryStackTraceElement(partialCallStack);
|
|
||||||
this.scanner = scanner;
|
this.scanner = scanner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,60 +98,6 @@ public final class ElementSource {
|
||||||
return moduleSource.getModuleClassNames();
|
return moduleSource.getModuleClassNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the position of {@link com.google.inject.Module#configure configure(Binder)} method
|
|
||||||
* call in the {@link #getStackTrace stack trace} for modules that their classes returned by
|
|
||||||
* {@link #getModuleClassNames}. For example, if the stack trace looks like the following:
|
|
||||||
*
|
|
||||||
* <ol>
|
|
||||||
* <li>{@code Binder.bind()}
|
|
||||||
* <li>{@code ModuleTwo.configure()}
|
|
||||||
* <li>{@code Binder.install()}
|
|
||||||
* <li>{@code ModuleOne.configure()}
|
|
||||||
* <li>{@code theRest().
|
|
||||||
* </ol>
|
|
||||||
*
|
|
||||||
* <p>1 and 3 are returned.
|
|
||||||
*
|
|
||||||
* <p>In the cases where stack trace is not available (i.e., the stack trace was not collected),
|
|
||||||
* it returns -1 for all module positions.
|
|
||||||
*/
|
|
||||||
public List<Integer> getModuleConfigurePositionsInStackTrace() {
|
|
||||||
int size = moduleSource.size();
|
|
||||||
Integer[] positions = new Integer[size];
|
|
||||||
int chunkSize = partialCallStack.length;
|
|
||||||
positions[0] = chunkSize - 1;
|
|
||||||
ModuleSource current = moduleSource;
|
|
||||||
for (int cursor = 1; cursor < size; cursor++) {
|
|
||||||
chunkSize = current.getPartialCallStackSize();
|
|
||||||
positions[cursor] = positions[cursor - 1] + chunkSize;
|
|
||||||
current = current.getParent();
|
|
||||||
}
|
|
||||||
return ImmutableList.<Integer>copyOf(positions);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the sequence of method calls that ends at one of {@link com.google.inject.Binder}
|
|
||||||
* {@code bindXXX()} methods and eventually defines the element. Note that {@link #getStackTrace}
|
|
||||||
* lists {@link StackTraceElement StackTraceElements} in reverse chronological order. The first
|
|
||||||
* element (index zero) is the last method call and the last element is the first method
|
|
||||||
* invocation. In the cases where stack trace is not available (i.e.,the stack trace was not
|
|
||||||
* collected), it returns an empty array.
|
|
||||||
*/
|
|
||||||
public StackTraceElement[] getStackTrace() {
|
|
||||||
int modulesCallStackSize = moduleSource.getStackTraceSize();
|
|
||||||
int chunkSize = partialCallStack.length;
|
|
||||||
int size = moduleSource.getStackTraceSize() + chunkSize;
|
|
||||||
StackTraceElement[] callStack = new StackTraceElement[size];
|
|
||||||
System.arraycopy(
|
|
||||||
StackTraceElements.convertToStackTraceElement(partialCallStack),
|
|
||||||
0,
|
|
||||||
callStack,
|
|
||||||
0,
|
|
||||||
chunkSize);
|
|
||||||
System.arraycopy(moduleSource.getStackTrace(), 0, callStack, chunkSize, modulesCallStackSize);
|
|
||||||
return callStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns {@code getDeclaringSource().toString()} value. */
|
/** Returns {@code getDeclaringSource().toString()} value. */
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -603,23 +603,13 @@ public final class Elements {
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModuleSource getModuleSource(Class<?> module) {
|
private ModuleSource getModuleSource(Class<?> module) {
|
||||||
StackTraceElement[] partialCallStack;
|
|
||||||
if (getIncludeStackTraceOption() == IncludeStackTraceOption.COMPLETE) {
|
|
||||||
partialCallStack = getPartialCallStack(new Throwable().getStackTrace());
|
|
||||||
} else {
|
|
||||||
partialCallStack = new StackTraceElement[0];
|
|
||||||
}
|
|
||||||
if (moduleSource == null) {
|
if (moduleSource == null) {
|
||||||
return new ModuleSource(module, partialCallStack, permitMapConstruction.getPermitMap());
|
return new ModuleSource(module, permitMapConstruction.getPermitMap());
|
||||||
}
|
}
|
||||||
return moduleSource.createChild(module, partialCallStack);
|
return moduleSource.createChild(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ElementSource getElementSource() {
|
private ElementSource getElementSource() {
|
||||||
// Full call stack
|
|
||||||
StackTraceElement[] callStack = null;
|
|
||||||
// The call stack starts from current top module configure and ends at this method caller
|
|
||||||
StackTraceElement[] partialCallStack = new StackTraceElement[0];
|
|
||||||
// The element original source
|
// The element original source
|
||||||
ElementSource originalSource = null;
|
ElementSource originalSource = null;
|
||||||
// The element declaring source
|
// The element declaring source
|
||||||
|
@ -628,21 +618,10 @@ public final class Elements {
|
||||||
originalSource = (ElementSource) declaringSource;
|
originalSource = (ElementSource) declaringSource;
|
||||||
declaringSource = originalSource.getDeclaringSource();
|
declaringSource = originalSource.getDeclaringSource();
|
||||||
}
|
}
|
||||||
IncludeStackTraceOption stackTraceOption = getIncludeStackTraceOption();
|
|
||||||
if (stackTraceOption == IncludeStackTraceOption.COMPLETE
|
|
||||||
|| (stackTraceOption == IncludeStackTraceOption.ONLY_FOR_DECLARING_SOURCE
|
|
||||||
&& declaringSource == null)) {
|
|
||||||
callStack = new Throwable().getStackTrace();
|
|
||||||
}
|
|
||||||
if (stackTraceOption == IncludeStackTraceOption.COMPLETE) {
|
|
||||||
partialCallStack = getPartialCallStack(callStack);
|
|
||||||
}
|
|
||||||
if (declaringSource == null) {
|
if (declaringSource == null) {
|
||||||
// So 'source' and 'originalSource' are null otherwise declaringSource has some value
|
IncludeStackTraceOption stackTraceOption = getIncludeStackTraceOption();
|
||||||
if (stackTraceOption == IncludeStackTraceOption.COMPLETE
|
if (stackTraceOption == IncludeStackTraceOption.ONLY_FOR_DECLARING_SOURCE) {
|
||||||
|| stackTraceOption == IncludeStackTraceOption.ONLY_FOR_DECLARING_SOURCE) {
|
StackTraceElement callingSource = sourceProvider.get(new Throwable().getStackTrace());
|
||||||
// With the above conditions and assignments 'callStack' is non-null
|
|
||||||
StackTraceElement callingSource = sourceProvider.get(callStack);
|
|
||||||
// If we've traversed past all reasonable sources and into our internal code, then we
|
// If we've traversed past all reasonable sources and into our internal code, then we
|
||||||
// don't know the source.
|
// don't know the source.
|
||||||
if (callingSource
|
if (callingSource
|
||||||
|
@ -653,37 +632,14 @@ public final class Elements {
|
||||||
} else {
|
} else {
|
||||||
declaringSource = callingSource;
|
declaringSource = callingSource;
|
||||||
}
|
}
|
||||||
} else { // or if (stackTraceOption == IncludeStackTraceOptions.OFF)
|
} else {
|
||||||
// As neither 'declaring source' nor 'call stack' is available use 'module source'
|
// As neither 'declaring source' nor 'call stack' is available use 'module source'
|
||||||
declaringSource = sourceProvider.getFromClassNames(moduleSource.getModuleClassNames());
|
declaringSource = sourceProvider.getFromClassNames(moduleSource.getModuleClassNames());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Build the binding call stack
|
// Build the binding call stack
|
||||||
return new ElementSource(
|
return new ElementSource(
|
||||||
originalSource,
|
originalSource, trustedSource, declaringSource, moduleSource, scannerSource);
|
||||||
trustedSource,
|
|
||||||
declaringSource,
|
|
||||||
moduleSource,
|
|
||||||
partialCallStack,
|
|
||||||
scannerSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes the {@link #moduleSource} call stack from the beginning of current call stack. It
|
|
||||||
* also removes the last two elements in order to make {@link #install(Module)} the last call in
|
|
||||||
* the call stack.
|
|
||||||
*/
|
|
||||||
private StackTraceElement[] getPartialCallStack(StackTraceElement[] callStack) {
|
|
||||||
int toSkip = 0;
|
|
||||||
if (moduleSource != null) {
|
|
||||||
toSkip = moduleSource.getStackTraceSize();
|
|
||||||
}
|
|
||||||
// -1 for skipping 'getModuleSource' and 'getElementSource' calls
|
|
||||||
int chunkSize = callStack.length - toSkip - 1;
|
|
||||||
|
|
||||||
StackTraceElement[] partialCallStack = new StackTraceElement[chunkSize];
|
|
||||||
System.arraycopy(callStack, 1, partialCallStack, 0, chunkSize);
|
|
||||||
return partialCallStack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns if the binder is in the module scanning phase. */
|
/** Returns if the binder is in the module scanning phase. */
|
||||||
|
|
|
@ -3,14 +3,11 @@ package com.google.inject.spi;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.internal.util.StackTraceElements;
|
|
||||||
import com.google.inject.internal.util.StackTraceElements.InMemoryStackTraceElement;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Associated to a {@link Module module}, provides the module class name, the parent module {@link
|
* Associated to a {@link Module module}, provides the module class name, the parent module {@link
|
||||||
* ModuleSource source}, and the call stack that ends just before the module {@link
|
* ModuleSource source}, and the call stack that ends just before the method invocation.
|
||||||
* Module#configure(Binder) configure(Binder)} method invocation.
|
|
||||||
*/
|
*/
|
||||||
final class ModuleSource {
|
final class ModuleSource {
|
||||||
|
|
||||||
|
@ -29,27 +26,14 @@ final class ModuleSource {
|
||||||
*/
|
*/
|
||||||
private final BindingSourceRestriction.PermitMap permitMap;
|
private final BindingSourceRestriction.PermitMap permitMap;
|
||||||
|
|
||||||
/**
|
|
||||||
* The chunk of call stack that starts from the parent module {@link Module#configure(Binder)
|
|
||||||
* configure(Binder)} call and ends just before the module {@link Module#configure(Binder)
|
|
||||||
* configure(Binder)} method invocation. For a module without a parent module the chunk starts
|
|
||||||
* from the bottom of call stack. The array is non-empty if stack trace collection is on.
|
|
||||||
*/
|
|
||||||
private final InMemoryStackTraceElement[] partialCallStack;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link ModuleSource} with a {@literal null} parent.
|
* Creates a new {@link ModuleSource} with a {@literal null} parent.
|
||||||
*
|
*
|
||||||
* @param moduleClass the corresponding module
|
* @param moduleClass the corresponding module
|
||||||
* @param partialCallStack the chunk of call stack that starts from the parent module {@link
|
|
||||||
* Module#configure(Binder) configure(Binder)} call and ends just before the module {@link
|
|
||||||
* Module#configure(Binder) configure(Binder)} method invocation
|
|
||||||
*/
|
*/
|
||||||
ModuleSource(
|
ModuleSource(Class<?> moduleClass,
|
||||||
Class<?> moduleClass,
|
|
||||||
StackTraceElement[] partialCallStack,
|
|
||||||
BindingSourceRestriction.PermitMap permitMap) {
|
BindingSourceRestriction.PermitMap permitMap) {
|
||||||
this(null, moduleClass, partialCallStack, permitMap);
|
this(null, moduleClass, permitMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,20 +41,14 @@ final class ModuleSource {
|
||||||
*
|
*
|
||||||
* @param parent the parent module {@link ModuleSource source}
|
* @param parent the parent module {@link ModuleSource source}
|
||||||
* @param moduleClass the corresponding module
|
* @param moduleClass the corresponding module
|
||||||
* @param partialCallStack the chunk of call stack that starts from the parent module {@link
|
|
||||||
* Module#configure(Binder) configure(Binder)} call and ends just before the module {@link
|
|
||||||
* Module#configure(Binder) configure(Binder)} method invocation
|
|
||||||
*/
|
*/
|
||||||
private ModuleSource(
|
private ModuleSource(
|
||||||
ModuleSource parent,
|
ModuleSource parent,
|
||||||
Class<?> moduleClass,
|
Class<?> moduleClass,
|
||||||
StackTraceElement[] partialCallStack,
|
|
||||||
BindingSourceRestriction.PermitMap permitMap) {
|
BindingSourceRestriction.PermitMap permitMap) {
|
||||||
Preconditions.checkNotNull(moduleClass, "module cannot be null.");
|
Preconditions.checkNotNull(moduleClass, "module cannot be null.");
|
||||||
Preconditions.checkNotNull(partialCallStack, "partialCallStack cannot be null.");
|
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.moduleClassName = moduleClass.getName();
|
this.moduleClassName = moduleClass.getName();
|
||||||
this.partialCallStack = StackTraceElements.convertToInMemoryStackTraceElement(partialCallStack);
|
|
||||||
this.permitMap = permitMap;
|
this.permitMap = permitMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,31 +61,13 @@ final class ModuleSource {
|
||||||
return moduleClassName;
|
return moduleClassName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the chunk of call stack that starts from the parent module {@link
|
|
||||||
* Module#configure(Binder) configure(Binder)} call and ends just before the module {@link
|
|
||||||
* Module#configure(Binder) configure(Binder)} method invocation. The return array is non-empty
|
|
||||||
* only if stack trace collection is on.
|
|
||||||
*/
|
|
||||||
StackTraceElement[] getPartialCallStack() {
|
|
||||||
return StackTraceElements.convertToStackTraceElement(partialCallStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the size of partial call stack if stack trace collection is on otherwise zero. */
|
|
||||||
int getPartialCallStackSize() {
|
|
||||||
return partialCallStack.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a child {@link ModuleSource} corresponding to the {@link Module module}.
|
* Creates and returns a child {@link ModuleSource} corresponding to the {@link Module module}.
|
||||||
*
|
*
|
||||||
* @param moduleClass the corresponding module
|
* @param moduleClass the corresponding module
|
||||||
* @param partialCallStack the chunk of call stack that starts from the parent module {@link
|
|
||||||
* Module#configure(Binder) configure(Binder)} call and ends just before the module {@link
|
|
||||||
* Module#configure(Binder) configure(Binder)} method invocation
|
|
||||||
*/
|
*/
|
||||||
ModuleSource createChild(Class<?> moduleClass, StackTraceElement[] partialCallStack) {
|
ModuleSource createChild(Class<?> moduleClass) {
|
||||||
return new ModuleSource(this, moduleClass, partialCallStack, permitMap);
|
return new ModuleSource(this, moduleClass, permitMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the parent module {@link ModuleSource source}. */
|
/** Returns the parent module {@link ModuleSource source}. */
|
||||||
|
@ -142,38 +102,6 @@ final class ModuleSource {
|
||||||
return parent.size() + 1;
|
return parent.size() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the size of call stack that ends just before the module {@link Module#configure(Binder)
|
|
||||||
* configure(Binder)} method invocation (see {@link #getStackTrace()}).
|
|
||||||
*/
|
|
||||||
int getStackTraceSize() {
|
|
||||||
if (parent == null) {
|
|
||||||
return partialCallStack.length;
|
|
||||||
}
|
|
||||||
return parent.getStackTraceSize() + partialCallStack.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the full call stack that ends just before the module {@link Module#configure(Binder)
|
|
||||||
* configure(Binder)} method invocation. The return array is non-empty if stack trace collection
|
|
||||||
* on.
|
|
||||||
*/
|
|
||||||
StackTraceElement[] getStackTrace() {
|
|
||||||
int stackTraceSize = getStackTraceSize();
|
|
||||||
StackTraceElement[] callStack = new StackTraceElement[stackTraceSize];
|
|
||||||
int cursor = 0;
|
|
||||||
ModuleSource current = this;
|
|
||||||
while (current != null) {
|
|
||||||
StackTraceElement[] chunk =
|
|
||||||
StackTraceElements.convertToStackTraceElement(current.partialCallStack);
|
|
||||||
int chunkSize = chunk.length;
|
|
||||||
System.arraycopy(chunk, 0, callStack, cursor, chunkSize);
|
|
||||||
current = current.parent;
|
|
||||||
cursor = cursor + chunkSize;
|
|
||||||
}
|
|
||||||
return callStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the permit map created by the binder that installed this module. */
|
/** Returns the permit map created by the binder that installed this module. */
|
||||||
BindingSourceRestriction.PermitMap getPermitMap() {
|
BindingSourceRestriction.PermitMap getPermitMap() {
|
||||||
return permitMap;
|
return permitMap;
|
||||||
|
|
|
@ -124,9 +124,10 @@ public class BinderTest {
|
||||||
} catch (CreationException e) {
|
} catch (CreationException e) {
|
||||||
assertEquals(1, e.getErrorMessages().size());
|
assertEquals(1, e.getErrorMessages().size());
|
||||||
assertContains(e.getMessage(),
|
assertContains(e.getMessage(),
|
||||||
"No implementation for java.lang.Runnable was bound.",
|
"No implementation for Runnable was bound",
|
||||||
"for field at " + NeedsRunnable.class.getName(), ".runnable(",
|
"for field runnable",
|
||||||
"at " + getClass().getName(), getDeclaringSourcePart(getClass()));
|
"at BinderTest",
|
||||||
|
getDeclaringSourcePart(getClass()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +441,7 @@ public class BinderTest {
|
||||||
fail();
|
fail();
|
||||||
} catch (CreationException expected) {
|
} catch (CreationException expected) {
|
||||||
assertContains(expected.getMessage(),
|
assertContains(expected.getMessage(),
|
||||||
"1) Binding to Provider is not allowed.",
|
"Binding to Provider is not allowed",
|
||||||
"at " + BinderTest.class.getName(), getDeclaringSourcePart(getClass()));
|
"at " + BinderTest.class.getName(), getDeclaringSourcePart(getClass()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,11 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import com.google.inject.name.Named;
|
import com.google.inject.name.Named;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class BoundInstanceInjectionTest {
|
public class BoundInstanceInjectionTest {
|
||||||
|
|
||||||
|
@ -19,7 +20,10 @@ public class BoundInstanceInjectionTest {
|
||||||
public void testInstancesAreInjected() throws CreationException {
|
public void testInstancesAreInjected() throws CreationException {
|
||||||
final O o = new O();
|
final O o = new O();
|
||||||
|
|
||||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
Injector injector =
|
||||||
|
Guice.createInjector(
|
||||||
|
new AbstractModule() {
|
||||||
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(O.class).toInstance(o);
|
bind(O.class).toInstance(o);
|
||||||
bind(int.class).toInstance(5);
|
bind(int.class).toInstance(5);
|
||||||
|
@ -29,14 +33,28 @@ public class BoundInstanceInjectionTest {
|
||||||
assertEquals(5, o.fromMethod);
|
assertEquals(5, o.fromMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class O {
|
||||||
|
int fromMethod;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
void setInt(int i) {
|
||||||
|
this.fromMethod = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProvidersAreInjected() throws CreationException {
|
public void testProvidersAreInjected() throws CreationException {
|
||||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
Injector injector =
|
||||||
|
Guice.createInjector(
|
||||||
|
new AbstractModule() {
|
||||||
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(O.class).toProvider(new Provider<O>() {
|
bind(O.class)
|
||||||
@Inject
|
.toProvider(
|
||||||
int i;
|
new Provider<O>() {
|
||||||
|
@Inject int i;
|
||||||
|
|
||||||
|
@Override
|
||||||
public O get() {
|
public O get() {
|
||||||
O o = new O();
|
O o = new O();
|
||||||
o.setInt(i);
|
o.setInt(i);
|
||||||
|
@ -53,68 +71,61 @@ public class BoundInstanceInjectionTest {
|
||||||
@Test
|
@Test
|
||||||
public void testMalformedInstance() {
|
public void testMalformedInstance() {
|
||||||
try {
|
try {
|
||||||
Guice.createInjector(new AbstractModule() {
|
Guice.createInjector(
|
||||||
|
new AbstractModule() {
|
||||||
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(Object.class).toInstance(new MalformedInjectable());
|
bind(Object.class).toInstance(new MalformedInjectable());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fail();
|
fail();
|
||||||
} catch (CreationException expected) {
|
} catch (CreationException expected) {
|
||||||
// disabled because of double message
|
Logger.getAnonymousLogger().log(Level.INFO, expected.getMessage());
|
||||||
/*Asserts.assertContains(expected.getMessage(),
|
Asserts.assertContains(
|
||||||
MalformedInjectable.class.getName(),
|
expected.getMessage(),
|
||||||
".doublyAnnotated() has more than one ",
|
"BoundInstanceInjectionTest$MalformedInjectable.doublyAnnotated() has more than one ",
|
||||||
"annotation annotated with @BindingAnnotation: ",
|
"annotation annotated with @BindingAnnotation: ",
|
||||||
Named.class.getName() + " and " + Another.class.getName());*/
|
"Named and BoundInstanceInjectionTest$Another");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMalformedProvider() {
|
public void testMalformedProvider() {
|
||||||
try {
|
try {
|
||||||
Guice.createInjector(new AbstractModule() {
|
Guice.createInjector(
|
||||||
|
new AbstractModule() {
|
||||||
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(String.class).toProvider(new MalformedProvider());
|
bind(String.class).toProvider(new MalformedProvider());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fail();
|
fail();
|
||||||
} catch (CreationException expected) {
|
} catch (CreationException expected) {
|
||||||
Asserts.assertContains(expected.getMessage(),
|
Asserts.assertContains(
|
||||||
MalformedProvider.class.getName(),
|
expected.getMessage(),
|
||||||
".doublyAnnotated() has more than one ",
|
"BoundInstanceInjectionTest$MalformedProvider.doublyAnnotated() has more than one ",
|
||||||
"annotation annotated with @BindingAnnotation: ",
|
"annotation annotated with @BindingAnnotation: ",
|
||||||
Named.class.getName() + " and " + Another.class.getName());
|
"Named and BoundInstanceInjectionTest$Another");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MalformedInjectable {
|
||||||
|
@Inject
|
||||||
|
void doublyAnnotated(@Named("a") @Another String unused) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MalformedProvider implements Provider<String> {
|
||||||
|
@Inject
|
||||||
|
void doublyAnnotated(@Named("a") @Another String s) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get() {
|
||||||
|
return "a";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@BindingAnnotation
|
@BindingAnnotation
|
||||||
@Target({FIELD, PARAMETER, METHOD})
|
@Target({FIELD, PARAMETER, METHOD})
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
public @interface Another {
|
public @interface Another {}
|
||||||
}
|
|
||||||
|
|
||||||
static class O {
|
|
||||||
int fromMethod;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
void setInt(int i) {
|
|
||||||
this.fromMethod = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class MalformedInjectable {
|
|
||||||
@Inject
|
|
||||||
void doublyAnnotated(@Named("a") @Another String unused) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class MalformedProvider implements Provider<String> {
|
|
||||||
@Inject
|
|
||||||
void doublyAnnotated(@Named("a") @Another String s) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public String get() {
|
|
||||||
return "a";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,6 +184,7 @@ public class CircularDependencyTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testDisabledCircularDependency() {
|
public void testDisabledCircularDependency() {
|
||||||
try {
|
try {
|
||||||
Guice.createInjector(
|
Guice.createInjector(
|
||||||
|
|
|
@ -2,9 +2,9 @@ package com.google.inject.internal;
|
||||||
|
|
||||||
import static com.google.inject.Asserts.awaitClear;
|
import static com.google.inject.Asserts.awaitClear;
|
||||||
import static com.google.inject.Asserts.awaitFullGc;
|
import static com.google.inject.Asserts.awaitFullGc;
|
||||||
import static com.google.inject.internal.WeakKeySetUtils.assertBlacklisted;
|
import static com.google.inject.internal.WeakKeySetUtils.assertBanned;
|
||||||
import static com.google.inject.internal.WeakKeySetUtils.assertInSet;
|
import static com.google.inject.internal.WeakKeySetUtils.assertInSet;
|
||||||
import static com.google.inject.internal.WeakKeySetUtils.assertNotBlacklisted;
|
import static com.google.inject.internal.WeakKeySetUtils.assertNotBanned;
|
||||||
import static com.google.inject.internal.WeakKeySetUtils.assertNotInSet;
|
import static com.google.inject.internal.WeakKeySetUtils.assertNotInSet;
|
||||||
import static com.google.inject.internal.WeakKeySetUtils.assertSourceNotInSet;
|
import static com.google.inject.internal.WeakKeySetUtils.assertSourceNotInSet;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -28,18 +28,18 @@ import com.google.inject.spi.ScopeBinding;
|
||||||
import com.google.inject.spi.StaticInjectionRequest;
|
import com.google.inject.spi.StaticInjectionRequest;
|
||||||
import com.google.inject.spi.TypeConverterBinding;
|
import com.google.inject.spi.TypeConverterBinding;
|
||||||
import com.google.inject.spi.TypeListenerBinding;
|
import com.google.inject.spi.TypeListenerBinding;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link WeakKeySet}.
|
* Tests for {@link WeakKeySet}.
|
||||||
* <p>
|
*
|
||||||
* Multibinding specific tests can be found in MultibinderTest and MapBinderTest.
|
* Multibinding specific tests can be found in MultibinderTest and MapBinderTest.
|
||||||
*/
|
*/
|
||||||
public class WeakKeySetTest {
|
public class WeakKeySetTest {
|
||||||
|
@ -47,22 +47,22 @@ public class WeakKeySetTest {
|
||||||
private WeakKeySet set;
|
private WeakKeySet set;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
set = new WeakKeySet(new Object());
|
set = new WeakKeySet(new Object());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEviction() {
|
public void testEviction() {
|
||||||
TestState state = new TestState();
|
TestInjectorBindingData bindingData = new TestInjectorBindingData();
|
||||||
Key<Integer> key = Key.get(Integer.class);
|
Key<Integer> key = Key.get(Integer.class);
|
||||||
Object source = new Object();
|
Object source = new Object();
|
||||||
|
|
||||||
WeakReference<Key<Integer>> weakKeyRef = new WeakReference<Key<Integer>>(key);
|
WeakReference<Key<Integer>> weakKeyRef = new WeakReference<>(key);
|
||||||
|
|
||||||
set.add(key, state, source);
|
set.add(key, bindingData, source);
|
||||||
assertInSet(set, key, 1, source);
|
assertInSet(set, key, 1, source);
|
||||||
|
|
||||||
state = null;
|
bindingData = null;
|
||||||
|
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
|
|
||||||
|
@ -75,16 +75,16 @@ public class WeakKeySetTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEviction_nullSource() {
|
public void testEviction_nullSource() {
|
||||||
TestState state = new TestState();
|
TestInjectorBindingData bindingData = new TestInjectorBindingData();
|
||||||
Key<Integer> key = Key.get(Integer.class);
|
Key<Integer> key = Key.get(Integer.class);
|
||||||
Object source = null;
|
Object source = null;
|
||||||
|
|
||||||
WeakReference<Key<Integer>> weakKeyRef = new WeakReference<Key<Integer>>(key);
|
WeakReference<Key<Integer>> weakKeyRef = new WeakReference<>(key);
|
||||||
|
|
||||||
set.add(key, state, source);
|
set.add(key, bindingData, source);
|
||||||
assertInSet(set, key, 1, source);
|
assertInSet(set, key, 1, source);
|
||||||
|
|
||||||
state = null;
|
bindingData = null;
|
||||||
|
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
|
|
||||||
|
@ -97,42 +97,43 @@ public class WeakKeySetTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEviction_keyOverlap_2x() {
|
public void testEviction_keyOverlap_2x() {
|
||||||
TestState state1 = new TestState();
|
TestInjectorBindingData bindingData1 = new TestInjectorBindingData();
|
||||||
TestState state2 = new TestState();
|
TestInjectorBindingData bindingData2 = new TestInjectorBindingData();
|
||||||
Key<Integer> key1 = Key.get(Integer.class);
|
Key<Integer> key1 = Key.get(Integer.class);
|
||||||
Key<Integer> key2 = Key.get(Integer.class);
|
Key<Integer> key2 = Key.get(Integer.class);
|
||||||
Object source1 = new Object();
|
Object source1 = new Object();
|
||||||
Object source2 = new Object();
|
Object source2 = new Object();
|
||||||
|
|
||||||
set.add(key1, state1, source1);
|
set.add(key1, bindingData1, source1);
|
||||||
assertInSet(set, key1, 1, source1);
|
assertInSet(set, key1, 1, source1);
|
||||||
|
|
||||||
set.add(key2, state2, source2);
|
set.add(key2, bindingData2, source2);
|
||||||
assertInSet(set, key2, 2, source1, source2);
|
assertInSet(set, key2, 2, source1, source2);
|
||||||
|
|
||||||
WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
|
WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<>(key1);
|
||||||
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
|
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<>(key2);
|
||||||
WeakReference<Object> weakSource1Ref = new WeakReference<Object>(source1);
|
WeakReference<Object> weakSource1Ref = new WeakReference<>(source1);
|
||||||
WeakReference<Object> weakSource2Ref = new WeakReference<Object>(source2);
|
WeakReference<Object> weakSource2Ref = new WeakReference<>(source2);
|
||||||
|
|
||||||
Key<Integer> key = key1 = key2 = Key.get(Integer.class);
|
Key<Integer> key = key1 = key2 = Key.get(Integer.class);
|
||||||
state1 = null;
|
bindingData1 = null;
|
||||||
|
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
|
|
||||||
assertSourceNotInSet(set, key, source1);
|
assertSourceNotInSet(set, key, source1);
|
||||||
assertInSet(set, key, 1, source2);
|
assertInSet(set, key, 1, source2);
|
||||||
|
|
||||||
source1 = source2 = null;
|
// Clear source1 and source2 fields so the objects can be GCed.
|
||||||
|
Object unused = source1 = source2 = null;
|
||||||
|
|
||||||
awaitClear(weakSource1Ref);
|
awaitClear(weakSource1Ref);
|
||||||
// Key1 will be referenced as the key in the sources backingSet and won't be
|
// Key1 will be referenced as the key in the sources backingSet and won't be
|
||||||
// GC'd.
|
// GC'd.
|
||||||
|
|
||||||
// Should not be GC'd until state2 goes away.
|
// Should not be GC'd until bindingData2 goes away.
|
||||||
assertNotNull(weakSource2Ref.get());
|
assertNotNull(weakSource2Ref.get());
|
||||||
|
|
||||||
state2 = null;
|
bindingData2 = null;
|
||||||
|
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
|
|
||||||
|
@ -146,28 +147,29 @@ public class WeakKeySetTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoEviction_keyOverlap_2x() {
|
public void testNoEviction_keyOverlap_2x() {
|
||||||
TestState state1 = new TestState();
|
TestInjectorBindingData bindingData1 = new TestInjectorBindingData();
|
||||||
TestState state2 = new TestState();
|
TestInjectorBindingData bindingData2 = new TestInjectorBindingData();
|
||||||
Key<Integer> key1 = Key.get(Integer.class);
|
Key<Integer> key1 = Key.get(Integer.class);
|
||||||
Key<Integer> key2 = Key.get(Integer.class);
|
Key<Integer> key2 = Key.get(Integer.class);
|
||||||
Object source1 = new Object();
|
Object source1 = new Object();
|
||||||
Object source2 = new Object();
|
Object source2 = new Object();
|
||||||
|
|
||||||
set.add(key1, state1, source1);
|
set.add(key1, bindingData1, source1);
|
||||||
assertInSet(set, key1, 1, source1);
|
assertInSet(set, key1, 1, source1);
|
||||||
|
|
||||||
set.add(key2, state2, source2);
|
set.add(key2, bindingData2, source2);
|
||||||
assertInSet(set, key2, 2, source1, source2);
|
assertInSet(set, key2, 2, source1, source2);
|
||||||
|
|
||||||
WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
|
WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<>(key1);
|
||||||
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
|
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<>(key2);
|
||||||
|
|
||||||
Key<Integer> key = key1 = key2 = Key.get(Integer.class);
|
Key<Integer> key = key1 = key2 = Key.get(Integer.class);
|
||||||
|
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
assertInSet(set, key, 2, source1, source2);
|
assertInSet(set, key, 2, source1, source2);
|
||||||
|
|
||||||
// Ensure the keys don't get GC'd when states are still referenced. key1 will be present in the
|
// Ensure the keys don't get GC'd when InjectorBindingData objects are still referenced. key1
|
||||||
|
// will be present in the
|
||||||
// as the map key but key2 could be GC'd if the implementation does something wrong.
|
// as the map key but key2 could be GC'd if the implementation does something wrong.
|
||||||
assertNotNull(weakKey1Ref.get());
|
assertNotNull(weakKey1Ref.get());
|
||||||
assertNotNull(weakKey2Ref.get());
|
assertNotNull(weakKey2Ref.get());
|
||||||
|
@ -175,26 +177,26 @@ public class WeakKeySetTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEviction_keyAndSourceOverlap_null() {
|
public void testEviction_keyAndSourceOverlap_null() {
|
||||||
TestState state1 = new TestState();
|
TestInjectorBindingData bindingData1 = new TestInjectorBindingData();
|
||||||
TestState state2 = new TestState();
|
TestInjectorBindingData bindingData2 = new TestInjectorBindingData();
|
||||||
Key<Integer> key1 = Key.get(Integer.class);
|
Key<Integer> key1 = Key.get(Integer.class);
|
||||||
Key<Integer> key2 = Key.get(Integer.class);
|
Key<Integer> key2 = Key.get(Integer.class);
|
||||||
Object source = null;
|
Object source = null;
|
||||||
|
|
||||||
set.add(key1, state1, source);
|
set.add(key1, bindingData1, source);
|
||||||
assertInSet(set, key1, 1, source);
|
assertInSet(set, key1, 1, source);
|
||||||
|
|
||||||
set.add(key2, state2, source);
|
set.add(key2, bindingData2, source);
|
||||||
// Same source so still only one value.
|
// Same source so still only one value.
|
||||||
assertInSet(set, key2, 1, source);
|
assertInSet(set, key2, 1, source);
|
||||||
assertInSet(set, key1, 1, source);
|
assertInSet(set, key1, 1, source);
|
||||||
|
|
||||||
WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
|
WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<>(key1);
|
||||||
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
|
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<>(key2);
|
||||||
WeakReference<Object> weakSourceRef = new WeakReference<Object>(source);
|
WeakReference<Object> weakSourceRef = new WeakReference<>(source);
|
||||||
|
|
||||||
Key<Integer> key = key1 = key2 = Key.get(Integer.class);
|
Key<Integer> key = key1 = key2 = Key.get(Integer.class);
|
||||||
state1 = null;
|
bindingData1 = null;
|
||||||
|
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
// Should still have a single source.
|
// Should still have a single source.
|
||||||
|
@ -206,7 +208,7 @@ public class WeakKeySetTest {
|
||||||
// Key1 will be referenced as the key in the sources backingSet and won't be
|
// Key1 will be referenced as the key in the sources backingSet and won't be
|
||||||
// GC'd.
|
// GC'd.
|
||||||
|
|
||||||
state2 = null;
|
bindingData2 = null;
|
||||||
|
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
assertNotInSet(set, key);
|
assertNotInSet(set, key);
|
||||||
|
@ -219,25 +221,25 @@ public class WeakKeySetTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEviction_keyAndSourceOverlap_nonNull() {
|
public void testEviction_keyAndSourceOverlap_nonNull() {
|
||||||
TestState state1 = new TestState();
|
TestInjectorBindingData bindingData1 = new TestInjectorBindingData();
|
||||||
TestState state2 = new TestState();
|
TestInjectorBindingData bindingData2 = new TestInjectorBindingData();
|
||||||
Key<Integer> key1 = Key.get(Integer.class);
|
Key<Integer> key1 = Key.get(Integer.class);
|
||||||
Key<Integer> key2 = Key.get(Integer.class);
|
Key<Integer> key2 = Key.get(Integer.class);
|
||||||
Object source = new Object();
|
Object source = new Object();
|
||||||
|
|
||||||
set.add(key1, state1, source);
|
set.add(key1, bindingData1, source);
|
||||||
assertInSet(set, key1, 1, source);
|
assertInSet(set, key1, 1, source);
|
||||||
|
|
||||||
set.add(key2, state2, source);
|
set.add(key2, bindingData2, source);
|
||||||
// Same source so still only one value.
|
// Same source so still only one value.
|
||||||
assertInSet(set, key2, 1, source);
|
assertInSet(set, key2, 1, source);
|
||||||
|
|
||||||
WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
|
WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<>(key1);
|
||||||
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
|
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<>(key2);
|
||||||
WeakReference<Object> weakSourceRef = new WeakReference<Object>(source);
|
WeakReference<Object> weakSourceRef = new WeakReference<>(source);
|
||||||
|
|
||||||
Key<Integer> key = key1 = key2 = Key.get(Integer.class);
|
Key<Integer> key = key1 = key2 = Key.get(Integer.class);
|
||||||
state1 = null;
|
bindingData1 = null;
|
||||||
|
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
|
|
||||||
|
@ -252,7 +254,7 @@ public class WeakKeySetTest {
|
||||||
// Key1 will be referenced as the key in the sources backingSet and won't be
|
// Key1 will be referenced as the key in the sources backingSet and won't be
|
||||||
// GC'd.
|
// GC'd.
|
||||||
|
|
||||||
state2 = null;
|
bindingData2 = null;
|
||||||
|
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
|
|
||||||
|
@ -266,9 +268,9 @@ public class WeakKeySetTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEviction_keyOverlap_3x() {
|
public void testEviction_keyOverlap_3x() {
|
||||||
TestState state1 = new TestState();
|
TestInjectorBindingData bindingData1 = new TestInjectorBindingData();
|
||||||
TestState state2 = new TestState();
|
TestInjectorBindingData bindingData2 = new TestInjectorBindingData();
|
||||||
TestState state3 = new TestState();
|
TestInjectorBindingData bindingData3 = new TestInjectorBindingData();
|
||||||
Key<Integer> key1 = Key.get(Integer.class);
|
Key<Integer> key1 = Key.get(Integer.class);
|
||||||
Key<Integer> key2 = Key.get(Integer.class);
|
Key<Integer> key2 = Key.get(Integer.class);
|
||||||
Key<Integer> key3 = Key.get(Integer.class);
|
Key<Integer> key3 = Key.get(Integer.class);
|
||||||
|
@ -276,24 +278,24 @@ public class WeakKeySetTest {
|
||||||
Object source2 = new Object();
|
Object source2 = new Object();
|
||||||
Object source3 = new Object();
|
Object source3 = new Object();
|
||||||
|
|
||||||
set.add(key1, state1, source1);
|
set.add(key1, bindingData1, source1);
|
||||||
assertInSet(set, key1, 1, source1);
|
assertInSet(set, key1, 1, source1);
|
||||||
|
|
||||||
set.add(key2, state2, source2);
|
set.add(key2, bindingData2, source2);
|
||||||
assertInSet(set, key1, 2, source1, source2);
|
assertInSet(set, key1, 2, source1, source2);
|
||||||
|
|
||||||
set.add(key3, state3, source3);
|
set.add(key3, bindingData3, source3);
|
||||||
assertInSet(set, key1, 3, source1, source2, source3);
|
assertInSet(set, key1, 3, source1, source2, source3);
|
||||||
|
|
||||||
WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<Key<Integer>>(key1);
|
WeakReference<Key<Integer>> weakKey1Ref = new WeakReference<>(key1);
|
||||||
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<Key<Integer>>(key2);
|
WeakReference<Key<Integer>> weakKey2Ref = new WeakReference<>(key2);
|
||||||
WeakReference<Key<Integer>> weakKey3Ref = new WeakReference<Key<Integer>>(key3);
|
WeakReference<Key<Integer>> weakKey3Ref = new WeakReference<>(key3);
|
||||||
WeakReference<Object> weakSource1Ref = new WeakReference<Object>(source1);
|
WeakReference<Object> weakSource1Ref = new WeakReference<>(source1);
|
||||||
WeakReference<Object> weakSource2Ref = new WeakReference<Object>(source2);
|
WeakReference<Object> weakSource2Ref = new WeakReference<>(source2);
|
||||||
WeakReference<Object> weakSource3Ref = new WeakReference<Object>(source3);
|
WeakReference<Object> weakSource3Ref = new WeakReference<>(source3);
|
||||||
|
|
||||||
Key<Integer> key = key1 = key2 = key3 = Key.get(Integer.class);
|
Key<Integer> key = key1 = key2 = key3 = Key.get(Integer.class);
|
||||||
state1 = null;
|
bindingData1 = null;
|
||||||
|
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
assertSourceNotInSet(set, key, source1);
|
assertSourceNotInSet(set, key, source1);
|
||||||
|
@ -304,7 +306,7 @@ public class WeakKeySetTest {
|
||||||
// GC'd.
|
// GC'd.
|
||||||
awaitClear(weakSource1Ref);
|
awaitClear(weakSource1Ref);
|
||||||
|
|
||||||
state2 = null;
|
bindingData2 = null;
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
assertSourceNotInSet(set, key, source2);
|
assertSourceNotInSet(set, key, source2);
|
||||||
assertInSet(set, key, 1, source3);
|
assertInSet(set, key, 1, source3);
|
||||||
|
@ -316,7 +318,7 @@ public class WeakKeySetTest {
|
||||||
// Key1 will be referenced as the key in the sources backingSet and won't be
|
// Key1 will be referenced as the key in the sources backingSet and won't be
|
||||||
// GC'd.
|
// GC'd.
|
||||||
|
|
||||||
state3 = null;
|
bindingData3 = null;
|
||||||
awaitFullGc();
|
awaitFullGc();
|
||||||
assertNotInSet(set, key);
|
assertNotInSet(set, key);
|
||||||
|
|
||||||
|
@ -329,125 +331,148 @@ public class WeakKeySetTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWeakKeySet_integration() {
|
public void testWeakKeySet_integration() {
|
||||||
Injector parentInjector = Guice.createInjector(new AbstractModule() {
|
Injector parentInjector =
|
||||||
|
Guice.createInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(Integer.class).toInstance(4);
|
bind(Integer.class).toInstance(4);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertNotBlacklisted(parentInjector, Key.get(String.class));
|
assertNotBanned(parentInjector, Key.get(String.class));
|
||||||
|
|
||||||
Injector childInjector = parentInjector.createChildInjector(new AbstractModule() {
|
Injector childInjector =
|
||||||
|
parentInjector.createChildInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(String.class).toInstance("bar");
|
bind(String.class).toInstance("bar");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
WeakReference<Injector> weakRef = new WeakReference<Injector>(childInjector);
|
WeakReference<Injector> weakRef = new WeakReference<>(childInjector);
|
||||||
assertBlacklisted(parentInjector, Key.get(String.class));
|
assertBanned(parentInjector, Key.get(String.class));
|
||||||
|
|
||||||
// Clear the ref, GC, and ensure that we are no longer blacklisting.
|
// Clear the ref, GC, and ensure that we are no longer banning.
|
||||||
childInjector = null;
|
childInjector = null;
|
||||||
awaitClear(weakRef);
|
awaitClear(weakRef);
|
||||||
assertNotBlacklisted(parentInjector, Key.get(String.class));
|
assertNotBanned(parentInjector, Key.get(String.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWeakKeySet_integration_multipleChildren() {
|
public void testWeakKeySet_integration_multipleChildren() {
|
||||||
Injector parentInjector = Guice.createInjector(new AbstractModule() {
|
Injector parentInjector =
|
||||||
|
Guice.createInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(Integer.class).toInstance(4);
|
bind(Integer.class).toInstance(4);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertNotBlacklisted(parentInjector, Key.get(String.class));
|
assertNotBanned(parentInjector, Key.get(String.class));
|
||||||
assertNotBlacklisted(parentInjector, Key.get(Long.class));
|
assertNotBanned(parentInjector, Key.get(Long.class));
|
||||||
|
|
||||||
Injector childInjector1 = parentInjector.createChildInjector(new AbstractModule() {
|
Injector childInjector1 =
|
||||||
|
parentInjector.createChildInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(String.class).toInstance("foo");
|
bind(String.class).toInstance("foo");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
WeakReference<Injector> weakRef1 = new WeakReference<Injector>(childInjector1);
|
WeakReference<Injector> weakRef1 = new WeakReference<>(childInjector1);
|
||||||
assertBlacklisted(parentInjector, Key.get(String.class));
|
assertBanned(parentInjector, Key.get(String.class));
|
||||||
assertNotBlacklisted(parentInjector, Key.get(Long.class));
|
assertNotBanned(parentInjector, Key.get(Long.class));
|
||||||
|
|
||||||
Injector childInjector2 = parentInjector.createChildInjector(new AbstractModule() {
|
Injector childInjector2 =
|
||||||
|
parentInjector.createChildInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(Long.class).toInstance(6L);
|
bind(Long.class).toInstance(6L);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
WeakReference<Injector> weakRef2 = new WeakReference<Injector>(childInjector2);
|
WeakReference<Injector> weakRef2 = new WeakReference<>(childInjector2);
|
||||||
assertBlacklisted(parentInjector, Key.get(String.class));
|
assertBanned(parentInjector, Key.get(String.class));
|
||||||
assertBlacklisted(parentInjector, Key.get(Long.class));
|
assertBanned(parentInjector, Key.get(Long.class));
|
||||||
|
|
||||||
// Clear ref1, GC, and ensure that we still blacklist.
|
// Clear ref1, GC, and ensure that we still ban.
|
||||||
childInjector1 = null;
|
childInjector1 = null;
|
||||||
awaitClear(weakRef1);
|
awaitClear(weakRef1);
|
||||||
assertNotBlacklisted(parentInjector, Key.get(String.class));
|
assertNotBanned(parentInjector, Key.get(String.class));
|
||||||
assertBlacklisted(parentInjector, Key.get(Long.class));
|
assertBanned(parentInjector, Key.get(Long.class));
|
||||||
|
|
||||||
// Clear the ref, GC, and ensure that we are no longer blacklisting.
|
// Clear the ref, GC, and ensure that we are no longer banning.
|
||||||
childInjector2 = null;
|
childInjector2 = null;
|
||||||
awaitClear(weakRef2);
|
awaitClear(weakRef2);
|
||||||
assertNotBlacklisted(parentInjector, Key.get(String.class));
|
assertNotBanned(parentInjector, Key.get(String.class));
|
||||||
assertNotBlacklisted(parentInjector, Key.get(Long.class));
|
assertNotBanned(parentInjector, Key.get(Long.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWeakKeySet_integration_multipleChildren_overlappingKeys() {
|
public void testWeakKeySet_integration_multipleChildren_overlappingKeys() {
|
||||||
Injector parentInjector = Guice.createInjector(new AbstractModule() {
|
Injector parentInjector =
|
||||||
|
Guice.createInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(Integer.class).toInstance(4);
|
bind(Integer.class).toInstance(4);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertNotBlacklisted(parentInjector, Key.get(String.class));
|
assertNotBanned(parentInjector, Key.get(String.class));
|
||||||
|
|
||||||
Injector childInjector1 = parentInjector.createChildInjector(new AbstractModule() {
|
Injector childInjector1 =
|
||||||
|
parentInjector.createChildInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(String.class).toInstance("foo");
|
bind(String.class).toInstance("foo");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
WeakReference<Injector> weakRef1 = new WeakReference<Injector>(childInjector1);
|
WeakReference<Injector> weakRef1 = new WeakReference<>(childInjector1);
|
||||||
assertBlacklisted(parentInjector, Key.get(String.class));
|
assertBanned(parentInjector, Key.get(String.class));
|
||||||
|
|
||||||
Injector childInjector2 = parentInjector.createChildInjector(new AbstractModule() {
|
Injector childInjector2 =
|
||||||
|
parentInjector.createChildInjector(
|
||||||
|
new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(String.class).toInstance("bar");
|
bind(String.class).toInstance("bar");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
WeakReference<Injector> weakRef2 = new WeakReference<Injector>(childInjector2);
|
WeakReference<Injector> weakRef2 = new WeakReference<>(childInjector2);
|
||||||
assertBlacklisted(parentInjector, Key.get(String.class));
|
assertBanned(parentInjector, Key.get(String.class));
|
||||||
|
|
||||||
// Clear ref1, GC, and ensure that we still blacklist.
|
// Clear ref1, GC, and ensure that we still ban.
|
||||||
childInjector1 = null;
|
childInjector1 = null;
|
||||||
awaitClear(weakRef1);
|
awaitClear(weakRef1);
|
||||||
assertBlacklisted(parentInjector, Key.get(String.class));
|
assertBanned(parentInjector, Key.get(String.class));
|
||||||
|
|
||||||
// Clear the ref, GC, and ensure that we are no longer blacklisting.
|
// Clear the ref, GC, and ensure that we are no longer banning.
|
||||||
childInjector2 = null;
|
childInjector2 = null;
|
||||||
awaitClear(weakRef2);
|
awaitClear(weakRef2);
|
||||||
assertNotBlacklisted(parentInjector, Key.get(String.class));
|
assertNotBanned(parentInjector, Key.get(String.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TestState implements State {
|
private static class TestInjectorBindingData extends InjectorBindingData {
|
||||||
public State parent() {
|
TestInjectorBindingData() {
|
||||||
return new TestState();
|
super(Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<InjectorBindingData> parent() {
|
||||||
|
return Optional.of(new TestInjectorBindingData());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public <T> BindingImpl<T> getExplicitBinding(Key<T> key) {
|
public <T> BindingImpl<T> getExplicitBinding(Key<T> key) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Map<Key<?>, Binding<?>> getExplicitBindingsThisLevel() {
|
public Map<Key<?>, Binding<?>> getExplicitBindingsThisLevel() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void putBinding(Key<?> key, BindingImpl<?> binding) {
|
public void putBinding(Key<?> key, BindingImpl<?> binding) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
@ -492,66 +517,63 @@ public class WeakKeySetTest {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation) {
|
public ScopeBinding getScopeBinding(Class<? extends Annotation> scopingAnnotation) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) {
|
public void putScopeBinding(Class<? extends Annotation> annotationType, ScopeBinding scope) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addConverter(TypeConverterBinding typeConverterBinding) {
|
public void addConverter(TypeConverterBinding typeConverterBinding) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeConverterBinding getConverter(String stringValue, TypeLiteral<?> type, Errors errors,
|
@Override
|
||||||
Object source) {
|
public TypeConverterBinding getConverter(
|
||||||
|
String stringValue, TypeLiteral<?> type, Errors errors, Object source) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Iterable<TypeConverterBinding> getConvertersThisLevel() {
|
public Iterable<TypeConverterBinding> getConvertersThisLevel() {
|
||||||
return ImmutableSet.of();
|
return ImmutableSet.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addTypeListener(TypeListenerBinding typeListenerBinding) {
|
public void addTypeListener(TypeListenerBinding typeListenerBinding) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TypeListenerBinding> getTypeListenerBindings() {
|
@Override
|
||||||
|
public ImmutableList<TypeListenerBinding> getTypeListenerBindings() {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addProvisionListener(ProvisionListenerBinding provisionListenerBinding) {
|
public void addProvisionListener(ProvisionListenerBinding provisionListenerBinding) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ProvisionListenerBinding> getProvisionListenerBindings() {
|
@Override
|
||||||
|
public ImmutableList<ProvisionListenerBinding> getProvisionListenerBindings() {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addScanner(ModuleAnnotatedMethodScannerBinding scanner) {
|
public void addScanner(ModuleAnnotatedMethodScannerBinding scanner) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ModuleAnnotatedMethodScannerBinding> getScannerBindings() {
|
@Override
|
||||||
|
public ImmutableList<ModuleAnnotatedMethodScannerBinding> getScannerBindings() {
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void blacklist(Key<?> key, State state, Object source) {
|
@Override
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isBlacklisted(Key<?> key) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Object> getSourcesForBlacklistedKey(Key<?> key) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object lock() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Class<? extends Annotation>, Scope> getScopes() {
|
public Map<Class<? extends Annotation>, Scope> getScopes() {
|
||||||
return ImmutableMap.of();
|
return ImmutableMap.of();
|
||||||
}
|
}
|
||||||
|
@ -562,17 +584,17 @@ public class WeakKeySetTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TypeListenerBinding> getTypeListenerBindingsThisLevel() {
|
public ImmutableList<TypeListenerBinding> getTypeListenerBindingsThisLevel() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProvisionListenerBinding> getProvisionListenerBindingsThisLevel() {
|
public ImmutableList<ProvisionListenerBinding> getProvisionListenerBindingsThisLevel() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ModuleAnnotatedMethodScannerBinding> getScannerBindingsThisLevel() {
|
public ImmutableList<ModuleAnnotatedMethodScannerBinding> getScannerBindingsThisLevel() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
package com.google.inject.internal;
|
package com.google.inject.internal;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,15 +15,14 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public final class WeakKeySetUtils {
|
public final class WeakKeySetUtils {
|
||||||
|
|
||||||
private WeakKeySetUtils() {
|
private WeakKeySetUtils() {}
|
||||||
|
|
||||||
|
public static void assertBanned(Injector injector, Key<?> key) {
|
||||||
|
assertBannedState(injector, key, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertBlacklisted(Injector injector, Key<?> key) {
|
public static void assertNotBanned(Injector injector, Key<?> key) {
|
||||||
assertBlacklistState(injector, key, true);
|
assertBannedState(injector, key, false);
|
||||||
}
|
|
||||||
|
|
||||||
public static void assertNotBlacklisted(Injector injector, Key<?> key) {
|
|
||||||
assertBlacklistState(injector, key, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertNotInSet(WeakKeySet set, Key<?> key) {
|
public static void assertNotInSet(WeakKeySet set, Key<?> key) {
|
||||||
|
@ -39,8 +37,8 @@ public final class WeakKeySetUtils {
|
||||||
assertNull(set.getSources(Key.get(Integer.class)));
|
assertNull(set.getSources(Key.get(Integer.class)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void assertInSet(WeakKeySet set, Key<?> key, int expectedSources,
|
public static void assertInSet(
|
||||||
Object... sources) {
|
WeakKeySet set, Key<?> key, int expectedSources, Object... sources) {
|
||||||
assertTrue(set.contains(key));
|
assertTrue(set.contains(key));
|
||||||
assertEquals(expectedSources, set.getSources(key).size());
|
assertEquals(expectedSources, set.getSources(key).size());
|
||||||
for (Object source : sources) {
|
for (Object source : sources) {
|
||||||
|
@ -63,17 +61,17 @@ public final class WeakKeySetUtils {
|
||||||
assertFalse(sources.contains(source));
|
assertFalse(sources.contains(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertBlacklistState(Injector injector, Key<?> key, boolean isBlacklisted) {
|
private static void assertBannedState(Injector injector, Key<?> key, boolean isBanned) {
|
||||||
// if we're expecting it to not be blacklisted, loop around and wait for threads to run.
|
// if we're expecting it to not be banned, loop around and wait for threads to run.
|
||||||
if (!isBlacklisted) {
|
if (!isBanned) {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
if (!((InjectorImpl) injector).state.isBlacklisted(key)) {
|
if (!((InjectorImpl) injector).getJitBindingData().isBannedKey(key)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sleep();
|
sleep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertEquals(isBlacklisted, ((InjectorImpl) injector).state.isBlacklisted(key));
|
assertEquals(isBanned, ((InjectorImpl) injector).getJitBindingData().isBannedKey(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sleep() {
|
private static void sleep() {
|
||||||
|
@ -82,6 +80,5 @@ public final class WeakKeySetUtils {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
Thread.yield();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import com.google.inject.Guice;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
@ -19,11 +19,11 @@ public class NamesTest {
|
||||||
|
|
||||||
@Named("foo")
|
@Named("foo")
|
||||||
private String foo;
|
private String foo;
|
||||||
private static Named namedFoo;
|
private Named namedFoo;
|
||||||
|
|
||||||
@BeforeClass
|
@Before
|
||||||
public static void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
namedFoo = NamesTest.class.getDeclaredField("foo").getAnnotation(Named.class);
|
namedFoo = getClass().getDeclaredField("foo").getAnnotation(Named.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,49 +1,30 @@
|
||||||
package com.google.inject.spi;
|
package com.google.inject.spi;
|
||||||
|
|
||||||
import static com.google.inject.internal.InternalFlags.getIncludeStackTraceOption;
|
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Binder;
|
import com.google.inject.Binder;
|
||||||
import com.google.inject.Binding;
|
import com.google.inject.Binding;
|
||||||
import com.google.inject.BindingAnnotation;
|
import com.google.inject.BindingAnnotation;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/** Tests for {@link ElementSource}. */
|
||||||
* Tests for {@link ElementSource}.
|
public class ElementSourceTest extends TestCase {
|
||||||
*/
|
|
||||||
public class ElementSourceTest {
|
|
||||||
|
|
||||||
private static final StackTraceElement BINDER_INSTALL =
|
private static final StackTraceElement BINDER_INSTALL =
|
||||||
new StackTraceElement("com.google.inject.spi.Elements$RecordingBinder", "install",
|
new StackTraceElement(
|
||||||
"Unknown Source", 234 /* line number*/);
|
"com.google.inject.spi.Elements$RecordingBinder",
|
||||||
|
"install",
|
||||||
|
"Unknown Source",
|
||||||
|
234 /* line number*/);
|
||||||
|
|
||||||
@Test
|
public void testGetCallStack_IntegrationTest() throws Exception {
|
||||||
public void testCallStackSize() {
|
|
||||||
ModuleSource moduleSource = createModuleSource();
|
|
||||||
StackTraceElement[] bindingCallStack = new StackTraceElement[3];
|
|
||||||
bindingCallStack[0] = new StackTraceElement(
|
|
||||||
"com.google.inject.spi.Elements$RecordingBinder", "bind", "Unknown Source", 200);
|
|
||||||
bindingCallStack[1] = new StackTraceElement(
|
|
||||||
"com.google.inject.spi.Elements$RecordingBinder", "bind", "Unknown Source", 100);
|
|
||||||
bindingCallStack[2] = new StackTraceElement(
|
|
||||||
"com.google.inject.spi.moduleSourceTest$C", "configure", "Unknown Source", 100);
|
|
||||||
ElementSource elementSource = new ElementSource(
|
|
||||||
null /* No original element source */, "" /* Don't care */, moduleSource, bindingCallStack);
|
|
||||||
assertEquals(10 /* call stack size */, elementSource.getStackTrace().length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetCallStack_IntegrationTest() {
|
|
||||||
List<Element> elements = Elements.getElements(new A());
|
List<Element> elements = Elements.getElements(new A());
|
||||||
for (Element element : elements) {
|
for (Element element : elements) {
|
||||||
if (element instanceof Binding) {
|
if (element instanceof Binding) {
|
||||||
|
@ -59,70 +40,7 @@ public class ElementSourceTest {
|
||||||
assertEquals("com.google.inject.spi.ElementSourceTest$B", moduleClassNames.get(1));
|
assertEquals("com.google.inject.spi.ElementSourceTest$B", moduleClassNames.get(1));
|
||||||
// Module A
|
// Module A
|
||||||
assertEquals("com.google.inject.spi.ElementSourceTest$A", moduleClassNames.get(2));
|
assertEquals("com.google.inject.spi.ElementSourceTest$A", moduleClassNames.get(2));
|
||||||
StackTraceElement[] callStack = elementSource.getStackTrace();
|
|
||||||
switch (getIncludeStackTraceOption()) {
|
|
||||||
case OFF:
|
|
||||||
// Check declaring source
|
|
||||||
StackTraceElement stackTraceElement =
|
|
||||||
(StackTraceElement) elementSource.getDeclaringSource();
|
|
||||||
assertEquals(new StackTraceElement(
|
|
||||||
"com.google.inject.spi.ElementSourceTest$C", "configure", null, -1),
|
|
||||||
stackTraceElement);
|
|
||||||
// Check call stack
|
|
||||||
assertEquals(0, callStack.length);
|
|
||||||
return;
|
return;
|
||||||
case ONLY_FOR_DECLARING_SOURCE:
|
|
||||||
// Check call stack
|
|
||||||
assertEquals(0, callStack.length);
|
|
||||||
return;
|
|
||||||
case COMPLETE:
|
|
||||||
// Check call stack
|
|
||||||
int skippedCallStackSize = new Throwable().getStackTrace().length - 1;
|
|
||||||
assertEquals(skippedCallStackSize + 15, elementSource.getStackTrace().length);
|
|
||||||
assertEquals("com.google.inject.spi.Elements$RecordingBinder",
|
|
||||||
callStack[0].getClassName());
|
|
||||||
assertEquals("com.google.inject.spi.Elements$RecordingBinder",
|
|
||||||
callStack[1].getClassName());
|
|
||||||
assertEquals("com.google.inject.AbstractModule",
|
|
||||||
callStack[2].getClassName());
|
|
||||||
// Module C
|
|
||||||
assertEquals("com.google.inject.spi.ElementSourceTest$C",
|
|
||||||
callStack[3].getClassName());
|
|
||||||
assertEquals("configure",
|
|
||||||
callStack[3].getMethodName());
|
|
||||||
assertEquals("Unknown Source",
|
|
||||||
callStack[3].getFileName());
|
|
||||||
assertEquals("com.google.inject.AbstractModule",
|
|
||||||
callStack[4].getClassName());
|
|
||||||
assertEquals("com.google.inject.spi.Elements$RecordingBinder",
|
|
||||||
callStack[5].getClassName());
|
|
||||||
// Module B
|
|
||||||
assertEquals("com.google.inject.spi.ElementSourceTest$B",
|
|
||||||
callStack[6].getClassName());
|
|
||||||
assertEquals("com.google.inject.spi.Elements$RecordingBinder",
|
|
||||||
callStack[7].getClassName());
|
|
||||||
// Module A
|
|
||||||
assertEquals("com.google.inject.AbstractModule",
|
|
||||||
callStack[8].getClassName());
|
|
||||||
assertEquals("com.google.inject.spi.ElementSourceTest$A",
|
|
||||||
callStack[9].getClassName());
|
|
||||||
assertEquals("com.google.inject.AbstractModule",
|
|
||||||
callStack[10].getClassName());
|
|
||||||
assertEquals("com.google.inject.spi.Elements$RecordingBinder",
|
|
||||||
callStack[11].getClassName());
|
|
||||||
assertEquals("com.google.inject.spi.Elements",
|
|
||||||
callStack[12].getClassName());
|
|
||||||
assertEquals("com.google.inject.spi.Elements",
|
|
||||||
callStack[13].getClassName());
|
|
||||||
assertEquals("com.google.inject.spi.ElementSourceTest",
|
|
||||||
callStack[14].getClassName());
|
|
||||||
// Check modules index
|
|
||||||
List<Integer> indexes = elementSource.getModuleConfigurePositionsInStackTrace();
|
|
||||||
assertEquals((int) indexes.get(0), 4);
|
|
||||||
assertEquals((int) indexes.get(1), 6);
|
|
||||||
assertEquals((int) indexes.get(2), 10);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,29 +49,11 @@ public class ElementSourceTest {
|
||||||
|
|
||||||
private ModuleSource createModuleSource() {
|
private ModuleSource createModuleSource() {
|
||||||
// First module
|
// First module
|
||||||
StackTraceElement[] partialCallStack = new StackTraceElement[1];
|
ModuleSource moduleSource = new ModuleSource(A.class, /* permitMap = */ null);
|
||||||
partialCallStack[0] = BINDER_INSTALL;
|
|
||||||
ModuleSource moduleSource = new ModuleSource(new A(), partialCallStack);
|
|
||||||
// Second module
|
// Second module
|
||||||
partialCallStack = new StackTraceElement[2];
|
moduleSource = moduleSource.createChild(B.class);
|
||||||
partialCallStack[0] = BINDER_INSTALL;
|
|
||||||
partialCallStack[1] = new StackTraceElement(
|
|
||||||
"com.google.inject.spi.moduleSourceTest$A", "configure", "Unknown Source", 100);
|
|
||||||
moduleSource = moduleSource.createChild(new B(), partialCallStack);
|
|
||||||
// Third module
|
// Third module
|
||||||
partialCallStack = new StackTraceElement[4];
|
return moduleSource.createChild(C.class);
|
||||||
partialCallStack[0] = BINDER_INSTALL;
|
|
||||||
partialCallStack[1] = new StackTraceElement("class1", "method1", "Class1.java", 1);
|
|
||||||
partialCallStack[2] = new StackTraceElement("class2", "method2", "Class2.java", 2);
|
|
||||||
partialCallStack[3] = new StackTraceElement(
|
|
||||||
"com.google.inject.spi.moduleSourceTest$B", "configure", "Unknown Source", 200);
|
|
||||||
return moduleSource.createChild(new C(), partialCallStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Retention(RUNTIME)
|
|
||||||
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
|
|
||||||
@BindingAnnotation
|
|
||||||
@interface SampleAnnotation {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class A extends AbstractModule {
|
private static class A extends AbstractModule {
|
||||||
|
@ -170,6 +70,11 @@ public class ElementSourceTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
|
||||||
|
@BindingAnnotation
|
||||||
|
@interface SampleAnnotation {}
|
||||||
|
|
||||||
private static class C extends AbstractModule {
|
private static class C extends AbstractModule {
|
||||||
@Override
|
@Override
|
||||||
public void configure() {
|
public void configure() {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package com.google.inject.spi;
|
||||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||||
import static com.google.inject.Asserts.assertContains;
|
import static com.google.inject.Asserts.assertContains;
|
||||||
import static com.google.inject.Asserts.getDeclaringSourcePart;
|
import static com.google.inject.Asserts.getDeclaringSourcePart;
|
||||||
import static com.google.inject.Asserts.isIncludeStackTraceComplete;
|
|
||||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
@ -1342,11 +1341,6 @@ public class ElementsTest {
|
||||||
if (!(element instanceof Message)) {
|
if (!(element instanceof Message)) {
|
||||||
ElementSource source = (ElementSource) element.getSource();
|
ElementSource source = (ElementSource) element.getSource();
|
||||||
assertFalse(source.getModuleClassNames().isEmpty());
|
assertFalse(source.getModuleClassNames().isEmpty());
|
||||||
if (isIncludeStackTraceComplete()) {
|
|
||||||
assertTrue(source.getStackTrace().length > 0);
|
|
||||||
} else {
|
|
||||||
assertEquals(0, source.getStackTrace().length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!(visitor instanceof ExternalFailureVisitor)) {
|
if (!(visitor instanceof ExternalFailureVisitor)) {
|
||||||
assertContains(element.getSource().toString(), getDeclaringSourcePart(ElementsTest.class));
|
assertContains(element.getSource().toString(), getDeclaringSourcePart(ElementsTest.class));
|
||||||
|
|
|
@ -1,27 +1,25 @@
|
||||||
package com.google.inject.spi;
|
package com.google.inject.spi;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Binder;
|
import com.google.inject.Binder;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import org.junit.Test;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/** Tests for {@link ModuleSource}. */
|
||||||
* Tests for {@link ModuleSource}.
|
public class ModuleSourceTest extends TestCase {
|
||||||
*/
|
|
||||||
public class ModuleSourceTest {
|
|
||||||
|
|
||||||
private static final StackTraceElement BINDER_INSTALL =
|
private static final StackTraceElement BINDER_INSTALL =
|
||||||
new StackTraceElement("com.google.inject.spi.Elements$RecordingBinder", "install",
|
new StackTraceElement(
|
||||||
"Unknown Source", 235 /* line number*/);
|
"com.google.inject.spi.Elements$RecordingBinder",
|
||||||
|
"install",
|
||||||
|
"Unknown Source",
|
||||||
|
235 /* line number*/);
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testOneModule() {
|
public void testOneModule() {
|
||||||
ModuleSource moduleSource = createWithSizeOne();
|
ModuleSource moduleSource = createWithSizeOne();
|
||||||
checkSizeOne(moduleSource);
|
checkSizeOne(moduleSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTwoModules() {
|
public void testTwoModules() {
|
||||||
ModuleSource moduleSource = createWithSizeTwo();
|
ModuleSource moduleSource = createWithSizeTwo();
|
||||||
checkSizeTwo(moduleSource);
|
checkSizeTwo(moduleSource);
|
||||||
|
@ -29,7 +27,6 @@ public class ModuleSourceTest {
|
||||||
checkSizeOne(moduleSource);
|
checkSizeOne(moduleSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testThreeModules() {
|
public void testThreeModules() {
|
||||||
ModuleSource moduleSource = createWithSizeThree();
|
ModuleSource moduleSource = createWithSizeThree();
|
||||||
checkSizeThree(moduleSource);
|
checkSizeThree(moduleSource);
|
||||||
|
@ -41,70 +38,28 @@ public class ModuleSourceTest {
|
||||||
|
|
||||||
private void checkSizeOne(ModuleSource moduleSource) {
|
private void checkSizeOne(ModuleSource moduleSource) {
|
||||||
assertEquals(1, moduleSource.size());
|
assertEquals(1, moduleSource.size());
|
||||||
assertEquals(1, moduleSource.getStackTraceSize());
|
|
||||||
// Check call stack
|
|
||||||
StackTraceElement[] callStack = moduleSource.getStackTrace();
|
|
||||||
assertEquals(BINDER_INSTALL, callStack[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSizeTwo(ModuleSource moduleSource) {
|
private void checkSizeTwo(ModuleSource moduleSource) {
|
||||||
assertEquals(2, moduleSource.size());
|
assertEquals(2, moduleSource.size());
|
||||||
assertEquals(3, moduleSource.getStackTraceSize());
|
|
||||||
// Check call stack
|
|
||||||
StackTraceElement[] callStack = moduleSource.getStackTrace();
|
|
||||||
assertEquals(BINDER_INSTALL, callStack[0]);
|
|
||||||
assertEquals(
|
|
||||||
new StackTraceElement(
|
|
||||||
"com.google.inject.spi.moduleSourceTest$A", "configure", "Unknown Source", 100),
|
|
||||||
callStack[1]);
|
|
||||||
assertEquals(BINDER_INSTALL, callStack[2]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkSizeThree(ModuleSource moduleSource) {
|
private void checkSizeThree(ModuleSource moduleSource) {
|
||||||
assertEquals(3, moduleSource.size());
|
assertEquals(3, moduleSource.size());
|
||||||
assertEquals(7, moduleSource.getStackTraceSize());
|
|
||||||
// Check call stack
|
|
||||||
StackTraceElement[] callStack = moduleSource.getStackTrace();
|
|
||||||
assertEquals(BINDER_INSTALL, callStack[0]);
|
|
||||||
assertEquals(new StackTraceElement("class1", "method1", "Unknown Source", 1), callStack[1]);
|
|
||||||
assertEquals(new StackTraceElement("class2", "method2", "Unknown Source", 2), callStack[2]);
|
|
||||||
assertEquals(
|
|
||||||
new StackTraceElement(
|
|
||||||
"com.google.inject.spi.moduleSourceTest$B", "configure", "Unknown Source", 200),
|
|
||||||
callStack[3]);
|
|
||||||
assertEquals(BINDER_INSTALL, callStack[4]);
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
new StackTraceElement(
|
|
||||||
"com.google.inject.spi.moduleSourceTest$A", "configure", "Unknown Source", 100),
|
|
||||||
callStack[5]);
|
|
||||||
assertEquals(BINDER_INSTALL, callStack[6]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModuleSource createWithSizeOne() {
|
private ModuleSource createWithSizeOne() {
|
||||||
StackTraceElement[] partialCallStack = new StackTraceElement[1];
|
return new ModuleSource(A.class, null);
|
||||||
partialCallStack[0] = BINDER_INSTALL;
|
|
||||||
return new ModuleSource(new A(), partialCallStack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModuleSource createWithSizeTwo() {
|
private ModuleSource createWithSizeTwo() {
|
||||||
ModuleSource moduleSource = createWithSizeOne();
|
ModuleSource moduleSource = createWithSizeOne();
|
||||||
StackTraceElement[] partialCallStack = new StackTraceElement[2];
|
return moduleSource.createChild(B.class);
|
||||||
partialCallStack[0] = BINDER_INSTALL;
|
|
||||||
partialCallStack[1] = new StackTraceElement(
|
|
||||||
"com.google.inject.spi.moduleSourceTest$A", "configure", "moduleSourceTest.java", 100);
|
|
||||||
return moduleSource.createChild(new B(), partialCallStack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ModuleSource createWithSizeThree() {
|
private ModuleSource createWithSizeThree() {
|
||||||
ModuleSource moduleSource = createWithSizeTwo();
|
ModuleSource moduleSource = createWithSizeTwo();
|
||||||
StackTraceElement[] partialCallStack = new StackTraceElement[4];
|
return moduleSource.createChild(C.class);
|
||||||
partialCallStack[0] = BINDER_INSTALL;
|
|
||||||
partialCallStack[1] = new StackTraceElement("class1", "method1", "Class1.java", 1);
|
|
||||||
partialCallStack[2] = new StackTraceElement("class2", "method2", "Class2.java", 2);
|
|
||||||
partialCallStack[3] = new StackTraceElement(
|
|
||||||
"com.google.inject.spi.moduleSourceTest$B", "configure", "moduleSourceTest.java", 200);
|
|
||||||
return moduleSource.createChild(new C(), partialCallStack);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class A extends AbstractModule {
|
private static class A extends AbstractModule {
|
||||||
|
@ -122,6 +77,7 @@ public class ModuleSourceTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class C extends AbstractModule {
|
private static class C extends AbstractModule {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure() {
|
public void configure() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package com.google.inject.spi;
|
||||||
|
|
||||||
import static com.google.inject.Asserts.assertContains;
|
import static com.google.inject.Asserts.assertContains;
|
||||||
import static com.google.inject.Asserts.getDeclaringSourcePart;
|
import static com.google.inject.Asserts.getDeclaringSourcePart;
|
||||||
import static com.google.inject.Asserts.isIncludeStackTraceComplete;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
@ -431,11 +430,6 @@ public class SpiBindingsTest {
|
||||||
assertContains(binding.getSource().toString(), getDeclaringSourcePart(getClass()));
|
assertContains(binding.getSource().toString(), getDeclaringSourcePart(getClass()));
|
||||||
ElementSource source = (ElementSource) binding.getSource();
|
ElementSource source = (ElementSource) binding.getSource();
|
||||||
assertFalse(source.getModuleClassNames().isEmpty());
|
assertFalse(source.getModuleClassNames().isEmpty());
|
||||||
if (isIncludeStackTraceComplete()) {
|
|
||||||
assertTrue(source.getStackTrace().length > 0);
|
|
||||||
} else {
|
|
||||||
assertEquals(0, source.getStackTrace().length);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkInjector(Module module, ElementVisitor<?>... visitors) {
|
public void checkInjector(Module module, ElementVisitor<?>... visitors) {
|
||||||
|
|
Loading…
Reference in a new issue