Package com.alibaba.antx.config

Examples of com.alibaba.antx.config.ConfigException


        Scanner scanner = new DirectoryScanner(getConfigEntryResource().getFile(), handler);

        try {
            scanner.scan();
        } catch (ScannerException e) {
            throw new ConfigException(e);
        }

        subEntries = handler.getSubEntries();

        getGenerator().init();
View Full Code Here


        String componentName = "";

        try {
            componentNamePattern = new PathNameCompiler().compile("META-INF/**/autoconf/auto-config.xml");
        } catch (MalformedPatternException e) {
            throw new ConfigException(e);
        }

        if (matcher.matches(name.replace('\\', '/'), componentNamePattern)) {
            componentName = matcher.getMatch().group(1);
        }
View Full Code Here

        scanner.setInputStream(istream);

        try {
            scanner.scan();
        } catch (ScannerException e) {
            throw new ConfigException(e);
        }

        subEntries = handler.getSubEntries();

        getGenerator().init();
View Full Code Here

            if (ostream == null) {
                if (outputFile == null) {
                    destfile = getConfigEntryResource().getFile();

                    if (destfile == null || !destfile.exists()) {
                        throw new ConfigException("Could not find " + getConfigEntryResource().getURL());
                    }

                    outputFile = new File(destfile.getParentFile(), destfile.getName() + ".tmp");
                }

                outputFile.getParentFile().mkdirs();

                ostream = new BufferedOutputStream(new FileOutputStream(outputFile), 8192);
                needCloseOutputStream = true;
            }

            // 检查或打开istream
            if (istream == null) {
                istream = getConfigEntryResource().getURL().openStream();

                if (!(istream instanceof BufferedInputStream)) {
                    istream = new BufferedInputStream(istream, 8192);
                }

                needCloseInputStream = true;
            }

            zis = new ZipInputStream(istream);
            zos = new ZipOutputStream(ostream);

            ZipEntry zipEntry;

            getGenerator().startSession(getConfigSettings().getPropertiesSet());

            while ((zipEntry = zis.getNextEntry()) != null) {
                allSuccess &= processZipEntry(zipEntry, zis, zos, dirs);
            }

            allSuccess &= getGenerator().getSession().generateLazyItems(new ZipCallback(zos, dirs));

            getGenerator().getSession().checkNonprocessedTemplates();
            getGenerator().getSession().generateLog(new ZipCallback(zos, dirs));

            success = true;
        } catch (IOException e) {
            throw new ConfigException(e);
        } finally {
            getGenerator().closeSession();

            // 结束zip文件,但不关闭流
            if (zos != null) {
                try {
                    zos.finish();
                } catch (IOException e) {
                }
            }

            // 仅当输入流是由当前entry亲自打开的,才关闭流
            if (needCloseInputStream && istream != null) {
                try {
                    istream.close();
                } catch (IOException e) {
                }
            }

            // 仅当输出流是由当前entry亲自打开的,才关闭流
            if (needCloseOutputStream && ostream != null) {
                try {
                    ostream.flush();
                    ostream.close();
                } catch (IOException e) {
                }

                // 如果成功,则将临时文件改成正式文件,否则删除临时文件
                if (success) {
                    // 仅当没有指定outputFile时才做下面的事
                    if (getOutputFile() == null) {
                        // 在windows下,观察到rename失败,因为lock的原因。过一会重试。
                        int retryTimes = 10;
                        boolean succ = false;
                        String message = String.format("Moving file %s to %s failed.", outputFile.getName(),
                                                       destfile.getName());

                        for (int i = 0; i < retryTimes; i++) {
                            destfile.delete();
                            succ = outputFile.renameTo(destfile);

                            if (succ) {
                                break;
                            }

                            getConfigSettings().warn(
                                    String.format(message + "  Wait 0.5s and try again...%d of %d", i + 1, retryTimes));

                            try {
                                System.gc();
                                Thread.sleep(500);
                            } catch (InterruptedException e) {
                            }
                        }

                        if (!succ) {
                            throw new ConfigException(message);
                        }
                    }
                } else {
                    outputFile.delete();
                }
View Full Code Here

        public void nextEntry(ConfigDescriptor descriptor, InputStream is, String dest) {
            try {
                makeParentDirs(dest);
                zos.putNextEntry(new ZipEntry(dest));
            } catch (IOException e) {
                throw new ConfigException(e);
            }

            getGenerator().getSession().setInputStream(is);
            getGenerator().getSession().setOutputStream(zos);
        }
View Full Code Here

        public void logEntry(ConfigDescriptor descriptor, String logfileName) {
            try {
                makeParentDirs(logfileName);
                zos.putNextEntry(new ZipEntry(logfileName));
            } catch (IOException e) {
                throw new ConfigException(e);
            }

            getGenerator().getSession().setOutputStream(zos);
        }
View Full Code Here

        // 执行初始化.
        try {
            engine.init();
        } catch (Exception e) {
            throw new ConfigException(e);
        }
    }
View Full Code Here

        File templateFile = new File(templateBase, base + template);
        File templateFileInPlace = new File(templateBase, template);

        if (!templateFile.exists()) {
            if (!templateFileInPlace.exists()) {
                throw new ConfigException("Could not find template file: " + templateFileInPlace.getAbsolutePath()
                                          + " for descriptor: " + descriptor.getURL());
            }

            if (templateFileInPlace.getAbsolutePath().equals(destFile.getAbsolutePath())) {
                templateFile.getParentFile().mkdirs();

                try {
                    StreamUtil.io(new FileInputStream(templateFileInPlace), new FileOutputStream(templateFile), true,
                                  true);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } else {
                templateFile = templateFileInPlace;
            }
        } else {
            template = base + template;
        }

        // 创建destFile的父目录
        File destBase = destFile.getParentFile();

        destBase.mkdirs();

        if (!destBase.isDirectory()) {
            throw new ConfigException("Could not create directory: " + destBase.getAbsolutePath());
        }

        try {
            istream = new BufferedInputStream(new FileInputStream(templateFile), 8192);
            ostream = new BufferedOutputStream(new FileOutputStream(destFile), 8192);
        } catch (FileNotFoundException e) {
            throw new ConfigException(e);
        }

        generator.getSession().setInputStream(istream);
        generator.getSession().setOutputStream(ostream);
View Full Code Here

        File logbase = logfile.getParentFile();

        logbase.mkdirs();

        if (!logbase.isDirectory()) {
            throw new ConfigException("Could not create directory: " + logbase.getAbsolutePath());
        }

        try {
            ostream = new BufferedOutputStream(new FileOutputStream(logfile), 8192);
        } catch (FileNotFoundException e) {
            throw new ConfigException(e);
        }

        generator.getSession().setOutputStream(ostream);
    }
View Full Code Here

                username = StringUtil.trimWhitespace(resourceManager.getIn().readLine());
            }

            password = new PasswordField().getPassword(resourceManager.getOut(), "Enter Password: ", message);
        } catch (IOException e) {
            throw new ConfigException(e);
        }

        savePassword(uri, username, password);

        return new UsernamePassword(username, password);
View Full Code Here

TOP

Related Classes of com.alibaba.antx.config.ConfigException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.