完善功能 适配linux

main
forget_the_bright 2 years ago
parent 241d0f6214
commit 196daf571a

2
.gitignore vendored

@ -13,5 +13,7 @@
downloads downloads
java java
versions versions
bin
j
# Dependency directories (remove the comment below to include it) # Dependency directories (remove the comment below to include it)
# vendor/ # vendor/

@ -10,7 +10,7 @@
"request": "launch", "request": "launch",
"mode": "auto", "mode": "auto",
"program": "${fileDirname}", "program": "${fileDirname}",
"args": [ "18" ] "args": ["use" ,"18" ]
} }
] ]
} }

@ -0,0 +1,24 @@
package cli
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/urfave/cli/v2"
)
func clean(ctx *cli.Context) (err error) {
entries, err := ioutil.ReadDir(downloadsDir)
if err != nil {
return cli.Exit(errstring(err), 1)
}
for i := range entries {
if err = os.RemoveAll(filepath.Join(downloadsDir, entries[i].Name())); err == nil {
fmt.Println("Remove", entries[i].Name())
}
}
return nil
}

@ -25,14 +25,14 @@ var (
) )
func init() { func init() {
ghomeDir, _ = os.Getwd() /* ghomeDir, _ = os.Getwd()
fmt.Println(ghomeDir) fmt.Println(ghomeDir)
goroot = filepath.Join(ghomeDir, "java") goroot = filepath.Join(ghomeDir, "java")
fmt.Println(goroot) fmt.Println(goroot)
downloadsDir = filepath.Join(ghomeDir, "downloads") downloadsDir = filepath.Join(ghomeDir, "downloads")
os.MkdirAll(downloadsDir, 0755) os.MkdirAll(downloadsDir, 0755)
versionsDir = filepath.Join(ghomeDir, "versions") versionsDir = filepath.Join(ghomeDir, "versions")
os.MkdirAll(versionsDir, 0755) os.MkdirAll(versionsDir, 0755) */
cli.AppHelpTemplate = fmt.Sprintf(`NAME: cli.AppHelpTemplate = fmt.Sprintf(`NAME:
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}} {{.Name}}{{if .Usage}} - {{.Usage}}{{end}}
@ -103,10 +103,10 @@ func ghome() (dir string) {
if dir = os.Getenv(homeEnv); dir != "" { if dir = os.Getenv(homeEnv); dir != "" {
return dir return dir
} }
/* homeDir, _ := os.UserHomeDir() homeDir, _ := os.UserHomeDir()
return filepath.Join(homeDir, ".g") */ return filepath.Join(homeDir, ".j")
path, _ := os.Getwd() /* path, _ := os.Getwd()
return path return path */
} }
// inuse 返回当前的go版本号 // inuse 返回当前的go版本号

@ -10,11 +10,35 @@ var (
UsageText: "j ls", UsageText: "j ls",
Action: list, Action: list,
}, },
{
Name: "ls-all",
Usage: "List All versions",
UsageText: "j ls-all",
Action: listAll,
},
{
Name: "install",
Usage: "install versions",
UsageText: "j install <version>",
Action: install,
},
{ {
Name: "use", Name: "use",
Usage: "Switch to specified version", Usage: "Switch to specified version",
UsageText: "j use <version>", UsageText: "j use <version>",
Action: use, Action: use,
}, },
{
Name: "uninstall",
Usage: "Uninstall a version",
UsageText: "j uninstall <version>",
Action: uninstall,
},
{
Name: "clean",
Usage: "Remove files from the package download directory",
UsageText: "j clean",
Action: clean,
},
} }
) )

