1 11 package org.eclipse.jdt.core; 12 13 import java.io.IOException ; 14 import java.util.Enumeration ; 15 import java.util.zip.ZipEntry ; 16 import java.util.zip.ZipFile ; 17 18 import org.apache.tools.ant.BuildException; 19 import org.apache.tools.ant.Task; 20 import org.eclipse.jdt.core.util.IClassFileReader; 21 import org.eclipse.jdt.core.util.ICodeAttribute; 22 import org.eclipse.jdt.core.util.IMethodInfo; 23 import org.eclipse.jdt.internal.antadapter.AntAdapterMessages; 24 25 39 public final class CheckDebugAttributes extends Task { 40 41 private String file; 42 private String property; 43 44 public void execute() throws BuildException { 45 if (this.file == null) { 46 throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.file.argument.cannot.be.null")); } 48 if (this.property == null) { 49 throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.property.argument.cannot.be.null")); } 51 try { 52 boolean hasDebugAttributes = false; 53 if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(this.file)) { 54 ZipFile jarFile = new ZipFile (this.file); 55 for (Enumeration entries = jarFile.entries(); !hasDebugAttributes && entries.hasMoreElements(); ) { 56 ZipEntry entry = (ZipEntry ) entries.nextElement(); 57 if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entry.getName())) { 58 IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(this.file, entry.getName(), IClassFileReader.ALL); 59 hasDebugAttributes = checkClassFile(classFileReader); 60 } 61 } 62 } else if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(this.file)) { 63 IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(this.file, IClassFileReader.ALL); 64 hasDebugAttributes = checkClassFile(classFileReader); 65 } else { 66 throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.file.argument.must.be.a.classfile.or.a.jarfile")); } 68 if (hasDebugAttributes) { 69 getProject().setUserProperty(this.property, "has debug"); } 71 } catch (IOException e) { 72 throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.ioexception.occured") + this.file); } 74 } 75 76 private boolean checkClassFile(IClassFileReader classFileReader) { 77 IMethodInfo[] methodInfos = classFileReader.getMethodInfos(); 78 for (int i = 0, max = methodInfos.length; i < max; i++) { 79 ICodeAttribute codeAttribute = methodInfos[i].getCodeAttribute(); 80 if (codeAttribute != null && codeAttribute.getLineNumberAttribute() != null) { 81 return true; 82 } 83 } 84 return false; 85 } 86 87 public void setFile(String value) { 88 this.file = value; 89 } 90 91 public void setProperty(String value) { 92 this.property = value; 93 } 94 } 95 | Popular Tags |