<commit_before>package com.redhat.ceylon.compiler.typechecker.io;

import java.io.File;
import java.util.List;

import com.redhat.ceylon.compiler.typechecker.io.impl.Helper;
import com.redhat.ceylon.compiler.typechecker.model.Module;

/**
 * @author <NAME> <<EMAIL>>
 */
public class VFSArtifactProvider implements ArtifactProvider {
    private final VirtualFile homeRepo;
    private final VFS vfs;

    public VFSArtifactProvider(VFS vfs) {
        File repo = Helper.getHomeRepository();
        homeRepo = vfs.getFromFile(repo);
        this.vfs = vfs;
    }



    public VFSArtifactProvider(VirtualFile homeRepo, VFS vfs) {
        this.homeRepo = homeRepo;
        this.vfs = vfs;
    }
    
    /**
     * Return the artifact or null if not present
     * Must be closed when done with it
     */
    @Override
    public ClosableVirtualFile getArtifact(List<String> moduleName, String version, Iterable<String> extensions) {
        VirtualFile moduleDirectory = getModuleDirectory(moduleName, version);
        if (moduleDirectory == null) {
            return null;
        }
        for (String extension : extensions) {
            final VirtualFile child = getChild(moduleDirectory, getArtifactName(moduleName, version, extension) );
            if (child != null) {
                //build sha1 and compare it
                return vfs.openAsContainer(child);
            }
        }
        return null;
    }

    /**
     * f.q.module.name-version.extension
     */
    public static String getArtifactName(List<String> moduleName, String version, String extension) {
        StringBuilder name = new StringBuilder();
        for (String moduleRadix : moduleName) {
            name.append(moduleRadix).append(".");
        }
        name.deleteCharAt( name.length() - 1 ); //remove trailing dot
        // the default module doesn't have a name
        if(!name.equals(Module.DEFAULT_MODULE_NAME))
            name.append("-").append(version);
        name.append(".").append(extension);
        return name.toString();
    }

    /**
     * Navigate down the path down to the version directory
     * f.q.module.name.version
     */
    private VirtualFile getModuleDirectory(List<String> moduleName, String version) {
        VirtualFile current = homeRepo;
        for (String dir : moduleName) {
            current = getChild(current, dir);
            if (current == null) {
                return null;
            }
        }
        current = getChild(current, version);
        return current;
    }

    private VirtualFile getChild(VirtualFile parent, String name) {
        for ( VirtualFile child : parent.getChildren() ) {
            if ( child.getName().equals(name) ) {
                return child;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return homeRepo.getPath();
    }
}
<commit_msg>issue #219 - Fix minor issue when extension is not present<commit_after>package com.redhat.ceylon.compiler.typechecker.io;

import java.io.File;
import java.util.List;

import com.redhat.ceylon.compiler.typechecker.io.impl.Helper;
import com.redhat.ceylon.compiler.typechecker.model.Module;

/**
 * @author <NAME> <<EMAIL>>
 */
public class VFSArtifactProvider implements ArtifactProvider {
    private final VirtualFile homeRepo;
    private final VFS vfs;

    public VFSArtifactProvider(VFS vfs) {
        File repo = Helper.getHomeRepository();
        homeRepo = vfs.getFromFile(repo);
        this.vfs = vfs;
    }



    public VFSArtifactProvider(VirtualFile homeRepo, VFS vfs) {
        this.homeRepo = homeRepo;
        this.vfs = vfs;
    }
    
    /**
     * Return the artifact or null if not present
     * Must be closed when done with it
     */
    @Override
    public ClosableVirtualFile getArtifact(List<String> moduleName, String version, Iterable<String> extensions) {
        VirtualFile moduleDirectory = getModuleDirectory(moduleName, version);
        if (moduleDirectory == null) {
            return null;
        }
        for (String extension : extensions) {
            final VirtualFile child = getChild(moduleDirectory, getArtifactName(moduleName, version, extension) );
            if (child != null) {
                //build sha1 and compare it
                return vfs.openAsContainer(child);
            }
        }
        return null;
    }

    /**
     * f.q.module.name-version.extension
     */
    public static String getArtifactName(List<String> moduleName, String version, String extension) {
        StringBuilder name = new StringBuilder();
        for (String moduleRadix : moduleName) {
            name.append(moduleRadix).append(".");
        }
        name.deleteCharAt( name.length() - 1 ); //remove trailing dot
        // the default module doesn't have a name
        if(!name.equals(Module.DEFAULT_MODULE_NAME)) {
            name.append("-").append(version);
        }
        if ( extension != null ) {
            name.append(".").append(extension);
        }
        return name.toString();
    }

    /**
     * Navigate down the path down to the version directory
     * f.q.module.name.version
     */
    private VirtualFile getModuleDirectory(List<String> moduleName, String version) {
        VirtualFile current = homeRepo;
        for (String dir : moduleName) {
            current = getChild(current, dir);
            if (current == null) {
                return null;
            }
        }
        current = getChild(current, version);
        return current;
    }

    private VirtualFile getChild(VirtualFile parent, String name) {
        for ( VirtualFile child : parent.getChildren() ) {
            if ( child.getName().equals(name) ) {
                return child;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return homeRepo.getPath();
    }
}

{'fraction_non_alphanumeric': 0.10054347826086957, 'fraction_numerical': 0.001188858695652174, 'mean_word_length': 2.1832432432432434, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7591218', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1605, 'n_words': 404}