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

ch.sourcepond.maven.plugin.repobuilder.RepositorySwitch 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 java.nio.file.Path;

import org.apache.maven.artifact.Artifact;

/**
 * This component decides, where a Maven repository structure shall be created.
 * See {@link #getRepository(Artifact)} for further information.
 *
 */
class RepositorySwitch {
	private final Path root;
	private final String snapshotRepositoryOrNull;
	private final String releaseRepositoryOrNull;

	/**
	 * Creates a new instance of this class.
	 * 
	 * @param pRoot
	 *            Root directory which will contain sub-repositories or maven
	 *            structures (depending on the configuration set on the Mojo);
	 *            must not be {@code null}.
	 * @param pSnapshotRepositoryOrNull
	 *            Name of the sub-repository for snapshot artifacts or
	 *            {@code null}.
	 * @param pReleaseRepositoryOrNull
	 *            Name of the sub-repository for release artifacts or
	 *            {@code null}.
	 */
	RepositorySwitch(final Path pRoot, final String pSnapshotRepositoryOrNull, final String pReleaseRepositoryOrNull) {
		root = pRoot;
		snapshotRepositoryOrNull = pSnapshotRepositoryOrNull;
		releaseRepositoryOrNull = pReleaseRepositoryOrNull;
	}

	/**
	 * Determines the path where to create a Maven repository structure for the
	 * artifact specified (see Repository Layout - Final, section "The new layout").
	 * 
	 * @param pArtifact
	 *            Artifact for which to create a repository layout, must not be
	 *            {@code null}
	 * @return Directory where to create the repository layout, never
	 *         {@code null}
	 */
	public Path getRepository(final Artifact pArtifact) {
		final Path repository;
		if (snapshotRepositoryOrNull != null && pArtifact.isSnapshot()) {
			repository = root.resolve(snapshotRepositoryOrNull);
		} else if (releaseRepositoryOrNull != null && !pArtifact.isSnapshot()) {
			repository = root.resolve(releaseRepositoryOrNull);
		} else {
			repository = root;
		}
		return repository;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy