Refactor SME swagger generation and remove OS profiles

SME swagger generation logic moved to go. OS based files removed.
OS based profile handling in maven removed.

Issue-ID: NONRTRIC-986
Change-Id: Ic33050488843fbd5400cb754092e0630ba40dc03
Signed-off-by: aravind.est <aravindhan.a@est.tech>
diff --git a/pom.xml b/pom.xml
index 79d2934..f392133 100755
--- a/pom.xml
+++ b/pom.xml
@@ -63,34 +63,9 @@
         <slf4j.version>2.0.12</slf4j.version>
         <apache.httpcore.version>4.4.16</apache.httpcore.version>
         <exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
+        <copy-resources-maven-plugin.version>3.3.1</copy-resources-maven-plugin.version>
         <apache.compress.version>1.25.0</apache.compress.version>
     </properties>
-    <profiles>
-        <profile>
-            <id>Windows</id>
-            <activation>
-                <os>
-                    <family>Windows</family>
-                </os>
-            </activation>
-            <properties>
-                <script.extension>.bat</script.extension>
-                <file.separator>\</file.separator>
-            </properties>
-        </profile>
-        <profile>
-            <id>unix</id>
-            <activation>
-                <os>
-                    <family>unix</family>
-                </os>
-            </activation>
-            <properties>
-                <script.extension>.sh</script.extension>
-                <file.separator>/</file.separator>
-            </properties>
-        </profile>
-    </profiles>
     <build>
         <plugins>
             <plugin>
diff --git a/rapp-manager-sme/pom.xml b/rapp-manager-sme/pom.xml
index eb82cfa..dd877d2 100755
--- a/rapp-manager-sme/pom.xml
+++ b/rapp-manager-sme/pom.xml
@@ -96,14 +96,46 @@
                     </execution>
                     <execution>
                         <id>initialize-sme-openapi-specs</id>
-                        <phase>initialize</phase>
+                        <phase>generate-sources</phase>
                         <goals>
                             <goal>exec</goal>
                         </goals>
                         <configuration>
+                            <workingDirectory>
+                                ${project.parent.basedir}/sme/capifcore
+                            </workingDirectory>
                             <executable>
-                                ..${file.separator}scripts${file.separator}init${file.separator}init-sme-spec${script.extension}
+                                go
                             </executable>
+                            <arguments>
+                                <argument>run</argument>
+                                <argument>getsmeswagger.go</argument>
+                            </arguments>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>${copy-resources-maven-plugin.version}</version>
+                <executions>
+                    <execution>
+                        <id>copy-swagger-generator</id>
+                        <phase>initialize</phase>
+                        <goals>
+                            <goal>copy-resources</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.parent.basedir}/sme/capifcore</outputDirectory>
+                            <resources>
+                                <resource>
+                                    <directory>${project.parent.basedir}/scripts/init/</directory>
+                                    <includes>
+                                        <include>getsmeswagger.go</include>
+                                    </includes>
+                                    <filtering>false</filtering>
+                                </resource>
+                            </resources>
                         </configuration>
                     </execution>
                 </executions>
diff --git a/scripts/init/getsmeswagger.go b/scripts/init/getsmeswagger.go
index 65826a2..0e2c8ce 100755
--- a/scripts/init/getsmeswagger.go
+++ b/scripts/init/getsmeswagger.go
@@ -3,6 +3,7 @@
 //   O-RAN-SC
 //   %%
 //   Copyright (C) 2023: Nordix Foundation
+//   Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved.
 //   %%
 //   Licensed under the Apache License, Version 2.0 (the "License");
 //   you may not use this file except in compliance with the License.
@@ -20,76 +21,83 @@
 
 package main
 
-
 import (
+	"encoding/json"
+	"fmt"
 	"github.com/getkin/kin-openapi/openapi3"
 	log "github.com/sirupsen/logrus"
 	"gopkg.in/yaml.v3"
-	"encoding/json"
-	 "io/ioutil"
+	"io/ioutil"
+	"os"
 
+	"oransc.org/nonrtric/capifcore/internal/common"
+	"oransc.org/nonrtric/capifcore/internal/common29122"
+	"oransc.org/nonrtric/capifcore/internal/common29571"
 	"oransc.org/nonrtric/capifcore/internal/invokermanagementapi"
 	"oransc.org/nonrtric/capifcore/internal/providermanagementapi"
 	"oransc.org/nonrtric/capifcore/internal/publishserviceapi"
-    "oransc.org/nonrtric/capifcore/internal/common"
-    "oransc.org/nonrtric/capifcore/internal/common29122"
-    "oransc.org/nonrtric/capifcore/internal/common29571"
 )
 
