DockerimageComponentToWorkspaceApplier implements ComponentToWorkspaceApplier { @VisibleForTesting static String toMachineName(String imageName) throws DevfileException { if (imageName.isEmpty()) { return imageName; } if (imageName.length() > Names.MAX_CONTAINER_NAME_LENGTH) { throw new DevfileException( format( "The image name '%s' is longer than 63 characters and as such cannot be used as a container" + " name. Please provide an alias for the component with that image.", imageName)); } String clean = imageName.replaceAll("[^-a-zA-Z0-9_]", "-"); if (isInvalidStartEndChar(clean.charAt(0)) || isInvalidStartEndChar(clean.charAt(clean.length() - 1))) { throw new DevfileException( format( "Cannot convert image %s to a valid component name." + " Please provide an alias that conforms to the Kubernetes label value format.", imageName)); } return clean; } @Inject  DockerimageComponentToWorkspaceApplier(
      @Named("che.workspace.projects.storage") String projectFolderPath,
      @Named("che.workspace.sidecar.image_pull_policy") String imagePullPolicy,
      KubernetesEnvironmentProvisioner k8sEnvProvisioner); @Override void apply(
      WorkspaceConfigImpl workspaceConfig,
      ComponentImpl dockerimageComponent,
      FileContentProvider contentProvider);  }
@Test(dataProvider = "imageNames") public void testGeneratesValidMachineNameFromImageName(String imageName) throws ValidationException, DevfileException { String machineName = DockerimageComponentToWorkspaceApplier.toMachineName(imageName); MachineConfigsValidator validator = new MachineConfigsValidator(); Map<String, InternalMachineConfig> configs = new HashMap<>(); configs.put(machineName, new InternalMachineConfig()); validator.validate(configs); }