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

com.github.htfv.maven.plugins.testing.ProjectWorkspaceReader Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2012 htfv (Aliaksei Lahachou)
 *
 * 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.github.htfv.maven.plugins.testing;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.repository.WorkspaceReader;
import org.sonatype.aether.repository.WorkspaceRepository;

/**
 * Implements workspace reader, which returns output directory for the artifact
 * identifying our project. This allows testing Maven plugins without installing
 * them to the repository.
 *
 * @author htfv (Aliaksei Lahachou)
 */
public class ProjectWorkspaceReader implements WorkspaceReader
{
    private ProjectProperties projectProperties = ProjectProperties.getInstance();
    private WorkspaceRepository workspaceRepository = new WorkspaceRepository();

    @Override
    public File findArtifact(final Artifact artifact)
    {
        if (isProjectArtifact(artifact))
        {
            return projectProperties.getOutputDirectory();
        }

        return null;
    }

    @Override
    public List findVersions(final Artifact artifact)
    {
        if (isProjectArtifact(artifact))
        {
            return Arrays.asList(projectProperties.getVersion());
        }

        return Collections.emptyList();
    }

    @Override
    public WorkspaceRepository getRepository()
    {
        return workspaceRepository;
    }

    private boolean isProjectArtifact(final Artifact artifact)
    {
        return projectProperties.getGroupId().equals(artifact.getGroupId())
                && projectProperties.getArtifactId().equals(artifact.getArtifactId());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy