diff options
author | Brett Porter <brett@apache.org> | 2008-04-08 01:24:10 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2008-04-08 01:24:10 +0000 |
commit | fa4aa397259b5e9a4037c71bdc490d7fb97ec529 (patch) | |
tree | aab81e27d38dade947ae0dd252492116c92f5f09 | |
parent | d346a91845de094c333c60cda17592038c44729d (diff) | |
download | archiva-fa4aa397259b5e9a4037c71bdc490d7fb97ec529.tar.gz archiva-fa4aa397259b5e9a4037c71bdc490d7fb97ec529.zip |
a couple of workarounds to force "offline" behaviour
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@645751 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 79 insertions, 30 deletions
diff --git a/archiva-cli/pom.xml b/archiva-cli/pom.xml index f2101ed79..ed18c9112 100644 --- a/archiva-cli/pom.xml +++ b/archiva-cli/pom.xml @@ -48,6 +48,11 @@ <artifactId>archiva-converter</artifactId> </dependency> <dependency> + <groupId>org.apache.maven.wagon</groupId> + <artifactId>wagon-file</artifactId> + <version>1.0-beta-2</version> + </dependency> + <dependency> <groupId>com.google.code.cli-parser</groupId> <artifactId>cli</artifactId> <version>7</version> diff --git a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java index c2e98049e..4462dbcb2 100644 --- a/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java +++ b/archiva-cli/src/main/java/org/apache/maven/archiva/cli/ArchivaCli.java @@ -19,8 +19,19 @@ package org.apache.maven.archiva.cli; * under the License. */ +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Properties; + import org.apache.commons.lang.StringUtils; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer; @@ -31,26 +42,13 @@ import org.apache.maven.archiva.converter.legacy.LegacyRepositoryConverter; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.scanner.RepositoryScanStatistics; import org.apache.maven.archiva.repository.scanner.RepositoryScanner; +import org.apache.maven.artifact.manager.WagonManager; import org.codehaus.plexus.spring.PlexusClassPathXmlApplicationContext; import org.codehaus.plexus.spring.PlexusToSpringUtils; import com.sampullara.cli.Args; import com.sampullara.cli.Argument; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; - /** * ArchivaCli * @@ -144,8 +142,14 @@ public class ArchivaCli } private void doScan( String path, String[] consumers ) - throws ConsumerException + throws ConsumerException, MalformedURLException { + // hack around poorly configurable project builder by pointing all repositories back at this location to be self + // contained + WagonManager wagonManager = + (WagonManager) applicationContext.getBean( PlexusToSpringUtils.buildSpringId( WagonManager.class.getName() ) ); + wagonManager.addMirror( "internal", "*", new File( path ).toURL().toExternalForm() ); + ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration(); repo.setId( "cliRepo" ); repo.setName( "Archiva CLI Provided Repo" ); @@ -218,7 +222,7 @@ public class ArchivaCli } } - @SuppressWarnings("unchecked") + @SuppressWarnings( "unchecked" ) private Map<String, KnownRepositoryContentConsumer> getConsumers() { return PlexusToSpringUtils.lookupMap( "knownRepositoryContentConsumer", applicationContext ); diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-dependency-tree-consumer/src/main/java/org/apache/archiva/consumers/dependencytree/DependencyTreeGeneratorConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-dependency-tree-consumer/src/main/java/org/apache/archiva/consumers/dependencytree/DependencyTreeGeneratorConsumer.java index 2d7537668..f748cb36d 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-dependency-tree-consumer/src/main/java/org/apache/archiva/consumers/dependencytree/DependencyTreeGeneratorConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-dependency-tree-consumer/src/main/java/org/apache/archiva/consumers/dependencytree/DependencyTreeGeneratorConsumer.java @@ -22,8 +22,10 @@ package org.apache.archiva.consumers.dependencytree; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.lang.reflect.Field; import java.net.MalformedURLException; import java.util.Collections; +import java.util.HashMap; import java.util.List; import org.apache.commons.io.IOUtils; @@ -39,6 +41,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactCollector; 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; @@ -92,6 +95,14 @@ public class DependencyTreeGeneratorConsumer private String repositoryLocation; + private final DefaultRepositoryLayout layout = new DefaultRepositoryLayout(); + + private ArtifactRepository localArtifactRepository; + + private Field rawProjectCacheField; + + private Field processedProjectCacheField; + public String getDescription() { return "Generate dependency tree metadata for tracking changes across algorithms"; @@ -127,6 +138,17 @@ public class DependencyTreeGeneratorConsumer // This is a bit crappy, it would be better to operate entirely within // the base repository, but would need to adjust maven-artifact localRepository = new File( System.getProperty( "user.home" ), ".m2/repository" ); + try + { + localArtifactRepository = + artifactRepositoryFactory.createArtifactRepository( "local", + localRepository.toURL().toExternalForm(), + layout, null, null ); + } + catch ( MalformedURLException e ) + { + throw new ConsumerException( e.getMessage(), e ); + } } } @@ -147,27 +169,18 @@ public class DependencyTreeGeneratorConsumer public void processFile( String path ) throws ConsumerException { - DefaultRepositoryLayout layout = new DefaultRepositoryLayout(); - - ArtifactRepository localRepository; MavenProject project; try { - localRepository = - artifactRepositoryFactory.createArtifactRepository( "local", - this.localRepository.toURL().toExternalForm(), - layout, null, null ); + project = projectBuilder.build( new File( repositoryLocation, path ), localArtifactRepository, null, false ); - project = projectBuilder.build( new File( repositoryLocation, path ), localRepository, null, false ); + // manually flush out the cache for memory concerns and more accurate building + flushProjectCache( projectBuilder ); } catch ( ProjectBuildingException e ) { throw new ConsumerException( e.getMessage(), e ); } - catch ( MalformedURLException e ) - { - throw new ConsumerException( e.getMessage(), e ); - } DependencyNode rootNode; try @@ -176,7 +189,7 @@ public class DependencyTreeGeneratorConsumer ArtifactFilter artifactFilter = null; rootNode = - dependencyTreeBuilder.buildDependencyTree( project, localRepository, artifactFactory, + dependencyTreeBuilder.buildDependencyTree( project, localArtifactRepository, artifactFactory, artifactMetadataSource, artifactFilter, artifactCollector ); } catch ( DependencyTreeBuilderException e ) @@ -224,6 +237,33 @@ public class DependencyTreeGeneratorConsumer } } + private void flushProjectCache( MavenProjectBuilder projectBuilder ) + { + try + { + if ( rawProjectCacheField == null ) + { + rawProjectCacheField = DefaultMavenProjectBuilder.class.getDeclaredField( "rawProjectCache" ); + rawProjectCacheField.setAccessible( true ); + } + + if ( processedProjectCacheField == null ) + { + processedProjectCacheField = + DefaultMavenProjectBuilder.class.getDeclaredField( "processedProjectCache" ); + processedProjectCacheField.setAccessible( true ); + } + + rawProjectCacheField.set( projectBuilder, new HashMap() ); + + processedProjectCacheField.set( projectBuilder, new HashMap() ); + } + catch ( Exception e ) + { + throw new RuntimeException( e ); + } + } + private static class XmlSerializingDependencyNodeVisitor implements DependencyNodeVisitor { |