-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
407 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>classversion-scanner</name> | ||
<comment/> | ||
<projects/> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments/> | ||
</buildCommand> | ||
</buildSpec> | ||
<linkedResources/> | ||
</projectDescription> |
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,14 @@ | ||
|
||
apply plugin: 'java' | ||
apply plugin: 'eclipse' | ||
apply plugin: 'application' | ||
|
||
mainClassName = "com.netmikey.cvscanner.ClassVersionScanner" | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
compile (group: 'commons-cli', name: 'commons-cli', version: '1.2') | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/netmikey/cvscanner/ClassVersionScanner.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,57 @@ | ||
package com.netmikey.cvscanner; | ||
|
||
import java.io.File; | ||
import java.util.logging.Level; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.CommandLineParser; | ||
import org.apache.commons.cli.HelpFormatter; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.PosixParser; | ||
|
||
/** | ||
* Main class for running the Class Version Scanner. | ||
* | ||
* @author netmikey | ||
*/ | ||
public class ClassVersionScanner { | ||
/** | ||
* Main method. | ||
* | ||
* @param argv | ||
* Command-Line arguments. | ||
* @throws Exception | ||
* Something went horribly wrong. | ||
*/ | ||
public static void main(String[] argv) throws Exception { | ||
// Command line stuff... | ||
Options opt = new Options(); | ||
opt.addOption("d", "dir", true, "the root directory from which to search for class files and java archives " | ||
+ "(if not set, the current working directory will be used)."); | ||
opt.addOption("n", "newer", true, "only look for class files compiled for the specified JRE and newer"); | ||
opt.addOption("o", "older", true, "only look for class files compiled for the specified JRE and older"); | ||
// I know java logging can be configured in an "awesome" *cough* way, | ||
// but srsly, nobody wants to do that for a little command line tool | ||
// like this... | ||
opt.addOption("v", "verbose", false, "display more processing info"); | ||
opt.addOption("h", "help", false, "display this help info"); | ||
|
||
CommandLineParser parser = new PosixParser(); | ||
CommandLine cmd = parser.parse(opt, argv); | ||
|
||
if (cmd.hasOption("help")) { | ||
HelpFormatter formatter = new HelpFormatter(); | ||
formatter.printHelp(ClassVersionScanner.class.getName(), opt); | ||
return; | ||
} | ||
|
||
Scanner scanner = new Scanner(); | ||
File baseDir = new File(cmd.hasOption("dir") ? cmd.getOptionValue("dir") : System.getProperty("user.dir")); | ||
scanner.setMinVersion(Scanner.VERSIONS.get(cmd.getOptionValue("newer"))); | ||
scanner.setMaxVersion(Scanner.VERSIONS.get(cmd.getOptionValue("older"))); | ||
if (cmd.hasOption("verbose")) { | ||
scanner.setFineLevel(Level.INFO); | ||
} | ||
scanner.scanForVersion(baseDir); | ||
} | ||
} |
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,61 @@ | ||
package com.netmikey.cvscanner; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* Wraps the required metadata of a java version/release. | ||
* | ||
* @author netmikey | ||
*/ | ||
public class JavaVersion { | ||
private int version; | ||
|
||
private List<String> aliases; | ||
|
||
private long classFileVersion; | ||
|
||
/** | ||
* Default constructor. | ||
* | ||
* @param version | ||
* The numeric value of the java version. | ||
* @param classFileVersion | ||
* The class file version that corresponds to this java version. | ||
* @param aliases | ||
* A list of aliases that match this version. | ||
*/ | ||
public JavaVersion(int version, long classFileVersion, String... aliases) { | ||
this.version = version; | ||
this.classFileVersion = classFileVersion; | ||
this.aliases = Arrays.asList(aliases); | ||
} | ||
|
||
/** | ||
* Get the version. | ||
* | ||
* @return Returns the version. | ||
*/ | ||
public int getVersion() { | ||
return version; | ||
} | ||
|
||
/** | ||
* Get the aliases. | ||
* | ||
* @return Returns the aliases. | ||
*/ | ||
public List<String> getAliases() { | ||
return aliases; | ||
} | ||
|
||
/** | ||
* Get the classFileVersion. | ||
* | ||
* @return Returns the classFileVersion. | ||
*/ | ||
public long getClassFileVersion() { | ||
return classFileVersion; | ||
} | ||
|
||
} |
Oops, something went wrong.