ch.sourcepond.maven.plugin.repobuilder.TargetPathFactory.java Source code

Java tutorial

Introduction

Here is the source code for ch.sourcepond.maven.plugin.repobuilder.TargetPathFactory.java

Source

/*Copyright (C) 2015 Roland Hauser, <sourcepond@gmail.com>
    
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 org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.split;

import java.io.IOException;
import java.nio.file.Path;

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

import org.apache.maven.artifact.Artifact;

/**
 * OEA Startseiten welche Lnder haben
 * 
 * 
 * @author rolandhauser
 *
 */
@Named
@Singleton
class TargetPathFactory {

    /**
     * @param pRepository
     * @param pGroupId
     * @return
     * @throws IOException
     */
    private Path createGroupFolders(final Path pRepository, final String pGroupId) {
        Path current = pRepository;
        for (final String token : split(pGroupId, '.')) {
            current = current.resolve(token);
        }
        return current;
    }

    /**
     * @param pArtifact
     * @return
     */
    private String toArtifactFileName(final Artifact pArtifact) {
        final StringBuilder b = new StringBuilder(pArtifact.getArtifactId()).append("-")
                .append(pArtifact.getBaseVersion());
        if (!isBlank(pArtifact.getClassifier())) {
            b.append("-").append(pArtifact.getClassifier());
        }

        return b.append(".").append(pArtifact.getArtifactHandler().getExtension()).toString();
    }

    /**
     * @param pRepository
     * @param pArtifact
     * @return
     */
    public Path createTargetPath(final Path pRepository, final Artifact pArtifact) {
        return createGroupFolders(pRepository, pArtifact.getGroupId()).resolve(pArtifact.getArtifactId())
                .resolve(pArtifact.getBaseVersion()).resolve(toArtifactFileName(pArtifact));
    }
}