<commit_before>package org.codehaus.mojo.gwt.utils;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 static org.apache.maven.artifact.Artifact.SCOPE_TEST;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;


/**
 * Helper class to resolve gwt-dev jar artifact 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @since 2.1.1
 */
public class GwtDevHelper
{
    private final MavenProject mavenProject;

    private final Map<String, Artifact> pluginArtifacts;

    private final Log log;

    private final String gwtGroupId;

    public GwtDevHelper( Map<String, Artifact> pluginArtifacts, MavenProject mavenProject, Log log, String gwtGroupId )
    {
        this.pluginArtifacts = pluginArtifacts;
        this.mavenProject = mavenProject;
        this.log = log;
        this.gwtGroupId = gwtGroupId;
    }

    public File getGwtDevJar()
        throws IOException
    {
        checkGwtDevAsDependency();
        checkGwtUserVersion();
        return pluginArtifacts.get( "com.google.gwt:gwt-dev" ).getFile();
    }

    public void checkGwtDevAsDependency()
    {
        for ( Iterator iterator = this.mavenProject.getArtifacts().iterator(); iterator.hasNext(); )
        {
            Artifact artifact = (Artifact) iterator.next();
            if ( this.gwtGroupId.equals( artifact.getGroupId() ) && "gwt-dev".equals( artifact.getArtifactId() )
                && !SCOPE_TEST.equals( artifact.getScope() ) )
            {
                log.warn( "Don't declare gwt-dev as a project dependency. This may introduce complex dependency conflicts" );
            }
        }
    }

    private void checkGwtUserVersion()
        throws IOException
    {
        InputStream inputStream = Thread.currentThread().getContextClassLoader()
            .getResourceAsStream( "org/codehaus/mojo/gwt/mojoGwtVersion.properties" );
        Properties properties = new Properties();
        try
        {
            properties.load( inputStream );<commit_msg>add an exception when loading the properties file is impossible<commit_after>package org.codehaus.mojo.gwt.utils;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 static org.apache.maven.artifact.Artifact.SCOPE_TEST;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.io.IOUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;


/**
 * Helper class to resolve gwt-dev jar artifact 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @since 2.1.1
 */
public class GwtDevHelper
{
    private final MavenProject mavenProject;

    private final Map<String, Artifact> pluginArtifacts;

    private final Log log;

    private final String gwtGroupId;

    public GwtDevHelper( Map<String, Artifact> pluginArtifacts, MavenProject mavenProject, Log log, String gwtGroupId )
    {
        this.pluginArtifacts = pluginArtifacts;
        this.mavenProject = mavenProject;
        this.log = log;
        this.gwtGroupId = gwtGroupId;
    }

    public File getGwtDevJar()
        throws IOException
    {
        checkGwtDevAsDependency();
        checkGwtUserVersion();
        return pluginArtifacts.get( "com.google.gwt:gwt-dev" ).getFile();
    }

    public void checkGwtDevAsDependency()
    {
        for ( Iterator iterator = this.mavenProject.getArtifacts().iterator(); iterator.hasNext(); )
        {
            Artifact artifact = (Artifact) iterator.next();
            if ( this.gwtGroupId.equals( artifact.getGroupId() ) && "gwt-dev".equals( artifact.getArtifactId() )
                && !SCOPE_TEST.equals( artifact.getScope() ) )
            {
                log.warn( "Don't declare gwt-dev as a project dependency. This may introduce complex dependency conflicts" );
            }
        }
    }

    private void checkGwtUserVersion()
        throws IOException
    {
        String resource = "org/codehaus/mojo/gwt/mojoGwtVersion.properties";
        InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream( resource );
        if ( inputStream == null )
        {
            throw new IOException( "impossible to load properties file " + resource );
        }
        Properties properties = new Properties();
        try
        {
            properties.load( inputStream );
{'fraction_non_alphanumeric': 0.09176579638498378, 'fraction_numerical': 0.0021628302178279004, 'mean_word_length': 3.157996146435453, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4262288', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1754, 'n_words': 529}