<commit_before>/*
 *
 * Copyright 2013 <NAME>
 *
 * 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.
 *
 */

/* jshint sub:true */

var fs   = require('fs');
var path = require('path');
var shell = require('shelljs');
var events = require('cordova-common').events;
var CordovaError = require('cordova-common').CordovaError;

// returns relative file path for a file in the plugin's folder that can be referenced
// from a project file.
function getPluginFilePath(plugin, pluginFile, targetDir) {
    var src = path.resolve(plugin.dir, pluginFile);
    return '$(ProjectDir)' + path.relative(targetDir, src);
}

var handlers = {
    'source-file': {
        install:function(obj, plugin, project, options) {
            var dest = path.join('plugins', plugin.id, obj.targetDir || '', path.basename(obj.src));
            if (options && options.force) {
                copyFile(plugin.dir, obj.src, project.root, dest);
            } else {
                copyNewFile(plugin.dir, obj.src, project.root, dest);
            }
            // add reference to this file to jsproj.
            project.addSourceFile(dest);
        },
        uninstall:function(obj, plugin, project, options) {
            var dest = path.join('plugins', plugin.id, obj.targetDir || '', path.basename(obj.src));
            removeFile(project.root, dest);
            // remove reference to this file from csproj.
            project.removeSourceFile(dest);
        }
    },
    'resource-file':{
        install:function(obj, plugin, project, options) {
            var targetConditions = getTargetConditions(obj);
            if (targetConditions.reference) {
                // do not copy, but reference the file in the plugin folder. This allows to
                // have multiple source files map to the same target and select the appropriate
                // one based on the current build settings, e.g. architecture.
                // also, we don't check for existence. This allows to insert build variables
                // into the source file name, e.g.
                // <resource-file src="$(Platform)/My.dll" target="My.dll" />
                var relativeSrcPath = getPluginFilePath(plugin, obj.src, project.projectFolder);
                project.addResourceFileToProject(relativeSrcPath, obj.target, targetConditions);
            } else {
                // as per specification resource-file target is specified relative to platform root
                copyFile(plugin.dir, obj.src, project.root, obj.target);
                project.addResourceFileToProject(obj.target, obj.target, targetConditions);
            }
        },
        uninstall:function(obj, plugin, project, options) {
            var targetConditions = getTargetConditions(obj);
            if (targetConditions.reference) {
                var relativeSrcPath = getPluginFilePath(plugin, obj.src, project.projectFolder);
                project.removeResourceFileFromProject(relativeSrcPath, targetConditions);
            } else {
                removeFile(project.root, obj.target);
                project.removeResourceFileFromProject(obj.target, targetConditions);
            }
        }
    },
    'lib-file': {
        install:function(obj, plugin, project, options) {
            var inc  = obj.Include || obj.src;
            project.addSDKRef(inc, getTargetConditions(obj));
        },
        uninstall:function(obj, plugin, project, options) {
            events.emit('verbose', 'windows lib-file uninstall :: ' + plugin.id);
            var inc = obj.Include || obj.src;
            project.removeSDKRef(inc, getTargetConditions(obj));
        }
    },
    'framework': {
        install:function(obj, plugin, project, options) {
            events.emit('verbose', 'windows framework install :: ' + plugin.id);<commit_msg>Emit warning if resource-file copy will overwrite target<commit_after>/*
 *
 * Copyright 2013 <NAME>
 *
 * 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.
 *
 */

/* jshint sub:true */

var fs   = require('fs');
var path = require('path');
var shell = require('shelljs');
var events = require('cordova-common').events;
var CordovaError = require('cordova-common').CordovaError;

// returns relative file path for a file in the plugin's folder that can be referenced
// from a project file.
function getPluginFilePath(plugin, pluginFile, targetDir) {
    var src = path.resolve(plugin.dir, pluginFile);
    return '$(ProjectDir)' + path.relative(targetDir, src);
}

var handlers = {
    'source-file': {
        install:function(obj, plugin, project, options) {
            var dest = path.join('plugins', plugin.id, obj.targetDir || '', path.basename(obj.src));
            if (options && options.force) {
                copyFile(plugin.dir, obj.src, project.root, dest);
            } else {
                copyNewFile(plugin.dir, obj.src, project.root, dest);
            }
            // add reference to this file to jsproj.
            project.addSourceFile(dest);
        },
        uninstall:function(obj, plugin, project, options) {
            var dest = path.join('plugins', plugin.id, obj.targetDir || '', path.basename(obj.src));
            removeFile(project.root, dest);
            // remove reference to this file from csproj.
            project.removeSourceFile(dest);
        }
    },
    'resource-file':{
        install:function(obj, plugin, project, options) {
            var targetConditions = getTargetConditions(obj);
            if (targetConditions.reference) {
                // do not copy, but reference the file in the plugin folder. This allows to
                // have multiple source files map to the same target and select the appropriate
                // one based on the current build settings, e.g. architecture.
                // also, we don't check for existence. This allows to insert build variables
                // into the source file name, e.g.
                // <resource-file src="$(Platform)/My.dll" target="My.dll" />
                var relativeSrcPath = getPluginFilePath(plugin, obj.src, project.projectFolder);
                project.addResourceFileToProject(relativeSrcPath, obj.target, targetConditions);
            } else {
                // if target already exists, emit warning to consider using a reference instead of copying
                if (fs.existsSync(path.resolve(project.root, obj.target))) {
                    events.emit('warn', '<resource-file> with target ' + obj.target + ' already exists and will be overwritten ' +
                    'by a <resource-file> with the same target. Consider using the attribute reference="true" in the ' +
                    '<resource-file> tag to avoid overwriting files with the same target. ');
                }
                // as per specification resource-file target is specified relative to platform root
                copyFile(plugin.dir, obj.src, project.root, obj.target);
                project.addResourceFileToProject(obj.target, obj.target, targetConditions);
            }
        },
        uninstall:function(obj, plugin, project, options) {
            var targetConditions = getTargetConditions(obj);
            if (targetConditions.reference) {
                var relativeSrcPath = getPluginFilePath(plugin, obj.src, project.projectFolder);
                project.removeResourceFileFromProject(relativeSrcPath, targetConditions);
            } else {
                removeFile(project.root, obj.target);
                project.removeResourceFileFromProject(obj.target, targetConditions);
            }
        }
    },
    'lib-file': {
        install:function(obj, plugin, project, options) {
            var inc  = obj.Include || obj.src;
            project.addSDKRef(inc, getTargetConditions(obj));
        },
        uninstall:function(obj, plugin, project, options) {
            events.emit('verbose', 'windows lib-file uninstall :: ' + plugin.id);
            var inc = obj.Include || obj.src;
            project.removeSDKRef(inc, getTargetConditions(obj));
        }
    },
    'framework': {
        install:function(obj, plugin, project, options) {
            events.emit('verbose', 'windows framework install :: ' + plugin.id);
{'fraction_non_alphanumeric': 0.10629537327987865, 'fraction_numerical': 0.0017336656192436883, 'mean_word_length': 2.378477306002928, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2476835', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2316, 'n_words': 726}