Author: lcorneliussen
Date: Wed Jul 25 14:04:59 2012
New Revision: 1365593

URL: http://svn.apache.org/viewvc?rev=1365593&view=rev
Log:
[NPANDAY-556] Importer for Nuget Packages

o some refactorings + better error messages

Added:
    
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/skeletons/AbstractHandleEachImportMojo.java
Modified:
    
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/AbstractManifestInfoMojo.java
    
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/ExtractNuspecFromPackagesMojo.java
    
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/GeneratePackageManifestInfosMojo.java
    
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/skeletons/AbstractHandleEachLibraryMojo.java

Modified: 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/AbstractManifestInfoMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/AbstractManifestInfoMojo.java?rev=1365593&r1=1365592&r2=1365593&view=diff
==============================================================================
--- 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/AbstractManifestInfoMojo.java
 (original)
+++ 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/AbstractManifestInfoMojo.java
 Wed Jul 25 14:04:59 2012
@@ -37,29 +37,5 @@ public abstract class AbstractManifestIn
      */
     protected NugetInvoker nugetInvoker;
 
-    /**
-     * The executable identifier used to locate the right configurations from 
executable-plugins.xml. Can't be changed.
-     */
-    private String executableIdentifier = "MANIFESTINFO";
-
-    /**
-     * The configured executable version, from executable-plugins.xml, to be 
used. Should align to a installed
-     * Azure SDK version.
-     *
-     * @parameter expression="${nuget.version}" default-value="1.0"
-     */
-    private String executableVersion;
-
-    /**
-     * The configured executable profile, from executable-plugins.xml, to be 
used.
-     *
-     * @parameter expression="${nuget.profile}"
-     */
-    private String executableProfile;
 
-    protected ExecutableRequirement getExecutableRequirement()
-    {
-        // TODO: profile is actually an identifier; the real profile has yet 
to be supported
-        return new ExecutableRequirement( getVendorRequirement(), 
executableIdentifier, executableVersion );
-    }
 }

Modified: 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/ExtractNuspecFromPackagesMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/ExtractNuspecFromPackagesMojo.java?rev=1365593&r1=1365592&r2=1365593&view=diff
==============================================================================
--- 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/ExtractNuspecFromPackagesMojo.java
 (original)
+++ 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/ExtractNuspecFromPackagesMojo.java
 Wed Jul 25 14:04:59 2012
@@ -20,6 +20,7 @@
 package npanday.plugin.libraryimporter.resolve;
 
 import npanday.plugin.libraryimporter.model.NugetPackage;
+import npanday.plugin.libraryimporter.skeletons.AbstractHandleEachImportMojo;
 import 
npanday.plugin.libraryimporter.skeletons.AbstractLibraryImportsProvidingMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
@@ -39,96 +40,80 @@ import java.util.zip.ZipInputStream;
  * @goal extract-nuspec
  */
 public class ExtractNuspecFromPackagesMojo
