<commit_before>/**
 * Copyright 2005-2012 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * createproject.groovy
 *
 * A groovy script which can be used to create a functioning project
 * skeleton for an application wishing to use Kuali Rice.
 *
 * This script produces a project which uses Maven as it's build tool.
 * Additionally, the generated project can be imported into Eclipse.
 */

if (args.length < 2 || args.length > 9) {
	println 'usage: groovy createproject.groovy -name PROJECT_NAME [-pdir PROJECT_DIR] [-rdir RICE_DIR] [-mdir MAVEN_HOME] [-sampleapp] [-standalone]'
	System.exit(1)
}

PROJECT_DIR = '/java/projects'
RICE_DIR = '/java/projects/rice'
MAVEN_HOME = ''
SAMPLEAPP = false
STANDALONE = false

count = 0
for (arg in args) {
	if (arg == '-name') PROJECT_NAME = args[count + 1]
	if (arg == '-pdir') PROJECT_DIR = args[count + 1]
	if (arg == '-rdir') RICE_DIR = args[count + 1]
	if (arg == '-mdir') MAVEN_HOME = args[count + 1]
	if (arg == '-sampleapp') SAMPLEAPP = true
	if (arg == '-standalone') STANDALONE = true
	count++
}

PROJECT_PATH = PROJECT_DIR + '/' + PROJECT_NAME

//get rice version from rice projects pom file
def pom=new XmlSlurper().parse(new File("${RICE_DIR}/pom.xml"))

riceVersion = pom.version.text()
projectNameUpper = PROJECT_NAME.toUpperCase()

if (SAMPLEAPP) {
	projectNameUpper = "TRAVEL"
}
TEMPLATE_BINDING = [
			"\${PROJECT_NAME}":"$PROJECT_NAME",
			"\${APP_NAMESPACE}":projectNameUpper,
			"\${RICE_VERSION}":riceVersion,
			"\${USER_HOME}":System.getProperty('user.home'),
			"\${bootstrap.spring.file}":"classpath:SpringBeans.xml",
			"\${monitoring.spring.import}":"",
			"\${monitoring.filter}":"",
			"\${monitoring.listener}":"",
			"\${monitoring.mapping}":"",
			"sample-app":PROJECT_NAME
		]

println warningtext()

input = new BufferedReader(new InputStreamReader(System.in))
answer = input.readLine()
if (!"yes".equals(answer.trim().toLowerCase())) {
	System.exit(2)
}

def maven = detectMaven(MAVEN_HOME)

if (!maven) {
	println mavenwarningtext()
	input = new BufferedReader(new InputStreamReader(System.in))
	answer = input.readLine()
	if (!"yes".equals(answer.trim().toLowerCase())) {
		System.exit(2)
	}
}

removeFile("${System.getProperty('user.home')}/kuali/main/dev/${PROJECT_NAME}-config.xml")
removeFile("${System.getProperty('user.home')}/kuali/main/dev/rice.keystore")

buildDir("${System.getProperty('user.home')}/kuali/main/dev/")
buildDir("${PROJECT_DIR}")

ant = new AntBuilder()

ant.delete(dir:PROJECT_PATH)

def springTemplateFile = null;

