Example usage for org.apache.maven.plugin.logging Log info

List of usage examples for org.apache.maven.plugin.logging Log info

Introduction

In this page you can find the example usage for org.apache.maven.plugin.logging Log info.

Prototype

void info(Throwable error);

Source Link

Document

Send an exception to the user in the info error level.
The stack trace for this exception will be output when this error level is enabled.

Usage

From source file:com.slim.service.GenerateService.java

License:Apache License

public void generateXml(MavenProject project, String outputDirectory, String archiveURI, String traHome,
        Log logger) throws MojoExecutionException {
    CommandUtils.createDirectoryIfNeeded(project.getBasedir().toString() + "\\" + outputDirectory, logger);

    String outConfigurationFile = CommandUtils.GUILLEMETS + project.getBasedir().toString() + "\\"
            + outputDirectory + "\\" + project.getArtifact().getArtifactId() + ".xml" + CommandUtils.GUILLEMETS;

    String earFile = CommandUtils.GUILLEMETS + project.getBasedir().toString() + "\\" + outputDirectory + "\\"
            + project.getArtifact().getArtifactId() + ".ear" + CommandUtils.GUILLEMETS;

    logger.info(" - BASE_DIR : " + project.getBasedir().toString());
    logger.info(" - TRA_HOME : " + traHome);
    logger.info(" - XML_CONFIG_LOCATION : " + outConfigurationFile);
    logger.info(" - EAR_LOCATION : " + earFile);

    try {//from  www  . ja  v  a 2 s.  c o m
        if (archiveURI == null || archiveURI.length() == 0) {
            archiveURI = "/" + project.getArtifact().getArtifactId();
        }

        Map<String, String> options = new HashMap<String, String>();
        options.put(CommandUtils.EXPORT_OPTION, "");
        options.put(CommandUtils.EAR_OPTION, earFile);
        options.put(CommandUtils.OUT_OPTION, outConfigurationFile);

        BufferedReader buildOutput = CommandUtils.executeCommand(logger, traHome,
                CommandUtils.getAppManageBin(), options);

        String line = null;
        while ((line = buildOutput.readLine()) != null) {
            // boolean ignored = false;
            logger.info(line);
        }

    } 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   w w w  .j  a v  a  2s  . c  om*/
 * @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/*from   w  w w . ja  v a 2 s .  c o  m*/
 * 
 * @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//from w ww .  j av a  2 s  . com
 * 
 * @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.slim.service.ValidateService.java

License:Apache License

/**
 * //from  ww w.  jav a 2s.co m
 * @param project
 * @param designerBinDir
 * @param outputDirectory
 * @param validationIgnoresFile
 * @param logger
 * @throws MojoExecutionException
 * @throws MojoFailureException
 */
public void validate(MavenProject project, String designerHome, String outputDirectory,
        String validationIgnoresFile, boolean checkUnusedGlobalVariables, Log logger)
        throws MojoExecutionException, MojoFailureException {
    String validateOutputFile = project.getBasedir().toString() + "\\" + outputDirectory + "\\"
            + "outValidate.txt";

    logger.info(" - DESIGNER_HOME : " + designerHome);
    logger.info(" - BASE_DIR : " + project.getBasedir().toString());
    logger.info(" - VALIDATE_OUTPUT_LOG : " + validateOutputFile);
    logger.info(" - IGNORE_FILE : " + validationIgnoresFile);

    boolean validated = true;

    Pattern pattern = preparePattern(project, designerHome, outputDirectory, validationIgnoresFile, logger);
    Pattern patternResult = Pattern.compile(".*Found.*errors.*and.*warnings.*");

    try {
        CommandUtils.createDirectoryIfNeeded(project.getBasedir().toString() + "\\" + outputDirectory, logger);

        Map<String, String> options = new HashMap<String, String>();
        if (checkUnusedGlobalVariables) {
            options.put(CommandUtils.U_OPTION,
                    project.getBasedir().toString() + "\\" + project.getArtifact().getArtifactId());
        } else {
            options.put(CommandUtils.STRING_VIDE,
                    project.getBasedir().toString() + "\\" + project.getArtifact().getArtifactId());
        }

        BufferedReader validateOutput = CommandUtils.executeCommand(logger, designerHome,
                CommandUtils.getValidateProjectBin(), options);

        BufferedWriter outLogStream = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(validateOutputFile)));
        outLogStream.append("#Log generated at " + new Date() + ".\n");

        String line = null;
        while ((line = validateOutput.readLine()) != null) {
            boolean ignored = false;
            String trimmedLine = line.trim();
            if (trimmedLine.length() == 0 || pattern.matcher(trimmedLine).matches()) {
                ignored = true;
            }
            if (!ignored) {
                validated = false;
                logger.warn(trimmedLine);
            }
            if (patternResult.matcher(line).matches()) {
                logger.info(line + "\n");
            }
            outLogStream.append(line + "\n");
        }

        outLogStream.close();

        logger.info("*******************************************************************");
        logger.info("Complete validation log is written to " + validateOutputFile);
        logger.info("*******************************************************************");
        logger.info("");
    } catch (IOException e) {
        e.printStackTrace();
        throw new MojoExecutionException("Error", e);
    } catch (Throwable e) {
        e.printStackTrace();
        throw new MojoExecutionException("Error", e);
    }

    if (!validated) {
        throw new MojoFailureException(
                "Project Validation failed ! Please check and verify Project or configure "
                        + validationIgnoresFile);
    }
}

