Index: InstallMojo.java =================================================================== --- InstallMojo.java (revisjon 697039) +++ InstallMojo.java (arbeidskopi) @@ -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,73 @@ private Artifact artifact; /** - * @parameter expression="${project.attachedArtifacts} + * @parameter expression="${project.attachedArtifacts}" * @required * @readonly */ private List attachedArtifacts; + /** + * @parameter expression="${project.properties}" + * @required + * @readonly + */ + private Properties projectProperties; + + /** + * @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-Z0-9_-]+\\}"); + String s = null; + boolean changed = false; + Properties systemProperties = System.getProperties(); + 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 = null; + if (projectProperties != null && projectProperties.containsKey(key)) { + value = projectProperties.getProperty(key); + } else if (systemProperties.containsKey(key)) { + value = systemProperties.getProperty(key); + } + if (value != null) { + s = s.replaceAll("\\$\\{" + key + "\\}", value); + changed = true; + } + } + buf.append(s).append("\n"); + } + if (changed) { + File target = new File(targetDirectory.getAbsolutePath() + File.separator + "maven-install-plugin"); + if (!target.exists()) { + target.mkdirs(); + } + File newPom = new File(target, "pom.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 +161,7 @@ { if ( isPomArtifact ) { - installer.install( pomFile, artifact, localRepository ); + installer.install( insertProperties(pomFile), artifact, localRepository ); } else {