maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r470148 - in /maven/sandbox/maven-repository-builder: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/maven/ src/main/java/org/apache/maven/shared/ src/main/java/org/apache/maven/shared...
Date Thu, 02 Nov 2006 00:48:01 GMT
Author: jdcasey
Date: Wed Nov  1 16:47:57 2006
New Revision: 470148

URL: http://svn.apache.org/viewvc?view=rev&rev=470148
Log:
Splitting out the repository-building components from the assembly plugin for use in a plugin-IT
project, among other things.

Added:
    maven/sandbox/maven-repository-builder/
    maven/sandbox/maven-repository-builder/pom.xml   (with props)
    maven/sandbox/maven-repository-builder/src/
    maven/sandbox/maven-repository-builder/src/main/
    maven/sandbox/maven-repository-builder/src/main/java/
    maven/sandbox/maven-repository-builder/src/main/java/org/
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/DefaultRepositoryAssembler.java
  (with props)
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssembler.java
  (with props)
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssemblyException.java
  (with props)
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryBuilderConfigSource.java
  (with props)
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/DefaultRepositoryInfo.java
  (with props)
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/GroupVersionAlignment.java
  (with props)
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/RepositoryInfo.java
  (with props)
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/utils/
    maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/utils/DigestUtils.java
  (with props)
    maven/sandbox/maven-repository-builder/src/test/
    maven/sandbox/maven-repository-builder/src/test/java/

Added: maven/sandbox/maven-repository-builder/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-repository-builder/pom.xml?view=auto&rev=470148
==============================================================================
--- maven/sandbox/maven-repository-builder/pom.xml (added)
+++ maven/sandbox/maven-repository-builder/pom.xml Wed Nov  1 16:47:57 2006
@@ -0,0 +1,93 @@
+<?xml version="1.0"?>
+
+<!--
+  ~ Copyright 2006 The Apache Software Foundation.
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.maven.shared</groupId>
+    <artifactId>maven-shared-components</artifactId>
+    <version>4-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>maven-repository-builder</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  
+  <name>Maven Repository Builder</name>
+  <url>http://maven.apache.org</url>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.0.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact-manager</artifactId>
+      <version>2.0.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0.3</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-common-artifact-filters</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-test-tools</artifactId>
+      <version>1.0-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <version>1.2_Java1.3</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-maven-plugin</artifactId>
+        <version>1.3</version>
+        <executions>
+          <execution>
+            <id>create-component-descriptor</id>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  
+</project>

