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

ch.sourcepond.maven.plugin.repobuilder.RootDirectoryFactory Maven / Gradle / Ivy

The newest version!
/*Copyright (C) 2015 Roland Hauser, 

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 ch.sourcepond.maven.plugin.repobuilder;

import static java.util.Arrays.asList;
import static org.apache.commons.lang3.StringUtils.isBlank;

import java.io.File;
import java.util.Collection;

import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;

import net.java.truevfs.access.TFile;

/**
 * @author rolandhauser
 *
 */
@Named
@Singleton
class RootDirectoryFactory {
	static final Collection TYPES = asList("zip", "tar", "tar.gz", "tar.bzip");

	/**
	 * @param archiveType
	 * @return
	 * @throws MojoExecutionException
	 */
	private String validatedArchiveType(final String archiveType) throws MojoExecutionException {
		if (!TYPES.contains(archiveType)) {
			throw new MojoExecutionException("Unsupported archive type " + archiveType);
		}
		return archiveType;
	}

	/**
	 * @param pUserSetting
	 * @return
	 * @throws MojoExecutionException
	 */
	public RootDirectory createRoot(final Log pLog, final File pOutputDirectory, final String pArchiveTypeOrNull)
			throws MojoExecutionException {
		final RootDirectory directory;
		// If no archive type is set, we do not create an archive but simply a
		// repository folder.
		if (isBlank(pArchiveTypeOrNull)) {
			directory = new RootDirectory(pLog, pOutputDirectory.toPath());
		} else {
			// Create virtual file-system to create repository archive
			directory = new RootDirectory(pLog,
					new TFile(pOutputDirectory.getAbsolutePath() + "." + validatedArchiveType(pArchiveTypeOrNull))
							.toPath());
		}
		return directory;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy