use of org.gradle.api.tasks.wrapper.Wrapper.DistributionType 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);
}
Aggregations