Search in sources :

Example 11 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project karaf by apache.

the class RunMojo method resolveFile.

private File resolveFile(String file) {
    File fileResolved = null;
    if (isMavenUrl(file)) {
        fileResolved = new File(fromMaven(file));
        try {
            Artifact artifactTemp = resourceToArtifact(file, false);
            if (!fileResolved.exists()) {
                try {
                    artifactResolver.resolve(artifactTemp, remoteRepos, localRepo);
                    fileResolved = artifactTemp.getFile();
                } catch (ArtifactResolutionException e) {
                    getLog().error("Artifact was not resolved", e);
                } catch (ArtifactNotFoundException e) {
                    getLog().error("Artifact was not found", e);
                }
            }
        } catch (MojoExecutionException e) {
            getLog().error(e);
        }
    } else {
        fileResolved = new File(file);
    }
    return fileResolved;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 12 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project karaf by apache.

the class KarMojo method resolveFile.

private File resolveFile(String file) {
    File fileResolved = null;
    if (isMavenUrl(file)) {
        fileResolved = new File(fromMaven(file));
        try {
            Artifact artifactTemp = resourceToArtifact(file, false);
            if (!fileResolved.exists()) {
                try {
                    artifactResolver.resolve(artifactTemp, remoteRepos, localRepo);
                    fileResolved = artifactTemp.getFile();
                } catch (ArtifactResolutionException e) {
                    getLog().error("Artifact was not resolved", e);
                } catch (ArtifactNotFoundException e) {
                    getLog().error("Artifact was not found", e);
                }
            }
        } catch (MojoExecutionException e) {
            getLog().error(e);
        }
    } else {
        fileResolved = new File(file);
    }
    return fileResolved;
}
Also used : ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 13 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project karaf by apache.

the class GenerateDescriptorMojo method writeFeatures.

/*
     * Write all project dependencies as feature
     */
private void writeFeatures(PrintStream out) throws ArtifactResolutionException, ArtifactNotFoundException, IOException, JAXBException, SAXException, ParserConfigurationException, XMLStreamException, MojoExecutionException {
    getLog().info("Generating feature descriptor file " + outputFile.getAbsolutePath());
    //read in an existing feature.xml
    ObjectFactory objectFactory = new ObjectFactory();
    Features features;
    if (inputFile.exists()) {
        filter(inputFile, filteredInputFile);
        features = readFeaturesFile(filteredInputFile);
    } else {
        features = objectFactory.createFeaturesRoot();
    }
    if (features.getName() == null) {
        features.setName(project.getArtifactId());
    }
    Feature feature = null;
    for (Feature test : features.getFeature()) {
        if (test.getName().equals(primaryFeatureName)) {
            feature = test;
        }
    }
    if (feature == null) {
        feature = objectFactory.createFeature();
        feature.setName(primaryFeatureName);
    }
    if (!feature.hasVersion()) {
        feature.setVersion(project.getArtifact().getBaseVersion());
    }
    if (feature.getDescription() == null) {
        feature.setDescription(project.getName());
    }
    if (installMode != null) {
        feature.setInstall(installMode);
    }
    if (project.getDescription() != null && feature.getDetails() == null) {
        feature.setDetails(project.getDescription());
    }
    if (includeProjectArtifact) {
        Bundle bundle = objectFactory.createBundle();
        bundle.setLocation(this.dependencyHelper.artifactToMvn(project.getArtifact(), project.getVersion()));
        if (startLevel != null) {
            bundle.setStartLevel(startLevel);
        }
        feature.getBundle().add(bundle);
    }
    boolean needWrap = false;
    // First pass to look for features
    // Track other features we depend on and their repositories (we track repositories instead of building them from
    // the feature's Maven artifact to allow for multi-feature repositories)
    // TODO Initialise the repositories from the existing feature file if any
    Map<Dependency, Feature> otherFeatures = new HashMap<>();
    Map<Feature, String> featureRepositories = new HashMap<>();
    for (final LocalDependency entry : localDependencies) {
        Object artifact = entry.getArtifact();
        if (excludedArtifactIds.contains(this.dependencyHelper.getArtifactId(artifact))) {
            continue;
        }
        processFeatureArtifact(features, feature, otherFeatures, featureRepositories, artifact, entry.getParent(), true);
    }
    // Second pass to look for bundles
    if (addBundlesToPrimaryFeature) {
        localDependency: for (final LocalDependency entry : localDependencies) {
            Object artifact = entry.getArtifact();
            if (excludedArtifactIds.contains(this.dependencyHelper.getArtifactId(artifact))) {
                continue;
            }
            if (!this.dependencyHelper.isArtifactAFeature(artifact)) {
                String bundleName = this.dependencyHelper.artifactToMvn(artifact, getVersionOrRange(entry.getParent(), artifact));
                File bundleFile = this.dependencyHelper.resolve(artifact, getLog());
                Manifest manifest = getManifest(bundleFile);
                for (ConfigFile cf : feature.getConfigfile()) {
                    if (bundleName.equals(cf.getLocation().replace('\n', ' ').trim())) {
                        // The bundle matches a configfile, ignore it
                        continue localDependency;
                    }
                }
                if (manifest == null || !ManifestUtils.isBundle(getManifest(bundleFile))) {
                    bundleName = "wrap:" + bundleName;
                    needWrap = true;
                }
                Bundle bundle = null;
                for (Bundle b : feature.getBundle()) {
                    if (bundleName.equals(b.getLocation())) {
                        bundle = b;
                        break;
                    }
                }
                if (bundle == null) {
                    bundle = objectFactory.createBundle();
                    bundle.setLocation(bundleName);
                    // Check the features this feature depends on don't already contain the dependency
                    // TODO Perhaps only for transitive dependencies?
                    boolean includedTransitively = simplifyBundleDependencies && isBundleIncludedTransitively(feature, otherFeatures, bundle);
                    if (!includedTransitively && (!"provided".equals(entry.getScope()) || !ignoreScopeProvided)) {
                        feature.getBundle().add(bundle);
                    }
                }
                if ("runtime".equals(entry.getScope())) {
                    bundle.setDependency(true);
                }
                if (startLevel != null && bundle.getStartLevel() == 0) {
                    bundle.setStartLevel(startLevel);
                }
            }
        }
    }
    if (needWrap) {
        Dependency wrapDependency = new Dependency();
        wrapDependency.setName("wrap");
        wrapDependency.setDependency(false);
        wrapDependency.setPrerequisite(true);
        feature.getFeature().add(wrapDependency);
    }
    if ((!feature.getBundle().isEmpty() || !feature.getFeature().isEmpty()) && !features.getFeature().contains(feature)) {
        features.getFeature().add(feature);
    }
    // Add any missing repositories for the included features
    for (Feature includedFeature : features.getFeature()) {
        for (Dependency dependency : includedFeature.getFeature()) {
            Feature dependedFeature = otherFeatures.get(dependency);
            if (dependedFeature != null && !features.getFeature().contains(dependedFeature)) {
                String repository = featureRepositories.get(dependedFeature);
                if (repository != null && !features.getRepository().contains(repository)) {
                    features.getRepository().add(repository);
                }
            }
        }
    }
    JaxbUtil.marshal(features, out);
    try {
        checkChanges(features, objectFactory);
    } catch (Exception e) {
        throw new MojoExecutionException("Features contents have changed", e);
    }
    getLog().info("...done!");
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ConfigFile(org.apache.karaf.features.internal.model.ConfigFile) Bundle(org.apache.karaf.features.internal.model.Bundle) Dependency(org.apache.karaf.features.internal.model.Dependency) LocalDependency(org.apache.karaf.tooling.utils.LocalDependency) Manifest(java.util.jar.Manifest) Feature(org.apache.karaf.features.internal.model.Feature) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) XMLStreamException(javax.xml.stream.XMLStreamException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) LocalDependency(org.apache.karaf.tooling.utils.LocalDependency) ObjectFactory(org.apache.karaf.features.internal.model.ObjectFactory) Features(org.apache.karaf.features.internal.model.Features) ConfigFile(org.apache.karaf.features.internal.model.ConfigFile) File(java.io.File)

Example 14 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException 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);
}
Also used : HashMap(java.util.HashMap) InvalidDependencyVersionException(org.apache.maven.project.artifact.InvalidDependencyVersionException) ArrayList(java.util.ArrayList) Dependency(org.apache.maven.model.Dependency) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 15 with ArtifactNotFoundException

