Example usage for org.jdom2 Element getChildTextNormalize

List of usage examples for org.jdom2 Element getChildTextNormalize

Introduction

In this page you can find the example usage for org.jdom2 Element getChildTextNormalize.

Prototype

public String getChildTextNormalize(final String cname) 

Source Link

Document

Returns the normalized textual content of the named child element, or null if there's no such child.

Usage

From source file:com.bc.ceres.nbmgen.NbmGenTool.java

License:Open Source License

@Override
public void process(CeresModuleProject project) throws JDOMException, IOException {

    System.out.println("Project [" + project.projectDir.getName() + "]:");

    File originalPomFile = getFile(project.projectDir, CeresModuleProject.ORIGINAL_POM_XML);
    File pomFile = getFile(project.projectDir, CeresModuleProject.POM_XML);
    File manifestBaseFile = getFile(project.projectDir, "src", "main", "nbm", "manifest.mf");

    Element projectElement = project.pomDocument.getRootElement();
    Namespace ns = projectElement.getNamespace();

    Element moduleElement = project.moduleDocument.getRootElement();
    String moduleName = moduleElement.getChildTextTrim("name");
    String moduleDescription = moduleElement.getChildTextNormalize("description");
    String modulePackaging = moduleElement.getChildTextTrim("packaging");
    String moduleNative = moduleElement.getChildTextTrim("native");
    String moduleActivator = moduleElement.getChildTextTrim("activator");
    String moduleChangelog = moduleElement.getChildTextTrim("changelog");
    String moduleFunding = moduleElement.getChildTextTrim("funding");
    String moduleVendor = moduleElement.getChildTextTrim("vendor");
    String moduleContactAddress = moduleElement.getChildTextTrim("contactAddress");
    String moduleCopyright = moduleElement.getChildTextTrim("copyright");
    String moduleLicenseUrl = moduleElement.getChildTextTrim("licenseUrl");
    // Not used anymore:
    //String moduleUrl = moduleElement.getChildTextTrim("url");
    //String moduleAboutUrl = moduleElement.getChildTextTrim("aboutUrl");

    if (moduleName != null) {
        Element nameElement = getOrAddElement(projectElement, "name", ns);
        nameElement.setText(moduleName);
    }//from   ww w.jav a2  s  .  c  om
    if (moduleDescription != null) {
        int nameIndex = projectElement.indexOf(projectElement.getChild("name"));
        Element descriptionElement = getOrAddElement(projectElement, "description", nameIndex + 1, ns);
        descriptionElement.setText(moduleDescription);
    }
    Element descriptionElement = getOrAddElement(projectElement, "packaging", ns);
    descriptionElement.setText("nbm");

    Element urlElement = getOrAddElement(projectElement, "url", ns);
    urlElement.setText("https://sentinel.esa.int/web/sentinel/toolboxes");

    Element buildElement = getOrAddElement(projectElement, "build", ns);
    Element pluginsElement = getOrAddElement(buildElement, "plugins", ns);

    Map<String, String> nbmConfiguration = new LinkedHashMap<>();
    // moduleType is actually a constant which can be put it into the <pluginManagement-element of the parent
    nbmConfiguration.put("moduleType", "normal");
    // licenseName/File should also be constant
    nbmConfiguration.put("licenseName", "GPL 3");
    nbmConfiguration.put("licenseFile", "../LICENSE.html");

    nbmConfiguration.put("cluster", cluster);
    nbmConfiguration.put("defaultCluster", cluster);
    nbmConfiguration.put("publicPackages", "");
    nbmConfiguration.put("requiresRestart", "true");

    addPluginElement(pluginsElement, "org.codehaus.mojo", "nbm-maven-plugin", nbmConfiguration, ns);

    Map<String, String> jarConfiguration = new LinkedHashMap<>();
    jarConfiguration.put("useDefaultManifestFile", "true");

    addPluginElement(pluginsElement, "org.apache.maven.plugins", "maven-jar-plugin", jarConfiguration, ns);

    StringBuilder longDescription = new StringBuilder();

    longDescription.append(moduleDescription != null ? "<p>" + moduleDescription + "" : "")
            .append(descriptionEntry("Funding", moduleFunding)).append(descriptionEntry("Vendor", moduleVendor))
            .append(descriptionEntry("Contact address", moduleContactAddress))
            .append(descriptionEntry("Copyright", moduleCopyright))
            .append(descriptionEntry("Vendor", moduleVendor))
            .append(descriptionEntry("License", moduleLicenseUrl))
            .append(descriptionEntry("Changelog", moduleChangelog));

    Map<String, String> manifestContent = new LinkedHashMap<>();
    manifestContent.put("Manifest-Version", "1.0");
    manifestContent.put("AutoUpdate-Show-In-Client", "false");
    manifestContent.put("AutoUpdate-Essential-Module", "true");
    manifestContent.put("OpenIDE-Module-Java-Dependencies", "Java > 1.8");
    manifestContent.put("OpenIDE-Module-Display-Category", "SNAP");
    if (longDescription.length() > 0) {
        manifestContent.put("OpenIDE-Module-Long-Description", longDescription.toString());
    }
    if (moduleActivator != null) {
        warnModuleDetail("Activator may be reimplemented for NB: " + moduleActivator + " (--> "
                + "consider using @OnStart, @OnStop, @OnShowing, or a ModuleInstall)");
        manifestContent.put("OpenIDE-Module-Install", moduleActivator);
    }
    if (modulePackaging != null && !"jar".equals(modulePackaging)) {
        warnModuleDetail("Unsupported module packaging: " + modulePackaging + " (--> "
                + "provide a ModuleInstall that does the job on install/uninstall)");
    }
    if (moduleNative != null && "true".equals(moduleNative)) {
        warnModuleDetail("Module contains native code: no auto-conversion possible (--> "
                + "follow NB instructions see http://bits.netbeans.org/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#how-layer");
    }

    if (!originalPomFile.exists()) {
        if (!dryRun) {
            Files.copy(project.pomFile.toPath(), originalPomFile.toPath());
        }
        infoModuleDetail("Copied " + project.pomFile + " to " + originalPomFile);
    }

    if (!dryRun) {
        writeXml(pomFile, project.pomDocument);
    }
    if (pomFile.equals(project.pomFile)) {
        infoModuleDetail("Updated " + pomFile);
    } else {
        infoModuleDetail("Converted " + project.pomFile + " to " + pomFile);
    }

    //noinspection ResultOfMethodCallIgnored
    if (!dryRun) {
        manifestBaseFile.getParentFile().mkdirs();
        writeManifest(manifestBaseFile, manifestContent);
    }
    infoModuleDetail("Written " + manifestBaseFile);
}