-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
742944c
commit 84690cc
Showing
14 changed files
with
532 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package pipeline | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
"time" | ||
|
||
"github.com/gaia-pipeline/gaia" | ||
"github.com/satori/go.uuid" | ||
) | ||
|
||
var ( | ||
mavenBinaryName = "mvn" | ||
) | ||
|
||
const ( | ||
javaFolder = "java" | ||
javaFinalJarName = "plugin-jar-with-dependencies.jar" | ||
mavenTargetFolder = "target" | ||
) | ||
|
||
// BuildPipelineJava is the real implementation of BuildPipeline for java | ||
type BuildPipelineJava struct { | ||
Type gaia.PipelineType | ||
} | ||
|
||
// PrepareEnvironment prepares the environment before we start the build process. | ||
func (b *BuildPipelineJava) PrepareEnvironment(p *gaia.CreatePipeline) error { | ||
// create uuid for destination folder | ||
uuid := uuid.Must(uuid.NewV4(), nil) | ||
|
||
// Create local temp folder for clone | ||
rootPath := filepath.Join(gaia.Cfg.HomePath, tmpFolder, javaFolder) | ||
cloneFolder := filepath.Join(rootPath, srcFolder, uuid.String()) | ||
err := os.MkdirAll(cloneFolder, 0700) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Set new generated path in pipeline obj for later usage | ||
p.Pipeline.Repo.LocalDest = cloneFolder | ||
p.Pipeline.UUID = uuid.String() | ||
return err | ||
} | ||
|
||
// ExecuteBuild executes the java build process | ||
func (b *BuildPipelineJava) ExecuteBuild(p *gaia.CreatePipeline) error { | ||
// Look for maven executeable | ||
path, err := exec.LookPath(mavenBinaryName) | ||
if err != nil { | ||
gaia.Cfg.Logger.Debug("cannot find maven executeable", "error", err.Error()) | ||
return err | ||
} | ||
env := os.Environ() | ||
|
||
// Set command args for build | ||
args := []string{ | ||
"clean", | ||
"compile", | ||
"assembly:single", | ||
} | ||
|
||
// Execute and wait until finish or timeout | ||
output, err := executeCmd(path, args, env, p.Pipeline.Repo.LocalDest) | ||
p.Output = string(output) | ||
if err != nil { | ||
gaia.Cfg.Logger.Debug("cannot build pipeline", "error", err.Error(), "output", string(output)) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// CopyBinary copies the final compiled archive to the | ||
// destination folder. | ||
func (b *BuildPipelineJava) CopyBinary(p *gaia.CreatePipeline) error { | ||
// Define src and destination | ||
src := filepath.Join(p.Pipeline.Repo.LocalDest, mavenTargetFolder, javaFinalJarName) | ||
dest := filepath.Join(gaia.Cfg.PipelinePath, appendTypeToName(p.Pipeline.Name, p.Pipeline.Type)) | ||
|
||
// Copy binary | ||
if err := copyFileContents(src, dest); err != nil { | ||
return err | ||
} | ||
|
||
// Set +x (execution right) for pipeline | ||
return os.Chmod(dest, 0766) | ||
} | ||
|
||
// SavePipeline saves the current pipeline configuration. | ||
func (b *BuildPipelineJava) SavePipeline(p *gaia.Pipeline) error { | ||
dest := filepath.Join(gaia.Cfg.PipelinePath, appendTypeToName(p.Name, p.Type)) | ||
p.ExecPath = dest | ||
p.Type = gaia.PTypeJava | ||
p.Name = strings.TrimSuffix(filepath.Base(dest), typeDelimiter+gaia.PTypeJava.String()) | ||
p.Created = time.Now() | ||
// Our pipeline is finished constructing. Save it. | ||
return storeService.PipelinePut(p) | ||
} |
Oops, something went wrong.