Skip to content

Commit

Permalink
Add empty TypeRegistryImpl constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltak committed Aug 9, 2019
1 parent 1679be2 commit ef8c8b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.terasology.engine.module.ModuleManager;
import org.terasology.engine.paths.PathManager;
import org.terasology.module.DependencyResolver;
import org.terasology.module.ModuleEnvironment;
import org.terasology.module.ResolutionResult;
import org.terasology.reflection.internal.TypeRegistryImpl;
import org.terasology.testUtil.ModuleManagerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,35 @@
import org.terasology.module.ModuleMetadata;
import org.terasology.module.ModuleMetadataReader;
import org.terasology.naming.Name;
import org.terasology.reflection.TypeRegistry;
import org.terasology.reflection.internal.TypeRegistryImpl;

import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Set;

/**
*/
public final class ModuleManagerFactory {
private ModuleManagerFactory() {
}

// Named "create" for legacy reasons, but does more than create
public static ModuleManager create() throws Exception {
return create(Mockito.mock(TypeRegistryImpl.class));
ModuleManager manager = create(Mockito.mock(TypeRegistryImpl.class));
manager.loadEnvironment(Sets.newHashSet(manager.getRegistry().getLatestModuleVersion(new Name("engine"))), true);
return manager;
}

/**
* Creates a new {@link ModuleManager} instance, but does not
* {@link ModuleManager#loadEnvironment(Set, boolean) load it's environment}.
*/
public static ModuleManager create(TypeRegistryImpl typeRegistry) throws Exception {
ModuleManager moduleManager = new ModuleManagerImpl("", typeRegistry);
try (Reader reader = new InputStreamReader(ModuleManagerFactory.class.getResourceAsStream("/module.txt"), TerasologyConstants.CHARSET)) {
ModuleMetadata metadata = new ModuleMetadataReader().read(reader);
moduleManager.getRegistry().add(ClasspathModule.create(metadata, ModuleManagerFactory.class));
}
moduleManager.loadEnvironment(Sets.newHashSet(moduleManager.getRegistry().getLatestModuleVersion(new Name("engine"))), true);
return moduleManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@
public class TypeRegistryImpl implements TypeRegistry {
private Reflections reflections;

public TypeRegistryImpl() {
initializeReflections(TypeRegistryImpl.class.getClassLoader());
/**
* Creates an empty {@link TypeRegistryImpl}. No types are loaded when this constructor
* is called -- to populate the registry use one of the other parameterized constructors.
*/
public TypeRegistryImpl() {}

public TypeRegistryImpl(ClassLoader classLoader) {
initializeReflections(classLoader);
}

public void reload(ModuleEnvironment environment) {
Expand Down

0 comments on commit ef8c8b4

Please sign in to comment.