plugins/org.wso2.developerstudio.eclipse.docker.distribution/src/org/wso2/developerstudio/eclipse/docker/distribution/ui/wizard/ContainerProjectCreationWizard.java
/**
     * Create new integration crd yaml file in the project directory if not exists.
     * 
     * @throws IOException
     *             An error occurred while writing the file
     */
Create new integration crd yaml file in the project directory if not exists.

@throws IOException
An error occurred while writing the file
Create new integration crd yaml file in the project directory if not exists . @throws IOException An error occurred while writing the file
private void copyKubeYamlFile() throws IOException {
        IFile kubeFile = project.getFile(DockerProjectConstants.KUBE_YAML_FILE_NAME);
        File newFile = new File(kubeFile.getLocationURI().getPath());
        if (!newFile.exists()) {
            YAMLFactory yamlFactory = new YAMLFactory();
            File file = kubeFile.getLocation().toFile();
            String imagePath = dockerModel.getKubeTargetRepository() + ":" + dockerModel.getKubeTargetTag();
            try (FileWriter fw = new FileWriter(file);) {
                YAMLGenerator yamlGenerator = yamlFactory.createGenerator(fw);
                yamlGenerator.writeStartObject();
                yamlGenerator.writeObjectField("apiVersion", "integration.wso2.com/v1alpha1");
                yamlGenerator.writeObjectField("kind", "Integration");
                yamlGenerator.writeFieldName("metadata");
                yamlGenerator.writeStartObject();
                yamlGenerator.writeObjectField("name", dockerModel.getKubeContainerName());
                yamlGenerator.writeEndObject();
                yamlGenerator.writeFieldName("spec");
                yamlGenerator.writeStartObject();
                yamlGenerator.writeObjectField("replicas", Integer.parseInt(dockerModel.getKubeReplicsas()));
                yamlGenerator.writeObjectField("image", imagePath);
                if (dockerModel.getKubernetesPortParameters().size() > 0) {
                    yamlGenerator.writeFieldName("inboundPorts");
                    yamlGenerator.writeStartArray();
                    for (Map.Entry<String, String> envMap : dockerModel.getKubernetesPortParameters().entrySet()) {
                        yamlGenerator.writeObject(Integer.parseInt(envMap.getKey()));
                    }
                    yamlGenerator.writeEndArray();
                }
                if (dockerModel.getKubernetesEnvParameters().size() > 0) {
                    yamlGenerator.writeFieldName("env");
                    yamlGenerator.writeStartArray();
                    for (Map.Entry<String, String> envMap : dockerModel.getKubernetesEnvParameters().entrySet()) {
                        yamlGenerator.writeStartObject();
                        yamlGenerator.writeObjectField("name", envMap.getKey());
                        yamlGenerator.writeObjectField("value", envMap.getValue());
                        yamlGenerator.writeEndObject();
                    }
                    yamlGenerator.writeEndArray();
                }
                yamlGenerator.writeEndObject();
                yamlGenerator.writeEndObject();
                yamlGenerator.flush();
                yamlGenerator.close();
            }
        }
    }
private void copyKubeYamlFile ( ) throws IOException { IFile kubeFile = project . getFile ( DockerProjectConstants . KUBE_YAML_FILE_NAME ) ; File newFile = new File ( kubeFile . getLocationURI ( ) . getPath ( ) ) ; if ( ! newFile . exists ( ) ) { YAMLFactory yamlFactory = new YAMLFactory ( ) ; File file = kubeFile . getLocation ( ) . toFile ( ) ; String imagePath = dockerModel . getKubeTargetRepository ( ) + ":" + dockerModel . getKubeTargetTag ( ) ; try ( FileWriter fw = new FileWriter ( file ) ; ) { YAMLGenerator yamlGenerator = yamlFactory . createGenerator ( fw ) ; yamlGenerator . writeStartObject ( ) ; yamlGenerator . writeObjectField ( "apiVersion" , "integration.wso2.com/v1alpha1" ) ; yamlGenerator . writeObjectField ( "kind" , "Integration" ) ; yamlGenerator . writeFieldName ( "metadata" ) ; yamlGenerator . writeStartObject ( ) ; yamlGenerator . writeObjectField ( "name" , dockerModel . getKubeContainerName ( ) ) ; yamlGenerator . writeEndObject ( ) ; yamlGenerator . writeFieldName ( "spec" ) ; yamlGenerator . writeStartObject ( ) ; yamlGenerator . writeObjectField ( "replicas" , Integer . parseInt ( dockerModel . getKubeReplicsas ( ) ) ) ; yamlGenerator . writeObjectField ( "image" , imagePath ) ; if ( dockerModel . getKubernetesPortParameters ( ) . size ( ) > 0 ) { yamlGenerator . writeFieldName ( "inboundPorts" ) ; yamlGenerator . writeStartArray ( ) ; for ( Map . Entry < String , String > envMap : dockerModel . getKubernetesPortParameters ( ) . entrySet ( ) ) { yamlGenerator . writeObject ( Integer . parseInt ( envMap . getKey ( ) ) ) ; } yamlGenerator . writeEndArray ( ) ; } if ( dockerModel . getKubernetesEnvParameters ( ) . size ( ) > 0 ) { yamlGenerator . writeFieldName ( "env" ) ; yamlGenerator . writeStartArray ( ) ; for ( Map . Entry < String , String > envMap : dockerModel . getKubernetesEnvParameters ( ) . entrySet ( ) ) { yamlGenerator . writeStartObject ( ) ; yamlGenerator . writeObjectField ( "name" , envMap . getKey ( ) ) ; yamlGenerator . writeObjectField ( "value" , envMap . getValue ( ) ) ; yamlGenerator . writeEndObject ( ) ; } yamlGenerator . writeEndArray ( ) ; } yamlGenerator . writeEndObject ( ) ; yamlGenerator . writeEndObject ( ) ; yamlGenerator . flush ( ) ; yamlGenerator . close ( ) ; } } }
Create new integration crd yaml file in the project directory if not exists.
Create new integration crd yaml file in the project directory if not exists .
// Creating the new yml file // check whether there are Inbound Ports given by user and append to the yaml // file // check whether there are ENV variables given by user and append to the yaml // file