blob: 4d1638a3e4b734573f95fece52012eb6f595cbd3 [file] [log] [blame]
Stuart McCullochb657c2f2008-01-25 08:10:25 +00001/*
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 */
19package org.apache.felix.obr.plugin;
20
21
22import java.io.File;
Stuart McCulloch473e9942008-01-28 05:23:50 +000023import java.net.URI;
Stuart McCullochb657c2f2008-01-25 08:10:25 +000024
25import org.apache.maven.artifact.repository.ArtifactRepository;
26import org.apache.maven.plugin.AbstractMojo;
27import org.apache.maven.plugin.MojoExecutionException;
28import org.apache.maven.plugin.MojoFailureException;
29import org.apache.maven.project.MavenProject;
30import org.apache.maven.settings.Settings;
31
32
33/**
34 * construct the repository.xml from a compiled bundle.
35 * @description construct the repository.xml from a compiled bundle.
36 * @goal install-file
37 * @requiresProject false
38 * @phase install
39 * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
40 */
41public class ObrInstallFile extends AbstractMojo
42{
43 /**
44 * The local Maven repository.
45 *
46 * @parameter expression="${localRepository}"
47 * @required
48 */
49 private ArtifactRepository m_localRepo;
50
51 /**
52 * path to the repository.xml.
53 *
54 * @parameter expression="${repository-path}"
55 * @require
56 */
57 private String m_repositoryPath;
58
59 /**
60 * setting of maven.
61 *
62 * @parameter expression="${settings}"
63 * @require
64 */
65 private Settings m_settings;
66
67 /**
68 * Artifact Id.
69 * @description symbolic name define by the user
70 * @parameter expression="${artifactId}"
71 */
72 private String m_artifactId;
73
74 /**
75 * Group Id.
76 * @description groupId define by the user
77 * @parameter expression="${groupId}"
78 */
79 private String m_groupId;
80
81 /**
82 * Version.
83 * @description version define by the user
84 * @parameter expression="${version}"
85 */
86 private String m_version;
87
88 /**
89 * Packaging.
90 * @description packaging define by the user
91 * @parameter expression="${packaging}"
92 */
93 private String m_packaging;
94
95 /**
96 * OBR File.
97 * @description obr file define by the user
98 * @parameter expression="${obr-file}"
99 */
100 private String m_obrFile;
101
102 /**
103 * store user information in a project.
104 */
105 private MavenProject m_project;
106
107
108 /**
109 * main method for this goal.
110 * @implements org.apache.maven.plugin.Mojo.execute
111 * @throws MojoExecutionException if the plugin failed
112 * @throws MojoFailureException if the plugin failed
113 */
114 public void execute() throws MojoExecutionException, MojoFailureException
115 {
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000116 m_project = new MavenProject();
117 m_project.setArtifactId( m_artifactId );
118 m_project.setGroupId( m_groupId );
119 m_project.setVersion( m_version );
120 m_project.setPackaging( m_packaging );
121
122 PathFile fileOut;
123
124 if ( m_groupId == null )
125 {
126 getLog().error( "-DgroupId=VALUE is required" );
127 return;
128 }
129 if ( m_artifactId == null )
130 {
131 getLog().error( "-Dartifactid=VALUE is required" );
132 return;
133 }
134 if ( m_version == null )
135 {
136 getLog().error( "-Dversion=VALUE is required" );
137 return;
138 }
139 if ( m_packaging == null )
140 {
141 getLog().error( "-Dpackaging=VALUE is required" );
142 return;
143 }
144
145 // copy the file to the local repository
146 PathFile repoLocal = new PathFile( m_localRepo.getBasedir() );
147
148 // get the target file in mvn repo
149 fileOut = new PathFile( PathFile.uniformSeparator( m_settings.getLocalRepository() ) + File.separator
150 + m_groupId.replace( '.', File.separatorChar ) + File.separator + m_artifactId + File.separator + m_version
151 + File.separator + m_artifactId + "-" + m_version + "." + m_packaging );
152
153 if ( !fileOut.isExists() )
154 {
155 getLog().error( "file doesn't exist: " + fileOut.getAbsoluteFilename() );
156 return;
157 }
158 else
159 {
160 getLog().info( "Target file: " + fileOut.getAbsoluteFilename() );
161 }
162
163 if ( m_repositoryPath == null )
164 {
165 m_repositoryPath = "file:" + repoLocal.getOnlyAbsoluteFilename() + "repository.xml";
Stuart McCulloch473e9942008-01-28 05:23:50 +0000166 getLog().info( "-Drepository-path is not set, using default repository: " + m_repositoryPath );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000167 }
168
169 PathFile fileRepo = new PathFile( m_repositoryPath );
170 if ( fileRepo.isRelative() )
171 {
172 fileRepo.setBaseDir( m_settings.getLocalRepository() );
173 }
174
175 // create the folder to the repository
176 PathFile repoExist = new PathFile( fileRepo.getAbsolutePath() );
177 if ( !repoExist.isExists() )
178 {
179 fileRepo.createPath();
180 }
181
Stuart McCulloch473e9942008-01-28 05:23:50 +0000182 URI obrXml = ObrUtils.toFileURI( m_obrFile );
183 if ( null == obrXml )
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000184 {
Stuart McCulloch473e9942008-01-28 05:23:50 +0000185 getLog().info( "obr.xml is not present, use default" );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000186 }
187
188 // build the user config
189 Config userConfig = new Config();
190
Stuart McCulloch473e9942008-01-28 05:23:50 +0000191 ObrUpdate obrUpdate = new ObrUpdate( fileRepo, obrXml, m_project, fileOut.getOnlyAbsoluteFilename(),
192 m_localRepo.getBasedir(), userConfig, getLog() );
Stuart McCullochb657c2f2008-01-25 08:10:25 +0000193 obrUpdate.updateRepository();
194
195 }
196
197}