<commit_before>package com.masse.mvn.plugin;

import java.io.BufferedReader;

/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * 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.
 */

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
import java.util.TreeMap;

import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.lang.SystemUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

@Mojo(name="propertiestojson", defaultPhase=LifecyclePhase.PROCESS_RESOURCES, threadSafe=true)
public class BuildJsonFromPropertiesMojo
    extends AbstractMojo
{

	@Parameter(property="propertiesSourcePath", defaultValue="${basedir}/src/properties")
    private String propertiesSourcePath;

	@Parameter(property="jsonTargetPath", defaultValue="${project.build.directory}/properties")
    private String jsonTargetPath;

	@Parameter(property="fileWilcard", defaultValue="*.properties")
    private String fileWilcard;
	
    public void execute()
        throws MojoExecutionException
    {
    	getLog().info("--- Maven plugin : Properties to JSON ---");
    	
    	File srcPath = new File(propertiesSourcePath);
    	if (!srcPath.isDirectory()) {
    		throw new MojoExecutionException( "PropertiesSourcePath " + propertiesSourcePath + " is not a directory !");
    	}

    	File dstPath = new File(jsonTargetPath);
    	if (!dstPath.isDirectory()) {
    		throw new MojoExecutionException( "JsonTargetPath " + jsonTargetPath + " is not a directory !");
    	}

    	FileFilter fileFilter = new WildcardFileFilter(fileWilcard);
    	File[] listOfFiles = srcPath.listFiles(fileFilter);
        
    	for (File f : listOfFiles) {
    		buidJsonTargetFile(f);
    	}
    }
    
    
    
    private void buidJsonTargetFile(File inputFile) throws MojoExecutionException {

		String inputFileString = inputFile.getAbsolutePath().substring(inputFile.getAbsolutePath().lastIndexOf(SystemUtils.IS_OS_LINUX ? "/" : "\\") + 1);
		String outputFileString = jsonTargetPath + new String(SystemUtils.IS_OS_LINUX ? "/" : "\\") + inputFileString.substring(0, inputFileString.lastIndexOf(".")) + ".json";
       
    	getLog().info("Process file " + inputFileString);
    	
    	if ( !inputFile.exists() )
        {
        	throw new MojoExecutionException( "Properties file " + inputFile + " not found !");
        }
        
        TreeMap<String, PropertiesToJson> propertiesJson = new TreeMap<String, PropertiesToJson>();
		Properties props = new Properties();

		try {
			FileInputStream fisOrig = new FileInputStream(inputFile);
			BufferedReader br = new BufferedReader(new InputStreamReader(fisOrig, "UTF-8"));

			File outputTempFile = new File(inputFileString + "-temp");
			FileOutputStream fos = new FileOutputStream(outputTempFile);
			OutputStreamWriter osr = new OutputStreamWriter(fos, "UTF-8");

			BufferedWriter writer = new BufferedWriter(osr);

			String line = "";
			while ((line = br.readLine()) != null) {
				if(!(line.isEmpty() || line.trim().equals("") || line.trim().equals("\n"))) {
					if(line.startsWith("#")){
						continue;
			        }
					writer.write(line + "\n");
				}
			}
<commit_msg>Add some replacements<commit_after>package com.masse.mvn.plugin;

import java.io.BufferedReader;

/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * 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.
 */

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
import java.util.TreeMap;

import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.lang.SystemUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

@Mojo(name="propertiestojson", defaultPhase=LifecyclePhase.PROCESS_RESOURCES, threadSafe=true)
public class BuildJsonFromPropertiesMojo
    extends AbstractMojo
{

	@Parameter(property="propertiesSourcePath", defaultValue="${basedir}/src/properties")
    private String propertiesSourcePath;

	@Parameter(property="jsonTargetPath", defaultValue="${project.build.directory}/properties")
    private String jsonTargetPath;

	@Parameter(property="fileWilcard", defaultValue="*.properties")
    private String fileWilcard;
	
    public void execute()
        throws MojoExecutionException
    {
    	getLog().info("--- Maven plugin : Properties to JSON ---");
    	
    	File srcPath = new File(propertiesSourcePath);
    	if (!srcPath.isDirectory()) {
    		throw new MojoExecutionException( "PropertiesSourcePath " + propertiesSourcePath + " is not a directory !");
    	}

    	File dstPath = new File(jsonTargetPath);
    	if (!dstPath.isDirectory()) {
    		throw new MojoExecutionException( "JsonTargetPath " + jsonTargetPath + " is not a directory !");
    	}

    	FileFilter fileFilter = new WildcardFileFilter(fileWilcard);
    	File[] listOfFiles = srcPath.listFiles(fileFilter);
        
    	for (File f : listOfFiles) {
    		buidJsonTargetFile(f);
    	}
    }
    
    
    
    private void buidJsonTargetFile(File inputFile) throws MojoExecutionException {

		String inputFileString = inputFile.getAbsolutePath().substring(inputFile.getAbsolutePath().lastIndexOf(SystemUtils.IS_OS_LINUX ? "/" : "\\") + 1);
		String outputFileString = jsonTargetPath + new String(SystemUtils.IS_OS_LINUX ? "/" : "\\") + inputFileString.substring(0, inputFileString.lastIndexOf(".")) + ".json";
       
    	getLog().info("Process file " + inputFileString);
    	
    	if ( !inputFile.exists() )
        {
        	throw new MojoExecutionException( "Properties file " + inputFile + " not found !");
        }
        
        TreeMap<String, PropertiesToJson> propertiesJson = new TreeMap<String, PropertiesToJson>();
		Properties props = new Properties();

		try {
			FileInputStream fisOrig = new FileInputStream(inputFile);
			BufferedReader br = new BufferedReader(new InputStreamReader(fisOrig, "UTF-8"));

			File outputTempFile = new File(inputFileString + "-temp");
			FileOutputStream fos = new FileOutputStream(outputTempFile);
			OutputStreamWriter osr = new OutputStreamWriter(fos, "UTF-8");

			BufferedWriter writer = new BufferedWriter(osr);

			String line = "";
			while ((line = br.readLine()) != null) {
				if(!(line.isEmpty() || line.trim().equals("") || line.trim().equals("\n"))) {
					if(line.startsWith("#")){
						continue;
			        }
		    		int equalsIndex = line.indexOf("=");
		    		if (equalsIndex < 0) {
		    			continue;
		    		}
		    		line = line.replace("\"", "&quot;");
		    		line = line.replace("\\", "\\\\\\\\");
		    		line = line.replace("	", "");
					writer.write(line + "\n");
				}
			}

{'fraction_non_alphanumeric': 0.11722293289917432, 'fraction_numerical': 0.0038376555413420165, 'mean_word_length': 3.9396898334290635, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '1373428', 'n_tokens_mistral': 2606, 'n_tokens_neox': 2432, 'n_words': 590}