View Javadoc

1   package org.apache.torque.mojo.morph;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.apache.commons.logging.Log;
5   import org.apache.commons.logging.LogFactory;
6   
7   public class VersionTableMorpher extends Morpher {
8   	private static final Log log = LogFactory.getLog(VersionTableMorpher.class);
9   
10  	String projectVersion;
11  
12  	public VersionTableMorpher() {
13  		this(null, null);
14  	}
15  
16  	public VersionTableMorpher(MorphRequest morphRequest, String artifactId) {
17  		super(morphRequest, artifactId);
18  	}
19  
20  	protected String getMorphedContents(String contents) {
21  		log.debug("contents=" + contents);
22  		String oldVersion = StringUtils.substringBetween(contents, "VERSION=\"", "\"");
23  		String searchString = "VERSION=\"" + oldVersion + "\"";
24  		String replacement = "VERSION=\"" + getProjectVersion() + "\"";
25  		String s = StringUtils.replace(contents, searchString, replacement);
26  		return s;
27  	}
28  
29  	/**
30  	 * Return true if we need to morph this file
31  	 */
32  	protected boolean isMorphNeeded(String contents) {
33  		return true;
34  	}
35  
36  	public String getProjectVersion() {
37  		return projectVersion;
38  	}
39  
40  	public void setProjectVersion(String projectVersion) {
41  		this.projectVersion = projectVersion;
42  	}
43  
44  }