maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r1138204 [1/2] - in /maven/sandbox/trunk/mae: ./ mae-components/ mae-components/mae-project-tools/ mae-components/mae-project-tools/src/ mae-components/mae-project-tools/src/main/ mae-components/mae-project-tools/src/main/java/ mae-componen...
Date Tue, 21 Jun 2011 21:48:37 GMT
Author: jdcasey
Date: Tue Jun 21 21:48:35 2011
New Revision: 1138204

URL: http://svn.apache.org/viewvc?rev=1138204&view=rev
Log:
Adding project-tools from EMB, which provides some convenience wrappers around the ProjectBuilder and related components.

Added:
    maven/sandbox/trunk/mae/mae-components/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/pom.xml   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/DefaultProjectLoader.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectLoader.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectToolsException.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/lib/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/lib/ProjectToolsLibrary.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/DefaultSessionInjector.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/ProjectToolsSession.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionInjector.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionWorkspaceReader.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SimpleProjectToolsSession.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/repository/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/repository/internal/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/repository/internal/ConfigurableArtifactDescriptorReader.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/java/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/java/org/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/java/org/apache/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/java/org/apache/maven/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/java/org/apache/maven/mae/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/java/org/apache/maven/mae/project/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/java/org/apache/maven/mae/project/ProjectLoaderTest.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/java/org/apache/maven/mae/project/testutil/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/java/org/apache/maven/mae/project/testutil/TestFixture.java   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/projects/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/projects/multi-module/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/projects/multi-module/child1/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/projects/multi-module/child1/pom.xml   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/projects/multi-module/child2/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/projects/multi-module/child2/pom.xml   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/projects/multi-module/pom.xml   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/projects/simple.pom.xml   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/test-repo/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/test-repo/test/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/test-repo/test/found-dep/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/test-repo/test/found-dep/1/
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/test-repo/test/found-dep/1/found-dep-1.pom   (with props)
    maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/test/resources/test-repo/test/found-dep/maven-metadata.xml   (with props)
    maven/sandbox/trunk/mae/mae-components/pom.xml   (with props)
Modified:
    maven/sandbox/trunk/mae/pom.xml

