[MASSEMBLY-855] Remote repositories ignored in a multi-module project

All the project repositories (and not just the session) need to be considered when a repository is assembled.

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1800508 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/it/projects/repositories/massembly-855/child/pom.xml b/src/it/projects/repositories/massembly-855/child/pom.xml
new file mode 100644
index 0000000..1b09351
--- /dev/null
+++ b/src/it/projects/repositories/massembly-855/child/pom.xml
@@ -0,0 +1,64 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.plugin.assembly.test</groupId>
+    <artifactId>massembly-855</artifactId>
+    <version>1</version>
+  </parent>
+  <artifactId>child</artifactId>
+  <packaging>pom</packaging>
+  <properties>
+    <it.repo.url>file://${project.basedir}/../remote-repository</it.repo.url>
+  </properties>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.plugins.assembly.it</groupId>
+      <artifactId>massembly-855</artifactId>
+      <version>1.0</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <descriptors>
+            <descriptor>src/assembly/repository.xml</descriptor>
+          </descriptors>
+        </configuration>
+        <executions>
+          <execution>
+            <id>create-repository</id>
+            <phase>package</phase>
+            <goals>
+              <goal>single</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/src/it/projects/repositories/massembly-855/child/src/assembly/repository.xml b/src/it/projects/repositories/massembly-855/child/src/assembly/repository.xml
new file mode 100644
index 0000000..1a933b3
--- /dev/null
+++ b/src/it/projects/repositories/massembly-855/child/src/assembly/repository.xml
@@ -0,0 +1,34 @@
+<?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.
+-->
+
+<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+  xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
+  <id>repository</id>
+  <formats>
+    <format>dir</format>
+  </formats>
+  <repositories>
+    <repository>
+      <includeMetadata>true</includeMetadata>
+      <outputDirectory>maven-repository</outputDirectory>
+    </repository>
+  </repositories>
+</assembly>
diff --git a/src/it/projects/repositories/massembly-855/invoker.properties b/src/it/projects/repositories/massembly-855/invoker.properties
new file mode 100644
index 0000000..4b2a3ba
--- /dev/null
+++ b/src/it/projects/repositories/massembly-855/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals=package
diff --git a/src/it/projects/repositories/massembly-855/pom.xml b/src/it/projects/repositories/massembly-855/pom.xml
new file mode 100644
index 0000000..ac41850
--- /dev/null
+++ b/src/it/projects/repositories/massembly-855/pom.xml
@@ -0,0 +1,48 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.plugin.assembly.test</groupId>
+    <artifactId>it-project-parent</artifactId>
+    <version>1</version>
+  </parent>
+  <artifactId>massembly-855</artifactId>
+  <packaging>pom</packaging>
+  <description>
+    Tests that repository building works when a custom repository is declared in a parent POM with the Assembly Plugin
+    used in a child POM.
+  </description>
+  <properties>
+    <it.repo.url>file://${project.basedir}/remote-repository</it.repo.url>
+  </properties>
+  <repositories>
+    <repository>
+      <id>it-repo</id>
+      <url>${it.repo.url}</url>
+    </repository>
+  </repositories>
+  <modules>
+    <module>child</module>
+  </modules>
+</project>
diff --git a/src/it/projects/repositories/massembly-855/remote-repository/org/apache/maven/plugins/assembly/it/massembly-855/1.0/massembly-855-1.0.jar b/src/it/projects/repositories/massembly-855/remote-repository/org/apache/maven/plugins/assembly/it/massembly-855/1.0/massembly-855-1.0.jar
new file mode 100644
index 0000000..fbbfbae
--- /dev/null
+++ b/src/it/projects/repositories/massembly-855/remote-repository/org/apache/maven/plugins/assembly/it/massembly-855/1.0/massembly-855-1.0.jar
Binary files differ
diff --git a/src/it/projects/repositories/massembly-855/remote-repository/org/apache/maven/plugins/assembly/it/massembly-855/1.0/massembly-855-1.0.pom b/src/it/projects/repositories/massembly-855/remote-repository/org/apache/maven/plugins/assembly/it/massembly-855/1.0/massembly-855-1.0.pom
new file mode 100644
index 0000000..9b2284f
--- /dev/null
+++ b/src/it/projects/repositories/massembly-855/remote-repository/org/apache/maven/plugins/assembly/it/massembly-855/1.0/massembly-855-1.0.pom
@@ -0,0 +1,34 @@
+<?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>
+  <groupId>org.apache.maven.plugins.assembly.it</groupId>
+  <artifactId>massembly-855</artifactId>
+  <version>1.0</version>
+  <distributionManagement>
+    <repository>
+	  <id>test-repo</id>
+	  <url>file://${project.basedir}/repo</url>
+	</repository>
+  </distributionManagement>
+</project>
diff --git a/src/it/projects/repositories/massembly-855/verify.bsh b/src/it/projects/repositories/massembly-855/verify.bsh
new file mode 100644
index 0000000..303b800
--- /dev/null
+++ b/src/it/projects/repositories/massembly-855/verify.bsh
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+import java.io.File;
+
+String repoDir = "child/target/child-1-repository/child-1/maven-repository";
+
+File[] filesToCheck = new File[] {
+  new File( basedir, repoDir + "/org/apache/maven/plugins/assembly/it/massembly-855/1.0/massembly-855-1.0.jar" ),
+  new File( basedir, repoDir + "/org/apache/maven/plugins/assembly/it/massembly-855/1.0/massembly-855-1.0.pom" )
+};
+
+for ( File file : filesToCheck )
+{
+  if ( !file.exists() )
+  {
+    System.out.println( "File doesn't exist: " + file );
+    return false;
+  }
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugins/assembly/archive/phase/wrappers/RepoBuilderConfigSourceWrapper.java b/src/main/java/org/apache/maven/plugins/assembly/archive/phase/wrappers/RepoBuilderConfigSourceWrapper.java
index aaa925f..9940476 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/archive/phase/wrappers/RepoBuilderConfigSourceWrapper.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/archive/phase/wrappers/RepoBuilderConfigSourceWrapper.java
@@ -21,6 +21,7 @@
 
 import org.apache.maven.plugins.assembly.AssemblerConfigurationSource;
 import org.apache.maven.plugins.assembly.repository.RepositoryBuilderConfigSource;
+import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingRequest;
 
@@ -47,6 +48,9 @@
     @Override
     public ProjectBuildingRequest getProjectBuildingRequest()
     {
-        return configSource.getMavenSession().getProjectBuildingRequest();
+        ProjectBuildingRequest pbr =
+            new DefaultProjectBuildingRequest( configSource.getMavenSession().getProjectBuildingRequest() );
+        pbr.setRemoteRepositories( getProject().getRemoteArtifactRepositories() );
+        return pbr;
     }
 }
