Package org.springframework.roo.process.manager

Examples of org.springframework.roo.process.manager.MutableFile


    private void updateWebXml(Element pConfiguration, boolean pAddjsr160proxy, boolean pAdddefaultinitparams) {
        InputStream is = null;
        try {
            String webXml = pathResolver.getIdentifier(Path.SRC_MAIN_WEBAPP, "WEB-INF/web.xml");
            if (fileManager.exists(webXml)) {
                MutableFile mutableWebXml = fileManager.updateFile(webXml);
                is = mutableWebXml.getInputStream();
                Document webXmlDoc = XmlUtils.getDocumentBuilder().parse(is);

                // Adapt web.xml
                updateServletDefinition(pConfiguration, pAdddefaultinitparams, webXmlDoc);

                // (Optional) Add JSR-160 proxy handler
                if (pAddjsr160proxy) {
                    updateJsr160Proxy(pConfiguration,webXmlDoc);
                }

                XmlUtils.writeXml(mutableWebXml.getOutputStream(), webXmlDoc);
            } else {
                throw new IllegalStateException("Could not acquire " + webXml);
            }
        } catch (Exception exp) {
            throw new IllegalStateException(exp);
View Full Code Here


        InputStream is = null;
        try {
            String webXml = pathResolver.getIdentifier(Path.SRC_MAIN_WEBAPP.getModulePathId(projectOperations.getFocusedModuleName()),
                                                       "WEB-INF/web.xml");
            if (fileManager.exists(webXml)) {
                MutableFile mutableWebXml = fileManager.updateFile(webXml);
                is = mutableWebXml.getInputStream();
                Document webXmlDoc = XmlUtils.getDocumentBuilder().parse(is);

                // Adapt web.xml
                updateServletDefinition(pConfiguration, pAdddefaultinitparams, webXmlDoc);

                // (Optional) Add JSR-160 proxy handler
                if (pAddjsr160proxy) {
                    updateJsr160Proxy(pConfiguration,webXmlDoc);
                }

                XmlUtils.writeXml(mutableWebXml.getOutputStream(), webXmlDoc);
            } else {
                throw new IllegalStateException("Could not acquire " + webXml);
            }
        } catch (Exception exp) {
            throw new IllegalStateException(exp);
View Full Code Here

        Validate.notBlank(propertyFilename, "Property filename required");
        Validate.notBlank(key, "Key required");

        final String filePath = projectOperations.getPathResolver()
                .getIdentifier(propertyFilePath, propertyFilename);
        MutableFile mutableFile = null;
        final Properties props = new Properties();

        if (fileManager.exists(filePath)) {
            mutableFile = fileManager.updateFile(filePath);
            loadProperties(props, mutableFile.getInputStream());
        }
        else {
            return null;
        }
View Full Code Here

        Validate.notBlank(propertyFilename, "Property filename required");
        Validate.notNull(properties, "Property map required");

        final String filePath = projectOperations.getPathResolver()
                .getIdentifier(propertyFilePath, propertyFilename);
        MutableFile mutableFile = null;

        Properties props;
        if (sorted) {
            props = new Properties() {
                private static final long serialVersionUID = 1L;

                // Override the keys() method to order the keys alphabetically
                @SuppressWarnings("all")
                public synchronized Enumeration keys() {
                    final Object[] keys = keySet().toArray();
                    Arrays.sort(keys);
                    return new Enumeration() {
                        int i = 0;

                        public boolean hasMoreElements() {
                            return i < keys.length;
                        }

                        public Object nextElement() {
                            return keys[i++];
                        }
                    };
                }
            };
        }
        else {
            props = new Properties();
        }

        if (fileManager.exists(filePath)) {
            mutableFile = fileManager.updateFile(filePath);
            loadProperties(props, mutableFile.getInputStream());
        }
        else {
            // Unable to find the file, so let's create it
            mutableFile = fileManager.createFile(filePath);
        }

        boolean saveNeeded = false;
        for (final Entry<String, String> entry : properties.entrySet()) {
            final String key = entry.getKey();
            final String newValue = entry.getValue();
            final String existingValue = props.getProperty(key);
            if (existingValue == null || !existingValue.equals(newValue)
                    && changeExisting) {
                props.setProperty(key, newValue);
                saveNeeded = true;
            }
        }

        if (saveNeeded) {
            storeProps(props, mutableFile.getOutputStream(), "Updated at "
                    + new Date());
        }
    }
View Full Code Here

        Validate.notBlank(propertyFilename, "Property filename required");
        Validate.notBlank(key, "Key required");

        final String filePath = projectOperations.getPathResolver()
                .getIdentifier(propertyFilePath, propertyFilename);
        MutableFile mutableFile = null;
        final Properties props = new Properties();

        if (fileManager.exists(filePath)) {
            mutableFile = fileManager.updateFile(filePath);
            loadProperties(props, mutableFile.getInputStream());
        }
        else {
            throw new IllegalStateException("Properties file not found");
        }

        props.remove(key);

        storeProps(props, mutableFile.getOutputStream(), "Updated at "
                + new Date());
    }
View Full Code Here

                Path.SRC_MAIN_RESOURCES, "log4j.properties");
        if (!fileManager.exists(log4jPath)) {
            return;
        }

        final MutableFile log4jMutableFile = fileManager.updateFile(log4jPath);
        final Properties props = new Properties();
        OutputStream outputStream = null;
        try {
            props.load(log4jMutableFile.getInputStream());
            final String dnKey = "log4j.category.DataNucleus";
            if (ormProvider == OrmProvider.DATANUCLEUS
                    && !props.containsKey(dnKey)) {
                outputStream = log4jMutableFile.getOutputStream();
                props.put(dnKey, "WARN");
                props.store(outputStream, "Updated at " + new Date());
            }
            else if (ormProvider != OrmProvider.DATANUCLEUS
                    && props.containsKey(dnKey)) {
                outputStream = log4jMutableFile.getOutputStream();
                props.remove(dnKey);
                props.store(outputStream, "Updated at " + new Date());
            }
        }
        catch (final IOException e) {
View Full Code Here

    private void writeProperties(final String path, final boolean exists,
            final Properties props) {
        OutputStream outputStream = null;
        try {
            final MutableFile mutableFile = exists ? fileManager
                    .updateFile(path) : fileManager.createFile(path);
            outputStream = mutableFile == null ? new FileOutputStream(path)
                    : mutableFile.getOutputStream();
            props.store(outputStream, "Updated at " + new Date());
        }
        catch (final IOException e) {
            throw new IllegalStateException(e);
        }
View Full Code Here

        if (!fileManager.exists(appCtxId)) {
            InputStream inputStream = null;
            OutputStream outputStream = null;
            try {
                inputStream = FileUtils.getInputStream(getClass(), MONGO_XML);
                final MutableFile mutableFile = fileManager
                        .createFile(appCtxId);
                String input = IOUtils.toString(inputStream);
                input = input.replace("TO_BE_CHANGED_BY_ADDON",
                        projectOperations.getTopLevelPackage(moduleName)
                                .getFullyQualifiedPackageName());
                outputStream = mutableFile.getOutputStream();
                IOUtils.write(input, outputStream);
            }
            catch (final IOException e) {
                throw new IllegalStateException("Unable to create file "
                        + appCtxId);
View Full Code Here

                }
                input = input.replace("__MESSAGE_BUNDLE__",
                        messageBundle.getName());

                // Output the file for the user
                final MutableFile mutableFile = fileManager
                        .createFile(destinationFile);
                outputStream = mutableFile.getOutputStream();
                IOUtils.write(input, outputStream);
            }
            catch (final IOException ioe) {
                throw new IllegalStateException("Unable to create '"
                        + languageName + "Language.java'", ioe);
View Full Code Here

                                .toLowerCase());
                input = input.replace("__PROJECT_NAME__",
                        projectName.toLowerCase());

                // Output the file for the user
                final MutableFile mutableFile = fileManager
                        .createFile(destinationFile);
                outputStream = mutableFile.getOutputStream();
                IOUtils.write(input, outputStream);
            }
            catch (final IOException ioe) {
                throw new IllegalStateException("Unable to create '"
                        + targetFilename + "'", ioe);
View Full Code Here

TOP

Related Classes of org.springframework.roo.process.manager.MutableFile

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.