<commit_before>package org.apache.maven.plugin.deploy;

/*
 * 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.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

/**
 * Installs the artifact in the remote repository.
 * 
 * @goal deploy-file
 * @requiresProject false 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class DeployFileMojo
    extends AbstractDeployMojo
{
    /**
     * GroupId of the artifact to be deployed.  Retrieved from POM file if specified.
     * 
     * @parameter expression="${groupId}"
     */
    private String groupId;

    /**
     * ArtifactId of the artifact to be deployed.  Retrieved from POM file if specified.
     * 
     * @parameter expression="${artifactId}"
     */
    private String artifactId;

    /**
     * Version of the artifact to be deployed.  Retrieved from POM file if specified.
     * 
     * @parameter expression="${version}"
     */
    private String version;

    /**
     * Type of the artifact to be deployed.  Retrieved from POM file if specified.
     * 
     * @parameter expression="${packaging}"
     */
    private String packaging;

    /**
     * File to be deployed.
     * 
     * @parameter expression="${file}"
     * @required
     */
    private File file;

    /**
     * Server Id to map on the &lt;id&gt; under &lt;server&gt; section of settings.xml
     * 
     * @parameter expression="${repositoryId}"
     * @required
     */
    private String repositoryId;

    /**
     * URL where the artifact will be deployed. <br/>
     * ie ( file://C:\m2-repo )
     * 
     * @parameter expression="${url}"
     * @required
     */
    private String url;

    /**
     * @component
     */
    private ArtifactFactory artifactFactory;

    /**
     * @component
     */
    private ArtifactRepositoryLayout layout;

    /**
     * @component
     */
    private ArtifactRepositoryFactory repositoryFactory;

    /**
     * @parameter expression="${pomFile}"
     */
    private File pomFile;

    /**
     * Upload a POM for this artifact.  Will generate a default POM if none is 
     * supplied with the pomFile argument.
     * 
     * @parameter expression="${generatePom}"
     * @readonly
     */
    private boolean generatePom = true;
    
    /**
     * Add classifier to the artifact
     * 
     * @parameter expression="${classifier}";
     */
    private String classifier;
    

    public void execute()
        throws MojoExecutionException
    {

        initProperties();

        Artifact pomArtifact = null;
        
        try
        {
            // Create the artifact
            Artifact artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier );
            
            ArtifactRepository deploymentRepository = repositoryFactory
                .createDeploymentArtifactRepository( repositoryId, url, layout, false );

            // Upload the POM if requested, generating one if need be
            if ( generatePom )
            {
                if ( !isPomFileExisting() )
                {
                    generatePomFile();
                }
                ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pomFile );
                artifact.addMetadata( metadata );
            }
            else
            {
                if( isPomFileExisting() )
                {
                    pomArtifact = artifactFactory.createArtifact( groupId, artifactId, version, null, "pom" );
                }
            }

            if ( !file.exists() )
            {
                throw new MojoExecutionException( file.getPath() + " not found." );
            }

            String protocol = deploymentRepository.getProtocol();

            if ( protocol.equals( "" ) || protocol == null )
            {
                throw new MojoExecutionException( "No transfer protocol found." );
            }
            getDeployer().deploy( file, artifact, deploymentRepository, getLocalRepository() );
            
            if( isPomFileExisting() && generatePom == false )
            {
                getDeployer().deploy( pomFile, pomArtifact, deploymentRepository, getLocalRepository() );
            }
        }
        catch ( ArtifactDeploymentException e )
        {
            throw new MojoExecutionException( e.getMessage(), e );
        }
    }
    
    private boolean isPomFileExisting()
    {
        boolean existing = false;
        if( pomFile != null && pomFile.exists() )
        {
            existing = true;
        }<commit_msg>deploy snapshots with a unique version by default<commit_after>package org.apache.maven.plugin.deploy;

/*
 * 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.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

/**
 * Installs the artifact in the remote repository.
 * 
 * @goal deploy-file
 * @requiresProject false 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class DeployFileMojo
    extends AbstractDeployMojo
{
    /**
     * GroupId of the artifact to be deployed.  Retrieved from POM file if specified.
     * 
     * @parameter expression="${groupId}"
     */
    private String groupId;

    /**
     * ArtifactId of the artifact to be deployed.  Retrieved from POM file if specified.
     * 
     * @parameter expression="${artifactId}"
     */
    private String artifactId;

    /**
     * Version of the artifact to be deployed.  Retrieved from POM file if specified.
     * 
     * @parameter expression="${version}"
     */
    private String version;

    /**
     * Type of the artifact to be deployed.  Retrieved from POM file if specified.
     * 
     * @parameter expression="${packaging}"
     */
    private String packaging;

    /**
     * File to be deployed.
     * 
     * @parameter expression="${file}"
     * @required
     */
    private File file;

    /**
     * Server Id to map on the &lt;id&gt; under &lt;server&gt; section of settings.xml
     * 
     * @parameter expression="${repositoryId}"
     * @required
     */
    private String repositoryId;

    /**
     * URL where the artifact will be deployed. <br/>
     * ie ( file://C:\m2-repo )
     * 
     * @parameter expression="${url}"
     * @required
     */
    private String url;

    /**
     * @component
     */
    private ArtifactFactory artifactFactory;

    /**
     * @component
     */
    private ArtifactRepositoryLayout layout;

    /**
     * @component
     */
    private ArtifactRepositoryFactory repositoryFactory;

    /**
     * @parameter expression="${pomFile}"
     */
    private File pomFile;

    /**
     * Upload a POM for this artifact.  Will generate a default POM if none is 
     * supplied with the pomFile argument.
     * 
     * @parameter expression="${generatePom}"
     * @readonly
     */
    private boolean generatePom = true;
    
    /**
     * Add classifier to the artifact
     * 
     * @parameter expression="${classifier}";
     */
    private String classifier;

    /**
     * Whether to deploy snapshots with a unique version or not.
     *
     * @parameter expression="${uniqueVersion}" default-value="true"
     */
    private boolean uniqueVersion;


    public void execute()
        throws MojoExecutionException
    {

        initProperties();

        Artifact pomArtifact = null;

        try
        {
            // Create the artifact
            Artifact artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier );

            ArtifactRepository deploymentRepository = repositoryFactory
                .createDeploymentArtifactRepository( repositoryId, url, layout, uniqueVersion );

            // Upload the POM if requested, generating one if need be
            if ( generatePom )
            {
                if ( !isPomFileExisting() )
                {
                    generatePomFile();
                }
                ArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pomFile );
                artifact.addMetadata( metadata );
            }
            else
            {
                if( isPomFileExisting() )
                {
                    pomArtifact = artifactFactory.createArtifact( groupId, artifactId, version, null, "pom" );
                }
            }

            if ( !file.exists() )
            {
                throw new MojoExecutionException( file.getPath() + " not found." );
            }

            String protocol = deploymentRepository.getProtocol();

            if ( protocol.equals( "" ) || protocol == null )
            {
                throw new MojoExecutionException( "No transfer protocol found." );
            }
            getDeployer().deploy( file, artifact, deploymentRepository, getLocalRepository() );

            if( isPomFileExisting() && generatePom == false )
            {
                getDeployer().deploy( pomFile, pomArtifact, deploymentRepository, getLocalRepository() );
            }
        }
        catch ( ArtifactDeploymentException e )
        {
            throw new MojoExecutionException( e.getMessage(), e );
        }
    }
    
    private boolean isPomFileExisting()
    {
        boolean existing = false;
        if( pomFile != null && pomFile.exists() )
        {
            existing = true;
        }
{'fraction_non_alphanumeric': 0.09711794623395495, 'fraction_numerical': 0.0027448131105190926, 'mean_word_length': 2.2981895633652822, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, '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': '6206558', 'n_tokens_mistral': 3393, 'n_tokens_neox': 3171, 'n_words': 891}