| ... | ...@@ -20,21 +20,33 @@ |
| 20 | 20 | |
| 21 | 21 | public class DefaultModuleReport extends ModuleReport { |
| 22 | 22 | |
| 23 | | private static final int INDENT_WIDTH = 3; |
| 24 | | private static final String INDENT_CHAR = " "; |
| 25 | | private static final String DEFAULT_GROUPID = "org.terracotta.modules"; |
| 26 | | private static final String LEGEND = "(+) Installed (!) Installed but newer version exists (-) Not installed"; |
| 23 | private static final String INSTALLED_MARKER = "+"; |
| 24 | private static final String NOTINSTALLED_MARKER = "-"; |
| 25 | private static final String OUTOFDATE_MARKER = "!"; |
| 26 | |
| 27 | private static final int INDENT_WIDTH = 3; |
| 28 | private static final String INDENT_CHAR = " "; |
| 29 | private static final String DEFAULT_GROUPID = "org.terracotta.modules"; |
| 30 | private static final String LEGEND = "(+) Installed (-) Not installed (!) Installed but newer version exists"; |
| 31 | |
| 32 | private String canonicalize(File path) { |
| 33 | try { |
| 34 | return path.getCanonicalFile().toString(); |
| 35 | } catch (IOException e) { |
| 36 | return path.toString(); |
| 37 | } |
| 38 | } |
| 27 | 39 | |
| 28 | 40 | private String marker(Module module) { |
| 29 | | if (!module.isInstalled()) return "-"; |
| 30 | | return module.isLatest() ? "+" : "!"; |
| 41 | if (!module.isInstalled()) return NOTINSTALLED_MARKER; |
| 42 | return module.isLatest() ? INSTALLED_MARKER : OUTOFDATE_MARKER; |
| 31 | 43 | } |
| 32 | 44 | |
| 33 | 45 | private boolean isUsingDefaultGroupId(AbstractModule module) { |
| 34 | 46 | return DEFAULT_GROUPID.equals(module.groupId()); |
| 35 | 47 | } |
| 36 | 48 | |
| 37 | | private String indent(String text, int spaces) { |
| 49 | private String indent(String text) { |
| 38 | 50 | StringBuffer result = new StringBuffer(); |
| 39 | 51 | String[] lines = StringUtils.split(text, '\n'); |
| 40 | 52 | for (String line : lines) { |
| ... | ...@@ -92,7 +104,7 @@ |
| 92 | 104 | String compatibility = module.tcVersion().equals("*") ? "any Terracotta version." : "TC " + module.tcVersion(); |
| 93 | 105 | out.println("Compatible with " + compatibility); |
| 94 | 106 | |
| 95 | | String text = indent(writer.toString(), INDENT_WIDTH); |
| 107 | String text = indent(writer.toString()); |
| 96 | 108 | return StringUtils.chomp(StringUtils.trim(text)); |
| 97 | 109 | } |
| 98 | 110 | |
| ... | ...@@ -101,12 +113,12 @@ |
| 101 | 113 | PrintWriter out = new PrintWriter(writer); |
| 102 | 114 | |
| 103 | 115 | out.println("Dependencies:\n "); |
| 104 | | if (module.dependencies().isEmpty()) out.println("None."); |
| 116 | if (module.dependencies().isEmpty()) out.println(indent("None.")); |
| 105 | 117 | |
| 106 | 118 | for (AbstractModule dependency : module.dependencies()) { |
| 107 | 119 | String line = "* " + dependency.artifactId() + " " + dependency.version(); |
| 108 | 120 | if (!isUsingDefaultGroupId(dependency)) line = line.concat(" [" + dependency.groupId() + "]"); |
| 109 | | out.println(indent(line, INDENT_WIDTH)); |
| 121 | out.println(indent(line)); |
| 110 | 122 | } |
| 111 | 123 | |
| 112 | 124 | String text = writer.toString(); |
| ... | ...@@ -117,9 +129,9 @@ |
| 117 | 129 | StringWriter writer = new StringWriter(); |
| 118 | 130 | PrintWriter out = new PrintWriter(writer); |
| 119 | 131 | out.println("Maven Coordinates:\n "); |
| 120 | | out.println(indent("groupId : " + module.groupId(), INDENT_WIDTH)); |
| 121 | | out.println(indent("artifactId: " + module.artifactId(), INDENT_WIDTH)); |
| 122 | | out.println(indent("version : " + module.version(), INDENT_WIDTH)); |
| 132 | out.println(indent("groupId : " + module.groupId())); |
| 133 | out.println(indent("artifactId: " + module.artifactId())); |
| 134 | out.println(indent("version : " + module.version())); |
| 123 | 135 | |
| 124 | 136 | String text = writer.toString(); |
| 125 | 137 | return StringUtils.chomp(StringUtils.trim(text)); |
| ... | ...@@ -143,7 +155,7 @@ |
| 143 | 155 | XMLOutputter xmlout = new XMLOutputter(formatter); |
| 144 | 156 | try { |
| 145 | 157 | xmlout.output(parent, new PrintWriter(sw)); |
| 146 | | out.println(indent(sw.toString(), INDENT_WIDTH)); |
| 158 | out.println(indent(sw.toString())); |
| 147 | 159 | } catch (IOException e) { |
| 148 | 160 | out.println(e.getMessage()); |
| 149 | 161 | } |
| ... | ...@@ -156,11 +168,16 @@ |
| 156 | 168 | StringWriter writer = new StringWriter(); |
| 157 | 169 | PrintWriter out = new PrintWriter(writer); |
| 158 | 170 | |
| 159 | | // XXX this is not accurate - a module may also be installed at the root |
| 160 | 171 | if (module.isInstalled()) { |
| 161 | 172 | Modules owner = module.owner(); |
| 173 | |
| 174 | // XXX compute actual location if installed - remember that |
| 175 | // a TIM may also be installed at the root of the repository |
| 162 | 176 | File location = new File(owner.repository(), module.installPath().toString()); |
| 163 | | out.println("Installed at " + location.getParent()); |
| 177 | location = new File(location, module.filename()); |
| 178 | File actualLocation = location.exists() ? location.getParentFile() : owner.repository(); |
| 179 | out.println("Installed at " + canonicalize(actualLocation)); |
| 180 | |
| 164 | 181 | if (module.isLatest()) out.println("This is the latest version.\n "); |
| 165 | 182 | else out.println("A newer version is available.\n "); |
| 166 | 183 | } |
| ... | ...@@ -168,27 +185,27 @@ |
| 168 | 185 | if (module.versions().isEmpty()) { |
| 169 | 186 | out.println("There are no other versions of this TIM that are compatible with TC " + module.tcVersion()); |
| 170 | 187 | } else { |
| 171 | | out.println("The following versions are also available for TC " + module.tcVersion() + ":\n "); |
| 188 | out.println("The following versions are also available:\n "); |
| 172 | 189 | List<Module> siblings = module.siblings(); |
| 173 | 190 | Collections.reverse(siblings); |
| 174 | 191 | for (Module sibling : siblings) { |
| 175 | | String line = "* " + sibling.version(); |
| 176 | | if (sibling.isInstalled()) line = line.concat(" (installed)"); |
| 177 | | out.println(indent(line, INDENT_WIDTH)); |
| 192 | String marker = "(" + (sibling.isInstalled() ? INSTALLED_MARKER : NOTINSTALLED_MARKER) + ") "; |
| 193 | String line = marker + sibling.version(); |
| 194 | out.println(indent(line)); |
| 178 | 195 | } |
| 179 | 196 | out.println("\n "); |
| 180 | 197 | } |
| 181 | 198 | |
| 199 | // XXX NEED A BETTER WAY HEURISTIC PRESENT THIS INSTALL/UPDATE INSTRUCTION |
| 182 | 200 | if (!module.isInstalled() || !module.isLatest()) { |
| 183 | 201 | out.println("Issue the following command to install the latest version:\n "); |
| 184 | | |
| 185 | 202 | String script = "tim-get."; |
| 186 | 203 | script += (Os.isWindows() ? "bat" : "sh"); |
| 187 | 204 | script += INDENT_CHAR + (module.isInstalled() ? "update" : "install"); |
| 188 | 205 | script += INDENT_CHAR + module.artifactId(); |
| 189 | 206 | script += INDENT_CHAR + module.version(); |
| 190 | 207 | if (isUsingDefaultGroupId(module)) script += INDENT_CHAR + module.groupId(); |
| 191 | | out.println(indent(script, INDENT_WIDTH)); |
| 208 | out.println(indent(script)); |
| 192 | 209 | } |
| 193 | 210 | |
| 194 | 211 | String text = writer.toString(); |
| ... | ...@@ -202,13 +219,13 @@ |
| 202 | 219 | |
| 203 | 220 | out.println(digest(module)); |
| 204 | 221 | out.println(); |
| 205 | | out.println(indent(dependencies(module), INDENT_WIDTH)); |
| 222 | out.println(indent(dependencies(module))); |
| 206 | 223 | out.println(); |
| 207 | | out.println(indent(mavenCoordinates(module), INDENT_WIDTH)); |
| 224 | out.println(indent(mavenCoordinates(module))); |
| 208 | 225 | out.println(); |
| 209 | | out.println(indent(configInfo(module), INDENT_WIDTH)); |
| 226 | out.println(indent(configInfo(module))); |
| 210 | 227 | out.println(); |
| 211 | | out.println(indent(installationInfo(module), INDENT_WIDTH)); |
| 228 | out.println(indent(installationInfo(module))); |
| 212 | 229 | |
| 213 | 230 | String text = writer.toString(); |
| 214 | 231 | return StringUtils.chomp(StringUtils.trim(text)); |