<commit_before>/*******************************************************************************
 * Copyright (c) 2004, 2006 svnClientAdapter project and others.
 *
 * 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.
 *
 * Contributors:
 *     svnClientAdapter project committers - initial API and implementation
 ******************************************************************************/
package org.tigris.subversion.svnclientadapter.javahl;

import org.tigris.subversion.javahl.SVNClient;
import org.tigris.subversion.javahl.SVNClientInterface;
import org.tigris.subversion.javahl.Version;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.SVNClientAdapterFactory;
import org.tigris.subversion.svnclientadapter.SVNClientException;

/**
 * Concrete implementation of SVNClientAdapterFactory for javahl interface.
 * To register this factory, just call {@link JhlClientAdapterFactory#setup()} 
 */
public class JhlClientAdapterFactory extends SVNClientAdapterFactory {
    
    private static boolean availabilityCached = false;
    private static boolean available;
	private static StringBuffer javaHLErrors = new StringBuffer("Failed to load JavaHL Library.\nThese are the errors that were encountered:\n");
	
	/** Client adapter implementation identifier */
    public static final String JAVAHL_CLIENT = "javahl";

	/**
	 * Private constructor.
	 * Clients are expected the use {@link #createSVNClientImpl()}, res.
	 * ask the {@link SVNClientAdapterFactory}
	 */
    private JhlClientAdapterFactory() {
    	super();
    }

	/* (non-Javadoc)
	 * @see org.tigris.subversion.svnclientadapter.SVNClientAdapterFactory#createSVNClientImpl()
	 */
	protected ISVNClientAdapter createSVNClientImpl() {
		return new JhlClientAdapter();
	}

    /* (non-Javadoc)
     * @see org.tigris.subversion.svnclientadapter.SVNClientAdapterFactory#getClientType()
     */
    protected String getClientType() {
        return JAVAHL_CLIENT;
    }
    
    /**
     * Setup the client adapter implementation and register it in the adapters factory
     * @throws SVNClientException
     */
    public static void setup() throws SVNClientException {
        if (!isAvailable()) {
        	throw new SVNClientException("Javahl client adapter is not available");
        }
        
    	SVNClientAdapterFactory.registerAdapterFactory(new JhlClientAdapterFactory());
    }
    
