<commit_before>/*
 * Code Pulse: A real-time code coverage testing tool. For more information
 * see http://code-pulse.com
 *
 * Copyright (C) 2014 Applied Visions - http://securedecisions.avi.com
 *
 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

package com.secdec.codepulse.data.jsp

import com.secdec.codepulse.data.bytecode.CodeForestBuilder
import java.io.File
import com.secdec.codepulse.data.bytecode.CodeTreeNode

/** Data adapter to help populate `CodeForestBuilder` with JSP info.
  * This implementation is specific to what Jasper does for JSP.
  *
  * @author robertf
  */
class JasperJspAdapter extends JspAdapter {
	private val jsps = List.newBuilder[(String, Int)]
	private val webinfs = List.newBuilder[String]

	def addJsp(path: String, size: Int) = jsps += path -> size
	def addWebinf(path: String) = webinfs += path

	def build(codeForestBuilder: CodeForestBuilder): List[(String, Int)] = {
		val jsps = this.jsps.result
		val webinfs = this.webinfs.result

		val jspClasses = Set.newBuilder[(String, Int)]

		for (webinf <- webinfs) {
			val parent = Option(new File(webinf).getParent) getOrElse ""
			val parentLen = parent.length
			jspClasses ++= jsps
				.filter(_._1.startsWith(parent))
				.map { case (clazz, size) => clazz.substring(parentLen) -> size }
		}

		// build up
		jspClasses.result.toList map {
			case (clazz, size) =>
				val jspClassName = JasperUtils.makeJavaClass(clazz)
				val displayName = clazz.split('/').filter(!_.isEmpty).toList
				val node = codeForestBuilder.getOrAddJsp(displayName, size)
				jspClassName -> node.id
		}
	}
}<commit_msg>Include all jsps to analysis processing and results view<commit_after>/*
 * Code Pulse: A real-time code coverage testing tool. For more information
 * see http://code-pulse.com
 *
 * Copyright (C) 2014 Applied Visions - http://securedecisions.avi.com
 *
 * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

package com.secdec.codepulse.data.jsp

import com.secdec.codepulse.data.bytecode.CodeForestBuilder
import java.io.File
import com.secdec.codepulse.data.bytecode.CodeTreeNode

/** Data adapter to help populate `CodeForestBuilder` with JSP info.
  * This implementation is specific to what Jasper does for JSP.
  *
  * @author robertf
  */
class JasperJspAdapter extends JspAdapter {
	private val jsps = List.newBuilder[(String, Int)]
	private val webinfs = List.newBuilder[String]

	def addJsp(path: String, size: Int) = jsps += path -> size
	def addWebinf(path: String) = webinfs += path

	def build(codeForestBuilder: CodeForestBuilder): List[(String, Int)] = {
		val jsps = this.jsps.result
		val webinfs = this.webinfs.result

		val jspClasses = Set.newBuilder[(String, Int)]

		for (webinf <- webinfs) {
			val parent = Option(new File(webinf).getParent) getOrElse ""
			val parentLen = parent.length
			jspClasses ++= jsps
				.filter(_._1.startsWith(parent))
				.map { case (clazz, size) => clazz.substring(parentLen) -> size }
		}

		// build up
		jsps map {
			case (clazz, size) =>
				val jspClassName = JasperUtils.makeJavaClass(clazz)
				val displayName = clazz.split('/').filter(!_.isEmpty).toList
				val node = codeForestBuilder.getOrAddJsp(displayName, size)
				jspClassName -> node.id
		}
	}
}
{'fraction_non_alphanumeric': 0.10394519253484526, 'fraction_numerical': 0.004252303330970942, 'mean_word_length': 3.849942726231386, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '6963639', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1283, 'n_words': 422}