All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bndtools.VersionControlIgnoresManagerTracker Maven / Gradle / Ivy

The newest version!
package bndtools;

import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;

import org.bndtools.api.NamedPlugin;
import org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;

public class VersionControlIgnoresManagerTracker extends
	ServiceTracker implements VersionControlIgnoresManager {
	private final AtomicReference>	managerReference	= new AtomicReference<>();
	private final AtomicReference						manager				= new AtomicReference<>();

	public VersionControlIgnoresManagerTracker(BundleContext context) {
		super(context, VersionControlIgnoresManager.class, null);
	}

	/*
	 * ServiceTracker
	 */

	@Override
	public VersionControlIgnoresManager addingService(ServiceReference reference) {
		VersionControlIgnoresManager manager = super.addingService(reference);
		this.managerReference.set(reference);
		this.manager.set(manager);
		return manager;
	}

	@Override
	public void remove(ServiceReference reference) {
		if (managerReference.compareAndSet(reference, null)) {
			manager.set(null);
		}

		super.remove(reference);
	}

	@Override
	public void close() {
		manager.set(null);
		managerReference.set(null);
		super.close();
	}

	/*
	 * VersionControlIgnoresManager
	 */

	@Override
	public String sanitiseGitIgnoreGlob(boolean rooted, String ignoreGlob, boolean directory) {
		VersionControlIgnoresManager manager = this.manager.get();
		if (manager == null) {
			return ignoreGlob;
		}

		return manager.sanitiseGitIgnoreGlob(rooted, ignoreGlob, directory);
	}

	@Override
	public void addIgnores(Set plugins, File dstDir, String ignores) {
		VersionControlIgnoresManager manager = this.manager.get();
		if (manager == null) {
			return;
		}

		manager.addIgnores(plugins, dstDir, ignores);
	}

	@Override
	public void addIgnores(Set plugins, File dstDir, List ignores) {
		VersionControlIgnoresManager manager = this.manager.get();
		if (manager == null) {
			return;
		}

		manager.addIgnores(plugins, dstDir, ignores);
	}

	@Override
	public Set getPluginsForProjectRepositoryProviderId(String repositoryProviderId) {
		VersionControlIgnoresManager manager = this.manager.get();
		if (manager == null) {
			return null;
		}

		return manager.getPluginsForProjectRepositoryProviderId(repositoryProviderId);
	}

	@Override
	public Collection getAllPluginsInformation() {
		VersionControlIgnoresManager manager = this.manager.get();
		if (manager == null) {
			return Collections.emptySet();
		}

		return manager.getAllPluginsInformation();
	}

	@Override
	public void createProjectIgnores(Set plugins, File projectDir, Map sourceOutputLocations,
		String targetDir) {
		VersionControlIgnoresManager manager = this.manager.get();
		if (manager == null) {
			return;
		}

		manager.createProjectIgnores(plugins, projectDir, sourceOutputLocations, targetDir);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy