<commit_before>/*
 * Copyright 2011 Red Hat inc. and third party contributors as noted 
 * by the author tags.
 * 
 * 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 com.redhat.ceylon.cmr.impl;

import com.redhat.ceylon.cmr.api.Logger;
import com.redhat.ceylon.cmr.api.Repository;
import com.redhat.ceylon.cmr.api.RepositoryBuilder;
import com.redhat.ceylon.cmr.spi.StructureBuilder;

import java.io.File;
import java.lang.reflect.Method;
import java.net.URI;

/**
 * Repository builder.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
class RepositoryBuilderImpl implements RepositoryBuilder {

    private Logger log;

    RepositoryBuilderImpl(Logger log) {
        this.log = log;
    }

    public Repository buildRepository(String token) throws Exception {
        if (token == null)
            throw new IllegalArgumentException("Null repository");

        final String key = (token.startsWith("${") ? token.substring(2, token.length() - 1) : token);
        final String temp = SecurityActions.getProperty(key);
        if (temp != null)
            token = temp;

        StructureBuilder structureBuilder;
        if (token.startsWith("http")) {
            structureBuilder = new RemoteContentStore(token, log);
        } else if (token.startsWith("mvn:")) {
            return MavenRepositoryHelper.getMavenRepository(token.substring("mvn:".length()), log);
        } else if (token.equals("aether")) {
            Class<?> aetherRepositoryClass = getClass().getClassLoader().loadClass("com.redhat.ceylon.cmr.maven.AetherRepository");
            Method createRepository = aetherRepositoryClass.getMethod("createRepository", Logger.class);
            return (Repository) createRepository.invoke(null, log);
        } else {
            final File file = (token.startsWith("file") ? new File(new URI(token)) : new File(token));
            if (file.exists() == false)
                throw new IllegalArgumentException("Directory does not exist: " + token);
            if (file.isDirectory() == false)
                throw new IllegalArgumentException("Repository exists but is not a directory: " + token);

            structureBuilder = new FileContentStore(file);
        }
        return new DefaultRepository(structureBuilder.createRoot());
    }
}<commit_msg>Allow for default mvn support.<commit_after>/*
 * Copyright 2011 Red Hat inc. and third party contributors as noted 
 * by the author tags.
 * 
 * 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 com.redhat.ceylon.cmr.impl;

import com.redhat.ceylon.cmr.api.Logger;
import com.redhat.ceylon.cmr.api.Repository;
import com.redhat.ceylon.cmr.api.RepositoryBuilder;
import com.redhat.ceylon.cmr.spi.StructureBuilder;

import java.io.File;
import java.lang.reflect.Method;
import java.net.URI;

/**
 * Repository builder.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
class RepositoryBuilderImpl implements RepositoryBuilder {

    private Logger log;

    RepositoryBuilderImpl(Logger log) {
        this.log = log;
    }

    public Repository buildRepository(String token) throws Exception {
        if (token == null)
            throw new IllegalArgumentException("Null repository");

        final String key = (token.startsWith("${") ? token.substring(2, token.length() - 1) : token);
        final String temp = SecurityActions.getProperty(key);
        if (temp != null)
            token = temp;

        StructureBuilder structureBuilder;
        if (token.startsWith("http")) {
            structureBuilder = new RemoteContentStore(token, log);
        } else if (token.startsWith("mvn:")) {
            return MavenRepositoryHelper.getMavenRepository(token.substring("mvn:".length()), log);
        } else if (token.equals("mvn")) {
            return MavenRepositoryHelper.getMavenRepository();
        } else if (token.equals("aether")) {
            Class<?> aetherRepositoryClass = getClass().getClassLoader().loadClass("com.redhat.ceylon.cmr.maven.AetherRepository");
            Method createRepository = aetherRepositoryClass.getMethod("createRepository", Logger.class);
            return (Repository) createRepository.invoke(null, log);
        } else {
            final File file = (token.startsWith("file") ? new File(new URI(token)) : new File(token));
            if (file.exists() == false)
                throw new IllegalArgumentException("Directory does not exist: " + token);
            if (file.isDirectory() == false)
                throw new IllegalArgumentException("Repository exists but is not a directory: " + token);

            structureBuilder = new FileContentStore(file);
        }
        return new DefaultRepository(structureBuilder.createRoot());
    }
}
{'fraction_non_alphanumeric': 0.10890052356020942, 'fraction_numerical': 0.0034904013961605585, 'mean_word_length': 3.168, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2894391', 'n_tokens_mistral': 1516, 'n_tokens_neox': 1489, 'n_words': 455}