[MINSTALL-118] MavenProject with only attachments must have packaging "pom"

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1724329 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/it/no-main-artifact-1/invoker.properties b/src/it/no-main-artifact-1/invoker.properties
new file mode 100644
index 0000000..e497ae4
--- /dev/null
+++ b/src/it/no-main-artifact-1/invoker.properties
@@ -0,0 +1,17 @@
+# 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.buildResult=failure
\ No newline at end of file
diff --git a/src/it/no-main-artifact-1/verify.bsh b/src/it/no-main-artifact-1/verify.bsh
deleted file mode 100644
index 8bdc8dc..0000000
--- a/src/it/no-main-artifact-1/verify.bsh
+++ /dev/null
@@ -1,41 +0,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.
- */
-
-import java.io.*;
-import java.util.*;
-
-String[] paths =
-{
-    "org/apache/maven/its/install/nma1/test/maven-metadata-local.xml",
-    "org/apache/maven/its/install/nma1/test/1.0-SNAPSHOT/maven-metadata-local.xml",
-    "org/apache/maven/its/install/nma1/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom",
-    "org/apache/maven/its/install/nma1/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-it.jar",
-};
-
-for ( String path : paths )
-{
-    File file = new File( localRepositoryPath, path );
-    System.out.println( "Checking for existence of " + file );
-    if ( !file.isFile() )
-    {
-        throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
-    }
-}
-
-return true;
diff --git a/src/it/no-main-artifact-1/verify.groovy b/src/it/no-main-artifact-1/verify.groovy
new file mode 100644
index 0000000..9442aa7
--- /dev/null
+++ b/src/it/no-main-artifact-1/verify.groovy
@@ -0,0 +1,23 @@
+/*

+ * 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.

+ */

+

+def buildLog = new File ( basedir, "build.log")

+

+assert buildLog.text.contains( "The packaging plugin for this project did not assign "

+                                   + "a main file to the project but it has attachments. Change packaging to 'pom'." )
\ No newline at end of file
diff --git a/src/it/no-main-artifact-2/invoker.properties b/src/it/no-main-artifact-2/invoker.properties
new file mode 100644
index 0000000..e497ae4
--- /dev/null
+++ b/src/it/no-main-artifact-2/invoker.properties
@@ -0,0 +1,17 @@
+# 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.buildResult=failure
\ No newline at end of file
diff --git a/src/it/no-main-artifact-2/verify.bsh b/src/it/no-main-artifact-2/verify.bsh
deleted file mode 100644
index dce2df0..0000000
--- a/src/it/no-main-artifact-2/verify.bsh
+++ /dev/null
@@ -1,41 +0,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.
- */
-
-import java.io.*;
-import java.util.*;
-
-String[] paths =
-{
-    "org/apache/maven/its/install/nma2/test/maven-metadata-local.xml",
-    "org/apache/maven/its/install/nma2/test/1.0-SNAPSHOT/maven-metadata-local.xml",
-    "org/apache/maven/its/install/nma2/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom",
-    "org/apache/maven/its/install/nma2/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-it.jar",
-};
-
-for ( String path : paths )
-{
-    File file = new File( localRepositoryPath, path );
-    System.out.println( "Checking for existence of " + file );
-    if ( !file.isFile() )
-    {
-        throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
-    }
-}
-
-return true;
diff --git a/src/it/no-main-artifact-2/verify.groovy b/src/it/no-main-artifact-2/verify.groovy
new file mode 100644
index 0000000..9442aa7
--- /dev/null
+++ b/src/it/no-main-artifact-2/verify.groovy
@@ -0,0 +1,23 @@
+/*

+ * 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.

+ */

+

+def buildLog = new File ( basedir, "build.log")

+

+assert buildLog.text.contains( "The packaging plugin for this project did not assign "

+                                   + "a main file to the project but it has attachments. Change packaging to 'pom'." )
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java b/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
index fd21105..097b0aa 100644
--- a/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
+++ b/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
@@ -274,7 +274,7 @@
         }
 
         validateArtifactInformation();
-
+        
         Artifact artifact =
             artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier );
 
@@ -526,24 +526,6 @@
         }
     }
 
-    /**
-     * @return the localRepositoryPath
-     */
-    @SuppressWarnings( "UnusedDeclaration" )
-    public File getLocalRepositoryPath()
-    {
-        return this.localRepositoryPath;
-    }
-
-    /**
-     * @param theLocalRepositoryPath the localRepositoryPath to set
-     */
-    public void setLocalRepositoryPath( File theLocalRepositoryPath )
-    {
-        this.localRepositoryPath = theLocalRepositoryPath;
-    }
-
-    
     private static class InstallModelProblemCollector implements ModelProblemCollector
     {
         /** */
diff --git a/src/main/java/org/apache/maven/plugin/install/InstallMojo.java b/src/main/java/org/apache/maven/plugin/install/InstallMojo.java
index fed3c16..f5cc9f7 100644
--- a/src/main/java/org/apache/maven/plugin/install/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugin/install/InstallMojo.java
@@ -182,21 +182,8 @@
                 }
                 else if ( !attachedArtifacts.isEmpty() )
                 {
-                    getLog().info( "No primary artifact to install, installing attached artifacts instead." );
-
-                    Artifact pomArtifact =
-                        artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(),
-                                                               artifact.getBaseVersion() );
-                    pomArtifact.setFile( pomFile );
-                    if ( updateReleaseInfo )
-                    {
-                        pomArtifact.setRelease( true );
-                    }
-
-//                    installer.install( pomFile, pomArtifact, localRepository );
-                    installer.install( session.getProjectBuildingRequest(), Collections.singletonList( pomArtifact ) );
-                    installChecksums( pomArtifact, createChecksum );
-                    addMetaDataFilesForArtifact( pomArtifact, metadataFiles, createChecksum );
+                    throw new MojoExecutionException( "The packaging plugin for this project did not assign "
+                                   + "a main file to the project but it has attachments. Change packaging to 'pom'." );
                 }
                 else
                 {
diff --git a/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java b/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
index fd1ae3e..5a53f85 100644
--- a/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
+++ b/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
@@ -145,10 +145,10 @@
                 attachedArtifact.getArtifactId() + "/" + attachedArtifact.getVersion() + "/" +
                 attachedArtifact.getArtifactId() + "-" + attachedArtifact.getVersion() + "." + packaging );
 
-            assertTrue( installedArtifact.exists() );
+            assertTrue( installedArtifact.getPath() + " does not exist", installedArtifact.exists() );
         }
         
-        assertEquals( 12, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
+        assertEquals( 13, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
     }
 
     public void testUpdateReleaseParamSetToTrue()
diff --git a/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml b/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml
index 18e6b36..4d480e2 100644
--- a/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml
+++ b/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml
@@ -26,7 +26,9 @@
           <project implementation="org.apache.maven.plugin.testing.stubs.MavenProjectStub">
             <file>${basedir}/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml</file>
             <packaging>jar</packaging>
-            <artifact implementation="org.apache.maven.plugin.install.stubs.InstallArtifactStub"/>
+            <artifact implementation="org.apache.maven.plugin.install.stubs.InstallArtifactStub">
+              <file>${basedir}/src/test/resources/unit/basic-install-test-with-attached-artifacts/plugin-config.xml</file>
+            </artifact>
             <attachedArtifacts>
               <attachedArtifact
                   implementation="org.apache.maven.plugin.install.stubs.AttachedArtifactStub0"/>