@@ -37,20 +37,18 @@ public class Controller {
3737
3838 private static final Path RECIPE_REPO = Paths .get ("/tmp" , "okd-build-controller" , "repo" );
3939 private static final JsonMapper MAPPER = new JsonMapper ();
40- // private final Thread watchThread;
41- private final AtomicBoolean running = new AtomicBoolean (false );
42- // private final String recipesDirectory;
43-
44- @ Inject
45- ManagedExecutor managedExecutor ;
4640
4741 @ Inject
4842 OpenShiftClient client ;
4943
5044 @ Inject
51- @ ConfigProperty (name = "controller.build-repo" )
45+ @ ConfigProperty (name = "controller.build-repo" , defaultValue = "https://github.com/okd-project/okd-operator-pipeline.git" )
5246 String buildRepo ;
5347
48+ @ Inject
49+ @ ConfigProperty (name = "controller.build-branch" , defaultValue = "master" )
50+ String buildBranch ;
51+
5452 @ Inject
5553 @ ConfigProperty (name = "controller.recipes.directory" , defaultValue = "recipes" )
5654 String recipesDirectory ;
@@ -71,6 +69,7 @@ void cloneRepo() throws IOException, GitAPIException {
7169 Git .cloneRepository ()
7270 .setURI (this .buildRepo )
7371 .setDirectory (RECIPE_REPO .toFile ())
72+ .setBranch (this .buildBranch )
7473 .call ()
7574 .close ();
7675 }
@@ -287,69 +286,75 @@ private boolean processComponent(Git git, String recipe, String version, Compone
287286
288287 Path gitDirectory = dataDirectory .resolve ("git" );
289288
290- Git componentGit ;
291- if (!RepositoryCache .FileKey .isGitRepository (gitDirectory .toFile (), FS .DETECTED )) {
292- if (Files .exists (gitDirectory )) {
289+ Git componentGit = null ;
290+ try {
291+ if (!RepositoryCache .FileKey .isGitRepository (gitDirectory .toFile (), FS .DETECTED )) {
292+ if (Files .exists (gitDirectory )) {
293+ try {
294+ Files .delete (gitDirectory );
295+ } catch (IOException e ) {
296+ throw new IllegalStateException ("Failed to delete git directory" , e );
297+ }
298+ }
293299 try {
294- Files .delete (gitDirectory );
295- } catch (IOException e ) {
296- throw new IllegalStateException ("Failed to delete git directory" , e );
300+ componentGit = Git .cloneRepository ()
301+ .setURI (component .getGitUrl ())
302+ .setDirectory (gitDirectory .toFile ())
303+ .setBranch (branch )
304+ .call ();
305+ } catch (GitAPIException e ) {
306+ throw new IllegalStateException ("Failed to clone repository" , e );
297307 }
298- }
299- try {
300- componentGit = Git .cloneRepository ()
301- .setURI (component .getGitUrl ())
302- .setDirectory (gitDirectory .toFile ())
303- .setBranch (branch )
304- .call ();
305- } catch (GitAPIException e ) {
306- throw new IllegalStateException ("Failed to clone repository" , e );
307- }
308- } else {
309- try {
310- componentGit = Git .open (gitDirectory .toFile ());
308+ } else {
309+ try {
310+ componentGit = Git .open (gitDirectory .toFile ());
311311
312- componentGit .pull ().call ();
313- } catch (IOException | GitAPIException e ) {
314- throw new IllegalStateException ("Failed to open git directory" , e );
312+ componentGit .pull ().call ();
313+ } catch (IOException | GitAPIException e ) {
314+ throw new IllegalStateException ("Failed to open git directory" , e );
315+ }
315316 }
316- }
317317
318- // Check if we need to create a new PipelineRun by polling the git repo
319- String hash = null ;
320- boolean runPipeline = false ;
321- try {
322- List <Ref > call = componentGit .branchList ().setListMode (ListBranchCommand .ListMode .REMOTE ).call ();
323- log .info ("Branches: {}" , call .stream ().map (Ref ::getName ).toList ());
324- for (Ref ref : call ) {
325- if (ref .getName ().equals ("refs/remotes/origin/" + branch )) {
326- hash = ref .getObjectId ().getName ();
327- break ;
318+ // Check if we need to create a new PipelineRun by polling the git repo
319+ String hash = null ;
320+ boolean runPipeline = false ;
321+ try {
322+ List <Ref > call = componentGit .branchList ().setListMode (ListBranchCommand .ListMode .REMOTE ).call ();
323+ log .info ("Branches: {}" , call .stream ().map (Ref ::getName ).toList ());
324+ for (Ref ref : call ) {
325+ if (ref .getName ().equals ("refs/remotes/origin/" + branch )) {
326+ hash = ref .getObjectId ().getName ();
327+ break ;
328+ }
328329 }
329- }
330330
331- if (hash == null ) {
332- log .error ("Branch {} not found" , branch );
333- throw new IllegalStateException ("Branch not found" );
334- }
331+ if (hash == null ) {
332+ log .error ("Branch {} not found" , branch );
333+ throw new IllegalStateException ("Branch not found" );
334+ }
335335
336- Path hashFile = dataDirectory .resolve ("hash" );
336+ Path hashFile = dataDirectory .resolve ("hash" );
337337
338- if (Files .notExists (hashFile )) {
339- Files .writeString (hashFile , hash );
340- runPipeline = true ;
341- } else {
342- String existingHash = Files .readString (hashFile );
343- if (!existingHash .equals (hash )) {
338+ if (Files .notExists (hashFile )) {
344339 Files .writeString (hashFile , hash );
345340 runPipeline = true ;
341+ } else {
342+ String existingHash = Files .readString (hashFile );
343+ if (!existingHash .equals (hash )) {
344+ Files .writeString (hashFile , hash );
345+ runPipeline = true ;
346+ }
346347 }
348+ } catch (GitAPIException | IOException e ) {
349+ throw new IllegalStateException ("Failed to get branch list" , e );
347350 }
348- } catch (GitAPIException | IOException e ) {
349- throw new IllegalStateException ("Failed to get branch list" , e );
350- }
351351
352- return runPipeline ;
352+ return runPipeline ;
353+ } finally {
354+ if (componentGit != null ) {
355+ componentGit .close ();
356+ }
357+ }
353358 }
354359
355360 private void buildComponent (String recipe , String version , ComponentRecipe component , String buildVersion ,
0 commit comments