/** * Fired when the build finishes, this adds the time taken and any error stacktrace to the build * element and writes the document to disk. * * @param event An event with any relevant extra information. Will not be <code>null</code>. */ public void buildFinished(BuildEvent event) { long totalTime = System.currentTimeMillis() - buildElement.startTime; buildElement.element.setAttribute(TIME_ATTR, DefaultLogger.formatTime(totalTime)); if (event.getException() != null) { buildElement.element.setAttribute(ERROR_ATTR, event.getException().toString()); // print the stacktrace in the build file it is always useful... // better have too much info than not enough. Throwable t = event.getException(); Text errText = doc.createCDATASection(StringUtils.getStackTrace(t)); Element stacktrace = doc.createElement(STACKTRACE_TAG); stacktrace.appendChild(errText); buildElement.element.appendChild(stacktrace); } String outFilename = event.getProject().getProperty("XmlLogger.file"); if (outFilename == null) { outFilename = "log.xml"; } String xslUri = event.getProject().getProperty("ant.XmlLogger.stylesheet.uri"); if (xslUri == null) { xslUri = "log.xsl"; } Writer out = null; try { // specify output in UTF8 otherwise accented characters will blow // up everything OutputStream stream = outStream; if (stream == null) { stream = new FileOutputStream(outFilename); } out = new OutputStreamWriter(stream, "UTF8"); out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); if (xslUri.length() > 0) { out.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + xslUri + "\"?>\n\n"); } (new DOMElementWriter()).write(buildElement.element, out, 0, "\t"); out.flush(); } catch (IOException exc) { throw new BuildException("Unable to write log file", exc); } finally { if (out != null) { try { out.close(); } catch (IOException e) { // ignore } } } buildElement = null; }
/** * Actual method executed by jakarta-ant. * * @exception BuildException */ public void execute() throws BuildException { InputRequest request = null; if (validargs != null) { Vector accept = StringUtils.split(validargs, ','); request = new MultipleChoiceInputRequest(message, accept); } else { request = new InputRequest(message); } getProject().getInputHandler().handleInput(request); String value = request.getInput(); if (addproperty != null && value != null) { project.setNewProperty(addproperty, value); } }
/** * Move the generated source file(s) to the base directory * * @throws org.apache.tools.ant.BuildException When error copying/removing files. */ private void moveGeneratedFile( File baseDir, File sourceBaseFile, String classname, RmicAdapter adapter) throws BuildException { String classFileName = classname.replace('.', File.separatorChar) + ".class"; String[] generatedFiles = adapter.getMapper().mapFileName(classFileName); for (int i = 0; i < generatedFiles.length; i++) { final String generatedFile = generatedFiles[i]; if (!generatedFile.endsWith(".class")) { // don't know how to handle that - a IDL file doesn't // have a corresponding Java source for example. continue; } String sourceFileName = StringUtils.removeSuffix(generatedFile, ".class") + ".java"; File oldFile = new File(baseDir, sourceFileName); if (!oldFile.exists()) { // no source file generated, nothing to move continue; } File newFile = new File(sourceBaseFile, sourceFileName); try { if (filtering) { FILE_UTILS.copyFile( oldFile, newFile, new FilterSetCollection(getProject().getGlobalFilterSet())); } else { FILE_UTILS.copyFile(oldFile, newFile); } oldFile.delete(); } catch (IOException ioe) { String msg = "Failed to copy " + oldFile + " to " + newFile + " due to " + ioe.getMessage(); throw new BuildException(msg, ioe, getLocation()); } } }
/** * Fired when a message is logged, this adds a message element to the most appropriate parent * element (task, target or build) and records the priority and text of the message. * * @param event An event with any relevant extra information. Will not be <code>null</code>. */ public void messageLogged(BuildEvent event) { if (buildElement == null) { buildElement = new TimedElement(); buildElement.startTime = System.currentTimeMillis(); buildElement.element = doc.createElement(BUILD_TAG); } int priority = event.getPriority(); if (priority > msgOutputLevel) { return; } Element messageElement = doc.createElement(MESSAGE_TAG); String name = "debug"; switch (event.getPriority()) { case MSG_ERR: name = "error"; break; case MSG_WARN: name = "warn"; break; case MSG_INFO: name = "info"; break; default: name = "debug"; break; } messageElement.setAttribute(PRIORITY_ATTR, name); Throwable ex = event.getException(); if (MSG_DEBUG <= msgOutputLevel && ex != null) { Text errText = doc.createCDATASection(StringUtils.getStackTrace(ex)); Element stacktrace = doc.createElement(STACKTRACE_TAG); stacktrace.appendChild(errText); buildElement.element.appendChild(stacktrace); } Text messageText = doc.createCDATASection(event.getMessage()); messageElement.appendChild(messageText); TimedElement parentElement = null; Task task = event.getTask(); Target target = event.getTarget(); if (task != null) { parentElement = getTaskElement(task); } if (parentElement == null && target != null) { parentElement = (TimedElement) targets.get(target); } /* * if (parentElement == null) { Stack threadStack = (Stack) * threadStacks.get(Thread.currentThread()); if (threadStack != null) { * if (!threadStack.empty()) { parentElement = (TimedElement) * threadStack.peek(); } } } */ if (parentElement != null) { parentElement.element.appendChild(messageElement); } else { buildElement.element.appendChild(messageElement); } }
private static void addPrivilege(String roleName, String privileges, Statement statement) throws IOException, SQLException { String serverName = null, dbName = null, tableName = null, uriPath = null, columnName = null; String action = "ALL"; // AccessConstants.ALL; for (String privilege : ROLE_SPLITTER.split(privileges)) { for (String section : AUTHORIZABLE_SPLITTER.split(privilege)) { // action is not an authorizeable if (!section.toLowerCase().startsWith(PRIVILEGE_PREFIX)) { DBModelAuthorizable dbAuthorizable = DBModelAuthorizables.from(section); if (dbAuthorizable == null) { throw new IOException("Unknown Auth type " + section); } if (DBModelAuthorizable.AuthorizableType.Server.equals(dbAuthorizable.getAuthzType())) { serverName = dbAuthorizable.getName(); } else if (DBModelAuthorizable.AuthorizableType.Db.equals( dbAuthorizable.getAuthzType())) { dbName = dbAuthorizable.getName(); } else if (DBModelAuthorizable.AuthorizableType.Table.equals( dbAuthorizable.getAuthzType())) { tableName = dbAuthorizable.getName(); } else if (DBModelAuthorizable.AuthorizableType.Column.equals( dbAuthorizable.getAuthzType())) { columnName = dbAuthorizable.getName(); } else if (DBModelAuthorizable.AuthorizableType.URI.equals( dbAuthorizable.getAuthzType())) { uriPath = dbAuthorizable.getName(); } else { throw new IOException( "Unsupported auth type " + dbAuthorizable.getName() + " : " + dbAuthorizable.getTypeName()); } } else { action = DBModelAction.valueOf( StringUtils.removePrefix(section, PRIVILEGE_PREFIX).toUpperCase()) .toString(); } } LOGGER.info("addPrivilege"); if (columnName != null) { statement.execute("CREATE DATABASE IF NOT EXISTS " + dbName); statement.execute("USE " + dbName); String sql = "GRANT " + action + " ( " + columnName + " ) ON TABLE " + tableName + " TO ROLE " + roleName; LOGGER.info("Granting column level privilege: database = " + dbName + ", sql = " + sql); statement.execute(sql); } else if (tableName != null) { statement.execute("CREATE DATABASE IF NOT EXISTS " + dbName); statement.execute("USE " + dbName); String sql = "GRANT " + action + " ON TABLE " + tableName + " TO ROLE " + roleName; LOGGER.info("Granting table level privilege: database = " + dbName + ", sql = " + sql); statement.execute(sql); } else if (dbName != null) { String sql = "GRANT " + action + " ON DATABASE " + dbName + " TO ROLE " + roleName; LOGGER.info("Granting db level privilege: " + sql); statement.execute(sql); } else if (uriPath != null) { String sql = "GRANT " + action + " ON URI '" + uriPath + "' TO ROLE " + roleName; LOGGER.info("Granting uri level privilege: " + sql); statement.execute(sql); // ALL? } else if (serverName != null) { String sql = "GRANT ALL ON SERVER " + serverName + " TO ROLE " + roleName; LOGGER.info("Granting server level privilege: " + sql); statement.execute(sql); } } }