Search in sources :

Example 41 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class AbstractItdMetadataProvider method resolveDownstreamDependencyIdentifier.

/**
 * Invoked whenever a "class-level" downstream dependency identifier is
 * presented in a metadata notification. An "instance-specific" downstream
 * dependency identifier is required so that a metadata request can
 * ultimately be made. This method is responsible for evaluating the
 * upstream dependency identifier and converting it into a valid downstream
 * dependency identifier. The downstream dependency identifier must be of
 * the same type as this metadata provider's {@link #getProvidesType()}. The
 * downstream dependency identifier must also be instance-specific.
 * <p>
 * The basic implementation offered in this class will only convert a
 * {@link PhysicalTypeIdentifier}. If a subclass registers a dependency on
 * an upstream (other than
 * {@link PhysicalTypeIdentifier#getMetadataIdentiferType()}) and presents
 * their {@link #getProvidesType()} as the downstream (thus meaning only
 * class-level downstream dependency identifiers will be presented), they
 * must override this method and appropriately handle instance-specific
 * downstream dependency identifier resolution.
 * <p>
 * This method may also return null if it wishes to abort processing of the
 * notification. This may be appropriate if a determination cannot be made
 * at this time for whatever reason (eg too early in a lifecycle etc).
 *
 * @param upstreamDependency the upstream (never null)
 * @return an instance-specific MID of type {@link #getProvidesType()} (or
 *         null if the metadata notification should be aborted)
 */
protected String resolveDownstreamDependencyIdentifier(final String upstreamDependency) {
    // We only support analysis of a PhysicalTypeIdentifier upstream MID to
    // convert this to a downstream MID.
    // In any other case the downstream metadata should have registered an
    // instance-specific downstream dependency on a given upstream.
    Validate.isTrue(isNotificationForJavaType(upstreamDependency), "Expected class-level notifications only for physical Java types (not '" + upstreamDependency + "') for metadata provider " + getClass().getName());
    // A physical Java type has changed, and determine what the
    // corresponding local metadata identification string would have been
    final JavaType javaType = PhysicalTypeIdentifier.getJavaType(upstreamDependency);
    final LogicalPath path = PhysicalTypeIdentifier.getPath(upstreamDependency);
    return createLocalIdentifier(javaType, path);
}
Also used : JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 42 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class CreatorOperationsImpl method writeTextFile.

private void writeTextFile(final String fullPathFromRoot, final String message, String folder) {
    Validate.notBlank(fullPathFromRoot, "Text file name to write is required");
    Validate.notBlank(message, "Message required");
    MutableFile mutableFile;
    if (folder != null) {
        LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
        mutableFile = fileManager.createFile(pathResolver.getIdentifier(rootPath, folder + "/" + fullPathFromRoot));
    } else {
        LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
        mutableFile = fileManager.createFile(pathResolver.getIdentifier(rootPath, fullPathFromRoot));
    }
    OutputStream outputStream = null;
    try {
        outputStream = mutableFile.getOutputStream();
        IOUtils.write(message, outputStream);
    } catch (final IOException ioe) {
        throw new IllegalStateException(ioe);
    } finally {
        IOUtils.closeQuietly(outputStream);
    }
}
Also used : OutputStream(java.io.OutputStream) LogicalPath(org.springframework.roo.project.LogicalPath) IOException(java.io.IOException) MutableFile(org.springframework.roo.process.manager.MutableFile)

Example 43 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class CreatorOperationsImpl method install.

