diff --git a/.gitignore b/.gitignore
index f590d8b..0c66bf9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,12 @@
.metadata/
.settings/
+.project
+.classpath
*.class
*.pyc
target/
+.idea
+*.iml
RemoteSystemsTempFiles
+.DS_Store
diff --git a/maven-python-mojos/maven-bdd-plugin/pom.xml b/maven-python-mojos/maven-bdd-plugin/pom.xml
index 8ff4734..6a72e17 100644
--- a/maven-python-mojos/maven-bdd-plugin/pom.xml
+++ b/maven-python-mojos/maven-bdd-plugin/pom.xml
@@ -26,6 +26,27 @@
org.javatuples
javatuples
+
+ org.apache.maven
+ maven-plugin-api
+
+
+ org.projectlombok
+ lombok
+
+
+ commons-io
+ commons-io
+
+
+ com.google.collections
+ google-collections
+
+
+
+ junit
+ junit
+
diff --git a/maven-python-mojos/maven-python-distribute-plugin/pom.xml b/maven-python-mojos/maven-python-distribute-plugin/pom.xml
index b85e3e8..afe3830 100644
--- a/maven-python-mojos/maven-python-distribute-plugin/pom.xml
+++ b/maven-python-mojos/maven-python-distribute-plugin/pom.xml
@@ -6,16 +6,40 @@
maven-python-mojos
maven-python-mojos
- 1.2
+ 1.3
+ ../pom.xml
maven-python-mojos
maven-python-distribute-plugin
- 0.1.1
+ 0.1.3
maven-plugin
Maven Python Distribute Plugin
-
+
+
+ org.apache.maven
+ maven-project
+
+
+ org.apache.maven
+ maven-plugin-api
+
+
+ commons-io
+ commons-io
+
+
+ org.projectlombok
+ lombok
+
+
+
+ junit
+ junit
+
+
+
diff --git a/maven-python-mojos/maven-python-distribute-plugin/src/main/java/com/github/mojos/distribute/PackageMojo.java b/maven-python-mojos/maven-python-distribute-plugin/src/main/java/com/github/mojos/distribute/PackageMojo.java
index dfd8a52..561712a 100644
--- a/maven-python-mojos/maven-python-distribute-plugin/src/main/java/com/github/mojos/distribute/PackageMojo.java
+++ b/maven-python-mojos/maven-python-distribute-plugin/src/main/java/com/github/mojos/distribute/PackageMojo.java
@@ -16,94 +16,157 @@
* limitations under the License.
*/
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
import java.util.List;
-import lombok.Getter;
-import lombok.Setter;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-
/**
* Packages a Python module using distribute
- *
+ *
* @goal package
* @phase package
*/
public class PackageMojo extends AbstractMojo {
- private static final String VERSION = "${VERSION}";
-
- /**
- * @parameter expression="${project.version}"
- * @required
- */
- private String projectVersion;
-
- /**
- * Allows overriding the default version
- */
- @Getter @Setter private String version = null;
-
- /* (non-Javadoc)
- * @see org.apache.maven.plugin.AbstractMojo#execute()
- */
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- File setup = new File("src/main/python/setup.py");
-
- try {
-
- if (version != null) {
- version = projectVersion;
- }
-
-
- //update VERSION to latest version
- List lines = IOUtils.readLines(new BufferedInputStream(new FileInputStream(setup)));
- for(String line : lines) {
- if (line.contains(VERSION)) {
- line = line.replace(VERSION,version);
- }
- }
- IOUtils.writeLines(lines,"\n", new BufferedOutputStream(new FileOutputStream(setup)));
-
- //execute setup script
- ProcessBuilder t = new ProcessBuilder("python","setup.py","bdist_egg");
- t.directory(new File("src/test/python"));
- t.redirectErrorStream(true);
-
- Process pr = t.start();
- int exitCode = pr.waitFor();
- BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
- String line = "";
- while ((line = buf.readLine()) != null) {
- getLog().info(line);
- }
-
- if (exitCode != 0) {
- throw new MojoExecutionException("python setup.py returned error code " + exitCode);
- }
-
- } catch (FileNotFoundException e) {
- throw new MojoExecutionException("Unable to find " + setup.getPath(),e);
- } catch (IOException e) {
- throw new MojoExecutionException("Unable to read " + setup.getPath(),e);
- } catch (InterruptedException e) {
- throw new MojoExecutionException("Unable to execute python " + setup.getPath(),e);
- }
-
-
- }
+ private static final String PROJECT_NAME = "${PROJECT_NAME}";
+ private static final String VERSION = "${VERSION}";
+
+ /**
+ * @parameter default-value="${project.version}"
+ * @required
+ */
+ private String packageVersion;
+
+ /**
+ * Allows overriding the default version
+ */
+ @Getter
+ @Setter
+ private String version;
+
+ /**
+ * @parameter default-value="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * @parameter default-value="${project.basedir}/src/main/python"
+ * @required
+ */
+ private String sourceDirectory;
+
+ /**
+ * @parameter default-value="${project.artifactId}"
+ * @required
+ */
+ private String packageName;
+
+ /**
+ * @parameter default-value="python"
+ * @required
+ */
+ private String pythonExecutable;
+
+ /* (non-Javadoc)
+ * @see org.apache.maven.plugin.AbstractMojo#execute()
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ if (version != null) {
+ packageVersion = version;
+ }
+
+ //Copy sourceDirectory
+ final File sourceDirectoryFile = new File(sourceDirectory);
+ final File buildDirectory = Paths.get(project.getBuild().getDirectory(), "py").toFile();
+
+ try {
+ FileUtils.copyDirectory(sourceDirectoryFile, buildDirectory);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Failed to copy source", e);
+ }
+
+ final File setup = Paths.get(buildDirectory.getPath(), "setup.py").toFile();
+ final boolean setupProvided = setup.exists();
+
+ final File setupTemplate = setupProvided ? setup : Paths.get(buildDirectory.getPath(), "setup-template.py").toFile();
+
+ try {
+ if (!setupProvided) {
+ //update VERSION to latest version
+ List lines = new ArrayList();
+ final InputStream inputStream = new BufferedInputStream(new FileInputStream(setupTemplate));
+ try {
+ lines.addAll(IOUtils.readLines(inputStream));
+ } finally {
+ inputStream.close();
+ }
+
+ int index = 0;
+ for (String line : lines) {
+ line = line.replace(VERSION, packageVersion);
+ line = line.replace(PROJECT_NAME, packageName);
+ lines.set(index, line);
+ index++;
+ }
+
+ final OutputStream outputStream = new FileOutputStream(setup);
+ try {
+ IOUtils.writeLines(lines, "\n", outputStream);
+ } finally {
+ outputStream.flush();
+ outputStream.close();
+ }
+ }
+
+ //execute setup script
+ ProcessBuilder processBuilder = new ProcessBuilder(pythonExecutable, setup.getCanonicalPath(), "bdist_egg");
+ processBuilder.directory(buildDirectory);
+ processBuilder.redirectErrorStream(true);
+
+ Process pr = processBuilder.start();
+ int exitCode = pr.waitFor();
+ BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
+ String line = "";
+ while ((line = buf.readLine()) != null) {
+ getLog().info(line);
+ }
+
+ if (exitCode != 0) {
+ throw new MojoExecutionException("python setup.py returned error code " + exitCode);
+ }
+
+ } catch (FileNotFoundException e) {
+ throw new MojoExecutionException("Unable to find " + setup.getPath(), e);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Unable to read " + setup.getPath(), e);
+ } catch (InterruptedException e) {
+ throw new MojoExecutionException("Unable to execute python " + setup.getPath(), e);
+ }
+
+
+ }
}
diff --git a/maven-python-mojos/pom.xml b/maven-python-mojos/pom.xml
index 92f9e38..9e27a0f 100644
--- a/maven-python-mojos/pom.xml
+++ b/maven-python-mojos/pom.xml
@@ -1,151 +1,159 @@
- 4.0.0
-
- maven-python-mojos
- maven-python-mojos
- 1.3
- pom
-
- Parent Maven Python Mojos
- Parent Module for all Maven Python Mojos
- https://github.com/jacek99/Maven-Python-Mojos
-
-
- maven-bdd-plugin
- maven-python-distribute-plugin
-
-
-
- UTF-8
-
-
-
- Jacek Furmankiewicz
- jacek99@gmail.com
-
-
-
-
-
- org.apache.maven
- maven-plugin-api
- 2.0
-
-
-
- org.projectlombok
- lombok
- 0.11.2
- provided
-
-
- commons-io
- commons-io
- 2.0
- compile
-
-
- com.google.collections
- google-collections
- 1.0
-
-
- junit
- junit
- 4.7
- test
-
-
-
-
-
-
- org.apache.maven
- maven-core
- 2.2.1
-
-
- org.javatuples
- javatuples
- 1.1
-
-
-
-
-
-
-
- maven-compiler-plugin
-
- 1.5
- 1.5
-
-
-
-
- org.apache.maven.plugins
- maven-plugin-plugin
- 2.5.1
-
-
- generated-helpmojo
-
- helpmojo
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
-
-
- attach-javadocs
- verify
-
- jar
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-source-plugin
- 2.1.1
-
-
- attach-sources
- verify
-
- jar-no-fork
-
-
-
-
-
-
-
-
-
- org.jvnet.wagon-svn
- wagon-svn
- 1.9
-
-
-
-
-
-
-
- googlecode
- svn:https://javabuilders.googlecode.com/svn/repo
-
-
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+
+ maven-python-mojos
+ maven-python-mojos
+ 1.3
+ pom
+
+ Parent Maven Python Mojos
+ Parent Module for all Maven Python Mojos
+ https://github.com/jacek99/Maven-Python-Mojos
+
+
+ maven-python-distribute-plugin
+ maven-bdd-plugin
+
+
+
+ UTF-8
+
+
+
+
+ Jacek Furmankiewicz
+ jacek99@gmail.com
+
+
+
+
+
+
+
+ org.apache.maven
+ maven-project
+ 2.0.6
+ compile
+
+
+ org.apache.maven
+ maven-plugin-api
+ 2.0
+ compile
+
+
+ org.projectlombok
+ lombok
+ 0.11.2
+ compile
+
+
+ commons-io
+ commons-io
+ 2.0
+ compile
+
+
+ com.google.collections
+ google-collections
+ 1.0
+ compile
+
+
+ org.javatuples
+ javatuples
+ 1.1
+ compile
+
+
+
+ junit
+ junit
+ 4.7
+ test
+
+
+ org.apache.maven
+ maven-core
+ 2.2.1
+
+
+
+
+
+
+
+
+ maven-compiler-plugin
+
+ 1.5
+ 1.5
+
+
+
+
+ org.apache.maven.plugins
+ maven-plugin-plugin
+ 2.5.1
+
+
+ generated-helpmojo
+
+ helpmojo
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+
+
+ attach-javadocs
+ verify
+
+ jar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 2.1.1
+
+
+ attach-sources
+ verify
+
+ jar-no-fork
+
+
+
+
+
+
+
+
+
+ org.jvnet.wagon-svn
+ wagon-svn
+ 1.9
+
+
+
+
+
+
+
+ googlecode
+ svn:https://javabuilders.googlecode.com/svn/repo
+
+
\ No newline at end of file