Permalink
Browse files

o Reformatted code

  • Loading branch information...
1 parent f33eb29 commit 16cac3911af0483472ec451d595eeb616956489b @krosenvold committed Jan 20, 2012
View
100 src/main/java/org/codehaus/plexus/archiver/jar/JarArchiver.java
@@ -17,6 +17,30 @@
* limitations under the License.
*/
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.StringTokenizer;
+import java.util.TreeMap;
+import java.util.Vector;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.util.EnumeratedAttribute;
import org.codehaus.plexus.archiver.zip.ZipArchiver;
@@ -27,15 +51,12 @@
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.codehaus.plexus.util.IOUtil;
-import java.io.*;
-import java.util.*;
-
/**
* Base class for tasks that build archives in JAR file format.
*
* @version $Revision$ $Date$
*/
-@SuppressWarnings({"NullableProblems"})
+@SuppressWarnings( { "NullableProblems" } )
public class JarArchiver
extends ZipArchiver
{
@@ -265,7 +286,7 @@ private Manifest getManifest( Reader r )
*
* @param config setting for found manifest behavior.
*/
- @SuppressWarnings({"UnusedDeclaration"})
+ @SuppressWarnings( { "UnusedDeclaration" } )
public void setFilesetmanifest( FilesetManifestConfig config )
{
filesetManifestConfig = config;
@@ -279,7 +300,6 @@ public void setFilesetmanifest( FilesetManifestConfig config )
}
/**
- *
* @param indexJar The indexjar
*/
public void addConfiguredIndexJars( File indexJar )
@@ -388,7 +408,8 @@ protected void finalizeZipOutputStream( ZipOutputStream zOut )
* @param zOut the zip stream representing the jar being built.
* @throws IOException thrown if there is an error while creating the
* index and adding it to the zip stream.
- * @throws org.codehaus.plexus.archiver.ArchiverException .
+ * @throws org.codehaus.plexus.archiver.ArchiverException
+ * .
*/
private void createIndexList( ZipOutputStream zOut )
throws IOException, ArchiverException
@@ -665,8 +686,9 @@ public void reset()
/**
* Writes the directory entries from the first and the filenames
* from the second list to the given writer, one entry per line.
- * @param dirs The directories
- * @param files The files
+ *
+ * @param dirs The directories
+ * @param files The files
* @param writer The printwriter ;)
*/
protected final void writeIndexLikeList( List<String> dirs, List<String> files, PrintWriter writer )
@@ -722,11 +744,12 @@ protected final void writeIndexLikeList( List<String> dirs, List<String> files,
* <p/>
* <p>if there is a classpath and the given file doesn't match any
* of its entries, return null.</p>
- * @param fileName .
+ *
+ * @param fileName .
* @param classpath .
* @return The guessed name
*/
- protected static String findJarName( String fileName, String[] classpath )
+ protected static String findJarName( String fileName, String[] classpath )
{
if ( classpath == null )
{
@@ -738,55 +761,62 @@ protected static String findJarName( String fileName, String[] classpath )
// longest match comes first
public int compare( String o1, String o2 )
{
- if ( (o1 != null) && (o2 != null) )
+ if ( ( o1 != null ) && ( o2 != null ) )
{
- return o2 .length() - o1.length();
+ return o2.length() - o1.length();
}
return 0;
}
} );
- for (String aClasspath : classpath) {
- if (fileName.endsWith(aClasspath)) {
- matches.put(aClasspath, aClasspath);
- } else {
- int slash = aClasspath.indexOf("/");
+ for ( String aClasspath : classpath )
+ {
+ if ( fileName.endsWith( aClasspath ) )
+ {
+ matches.put( aClasspath, aClasspath );
+ }
+ else
+ {
+ int slash = aClasspath.indexOf( "/" );
String candidate = aClasspath;
- while (slash > -1) {
- candidate = candidate.substring(slash + 1);
- if (fileName.endsWith(candidate)) {
- matches.put(candidate, aClasspath);
+ while ( slash > -1 )
+ {
+ candidate = candidate.substring( slash + 1 );
+ if ( fileName.endsWith( candidate ) )
+ {
+ matches.put( candidate, aClasspath );
break;
}
- slash = candidate.indexOf("/");
+ slash = candidate.indexOf( "/" );
}
}
}
- return matches.size() == 0 ? null : matches.get( matches.firstKey() );
+ return matches.size() == 0 ? null : matches.get( matches.firstKey() );
}
/**
* Grab lists of all root-level files and all directories
* contained in the given archive.
- * @param file .
+ *
+ * @param file .
* @param files .
- * @param dirs .
- * @throws java.io.IOException
+ * @param dirs .
+ * @throws java.io.IOException .
*/
protected static void grabFilesAndDirs( String file, List<String> dirs, List<String> files )
throws IOException
{
- File zipFile = new File(file);
- if (!zipFile.exists())
+ File zipFile = new File( file );
+ if ( !zipFile.exists() )
{
Logger logger = new ConsoleLogger( Logger.LEVEL_INFO, "console" );
- logger.error("JarArchive skipping non-existing file: " + zipFile.getAbsolutePath());
+ logger.error( "JarArchive skipping non-existing file: " + zipFile.getAbsolutePath() );
}
- else if (zipFile.isDirectory())
+ else if ( zipFile.isDirectory() )
{
Logger logger = new ConsoleLogger( Logger.LEVEL_INFO, "console" );
- logger.info("JarArchiver skipping indexJar " + zipFile + " because it is not a jar");
+ logger.info( "JarArchiver skipping indexJar " + zipFile + " because it is not a jar" );
}
else
{
@@ -801,14 +831,14 @@ else if (zipFile.isDirectory())
ZipEntry ze = entries.nextElement();
String name = ze.getName();
// avoid index for manifest-only jars.
- if ( !name.equals( META_INF_NAME ) && !name.equals( META_INF_NAME + '/' )
- && !name.equals( INDEX_NAME ) && !name.equals( MANIFEST_NAME ) )
+ if ( !name.equals( META_INF_NAME ) && !name.equals( META_INF_NAME + '/' ) && !name.equals(
+ INDEX_NAME ) && !name.equals( MANIFEST_NAME ) )
{
if ( ze.isDirectory() )
{
dirSet.add( name );
}
- else if (!name.contains("/"))
+ else if ( !name.contains( "/" ) )
{
files.add( name );
}
View
84 src/main/java/org/codehaus/plexus/archiver/jar/Manifest.java
@@ -17,10 +17,9 @@
* limitations under the License.
*/
-import org.codehaus.plexus.archiver.ArchiverException;
-import org.codehaus.plexus.util.IOUtil;
-
import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -32,6 +31,8 @@
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.util.IOUtil;
/**
* Holds the data of a jar manifest.
@@ -48,39 +49,37 @@
*
* @since Ant 1.4
*/
-public class Manifest
+public class Manifest extends java.util.jar.Manifest
{
/**
* The standard manifest version header
*/
- public static final String ATTRIBUTE_MANIFEST_VERSION
- = "Manifest-Version";
+ public static final String ATTRIBUTE_MANIFEST_VERSION = ManifestConstants.ATTRIBUTE_MANIFEST_VERSION;
/**
* The standard Signature Version header
*/
- public static final String ATTRIBUTE_SIGNATURE_VERSION
- = "Signature-Version";
+ public static final String ATTRIBUTE_SIGNATURE_VERSION = ManifestConstants.ATTRIBUTE_SIGNATURE_VERSION;
/**
* The Name Attribute is the first in a named section
*/
- public static final String ATTRIBUTE_NAME = "Name";
+ public static final String ATTRIBUTE_NAME = ManifestConstants.ATTRIBUTE_NAME;
/**
* The From Header is disallowed in a Manifest
*/
- public static final String ATTRIBUTE_FROM = "From";
+ public static final String ATTRIBUTE_FROM = ManifestConstants.ATTRIBUTE_FROM;
/**
* The Class-Path Header is special - it can be duplicated
*/
- public static final String ATTRIBUTE_CLASSPATH = "Class-Path";
+ public static final String ATTRIBUTE_CLASSPATH = ManifestConstants.ATTRIBUTE_CLASSPATH;
/**
* Default Manifest version if one is not specified
*/
- public static final String DEFAULT_MANIFEST_VERSION = "1.0";
+ public static final String DEFAULT_MANIFEST_VERSION = ManifestConstants.DEFAULT_MANIFEST_VERSION;
/**
* The max length of a line in a Manifest
@@ -334,14 +333,14 @@ public void write( PrintWriter writer )
{
StringWriter sWriter = new StringWriter();
PrintWriter bufferWriter = new PrintWriter( sWriter );
-
+
for ( Enumeration e = getValues(); e.hasMoreElements(); )
{
writeValue( bufferWriter, (String) e.nextElement() );
}
-
+
byte[] convertedToUtf8 = sWriter.toString().getBytes( "UTF-8" );
-
+
writer.print( new String( convertedToUtf8, "UTF-8" ) );
}
@@ -383,8 +382,7 @@ private void writeLine( PrintWriter writer, String line )
// try to find a MAX_LINE_LENGTH byte section
int breakIndex = MAX_SECTION_LENGTH;
String section = line.substring( 0, breakIndex );
- while ( section.getBytes().length > MAX_SECTION_LENGTH
- && breakIndex > 0 )
+ while ( section.getBytes().length > MAX_SECTION_LENGTH && breakIndex > 0 )
{
breakIndex--;
section = line.substring( 0, breakIndex );
@@ -484,8 +482,8 @@ public String read( BufferedReader reader )
}
else
{
- throw new ManifestException( "Can't start an "
- + "attribute with a continuation line " + line );
+ throw new ManifestException(
+ "Can't start an " + "attribute with a continuation line " + line );
}
}
else
@@ -516,8 +514,8 @@ public String read( BufferedReader reader )
public void merge( Section section )
throws ManifestException
{
- if ( name == null && section.getName() != null || name != null
- && !( name.equalsIgnoreCase( section.getName() ) ) )
+ if ( name == null && section.getName() != null || name != null && !( name.equalsIgnoreCase(
+ section.getName() ) ) )
{
throw new ManifestException( "Unable to merge sections with different names" );
}
@@ -528,12 +526,12 @@ public void merge( Section section )
{
String attributeName = (String) e.nextElement();
Attribute attribute = section.getAttribute( attributeName );
- if ( attributeName.equalsIgnoreCase( ATTRIBUTE_CLASSPATH ) )
+ if ( attributeName.equalsIgnoreCase( ManifestConstants.ATTRIBUTE_CLASSPATH ) )
{
if ( classpathAttribute == null )
{
classpathAttribute = new Attribute();
- classpathAttribute.setName( ATTRIBUTE_CLASSPATH );
+ classpathAttribute.setName( ManifestConstants.ATTRIBUTE_CLASSPATH );
}
Enumeration cpe = attribute.getValues();
while ( cpe.hasMoreElements() )
@@ -652,9 +650,9 @@ public void addConfiguredAttribute( Attribute attribute )
String check = addAttributeAndCheck( attribute );
if ( check != null )
{
- throw new ManifestException( "Specify the section name using "
- + "the \"name\" attribute of the <section> element rather "
- + "than using a \"Name\" manifest attribute" );
+ throw new ManifestException(
+ "Specify the section name using " + "the \"name\" attribute of the <section> element rather "
+ + "than using a \"Name\" manifest attribute" );
}
}
@@ -676,37 +674,35 @@ public String addAttributeAndCheck( Attribute attribute )
}
if ( attribute.getKey().equalsIgnoreCase( ATTRIBUTE_NAME ) )
{
- warnings.addElement( "\"" + ATTRIBUTE_NAME + "\" attributes "
- + "should not occur in the main section and must be the "
- + "first element in all other sections: \""
- + attribute.getName() + ": " + attribute.getValue() + "\"" );
+ warnings.addElement(
+ "\"" + ATTRIBUTE_NAME + "\" attributes " + "should not occur in the main section and must be the "
+ + "first element in all other sections: \"" + attribute.getName() + ": " + attribute.getValue()
+ + "\"" );
return attribute.getValue();
}
if ( attribute.getKey().startsWith( ATTRIBUTE_FROM.toLowerCase() ) )
{
- warnings.addElement( "Manifest attributes should not start "
- + "with \"" + ATTRIBUTE_FROM + "\" in \""
- + attribute.getName() + ": " + attribute.getValue() + "\"" );
+ warnings.addElement( "Manifest attributes should not start " + "with \"" + ATTRIBUTE_FROM + "\" in \""
+ + attribute.getName() + ": " + attribute.getValue() + "\"" );
}
else
{
// classpath attributes go into a vector
String attributeKey = attribute.getKey();
- if ( attributeKey.equalsIgnoreCase( ATTRIBUTE_CLASSPATH ) )
+ if ( attributeKey.equalsIgnoreCase( ManifestConstants.ATTRIBUTE_CLASSPATH ) )
{
- Attribute classpathAttribute = attributes.get(attributeKey );
+ Attribute classpathAttribute = attributes.get( attributeKey );
if ( classpathAttribute == null )
{
storeAttribute( attribute );
}
else
{
- warnings.addElement( "Multiple Class-Path attributes "
- + "are supported but violate the Jar "
- + "specification and may not be correctly "
- + "processed in all environments" );
+ warnings.addElement( "Multiple Class-Path attributes " + "are supported but violate the Jar "
+ + "specification and may not be correctly "
+ + "processed in all environments" );
Enumeration e = attribute.getValues();
while ( e.hasMoreElements() )
{
@@ -717,9 +713,8 @@ public String addAttributeAndCheck( Attribute attribute )
}
else if ( attributes.containsKey( attributeKey ) )
{
- throw new ManifestException( "The attribute \""
- + attribute.getName() + "\" may not occur more "
- + "than once in the same section" );
+ throw new ManifestException( "The attribute \"" + attribute.getName() + "\" may not occur more "
+ + "than once in the same section" );
}
else
{
@@ -744,8 +739,7 @@ public Object clone()
{
String key = (String) e.nextElement();
Attribute attribute = getAttribute( key );
- cloned.storeAttribute( new Attribute( attribute.getName(),
- attribute.getValue() ) );
+ cloned.storeAttribute( new Attribute( attribute.getName(), attribute.getValue() ) );
}
return cloned;
}
@@ -1122,7 +1116,7 @@ public String toString()
*
* @return an enumeration of warning strings
*/
- public Enumeration getWarnings()
+ public Enumeration<String> getWarnings()
{
Vector<String> warnings = new Vector<String>();

0 comments on commit 16cac39

Please sign in to comment.