-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
111 lines (97 loc) · 3.73 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"code.cloudfoundry.org/cli/plugin"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
type MavenPushPlugin struct {
}
func (c *MavenPushPlugin) Run(cliConnection plugin.CliConnection, args []string) {
if len(args) == 0 || args[0] != "maven-push" {
os.Exit(0)
}
command, err := ParseArgs(args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
tempDir, err := ioutil.TempDir("", "cf-maven-push")
defer os.Remove(tempDir)
useRemoteManifest := command.RemoteManifestUrl != ""
if useRemoteManifest {
err = command.ConfigureRemoteManifestIfPresent(tempDir)
if err != nil {
fmt.Println("failed to download remote manifest", err)
os.Exit(1)
}
}
fmt.Printf("using manifest file %s\n", command.ManifestPath())
config, err := ExtractMavenConfigFromManifest(command.ManifestPath())
config = command.Merge(config)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if err != nil {
fmt.Printf("failed to create temp dir, %+v", err)
os.Exit(1)
}
artifactFile := filepath.Join(tempDir, "artifact")
err = DownloadFile(config.ArtifactUrl(), artifactFile, config.RepoUsername, config.RepoPassword)
if err != nil {
fmt.Println("failed to download remote manifest", err)
os.Exit(1)
}
args = append(args, "-p", artifactFile)
if useRemoteManifest {
args = append(args, "-f", string(command.Push.PathToManifest))
}
args[0] = "push"
args = RemoveMavenArgs(args)
args = RemoveRemoteManifestArgs(args)
fmt.Println("running: cf", strings.Join(args, " "))
_, err = cliConnection.CliCommand(args...)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func (c *MavenPushPlugin) GetMetadata() plugin.PluginMetadata {
return plugin.PluginMetadata{
Name: "maven-push",
Version: plugin.VersionType{
Major: 0,
Minor: 4,
Build: 0,
},
Commands: []plugin.Command{
{
Name: "maven-push",
HelpText: "Download and push an application based on maven coordinates defined in the manifest",
UsageDetails: plugin.Usage{
Usage: "cf maven-push [-f MANIFEST_PATH] [--maven-repo-url REPO_URL] [--maven-group-id GROUP_ID]\n [--maven-artifact-id ARTIFACT_ID] [--maven-version VERSION] [--maven-classifier CLASSIFIER]\n [--maven-extension EXTENSION] [--maven-repo-username REPO_USERNAME] [--maven-repo-password REPO_PASSWORD] <cf push flags>\n\n cf maven-push APP_NAME [-f MANIFEST_PATH] [--maven-repo-url REPO_URL] [--maven-group-id GROUP_ID]\n [--maven-artifact-id ARTIFACT_ID] [--maven-version VERSION] [--maven-classifier CLASSIFIER]\n [--maven-extension EXTENSION] [--maven-repo-username REPO_USERNAME] [--maven-repo-password REPO_PASSWORD] <cf push flags>",
Options: map[string]string{
"f": "Path to manifest (default manifest.yml)",
"-maven-repo-url": "Maven repository to pull the artifact from (e.g. https://repo.maven.apache.org/maven2/)",
"-maven-group-id": "Maven groupId",
"-maven-artifact-id": "Maven artifactId",
"-maven-version": "Maven version",
"-maven-classifier": "Maven classifier (optional)",
"-maven-extension": "Maven extension (e.g. jar, zip) (default jar)",
"-maven-repo-username": "Basic auth username when accessing Maven Repository (optional)",
"-maven-repo-password": "Basic auth password when accessing Maven Repository (optional)",
"-remote-manifest-url": "URL to retrieve manifest from (e.g. https://example.com/manifest.yml) (optional)",
"-remote-manifest-username": "Basic auth username when retrieving a remote manifest (optional)",
"-remote-manifest-password": "Basic auth password when retrieving a remote manifest (optional)",
},
},
},
},
}
}
func main() {
plugin.Start(new(MavenPushPlugin))
}