use of org.jboss.modules.LocalDependencySpecBuilder in project jboss-modules by jboss-modules.
the class ModuleXmlParser method parseModuleContents.
private static ModuleSpec.Builder parseModuleContents(final MavenResolver mavenResolver, final XmlPullParser reader, final ResourceRootFactory factory, final ModuleLoader moduleLoader, final String moduleName, final String rootPath) throws XmlPullParserException, IOException {
final int count = reader.getAttributeCount();
String name = null;
String slot = null;
boolean is1_6 = atLeast1_6(reader);
Version version = null;
final Set<String> required = is1_6 ? new HashSet<>(LIST_A_NAME) : new HashSet<>(LIST_A_NAME);
for (int i = 0; i < count; i++) {
validateAttributeNamespace(reader, i);
final String attribute = reader.getAttributeName(i);
required.remove(attribute);
switch(attribute) {
case A_NAME:
name = reader.getAttributeValue(i);
break;
case A_SLOT:
if (is1_6)
throw unknownAttribute(reader, i);
else
slot = reader.getAttributeValue(i);
break;
case A_VERSION:
try {
version = Version.parse(reader.getAttributeValue(i));
break;
} catch (IllegalArgumentException ex) {
throw new XmlPullParserException(ex.getMessage(), reader, ex);
}
default:
throw unknownAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingAttributes(reader, required);
}
final String realModuleName;
if (is1_6) {
realModuleName = name;
} else {
realModuleName = ModuleIdentifier.create(name, slot).toString();
}
if (moduleName != null && !realModuleName.equals(moduleName)) {
throw invalidModuleName(reader, realModuleName);
}
final ModuleSpec.Builder specBuilder = ModuleSpec.build(realModuleName);
specBuilder.setVersion(version);
// xsd:all
MultiplePathFilterBuilder exportsBuilder = PathFilters.multiplePathFilterBuilder(true);
ArrayList<DependencySpec> dependencies = new ArrayList<>();
final boolean is1_8 = atLeast1_8(reader);
if (!is1_8) {
// add default system dependencies
specBuilder.addDependency(DEP_JAVA_SE);
specBuilder.addDependency(DEP_JDK_UNSUPPORTED);
}
Set<String> visited = new HashSet<>();
int eventType;
boolean gotPerms = false;
for (; ; ) {
eventType = reader.nextTag();
switch(eventType) {
case END_TAG:
{
specBuilder.addDependency(new LocalDependencySpecBuilder().setExportFilter(exportsBuilder.create()).build());
for (DependencySpec dependency : dependencies) {
specBuilder.addDependency(dependency);
}
if (!gotPerms)
specBuilder.setPermissionCollection(DEFAULT_PERMISSION_COLLECTION);
return specBuilder;
}
case START_TAG:
{
validateNamespace(reader);
final String element = reader.getName();
if (visited.contains(element)) {
throw unexpectedContent(reader);
}
visited.add(element);
switch(element) {
case E_EXPORTS:
parseFilterList(reader, exportsBuilder);
break;
case E_DEPENDENCIES:
parseDependencies(reader, dependencies);
break;
case E_MAIN_CLASS:
parseMainClass(reader, specBuilder);
break;
case E_RESOURCES:
parseResources(mavenResolver, factory, rootPath, reader, specBuilder);
break;
case E_PROPERTIES:
parseProperties(reader, specBuilder);
break;
case E_PERMISSIONS:
parsePermissions(reader, moduleLoader, realModuleName, specBuilder);
gotPerms = true;
break;
case E_PROVIDES:
if (is1_8)
parseProvidesType(reader, specBuilder);
else
throw unexpectedContent(reader);
break;
default:
throw unexpectedContent(reader);
}
break;
}
default:
{
throw unexpectedContent(reader);
}
}
}
}
Aggregations