@Test public void testThisClass() throws ManipulationException { ManifestUtils.getManifestInformation( ManifestUtilsTest.class ); assertTrue( systemRule.getLog() .contains( "Unable to retrieve manifest for class " + "org.commonjava.maven.ext.common.util.ManifestUtilsTest as " + "location is a directory not a jar" ) ); }
public static String getManifestInformation(Class<?> target) throws ManipulationException { String result = ""; if (target == null) { throw new ManipulationException( "No target specified." ); } try { final CodeSource cs = target.getProtectionDomain().getCodeSource(); if ( cs == null ) { logger.debug( "Unable to retrieve manifest for {} as CodeSource was null for the protection domain ({})", target, target.getProtectionDomain() ); } else { final URL jarUrl = cs.getLocation(); if ( new File( jarUrl.getPath() ).isDirectory() ) { logger.debug( "Unable to retrieve manifest for {} as location is a directory not a jar ({})", target, jarUrl.getPath() ); } else { try (JarInputStream jarStream = new JarInputStream( jarUrl.openStream() )) { final Manifest manifest = jarStream.getManifest(); result = manifest.getMainAttributes().getValue( "Implementation-Version" ); result += " ( SHA: " + manifest.getMainAttributes().getValue( "Scm-Revision" ) + " )"; } } } } catch ( final IOException e ) { throw new ManipulationException( "Error retrieving information from manifest", e ); } return result; }
ManifestUtils { public static String getManifestInformation(Class<?> target) throws ManipulationException { String result = ""; if (target == null) { throw new ManipulationException( "No target specified." ); } try { final CodeSource cs = target.getProtectionDomain().getCodeSource(); if ( cs == null ) { logger.debug( "Unable to retrieve manifest for {} as CodeSource was null for the protection domain ({})", target, target.getProtectionDomain() ); } else { final URL jarUrl = cs.getLocation(); if ( new File( jarUrl.getPath() ).isDirectory() ) { logger.debug( "Unable to retrieve manifest for {} as location is a directory not a jar ({})", target, jarUrl.getPath() ); } else { try (JarInputStream jarStream = new JarInputStream( jarUrl.openStream() )) { final Manifest manifest = jarStream.getManifest(); result = manifest.getMainAttributes().getValue( "Implementation-Version" ); result += " ( SHA: " + manifest.getMainAttributes().getValue( "Scm-Revision" ) + " )"; } } } } catch ( final IOException e ) { throw new ManipulationException( "Error retrieving information from manifest", e ); } return result; } }
ManifestUtils { public static String getManifestInformation(Class<?> target) throws ManipulationException { String result = ""; if (target == null) { throw new ManipulationException( "No target specified." ); } try { final CodeSource cs = target.getProtectionDomain().getCodeSource(); if ( cs == null ) { logger.debug( "Unable to retrieve manifest for {} as CodeSource was null for the protection domain ({})", target, target.getProtectionDomain() ); } else { final URL jarUrl = cs.getLocation(); if ( new File( jarUrl.getPath() ).isDirectory() ) { logger.debug( "Unable to retrieve manifest for {} as location is a directory not a jar ({})", target, jarUrl.getPath() ); } else { try (JarInputStream jarStream = new JarInputStream( jarUrl.openStream() )) { final Manifest manifest = jarStream.getManifest(); result = manifest.getMainAttributes().getValue( "Implementation-Version" ); result += " ( SHA: " + manifest.getMainAttributes().getValue( "Scm-Revision" ) + " )"; } } } } catch ( final IOException e ) { throw new ManipulationException( "Error retrieving information from manifest", e ); } return result; }  }
ManifestUtils { public static String getManifestInformation(Class<?> target) throws ManipulationException { String result = ""; if (target == null) { throw new ManipulationException( "No target specified." ); } try { final CodeSource cs = target.getProtectionDomain().getCodeSource(); if ( cs == null ) { logger.debug( "Unable to retrieve manifest for {} as CodeSource was null for the protection domain ({})", target, target.getProtectionDomain() ); } else { final URL jarUrl = cs.getLocation(); if ( new File( jarUrl.getPath() ).isDirectory() ) { logger.debug( "Unable to retrieve manifest for {} as location is a directory not a jar ({})", target, jarUrl.getPath() ); } else { try (JarInputStream jarStream = new JarInputStream( jarUrl.openStream() )) { final Manifest manifest = jarStream.getManifest(); result = manifest.getMainAttributes().getValue( "Implementation-Version" ); result += " ( SHA: " + manifest.getMainAttributes().getValue( "Scm-Revision" ) + " )"; } } } } catch ( final IOException e ) { throw new ManipulationException( "Error retrieving information from manifest", e ); } return result; }  static String getManifestInformation(Class<?> target); }
ManifestUtils { public static String getManifestInformation(Class<?> target) throws ManipulationException { String result = ""; if (target == null) { throw new ManipulationException( "No target specified." ); } try { final CodeSource cs = target.getProtectionDomain().getCodeSource(); if ( cs == null ) { logger.debug( "Unable to retrieve manifest for {} as CodeSource was null for the protection domain ({})", target, target.getProtectionDomain() ); } else { final URL jarUrl = cs.getLocation(); if ( new File( jarUrl.getPath() ).isDirectory() ) { logger.debug( "Unable to retrieve manifest for {} as location is a directory not a jar ({})", target, jarUrl.getPath() ); } else { try (JarInputStream jarStream = new JarInputStream( jarUrl.openStream() )) { final Manifest manifest = jarStream.getManifest(); result = manifest.getMainAttributes().getValue( "Implementation-Version" ); result += " ( SHA: " + manifest.getMainAttributes().getValue( "Scm-Revision" ) + " )"; } } } } catch ( final IOException e ) { throw new ManipulationException( "Error retrieving information from manifest", e ); } return result; }  static String getManifestInformation(Class<?> target);  }