Skip to content
This repository has been archived by the owner on Dec 23, 2020. It is now read-only.

Commit

Permalink
Fixed issue with empty directories and added support for running on
Browse files Browse the repository at this point in the history
Windows.
  • Loading branch information
mpellegrini committed Oct 17, 2011
1 parent c8d3eb4 commit 201c6e0
Showing 1 changed file with 81 additions and 51 deletions.
132 changes: 81 additions & 51 deletions src/main/java/org/jboss/busunit/util/scanner/JBossProductScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,22 @@
/**
*
* @author Michael Pellegrini
*
*
*/
public class JBossProductScanner {

private static final Pattern MF_VENDOR_PATTERN = Pattern.compile("jboss", Pattern.CASE_INSENSITIVE);
private static final Pattern MF_VERSION_ENT_PATTERN = Pattern.compile("jbpapp", Pattern.CASE_INSENSITIVE);
private static final Pattern MF_VERSION_COMU_PATTERN = Pattern.compile("jboss", Pattern.CASE_INSENSITIVE);
private static final Pattern MF_VERSION_ENTSOA_PATTERN = Pattern.compile("soa", Pattern.CASE_INSENSITIVE);
private static final Pattern MF_TITLE_EAP_PATTERN = Pattern.compile("eap", Pattern.CASE_INSENSITIVE);
private static final Pattern MF_TITLE_EWP_PATTERN = Pattern.compile("ewp", Pattern.CASE_INSENSITIVE);

private static final Pattern MF_VENDOR_PATTERN = Pattern.compile("jboss",
Pattern.CASE_INSENSITIVE);
private static final Pattern MF_VERSION_ENT_PATTERN = Pattern.compile(
"jbpapp", Pattern.CASE_INSENSITIVE);
private static final Pattern MF_VERSION_COMU_PATTERN = Pattern.compile(
"jboss", Pattern.CASE_INSENSITIVE);
private static final Pattern MF_VERSION_ENTSOA_PATTERN = Pattern.compile(
"soa", Pattern.CASE_INSENSITIVE);
private static final Pattern MF_TITLE_EAP_PATTERN = Pattern.compile("eap",
Pattern.CASE_INSENSITIVE);
private static final Pattern MF_TITLE_EWP_PATTERN = Pattern.compile("ewp",
Pattern.CASE_INSENSITIVE);

public static String startScan(File baseDir) throws Exception {
if (baseDir == null) {
Expand All @@ -54,58 +59,70 @@ public static String startScan(File baseDir) throws Exception {
if (!baseDir.exists()) {
throw new IllegalArgumentException("baseDir does not exisit.");
}

System.out.println("JBoss Product Scanner started scanning from " + baseDir);

//List<File> filesFound = new ArrayList<File>();

System.out.println("JBoss Product Scanner started scanning from "
+ baseDir);

// List<File> filesFound = new ArrayList<File>();
List filesFound = new ArrayList();
scan(filesFound, baseDir);
String report = produceReport(filesFound, baseDir);

return report;

}

private static String produceReport(List filesFound, File baseDir) {
final String NEW_LINE = System.getProperty("line.separator");

String hostName = "Unknown";
String ip = "Unknown";

try {
InetAddress inetAddr = InetAddress.getLocalHost();
hostName = inetAddr.getHostName();
ip = inetAddr.getHostAddress();
InetAddress inetAddr = InetAddress.getLocalHost();
hostName = inetAddr.getHostName();
ip = inetAddr.getHostAddress();
} catch (UnknownHostException e1) {
e1.printStackTrace();
}

StringBuffer sb = new StringBuffer();
sb.append("JBoss Product Scanner Report").append(NEW_LINE);
sb.append("Report created on : " + new java.util.Date()).append(NEW_LINE);
sb.append("Started scan from ").append(baseDir).append(NEW_LINE).append(NEW_LINE);
sb.append("Report created on : " + new java.util.Date()).append(
NEW_LINE);
sb.append("Started scan from ").append(baseDir).append(NEW_LINE)
.append(NEW_LINE);
sb.append("Summary").append(NEW_LINE);
sb.append("-------------------------------------------------").append(NEW_LINE);
sb.append("-------------------------------------------------").append(
NEW_LINE);
sb.append("Host Name: ").append(hostName).append(NEW_LINE);
sb.append("IP Address: ").append(ip).append(NEW_LINE);
sb.append("Operating System: ").append(System.getProperty("os.name"));
sb.append(" ").append(System.getProperty("os.version")).append(NEW_LINE);
sb.append("Operating System Architecture: ").append(System.getProperty("os.arch")).append(NEW_LINE);
sb.append("Number of available processors: ").append(Runtime.getRuntime().availableProcessors()).append(NEW_LINE);
sb.append("Java Virtual Machine: ").append(System.getProperty("java.vendor")).append(" ");
sb.append(" ").append(System.getProperty("os.version"))
.append(NEW_LINE);
sb.append("Operating System Architecture: ")
.append(System.getProperty("os.arch")).append(NEW_LINE);
sb.append("Number of available processors: ")
.append(Runtime.getRuntime().availableProcessors())
.append(NEW_LINE);
sb.append("Java Virtual Machine: ")
.append(System.getProperty("java.vendor")).append(" ");
sb.append(System.getProperty("java.version")).append(NEW_LINE);
sb.append("Found ").append(filesFound.size()).append(" possible JBoss ");
sb.append((filesFound.size() == 1) ? "installation" : "installations").append(NEW_LINE);
sb.append("Found ").append(filesFound.size())
.append(" possible JBoss ");
sb.append((filesFound.size() == 1) ? "installation" : "installations")
.append(NEW_LINE);
sb.append(NEW_LINE);
sb.append("Note: Identified Enterprise Platform installations could be ");
sb.append("bundled with other JBoss products or other 3rd party applications and ");
sb.append("bundled with other JBoss products or other 3rd party applications and ");
sb.append("therefore may not be a true standalone installation.");
sb.append(NEW_LINE);
sb.append("-------------------------------------------------").append(NEW_LINE).append(NEW_LINE);

sb.append("-------------------------------------------------")
.append(NEW_LINE).append(NEW_LINE);

for (Iterator iterator = filesFound.iterator(); iterator.hasNext();) {
File file = (File) iterator.next();

sb.append("Installation Location: ").append(file.toString())
.append(NEW_LINE);
try {
Expand All @@ -121,23 +138,31 @@ private static String produceReport(List filesFound, File baseDir) {

if (vendor != null && MF_VENDOR_PATTERN.matcher(vendor).find()) {
String title = mainAttrbs.getValue("Implementation-Title");
String version = mainAttrbs.getValue("Implementation-Version");
String version = mainAttrbs
.getValue("Implementation-Version");

sb.append("Product Name: ").append(title).append(NEW_LINE);
sb.append("Product Version: ").append(version).append(NEW_LINE);
sb.append("Product Version: ").append(version)
.append(NEW_LINE);

if (version != null && MF_VERSION_ENT_PATTERN.matcher(version).find()) {
if (title != null && MF_TITLE_EAP_PATTERN.matcher(title).find()) {
if (version != null
&& MF_VERSION_ENT_PATTERN.matcher(version).find()) {
if (title != null
&& MF_TITLE_EAP_PATTERN.matcher(title).find()) {
// Enterprise Application Platform
sb.append("This appears to be a JBoss Enterprise Application Platform installation");
} else if (title !=null && MF_TITLE_EWP_PATTERN.matcher(title).find()) {
sb.append("This appears to be a JBoss Enterprise Application Platform installation");
} else if (title != null
&& MF_TITLE_EWP_PATTERN.matcher(title).find()) {
// Enterprise Web Platform
sb.append("This appears to be a JBoss Enterprise Web Platform installation");
}
} else if (version != null && MF_VERSION_COMU_PATTERN.matcher(version).find()) {
} else if (version != null
&& MF_VERSION_COMU_PATTERN.matcher(version).find()) {
// Community
sb.append("This appears to be a JBoss Application Server Community installation");
} else if (version != null && MF_VERSION_ENTSOA_PATTERN.matcher(version).find()) {
} else if (version != null
&& MF_VERSION_ENTSOA_PATTERN.matcher(version)
.find()) {
// Enterprise SOA Platform
sb.append("This appears to be a JBoss SOA Platform Enterprise installation");
} else {
Expand All @@ -147,29 +172,34 @@ private static String produceReport(List filesFound, File baseDir) {
sb.append("This does not appear to be a valid JBoss installation");
}
sb.append(NEW_LINE).append(NEW_LINE);
sb.append("-------------------------------------------------").append(NEW_LINE).append(NEW_LINE);
sb.append("-------------------------------------------------")
.append(NEW_LINE).append(NEW_LINE);
} catch (IOException e) {
e.printStackTrace();
}
}

return sb.toString();
}

private static void scan(List results, File directory) {
// Determine if there is sufficient rights to read the file or directory
if (directory.canRead()) {
File files[] = directory.listFiles();

for (int i = 0; i < files.length; i++) {
File file = files[i];

if (file.isDirectory() && !isLink(file)) {
scan(results, file);
} else {
if (file.getName().equals("run.jar")) {
System.out.println("Found possible JBoss installation at " + file);
results.add(file);
if (files != null) {
for (int i = 0; i < files.length; i++) {
File file = files[i];

if (file.isDirectory() && !isLink(file)) {
scan(results, file);
} else {
if (file.getName().equals("run.jar")) {
System.out
.println("Found possible JBoss installation at "
+ file);
results.add(file);
}
}
}
}
Expand Down

0 comments on commit 201c6e0

Please sign in to comment.