From d20b9a95117482a811c90df92c740b004438ea54 Mon Sep 17 00:00:00 2001 From: Michael Dick Date: Tue, 12 Apr 2011 03:17:16 +0000 Subject: [PATCH] OPENJPA-1934: Cleanup compiler warnings. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1091279 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/AbstractOpenJpaEnhancerMojo.java | 5 ++- .../maven/AbstractOpenJpaMappingToolMojo.java | 38 ++++++++----------- .../tools/maven/AbstractOpenJpaMojo.java | 25 ++++++------ .../tools/maven/OpenJpaTestEnhancerMojo.java | 4 +- .../tools/maven/OpenJpaEnhancerMojoTest.java | 2 +- 5 files changed, 33 insertions(+), 41 deletions(-) diff --git a/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaEnhancerMojo.java b/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaEnhancerMojo.java index 4303497db..6795de5eb 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaEnhancerMojo.java +++ b/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaEnhancerMojo.java @@ -26,6 +26,7 @@ import org.codehaus.plexus.util.FileUtils; import org.apache.openjpa.enhance.PCEnhancer; import org.apache.openjpa.lib.util.Options; +import java.io.File; import java.util.List; /** @@ -89,7 +90,7 @@ public abstract class AbstractOpenJpaEnhancerMojo extends AbstractOpenJpaMojo { FileUtils.mkdir(getEntityClasses().getAbsolutePath()); } - List entities = findEntityClassFiles(); + List entities = findEntityClassFiles(); enhance(entities); } @@ -117,7 +118,7 @@ public abstract class AbstractOpenJpaEnhancerMojo extends AbstractOpenJpaMojo { * @param files class file resources to enhance. * @throws MojoExecutionException if the enhancer encountered a failure */ - private void enhance(List files) throws MojoExecutionException { + private void enhance(List files) throws MojoExecutionException { Options opts = getOptions(); // list of input files diff --git a/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaMappingToolMojo.java b/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaMappingToolMojo.java index 5adeed2d1..be2b1e485 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaMappingToolMojo.java +++ b/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaMappingToolMojo.java @@ -19,10 +19,15 @@ package org.apache.openjpa.tools.maven; +import java.io.File; +import java.io.IOException; +import java.sql.SQLException; +import java.util.List; + +import javax.persistence.Entity; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.codehaus.plexus.util.FileUtils; - import org.apache.openjpa.enhance.PersistenceCapable; import org.apache.openjpa.jdbc.conf.JDBCConfiguration; import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl; @@ -31,14 +36,7 @@ import org.apache.openjpa.lib.conf.Configurations; import org.apache.openjpa.lib.meta.ClassArgParser; import org.apache.openjpa.lib.util.Options; import org.apache.openjpa.meta.MetaDataRepository; - -import java.io.File; -import java.io.IOException; -import java.sql.SQLException; -import java.util.Iterator; -import java.util.List; - -import javax.persistence.Entity; +import org.codehaus.plexus.util.FileUtils; /** * Processes Application model classes and generate the DDL by running the @@ -78,7 +76,7 @@ public abstract class AbstractOpenJpaMappingToolMojo extends AbstractOpenJpaMojo FileUtils.mkdir(getEntityClasses().getAbsolutePath()); } - List entities = findEntityClassFiles(); + List entities = findEntityClassFiles(); mappingTool(entities); } @@ -90,7 +88,7 @@ public abstract class AbstractOpenJpaMappingToolMojo extends AbstractOpenJpaMojo * @param files class file resources to map. * @throws MojoExecutionException if the MappingTool detected an error */ - private void mappingTool(List files) throws MojoExecutionException { + private void mappingTool(List files) throws MojoExecutionException { extendRealmClasspath(); Options opts = getOptions(); @@ -126,23 +124,20 @@ public abstract class AbstractOpenJpaMappingToolMojo extends AbstractOpenJpaMojo * @param files List with classPath Files; non persistence classes will be removed * @param opts filled configuration Options */ - private void filterPersistenceCapable(List files, Options opts) { + private void filterPersistenceCapable(List files, Options opts) { JDBCConfiguration conf = new JDBCConfigurationImpl(); Configurations.populateConfiguration(conf, opts); MetaDataRepository repo = conf.newMetaDataRepositoryInstance(); ClassArgParser cap = repo.getMetaDataFactory().newClassArgParser(); - Iterator fileIt = files.iterator(); - while (fileIt.hasNext()) { - File classPath = (File) fileIt.next(); - - Class[] classes = cap.parseTypes(classPath.getAbsolutePath()); + for(File classPath : files) { + Class[] classes = cap.parseTypes(classPath.getAbsolutePath()); if (classes == null) { getLog().info("Found no classes for " + classPath.getAbsolutePath()); } else { for (int i = 0; i < classes.length; i++) { - Class cls = classes[i]; + Class cls = classes[i]; if (cls.getAnnotation(Entity.class) != null) { getLog().debug("Found @Entity in class " + classPath); @@ -151,7 +146,6 @@ public abstract class AbstractOpenJpaMappingToolMojo extends AbstractOpenJpaMojo + PersistenceCapable.class.getName()); } else { getLog().debug("Removing non-entity class " + classPath); - fileIt.remove(); } } } @@ -163,9 +157,9 @@ public abstract class AbstractOpenJpaMappingToolMojo extends AbstractOpenJpaMojo * @param cls the Class to check * @return true if the given Class cls implements the interface {@link PersistenceCapable} */ - private boolean implementsPersistenceCapable(Class cls) { + private boolean implementsPersistenceCapable(Class cls) { boolean isPersistenceCapable = false; - Class[] interfaces = cls.getInterfaces(); + Class[] interfaces = cls.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (interfaces[i].getName().equals(PersistenceCapable.class.getName())) { isPersistenceCapable = true; diff --git a/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaMojo.java b/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaMojo.java index ad8761ded..ddb72fe49 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaMojo.java +++ b/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/AbstractOpenJpaMojo.java @@ -25,16 +25,14 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Properties; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.FileUtils; - import org.apache.openjpa.lib.util.Options; +import org.codehaus.plexus.util.FileUtils; /** * Base class for OpenJPA maven tasks. @@ -141,7 +139,7 @@ public abstract class AbstractOpenJpaMojo extends AbstractMojo * @required * @readonly */ - protected List compileClasspathElements; + protected List compileClasspathElements; /** * Setting this parameter to true will force @@ -199,7 +197,7 @@ public abstract class AbstractOpenJpaMojo extends AbstractMojo * This function retrieves the injected classpath elements for the current mojo. * @return List of classpath elements for the compile phase */ - protected List getClasspathElements() + protected List getClasspathElements() { return compileClasspathElements; } @@ -278,11 +276,10 @@ public abstract class AbstractOpenJpaMojo extends AbstractMojo protected void extendRealmClasspath() throws MojoExecutionException { - List urls = new ArrayList(); + List urls = new ArrayList(); - for ( Iterator itor = getClasspathElements().iterator(); itor.hasNext(); ) - { - File pathElem = new File( (String) itor.next() ); + for(String fileName: getClasspathElements()) { + File pathElem = new File(fileName); try { URL url = pathElem.toURI().toURL(); @@ -310,13 +307,13 @@ public abstract class AbstractOpenJpaMojo extends AbstractMojo * @throws MojoExecutionException if there was an error scanning class file * resources. */ - protected List findEntityClassFiles() throws MojoExecutionException + protected List findEntityClassFiles() throws MojoExecutionException { - List files = new ArrayList(); + List files = new ArrayList(); try { - files = FileUtils.getFiles( getEntityClasses(), includes, excludes ); + files = (List) FileUtils.getFiles( getEntityClasses(), includes, excludes ); } catch ( IOException e ) { @@ -331,12 +328,12 @@ public abstract class AbstractOpenJpaMojo extends AbstractMojo * @param files List of files * @return the paths of the given files as String[] */ - protected String[] getFilePaths( List files ) + protected String[] getFilePaths( List files ) { String[] args = new String[ files.size() ]; for ( int i = 0; i < files.size(); i++ ) { - File file = (File) files.get( i ); + File file = files.get( i ); args[ i ] = file.getAbsolutePath(); } diff --git a/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/OpenJpaTestEnhancerMojo.java b/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/OpenJpaTestEnhancerMojo.java index a1d642637..70da970f9 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/OpenJpaTestEnhancerMojo.java +++ b/openjpa-tools/openjpa-maven-plugin/src/main/java/org/apache/openjpa/tools/maven/OpenJpaTestEnhancerMojo.java @@ -43,7 +43,7 @@ public class OpenJpaTestEnhancerMojo extends AbstractOpenJpaEnhancerMojo { * @required * @readonly */ - protected List testClasspathElements; + protected List testClasspathElements; /** * This is where compiled test classes go. @@ -70,7 +70,7 @@ public class OpenJpaTestEnhancerMojo extends AbstractOpenJpaEnhancerMojo { * * @return List of classpath elements for the test phase */ - protected List getClasspathElements() { + protected List getClasspathElements() { return testClasspathElements; } diff --git a/openjpa-tools/openjpa-maven-plugin/src/test/java/org/apache/openjpa/tools/maven/OpenJpaEnhancerMojoTest.java b/openjpa-tools/openjpa-maven-plugin/src/test/java/org/apache/openjpa/tools/maven/OpenJpaEnhancerMojoTest.java index 8cae9894c..748d74d44 100644 --- a/openjpa-tools/openjpa-maven-plugin/src/test/java/org/apache/openjpa/tools/maven/OpenJpaEnhancerMojoTest.java +++ b/openjpa-tools/openjpa-maven-plugin/src/test/java/org/apache/openjpa/tools/maven/OpenJpaEnhancerMojoTest.java @@ -42,7 +42,7 @@ public class OpenJpaEnhancerMojoTest extends AbstractMojoTestCase { assertNotNull( mojo ); mojo.classes = new File( getBasedir(), "target/test-classes/" ); - mojo.compileClasspathElements = new ArrayList(); + mojo.compileClasspathElements = new ArrayList(); mojo.compileClasspathElements.add( mojo.classes.getAbsolutePath() ); mojo.execute();