List of usage examples for org.apache.maven.plugin.logging Log error
void error(Throwable error);
From source file:com.samaxes.maven.plugin.minify.ProcessFilesTask.java
License:Apache License
/** * Task constructor.//from w ww .j ava 2s . c o m * * @param log Maven plugin log * @param bufferSize size of the buffer used to read source files. * @param webappSourceDir web resources source directory * @param webappTargetDir web resources target directory * @param inputDir directory containing source files * @param sourceFiles list of source files to include * @param sourceIncludes list of source files to include * @param sourceExcludes list of source files to exclude * @param outputDir directory to write the final file * @param finalFilename final filename * @param suffix final filename suffix * @param charset if a character set is specified, a byte-to-char variant allows the encoding to be selected. * Otherwise, only byte-to-byte operations are used * @param linebreak split long lines after a specific column */ public ProcessFilesTask(Log log, Integer bufferSize, String webappSourceDir, String webappTargetDir, String inputDir, List<String> sourceFiles, List<String> sourceIncludes, List<String> sourceExcludes, String outputDir, String finalFilename, String suffix, String charset, int linebreak) { this.log = log; this.linebreak = linebreak; this.bufferSize = bufferSize; this.charset = charset; File sourceDir = new File(webappSourceDir.concat(File.separator).concat(inputDir)); File targetDir = new File(webappTargetDir.concat(File.separator).concat(outputDir)); for (String sourceFile : sourceFiles) { logNewSourceFile(finalFilename, sourceFile); files.add(new File(sourceDir, sourceFile)); } for (File sourceInclude : getFilesToInclude(sourceDir, sourceIncludes, sourceExcludes)) { if (!files.contains(sourceInclude)) { logNewSourceFile(finalFilename, sourceInclude.getName()); files.add(sourceInclude); } } if (!files.isEmpty() && (targetDir.exists() || targetDir.mkdirs())) { this.mergedFile = new File(targetDir, finalFilename); String extension = ".".concat(FileUtils.getExtension(this.mergedFile.getName())); this.minifiedFile = new File(targetDir, this.mergedFile.getName().replace(extension, suffix.concat(extension))); } else if (!sourceFiles.isEmpty() || !sourceIncludes.isEmpty()) { // The 'files' list will be empty if the source file paths or names added to the project's POM are wrong. log.error("An error has occurred while loading source files." + " Please check your source directory path and source file names."); } }
From source file:com.sixsq.slipstream.SlipStreamMojo.java
License:Apache License
public void execute() throws MojoExecutionException { Log log = getLog(); fillInAndValidateParameters();/*from w ww . j a v a 2 s . co m*/ DeploymentController controller = new DeploymentController(slipstreamServerUri, server.getUsername(), server.getPassword()); // Ensure that the output directory exists. File outputDirectory = new File(targetDirectory); if (!outputDirectory.mkdirs()) { log.error(String.format("unable to create output directory: %s", outputDirectory.getAbsolutePath())); } try { controller.checkServerResponds(); controller.login(); controller.checkLogin(); for (String module : deploymentModuleNames) { try { controller.verifyModuleExists(module); log.info(String.format("Module: %s", module)); URI runUri = controller.runModule(module); log.info(String.format("Run URI: %s", runUri.toString())); pollServerUntilDone(log, runUri, controller); List<URI> reportUris = controller.getReports(runUri); List<File> localFiles = new ArrayList<File>(); for (URI uri : reportUris) { File localFile = controller.downloadFile(uri, outputDirectory); localFiles.add(localFile); } attachArtifacts(log, localFiles); } catch (MojoExecutionException e) { log.warn(String.format("Error while running module %s: %s", module, e.getMessage())); } } } finally { closeReliably(controller, log); } }
From source file:com.slim.service.BuildService.java
License:Apache License
public void buildear(MavenProject project, String outputDirectory, String archiveURI, String traHome, Log logger) throws MojoExecutionException { logger.info(" - BASE_DIR : " + project.getBasedir().toString()); logger.info(" - TRA_HOME : " + traHome); logger.info(" - OUTPUT_DIRECTORY : " + outputDirectory); try {/* www. jav a 2s . c om*/ CommandUtils.createDirectoryIfNeeded(project.getBasedir().toString() + "\\" + outputDirectory, logger); if (archiveURI == null || archiveURI.length() == 0) { archiveURI = "/" + project.getArtifact().getArtifactId(); } Map<String, String> options = new HashMap<String, String>(); options.put("-v", ""); options.put("-xs", ""); options.put(CommandUtils.EAR_OPTION, CommandUtils.GUILLEMETS + archiveURI + CommandUtils.GUILLEMETS); options.put(CommandUtils.PROJECT_OPTION, CommandUtils.GUILLEMETS + project.getBasedir().toString() + "\\" + project.getArtifact().getArtifactId() + CommandUtils.GUILLEMETS); options.put(CommandUtils.O_OPTION, CommandUtils.GUILLEMETS + project.getBasedir().toString() + "\\" + outputDirectory + "\\" + project.getArtifact().getArtifactId() + ".ear" + CommandUtils.GUILLEMETS); BufferedReader buildOutput = CommandUtils.executeCommand(logger, traHome, CommandUtils.getBuildEarBin(), options); boolean isError = false; StringBuffer result = new StringBuffer(); String line = null; while ((line = buildOutput.readLine()) != null) { if (line.contains("Error")) { isError = true; } result.append(line + "\n"); } if (isError) { logger.error(result.toString()); throw new Exception("Error in building ear ..."); } else { logger.info(result.toString()); } } catch (IOException e) { e.printStackTrace(); throw new MojoExecutionException("Error", e); } catch (Throwable e) { e.printStackTrace(); throw new MojoExecutionException("Error", e); } }
From source file:com.slim.service.ReplaceService.java
License:Apache License
/** * /*from ww w. jav a2 s . c o m*/ * @param project * @param outputDirectory * @param traHome * @param filterFile * @param machineTibco * @throws TransformerFactoryConfigurationError * @throws MojoFailureException */ public void replaceXml(MavenProject project, String outputDirectory, String traHome, String filterFile, String machineTibco, Log logger) throws TransformerFactoryConfigurationError, MojoFailureException { CommandUtils.createDirectoryIfNeeded(project.getBasedir().toString() + "\\" + outputDirectory, logger); String configFile = project.getBasedir().toString() + "\\" + outputDirectory + "\\" + project.getArtifact().getArtifactId() + CommandUtils.SUFFIXE_XML; String propertiesFile = project.getBasedir().toString() + "\\" + filterFile; logger.info(" - BASE_DIR : " + project.getBasedir().toString()); logger.info(" - TRA_HOME : " + traHome); logger.info(" - OUTPUT_DIRECTORY : " + outputDirectory); logger.info(" - CONFIG_FILE : " + configFile); logger.info(" - FILTER_FILE : " + propertiesFile); Map<String, String> mapAttribute = new HashMap<String, String>(); mapAttribute = parseFileProperties(propertiesFile, logger); Document doc = remplace(configFile, mapAttribute, machineTibco, logger); try { createFile(doc, outputDirectory, project, logger); } catch (TransformerException tfe) { logger.error(tfe.getMessage()); tfe.printStackTrace(); } }
From source file:com.slim.service.ReplaceService.java
License:Apache License
/** * Parse a filter file and set a Map/*w w w . j a v a 2s .com*/ * * @param filepath * @return */ private Map<String, String> parseFileProperties(String filepath, Log logger) { Map<String, String> mapAttribute = new HashMap<String, String>(); BufferedReader buffer = null; try { String currentLine; String cle = null; String valeur = null; String[] tab = null; buffer = new BufferedReader(new FileReader(filepath)); while ((currentLine = buffer.readLine()) != null) { logger.info(currentLine); tab = currentLine.split("="); if (tab.length == 2 && !currentLine.startsWith("#")) { cle = tab[0]; valeur = tab[1]; mapAttribute.put(cle, valeur); } } } catch (IOException e) { logger.error(e.getMessage()); e.printStackTrace(); } finally { try { if (buffer != null) { buffer.close(); } } catch (IOException ex) { logger.error(ex.getMessage()); ex.printStackTrace(); } } return mapAttribute; }
From source file:com.slim.service.ReplaceService.java
License:Apache License
/** * Replace variables in config file// ww w. ja va 2 s . c o m * * @param filepath * @param mapAttribute * @throws TransformerFactoryConfigurationError * @throws MojoFailureException */ private Document remplace(String filepath, Map<String, String> mapAttribute, String machineTibco, Log logger) throws TransformerFactoryConfigurationError, MojoFailureException { Document doc = null; try { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); doc = docBuilder.parse(filepath); // Get the root element // Node application = doc.getFirstChild(); Node globalVariables = doc.getElementsByTagName("NVPairs").item(0); // update staff attribute NamedNodeMap gbattr = globalVariables.getAttributes(); Node nodeAttr = gbattr.getNamedItem("name"); if (!nodeAttr.getTextContent().equals("Global Variables")) { throw new MojoFailureException("Unable to find global variables node in " + filepath); } // Loop the staff child node NodeList listeGlobalVariable = globalVariables.getChildNodes(); for (int i = 0; i < listeGlobalVariable.getLength(); i++) { Node nameValuePair = listeGlobalVariable.item(i); if (nameValuePair.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) nameValuePair; String name = element.getElementsByTagName("name").item(0).getTextContent(); String value = element.getElementsByTagName("value").item(0).getTextContent(); String newValue = null; if (mapAttribute.containsKey(name)) { newValue = mapAttribute.get(name); element.getElementsByTagName("value").item(0).setTextContent(newValue); logger.info( "Replacing '" + value + "' with '" + newValue + "' in variable '" + name + "' \n"); } } } // Modification de la section machine Node machine = doc.getElementsByTagName("machine").item(0); if (machine.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) machine; element.setTextContent(machineTibco); } // Modification de la section repo_instance Node repoInstances = doc.getElementsByTagName("repoInstances").item(0); NamedNodeMap rpattr = repoInstances.getAttributes(); Node selectedAttr = rpattr.getNamedItem("selected"); selectedAttr.setTextContent("local"); NodeList list = repoInstances.getChildNodes(); for (int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if ("httpRepoInstance".equals(node.getNodeName()) || "rvRepoInstance".equals(node.getNodeName())) { repoInstances.removeChild(node); } } } catch (ParserConfigurationException pce) { logger.error(pce.getMessage()); pce.printStackTrace(); } catch (IOException ioe) { logger.error(ioe.getMessage()); ioe.printStackTrace(); } catch (SAXException sae) { logger.error(sae.getMessage()); sae.printStackTrace(); } return doc; }
From source file:com.tvarit.plugin.StackMaker.java
License:Open Source License
public Stack makeStack(CreateStackRequest createStackRequest, AmazonCloudFormationClient amazonCloudFormationClient, Log log) throws MojoFailureException { CreateStackResult createStackResult = amazonCloudFormationClient.createStack(createStackRequest); final String stackName = createStackRequest.getStackName(); DescribeStacksResult describeStacksResult = amazonCloudFormationClient .describeStacks(new DescribeStacksRequest().withStackName(stackName)); while (describeStacksResult.getStacks().get(0).getStackStatus() .equals(StackStatus.CREATE_IN_PROGRESS.toString())) { try {/*from w w w.j av a 2 s . c om*/ log.info("Awaiting stack create completion!"); Thread.sleep(5000); } catch (InterruptedException e) { log.error(e); throw new RuntimeException(e); } describeStacksResult = amazonCloudFormationClient .describeStacks(new DescribeStacksRequest().withStackName(stackName)); } final Stack stack = describeStacksResult.getStacks().get(0); final String stackStatus = stack.getStackStatus(); if (!stackStatus.equals(StackStatus.CREATE_COMPLETE.toString())) { throw new MojoFailureException("Could not create infrastructure. Stack Status is: " + stackStatus + ". Please review details on the AWS console and open a new github issue on https://github.com/sdole/tvarit-maven/issues/new that is needed."); } return stack; }
From source file:com.wibidata.maven.plugins.hbase.MiniHBaseClusterSingleton.java
License:Apache License
/** * Stops the HBase cluster and blocks until is has been shutdown completely. * * @param log The maven log.//from w w w .j av a 2 s. c o m */ public void stop(Log log) { if (null == mCluster) { log.error("Attempted to stop a cluster, but no cluster was ever started in this process."); return; } log.info("Stopping the HBase cluster thread..."); mThread.stopClusterGracefully(); while (mThread.isAlive()) { try { mThread.join(); } catch (InterruptedException e) { log.debug("HBase cluster thread interrupted."); } } log.info("HBase cluster thread stopped."); }
From source file:de.faustedition.maven.OddSchemaDeployMojo.java
License:Apache License
/** * Configure the Wagon with the information from serverConfigurationMap * ( which comes from settings.xml )/*from w ww . j ava2 s . com*/ * * @todo Remove when {@link WagonManager#getWagon(Repository) is * available}. It's available in Maven 2.0.5. * @param wagon * @param repositoryId * @param settings * @param container * @param log * @throws WagonConfigurationException */ static void configureWagon(Wagon wagon, String repositoryId, Settings settings, PlexusContainer container, Log log) throws WagonConfigurationException { // MSITE-25: Make sure that the server settings are inserted for (int i = 0; i < settings.getServers().size(); i++) { Server server = (Server) settings.getServers().get(i); String id = server.getId(); if (id != null && id.equals(repositoryId)) { if (server.getConfiguration() != null) { final PlexusConfiguration plexusConf = new XmlPlexusConfiguration( (Xpp3Dom) server.getConfiguration()); ComponentConfigurator componentConfigurator = null; try { componentConfigurator = (ComponentConfigurator) container .lookup(ComponentConfigurator.ROLE); componentConfigurator.configureComponent(wagon, plexusConf, container.getContainerRealm()); } catch (final ComponentLookupException e) { throw new WagonConfigurationException(repositoryId, "Unable to lookup wagon configurator." + " Wagon configuration cannot be applied.", e); } catch (ComponentConfigurationException e) { throw new WagonConfigurationException(repositoryId, "Unable to apply wagon configuration.", e); } finally { if (componentConfigurator != null) { try { container.release(componentConfigurator); } catch (ComponentLifecycleException e) { log.error("Problem releasing configurator - ignoring: " + e.getMessage()); } } } } } } }
From source file:de.sisao.maven.Deployer.java
License:Open Source License
void deployResource(File resource, String autodeployTarget, Log log) { this.log = log; String targetFilePath;/*from w w w . j ava 2 s . c o m*/ // do not deploy directory resources! if (!(resource instanceof File)) return; File file = resource; sourceFileName = file.getName(); sourceFilePath = file.getPath(); sourceFilePathAbsolute = file.getAbsolutePath(); // we do not deploy files from the source directories // skip source files like /src/main/java/* for (String value : IGNORE_DIRECTORIES) { if (sourceFilePath.contains(value)) { log.info("Skipping resource: " + sourceFilePath + " because it contains: " + value); return; } } if ("".equals(hotdeployTarget)) hotdeployTarget = null; if ("".equals(autodeployTarget)) autodeployTarget = null; // check for an missing/invalid confiugration if (autodeployTarget == null && hotdeployTarget == null) { // no message is needed here! return; } // check if a .ear or .war file should be autodeplyed.... if ((sourceFileName.endsWith(".ear") || sourceFileName.endsWith(".war"))) { // verify if target autodeploy folder exists! if (autodeployTarget == null || autodeployTarget.isEmpty()) { return; // no op.. } if (!autodeployTarget.endsWith("/")) autodeployTarget += "/"; File targetTest = new File(autodeployTarget); if (!targetTest.exists()) { log.error("autodeploy directory '" + autodeployTarget + "' dose not exist. Please check your manik properties for this project."); return; } // verify if sourceFileName includes a maven /target folder pattern if (sourceFilePath.indexOf("/target/") > -1) { // in this case only root artifacts will be copied. No .war // files included in a /target sub folder! if (sourceFilePath.indexOf('/', sourceFilePath.indexOf("/target/") + 8) > -1) return; // no op! } targetFilePath = autodeployTarget + sourceFileName; // disable hotdeploy mode! hotDeployMode = false; } else { // Hotdepoyment mode! if (hotdeployTarget == null) // no hotdeployTarget defined return; // optimize path.... if (!hotdeployTarget.endsWith("/")) hotdeployTarget += "/"; // compute the target path.... targetFilePath = computeTarget(); // enable hotdeploy mode! hotDeployMode = true; } // if the target file was not computed return.... if (targetFilePath == null) return; // check if Autodeploy or Hotdeploy if (hotDeployMode) { // HOTDEPLOY MODE long lStart = System.currentTimeMillis(); copySingleResource(file, targetFilePath); long lTime = System.currentTimeMillis() - lStart; // log message.. if (sourceFileName.endsWith(".ear") || sourceFileName.endsWith(".war")) log.info("[AUTODEPLOY]: " + sourceFilePath + " in " + lTime + "ms"); else log.info("[HOTDEPLOY]: " + sourceFilePath + " in " + lTime + "ms"); } else { // AUTODEPLOY MODE long lStart = System.currentTimeMillis(); // check if a .ear or .war file should be autodeplyed in exploded // format!... if (!explodeArtifact) { copySingleResource(file, targetFilePath); } else { // find extension int i = sourceFilePathAbsolute.lastIndexOf("."); String sDirPath = sourceFilePathAbsolute.substring(0, i) + "/"; try { File srcFolder = new File(sDirPath); File destFolder = new File(targetFilePath); copyFolder(srcFolder, destFolder); } catch (IOException e) { log.info("[AUTODEPLOY]: error - " + e.getMessage()); } } // if wildfly support then tough the .deploy file if (wildflySupport) { try { String sDeployFile = targetFilePath + ".dodeploy"; File deployFile = new File(sDeployFile); if (!deployFile.exists()) new FileOutputStream(deployFile).close(); deployFile.setLastModified(System.currentTimeMillis()); } catch (FileNotFoundException e) { // console.println("[AUTODEPLOY]: error - " + // e.getMessage()); } catch (IOException e) { // console.println("[AUTODEPLOY]: error - " + // e.getMessage()); } } long lTime = System.currentTimeMillis() - lStart; log.info("[AUTODEPLOY]: " + sourceFilePath + " in " + lTime + "ms"); } }