Skip to content

Commit d38ee72

Browse files
committed
Initial commit
0 parents  commit d38ee72

File tree

5 files changed

+331
-0
lines changed

5 files changed

+331
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target/
2+
/.settings/
3+
.classpath

README.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# General
2+
Generates a list of mvn commands that can be executed to upload artifacts from a directory to a
3+
remote repository. To use the generated commands, you need to configure your Maven settings.xml with
4+
the target repository (id, user, password).
5+
6+
# Configuration
7+
Example repository configuration:
8+
```xml
9+
<settings>
10+
...
11+
<servers>
12+
<server>
13+
<id>repository-id</id>
14+
<username>deployment-user</username>
15+
<password>password</password>
16+
</server>
17+
</servers>
18+
</settings>
19+
20+
```
21+
22+
The value of the `<id>` tag needs to be passed as the `-r` parameter to the application.
23+
24+
# Usage
25+
```
26+
The following options are required: -o -r -d -u
27+
28+
Usage: <main class> [options]
29+
Options:
30+
* -d
31+
The directory to scan for pom files
32+
* -o
33+
The shell script that should be generated by this application
34+
* -r
35+
The target repository id that is configured in the settings.xml
36+
* -u
37+
The target deployment URL of the repository
38+
39+
```

deploy-command-generator.iml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
11+
<excludeFolder url="file://$MODULE_DIR$/target" />
12+
</content>
13+
<orderEntry type="inheritedJdk" />
14+
<orderEntry type="sourceFolder" forTests="false" />
15+
<orderEntry type="library" name="Maven: com.beust:jcommander:1.47" level="project" />
16+
<orderEntry type="library" name="Maven: commons-io:commons-io:2.5" level="project" />
17+
</component>
18+
</module>

