<commit_before>package gov.nih.nci.cagrid.introduce.extensions.metadata.upgrade;

import gov.nih.nci.cagrid.common.Utils;
import gov.nih.nci.cagrid.data.upgrades.UpgradeException;
import gov.nih.nci.cagrid.introduce.beans.ServiceDescription;
import gov.nih.nci.cagrid.introduce.beans.extension.ExtensionType;
import gov.nih.nci.cagrid.introduce.beans.method.MethodType;
import gov.nih.nci.cagrid.introduce.beans.method.MethodTypeExceptions;
import gov.nih.nci.cagrid.introduce.beans.method.MethodTypeExceptionsException;
import gov.nih.nci.cagrid.introduce.beans.method.MethodTypeInputs;
import gov.nih.nci.cagrid.introduce.beans.method.MethodTypeInputsInput;
import gov.nih.nci.cagrid.introduce.beans.method.MethodTypeOutput;
import gov.nih.nci.cagrid.introduce.beans.method.MethodsType;
import gov.nih.nci.cagrid.introduce.beans.resource.ResourcePropertiesListType;
import gov.nih.nci.cagrid.introduce.beans.resource.ResourcePropertyType;
import gov.nih.nci.cagrid.introduce.beans.service.ServiceType;
import gov.nih.nci.cagrid.introduce.common.ServiceInformation;
import gov.nih.nci.cagrid.introduce.extension.ExtensionsLoader;
import gov.nih.nci.cagrid.introduce.extension.utils.ExtensionUtilities;
import gov.nih.nci.cagrid.introduce.extensions.metadata.common.MetadataExtensionHelper;
import gov.nih.nci.cagrid.introduce.extensions.metadata.constants.MetadataConstants;
import gov.nih.nci.cagrid.introduce.upgrade.common.StatusBase;
import gov.nih.nci.cagrid.introduce.upgrade.one.one.ExtensionUpgraderBase;
import gov.nih.nci.cagrid.metadata.MetadataUtils;
import gov.nih.nci.cagrid.metadata.service.ContextProperty;
import gov.nih.nci.cagrid.metadata.service.Fault;
import gov.nih.nci.cagrid.metadata.service.InputParameter;
import gov.nih.nci.cagrid.metadata.service.Operation;
import gov.nih.nci.cagrid.metadata.service.OperationFaultCollection;
import gov.nih.nci.cagrid.metadata.service.OperationInputParameterCollection;
import gov.nih.nci.cagrid.metadata.service.Output;
import gov.nih.nci.cagrid.metadata.service.Service;
import gov.nih.nci.cagrid.metadata.service.ServiceContext;
import gov.nih.nci.cagrid.metadata.service.ServiceContextContextPropertyCollection;
import gov.nih.nci.cagrid.metadata.service.ServiceContextOperationCollection;

import java.io.File;
import java.io.FileFilter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * MetadataUpgrade1pt0to1pt1 copies metadata descriptions
 * 
 * @author oster
 * @created Apr 9, 2007 11:21:24 AM
 * @version $Id: multiscaleEclipseCodeTemplates.xml,v 1.1 2007/03/02 14:35:01
 *          dervin Exp $
 */
public class MetadataUpgrade1pt0to1pt1 extends ExtensionUpgraderBase {
    /**
     * Comment for <code>CAGRID_1_0_METADATA_JAR_PREFIX</code>
     */
    private static final String CAGRID_1_0_METADATA_JAR_PREFIX = "caGrid-1.0-metadata";
    protected MetadataExtensionHelper helper;
    protected static Log LOG = LogFactory.getLog(MetadataUpgrade1pt0to1pt1.class.getName());


    /**
     * @param extensionType
     * @param serviceInfo
     * @param servicePath
     * @param fromVersion
     * @param toVersion
     */
    public MetadataUpgrade1pt0to1pt1(ExtensionType extensionType, ServiceInformation serviceInfo, String servicePath,
        String fromVersion, String toVersion) {
        super("MetadataUpgrade1pt0to1pt1", extensionType, serviceInfo, servicePath, fromVersion, toVersion);
        this.helper = new MetadataExtensionHelper(serviceInfo);
    }


