3131
3232import net .sourceforge .pmd .PMD ;
3333import net .sourceforge .pmd .RuleSet ;
34- import net .sourceforge .pmd .RuleSets ;
3534import net .sourceforge .pmd .eclipse .core .internal .FileModificationUtil ;
3635import net .sourceforge .pmd .eclipse .plugin .PMDPlugin ;
3736import net .sourceforge .pmd .eclipse .runtime .cmd .JavaProjectClassLoader ;
4241import net .sourceforge .pmd .eclipse .runtime .writer .WriterException ;
4342import net .sourceforge .pmd .eclipse .ui .actions .RuleSetUtil ;
4443import net .sourceforge .pmd .eclipse .ui .actions .internal .InternalRuleSetUtil ;
45- import net .sourceforge .pmd .eclipse .util .IOUtil ;
4644
4745/**
4846 * Implementation of a project properties information structure
@@ -146,7 +144,7 @@ public void setPmdEnabled(final boolean pmdEnabled) {
146144 */
147145 @ Deprecated
148146 @ Override
149- public RuleSets getProjectRuleSets () throws PropertiesException {
147+ public net . sourceforge . pmd . RuleSets getProjectRuleSets () throws PropertiesException {
150148 return InternalRuleSetUtil .toRuleSets (projectRuleSets );
151149 }
152150
@@ -170,7 +168,7 @@ public void setProjectRuleSet(RuleSet projectRuleSet) throws PropertiesException
170168 */
171169 @ Override
172170 @ Deprecated
173- public void setProjectRuleSets (final RuleSets newProjectRuleSets ) throws PropertiesException {
171+ public void setProjectRuleSets (final net . sourceforge . pmd . RuleSets newProjectRuleSets ) throws PropertiesException {
174172 setProjectRuleSetList (Arrays .asList (newProjectRuleSets .getAllRuleSets ()));
175173 }
176174
@@ -357,11 +355,8 @@ private File getExistingFileOrNull(IFile file) {
357355 @ Override
358356 public void createDefaultRuleSetFile () throws PropertiesException {
359357 LOG .info ("Create a default rule set file for project " + this .project .getName ());
360- ByteArrayOutputStream baos = null ;
361- ByteArrayInputStream bais = null ;
362- try {
358+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream ()) {
363359 IRuleSetWriter writer = PMDPlugin .getDefault ().getRuleSetWriter ();
364- baos = new ByteArrayOutputStream ();
365360
366361 // create a single ruleset from all the rulesets
367362 // the ruleset writer is only capable of writing one ruleset
@@ -378,14 +373,12 @@ public void createDefaultRuleSetFile() throws PropertiesException {
378373 if (file .exists () && file .isAccessible ()) {
379374 throw new PropertiesException ("Project ruleset file already exists" );
380375 } else {
381- bais = new ByteArrayInputStream (baos .toByteArray ());
382- file .create (bais , true , null );
376+ try (ByteArrayInputStream bais = new ByteArrayInputStream (baos .toByteArray ())) {
377+ file .create (bais , true , null );
378+ }
383379 }
384- } catch (WriterException | CoreException e ) {
380+ } catch (IOException | WriterException | CoreException e ) {
385381 throw new PropertiesException ("Error while creating default ruleset file for project " + this .project .getName (), e );
386- } finally {
387- IOUtil .closeQuietly (baos );
388- IOUtil .closeQuietly (bais );
389382 }
390383 }
391384
0 commit comments