<commit_before>#
#  Copyright 2015 Electric Cloud, Inc.
#
#  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.
#

# preamble.pl
$[/myProject/preamble]

my $PROJECT_NAME = '$[/myProject/projectName]';
my $PLUGIN_NAME = '@PLUGIN_NAME@';
my $PLUGIN_KEY = '@PLUGIN_KEY@';

my $MAIN_CLASS = 'weblogic.Deployer';

use Data::Dumper;

$|=1;

main();


sub main {
    my $wl = EC::WebLogic->new(
        project_name => $PROJECT_NAME,
        plugin_name => $PLUGIN_NAME,
        plugin_key => $PLUGIN_KEY
    );

    # TODO: remove javapath, javaparams, additionalcommands, webjarpath, envscriptpath field.
    my $params = $wl->get_params_as_hashref(
        'wlstabspath',
        'appname',
        'apppath',
        'configname',
        'targets',
        'is_library',
        ### new options ###
        'stage_mode',
        'deployment_plan',
        'plan_path',
        'additional_options',
        'archive_version',
        'plan_version',
        'retire_gracefully',
        'retire_timeout',
        'version_identifier',
        'upload'
    );

    my $is_library = 'false';
    my $upload = 'false';
    if ($params->{is_library}) {
        $is_library = 'true';
    }
    if ($params->{upload}) {
        $upload = 'true';
    }
    my $check = $wl->check_executable($params->{wlstabspath});
    unless ($check->{ok}) {
        $wl->bail_out($check->{msg});
    }

    if ($params->{plan_path}) {
        if (-e $params->{plan_path} && -d $params->{plan_path}) {
            $wl->bail_out("$params->{plan_path} exists and it is a directory");
        }
        if (!-e $params->{plan_path}) {
            if (!$params->{deployment_plan}) {
                $wl->bail_out("$params->{plan_path} doesn't exist and it's content was not provided");
            }
            open(my $fh, '>', $params->{plan_path}) or $wl->bail_out("Can't open file $params->{plan_path} for writing: $!");
            print $fh $params->{deployment_plan};
            close $fh;
        }
    }

    my $cred = $wl->get_credentials($params->{configname});
    my $render_params = {
        username => $cred->{user},
        password => $<PASSWORD>->{password},
        admin_url => $cred->{weblogic_url},

        targets => $params->{targets},
        app_name => $params->{appname},<commit_msg>Added error when deployment plan content is provided and deployment plan file exists and not empty<commit_after>#
#  Copyright 2015 Electric Cloud, Inc.
#
#  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.
#

# preamble.pl
$[/myProject/preamble]

my $PROJECT_NAME = '$[/myProject/projectName]';
my $PLUGIN_NAME = '@PLUGIN_NAME@';
my $PLUGIN_KEY = '@PLUGIN_KEY@';

my $MAIN_CLASS = 'weblogic.Deployer';

use Data::Dumper;

$|=1;

main();


sub main {
    my $wl = EC::WebLogic->new(
        project_name => $PROJECT_NAME,
        plugin_name => $PLUGIN_NAME,
        plugin_key => $PLUGIN_KEY
    );

    # TODO: remove javapath, javaparams, additionalcommands, webjarpath, envscriptpath field.
    my $params = $wl->get_params_as_hashref(
        'wlstabspath',
        'appname',
        'apppath',
        'configname',
        'targets',
        'is_library',
        ### new options ###
        'stage_mode',
        'deployment_plan',
        'plan_path',
        'additional_options',
        'archive_version',
        'plan_version',
        'retire_gracefully',
        'retire_timeout',
        'version_identifier',
        'upload'
    );

    my $is_library = 'false';
    my $upload = 'false';
    if ($params->{is_library}) {
        $is_library = 'true';
    }
    if ($params->{upload}) {
        $upload = 'true';
    }
    my $check = $wl->check_executable($params->{wlstabspath});
    unless ($check->{ok}) {
        $wl->bail_out($check->{msg});
    }
    if ($params->{plan_path}) {
        if (-e $params->{plan_path} && -d $params->{plan_path}) {
            $wl->bail_out("$params->{plan_path} exists and it is a directory");
        }
        if (-e $params->{plan_path} && -s $params->{plan_path} && $params->{deployment_plan}) {
            $wl->bail_out("File $params->{plan_path} is already exists and not empty. Can't overwrite it");
        }
        if (!-e $params->{plan_path}) {
            if (!$params->{deployment_plan}) {
                $wl->bail_out("$params->{plan_path} doesn't exist and it's content was not provided");
            }
            open(my $fh, '>', $params->{plan_path}) or $wl->bail_out("Can't open file $params->{plan_path} for writing: $!");
            print $fh $params->{deployment_plan};
            close $fh;
        }
    }

    my $cred = $wl->get_credentials($params->{configname});
    my $render_params = {
        username => $cred->{user},
        password => $cred->{password},
        admin_url => $cred->{weblogic_url},

        targets => $params->{targets},
        app_name => $params->{appname},
{'fraction_non_alphanumeric': 0.15098841172460806, 'fraction_numerical': 0.003067484662576687, 'mean_word_length': 2.6228395061728396, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 85, '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': '6952178', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1882, 'n_words': 471}