List of usage examples for org.apache.maven.plugin.logging Log info
void info(Throwable error);
From source file:de.bbe_consulting.mavento.helper.MagentoSqlUtil.java
License:Apache License
/** * Drops a mysql database.//w w w . jav a 2 s . com * * @param magentoDbUser * @param magentoDbPasswd * @param magentoDbHost * @param magentoDbPort * @param magentoDbName * @param logger * @throws MojoExecutionException */ public static void dropMagentoDb(String magentoDbUser, String magentoDbPasswd, String magentoDbHost, String magentoDbPort, String magentoDbName, Log logger) throws MojoExecutionException { try { logger.info("Dropping database " + magentoDbName + ".."); String query = "DROP DATABASE `" + magentoDbName + "`"; executeRawSql(query, magentoDbUser, magentoDbPasswd, magentoDbHost, magentoDbPort, logger); } catch (Exception e) { if (e.getMessage().startsWith("ERROR 1008")) { logger.warn("..Database does not exist!"); } else { throw new MojoExecutionException("Error while dropping database: " + e.getMessage(), e); } } }
From source file:de.bbe_consulting.mavento.helper.MagentoSqlUtil.java
License:Apache License
/** * Drop, truncate or partially delete sql tables. * /*from w w w .ja va2 s . c om*/ * @param tableNames * @param whereCondidtion * @param dropTables * @param magentoDbUser * @param magentoDbPasswd * @param magentoDbHost * @param magentoDbPort * @param magentoDbName * @param logger * @throws MojoExecutionException */ public static void dropSqlTables(ArrayList<String> tableNames, String whereCondidtion, boolean dropTables, String magentoDbUser, String magentoDbPasswd, String magentoDbHost, String magentoDbPort, String magentoDbName, Log logger) throws MojoExecutionException { String query = ""; String action = ""; if (dropTables) { query = "DROP TABLE "; for (String tableName : tableNames) { query += "`" + tableName + "`, "; } query = query.substring(0, query.length() - 2); query += ";"; action = "Dropping tables " + tableNames.toString() + " in "; } else if (whereCondidtion != null && !whereCondidtion.isEmpty()) { for (String tableName : tableNames) { query += "DELETE FROM `" + tableName + "` WHERE " + whereCondidtion + "; "; } action = "Deleting from tables " + tableNames.toString() + " where " + whereCondidtion + " in "; } else { for (String tableName : tableNames) { query += "TRUNCATE `" + tableName + "`; "; } action = "Truncating tables " + tableNames.toString() + " in "; } try { logger.info(action + magentoDbName + ".."); executeRawSql(query, magentoDbUser, magentoDbPasswd, magentoDbHost, magentoDbPort, magentoDbName, logger); } catch (Exception e) { if (e.getMessage().startsWith("ERROR 1008")) { logger.warn("..Database does not exist!"); } else { throw new MojoExecutionException("Error while truncating/dropping tables: " + e.getMessage(), e); } } }
From source file:de.bbe_consulting.mavento.helper.MagentoSqlUtil.java
License:Apache License
/** * Imports a mysql dump./*from w w w .j a v a2 s . c o m*/ * * @param sqlDump * @param magentoDbUser * @param magentoDbPasswd * @param magentoDbHost * @param magentoDbPort * @param magentoDbName * @param logger * @throws MojoExecutionException */ public static void importSqlDump(String sqlDump, String magentoDbUser, String magentoDbPasswd, String magentoDbHost, String magentoDbPort, String magentoDbName, Log logger) throws MojoExecutionException { final Commandline cl = MagentoSqlUtil.getMysqlCommandLine(magentoDbUser, magentoDbPasswd, magentoDbHost, magentoDbPort, magentoDbName); final InputStream input; FileInputStream rawIn = null; FileChannel channel = null; try { rawIn = new FileInputStream(Paths.get(sqlDump).toFile()); channel = rawIn.getChannel(); input = Channels.newInputStream(channel); final StringStreamConsumer output = new CommandLineUtils.StringStreamConsumer(); final StringStreamConsumer error = new CommandLineUtils.StringStreamConsumer(); logger.info("Importing sql dump into database " + magentoDbName + ".."); final int returnValue = CommandLineUtils.executeCommandLine(cl, input, output, error); if (returnValue != 0) { logger.info(output.getOutput().toString()); logger.info(error.getOutput().toString()); logger.info("retval: " + returnValue); throw new MojoExecutionException("Error while importing sql dump."); } logger.info("..done."); } catch (CommandLineException e) { throw new MojoExecutionException("Error while importing sql dump.", e); } catch (FileNotFoundException e) { throw new MojoExecutionException("Error while reading sql dump.", e); } finally { if (channel != null) { try { channel.close(); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } } if (rawIn != null) { try { rawIn.close(); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } } } }
From source file:de.bbe_consulting.mavento.helper.MagentoSqlUtil.java
License:Apache License
/** * Dumps a mysql database via mysqldump exec. * // ww w.ja v a 2 s .c o m * @param sqlDump * @param magentoDbUser * @param magentoDbPasswd * @param magentoDbHost * @param magentoDbPort * @param magentoDbName * @param logger * @throws MojoExecutionException */ public static void dumpSqlDb(String sqlDump, String magentoDbUser, String magentoDbPasswd, String magentoDbHost, String magentoDbPort, String magentoDbName, Log logger) throws MojoExecutionException { final Commandline cl = getMysqlCommandLine(magentoDbUser, magentoDbPasswd, magentoDbHost, magentoDbPort); cl.setExecutable("mysqldump"); cl.addArguments(new String[] { "-C", magentoDbName }); cl.addArguments(new String[] { "--result-file=\"" + sqlDump + "\"" }); final StringStreamConsumer output = new CommandLineUtils.StringStreamConsumer(); final StringStreamConsumer error = new CommandLineUtils.StringStreamConsumer(); try { logger.info("Dumping database " + magentoDbName + " to " + sqlDump + ".."); final int returnValue = CommandLineUtils.executeCommandLine(cl, output, error); if (returnValue != 0) { logger.info(error.getOutput().toString()); logger.info("retval: " + returnValue); throw new MojoExecutionException("Error while exporting sql dump."); } logger.info("..done."); } catch (CommandLineException e) { throw new MojoExecutionException("Error while dumping from database " + magentoDbName + ".", e); } }
From source file:de.bbe_consulting.mavento.helper.MagentoSqlUtil.java
License:Apache License
/** * Dumps db table(s) via mysqldump exec. whereCondition is optional. * /*from w w w. j a va 2s . c o m*/ * @param tableNames * @param whereCondidtion * @param sqlDump * @param magentoDbUser * @param magentoDbPasswd * @param magentoDbHost * @param magentoDbPort * @param magentoDbName * @param logger * @throws MojoExecutionException */ public static void dumpSqlTables(ArrayList<String> tableNames, String whereCondidtion, String sqlDump, String magentoDbUser, String magentoDbPasswd, String magentoDbHost, String magentoDbPort, String magentoDbName, Log logger) throws MojoExecutionException { String action = "Dumping table(s) " + tableNames.toString(); final Commandline cl = getMysqlCommandLine(magentoDbUser, magentoDbPasswd, magentoDbHost, magentoDbPort); cl.setExecutable("mysqldump"); cl.addArguments(new String[] { "--no-create-info" }); cl.addArguments(new String[] { magentoDbName }); for (String table : tableNames) { cl.addArguments(new String[] { table }); } if (whereCondidtion != null && !whereCondidtion.isEmpty()) { cl.addArguments(new String[] { "--where=" + whereCondidtion }); action += " where " + whereCondidtion; } cl.addArguments(new String[] { "--result-file=\"" + sqlDump + "\"" }); final StringStreamConsumer output = new CommandLineUtils.StringStreamConsumer(); final StringStreamConsumer error = new CommandLineUtils.StringStreamConsumer(); try { logger.info(action + " to " + sqlDump + ".."); final int returnValue = CommandLineUtils.executeCommandLine(cl, output, error); if (returnValue != 0) { logger.info(error.getOutput().toString()); logger.info("retval: " + returnValue); throw new MojoExecutionException("Error while exporting sql dump."); } logger.info("..done."); } catch (CommandLineException e) { throw new MojoExecutionException("Error while dumping tables from database " + magentoDbName + ".", e); } }
From source file:de.bbe_consulting.mavento.helper.MagentoUtil.java
License:Apache License
/** * Execute a pear command./* w ww.j a v a 2 s. c o m*/ * * @param executable * @param arguments * @param targetDir * @param magentoVersion * @param logger * @throws MojoExecutionException */ public static void executePearCommand(String executable, String[] arguments, String targetDir, MagentoVersion magentoVersion, Log logger) throws MojoExecutionException { final Commandline cl = new Commandline(); cl.addArguments(arguments); cl.setWorkingDirectory(targetDir); cl.setExecutable(executable); final StringStreamConsumer output = new CommandLineUtils.StringStreamConsumer(); final StringStreamConsumer error = new CommandLineUtils.StringStreamConsumer(); try { int returnValue = CommandLineUtils.executeCommandLine(cl, output, error); if (returnValue != 0) { // Magento 1.4.2.0 pear script seems to be bugged, returns 1 // even tho there was no error? if (magentoVersion.getMajorVersion() != 1 || magentoVersion.getMinorVersion() != 4 || magentoVersion.getRevisionVersion() != 2 || !arguments[0].equals("mage-setup")) { logger.info("retval: " + returnValue); logger.info(output.getOutput().toString()); logger.info(error.getOutput().toString()); throw new MojoExecutionException("Error while executing pear command!"); } } if (output.getOutput().toString().startsWith("Error:")) { throw new MojoExecutionException(output.getOutput().toString()); } } catch (CommandLineException e) { throw new MojoExecutionException("Error while executing pear command!", e); } }
From source file:de.bbe_consulting.mavento.helper.MagentoUtil.java
License:Apache License
/** * Execute magento install.php with some bogus values.<br/> * Only used for vanilla artifact creation. * //from w ww. j a va 2s. c o m * @param magentoRoot * @param magentoDbUser * @param magentoDbPasswd * @param magentoDbHost * @param magentoDbName * @param logger * @throws MojoExecutionException */ public static void execMagentoInstall(Path magentoRoot, String magentoDbUser, String magentoDbPasswd, String magentoDbHost, String magentoDbName, Log logger) throws MojoExecutionException { final Commandline cl = new Commandline(); cl.addArguments(new String[] { "install.php", "--license_agreement_accepted", "yes", "--locale", "de_DE", "--timezone", "\"Europe/Berlin\"", "--default_currency", "EUR", "--db_user", magentoDbUser, "--db_host", magentoDbHost, "--db_name", magentoDbName, "--url", "\"http://mavento.local/\"", "--secure_base_url", "\"https://mavento.local/\"", "--skip_url_validation", "yes", "--use_secure", "yes", "--use_secure_admin", "yes", "--use_rewrites", "yes", "--admin_lastname", "Floppel", "--admin_firstname", "Heinzi", "--admin_email", "\"heinzi@floppel.net\"", "--admin_username", "admin", "--admin_password", "123test" }); if (magentoDbPasswd != null && !magentoDbPasswd.isEmpty()) { cl.addArguments(new String[] { "--db_pass", magentoDbPasswd }); } cl.setExecutable("php"); cl.setWorkingDirectory(magentoRoot.toString() + "/magento"); final StringStreamConsumer error = new CommandLineUtils.StringStreamConsumer(); WriterStreamConsumer output = null; try { logger.info("Executing install.php on db " + magentoDbName + ".."); final int returnValue = CommandLineUtils.executeCommandLine(cl, output, error); if (returnValue != 0) { logger.info(error.getOutput().toString()); logger.info("retval: " + returnValue); throw new MojoExecutionException("Error while executing install.php."); } logger.info("..done."); } catch (CommandLineException e) { throw new MojoExecutionException("Error while executing install.php.", e); } }
From source file:de.bbe_consulting.mavento.helper.MavenUtil.java
License:Apache License
/** * Extracts all compile dependencies./*from w w w .j a va 2 s . com*/ * * @param targetDirectory * @param project * @param logger * @throws MojoExecutionException * @throws IOException */ public static void extractCompileDependencies(String targetDirectory, MavenProject project, Log logger) throws MojoExecutionException, IOException { final Set<Artifact> projectDependencies = project.getDependencyArtifacts(); FileUtil.createDirectories(targetDirectory, true); final Properties p = project.getProperties(); final String testId = (String) p.get("magento.test.artifact.id"); final String testGroupdId = (String) p.get("magento.test.artifact.group.id"); final String testVersion = (String) p.get("magento.test.artifact.version"); if (testId == null && testGroupdId == null && testVersion == null) { throw new MojoExecutionException("Error: One of the magento.test.artifact.* properties" + " is not defined. Please fix your pom.xml."); } // cycle through project dependencies for (Iterator<Artifact> artifactIterator = projectDependencies.iterator(); artifactIterator.hasNext();) { Artifact artifact = artifactIterator.next(); if ("compile".equals(artifact.getScope())) { if (!artifact.getArtifactId().equals(testId) && !artifact.getGroupId().equals(testGroupdId) && !artifact.getVersion().equals(testVersion)) { logger.info("Extracting " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ".."); String artifactPath = artifact.getFile().getPath(); FileUtil.unzipFile(artifactPath, targetDirectory); } } } }
From source file:de.berlios.statcvs.xml.maven.JavaCommandLine.java
License:Apache License
/** * Dump the contents of the writer to the given logger instance. * /*w w w . j av a 2 s .c om*/ * @param logger output logger * @param writer writer containing lines to output */ public static void print(Log logger, Writer writer) { String string = writer.toString(); if (string != null && string.length() > 0) { StringReader sr = new StringReader(string); BufferedReader br = new BufferedReader(sr); try { while ((string = br.readLine()) != null) { logger.info(string); } } catch (IOException e) { logger.debug(e); } } }
From source file:de.eacg.ecs.plugin.ScanAndTransferMojo.java
private void printStats(Set<Map.Entry<String, SortedSet<MavenProject>>> licenseAndProjectSet, Set<Map.Entry<MavenProject, String[]>> projectsAndLicenseSet) { Log log = getLog(); if (log.isInfoEnabled() && this.verbose) { log.info("Dependencies found:"); for (Map.Entry<MavenProject, String[]> entry : projectsAndLicenseSet) { MavenProject project = entry.getKey(); String[] licenses = entry.getValue(); log.info(String.format("%s %s, %s", project.getId(), project.getName(), Arrays.toString(licenses))); }//from ww w. j a v a 2s . com } if (log.isInfoEnabled()) { log.info("Licenses found:"); for (Map.Entry<String, SortedSet<MavenProject>> entry : licenseAndProjectSet) { log.info(String.format("%-75s %d", entry.getKey(), entry.getValue().size())); } } }