use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class AbstractFromConfigurationMojo method fillMissingArtifactVersion.
/**
* Tries to find missing version from dependency list and dependency management. If found, the artifact is updated
* with the correct version. It will first look for an exact match on artifactId/groupId/classifier/type and if it
* doesn't find a match, it will try again looking for artifactId and groupId only.
*
* @param artifact representing configured file.
* @throws MojoExecutionException
*/
private void fillMissingArtifactVersion(ArtifactItem artifact) throws MojoExecutionException {
MavenProject project = getProject();
List<Dependency> deps = project.getDependencies();
List<Dependency> depMngt = project.getDependencyManagement() == null ? Collections.<Dependency>emptyList() : project.getDependencyManagement().getDependencies();
if (!findDependencyVersion(artifact, deps, false) && (project.getDependencyManagement() == null || !findDependencyVersion(artifact, depMngt, false)) && !findDependencyVersion(artifact, deps, true) && (project.getDependencyManagement() == null || !findDependencyVersion(artifact, depMngt, true))) {
throw new MojoExecutionException("Unable to find artifact version of " + artifact.getGroupId() + ":" + artifact.getArtifactId() + " in either dependency list or in project's dependency management.");
}
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class CompilerMojoTestCase method getTestCompilerMojo.
private TestCompilerMojo getTestCompilerMojo(CompilerMojo compilerMojo, String pomXml) throws Exception {
File testPom = new File(getBasedir(), pomXml);
TestCompilerMojo mojo = (TestCompilerMojo) lookupMojo("testCompile", testPom);
setVariableValueToObject(mojo, "log", new DebugEnabledLog());
File buildDir = (File) getVariableValueFromObject(compilerMojo, "buildDirectory");
File testClassesDir = new File(buildDir, "test-classes");
setVariableValueToObject(mojo, "outputDirectory", testClassesDir);
List<String> testClasspathList = new ArrayList<String>();
Artifact junitArtifact = mock(Artifact.class);
ArtifactHandler handler = mock(ArtifactHandler.class);
when(handler.isAddedToClasspath()).thenReturn(true);
when(junitArtifact.getArtifactHandler()).thenReturn(handler);
File artifactFile;
String localRepository = System.getProperty("localRepository");
if (localRepository != null) {
artifactFile = new File(localRepository, "junit/junit/3.8.1/junit-3.8.1.jar");
} else {
// for IDE
String junitURI = org.junit.Test.class.getResource("Test.class").toURI().toString();
junitURI = junitURI.substring("jar:".length(), junitURI.indexOf('!'));
artifactFile = new File(URI.create(junitURI));
}
when(junitArtifact.getFile()).thenReturn(artifactFile);
testClasspathList.add(artifactFile.getAbsolutePath());
testClasspathList.add(compilerMojo.getOutputDirectory().getPath());
String testSourceRoot = testPom.getParent() + "/src/test/java";
setVariableValueToObject(mojo, "compileSourceRoots", Collections.singletonList(testSourceRoot));
MavenProject project = getMockMavenProject();
project.setArtifacts(Collections.singleton(junitArtifact));
project.getBuild().setOutputDirectory(new File(buildDir, "classes").getAbsolutePath());
setVariableValueToObject(mojo, "project", project);
setVariableValueToObject(mojo, "compilePath", Collections.EMPTY_LIST);
setVariableValueToObject(mojo, "testPath", testClasspathList);
setVariableValueToObject(mojo, "session", getMockMavenSession());
setVariableValueToObject(mojo, "mojoExecution", getMockMojoExecution());
setVariableValueToObject(mojo, "source", source);
setVariableValueToObject(mojo, "target", target);
return mojo;
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class AbstractGpgSigner method getPassphrase.
public String getPassphrase(MavenProject project) throws IOException {
String pass = null;
if (project != null) {
pass = project.getProperties().getProperty("gpg.passphrase");
if (pass == null) {
MavenProject prj2 = findReactorProject(project);
pass = prj2.getProperties().getProperty("gpg.passphrase");
}
}
if (pass == null) {
pass = readPassword("GPG Passphrase: ");
}
if (project != null) {
findReactorProject(project).getProperties().setProperty("gpg.passphrase", pass);
}
return pass;
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class AbstractJavadocMojo method getDependenciesLinks.
/**
* Using Maven, a Javadoc link is given by <code>${project.url}/apidocs</code>.
*
* @return the detected Javadoc links using the Maven conventions for all dependencies defined in the current
* project or an empty list.
* @see #detectLinks
* @see #isValidJavadocLink(String)
* @since 2.6
*/
private List<String> getDependenciesLinks() {
if (!detectLinks) {
return Collections.emptyList();
}
getLog().debug("Trying to add links for dependencies...");
List<String> dependenciesLinks = new ArrayList<String>();
final Set<Artifact> dependencies = project.getDependencyArtifacts();
for (Artifact artifact : dependencies) {
if (artifact.getFile() == null || !artifact.getFile().exists()) {
continue;
}
try {
MavenProject artifactProject = mavenProjectBuilder.build(artifact, session.getProjectBuildingRequest()).getProject();
if (StringUtils.isNotEmpty(artifactProject.getUrl())) {
String url = getJavadocLink(artifactProject);
if (isValidJavadocLink(url, true)) {
getLog().debug("Added Javadoc link: " + url + " for " + artifactProject.getId());
dependenciesLinks.add(url);
}
}
} catch (ProjectBuildingException e) {
logError("ProjectBuildingException for " + artifact.toString() + ": " + e.getMessage(), e);
}
}
return dependenciesLinks;
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class ResourceResolver method resolveDependencyJavadocBundles.
/**
* @param config {@link SourceResolverConfig}
* @return list of {@link JavadocBundle}.
* @throws IOException {@link IOException}
*/
public List<JavadocBundle> resolveDependencyJavadocBundles(final SourceResolverConfig config) throws IOException {
final List<JavadocBundle> bundles = new ArrayList<JavadocBundle>();
final Map<String, MavenProject> projectMap = new HashMap<String, MavenProject>();
if (config.reactorProjects() != null) {
for (final MavenProject p : config.reactorProjects()) {
projectMap.put(key(p.getGroupId(), p.getArtifactId()), p);
}
}
final List<Artifact> artifacts = config.project().getTestArtifacts();
final List<Artifact> forResourceResolution = new ArrayList<Artifact>(artifacts.size());
for (final Artifact artifact : artifacts) {
final String key = key(artifact.getGroupId(), artifact.getArtifactId());
final MavenProject p = projectMap.get(key);
if (p != null) {
bundles.addAll(resolveBundleFromProject(config, p, artifact));
} else {
forResourceResolution.add(artifact);
}
}
bundles.addAll(resolveBundlesFromArtifacts(config, forResourceResolution));
return bundles;
}
Aggregations