mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Trying to fix #460
Actually, could not reproduce this, added some tests (they passed on initial version).
This commit is contained in:
parent
c30e2d3c24
commit
afa4e15846
|
@ -61,12 +61,13 @@ public class ServiceLoaderSupport extends AbstractDependencyListener implements
|
||||||
for (Map.Entry<String, List<String>> entry : serviceMap.entrySet()) {
|
for (Map.Entry<String, List<String>> entry : serviceMap.entrySet()) {
|
||||||
writer.appendClass(entry.getKey()).append(".$$serviceList$$ = [");
|
writer.appendClass(entry.getKey()).append(".$$serviceList$$ = [");
|
||||||
List<String> implementations = entry.getValue();
|
List<String> implementations = entry.getValue();
|
||||||
for (int i = 0; i < implementations.size(); ++i) {
|
boolean first = true;
|
||||||
if (i > 0) {
|
for (String implName : implementations) {
|
||||||
writer.append(", ");
|
|
||||||
}
|
|
||||||
String implName = implementations.get(i);
|
|
||||||
if (context.getClassSource().getClassNames().contains(implName)) {
|
if (context.getClassSource().getClassNames().contains(implName)) {
|
||||||
|
if (!first) {
|
||||||
|
writer.append(", ");
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
writer.append("[").appendClass(implName).append(", ").appendMethodBody(
|
writer.append("[").appendClass(implName).append(", ").appendMethodBody(
|
||||||
new MethodReference(implName, INIT_METHOD))
|
new MethodReference(implName, INIT_METHOD))
|
||||||
.append("]");
|
.append("]");
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2020 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* 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.teavm.classlib.java.util;
|
||||||
|
|
||||||
|
public interface MultipleTestService {
|
||||||
|
String foo();
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2020 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* 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.teavm.classlib.java.util;
|
||||||
|
|
||||||
|
public class MultipleTestServiceImpl1 implements MultipleTestService {
|
||||||
|
@Override
|
||||||
|
public String foo() {
|
||||||
|
return "A";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2020 Alexey Andreev.
|
||||||
|
*
|
||||||
|
* 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.teavm.classlib.java.util;
|
||||||
|
|
||||||
|
public class MultipleTestServiceImpl2 implements MultipleTestService {
|
||||||
|
@Override
|
||||||
|
public String foo() {
|
||||||
|
return "B";
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,9 @@
|
||||||
package org.teavm.classlib.java.util;
|
package org.teavm.classlib.java.util;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
@ -30,4 +33,14 @@ public class ServiceLoaderTest {
|
||||||
assertEquals(TestServiceImpl.class, instance.getClass());
|
assertEquals(TestServiceImpl.class, instance.getClass());
|
||||||
assertEquals(1, ((TestServiceImpl) instance).getCounter());
|
assertEquals(1, ((TestServiceImpl) instance).getCounter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void loadsMultipleServices() {
|
||||||
|
List<String> strings = new ArrayList<>();
|
||||||
|
for (MultipleTestService instance : ServiceLoader.load(MultipleTestService.class)) {
|
||||||
|
strings.add(instance.foo());
|
||||||
|
}
|
||||||
|
strings.sort(String::compareTo);
|
||||||
|
assertEquals(Arrays.asList("A", "B"), strings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#
|
||||||
|
# Copyright 2017 Alexey Andreev.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
org.teavm.classlib.java.util.MultipleTestServiceImpl1
|
||||||
|
org.teavm.classlib.java.util.MultipleTestServiceImpl2
|
Loading…
Reference in New Issue
Block a user