maven-m2-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject cvs commit: maven-components/sandbox/repoclean/src/main/bash repoclean.sh
Date Wed, 06 Apr 2005 20:15:07 GMT
jdcasey     2005/04/06 13:15:07

  Modified:    sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean
                        RepositoryCleanerConfiguration.java
                        RepositoryCleaner.java Main.java
               sandbox/repoclean install.sh
               sandbox/repoclean/src/main/bash repoclean.sh
  Log:
  added ability to mail out the repository-level report contents in the event an error occurs...also
the ability to configure the email options using the config properties file.
  
  Revision  Changes    Path
  1.2       +83 -0     maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java
  
  Index: RepositoryCleanerConfiguration.java
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleanerConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RepositoryCleanerConfiguration.java	23 Mar 2005 04:53:30 -0000	1.1
  +++ RepositoryCleanerConfiguration.java	6 Apr 2005 20:15:07 -0000	1.2
  @@ -37,6 +37,20 @@
   
       private boolean reportOnly;
   
  +    private String errorReportSubject;
  +
  +    private String errorReportFromName;
  +
  +    private String errorReportFromAddress;
  +
  +    private String errorReportToName;
  +
  +    private String errorReportToAddress;
  +
  +    private String errorReportSmtpHost;
  +
  +    private boolean mailErrorReport;
  +
       public void setSourceRepositoryPath( String sourceRepositoryPath )
       {
           this.sourceRepositoryPath = sourceRepositoryPath;
  @@ -107,4 +121,73 @@
           return reportOnly;
       }
   
  +    public void setErrorReportSubject( String errorReportSubject )
  +    {
  +        this.errorReportSubject = errorReportSubject;
  +    }
  +
  +    public String getErrorReportSubject()
  +    {
  +        return errorReportSubject;
  +    }
  +
  +    public String getErrorReportFromAddress()
  +    {
  +        return errorReportFromAddress;
  +    }
  +
  +    public void setErrorReportFromAddress( String errorReportFromAddress )
  +    {
  +        this.errorReportFromAddress = errorReportFromAddress;
  +    }
  +
  +    public String getErrorReportFromName()
  +    {
  +        return errorReportFromName;
  +    }
  +
  +    public void setErrorReportFromName( String errorReportFromName )
  +    {
  +        this.errorReportFromName = errorReportFromName;
  +    }
  +
  +    public String getErrorReportSmtpHost()
  +    {
  +        return errorReportSmtpHost;
  +    }
  +
  +    public void setErrorReportSmtpHost( String errorReportSmtpHost )
  +    {
  +        this.errorReportSmtpHost = errorReportSmtpHost;
  +    }
  +
  +    public String getErrorReportToAddress()
  +    {
  +        return errorReportToAddress;
  +    }
  +
  +    public void setErrorReportToAddress( String errorReportToAddress )
  +    {
  +        this.errorReportToAddress = errorReportToAddress;
  +    }
  +
  +    public String getErrorReportToName()
  +    {
  +        return errorReportToName;
  +    }
  +
  +    public void setErrorReportToName( String errorReportToName )
  +    {
  +        this.errorReportToName = errorReportToName;
  +    }
  +
  +    public void setMailErrorReport( boolean mailErrorReport )
  +    {
  +        this.mailErrorReport = mailErrorReport;
  +    }
  +
  +    public boolean mailErrorReport()
  +    {
  +        return mailErrorReport;
  +    }
   }
  \ No newline at end of file
  
  
  
  1.10      +59 -49    maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java
  
  Index: RepositoryCleaner.java
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/RepositoryCleaner.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- RepositoryCleaner.java	6 Apr 2005 01:28:29 -0000	1.9
  +++ RepositoryCleaner.java	6 Apr 2005 20:15:07 -0000	1.10
  @@ -59,7 +59,7 @@
       public static final String ROLE = RepositoryCleaner.class.getName();
   
       private ArtifactDigestVerifier artifactDigestVerifier;
  -    
  +
       private MailSender mailSender;
   
       private ArtifactConstructionSupport artifactConstructionSupport = new ArtifactConstructionSupport();
  @@ -74,7 +74,7 @@
           File sourceRepositoryBase = normalizeSourceRepositoryBase( configuration.getSourceRepositoryPath()
);
   
           File targetRepositoryBase = normalizeTargetRepositoryBase( configuration.getTargetRepositoryPath()
);
  -        
  +
           boolean mailReport = false;
   
           // do not proceed if we cannot produce reports, or if the repository is
  @@ -93,14 +93,15 @@
                   List artifacts = null;
                   try
                   {
  -                    artifactDiscoverer = (ArtifactDiscoverer) container.lookup( ArtifactDiscoverer.ROLE,
  +                    artifactDiscoverer = (ArtifactDiscoverer) container.lookup(
  +                                                                                ArtifactDiscoverer.ROLE,
                                                                                   configuration.getSourceRepositoryLayout()
);
   
                       if ( logger.isInfoEnabled() )
                       {
                           logger.info( "Discovering artifacts." );
                       }
  -                    
  +
                       try
                       {
                           artifacts = artifactDiscoverer.discoverArtifacts( sourceRepositoryBase,
repoReporter );
  @@ -143,7 +144,7 @@
                           {
                               logger.info( "Rewriting POMs and artifact files." );
                           }
  -                        
  +
                           rewriteArtifactsAndPoms( artifacts, sourceRepo, targetRepo, configuration,
reportsBase,
                                                    sourceRepositoryBase, targetRepositoryBase,
repoReporter );
                       }
  @@ -170,59 +171,62 @@
                   {
                       logger.warn( "Warning encountered while rewriting one or more artifacts
from source repository to target repository." );
                   }
  -                
  -                if(repoReporter.hasError())
  +
  +                if ( repoReporter.hasError() )
                   {
                       mailReport = true;
                   }
               }
               finally
               {
  -                if(repoReporter != null)
  +                if ( repoReporter != null )
                   {
                       repoReporter.close();
                   }
               }
  -            
  -            if(mailReport)
  +
  +            if ( mailReport && configuration.mailErrorReport() )
               {
  -                String reportContents = readReportFile(repoReporter.getReportFile());
  -                
  +                String reportContents = readReportFile( repoReporter.getReportFile() );
  +
                   MailMessage message = new MailMessage();
  -                message.setContent(reportContents);
  -                message.setSubject("[REPOCLEAN] Error converting repository.");
  -                message.setFromName("Repoclean");
  -                message.setFromAddress("jdcasey@codehaus.org");
  -                message.setSendDate(new Date());
  -                message.addTo("Maven-2 Developers List", "m2-dev@maven.apache.org");
  -                
  -                mailSender.send(message);
  +                message.setContent( reportContents );
  +                message.setSubject( configuration.getErrorReportSubject() );
  +                message.setFromName( configuration.getErrorReportFromName() );
  +                message.setFromAddress( configuration.getErrorReportFromAddress() );
  +                message.setSendDate( new Date() );
  +                message.addTo( configuration.getErrorReportToName(), configuration.getErrorReportToAddress()
);
  +
  +                mailSender.setSmtpHost( configuration.getErrorReportSmtpHost() );
  +
  +                mailSender.send( message );
               }
           }
  -        
  +
       }
   
  -    private String readReportFile( File reportFile ) throws IOException
  +    private String readReportFile( File reportFile )
  +        throws IOException
       {
           FileReader reader = null;
           try
           {
  -            reader = new FileReader(reportFile);
  -            
  +            reader = new FileReader( reportFile );
  +
               StringBuffer reportContent = new StringBuffer();
               char[] buffer = new char[512];
               int read = -1;
  -            
  -            while((read = reader.read(buffer)) > -1)
  +
  +            while ( ( read = reader.read( buffer ) ) > -1 )
               {
  -                reportContent.append(buffer, 0, read);
  +                reportContent.append( buffer, 0, read );
               }
  -            
  +
               return reportContent.toString();
           }
           finally
           {
  -            IOUtil.close(reader);
  +            IOUtil.close( reader );
           }
       }
   
  @@ -237,13 +241,14 @@
   
           try
           {
  -            logger.info("Rewriting " + artifacts.size() + " artifacts (Should be " + (artifacts.size()
* 2) + " rewrites including POMs).");
  +            logger.info( "Rewriting " + artifacts.size() + " artifacts (Should be " + (
artifacts.size() * 2 )
  +                + " rewrites including POMs)." );
               for ( Iterator it = artifacts.iterator(); it.hasNext(); )
               {
                   Artifact artifact = (Artifact) it.next();
   
  -                String artifactReportPath = buildArtifactReportPath(artifact);
  -                
  +                String artifactReportPath = buildArtifactReportPath( artifact );
  +
                   Reporter artifactReporter = null;
                   try
                   {
  @@ -255,17 +260,18 @@
                       File artifactTarget = new File( targetRepo.getBasedir(), targetRepo.pathOf(
artifact ) );
   
                       artifact.setFile( artifactSource );
  -                    
  -                    boolean targetMissingOrOlder = !artifactTarget.exists() || artifactTarget.lastModified()
< artifactSource.lastModified();
  -                    
  -                    if(artifactSource.exists() && targetMissingOrOlder)
  +
  +                    boolean targetMissingOrOlder = !artifactTarget.exists()
  +                        || artifactTarget.lastModified() < artifactSource.lastModified();
  +
  +                    if ( artifactSource.exists() && targetMissingOrOlder )
                       {
  -                        
  +
                           try
                           {
                               if ( !configuration.reportOnly() )
                               {
  -                                if(logger.isDebugEnabled())
  +                                if ( logger.isDebugEnabled() )
                                   {
                                       logger.debug( "sourceRepo basedir is: \'" + sourceRepo.getBasedir()
+ "\'" );
                                       logger.debug( "targetRepo basedir is: \'" + targetRepo.getBasedir()
+ "\'" );
  @@ -299,8 +305,8 @@
                           {
                               if ( logger.isDebugEnabled() )
                               {
  -                                logger.debug( "working on digest for artifact[" + artifact.getId()
+ "] with groupId: \'"
  -                                    + artifact.getGroupId() + "\'" );
  +                                logger.debug( "working on digest for artifact[" + artifact.getId()
  +                                    + "] with groupId: \'" + artifact.getGroupId() + "\'"
);
                               }
   
                               try
  @@ -317,8 +323,9 @@
                           if ( !errorOccurred )
                           {
                               ArtifactMetadata pom = new ProjectMetadata( artifact );
  -                            
  -                            artifactPomRewriter = (ArtifactPomRewriter) container.lookup(
ArtifactPomRewriter.ROLE,
  +
  +                            artifactPomRewriter = (ArtifactPomRewriter) container.lookup(
  +                                                                                      
   ArtifactPomRewriter.ROLE,
                                                                                         
   configuration.getSourcePomVersion() );
   
                               File sourcePom = new File( sourceRepositoryBase, sourceRepo.pathOfMetadata(
pom ) );
  @@ -340,18 +347,20 @@
                       }
                       else
                       {
  -                        artifactReporter.error("Cannot find source file for artifact: \'"
+ artifact.getId() + "\' under path: \'" + artifactSource + "\'");
  +                        artifactReporter.error( "Cannot find source file for artifact:
\'" + artifact.getId()
  +                            + "\' under path: \'" + artifactSource + "\'" );
                       }
  -                    
  +
                       if ( artifactReporter.hasError() )
                       {
                           repoReporter.warn( "Error(s) occurred while rewriting artifact:
\'" + artifact.getId()
                               + "\' or its POM." );
                       }
                   }
  -                catch(Exception e)
  +                catch ( Exception e )
                   {
  -                    artifactReporter.error("Error while rewriting file or POM for artifact:
\'" + artifact.getId() + "\'. See report at: \'" + artifactReportPath + "\'.", e);
  +                    artifactReporter.error( "Error while rewriting file or POM for artifact:
\'" + artifact.getId()
  +                        + "\'. See report at: \'" + artifactReportPath + "\'.", e );
                   }
                   finally
                   {
  @@ -374,15 +383,16 @@
       private String buildArtifactReportPath( Artifact artifact )
       {
           String classifier = artifact.getClassifier();
  -        
  -        return artifact.getGroupId().replace('.', '/') + "/" + artifact.getArtifactId()
+ "/" + artifact.getType() + "/" + ((classifier != null)?(classifier + "-"):("")) + artifact.getVersion()
+ ".report.txt";
  +
  +        return artifact.getGroupId().replace( '.', '/' ) + "/" + artifact.getArtifactId()
+ "/" + artifact.getType()
  +            + "/" + ( ( classifier != null ) ? ( classifier + "-" ) : ( "" ) ) + artifact.getVersion()
+ ".report.txt";
       }
   
       private void copyArtifact( Artifact artifact, File artifactTarget, Reporter reporter
)
           throws IOException
       {
           File artifactSource = artifact.getFile();
  -        
  +
           InputStream inStream = null;
           OutputStream outStream = null;
           try
  
  
  
  1.5       +34 -13    maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/java/org/apache/maven/tools/repoclean/Main.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Main.java	1 Apr 2005 02:45:05 -0000	1.4
  +++ Main.java	6 Apr 2005 20:15:07 -0000	1.5
  @@ -101,6 +101,14 @@
           config.setReportsPath( props.getProperty( "reportsPath" ) );
           config.setReportOnly( Boolean.valueOf( props.getProperty( "reportOnly" ) ).booleanValue()
);
   
  +        config.setMailErrorReport( Boolean.valueOf( props.getProperty( "errorReport.mailOnError",
"false") ).booleanValue() );
  +        config.setErrorReportFromAddress( props.getProperty( "errorReport.fromAddress"
) );
  +        config.setErrorReportFromName( props.getProperty( "errorReport.fromName" ) );
  +        config.setErrorReportSmtpHost( props.getProperty( "errorReport.smtpHost", "localhost"
) );
  +        config.setErrorReportSubject( props.getProperty( "errorReport.subject" ) );
  +        config.setErrorReportToAddress( props.getProperty( "errorReport.toAddress" ) );
  +        config.setErrorReportToName( props.getProperty( "errorReport.toName" ) );
  +
           return config;
       }
   
  @@ -108,26 +116,39 @@
       {
           System.out.println( "repoclean: Repository Cleaner/Converter.\n\n"
               + "Usage: repoclean -h|-template|<configuration-properties-file>\n\n"
  -            + "Where the configuration properfies file can contain the following options:\n"
               + "---------------------------------------------------------------------------\n"
  -            + "sourceRepositoryPath=/path/to/repository/root #[REQUIRED]\n"
  -            + "sourceRepositoryLayout=[legacy|default] #[DEFAULT: legacy]\n" + "sourcePomType=[v3|v4]
#[DEFAULT: v3]\n"
  -            + "targetRepositoryPath=/path/to/repository/root #[REQUIRED]\n"
  -            + "targetRepositoryLayout=[legacy|default] #[DEFAULT: default]\n"
  -            + "reportsPath=/path/to/reports/directory #[REQUIRED]\n" + "reportOnly=[true|false]
#[REQUIRED]\n" + "\n" );
  +            + "  Use the '-template' option to see sample configuration file options.\n"
  +            + "\n" );
       }
   
       private static void printTemplate()
       {
           System.out.println( "# ---------------------------------------------------------------------------\n"
  -            + "# repoclean: Repository Cleaner/Converter.\n" + "# This configuration auto-generated
on: "
  -            + new java.util.Date() + "\n"
  +            + "# repoclean: Repository Cleaner/Converter.\n" 
  +            + "# This configuration auto-generated on: " + new java.util.Date() + "\n"
               + "# ---------------------------------------------------------------------------\n\n"
  -            + "# [REQUIRED OPTIONS]\n" + "sourceRepositoryPath=/path/to/repository/root\n"
  -            + "targetRepositoryPath=/path/to/repository/root\n" + "reportsPath=/path/to/reports/directory\n"
  -            + "reportOnly=[true|false]\n\n" + "# [DEFAULT VALUE: legacy]\n"
  -            + "#sourceRepositoryLayout=[legacy|default]\n\n" + "# [DEFAULT VALUE: v3]\n"
+ "#sourcePomType=[v3|v4]\n\n"
  -            + "# [DEFAULT VALUE: default]\n" + "#targetRepositoryLayout=[legacy|default]\n"
+ "\n" );
  +            + "# [REQUIRED OPTIONS]\n" 
  +            + "sourceRepositoryPath=/path/to/repository/root\n"
  +            + "targetRepositoryPath=/path/to/repository/root\n" 
  +            + "reportsPath=/path/to/reports/directory\n"
  +            + "reportOnly=[true|false]\n"
  +            + "\n" 
  +            + "errorReport.mailOnError=[true|false]\n"
  +            + "errorReport.fromAddress=admin@somewhere.com\n"
  +            + "errorReport.fromName=Admin\n"
  +            + "errorReport.subject=[REPOCLEAN] Error!\n"
  +            + "errorReport.toAddress=dev@somewhere.com\n"
  +            + "errorReport.toName=Developers List\n"
  +            + "\n"
  +            + "# [DEFAULT VALUE: legacy]\n"
  +            + "#sourceRepositoryLayout=[legacy|default]\n\n" 
  +            + "# [DEFAULT VALUE: v3]\n" 
  +            + "#sourcePomType=[v3|v4]\n\n"
  +            + "# [DEFAULT VALUE: default]\n" 
  +            + "#targetRepositoryLayout=[legacy|default]\n" 
  +            + "# [DEFAULT VALUE: localhost]\n"
  +            + "#errorReport.smtpHost=<hostname>\n"
  +            + "\n" );
       }
   
       private static void printUsage()
  
  
  
  1.5       +10 -8     maven-components/sandbox/repoclean/install.sh
  
  Index: install.sh
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/install.sh,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- install.sh	1 Apr 2005 00:32:07 -0000	1.4
  +++ install.sh	6 Apr 2005 20:15:07 -0000	1.5
  @@ -37,14 +37,16 @@
       echo ""
       
       cp -f target/repoclean-1.0-SNAPSHOT.jar $1/lib
  -    cp -f $2/plexus/jars/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar $1/lib
  -    cp -f $2/plexus/jars/plexus-utils-1.0-alpha-2-SNAPSHOT.jar $1/lib
  -    cp -f $2/classworlds/jars/classworlds-1.1-alpha-1.jar $1/lib
  -    cp -f $2/org.apache.maven/jars/maven-artifact-2.0-SNAPSHOT.jar $1/lib
  -    cp -f $2/org.apache.maven/jars/maven-model-2.0-SNAPSHOT.jar $1/lib
  -    cp -f $2/maven/jars/wagon-provider-api-1.0-alpha-2-SNAPSHOT.jar $1/lib
  -    cp -f $2/maven/jars/wagon-file-1.0-alpha-2-SNAPSHOT.jar $1/lib
  -    cp -f $2/maven/jars/wagon-http-lightweight-1.0-alpha-2-SNAPSHOT.jar $1/lib
  +    cp -f $2/plexus/plexus-container-default/1.0-alpha-2/plexus-container-default-1.0-alpha-2.jar
$1/lib
  +    cp -f $2/plexus/plexus-utils/1.0-alpha-2/plexus-utils-1.0-alpha-2.jar $1/lib
  +    cp -f $2/plexus/plexus-mail-sender-api/1.0-alpha-1-SNAPSHOT/plexus-mail-sender-api-1.0-alpha-1-SNAPSHOT.jar
$1/lib
  +    cp -f $2/plexus/plexus-mail-sender-simple/1.0-alpha-1-SNAPSHOT/plexus-mail-sender-simple-1.0-alpha-1-SNAPSHOT.jar
$1/lib
  +    cp -f $2/classworlds/classworlds/1.1-alpha-1/classworlds-1.1-alpha-1.jar $1/lib
  +    cp -f $2/org/apache/maven/maven-artifact/2.0-SNAPSHOT/maven-artifact-2.0-SNAPSHOT.jar
$1/lib
  +    cp -f $2/org/apache/maven/maven-model/2.0-SNAPSHOT/maven-model-2.0-SNAPSHOT.jar $1/lib
  +    cp -f $2/org/apache/maven/wagon/wagon-provider-api/1.0-alpha-2/wagon-provider-api-1.0-alpha-2.jar
$1/lib
  +    cp -f $2/org/apache/maven/wagon/wagon-file/1.0-alpha-2/wagon-file-1.0-alpha-2.jar $1/lib
  +    cp -f $2/org/apache/maven/wagon/wagon-http-lightweight/1.0-alpha-2/wagon-http-lightweight-1.0-alpha-2.jar
$1/lib
   
       echo "Copying startup script, and changing its permissions to '+x'..."
       echo ""
  
  
  
  1.6       +7 -5      maven-components/sandbox/repoclean/src/main/bash/repoclean.sh
  
  Index: repoclean.sh
  ===================================================================
  RCS file: /home/cvs/maven-components/sandbox/repoclean/src/main/bash/repoclean.sh,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- repoclean.sh	2 Apr 2005 02:17:19 -0000	1.5
  +++ repoclean.sh	6 Apr 2005 20:15:07 -0000	1.6
  @@ -1,14 +1,16 @@
   #!/bin/bash
   
   CP=./lib/repoclean-1.0-SNAPSHOT.jar
  -CP=$CP:./lib/plexus-container-default-1.0-alpha-2-SNAPSHOT.jar
  -CP=$CP:./lib/plexus-utils-1.0-alpha-2-SNAPSHOT.jar
  +CP=$CP:./lib/plexus-container-default-1.0-alpha-2.jar
  +CP=$CP:./lib/plexus-utils-1.0-alpha-2.jar
  +CP=$CP:./lib/plexus-mail-sender-api-1.0-alpha-1-SNAPSHOT.jar
  +CP=$CP:./lib/plexus-mail-sender-simple-1.0-alpha-1-SNAPSHOT.jar
   CP=$CP:./lib/classworlds-1.1-alpha-1.jar
   CP=$CP:./lib/maven-artifact-2.0-SNAPSHOT.jar
   CP=$CP:./lib/maven-model-2.0-SNAPSHOT.jar
  -CP=$CP:./lib/wagon-provider-api-1.0-alpha-2-SNAPSHOT.jar
  -CP=$CP:./lib/wagon-file-1.0-alpha-2-SNAPSHOT.jar
  -CP=$CP:./lib/wagon-http-lightweight-1.0-alpha-2-SNAPSHOT.jar
  +CP=$CP:./lib/wagon-provider-api-1.0-alpha-2.jar
  +CP=$CP:./lib/wagon-file-1.0-alpha-2.jar
  +CP=$CP:./lib/wagon-http-lightweight-1.0-alpha-2.jar
   
   cygwin=false
   case "`uname`" in
  
  
  

Mime
View raw message