Skip to content

Commit

Permalink
Initial code commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
netmikey committed Aug 30, 2012
1 parent f89af67 commit 3859653
Show file tree
Hide file tree
Showing 5 changed files with 407 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .project
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>
14 changes: 14 additions & 0 deletions build.gradle
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 src/main/java/com/netmikey/cvscanner/ClassVersionScanner.java
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);
}
}
61 changes: 61 additions & 0 deletions src/main/java/com/netmikey/cvscanner/JavaVersion.java
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;
}

}
Loading

0 comments on commit 3859653

Please sign in to comment.