<commit_before>/*
 * 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.
 */

package org.apache.felix.sigil.obr;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.apache.felix.sigil.obr.impl.CachingOBRBundleRepository;
import org.apache.felix.sigil.obr.impl.NonCachingOBRBundleRepository;
import org.apache.felix.sigil.repository.IBundleRepository;
import org.apache.felix.sigil.repository.IRepositoryProvider;
import org.apache.felix.sigil.repository.RepositoryException;

public class OBRRepositoryProvider implements IRepositoryProvider
{
    public IBundleRepository createRepository(String id, Properties preferences)
        throws RepositoryException
    {
        String urlStr = preferences.getProperty("url");
        if (urlStr == null)
            throw new RepositoryException("url is not specified.");

        try
        {
            File urlFile = new File(urlStr);
            URL repositoryURL = urlFile.exists() ? urlFile.toURL() : new URL(urlStr);
            URL testURL = urlFile.exists() ? urlFile.toURL() : new URL(urlStr);
            File indexCache = new File(preferences.getProperty("index"));
            File localCache = new File(preferences.getProperty("cache"));
            String auth = preferences.getProperty("auth");
            File authFile = auth == null ? null : new File(auth);

            if (testURL.openConnection().getLastModified() == 0)
            {
                String msg = "Failed to read OBR index: ";
                if (!indexCache.exists())
                    throw new RepositoryException(msg + urlStr);
                System.err.println("WARNING: " + msg + "using cache: " + urlStr);
            }

            // TODO create user configurable updatePeriod
            long updatePeriod = TimeUnit.MILLISECONDS.convert(60 * 60 * 24 * 7,
                TimeUnit.SECONDS);<commit_msg>use toURI().toURL() to avoid windows file conversion bugs<commit_after>/*
 * 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.
 */

package org.apache.felix.sigil.obr;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.apache.felix.sigil.obr.impl.CachingOBRBundleRepository;
import org.apache.felix.sigil.obr.impl.NonCachingOBRBundleRepository;
import org.apache.felix.sigil.repository.IBundleRepository;
import org.apache.felix.sigil.repository.IRepositoryProvider;
import org.apache.felix.sigil.repository.RepositoryException;

public class OBRRepositoryProvider implements IRepositoryProvider
{
    public IBundleRepository createRepository(String id, Properties preferences)
        throws RepositoryException
    {
        String urlStr = preferences.getProperty("url");
        if (urlStr == null)
            throw new RepositoryException("url is not specified.");

        try
        {
            File urlFile = new File(urlStr);
            URL repositoryURL = urlFile.exists() ? urlFile.toURI().toURL() : new URL(urlStr);
            URL testURL = urlFile.exists() ? urlFile.toURI().toURL() : new URL(urlStr);
            File indexCache = new File(preferences.getProperty("index"));
            File localCache = new File(preferences.getProperty("cache"));
            String auth = preferences.getProperty("auth");
            File authFile = auth == null ? null : new File(auth);

            if (testURL.openConnection().getLastModified() == 0)
            {
                String msg = "Failed to read OBR index: ";
                if (!indexCache.exists())
                    throw new RepositoryException(msg + urlStr);
                System.err.println("WARNING: " + msg + "using cache: " + urlStr);
            }

            // TODO create user configurable updatePeriod
            long updatePeriod = TimeUnit.MILLISECONDS.convert(60 * 60 * 24 * 7,
                TimeUnit.SECONDS);
{'fraction_non_alphanumeric': 0.09069256137779406, 'fraction_numerical': 0.004397215097105167, 'mean_word_length': 3.005135730007337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4046906', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1396, 'n_words': 462}