1 19 20 package org.netbeans.modules.java.j2seproject; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.regex.Pattern ; 25 import org.apache.tools.ant.module.spi.AntEvent; 26 import org.apache.tools.ant.module.spi.AntLogger; 27 import org.apache.tools.ant.module.spi.AntSession; 28 import org.netbeans.api.project.Project; 29 import org.netbeans.api.project.ProjectManager; 30 import org.openide.ErrorManager; 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileUtil; 33 34 39 public final class J2SEAntLogger extends AntLogger { 40 41 42 public J2SEAntLogger() {} 43 44 public boolean interestedInSession(AntSession session) { 45 return session.getVerbosity() <= AntEvent.LOG_INFO; 48 } 49 50 private static boolean isJ2SEProject(File dir) { 51 FileObject projdir = FileUtil.toFileObject(FileUtil.normalizeFile(dir)); 52 try { 53 Project proj = ProjectManager.getDefault().findProject(projdir); 54 if (proj != null) { 55 return proj.getLookup().lookup(J2SEProject.class) != null; 57 } 58 } catch (IOException e) { 59 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 60 } 61 return false; 62 } 63 64 public boolean interestedInScript(File script, AntSession session) { 65 if (script.getName().equals("build-impl.xml")) { File parent = script.getParentFile(); 67 if (parent != null && parent.getName().equals("nbproject")) { File parent2 = parent.getParentFile(); 69 if (parent2 != null) { 70 return isJ2SEProject(parent2); 71 } 72 } 73 } 74 return false; 76 } 77 78 public String [] interestedInTargets(AntSession session) { 79 return AntLogger.ALL_TARGETS; 80 } 81 82 public String [] interestedInTasks(AntSession session) { 83 return AntLogger.ALL_TASKS; 85 } 86 87 public int[] interestedInLogLevels(AntSession session) { 88 return new int[] { 89 AntEvent.LOG_WARN, 90 }; 91 } 92 93 public void taskFinished(AntEvent event) { 94 if ("javac".equals(event.getTaskName())) { Throwable t = event.getException(); 96 AntSession session = event.getSession(); 97 if (t != null && !session.isExceptionConsumed(t)) { 98 session.consumeException(t); 101 } 102 } 103 } 104 105 public void messageLogged(AntEvent event) { 106 if (!event.isConsumed() && event.getLogLevel() == AntEvent.LOG_WARN && 108 event.getMessage().startsWith("Trying to override old definition of " + "task http://www.netbeans.org/ns/j2se-project/")) { event.consume(); 111 } 112 } 113 114 } 115 | Popular Tags |