| 1 |
/* |
| 2 |
* Copyright 2009 Ludovic Claude. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package org.debian.maven.packager; |
| 18 |
|
| 19 |
import java.io.File; |
| 20 |
import java.util.ArrayList; |
| 21 |
import java.util.List; |
| 22 |
|
| 23 |
import org.apache.maven.plugin.AbstractMojo; |
| 24 |
import org.apache.maven.plugin.MojoExecutionException; |
| 25 |
import org.apache.maven.plugins.annotations.Component; |
| 26 |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
| 27 |
import org.apache.maven.plugins.annotations.Mojo; |
| 28 |
import org.apache.maven.plugins.annotations.Parameter; |
| 29 |
import org.apache.maven.plugins.annotations.ResolutionScope; |
| 30 |
import org.apache.maven.project.MavenProject; |
| 31 |
import org.debian.maven.packager.util.PackageScanner; |
| 32 |
import org.debian.maven.repo.DependencyRuleSetFiles.RulesType; |
| 33 |
|
| 34 |
/** |
| 35 |
* Analyze the Maven dependencies and extract the list of dependent packages, |
| 36 |
* reusable as subvars in the Debian control file and the list of POM files |
| 37 |
* to use and the rules if they did not exist already. |
| 38 |
* |
| 39 |
* @author Ludovic Claude |
| 40 |
*/ |
| 41 |
@Mojo(name = "dependencies", defaultPhase = LifecyclePhase.PROCESS_SOURCES, aggregator = true, requiresDependencyResolution = ResolutionScope.RUNTIME) |
| 42 |
public class DependenciesMojo extends AbstractMojo { |
| 43 |
|
| 44 |
/** |
| 45 |
* The Maven Project Object |
| 46 |
*/ |
| 47 |
@Parameter(defaultValue = "${project}", readonly = true, required = true) |
| 48 |
protected MavenProject project; |
| 49 |
|
| 50 |
/** |
| 51 |
* A list of every project in this reactor; provided by Maven |
| 52 |
*/ |
| 53 |
@Parameter(defaultValue = "${project.collectedProjects}") |
| 54 |
protected List<MavenProject> collectedProjects; |
| 55 |
|
| 56 |
/** |
| 57 |
* Location of the file. |
| 58 |
*/ |
| 59 |
@Parameter(property = "debian.directory", defaultValue = "debian") |
| 60 |
protected File outputDirectory; |
| 61 |
|
| 62 |
/** |
| 63 |
* Name of the package (e.g. 'commons-lang') |
| 64 |
*/ |
| 65 |
@Parameter(property = "package", required = true) |
| 66 |
protected String packageName; |
| 67 |
|
| 68 |
/** |
| 69 |
* Should we also resolve Javadoc dependencies |
| 70 |
*/ |
| 71 |
@Parameter(property = "resolveJavadoc", defaultValue = "false") |
| 72 |
protected boolean resolveJavadoc; |
| 73 |
|
| 74 |
/** |
| 75 |
* Location for the list of POMs file. |
| 76 |
*/ |
| 77 |
@Parameter(defaultValue = "debian/${package}.poms", required = true) |
| 78 |
protected File listOfPoms; |
| 79 |
|
| 80 |
/** |
| 81 |
* Location of the Maven repository |
| 82 |
*/ |
| 83 |
@Parameter(property = "maven.repo.local", defaultValue = "/usr/share/maven-repo") |
| 84 |
protected File mavenRepo; |
| 85 |
|
| 86 |
/** |
| 87 |
* Interactive execution will ask questions to the user |
| 88 |
*/ |
| 89 |
@Parameter(property = "interactive", defaultValue = "true") |
| 90 |
protected boolean interactive; |
| 91 |
|
| 92 |
/** |
| 93 |
* Offline prevents any download from Internet |
| 94 |
*/ |
| 95 |
@Parameter(property = "offline", defaultValue = "false") |
| 96 |
protected boolean offline; |
| 97 |
|
| 98 |
/** |
| 99 |
* Try to be verbose |
| 100 |
*/ |
| 101 |
@Parameter(property = "verbose", defaultValue = "false") |
| 102 |
protected boolean verbose; |
| 103 |
|
| 104 |
public void execute() throws MojoExecutionException { |
| 105 |
if (!outputDirectory.exists()) { |
| 106 |
outputDirectory.mkdirs(); |
| 107 |
} |
| 108 |
|
| 109 |
DependenciesSolver solver = new DependenciesSolver(outputDirectory, new PackageScanner(offline), interactive); |
| 110 |
|
| 111 |
File basedir = project.getBasedir(); |
| 112 |
// TODO: use the list of project defined here for some initialisation step, I've forgotten what to do... |
| 113 |
List<File> projects = new ArrayList<File>(); |
| 114 |
projects.add(project.getFile()); |
| 115 |
if (collectedProjects != null) { |
| 116 |
for (MavenProject subProject : collectedProjects) { |
| 117 |
projects.add(subProject.getFile()); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
solver.setBaseDir(basedir); |
| 122 |
solver.mavenRepo = mavenRepo; |
| 123 |
solver.packageName = packageName; |
| 124 |
solver.generateJavadoc = resolveJavadoc; |
| 125 |
solver.setListOfPoms(listOfPoms); |
| 126 |
solver.verbose = verbose; |
| 127 |
|
| 128 |
if (solver.pomTransformer.getListOfPOMs().getFirstPOM() == null && collectedProjects != null) { |
| 129 |
for (MavenProject subProject : collectedProjects) { |
| 130 |
solver.pomTransformer.getListOfPOMs().addPOM(subProject.getFile()); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
solver.solveDependencies(); |
| 135 |
|
| 136 |
solver.pomTransformer.getListOfPOMs().save(); |
| 137 |
solver.pomTransformer.getRulesFiles().save(outputDirectory, RulesType.RULES); |
| 138 |
solver.saveSubstvars(); |
| 139 |
} |
| 140 |
|
| 141 |
} |