Propchange: maven/sandbox/maven-repository-builder/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/DefaultRepositoryAssembler.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/DefaultRepositoryAssembler.java?view=auto&rev=470148
==============================================================================
--- maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/DefaultRepositoryAssembler.java
(added)
+++ maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/DefaultRepositoryAssembler.java
Wed Nov  1 16:47:57 2006
@@ -0,0 +1,508 @@
+package org.apache.maven.shared.repository;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+import org.apache.maven.artifact.repository.metadata.Versioning;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+import org.apache.maven.project.DefaultMavenProjectBuilder;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.shared.repository.model.GroupVersionAlignment;
+import org.apache.maven.shared.repository.model.RepositoryInfo;
+import org.apache.maven.shared.repository.utils.DigestUtils;
+import org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter;
+import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter;
+import org.apache.maven.shared.artifact.filter.ScopeArtifactFilter;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.lang.reflect.Field;
+import java.security.NoSuchAlgorithmException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TimeZone;
+
+/**
+ * @author Jason van Zyl
+ * @plexus.component role="org.apache.maven.shared.repository.RepositoryAssembler" role-hint="default"
+ */
+
+// todo will need to pop the processed project cache using reflection
+public class DefaultRepositoryAssembler
+    extends AbstractLogEnabled
+    implements RepositoryAssembler
+{
+    protected static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
+
+    protected static final String UTC_TIMESTAMP_PATTERN = "yyyyMMddHHmmss";
+
+    /**
+     * @plexus.requirement
+     */
+    protected ArtifactFactory artifactFactory;
+
+    /**
+     * @plexus.requirement
+     */
+    protected ArtifactResolver artifactResolver;
+
+    /**
+     * @plexus.requirement
+     */
+    protected ArtifactRepositoryLayout repositoryLayout;
+
+    /**
+     * @plexus.requirement
+     */
+    protected ArtifactRepositoryFactory artifactRepositoryFactory;
+
+    /**
+     * @plexus.requirement
+     */
+    protected ArtifactMetadataSource metadataSource;
+
+    /**
+     * @plexus.requirement
+     */
+    protected MavenProjectBuilder projectBuilder;
+
+    public void buildRemoteRepository( File repositoryDirectory, RepositoryInfo repository,
RepositoryBuilderConfigSource configSource )
+        throws RepositoryAssemblyException
+    {
+        MavenProject project = configSource.getProject();
+        ArtifactRepository localRepository = configSource.getLocalRepository();
+
+        Map groupVersionAlignments = createGroupVersionAlignments( repository.getGroupVersionAlignments()
);
+
+        ArtifactRepository targetRepository = createLocalRepository( repositoryDirectory
);
+
+        ArtifactResolutionResult result = null;
+        
+        Set dependencyArtifacts = project.getDependencyArtifacts();
+        
+        if ( dependencyArtifacts == null )
+        {
+            Logger logger = getLogger();
+            
+            if ( logger.isDebugEnabled() )
+            {
+                logger.debug( "dependency-artifact set for project: " + project.getId() +
" is null. Skipping repository processing." );
+            }
+            
+            return;
+        }
+        
+        try
+        {
+            // i have to get everything first as a filter or transformation here
+            // doesn't seem to work
+            // to align everything. If I use a filter to change the version on
+            // the fly then I get the
+            // I get JARs but no POMs, and in some directories POMs with no
+            // JARs.
+
+            // FIXME I'm not getting runtime dependencies here
+            result = artifactResolver.resolveTransitively( dependencyArtifacts, project.getArtifact(),
+                project.getRemoteArtifactRepositories(), localRepository, metadataSource
);
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new RepositoryAssemblyException( "Error resolving artifacts: " + e.getMessage(),
e );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            throw new RepositoryAssemblyException( "Error resolving artifacts: " + e.getMessage(),
e );
+        }
+
+        try
+        {
+            // Blow the cache in the project builder so that we get POMs again
+            // on this next download
+            invalidateProccessedProjectCache();
+        }
+        catch ( Exception e )
+        {
+            throw new RepositoryAssemblyException( "Error invalidating the processed project
cache.", e );
+        }
+        
+        ArtifactFilter filter = buildRepositoryFilter( repository, project);
+
+        assembleRepositoryArtifacts( result, filter, project, localRepository, targetRepository,
repositoryDirectory, groupVersionAlignments );
+        
+        ArtifactRepository centralRepository = findCentralRepository( project );
+
+        if ( repository.isIncludeMetadata() )
+        {
+            assembleRepositoryMetadata( result, filter, centralRepository, targetRepository
);
+        }
+    }
+
+    private ArtifactFilter buildRepositoryFilter(RepositoryInfo repository, MavenProject
project)
+    {
+        AndArtifactFilter filter = new AndArtifactFilter();
+
+        ArtifactFilter scopeFilter = new ScopeArtifactFilter( repository.getScope() );
+        filter.add( scopeFilter );
+
+        // ----------------------------------------------------------------------------
+        // Includes
+        //
+        // We'll take everything if no includes are specified to try and make
+        // this
+        // process more maintainable. Don't want to have to update the assembly
+        // descriptor everytime the POM is updated.
+        // ----------------------------------------------------------------------------
+
+        if ( repository.getIncludes().isEmpty() )
+        {
+            List patterns = new ArrayList();
+
+            Set projectArtifacts = project.getDependencyArtifacts();
+
+            if ( projectArtifacts != null )
+            {
+                for ( Iterator it = projectArtifacts.iterator(); it.hasNext(); )
+                {
+                    Artifact artifact = (Artifact) it.next();
+
+                    patterns.add( artifact.getDependencyConflictId() );
+                }
+            }
+
+            PatternIncludesArtifactFilter includeFilter = new PatternIncludesArtifactFilter(
patterns, true );
+
+            filter.add( includeFilter );
+        }
+        else
+        {
+            filter.add( new PatternIncludesArtifactFilter( repository.getIncludes(), true
) );
+        }
+
+        // ----------------------------------------------------------------------------
+        // Excludes
+        //
+        // We still want to make it easy to exclude a few things even if we
+        // slurp
+        // up everything.
+        // ----------------------------------------------------------------------------
+
+        if ( !repository.getExcludes().isEmpty() )
+        {
+            filter.add( new PatternExcludesArtifactFilter( repository.getExcludes(), true
) );
+        }
+
+        return filter;
+    }
+
+    private void assembleRepositoryArtifacts( ArtifactResolutionResult result, ArtifactFilter
filter,
+                                              MavenProject project, ArtifactRepository localRepository,
+                                              ArtifactRepository targetRepository, File repositoryDirectory,
Map groupVersionAlignments )
+        throws RepositoryAssemblyException
+    {
+        try
+        {
+            // Now that we have the graph, let's try to align it to versions
+            // that we want and remove
+            // the repository we previously populated.
+            FileUtils.deleteDirectory( repositoryDirectory );
+
+            FileUtils.mkdir( repositoryDirectory.getAbsolutePath() );
+
+            for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
+            {
+                Artifact a = (Artifact) i.next();
+
+                if ( filter.include( a ) )
+                {
+                    setAlignment( a, groupVersionAlignments );
+
+                    // We need to flip it back to not being resolved so we can
+                    // look for it again!
+                    a.setResolved( false );
+
+                    artifactResolver.resolve( a, project.getRemoteArtifactRepositories(),
localRepository );
+
+                    File targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf(
a ) );
+                    FileUtils.copyFile( a.getFile(), targetFile );
+
+                    writeChecksums( targetFile );
+
+                    if ( !"pom".equals( a.getType() ) )
+                    {
+                        a = artifactFactory.createProjectArtifact( a.getGroupId(), a.getArtifactId(),
a.getVersion() );
+
+                        MavenProject p = projectBuilder.buildFromRepository( a,
+                            project.getRemoteArtifactRepositories(), localRepository );
+
+                        do
+                        {
+                            a = artifactFactory.createProjectArtifact( p.getGroupId(), p.getArtifactId(),
p
+                                .getVersion() );
+
+                            setAlignment( a, groupVersionAlignments );
+
+                            File sourceFile = new File( localRepository.getBasedir(), localRepository.pathOf(
a ) );
+
+                            if ( !sourceFile.exists() )
+                            {
+                                break;
+                            }
+
+                            targetFile = new File( targetRepository.getBasedir(), targetRepository.pathOf(
a ) );
+
+                            FileUtils.copyFile( sourceFile, targetFile );
+
+                            writeChecksums( targetFile );
+
+                            p = p.getParent();
+                        } while ( p != null );
+                    }
+                }
+            }
+        }
+        catch ( ArtifactResolutionException e )
+        {
+            throw new RepositoryAssemblyException( "Error resolving artifacts: " + e.getMessage(),
e );
+        }
+        catch ( ArtifactNotFoundException e )
+        {
+            throw new RepositoryAssemblyException( "Error resolving artifacts: " + e.getMessage(),
e );
+        }
+        catch ( IOException e )
+        {
+            throw new RepositoryAssemblyException( "Error writing artifact metdata.", e );
+        }
+        catch ( ProjectBuildingException e )
+        {
+            throw new RepositoryAssemblyException( "Error reading POM.", e );
+        }
+    }
+
+    private ArtifactRepository findCentralRepository( MavenProject project )
+    {
+        ArtifactRepository centralRepository = null;
+        for ( Iterator i = project.getRemoteArtifactRepositories().iterator(); i.hasNext();
)
+        {
+            ArtifactRepository r = (ArtifactRepository) i.next();
+            if ( "central".equals( r.getId() ) )
+            {
+                centralRepository = r;
+            }
+        }
+
+        return centralRepository;
+    }
+
+    private void assembleRepositoryMetadata( ArtifactResolutionResult result, ArtifactFilter
filter,
+                                             ArtifactRepository centralRepository, ArtifactRepository
targetRepository )
+        throws RepositoryAssemblyException
+    {
+        for ( Iterator i = result.getArtifacts().iterator(); i.hasNext(); )
+        {
+            Artifact a = (Artifact) i.next();
+
+            if ( filter.include( a ) )
+            {
+                Versioning v = new Versioning();
+
+                v.setRelease( a.getVersion() );
+
+                v.setLatest( a.getVersion() );
+
+                v.addVersion( a.getVersion() );
+
+                v.setLastUpdated( getUtcDateFormatter().format( new Date() ) );
+
+                ArtifactRepositoryMetadata metadata = new ArtifactRepositoryMetadata( a,
v );
+                String path = targetRepository.pathOfLocalRepositoryMetadata( metadata, centralRepository
);
+                File metadataFile = new File( targetRepository.getBasedir(), path );
+
+                MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer();
+
+                Writer writer = null;
+                try
+                {
+                    writer = new FileWriter( metadataFile );
+
+                    metadataWriter.write( writer, metadata.getMetadata() );
+                }
+                catch ( IOException e )
+                {
+                    throw new RepositoryAssemblyException( "Error writing artifact metdata.",
e );
+                }
+                finally
+                {
+                    IOUtil.close( writer );
+                }
+
+                try
+                {
+                    writeChecksums( metadataFile );
+
+                    File metadataFileRemote = new File( targetRepository.getBasedir(), targetRepository
+                        .pathOfRemoteRepositoryMetadata( metadata ) );
+
+                    FileUtils.copyFile( metadataFile, metadataFileRemote );
+
+                    FileUtils.copyFile( new File( metadataFile.getParentFile(), metadataFile.getName()
+ ".sha1" ),
+                        new File( metadataFileRemote.getParentFile(), metadataFileRemote.getName()
+ ".sha1" ) );
+
+                    FileUtils.copyFile( new File( metadataFile.getParentFile(), metadataFile.getName()
+ ".md5" ),
+                        new File( metadataFileRemote.getParentFile(), metadataFileRemote.getName()
+ ".md5" ) );
+                }
+                catch ( IOException e )
+                {
+                    throw new RepositoryAssemblyException( "Error writing artifact metdata.",
e );
+                }
+            }
+        }
+    }
+
+    private void writeChecksums( File file )
+        throws IOException, RepositoryAssemblyException
+    {
+        try
+        {
+            String md5 = DigestUtils.createChecksum( file, "MD5" );
+            String sha1 = DigestUtils.createChecksum( file, "SHA-1" );
+
+            FileUtils.fileWrite( new File( file.getParentFile(), file.getName() + ".md5"
).getAbsolutePath(), md5
+                .toLowerCase() );
+            FileUtils.fileWrite( new File( file.getParentFile(), file.getName() + ".sha1"
).getAbsolutePath(), sha1
+                .toLowerCase() );
+        }
+        catch ( NoSuchAlgorithmException e )
+        {
+            throw new RepositoryAssemblyException( "Unable to get write checksums: " + e.getMessage(),
e );
+        }
+    }
+
+    protected Map createGroupVersionAlignments( List versionAlignments )
+    {
+        Map groupVersionAlignments = new HashMap();
+
+        for ( Iterator i = versionAlignments.iterator(); i.hasNext(); )
+        {
+            GroupVersionAlignment alignment = (GroupVersionAlignment) i.next();
+
+            groupVersionAlignments.put( alignment.getId(), alignment );
+        }
+        
+        return groupVersionAlignments;
+    }
+
+    protected static DateFormat getUtcDateFormatter()
+    {
+        DateFormat utcDateFormatter = new SimpleDateFormat( UTC_TIMESTAMP_PATTERN );
+        utcDateFormatter.setTimeZone( UTC_TIME_ZONE );
+        return utcDateFormatter;
+    }
+
+    protected ArtifactRepository createLocalRepository( File directory )
+    {
+        String localRepositoryUrl = directory.getAbsolutePath();
+
+        if ( !localRepositoryUrl.startsWith( "file:" ) )
+        {
+            localRepositoryUrl = "file://" + localRepositoryUrl;
+        }
+
+        return createRepository( "local", localRepositoryUrl, false, true,
+            ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
+    }
+
+    public ArtifactRepository createRepository( String repositoryId, String repositoryUrl,
boolean offline,
+                                                boolean updateSnapshots, String globalChecksumPolicy
)
+    {
+        ArtifactRepository localRepository = new DefaultArtifactRepository( repositoryId,
repositoryUrl,
+            repositoryLayout );
+
+        boolean snapshotPolicySet = false;
+
+        if ( offline )
+        {
+            snapshotPolicySet = true;
+        }
+
+        if ( !snapshotPolicySet && updateSnapshots )
+        {
+            artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS
);
+        }
+
+        artifactRepositoryFactory.setGlobalChecksumPolicy( globalChecksumPolicy );
+
+        return localRepository;
+    }
+
+    private void invalidateProccessedProjectCache()
+        throws Exception
+    {
+        Class klass = DefaultMavenProjectBuilder.class;
+
+        Field field = klass.getDeclaredField( "processedProjectCache" );
+
+        field.setAccessible( true );
+
+        Object cache = field.get( projectBuilder );
+
+        cache.getClass().getDeclaredMethod( "clear", null ).invoke( cache, null );
+
+        field.setAccessible( false );
+    }
+
+    private void setAlignment( Artifact artifact, Map groupVersionAlignments )
+    {
+        GroupVersionAlignment alignment = (GroupVersionAlignment) groupVersionAlignments.get(
artifact.getGroupId() );
+
+        if ( alignment != null )
+        {
+            if ( !alignment.getExcludes().contains( artifact.getArtifactId() ) )
+            {
+                artifact.setVersion( alignment.getVersion() );
+            }
+        }
+    }
+}

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/DefaultRepositoryAssembler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/DefaultRepositoryAssembler.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/DefaultRepositoryAssembler.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssembler.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssembler.java?view=auto&rev=470148
==============================================================================
--- maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssembler.java
(added)
+++ maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssembler.java
Wed Nov  1 16:47:57 2006
@@ -0,0 +1,32 @@
+package org.apache.maven.shared.repository;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.shared.repository.model.RepositoryInfo;
+
+import java.io.File;
+
+/**
+ * @author Jason van Zyl
+ */
+public interface RepositoryAssembler
+{
+    String ROLE = RepositoryAssembler.class.getName();
+
+    public void buildRemoteRepository( File repositoryDirectory, RepositoryInfo repository,
RepositoryBuilderConfigSource configSource )
+        throws RepositoryAssemblyException;
+}

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssembler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssembler.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssembler.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssemblyException.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssemblyException.java?view=auto&rev=470148
==============================================================================
--- maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssemblyException.java
(added)
+++ maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssemblyException.java
Wed Nov  1 16:47:57 2006
@@ -0,0 +1,41 @@
+package org.apache.maven.shared.repository;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @author Jason van Zyl
+ */
+public class RepositoryAssemblyException
+    extends Exception
+{
+    private static final long serialVersionUID = 1L;
+
+    public RepositoryAssemblyException( String string )
+    {
+        super( string );
+    }
+
+    public RepositoryAssemblyException( String string, Throwable throwable )
+    {
+        super( string, throwable );
+    }
+
+    public RepositoryAssemblyException( Throwable throwable )
+    {
+        super( throwable );
+    }
+}

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssemblyException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssemblyException.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryAssemblyException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryBuilderConfigSource.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryBuilderConfigSource.java?view=auto&rev=470148
==============================================================================
--- maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryBuilderConfigSource.java
(added)
+++ maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryBuilderConfigSource.java
Wed Nov  1 16:47:57 2006
@@ -0,0 +1,13 @@
+package org.apache.maven.shared.repository;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.project.MavenProject;
+
+public interface RepositoryBuilderConfigSource
+{
+    
+    MavenProject getProject();
+    
+    ArtifactRepository getLocalRepository();
+
+}

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryBuilderConfigSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/RepositoryBuilderConfigSource.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/DefaultRepositoryInfo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/DefaultRepositoryInfo.java?view=auto&rev=470148
==============================================================================
--- maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/DefaultRepositoryInfo.java
(added)
+++ maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/DefaultRepositoryInfo.java
Wed Nov  1 16:47:57 2006
@@ -0,0 +1,65 @@
+package org.apache.maven.shared.repository.model;
+
+import java.util.List;
+
+public class DefaultRepositoryInfo
+    implements RepositoryInfo
+{
+
+    private boolean includeMetadata;
+    private String scope;
+    private List includes;
+    private List groupVersionAlignments;
+    private List excludes;
+
+    public List getExcludes()
+    {
+        return excludes;
+    }
+
+    public void setGroupVersionAlignments( List groupVersionAlignments )
+    {
+        this.groupVersionAlignments = groupVersionAlignments;
+    }
+
+    public void setIncludeMetadata( boolean includeMetadata )
+    {
+        this.includeMetadata = includeMetadata;
+    }
+
+    public void setIncludes( List includes )
+    {
+        this.includes = includes;
+    }
+
+    public void setScope( String scope )
+    {
+        this.scope = scope;
+    }
+
+    public List getGroupVersionAlignments()
+    {
+        return groupVersionAlignments;
+    }
+
+    public List getIncludes()
+    {
+        return includes;
+    }
+
+    public String getScope()
+    {
+        return scope;
+    }
+
+    public boolean isIncludeMetadata()
+    {
+        return includeMetadata;
+    }
+
+    public void setExcludes( List excludes )
+    {
+        this.excludes = excludes;
+    }
+
+}

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/DefaultRepositoryInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/DefaultRepositoryInfo.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/GroupVersionAlignment.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/GroupVersionAlignment.java?view=auto&rev=470148
==============================================================================
--- maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/GroupVersionAlignment.java
(added)
+++ maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/GroupVersionAlignment.java
Wed Nov  1 16:47:57 2006
@@ -0,0 +1,14 @@
+package org.apache.maven.shared.repository.model;
+
+import java.util.List;
+
+public interface GroupVersionAlignment
+{
+
+    String getId();
+
+    List getExcludes();
+
+    String getVersion();
+
+}

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/GroupVersionAlignment.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/GroupVersionAlignment.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/RepositoryInfo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/RepositoryInfo.java?view=auto&rev=470148
==============================================================================
--- maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/RepositoryInfo.java
(added)
+++ maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/RepositoryInfo.java
Wed Nov  1 16:47:57 2006
@@ -0,0 +1,18 @@
+package org.apache.maven.shared.repository.model;
+
+import java.util.List;
+
+public interface RepositoryInfo
+{
+    
+    List getGroupVersionAlignments();
+    
+    boolean isIncludeMetadata();
+    
+    String getScope();
+
+    List getIncludes();
+
+    List getExcludes();
+
+}

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/RepositoryInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/model/RepositoryInfo.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/utils/DigestUtils.java
URL: http://svn.apache.org/viewvc/maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/utils/DigestUtils.java?view=auto&rev=470148
==============================================================================
--- maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/utils/DigestUtils.java
(added)
+++ maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/utils/DigestUtils.java
Wed Nov  1 16:47:57 2006
@@ -0,0 +1,149 @@
+package org.apache.maven.shared.repository.utils;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Create a digest for a file. Stolen from repository-utils - once released, use that instead.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @todo [jdcasey] This needs unit tests.
+ */
+public final class DigestUtils
+{
+    private static final int CHECKSUM_BUFFER_SIZE = 16384;
+
+    private static final int BYTE_MASK = 0xFF;
+    
+    private DigestUtils()
+    {
+    }
+
+    public static String createChecksum( File file, String algorithm )
+        throws IOException, NoSuchAlgorithmException
+    {
+        MessageDigest digest = MessageDigest.getInstance( algorithm );
+
+        InputStream fis = new FileInputStream( file );
+        try
+        {
+            byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE];
+            int numRead;
+            do
+            {
+                numRead = fis.read( buffer );
+                if ( numRead > 0 )
+                {
+                    digest.update( buffer, 0, numRead );
+                }
+            }
+            while ( numRead != -1 );
+        }
+        finally
+        {
+            IOUtil.close( fis );
+        }
+
+        return byteArrayToHexStr( digest.digest() );
+    }
+
+    public boolean verifyChecksum( File file, String checksum, String algorithm )
+        throws NoSuchAlgorithmException, IOException
+    {
+        boolean result = true;
+
+        String trimmedChecksum = checksum.replace( '\n', ' ' ).trim();
+        // Free-BSD / openssl
+        Matcher m =
+            Pattern.compile( algorithm.replaceAll( "-", "" ) + "\\s*\\((.*?)\\)\\s*=\\s*([a-zA-Z0-9]+)"
).matcher(
+                trimmedChecksum );
+        if ( m.matches() )
+        {
+            String filename = m.group( 1 );
+            if ( !filename.equals( file.getName() ) )
+            {
+                // TODO: provide better warning
+                result = false;
+            }
+            trimmedChecksum = m.group( 2 );
+        }
+        else
+        {
+            // GNU tools
+            m = Pattern.compile( "([a-zA-Z0-9]+)\\s\\*?(.+)" ).matcher( trimmedChecksum );
+            if ( m.matches() )
+            {
+                String filename = m.group( 2 );
+                if ( !filename.equals( file.getName() ) )
+                {
+                    // TODO: provide better warning
+                    result = false;
+                }
+                trimmedChecksum = m.group( 1 );
+            }
+        }
+
+        if ( result )
+        {
+            //Create checksum for jar file
+            String sum = createChecksum( file, algorithm );
+            result = trimmedChecksum.toUpperCase().equals( sum.toUpperCase() );
+        }
+        return result;
+    }
+
+    /**
+     * Convert an incoming array of bytes into a string that represents each of
+     * the bytes as two hex characters.
+     *
+     * @param data
+     */
+    private static String byteArrayToHexStr( byte[] data )
+    {
+        String output = "";
+
+        for ( int cnt = 0; cnt < data.length; cnt++ )
+        {
+            //Deposit a byte into the 8 lsb of an int.
+            int tempInt = data[cnt] & BYTE_MASK;
+
+            //Get hex representation of the int as a string.
+            String tempStr = Integer.toHexString( tempInt );
+
+            //Append a leading 0 if necessary so that each hex string will contain 2 characters.
+            if ( tempStr.length() == 1 )
+            {
+                tempStr = "0" + tempStr;
+            }
+
+            //Concatenate the two characters to the output string.
+            output = output + tempStr;
+        }
+
+        return output.toUpperCase();
+    }
+}

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/utils/DigestUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/utils/DigestUtils.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/sandbox/maven-repository-builder/src/main/java/org/apache/maven/shared/repository/utils/DigestUtils.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"



Mime
View raw message