langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/ModulesXmlReader.java
author attila
Wed, 01 Oct 2014 10:26:25 +0200
changeset 26888 2722a9c501a5
parent 26276 0dca2378aa34
child 27579 d1a63c99cdd5
permissions -rw-r--r--
8059370: Unnecessary work in deoptimizing recompilation Reviewed-by: jlaskey, lagergren
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 {
26276
0dca2378aa34 8055856: checkdeps build target doesn't work for cross-compilation builds
mchung
parents: 25874
diff changeset
    74
                // aggregator module or os-specific module in jdeps-modules.xml
25874
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) {
26276
0dca2378aa34 8055856: checkdeps build target doesn't work for cross-compilation builds
mchung
parents: 25874
diff changeset
   127
            throw new RuntimeException("jdeps-modules.xml doesn't exist");
25874
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   128
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   129
        XMLInputFactory factory = XMLInputFactory.newInstance();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   130
        XMLEventReader reader = factory.createXMLEventReader(in, "UTF-8");
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   131
        Module.Builder mb = null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   132
        String modulename = null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   133
        String exportedPackage = null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   134
        Set<String> permits = new HashSet<>();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   135
        while (reader.hasNext()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   136
            XMLEvent event = reader.nextEvent();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   137
            if (event.isStartElement()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   138
                String startTag = event.asStartElement().getName().getLocalPart();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   139
                switch (startTag) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   140
                    case MODULES:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   141
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   142
                    case MODULE:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   143
                        if (mb != null) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   144
                            throw new RuntimeException("end tag for module is missing");
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   145
                        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   146
                        modulename = getNextTag(reader, NAME);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   147
                        mb = new Module.Builder();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   148
                        mb.name(modulename);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   149
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   150
                    case NAME:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   151
                        throw new RuntimeException(event.toString());
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   152
                    case DEPEND:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   153
                        boolean reexports = false;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   154
                        Attribute attr = event.asStartElement().getAttributeByName(REEXPORTS);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   155
                        if (attr != null) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   156
                            String value = attr.getValue();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   157
                            if (value.equals("true") || value.equals("false")) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   158
                                reexports = Boolean.parseBoolean(value);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   159
                            } else {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   160
                                throw new RuntimeException("unexpected attribute " + attr.toString());
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   161
                            }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   162
                        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   163
                        mb.require(getData(reader), reexports);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   164
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   165
                    case INCLUDE:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   166
                        mb.include(getData(reader));
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   167
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   168
                    case EXPORT:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   169
                        exportedPackage = getNextTag(reader, NAME);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   170
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   171
                    case TO:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   172
                        permits.add(getData(reader));
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   173
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   174
                    default:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   175
                        throw new RuntimeException("invalid element: " + event);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   176
                }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   177
            } else if (event.isEndElement()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   178
                String endTag = event.asEndElement().getName().getLocalPart();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   179
                switch (endTag) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   180
                    case MODULE:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   181
                        ClassFileReader cfr = getClassFileReader(modulename, mb.packages);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   182
                        mb.classes(cfr);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   183
                        modules.add(mb.build());
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   184
                        mb = null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   185
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   186
                    case EXPORT:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   187
                        if (exportedPackage == null) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   188
                            throw new RuntimeException("export's name is missing");
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   189
                        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   190
                        mb.export(exportedPackage, permits);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   191
                        exportedPackage = null;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   192
                        permits.clear();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   193
                        break;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   194
                    default:
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   195
                }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   196
            } else if (event.isCharacters()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   197
                String s = event.asCharacters().getData();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   198
                if (!s.trim().isEmpty()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   199
                    throw new RuntimeException("export-to is malformed");
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   200
                }
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
        return modules;
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   204
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   205
    private String getData(XMLEventReader reader) throws XMLStreamException {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   206
        XMLEvent e = reader.nextEvent();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   207
        if (e.isCharacters()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   208
            return e.asCharacters().getData();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   209
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   210
        throw new RuntimeException(e.toString());
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   211
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   212
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   213
    private String getNextTag(XMLEventReader reader, String tag) throws XMLStreamException {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   214
        XMLEvent e = reader.nextTag();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   215
        if (e.isStartElement()) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   216
            String t = e.asStartElement().getName().getLocalPart();
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   217
            if (!tag.equals(t)) {
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   218
                throw new RuntimeException(e + " expected: " + tag);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   219
            }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   220
            return getData(reader);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   221
        }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   222
        throw new RuntimeException("export-to name is missing:" + e);
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   223
    }
83c19f00452c 8054834: Modular Source Code
chegar
parents:
diff changeset
   224
}