@Override protected void configure(VisualStudioProjectFile projectFile) { DefaultVisualStudioProject vsProject = visualStudioProject; projectFile.setGradleCommand(buildGradleCommand()); projectFile.setProjectUuid(vsProject.getUuid()); for (File sourceFile : vsProject.getSourceFiles()) { projectFile.addSourceFile(sourceFile); } for (File resourceFile : vsProject.getResourceFiles()) { projectFile.addResource(resourceFile); } for (File headerFile : vsProject.getHeaderFiles()) { projectFile.addHeaderFile(headerFile); } for (VisualStudioProjectConfiguration configuration : vsProject.getConfigurations()) { projectFile.addConfiguration(configuration); } for (Action<? super XmlProvider> xmlAction : vsProject.getProjectFile().getXmlActions()) { getXmlTransformer().addAction(xmlAction); } }
@Override protected void configure(final VisualStudioFiltersFile filtersFile) { DefaultVisualStudioProject vsProject = visualStudioProject; for (File sourceFile : vsProject.getSourceFiles()) { filtersFile.addSource(sourceFile); } for (File headerFile : vsProject.getHeaderFiles()) { filtersFile.addHeader(headerFile); } for (Action<? super XmlProvider> xmlAction : vsProject.getFiltersFile().getXmlActions()) { getXmlTransformer().addAction(xmlAction); } }
private void createMavenMarkerPublication(PluginDeclaration declaration, final MavenPublication coordinates, PublicationContainer publications) { String pluginId = declaration.getId(); MavenPublication publication = publications.create(declaration.getName() + "PluginMarkerMaven", MavenPublication.class); publication.setArtifactId(pluginId + PLUGIN_MARKER_SUFFIX); publication.setGroupId(pluginId); publication.getPom().withXml(new Action<XmlProvider>() { @Override public void execute(XmlProvider xmlProvider) { Element root = xmlProvider.asElement(); Document document = root.getOwnerDocument(); Node dependencies = root.appendChild(document.createElement("dependencies")); Node dependency = dependencies.appendChild(document.createElement("dependency")); Node groupId = dependency.appendChild(document.createElement("groupId")); groupId.setTextContent(coordinates.getGroupId()); Node artifactId = dependency.appendChild(document.createElement("artifactId")); artifactId.setTextContent(coordinates.getArtifactId()); Node version = dependency.appendChild(document.createElement("version")); version.setTextContent(coordinates.getVersion()); } }); }
public void configure() { rootProject.getGradle().addBuildListener(new BuildAdapter() { public void projectsEvaluated(Gradle gradle) { VersionNumber ideaTargetVersion = findIdeaTargetVersion(); final boolean useScalaSdk = ideaTargetVersion == null || IDEA_VERSION_WHEN_SCALA_SDK_WAS_INTRODUCED.compareTo(ideaTargetVersion) <= 0; final Collection<Project> scalaProjects = findProjectsApplyingIdeaAndScalaPlugins(); final Map<String, ProjectLibrary> scalaCompilerLibraries = Maps.newHashMap(); rootProject.getTasks().getByName("ideaProject").doFirst(new Action<Task>() { @Override public void execute(Task task) { if (scalaProjects.size() > 0) { scalaCompilerLibraries.clear(); scalaCompilerLibraries.putAll(resolveScalaCompilerLibraries(scalaProjects, useScalaSdk)); declareUniqueProjectLibraries(Sets.newLinkedHashSet(scalaCompilerLibraries.values())); } } }); rootProject.configure(scalaProjects, new Action<Project>() { @Override public void execute(final Project project) { project.getExtensions().getByType(IdeaModel.class).getModule().getIml().withXml(new Action<XmlProvider>() { @Override public void execute(XmlProvider xmlProvider) { if (useScalaSdk) { declareScalaSdk(scalaCompilerLibraries.get(project.getPath()), xmlProvider.asNode()); } else { declareScalaFacet(scalaCompilerLibraries.get(project.getPath()), xmlProvider.asNode()); } } }); } }); } }); }
/** * Customizes the pom. The method requires following properties on root project to function correctly: */ public static void customizePom(final Project project, final ShipkitConfiguration conf, final MavenPublication publication) { publication.getPom().withXml(new Action<XmlProvider>() { public void execute(XmlProvider xml) { String archivesBaseName = (String) project.getProperties().get("archivesBaseName"); File contributorsFile = contributorsFile(project); LOG.info(" Read project contributors from file: " + contributorsFile.getAbsolutePath()); // It can happens that contributorsFile doesn't exist e.g. when shipkit.team.contributors is NOT empty ProjectContributorsSet contributorsFromGitHub = new ProjectContributorsSerializer() .deserialize(IOUtil.readFullyOrDefault(contributorsFile, "[]")); LOG.info(" Customizing pom for publication " + publication.getName() + " in " + project.toString() + "\n - Module name (project.archivesBaseName): " + archivesBaseName + "\n - Description (project.description): " + project.getDescription() + "\n - GitHub repository (project.rootProject.shipkit.gitHub.repository): " + conf.getGitHub().getRepository() + "\n - Developers (project.rootProject.shipkit.team.developers): " + StringUtil.join(conf.getTeam().getDevelopers(), ", ") + "\n - Contributors (project.rootProject.shipkit.team.contributors): " + StringUtil.join(conf.getTeam().getContributors(), ", ") + "\n - Contributors read from GitHub: " + StringUtil.join(contributorsFromGitHub.toConfigNotation(), ", ")); customizePom(xml.asNode(), conf, archivesBaseName, project.getDescription(), contributorsFromGitHub); } }); }
/** Creates an XML string from a groovy.util.Node. */ public static void modifyXmlInPlace(File file, Action<XmlProvider> action) throws IOException { String original = Files.toString(file, StandardCharsets.UTF_8); XmlTransformer transformer = new XmlTransformer(); transformer.addAction(action); try (OutputStream output = Files.asByteSink(file).openBufferedStream()) { transformer.transform(original, output); } }
private static void configPom(Project project, XmlProvider xmlProvider) { val extension = defaultsExtension(project); val node = xmlProvider.asNode(); name(node, project); description(node, project); siteUrl(node, extension); organization(node, extension); licenses(node, extension); developers(node, extension); contributors(node, extension); scm(node, extension); dependencies(node, project); }
private static void customizeProjectXml(Project project, XmlProvider provider) { val rootNode = provider.asNode(); addGradleHome(project, rootNode); setupCodeStyle(rootNode, String.valueOf(codeStyleExtension(project).getIndentSize())); setupCompiler(project, rootNode); }
public void withXml(Action<? super XmlProvider> action) { actions.add(action); }
public List<Action<? super XmlProvider>> getXmlActions() { return actions; }
public DefaultMavenPom withXml(final Action<XmlProvider> action) { withXmlActions.addAction(action); return this; }
public MavenPomFileGenerator withXml(final Action<XmlProvider> action) { xmlTransformer.addAction(action); return this; }
public void withXml(Action<? super XmlProvider> action) { xmlAction.add(new UserCodeAction<XmlProvider>("Could not apply withXml() to generated POM", action)); }
public Action<XmlProvider> getXmlAction() { return xmlAction; }
@Override public DeploymentDescriptor withXml(Action<? super XmlProvider> action) { transformer.addAction(action); return this; }
public void withXml(Action<? super XmlProvider> action) { xmlActions.add(new UserCodeAction<XmlProvider>("Could not apply withXml() to Ivy module descriptor", action)); }
public Action<XmlProvider> getXmlAction() { return xmlActions; }
public IvyDescriptorFileGenerator withXml(final Action<XmlProvider> action) { xmlTransformer.addAction(action); return this; }
public void addAction(Action<? super XmlProvider> provider) { actions.add(provider); }
public void apply(Iterable<Action<? super XmlProvider>> actions) { for (Action<? super XmlProvider> action : actions) { action.execute(this); } }
/** * Configure the classpath XML document * * @param xml XML document to configure */ protected void configureClasspathXml(XmlProvider xml) { Element root = xml.asElement(); NodeList classpathentries = root.getElementsByTagName("classpathentry"); getLogger().debug("Checking classpath entries for {}", getProject()); for (Node classpathentry : Nodes.elements(classpathentries)) { String kind = Nodes.attributeValue(classpathentry, "kind"); String path = Nodes.attributeValue(classpathentry, "path"); getLogger().debug("Checking classpath entry '{}' of kind '{}'", path, kind); switch (kind) { case "lib": { if (GRADLE_JAR_PATTERN.matcher(path).find()) { configureLibraryEntry((Element) classpathentry, path, "gradle-api-annotations"); } else { File file = new File(path); Optional<ProjectElement<ResolvedArtifact>> artifact = Projects.findResolvedArtifact( getProject().getAllprojects(), p -> true, a -> a.getFile().equals(file)); artifact.ifPresent(a -> { getLogger().debug("Resolved classpath to artifact '{}'", a.getElement().getId()); configureLibraryEntry((Element) classpathentry, path, a.getElement().getName() + "-annotations"); }); } break; } case "con": { if (path.startsWith("org.eclipse.jdt.launching.JRE_CONTAINER/")) { configureLibraryEntry((Element) classpathentry, path, "jdk-annotations"); } break; } case "src": { configureSourceEntry((Element) classpathentry); } } } }
/** * Modifies the xml that was written in a previous call to {@link #workspaceFile(String, Object)} or * {@link #workspaceXml(String, Action)}. However, */ @SuppressWarnings("unchecked") public void workspaceXml(String destination, Action<XmlProvider> xmlSupplier) { workspaceXmls.merge(destination, xmlSupplier, (before, after) -> Actions.composite(before, after)); }
public void addAction(Closure closure) { actions.add(new ClosureBackedAction<XmlProvider>(closure)); }