Search in sources :

Example 1 with XmlParser

use of groovy.util.XmlParser in project camel by apache.

the class XmlParserDataFormat method newParser.

private XmlParser newParser() throws Exception {
    XmlParser xmlParser = new XmlParser(newSaxParser());
    xmlParser.setErrorHandler(getErrorHandler());
    xmlParser.setTrimWhitespace(!isKeepWhitespace());
    return xmlParser;
}
Also used : XmlParser(groovy.util.XmlParser)

Example 2 with XmlParser

use of groovy.util.XmlParser in project curiostack by curioswitch.

the class CuriostackRootPlugin method setupProjectXml.

private static void setupProjectXml(Project project, XmlProvider xml) {
    var gradleSettings = findOrCreateChild(xml.asNode(), "component", "GradleSettings");
    if (gradleSettings.children().isEmpty()) {
        var linkedExternalProjectsSettings = findOrCreateChild(gradleSettings, "option", "linkedExternalProjectsSettings");
        var gradleProjectSettings = linkedExternalProjectsSettings.appendNode("GradleProjectSettings");
        setOption(gradleProjectSettings, "distributionType", "DEFAULT_WRAPPED");
        setOption(gradleProjectSettings, "externalProjectPath", "$PROJECT_DIR$");
        setOption(gradleProjectSettings, "useAutoImport", "true");
        setOption(gradleProjectSettings, "useQualifiedModuleNames", "true");
    }
    var googleJavaFormat = findOrCreateChild(xml.asNode(), "component", "GoogleJavaFormatSettings");
    if (googleJavaFormat.children().isEmpty()) {
        setOption(googleJavaFormat, "enabled", "true");
    }
    var copyrightManager = findOrCreateChild(xml.asNode(), "component", "CopyrightManager");
    var copyrightDir = project.file(".baseline").toPath().resolve("copyright");
    try (var files = Files.list(copyrightDir)) {
        files.forEach(file -> {
            String filename = copyrightDir.relativize(file).toString();
            if (findChild(copyrightManager, copyright -> copyright.name().equals("copyright") && findChild(copyright, option -> option.name().equals("myName") && option.attribute("value").equals(filename)).isPresent()).isPresent()) {
                return;
            }
            final String copyrightText;
            try {
                copyrightText = Files.readString(file);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            var copyrightNode = copyrightManager.appendNode("copyright");
            setOption(copyrightNode, "notice", copyrightText);
            setOption(copyrightNode, "keyword", "Copyright");
            setOption(copyrightNode, "allowReplaceKeyword", "");
            setOption(copyrightNode, "myName", filename);
            setOption(copyrightNode, "myLocal", "true");
            copyrightManager.attributes().put("default", filename);
        });
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    var vcsDirectoryMappings = findOrCreateChild(xml.asNode(), "component", "VcsDirectoryMappings");
    if (findChild(vcsDirectoryMappings, node -> node.name().equals("mapping") && node.attribute("vcs").equals("Git")).isEmpty()) {
        vcsDirectoryMappings.appendNode("mapping", ImmutableMap.of("directory", "$PROJECT_DIR$", "vcs", "Git"));
    }
    Node typescriptCompiler = findOrCreateChild(xml.asNode(), "component", "TypeScriptCompiler");
    setOption(typescriptCompiler, "nodeInterpreterTextField", NodeUtil.getNodeExe(project).toString());
    Node eslintConfiguration = findOrCreateChild(xml.asNode(), "component", "EslintConfiguration");
    findOrCreateChild(eslintConfiguration, "extra-options").attributes().put("value", "--ext .js,.ts,.jsx,.tsx");
    Node inspectionManager = findOrCreateChild(xml.asNode(), "component", "InspectionProjectProfileManager");
    Node profile = findChild(inspectionManager, n -> n.name().equals("profile")).orElseGet(() -> inspectionManager.appendNode("profile", ImmutableMap.of("version", "1.0")));
    setOption(profile, "myName", "Project Default");
    Node updated = findChild(profile, n -> n.name().equals("inspection_tool") && "Eslint".equals(n.attribute("class"))).orElseGet(() -> profile.appendNode("inspection_tool", ImmutableMap.of("class", "Eslint", "enabled", "true", "level", "WARNING", "enabled_by_default", "true")));
    var projectCodeStyleConfiguration = findOrCreateChild(xml.asNode(), "component", "ProjectCodeStyleConfiguration");
    setOption(projectCodeStyleConfiguration, "USE_PER_PROJECT_SETTINGS", "true");
    projectCodeStyleConfiguration.remove(findOrCreateChild(projectCodeStyleConfiguration, "code_scheme", "Project"));
    final String googleStyle;
    try {
        googleStyle = Resources.toString(Resources.getResource(CuriostackRootPlugin.class, "/curiostack/intellij-java-google-style.xml"), StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    final Node googleStyleNode;
    try {
        googleStyleNode = new XmlParser().parseText(googleStyle);
    } catch (IOException | SAXException | ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }
    googleStyleNode.attributes().put("name", "Project");
    projectCodeStyleConfiguration.append(googleStyleNode);
}
Also used : ErrorProneOptions(net.ltgt.gradle.errorprone.ErrorProneOptions) AwsSetupPlugin(org.curioswitch.gradle.plugins.aws.AwsSetupPlugin) MavenPublishPlugin(org.gradle.api.publish.maven.plugins.MavenPublishPlugin) CondaPlugin(org.curioswitch.gradle.conda.CondaPlugin) JavaPlugin(org.gradle.api.plugins.JavaPlugin) IdeaPlugin(org.gradle.plugins.ide.idea.IdeaPlugin) MonotonicNonNull(org.checkerframework.checker.nullness.qual.MonotonicNonNull) NodePlugin(org.curioswitch.gradle.plugins.nodejs.NodePlugin) Wrapper(org.gradle.api.tasks.wrapper.Wrapper) PublishingExtension(org.gradle.api.publish.PublishingExtension) Javadoc(org.gradle.api.tasks.javadoc.Javadoc) JibTask(org.curioswitch.gradle.golang.tasks.JibTask) GolangPlugin(org.curioswitch.gradle.golang.GolangPlugin) Locale(java.util.Locale) Map(java.util.Map) ExtensionAware(org.gradle.api.plugins.ExtensionAware) TestExceptionFormat(org.gradle.api.tasks.testing.logging.TestExceptionFormat) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ReleasePlugin(org.curioswitch.gradle.release.ReleasePlugin) Project(org.gradle.api.Project) VariantVersionMappingStrategy(org.gradle.api.publish.VariantVersionMappingStrategy) Predicate(java.util.function.Predicate) CheckSeverity(net.ltgt.gradle.errorprone.CheckSeverity) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SetupGitHooks(org.curioswitch.gradle.plugins.curiostack.tasks.SetupGitHooks) DistributionType(org.gradle.api.tasks.wrapper.Wrapper.DistributionType) Set(java.util.Set) UpdateProjectSettingsTask(org.curioswitch.gradle.plugins.curiostack.tasks.UpdateProjectSettingsTask) SpotlessExtension(com.diffplug.gradle.spotless.SpotlessExtension) XmlParser(groovy.util.XmlParser) Collectors(java.util.stream.Collectors) JavaVersion(org.gradle.api.JavaVersion) StandardCharsets(java.nio.charset.StandardCharsets) NullAwayPlugin(net.ltgt.gradle.nullaway.NullAwayPlugin) UncheckedIOException(java.io.UncheckedIOException) CondaBuildEnvPlugin(org.curioswitch.gradle.conda.CondaBuildEnvPlugin) List(java.util.List) ToolDownloaderPlugin(org.curioswitch.gradle.tooldownloader.ToolDownloaderPlugin) CoreJavadocOptions(org.gradle.external.javadoc.CoreJavadocOptions) VersionsPlugin(com.github.benmanes.gradle.versions.VersionsPlugin) JavaPluginExtension(org.gradle.api.plugins.JavaPluginExtension) SAXException(org.xml.sax.SAXException) DependencyUpdatesTask(com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask) Optional(java.util.Optional) PluginContainer(org.gradle.api.plugins.PluginContainer) XmlProvider(org.gradle.api.XmlProvider) Pattern(java.util.regex.Pattern) JooqPlugin(nu.studer.gradle.jooq.JooqPlugin) QName(groovy.xml.QName) GenerateApiServerTask(org.curioswitch.gradle.plugins.curiostack.tasks.GenerateApiServerTask) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) ERROR(net.ltgt.gradle.errorprone.CheckSeverity.ERROR) CurioGenericCiPlugin(org.curioswitch.gradle.plugins.ci.CurioGenericCiPlugin) ErrorPronePlugin(net.ltgt.gradle.errorprone.ErrorPronePlugin) CondaExtension(org.curioswitch.gradle.conda.CondaExtension) HashMap(java.util.HashMap) GolangExtension(org.curioswitch.gradle.golang.GolangExtension) BasePlugin(org.gradle.api.plugins.BasePlugin) MavenPublication(org.gradle.api.publish.maven.MavenPublication) DownloadToolUtil(org.curioswitch.gradle.tooldownloader.util.DownloadToolUtil) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) TargetJvmVersion(org.gradle.api.attributes.java.TargetJvmVersion) JMHPluginExtension(me.champeau.gradle.JMHPluginExtension) ImmutableList(com.google.common.collect.ImmutableList) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) JooqTask(nu.studer.gradle.jooq.JooqTask) DownloadedToolManager(org.curioswitch.gradle.tooldownloader.DownloadedToolManager) UpdateGradleWrapperTask(org.curioswitch.gradle.plugins.curiostack.tasks.UpdateGradleWrapperTask) CreateShellConfigTask(org.curioswitch.gradle.plugins.curiostack.tasks.CreateShellConfigTask) NodeUtil(org.curioswitch.gradle.plugins.nodejs.util.NodeUtil) Test(org.gradle.api.tasks.testing.Test) OFF(net.ltgt.gradle.errorprone.CheckSeverity.OFF) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Resources(com.google.common.io.Resources) Files(java.nio.file.Files) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) JacocoPlugin(org.gradle.testing.jacoco.plugins.JacocoPlugin) JMHPlugin(me.champeau.gradle.JMHPlugin) UpdateIntelliJSdksTask(org.curioswitch.gradle.plugins.curiostack.tasks.UpdateIntelliJSdksTask) IOException(java.io.IOException) Node(groovy.util.Node) GcloudPlugin(org.curioswitch.gradle.plugins.gcloud.GcloudPlugin) GolangSetupPlugin(org.curioswitch.gradle.golang.GolangSetupPlugin) SpotlessPlugin(com.diffplug.gradle.spotless.SpotlessPlugin) ResolutionStrategy(org.gradle.api.artifacts.ResolutionStrategy) TerraformSetupPlugin(org.curioswitch.gradle.plugins.terraform.TerraformSetupPlugin) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NullAwayOptions(net.ltgt.gradle.nullaway.NullAwayOptions) JavaExec(org.gradle.api.tasks.JavaExec) WARN(net.ltgt.gradle.errorprone.CheckSeverity.WARN) Plugin(org.gradle.api.Plugin) Copy(org.gradle.api.tasks.Copy) XmlParser(groovy.util.XmlParser) Node(groovy.util.Node) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

XmlParser (groovy.util.XmlParser)2 SpotlessExtension (com.diffplug.gradle.spotless.SpotlessExtension)1 SpotlessPlugin (com.diffplug.gradle.spotless.SpotlessPlugin)1 VersionsPlugin (com.github.benmanes.gradle.versions.VersionsPlugin)1 DependencyUpdatesTask (com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Resources (com.google.common.io.Resources)1 Node (groovy.util.Node)1 QName (groovy.xml.QName)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1