private void install(final String targetFilename, final JavaPackage topLevelPackage, final Path path, final Type type, String projectName, String folder) {
    if (StringUtils.isBlank(projectName)) {
        projectName = topLevelPackage.getFullyQualifiedPackageName().replace(".", "-");
    }
    final String topLevelPackageName = topLevelPackage.getFullyQualifiedPackageName();
    final String packagePath = topLevelPackageName.replace('.', separatorChar);
    String destinationFile = "";
    if (targetFilename.endsWith(".java")) {
        destinationFile = path.getDefaultLocation() + "/" + packagePath + separatorChar + StringUtils.capitalize(topLevelPackageName.substring(topLevelPackageName.lastIndexOf(".") + 1)) + targetFilename;
    } else {
        destinationFile = path.getDefaultLocation() + "/" + packagePath + separatorChar + targetFilename;
    }
    // Adjust name for Roo Annotation
    if (targetFilename.startsWith("RooAnnotation")) {
        destinationFile = path.getDefaultLocation() + "/" + packagePath + separatorChar + "Roo" + StringUtils.capitalize(topLevelPackageName.substring(topLevelPackageName.lastIndexOf(".") + 1)) + ".java";
    }
    if (!fileManager.exists(destinationFile)) {
        final InputStream templateInputStream = FileUtils.getInputStream(getClass(), type.name().toLowerCase() + "/" + targetFilename + "-template");
        OutputStream outputStream = null;
        try {
            // Read template and insert the user's package
            String input = IOUtils.toString(templateInputStream);
            input = input.replace("__TOP_LEVEL_PACKAGE__", topLevelPackage.getFullyQualifiedPackageName());
            input = input.replace("__APP_NAME__", StringUtils.capitalize(topLevelPackageName.substring(topLevelPackageName.lastIndexOf(".") + 1)));
            input = input.replace("__APP_NAME_LWR_CASE__", topLevelPackageName.substring(topLevelPackageName.lastIndexOf(".") + 1).toLowerCase());
            input = input.replace("__PROJECT_NAME__", projectName.toLowerCase());
            // Output the file for the user
            MutableFile mutableFile;
            if (folder != null) {
                LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
                mutableFile = fileManager.createFile(pathResolver.getIdentifier(rootPath, folder + "/" + destinationFile));
            } else {
                LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
                mutableFile = fileManager.createFile(pathResolver.getIdentifier(rootPath, destinationFile));
            }
            outputStream = mutableFile.getOutputStream();
            IOUtils.write(input, outputStream);
        } catch (final IOException ioe) {
            throw new IllegalStateException("Unable to create '" + targetFilename + "'", ioe);
        } finally {
            IOUtils.closeQuietly(templateInputStream);
            IOUtils.closeQuietly(outputStream);
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) LogicalPath(org.springframework.roo.project.LogicalPath) IOException(java.io.IOException) MutableFile(org.springframework.roo.process.manager.MutableFile)

Example 44 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class CreatorOperationsImpl method writePomFile.

/**
 * Writes the given Maven POM to disk
 *
 * @param pom the POM to write (required)
 */
private void writePomFile(final Document pom, String folder) {
    MutableFile pomFile;
    if (folder != null) {
        LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
        pomFile = fileManager.createFile(pathResolver.getIdentifier(rootPath, folder + "/" + POM_XML));
    } else {
        LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
        pomFile = fileManager.createFile(pathResolver.getIdentifier(rootPath, POM_XML));
    }
    XmlUtils.writeXml(pomFile.getOutputStream(), pom);
}
Also used : LogicalPath(org.springframework.roo.project.LogicalPath) MutableFile(org.springframework.roo.process.manager.MutableFile)

Example 45 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class CreatorOperationsImpl method createObrFile.

private void createObrFile(String topLevelPackageName, Type type, String folder) {
    // Getting obr location
    if (folder != null) {
        LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
        fileManager.createFile(pathResolver.getIdentifier(rootPath, folder + "/" + "src/main/resources/obr.xml"));
    } else {
        LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
        fileManager.createFile(pathResolver.getIdentifier(rootPath, "src/main/resources/obr.xml"));
    }
    final InputStream templateInputStream = FileUtils.getInputStream(getClass(), type.name().toLowerCase() + "/obr-template.xml");
    final Document docXml = XmlUtils.readXml(templateInputStream);
    final Element document = docXml.getDocumentElement();
    Element capabilityElement = XmlUtils.findFirstElement("resource/capability", document);
    if (capabilityElement != null) {
        if (type.equals(Type.ADVANCED)) {
            String commandInit = topLevelPackageName.substring(topLevelPackageName.lastIndexOf(".") + 1).toLowerCase();
            Element commandAddElement = docXml.createElement("p");
            commandAddElement.setAttribute("n", "command-add");
            commandAddElement.setAttribute("v", commandInit + " add");
            Element commandAllElement = docXml.createElement("p");
            commandAllElement.setAttribute("n", "command-all");
            commandAllElement.setAttribute("v", commandInit + " all");
            Element commandSetupElement = docXml.createElement("p");
            commandSetupElement.setAttribute("n", "command-setup");
            commandSetupElement.setAttribute("v", commandInit + " setup");
            capabilityElement.appendChild(commandAddElement);
            capabilityElement.appendChild(commandAllElement);
            capabilityElement.appendChild(commandSetupElement);
        }
        if (type.equals(Type.SIMPLE)) {
            Element commandSayHelloElement = docXml.createElement("p");
            commandSayHelloElement.setAttribute("n", "command-say-hello");
            commandSayHelloElement.setAttribute("v", "say hello");
            Element commandInstallElement = docXml.createElement("p");
            commandInstallElement.setAttribute("n", "command-install-tags");
            commandInstallElement.setAttribute("v", "web mvc install tags");
            capabilityElement.appendChild(commandSayHelloElement);
            capabilityElement.appendChild(commandInstallElement);
        }
        if (folder != null) {
            LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
            XmlUtils.writeXml(fileManager.updateFile(pathResolver.getIdentifier(rootPath, folder + "/" + "src/main/resources/obr.xml")).getOutputStream(), docXml);
        } else {
            LogicalPath rootPath = LogicalPath.getInstance(Path.ROOT, "");
            XmlUtils.writeXml(fileManager.updateFile(pathResolver.getIdentifier(rootPath, "src/main/resources/obr.xml")).getOutputStream(), docXml);
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) LogicalPath(org.springframework.roo.project.LogicalPath) Document(org.w3c.dom.Document)

Aggregations

LogicalPath (org.springframework.roo.project.LogicalPath)85 JavaType (org.springframework.roo.model.JavaType)62 RooJavaType (org.springframework.roo.model.RooJavaType)55 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)13 JpaJavaType (org.springframework.roo.model.JpaJavaType)12 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)10 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)9 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)9 SpringJavaType (org.springframework.roo.model.SpringJavaType)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)6 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)5 BufferedInputStream (java.io.BufferedInputStream)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 I18n (org.springframework.roo.addon.web.mvc.i18n.components.I18n)4 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)3 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)3