8
8
package org .jboss .forge .addon .devtools .java ;
9
9
10
10
import java .io .File ;
11
- import java .io .FileInputStream ;
12
- import java .io .IOException ;
11
+ import java .io .InputStream ;
13
12
import java .util .ArrayList ;
14
13
import java .util .List ;
15
14
import java .util .Properties ;
35
34
import org .jboss .forge .addon .ui .util .Metadata ;
36
35
import org .jboss .forge .furnace .Furnace ;
37
36
import org .jboss .forge .furnace .container .simple .lifecycle .SimpleContainer ;
38
- import org .jboss .forge .roaster .Roaster ;
39
37
import org .jboss .forge .roaster .model .util .FormatterProfileReader ;
40
38
import org .jboss .forge .roaster .model .util .Strings ;
41
39
@@ -104,7 +102,7 @@ public void initializeUI(UIBuilder builder) throws Exception
104
102
105
103
@ SuppressWarnings ({ "rawtypes" })
106
104
@ Override
107
- public Result execute (UIExecutionContext context )
105
+ public Result execute (UIExecutionContext context ) throws Exception
108
106
{
109
107
XMLResource formatProfileLocation = profilepath .getValue ();
110
108
Iterable <FileResource > formatSources = sources .getValue ();
@@ -131,27 +129,21 @@ public Result execute(UIExecutionContext context)
131
129
132
130
else
133
131
{
134
- String formatterProfilePath = formatProfileLocation .getFullyQualifiedName ();
135
- FileInputStream fis ;
136
- FormatterProfileReader reader ;
137
-
138
- try
132
+ try (InputStream is = formatProfileLocation .getResourceInputStream ())
139
133
{
140
- fis = new FileInputStream (formatterProfilePath );
141
- reader = FormatterProfileReader .fromEclipseXml (fis );
134
+ FormatterProfileReader reader = FormatterProfileReader .fromEclipseXml (is );
142
135
formatProfile = reader .getPropertiesFor (formatterName );
143
-
144
- }
145
- catch (IOException e )
146
- {
147
- return Results .fail ("The profile xml could not be read" );
148
136
}
149
-
150
137
}
151
-
152
- format (fileResourceList , formatProfile );
153
-
154
- return Results .success ("Files Formatted Sucessfully" );
138
+ if (formatProfile != null )
139
+ {
140
+ format (fileResourceList , formatProfile );
141
+ return Results .success ("Files Formatted Sucessfully" );
142
+ }
143
+ else
144
+ {
145
+ return Results .fail ("No format profile found to be applied" );
146
+ }
155
147
}
156
148
157
149
// Formatting the file or folder(recursively).
@@ -169,18 +161,10 @@ private static void format(List<FileResource<?>> fileResourceList, Properties fo
169
161
170
162
format (newFileResourceList , formatProfile );
171
163
}
172
-
173
164
else if (fileResource instanceof JavaResource )
174
- {
175
-
176
- JavaResource file =fileResource .reify (JavaResource .class );
177
-
178
- if (formatProfile == null )
179
- file .setContents (fileResource .getResourceInputStream ());
180
-
181
- else
182
- file .setContents (fileResource .getResourceInputStream (),formatProfile );
183
-
165
+ {
166
+ JavaResource file = fileResource .reify (JavaResource .class );
167
+ file .setContents (fileResource .getResourceInputStream (), formatProfile );
184
168
}
185
169
}
186
170
0 commit comments