use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class AntBuildWriter method getUninterpolatedSystemPath.
private String getUninterpolatedSystemPath(Artifact artifact) {
String managementKey = artifact.getDependencyConflictId();
for (Dependency dependency : project.getOriginalModel().getDependencies()) {
if (managementKey.equals(dependency.getManagementKey())) {
return dependency.getSystemPath();
}
}
for (Profile profile : project.getOriginalModel().getProfiles()) {
for (Dependency dependency : profile.getDependencies()) {
if (managementKey.equals(dependency.getManagementKey())) {
return dependency.getSystemPath();
}
}
}
String path = artifact.getFile().getAbsolutePath();
Properties props = new Properties();
props.putAll(project.getProperties());
props.putAll(executionProperties);
props.remove("user.dir");
props.put("basedir", project.getBasedir().getAbsolutePath());
SortedMap<String, String> candidateProperties = new TreeMap<String, String>();
for (Object o : props.keySet()) {
String key = (String) o;
String value = new File(props.getProperty(key)).getPath();
if (path.startsWith(value) && value.length() > 0) {
candidateProperties.put(value, key);
}
}
if (!candidateProperties.isEmpty()) {
String value = candidateProperties.lastKey();
String key = candidateProperties.get(value);
path = path.substring(value.length());
path = path.replace('\\', '/');
return "${" + key + "}" + path;
}
return path;
}
use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class AbstractJavadocMojo method getResource.
/**
* @param outputFile not nul
* @param inputResourceName a not null resource in <code>src/main/java</code>, <code>src/main/resources</code> or
* <code>src/main/javadoc</code> or in the Javadoc plugin dependencies.
* @return the resource file absolute path as String
* @since 2.6
*/
private String getResource(File outputFile, String inputResourceName) {
if (inputResourceName.startsWith("/")) {
inputResourceName = inputResourceName.replaceFirst("//*", "");
}
List<String> classPath = new ArrayList<String>();
classPath.add(project.getBuild().getSourceDirectory());
URL resourceURL = getResource(classPath, inputResourceName);
if (resourceURL != null) {
getLog().debug(inputResourceName + " found in the main src directory of the project.");
return FileUtils.toFile(resourceURL).getAbsolutePath();
}
classPath.clear();
List<Resource> resources = project.getBuild().getResources();
for (Resource resource : resources) {
classPath.add(resource.getDirectory());
}
resourceURL = getResource(classPath, inputResourceName);
if (resourceURL != null) {
getLog().debug(inputResourceName + " found in the main resources directories of the project.");
return FileUtils.toFile(resourceURL).getAbsolutePath();
}
if (javadocDirectory.exists()) {
classPath.clear();
classPath.add(javadocDirectory.getAbsolutePath());
resourceURL = getResource(classPath, inputResourceName);
if (resourceURL != null) {
getLog().debug(inputResourceName + " found in the main javadoc directory of the project.");
return FileUtils.toFile(resourceURL).getAbsolutePath();
}
}
classPath.clear();
final String pluginId = "org.apache.maven.plugins:maven-javadoc-plugin";
Plugin javadocPlugin = getPlugin(project, pluginId);
if (javadocPlugin != null && javadocPlugin.getDependencies() != null) {
List<Dependency> dependencies = javadocPlugin.getDependencies();
for (Dependency dependency : dependencies) {
JavadocPathArtifact javadocPathArtifact = new JavadocPathArtifact();
javadocPathArtifact.setGroupId(dependency.getGroupId());
javadocPathArtifact.setArtifactId(dependency.getArtifactId());
javadocPathArtifact.setVersion(dependency.getVersion());
Artifact artifact = null;
try {
artifact = createAndResolveArtifact(javadocPathArtifact);
} catch (Exception e) {
logError("Unable to retrieve the dependency: " + dependency + ". Ignored.", e);
}
if (artifact != null && artifact.getFile().exists()) {
classPath.add(artifact.getFile().getAbsolutePath());
}
}
resourceURL = getResource(classPath, inputResourceName);
if (resourceURL != null) {
getLog().debug(inputResourceName + " found in javadoc plugin dependencies.");
try {
JavadocUtil.copyResource(resourceURL, outputFile);
return outputFile.getAbsolutePath();
} catch (IOException e) {
logError("IOException: " + e.getMessage(), e);
}
}
}
getLog().warn("Unable to find the resource '" + inputResourceName + "'. Using default Javadoc resources.");
return null;
}
use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class AbstractJavadocMojo method getClasspath.
/**
* Method that sets the classpath elements that will be specified in the javadoc <code>-classpath</code>
* parameter. Since we have all the sources of the current reactor, it is sufficient to consider the
* dependencies of the reactor modules, excluding the module artifacts which may not yet be available
* when the reactor project is built for the first time.
*
* @return a String that contains the concatenated classpath elements, separated by the System pathSeparator
* string (colon (<code>:</code>) on Solaris or semi-colon (<code>;</code>) on Windows).
* @throws MavenReportException if any.
* @see File#pathSeparator
*/
private String getClasspath() throws MavenReportException {
List<String> classpathElements = new ArrayList<String>();
Map<String, Artifact> compileArtifactMap = new HashMap<String, Artifact>();
if (isTest()) {
classpathElements.addAll(getProjectBuildOutputDirs(project));
}
populateCompileArtifactMap(compileArtifactMap, getProjectArtifacts(project));
if (isAggregator() && project.isExecutionRoot()) {
List<Artifact> reactorArtifacts = new ArrayList<Artifact>();
for (MavenProject p : reactorProjects) {
reactorArtifacts.add(p.getArtifact());
}
try {
for (MavenProject subProject : reactorProjects) {
if (subProject != project) {
classpathElements.addAll(getProjectBuildOutputDirs(subProject));
Set<Artifact> dependencyArtifacts = subProject.createArtifacts(factory, null, null);
// do not attempt to resolve artifacts of the current reactor which may not exist yet
dependencyArtifacts.removeAll(reactorArtifacts);
if (!dependencyArtifacts.isEmpty()) {
ArtifactResolutionResult result = null;
try {
result = resolver.resolveTransitively(dependencyArtifacts, subProject.getArtifact(), subProject.getManagedVersionMap(), localRepository, subProject.getRemoteArtifactRepositories(), artifactMetadataSource);
} catch (ArtifactNotFoundException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (ArtifactResolutionException e) {
throw new MavenReportException(e.getMessage(), e);
}
if (result == null) {
continue;
}
populateCompileArtifactMap(compileArtifactMap, getCompileArtifacts(result.getArtifacts()));
if (getLog().isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append("Compiled artifacts for ");
sb.append(subProject.getGroupId()).append(":");
sb.append(subProject.getArtifactId()).append(":");
sb.append(subProject.getVersion()).append('\n');
for (Artifact a : compileArtifactMap.values()) {
sb.append(a.getFile()).append('\n');
}
getLog().debug(sb.toString());
}
}
}
}
} catch (InvalidDependencyVersionException e) {
throw new MavenReportException(e.getMessage(), e);
}
}
for (Artifact a : compileArtifactMap.values()) {
classpathElements.add(a.getFile().toString());
}
if (additionalDependencies != null) {
for (Dependency dependency : additionalDependencies) {
Artifact artifact = resolveDependency(dependency);
String path = artifact.getFile().toString();
getLog().debug("add additional artifact with path " + path);
classpathElements.add(path);
}
}
return StringUtils.join(classpathElements.iterator(), File.pathSeparator);
}
use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class SubProject1Stub method getDependencies.
@Override
public List<Dependency> getDependencies() {
Dependency d = new Dependency();
d.setGroupId("junit");
d.setArtifactId("junit");
d.setVersion("3.8.1");
d.setScope(Artifact.SCOPE_COMPILE);
return Collections.singletonList(d);
}
use of org.apache.maven.model.Dependency in project maven-plugins by apache.
the class AnalyzeDepMgt method checkDependencyManagement.
/**
* Does the work of checking the DependencyManagement Section.
*
* @return true if errors are found.
* @throws MojoExecutionException
*/
private boolean checkDependencyManagement() throws MojoExecutionException {
boolean foundError = false;
getLog().info("Found Resolved Dependency/DependencyManagement mismatches:");
List<Dependency> depMgtDependencies = null;
DependencyManagement depMgt = project.getDependencyManagement();
if (depMgt != null) {
depMgtDependencies = depMgt.getDependencies();
}
if (depMgtDependencies != null && !depMgtDependencies.isEmpty()) {
// put all the dependencies from depMgt into a map for quick lookup
Map<String, Dependency> depMgtMap = new HashMap<String, Dependency>();
Map<String, Exclusion> exclusions = new HashMap<String, Exclusion>();
for (Dependency depMgtDependency : depMgtDependencies) {
depMgtMap.put(depMgtDependency.getManagementKey(), depMgtDependency);
// now put all the exclusions into a map for quick lookup
exclusions.putAll(addExclusions(depMgtDependency.getExclusions()));
}
// get dependencies for the project (including transitive)
Set<Artifact> allDependencyArtifacts = new LinkedHashSet<Artifact>(project.getArtifacts());
// depMgt. That's ok.
if (this.ignoreDirect) {
getLog().info("\tIgnoring Direct Dependencies.");
Set<Artifact> directDependencies = project.getDependencyArtifacts();
allDependencyArtifacts.removeAll(directDependencies);
}
// log exclusion errors
List<Artifact> exclusionErrors = getExclusionErrors(exclusions, allDependencyArtifacts);
for (Artifact exclusion : exclusionErrors) {
getLog().info(StringUtils.stripEnd(getArtifactManagementKey(exclusion), ":") + " was excluded in DepMgt, but version " + exclusion.getVersion() + " has been found in the dependency tree.");
foundError = true;
}
// find and log version mismatches
Map<Artifact, Dependency> mismatch = getMismatch(depMgtMap, allDependencyArtifacts);
for (Map.Entry<Artifact, Dependency> entry : mismatch.entrySet()) {
logMismatch(entry.getKey(), entry.getValue());
foundError = true;
}
if (!foundError) {
getLog().info("\tNone");
}
} else {
getLog().info("\tNothing in DepMgt.");
}
return foundError;
}
Aggregations