<commit_before>/*
 * Copyright 2016 DiffPlug
 *
 * 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.diffplug.gradle.p2;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.stream.Collectors;

import org.osgi.framework.Version;

import groovy.util.Node;
import groovy.xml.XmlUtil;

import com.diffplug.common.collect.HashMultimap;
import com.diffplug.common.collect.Multimap;
import com.diffplug.gradle.FileMisc;

/** Builds a maven repo out of a p2 repository. */
class MavenRepoBuilder implements AutoCloseable {
	final File root;
	final Multimap<Coordinate, Artifact> artifactMap = HashMultimap.create();

	MavenRepoBuilder(File root) throws Exception {
		this.root = Objects.requireNonNull(root);
	}

	/**
	 * Installs the given OSGi jar into the given group.
	 *
	 * Parses the name from Bundle-SymbolicName, the version
	 * from Bundle-Version, and the source for Eclipse-SourceBundle.
	 */
	public void install(String group, File osgiJar) throws Exception {
		String symbolicName;
		String version;
		boolean isSource;
		try (JarFile jarFile = new JarFile(osgiJar)) {
			if (jarFile.getManifest() != null) {
				Attributes attr = jarFile.getManifest().getMainAttributes();
				symbolicName = beforeSemicolon(attr.getValue("Bundle-SymbolicName"));
				version = attr.getValue("Bundle-Version");
				String source = attr.getValue("Eclipse-SourceBundle");
				if (source != null) {
					isSource = true;
					symbolicName = beforeSemicolon(source);
				} else {
					isSource = false;
				}
			} else {
				String name = osgiJar.getName();
				int lastUnderscore = name.lastIndexOf("_");
				symbolicName = name.substring(0, lastUnderscore);
				version = name.substring(lastUnderscore + 1);
				isSource = false;
				System.err.println(osgiJar.getAbsolutePath() + " has no manifest.  Guessing name=" + symbolicName + " and version=" + version);
			}
		} catch (Exception e) {
			System.err.println("Error parsing manifest of " + osgiJar.getAbsolutePath() + ", unable to put this jar into maven.");<commit_msg>Fixed FindBugs warning re: unwise exception handling.<commit_after>/*
 * Copyright 2016 DiffPlug
 *
 * 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.diffplug.gradle.p2;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.stream.Collectors;

import org.osgi.framework.Version;

import groovy.util.Node;
import groovy.xml.XmlUtil;

import com.diffplug.common.collect.HashMultimap;
import com.diffplug.common.collect.Multimap;
import com.diffplug.gradle.FileMisc;

/** Builds a maven repo out of a p2 repository. */
class MavenRepoBuilder implements AutoCloseable {
	final File root;
	final Multimap<Coordinate, Artifact> artifactMap = HashMultimap.create();

	MavenRepoBuilder(File root) throws Exception {
		this.root = Objects.requireNonNull(root);
	}

	/**
	 * Installs the given OSGi jar into the given group.
	 *
	 * Parses the name from Bundle-SymbolicName, the version
	 * from Bundle-Version, and the source for Eclipse-SourceBundle.
	 */
	public void install(String group, File osgiJar) throws Exception {
		String symbolicName;
		String version;
		boolean isSource;
		try (JarFile jarFile = new JarFile(osgiJar)) {
			if (jarFile.getManifest() != null) {
				Attributes attr = jarFile.getManifest().getMainAttributes();
				symbolicName = beforeSemicolon(attr.getValue("Bundle-SymbolicName"));
				version = attr.getValue("Bundle-Version");
				String source = attr.getValue("Eclipse-SourceBundle");
				if (source != null) {
					isSource = true;
					symbolicName = beforeSemicolon(source);
				} else {
					isSource = false;
				}
			} else {
				String name = osgiJar.getName();
				int lastUnderscore = name.lastIndexOf("_");
				symbolicName = name.substring(0, lastUnderscore);
				version = name.substring(lastUnderscore + 1);
				isSource = false;
				System.err.println(osgiJar.getAbsolutePath() + " has no manifest.  Guessing name=" + symbolicName + " and version=" + version);
			}
		} catch (RuntimeException e) {
			System.err.println("Error parsing manifest of " + osgiJar.getAbsolutePath() + ", unable to put this jar into maven.");
{'fraction_non_alphanumeric': 0.1038961038961039, 'fraction_numerical': 0.004269702899839886, 'mean_word_length': 4.138939670932358, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1561662', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1661, 'n_words': 505}