Compare commits

..

No commits in common. "4cf354733ca692ab16b8a9d086d6bdeaa3975ad9" and "6f1cc3cc7c6bfb28cdd58b359629a8d4b2060dad" have entirely different histories.

3 changed files with 66 additions and 111 deletions

View File

@ -56,6 +56,5 @@ func ListDir(path string) ([]fs.FileInfo, error) {
func GetParentDir(filePath string) (string, error) {
cuttedPath := strings.Split(filePath, "/")
cuttedPath = cuttedPath[:len(cuttedPath)-1]
finalPath := path.Join("/", path.Join(cuttedPath...))
return finalPath, nil
return path.Join(cuttedPath...), nil
}

View File

@ -1,47 +0,0 @@
package osutils
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
func WriteStructAsJSON(data interface{}, versionJsonPath string) error {
file, _ := json.MarshalIndent(data, "", " ")
directory, err := GetParentDir(versionJsonPath)
if err != nil {
return err
}
err = os.MkdirAll(directory+"/", os.ModePerm)
if err != nil {
return err
}
err = ioutil.WriteFile(versionJsonPath, file, 0644)
if err != nil {
return err
}
return nil
}
func ReadJsonFromDisk(target interface{}, filePath string) error {
// Open our jsonFile
jsonFile, err := os.Open(filePath)
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
// fmt.Println("Successfully Opened users.json")
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
// read our opened xmlFile as a byte array.
byteValue, _ := ioutil.ReadAll(jsonFile)
// we unmarshal our byteArray which contains our
// jsonFile's content into 'users' which we defined above
json.Unmarshal(byteValue, &target)
return nil
}

View File

@ -1,75 +1,78 @@
package javaentities
// type JavaVersion struct {
// Component string
// Type string
// Name string
// Major int
// Minor int
// Patch int
// }
import (
"errors"
"os"
"path"
"runtime"
"strconv"
"strings"
)
// type JavaMetas struct {
// JavaVersions []JavaMeta `json:"javaVersions"`
// }
type JavaVersion struct {
Major int
Minor int
Patch int
}
// func (jm JavaMetas) FindSpecificJavaOsByMajor(version JavaVersion) (SpecificJavaVersion, error) {
// for _, v := range jm.JavaVersions {
// if version.Major == v.Version.Major {
// jv, err := v.getOsJava()
// if err != nil {
// continue
// }
// return jv, nil
// }
// }
// return SpecificJavaVersion{}, errors.New("cant find os url")
// }
type JavaMetas struct {
JavaVersions []JavaMeta `json:"javaVersions"`
}
// func (jm JavaMetas) FindSpecificJava(MajorVersion string)
func (jm JavaMetas) FindOsURL(MajorVersion string) (SpecificJavaVersion, error) {
for _, v := range jm.JavaVersions {
if MajorVersion == v.Version.Major {
jv, err := v.getOsJava()
if err != nil {
continue
}
return jv, nil
}
}
return SpecificJavaVersion{}, errors.New("cant find os url")
}
// type JavaMeta struct {
// Version struct {
// Major int `json:"major"`
// Minor int `json:"minor"`
// Patch int `json:"patch"`
// } `json:"version"`
// Name string
// Specifics `json:"specifics"`
// }
type JavaMeta struct {
Version struct {
Major string `json:"major"`
Minor string `json:"minor"`
Patch string `json:"patch"`
} `json:"version"`
Specifics `json:"specifics"`
}
// type SpecificJavaVersion struct {
// Os string `json:"os"`
// Arch string `json:"arch"`
// URL string `json:"URL"`
// Sha1 string `json:"SHA1"`
// }
type SpecificJavaVersion struct {
Os string `json:"os"`
Arch string `json:"arch"`
URL string `json:"URL"`
Sha1 string `json:"SHA1"`
}
// type Specifics []SpecificJavaVersion
type Specifics []SpecificJavaVersion
// func (s Specifics) getOsJava() (SpecificJavaVersion, error) {
// for _, v := range s {
// if v.Os == runtime.GOOS {
// return v, nil
// }
// }
// return SpecificJavaVersion{}, errors.New("not java for current os")
// }
func (s Specifics) getOsJava() (SpecificJavaVersion, error) {
for _, v := range s {
if v.Os == runtime.GOOS {
return v, nil
}
}
return SpecificJavaVersion{}, errors.New("not java for current os")
}
// func (v *JavaVersion) CheckNotExists(launcherPath string) bool {
// javaBinPath := path.Join(launcherPath, ".redist", "java", v.GetString())
// _, err := os.Stat(javaBinPath)
func (v *JavaVersion) CheckNotExists(launcherPath string) bool {
javaBinPath := path.Join(launcherPath, ".redist", "java", v.GetString())
_, err := os.Stat(javaBinPath)
// return err != nil
// }
return err != nil
}
// func (v *JavaVersion) GetString() string {
// var stringBuilder strings.Builder
// stringBuilder.WriteString(strconv.Itoa(v.Major))
// stringBuilder.WriteRune('.')
// stringBuilder.WriteString(strconv.Itoa(v.Minor))
// stringBuilder.WriteRune('.')
// stringBuilder.WriteString(strconv.Itoa(v.Patch))
func (v *JavaVersion) GetString() string {
var stringBuilder strings.Builder
stringBuilder.WriteString(strconv.Itoa(v.Major))
stringBuilder.WriteRune('.')
stringBuilder.WriteString(strconv.Itoa(v.Minor))
stringBuilder.WriteRune('.')
stringBuilder.WriteString(strconv.Itoa(v.Patch))
// return stringBuilder.String()
// }
return stringBuilder.String()
}