@ -1,49 +1,63 @@
package cli package cli
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/forget-the-bright/j/internal/pkg/archiver"
"github.com/forget-the-bright/j/internal/pkg/config" "github.com/forget-the-bright/j/internal/pkg/config"
"github.com/forget-the-bright/j/internal/pkg/download" "github.com/forget-the-bright/j/internal/pkg/download"
"github.com/mholt/archiver/v3"
//"github.com/mholt/archiver/v3"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
func fundVersion(version string) *config.UrlItem { func fundVersion(version string) *config.UrlItem {
for _, v := range config.Url_Items { for _, v := range config.Url_Items {
if strings.Contains(v.Expected, version) { if v.SimpleName == version { //strings.Contains(v.SimpleName, version)
return v return v
} }
} }
return nil return nil
} }
func Install(version string) (err error) { func downloadAndInstall(version string) (err error) {
ui := fundVersion(version) ui := fundVersion(version)
if ui == nil { if ui == nil {
return nil return cli.Exit(errors.New(version+" version is not supported"), 1)
} }
filename := filepath.Join(downloadsDir, ui.In.FileName) filename := filepath.Join(downloadsDir, ui.In.FileName)
DownloadWithProgress(ui.In.URL, filename) //判断本地有没有安装包 没有就进入下载
if _, err := os.Stat(filename); err != nil {
DownloadWithProgress(ui.In.URL, filename)
}
//获取解压目标目录
targetV := filepath.Join(versionsDir, ui.SimpleName) targetV := filepath.Join(versionsDir, ui.SimpleName)
// 解压安装包 //判断判断解压目录是否存在,不存在就解压
if err = archiver.Unarchive(filename, versionsDir); err != nil { if _, err := os.Stat(targetV); err != nil {
fmt.Println(err.Error()) // 解压安装包
return cli.Exit(errstring(err), 1) if err = archiver.Unarchive(filename, targetV, true); err != nil {
} return cli.Exit(errstring(err), 1)
// 目录重命名 }
if err = os.Rename(filepath.Join(versionsDir, ui.Expected), targetV); err != nil {
fmt.Println(err.Error())
return cli.Exit(errstring(err), 1)
} }
/* // 解压安装包
if err = archiver.Unarchive(filename, versionsDir); err != nil {
fmt.Println(err.Error())
return cli.Exit(errstring(err), 1)
}
// 目录重命名
if err = os.Rename(filepath.Join(versionsDir, ui.Expected), targetV); err != nil {
fmt.Println(err.Error())
return cli.Exit(errstring(err), 1)
} */
// 重新建立软链接 // 重新建立软链接
_ = os.Remove(goroot) _ = os.Remove(goroot)
if err = mkSymlink(targetV, goroot); err != nil { if err = mkSymlink(targetV, goroot); err != nil {
return cli.Exit(errstring(err), 1) return cli.Exit(errstring(err), 1)
} }
@ -51,6 +65,19 @@ func Install(version string) (err error) {
return nil return nil
} }
func install(ctx *cli.Context) (err error) {
version := ctx.Args().First()
if version == "" {
return cli.ShowSubcommandHelp(ctx)
}
return downloadAndInstall(version)
}
func Install(version string) (err error) {
return downloadAndInstall(version)
}
// DownloadWithProgress 下载版本另存为指定文件且显示下载进度 // DownloadWithProgress 下载版本另存为指定文件且显示下载进度
func DownloadWithProgress(url, dst string) (size int64, err error) { func DownloadWithProgress(url, dst string) (size int64, err error) {
return download.Download(url, dst, os.O_CREATE|os.O_WRONLY, 0644, true) return download.Download(url, dst, os.O_CREATE|os.O_WRONLY, 0644, true)

@ -0,0 +1,36 @@
package cli
import (
"fmt"
"github.com/fatih/color"
"github.com/forget-the-bright/j/internal/pkg/config"
"github.com/k0kubun/go-ansi"
"github.com/urfave/cli/v2"
)
func reverseArray(arr []*config.UrlItem) []*config.UrlItem {
for i, j := 0, len(arr)-1; i < j; i, j = i+1, j-1 {
arr[i], arr[j] = arr[j], arr[i]
}
return arr
}
func mathVersionLength(version string) string {
if len(version) <= 1 {
return version + " "
}
return version
}
func listAll(*cli.Context) (err error) {
use_version := inuse(goroot)
out := ansi.NewAnsiStdout()
color.New(color.FgGreen).Fprintf(out, " %s\n", "version info")
for _, v := range reverseArray(config.Url_Items) {
if v.SimpleName == use_version { //strings.Contains(v.SimpleName, version)
color.New(color.FgGreen).Fprintf(out, "* %s\n", mathVersionLength(v.SimpleName)+" "+v.Expected)
} else {
fmt.Fprintf(out, " %s\n", mathVersionLength(v.SimpleName)+" "+v.Expected)
}
}
return nil
}

@ -0,0 +1,27 @@
package cli
import (
"fmt"
"os"
"path/filepath"
"github.com/urfave/cli/v2"
)
func uninstall(ctx *cli.Context) (err error) {
vname := ctx.Args().First()
if vname == "" {
return cli.ShowSubcommandHelp(ctx)
}
targetV := filepath.Join(versionsDir, vname)
if finfo, err := os.Stat(targetV); err != nil || !finfo.IsDir() {
return cli.Exit(fmt.Sprintf("[j] %q version is not installed", vname), 1)
}
if err = os.RemoveAll(targetV); err != nil {
return cli.Exit(wrapstring(fmt.Sprintf("Uninstall failed: %s", err.Error())), 1)
}
fmt.Printf("Uninstalled java %s\n", vname)
return nil
}

@ -12,13 +12,12 @@ import (
func use(ctx *cli.Context) (err error) { func use(ctx *cli.Context) (err error) {
vname := ctx.Args().First() vname := ctx.Args().First()
if vname == "" { if vname == "" {
return nil return cli.ShowSubcommandHelp(ctx)
//return cli.ShowSubcommandHelp(ctx)
} }
targetV := filepath.Join(versionsDir, vname) targetV := filepath.Join(versionsDir, vname)
if finfo, err := os.Stat(targetV); err != nil || !finfo.IsDir() { if finfo, err := os.Stat(targetV); err != nil || !finfo.IsDir() {
return cli.Exit(fmt.Sprintf("[g] The %q version does not exist, please install it first.", vname), 1) return cli.Exit(fmt.Sprintf("[j] The %q version does not exist, please install it first.", vname), 1)
} }
_ = os.Remove(goroot) _ = os.Remove(goroot)
@ -26,7 +25,7 @@ func use(ctx *cli.Context) (err error) {
if err = mkSymlink(targetV, goroot); err != nil { if err = mkSymlink(targetV, goroot); err != nil {
return cli.Exit(errstring(err), 1) return cli.Exit(errstring(err), 1)
} }
if output, err := exec.Command(filepath.Join(goroot, "bin", "go"), "version").Output(); err == nil { if output, err := exec.Command(filepath.Join(goroot, "bin", "java"), "--version").Output(); err == nil {
fmt.Print(string(output)) fmt.Print(string(output))
} }
return nil return nil

@ -0,0 +1,29 @@
package archiver
import (
"errors"
"strings"
)
func Run_unzip(src string, dst string, strip bool) error {
return Unarchive(src, dst, strip)
}
func Unarchive(src string, dst string, strip bool) (err error) {
fileTypes := strings.Split(src, ".")
if len(fileTypes) == 0 {
return errors.New("fileType is not supported")
}
//fmt.Println(fileTypes[len(fileTypes)-1])
switch fileTypes[len(fileTypes)-1] {
case "gz":
err = untgz(src, dst, strip)
case "gx":
err = untgx(src, dst, strip)
case "zip":
err = unzip(src, dst, strip)
default:
err = errors.New(fileTypes[len(fileTypes)-1] + " is not supported")
}
return err
}

@ -0,0 +1,117 @@
package archiver
import (
"archive/tar"
"io"
"os"
"path/filepath"
"strings"
"github.com/xi2/xz"
)
func untgx(src string, dst string, strip bool) error {
xzFile, err := os.Open(src)
if err != nil {
return err
}
defer xzFile.Close()
var prefixToStrip string
if strip {
xzr, err := xz.NewReader(xzFile, 0)
if err != nil {
return err
}
r := tar.NewReader(xzr)
var prefix []string
for {
header, err := r.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
var dir string
if header.Typeflag != tar.TypeDir {
dir = filepath.Dir(header.Name)
} else {
continue
}
if prefix != nil {
dirSplit := strings.Split(dir, string(filepath.Separator))
i, e, dse := 0, len(prefix), len(dirSplit)
if dse < e {
e = dse
}
for i < e {
if prefix[i] != dirSplit[i] {
prefix = prefix[0:i]
break
}
i++
}
} else {
prefix = strings.Split(dir, string(filepath.Separator))
}
}
prefixToStrip = strings.Join(prefix, string(filepath.Separator))
}
xzFile.Seek(0, 0)
xzr, err := xz.NewReader(xzFile, 0)
if err != nil {
return err
}
r := tar.NewReader(xzr)
dirCache := make(map[string]bool) // todo: radix tree would perform better here
if err := os.MkdirAll(dst, 0755); err != nil {
return err
}
for {
header, err := r.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
var dir string
if header.Typeflag != tar.TypeDir {
dir = filepath.Dir(header.Name)
} else {
dir = filepath.Clean(header.Name)
if !strings.HasPrefix(dir, prefixToStrip) {
continue
}
}
dir = strings.TrimPrefix(dir, prefixToStrip)
if dir != "" && dir != "." {
cached := dirCache[dir]
if !cached {
if err := os.MkdirAll(filepath.Join(dst, dir), 0755); err != nil {
return err
}
dirCache[dir] = true
}
}
target := filepath.Join(dst, dir, filepath.Base(header.Name))
switch header.Typeflag {
case tar.TypeReg:
d, err := os.OpenFile(target,
os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(header.Mode|0600)&0777)
if err != nil {
return err
}
_, err = io.Copy(d, r)
d.Close()
if err != nil {
return err
}
case tar.TypeSymlink:
if err = os.Symlink(header.Linkname, target); err != nil {
return err
}
}
}
return nil
}

@ -0,0 +1,118 @@
package archiver
import (
"archive/tar"
"compress/gzip"
"io"
"os"
"path/filepath"
"strings"
)
func untgz(src string, dst string, strip bool) error {
gzFile, err := os.Open(src)
if err != nil {
return err
}
defer gzFile.Close()
var prefixToStrip string
if strip {
gzr, err := gzip.NewReader(gzFile)
if err != nil {
return err
}
defer gzr.Close()
r := tar.NewReader(gzr)
var prefix []string
for {
header, err := r.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
var dir string
if header.Typeflag != tar.TypeDir {
dir = filepath.Dir(header.Name)
} else {
continue
}
if prefix != nil {
dirSplit := strings.Split(dir, string(filepath.Separator))
i, e, dse := 0, len(prefix), len(dirSplit)
if dse < e {
e = dse
}
for i < e {
if prefix[i] != dirSplit[i] {
prefix = prefix[0:i]
break
}
i++
}
} else {
prefix = strings.Split(dir, string(filepath.Separator))
}
}
prefixToStrip = strings.Join(prefix, string(filepath.Separator))
}
gzFile.Seek(0, 0)
gzr, err := gzip.NewReader(gzFile)
if err != nil {
return err
}
defer gzr.Close()
r := tar.NewReader(gzr)
dirCache := make(map[string]bool) // todo: radix tree would perform better here
if err := os.MkdirAll(dst, 0755); err != nil {
return err
}
for {
header, err := r.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
var dir string
if header.Typeflag != tar.TypeDir {
dir = filepath.Dir(header.Name)
} else {
dir = filepath.Clean(header.Name)
if !strings.HasPrefix(dir, prefixToStrip) {
continue
}
}
dir = strings.TrimPrefix(dir, prefixToStrip)
if dir != "" && dir != "." {
cached := dirCache[dir]
if !cached {
if err := os.MkdirAll(filepath.Join(dst, dir), 0755); err != nil {
return err
}
dirCache[dir] = true
}
}
target := filepath.Join(dst, dir, filepath.Base(header.Name))
switch header.Typeflag {
case tar.TypeReg:
d, err := os.OpenFile(target,
os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.FileMode(header.Mode|0600)&0777)
if err != nil {
return err
}
_, err = io.Copy(d, r)
d.Close()
if err != nil {
return err
}
case tar.TypeSymlink:
if err = os.Symlink(header.Linkname, target); err != nil {
return err
}
}
}
return nil
}

@ -0,0 +1,89 @@
package archiver
import (
"archive/zip"
"io"
"os"
"path/filepath"
"strings"
)
func unzip(src string, dst string, strip bool) error {
r, err := zip.OpenReader(src)
if err != nil {
return err
}
defer r.Close()
var prefixToStrip string
if strip {
var prefix []string
for _, f := range r.File {
var dir string
if !f.Mode().IsDir() {
dir = filepath.Dir(f.Name)
} else {
continue
}
if prefix != nil {
dirSplit := strings.Split(dir, string(filepath.Separator))
i, e, dse := 0, len(prefix), len(dirSplit)
if dse < e {
e = dse
}
for i < e {
if prefix[i] != dirSplit[i] {
prefix = prefix[0:i]
break
}
i++
}
} else {
prefix = strings.Split(dir, string(filepath.Separator))
}
}
prefixToStrip = strings.Join(prefix, string(filepath.Separator))
}
dirCache := make(map[string]bool) // todo: radix tree would perform better here
if err := os.MkdirAll(dst, 0755); err != nil {
return err
}
for _, f := range r.File {
var dir string
if !f.Mode().IsDir() {
dir = filepath.Dir(f.Name)
} else {
dir = filepath.Clean(f.Name)
if !strings.HasPrefix(dir, prefixToStrip) {
continue
}
}
dir = strings.TrimPrefix(dir, prefixToStrip)
if dir != "" && dir != "." {
cached := dirCache[dir]
if !cached {
if err := os.MkdirAll(filepath.Join(dst, dir), 0755); err != nil {
return err
}
dirCache[dir] = true
}
}
if !f.Mode().IsDir() {
name := filepath.Base(f.Name)
fr, err := f.Open()
if err != nil {
return err
}
d, err := os.OpenFile(filepath.Join(dst, dir, name),
os.O_WRONLY|os.O_CREATE|os.O_TRUNC, (f.Mode()|0600)&0777)
if err != nil {
return err
}
_, err = io.Copy(d, fr)
d.Close()
if err != nil {
return err
}
}
}
return nil
}

@ -0,0 +1,100 @@
package config
var linux_Url_Items = []*UrlItem{
{
In: &JavaFileItem{
FileName: "openjdk-19+36_linux-x64_bin.tar.gz",
URL: "https://download.java.net/openjdk/jdk19/ri/openjdk-19+36_linux-x64_bin.tar.gz",
},
Expected: "jdk-19",
SimpleName: "19",
},
{
In: &JavaFileItem{
FileName: "openjdk-18+36_linux-x64_bin.tar.gz",
URL: "https://download.java.net/openjdk/jdk18/ri/openjdk-18+36_linux-x64_bin.tar.gz",
},
Expected: "jdk-18",
SimpleName: "18",
},
{
In: &JavaFileItem{
FileName: "openjdk-17+35_linux-x64_bin.tar.gz",
URL: "https://download.java.net/openjdk/jdk17/ri/openjdk-17+35_linux-x64_bin.tar.gz",
},
Expected: "jdk-17",
SimpleName: "17",
},
{
In: &JavaFileItem{
FileName: "openjdk-16+36_linux-x64_bin.tar.gz",
URL: "https://download.java.net/openjdk/jdk16/ri/openjdk-16+36_linux-x64_bin.tar.gz",
},
Expected: "jdk-16",
SimpleName: "16",
},
{
In: &JavaFileItem{
FileName: "openjdk-15+36_linux-x64_bin.tar.gz",
URL: "https://download.java.net/openjdk/jdk15/ri/openjdk-15+36_linux-x64_bin.tar.gz",
},
Expected: "jdk-15",
SimpleName: "15",
},
{
In: &JavaFileItem{
FileName: "openjdk-14+36_linux-x64_bin.tar.gz",
URL: "https://download.java.net/openjdk/jdk14/ri/openjdk-14+36_linux-x64_bin.tar.gz",
},
Expected: "jdk-14",
SimpleName: "14",
},
{
In: &JavaFileItem{
FileName: "openjdk-13+33_linux-x64_bin.tar.gz",
URL: "https://download.java.net/openjdk/jdk13/ri/openjdk-13+33_linux-x64_bin.tar.gz",
},
Expected: "jdk-13",
SimpleName: "13",
},
{
In: &JavaFileItem{
FileName: "openjdk-12+32_linux-x64_bin.tar.gz",
URL: "https://download.java.net/openjdk/jdk12/ri/openjdk-12+32_linux-x64_bin.tar.gz",
},
Expected: "jdk-12",
SimpleName: "12",
},
{
In: &JavaFileItem{
FileName: "openjdk-11+28_linux-x64_bin.tar.gz",
URL: "https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz",
},
Expected: "jdk-11",
SimpleName: "11",
},
{
In: &JavaFileItem{
FileName: "openjdk-10+44_linux-x64_bin_ri.tar.gz",
URL: "https://download.java.net/openjdk/jdk10/ri/openjdk-10+44_linux-x64_bin_ri.tar.gz",
},
Expected: "jdk-10",
SimpleName: "10",
},
{
In: &JavaFileItem{
FileName: "openjdk-9+181_linux-x64_ri.zip",
URL: "https://download.java.net/openjdk/jdk9/ri/openjdk-9+181_linux-x64_ri.zip",
},
Expected: "jdk-9",
SimpleName: "9",
},
{
In: &JavaFileItem{
FileName: "openjdk-8u42-b03-linux-x64-14_jul_2022.tar.gz",
URL: "https://download.java.net/openjdk/jdk8u42/ri/openjdk-8u42-b03-linux-x64-14_jul_2022.tar.gz",
},
Expected: "jdk-8",
SimpleName: "8",
},
}

@ -1,5 +1,12 @@
package config package config
import (
"errors"
"runtime"
cli "github.com/urfave/cli/v2"
)
type JavaFileItem struct { type JavaFileItem struct {
FileName string FileName string
URL string URL string
@ -10,93 +17,15 @@ type UrlItem struct {
SimpleName string SimpleName string
} }
var Url_Items = []*UrlItem{ var Url_Items []*UrlItem
{
In: &JavaFileItem{ func init() {
FileName: "openjdk-19+36_windows-x64_bin.zip", switch runtime.GOOS {
URL: "https://download.java.net/openjdk/jdk19/ri/openjdk-19+36_windows-x64_bin.zip", case "linux":
}, Url_Items = linux_Url_Items
Expected: "jdk-19", case "windows":
SimpleName: "19", Url_Items = windows_Url_Items
}, default:
{ cli.Exit(errors.New(runtime.GOOS+" OS is not supported"), 1)
In: &JavaFileItem{ }
FileName: "openjdk-18+36_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk18/ri/openjdk-18+36_windows-x64_bin.zip",
},
Expected: "jdk-18",
SimpleName: "18",
},
{
In: &JavaFileItem{
FileName: "openjdk-17+35_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk17/ri/openjdk-17+35_windows-x64_bin.zip",
},
Expected: "jdk-17",
SimpleName: "17",
},
{
In: &JavaFileItem{
FileName: "openjdk-16+36_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk16/ri/openjdk-16+36_windows-x64_bin.zip",
},
Expected: "jdk-16",
SimpleName: "16",
},
{
In: &JavaFileItem{
FileName: "openjdk-15+36_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk15/ri/openjdk-15+36_windows-x64_bin.zip",
},
Expected: "jdk-15",
SimpleName: "15",
},
{
In: &JavaFileItem{
FileName: "openjdk-14+36_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk14/ri/openjdk-14+36_windows-x64_bin.zip",
},
Expected: "jdk-14",
SimpleName: "14",
},
{
In: &JavaFileItem{
FileName: "openjdk-13+33_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk13/ri/openjdk-13+33_windows-x64_bin.zip",
},
Expected: "jdk-13",
SimpleName: "13",
},
{
In: &JavaFileItem{
FileName: "openjdk-12+32_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk12/ri/openjdk-12+32_windows-x64_bin.zip",
},
Expected: "jdk-12",
SimpleName: "12",
},
{
In: &JavaFileItem{
FileName: "openjdk-11+28_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_windows-x64_bin.zip",
},
Expected: "jdk-11",
SimpleName: "11",
},
{
In: &JavaFileItem{
FileName: "jdk-9+181_windows-x64_ri.zip",
URL: "https://download.java.net/openjdk/jdk9/ri/jdk-9+181_windows-x64_ri.zip",
},
Expected: "jdk-9",
SimpleName: "9",
},
{
In: &JavaFileItem{
FileName: "openjdk-8u42-b03-windows-i586-14_jul_2022.zip",
URL: "https://download.java.net/openjdk/jdk8u42/ri/openjdk-8u42-b03-windows-i586-14_jul_2022.zip",
},
Expected: "jdk-8",
SimpleName: "8",
},
} }

@ -0,0 +1,92 @@
package config
var windows_Url_Items = []*UrlItem{
{
In: &JavaFileItem{
FileName: "openjdk-19+36_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk19/ri/openjdk-19+36_windows-x64_bin.zip",
},
Expected: "jdk-19",
SimpleName: "19",
},
{
In: &JavaFileItem{
FileName: "openjdk-18+36_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk18/ri/openjdk-18+36_windows-x64_bin.zip",
},
Expected: "jdk-18",
SimpleName: "18",
},
{
In: &JavaFileItem{
FileName: "openjdk-17+35_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk17/ri/openjdk-17+35_windows-x64_bin.zip",
},
Expected: "jdk-17",
SimpleName: "17",
},
{
In: &JavaFileItem{
FileName: "openjdk-16+36_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk16/ri/openjdk-16+36_windows-x64_bin.zip",
},
Expected: "jdk-16",
SimpleName: "16",
},
{
In: &JavaFileItem{
FileName: "openjdk-15+36_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk15/ri/openjdk-15+36_windows-x64_bin.zip",
},
Expected: "jdk-15",
SimpleName: "15",
},
{
In: &JavaFileItem{
FileName: "openjdk-14+36_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk14/ri/openjdk-14+36_windows-x64_bin.zip",
},
Expected: "jdk-14",
SimpleName: "14",
},
{
In: &JavaFileItem{
FileName: "openjdk-13+33_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk13/ri/openjdk-13+33_windows-x64_bin.zip",
},
Expected: "jdk-13",
SimpleName: "13",
},
{
In: &JavaFileItem{
FileName: "openjdk-12+32_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk12/ri/openjdk-12+32_windows-x64_bin.zip",
},
Expected: "jdk-12",
SimpleName: "12",
},
{
In: &JavaFileItem{
FileName: "openjdk-11+28_windows-x64_bin.zip",
URL: "https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_windows-x64_bin.zip",
},
Expected: "jdk-11",
SimpleName: "11",
},
{
In: &JavaFileItem{
FileName: "jdk-9+181_windows-x64_ri.zip",
URL: "https://download.java.net/openjdk/jdk9/ri/jdk-9+181_windows-x64_ri.zip",
},
Expected: "jdk-9",
SimpleName: "9",
},
{
In: &JavaFileItem{
FileName: "openjdk-8u42-b03-windows-i586-14_jul_2022.zip",
URL: "https://download.java.net/openjdk/jdk8u42/ri/openjdk-8u42-b03-windows-i586-14_jul_2022.zip",
},
Expected: "java-se-8u42-ri",
SimpleName: "8",
},
}

@ -1,10 +1,6 @@
package main package main
import ( import "github.com/forget-the-bright/j/cli"
"os"
"github.com/forget-the-bright/j/cli"
)
func main() { func main() {
/* dir, _ := os.Getwd() /* dir, _ := os.Getwd()
@ -14,9 +10,14 @@ func main() {
fmt.Println(os.Args[1]) fmt.Println(os.Args[1])
cli.Use(os.Args[1]) //"1.17.9" cli.Use(os.Args[1]) //"1.17.9"
} */ } */
//cli.Run() cli.Run()
if len(os.Args) > 1 { /* if len(os.Args) > 1 {
cli.Install(os.Args[1]) cli.Install(os.Args[1])
} }
*/
/* ghomeDir, _ := os.Getwd()
fmt.Println(ghomeDir)
downloadsDir := filepath.Join(ghomeDir, "downloads")
versionsDir := filepath.Join(ghomeDir, "versions")
archiver.Run_unzip(downloadsDir+"\\openjdk-19+36_windows-x64_bin.zip", versionsDir+"\\20", true) */
} }

@ -0,0 +1,11 @@
VERSION := 1.0.0
build_linux:
set CGO_ENABLED=0
set GOARCH=amd64
set GOOS=linux
go build -ldflags "-s -w -X main.version=${VERSION}" -o ./bin/linux/j
build_windows:
set CGO_ENABLED=0
set GOARCH=amd64
set GOOS=windows
go build -ldflags "-s -w -X main.version=${VERSION}" -o ./bin/windows/j.exe
Loading…
Cancel
Save