Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.jboss.maven.plugins.retro;
  
  import java.io.File;
  import java.util.List;
  
Maven plugin for JBoss Retro Weaver. This can be used to do byte code weaving on classes in jars and directories. By default the weaver will weave the main classes and output the result to a jar with the specified classifier.

Phase:
process-classes
Goal:
weave
 
 public class WeaveMojo extends AbstractWeaveMojo
 {

   
The plugin dependencies.

Parameter:
expression="${plugin.artifacts}"
Required:
Readonly:
 
    protected List pluginArtifacts;

   
The directory for compiled classes.

Parameter:
expression="${project.build.outputDirectory}"
Required:
 
    protected File classesDirectory;


   
The directory where the weaved classes should be written.

Parameter:
expression="${project.build.directory}/classes-weaved"
 
    protected File outputDirectory;
   
   
Attach a jar of the weaved classes to the build lifecycle. This will allow the weaved jar to be deployed with the other build artifacts.

Parameter:
 
    protected boolean attachJar = false;
   
   
Project classpath.

Parameter:
expression="${project.compileClasspathElements}"
Required:
 
    protected List classpathElements;
   
   
Main plugin execution method
    
    public void execute() throws MojoFailureExceptionMojoExecutionException
    {
       if ( ( ! this.getClassesDirecotry().exists()) 
             || ( ! this.getClassesDirecotry().isDirectory()))
       {
          getLog().info("No classes found to weave.");
          return;
       }
       
       this.getLog().info("Weaving classes in: " + this.getClassesDirecotry());
       
       try 
       {
          doWeave(this.buildWeaveClasspath(), this.generateWeaverArgs());
       }
       catch (Exception e)
       {
          throw new MojoExecutionException("Error during weave: " + e);
       }
       this.getLog().info("Weaving complete.");
       if (this.
       {
          String jarFilePath = .getBuild().getDirectory()
             + . + .getArtifactId() + "-" + this.getJarClassifier() + ".jar";
          try 
          {
             File jarFile = JarUtil.createJarFile(this.getOutputPath(), jarFilePath);
            .attachArtifact(jarFilethis.getJarClassifier());
            getLog().info("Weaved jar file created: " + jarFile.getAbsolutePath());
         }
         catch (IOException ioe
         {
            getLog().warn("Unable to create Jar file: " + ioe);
         }
      }
   }
      
   protected String [] generateWeaverArgs() 
   {
      ArrayList<StringargsList = new ArrayList<String> ();
      if (this.)
      {
         argsList.add("-verbose");
      }
      if (this.)
      {
         argsList.add("-suppress");
      }
      if (this.)
      {
         argsList.add("-useSystemClasspath");
         argsList.add(Boolean.toString());
      }
      argsList.add("-cp");
      argsList.add(buildWeaveClasspath());
      if (this. !=null)
      {
         argsList.add("-weaverClass");
         argsList.add(this.);
      }
      argsList.add("-outputDir");
      argsList.add(this.getOutputPath());
      argsList.add(this.getClassesDirecotry().getAbsolutePath());
      
      String [] args = new String[argsList.size()];
      return argsList.toArray(args);
   }
   
   
Generates a classpath string based on the compile class path and the plugin dependencies.

Returns:
   protected String buildWeaveClasspath() {
      StringBuilder classpath = new StringBuilder();
      List cpElements = this.getClasspathElements();
      for (Object element : cpElements)
      {
         classpath.append(element);
         classpath.append();
      }
      
      // If the weaver classes can be found in the source directory 
      // (i.e. we are weaving jboss retro), then we don't want the 
      // retro jar from the plugin dependency to be pulled in from the repo.
      boolean useRetroDep = true;
      NameFileFilter nameFilter = new NameFileFilter("Weaver.class");
      Collection weaverClassFiles = FileUtils.listFiles(this.getClassesDirecotry(), nameFilter.);
      if (weaverClassFiles.size() > 0)
      {
         useRetroDep = false;
      }
      
      for (Object artifactObj : )
      {
         try
         {
            Artifact artifact = (ArtifactartifactObj;
            if (artifact.getFile() != null)
            {
               if ( useRetroDep || ( ! artifact.getArtifactId().equals()))
               {
                  classpath.append(artifact.getFile().getCanonicalPath());
                  classpath.append();
               }
            }
         }
         catch (IOException ioe)
         {
            this.getLog().warn("Could not get filename");
         }
      }
      return classpath.toString();
   }
         
   protected String getOutputPath() 
   {
      return this..getAbsolutePath();
   }
   
   public File getClassesDirecotry() 
   {
      return this.;
   }
   
   
Get the list of classpath elements to use for weaving.

Returns:
   public List getClasspathElements() 
   {
      return this.;
   }
      
New to GrepCode? Check out our FAQ X