Skip to content

Commit 3332998

Browse files
committedJul 29, 2016
Add call prefix for windows batch file, fix SNAPSHOT handling
1 parent fec0ce0 commit 3332998

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed
 

‎src/main/java/com/github/ahatius/maven/DeploymentGenerator.java

+30-15
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javax.xml.parsers.ParserConfigurationException;
1212

1313
import org.apache.commons.io.FileUtils;
14+
import org.apache.commons.io.FilenameUtils;
1415
import org.apache.commons.io.filefilter.DirectoryFileFilter;
1516
import org.apache.commons.io.filefilter.RegexFileFilter;
1617
import org.w3c.dom.Document;
@@ -21,7 +22,8 @@
2122
import com.beust.jcommander.ParameterException;
2223

2324
public class DeploymentGenerator {
24-
public DeploymentGenerator(String[] args) throws ParserConfigurationException, IOException, SAXException {
25+
public DeploymentGenerator(String[] args)
26+
throws ParserConfigurationException, IOException, SAXException {
2527
// Parse arguments and validate them
2628
Arguments arguments = new Arguments();
2729
JCommander cli = new JCommander(arguments);
@@ -36,35 +38,44 @@ public DeploymentGenerator(String[] args) throws ParserConfigurationException, I
3638
}
3739

3840
Collection<File> files = FileUtils.listFiles(arguments.dir, new RegexFileFilter("^(.*?)\\.pom"),
39-
DirectoryFileFilter.DIRECTORY);
41+
DirectoryFileFilter.DIRECTORY);
4042

4143
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
4244
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
4345

4446
BufferedWriter writer = new BufferedWriter(new FileWriter(arguments.output));
4547
try {
48+
String prefix = "";
49+
if (arguments.windows) {
50+
prefix = "call ";
51+
} else {
52+
writer.write("#!/bin/bash");
53+
writer.newLine();
54+
}
55+
4656
for (File file : files) {
4757
Document document = documentBuilder.parse(file);
4858

4959
String groupId = document.getElementsByTagName("groupId").item(0).getTextContent();
5060
String artifactId = document.getElementsByTagName("artifactId").item(0).getTextContent();
5161
String version = document.getElementsByTagName("version").item(0).getTextContent();
5262

53-
File artifact = new File(file.getParent(), artifactId + "-" + version + ".jar");
54-
File sources = new File(file.getParent(), artifactId + "-" + version + "-sources.jar");
55-
File javadoc = new File(file.getParent(), artifactId + "-" + version + "-javadoc.jar");
63+
String filename = FilenameUtils.removeExtension(file.getName());
64+
File artifact = new File(file.getParent(), filename + ".jar");
65+
File sources = new File(file.getParent(), filename + "-sources.jar");
66+
File javadoc = new File(file.getParent(), filename + "-javadoc.jar");
5667

57-
if(!artifact.isFile()) {
58-
System.out.println("Artifact for " + groupId + ":" + artifactId + ":" + version + " not found");
68+
if (!artifact.isFile()) {
5969
continue;
6070
}
6171

6272
StringBuilder sb = new StringBuilder();
6373

64-
sb.append("call mvn deploy:deploy-file -DgeneratePom=false ");
74+
sb.append(prefix);
75+
sb.append("mvn deploy:deploy-file -DgeneratePom=false ");
6576
sb.append("-Durl=");
6677

67-
if(!version.toLowerCase().endsWith("-snapshot")) {
78+
if (!version.toLowerCase().endsWith("-snapshot")) {
6879
sb.append(arguments.releaseUrl);
6980
} else {
7081
sb.append(arguments.snapshotUrl);
@@ -115,7 +126,7 @@ public DeploymentGenerator(String[] args) throws ParserConfigurationException, I
115126
* @param args Commandline arguments
116127
*/
117128
public static void main(String[] args)
118-
throws IOException, SAXException, ParserConfigurationException {
129+
throws IOException, SAXException, ParserConfigurationException {
119130
new DeploymentGenerator(args);
120131
}
121132

@@ -140,21 +151,25 @@ private static class Arguments {
140151
private File dir;
141152

142153
@Parameter(names = {"-r"},
143-
description = "The target repository id that is configured in the settings.xml",
144-
required = true)
154+
description = "The target repository id that is configured in the settings.xml",
155+
required = true)
145156
private String repositoryId;
146157

147158
@Parameter(names = {"-u"}, description = "The target deployment URL for releases",
148-
required = true)
159+
required = true)
149160
private String releaseUrl;
150161

151162
@Parameter(names = {"-s"}, description = "The target deployment URL for snapshots",
152163
required = true)
153164
private String snapshotUrl;
154165

155166
@Parameter(names = {"-o"},
156-
description = "The shell script that should be generated by this application",
157-
required = true)
167+
description = "The shell script that should be generated by this application",
168+
required = true)
158169
private File output;
170+
171+
@Parameter(names = {"-w"},
172+
description = "Windows batch mode - adds a call command before each mvn command to allow execution within a batch script, otherwise a shell script will be created")
173+
private boolean windows;
159174
}
160175
}

0 commit comments

Comments
 (0)
Please sign in to comment.