private static String processPart(String pluginIdPart) { StringBuilder sb = new StringBuilder(); String[] parts = pluginIdPart.split("-"); for (String part: parts) { sb.append(StringUtil.capitalize(part)); } return sb.toString(); }
static String getNonEmpty(String value) { if (StringUtil.isEmpty(value)) { return null; } return value; } }
private String getDependencyWithArtifacts(CreateDependencyInfoFileTask task, ModuleDependency dependency) { String result = getDependency(task, dependency); if (!dependency.getArtifacts().isEmpty()) { //sorting artifacts to assure that they are always in the same order //without depending on Gradle implementation SortedSet<String> artifacts = new TreeSet<>(); for (DependencyArtifact artifact : dependency.getArtifacts()) { artifacts.add(getArtifact(artifact)); } return result + ARTIFACT_INDENT + StringUtil.join(artifacts, ARTIFACT_INDENT); } return result; }
public void execute(Task task) { LOG.lifecycle(" Running:\n {}", join(exec.getCommandLine(), " ")); } });
private String getDependencyWithArtifacts(CreateDependencyInfoFileTask task, ModuleDependency dependency) { String result = getDependency(task, dependency); if (!dependency.getArtifacts().isEmpty()) { //sorting artifacts to assure that they are always in the same order //without depending on Gradle implementation SortedSet<String> artifacts = new TreeSet<>(); for (DependencyArtifact artifact : dependency.getArtifacts()) { artifacts.add(getArtifact(artifact)); } return result + ARTIFACT_INDENT + StringUtil.join(artifacts, ARTIFACT_INDENT); } return result; }
static String getNonEmpty(String value) { if (StringUtil.isEmpty(value)) { return null; } return value; } }
private static String processPart(String pluginIdPart) { StringBuilder sb = new StringBuilder(); String[] parts = pluginIdPart.split("-"); for (String part: parts) { sb.append(StringUtil.capitalize(part)); } return sb.toString(); }
public void createDependencyInfoFile(CreateDependencyInfoFileTask task) { String result = "# Description" + NEWLINE + DESCRIPTION + NEWLINE + "# Dependencies"; //sorting dependencies to assure that they are always in the same order //without depending on Gradle implementation SortedSet<String> dependencies = new TreeSet<>(); for (Dependency dependency: task.getConfiguration().getAllDependencies()) { if (dependency instanceof ModuleDependency) { String dep = getDependencyWithArtifacts(task, (ModuleDependency) dependency); dependencies.add(dep); } } result += DEPENDENCY_INDENT + StringUtil.join(dependencies, DEPENDENCY_INDENT); IOUtil.writeFile(task.getOutputFile(), result.toString()); }
private static String link(String text, String link) { return isEmpty(link) ? text : "[" + text + "](" + link + ")"; }
/** * Formats repositoryName to camel case version of it with the first letter capitalized. Eg. * "mockito/shipkit" -> "MockitoShipkit" * "mockito/shipkit-example" -> "MockitoShipkitExample" * * @param repositoryName GitHub repo name in format "org/repo", eg. "mockito/shipkit" */ public static String repositoryNameToCapitalizedCamelCase(String repositoryName) { return StringUtil.capitalize(repositoryNameToCamelCase(repositoryName)); }
/** * generates diff between contents of two files in the same format as "git diff" */ public String generateDiff(String previousFilePath, String currentFilePath, String previousContent, String currentContent) { List<String> previousLines = breakIntoLines(previousContent); List<String> currentLines = breakIntoLines(currentContent); Patch<String> patch = DiffUtils.diff(previousLines, currentLines); List<String> unifiedDiff = DiffUtils.generateUnifiedDiff(previousFilePath, currentFilePath, previousLines, patch, 0); if(unifiedDiff.size() <= 2){ return ""; // no differences found } List<String> diffWithoutFileNames = unifiedDiff.subList(2, unifiedDiff.size()); // remove file names return INDENTATION + StringUtil.join(diffWithoutFileNames, getLineSeparator() + INDENTATION); }
private static String link(String text, String link) { return StringUtil.isEmpty(link) ? text : "[" + text + "](" + link + ")"; }
/** * Formats repositoryName to camel case version of it with the first letter capitalized. Eg. * "mockito/shipkit" -> "MockitoShipkit" * "mockito/shipkit-example" -> "MockitoShipkitExample" * * @param repositoryName GitHub repo name in format "org/repo", eg. "mockito/shipkit" */ public static String repositoryNameToCapitalizedCamelCase(String repositoryName) { return StringUtil.capitalize(repositoryNameToCamelCase(repositoryName)); }
/** * generates diff between contents of two files in the same format as "git diff" */ public String generateDiff(String previousContent, String currentContent, int context) { List<String> previousLines = breakIntoLines(previousContent); List<String> currentLines = breakIntoLines(currentContent); Patch<String> patch = DiffUtils.diff(previousLines, currentLines); List<String> unifiedDiff = DiffUtils.generateUnifiedDiff("", "", previousLines, patch, context); if (unifiedDiff.size() <= 2) { return ""; // no differences found } List<String> diffWithoutFileNames = unifiedDiff.subList(2, unifiedDiff.size()); // remove file names return INDENTATION + StringUtil.join(diffWithoutFileNames, getLineSeparator() + INDENTATION); }
private static String link(String text, String link) { return StringUtil.isEmpty(link) ? text : "[" + text + "](" + link + ")"; }
static List<String> getClassCandidates(String pluginId) { List<String> candidates = new ArrayList<>(); String[] pluginIdParts = pluginId.split("\\."); String previousCandidate = "Plugin"; if (pluginId.toLowerCase().endsWith(previousCandidate.toLowerCase())) { previousCandidate = ""; } for (int i = pluginIdParts.length - 1; i >= 0; i--) { String candidate = StringUtil.capitalize(processPart(pluginIdParts[i])) + previousCandidate; candidates.add(candidate); previousCandidate = candidate; } return candidates; }
/** * generates diff between contents of two files in the same format as "git diff" */ public String generateDiff(String previousContent, String currentContent, int context) { List<String> previousLines = breakIntoLines(previousContent); List<String> currentLines = breakIntoLines(currentContent); Patch<String> patch = DiffUtils.diff(previousLines, currentLines); List<String> unifiedDiff = DiffUtils.generateUnifiedDiff("", "", previousLines, patch, context); if (unifiedDiff.size() <= 2) { return ""; // no differences found } List<String> diffWithoutFileNames = unifiedDiff.subList(2, unifiedDiff.size()); // remove file names return INDENTATION + StringUtil.join(diffWithoutFileNames, getLineSeparator() + INDENTATION); }
private String formatVersionInformationInCommitMessage(String version, String previousVersion) { String versionMessage = format("%s release", version); if (StringUtil.isEmpty(previousVersion)) { return versionMessage; } else { return format("%s (previous %s)", versionMessage, previousVersion); } } }
static List<String> getClassCandidates(String pluginId) { List<String> candidates = new ArrayList<>(); String[] pluginIdParts = pluginId.split("\\."); String previousCandidate = "Plugin"; if (pluginId.toLowerCase().endsWith(previousCandidate.toLowerCase())) { previousCandidate = ""; } for (int i = pluginIdParts.length - 1; i >= 0; i--) { String candidate = StringUtil.capitalize(processPart(pluginIdParts[i])) + previousCandidate; candidates.add(candidate); previousCandidate = candidate; } return candidates; }
public DefaultVersionInfo bumpVersion(boolean updateNotable) { String content = IOUtil.readFully(versionFile); if (updateNotable) { notableVersions.addFirst(version); String asString = "notableVersions=" + StringUtil.join(notableVersions, ", ") + "\n"; if (notableVersions.size() == 1) { //when no prior notable versions, we just add new entry content += "\n" + asString; } else { //update existing entry content = content.replaceAll("(?m)^notableVersions=(.*?)\n", asString); } } String previousVersion = this.version; String newVersion = new VersionBumper().incrementVersion(this.version); if (!content.endsWith("\n")) { //This makes the regex simpler. Add arbitrary end of line at the end of file should not bother anyone. //See also unit tests for this class content += "\n"; } String updated = content .replaceAll("(?m)^version=(.*?)\n", "version=" + newVersion + "\n") .replaceAll("(?m)^previousVersion=(.*?)\n", "previousVersion=" + previousVersion + "\n"); if (!updated.contains("previousVersion")) { updated += "previousVersion=" + previousVersion + "\n"; } IOUtil.writeFile(versionFile, updated); return new DefaultVersionInfo(versionFile, newVersion, notableVersions, previousVersion); }