<commit_before>package org.apache.maven.project;

/*
 * 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 org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Contributor;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Developer;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.IssueManagement;
import org.apache.maven.model.License;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Prerequisites;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.artifact.ActiveProjectArtifact;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.overlay.BuildOverlay;
import org.codehaus.plexus.util.xml.Xpp3Dom;

import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * The concern of the project is provide runtime values based on the model. <p/>
 * The values in the model remain untouched but during the process of building a
 * project notions like inheritance and interpolation can be added. This allows
 * to have an entity which is useful in a runtime while preserving the model so
 * that it can be marshalled and unmarshalled without being tainted by runtime
 * requirements. <p/>We need to leave the model intact because we don't want
 * the following:
 * <ol>
 * <li>We don't want interpolated values being written back into the model.
 * <li>We don't want inherited values being written back into the model.
 * </ol>
 */
public class MavenProject
{
    private Model model;

    private MavenProject parent;

    private File file;

    private Set artifacts;

    private Artifact parentArtifact;

    private Set pluginArtifacts;

    private List remoteArtifactRepositories;

    private List collectedProjects = Collections.EMPTY_LIST;

    private List attachedArtifacts;

    private MavenProject executionProject;

    private List compileSourceRoots = new ArrayList();

    private List testCompileSourceRoots = new ArrayList();

    private List scriptSourceRoots = new ArrayList();

    private List pluginArtifactRepositories;

    private ArtifactRepository releaseArtifactRepository;

    private ArtifactRepository snapshotArtifactRepository;

    private List activeProfiles = new ArrayList();

    private Set dependencyArtifacts;

    private Artifact artifact;

    // calculated.
    private Map artifactMap;

    private Model originalModel;

    private Map pluginArtifactMap;

    private Set reportArtifacts;

    private Map reportArtifactMap;

    private Set extensionArtifacts;

    private Map extensionArtifactMap;

    private Map projectReferences = new HashMap();

    private Build buildOverlay;

    private boolean executionRoot;
    
    private Map moduleAdjustments;

    public MavenProject( Model model )
    {
        this.model = model;
    }

    public MavenProject( MavenProject project )
    {
        // disown the parent

        // copy fields
        this.file = project.file;

        // don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be sure!
        if ( project.dependencyArtifacts != null )
        {
            this.dependencyArtifacts = Collections.unmodifiableSet( project.dependencyArtifacts );
        }
        if ( project.artifacts != null )
        {
            this.artifacts = Collections.unmodifiableSet( project.artifacts );
        }
        this.pluginArtifacts = Collections.unmodifiableSet( project.pluginArtifacts );
        this.reportArtifacts = Collections.unmodifiableSet( project.reportArtifacts );
        this.extensionArtifacts = Collections.unmodifiableSet( project.extensionArtifacts );
        this.parentArtifact = project.parentArtifact;

        this.remoteArtifactRepositories = Collections.unmodifiableList( project.remoteArtifactRepositories );
        this.pluginArtifactRepositories = Collections.unmodifiableList( project.pluginArtifactRepositories );
        this.collectedProjects = Collections.unmodifiableList( project.collectedProjects );
        this.activeProfiles = Collections.unmodifiableList( project.activeProfiles );

        // clone properties modifyable by plugins in a forked lifecycle
        this.attachedArtifacts = new ArrayList( project.getAttachedArtifacts() );

        // no need for execution project

        // clone source roots
        this.compileSourceRoots = new ArrayList( project.compileSourceRoots );
        this.testCompileSourceRoots = new ArrayList( project.testCompileSourceRoots );
        this.scriptSourceRoots = new ArrayList( project.scriptSourceRoots );

        this.model = ModelUtils.cloneModel( project.model );

        if ( project.originalModel != null )
        {
            this.originalModel = ModelUtils.cloneModel( project.originalModel );
        }

        this.executionRoot = project.executionRoot;

        this.artifact = ArtifactUtils.copyArtifact( project.artifact );
    }
    
