labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simo...@apache.org
Subject svn commit: r763469 - /labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java
Date Thu, 09 Apr 2009 00:18:41 GMT
Author: simoneg
Date: Thu Apr  9 00:18:40 2009
New Revision: 763469

URL: http://svn.apache.org/viewvc?rev=763469&view=rev
Log:
LABS-333 : Slight optimization in build time and ram consumption

Modified:
    labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java

Modified: labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java?rev=763469&r1=763468&r2=763469&view=diff
==============================================================================
--- labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java
(original)
+++ labs/magma/trunk/maven-magma-plugin/src/main/java/org/apache/magma/tools/maven/MagmaAjcCompleteCompileMojo.java
Thu Apr  9 00:18:40 2009
@@ -17,12 +17,14 @@
 package org.apache.magma.tools.maven;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.lang.annotation.Annotation;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -207,6 +209,7 @@
 	}
 	
 	private void jpaEnhance(Set<String> set, Artifact art, File baseout) {
+		if (art != null && art.getGroupId().equals("org.apache.openjpa")) return;
 		StringBuilder clazzes = new StringBuilder();
 		// set class loader
 		URL[] mycp = allUrlsExcept(set, art, baseout);
@@ -245,6 +248,10 @@
 		}
 	}
 
+	private byte[] classBuff = new byte[65000];
+	private String jpaPack = "javax.persistence";
+	private byte[] jpaPackBytes = "javax/persistence/".getBytes();
+	
 	private void recurseClasses(File root, File baseout, StringBuilder build, ClassLoader cl)
{
 		if (baseout.isDirectory()) {
 			File[] listFiles = baseout.listFiles();
@@ -253,27 +260,55 @@
 			}
 		} else {
 			if (baseout.getName().endsWith(".class")) {
-				String clname = baseout.getAbsolutePath().substring(root.getAbsolutePath().length());
-				if (clname.startsWith(File.separator)) clname = clname.substring(1);
-				clname = clname.substring(0, clname.length() - 6);
-				clname = clname.replace(File.separatorChar, '.');
+				// Dumb analysis of .class file, cuts down ram cost a lot
+				FileInputStream fis = null;
 				try {
-					Class<?> class1 = cl.loadClass(clname);
-					boolean toenhance = false;
-					Annotation[] annotations = class1.getAnnotations();
-					for (Annotation annotation : annotations) {
-						if (annotation.annotationType().getName().startsWith("javax.persistence")) {
-							toenhance = true;
-							break;
-						}
+					fis = new FileInputStream(baseout);
+					int len = fis.read(classBuff);
+					boolean containsPackage = false;
+					int jpp = 0;
+					for (int cbp = 0; cbp < len; cbp++) {
+						if (classBuff[cbp] == jpaPackBytes[jpp]) {
+							jpp++;
+							if (jpp >= jpaPackBytes.length) {
+								containsPackage = true;
+								break;
+							}
+						} else if (jpp > 0) {
+							cbp--;
+							jpp = 0;
+						}							
 					}
-					
-					if (toenhance) {
-						build.append(' ');
-						build.append(baseout.getAbsolutePath());
+					if (containsPackage) {
+						// Loads the class and checks for annotation 
+						String clname = baseout.getAbsolutePath().substring(root.getAbsolutePath().length());
+						if (clname.startsWith(File.separator)) clname = clname.substring(1);
+						clname = clname.substring(0, clname.length() - 6);
+						clname = clname.replace(File.separatorChar, '.');
+						Class<?> class1 = cl.loadClass(clname);
+						boolean toenhance = false;
+						Annotation[] annotations = class1.getAnnotations();
+						for (Annotation annotation : annotations) {
+							if (annotation.annotationType().getName().startsWith(jpaPack)) {
+								toenhance = true;
+								break;
+							}
+						}
+						
+						if (toenhance) {
+							build.append(' ');
+							build.append(baseout.getAbsolutePath());
+						}
 					}
 				} catch (Throwable e) {
 					e.printStackTrace();
+				} finally {
+					if (fis != null) {
+						try {
+							fis.close();
+						} catch (IOException e) {
+						}
+					}
 				}
 			}
 		}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message