-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite version command to show information about Ava and Watchdog
- Loading branch information
Showing
5 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.avairebot.watchdog; | ||
|
||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
public class AppInfo { | ||
|
||
private static AppInfo instance; | ||
|
||
private final String version; | ||
private final String groupId; | ||
private final String artifactId; | ||
|
||
private AppInfo() { | ||
Properties properties = new Properties(); | ||
try { | ||
properties.load( | ||
getClass().getClassLoader().getResourceAsStream("app.properties") | ||
); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to load app.properties", e); | ||
} | ||
|
||
this.version = properties.getProperty("version"); | ||
this.groupId = properties.getProperty("groupId"); | ||
this.artifactId = properties.getProperty("artifactId"); | ||
} | ||
|
||
public static AppInfo getAppInfo() { | ||
if (instance == null) { | ||
instance = new AppInfo(); | ||
} | ||
return instance; | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
public String getGroupId() { | ||
return groupId; | ||
} | ||
|
||
public String getArtifactId() { | ||
return artifactId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/avairebot/watchdog/VersionFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.avairebot.watchdog; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
|
||
class VersionFormatter { | ||
|
||
static void formatAndSend() { | ||
ProcessBuilder pb = new ProcessBuilder(); | ||
|
||
pb.command(Arrays.asList("java", "-jar", "AvaIre.jar", "--version", "--no-colors")); | ||
|
||
try { | ||
Process process = pb.start(); | ||
|
||
StringBuilder content = new StringBuilder(); | ||
try (InputStream inputStream = process.getInputStream()) { | ||
InputStreamReader streamReader = new InputStreamReader(inputStream); | ||
BufferedReader reader = new BufferedReader(streamReader); | ||
|
||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
content.append(line).append("\n"); | ||
} | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
process.waitFor(); | ||
process.destroy(); | ||
|
||
if (content.toString().trim().isEmpty()) { | ||
System.out.println("No AvaIre.jar file were found, unable to show the version of Ava being used."); | ||
System.out.println("Watchdog is version: " + AppInfo.getAppInfo().getVersion()); | ||
return; | ||
} | ||
|
||
for (String line : content.toString().split("\n")) { | ||
System.out.println(line); | ||
if (line.contains("Version:")) { | ||
StringBuilder watchdogLine = new StringBuilder("\tWatchdog:"); | ||
int index = line.indexOf(line.trim().split("\\s+")[1]); | ||
while (watchdogLine.length() < index) { | ||
watchdogLine.append(" "); | ||
} | ||
System.out.println(watchdogLine.append(AppInfo.getAppInfo().getVersion()).toString()); | ||
} | ||
} | ||
} catch (IOException | InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version[email protected]@ | ||
groupId[email protected]@ | ||
artifactId[email protected]@ |