Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 437a588b8b23f3c59a044afb689858037d20fc6d @brianm committed Sep 22, 2011
Showing with 155 additions and 0 deletions.
  1. +14 −0 .gitignore
  2. +79 −0 pom.xml
  3. +62 −0 src/main/java/org/skife/waffles/MyMojo.java
@@ -0,0 +1,14 @@
+target
+report
+*.ipr
+*.iws
+*.iml
+.clover
+.idea
+build
+out
+.classpath
+.project
+.settings
+*~
+test-output
79 pom.xml
@@ -0,0 +1,79 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.skife.maven</groupId>
+ <artifactId>really-executable-jar</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <name>Really Executable Jar Maven Plugin</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0.6</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0.6</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ <encoding>UTF-8</encoding>
+ </configuration>
+ </plugin>
+
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>2.5.1</version>
+ <configuration>
+ <goalPrefix>really-executable-jar</goalPrefix>
+ </configuration>
+ <executions>
+ <execution>
+ <id>generated-helpmojo</id>
+ <goals>
+ <goal>helpmojo</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
@@ -0,0 +1,62 @@
+package org.skife.waffles;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.AttachedArtifact;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ * @goal really-executable-jar
+ */
+public class MyMojo extends AbstractMojo
+{
+
+ /**
+ * The Maven project.
+ *
+ * @parameter expression="${project}"
+ * @required
+ * @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * The greeting to display.
+ *
+ * @parameter
+ */
+ private String flags = "";
+
+ public void execute() throws MojoExecutionException
+ {
+ try {
+
+ for (Object o : project.getAttachedArtifacts()) {
+ AttachedArtifact a = (AttachedArtifact) o;
+ File f = a.getFile();
+ File tmp = File.createTempFile("waffles", ".tmp");
+
+ FileUtils.rename(f, tmp);
+
+ FileOutputStream fout = new FileOutputStream(f);
+ FileInputStream in = new FileInputStream(tmp);
+ fout.write(("#!/bin/sh\n\nexec java " + flags + " -jar $0 $@\n\n").getBytes());
+ IOUtil.copy(in, fout);
+ in.close();
+ fout.close();
+ Runtime.getRuntime().exec("chmod +x " + f.getAbsolutePath());
+ }
+ }
+ catch (IOException e) {
+ throw new MojoExecutionException(e, "FAILURE!", e.getMessage());
+ }
+
+ }
+}

0 comments on commit 437a588

Please sign in to comment.