Index: InstallMojo.java =================================================================== --- InstallMojo.java (revision 672740) +++ InstallMojo.java (working copy) @@ -25,7 +25,15 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.artifact.ProjectArtifactMetadata; +import java.io.BufferedReader; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.Iterator; import java.util.List; @@ -69,12 +77,62 @@ private Artifact artifact; /** - * @parameter expression="${project.attachedArtifacts} + * @parameter expression="${project.attachedArtifacts}" * @required * @readonly */ private List attachedArtifacts; + /** + * @parameter expression="${project.properties}" + * @required + * @readonly + */ + private Properties properties; + + /** + * @parameter expression="${project.build.directory}" + * @required + * @readonly + */ + private File targetDirectory; + + + private File insertProperties(File thePom) { + try { + BufferedReader br = new BufferedReader(new FileReader(thePom)); + StringBuffer buf = new StringBuffer(); + Pattern p = Pattern.compile("\\$\\{[a-zA-Z]+\\}"); + String s = null; + while((s = br.readLine()) != null) { + Matcher m = p.matcher(s); + while (m.find()) { + String match = m.group(); + String key = match.substring(2, match.length()-1); + String value = properties.getProperty(key); + if (value != null) { + s = s.replaceAll("\\$\\{" + key + "\\}", value); + } + } + buf.append(s).append("\n"); + } + if (!targetDirectory.exists()) { + targetDirectory.mkdirs(); + } + File newPom = new File(targetDirectory, "pom-with-properties.xml"); + FileWriter fw = new FileWriter(newPom); + fw.write(buf.toString()); + fw.flush(); + fw.close(); + thePom = newPom; + } catch (FileNotFoundException e) { + getLog().warn(e.getMessage()); + } catch (IOException e) { + getLog().warn(e.getMessage()); + } + return thePom; + } + public void execute() throws MojoExecutionException { @@ -92,7 +150,7 @@ { if ( isPomArtifact ) { - installer.install( pomFile, artifact, localRepository ); + installer.install( insertProperties(pomFile), artifact, localRepository ); } else {