package io.quarkus.resteasy.deployment.devmode;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import io.quarkus.deployment.devmode.HotReplacementContext;
import io.quarkus.deployment.devmode.HotReplacementSetup;
import io.quarkus.resteasy.runtime.standalone.ResteasyStandaloneRecorder;

public class ResteasyHotReplacementSetup implements HotReplacementSetup {

    public static final String META_INF_SERVICES = "META-INF/resources";

    @Override
    public void setupHotDeployment(HotReplacementContext context) {
        List<Path> resources = new ArrayList<>();
        for (Path i : context.getResourcesDir()) {
            Path resolved = i.resolve(META_INF_SERVICES);
            if (Files.exists(resolved)) {
                resources.add(resolved);
            }
        }
        ResteasyStandaloneRecorder.setHotDeploymentResources(resources);
    }

    @Override
    public void handleFailedInitialStart() {
    }

    @Override
    public void close() {
        ResteasyStandaloneRecorder.setHotDeploymentResources(null);
    }
}

@@ -457,21 +457,22 @@
 ETA_INF_
-SERVI
+RESOUR
 CES = %22M
@@ -642,17 +642,27 @@
 r (Path 
-i
+resourceDir
  : conte
@@ -710,16 +710,26 @@
 reso
-lved = i
+urce = resourceDir
 .res
@@ -746,13 +746,14 @@
 INF_
-SERVI
+RESOUR
 CES)
@@ -787,20 +787,20 @@
 sts(reso
-lved
+urce
 )) %7B%0A   
@@ -834,12 +834,12 @@
 reso
-lved
+urce
 );%0A 

rename META_INF_SERVICES to META_INF_RESOURCES in ResteasyHotReplacementSetup