+type fn func() (swagger *openapi3.T, err error)
+
+var smeOpenApiFileLocation string = "../../openapi/sme/"
+
 func main() {
-	var swagger *openapi3.T
+
 	var err error
-
-	swagger,err = providermanagementapi.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "TS29222_CAPIF_API_Provider_Management_API.yaml")
-    }
-
-    swagger,err = publishserviceapi.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "TS29222_CAPIF_Publish_Service_API.yaml")
-    }
-
-    swagger,err = invokermanagementapi.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "TS29222_CAPIF_API_Invoker_Management_API.yaml")
-    }
-
-    swagger,err = common.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "CommonData.yaml")
-    }
-
-    swagger,err = common29122.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "TS29122_CommonData.yaml")
-    }
-
-    swagger,err = common29571.GetSwagger()
-    if err == nil {
-        generateSwaggerYaml(swagger, "TS29571_CommonData.yaml")
-    }
+	fmt.Println("Generating SME openapi spec...")
+	os.MkdirAll(smeOpenApiFileLocation, 0755)
+	if err == nil {
+		generateAndCopySwagger("TS29222_CAPIF_API_Provider_Management_API.yaml", providermanagementapi.GetSwagger)
+		generateAndCopySwagger("TS29222_CAPIF_Publish_Service_API.yaml", publishserviceapi.GetSwagger)
+		generateAndCopySwagger("TS29222_CAPIF_API_Invoker_Management_API.yaml", invokermanagementapi.GetSwagger)
+		generateAndCopySwagger("CommonData.yaml", common.GetSwagger)
+		generateAndCopySwagger("TS29122_CommonData.yaml", common29122.GetSwagger)
+		generateAndCopySwagger("TS29571_CommonData.yaml", common29571.GetSwagger)
+	}
 }
 
 func generateSwaggerYaml(swagger *openapi3.T, filename string) {
-    jsondataarr, jsondataarrerr := json.Marshal(&swagger)
-    if jsondataarrerr != nil {
-        log.Fatalf("Error loading json data from swagger \n: %s", jsondataarrerr)
-    }
+	jsondataarr, jsondataarrerr := json.Marshal(&swagger)
+	if jsondataarrerr != nil {
+		log.Fatalf("Error loading json data from swagger \n: %s", jsondataarrerr)
+	}
 
-    var data map[string]interface{}
-    if err := json.Unmarshal(jsondataarr, &data); err != nil {
-    log.Fatalf("Error loading json data to map \n: %s", jsondataarrerr)
-        log.Fatal(err)
-    }
+	var data map[string]interface{}
+	if err := json.Unmarshal(jsondataarr, &data); err != nil {
+		log.Fatalf("Error loading json data to map \n: %s", jsondataarrerr)
+		log.Fatal(err)
+	}
 
-    yamldataarr, yamldataarrerr := yaml.Marshal(&data)
-    if yamldataarrerr != nil {
-        log.Fatalf("Error loading json data map to array \n: %s", yamldataarrerr)
-    }
+	yamldataarr, yamldataarrerr := yaml.Marshal(&data)
+	if yamldataarrerr != nil {
+		log.Fatalf("Error loading json data map to array \n: %s", yamldataarrerr)
+	}
 
-    err2 := ioutil.WriteFile(filename, yamldataarr, 0755)
-    if err2 != nil {
-        log.Fatalf("Error writing provider yaml \n: %s", err2)
-    }
-}
\ No newline at end of file
+	err2 := ioutil.WriteFile(filename, yamldataarr, 0755)
+	if err2 != nil {
+		log.Fatalf("Error writing provider yaml \n: %s", err2)
+	}
+}
+
+func copy(srcFile string, targetFile string) error {
+	data, err := os.ReadFile(srcFile)
+	if err != nil {
+		return err
+	}
+	err = os.WriteFile(targetFile, data, 0644)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func generateAndCopySwagger(openApiFileName string, getSwagger fn) {
+	fmt.Printf("Generating %s...\n", openApiFileName)
+	swagger, err := getSwagger()
+	if err == nil {
+		generateSwaggerYaml(swagger, openApiFileName)
+		fmt.Printf("Copying %s to %s \n", openApiFileName, smeOpenApiFileLocation + openApiFileName)
+		copy(openApiFileName, smeOpenApiFileLocation +openApiFileName)
+	}
+}
diff --git a/scripts/init/init-sme-spec.bat b/scripts/init/init-sme-spec.bat
deleted file mode 100755
index e9ee0b6..0000000
--- a/scripts/init/init-sme-spec.bat
+++ /dev/null
@@ -1,46 +0,0 @@
-:: ============LICENSE_START===============================================
-::  Copyright (C) 2023 Nordix Foundation. All rights reserved.
-::  ========================================================================
-::  Licensed under the Apache License, Version 2.0 (the "License");
-::  you may not use this file except in compliance with the License.
-::  You may obtain a copy of the License at
-::
-::       http:\\www.apache.org\licenses\LICENSE-2.0
-::
-::  Unless required by applicable law or agreed to in writing, software
-::  distributed under the License is distributed on an "AS IS" BASIS,
-::  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-::  See the License for the specific language governing permissions and
-::  limitations under the License.
-::  ============LICENSE_END=================================================
-::
-
-@echo off
-set SME_LOCATION="..\sme\capifcore"
-set SME_OPENAPI_LOCATION="..\..\openapi\sme"
-cp ..\scripts\init\getsmeswagger.go %SME_LOCATION%
-cd %SME_LOCATION%
-
-echo Generating SME openapi spec...
-
-IF EXIST getsmeswagger.go (
-  echo Generating...
-  go run getsmeswagger.go
-
-  echo Copying generated specs...
-  mkdir %SME_OPENAPI_LOCATION%
-  echo Copying CommonData.yaml
-  mv CommonData.yaml %SME_OPENAPI_LOCATION%
-  echo Copying TS29122_CommonData.yaml
-  mv TS29122_CommonData.yaml %SME_OPENAPI_LOCATION%
-  echo Copying TS29571_CommonData.yaml
-  mv TS29571_CommonData.yaml %SME_OPENAPI_LOCATION%
-  echo Copying TS29222_CAPIF_API_Invoker_Management_API.yaml
-  mv TS29222_CAPIF_API_Invoker_Management_API.yaml %SME_OPENAPI_LOCATION%
-  echo Copying TS29222_CAPIF_API_Provider_Management_API.yaml
-  mv TS29222_CAPIF_API_Provider_Management_API.yaml %SME_OPENAPI_LOCATION%
-  echo Copying TS29222_CAPIF_Publish_Service_API.yaml
-  mv TS29222_CAPIF_Publish_Service_API.yaml %SME_OPENAPI_LOCATION%
-) ELSE (
-  echo Unable to find the openapi spec generator.
-)
diff --git a/scripts/init/init-sme-spec.sh b/scripts/init/init-sme-spec.sh
deleted file mode 100755
index ee3e108..0000000
--- a/scripts/init/init-sme-spec.sh
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/bash
-
-#  ============LICENSE_START===============================================
-#  Copyright (C) 2023 Nordix Foundation. All rights reserved.
-#  ========================================================================
-#  Licensed under the Apache License, Version 2.0 (the "License");
-#  you may not use this file except in compliance with the License.
-#  You may obtain a copy of the License at
-#
-#       http://www.apache.org/licenses/LICENSE-2.0
-#
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.
-#  ============LICENSE_END=================================================
-#
-
-SME_LOCATION="../sme/capifcore"
-SME_OPENAPI_LOCATION="../../openapi/sme"
-cp ../scripts/init/getsmeswagger.go $SME_LOCATION
-cd $SME_LOCATION
-
-echo "Generating SME openapi spec..."
-
-if [ -f "getsmeswagger.go" ]; then
-  echo "Generating..."
-  go run getsmeswagger.go
-
-  echo "Copying generated specs..."
-  mkdir -p $SME_OPENAPI_LOCATION
-  echo "Copying CommonData.yaml"
-  mv CommonData.yaml $SME_OPENAPI_LOCATION
-  echo "Copying TS29122_CommonData.yaml"
-  mv TS29122_CommonData.yaml $SME_OPENAPI_LOCATION
-  echo "Copying TS29571_CommonData.yaml"
-  mv TS29571_CommonData.yaml $SME_OPENAPI_LOCATION
-  echo "Copying TS29222_CAPIF_API_Invoker_Management_API.yaml"
-  mv TS29222_CAPIF_API_Invoker_Management_API.yaml $SME_OPENAPI_LOCATION
-  echo "Copying TS29222_CAPIF_API_Provider_Management_API.yaml"
-  mv TS29222_CAPIF_API_Provider_Management_API.yaml $SME_OPENAPI_LOCATION
-  echo "Copying TS29222_CAPIF_Publish_Service_API.yaml"
-  mv TS29222_CAPIF_Publish_Service_API.yaml $SME_OPENAPI_LOCATION
-else
-  echo "Unable to find the openapi spec generator."
-fi