Permalink
Browse files

draft of a way that MNG-3989 could be handled in Maven 3.x, though th…

…ere are probably better ways

git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk@1086237 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
brettporter committed Mar 28, 2011
1 parent eb8e578 commit d5a7bb778a0df7203ca6c94d527fa58441bf7000
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>modules</artifactId>
+ <groupId>test.MNG3989</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>my-artifact</artifactId>
+ <name>my-artifact</name>
+ <dependencies>
+ <dependency>
+ <groupId>test.MNG3989</groupId>
+ <artifactId>ancient-artifact</artifactId>
+ <version>3.1.0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
@@ -0,0 +1,13 @@
+package test;
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+ public static void main( String[] args )
+ {
+ System.out.println( "Hello World! I am " + (com.example.ancient.AncientClass.isAncient ? "ancient" : "not ancient" ) );
+ }
+}
@@ -0,0 +1,38 @@
+package test;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( com.example.ancient.AncientClass.isAncient );
+ }
+}
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>MNG-3989</artifactId>
+ <groupId>test.MNG3989</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>modules</artifactId>
+ <name>modules</name>
+ <packaging>pom</packaging>
+ <modules>
+ <module>my-artifact</module>
+ </modules>
+ <build>
+ <extensions>
+ <extension>
+ <groupId>org.apache.maven.examples</groupId>
+ <artifactId>bundled-repository-extension</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </extension>
+ </extensions>
+ </build>
+</project>
@@ -0,0 +1,18 @@
+<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>
+ <groupId>test.MNG3989</groupId>
+ <artifactId>ancient-artifact</artifactId>
+ <packaging>jar</packaging>
+ <version>3.1.0.2</version>
+ <name>ancient-artifact</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>
+ <groupId>test.MNG3989</groupId>
+ <artifactId>MNG-3989</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>MNG-3989</name>
+ <packaging>pom</packaging>
+ <modules>
+ <module>modules</module>
+ </modules>
+</project>
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>MNG-3989</artifactId>
+ <groupId>test.MNG3989</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>repository</artifactId>
+ <name>repository</name>
+ <dependencies>
+ <dependency>
+ <groupId>test.MNG3989</groupId>
+ <artifactId>ancient-artifact</artifactId>
+ <version>3.1.0.2</version>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <id>local</id>
+ <url>file:${basedir}/src/repository</url>
+ </repository>
+ </repositories>
+</project>
@@ -0,0 +1,41 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.examples</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <artifactId>bundled-repository-extension</artifactId>
+ <name>bundled-repository-extension</name>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-compat</artifactId>
+ <version>3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>3.0</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-component-metadata</artifactId>
+ <version>1.5.5</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>generate-metadata</goal>
+ <goal>generate-test-metadata</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
@@ -0,0 +1,61 @@
+package org.apache.maven.examples.bundledrepository;
+
+import org.apache.maven.AbstractMavenLifecycleParticipant;
+import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.execution.RuntimeInformation;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.logging.Logger;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.List;
+import java.util.ArrayList;
+
+@Component( role = AbstractMavenLifecycleParticipant.class, hint = "bundledrepository" )
+public class BundledRepositoryMavenExtension
+ extends AbstractMavenLifecycleParticipant
+{
+ @Requirement
+ private Logger logger;
+
+ @Requirement
+ RuntimeInformation runtime;
+
+ @Requirement
+ private ArtifactRepositoryFactory factory;
+
+ public void afterProjectsRead( MavenSession session ) {
+ // Currently a dumb implementation - some searching & configuration via execution properties might help
+ // or better adding in to the resolution model with a new repository type
+
+ // Search for projects that have a repository
+ boolean found = false;
+ List<ArtifactRepository> artifactRepositories = new ArrayList<ArtifactRepository>();
+ for ( MavenProject project : session.getProjects() ) {
+ File repositoryDir = new File( project.getBasedir(), "repository" );
+ if ( repositoryDir.exists() && repositoryDir.isDirectory() ) {
+ try {
+ logger.debug( "Found repository in project " + project.getId() + " under " + repositoryDir );
+ artifactRepositories.add( factory.createArtifactRepository( "bundledrepository", repositoryDir.toURL().toExternalForm(), new DefaultRepositoryLayout(), null, null ) );
+ }
+ catch ( MalformedURLException e ) {
+ logger.error( "Ignoring bad URL: " + e.getMessage() );
+ }
+ }
+ }
+
+ // Add the repository to all projects
+ for ( MavenProject project : session.getProjects() ) {
+ List<ArtifactRepository> repos = new ArrayList<ArtifactRepository>( project.getRemoteArtifactRepositories() );
+ repos.addAll( artifactRepositories );
+ project.setRemoteArtifactRepositories( repos );
+ logger.debug( "Project " + project.getId() + " now using repositories: " + repos );
+ }
+ }
+
+}

0 comments on commit d5a7bb7

Please sign in to comment.