Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Stuart McCulloch | bdb8168 | 2007-12-16 09:46:19 +0000 | [diff] [blame] | 19 | package org.apache.felix.obr.plugin; |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 20 | |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 21 | |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 22 | import java.io.File; |
Stuart McCulloch | 473e994 | 2008-01-28 05:23:50 +0000 | [diff] [blame^] | 23 | import java.net.URI; |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 24 | |
| 25 | import org.apache.maven.artifact.repository.ArtifactRepository; |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 26 | import org.apache.maven.plugin.AbstractMojo; |
| 27 | import org.apache.maven.plugin.MojoExecutionException; |
| 28 | import org.apache.maven.project.MavenProject; |
| 29 | import org.apache.maven.settings.Settings; |
| 30 | |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 31 | |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 32 | /** |
| 33 | * construct the repository.xml with a project Maven compiled |
| 34 | * |
| 35 | * @goal repository |
| 36 | * @phase install |
| 37 | * @requiresDependencyResolution compile |
| 38 | * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a> |
| 39 | */ |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 40 | public class ObrInstall extends AbstractMojo |
| 41 | { |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 42 | /** |
| 43 | * The local Maven repository. |
| 44 | * |
| 45 | * @parameter expression="${localRepository}" |
| 46 | * @required |
| 47 | */ |
| 48 | private ArtifactRepository m_localRepo; |
| 49 | |
| 50 | /** |
| 51 | * path to the repository.xml. |
| 52 | * |
| 53 | * @parameter expression="${repository-path}" |
| 54 | * @require |
| 55 | */ |
| 56 | private String m_repositoryPath; |
| 57 | |
| 58 | /** |
| 59 | * Project in use. |
| 60 | * |
| 61 | * @parameter expression="${project}" |
| 62 | * @require |
| 63 | */ |
| 64 | |
| 65 | private MavenProject m_project; |
| 66 | |
| 67 | /** |
| 68 | * setting of maven. |
| 69 | * |
| 70 | * @parameter expression="${settings}" |
| 71 | * @require |
| 72 | */ |
| 73 | |
| 74 | private Settings m_settings; |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 75 | |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 76 | /** |
| 77 | * Enable/Disable this goal |
| 78 | * @description If true evrything the goal do nothing, the goal just skip over |
| 79 | * @parameter expression="${maven.obr.installToLocalOBR}" default-value="true" |
| 80 | */ |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 81 | private boolean installToLocalOBR; |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * path to file in the maven local repository. |
| 85 | */ |
| 86 | private String m_fileInLocalRepo; |
| 87 | |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 88 | |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 89 | /** |
| 90 | * main method for this goal. |
| 91 | * @implements org.apache.maven.plugin.Mojo.execute |
| 92 | * @throws MojoExecutionException if the plugin failed |
| 93 | */ |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 94 | public void execute() throws MojoExecutionException |
| 95 | { |
| 96 | getLog().info( "Obr Plugin starts:" ); |
| 97 | if ( !installToLocalOBR ) |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 98 | { |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 99 | getLog().info( "maven-obr-plugin:repository goal is disable due to one of the following reason:" ); |
| 100 | getLog().info( " - 'installToLocalOBR' configuration set to false" ); |
| 101 | getLog().info( " - JVM property maven.obr.installToLocalOBR set to false" ); |
| 102 | return; |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 105 | if ( m_repositoryPath == null ) |
| 106 | { |
| 107 | m_repositoryPath = "file:/" + m_localRepo.getBasedir() + File.separator + "repository.xml"; |
Stuart McCulloch | 473e994 | 2008-01-28 05:23:50 +0000 | [diff] [blame^] | 108 | getLog().info( "-Drepository-path is not set, using default repository: " + m_repositoryPath ); |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | PathFile file = new PathFile( m_repositoryPath ); |
| 112 | if ( file.isExists() ) |
| 113 | { |
| 114 | if ( !m_repositoryPath.startsWith( "file:/" ) ) |
| 115 | { |
| 116 | m_repositoryPath = "file:/" + m_repositoryPath; |
| 117 | } |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | // locate the obr.xml file |
Stuart McCulloch | 473e994 | 2008-01-28 05:23:50 +0000 | [diff] [blame^] | 121 | URI obrXml = ObrUtils.findObrXml( m_project.getResources() ); |
| 122 | |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 123 | // the obr.xml file is not present |
Stuart McCulloch | 473e994 | 2008-01-28 05:23:50 +0000 | [diff] [blame^] | 124 | if ( null == obrXml ) |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 125 | { |
Stuart McCulloch | 473e994 | 2008-01-28 05:23:50 +0000 | [diff] [blame^] | 126 | getLog().info( "obr.xml is not present, use default" ); |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | // get the path to local maven repository |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 130 | file = new PathFile( PathFile.uniformSeparator( m_settings.getLocalRepository() ) + File.separator |
| 131 | + PathFile.uniformSeparator( m_localRepo.pathOf( m_project.getArtifact() ) ) ); |
| 132 | |
| 133 | if ( file.isExists() ) |
| 134 | { |
| 135 | m_fileInLocalRepo = file.getOnlyAbsoluteFilename(); |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | getLog().error( |
| 140 | "file not found in local repository: " + m_settings.getLocalRepository() + File.separator |
| 141 | + m_localRepo.pathOf( m_project.getArtifact() ) ); |
| 142 | getLog().error( |
| 143 | "file not found in local repository: " + m_localRepo.getBasedir() + File.separator |
| 144 | + m_localRepo.pathOf( m_project.getArtifact() ) ); |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 145 | return; |
| 146 | } |
| 147 | |
| 148 | // verify the repository.xml |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 149 | PathFile fileRepo = new PathFile( m_repositoryPath ); |
| 150 | if ( fileRepo.isRelative() ) |
| 151 | { |
| 152 | fileRepo.setBaseDir( m_settings.getLocalRepository() ); |
| 153 | } |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 154 | |
| 155 | // create the folder to the repository |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 156 | PathFile repoExist = new PathFile( fileRepo.getAbsolutePath() ); |
| 157 | if ( !repoExist.isExists() ) |
| 158 | { |
| 159 | fileRepo.createPath(); |
| 160 | } |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 161 | |
| 162 | // build the user configuration (use default) |
| 163 | Config user = new Config(); |
| 164 | |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 165 | getLog().debug( "Maven2 Local File repository = " + fileRepo.getAbsoluteFilename() ); |
Stuart McCulloch | 473e994 | 2008-01-28 05:23:50 +0000 | [diff] [blame^] | 166 | getLog().debug( "OBR repository = " + obrXml ); |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 167 | |
Stuart McCulloch | 473e994 | 2008-01-28 05:23:50 +0000 | [diff] [blame^] | 168 | ObrUpdate obrUpdate = new ObrUpdate( fileRepo, obrXml, m_project, m_fileInLocalRepo, PathFile |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 169 | .uniformSeparator( m_settings.getLocalRepository() ), user, getLog() ); |
| 170 | try |
| 171 | { |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 172 | obrUpdate.updateRepository(); |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 173 | } |
| 174 | catch ( MojoExecutionException e ) |
| 175 | { |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 176 | e.printStackTrace(); |
Stuart McCulloch | 7a49c28 | 2008-01-25 08:08:15 +0000 | [diff] [blame] | 177 | throw new MojoExecutionException( "MojoFailureException" ); |
Stefano Lenzi | 476013d | 2007-09-21 23:59:54 +0000 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
| 181 | } |