use of org.apache.maven.artifact.resolver.ArtifactNotFoundException in project maven-plugins by apache.

the class AbstractJavadocMojo method getDependencySourcePaths.

/**
     * Resolve dependency sources so they can be included directly in the javadoc process. To customize this,
     * override {@link AbstractJavadocMojo#configureDependencySourceResolution(SourceResolverConfig)}.
     * @return List of source paths.
     * @throws MavenReportException {@link MavenReportException}
     */
protected final List<String> getDependencySourcePaths() throws MavenReportException {
    try {
        if (sourceDependencyCacheDir.exists()) {
            FileUtils.forceDelete(sourceDependencyCacheDir);
            sourceDependencyCacheDir.mkdirs();
        }
    } catch (IOException e) {
        throw new MavenReportException("Failed to delete cache directory: " + sourceDependencyCacheDir + "\nReason: " + e.getMessage(), e);
    }
    final SourceResolverConfig config = getDependencySourceResolverConfig();
    final List<TransformableFilter> andFilters = new ArrayList<TransformableFilter>();
    final List<String> dependencyIncludes = dependencySourceIncludes;
    final List<String> dependencyExcludes = dependencySourceExcludes;
    if (!includeTransitiveDependencySources || isNotEmpty(dependencyIncludes) || isNotEmpty(dependencyExcludes)) {
        if (!includeTransitiveDependencySources) {
            andFilters.add(createDependencyArtifactFilter());
        }
        if (isNotEmpty(dependencyIncludes)) {
            andFilters.add(new PatternInclusionsFilter(dependencyIncludes));
        }
        if (isNotEmpty(dependencyExcludes)) {
            andFilters.add(new PatternExclusionsFilter(dependencyExcludes));
        }
        config.withFilter(new AndFilter(andFilters));
    }
    try {
        return resourceResolver.resolveDependencySourcePaths(config);
    } catch (final ArtifactResolutionException e) {
        throw new MavenReportException("Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
    } catch (final ArtifactNotFoundException e) {
        throw new MavenReportException("Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
    }
}
Also used : PatternInclusionsFilter(org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PatternExclusionsFilter(org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter) AndFilter(org.apache.maven.shared.artifact.filter.resolve.AndFilter) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) TransformableFilter(org.apache.maven.shared.artifact.filter.resolve.TransformableFilter) SourceResolverConfig(org.apache.maven.plugin.javadoc.resolver.SourceResolverConfig) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) MavenReportException(org.apache.maven.reporting.MavenReportException)

Aggregations

ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)20 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)20 Artifact (org.apache.maven.artifact.Artifact)15 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 File (java.io.File)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)2 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)2 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)2 SnapshotArtifactRepositoryMetadata (org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata)2 AbstractArtifactResolutionException (org.apache.maven.artifact.resolver.AbstractArtifactResolutionException)2 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 VersionRange (org.apache.maven.artifact.versioning.VersionRange)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 MavenProject (org.apache.maven.project.MavenProject)2 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 TransformableFilter (org.apache.maven.shared.artifact.filter.resolve.TransformableFilter)2