-    extends AbstractLibraryImportsProvidingMojo
+    extends AbstractHandleEachImportMojo
 {
     @Override
-    protected void innerExecute() throws MojoExecutionException, 
MojoFailureException
+    protected void handleNugetPackage( NugetPackage nuget ) throws 
MojoExecutionException, MojoFailureException
     {
-        super.innerExecute();
-
-        for ( NugetPackage nuget :  getNugetImports() )
+        FileInputStream zipFile = null;
+        try
         {
-            if ( nuget.getNuspecFile().exists() )
-            {
-                if ( getLog().isDebugEnabled() )
-                {
-                    getLog().debug(
-                        "NPANDAY-139-006: skipping nuspec extraction; does 
already exist " +  nuget.getNuspecFile()
-                    );
-                }
-                continue;
-            }
-
-            FileInputStream zipFile = null;
-            try
-            {
-                zipFile = new FileInputStream(  
nuget.getPackageFile().getAbsolutePath() );
-                ZipInputStream zip = new ZipInputStream( zipFile );
-                ZipEntry ze;
+            zipFile = new FileInputStream(  
nuget.getPackageFile().getAbsolutePath() );
+            ZipInputStream zip = new ZipInputStream( zipFile );
+            ZipEntry ze;
 
-                String foundSpec = null;
+            String foundSpec = null;
 
-                while ( ( ze = zip.getNextEntry() ) != null )
+            while ( ( ze = zip.getNextEntry() ) != null )
+            {
+                if ( ze.getName().endsWith( ".nuspec" ) )
                 {
-                    if ( ze.getName().endsWith( ".nuspec" ) )
-                    {
-                        foundSpec = ze.getName();
+                    foundSpec = ze.getName();
 
-                        byte[] buf = new byte[1024];
+                    byte[] buf = new byte[1024];
 
-                        FileOutputStream fileoutputstream = null;
-                        try
-                        {
-                            fileoutputstream = new FileOutputStream( 
nuget.getNuspecFile().getAbsolutePath() );
+                    FileOutputStream fileoutputstream = null;
+                    try
+                    {
+                        fileoutputstream = new FileOutputStream( 
nuget.getNuspecFile().getAbsolutePath() );
 
-                            int n;
-                            while ( ( n = zip.read( buf, 0, 1024 ) ) > -1 )
-                            {
-                                fileoutputstream.write( buf, 0, n );
-                            }
-                        }
-                        finally
+                        int n;
+                        while ( ( n = zip.read( buf, 0, 1024 ) ) > -1 )
                         {
-                            IOUtil.close( fileoutputstream );
+                            fileoutputstream.write( buf, 0, n );
                         }
-
-                        break;
                     }
-                }
-
-                if ( foundSpec == null )
-                {
-                    throw new MojoExecutionException(
-                        "NPANDAY-139-004: Could not find nuspec in package 
file " + nuget.getPackageFile()
-                    );
-                }
-                else
-                {
-                    if ( getLog().isDebugEnabled() )
+                    finally
                     {
-                        getLog().debug(
-                            "NPANDAY-139-005: found nuspec " + foundSpec + " 
and extracted to " + nuget.getNuspecFile()
-                        );
+                        IOUtil.close( fileoutputstream );
                     }
+
+                    break;
                 }
             }
-            catch ( FileNotFoundException e )
-            {
-                throw new MojoExecutionException(
-                    "NPANDAY-139-001: Could not find package file " + 
nuget.getPackageFile().getAbsolutePath()
-                );
-            }
-            catch ( IOException e )
+
+            if ( foundSpec == null )
             {
                 throw new MojoExecutionException(
-                    "NPANDAY-139-003: Error on reading or extracting zip 
contents of " + nuget.getPackageFile()
+                    "NPANDAY-139-004: Could not find nuspec in package file " 
+ nuget.getPackageFile()
                 );
             }
-            finally
+            else
             {
-                IOUtil.close( zipFile );
+                if ( getLog().isDebugEnabled() )
+                {
+                    getLog().debug(
+                        "NPANDAY-139-005: found nuspec " + foundSpec + " and 
extracted to " + nuget.getNuspecFile()
+                    );
+                }
             }
         }
+        catch ( FileNotFoundException e )
+        {
+            throw new MojoExecutionException(
+                "NPANDAY-139-001: Could not find package file " + 
nuget.getPackageFile().getAbsolutePath()
+            );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException(
+                "NPANDAY-139-003: Error on reading or extracting zip contents 
of " + nuget.getPackageFile()
+            );
+        }
+        finally
+        {
+            IOUtil.close( zipFile );
+        }
     }
 
 }

Modified: 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/GeneratePackageManifestInfosMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/GeneratePackageManifestInfosMojo.java?rev=1365593&r1=1365592&r2=1365593&view=diff
==============================================================================
--- 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/GeneratePackageManifestInfosMojo.java
 (original)
+++ 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/resolve/GeneratePackageManifestInfosMojo.java
 Wed Jul 25 14:04:59 2012
@@ -21,9 +21,12 @@ package npanday.plugin.libraryimporter.r
 
 import com.google.common.collect.Lists;
 import npanday.PlatformUnsupportedException;
+import npanday.executable.ExecutableRequirement;
 import npanday.executable.ExecutionException;
 import npanday.executable.NetExecutable;
 import npanday.plugin.libraryimporter.model.NugetPackage;
+import npanday.plugin.libraryimporter.skeletons.AbstractHandleEachImportMojo;
+import 
npanday.plugin.libraryimporter.skeletons.AbstractLibraryImportsProvidingMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 
@@ -36,64 +39,83 @@ import java.io.File;
  * @goal generate-package-manifestinfos
  */
 public class GeneratePackageManifestInfosMojo
-    extends AbstractManifestInfoMojo
+    extends AbstractHandleEachImportMojo
 {
-    @Override
-    protected void innerExecute() throws MojoExecutionException, 
MojoFailureException
+    /**
+     * The executable identifier used to locate the right configurations from 
executable-plugins.xml. Can't be changed.
+     */
+    private String executableIdentifier = "MANIFESTINFO";
+
+    /**
+     * The configured executable version, from executable-plugins.xml, to be 
used. Should align to a installed
+     * Azure SDK version.
+     *
+     * @parameter expression="${nuget.version}" default-value="1.0"
+     */
+    private String executableVersion;
+
+    /**
+     * The configured executable profile, from executable-plugins.xml, to be 
used.
+     *
+     * @parameter expression="${nuget.profile}"
+     */
+    private String executableProfile;
+
+    protected ExecutableRequirement getExecutableRequirement()
     {
-        super.innerExecute();
+        // TODO: profile is actually an identifier; the real profile has yet 
to be supported
+        return new ExecutableRequirement( getVendorRequirement(), 
executableIdentifier, executableVersion );
+    }
 
-        for ( NugetPackage nuget : getNugetImports() )
+    @Override
+    protected void handleNugetPackage( NugetPackage nuget ) throws 
MojoExecutionException, MojoFailureException
+    {
+        for ( File libDir : nuget.getLibraryDirectories() )
         {
-            for ( File libDir : nuget.getLibraryDirectories() )
-            {
-                File manifestInfoFile = new File( libDir, "manifestinfo.xml" );
-
-                if ( manifestInfoFile.exists() )
-                {
-                    if ( getLog().isDebugEnabled() )
-                    {
-                        getLog().debug(
-                            "NPANDAY-140-002: skipping; manifest info does 
already exist for " + libDir
-                        );
-                    }
-                    continue;
-                }
+            File manifestInfoFile = new File( libDir, "manifestinfo.xml" );
 
+            if ( manifestInfoFile.exists() )
+            {
                 if ( getLog().isDebugEnabled() )
                 {
                     getLog().debug(
-                        "NPANDAY-140-002: running manifestinfo for " + libDir
+                        "NPANDAY-140-002: skipping; manifest info does already 
exist for " + libDir
                     );
                 }
+                continue;
+            }
 
-                final NetExecutable executable;
-                try
-                {
+            if ( getLog().isDebugEnabled() )
+            {
+                getLog().debug(
+                    "NPANDAY-140-002: running manifestinfo for " + libDir
+                );
+            }
 
-                    executable = netExecutableFactory.getExecutable(
-                        getExecutableRequirement(), Lists.newArrayList(
-                        libDir.getAbsolutePath(), "-x", "-r", "-q", "-o", 
manifestInfoFile.getAbsolutePath()
-                    ), null
-                    );
+            final NetExecutable executable;
+            try
+            {
 
-                    executable.execute();
-                }
-                catch ( ExecutionException e )
-                {
-                    throw new MojoExecutionException(
-                        "NPANDAY-140-000: Error occured when running 
manifestinfo for " + libDir, e
-                    );
-                }
-                catch ( PlatformUnsupportedException e )
-                {
-                    throw new MojoExecutionException(
-                        "NPANDAY-140-001: Error occured when running 
manifestinfo for " + libDir, e
-                    );
-                }
+                executable = netExecutableFactory.getExecutable(
+                    getExecutableRequirement(), Lists.newArrayList(
+                    libDir.getAbsolutePath(), "-x", "-r", "-q", "-o", 
manifestInfoFile.getAbsolutePath()
+                ), null
+                );
+
+                executable.execute();
+            }
+            catch ( ExecutionException e )
+            {
+                throw new MojoExecutionException(
+                    "NPANDAY-140-000: Error occured when running manifestinfo 
for " + libDir, e
+                );
+            }
+            catch ( PlatformUnsupportedException e )
+            {
+                throw new MojoExecutionException(
+                    "NPANDAY-140-001: Error occured when running manifestinfo 
for " + libDir, e
+                );
             }
         }
-
     }
-
 }

Added: 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/skeletons/AbstractHandleEachImportMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/skeletons/AbstractHandleEachImportMojo.java?rev=1365593&view=auto
==============================================================================
--- 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/skeletons/AbstractHandleEachImportMojo.java
 (added)
+++ 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/skeletons/AbstractHandleEachImportMojo.java
 Wed Jul 25 14:04:59 2012
@@ -0,0 +1,57 @@
+/*
+ * 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.
+ */
+
+package npanday.plugin.libraryimporter.skeletons;
+
+import npanday.plugin.libraryimporter.model.NugetPackage;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * @author <a href="mailto:m...@lcorneliussen.de>Lars Corneliussen, Faktum 
Software</a>
+ */
+public abstract class AbstractHandleEachImportMojo
+    extends AbstractLibraryImportsProvidingMojo
+{
+
+    @Override
+    protected void innerExecute() throws MojoExecutionException, 
MojoFailureException
+    {
+        super.innerExecute();
+
+        for ( NugetPackage nuget : getNugetImports() )
+        {
+            getLog().debug( "NPANDAY-151-000: handling package " + 
nuget.toString() );
+            try {
+                handleNugetPackage(nuget);
+            }
+            catch (MojoExecutionException e){
+                throw new MojoExecutionException( "NPANDAY-151-001: error 
handling " + nuget.toString(), e);
+            }
+            catch (MojoFailureException e){
+                throw new MojoExecutionException( "NPANDAY-151-002: error 
handling " + nuget.toString(), e);
+            }
+            catch (Exception e){
+                throw new MojoExecutionException( "NPANDAY-151-003: error 
handling " + nuget.toString(), e);
+            }
+        }
+    }
+
+    protected abstract void handleNugetPackage( NugetPackage nuget ) throws 
MojoExecutionException, MojoFailureException;
+}

Modified: 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/skeletons/AbstractHandleEachLibraryMojo.java
URL: 
http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/skeletons/AbstractHandleEachLibraryMojo.java?rev=1365593&r1=1365592&r2=1365593&view=diff
==============================================================================
--- 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/skeletons/AbstractHandleEachLibraryMojo.java
 (original)
+++ 
incubator/npanday/trunk/plugins/library-importer-maven-plugin/src/main/java/npanday/plugin/libraryimporter/skeletons/AbstractHandleEachLibraryMojo.java
 Wed Jul 25 14:04:59 2012
@@ -28,23 +28,29 @@ import org.apache.maven.plugin.MojoFailu
  * @author <a href="mailto:m...@lcorneliussen.de>Lars Corneliussen, Faktum 
Software</a>
  */
 public abstract class AbstractHandleEachLibraryMojo
-    extends AbstractLibraryImportsProvidingMojo
+    extends AbstractHandleEachImportMojo
 {
-
     @Override
-    protected void innerExecute() throws MojoExecutionException, 
MojoFailureException
+    protected void handleNugetPackage( NugetPackage nuget) throws 
MojoExecutionException, MojoFailureException
     {
-        super.innerExecute();
-
-        for ( NugetPackage nuget : getNugetImports() )
+        for ( NugetPackageLibrary lib : nuget.getLibraries( getLog(), 
mavenProjectsCacheDirectory ) )
         {
-            for ( NugetPackageLibrary lib : nuget.getLibraries( getLog(), 
mavenProjectsCacheDirectory ) )
-            {
-
+            getLog().debug( "NPANDAY-152-000: handling lib " + lib.toString() 
);
+            try {
                 handleLibrary( lib );
             }
+            catch (MojoExecutionException e){
+                throw new MojoExecutionException( "NPANDAY-152-001: error 
handling " + lib.toString(), e);
+            }
+            catch (MojoFailureException e){
+                throw new MojoExecutionException( "NPANDAY-152-002: error 
handling " + lib.toString(), e);
+            }
+            catch (Exception e){
+                throw new MojoExecutionException( "NPANDAY-152-003: error 
handling " + lib.toString(), e);
+            }
         }
     }
 
     protected abstract void handleLibrary( NugetPackageLibrary lib ) throws 
MojoExecutionException, MojoFailureException;
 }
+


Reply via email to