Skip to content

Commit

Permalink
Remove problematic configuration parsing option
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Apr 12, 2012
1 parent 42dbd16 commit 62fab25
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 218 deletions.
25 changes: 3 additions & 22 deletions src/main/java/org/jboss/modules/Main.java
Expand Up @@ -85,9 +85,6 @@ private static void usage() {
System.out.println(" requires -class or -cp");
System.out.println(" -jar Specify that the final argument is the name of a");
System.out.println(" JAR file to run as a module; not compatible with -class");
System.out.println(" -config <config-location>");
System.out.println(" The location of the module configuration. Either -mp or -config");
System.out.println(" may be specified, but not both");
System.out.println(" -jaxpmodule <module-name>");
System.out.println(" The default JAXP implementation to use of the JDK");
System.out.println(" -version Print version and exit\n");
Expand All @@ -105,7 +102,6 @@ public static void main(String[] args) throws Throwable {
String deps = null;
String[] moduleArgs = NO_STRINGS;
String modulePath = null;
String configPath = null;
String classpath = null;
boolean jar = false;
boolean classpathDefined = false;
Expand All @@ -130,22 +126,11 @@ public static void main(String[] args) throws Throwable {
System.err.println("Module path may only be specified once");
System.exit(1);
}
if (configPath != null) {
System.err.println("Module path may not be specified with config path");
System.exit(1);
}
modulePath = args[++i];
System.setProperty("module.path", modulePath);
} else if ("-config".equals(arg)) {
if (configPath != null) {
System.err.println("Config file path may only be specified once");
System.exit(1);
}
if (modulePath != null) {
System.err.println("Module path may not be specified with config path");
System.exit(1);
}
configPath = args[++i];
System.err.println("Config files are no longer supported. Use the -mp option instead");
System.exit(1);
} else if ("-jaxpmodule".equals(arg)) {
jaxpModuleIdentifier = ModuleIdentifier.fromString(args[++i]);
} else if ("-jar".equals(arg)) {
Expand Down Expand Up @@ -260,11 +245,7 @@ public static void main(String[] args) throws Throwable {
}
final ModuleLoader loader;
final ModuleLoader environmentLoader;
if (configPath != null) {
environmentLoader = ModuleXmlParser.parseModuleConfigXml(new File(configPath));
} else {
environmentLoader = DefaultBootModuleLoaderHolder.INSTANCE;
}
environmentLoader = DefaultBootModuleLoaderHolder.INSTANCE;
final ModuleIdentifier moduleIdentifier;
if (jar) {
loader = new JarModuleLoader(environmentLoader, new JarFile(moduleIdentifierOrExeName));
Expand Down
195 changes: 0 additions & 195 deletions src/main/java/org/jboss/modules/ModuleXmlParser.java
Expand Up @@ -38,8 +38,6 @@
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -255,20 +253,6 @@ public ResourceLoader createResourceLoader(final String rootPath, final String l
}
}

static ModuleLoader parseModuleConfigXml(final File moduleConfigFile) {
final FileInputStream fis;
try {
fis = new FileInputStream(moduleConfigFile);
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("No module-config.xml file found at " + moduleConfigFile);
}
try {
return parseModuleConfigXml(moduleConfigFile.getPath(), fis);
} finally {
safeClose(fis);
}
}

private static void setIfSupported(XMLInputFactory inputFactory, String property, Object value) {
if (inputFactory.isPropertySupported(property)) {
inputFactory.setProperty(property, value);
Expand All @@ -293,22 +277,6 @@ static ModuleSpec parseModuleXml(final ResourceRootFactory factory, final String
}
}

private static ModuleLoader parseModuleConfigXml(final String configFilePath, final InputStream source) {
try {
final XMLInputFactory inputFactory = INPUT_FACTORY;
setIfSupported(inputFactory, XMLInputFactory.IS_VALIDATING, Boolean.FALSE);
setIfSupported(inputFactory, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
final XMLStreamReader streamReader = inputFactory.createXMLStreamReader(source);
try {
return parseConfigDocument(streamReader);
} finally {
safeClose(streamReader);
}
} catch (XMLStreamException e) {
throw new IllegalArgumentException("Error loading module configuration from " + configFilePath, e);
}
}

private static void safeClose(final Closeable closeable) {
if (closeable != null) try {
closeable.close();
Expand Down Expand Up @@ -371,169 +339,6 @@ private static XMLStreamException missingAttributes(final Location location, fin
return new XMLStreamException(b.toString(), location);
}

private static XMLStreamException noSuchLoader(final XMLStreamReader reader, final String loader) {
return new XMLStreamException("No such loader found named '" + loader + "'", reader.getLocation());
}

private static XMLStreamException selfImport(final XMLStreamReader reader, final String loader) {
return new XMLStreamException("Module loader '" + loader + "' imports itself", reader.getLocation());
}

private static XMLStreamException duplicateLoader(final XMLStreamReader reader, final String loader) {
return new XMLStreamException("Multiple loaders defined named '" + loader + "'", reader.getLocation());
}

private static ModuleLoader parseConfigDocument(XMLStreamReader reader) throws XMLStreamException {
while (reader.hasNext()) {
switch (reader.nextTag()) {
case START_DOCUMENT: {
return parseConfigRootElement(reader);
}
case START_ELEMENT: {
if (Element.of(reader.getName()) != Element.CONFIGURATION) {
throw unexpectedContent(reader);
}
return parseConfigRootElementContents(reader);
}
default: {
throw unexpectedContent(reader);
}
}
}
throw endOfDocument(reader.getLocation());
}

private static ModuleLoader parseConfigRootElement(final XMLStreamReader reader) throws XMLStreamException {
while (reader.hasNext()) {
switch (reader.nextTag()) {
case START_ELEMENT: {
if (Element.of(reader.getName()) != Element.CONFIGURATION) {
throw unexpectedContent(reader);
}
return parseConfigRootElementContents(reader);
}
default: {
throw unexpectedContent(reader);
}
}
}
throw endOfDocument(reader.getLocation());
}

private static ModuleLoader parseConfigRootElementContents(final XMLStreamReader reader) throws XMLStreamException {
final int count = reader.getAttributeCount();
String defaultLoader = null;
final Set<Attribute> required = EnumSet.of(Attribute.DEFAULT_LOADER);
for (int i = 0; i < count; i ++) {
final Attribute attribute = Attribute.of(reader.getAttributeName(i));
required.remove(attribute);
switch (attribute) {
case DEFAULT_LOADER: defaultLoader = reader.getAttributeValue(i); break;
default: throw unexpectedContent(reader);
}
}
if (! required.isEmpty() || defaultLoader == null) {
throw missingAttributes(reader.getLocation(), required);
}
final Map<String, LocalModuleLoader> moduleLoaderMap = new HashMap<String, LocalModuleLoader>();
final Map<String, Set<String>> importsMap = new HashMap<String, Set<String>>();
while (reader.hasNext()) {
switch (reader.nextTag()) {
case START_ELEMENT: {
switch (Element.of(reader.getName())) {
case LOADER: {
parseConfigLoaderElement(reader, moduleLoaderMap, importsMap);
break;
}
default: throw unexpectedContent(reader);
}
break;
}
case END_ELEMENT: {
ModuleLoader loader = moduleLoaderMap.get(defaultLoader);
if (loader == null) {
throw noSuchLoader(reader, defaultLoader);
}
for (Map.Entry<String, Set<String>> entry : importsMap.entrySet()) {
String key = entry.getKey();
Set<String> value = entry.getValue();
LocalModuleLoader moduleLoader = moduleLoaderMap.get(key);
assert moduleLoader != null;
final ModuleLoader[] importedLoaders = new ModuleLoader[value.size()];
int i = 0;
for (String importName : value) {
LocalModuleLoader importedLoader = moduleLoaderMap.get(importName);
if (importedLoader == null) {
throw noSuchLoader(reader, importName);
}
if (importName.equals(key)) {
throw selfImport(reader, importName);
}
importedLoaders[i++] = importedLoader;
}
moduleLoader.setImportLoaders(importedLoaders);
}
return loader;
}
default: {
throw unexpectedContent(reader);
}
}
}
throw endOfDocument(reader.getLocation());
}

private static void parseConfigLoaderElement(final XMLStreamReader reader, final Map<String, LocalModuleLoader> map, final Map<String, Set<String>> importsMap) throws XMLStreamException {
final Set<String> roots = new HashSet<String>();
final Set<String> imports = new LinkedHashSet<String>();
final int count = reader.getAttributeCount();
String name = null;
final Set<Attribute> required = EnumSet.of(Attribute.NAME);
for (int i = 0; i < count; i ++) {
final Attribute attribute = Attribute.of(reader.getAttributeName(i));
required.remove(attribute);
switch (attribute) {
case NAME: name = reader.getAttributeValue(i); break;
default: throw unexpectedContent(reader);
}
}
if (! required.isEmpty() || name == null) {
throw missingAttributes(reader.getLocation(), required);
}
if (map.containsKey(name)) {
throw duplicateLoader(reader, name);
}
while (reader.hasNext()) {
switch (reader.nextTag()) {
case START_ELEMENT: {
switch (Element.of(reader.getName())) {
case MODULE_PATH: {
parsePathName(reader, roots);
break;
}
case IMPORT: {
// it's not really a path name, but whatever works
parsePathName(reader, imports);
break;
}
}
break;
}
case END_ELEMENT: {
File[] files = new File[roots.size()];
int i = 0;
for (String root : roots) {
files[i++] = new File(root);
}
map.put(name, new LocalModuleLoader(files));
importsMap.put(name, imports);
return;
}
default: throw unexpectedContent(reader);
}
}
}

private static ModuleSpec parseDocument(final ResourceRootFactory factory, final String rootPath, XMLStreamReader reader, final ModuleIdentifier moduleIdentifier) throws XMLStreamException {
while (reader.hasNext()) {
switch (reader.nextTag()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/schema/module-1_1.xsd
Expand Up @@ -2,7 +2,7 @@

<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2011, Red Hat, Inc., and individual contributors
~ Copyright 2012, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
Expand Down

0 comments on commit 62fab25

Please sign in to comment.