run-script-maven-plugin/src/main/java/org/lcsim
diff -u -r1.9 -r1.10
--- RunScriptMavenPluginMojo.java 16 Mar 2009 23:28:46 -0000 1.9
+++ RunScriptMavenPluginMojo.java 17 Mar 2009 18:19:57 -0000 1.10
@@ -16,9 +16,12 @@
import org.apache.maven.project.MavenProject;
/**
- * A Maven plugin that generates a portable run script.
+ * A Maven plugin that generates a run script
+ * for the current project.
*
* @goal generate-run-script
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
*/
public class RunScriptMavenPluginMojo extends AbstractMojo
{
@@ -69,7 +72,8 @@
List<String> classPathEntries = makeClassPathEntries();
// If a library directory is specified, copy the dependencies there,
- // and get back a new set of class path entries.
+ // and get back a new set of class path entries pointing to the new
+ // locations for the jars.
if (libDir != null)
{
classPathEntries = copyDepsToLibDir(libDir, classPathEntries);
@@ -92,11 +96,19 @@
}
// Full path to the script.
- File scriptFile = new File(binDir + File.separator + scriptName.replace(" ", ""));
+ String scriptPath = binDir + File.separator + scriptName.replace(" ", "");
+
+ // Make a .bat file if running on Windows.
+ if (System.getProperty("os.name").contains("Windows"))
+ scriptPath += ".bat";
+
+ // Create the script file.
+ File scriptFile = new File(scriptPath);
- // Create the run script in the bin dir.
+ // Output the script to the path.
Writer output = null;
- try {
+ try
+ {
output = new BufferedWriter(new FileWriter(scriptFile));
output.write(runLine);
output.close();
@@ -107,7 +119,6 @@
}
// Set run script permissions if on Linux or Mac OS X.
- // (No idea about how to do this on Windows with a simple command.)
String os = System.getProperty("os.name");
if (os.equals("Linux") || os.equals("Mac OS X"))
{
@@ -120,13 +131,11 @@
throw new RuntimeException(x);
}
}
- // Java 1.6 only!
- //scriptFile.setExecutable(true);
}
/**
- * Makes a list of class path entries including this project's dependencies
- * and its own jar.
+ * Makes a list of class path entries, including this project's dependencies
+ * and its own jar, from the Maven artifact information for this project.
* @return A list of class path entries.
*/
private List<String> makeClassPathEntries()
@@ -160,9 +169,11 @@
}
/**
- * Creates a class path with entries separated by colons.
+ * Creates a class path with entries separated by colons
+ * from a list of class path entry strings that should point
+ * to jar files or directories with class files.
* @param classPathEntries A list of class path entries.
- * @return A string with the class path.
+ * @return A single string with the full colon-delimited class path.
*/
private String makeClassPath(List<String> classPathEntries)
{
@@ -190,10 +201,7 @@
File libDirFile = new File(libDir);
if (!libDirFile.exists())
{
- libDirFile.mkdir();
- //libDirFile.setExecutable(true);
- //libDirFile.setReadable(true);
- //libDirFile.setWritable(true);
+ libDirFile.mkdirs();
}
for (String depPath : classPathEntries)
{
@@ -202,24 +210,22 @@
File libFile = new File(libPath);
try
{
- //System.out.println("copying " + repoFile.getCanonicalPath() + " to " + libFile.getCanonicalPath());
copyFile(repoFile, libFile);
}
catch (Exception x)
{
throw new RuntimeException("Problem copying " + repoFile.getAbsolutePath() + " to " + libFile.getAbsolutePath() + ".");
}
- //System.out.println("adding new classpath entry " + libPath);
newClassPathEntries.add(libPath);
}
return newClassPathEntries;
}
/**
- * Simple file copy utility method.
- * @param in
- * @param out
- * @throws Exception
+ * A simple file copy utility method.
+ * @param in The input file.
+ * @param out The output file.
+ * @throws Exception if there is a problem writing to the output destination.
*/
private static void copyFile(File in, File out) throws Exception
{