Package org.apache.maven.plugin.logging

Examples of org.apache.maven.plugin.logging.Log


     * @throws MojoExecutionException
     */
    public void execute ()
        throws MojoExecutionException
    {
        Log log = this.getLog();

        EnforcerExpressionEvaluator evaluator = new EnforcerExpressionEvaluator( session, translator, project );

        // the entire execution can be easily skipped
        if ( !skip )
        {
            // list to store exceptions
            List<String> list = new ArrayList<String>();

            // make sure the rules exist
            if ( rules != null && rules.length > 0 )
            {
                String currentRule = "Unknown";

                // create my helper
                EnforcerRuleHelper helper = new DefaultEnforcementRuleHelper( session, evaluator, log, container );

                // if we are only warning, then disable
                // failFast
                if ( !fail )
                {
                    failFast = false;
                }

                // go through each rule
                for ( int i = 0; i < rules.length; i++ )
                {

                    // prevent against empty rules
                    EnforcerRule rule = rules[i];
                    if ( rule != null )
                    {
                        // store the current rule for
                        // logging purposes
                        currentRule = rule.getClass().getName();
                        log.debug( "Executing rule: " + currentRule );
                        try
                        {
                            if ( ignoreCache || shouldExecute( rule ) )
                            {
                                // execute the rule
                                //noinspection SynchronizationOnLocalVariableOrMethodParameter
                                synchronized ( rule )
                                {
                                   rule.execute( helper );
                                }
                            }
                        }
                        catch ( EnforcerRuleException e )
                        {
                            // i can throw an exception
                            // because failfast will be
                            // false if fail is false.
                            if ( failFast )
                            {
                                throw new MojoExecutionException( currentRule + " failed with message:\n"
                                    + e.getMessage(), e );
                            }
                            else
                            {
                                list.add( "Rule " + i + ": " + currentRule + " failed with message:\n" + e.getMessage() );
                                log.debug( "Adding failure due to exception", e );
                            }
                        }
                    }
                }

                // if we found anything
                if ( !list.isEmpty() )
                {
                    for ( String failure  : list )
                    {
                        log.warn( failure );
                    }
                    if ( fail )
                    {
                        throw new MojoExecutionException(
                                                          "Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed." );
                    }
                }
            }
            else
            {
                throw new MojoExecutionException(
                                                  "No rules are configured. Use the skip flag if you want to disable execution." );
            }
        }
        else
        {
            log.info( "Skipping Rule Enforcement." );
        }
    }