if (SAMPLEAPP) {
	// copy the Sample Application Files
	ant.copy(todir:PROJECT_PATH + '/src/main/java') {
		fileset(dir:RICE_DIR + '/sampleapp/src/main/java')
	}
	/*ant.copy(todir:PROJECT_PATH + '/src/main/resources') {
	 fileset(dir:RICE_DIR + '/web/src/test/resources') 
	 }*/

	ant.copy(todir:PROJECT_PATH + '/src/main/resources') {
		fileset(dir:RICE_DIR + '/sampleapp/src/main/resources', includes:'META-INF/*,edu/sampleu/**/*,OJB-repository-sampleapp.xml')
	}

	// Remove if Sample app not required on Homepage
	ant.copy(todir:PROJECT_PATH + '/src/main/webapp/WEB-INF/jsp') {
		fileset(dir:RICE_DIR + '/sampleapp/src/main/webapp/WEB-INF/jsp')
	}


	// copy main channels from sampleapp to new project
	ant.copy(todir:PROJECT_PATH + '/src/main/webapp/WEB-INF/tags/rice-portal/channel/main') {
		fileset(dir:RICE_DIR + '/sampleapp/src/main/webapp/WEB-INF/tags/rice-portal/channel/main')
	}

	//Copy tag to new project to enable sample-app channel
	ant.copy(todir:PROJECT_PATH + '/src/main/webapp/WEB-INF/tags/rice-portal/') {
		fileset(file:RICE_DIR + '/sampleapp/src/main/webapp/WEB-INF/tags/rice-portal/mainTab.tag')
	}	// copy sample-app-config.xml
	/*ant.copy(todir:PROJECT_PATH + '/src/main/resources') { 
	 fileset(dir:RICE_DIR + '/sampleapp/src/main/resources', includes:'META-INF/*') 
	 }*/

	// copy other configuration files
	/*ant.copy(todir:PROJECT_PATH + '/src/main/resources') { 
	 fileset(dir:RICE_DIR + '/web/src/test/resources', includes:'configurationServiceData.xml, *Resources.properties, OJB-*.xml')
	 }*/

	// copy the Sample Application scripts. Like database create sql
	ant.copy(todir:PROJECT_PATH + '/scripts') {
		fileset(dir:RICE_DIR + '/sampleapp/scripts')
	}

	springTemplateFile = new File(RICE_DIR + '/config/templates/createproject.SampleAppBeans.template.xml')
} else {
	// copy an empty java file to /src/main/java
	ant.copy(file:RICE_DIR + "/config/templates/PutJavaCodeHere.java",
			tofile:PROJECT_PATH + "/src/main/java/PutJavaCodeHere.java")

	// copy configuration files
	ant.copy(todir:PROJECT_PATH + '/src/main/resources') {
		fileset(dir:RICE_DIR + '/web/src/main/resources', includes:'configurationServiceData.xml, META-INF/*')
	}
	/*ant.copy(todir:PROJECT_PATH + '/src/main/resources') { 
	 fileset(dir:RICE_DIR + '/web/src/test/resources', includes:'KR-ApplicationResources.properties')
	 }*/

	//copies meta-inf folder to empty rice project skeleton
	ant.copy(todir:PROJECT_PATH + '/src/main/resources/META-INF') {
		fileset(dir:RICE_DIR + '/sampleapp/src/main/resources/META-INF')
	}


	springTemplateFile = new File(RICE_DIR + '/config/templates/createproject.SpringBeans.template.xml')
}

// copy standard Rice Spring configuration files to project and rename

ant.copy(file:RICE_DIR + "/core/impl/src/main/resources/org/kuali/rice/core/RiceJTASpringBeans.xml",
	tofile:PROJECT_PATH + "/src/main/resources/RiceJTASpringBeans.xml")

// Adding log4j.proprties file
ant.copy(file:RICE_DIR + "sampleapp/src/main/resources/log4j.properties",
	tofile:PROJECT_PATH + "/src/main/resources/log4j.properties")



