langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/ModulesXmlReader.java
author chegar
Sun, 17 Aug 2014 15:52:32 +0100
changeset 25874 83c19f00452c
child 26276 0dca2378aa34
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
     1
/*
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
     4
 *
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    10
 *
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    15
 * accompanied this code).
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    16
 *
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    20
 *
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    23
 * questions.
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    24
 */
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    25
package com.sun.tools.jdeps;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    26
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    27
import com.sun.tools.classfile.ClassFile;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    28
import com.sun.tools.jdeps.PlatformClassPath.LegacyImageHelper;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    29
import java.io.IOException;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    30
import java.io.InputStream;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    31
import java.nio.file.Files;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    32
import java.nio.file.Path;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    33
import java.util.Collections;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    34
import java.util.HashSet;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    35
import java.util.List;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    36
import java.util.Set;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    37
import javax.xml.namespace.QName;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    38
import javax.xml.stream.XMLEventReader;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    39
import javax.xml.stream.XMLInputFactory;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    40
import javax.xml.stream.XMLStreamException;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    41
import javax.xml.stream.events.Attribute;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    42
import javax.xml.stream.events.XMLEvent;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    43
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    44
abstract class ModulesXmlReader {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    45
    abstract ClassFileReader getClassFileReader(String modulename, Set<String> packages)
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    46
        throws IOException;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    47
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    48
    static class ImageReader extends ModulesXmlReader {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    49
        final LegacyImageHelper helper;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    50
        ImageReader(LegacyImageHelper helper) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    51
            this.helper = helper;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    52
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    53
        ClassFileReader getClassFileReader(String modulename, Set<String> packages)
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    54
            throws IOException
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    55
        {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    56
            return helper.getClassReader(modulename, packages);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    57
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    58
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    59
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    60
    static class ModulePathReader extends ModulesXmlReader {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    61
        final Path mpath;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    62
        final ClassFileReader defaultReader;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    63
        ModulePathReader(Path mp) throws IOException {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    64
            this.mpath = mp;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    65
            this.defaultReader = new NonExistModuleReader(mpath);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    66
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    67
        ClassFileReader getClassFileReader(String modulename, Set<String> packages)
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    68
            throws IOException
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    69
        {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    70
            Path mdir = mpath.resolve(modulename);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    71
            if (Files.exists(mdir) && Files.isDirectory(mdir)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    72
                return ClassFileReader.newInstance(mdir);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    73
            } else {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    74
                // aggregator module or os-specific module in modules.xml
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    75
                // mdir not exist
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    76
                return defaultReader;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    77
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    78
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    79
        class NonExistModuleReader extends ClassFileReader {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    80
            private final List<ClassFile> classes = Collections.emptyList();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    81
            private NonExistModuleReader(Path mpath) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    82
                super(mpath);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    83
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    84
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    85
            public ClassFile getClassFile(String name) throws IOException {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    86
                return null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    87
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    88
            public Iterable<ClassFile> getClassFiles() throws IOException {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    89
                return classes;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    90
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    91
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    92
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    93
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    94
    public static Set<Module> load(Path mpath, InputStream in)
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    95
        throws IOException
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    96
    {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    97
        try {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    98
            ModulePathReader reader = new ModulePathReader(mpath);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
    99
            return reader.load(in);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   100
        } catch (XMLStreamException e) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   101
            throw new RuntimeException(e);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   102
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   103
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   104
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   105
    public static Set<Module> loadFromImage(LegacyImageHelper helper, InputStream in)
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   106
        throws IOException
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   107
    {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   108
        try {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   109
            ImageReader reader = new ImageReader(helper);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   110
            return reader.load(in);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   111
        } catch (XMLStreamException e) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   112
            throw new RuntimeException(e);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   113
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   114
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   115
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   116
    private static final String MODULES   = "modules";
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   117
    private static final String MODULE    = "module";
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   118
    private static final String NAME      = "name";
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   119
    private static final String DEPEND    = "depend";
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   120
    private static final String EXPORT    = "export";
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   121
    private static final String TO        = "to";
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   122
    private static final String INCLUDE   = "include";
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   123
    private static final QName  REEXPORTS = new QName("re-exports");
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   124
    public Set<Module> load(InputStream in) throws XMLStreamException, IOException {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   125
        Set<Module> modules = new HashSet<>();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   126
        if (in == null) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   127
            System.err.println("WARNING: modules.xml doesn't exist");
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   128
            return modules;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   129
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   130
        XMLInputFactory factory = XMLInputFactory.newInstance();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   131
        XMLEventReader reader = factory.createXMLEventReader(in, "UTF-8");
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   132
        Module.Builder mb = null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   133
        String modulename = null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   134
        String exportedPackage = null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   135
        Set<String> permits = new HashSet<>();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   136
        while (reader.hasNext()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   137
            XMLEvent event = reader.nextEvent();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   138
            if (event.isStartElement()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   139
                String startTag = event.asStartElement().getName().getLocalPart();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   140
                switch (startTag) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   141
                    case MODULES:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   142
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   143
                    case MODULE:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   144
                        if (mb != null) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   145
                            throw new RuntimeException("end tag for module is missing");
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   146
                        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   147
                        modulename = getNextTag(reader, NAME);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   148
                        mb = new Module.Builder();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   149
                        mb.name(modulename);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   150
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   151
                    case NAME:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   152
                        throw new RuntimeException(event.toString());
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   153
                    case DEPEND:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   154
                        boolean reexports = false;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   155
                        Attribute attr = event.asStartElement().getAttributeByName(REEXPORTS);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   156
                        if (attr != null) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   157
                            String value = attr.getValue();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   158
                            if (value.equals("true") || value.equals("false")) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   159
                                reexports = Boolean.parseBoolean(value);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   160
                            } else {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   161
                                throw new RuntimeException("unexpected attribute " + attr.toString());
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   162
                            }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   163
                        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   164
                        mb.require(getData(reader), reexports);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   165
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   166
                    case INCLUDE:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   167
                        mb.include(getData(reader));
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   168
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   169
                    case EXPORT:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   170
                        exportedPackage = getNextTag(reader, NAME);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   171
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   172
                    case TO:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   173
                        permits.add(getData(reader));
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   174
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   175
                    default:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   176
                        throw new RuntimeException("invalid element: " + event);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   177
                }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   178
            } else if (event.isEndElement()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   179
                String endTag = event.asEndElement().getName().getLocalPart();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   180
                switch (endTag) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   181
                    case MODULE:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   182
                        ClassFileReader cfr = getClassFileReader(modulename, mb.packages);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   183
                        mb.classes(cfr);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   184
                        modules.add(mb.build());
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   185
                        mb = null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   186
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   187
                    case EXPORT:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   188
                        if (exportedPackage == null) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   189
                            throw new RuntimeException("export's name is missing");
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   190
                        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   191
                        mb.export(exportedPackage, permits);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   192
                        exportedPackage = null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   193
                        permits.clear();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   194
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   195
                    default:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   196
                }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   197
            } else if (event.isCharacters()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   198
                String s = event.asCharacters().getData();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   199
                if (!s.trim().isEmpty()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   200
                    throw new RuntimeException("export-to is malformed");
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   201
                }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   202
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   203
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   204
        return modules;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   205
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   206
    private String getData(XMLEventReader reader) throws XMLStreamException {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   207
        XMLEvent e = reader.nextEvent();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   208
        if (e.isCharacters()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   209
            return e.asCharacters().getData();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   210
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   211
        throw new RuntimeException(e.toString());
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   212
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   213
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   214
    private String getNextTag(XMLEventReader reader, String tag) throws XMLStreamException {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   215
        XMLEvent e = reader.nextTag();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   216
        if (e.isStartElement()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   217
            String t = e.asStartElement().getName().getLocalPart();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   218
            if (!tag.equals(t)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   219
                throw new RuntimeException(e + " expected: " + tag);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   220
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   221
            return getData(reader);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   222
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   223
        throw new RuntimeException("export-to name is missing:" + e);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   224
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   225
}