<commit_before>/*-
 * Copyright (c) 2012 Red Hat, 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.
 */
package org.fedoraproject.maven.rpminstall.plugin;

import java.io.IOException;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

import org.fedoraproject.maven.model.Artifact;
import org.fedoraproject.maven.resolver.DependencyMap;

public class FragmentFile
    extends DependencyMap
{
    private final Set<Artifact> dependencies = new TreeSet<>();

    private final Set<Artifact> develDependencies = new TreeSet<>();

    private BigDecimal javaVersionRequirement;

    @Override
    public boolean isEmpty()
    {
        return super.isEmpty() && dependencies.isEmpty() && develDependencies.isEmpty()
            && javaVersionRequirement == null;
    }

    public void addDependency( Artifact artifact )
    {
        dependencies.add( artifact.clearVersionAndExtension() );
    }

    public void addDevelDependency( Artifact artifact )
    {
        develDependencies.add( artifact.clearVersionAndExtension() );
    }

    public void addDependency( String groupId, String artifactId )
    {
        addDependency( new Artifact( groupId, artifactId ) );
    }

    public void addDevelDependency( String groupId, String artifactId )
    {
        addDevelDependency( new Artifact( groupId, artifactId ) );
    }

    public void addJavaVersionRequirement( BigDecimal version )
    {
        if ( javaVersionRequirement == null || javaVersionRequirement.compareTo( version ) < 0 )
            javaVersionRequirement = version;
    }

    public void optimize()
    {
        for ( Iterator<Artifact> iter = dependencies.iterator(); iter.hasNext(); )
        {
            Artifact artifact = iter.next();
            if ( mapping.containsKey( artifact ) )
                iter.remove();
        }

        for ( Iterator<Artifact> iter = develDependencies.iterator(); iter.hasNext(); )
        {
            Artifact artifact = iter.next();
            if ( mapping.containsKey( artifact ) )
                iter.remove();
        }
    }

    public void write( Path path, boolean writeDevel )
        throws IOException
    {
        try (PrintStream ps = new PrintStream( path.toFile() ))
        {
            ps.println( "<!-- This depmap file was generated by XMvn. -->" );
            ps.println( "<dependencyMap>" );

            // TODO: implement
            if ( Boolean.valueOf( false ) )
                ps.println( "<skipProvides/>" );

            if ( javaVersionRequirement != null )
                ps.println( "  <requiresJava>" + javaVersionRequirement + "</requiresJava>" );

            for ( Artifact mavenArtifact : mapping.keySet() )
            {
                Artifact jppArtifact = mapping.get( mavenArtifact );

                ps.println( "  <dependency>" );
                ps.println( "    <maven>" );
                ps.println( "      <groupId>" + mavenArtifact.getGroupId() + "</groupId>" );
                ps.println( "      <artifactId>" + mavenArtifact.getArtifactId() + "</artifactId>" );
                ps.println( "      <version>" + mavenArtifact.getVersion() + "</version>" );
                ps.println( "    </maven>" );
                ps.println( "    <jpp>" );<commit_msg>Implement generation of skipProvides in fragment files<commit_after>/*-
 * Copyright (c) 2012 Red Hat, 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.
 */
package org.fedoraproject.maven.rpminstall.plugin;

import java.io.IOException;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

import org.fedoraproject.maven.Configuration;
import org.fedoraproject.maven.model.Artifact;
import org.fedoraproject.maven.resolver.DependencyMap;

public class FragmentFile
    extends DependencyMap
{
    private final Set<Artifact> dependencies = new TreeSet<>();

    private final Set<Artifact> develDependencies = new TreeSet<>();

    private BigDecimal javaVersionRequirement;

    @Override
    public boolean isEmpty()
    {
        return super.isEmpty() && dependencies.isEmpty() && develDependencies.isEmpty()
            && javaVersionRequirement == null;
    }

    public void addDependency( Artifact artifact )
    {
        dependencies.add( artifact.clearVersionAndExtension() );
    }

    public void addDevelDependency( Artifact artifact )
    {
        develDependencies.add( artifact.clearVersionAndExtension() );
    }

    public void addDependency( String groupId, String artifactId )
    {
        addDependency( new Artifact( groupId, artifactId ) );
    }

    public void addDevelDependency( String groupId, String artifactId )
    {
        addDevelDependency( new Artifact( groupId, artifactId ) );
    }

    public void addJavaVersionRequirement( BigDecimal version )
    {
        if ( javaVersionRequirement == null || javaVersionRequirement.compareTo( version ) < 0 )
            javaVersionRequirement = version;
    }

    public void optimize()
    {
        for ( Iterator<Artifact> iter = dependencies.iterator(); iter.hasNext(); )
        {
            Artifact artifact = iter.next();
            if ( mapping.containsKey( artifact ) )
                iter.remove();
        }

        for ( Iterator<Artifact> iter = develDependencies.iterator(); iter.hasNext(); )
        {
            Artifact artifact = iter.next();
            if ( mapping.containsKey( artifact ) )
                iter.remove();
        }
    }

    public void write( Path path, boolean writeDevel )
        throws IOException
    {
        try (PrintStream ps = new PrintStream( path.toFile() ))
        {
            ps.println( "<!-- This depmap file was generated by XMvn. -->" );
            ps.println( "<dependencyMap>" );

            if ( !Configuration.getInstallVersions().isEmpty() )
                ps.println( "<skipProvides/>" );

            if ( javaVersionRequirement != null )
                ps.println( "  <requiresJava>" + javaVersionRequirement + "</requiresJava>" );

            for ( Artifact mavenArtifact : mapping.keySet() )
            {
                Artifact jppArtifact = mapping.get( mavenArtifact );

                ps.println( "  <dependency>" );
                ps.println( "    <maven>" );
                ps.println( "      <groupId>" + mavenArtifact.getGroupId() + "</groupId>" );
                ps.println( "      <artifactId>" + mavenArtifact.getArtifactId() + "</artifactId>" );
                ps.println( "      <version>" + mavenArtifact.getVersion() + "</version>" );
                ps.println( "    </maven>" );
                ps.println( "    <jpp>" );
{'fraction_non_alphanumeric': 0.10811850711812235, 'fraction_numerical': 0.002308580223162755, 'mean_word_length': 2.4565602836879434, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 45, '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': '1894756', 'n_tokens_mistral': 2160, 'n_tokens_neox': 2023, 'n_words': 565}