You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jv...@apache.org on 2003/12/29 05:39:07 UTC

cvs commit: maven-plugins Fix.java

jvanzyl     2003/12/28 20:39:07

  Added:       .        Fix.java
  Log:
  o little dom4j thingy to flip <id/> to <artifactId/> and <groupId/>
  
    If you see any problems I'll fix the script and run it again.
  
  Revision  Changes    Path
  1.1                  maven-plugins/Fix.java
  
  Index: Fix.java
  ===================================================================
  import org.dom4j.*;
  import org.dom4j.io.*;
  import java.io.*;
  import java.util.*;
  
  public class Fix
  {
      public static void main( String[] args )
          throws Exception
      {
          SAXReader r = new SAXReader();
          
          Document d = r.read( new FileReader( args[0] ) );
          
          Element root = d.getRootElement();
          
          Element deps = root.element( "dependencies" );
          
          for ( Iterator i = deps.elementIterator( "dependency" ); i.hasNext(); )
          {
              Element e = (Element) i.next();
              
              Element id = e.element( "id" );
              
              if ( id != null )
              {
                  String text = id.getText();
                  
                  id.detach();
                  
                  e.addElement( "groupId" ).addText( text );
                  
                  e.addElement( "artifactId" ).addText( text );
                  
                  Element v = e.element( "version" );
                  
                  v.detach();
  
                  e.add( v );
                  
                  Element u = e.element( "url" );
                  
                  if ( u != null )
                  {
                      u.detach();
                      
                      e.add( u );
                  }
                  
                  Element p = e.element( "properties" );
                  
                  if ( p !=  null )
                  {
                      p.detach();
                      
                      e.add( p );
                  }
              }
          }
          
          File f = new File( args[0] );
          
          f.delete();
          
          OutputStream os = new FileOutputStream( args[0] );
  
          OutputFormat format = new OutputFormat();
          
          format.setIndentSize( 2 );
          
          format.setNewlines( true );
          
          format.setTrimText( true );
  
          XMLWriter writer = new XMLWriter( format );
          
          writer.setOutputStream( os );
          
          writer.write( d );
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org