|
| 1 | +package org.jvnet.jaxb2_commons.tests.issues; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | +import java.net.URL; |
| 5 | + |
| 6 | +import org.junit.Before; |
| 7 | +import org.junit.Test; |
| 8 | + |
| 9 | +import com.sun.codemodel.JCodeModel; |
| 10 | +import com.sun.tools.xjc.ConsoleErrorReporter; |
| 11 | +import com.sun.tools.xjc.ModelLoader; |
| 12 | +import com.sun.tools.xjc.Options; |
| 13 | +import com.sun.tools.xjc.model.Model; |
| 14 | + |
| 15 | +public class RunPlugins { |
| 16 | + |
| 17 | + @Before |
| 18 | + public void setUp() { |
| 19 | + System.setProperty("javax.xml.accessExternalSchema", "all"); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void compilesSchema() throws Exception { |
| 24 | + |
| 25 | + new File("target/generated-sources/xjc").mkdirs(); |
| 26 | + |
| 27 | + URL schema = getClass().getResource("/schema.xsd"); |
| 28 | + URL binding = getClass().getResource("/binding.xjb"); |
| 29 | + final String[] arguments = new String[] { "-xmlschema", |
| 30 | + schema.toExternalForm(), "-b", binding.toExternalForm(), "-d", |
| 31 | + "target/generated-sources/xjc", "-extension", "-XhashCode", |
| 32 | + "-Xequals", "-XtoString", "-Xcopyable", "-Xmergeable", "-Xinheritance", "-Xwildcard" |
| 33 | + // "-XsimpleToString" |
| 34 | + |
| 35 | + }; |
| 36 | + |
| 37 | + Options options = new Options(); |
| 38 | + options.parseArguments(arguments); |
| 39 | + ConsoleErrorReporter receiver = new ConsoleErrorReporter(); |
| 40 | + Model model = ModelLoader.load(options, new JCodeModel(), receiver); |
| 41 | + model.generateCode(options, receiver); |
| 42 | + com.sun.codemodel.CodeWriter cw = options.createCodeWriter(); |
| 43 | + model.codeModel.build(cw); |
| 44 | + } |
| 45 | +} |
0 commit comments