    public static boolean isAvailable() {
    	if (!availabilityCached) {
    		Class c = null;
    		try {
    			// load a JavaHL class to see if it is found.  Do not use SVNClient as
    			// it will try to load native libraries and we do not want that yet
    			c = Class.forName("org.tigris.subversion.javahl.ClientException");
    			if (c == null)
    				return false;
    		} catch (Throwable t) {
    			availabilityCached = true;
    			return false;
    		}
    		// if library is already loaded, it will not be reloaded

    		//workaround to solve Subclipse ISSUE #83
    		// we will ignore these exceptions to handle scenarios where
    		// javaHL was built diffently.  Ultimately, if javaHL fails to load
    		// because of a problem in one of these libraries the proper behavior
    		// will still occur -- meaning JavaHL adapter is disabled.
    		if(isOsWindows()) {
    			StringBuffer bdbErrors = new StringBuffer();
    			boolean bdbLoaded = false;
    			try {
    				System.loadLibrary("sqlite3");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libapr");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libapriconv");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libeay32");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libdb44");
    				bdbLoaded = true;
    			} catch (Exception e) {
    				bdbErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				bdbErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libdb43");
    				bdbLoaded = true;
    			} catch (Exception e) {
    				bdbErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				bdbErrors.append(e.getMessage()).append("\n");
    			}
    			if (!bdbLoaded) {
    				javaHLErrors.append(bdbErrors.toString());
    			}
    			try {
    				System.loadLibrary("ssleay32");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libaprutil");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("intl3_svn");<commit_msg>Load APR 1.x DLL on Windows<commit_after>/*******************************************************************************
 * Copyright (c) 2004, 2006 svnClientAdapter project and others.
 *
 * 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.
 *
 * Contributors:
 *     svnClientAdapter project committers - initial API and implementation
 ******************************************************************************/
package org.tigris.subversion.svnclientadapter.javahl;

import org.tigris.subversion.javahl.SVNClient;
import org.tigris.subversion.javahl.SVNClientInterface;
import org.tigris.subversion.javahl.Version;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.SVNClientAdapterFactory;
import org.tigris.subversion.svnclientadapter.SVNClientException;

/**
 * Concrete implementation of SVNClientAdapterFactory for javahl interface.
 * To register this factory, just call {@link JhlClientAdapterFactory#setup()} 
 */
public class JhlClientAdapterFactory extends SVNClientAdapterFactory {
    
    private static boolean availabilityCached = false;
    private static boolean available;
	private static StringBuffer javaHLErrors = new StringBuffer("Failed to load JavaHL Library.\nThese are the errors that were encountered:\n");
	
	/** Client adapter implementation identifier */
    public static final String JAVAHL_CLIENT = "javahl";

	/**
	 * Private constructor.
	 * Clients are expected the use {@link #createSVNClientImpl()}, res.
	 * ask the {@link SVNClientAdapterFactory}
	 */
    private JhlClientAdapterFactory() {
    	super();
    }

	/* (non-Javadoc)
	 * @see org.tigris.subversion.svnclientadapter.SVNClientAdapterFactory#createSVNClientImpl()
	 */
	protected ISVNClientAdapter createSVNClientImpl() {
		return new JhlClientAdapter();
	}

    /* (non-Javadoc)
     * @see org.tigris.subversion.svnclientadapter.SVNClientAdapterFactory#getClientType()
     */
    protected String getClientType() {
        return JAVAHL_CLIENT;
    }
    
    /**
     * Setup the client adapter implementation and register it in the adapters factory
     * @throws SVNClientException
     */
    public static void setup() throws SVNClientException {
        if (!isAvailable()) {
        	throw new SVNClientException("Javahl client adapter is not available");
        }
        
    	SVNClientAdapterFactory.registerAdapterFactory(new JhlClientAdapterFactory());
    }
    
    public static boolean isAvailable() {
    	if (!availabilityCached) {
    		Class c = null;
    		try {
    			// load a JavaHL class to see if it is found.  Do not use SVNClient as
    			// it will try to load native libraries and we do not want that yet
    			c = Class.forName("org.tigris.subversion.javahl.ClientException");
    			if (c == null)
    				return false;
    		} catch (Throwable t) {
    			availabilityCached = true;
    			return false;
    		}
    		// if library is already loaded, it will not be reloaded

    		//workaround to solve Subclipse ISSUE #83
    		// we will ignore these exceptions to handle scenarios where
    		// javaHL was built diffently.  Ultimately, if javaHL fails to load
    		// because of a problem in one of these libraries the proper behavior
    		// will still occur -- meaning JavaHL adapter is disabled.
    		if(isOsWindows()) {
    			StringBuffer bdbErrors = new StringBuffer();
    			boolean bdbLoaded = false;
    			try {
    				System.loadLibrary("sqlite3");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libapr");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libapriconv");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libapr-1");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libapriconv-1");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libeay32");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libdb44");
    				bdbLoaded = true;
    			} catch (Exception e) {
    				bdbErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				bdbErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libdb43");
    				bdbLoaded = true;
    			} catch (Exception e) {
    				bdbErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				bdbErrors.append(e.getMessage()).append("\n");
    			}
    			if (!bdbLoaded) {
    				javaHLErrors.append(bdbErrors.toString());
    			}
    			try {
    				System.loadLibrary("ssleay32");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libaprutil");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("libaprutil-1");
    			} catch (Exception e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			} catch (UnsatisfiedLinkError e) {
    				javaHLErrors.append(e.getMessage()).append("\n");
    			}
    			try {
    				System.loadLibrary("intl3_svn");
{'fraction_non_alphanumeric': 0.13482280431432975, 'fraction_numerical': 0.004006163328197226, 'mean_word_length': 2.913476032559542, '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': '1894739', 'n_tokens_mistral': 4301, 'n_tokens_neox': 3963, 'n_words': 904}