    @Override
    protected void upgrade() throws Exception {
        if (this.helper.getExistingServiceMetdata() == null) {
            LOG.info("Unable to locate service metdata; no metadata upgrade will be performed.");
            getStatus().addDescriptionLine("Unable to locate service metdata; no metadata upgrade will be performed.");
            getStatus().setStatus(StatusBase.UPGRADE_OK);
            return;
        }

        upgradeJars();

        // make a copy of the metadata backup
        writeBackupServiceMetadata();

        processService(this.helper.getExistingServiceMetdata().getServiceDescription().getService(),
            getServiceInformation().getServiceDescriptor());
        getStatus().addDescriptionLine("Successfully updated metadata instance.");

        getStatus().setStatus(StatusBase.UPGRADE_OK);
    }


    /**
     * Upgrade the jars which are required for metadata
     */
    private void upgradeJars() throws UpgradeException {
        FileFilter metadataLibFilter = new FileFilter() {
            public boolean accept(File pathname) {
                String name = pathname.getName();
                return name.endsWith(".jar") && name.startsWith(CAGRID_1_0_METADATA_JAR_PREFIX)
                    && !name.startsWith(CAGRID_1_0_METADATA_JAR_PREFIX + "-data")
                    && !name.startsWith(CAGRID_1_0_METADATA_JAR_PREFIX + "-security");
            }
        };
        FileFilter newMetadataLibFilter = new FileFilter() {
            public boolean accept(File pathname) {
                String name = pathname.getName();
                return name.endsWith(".jar") && name.startsWith(MetadataConstants.METADATA_JAR_PREFIX)
                    && !name.startsWith(MetadataConstants.METADATA_JAR_PREFIX + "-data")
                    && !name.startsWith(MetadataConstants.METADATA_JAR_PREFIX + "-security");
            }
        };
        // locate the old data service libs in the service
        File serviceLibDir = new File(getServicePath() + File.separator + "lib");
        File[] serviceMetadataLibs = serviceLibDir.listFiles(metadataLibFilter);
        // delete the old libraries
        for (File oldLib : serviceMetadataLibs) {
            oldLib.delete();
            getStatus().addDescriptionLine("caGrid 1.0 library " + oldLib.getName() + " removed");
        }
        // copy new libraries in
        File extLibDir = new File(ExtensionsLoader.EXTENSIONS_DIRECTORY + File.separator + "lib");
        File[] metadataLibs = extLibDir.listFiles(newMetadataLibFilter);
        List<File> outLibs = new ArrayList<File>(metadataLibs.length);
        for (File newLib : metadataLibs) {
            File out = new File(serviceLibDir.getAbsolutePath() + File.separator + newLib.getName());
            try {
                Utils.copyFile(newLib, out);
                getStatus().addDescriptionLine("caGrid 1.1 library " + newLib.getName() + " added");
            } catch (IOException ex) {
                throw new UpgradeException("Error copying new metadata library: " + ex.getMessage(), ex);
            }
            outLibs.add(out);
        }

        // update the Eclipse .classpath file
        File classpathFile = new File(getServicePath() + File.separator + ".classpath");
        File[] outLibArray = new File[metadataLibs.length];
        outLibs.toArray(outLibArray);
        try {
            ExtensionUtilities.syncEclipseClasspath(classpathFile, outLibArray);
            getStatus().addDescriptionLine("Eclipse .classpath file updated");
        } catch (Exception ex) {
            throw new UpgradeException("Error updating Eclipse .classpath file: " + ex.getMessage(), ex);
        }

    }
<commit_msg>*** empty log message ***<commit_after>package gov.nih.nci.cagrid.introduce.extensions.metadata.upgrade;

import gov.nih.nci.cagrid.common.Utils;
import gov.nih.nci.cagrid.introduce.beans.ServiceDescription;
import gov.nih.nci.cagrid.introduce.beans.extension.ExtensionType;
import gov.nih.nci.cagrid.introduce.beans.method.MethodType;
import gov.nih.nci.cagrid.introduce.beans.method.MethodTypeExceptions;
import gov.nih.nci.cagrid.introduce.beans.method.MethodTypeExceptionsException;
import gov.nih.nci.cagrid.introduce.beans.method.MethodTypeInputs;
import gov.nih.nci.cagrid.introduce.beans.method.MethodTypeInputsInput;
import gov.nih.nci.cagrid.introduce.beans.method.MethodTypeOutput;
import gov.nih.nci.cagrid.introduce.beans.method.MethodsType;
import gov.nih.nci.cagrid.introduce.beans.resource.ResourcePropertiesListType;
import gov.nih.nci.cagrid.introduce.beans.resource.ResourcePropertyType;
import gov.nih.nci.cagrid.introduce.beans.service.ServiceType;
import gov.nih.nci.cagrid.introduce.common.ServiceInformation;
import gov.nih.nci.cagrid.introduce.extension.ExtensionsLoader;
import gov.nih.nci.cagrid.introduce.extension.utils.ExtensionUtilities;
import gov.nih.nci.cagrid.introduce.extensions.metadata.common.MetadataExtensionHelper;
import gov.nih.nci.cagrid.introduce.extensions.metadata.constants.MetadataConstants;
import gov.nih.nci.cagrid.introduce.upgrade.common.StatusBase;
import gov.nih.nci.cagrid.introduce.upgrade.one.one.ExtensionUpgraderBase;
import gov.nih.nci.cagrid.metadata.MetadataUtils;
import gov.nih.nci.cagrid.metadata.service.ContextProperty;
import gov.nih.nci.cagrid.metadata.service.Fault;
import gov.nih.nci.cagrid.metadata.service.InputParameter;
import gov.nih.nci.cagrid.metadata.service.Operation;
import gov.nih.nci.cagrid.metadata.service.OperationFaultCollection;
import gov.nih.nci.cagrid.metadata.service.OperationInputParameterCollection;
import gov.nih.nci.cagrid.metadata.service.Output;
import gov.nih.nci.cagrid.metadata.service.Service;
import gov.nih.nci.cagrid.metadata.service.ServiceContext;
import gov.nih.nci.cagrid.metadata.service.ServiceContextContextPropertyCollection;
import gov.nih.nci.cagrid.metadata.service.ServiceContextOperationCollection;

import java.io.File;
import java.io.FileFilter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * MetadataUpgrade1pt0to1pt1 copies metadata descriptions
 * 
 * @author oster
 * @created Apr 9, 2007 11:21:24 AM
 * @version $Id: multiscaleEclipseCodeTemplates.xml,v 1.1 2007/03/02 14:35:01
 *          dervin Exp $
 */
public class MetadataUpgrade1pt0to1pt1 extends ExtensionUpgraderBase {
    /**
     * Comment for <code>CAGRID_1_0_METADATA_JAR_PREFIX</code>
     */
    private static final String CAGRID_1_0_METADATA_JAR_PREFIX = "caGrid-1.0-metadata";
    protected MetadataExtensionHelper helper;
    protected static Log LOG = LogFactory.getLog(MetadataUpgrade1pt0to1pt1.class.getName());


