Author: olamy
Date: Tue Apr 8 11:38:13 2014
New Revision: 1585690
URL: http://svn.apache.org/r1585690
Log:
try with resources
Modified:
archiva/redback/redback-components/trunk/modello-plugins/modello-db-keywords/src/main/java/org/apache/archiva/redback/components/modello/db/SQLReservedWords.java
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-jpox/src/main/java/org/apache/archiva/redback/components/modello/jpox/JPoxJdoMappingModelloGenerator.java
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-store/src/main/java/org/apache/archiva/redback/components/modello/plugin/store/AbstractVelocityModelloGenerator.java
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-store/src/main/java/org/apache/archiva/redback/components/modello/plugin/store/StoreModelloGenerator.java
Modified:
archiva/redback/redback-components/trunk/modello-plugins/modello-db-keywords/src/main/java/org/apache/archiva/redback/components/modello/db/SQLReservedWords.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/modello-plugins/modello-db-keywords/src/main/java/org/apache/archiva/redback/components/modello/db/SQLReservedWords.java?rev=1585690&r1=1585689&r2=1585690&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/modello-plugins/modello-db-keywords/src/main/java/org/apache/archiva/redback/components/modello/db/SQLReservedWords.java
(original)
+++
archiva/redback/redback-components/trunk/modello-plugins/modello-db-keywords/src/main/java/org/apache/archiva/redback/components/modello/db/SQLReservedWords.java
Tue Apr 8 11:38:13 2014
@@ -41,14 +41,13 @@ import java.util.Properties;
* SQLReservedWords - utility object to test against SQL Keywords.
*
* @author <a href="mailto:[email protected]">Joakim Erdfelt</a>
- *
* @plexus.component
role="org.apache.archiva.redback.components.modello.db.SQLReservedWords"
*/
public class SQLReservedWords
extends AbstractLogEnabled
implements Initializable
{
- private Map<String,List<KeywordSource>> keywords;
+ private Map<String, List<KeywordSource>> keywords;
/**
* Tests the provided word to see if it is a keyword.
@@ -74,7 +73,7 @@ public class SQLReservedWords
*
* @param word the word to test.
* @return the {@link List} of {@link KeywordSource} objects, or
<code>null</code> if specified word is
- * not a reserved word.
+ * not a reserved word.
*/
public List<KeywordSource> getKeywordSourceList( String word )
{
@@ -94,7 +93,7 @@ public class SQLReservedWords
*
* @param word the wor to test.
* @return the {@link String} of keyword source names seperated by commas,
or <code>null</code> if word is
- * not a reserved word.
+ * not a reserved word.
*/
public String getKeywordSourceString( String word )
{
@@ -150,11 +149,8 @@ public class SQLReservedWords
return;
}
- InputStream is = null;
-
- try
+ try (InputStream is = definitionsURL.openStream())
{
- is = definitionsURL.openStream();
props.load( is );
String sources[] = StringUtils.split( props.getProperty(
"keyword.sources" ), "," );
@@ -175,10 +171,6 @@ public class SQLReservedWords
getLogger().error( "Unable to load definitions file: " +
"keywords.properties", e );
return;
}
- finally
- {
- IOUtil.close( is );
- }
}
private void loadKeywordSource( String resource, KeywordSource source )
@@ -191,25 +183,24 @@ public class SQLReservedWords
return;
}
- InputStream is = null;
- InputStreamReader isr = null;
- BufferedReader reader = null;
-
- try
- {
- is = keywordsURL.openStream();
- isr = new InputStreamReader( is );
- reader = new BufferedReader( isr );
- String line = reader.readLine();
- while ( line != null )
+ try (InputStream is = keywordsURL.openStream() )
+ {
+ try (InputStreamReader isr = new InputStreamReader( is ))
{
- line = line.trim();
- if ( line.length() > 0 )
+ try (BufferedReader reader = new BufferedReader( isr ))
{
- addKeyword( line, source );
+ String line = reader.readLine();
+ while ( line != null )
+ {
+ line = line.trim();
+ if ( line.length() > 0 )
+ {
+ addKeyword( line, source );
+ }
+ line = reader.readLine();
+ }
}
- line = reader.readLine();
}
}
catch ( IOException e )
@@ -217,12 +208,6 @@ public class SQLReservedWords
getLogger().warn( "Unable to load keywords from " +
keywordsURL.toExternalForm() + ": " + e.getMessage(),
e );
}
- finally
- {
- IOUtil.close( reader );
- IOUtil.close( isr );
- IOUtil.close( is );
- }
}
private void addKeyword( String keyword, KeywordSource source )
Modified:
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-jpox/src/main/java/org/apache/archiva/redback/components/modello/jpox/JPoxJdoMappingModelloGenerator.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-jpox/src/main/java/org/apache/archiva/redback/components/modello/jpox/JPoxJdoMappingModelloGenerator.java?rev=1585690&r1=1585689&r2=1585690&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-jpox/src/main/java/org/apache/archiva/redback/components/modello/jpox/JPoxJdoMappingModelloGenerator.java
(original)
+++
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-jpox/src/main/java/org/apache/archiva/redback/components/modello/jpox/JPoxJdoMappingModelloGenerator.java
Tue Apr 8 11:38:13 2014
@@ -163,7 +163,8 @@ public class JPoxJdoMappingModelloGenera
{
throw new ModelloException(
"Error while creating parent directories for the file
" + "'" + packageJdo.getAbsolutePath()
- + "'." );
+ + "'."
+ );
}
}
@@ -182,84 +183,92 @@ public class JPoxJdoMappingModelloGenera
private void generatePackageJdo( File file, Model model )
throws IOException, ModelloException
{
- OutputStreamWriter fileWriter = new OutputStreamWriter( new
FileOutputStream( file ), "UTF-8" );
+ try (FileOutputStream fileOutputStream = new FileOutputStream( file ))
+ {
+ try (OutputStreamWriter fileWriter = new OutputStreamWriter(
fileOutputStream, "UTF-8" ))
+ {
- PrintWriter printWriter = new PrintWriter( fileWriter );
+ try (PrintWriter printWriter = new PrintWriter( fileWriter ))
+ {
- XMLWriter writer = new PrettyPrintXMLWriter( printWriter );
+ XMLWriter writer = new PrettyPrintXMLWriter( printWriter );
- Map<String, List<ModelClass>> classes = new HashMap<>();
+ Map<String, List<ModelClass>> classes = new HashMap<>();
- for ( Iterator<ModelClass> it = model.getClasses(
getGeneratedVersion() ).iterator(); it.hasNext(); )
- {
- ModelClass modelClass = it.next();
+ for ( Iterator<ModelClass> it = model.getClasses(
getGeneratedVersion() ).iterator();
+ it.hasNext(); )
+ {
+ ModelClass modelClass = it.next();
- JPoxClassMetadata jpoxMetadata =
- JPoxClassMetadata.class.cast( modelClass.getMetadata(
JPoxClassMetadata.ID ) );
+ JPoxClassMetadata jpoxMetadata =
+ JPoxClassMetadata.class.cast(
modelClass.getMetadata( JPoxClassMetadata.ID ) );
- if ( !jpoxMetadata.isEnabled() )
- {
- // Skip generation of those classes that are not enabled for
the jpox plugin.
- continue;
- }
+ if ( !jpoxMetadata.isEnabled() )
+ {
+ // Skip generation of those classes that are not
enabled for the jpox plugin.
+ continue;
+ }
- String packageName = modelClass.getPackageName(
isPackageWithVersion(), getGeneratedVersion() );
+ String packageName = modelClass.getPackageName(
isPackageWithVersion(), getGeneratedVersion() );
- List<ModelClass> list = classes.get( packageName );
+ List<ModelClass> list = classes.get( packageName );
- if ( list == null )
- {
- list = new ArrayList<>();
- }
+ if ( list == null )
+ {
+ list = new ArrayList<>();
+ }
- list.add( modelClass );
+ list.add( modelClass );
- classes.put( packageName, list );
- }
+ classes.put( packageName, list );
+ }
- printWriter.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" );
- printWriter.println();
- printWriter.println( "<!DOCTYPE jdo PUBLIC" );
- printWriter.println( " \"-//Sun Microsystems, Inc.//DTD Java Data
Objects Metadata 2.0//EN\"" );
- printWriter.println( " \"http://java.sun.com/dtd/jdo_2_0.dtd\">" );
- printWriter.println();
+ printWriter.println( "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>" );
+ printWriter.println();
+ printWriter.println( "<!DOCTYPE jdo PUBLIC" );
+ printWriter.println( " \"-//Sun Microsystems, Inc.//DTD
Java Data Objects Metadata 2.0//EN\"" );
+ printWriter.println( "
\"http://java.sun.com/dtd/jdo_2_0.dtd\">" );
+ printWriter.println();
- writer.startElement( "jdo" );
+ writer.startElement( "jdo" );
- for ( Map.Entry<String, List<ModelClass>> entry : classes.entrySet() )
- {
+ for ( Map.Entry<String, List<ModelClass>> entry :
classes.entrySet() )
+ {
- List<ModelClass> list = entry.getValue();
+ List<ModelClass> list = entry.getValue();
- if ( list.size() == 0 )
- {
- continue;
- }
+ if ( list.size() == 0 )
+ {
+ continue;
+ }
- String packageName = entry.getKey();
+ String packageName = entry.getKey();
- writer.startElement( "package" );
+ writer.startElement( "package" );
- writer.addAttribute( "name", packageName );
+ writer.addAttribute( "name", packageName );
- for ( ModelClass modelClass : list )
- {
- writeClass( writer, modelClass );
- }
+ for ( ModelClass modelClass : list )
+ {
+ writeClass( writer, modelClass );
+ }
- if ( packageName.equals( model.getDefaultPackageName(
isPackageWithVersion(), getGeneratedVersion() ) ) )
- {
- writeModelloMetadataClass( writer );
- }
+ if ( packageName.equals(
+ model.getDefaultPackageName(
isPackageWithVersion(), getGeneratedVersion() ) ) )
+ {
+ writeModelloMetadataClass( writer );
+ }
- writer.endElement(); // package
- }
+ writer.endElement(); // package
+ }
- writer.endElement(); // jdo
+ writer.endElement(); // jdo
- printWriter.println();
+ printWriter.println();
- printWriter.close();
+ }
+ }
+ }
}
private void writeClass( XMLWriter writer, ModelClass modelClass )
@@ -319,7 +328,8 @@ public class JPoxJdoMappingModelloGenera
{
throw new ModelloException(
"The JDO mapping generator does not support the
specified " + "class identity type '"
- + identityType + "'. " + "Supported types: " +
IDENTITY_TYPES );
+ + identityType + "'. " + "Supported types: " +
IDENTITY_TYPES
+ );
}
writer.addAttribute( "identity-type", identityType );
}
@@ -1139,7 +1149,8 @@ public class JPoxJdoMappingModelloGenera
{
throw new ModelloException(
"The JDO mapping generator does not support the specified
" + "value-strategy '" + valueStrategy
- + "'. " + "Supported types: " + VALUE_STRATEGY_LIST );
+ + "'. " + "Supported types: " + VALUE_STRATEGY_LIST
+ );
}
writer.addAttribute( "value-strategy", valueStrategy );
}
@@ -1313,7 +1324,8 @@ public class JPoxJdoMappingModelloGenera
{
throw new ModelloException(
"The JDO mapping generator does not support the specified " +
"field type '" + modelField.getType()
- + "'. " + "Supported types: " +
PRIMITIVE_IDENTITY_MAP.keySet() );
+ + "'. " + "Supported types: " +
PRIMITIVE_IDENTITY_MAP.keySet()
+ );
}
}
Modified:
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-store/src/main/java/org/apache/archiva/redback/components/modello/plugin/store/AbstractVelocityModelloGenerator.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-store/src/main/java/org/apache/archiva/redback/components/modello/plugin/store/AbstractVelocityModelloGenerator.java?rev=1585690&r1=1585689&r2=1585690&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-store/src/main/java/org/apache/archiva/redback/components/modello/plugin/store/AbstractVelocityModelloGenerator.java
(original)
+++
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-store/src/main/java/org/apache/archiva/redback/components/modello/plugin/store/AbstractVelocityModelloGenerator.java
Tue Apr 8 11:38:13 2014
@@ -148,12 +148,13 @@ public abstract class AbstractVelocityMo
try
{
- Writer writer = getEncoding() == null ?
WriterFactory.newPlatformWriter( file )
- : WriterFactory.newWriter( file, getEncoding() );
+ try (Writer writer = getEncoding() == null ?
WriterFactory.newPlatformWriter( file )
+ : WriterFactory.newWriter( file, getEncoding() ))
+ {
- template.merge( context, writer );
+ template.merge( context, writer );
+ }
- writer.close();
}
catch ( Exception e )
{
Modified:
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-store/src/main/java/org/apache/archiva/redback/components/modello/plugin/store/StoreModelloGenerator.java
URL:
http://svn.apache.org/viewvc/archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-store/src/main/java/org/apache/archiva/redback/components/modello/plugin/store/StoreModelloGenerator.java?rev=1585690&r1=1585689&r2=1585690&view=diff
==============================================================================
---
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-store/src/main/java/org/apache/archiva/redback/components/modello/plugin/store/StoreModelloGenerator.java
(original)
+++
archiva/redback/redback-components/trunk/modello-plugins/modello-plugin-store/src/main/java/org/apache/archiva/redback/components/modello/plugin/store/StoreModelloGenerator.java
Tue Apr 8 11:38:13 2014
@@ -101,14 +101,15 @@ public class StoreModelloGenerator
{
try
{
- Writer writer = getEncoding() == null ?
WriterFactory.newPlatformWriter( file )
- : WriterFactory.newWriter( file, getEncoding()
);
+ try (Writer writer = getEncoding() == null ?
WriterFactory.newPlatformWriter( file )
+ : WriterFactory.newWriter( file, getEncoding()
))
- velocity.getEngine().mergeTemplate( template, context, writer );
+ {
+ velocity.getEngine().mergeTemplate( template, context, writer
);
- writer.flush();
+ writer.flush();
- writer.close();
+ }
}
catch ( Exception e )
{