<commit_before>/*
 * Copyright (c) 2014 <NAME> (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    <NAME> - initial API and implementation
 */
package org.eclipse.oomph.targlets.internal.core;

import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
import org.eclipse.equinox.internal.p2.metadata.OSGiVersion;
import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.metadata.MetadataFactory;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction;
import org.eclipse.equinox.p2.publisher.eclipse.Feature;
import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction;
import org.eclipse.osgi.service.resolver.BundleDescription;

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

/**
 * @author <NAME>
 */
public interface IUGenerator
{
  public IInstallableUnit generateIU(File location) throws Exception;

  /**
   * @author <NAME>
   */
  public static final class BundleIUGenerator extends BundlesAction implements IUGenerator
  {
    public static final IUGenerator INSTANCE = new BundleIUGenerator();

    private BundleIUGenerator()
    {
      super((File[])null);
      setPublisherInfo(new PublisherInfo());
    }

    public IInstallableUnit generateIU(File location) throws Exception
    {
      Dictionary<String, String> manifest = loadManifest(location);
      if (manifest == null)
      {
        return null;
      }

      String version = manifest.get(org.osgi.framework.Constants.BUNDLE_VERSION);
      if (version.endsWith(".qualifier"))
      {
        version = version.substring(0, version.length() - ".qualifier".length());
        manifest.put(org.osgi.framework.Constants.BUNDLE_VERSION, version);
      }

      BundleDescription description = createBundleDescription(manifest, location);
      if (description == null)
      {
        return null;
      }

      IInstallableUnit iu = createBundleIU(description, null, info);
      if (iu instanceof InstallableUnit)
      {
        ((InstallableUnit)iu).setArtifacts(new IArtifactKey[0]);
      }

      return iu;
    }
  }

  /**
   * @author <NAME>
   */
  public static final class FeatureIUGenerator extends FeaturesAction implements IUGenerator
  {
    public static final IUGenerator INSTANCE = new FeatureIUGenerator();

    private FeatureIUGenerator()
    {
      super((File[])null);
      setPublisherInfo(new PublisherInfo());
    }

    public IInstallableUnit generateIU(File location) throws Exception
    {
      Feature[] features = getFeatures(new File[] { location });
      if (features == null || features.length == 0)
      {
        return null;
      }

      Feature feature = features[0];

      String version = feature.getVersion();
      if (version.endsWith(".qualifier"))
      {
        version = version.substring(0, version.length() - ".qualifier".length());
        feature.setVersion(version);<commit_msg>[437344] Changes in workspace components aren't picked up by p2 https://bugs.eclipse.org/bugs/show_bug.cgi?id=437344<commit_after>/*
 * Copyright (c) 2014 <NAME> (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    <NAME> - initial API and implementation
 */
package org.eclipse.oomph.targlets.internal.core;

import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
import org.eclipse.equinox.internal.p2.metadata.OSGiVersion;
import org.eclipse.equinox.internal.p2.metadata.RequiredCapability;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.IRequirement;
import org.eclipse.equinox.p2.metadata.MetadataFactory;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.metadata.VersionRange;
import org.eclipse.equinox.p2.metadata.expression.IMatchExpression;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
import org.eclipse.equinox.p2.publisher.eclipse.BundlesAction;
import org.eclipse.equinox.p2.publisher.eclipse.Feature;
import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction;
import org.eclipse.osgi.service.resolver.BundleDescription;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Dictionary;
import java.util.List;

/**
 * @author <NAME>
 */
public interface IUGenerator
{
  public static final SimpleDateFormat QUALIFIER_FORMAT = new SimpleDateFormat("'v'yyyyMMdd-HHmmss");

  public IInstallableUnit generateIU(File location) throws Exception;

  /**
   * @author <NAME>
   */
  public static final class BundleIUGenerator extends BundlesAction implements IUGenerator
  {
    public static final IUGenerator INSTANCE = new BundleIUGenerator();

    private BundleIUGenerator()
    {
      super((File[])null);
      setPublisherInfo(new PublisherInfo());
    }

    public IInstallableUnit generateIU(File location) throws Exception
    {
      Dictionary<String, String> manifest = loadManifest(location);
      if (manifest == null)
      {
        return null;
      }

      String version = manifest.get(org.osgi.framework.Constants.BUNDLE_VERSION);
      if (version.endsWith(".qualifier"))
      {
        version = version.substring(0, version.length() - "qualifier".length());
        version += QUALIFIER_FORMAT.format(new Date());
        manifest.put(org.osgi.framework.Constants.BUNDLE_VERSION, version);
      }

      BundleDescription description = createBundleDescription(manifest, location);
      if (description == null)
      {
        return null;
      }

      IInstallableUnit iu = createBundleIU(description, null, info);
      if (iu instanceof InstallableUnit)
      {
        ((InstallableUnit)iu).setArtifacts(new IArtifactKey[0]);
      }

      return iu;
    }
  }

  /**
   * @author <NAME>
   */
  public static final class FeatureIUGenerator extends FeaturesAction implements IUGenerator
  {
    public static final IUGenerator INSTANCE = new FeatureIUGenerator();

    private FeatureIUGenerator()
    {
      super((File[])null);
      setPublisherInfo(new PublisherInfo());
    }

    public IInstallableUnit generateIU(File location) throws Exception
    {
      Feature[] features = getFeatures(new File[] { location });
      if (features == null || features.length == 0)
      {
        return null;
      }

      Feature feature = features[0];

      String version = feature.getVersion();
      if (version.endsWith(".qualifier"))
      {
        version = version.substring(0, version.length() - "qualifier".length());
        version += QUALIFIER_FORMAT.format(new Date());
        feature.setVersion(version);
{'fraction_non_alphanumeric': 0.10824468085106383, 'fraction_numerical': 0.008909574468085107, 'mean_word_length': 3.688902743142145, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 1, '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': '382203', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2142, 'n_words': 468}