    /**
     * @param extensionType
     * @param serviceInfo
     * @param servicePath
     * @param fromVersion
     * @param toVersion
     */
    public MetadataUpgrade1pt0to1pt1(ExtensionType extensionType, ServiceInformation serviceInfo, String servicePath,
        String fromVersion, String toVersion) {
        super("MetadataUpgrade1pt0to1pt1", extensionType, serviceInfo, servicePath, fromVersion, toVersion);
        this.helper = new MetadataExtensionHelper(serviceInfo);
    }


    @Override
    protected void upgrade() throws Exception {
        if (this.helper.getExistingServiceMetdata() == null) {
            LOG.info("Unable to locate service metdata; no metadata upgrade will be performed.");
            getStatus().addDescriptionLine("Unable to locate service metdata; no metadata upgrade will be performed.");
            getStatus().setStatus(StatusBase.UPGRADE_OK);
            return;
        }

        upgradeJars();

        // make a copy of the metadata backup
        writeBackupServiceMetadata();

        processService(this.helper.getExistingServiceMetdata().getServiceDescription().getService(),
            getServiceInformation().getServiceDescriptor());
        getStatus().addDescriptionLine("Successfully updated metadata instance.");

        getStatus().setStatus(StatusBase.UPGRADE_OK);
    }