pom.xml

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.github.ahatius.maven</groupId>
5+
<artifactId>deploy-command-generator</artifactId>
6+
<version>1.0.0</version>
7+
8+
<name>uploader</name>
9+
<description></description>
10+
11+
<properties>
12+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
15+
<timestamp>${maven.build.timestamp}</timestamp>
16+
<maven.build.timestamp.format>yyyy</maven.build.timestamp.format>
17+
18+
<sonar.language>java</sonar.language>
19+
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>com.beust</groupId>
25+
<artifactId>jcommander</artifactId>
26+
<version>1.47</version>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>commons-io</groupId>
31+
<artifactId>commons-io</artifactId>
32+
<version>2.5</version>
33+
</dependency>
34+
</dependencies>
35+
36+
<build>
37+
<finalName>${project.artifactId}</finalName>
38+
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-source-plugin</artifactId>
43+
<version>2.4</version>
44+
45+
<executions>
46+
<execution>
47+
<id>attach-sources</id>
48+
<goals>
49+
<goal>jar</goal>
50+
</goals>
51+
</execution>
52+
</executions>
53+
</plugin>
54+
55+
<plugin>
56+
<groupId>org.apache.maven.plugins</groupId>
57+
<artifactId>maven-javadoc-plugin</artifactId>
58+
<version>2.10.3</version>
59+
60+
<executions>
61+
<execution>
62+
<id>attach-javadocs</id>
63+
<goals>
64+
<goal>jar</goal>
65+
</goals>
66+
</execution>
67+
</executions>
68+
</plugin>
69+
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-deploy-plugin</artifactId>
73+
<version>2.8.2</version>
74+
75+
<executions>
76+
<execution>
77+
<id>deploy</id>
78+
<phase>deploy</phase>
79+
</execution>
80+
</executions>
81+
</plugin>
82+
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-compiler-plugin</artifactId>
86+
<version>3.5</version>
87+
88+
<configuration>
89+
<source>1.6</source>
90+
<target>1.6</target>
91+
</configuration>
92+
</plugin>
93+
94+
<plugin>
95+
<groupId>org.apache.maven.plugins</groupId>
96+
<artifactId>maven-shade-plugin</artifactId>
97+
<version>2.4.3</version>
98+
<executions>
99+
<execution>
100+
<phase>package</phase>
101+
102+
<goals>
103+
<goal>shade</goal>
104+
</goals>
105+
106+
<configuration>
107+
<transformers>
108+
<transformer
109+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
110+
<mainClass>com.github.ahatius.maven.DeploymentGenerator</mainClass>
111+
<manifestEntries>
112+
<Implementation-Title>${project.name}</Implementation-Title>
113+
<Implementation-Version>${project.version}</Implementation-Version>
114+
<Implementation-Vendor>Ahatius, ${timestamp}</Implementation-Vendor>
115+
</manifestEntries>
116+
</transformer>
117+
</transformers>
118+
119+
<createDependencyReducedPom>false</createDependencyReducedPom>
120+
</configuration>
121+
</execution>
122+
</executions>
123+
</plugin>
124+
</plugins>
125+
</build>
126+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package com.github.ahatius.maven;
2+
3+
import java.io.BufferedWriter;
4+
import java.io.File;
5+
import java.io.FileWriter;
6+
import java.io.IOException;
7+
import java.util.Collection;
8+
9+
import javax.xml.parsers.DocumentBuilder;
10+
import javax.xml.parsers.DocumentBuilderFactory;
11+
import javax.xml.parsers.ParserConfigurationException;
12+
13+
import org.apache.commons.io.FileUtils;
14+
import org.apache.commons.io.filefilter.DirectoryFileFilter;
15+
import org.apache.commons.io.filefilter.RegexFileFilter;
16+
import org.w3c.dom.Document;
17+
import org.xml.sax.SAXException;
18+
19+
import com.beust.jcommander.JCommander;
20+
import com.beust.jcommander.Parameter;
21+
import com.beust.jcommander.ParameterException;
22+
23+
public class DeploymentGenerator {
24+
public DeploymentGenerator(String[] args) throws ParserConfigurationException, IOException, SAXException {
25+
// Parse arguments and validate them
26+
Arguments arguments = new Arguments();
27+
JCommander cli = new JCommander(arguments);
28+
29+
try {
30+
cli.parse(args);
31+
} catch (ParameterException e) {
32+
// Display help and exit
33+
printHelp(cli, e.getMessage());
34+
System.exit(1);
35+
return;
36+
}
37+
38+
Collection<File> files = FileUtils.listFiles(arguments.dir, new RegexFileFilter("^(.*?)\\.pom"),
39+
DirectoryFileFilter.DIRECTORY);
40+
41+
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
42+
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
43+
44+
BufferedWriter writer = new BufferedWriter(new FileWriter(arguments.output));
45+
try {
46+
for (File file : files) {
47+
Document document = documentBuilder.parse(file);
48+
49+
String groupId = document.getElementsByTagName("groupId").item(0).getTextContent();
50+
String artifactId = document.getElementsByTagName("artifactId").item(0).getTextContent();
51+
String version = document.getElementsByTagName("version").item(0).getTextContent();
52+
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");
56+
57+
StringBuilder sb = new StringBuilder();
58+
59+
sb.append("mvn deploy:deploy-file -DgeneratePom=false ");
60+
sb.append("-Durl=");
61+
sb.append(arguments.url);
62+
sb.append(" ");
63+
sb.append("-DgroupId=");
64+
sb.append(groupId);
65+
sb.append(" ");
66+
sb.append("-DartifactId=");
67+
sb.append(artifactId);
68+
sb.append(" ");
69+
sb.append("-Dversion=");
70+
sb.append(version);
71+
sb.append(" ");
72+
sb.append("-DpomFile=");
73+
sb.append(file.getAbsolutePath());
74+
sb.append(" ");
75+
sb.append("-Dfile=");
76+
sb.append(artifact.getAbsolutePath());
77+
sb.append(" ");
78+
sb.append("-DrepositoryId=");
79+
sb.append(arguments.repositoryId);
80+
81+
if (sources.exists()) {
82+
sb.append(" ");
83+
sb.append("-Dsources=");
84+
sb.append(sources.getAbsolutePath());
85+
}
86+
87+
if (javadoc.exists()) {
88+
sb.append(" ");
89+
sb.append("-javadoc=");
90+
sb.append(javadoc.getAbsolutePath());
91+
}
92+
93+
writer.write(sb.toString());
94+
writer.newLine();
95+
}
96+
} finally {
97+
writer.close();
98+
}
99+
}
100+
101+
/**
102+
* Main method
103+
*
104+
* @param args Commandline arguments
105+
*/
106+
public static void main(String[] args)
107+
throws IOException, SAXException, ParserConfigurationException {
108+
new DeploymentGenerator(args);
109+
}
110+
111+
/**
112+
* Prints the help text including a message what went wrong
113+
*
114+
* @param cli The JCommander object that will be used to generate the help
115+
* @param message Additional information that shows why the help is shown
116+
*/
117+
private static void printHelp(JCommander cli, String message) {
118+
System.out.println();
119+
System.out.println(message);
120+
System.out.println();
121+
cli.usage();
122+
}
123+
124+
/**
125+
* Contains the allowed and required arguments for this application
126+
*/
127+
private static class Arguments {
128+
@Parameter(names = {"-d"}, description = "The directory to scan for pom files", required = true)
129+
private File dir;
130+
131+
@Parameter(names = {"-r"},
132+
description = "The target repository id that is configured in the settings.xml",
133+
required = true)
134+
private String repositoryId;
135+
136+
@Parameter(names = {"-u"}, description = "The target deployment URL of the repository",
137+
required = true)
138+
private String url;
139+
140+
@Parameter(names = {"-o"},
141+
description = "The shell script that should be generated by this application",
142+
required = true)
143+
private File output;
144+
}
145+
}

0 commit comments

Comments
 (0)