Package gw.internal.gosu.module
Class Module
- java.lang.Object
-
- gw.internal.gosu.module.Module
-
- All Implemented Interfaces:
IModule
- Direct Known Subclasses:
GlobalModule,JreModule
public class Module extends java.lang.Object implements IModule
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classModule.ExtensionClassLoaderSingleton extension classloader.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<IDirectory>_backingSourcePathprivate java.util.List<IDirectory>_classpathprivate java.util.List<Dependency>_dependenciesprivate IExecutionEnvironment_execEnvprivate java.lang.ClassLoader_extensionsClassLoaderprivate IFileSystemGosuClassRepository_fileRepositoryprivate ModuleTypeLoader_modTypeLoaderprivate java.lang.ClassLoader_moduleClassLoaderprivate INativeModule_nativeModuleprivate java.lang.String_strNameprivate LocklessLazyVar<IModule[]>_traversalList-
Fields inherited from interface gw.lang.reflect.module.IModule
CONFIG_RESOURCE_PREFIX
-
-
Constructor Summary
Constructors Constructor Description Module(IExecutionEnvironment execEnv, java.lang.String strName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDependency(Dependency d)private java.util.List<IDirectory>addFromManifestClassPath(java.util.List<IDirectory> classpath)This will add items to the Gosu classpath, but only under very specific circumstances.private IModule[]buildTraversalList()voidconfigurePaths(java.util.List<IDirectory> classpath, java.util.List<IDirectory> sourcePaths, java.util.List<IDirectory> backingSourcePaths)Configure both source and Java classpaths of the module in a semi-automated way.private ITypeLoadercreateAndPushTypeLoader(IFileSystemGosuClassRepository classRepository, java.lang.String className)protected voidcreateExtensionTypeLoaders()protected voidcreateExtensionTypeloadersImpl()protected voidcreateStandardTypeLoaders()voiddisposeLoader()booleanequals(java.lang.Object o)protected java.util.List<IDirectory>getAdditionalSourceRoots()java.util.List<IDirectory>getBackingSourcePath()private java.lang.reflect.ConstructorgetConstructor(java.lang.Class<?> loaderClass, java.lang.Class... argTypes)java.util.List<Dependency>getDependencies()java.util.List<IDirectory>getExcludedPaths()IExecutionEnvironmentgetExecutionEnvironment()private java.lang.ClassLoadergetExtensionClassLoader()private java.util.Set<java.lang.String>getExtensionTypeloaderNames()private java.net.URL[]getExtensionURLs()IFileSystemGosuClassRepositorygetFileRepository()java.util.List<IDirectory>getJavaClassPath()java.lang.ClassLoadergetModuleClassLoader()Get class loader, associated with this module.IModule[]getModuleTraversalList()ModuleTypeLoadergetModuleTypeLoader()java.lang.StringgetName()java.lang.ObjectgetNativeModule()IDirectorygetOutputPath()java.util.List<IDirectory>getSourcePath()<T extends ITypeLoader>
java.util.List<? extends T>getTypeLoaders(java.lang.Class<T> typeLoaderClass)Returns typeloaders of the given class that are local to this module as well as such typeloaders from dependent modules.inthashCode()voidinitializeTypeLoaders()protected voidmaybeCreateModuleTypeLoader()voidremoveDependency(Dependency d)private static voidscanPaths(java.util.List<IDirectory> paths, java.util.Set<java.lang.String> extensions, java.util.List<IDirectory> roots)voidsetBackingSourcePath(java.util.List<IDirectory> backingSourcePath)voidsetDependencies(java.util.List<Dependency> newDeps)voidsetExcludedPaths(java.util.List<IDirectory> paths)voidsetJavaClassPath(java.util.List<IDirectory> classpath)voidsetModuleTypeLoader(ModuleTypeLoader modTypeLoader)voidsetName(java.lang.String name)voidsetNativeModule(INativeModule nativeModule)voidsetSourcePath(java.util.List<IDirectory> sourcePaths)java.lang.StringtoString()protected voidtraverse(IModule theModule, java.util.List<IModule> traversalList)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface gw.lang.reflect.module.IModule
configurePaths
-
-
-
-
Field Detail
-
_execEnv
private final IExecutionEnvironment _execEnv
-
_strName
private java.lang.String _strName
-
_dependencies
private java.util.List<Dependency> _dependencies
-
_traversalList
private LocklessLazyVar<IModule[]> _traversalList
-
_modTypeLoader
private ModuleTypeLoader _modTypeLoader
-
_classpath
private java.util.List<IDirectory> _classpath
-
_backingSourcePath
private java.util.List<IDirectory> _backingSourcePath
-
_nativeModule
private INativeModule _nativeModule
-
_moduleClassLoader
private java.lang.ClassLoader _moduleClassLoader
-
_extensionsClassLoader
private java.lang.ClassLoader _extensionsClassLoader
-
_fileRepository
private final IFileSystemGosuClassRepository _fileRepository
-
-
Constructor Detail
-
Module
public Module(IExecutionEnvironment execEnv, java.lang.String strName)
-
-
Method Detail
-
getExecutionEnvironment
public final IExecutionEnvironment getExecutionEnvironment()
- Specified by:
getExecutionEnvironmentin interfaceIModule
-
getFileRepository
public IFileSystemGosuClassRepository getFileRepository()
- Specified by:
getFileRepositoryin interfaceIModule
-
setDependencies
public void setDependencies(java.util.List<Dependency> newDeps)
- Specified by:
setDependenciesin interfaceIModule
-
getDependencies
public java.util.List<Dependency> getDependencies()
- Specified by:
getDependenciesin interfaceIModule- Returns:
- A list of dependencies for this module. The list may contain both libraries and other modules. The dependency graph must not have cycles.
-
addDependency
public void addDependency(Dependency d)
- Specified by:
addDependencyin interfaceIModule
-
removeDependency
public void removeDependency(Dependency d)
- Specified by:
removeDependencyin interfaceIModule
-
getSourcePath
public java.util.List<IDirectory> getSourcePath()
- Specified by:
getSourcePathin interfaceIModule- Returns:
- The path[s] having source files that should be exposed to this module.
-
setSourcePath
public void setSourcePath(java.util.List<IDirectory> sourcePaths)
- Specified by:
setSourcePathin interfaceIModule
-
getExcludedPaths
public java.util.List<IDirectory> getExcludedPaths()
- Specified by:
getExcludedPathsin interfaceIModule
-
setExcludedPaths
public void setExcludedPaths(java.util.List<IDirectory> paths)
- Specified by:
setExcludedPathsin interfaceIModule
-
getModuleClassLoader
public java.lang.ClassLoader getModuleClassLoader()
Description copied from interface:IModuleGet class loader, associated with this module.- Specified by:
getModuleClassLoaderin interfaceIModule- Returns:
-
disposeLoader
public void disposeLoader()
- Specified by:
disposeLoaderin interfaceIModule
-
scanPaths
private static void scanPaths(java.util.List<IDirectory> paths, java.util.Set<java.lang.String> extensions, java.util.List<IDirectory> roots)
-
getOutputPath
public IDirectory getOutputPath()
- Specified by:
getOutputPathin interfaceIModule
-
getModuleTypeLoader
public ModuleTypeLoader getModuleTypeLoader()
- Specified by:
getModuleTypeLoaderin interfaceIModule
-
setModuleTypeLoader
public void setModuleTypeLoader(ModuleTypeLoader modTypeLoader)
-
configurePaths
public void configurePaths(java.util.List<IDirectory> classpath, java.util.List<IDirectory> sourcePaths, java.util.List<IDirectory> backingSourcePaths)
Description copied from interface:IModuleConfigure both source and Java classpaths of the module in a semi-automated way. First parameter is Java classpath. Second parameter is extended with all paths from Java classpath that are marked to have Gosu "sources" (through MANIFEST.MF with Contains-Sources header) and used as Gosu source path.- Specified by:
configurePathsin interfaceIModule- Parameters:
classpath- path to types not directly in the module's sources e.g., jar files containing .class files and other types/resourcessourcePaths- path to the sources directly defined in this module; sources in this path are statically compiled as part of this module's build target e.g., ./src directoriesbackingSourcePaths- path to sources corresponding with the classpath parameter (intended for IDE use)
-
addFromManifestClassPath
private java.util.List<IDirectory> addFromManifestClassPath(java.util.List<IDirectory> classpath)
This will add items to the Gosu classpath, but only under very specific circumstances.
If both of the following conditions are met:
- The JAR's manifest contains a Class-Path entry
- The Class-Path entry contains a space-delimited list of URIs
Then the entries will be parsed and added to the Gosu classpath.
This logic also handles strange libraries packaged pre-Maven such as xalan:xalan:2.4.1
The xalan JAR above has a Class-Path attribute referencing the following:
Class-Path: xercesImpl.jar xml-apis.jar
These unqualified references should have been resolved by the build tooling, and if we try to interfere and resolve the references, we may cause classpath confusion. Therefore any Class-Path entry not resolvable to an absolute path on disk (and, therefore, can be listed as a URL) will be skipped.- Parameters:
classpath- The module's Java classpath- Returns:
- The original classpath, possibly with dependencies listed in JAR manifests Class-Path extracted and explicitly listed
- See Also:
Attributes.Name.CLASS_PATH
-
getJavaClassPath
public java.util.List<IDirectory> getJavaClassPath()
- Specified by:
getJavaClassPathin interfaceIModule
-
setJavaClassPath
public void setJavaClassPath(java.util.List<IDirectory> classpath)
- Specified by:
setJavaClassPathin interfaceIModule
-
getBackingSourcePath
public java.util.List<IDirectory> getBackingSourcePath()
- Specified by:
getBackingSourcePathin interfaceIModule
-
setBackingSourcePath
public void setBackingSourcePath(java.util.List<IDirectory> backingSourcePath)
- Specified by:
setBackingSourcePathin interfaceIModule
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
getNativeModule
public java.lang.Object getNativeModule()
- Specified by:
getNativeModulein interfaceIModule- Returns:
- The module/project from the execution environment that corresponds with this logical module. For example, in Eclipse the native module is of type IJavaProject.
-
setNativeModule
public void setNativeModule(INativeModule nativeModule)
- Specified by:
setNativeModulein interfaceIModule
-
initializeTypeLoaders
public void initializeTypeLoaders()
-
createExtensionTypeLoaders
protected void createExtensionTypeLoaders()
-
createExtensionTypeloadersImpl
protected void createExtensionTypeloadersImpl()
-
getExtensionTypeloaderNames
private java.util.Set<java.lang.String> getExtensionTypeloaderNames()
-
createStandardTypeLoaders
protected void createStandardTypeLoaders()
-
maybeCreateModuleTypeLoader
protected void maybeCreateModuleTypeLoader()
-
getModuleTraversalList
public final IModule[] getModuleTraversalList()
- Specified by:
getModuleTraversalListin interfaceIModule
-
buildTraversalList
private IModule[] buildTraversalList()
-
getTypeLoaders
public <T extends ITypeLoader> java.util.List<? extends T> getTypeLoaders(java.lang.Class<T> typeLoaderClass)
Description copied from interface:IModuleReturns typeloaders of the given class that are local to this module as well as such typeloaders from dependent modules.- Specified by:
getTypeLoadersin interfaceIModule- Returns:
-
createAndPushTypeLoader
private ITypeLoader createAndPushTypeLoader(IFileSystemGosuClassRepository classRepository, java.lang.String className)
-
getExtensionClassLoader
private java.lang.ClassLoader getExtensionClassLoader()
-
getExtensionURLs
private java.net.URL[] getExtensionURLs()
-
getConstructor
private java.lang.reflect.Constructor getConstructor(java.lang.Class<?> loaderClass, java.lang.Class... argTypes)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getName
public java.lang.String getName()
-
getAdditionalSourceRoots
protected java.util.List<IDirectory> getAdditionalSourceRoots()
-
-