Added: maven/sandbox/trunk/mae/mae-components/mae-project-tools/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mae/mae-components/mae-project-tools/pom.xml?rev=1138204&view=auto
==============================================================================
--- maven/sandbox/trunk/mae/mae-components/mae-project-tools/pom.xml (added)
+++ maven/sandbox/trunk/mae/mae-components/mae-project-tools/pom.xml Tue Jun 21 21:48:35 2011
@@ -0,0 +1,75 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you 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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.mae.components</groupId>
+    <artifactId>mae-components</artifactId>
+    <version>1.0-alpha-1-SNAPSHOT</version>
+  </parent>
+  
+  <artifactId>mae-project-tools</artifactId>
+  <name>Maven App Engine: Project Tools</name>
+  
+  <dependencies>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>2.0.1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.mae</groupId>
+      <artifactId>mae-booter</artifactId>
+      <version>${maeVersion}</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.mae</groupId>
+      <artifactId>mae-app</artifactId>
+      <version>${maeVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http-lightweight</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-file</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.sonatype.aether</groupId>
+      <artifactId>aether-connector-wagon</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-aether-provider</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+      <version>2.5</version>
+    </dependency>
+  </dependencies>
+</project>

Propchange: maven/sandbox/trunk/mae/mae-components/mae-project-tools/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/DefaultProjectLoader.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/DefaultProjectLoader.java?rev=1138204&view=auto
==============================================================================
--- maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/DefaultProjectLoader.java (added)
+++ maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/DefaultProjectLoader.java Tue Jun 21 21:48:35 2011
@@ -0,0 +1,540 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * 
+ * 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.
+ */
+
+package org.apache.maven.mae.project;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.apache.maven.RepositoryUtils;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.mae.project.session.ProjectToolsSession;
+import org.apache.maven.mae.project.session.SessionInjector;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Parent;
+import org.apache.maven.model.building.ModelProblem;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.project.ProjectBuildingResult;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.util.Os;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.sonatype.aether.RepositorySystem;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.resolution.ArtifactRequest;
+import org.sonatype.aether.resolution.ArtifactResolutionException;
+import org.sonatype.aether.resolution.ArtifactResult;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@Component( role = ProjectLoader.class )
+public class DefaultProjectLoader
+    implements ProjectLoader
+{
+
+    private static final Logger LOGGER = Logger.getLogger( DefaultProjectLoader.class );
+
+    @Requirement
+    private RepositorySystem aetherRepositorySystem;
+
+    @Requirement
+    private org.apache.maven.repository.RepositorySystem mavenRepositorySystem;
+
+    @Requirement
+    private ProjectBuilder projectBuilder;
+
+    @Requirement
+    private SessionInjector sessionInjector;
+
+    @Override
+    public List<MavenProject> buildReactorProjectInstances( final ProjectToolsSession session, final File... rootPoms )
+        throws ProjectToolsException
+    {
+        final ProjectBuildingRequest pbr = sessionInjector.getProjectBuildingRequest( session );
+
+        try
+        {
+            final List<File> pomFiles = Arrays.asList( rootPoms );
+            final List<ProjectBuildingResult> results = projectBuilder.build( pomFiles, true, pbr );
+
+            final List<MavenProject> projects = new ArrayList<MavenProject>( results.size() );
+            for ( final ProjectBuildingResult result : results )
+            {
+                final MavenProject project = result.getProject();
+                project.setRemoteArtifactRepositories( session.getRemoteArtifactRepositories() );
+
+                projects.add( project );
+            }
+
+            session.setReactorProjects( projects );
+
+            if ( LOGGER.isDebugEnabled() )
+            {
+                LOGGER.debug( "Adding projects to dependency graph:\n\t"
+                    + StringUtils.join( projects.iterator(), "\n\t" ) );
+            }
+            addProjects( session, projects );
+
+            return projects;
+        }
+        catch ( final ProjectBuildingException e )
+        {
+            // logger.error( "Failed to build MavenProject instances from POM files for sorting: " + e.getMessage(), e
+            // );
+            final List<ProjectBuildingResult> results = e.getResults();
+
+            final StringBuilder sb = new StringBuilder();
+
+            if ( results == null )
+            {
+                sb.append( "Cannot build reactor project instances for root-POM: " ).append( rootPoms );
+
+                final StringWriter sWriter = new StringWriter();
+                final PrintWriter pWriter = new PrintWriter( sWriter );
+
+                e.printStackTrace( pWriter );
+                sb.append( "\n" ).append( sWriter );
+            }
+            else
+            {
+                int i = 0;
+                for ( final ProjectBuildingResult result : results )
+                {
+                    final List<ModelProblem> problems = result.getProblems();
+                    if ( problems != null && !problems.isEmpty() )
+                    {
+                        sb.append( "\n" ).append( result.getProjectId() );
+                        for ( final ModelProblem problem : problems )
+                        {
+                            sb.append( "\n\t" )
+                              .append( problem.getMessage() )
+                              .append( "\n\t\t" )
+                              .append( problem.getSource() )
+                              .append( "@" )
+                              .append( problem.getLineNumber() )
+                              .append( ":" + problem.getColumnNumber() );
+
+                            if ( problem.getException() != null )
+                            {
+                                final StringWriter sWriter = new StringWriter();
+                                final PrintWriter pWriter = new PrintWriter( sWriter );
+
+                                problem.getException().printStackTrace( pWriter );
+                                sb.append( "\n" ).append( sWriter );
+                            }
+
+                            sb.append( ( ++i ) ).append( " " ).append( sb );
+                        }
+                    }
+                }
+            }
+
+            throw new ProjectToolsException( "Failed to build project instance. \n\n%s", e, sb );
+        }
+    }
+
+    private void addProjects( final ProjectToolsSession session, final MavenProject... projects )
+    {
+        if ( projects == null || projects.length == 0 )
+        {
+            return;
+        }
+
+        addProjects( session, Arrays.asList( projects ) );
+    }
+
+    private void addProjects( final ProjectToolsSession session, final List<MavenProject> projects )
+    {
+        for ( final MavenProject project : projects )
+        {
+            final LinkedList<Artifact> parentage = new LinkedList<Artifact>();
+            MavenProject parent = project;
+            while ( parent != null )
+            {
+                final org.apache.maven.artifact.Artifact pomArtifact =
+                    mavenRepositorySystem.createArtifact( project.getGroupId(),
+                                                          project.getArtifactId(),
+                                                          project.getVersion(),
+                                                          "pom" );
+
+                final Artifact aetherPomArtifact = RepositoryUtils.toArtifact( pomArtifact );
+
+                parentage.addFirst( aetherPomArtifact );
+
+                parent = parent.getParent();
+            }
+
+            Artifact current = parentage.removeFirst();
+            while ( !parentage.isEmpty() )
+            {
+                final Artifact next = parentage.getFirst();
+
+                // This is WEIRD, but the parent POM is actually a dependency of the current one,
+                // since it's required in order to build the current project...
+                if ( LOGGER.isDebugEnabled() )
+                {
+                    LOGGER.debug( "Marking parent POM: " + current + " as dependency of POM: " + next );
+                }
+                
+                session.connectProjectHierarchy( next, true, current, true );
+
+                if ( !parentage.isEmpty() )
+                {
+                    current = parentage.removeFirst();
+                }
+            }
+        }
+    }
+
+    @Override
+    public MavenProject buildProjectInstance( final File pomFile, final ProjectToolsSession session )
+        throws ProjectToolsException
+    {
+        final ProjectBuildingRequest pbr = sessionInjector.getProjectBuildingRequest( session );
+
+        try
+        {
+            final ProjectBuildingResult result = projectBuilder.build( pomFile, pbr );
+
+            final MavenProject project = result.getProject();
+            project.setRemoteArtifactRepositories( session.getRemoteArtifactRepositories() );
+
+            addProjects( session, project );
+
+            return project;
+        }
+        catch ( final ProjectBuildingException e )
+        {
+            // logger.error( "Failed to build MavenProject instances from POM files for sorting: " + e.getMessage(), e
+            // );
+            final List<ProjectBuildingResult> results = e.getResults();
+
+            final StringBuilder sb = new StringBuilder();
+
+            if ( results == null )
+            {
+                sb.append( "Cannot build project instance for: " ).append( pomFile );
+
+                final StringWriter sWriter = new StringWriter();
+                final PrintWriter pWriter = new PrintWriter( sWriter );
+
+                e.printStackTrace( pWriter );
+                sb.append( "\n" ).append( sWriter );
+            }
+            else
+            {
+                int i = 0;
+                for ( final ProjectBuildingResult result : results )
+                {
+                    final List<ModelProblem> problems = result.getProblems();
+                    for ( final ModelProblem problem : problems )
+                    {
+                        sb.append( problem.getMessage() )
+                          .append( "\n\t" )
+                          .append( problem.getSource() )
+                          .append( "@" )
+                          .append( problem.getLineNumber() )
+                          .append( ":" + problem.getColumnNumber() );
+
+                        if ( problem.getException() != null )
+                        {
+                            final StringWriter sWriter = new StringWriter();
+                            final PrintWriter pWriter = new PrintWriter( sWriter );
+
+                            problem.getException().printStackTrace( pWriter );
+                            sb.append( "\n" ).append( sWriter );
+                        }
+
+                        sb.append( ( ++i ) ).append( " " ).append( sb );
+                    }
+                }
+            }
+
+            throw new ProjectToolsException( "Failed to build project instance. \n\n%s", e, sb );
+        }
+    }
+
+    @Override
+    public MavenProject buildProjectInstance( final String groupId, final String artifactId, final String version,
+                                              final ProjectToolsSession session )
+        throws ProjectToolsException
+    {
+        final ProjectBuildingRequest req = sessionInjector.getProjectBuildingRequest( session );
+
+        try
+        {
+            final org.apache.maven.artifact.Artifact pomArtifact =
+                mavenRepositorySystem.createArtifact( groupId, artifactId, version, "pom" );
+
+            final Artifact aetherPomArtifact = RepositoryUtils.toArtifact( pomArtifact );
+
+            final ArtifactRequest artifactRequest =
+                new ArtifactRequest( aetherPomArtifact, sessionInjector.getRemoteRepositories( session ), "project" );
+
+            final ArtifactResult artifactResult =
+                aetherRepositorySystem.resolveArtifact( req.getRepositorySession(), artifactRequest );
+
+            final File pomFile = artifactResult.getArtifact().getFile();
+            final ProjectBuildingResult result = projectBuilder.build( pomFile, req );
+
+            final MavenProject project = result.getProject();
+            project.setRemoteArtifactRepositories( session.getRemoteArtifactRepositories() );
+
+            project.setFile( pomFile );
+
+            addProjects( session, project );
+
+            return project;
+        }
+        catch ( final ProjectBuildingException e )
+        {
+            // logger.error( "Failed to build MavenProject instances from POM files for sorting: " + e.getMessage(), e
+            // );
+            final List<ProjectBuildingResult> results = e.getResults();
+
+            final StringBuilder sb = new StringBuilder();
+
+            int i = 0;
+            if ( results == null )
+            {
+                sb.append( "Cannot build project instance for: " )
+                  .append( groupId )
+                  .append( ':' )
+                  .append( artifactId )
+                  .append( ':' )
+                  .append( version );
+
+                final StringWriter sWriter = new StringWriter();
+                final PrintWriter pWriter = new PrintWriter( sWriter );
+
+                e.printStackTrace( pWriter );
+                sb.append( "\n" ).append( sWriter );
+            }
+            else
+            {
+                for ( final ProjectBuildingResult result : results )
+                {
+                    final List<ModelProblem> problems = result.getProblems();
+                    for ( final ModelProblem problem : problems )
+                    {
+                        sb.append( problem.getMessage() )
+                          .append( "\n\t" )
+                          .append( problem.getSource() )
+                          .append( "@" )
+                          .append( problem.getLineNumber() )
+                          .append( ":" + problem.getColumnNumber() );
+
+                        if ( problem.getException() != null )
+                        {
+                            final StringWriter sWriter = new StringWriter();
+                            final PrintWriter pWriter = new PrintWriter( sWriter );
+
+                            problem.getException().printStackTrace( pWriter );
+                            sb.append( "\n" ).append( sWriter );
+                        }
+
+                        sb.append( ( ++i ) ).append( " " ).append( sb );
+                    }
+                }
+            }
+
+            throw new ProjectToolsException( "Failed to build project instance. \n\n%s", e, sb );
+        }
+        catch ( final ArtifactResolutionException e )
+        {
+            throw new ProjectToolsException( "Failed to resolve POM: %s:%s:%s\nReason: %s",
+                                             e,
+                                             groupId,
+                                             artifactId,
+                                             version,
+                                             e.getMessage() );
+        }
+    }
+
+    @Override
+    public Set<String> retrieveReactorProjectIds( final File rootPom )
+        throws ProjectToolsException
+    {
+        if ( LOGGER.isInfoEnabled() )
+        {
+            if ( LOGGER.isDebugEnabled() )
+            {
+                LOGGER.debug( "Finding projectIds contained within reactor for: " + rootPom );
+            }
+        }
+
+        final Map<File, Model> models = new LinkedHashMap<File, Model>();
+        readReactorModels( rootPom, rootPom, models );
+
+        final Set<String> projectIds = new HashSet<String>( models.size() );
+        for ( final Model model : models.values() )
+        {
+            String groupId = model.getGroupId();
+            final String artifactId = model.getArtifactId();
+            String version = model.getVersion();
+            String packaging = model.getPackaging();
+
+            if ( packaging == null )
+            {
+                packaging = "jar";
+            }
+
+            if ( groupId == null || version == null )
+            {
+                final Parent parent = model.getParent();
+                if ( parent != null )
+                {
+                    if ( groupId == null )
+                    {
+                        groupId = parent.getGroupId();
+                    }
+                    if ( version == null )
+                    {
+                        version = parent.getVersion();
+                    }
+                }
+                else
+                {
+                    LOGGER.warn( String.format( "Invalid POM: %s", model.getId() ) );
+                    continue;
+                }
+            }
+
+            final String key = ArtifactUtils.key( groupId, artifactId, version );
+            if ( LOGGER.isInfoEnabled() )
+            {
+                if ( LOGGER.isDebugEnabled() )
+                {
+                    LOGGER.debug( "Found: " + key );
+                }
+            }
+
+            projectIds.add( key );
+        }
+
+        return projectIds;
+    }
+
+    private void readReactorModels( final File topPom, final File pom, final Map<File, Model> models )
+        throws ProjectToolsException
+    {
+        final Model model = readModel( pom );
+        models.put( pom, model );
+
+        if ( model.getModules() != null && !model.getModules().isEmpty() )
+        {
+            final File basedir = pom.getParentFile();
+
+            final List<File> moduleFiles = new ArrayList<File>();
+
+            for ( String module : model.getModules() )
+            {
+                if ( StringUtils.isEmpty( module ) )
+                {
+                    continue;
+                }
+
+                module = module.replace( '\\', File.separatorChar ).replace( '/', File.separatorChar );
+
+                File moduleFile = new File( basedir, module );
+
+                if ( moduleFile.isDirectory() )
+                {
+                    moduleFile = new File( moduleFile, "pom.xml" );
+                }
+
+                if ( !moduleFile.isFile() )
+                {
+                    LOGGER.warn( String.format( "In reactor of: %s: Child module %s of %s does not exist.",
+                                                topPom,
+                                                moduleFile,
+                                                pom ) );
+                    continue;
+                }
+
+                if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
+                {
+                    // we don't canonicalize on unix to avoid interfering with symlinks
+                    try
+                    {
+                        moduleFile = moduleFile.getCanonicalFile();
+                    }
+                    catch ( final IOException e )
+                    {
+                        moduleFile = moduleFile.getAbsoluteFile();
+                    }
+                }
+                else
+                {
+                    moduleFile = new File( moduleFile.toURI().normalize() );
+                }
+
+                moduleFiles.add( moduleFile );
+                readReactorModels( topPom, moduleFile, models );
+            }
+        }
+    }
+
+    private Model readModel( final File pom )
+        throws ProjectToolsException
+    {
+        Reader reader = null;
+        try
+        {
+            reader = ReaderFactory.newPlatformReader( pom );
+
+            return new MavenXpp3Reader().read( reader, false );
+        }
+        catch ( final IOException e )
+        {
+            LOGGER.error( String.format( "Failed to read POM: %s.\nReason: %s", pom, e.getMessage() ), e );
+            throw new ProjectToolsException( "Failed to read POM: %s. Reason: %s",
+                                             e,
+                                             pom.getAbsolutePath(),
+                                             e.getMessage() );
+        }
+        catch ( final XmlPullParserException e )
+        {
+            LOGGER.error( String.format( "Failed to read POM: %s.\nReason: %s", pom, e.getMessage() ), e );
+            throw new ProjectToolsException( "Failed to read POM: %s. Reason: %s",
+                                             e,
+                                             pom.getAbsolutePath(),
+                                             e.getMessage() );
+        }
+        finally
+        {
+            IOUtils.closeQuietly( reader );
+        }
+    }
+
+}

Propchange: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/DefaultProjectLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectLoader.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectLoader.java?rev=1138204&view=auto
==============================================================================
--- maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectLoader.java (added)
+++ maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectLoader.java Tue Jun 21 21:48:35 2011
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * 
+ * 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.
+ */
+
+package org.apache.maven.mae.project;
+
+import org.apache.maven.mae.project.session.ProjectToolsSession;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+import java.util.List;
+import java.util.Set;
+
+public interface ProjectLoader
+{
+
+    List<MavenProject> buildReactorProjectInstances( final ProjectToolsSession session, final File... rootPoms )
+        throws ProjectToolsException;
+
+    MavenProject buildProjectInstance( final File pomFile, final ProjectToolsSession session )
+        throws ProjectToolsException;
+
+    MavenProject buildProjectInstance( final String groupId, final String artifactId, final String version,
+                                       final ProjectToolsSession session )
+        throws ProjectToolsException;
+
+    Set<String> retrieveReactorProjectIds( final File rootPom )
+        throws ProjectToolsException;
+
+}

Propchange: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectToolsException.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectToolsException.java?rev=1138204&view=auto
==============================================================================
--- maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectToolsException.java (added)
+++ maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectToolsException.java Tue Jun 21 21:48:35 2011
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * 
+ * 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.
+ */
+
+package org.apache.maven.mae.project;
+
+import org.apache.maven.mae.MAEException;
+
+public class ProjectToolsException
+    extends MAEException
+{
+
+    private static final long serialVersionUID = 1L;
+
+    public ProjectToolsException( final String message, final Object... params )
+    {
+        super( message, params );
+    }
+
+    public ProjectToolsException( final String message, final Throwable cause, final Object... params )
+    {
+        super( message, cause, params );
+    }
+
+    public ProjectToolsException( final String message, final Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public ProjectToolsException( final String message )
+    {
+        super( message );
+    }
+
+}

Propchange: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/ProjectToolsException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/lib/ProjectToolsLibrary.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/lib/ProjectToolsLibrary.java?rev=1138204&view=auto
==============================================================================
--- maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/lib/ProjectToolsLibrary.java (added)
+++ maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/lib/ProjectToolsLibrary.java Tue Jun 21 21:48:35 2011
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * 
+ * 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.
+ */
+
+package org.apache.maven.mae.project.lib;
+
+import org.apache.maven.mae.conf.AbstractMAELibrary;
+import org.apache.maven.mae.conf.MAELibrary;
+import org.apache.maven.mae.conf.MavenPomVersionProvider;
+import org.commonjava.atservice.annotation.Service;
+
+@Service( MAELibrary.class )
+public class ProjectToolsLibrary
+    extends AbstractMAELibrary
+{
+
+    public ProjectToolsLibrary()
+    {
+        super( "project", "Project-Tools", new MavenPomVersionProvider( "org.commonjava.emb.components",
+                                                                        "emb-project-tools" ) );
+    }
+
+}

Propchange: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/lib/ProjectToolsLibrary.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/DefaultSessionInjector.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/DefaultSessionInjector.java?rev=1138204&view=auto
==============================================================================
--- maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/DefaultSessionInjector.java (added)
+++ maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/DefaultSessionInjector.java Tue Jun 21 21:48:35 2011
@@ -0,0 +1,231 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * 
+ * 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.
+ */
+
+package org.apache.maven.mae.project.session;
+
+import org.apache.log4j.Logger;
+import org.apache.maven.artifact.InvalidRepositoryException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.MavenArtifactRepository;
+import org.apache.maven.mae.MAEException;
+import org.apache.maven.mae.boot.embed.MAEEmbedder;
+import org.apache.maven.mae.project.ProjectToolsException;
+import org.apache.maven.model.Repository;
+import org.apache.maven.project.DefaultProjectBuildingRequest;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.repository.RepositorySystem;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.sonatype.aether.RepositorySystemSession;
+import org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager;
+import org.sonatype.aether.repository.AuthenticationSelector;
+import org.sonatype.aether.repository.ProxySelector;
+import org.sonatype.aether.repository.RemoteRepository;
+import org.sonatype.aether.util.DefaultRepositorySystemSession;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+@Component( role = SessionInjector.class )
+public class DefaultSessionInjector
+    implements SessionInjector
+{
+
+    private static final Logger LOGGER = Logger.getLogger( DefaultSessionInjector.class );
+
+    @Requirement
+    private MAEEmbedder embedder;
+
+    @Requirement
+    private RepositorySystem mavenRepositorySystem;
+
+    @Override
+    public synchronized ProjectBuildingRequest getProjectBuildingRequest( final ProjectToolsSession session )
+        throws ProjectToolsException
+    {
+        ProjectBuildingRequest pbr = session.getProjectBuildingRequest();
+        try
+        {
+            if ( pbr == null )
+            {
+                pbr = embedder.serviceManager().createProjectBuildingRequest();
+
+                pbr.setProcessPlugins( session.isProcessPomPlugins() );
+                pbr.setResolveDependencies( false );
+                pbr.setSystemProperties( System.getProperties() );
+                pbr.setInactiveProfileIds( new ArrayList<String>() );
+                pbr.setRepositoryMerging( ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT );
+
+                final RepositorySystemSession rss = getRepositorySystemSession( session );
+                pbr.setRepositorySession( rss );
+                pbr.setLocalRepository( mavenRepositorySystem.createLocalRepository( rss.getLocalRepository()
+                                                                                        .getBasedir() ) );
+                pbr.setRemoteRepositories( getArtifactRepositories( session ) );
+
+                session.setProjectBuildingRequest( pbr );
+            }
+            else
+            {
+                pbr = new DefaultProjectBuildingRequest( pbr );
+                pbr.setRepositorySession( getRepositorySystemSession( session ) );
+            }
+        }
+        catch ( final MAEException e )
+        {
+            throw new ProjectToolsException( "Failed to create project-building request: %s", e, e.getMessage() );
+        }
+        catch ( final InvalidRepositoryException e )
+        {
+            throw new ProjectToolsException( "Failed to create local-repository instance. Reason: %s",
+                                             e,
+                                             e.getMessage() );
+        }
+
+        return pbr;
+    }
+
+    @Override
+    public RepositorySystemSession getRepositorySystemSession( final ProjectToolsSession session )
+        throws MAEException
+    {
+        final File localRepo = session.getLocalRepositoryDirectory();
+        localRepo.mkdirs();
+
+        RepositorySystemSession sess = session.getRepositorySystemSession();
+        if ( sess == null )
+        {
+            final DefaultRepositorySystemSession rss =
+                new DefaultRepositorySystemSession( embedder.serviceManager()
+                                                            .createAetherRepositorySystemSession( session.getExecutionRequest() ) );
+
+            // session.setWorkspaceReader( new ImportWorkspaceReader( workspace ) );
+            rss.setConfigProperty( ProjectToolsSession.SESSION_KEY, session );
+            rss.setLocalRepositoryManager( new EnhancedLocalRepositoryManager( localRepo ) );
+            rss.setWorkspaceReader( new SessionWorkspaceReader( session ) );
+
+            sess = rss;
+
+            session.setRepositorySystemSession( sess );
+        }
+
+        sess.getData().set( ProjectToolsSession.SESSION_KEY, session );
+
+        return sess;
+    }
+
+    @Override
+    public synchronized List<RemoteRepository> getRemoteRepositories( final ProjectToolsSession session )
+        throws ProjectToolsException
+    {
+        List<RemoteRepository> result = session.getRemoteRepositories();
+
+        if ( result == null )
+        {
+            result = new ArrayList<RemoteRepository>();
+
+            boolean selectorsEnabled = false;
+            AuthenticationSelector authSelector = null;
+            ProxySelector proxySelector = null;
+            if ( session.getRepositorySystemSession() != null )
+            {
+                selectorsEnabled = true;
+                authSelector = session.getRepositorySystemSession().getAuthenticationSelector();
+                proxySelector = session.getRepositorySystemSession().getProxySelector();
+            }
+            else
+            {
+                LOGGER.warn( "Cannot set proxy or authentication information on new RemoteRepositories; "
+                    + "RepositorySystemSession is not available in ProjectToolsSession instance." );
+            }
+
+            for ( final ArtifactRepository repo : getArtifactRepositories( session ) )
+            {
+                RemoteRepository r = null;
+                if ( repo instanceof RemoteRepository )
+                {
+                    r = (RemoteRepository) repo;
+                }
+                else if ( repo instanceof MavenArtifactRepository )
+                {
+                    r = new RemoteRepository( repo.getId(), "default", repo.getUrl() );
+                }
+
+                if ( r != null )
+                {
+                    if ( selectorsEnabled )
+                    {
+                        r.setAuthentication( authSelector.getAuthentication( r ) );
+                        r.setProxy( proxySelector.getProxy( r ) );
+                    }
+
+                    result.add( r );
+                }
+            }
+
+            session.setRemoteRepositories( result );
+        }
+
+        return result;
+    }
+
+    @Override
+    public synchronized List<ArtifactRepository> getArtifactRepositories( final ProjectToolsSession session )
+        throws ProjectToolsException
+    {
+        List<ArtifactRepository> repos = session.getRemoteArtifactRepositories();
+        if ( repos == null )
+        {
+            final Repository[] remoteRepositories = session.getResolveRepositories();
+
+            repos = new ArrayList<ArtifactRepository>( remoteRepositories == null ? 0 : remoteRepositories.length );
+
+            if ( remoteRepositories != null )
+            {
+                for ( final Repository repo : remoteRepositories )
+                {
+                    try
+                    {
+                        repos.add( mavenRepositorySystem.buildArtifactRepository( repo ) );
+                    }
+                    catch ( final InvalidRepositoryException e )
+                    {
+                        throw new ProjectToolsException( "Failed to create remote artifact repository instance from: %s\nReason: %s",
+                                                         e,
+                                                         repo,
+                                                         e.getMessage() );
+                    }
+                }
+            }
+
+            try
+            {
+                repos.add( mavenRepositorySystem.createDefaultRemoteRepository() );
+            }
+            catch ( final InvalidRepositoryException e )
+            {
+                throw new ProjectToolsException( "Failed to create default (central) repository instance: %s",
+                                                 e,
+                                                 e.getMessage() );
+            }
+
+            session.setRemoteArtifactRepositories( repos );
+        }
+
+        return repos;
+    }
+
+}

Propchange: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/DefaultSessionInjector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/ProjectToolsSession.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/ProjectToolsSession.java?rev=1138204&view=auto
==============================================================================
--- maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/ProjectToolsSession.java (added)
+++ maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/ProjectToolsSession.java Tue Jun 21 21:48:35 2011
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * 
+ * 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.
+ */
+
+package org.apache.maven.mae.project.session;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.model.Repository;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.sonatype.aether.RepositorySystemSession;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.collection.DependencySelector;
+import org.sonatype.aether.graph.DependencyFilter;
+import org.sonatype.aether.repository.RemoteRepository;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+
+public interface ProjectToolsSession
+{
+
+    public static final String SESSION_KEY = "dependency-resolver-session";
+
+    List<ArtifactRepository> getRemoteArtifactRepositories();
+
+    ProjectToolsSession setRemoteArtifactRepositories( final List<ArtifactRepository> remoteArtifactRepositories );
+
+    Repository[] getResolveRepositories();
+
+    File getLocalRepositoryDirectory();
+
+    List<RemoteRepository> getRemoteRepositories();
+
+    ProjectToolsSession setRemoteRepositories( final List<RemoteRepository> remoteRepositories );
+
+    ProjectBuildingRequest getProjectBuildingRequest();
+
+    ProjectToolsSession setProjectBuildingRequest( final ProjectBuildingRequest projectBuildingRequest );
+
+    File getWorkdir();
+
+    RepositorySystemSession getRepositorySystemSession();
+
+    ProjectToolsSession setRepositorySystemSession( final RepositorySystemSession repositorySystemSession );
+
+    ProjectToolsSession addReactorProject( final MavenProject project );
+
+    ProjectToolsSession setReactorProjects( final MavenProject... projects );
+
+    ProjectToolsSession setReactorProjects( final Iterable<MavenProject> projects );
+
+    Collection<MavenProject> getReactorProjects();
+
+    File getReactorPom( final Artifact artifact );
+
+    MavenProject getReactorProject( final Artifact artifact );
+
+    ProjectToolsSession copy();
+
+    RemoteRepository[] getRemoteRepositoriesArray();
+
+    ProjectToolsSession setExecutionRequest( MavenExecutionRequest request );
+
+    MavenExecutionRequest getExecutionRequest();
+
+    ProjectToolsSession setResolveThreads( int threads );
+
+    int getResolveThreads();
+
+    boolean isProcessPomPlugins();
+
+    ProjectToolsSession setProcessPomPlugins( boolean resolvePlugins );
+
+    DependencySelector getDependencySelector();
+
+    ProjectToolsSession setDependencySelector( DependencySelector selector );
+
+    DependencyFilter getDependencyFilter();
+
+    ProjectToolsSession setDependencyFilter( DependencyFilter filter );
+
+    void connectProjectHierarchy( Artifact parent, boolean parentPreResolved, Artifact child, boolean childPreResolved );
+    
+    <T> T setState( T state );
+    
+    <T> T getState( Class<T> stateType );
+    
+    <T> T clearState( Class<T> stateType );
+    
+    void clearStates();
+    
+}

Propchange: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/ProjectToolsSession.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionInjector.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionInjector.java?rev=1138204&view=auto
==============================================================================
--- maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionInjector.java (added)
+++ maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionInjector.java Tue Jun 21 21:48:35 2011
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * 
+ * 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.
+ */
+
+package org.apache.maven.mae.project.session;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.mae.MAEException;
+import org.apache.maven.mae.project.ProjectToolsException;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.sonatype.aether.RepositorySystemSession;
+import org.sonatype.aether.repository.RemoteRepository;
+
+import java.util.List;
+
+/**
+ * 
+ */
+public interface SessionInjector
+{
+
+    ProjectBuildingRequest getProjectBuildingRequest( final ProjectToolsSession session )
+        throws ProjectToolsException;
+
+    RepositorySystemSession getRepositorySystemSession( final ProjectToolsSession session )
+        throws MAEException;
+
+    List<RemoteRepository> getRemoteRepositories( final ProjectToolsSession session )
+        throws ProjectToolsException;
+
+    List<ArtifactRepository> getArtifactRepositories( final ProjectToolsSession session )
+        throws ProjectToolsException;
+
+}

Propchange: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionInjector.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionWorkspaceReader.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionWorkspaceReader.java?rev=1138204&view=auto
==============================================================================
--- maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionWorkspaceReader.java (added)
+++ maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionWorkspaceReader.java Tue Jun 21 21:48:35 2011
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * 
+ * 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.
+ */
+
+package org.apache.maven.mae.project.session;
+
+import org.apache.maven.project.MavenProject;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.repository.WorkspaceReader;
+import org.sonatype.aether.repository.WorkspaceRepository;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+public class SessionWorkspaceReader
+    implements WorkspaceReader
+{
+
+    private static final WorkspaceRepository REPO = new WorkspaceRepository();
+
+    private final ProjectToolsSession session;
+
+    public SessionWorkspaceReader( final ProjectToolsSession session )
+    {
+        this.session = session;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.sonatype.aether.repository.WorkspaceReader#getRepository()
+     */
+    @Override
+    public WorkspaceRepository getRepository()
+    {
+        return REPO;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.sonatype.aether.repository.WorkspaceReader#findArtifact(org.sonatype.aether.artifact.Artifact)
+     */
+    @Override
+    public File findArtifact( final Artifact artifact )
+    {
+        return session.getReactorPom( artifact );
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.sonatype.aether.repository.WorkspaceReader#findVersions(org.sonatype.aether.artifact.Artifact)
+     */
+    @Override
+    public List<String> findVersions( final Artifact artifact )
+    {
+        final List<String> versions = new ArrayList<String>( 1 );
+
+        final MavenProject project = session.getReactorProject( artifact );
+        if ( project != null )
+        {
+            versions.add( project.getVersion() );
+        }
+
+        return versions;
+    }
+
+}

Propchange: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SessionWorkspaceReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SimpleProjectToolsSession.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SimpleProjectToolsSession.java?rev=1138204&view=auto
==============================================================================
--- maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SimpleProjectToolsSession.java (added)
+++ maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SimpleProjectToolsSession.java Tue Jun 21 21:48:35 2011
@@ -0,0 +1,486 @@
+/*
+ * Copyright 2011 Red Hat, Inc.
+ * 
+ * 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.
+ */
+
+package org.apache.maven.mae.project.session;
+
+import static org.apache.maven.artifact.ArtifactUtils.key;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.model.Repository;
+import org.apache.maven.project.DefaultProjectBuildingRequest;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.sonatype.aether.RepositorySystemSession;
+import org.sonatype.aether.artifact.Artifact;
+import org.sonatype.aether.collection.DependencySelector;
+import org.sonatype.aether.graph.DependencyFilter;
+import org.sonatype.aether.repository.RemoteRepository;
+import org.sonatype.aether.util.DefaultRepositorySystemSession;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SimpleProjectToolsSession
+    implements ProjectToolsSession
+{
+
+    private final File workdir;
+
+    private final Repository[] resolveRepositories;
+
+    private transient List<ArtifactRepository> remoteArtifactRepositories;
+
+    private transient List<RemoteRepository> remoteRepositories;
+
+    private transient ProjectBuildingRequest projectBuildingRequest;
+
+    private transient RepositorySystemSession repositorySystemSession;
+
+    private transient LinkedHashMap<String, MavenProject> reactorProjects = new LinkedHashMap<String, MavenProject>();
+
+    private final File localRepositoryDirectory;
+
+    private MavenExecutionRequest executionRequest;
+
+    private int resolveThreads = 4;
+
+    private boolean resolvePlugins;
+
+    private DependencySelector dependencySelector;
+
+    private DependencyFilter filter;
+
+    private transient Map<Class<?>, Object> states = new HashMap<Class<?>, Object>();
+
+    public SimpleProjectToolsSession( final File workdir, final Repository... resolveRepositories )
+    {
+        this( workdir, new File( workdir, "local-repository" ), resolveRepositories );
+    }
+
+    public SimpleProjectToolsSession( final File workdir, final File localRepositoryDirectory,
+                                      final Repository... resolveRepositories )
+    {
+        this.workdir = workdir;
+        this.localRepositoryDirectory = localRepositoryDirectory;
+        this.resolveRepositories = resolveRepositories;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getRemoteArtifactRepositories()
+     */
+    @Override
+    public List<ArtifactRepository> getRemoteArtifactRepositories()
+    {
+        return remoteArtifactRepositories;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#setRemoteArtifactRepositories(java.util.List)
+     */
+    @Override
+    public ProjectToolsSession setRemoteArtifactRepositories( final List<ArtifactRepository> remoteArtifactRepositories )
+    {
+        this.remoteArtifactRepositories = remoteArtifactRepositories;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getResolveRepositories()
+     */
+    @Override
+    public Repository[] getResolveRepositories()
+    {
+        return resolveRepositories;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getRemoteRepositories()
+     */
+    @Override
+    public List<RemoteRepository> getRemoteRepositories()
+    {
+        return remoteRepositories;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getRemoteRepositoriesArray()
+     */
+    @Override
+    public RemoteRepository[] getRemoteRepositoriesArray()
+    {
+        return remoteRepositories == null ? new RemoteRepository[] {}
+                        : remoteRepositories.toArray( new RemoteRepository[] {} );
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#setRemoteRepositories(java.util.List)
+     */
+    @Override
+    public ProjectToolsSession setRemoteRepositories( final List<RemoteRepository> remoteRepositories )
+    {
+        this.remoteRepositories = remoteRepositories;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getProjectBuildingRequest()
+     */
+    @Override
+    public ProjectBuildingRequest getProjectBuildingRequest()
+    {
+        return projectBuildingRequest;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#setProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest)
+     */
+    @Override
+    public ProjectToolsSession setProjectBuildingRequest( final ProjectBuildingRequest projectBuildingRequest )
+    {
+        this.projectBuildingRequest = projectBuildingRequest;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getWorkdir()
+     */
+    @Override
+    public File getWorkdir()
+    {
+        return workdir;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getRepositorySystemSession()
+     */
+    @Override
+    public RepositorySystemSession getRepositorySystemSession()
+    {
+        return repositorySystemSession;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#setRepositorySystemSession(org.sonatype.aether.RepositorySystemSession)
+     */
+    @Override
+    public ProjectToolsSession setRepositorySystemSession( final RepositorySystemSession repositorySystemSession )
+    {
+        this.repositorySystemSession = repositorySystemSession;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#addReactorProject(org.apache.maven.project.MavenProject)
+     */
+    @Override
+    public synchronized ProjectToolsSession addReactorProject( final MavenProject project )
+    {
+        final String id = key( project.getGroupId(), project.getArtifactId(), project.getVersion() );
+        if ( !reactorProjects.containsKey( id ) )
+        {
+            reactorProjects.put( id, project );
+        }
+
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#setReactorProjects(org.apache.maven.project.MavenProject)
+     */
+    @Override
+    public synchronized ProjectToolsSession setReactorProjects( final MavenProject... projects )
+    {
+        reactorProjects.clear();
+        for ( final MavenProject project : projects )
+        {
+            addReactorProject( project );
+        }
+
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#setReactorProjects(java.lang.Iterable)
+     */
+    @Override
+    public synchronized ProjectToolsSession setReactorProjects( final Iterable<MavenProject> projects )
+    {
+        reactorProjects.clear();
+        for ( final MavenProject project : projects )
+        {
+            addReactorProject( project );
+        }
+
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getReactorProjects()
+     */
+    @Override
+    public Collection<MavenProject> getReactorProjects()
+    {
+        return new ArrayList<MavenProject>( reactorProjects.values() );
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getReactorPom(org.sonatype.aether.artifact.Artifact)
+     */
+    @Override
+    public File getReactorPom( final Artifact artifact )
+    {
+        final MavenProject project = getReactorProject( artifact );
+        return project == null ? null : project.getFile();
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getReactorProject(org.sonatype.aether.artifact.Artifact)
+     */
+    @Override
+    public MavenProject getReactorProject( final Artifact artifact )
+    {
+        final String id = key( artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion() );
+        return reactorProjects.get( id );
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#copyOf(org.apache.maven.mae.project.session.ProjectToolsSession)
+     */
+    @Override
+    public ProjectToolsSession copy()
+    {
+        final SimpleProjectToolsSession copy = new SimpleProjectToolsSession( workdir, resolveRepositories );
+
+        copy.projectBuildingRequest =
+            projectBuildingRequest == null ? null : new DefaultProjectBuildingRequest( projectBuildingRequest );
+
+        copy.reactorProjects = new LinkedHashMap<String, MavenProject>( reactorProjects );
+
+        copy.remoteArtifactRepositories =
+            remoteArtifactRepositories == null ? null : new ArrayList<ArtifactRepository>( remoteArtifactRepositories );
+
+        copy.remoteRepositories =
+            remoteRepositories == null ? null : new ArrayList<RemoteRepository>( remoteRepositories );
+
+        copy.repositorySystemSession =
+            repositorySystemSession == null ? null : new DefaultRepositorySystemSession( repositorySystemSession );
+
+        return copy;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getLocalRepositoryDirectory()
+     */
+    @Override
+    public File getLocalRepositoryDirectory()
+    {
+        return localRepositoryDirectory;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#setExecutionRequest(org.apache.maven.execution.MavenExecutionRequest)
+     */
+    @Override
+    public ProjectToolsSession setExecutionRequest( final MavenExecutionRequest request )
+    {
+        executionRequest = request;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getExecutionRequest()
+     */
+    @Override
+    public MavenExecutionRequest getExecutionRequest()
+    {
+        return executionRequest;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#setResolveThreads(int)
+     */
+    @Override
+    public ProjectToolsSession setResolveThreads( final int threads )
+    {
+        resolveThreads = threads;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getResolveThreads()
+     */
+    @Override
+    public int getResolveThreads()
+    {
+        return resolveThreads;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#isProcessPomPlugins()
+     */
+    @Override
+    public boolean isProcessPomPlugins()
+    {
+        return resolvePlugins;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#setProcessPomPlugins(boolean)
+     */
+    @Override
+    public ProjectToolsSession setProcessPomPlugins( final boolean resolvePlugins )
+    {
+        this.resolvePlugins = resolvePlugins;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getDependencySelector()
+     */
+    @Override
+    public DependencySelector getDependencySelector()
+    {
+        return dependencySelector;
+    }
+
+    @Override
+    public ProjectToolsSession setDependencySelector( final DependencySelector dependencySelector )
+    {
+        this.dependencySelector = dependencySelector;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#getDependencyFilter()
+     */
+    @Override
+    public DependencyFilter getDependencyFilter()
+    {
+        return filter;
+    }
+
+    /**
+     * {@inheritDoc}
+     * 
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#setDependencyFilter(org.sonatype.aether.graph.DependencyFilter)
+     */
+    @Override
+    public ProjectToolsSession setDependencyFilter( final DependencyFilter filter )
+    {
+        this.filter = filter;
+        return this;
+    }
+
+    /**
+     * {@inheritDoc}
+     * @see org.apache.maven.mae.project.session.ProjectToolsSession#connectProjectHierarchy(org.sonatype.aether.artifact.Artifact, boolean, org.sonatype.aether.artifact.Artifact, boolean)
+     */
+    @Override
+    public void connectProjectHierarchy( Artifact parent, boolean parentPreResolved, Artifact child,
+                                         boolean childPreResolved )
+    {
+        // NOP.
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public <T> T setState( final T state )
+    {
+        if ( state != null )
+        {
+            return (T) states.put( state.getClass(), state );
+        }
+        
+        return null;
+    }
+
+    public void clearStates()
+    {
+        states.clear();
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public <T> T clearState( final Class<T> type )
+    {
+        return (T) states.remove( type );
+    }
+
+    public <T> T getState( final Class<T> type )
+    {
+        final Object state = states.get( type );
+        return state == null ? null : type.cast( state );
+    }
+
+}

Propchange: maven/sandbox/trunk/mae/mae-components/mae-project-tools/src/main/java/org/apache/maven/mae/project/session/SimpleProjectToolsSession.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message