Author: rob.stryker(a)jboss.com
Date: 2011-05-05 10:31:15 -0400 (Thu, 05 May 2011)
New Revision: 31102
Added:
workspace/rstryker/CheckAllVersions/
workspace/rstryker/CheckAllVersions/.classpath
workspace/rstryker/CheckAllVersions/.project
workspace/rstryker/CheckAllVersions/.settings/
workspace/rstryker/CheckAllVersions/.settings/org.eclipse.jdt.core.prefs
workspace/rstryker/CheckAllVersions/bin/
workspace/rstryker/CheckAllVersions/bin/check/
workspace/rstryker/CheckAllVersions/bin/check/versions/
workspace/rstryker/CheckAllVersions/bin/check/versions/Main$TempLog.class
workspace/rstryker/CheckAllVersions/bin/check/versions/Main.class
workspace/rstryker/CheckAllVersions/src/
workspace/rstryker/CheckAllVersions/src/check/
workspace/rstryker/CheckAllVersions/src/check/versions/
workspace/rstryker/CheckAllVersions/src/check/versions/Main.java
Log:
workspace stuff for me and nick boldt
Added: workspace/rstryker/CheckAllVersions/.classpath
===================================================================
--- workspace/rstryker/CheckAllVersions/.classpath (rev 0)
+++ workspace/rstryker/CheckAllVersions/.classpath 2011-05-05 14:31:15 UTC (rev 31102)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added: workspace/rstryker/CheckAllVersions/.project
===================================================================
--- workspace/rstryker/CheckAllVersions/.project (rev 0)
+++ workspace/rstryker/CheckAllVersions/.project 2011-05-05 14:31:15 UTC (rev 31102)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>CheckAllVersions</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added: workspace/rstryker/CheckAllVersions/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- workspace/rstryker/CheckAllVersions/.settings/org.eclipse.jdt.core.prefs
(rev 0)
+++ workspace/rstryker/CheckAllVersions/.settings/org.eclipse.jdt.core.prefs 2011-05-05
14:31:15 UTC (rev 31102)
@@ -0,0 +1,12 @@
+#Wed May 04 10:12:28 CST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
Added: workspace/rstryker/CheckAllVersions/bin/check/versions/Main$TempLog.class
===================================================================
(Binary files differ)
Property changes on:
workspace/rstryker/CheckAllVersions/bin/check/versions/Main$TempLog.class
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: workspace/rstryker/CheckAllVersions/bin/check/versions/Main.class
===================================================================
(Binary files differ)
Property changes on: workspace/rstryker/CheckAllVersions/bin/check/versions/Main.class
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: workspace/rstryker/CheckAllVersions/src/check/versions/Main.java
===================================================================
--- workspace/rstryker/CheckAllVersions/src/check/versions/Main.java
(rev 0)
+++ workspace/rstryker/CheckAllVersions/src/check/versions/Main.java 2011-05-05 14:31:15
UTC (rev 31102)
@@ -0,0 +1,338 @@
+package check.versions;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class Main {
+ public static final String LAST_MAJOR_PROP =
"check.versions.last.major.tag.prop";
+ public static final String MAINTENANCE_STREAM =
"check.versions.maintenance.stream.prop";
+ public static final String TRUNK_STREAM = "check.versions.trunk.stream.prop";
+ public static final String LAST_MAJOR_LOC = System.getProperty(LAST_MAJOR_PROP);
+ public static final String MAINTENANCE_LOC = System.getProperty(MAINTENANCE_STREAM);
+ public static final String TRUNK_LOC = System.getProperty(TRUNK_STREAM);
+ public static final String[] excludes = new String[] { ".svn",
"bin", ".gitignore", "pom.xml" };
+
+ public static final int TRANSITION_MAINTENANCE=1;
+ public static final int TRANSITION_MAJOR=2;
+ private int currentTransition = 0;
+
+ private ArrayList<String> changedPlugins = new ArrayList<String>();
+
+ public static void main(String[] args) {
+ new Main().execute();
+ }
+
+ public void execute() {
+ diffRoots();
+ }
+
+ // replace with maven log later
+ public class TempLog {
+ public void trace(String s) {
+ //System.out.println(s);
+ }
+ public void info(String s) {
+ System.out.println(s);
+ }
+ public void error(String s) {
+ System.out.println(s);
+ }
+ public void warn(String s) {
+ System.out.println(s);
+ }
+ }
+ private TempLog log = new TempLog();
+ public TempLog getLog() {
+ return log;
+ }
+ // end log bullshit
+
+ public void diffRoots() {
+ printUsage();
+ getLog().info("Comparing last major release to maintenance\n\n");
+ currentTransition = TRANSITION_MAINTENANCE;
+ diffRoots(LAST_MAJOR_LOC, MAINTENANCE_LOC);
+ getLog().info("\n\n");
+ getLog().info("Comparing maintenance release to trunk\n\n");
+ currentTransition = TRANSITION_MAJOR;
+ diffRoots(MAINTENANCE_LOC, TRUNK_LOC);
+ }
+
+ private void printUsage() {
+ getLog().info("**************");
+ getLog().info("* Running comparisons");
+ getLog().info("*");
+ getLog().info("* Ignoring following files / folders: " );
+ for( int i = 0; i < excludes.length; i++ ) {
+ getLog().info("* " + excludes[i]);
+ }
+ getLog().info("*");
+ getLog().info("* Example diff command: ");
+ getLog().info("* diff -r --exclude=.svn --exclude=bin --exclude=.gitignore
--exclude=pom.xml ${root1}/jmx/plugins/org.jboss.tools.jmx.core
${root2}/jmx/plugins/org.jboss.tools.jmx.core");
+ getLog().info("*************");
+
+ getLog().info("\n\n");
+ }
+
+ public void diffRoots(String oldLoc, String newLoc) {
+ String[] oldMods = new File(oldLoc).list();
+ String[] newMods2 = new File(newLoc).list();
+ ArrayList<String> newMods = new ArrayList<String>();
+ newMods.addAll(Arrays.asList(newMods2));
+ for( int i = 0; i < oldMods.length; i++ ) {
+ if( !ignore(oldMods[i])) {
+ // ONLY handle modules that are in both locations
+ if( newMods.contains(oldMods[i])) {
+ getLog().info(" [Module " + oldMods[i] + "]");
+ diffMod(oldLoc, newLoc, oldMods[i]);
+ } else {
+ getLog().info(" [Module " + oldMods[i] + "] - IGNORING, not present
in newer branch");
+ }
+ }
+ }
+ }
+
+ public void diffMod(String oldLoc, String newLoc, String mod) {
+ diffPluginContainer(oldLoc, newLoc, mod, "plugins");
+ diffPluginContainer(oldLoc, newLoc, mod, "tests");
+ handleFeatures(oldLoc, newLoc, mod);
+ }
+
+ private void handleFeatures(String oldLoc, String newLoc, String module) {
+
+ }
+
+ private boolean ignore(String folder) {
+ if( Arrays.asList(excludes).contains(folder))
+ return true;
+ if( folder.equals("pom.xml"))
+ return true;
+ return false;
+ }
+
+ public void diffPluginContainer(String oldLoc, String newLoc, String mod, String folder)
{
+ if( ignore( folder ))
+ return;
+
+ File o1 = new File(new File(new File(oldLoc), mod), folder);
+ File n1 = new File(new File(new File(newLoc), mod), folder);
+ String[] oldbundles = o1.list();
+ String[] newbundles2 = n1.list();
+ ArrayList<String> newbundles = new ArrayList<String>();
+ if( newbundles2 != null )
+ newbundles.addAll(Arrays.asList(newbundles2));
+ if( oldbundles != null ) {
+ for( int i = 0; i < oldbundles.length; i++ ) {
+ // ONLY handle modules that are in both locations
+ if( newbundles.contains(oldbundles[i]) && !ignore(oldbundles[i])) {
+ handleOneBundle(o1, n1, oldbundles[i]);
+ }
+ }
+ }
+ }
+
+ private void handleOneBundle(File o1, File n1, String bundleName) {
+ // Handle / diff one bundle
+ File bundle1 = new File(o1, bundleName);
+ File bundle2 = new File(n1, bundleName);
+ String out = diffBundleString(bundle1, bundle2);
+ int bundleDiffLength = out == null ? -1 : out.length();
+ if( out == null ) {
+ getLog().error(" * IOException while executing diff for bundle " +
bundle1.getName());
+ } else {
+ getLog().trace(" * bundle " + bundle1.getName() + " has a diff of
length " + bundleDiffLength);
+ if( bundle1.isFile() && bundle2.isFile())
+ getLog().trace(" * ignoring file " + bundle1.getName());
+ else {
+ handleOneBundle2(bundle1, bundle2, bundleDiffLength > 0);
+ changedPlugins.add(bundle1.getName());
+ }
+ }
+ }
+
+ private void handleOneBundle2(File bundle1, File bundle2, boolean requiresIncrement) {
+ File manifest1 = new File(new File(bundle1, "META-INF"),
"MANIFEST.MF");
+ File manifest2 = new File(new File(bundle2, "META-INF"),
"MANIFEST.MF");
+ File pom1 = new File(bundle1, "pom.xml");
+ File pom2 = new File(bundle2, "pom.xml");
+
+ if( !manifest1.exists())
+ getLog().error( " *** Manifest1 does not exist: " +
manifest1.getAbsolutePath());
+ if( !manifest2.exists())
+ getLog().error( " *** Manifest2 does not exist: " +
manifest2.getAbsolutePath());
+ if( !pom1.exists())
+ getLog().error( " *** Pom1 does not exist: " + pom1.getAbsolutePath());
+ if( !pom2.exists())
+ getLog().error( " *** Pom2 does not exist: " + pom2.getAbsolutePath());
+
+ String manVersion1 = findManifestVersion(manifest1);
+ String manVersion2 = findManifestVersion(manifest2);
+ String pomVersion1 = findPomVersion(pom1);
+ String pomVersion2 = findPomVersion(pom2);
+
+ if( manifest1.exists() && manVersion1 == null )
+ getLog().error( " *** No manifest version number for " +
manifest1.getAbsolutePath());
+ if( manifest2.exists() && manVersion2 == null )
+ getLog().error( " *** No manifest version number for " +
manifest2.getAbsolutePath());
+ if( pom1.exists() && pomVersion1 == null )
+ getLog().error( " *** No pom version number for " +
pom1.getAbsolutePath());
+ if( pom2.exists() && pomVersion2 == null )
+ getLog().error( " *** No pom version number for " +
pom2.getAbsolutePath());
+
+ if( manVersion1 != null && !manVersion1.endsWith(".qualifier"))
+ getLog().trace( " *** No '.qualifier' in file " +
manifest1.getAbsolutePath());
+ if( manVersion2 != null && !manVersion2.endsWith(".qualifier"))
+ getLog().trace( " *** No '.qualifier' in file " +
manifest2.getAbsolutePath());
+ if( pomVersion1 != null && !pomVersion1.endsWith("-SNAPSHOT"))
+ getLog().trace( " *** No '-SNAPSHOT' in file " +
pom1.getAbsolutePath());
+ if( pomVersion2 != null && !pomVersion2.endsWith("-SNAPSHOT"))
+ getLog().trace( " *** No '-SNAPSHOT' in file " +
pom2.getAbsolutePath());
+
+
+ String man1Small, man2Small, pom1Small, pom2Small;
+ man1Small = getSmallManifestVersion(manVersion1);
+ man2Small = getSmallManifestVersion(manVersion2);
+ pom1Small = getSmallPomVersion(pomVersion1);
+ pom2Small = getSmallPomVersion(pomVersion2);
+ if( man1Small != null && pom1Small != null &&
!pom1Small.equals(man1Small))
+ getLog().error(" *** Previous version's pom.xml and manifest.mf version
string for bundle " + bundle1.getName() + " do not match. (pom=" +
pom1Small + " vs manifest=" + man1Small + ")");
+ if( man2Small != null && pom2Small != null &&
!pom2Small.equals(man2Small))
+ getLog().error(" *** Newer version's pom.xml and manifest.mf version
string for bundle " + bundle1.getName() + " do not match. (pom=" +
pom2Small + " vs manifest=" + man2Small + ")");
+
+ if( requiresIncrement) {
+ if( man1Small != null && man2Small != null &&
man1Small.equals(man2Small))
+ getLog().error(getIncrementString("manifest", bundle1.getName(),
man1Small));
+ if( pom1Small != null && pom2Small != null &&
pom1Small.equals(pom2Small))
+ getLog().error(getIncrementString("pom.xml", bundle1.getName(),
pom1Small));
+ }
+ }
+
+ private String getIncrementString(String file, String bundleName, String
previousVersion) {
+ String[] prevArr = previousVersion.split("\\.");
+ int index = currentTransition == TRANSITION_MAINTENANCE ? 1 : 2;
+ String p = prevArr[prevArr.length-index];
+ try {
+ int tmp = new Integer(p).intValue();
+ prevArr[prevArr.length-index] = "" + (tmp+1);
+ String newVersion = prevArr[0];
+ for( int i = 1; i < prevArr.length; i++ )
+ newVersion += "." + prevArr[i];
+ return " *** Bundle " + bundleName + " has changed. Increment
" + file + " version from " + previousVersion + " to " +
newVersion;
+ } catch(NumberFormatException nfe) {
+ return " *** Bundle " + bundleName + " has changed. Increment
" + file + " version from " + previousVersion + " to SOMETHING
ELSE";
+ }
+ }
+
+ private String getSmallManifestVersion(String full) {
+ if( full == null)
+ return null;
+ if( !full.endsWith(".qualifier") )
+ return full;
+ return full.substring(0, full.indexOf(".qualifier"));
+ }
+ private String getSmallPomVersion(String full) {
+ if( full == null)
+ return null;
+ if( !full.endsWith("-SNAPSHOT") )
+ return full;
+ return full.substring(0, full.indexOf("-SNAPSHOT"));
+ }
+
+ /*
+ * Has the bundle changed at all?
+ */
+ private String diffBundleString(File bundle1, File bundle2) {
+ String command = getDiffCommand(bundle1.getAbsolutePath(), bundle2.getAbsolutePath());
+ try {
+ Process p = Runtime.getRuntime().exec(command);
+ String output = readOutput(p);
+ return output;
+ } catch(IOException ioe) {
+ // ignore?
+ ioe.printStackTrace();
+ }
+ return null;
+ }
+
+ private String findManifestVersion(File file) {
+ if( !file.exists())
+ return null;
+
+ try {
+ InputStreamReader isr = new InputStreamReader(new FileInputStream(file));
+ BufferedReader br = new BufferedReader(isr);
+ String VERSION_KEY = "Bundle-Version:";
+ String line;
+ while ((line = br.readLine()) != null) {
+ if( line.startsWith(VERSION_KEY)) {
+ return line.substring(VERSION_KEY.length()).trim();
+ }
+ }
+ } catch(IOException ioe) {
+
+ }
+ return null;
+ }
+
+ private String findPomVersion(File file) {
+ if( !file.exists())
+ return null;
+
+ try {
+ FileInputStream is = new FileInputStream(file);
+ BufferedReader br = new BufferedReader(new InputStreamReader(is));
+ String pomContents = getOutput(br);
+ int index = pomContents.indexOf("<version>");
+ if( index == -1 )
+ throw new Exception("Blah");
+ int newIndex = pomContents.indexOf("<version>", index+1);
+ if( newIndex == -1 )
+ throw new Exception("blah");
+ int end = pomContents.indexOf("</version>", newIndex+1);
+ String versionString = pomContents.substring(newIndex +
"<version>".length(), end);
+ return versionString;
+ } catch( Exception e) {
+ getLog().error(" *** Cannot read pom plugin version for file: " +
file.getAbsolutePath());
+ }
+ return null;
+ }
+
+ public String getDiffCommand(String o1, String n1) {
+ String generateCommand = "diff -r ";
+ for( int i = 0; i < excludes.length; i++ ) {
+ generateCommand += "--exclude=" + excludes[i] + " ";
+ }
+ generateCommand += o1 + " " + n1; // + " > " + tmpFilePath;
+ return generateCommand;
+ }
+
+
+ private String readOutput(Process p) {
+ InputStream is = p.getInputStream();
+ InputStreamReader isr = new InputStreamReader(is);
+ BufferedReader br = new BufferedReader(isr);
+ return getOutput(br);
+ }
+
+ private String getOutput(BufferedReader br) {
+ String out = "";
+ String line;
+ int exit = -1;
+
+ try {
+ while ((line = br.readLine()) != null) {
+ // Outputs your process execution
+ out += line + '\n';
+ }
+ } catch(IOException ioe) {
+ ioe.printStackTrace();
+ }
+ return out;
+ }
+}