diff --git a/dependencies/wso2-esb-api-plugin/src/main/java/org/wso2/maven/api/RESTAPIPOMGenMojo.java b/dependencies/wso2-esb-api-plugin/src/main/java/org/wso2/maven/api/RESTAPIPOMGenMojo.java index 67385bb87..b99a3e164 100644 --- a/dependencies/wso2-esb-api-plugin/src/main/java/org/wso2/maven/api/RESTAPIPOMGenMojo.java +++ b/dependencies/wso2-esb-api-plugin/src/main/java/org/wso2/maven/api/RESTAPIPOMGenMojo.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Properties; +import java.util.StringTokenizer; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; @@ -28,6 +30,7 @@ import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.wso2.developerstudio.eclipse.utils.data.ITemporaryFileTag; import org.wso2.maven.capp.model.Artifact; import org.wso2.maven.capp.mojo.AbstractPOMGenMojo; import org.wso2.maven.capp.utils.CAppMavenUtils; @@ -124,8 +127,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { protected void copyResources(MavenProject project, File projectLocation, Artifact artifact)throws IOException { - File sequenceArtifact = artifact.getFile(); - FileUtils.copyFile(sequenceArtifact, new File(projectLocation, sequenceArtifact.getName())); + ITemporaryFileTag newTag = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createNewTempTag(); + File sequenceArtifact = processTokenReplacement(artifact); + if (sequenceArtifact == null) { + sequenceArtifact = artifact.getFile(); + } + FileUtils.copyFile(sequenceArtifact, new File(projectLocation, artifact.getFile().getName())); + newTag.clearAndEnd(); } protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) { @@ -142,5 +150,41 @@ protected String getArtifactType() { return ARTIFACT_TYPE; } + @Override + protected File processTokenReplacement(Artifact artifact) { + File file = artifact.getFile(); + if(file.exists()){ + String fileContent; + StringBuffer sb=new StringBuffer(); + try { + fileContent = org.wso2.developerstudio.eclipse.utils.file.FileUtils.getContentAsString(file); + StringTokenizer st=new StringTokenizer(fileContent, CAppMavenUtils.REPLACER_DEFAULT_DELIMETER); + + Properties mavenProperties = getProject().getModel().getProperties(); + //Check whether the content actually has tokens and Properties section should define them. Otherwise skip. + //By default there are 2 such properties. So size check is 2. + if (st.countTokens()>1 && mavenProperties.size()>1) { + while (st.hasMoreTokens()) { + String nextToken = st.nextToken(); + if (mavenProperties.containsKey(nextToken)) { + String originalToken = nextToken; + nextToken = (String) mavenProperties.get(nextToken); + getLog().info("Replacing the token: "+originalToken+" with value: "+nextToken); + } + sb.append(nextToken); + } + }else{ + sb.append(fileContent); + } + File tempFile = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createTempFile(); + org.wso2.developerstudio.eclipse.utils.file.FileUtils.writeContent(tempFile, sb.toString()); + return tempFile; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return file; + } } diff --git a/dependencies/wso2-esb-localentry-plugin/src/main/java/org/wso2/maven/plugin/localentry/LocalEntryPOMGenMojo.java b/dependencies/wso2-esb-localentry-plugin/src/main/java/org/wso2/maven/plugin/localentry/LocalEntryPOMGenMojo.java index 39f06afbf..c164720f6 100644 --- a/dependencies/wso2-esb-localentry-plugin/src/main/java/org/wso2/maven/plugin/localentry/LocalEntryPOMGenMojo.java +++ b/dependencies/wso2-esb-localentry-plugin/src/main/java/org/wso2/maven/plugin/localentry/LocalEntryPOMGenMojo.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Properties; +import java.util.StringTokenizer; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; @@ -28,6 +30,7 @@ import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.wso2.developerstudio.eclipse.utils.data.ITemporaryFileTag; import org.wso2.maven.capp.model.Artifact; import org.wso2.maven.capp.mojo.AbstractPOMGenMojo; import org.wso2.maven.capp.utils.CAppMavenUtils; @@ -117,8 +120,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { protected void copyResources(MavenProject project, File projectLocation, Artifact artifact)throws IOException { - File sequenceArtifact = artifact.getFile(); - FileUtils.copyFile(sequenceArtifact, new File(projectLocation, sequenceArtifact.getName())); + ITemporaryFileTag newTag = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createNewTempTag(); + File sequenceArtifact = processTokenReplacement(artifact); + if (sequenceArtifact == null) { + sequenceArtifact = artifact.getFile(); + } + FileUtils.copyFile(sequenceArtifact, new File(projectLocation, artifact.getFile().getName())); + newTag.clearAndEnd(); } protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) { Plugin plugin = CAppMavenUtils.createPluginEntry(artifactMavenProject,"org.wso2.maven","maven-localentry-plugin",WSO2MavenPluginConstantants.MAVEN_LOCALENTRY_PLUGIN_VERSION,true); @@ -131,5 +139,42 @@ protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) protected String getArtifactType() { return ARTIFACT_TYPE; } + + @Override + protected File processTokenReplacement(Artifact artifact) { + File file = artifact.getFile(); + if(file.exists()){ + String fileContent; + StringBuffer sb=new StringBuffer(); + try { + fileContent = org.wso2.developerstudio.eclipse.utils.file.FileUtils.getContentAsString(file); + StringTokenizer st=new StringTokenizer(fileContent, CAppMavenUtils.REPLACER_DEFAULT_DELIMETER); + + Properties mavenProperties = getProject().getModel().getProperties(); + //Check whether the content actually has tokens and Properties section should define them. Otherwise skip. + //By default there are 2 such properties. So size check is 2. + if (st.countTokens()>1 && mavenProperties.size()>1) { + while (st.hasMoreTokens()) { + String nextToken = st.nextToken(); + if (mavenProperties.containsKey(nextToken)) { + String originalToken = nextToken; + nextToken = (String) mavenProperties.get(nextToken); + getLog().info("Replacing the token: "+originalToken+" with value: "+nextToken); + } + sb.append(nextToken); + } + }else{ + sb.append(fileContent); + } + File tempFile = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createTempFile(); + org.wso2.developerstudio.eclipse.utils.file.FileUtils.writeContent(tempFile, sb.toString()); + return tempFile; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return file; + } } diff --git a/dependencies/wso2-esb-proxy-plugin/src/main/java/org/wso2/maven/proxy/ProxyServicePOMGenMojo.java b/dependencies/wso2-esb-proxy-plugin/src/main/java/org/wso2/maven/proxy/ProxyServicePOMGenMojo.java index dd07eb380..2295893e8 100644 --- a/dependencies/wso2-esb-proxy-plugin/src/main/java/org/wso2/maven/proxy/ProxyServicePOMGenMojo.java +++ b/dependencies/wso2-esb-proxy-plugin/src/main/java/org/wso2/maven/proxy/ProxyServicePOMGenMojo.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Properties; +import java.util.StringTokenizer; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; @@ -28,6 +30,7 @@ import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.wso2.developerstudio.eclipse.utils.data.ITemporaryFileTag; import org.wso2.maven.capp.model.Artifact; import org.wso2.maven.capp.mojo.AbstractPOMGenMojo; import org.wso2.maven.capp.utils.CAppMavenUtils; @@ -124,8 +127,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { protected void copyResources(MavenProject project, File projectLocation, Artifact artifact)throws IOException { - File sequenceArtifact = artifact.getFile(); - FileUtils.copyFile(sequenceArtifact, new File(projectLocation, sequenceArtifact.getName())); + ITemporaryFileTag newTag = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createNewTempTag(); + File sequenceArtifact = processTokenReplacement(artifact); + if (sequenceArtifact == null) { + sequenceArtifact = artifact.getFile(); + } + FileUtils.copyFile(sequenceArtifact, new File(projectLocation, artifact.getFile().getName())); + newTag.clearAndEnd(); } protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) { @@ -139,6 +147,43 @@ protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) protected String getArtifactType() { return ARTIFACT_TYPE; } + + @Override + protected File processTokenReplacement(Artifact artifact) { + File file = artifact.getFile(); + if(file.exists()){ + String fileContent; + StringBuffer sb=new StringBuffer(); + try { + fileContent = org.wso2.developerstudio.eclipse.utils.file.FileUtils.getContentAsString(file); + StringTokenizer st=new StringTokenizer(fileContent, CAppMavenUtils.REPLACER_DEFAULT_DELIMETER); + + Properties mavenProperties = getProject().getModel().getProperties(); + //Check whether the content actually has tokens and Properties section should define them. Otherwise skip. + //By default there are 2 such properties. So size check is 2. + if (st.countTokens()>1 && mavenProperties.size()>1) { + while (st.hasMoreTokens()) { + String nextToken = st.nextToken(); + if (mavenProperties.containsKey(nextToken)) { + String originalToken = nextToken; + nextToken = (String) mavenProperties.get(nextToken); + getLog().info("Replacing the token: "+originalToken+" with value: "+nextToken); + } + sb.append(nextToken); + } + }else{ + sb.append(fileContent); + } + File tempFile = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createTempFile(); + org.wso2.developerstudio.eclipse.utils.file.FileUtils.writeContent(tempFile, sb.toString()); + return tempFile; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return file; + } } diff --git a/dependencies/wso2-esb-sequence-plugin/src/main/java/org/wso2/maven/plugin/sequence/SequencePOMGenMojo.java b/dependencies/wso2-esb-sequence-plugin/src/main/java/org/wso2/maven/plugin/sequence/SequencePOMGenMojo.java index 49e9c6d79..4f10db97d 100644 --- a/dependencies/wso2-esb-sequence-plugin/src/main/java/org/wso2/maven/plugin/sequence/SequencePOMGenMojo.java +++ b/dependencies/wso2-esb-sequence-plugin/src/main/java/org/wso2/maven/plugin/sequence/SequencePOMGenMojo.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Properties; +import java.util.StringTokenizer; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; @@ -28,6 +30,7 @@ import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.wso2.developerstudio.eclipse.utils.data.ITemporaryFileTag; import org.wso2.maven.capp.model.Artifact; import org.wso2.maven.capp.mojo.AbstractPOMGenMojo; import org.wso2.maven.capp.utils.CAppMavenUtils; @@ -123,8 +126,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { protected void copyResources(MavenProject project, File projectLocation, Artifact artifact)throws IOException { - File sequenceArtifact = artifact.getFile(); - FileUtils.copyFile(sequenceArtifact, new File(projectLocation, sequenceArtifact.getName())); + ITemporaryFileTag newTag = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createNewTempTag(); + File sequenceArtifact = processTokenReplacement(artifact); + if (sequenceArtifact == null) { + sequenceArtifact = artifact.getFile(); + } + FileUtils.copyFile(sequenceArtifact, new File(projectLocation, artifact.getFile().getName())); + newTag.clearAndEnd(); } protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) { Plugin plugin = CAppMavenUtils.createPluginEntry(artifactMavenProject,"org.wso2.maven","maven-sequence-plugin",WSO2MavenPluginConstantants.MAVEN_SEQUENCE_PLUGIN_VERSION,true); @@ -137,5 +145,42 @@ protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) protected String getArtifactType() { return ARTIFACT_TYPE; } + + @Override + protected File processTokenReplacement(Artifact artifact) { + File file = artifact.getFile(); + if(file.exists()){ + String fileContent; + StringBuffer sb=new StringBuffer(); + try { + fileContent = org.wso2.developerstudio.eclipse.utils.file.FileUtils.getContentAsString(file); + StringTokenizer st=new StringTokenizer(fileContent, CAppMavenUtils.REPLACER_DEFAULT_DELIMETER); + + Properties mavenProperties = getProject().getModel().getProperties(); + //Check whether the content actually has tokens and Properties section should define them. Otherwise skip. + //By default there are 2 such properties. So size check is 2. + if (st.countTokens()>1 && mavenProperties.size()>1) { + while (st.hasMoreTokens()) { + String nextToken = st.nextToken(); + if (mavenProperties.containsKey(nextToken)) { + String originalToken = nextToken; + nextToken = (String) mavenProperties.get(nextToken); + getLog().info("Replacing the token: "+originalToken+" with value: "+nextToken); + } + sb.append(nextToken); + } + }else{ + sb.append(fileContent); + } + File tempFile = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createTempFile(); + org.wso2.developerstudio.eclipse.utils.file.FileUtils.writeContent(tempFile, sb.toString()); + return tempFile; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return file; + } } diff --git a/dependencies/wso2-esb-template-plugin/src/main/java/org/wso2/maven/template/ESBTemplatePOMGenMojo.java b/dependencies/wso2-esb-template-plugin/src/main/java/org/wso2/maven/template/ESBTemplatePOMGenMojo.java index dcde7fc58..ed6da0992 100644 --- a/dependencies/wso2-esb-template-plugin/src/main/java/org/wso2/maven/template/ESBTemplatePOMGenMojo.java +++ b/dependencies/wso2-esb-template-plugin/src/main/java/org/wso2/maven/template/ESBTemplatePOMGenMojo.java @@ -20,6 +20,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Properties; +import java.util.StringTokenizer; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.MojoExecutionException; @@ -28,6 +30,7 @@ import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.wso2.developerstudio.eclipse.utils.data.ITemporaryFileTag; import org.wso2.maven.capp.model.Artifact; import org.wso2.maven.capp.mojo.AbstractPOMGenMojo; import org.wso2.maven.capp.utils.CAppMavenUtils; @@ -128,8 +131,13 @@ public void execute() throws MojoExecutionException, MojoFailureException { protected void copyResources(MavenProject project, File projectLocation, Artifact artifact)throws IOException { - File sequenceArtifact = artifact.getFile(); - FileUtils.copyFile(sequenceArtifact, new File(projectLocation, sequenceArtifact.getName())); + ITemporaryFileTag newTag = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createNewTempTag(); + File sequenceArtifact = processTokenReplacement(artifact); + if (sequenceArtifact == null) { + sequenceArtifact = artifact.getFile(); + } + FileUtils.copyFile(sequenceArtifact, new File(projectLocation, artifact.getFile().getName())); + newTag.clearAndEnd(); } protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) { @@ -146,5 +154,40 @@ protected String getArtifactType() { return ARTIFACT_TYPE; } - + @Override + protected File processTokenReplacement(Artifact artifact) { + File file = artifact.getFile(); + if(file.exists()){ + String fileContent; + StringBuffer sb=new StringBuffer(); + try { + fileContent = org.wso2.developerstudio.eclipse.utils.file.FileUtils.getContentAsString(file); + StringTokenizer st=new StringTokenizer(fileContent, CAppMavenUtils.REPLACER_DEFAULT_DELIMETER); + + Properties mavenProperties = getProject().getModel().getProperties(); + //Check whether the content actually has tokens and Properties section should define them. Otherwise skip. + //By default there are 2 such properties. So size check is 2. + if (st.countTokens()>1 && mavenProperties.size()>1) { + while (st.hasMoreTokens()) { + String nextToken = st.nextToken(); + if (mavenProperties.containsKey(nextToken)) { + String originalToken = nextToken; + nextToken = (String) mavenProperties.get(nextToken); + getLog().info("Replacing the token: "+originalToken+" with value: "+nextToken); + } + sb.append(nextToken); + } + }else{ + sb.append(fileContent); + } + File tempFile = org.wso2.developerstudio.eclipse.utils.file.FileUtils.createTempFile(); + org.wso2.developerstudio.eclipse.utils.file.FileUtils.writeContent(tempFile, sb.toString()); + return tempFile; + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return file; + } }