Package org.springframework.roo.process.manager

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


            zis = new ZipInputStream(bis);
            ZipEntry entry;
            final String expectedEntryName = "png/" + countryCode + ".png";
            while ((entry = zis.getNextEntry()) != null) {
                if (entry.getName().equals(expectedEntryName)) {
                    final MutableFile target = fileManager
                            .createFile(pathResolver.getFocusedIdentifier(
                                    Path.SRC_MAIN_RESOURCES, packagePath + "/"
                                            + countryCode + ".png"));
                    OutputStream outputStream = null;
                    try {
                        outputStream = target.getOutputStream();
                        IOUtils.copy(zis, outputStream);
                        success = true;
                    }
                    finally {
                        IOUtils.closeQuietly(outputStream);
View Full Code Here


     *
     * @param pom the POM to write (required)
     */
    private void writePomFile(final Document pom) {
        final LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
        final MutableFile pomFile = fileManager.createFile(pathResolver
                .getIdentifier(rootPath, POM_XML));
        XmlUtils.writeXml(pomFile.getOutputStream(), pom);
    }
View Full Code Here

        Validate.notBlank(fullPathFromRoot,
                "Text file name to write is required");
        Validate.notBlank(message, "Message required");
        final String path = pathResolver.getFocusedIdentifier(Path.ROOT,
                fullPathFromRoot);
        final MutableFile mutableFile = fileManager.exists(path) ? fileManager
                .updateFile(path) : fileManager.createFile(path);
        OutputStream outputStream = null;
        try {
            outputStream = mutableFile.getOutputStream();
            IOUtils.write(message, outputStream);
        }
        catch (final IOException ioe) {
            throw new IllegalStateException(ioe);
        }
View Full Code Here

                String input = IOUtils.toString(templateInputStream);
                input = input.replace("TO_BE_CHANGED_BY_ADDON",
                        projectOperations.getFocusedTopLevelPackage()
                                .getFullyQualifiedPackageName());
                final MutableFile mutableFile = fileManager
                        .createFile(appCtxId);
                outputStream = mutableFile.getOutputStream();
                IOUtils.write(input, outputStream);
            }
            catch (final IOException e) {
                throw new IllegalStateException("Unable to create '" + appCtxId
                        + "'", e);
View Full Code Here

        ZipOutputStream zos = null;
        try {
            final File projectDirectory = new File(projectOperations
                    .getPathResolver().getFocusedIdentifier(Path.ROOT, "."));
            final MutableFile file = fileManager.createFile(FileUtils
                    .getCanonicalPath(new File(projectDirectory,
                            projectOperations.getFocusedProjectName() + "_"
                                    + df.format(new Date()) + ".zip")));
            zos = new ZipOutputStream(file.getOutputStream());
            zip(projectDirectory, projectDirectory, zos);
        }
        catch (final FileNotFoundException e) {
            LOGGER.fine("Could not determine project directory");
        }
View Full Code Here

        final String webMvcConfigPath = pathResolver.getFocusedIdentifier(
                Path.SRC_MAIN_WEBAPP, WEBMVC_CONFIG_XML);
        Validate.isTrue(fileManager.exists(webMvcConfigPath),
                "'%s'  doesn't exist", webMvcConfigPath);

        final MutableFile mutableFile = fileManager
                .updateFile(webMvcConfigPath);
        final Document document = XmlUtils
                .readXml(mutableFile.getInputStream());
        final Element root = document.getDocumentElement();

        final Element annotationDrivenElement = DomUtils
                .findFirstElementByName("mvc:annotation-driven", root);
        return isConversionServiceConfigured(root, annotationDrivenElement);
View Full Code Here

    private void setupProperties(final LogLevel logLevel,
            final LoggerPackage loggerPackage) {
        final String filePath = pathResolver.getFocusedIdentifier(
                Path.SRC_MAIN_RESOURCES, "log4j.properties");
        MutableFile log4jMutableFile = null;
        final Properties props = new Properties();

        InputStream inputStream = null;
        try {
            if (fileManager.exists(filePath)) {
                log4jMutableFile = fileManager.updateFile(filePath);
                inputStream = log4jMutableFile.getInputStream();
                props.load(inputStream);
            }
            else {
                log4jMutableFile = fileManager.createFile(filePath);
                inputStream = FileUtils.getInputStream(getClass(),
                        "log4j-template.properties");
                Validate.notNull(inputStream,
                        "Could not acquire log4j configuration template");
                props.load(inputStream);
            }
        }
        catch (final IOException ioe) {
            throw new IllegalStateException(ioe);
        }
        finally {
            IOUtils.closeQuietly(inputStream);
        }

        final JavaPackage topLevelPackage = projectOperations
                .getTopLevelPackage(projectOperations.getFocusedModuleName());
        final String logStr = "log4j.logger.";

        switch (loggerPackage) {
        case ROOT:
            props.remove("log4j.rootLogger");
            props.setProperty("log4j.rootLogger", logLevel.name() + ", stdout");
            break;
        case PROJECT:
            props.remove(logStr
                    + topLevelPackage.getFullyQualifiedPackageName());
            props.setProperty(
                    logStr + topLevelPackage.getFullyQualifiedPackageName(),
                    logLevel.name());
            break;
        default:
            for (final String packageName : loggerPackage.getPackageNames()) {
                props.remove(logStr + packageName);
                props.setProperty(logStr + packageName, logLevel.name());
            }
            break;
        }

        OutputStream outputStream = null;
        try {
            outputStream = log4jMutableFile.getOutputStream();
            props.store(outputStream, "Updated at " + new Date());
        }
        catch (final IOException ioe) {
            throw new IllegalStateException(ioe);
        }
View Full Code Here

        props.put("solr.serverUrl", solrServerUrl);
        props.put("executor.poolSize", "10");

        OutputStream outputStream = null;
        try {
            final MutableFile mutableFile = solrExists ? fileManager
                    .updateFile(solrPath) : fileManager.createFile(solrPath);
            outputStream = mutableFile.getOutputStream();
            props.store(outputStream, "Updated at " + new Date());
        }
        catch (final IOException e) {
            throw new IllegalStateException(e);
        }
View Full Code Here

                body.getOwnerDocument());
        final String viewContent = byteArrayOutputStream.toString();

        // If mutableFile becomes non-null, it means we need to use it to write
        // out the contents of jspContent to the file
        MutableFile mutableFile = null;
        if (fileManager.exists(tilesDefinitionFile)) {
            // First verify if the file has even changed
            final File file = new File(tilesDefinitionFile);
            String existing = null;
            try {
                existing = org.apache.commons.io.FileUtils
                        .readFileToString(file);
            }
            catch (final IOException ignored) {
            }

            if (!viewContent.equals(existing)) {
                mutableFile = fileManager.updateFile(tilesDefinitionFile);
            }
        }
        else {
            mutableFile = fileManager.createFile(tilesDefinitionFile);
            Validate.notNull(mutableFile,
                    "Could not create tiles view definition '%s'",
                    tilesDefinitionFile);
        }

        if (mutableFile != null) {
            OutputStream outputStream = null;
            try {
                // We need to write the file out (it's a new file, or the
                // existing file has different contents)
                outputStream = mutableFile.getOutputStream();
                IOUtils.write(viewContent, outputStream);

                // Return and indicate we wrote out the file
                return true;
            }
            catch (final IOException ioe) {
                throw new IllegalStateException("Could not output '"
                        + mutableFile.getCanonicalPath() + "'", ioe);
            }
            finally {
                IOUtils.closeQuietly(outputStream);
            }
        }
View Full Code Here

                writeImmediately);
    }

    private void createOrUpdateTextFileIfRequired(final String fileIdentifier,
            final String newContents, final String descriptionOfChange) {
        MutableFile mutableFile = null;
        if (exists(fileIdentifier)) {
            // First verify if the file has even changed
            final File file = new File(fileIdentifier);
            String existing = null;
            try {
                existing = FileUtils.readFileToString(file);
            }
            catch (final IOException ignored) {
            }

            if (!newContents.equals(existing)) {
                mutableFile = updateFile(fileIdentifier);
            }
        }
        else {
            mutableFile = createFile(fileIdentifier);
            Validate.notNull(mutableFile, "Could not create file '%s'",
                    fileIdentifier);
        }

        if (mutableFile != null) {
            OutputStream outputStream = null;
            try {
                if (StringUtils.isNotBlank(descriptionOfChange)) {
                    mutableFile.setDescriptionOfChange(descriptionOfChange);
                }
                outputStream = mutableFile.getOutputStream();
                IOUtils.write(newContents, outputStream);
            }
            catch (final IOException e) {
                throw new IllegalStateException("Could not output '"
                        + mutableFile.getCanonicalPath() + "'", e);
            }
            finally {
                IOUtils.closeQuietly(outputStream);
            }
        }
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.