From source file:com.spoledge.audao.maven.GeneratorMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException {
    Log log = getLog();

    // Check if something was changed:
    File touch = new File(dest, "audao.txt");

    if (!touch.exists() || touch.lastModified() < src.lastModified())
        generate();/*from   w w  w . j a  v  a  2 s.  co  m*/
    else
        log.info("Skipping AuDAO generator task - sources are up-to-date.");

    try {
        touch.delete();
        touch.createNewFile();
    } catch (Exception e) {
    }

    project.addCompileSourceRoot(dest.getAbsolutePath());
    log.info("Added source directory: " + dest);
}

From source file:com.spoledge.audao.maven.GeneratorMojo.java

License:Apache License

private void generate() throws MojoExecutionException {
    Log log = getLog();

    String targetName = dbType.toUpperCase();

    log.info("AuDAO Generating from '" + src + "', to '" + dest + "', target '" + targetName + "'");

    try {//w ww.  j a v a2  s .c om
        Target target = Target.valueOf(targetName);
        InputStreamReader xmlReader = new InputStreamReader(new FileInputStream(src), "UTF-8");

        Output output = dest.getName().endsWith(".zip") ? new ZipFileOutput(dest) : new FileOutput(dest);

        Generator g = new Generator(target);
        g.setIsDebugEnabled(debug);
        g.validate(xmlReader);

        xmlReader = new InputStreamReader(new FileInputStream(src), "UTF-8");

        if (enableResources != null) {
            for (ResourceType res : enableResources) {
                g.setResourceEnabled(res, true);
            }

            if (generateDtoGwtSerializer) {
                g.setResourceEnabled(ResourceType.DTO_GWT_SERIALIZER, generateDtoGwtSerializer);
            }
        } else {
            g.setAllResourcesEnabled(true);
            g.setResourceEnabled(ResourceType.DTO_GWT_SERIALIZER, generateDtoGwtSerializer);
        }

        g.generate(pkg, xmlReader, output);

        output.finish();
    } catch (GeneratorException e) {
        if (e.isWarningOnly()) {
            log.warn(e.toString());
        } else {
            List<? extends Exception> exceptions = e.getExceptions();
            List<GeneratorException.Type> types = e.getTypes();

            for (int i = 0; i < exceptions.size(); i++) {
                switch (types.get(i)) {
                case WARNING:
                    log.warn(exceptions.get(i).toString());
                    break;

                case ERROR:
                    log.error("Error: ", exceptions.get(i));
                    break;

                default:
                    log.error("Fatal error:", exceptions.get(i));
                    break;

                }
            }

            throw new MojoExecutionException("Error (" + exceptions.size() + " nested errors)", e);
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error", e);
    }
}

From source file:com.spotify.docker.Utils.java

License:Apache License

public static void pushImage(DockerClient docker, String imageName, Log log,
        final DockerBuildInformation buildInfo, int retryPushCount, int retryPushTimeout)
        throws MojoExecutionException, DockerException, IOException, InterruptedException {
    int attempt = 0;
    do {/* ww w  .j  av  a 2 s  . c  om*/
        final AnsiProgressHandler ansiProgressHandler = new AnsiProgressHandler();
        final DigestExtractingProgressHandler handler = new DigestExtractingProgressHandler(
                ansiProgressHandler);

        try {
            log.info("Pushing " + imageName);
            docker.push(imageName, handler);
            // A concurrent push raises a generic DockerException and not
            // the more logical ImagePushFailedException. Hence the rather
            // wide catch clause.
        } catch (DockerException e) {
            if (attempt < retryPushCount) {
                log.warn(String.format(PUSH_FAIL_WARN_TEMPLATE, imageName, retryPushTimeout / 1000, attempt + 1,
                        retryPushCount));
                sleep(retryPushTimeout);
                continue;
            } else {
                throw e;
            }
        }
        if (buildInfo != null) {
            final String imageNameWithoutTag = parseImageName(imageName)[0];
            buildInfo.setDigest(imageNameWithoutTag + "@" + handler.digest());
        }
        break;
    } while (attempt++ <= retryPushCount);
}

From source file:com.spotify.docker.Utils.java

License:Apache License

public static void pushImageTag(DockerClient docker, String imageName, List<String> imageTags, Log log)
        throws MojoExecutionException, DockerException, IOException, InterruptedException {
    // tags should not be empty if you have specified the option to push tags
    if (imageTags.isEmpty()) {
        throw new MojoExecutionException("You have used option \"pushImageTag\" but have"
                + " not specified an \"imageTag\" in your" + " docker-maven-client's plugin configuration");
    }/*from   www .j a v  a 2 s.c  o m*/
    final CompositeImageName compositeImageName = CompositeImageName.create(imageName, imageTags);
    for (final String imageTag : compositeImageName.getImageTags()) {
        final String imageNameWithTag = compositeImageName.getName() + ":" + imageTag;
        log.info("Pushing " + imageNameWithTag);
        docker.push(imageNameWithTag, new AnsiProgressHandler());
    }
}

From source file:com.spotify.plugin.dockerfile.BuildMojo.java

License:Apache License

@Override
public void execute(DockerClient dockerClient) throws MojoExecutionException, MojoFailureException {
    final Log log = getLog();

    if (skipBuild) {
        log.info("Skipping execution because 'dockerfile.build.skip' is set");
        return;//  w ww . j  a  v  a  2 s  . co m
    }

    if (!new File(contextDirectory, "Dockerfile").exists()
            && !new File(contextDirectory, "dockerfile").exists()) {
        log.info("Skipping execution because missing Dockerfile in context directory: "
                + contextDirectory.getPath());
        return;
    }

    final String imageId = buildImage(dockerClient, log, verbose, contextDirectory, repository, tag,
            pullNewerImage, noCache);

    if (imageId == null) {
        log.warn("Docker build was successful, but no image was built");
    } else {
        log.info(MessageFormat.format("Detected build of image with id {0}", imageId));
        writeMetadata(Metadata.IMAGE_ID, imageId);
    }

    // Do this after the build so that other goals don't use the tag if it doesn't exist
    if (repository != null) {
        writeImageInfo(repository, tag);
    }

    writeMetadata(log);

    if (repository == null) {
        log.info(MessageFormat.format("Successfully built {0}", imageId));
    } else {
        log.info(MessageFormat.format("Successfully built {0}", formatImageName(repository, tag)));
    }
}