Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from wso2-dev/master
Browse files Browse the repository at this point in the history
* Fixed TOOLS-2367.
  • Loading branch information
Jasintha committed Mar 5, 2014
2 parents d44f6b9 + 931aaef commit 9430f62
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}

0 comments on commit 9430f62

Please sign in to comment.