| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MavenOneRepositoryDeployMojo |
|
| 8.0;8 |
| 1 | package org.apache.maven.plugins.mavenone; | |
| 2 | ||
| 3 | /* | |
| 4 | * Licensed to the Apache Software Foundation (ASF) under one | |
| 5 | * or more contributor license agreements. See the NOTICE file | |
| 6 | * distributed with this work for additional information | |
| 7 | * regarding copyright ownership. The ASF licenses this file | |
| 8 | * to you under the Apache License, Version 2.0 (the | |
| 9 | * "License"); you may not use this file except in compliance | |
| 10 | * with the License. You may obtain a copy of the License at | |
| 11 | * | |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 13 | * | |
| 14 | * Unless required by applicable law or agreed to in writing, | |
| 15 | * software distributed under the License is distributed on an | |
| 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 17 | * KIND, either express or implied. See the License for the | |
| 18 | * specific language governing permissions and limitations | |
| 19 | * under the License. | |
| 20 | */ | |
| 21 | ||
| 22 | import java.io.File; | |
| 23 | import java.util.Iterator; | |
| 24 | import java.util.List; | |
| 25 | ||
| 26 | import org.apache.maven.artifact.Artifact; | |
| 27 | import org.apache.maven.artifact.deployer.ArtifactDeployer; | |
| 28 | import org.apache.maven.artifact.deployer.ArtifactDeploymentException; | |
| 29 | import org.apache.maven.artifact.repository.ArtifactRepository; | |
| 30 | import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | |
| 31 | import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |
| 32 | import org.apache.maven.plugin.AbstractMojo; | |
| 33 | import org.apache.maven.plugin.MojoExecutionException; | |
| 34 | ||
| 35 | /** | |
| 36 | * Deploy the artifact in a Maven 1 remote repository. | |
| 37 | * | |
| 38 | * @goal deploy-maven-one-repository | |
| 39 | * @phase deploy | |
| 40 | */ | |
| 41 | 0 | public class MavenOneRepositoryDeployMojo |
| 42 | extends AbstractMojo | |
| 43 | { | |
| 44 | /** | |
| 45 | * @parameter expression="${project.packaging}" | |
| 46 | * @required | |
| 47 | * @readonly | |
| 48 | */ | |
| 49 | protected String packaging; | |
| 50 | ||
| 51 | /** | |
| 52 | * @parameter expression="${project.file}" | |
| 53 | * @required | |
| 54 | * @readonly | |
| 55 | */ | |
| 56 | private File pomFile; | |
| 57 | ||
| 58 | /** | |
| 59 | * @parameter expression="${project.artifact}" | |
| 60 | * @required | |
| 61 | * @readonly | |
| 62 | */ | |
| 63 | private Artifact artifact; | |
| 64 | ||
| 65 | /** | |
| 66 | * @component | |
| 67 | * @todo Write Javadoc for this | |
| 68 | */ | |
| 69 | protected ArtifactDeployer deployer; | |
| 70 | ||
| 71 | /** | |
| 72 | * @component | |
| 73 | * @todo Write Javadoc for this | |
| 74 | */ | |
| 75 | protected ArtifactRepositoryFactory factory; | |
| 76 | ||
| 77 | /** | |
| 78 | * The id to use in <code>settings.xml</code> if you want to configure server settings there. | |
| 79 | * | |
| 80 | * @parameter expression="${remoteRepositoryId}" default-value="mavenOneRemoteRepository" | |
| 81 | * @required | |
| 82 | */ | |
| 83 | protected String remoteRepositoryId; | |
| 84 | ||
| 85 | /** | |
| 86 | * The URL to the remote repository. | |
| 87 | * | |
| 88 | * @parameter expression="${remoteRepositoryUrl}" | |
| 89 | * @required | |
| 90 | */ | |
| 91 | protected String remoteRepositoryUrl; | |
| 92 | ||
| 93 | /** | |
| 94 | * Whether the remote repository uses a legacy layout or not. | |
| 95 | * | |
| 96 | * @component roleHint="legacy" | |
| 97 | */ | |
| 98 | private ArtifactRepositoryLayout legacyLayout; | |
| 99 | ||
| 100 | /** | |
| 101 | * @parameter expression="${localRepository}" | |
| 102 | * @required | |
| 103 | * @readonly | |
| 104 | */ | |
| 105 | private ArtifactRepository localRepository; | |
| 106 | ||
| 107 | /** | |
| 108 | * @parameter expression="${project.attachedArtifacts} | |
| 109 | * @required | |
| 110 | * @readonly | |
| 111 | */ | |
| 112 | private List attachedArtifacts; | |
| 113 | ||
| 114 | public void execute() | |
| 115 | throws MojoExecutionException | |
| 116 | { | |
| 117 | try | |
| 118 | { | |
| 119 | 0 | ArtifactRepository deploymentRepository = factory.createDeploymentArtifactRepository( remoteRepositoryId, |
| 120 | remoteRepositoryUrl, | |
| 121 | legacyLayout, false ); | |
| 122 | ||
| 123 | 0 | boolean isPomArtifact = "pom".equals( packaging ); |
| 124 | ||
| 125 | 0 | if ( isPomArtifact ) |
| 126 | { | |
| 127 | 0 | deployer.deploy( pomFile, artifact, deploymentRepository, localRepository ); |
| 128 | } | |
| 129 | else | |
| 130 | { | |
| 131 | 0 | File file = artifact.getFile(); |
| 132 | 0 | if ( file == null ) |
| 133 | { | |
| 134 | 0 | throw new MojoExecutionException( |
| 135 | "The packaging for this project did not assign a file to the build artifact" ); | |
| 136 | } | |
| 137 | 0 | deployer.deploy( file, artifact, deploymentRepository, localRepository ); |
| 138 | } | |
| 139 | ||
| 140 | 0 | if ( attachedArtifacts != null && !attachedArtifacts.isEmpty() ) |
| 141 | { | |
| 142 | 0 | for ( Iterator i = attachedArtifacts.iterator(); i.hasNext(); ) |
| 143 | { | |
| 144 | 0 | Artifact attached = (Artifact) i.next(); |
| 145 | ||
| 146 | 0 | deployer.deploy( attached.getFile(), attached, deploymentRepository, localRepository ); |
| 147 | } | |
| 148 | } | |
| 149 | } | |
| 150 | 0 | catch ( ArtifactDeploymentException e ) |
| 151 | { | |
| 152 | 0 | throw new MojoExecutionException( e.getMessage(), e ); |
| 153 | 0 | } |
| 154 | 0 | } |
| 155 | } |