View Full Code Here


     */
    protected boolean shouldExecute ( EnforcerRule rule )
    {
        if ( rule.isCacheable() )
        {
            Log log = this.getLog();
            log.debug( "Rule " + rule.getClass().getName() + " is cacheable." );
            String key = rule.getClass().getName() + " " + rule.getCacheId();
            if ( EnforceMojo.cache.containsKey( key ) )
            {
                log.debug( "Key " + key + " was found in the cache" );
                if ( rule.isResultValid( (EnforcerRule) cache.get( key ) ) )
                {
                    log.debug( "The cached results are still valid. Skipping the rule: " + rule.getClass().getName() );
                    return false;
                }
            }
           
            //add it to the cache of executed rules
View Full Code Here

     * @see org.apache.maven.enforcer.rule.api.EnforcerRule#execute(org.apache.maven.enforcer.rule.api.EnforcerRuleHelper)
     */
    public void execute( EnforcerRuleHelper helper )
        throws EnforcerRuleException
    {
        Log log = helper.getLog();

        try
        {
            log.debug( "Echo condition : " + this.condition );
            // Evaluate condition within Plexus Container
            String script = (String) helper.evaluate( this.condition );
            log.debug( "Echo script : " + script );
            if ( !evaluateCondition( script, log ) )
            {
                String message = getMessage();
                if ( StringUtils.isEmpty( message ) )
                {
View Full Code Here

    public void execute() throws MojoExecutionException {
        if (project.getPackaging().equals("pom")) {
            return;
        }

        Log log = getLog();
        List<URL> jarFiles = new ArrayList<URL>();
        for (Object o : project.getArtifacts()) {
            Artifact a = (Artifact)o;
            try {
                if (log.isDebugEnabled()) {
                    log.debug("Adding: " + a);
                }
                jarFiles.add(a.getFile().toURI().toURL());
            } catch (MalformedURLException e) {
                getLog().error(e);
            }
        }

        /*
         * Add org.apache.tuscany.sca:tuscany-extensibility-osgi module
         */
        String aid = "equinox".equals(osgiRuntime) ? "tuscany-extensibility-equinox" : "tuscany-extensibility-osgi";
        Artifact ext = getArtifact("org.apache.tuscany.sca", aid);
        try {
            URL url = ext.getFile().toURI().toURL();
            if (!jarFiles.contains(url)) {
                if (log.isDebugEnabled()) {
                    log.debug("Adding: " + ext);
                }
                jarFiles.add(url);
            }
        } catch (MalformedURLException e) {
            getLog().error(e);
View Full Code Here

    public void execute() throws MojoExecutionException {
        if (project.getPackaging().equals("pom")) {
            return;
        }

        Log log = getLog();
        List<File> jarFiles = new ArrayList<File>();
        for (Object o : project.getArtifacts()) {
            Artifact a = (Artifact)o;
            if (!(Artifact.SCOPE_COMPILE.equals(a.getScope()) || Artifact.SCOPE_RUNTIME.equals(a.getScope()))) {
                if (log.isDebugEnabled()) {
                    log.debug("Skipping artifact: " + a);
                }
                continue;
            }
            if (log.isDebugEnabled()) {
                log.debug("Artifact: " + a);
            }
            String bundleName = null;
            try {
                bundleName = LibraryBundleUtil.getBundleName(a.getFile());
            } catch (IOException e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
            if (bundleName == null) {
                if (log.isDebugEnabled()) {
                    log.debug("Adding non-OSGi jar: " + a);
                }
                jarFiles.add(a.getFile());
            }
        }

        try {
            String version = project.getVersion();
            if (version.endsWith(Artifact.SNAPSHOT_VERSION)) {
                version = version.substring(0, version.length() - Artifact.SNAPSHOT_VERSION.length() - 1);
            }

            Manifest mf = LibraryBundleUtil.libraryManifest(jarFiles, project.getName(), version, copyJars);
            File file = new File(project.getBasedir(), "META-INF");
            file.mkdir();
            file= new File(file, "MANIFEST.MF");
            if (log.isDebugEnabled()) {
                log.debug("Generating " + file);
            }

            FileOutputStream fos = new FileOutputStream(file);
            mf.write(fos);
            fos.close();

            if (copyJars) {
                File lib = new File(project.getBasedir(), "lib");
                if (lib.isDirectory()) {
                    for (File c : lib.listFiles()) {
                        c.delete();
                    }
                }
                lib.mkdir();
                byte[] buf = new byte[4096];
                for (File jar : jarFiles) {
                    File jarFile = new File(lib, jar.getName());
                    if (log.isDebugEnabled()) {
                        log.debug("Copying " + jar + " to " + jarFile);
                    }
                    FileInputStream in = new FileInputStream(jar);
                    FileOutputStream out = new FileOutputStream(jarFile);
                    int len = 0;
                    while (len > 0) {
View Full Code Here

    private boolean shouldIfail = false;

    public void execute( EnforcerRuleHelper helper )
        throws EnforcerRuleException
    {
        Log log = helper.getLog();

        try
        {
            // get the various expressions out of the helper.
            MavenProject project = (MavenProject) helper.evaluate( "${project}" );
            MavenSession session = (MavenSession) helper.evaluate( "${session}" );
            String target = (String) helper.evaluate( "${project.build.directory}" );
            String artifactId = (String) helper.evaluate( "${project.artifactId}" );

            // retreive any component out of the session directly
            ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class );
            RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class );

            log.info( "Retrieved Target Folder: " + target );
            log.info( "Retrieved ArtifactId: " +artifactId );
            log.info( "Retrieved Project: " + project );
            log.info( "Retrieved RuntimeInfo: " + rti );
            log.info( "Retrieved Session: " + session );
            log.info( "Retrieved Resolver: " + resolver );

            if ( this.shouldIfail )
            {
                throw new EnforcerRuleException( "Failing because my param said so." );
            }
View Full Code Here

     * @throws MojoExecutionException
     */
    public void execute ()
        throws MojoExecutionException
    {
        Log log = this.getLog();

        EnforcerExpressionEvaluator evaluator = new EnforcerExpressionEvaluator( session, translator, project );

        // the entire execution can be easily skipped
        if ( !skip )
        {
            // list to store exceptions
            List<String> list = new ArrayList<String>();

            // make sure the rules exist
            if ( rules != null && rules.length > 0 )
            {
                String currentRule = "Unknown";

                // create my helper
                EnforcerRuleHelper helper = new DefaultEnforcementRuleHelper( session, evaluator, log, container );

                // if we are only warning, then disable
                // failFast
                if ( !fail )
                {
                    failFast = false;
                }

                // go through each rule
                for ( int i = 0; i < rules.length; i++ )
                {

                    // prevent against empty rules
                    EnforcerRule rule = rules[i];
                    if ( rule != null )
                    {
                        // store the current rule for
                        // logging purposes
                        currentRule = rule.getClass().getName();
                        log.debug( "Executing rule: " + currentRule );
                        try
                        {
                            if ( ignoreCache || shouldExecute( rule ) )
                            {
                                // execute the rule
                                //noinspection SynchronizationOnLocalVariableOrMethodParameter
                                synchronized ( rule )
                                {
                                   rule.execute( helper );
                                }
                            }
                        }
                        catch ( EnforcerRuleException e )
                        {
                            // i can throw an exception
                            // because failfast will be
                            // false if fail is false.
                            if ( failFast )
                            {
                                throw new MojoExecutionException( currentRule + " failed with message:\n"
                                    + e.getMessage(), e );
                            }
                            else
                            {
                                list.add( "Rule " + i + ": " + currentRule + " failed with message:\n" + e.getMessage() );
                                log.debug( "Adding failure due to exception", e );
                            }
                        }
                    }
                }

                // if we found anything
                if ( !list.isEmpty() )
                {
                    for ( String failure  : list )
                    {
                        log.warn( failure );
                    }
                    if ( fail )
                    {
                        throw new MojoExecutionException(
                                                          "Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed." );
                    }
                }
            }
            else
            {
                throw new MojoExecutionException(
                                                  "No rules are configured. Use the skip flag if you want to disable execution." );
            }
        }
        else
        {
            log.info( "Skipping Rule Enforcement." );
        }
    }
View Full Code Here

     */
    protected boolean shouldExecute ( EnforcerRule rule )
    {
        if ( rule.isCacheable() )
        {
            Log log = this.getLog();
            log.debug( "Rule " + rule.getClass().getName() + " is cacheable." );
            String key = rule.getClass().getName() + " " + rule.getCacheId();
            if ( EnforceMojo.cache.containsKey( key ) )
            {
                log.debug( "Key " + key + " was found in the cache" );
                if ( rule.isResultValid( (EnforcerRule) cache.get( key ) ) )
                {
                    log.debug( "The cached results are still valid. Skipping the rule: " + rule.getClass().getName() );
                    return false;
                }
            }
           
            //add it to the cache of executed rules
View Full Code Here

     *             error occurs.
     */
    protected void copyFile( File artifact, File destFile )
        throws MojoExecutionException
    {
        Log theLog = this.getLog();
        try
        {
            theLog.info( "Copying "
                + ( this.outputAbsoluteArtifactFilename ? artifact.getAbsolutePath() : artifact.getName() ) + " to "
                + destFile );
            FileUtils.copyFile( artifact, destFile );

        }
View Full Code Here

import org.junit.Test;

public class SummaryBuilderTest {
  @Test
  public void shouldAddToSummaryAndPrintToLog() {
    Log log = mock(Log.class);
   
    SummaryBuilder builder = new SummaryBuilder();
    builder.add("INPUT", "OUTPUT", "ENCODING", log);
    builder.add("INPUT", "OUTPUT", "ENCODING", log);
   
View Full Code Here

TOP

Related Classes of org.apache.maven.plugin.logging.Log

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.