    public String getModulePathAdjustment( MavenProject moduleProject ) throws IOException
    {
        // FIXME: This is hacky. What if module directory doesn't match artifactid, and parent
        // is coming from the repository??
        String module = moduleProject.getArtifactId();
        
        File moduleFile = moduleProject.getFile();
        
        if ( moduleFile != null )
        {
            File moduleDir = moduleFile.getCanonicalFile().getParentFile();
            
            module = moduleDir.getName();
        }
        
        if ( moduleAdjustments == null )
        {
            moduleAdjustments = new HashMap();
            
            List modules = getModules();
            if ( modules != null )
            {
                for ( Iterator it = modules.iterator(); it.hasNext(); )
                {
                    String modulePath = (String) it.next();
                    String moduleName = modulePath;
                    
                    if ( moduleName.endsWith( "/" ) || moduleName.endsWith( "\\" ) )
                    {
                        moduleName = moduleName.substring( 0, moduleName.length() - 1 );
                    }<commit_msg>Added TODO comment to the getModulePathAdjustment() method.<commit_after>package org.apache.maven.project;

/*
 * 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 org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Contributor;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Developer;
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.IssueManagement;
import org.apache.maven.model.License;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
import org.apache.maven.model.Organization;
import org.apache.maven.model.Parent;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.model.Prerequisites;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.artifact.ActiveProjectArtifact;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.artifact.MavenMetadataSource;
import org.apache.maven.project.overlay.BuildOverlay;
import org.codehaus.plexus.util.xml.Xpp3Dom;

import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * The concern of the project is provide runtime values based on the model. <p/>
 * The values in the model remain untouched but during the process of building a
 * project notions like inheritance and interpolation can be added. This allows
 * to have an entity which is useful in a runtime while preserving the model so
 * that it can be marshalled and unmarshalled without being tainted by runtime
 * requirements. <p/>We need to leave the model intact because we don't want
 * the following:
 * <ol>
 * <li>We don't want interpolated values being written back into the model.
 * <li>We don't want inherited values being written back into the model.
 * </ol>
 */
public class MavenProject
{
    private Model model;

    private MavenProject parent;

    private File file;

    private Set artifacts;

    private Artifact parentArtifact;

    private Set pluginArtifacts;

    private List remoteArtifactRepositories;

    private List collectedProjects = Collections.EMPTY_LIST;

    private List attachedArtifacts;

    private MavenProject executionProject;

    private List compileSourceRoots = new ArrayList();

    private List testCompileSourceRoots = new ArrayList();

    private List scriptSourceRoots = new ArrayList();

    private List pluginArtifactRepositories;

    private ArtifactRepository releaseArtifactRepository;

    private ArtifactRepository snapshotArtifactRepository;

    private List activeProfiles = new ArrayList();

    private Set dependencyArtifacts;

    private Artifact artifact;

    // calculated.
    private Map artifactMap;

    private Model originalModel;

    private Map pluginArtifactMap;

    private Set reportArtifacts;

    private Map reportArtifactMap;

    private Set extensionArtifacts;

    private Map extensionArtifactMap;

    private Map projectReferences = new HashMap();

    private Build buildOverlay;

    private boolean executionRoot;
    
    private Map moduleAdjustments;

    public MavenProject( Model model )
    {
        this.model = model;
    }

    public MavenProject( MavenProject project )
    {
        // disown the parent

        // copy fields
        this.file = project.file;

        // don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be sure!
        if ( project.dependencyArtifacts != null )
        {
            this.dependencyArtifacts = Collections.unmodifiableSet( project.dependencyArtifacts );
        }
        if ( project.artifacts != null )
        {
            this.artifacts = Collections.unmodifiableSet( project.artifacts );
        }
        this.pluginArtifacts = Collections.unmodifiableSet( project.pluginArtifacts );
        this.reportArtifacts = Collections.unmodifiableSet( project.reportArtifacts );
        this.extensionArtifacts = Collections.unmodifiableSet( project.extensionArtifacts );
        this.parentArtifact = project.parentArtifact;

        this.remoteArtifactRepositories = Collections.unmodifiableList( project.remoteArtifactRepositories );
        this.pluginArtifactRepositories = Collections.unmodifiableList( project.pluginArtifactRepositories );
        this.collectedProjects = Collections.unmodifiableList( project.collectedProjects );
        this.activeProfiles = Collections.unmodifiableList( project.activeProfiles );

        // clone properties modifyable by plugins in a forked lifecycle
        this.attachedArtifacts = new ArrayList( project.getAttachedArtifacts() );

        // no need for execution project

        // clone source roots
        this.compileSourceRoots = new ArrayList( project.compileSourceRoots );
        this.testCompileSourceRoots = new ArrayList( project.testCompileSourceRoots );
        this.scriptSourceRoots = new ArrayList( project.scriptSourceRoots );

        this.model = ModelUtils.cloneModel( project.model );

        if ( project.originalModel != null )
        {
            this.originalModel = ModelUtils.cloneModel( project.originalModel );
        }

        this.executionRoot = project.executionRoot;

        this.artifact = ArtifactUtils.copyArtifact( project.artifact );
    }
    
    // TODO: Find a way to use <relativePath/> here...it's tricky, because the moduleProject
    // usually doesn't have a file associated with it yet.
    public String getModulePathAdjustment( MavenProject moduleProject ) throws IOException
    {
        // FIXME: This is hacky. What if module directory doesn't match artifactid, and parent
        // is coming from the repository??
        String module = moduleProject.getArtifactId();
        
        File moduleFile = moduleProject.getFile();
        
        if ( moduleFile != null )
        {
            File moduleDir = moduleFile.getCanonicalFile().getParentFile();
            
            module = moduleDir.getName();
        }
        
        if ( moduleAdjustments == null )
        {
            moduleAdjustments = new HashMap();
            
            List modules = getModules();
            if ( modules != null )
            {
                for ( Iterator it = modules.iterator(); it.hasNext(); )
                {
                    String modulePath = (String) it.next();
                    String moduleName = modulePath;
                    
                    if ( moduleName.endsWith( "/" ) || moduleName.endsWith( "\\" ) )
                    {
                        moduleName = moduleName.substring( 0, moduleName.length() - 1 );
                    }
{'fraction_non_alphanumeric': 0.08022155837689818, 'fraction_numerical': 0.0021160069703759026, 'mean_word_length': 3.154343329886246, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3110716', 'n_tokens_mistral': 4290, 'n_tokens_neox': 4020, 'n_words': 1173}