if (STANDALONE) {
	//	new File(PROJECT_PATH + "/src/main/resources/${PROJECT_NAME}-RiceDataSourceSpringBeans.xml") << templateReplace(new File(RICE_DIR + '/core/impl/src/main/resources/org/kuali/rice/core/RiceDataSourceStandaloneClientSpringBeans.xml.template'))
	//	new File(PROJECT_PATH + "/src/main/resources/${PROJECT_NAME}-RiceSpringBeans.xml") << templateReplace(new File(RICE_DIR + '/web/src/main/resources/org/kuali/rice/config/RiceStandaloneClientSpringBeans.xml.template'))<commit_msg>KULRICE-7101 Added missing slash to path while copying log4j.properties file.<commit_after>/**
 * Copyright 2005-2012 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * createproject.groovy
 *
 * A groovy script which can be used to create a functioning project
 * skeleton for an application wishing to use Kuali Rice.
 *
 * This script produces a project which uses Maven as it's build tool.
 * Additionally, the generated project can be imported into Eclipse.
 */

if (args.length < 2 || args.length > 9) {
	println 'usage: groovy createproject.groovy -name PROJECT_NAME [-pdir PROJECT_DIR] [-rdir RICE_DIR] [-mdir MAVEN_HOME] [-sampleapp] [-standalone]'
	System.exit(1)
}

PROJECT_DIR = '/java/projects'
RICE_DIR = '/java/projects/rice'
MAVEN_HOME = ''
SAMPLEAPP = false
STANDALONE = false

count = 0
for (arg in args) {
	if (arg == '-name') PROJECT_NAME = args[count + 1]
	if (arg == '-pdir') PROJECT_DIR = args[count + 1]
	if (arg == '-rdir') RICE_DIR = args[count + 1]
	if (arg == '-mdir') MAVEN_HOME = args[count + 1]
	if (arg == '-sampleapp') SAMPLEAPP = true
	if (arg == '-standalone') STANDALONE = true
	count++
}

PROJECT_PATH = PROJECT_DIR + '/' + PROJECT_NAME

//get rice version from rice projects pom file
def pom=new XmlSlurper().parse(new File("${RICE_DIR}/pom.xml"))

riceVersion = pom.version.text()
projectNameUpper = PROJECT_NAME.toUpperCase()

if (SAMPLEAPP) {
	projectNameUpper = "TRAVEL"
}
TEMPLATE_BINDING = [
			"\${PROJECT_NAME}":"$PROJECT_NAME",
			"\${APP_NAMESPACE}":projectNameUpper,
			"\${RICE_VERSION}":riceVersion,
			"\${USER_HOME}":System.getProperty('user.home'),
			"\${bootstrap.spring.file}":"classpath:SpringBeans.xml",
			"\${monitoring.spring.import}":"",
			"\${monitoring.filter}":"",
			"\${monitoring.listener}":"",
			"\${monitoring.mapping}":"",
			"sample-app":PROJECT_NAME
		]

println warningtext()

input = new BufferedReader(new InputStreamReader(System.in))
answer = input.readLine()
if (!"yes".equals(answer.trim().toLowerCase())) {
	System.exit(2)
}

def maven = detectMaven(MAVEN_HOME)

if (!maven) {
	println mavenwarningtext()
	input = new BufferedReader(new InputStreamReader(System.in))
	answer = input.readLine()
	if (!"yes".equals(answer.trim().toLowerCase())) {
		System.exit(2)
	}
}

removeFile("${System.getProperty('user.home')}/kuali/main/dev/${PROJECT_NAME}-config.xml")
removeFile("${System.getProperty('user.home')}/kuali/main/dev/rice.keystore")

buildDir("${System.getProperty('user.home')}/kuali/main/dev/")
buildDir("${PROJECT_DIR}")

ant = new AntBuilder()

ant.delete(dir:PROJECT_PATH)

def springTemplateFile = null;

if (SAMPLEAPP) {
	// copy the Sample Application Files
	ant.copy(todir:PROJECT_PATH + '/src/main/java') {
		fileset(dir:RICE_DIR + '/sampleapp/src/main/java')
	}
	/*ant.copy(todir:PROJECT_PATH + '/src/main/resources') {
	 fileset(dir:RICE_DIR + '/web/src/test/resources') 
	 }*/

	ant.copy(todir:PROJECT_PATH + '/src/main/resources') {
		fileset(dir:RICE_DIR + '/sampleapp/src/main/resources', includes:'META-INF/*,edu/sampleu/**/*,OJB-repository-sampleapp.xml')
	}

	// Remove if Sample app not required on Homepage
	ant.copy(todir:PROJECT_PATH + '/src/main/webapp/WEB-INF/jsp') {
		fileset(dir:RICE_DIR + '/sampleapp/src/main/webapp/WEB-INF/jsp')
	}


	// copy main channels from sampleapp to new project
	ant.copy(todir:PROJECT_PATH + '/src/main/webapp/WEB-INF/tags/rice-portal/channel/main') {
		fileset(dir:RICE_DIR + '/sampleapp/src/main/webapp/WEB-INF/tags/rice-portal/channel/main')
	}

	//Copy tag to new project to enable sample-app channel
	ant.copy(todir:PROJECT_PATH + '/src/main/webapp/WEB-INF/tags/rice-portal/') {
		fileset(file:RICE_DIR + '/sampleapp/src/main/webapp/WEB-INF/tags/rice-portal/mainTab.tag')
	}	// copy sample-app-config.xml
	/*ant.copy(todir:PROJECT_PATH + '/src/main/resources') { 
	 fileset(dir:RICE_DIR + '/sampleapp/src/main/resources', includes:'META-INF/*') 
	 }*/

	// copy other configuration files
	/*ant.copy(todir:PROJECT_PATH + '/src/main/resources') { 
	 fileset(dir:RICE_DIR + '/web/src/test/resources', includes:'configurationServiceData.xml, *Resources.properties, OJB-*.xml')
	 }*/

	// copy the Sample Application scripts. Like database create sql
	ant.copy(todir:PROJECT_PATH + '/scripts') {
		fileset(dir:RICE_DIR + '/sampleapp/scripts')
	}

	springTemplateFile = new File(RICE_DIR + '/config/templates/createproject.SampleAppBeans.template.xml')
} else {
	// copy an empty java file to /src/main/java
	ant.copy(file:RICE_DIR + "/config/templates/PutJavaCodeHere.java",
			tofile:PROJECT_PATH + "/src/main/java/PutJavaCodeHere.java")

	// copy configuration files
	ant.copy(todir:PROJECT_PATH + '/src/main/resources') {
		fileset(dir:RICE_DIR + '/web/src/main/resources', includes:'configurationServiceData.xml, META-INF/*')
	}
	/*ant.copy(todir:PROJECT_PATH + '/src/main/resources') { 
	 fileset(dir:RICE_DIR + '/web/src/test/resources', includes:'KR-ApplicationResources.properties')
	 }*/

	//copies meta-inf folder to empty rice project skeleton
	ant.copy(todir:PROJECT_PATH + '/src/main/resources/META-INF') {
		fileset(dir:RICE_DIR + '/sampleapp/src/main/resources/META-INF')
	}


	springTemplateFile = new File(RICE_DIR + '/config/templates/createproject.SpringBeans.template.xml')
}

// copy standard Rice Spring configuration files to project and rename

ant.copy(file:RICE_DIR + "/core/impl/src/main/resources/org/kuali/rice/core/RiceJTASpringBeans.xml",
	tofile:PROJECT_PATH + "/src/main/resources/RiceJTASpringBeans.xml")

// Adding log4j.proprties file
ant.copy(file:RICE_DIR + "/sampleapp/src/main/resources/log4j.properties",
	tofile:PROJECT_PATH + "/src/main/resources/log4j.properties")



if (STANDALONE) {
	//	new File(PROJECT_PATH + "/src/main/resources/${PROJECT_NAME}-RiceDataSourceSpringBeans.xml") << templateReplace(new File(RICE_DIR + '/core/impl/src/main/resources/org/kuali/rice/core/RiceDataSourceStandaloneClientSpringBeans.xml.template'))
	//	new File(PROJECT_PATH + "/src/main/resources/${PROJECT_NAME}-RiceSpringBeans.xml") << templateReplace(new File(RICE_DIR + '/web/src/main/resources/org/kuali/rice/config/RiceStandaloneClientSpringBeans.xml.template'))
{'fraction_non_alphanumeric': 0.15706884901268864, 'fraction_numerical': 0.003979277723552819, 'mean_word_length': 4.6923076923076925, 'pattern_counts': {'":': 20, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 32}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1526992', 'n_tokens_mistral': 4811, 'n_tokens_neox': 4619, 'n_words': 886}