public int run()

in cxf-xjc-plugin/src/main/java/org/apache/cxf/maven_plugin/XSDToJavaRunner.java [97:195]


    public int run() throws Exception {
        List<URL> urls = new ArrayList<URL>();
        for (String s : cpList) {
            File file = getFile(s, listener);
            if (file != null) {
                urls.add(file.toURI().toURL());
            }
        }
        for (int x = 0; x < args.length - 1; x++) {
            if ("-classpath".equals(args[x])) {
                File file = getFile(args[x + 1], listener);
                if (file != null && file.exists()) {
                    cpList.add(file.getAbsolutePath());
                    urls.add(file.getAbsoluteFile().toURI().toURL());
                }
                x++;
            }
        }

        try (URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[0]),
                                                      this.getClass().getClassLoader())) {
            final CatalogManager cm = new CatalogManager();
            cm.setUseStaticCatalog(false);
            cm.setIgnoreMissingProperties(true);
            final CatalogResolver catResolver = new CatalogResolver(cm) {
                public InputSource resolveEntity(String publicId, String systemId) {
                    final String resolved = getResolvedEntity(publicId, systemId);
                    if (resolved == null) {
                        return null;
                    }
                    InputSource iSource = new InputSource((systemId != null) ? systemId : resolved);
                    iSource.setPublicId(publicId);
                    try {
                        final URL url;
                        if (resolved.startsWith("classpath:")) {
                            url = loader.getResource(resolved.substring("classpath:".length()));
                            iSource.setSystemId(url.toExternalForm());
                        } else {
                            url = new URL(resolved);
                        }
                        InputStream iStream = url.openStream();
                        iSource.setByteStream(iStream);

                        //System.out.println("Resolved: " + publicId + " " + systemId + " " + url);
                        return iSource;
                    } catch (Exception e) {
                        listener.warning(xsdFile, e);
                        return null;
                    }
                }
            };
            final Options opt = new Options() {
                @Override
                public void addCatalog(File catalogFile) throws IOException {
                    if (entityResolver == null) {
                        entityResolver = catResolver;
                    }
                    catResolver.getCatalog().parseCatalog(catalogFile.getPath());
                }
            };

            for (URL url : urls) {
                opt.classpaths.add(url);
            }
            if (checkXmlElementRef()) {
                opt.target = SpecVersion.V2_3;
            }
            opt.setSchemaLanguage(Language.XMLSCHEMA);
            // set up the context class loader so that the user-specified plugin
            // on classpath can be loaded from there with jaxb-xjc 2.3.0
            ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
            try {
                Thread.currentThread().setContextClassLoader(opt.getUserClassLoader(origLoader));
                opt.parseArguments(args);
            } finally {
                Thread.currentThread().setContextClassLoader(origLoader);
            }
            Model model = loadModel(opt); 
            if (model == null) {
                listener.message(xsdFile, "Failed to create model");
                return -1;
            }
            Outline outline = model.generateCode(opt, listener);
            if (outline == null) {
                listener.message(xsdFile, "Failed to generate code");
                return -1;
            }

            // then print them out
            try {
                CodeWriter cw = opt.createCodeWriter();
                model.codeModel.build(cw);
            } catch (IOException e) {
                listener.error(e);
                return -1;
            }
        }
        return 0;
    }