You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by KC Baltz <KC...@Copart.Com> on 2005/11/01 20:23:04 UTC

RE: Installing Commercial Jars and missing POM XML files

Peter, 

Your MvnCreateLocalPom works well, but I think it needed a small fix and an enhancement.

You have two places in dumpPom(String, String) where groupId is used to create a path.  I appended .replace('.', '/') to the groupId to handle dotted groups.  

Also, when you actually create the pom, you were doing artifact.version.pom, when I think it's supposed to be artifact-version.pom  (note the dash). 

My modified version is pasted below.

K.C.

import java.io.*;

/**
 * Create missing POM XML descriptions for maven repository
 * elements
 *
 *
 * @author Peter Pilgrim, Oct 24, 2005 2:43:57 PM
 * @version $Id$
 */
public class MvnCreateLocalPom {

    private static String repositoryPath = 
        System.getProperty("user.home")+"/.m2/repository";

    /**
     * Default constructor 
     */
    public MvnCreateLocalPom() {
        super();
    }
    
    /**
     * Write the POM to standard output
     * @param groupId the group  name
     * 
     * @see #dumpPom(String, String)
     */
    public void dumpPom( String groupId ) throws IOException
    {
        File groupDir = new File( repositoryPath +"/" +groupId );
        if ( !groupDir.exists() )
            throw new FileNotFoundException( 
                    "no such group directory = "+groupDir );
        
        File contents[] = groupDir.listFiles();
        for ( int j=0; j<contents.length; ++j ) {
            String oneFile = contents[j].getName();
            if ( oneFile.equals(".") || 
                oneFile.equals("..") ) 
                continue;
            
            // System.out.println( oneFile+"  file "+( contents[j].exists() ? "exists" : "not file"));
            dumpPom( groupId, oneFile );
            
        }
    }
    
    /**
     * Write the POM to standard output
     * @param groupId the group  name
     * @param artifactId the artifact name
     */
    public void dumpPom( String groupId, String artifactId ) throws IOException
    {
        File groupArtifactDir = new File( 
                repositoryPath +"/" +groupId.replace('.', '/')+"/"+artifactId );
        
        if ( !groupArtifactDir.exists() )
            throw new FileNotFoundException( 
                    "no such group artifact directory = "+groupArtifactDir );
        File contents[] = groupArtifactDir.listFiles();
        for ( int j=0; j<contents.length; ++j ) {
            String oneFile = contents[j].getName();
            if ( oneFile.equals(".") || 
                oneFile.equals("..") ) 
                continue;
            
//            System.out.println( oneFile+"  file "+( contents[j].exists() ? "exists" : "not file"));
            if ( contents[j].isDirectory() &&
                    !oneFile.equals("maven-metadata-local.xml") ) {
                // We could have a better stringent test here.
                File outputFile = new File(
                        repositoryPath +"/" +groupId.replace('.', '/')+"/"+artifactId +"/"+ oneFile+"/"+
                        artifactId+"-"+oneFile+".pom" );
                
                // Here oneFile should be version identifier number!
                FileWriter fwriter = new FileWriter( outputFile );
                PrintWriter pwriter = new PrintWriter( fwriter );
                pwriter.println("<project>");
                pwriter.println("    <modelVersion>4.0.0</modelVersion>");
                pwriter.println("    <groupId>"+groupId+"</groupId>");
                pwriter.println("    <artifactId>"+artifactId+"</artifactId>");
                pwriter.println("    <version>"+oneFile+"</version>");
                pwriter.println("</project>");
                pwriter.close();
            }
        }
    }
    

    public static void main( String args[] )
    {
        MvnCreateLocalPom pommer = new MvnCreateLocalPom();
        try {
//            pommer.dumpPom( "com.sun.jsfcl", "jsfcl");
            pommer.dumpPom( "com.sun.data", "dataprovider");
            pommer.dumpPom( "javax.faces", "jsf-impl");
            pommer.dumpPom( "com.sun.web", "defaulttheme");
//            pommer.dumpPom( "expresso");
//            pommer.dumpPom( "bea-weblogic", "weblogic");
        }
        catch (Exception ex) {
            ex.printStackTrace( System.err );
        }
    }
}

-----Original Message-----
From: Pilgrim, Peter [mailto:peter.pilgrim@csfb.com]
Sent: Monday, October 24, 2005 7:35 AM
To: 'Maven Users List'
Subject: RE: Installing Commercial Jars and missing POM XML files