diff --git a/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java b/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java
index e056634..741b19d 100644
--- a/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java
+++ b/src/main/java/org/apache/maven/plugins/assembly/artifact/DefaultDependencyResolver.java
@@ -44,6 +44,7 @@
 import org.apache.maven.plugins.assembly.model.Repository;
 import org.apache.maven.plugins.assembly.resolved.AssemblyId;
 import org.apache.maven.plugins.assembly.utils.FilterUtils;
+import org.apache.maven.project.DefaultProjectBuildingRequest;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.repository.RepositorySystem;
@@ -335,16 +336,18 @@
             {
                 try
                 {
+                    ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( buildingRequest );
+                    pbr.setRemoteRepositories( project.getRemoteArtifactRepositories() );
                     Iterable<ArtifactResult> artifactResults =
-                        dependencyResolver.resolveDependencies( buildingRequest, project.getModel(), scopeFilter );
-                    
+                        dependencyResolver.resolveDependencies( pbr, project.getModel(), scopeFilter );
+
                     dependencyArtifacts = new HashSet<Artifact>();
-                    
+
                     for ( ArtifactResult artifactResult : artifactResults )
                     {
                         dependencyArtifacts.add( artifactResult.getArtifact() );
                     }
-                    
+
                     project.setDependencyArtifacts( dependencyArtifacts );
                 }
                 catch ( final DependencyResolverException e )