Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override getResources in DefaultDeprecatedClassLoader
This fixes #10347 In #9898 we introduced a DefaultDeprecatedClassLoader, which overrides getResource() but not getResources(). This causes some issues. This PR fixes the issue by correctly overriding getResources() method.
- Loading branch information
1 parent
f0b9d60
commit 07e3e0d
Showing
2 changed files
with
95 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...est/groovy/org/gradle/api/internal/initialization/DefaultDeprecatedClassLoaderTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.gradle.api.internal.initialization | ||
|
||
import com.google.common.collect.Iterators | ||
import spock.lang.Specification | ||
import spock.lang.Subject | ||
|
||
class DefaultDeprecatedClassLoaderTest extends Specification { | ||
ClassLoader nonDeprecatedParent = Mock() | ||
ClassLoader deprecatedUsageLoader = Mock() | ||
|
||
String resource = 'testResource' | ||
URL url1 = new URL('https://a.com') | ||
URL url2 = new URL('https://b.com') | ||
|
||
@Subject | ||
DefaultDeprecatedClassLoader classLoader = new DefaultDeprecatedClassLoader(deprecatedUsageLoader, nonDeprecatedParent) | ||
|
||
def 'can get resource from nonDeprecatedParent'() { | ||
when: | ||
1 * nonDeprecatedParent.getResource(resource) >> url1 | ||
0 * _._ | ||
|
||
then: | ||
classLoader.getResource(resource) == url1 | ||
} | ||
|
||
def 'can get resource from deprecatedUsageLoader'() { | ||
when: | ||
1 * nonDeprecatedParent.getResource(resource) >> null | ||
1 * deprecatedUsageLoader.getResource(resource) >> url2 | ||
|
||
then: | ||
classLoader.getResource(resource) == url2 | ||
} | ||
|
||
def 'can get resources from nonDeprecatedParent'() { | ||
when: | ||
1 * nonDeprecatedParent.getResources(resource) >> Iterators.asEnumeration([url1].iterator()) | ||
0 * _._ | ||
|
||
then: | ||
classLoader.getResources(resource).nextElement() == url1 | ||
} | ||
|
||
def 'can get resources from deprecatedUsageLoader'() { | ||
when: | ||
1 * nonDeprecatedParent.getResources(resource) >> Iterators.asEnumeration([].iterator()) | ||
1 * deprecatedUsageLoader.getResources(resource) >> Iterators.asEnumeration([url2].iterator()) | ||
|
||
then: | ||
classLoader.getResources(resource).nextElement() == url2 | ||
} | ||
} |