> -----Original Message-----
> From: Wendy Smoak [mailto:wsmoak@apache.org]
==////==
> 
> From: "Pilgrim, Peter" <pe...@csfb.com>
> 
> > My question is, how do I tell maven not to going looking remotely
> > for POM XML files for the commercial jars since I installed
> > them locally on my machine?
> 
> http://www.mail-archive.com/users%40maven.apache.org/msg26066.html
> 
> I've just been creating a pom for them with just the 
> group/artifact/version 
> and Maven stops complaining.
> 
> Should we submit poms for these non-distributable commercial 
> libraries, so 
> that they're in the repository like the ones for Sun .jars 
> (and we can come 
> to some agreement on the group/artifact ids?)
==////==

I just created a program to create the local POMs for me in the
m2 repository. But when I run it, and manually rename AUTO-pom to
.pom file, and then re-run ``mvn''. 

Guess what? Maven still complains about remote repository. So it
cannot possibly that the ``**/*.pom''  does not exist in the right
place. I created it, so therefore maven should shut the ++++ up(!).

import java.io.*;

/**
 * Create missing POM XML descriptions for maven repository
 * elements
 *
 *
 * @author Peter Pilgrim, Oct 24, 2005 2:43:57 PM
 * @version $Id$
 */
public class MvnCreateLocalPom {

    private static String repositoryPath = 
        System.getProperty("user.home")+"/.m2/repository";

    /**
     * Default constructor 
     */
    public MvnCreateLocalPom() {
        super();
    }
    
    /**
     * Write the POM to standard output
     * @param groupId the group  name
     * 
     * @see #dumpPom(String, String)
     */
    public void dumpPom( String groupId ) throws IOException
    {
        File groupDir = new File( repositoryPath +"/" +groupId );
        if ( !groupDir.exists() )
            throw new FileNotFoundException( 
                    "no such group directory = "+groupDir );
        
        File contents[] = groupDir.listFiles();
        for ( int j=0; j<contents.length; ++j ) {
            String oneFile = contents[j].getName();
            if ( oneFile.equals(".") || 
                oneFile.equals("..") ) 
                continue;
            
            // System.out.println( oneFile+"  file "+( contents[j].exists() ? "exists" : "not file"));
            dumpPom( groupId, oneFile );
            
        }
    }
    
    /**
     * Write the POM to standard output
     * @param groupId the group  name
     * @param artifactId the artifact name
     */
    public void dumpPom( String groupId, String artifactId ) throws IOException
    {
        File groupArtifactDir = new File( 
                repositoryPath +"/" +groupId+"/"+artifactId );
        
        if ( !groupArtifactDir.exists() )
            throw new FileNotFoundException( 
                    "no such group artifact directory = "+groupArtifactDir );
        File contents[] = groupArtifactDir.listFiles();
        for ( int j=0; j<contents.length; ++j ) {
            String oneFile = contents[j].getName();
            if ( oneFile.equals(".") || 
                oneFile.equals("..") ) 
                continue;
            
//            System.out.println( oneFile+"  file "+( contents[j].exists() ? "exists" : "not file"));
            if ( contents[j].isDirectory() &&
                    !oneFile.equals("maven-metadata-local.xml") ) {
                // We could have a better stringent test here.
                File outputFile = new File(
                        repositoryPath +"/" +groupId+"/"+artifactId +"/"+ oneFile+"/"+
                        artifactId+"."+oneFile+".AUTO-pom" );
                
                // Here oneFile should be version identifier number!
                FileWriter fwriter = new FileWriter( outputFile );
                PrintWriter pwriter = new PrintWriter( fwriter );
                pwriter.println("<project>");
                pwriter.println("    <modelVersion>4.0.0</modelVersion>");
                pwriter.println("    <groupId>"+groupId+"</groupId>");
                pwriter.println("    <artifactId>"+artifactId+"</artifactId>");
                pwriter.println("    <version>"+oneFile+"</version>");
                pwriter.println("</project>");
                pwriter.close();
            }
        }
    }
    

    public static void main( String args[] )
    {
        MvnCreateLocalPom pommer = new MvnCreateLocalPom();
        try {
            pommer.dumpPom( "commons-beanutils", "commons-beanutils");
            pommer.dumpPom( "expresso");
            pommer.dumpPom( "bea-weblogic", "weblogic");
        }
        catch (Exception ex) {
            ex.printStackTrace( System.err );
        }
    }
}

--
Peter Pilgrim :: J2EE Software Development
Operations/IT - Credit Suisse First Boston, 
Floor 15, 5 Canada Square, London E14 4QJ, United Kingdom
Tel: +44-(0)207-883-4497



==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer: 

http://www.csfb.com/legal_terms/disclaimer_external_email.shtml

==============================================================================


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


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