@@ -84,34 +84,51 @@ public MasterToSlaveCallable<String, IOException> getCallable(Run<?, ?> run, Str
8484 } catch (Exception e ) {
8585 listener .error ("Error retrieving environment: %s" , e .getMessage ());
8686 }
87- return new MasterToSlaveCallable <String , IOException >() {
88- @ Override
89- public String call () throws IOException {
90-
91- File file = new File (root , path );
92- if (!file .exists ()) {
93- return String .format (fileNotFoundMessage , path );
94- }
95-
96- try {
97- Charset charset = Charset .forName (charSet );
98- try (BufferedReader reader =
99- new BufferedReader (new InputStreamReader (new FileInputStream (file ), charset ))) {
100- if (maxLines > 0 ) {
101- return reader .lines ().limit (maxLines ).collect (Collectors .joining ("\n " ));
102- } else {
103- return reader .lines ().collect (Collectors .joining ("\n " ));
104- }
105- }
106- } catch (IOException e ) {
107- return "ERROR: File '" + path + "' could not be read" ;
108- }
109- }
110- };
87+ return new WorkspaceFileMasterToSlaveCallable (root , path , fileNotFoundMessage , charSet , maxLines );
11188 }
11289
11390 @ Override
11491 public boolean hasNestedContent () {
11592 return true ;
11693 }
94+
95+ private static class WorkspaceFileMasterToSlaveCallable extends MasterToSlaveCallable <String , IOException > {
96+ private final String root ;
97+ private final String path ;
98+ private final String fileNotFoundMessage ;
99+ private final String charSet ;
100+ private final int maxLines ;
101+
102+ public WorkspaceFileMasterToSlaveCallable (
103+ String root , String path , String fileNotFoundMessage , String charSet , int maxLines ) {
104+ this .root = root ;
105+ this .path = path ;
106+ this .fileNotFoundMessage = fileNotFoundMessage ;
107+ this .charSet = charSet ;
108+ this .maxLines = maxLines ;
109+ }
110+
111+ @ Override
112+ public String call () throws IOException {
113+
114+ File file = new File (root , path );
115+ if (!file .exists ()) {
116+ return String .format (fileNotFoundMessage , path );
117+ }
118+
119+ try {
120+ Charset charset = Charset .forName (charSet );
121+ try (BufferedReader reader =
122+ new BufferedReader (new InputStreamReader (new FileInputStream (file ), charset ))) {
123+ if (maxLines > 0 ) {
124+ return reader .lines ().limit (maxLines ).collect (Collectors .joining ("\n " ));
125+ } else {
126+ return reader .lines ().collect (Collectors .joining ("\n " ));
127+ }
128+ }
129+ } catch (IOException e ) {
130+ return "ERROR: File '" + path + "' could not be read" ;
131+ }
132+ }
133+ }
117134}
0 commit comments