-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathPushMojo.java
More file actions
100 lines (90 loc) · 3.52 KB
/
Copy pathPushMojo.java
File metadata and controls
100 lines (90 loc) · 3.52 KB
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
package de.saumya.mojo.gem;
import java.io.File;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import de.saumya.mojo.ruby.gems.GemException;
import de.saumya.mojo.ruby.script.Script;
import de.saumya.mojo.ruby.script.ScriptException;
/**
* goal to push a given gem or a gem artifact to rubygems.org via the
* command "gem push {gem}"
*/
@Mojo( name = "push", defaultPhase = LifecyclePhase.DEPLOY )
public class PushMojo extends AbstractGemMojo {
/**
* skip the pushng the gem
*/
@Parameter( property = "push.skip", defaultValue = "false" )
protected boolean skip;
/**
* arguments for the ruby script given through file parameter.
*/
@Parameter( property = "push.args" )
protected String pushArgs;
/**
* arguments for the ruby script given through file parameter.
*/
@Parameter( property = "gem" )
protected File gem;
@Parameter( defaultValue = "${repositorySystemSession}", readonly = true )
protected Object repoSession;
@Override
public void execute() throws MojoExecutionException, MojoFailureException{
if (skip){
getLog().info( "skipping to push gem" );
}
else {
super.execute();
}
}
@Override
public void executeWithGems() throws MojoExecutionException,
ScriptException, IOException, MojoFailureException, GemException {
final Script script = this.factory.newScriptFromJRubyJar("gem")
.addArg("push");
if(this.project.getArtifact().getFile() == null){
File f = new File(this.project.getBuild().getDirectory(), this.project.getBuild().getFinalName() +".gem");
if (f.exists()) {
this.project.getArtifact().setFile(f);
}
}
// no given gem and pom artifact in place
if (this.gem == null && this.project.getArtifact() != null
&& this.project.getArtifact().getFile() != null
&& this.project.getArtifact().getFile().exists()) {
final GemArtifact gemArtifact = new GemArtifact(this.project);
// skip artifact unless it is a gem.
// this allows to use this mojo for installing arbitrary gems
if (!gemArtifact.isGem()) {
throw new MojoExecutionException("not a gem artifact");
}
script.addArg(gemArtifact.getFile());
}
else {
// no pom artifact and no given gem so search for a gem
if (this.gem == null && null == args ) {
for (final File f : this.launchDirectory().listFiles()) {
if (f.getName().endsWith(".gem")) {
if (this.gem == null) {
this.gem = f;
}
else {
throw new MojoFailureException("more than one gem file found, use -Dgem=... to specifiy one");
}
}
}
}
if (this.gem != null) {
getLog().info("use gem: " + this.gem);
script.addArg(this.gem);
}
}
script.addArgs(this.pushArgs);
script.addArgs(this.args);
script.execute();
}
}