You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2016/09/11 12:23:46 UTC
svn commit: r1760245 -
/maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
Author: khmarbaise
Date: Sun Sep 11 12:23:46 2016
New Revision: 1760245
URL: http://svn.apache.org/viewvc?rev=1760245&view=rev
Log:
Refactored code.
Modified:
maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
Modified: maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java?rev=1760245&r1=1760244&r2=1760245&view=diff
==============================================================================
--- maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java (original)
+++ maven/plugins/trunk/maven-install-plugin/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java Sun Sep 11 12:23:46 2016
@@ -197,86 +197,7 @@ public class InstallFileMojo
}
else
{
- boolean foundPom = false;
-
- JarFile jarFile = null;
- try
- {
- Pattern pomEntry = Pattern.compile( "META-INF/maven/.*/pom\\.xml" );
-
- jarFile = new JarFile( file );
-
- Enumeration<JarEntry> jarEntries = jarFile.entries();
-
- while ( jarEntries.hasMoreElements() )
- {
- JarEntry entry = jarEntries.nextElement();
-
- if ( pomEntry.matcher( entry.getName() ).matches() )
- {
- getLog().debug( "Using " + entry.getName() + " as pomFile" );
-
- foundPom = true;
-
- InputStream pomInputStream = null;
- OutputStream pomOutputStream = null;
-
- try
- {
- pomInputStream = jarFile.getInputStream( entry );
-
- String base = file.getName();
- if ( base.indexOf( '.' ) > 0 )
- {
- base = base.substring( 0, base.lastIndexOf( '.' ) );
- }
- pomFile = new File( file.getParentFile(), base + ".pom" );
-
- pomOutputStream = new FileOutputStream( pomFile );
-
- IOUtil.copy( pomInputStream, pomOutputStream );
-
- pomOutputStream.close();
- pomOutputStream = null;
-
- pomInputStream.close();
- pomInputStream = null;
-
- processModel( readModel( pomFile ) );
-
- break;
- }
- finally
- {
- IOUtil.close( pomInputStream );
- IOUtil.close( pomOutputStream );
- }
- }
- }
-
- if ( !foundPom )
- {
- getLog().info( "pom.xml not found in " + file.getName() );
- }
- }
- catch ( IOException e )
- {
- // ignore, artifact not packaged by Maven
- }
- finally
- {
- if ( jarFile != null )
- {
- try
- {
- jarFile.close();
- }
- catch ( IOException e )
- {
- // we did our best
- }
- }
- }
+ readingPomFromJarFile();
}
validateArtifactInformation();
@@ -387,6 +308,91 @@ public class InstallFileMojo
installChecksums( metadataFiles );
}
+ private void readingPomFromJarFile()
+ throws MojoExecutionException
+ {
+ boolean foundPom = false;
+
+ JarFile jarFile = null;
+ try
+ {
+ Pattern pomEntry = Pattern.compile( "META-INF/maven/.*/pom\\.xml" );
+
+ jarFile = new JarFile( file );
+
+ Enumeration<JarEntry> jarEntries = jarFile.entries();
+
+ while ( jarEntries.hasMoreElements() )
+ {
+ JarEntry entry = jarEntries.nextElement();
+
+ if ( pomEntry.matcher( entry.getName() ).matches() )
+ {
+ getLog().debug( "Using " + entry.getName() + " as pomFile" );
+
+ foundPom = true;
+
+ InputStream pomInputStream = null;
+ OutputStream pomOutputStream = null;
+
+ try
+ {
+ pomInputStream = jarFile.getInputStream( entry );
+
+ String base = file.getName();
+ if ( base.indexOf( '.' ) > 0 )
+ {
+ base = base.substring( 0, base.lastIndexOf( '.' ) );
+ }
+ pomFile = new File( file.getParentFile(), base + ".pom" );
+
+ pomOutputStream = new FileOutputStream( pomFile );
+
+ IOUtil.copy( pomInputStream, pomOutputStream );
+
+ pomOutputStream.close();
+ pomOutputStream = null;
+
+ pomInputStream.close();
+ pomInputStream = null;
+
+ processModel( readModel( pomFile ) );
+
+ break;
+ }
+ finally
+ {
+ IOUtil.close( pomInputStream );
+ IOUtil.close( pomOutputStream );
+ }
+ }
+ }
+
+ if ( !foundPom )
+ {
+ getLog().info( "pom.xml not found in " + file.getName() );
+ }
+ }
+ catch ( IOException e )
+ {
+ // ignore, artifact not packaged by Maven
+ }
+ finally
+ {
+ if ( jarFile != null )
+ {
+ try
+ {
+ jarFile.close();
+ }
+ catch ( IOException e )
+ {
+ // we did our best
+ }
+ }
+ }
+ }
+
/**
* Parses a POM.
*