    /**
     * Upgrade the jars which are required for metadata
     */
    private void upgradeJars() {
        FileFilter metadataLibFilter = new FileFilter() {
            public boolean accept(File pathname) {
                String name = pathname.getName();
                return name.endsWith(".jar") && name.startsWith(CAGRID_1_0_METADATA_JAR_PREFIX)
                    && !name.startsWith(CAGRID_1_0_METADATA_JAR_PREFIX + "-data")
                    && !name.startsWith(CAGRID_1_0_METADATA_JAR_PREFIX + "-security");
            }
        };
        FileFilter newMetadataLibFilter = new FileFilter() {
            public boolean accept(File pathname) {
                String name = pathname.getName();
                return name.endsWith(".jar") && name.startsWith(MetadataConstants.METADATA_JAR_PREFIX)
                    && !name.startsWith(MetadataConstants.METADATA_JAR_PREFIX + "-data")
                    && !name.startsWith(MetadataConstants.METADATA_JAR_PREFIX + "-security");
            }
        };
        // locate the old data service libs in the service
        File serviceLibDir = new File(getServicePath() + File.separator + "lib");
        File[] serviceMetadataLibs = serviceLibDir.listFiles(metadataLibFilter);
        // delete the old libraries
        for (File oldLib : serviceMetadataLibs) {
            oldLib.delete();
            getStatus().addDescriptionLine("caGrid 1.0 library " + oldLib.getName() + " removed");
        }
        // copy new libraries in
        File extLibDir = new File(ExtensionsLoader.EXTENSIONS_DIRECTORY + File.separator + "lib");
        File[] metadataLibs = extLibDir.listFiles(newMetadataLibFilter);
        List<File> outLibs = new ArrayList<File>(metadataLibs.length);
        for (File newLib : metadataLibs) {
            File out = new File(serviceLibDir.getAbsolutePath() + File.separator + newLib.getName());
            try {
                Utils.copyFile(newLib, out);
                getStatus().addDescriptionLine("caGrid 1.1 library " + newLib.getName() + " added");
            } catch (IOException ex) {
                // TODO: change this to use a better exception
                throw new RuntimeException("Error copying new metadata library: " + ex.getMessage(), ex);
            }
            outLibs.add(out);
        }

        // update the Eclipse .classpath file
        File classpathFile = new File(getServicePath() + File.separator + ".classpath");
        File[] outLibArray = new File[metadataLibs.length];
        outLibs.toArray(outLibArray);
        try {
            ExtensionUtilities.syncEclipseClasspath(classpathFile, outLibArray);
            getStatus().addDescriptionLine("Eclipse .classpath file updated");
        } catch (Exception ex) {
            // TODO: change this to use a better exception
            throw new RuntimeException("Error updating Eclipse .classpath file: " + ex.getMessage(), ex);
        }

    }

{'fraction_non_alphanumeric': 0.10482450196503591, 'fraction_numerical': 0.008537742241496138, 'mean_word_length': 3.422834881630207, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6006156', 'n_tokens_mistral': 4503, 'n_tokens_neox': 4339, 'n_words': 762}