Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses try with resources #45

Merged
merged 2 commits into from Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -38,7 +38,6 @@
import com.thoughtworks.qdox.parser.ParseException;
import com.thoughtworks.qdox.type.TypeResolver;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
Expand All @@ -55,7 +54,6 @@
import org.codehaus.plexus.components.interactivity.InputHandler;
import org.codehaus.plexus.languages.java.version.JavaVersion;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;

Expand Down Expand Up @@ -91,7 +89,7 @@
/**
* Abstract class to fix Javadoc documentation and tags in source files.
* <br>
* See <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#wheretags">Where Tags
* See <a href="https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#wheretags">Where Tags
* Can Be Used</a>.
*
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
Expand Down Expand Up @@ -771,10 +769,8 @@ private void parseClirrTextOutputFile( File clirrTextOutputFile )
clirrNewClasses = new LinkedList<>();
clirrNewMethods = new LinkedHashMap<>();

BufferedReader reader = null;
try
try ( BufferedReader reader = new BufferedReader( ReaderFactory.newReader( clirrTextOutputFile, "UTF-8" ) ) )
{
reader = new BufferedReader( ReaderFactory.newReader( clirrTextOutputFile, "UTF-8" ) );

for ( String line = reader.readLine(); line != null; line = reader.readLine() )
{
Expand Down Expand Up @@ -849,13 +845,6 @@ private void parseClirrTextOutputFile( File clirrTextOutputFile )
}
// CHECKSTYLE_ON: MagicNumber
}

reader.close();
reader = null;
}
finally
{
IOUtils.closeQuietly( reader );
}
if ( clirrNewClasses.isEmpty() && clirrNewMethods.isEmpty() )
{
Expand Down Expand Up @@ -1025,11 +1014,9 @@ private void processFix( JavaClass javaClass )
}

final StringWriter stringWriter = new StringWriter();
BufferedReader reader = null;
boolean changeDetected = false;
try
try ( BufferedReader reader = new BufferedReader( new StringReader( originalContent ) ) )
{
reader = new BufferedReader( new StringReader( originalContent ) );

int lineNumber = 0;
for ( String line = reader.readLine(); line != null; line = reader.readLine() )
Expand Down Expand Up @@ -1106,13 +1093,6 @@ else if ( lineNumber == javaClass.getLineNumber() )
stringWriter.write( line );
stringWriter.write( EOL );
}

reader.close();
reader = null;
}
finally
{
IOUtil.close( reader );
}

if ( changeDetected )
Expand Down Expand Up @@ -3068,19 +3048,18 @@ private static String getFullClirrGoal()
sb.append( CLIRR_MAVEN_PLUGIN_GROUPID ).append( ":" ).append( CLIRR_MAVEN_PLUGIN_ARTIFACTID ).append( ":" );

String clirrVersion = CLIRR_MAVEN_PLUGIN_VERSION;
InputStream resourceAsStream = null;
try

String resource = "META-INF/maven/" + CLIRR_MAVEN_PLUGIN_GROUPID + "/" + CLIRR_MAVEN_PLUGIN_ARTIFACTID
+ "/pom.properties";

try ( InputStream resourceAsStream =
AbstractFixJavadocMojo.class.getClassLoader().getResourceAsStream( resource ) )
{
String resource = "META-INF/maven/" + CLIRR_MAVEN_PLUGIN_GROUPID + "/" + CLIRR_MAVEN_PLUGIN_ARTIFACTID
+ "/pom.properties";
resourceAsStream = AbstractFixJavadocMojo.class.getClassLoader().getResourceAsStream( resource );

if ( resourceAsStream != null )
{
Properties properties = new Properties();
properties.load( resourceAsStream );
resourceAsStream.close();
resourceAsStream = null;
if ( StringUtils.isNotEmpty( properties.getProperty( "version" ) ) )
{
clirrVersion = properties.getProperty( "version" );
Expand All @@ -3091,10 +3070,6 @@ private static String getFullClirrGoal()
{
// nop
}
finally
{
IOUtil.close( resourceAsStream );
}

sb.append( clirrVersion ).append( ":" ).append( CLIRR_MAVEN_PLUGIN_GOAL );

Expand Down Expand Up @@ -3137,7 +3112,7 @@ private static String getDefaultClassJavadocComment( final JavaClass javaClass )
* Default comment for method with taking care of getter/setter in the javaMethod name.
*
* @param javaExecutable not null
* @return a default comment for method.
* @return a default comment for method
*/
private static String getDefaultMethodJavadocComment( final JavaExecutable javaExecutable )
{
Expand Down