/** * Get the runtime value of an expression. <br> * <li><b>"current" </b> points to the current project object. * <li>Characters in '' will keep there original string value. * <li>Other tokens will be treated as property key of current project. <br> * <br> * e.g: "utest.report.base.dir, '/', current.projectName" will be split into three tokens: * Runtime value for "utest.report.base.dir" will be retrieved from current project, '/' will * keep its original value, while "current.projectName" will be the current project name. * * @param info * @param key * @return */ private String getRuntimeValue(ProjectInfo info, String key) { final String CURRENT_KEY = "current"; // $NON-NLS-1$ if (key.startsWith(CURRENT_KEY)) { // e.g: // projectInfo.getAttribute( "projectName" ) // projectInfo.getAttribute( "baseDir" ) return info.getValue(key.substring(CURRENT_KEY.length() + 1)); } else if (key.startsWith("'") && key.endsWith("'")) // $NON-NLS-1$//$NON-NLS-2$ { return key.substring(1, key.length() - 1); } else return getProject().getProperty(key); }
/** * Execute all nestedTasks. * * @throws BuildException if one of the nested tasks fails. */ public void execute() throws BuildException { Object o = getProject().getReference(refID); ProjectList list; if (o instanceof ProjectList) { list = (ProjectList) o; } else { log( "ForEach only support one ProjectList reference!", //$NON-NLS-1$ Project.MSG_ERR); throw new BuildException("ForEach only support one ProjectList reference!"); // $NON-NLS-1$ } for (int i = 0; i < list.getCount(); i++) { ProjectInfo projectInfo = list.getProject(i); // register dynamic property for (int j = 0; j < dynamicProperties.size(); j++) { DynamicProperty property = (DynamicProperty) dynamicProperties.get(j); getDynamicValue(projectInfo, property); } // ================= Add Build Listeners // ============================ DefaultLogger logger = null; if (loggerPath != null) { File loggerPathDir = new File(loggerPath); if (!loggerPathDir.exists()) loggerPathDir.mkdir(); if (!loggerPathDir.isDirectory()) throw new BuildException( "loggerPath attribute should reference to a directory."); //$NON-NLS-1$ // Add INFO level logger. logger = new DefaultLogger(); PrintStream str = null; try { String fileName = projectInfo.getValue("projectName") + "_log.txt"; // $NON-NLS-1$//$NON-NLS-2$ str = new PrintStream( new FileOutputStream(new File(loggerPathDir, fileName), true), true); //$NON-NLS-1$ } catch (FileNotFoundException e1) { e1.printStackTrace(); } logger.setMessageOutputLevel(Project.MSG_INFO); logger.setErrorPrintStream(str); logger.setOutputPrintStream(str); getProject().addBuildListener(logger); } // ================= End of adding Build Listeners // ============================ for (Enumeration e = nestedTasks.elements(); e.hasMoreElements(); ) { Task nestedTask = (Task) e.nextElement(); try { nestedTask.perform(); getProject().setProperty(failurePropertyName, TASK_STATUS_PASS); // $NON-NLS-1$ } catch (BuildException ex) { log( "Execution error on task: [" + nestedTask.getTaskName() + "] message: " + ex.toString(), Project.MSG_WARN); // $NON-NLS-1$ //$NON-NLS-2$ // Check for Ant execution, check to see whether the // individual project // failed on itself or failed on dependencies. if ("Ant".equalsIgnoreCase(nestedTask.getTaskName())) // $NON-NLS-1$ { if (isThisProjectError(ex)) { getProject().setProperty(failurePropertyName, TASK_STATUS_FAIL); // $NON-NLS-1$ log("Project failed on itself: ", Project.MSG_ERR); // $NON-NLS-1$ } else { getProject().setProperty(failurePropertyName, TASK_STATUS_FAIL_ON_DEPENDENCY); log("Project failed on dependencies:", Project.MSG_WARN); // $NON-NLS-1$ //$NON-NLS-2$ } } if (failOnError) { throw ex; } log("Continue execution.", Project.MSG_INFO); // $NON-NLS-1$ } } // Remove Build Listener. if (logger != null) getProject().removeBuildListener(logger); } }