Example usage for org.apache.maven.artifact.resolver ArtifactNotFoundException ArtifactNotFoundException

List of usage examples for org.apache.maven.artifact.resolver ArtifactNotFoundException ArtifactNotFoundException

Introduction

In this page you can find the example usage for org.apache.maven.artifact.resolver ArtifactNotFoundException ArtifactNotFoundException.

Prototype

public ArtifactNotFoundException(String message, Artifact artifact) 

Source Link

Usage

From source file:de.thetaphi.forbiddenapis.maven.AbstractCheckMojo.java

License:Apache License

private File resolveSignaturesArtifact(SignaturesArtifact signaturesArtifact)
        throws ArtifactResolutionException, ArtifactNotFoundException {
    final Artifact artifact = signaturesArtifact.createArtifact(artifactFactory);
    artifactResolver.resolve(artifact, this.remoteRepositories, this.localRepository);
    final File f = artifact.getFile();
    // Can this ever be false? Be sure. Found the null check also in other Maven code, so be safe!
    if (f == null) {
        throw new ArtifactNotFoundException("Artifact does not resolve to a file.", artifact);
    }//from   w w  w . j a v  a2 s.co m
    return f;
}

From source file:io.fabric8.jube.maven.BuildMojo.java

License:Apache License

protected void unpackBaseImage(File buildDir, boolean useDefaultPrefix) throws Exception {
    String imageName = project.getProperties().getProperty(DOCKER_BASE_IMAGE_PROPERTY);
    Objects.notNull(imageName, DOCKER_BASE_IMAGE_PROPERTY);

    ImageMavenCoords baseImageCoords = ImageMavenCoords.parse(imageName, useDefaultPrefix);
    String coords = baseImageCoords.getAetherCoords();

    Artifact artifact = repositorySystem.createArtifactWithClassifier(baseImageCoords.getGroupId(),
            baseImageCoords.getArtifactId(), baseImageCoords.getVersion(), baseImageCoords.getType(),
            baseImageCoords.getClassifier());
    getLog().info("Resolving Jube image: " + artifact);

    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);//from ww  w  .j  a  v  a 2s  .  c o m
    request.setLocalRepository(localRepository);
    request.setRemoteRepositories(pomRemoteRepositories);

    ArtifactResolutionResult result = artifactResolver.resolve(request);
    if (!result.isSuccess()) {
        throw new ArtifactNotFoundException("Cannot download Jube image", artifact);
    }

    getLog().info("Resolved Jube image: " + artifact);

    if (artifact.getFile() != null) {
        File file = artifact.getFile();
        getLog().info("File: " + file);

        if (!file.exists() || file.isDirectory()) {
            throw new MojoExecutionException(
                    "Resolved file for " + coords + " is not a valid file: " + file.getAbsolutePath());
        }
        getLog().info("Unpacking base image " + file.getAbsolutePath() + " to build dir: " + buildDir);
        Zips.unzip(new FileInputStream(file), buildDir);
    }
}

From source file:lu.softec.maven.mavenizer.mavenfile.internal.DefaultMavenFileFactory.java

License:Open Source License

public MavenFile getMavenFile(File libfile, String groupId, String artifactId, String version,
        String classifier, MavenFileSet deps, ArtifactRepository repository, List remoteRepositories)
        throws InvalidMavenCoordinatesException, ArtifactResolutionException, ArtifactNotFoundException {
    File file = libfile;//w  w w .  ja v a  2 s  . c om

    // If no local file is provided, try to resolve missing artifact from local or remote repositories
    if (file == null) {
        if (repository == null) {
            return null;
        }
        Artifact artifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, "jar",
                classifier);

        if (!artifact.isResolved() && remoteRepositories != null) {
            artifactResolver.resolve(artifact, remoteRepositories, repository);
        }
        file = artifact.getFile();

        if (file == null) {
            // Should never happen
            throw new ArtifactNotFoundException("No file available after artifact resolution", artifact);
        }
    }

    // If maven file already exists, than check it for consistencies and return the existing one
    if (mavenFiles.containsKey(file)) {
        InternalMavenFile mvnFile = (InternalMavenFile) mavenFiles.get(file);
        if (!StringUtils.equals(mvnFile.getGroupId(), groupId)
                || !StringUtils.equals(mvnFile.getArtifactId(), artifactId)
                || !StringUtils.equals(mvnFile.getVersion(), version)
                || !StringUtils.equals(mvnFile.getClassifier(), classifier) || (deps != null
                        && mvnFile.getDependencies().size() != 0 && !deps.equals(mvnFile.getDependencies()))) {
            throw new IllegalArgumentException(
                    "The instance requested mismatch with a previously existing instance for file "
                            + file.getAbsolutePath());
        }

        if (deps != null && mvnFile.getDependencies().size() == 0) {
            mvnFile.setDependencies(deps);
        }

        return mvnFile;
    }

    // Create a new maven file instance
    MavenFile mvnFile = new InternalMavenFile(file, groupId, artifactId, version, classifier, deps);

    // If the file has been provided, ensure proper maven coordinates has been used
    if (libfile != null) {
        validateArtifactInformation(mvnFile);
    }

    // Remember this new instance for future request
    mavenFiles.put(file, mvnFile);
    return mvnFile;
}

From source file:npanday.resolver.resolvers.GacResolver.java

License:Apache License

public void tryResolve(Artifact artifact, Set<Artifact> additionalDependenciesCollector, ArtifactFilter filter)
        throws ArtifactNotFoundException {

    File artifactFile = null;//from  w w  w . ja va2s. c o m
    String artifactType = artifact.getType();

    if (ArtifactTypeHelper.isDotnetAnyGac(artifactType)) {
        if (cache.applyTo(artifact)) {
            return;
        }

        if (!ArtifactTypeHelper.isDotnet4Gac(artifactType)) {
            artifactFile = PathUtil.getGlobalAssemblyCacheFileFor(artifact,
                    new File("C:\\WINDOWS\\assembly\\"));
        } else {
            artifactFile = PathUtil.getGACFile4Artifact(artifact);
        }

        if (artifactFile.exists()) {
            artifact.setFile(artifactFile);
            artifact.setResolved(true);
            cache.put(artifact);
        } else {
            throw new ArtifactNotFoundException(
                    "NPANDAY-158-001: Could not resolve gac-dependency " + artifact + ", tried " + artifactFile,
                    artifact);
        }
    }

}

From source file:org.eclipse.che.maven.CheArtifactResolver.java

License:Apache License

private void resolveOrig(Artifact artifact, List<ArtifactRepository> remoteRepositories,
        RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
    if (artifact == null) {
        return;/*  w ww . j  ava 2  s. c o  m*/
    }

    if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
        File systemFile = artifact.getFile();

        if (systemFile == null) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached",
                    artifact);
        }

        if (!systemFile.exists()) {
            throw new ArtifactNotFoundException(
                    "System artifact: " + artifact + " not found in path: " + systemFile, artifact);
        }

        if (!systemFile.isFile()) {
            throw new ArtifactNotFoundException(
                    "System artifact: " + artifact + " is not a file: " + systemFile, artifact);
        }

        artifact.setResolved(true);

        return;
    }

    if (!artifact.isResolved()) {
        ArtifactResult result;

        try {
            ArtifactRequest artifactRequest = new ArtifactRequest();
            artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
            artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));

            // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
            LocalRepositoryManager lrm = session.getLocalRepositoryManager();
            String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
            artifact.setFile(new File(lrm.getRepository().getBasedir(), path));

            result = repoSystem.resolveArtifact(session, artifactRequest);
        } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
            if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
                throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(),
                        artifact.getArtifactId(), artifact.getVersion(), artifact.getType(),
                        artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(),
                        artifact.getDependencyTrail(), e);
            } else {
                throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
            }
        }

        artifact.selectVersion(result.getArtifact().getVersion());
        artifact.setFile(result.getArtifact().getFile());
        artifact.setResolved(true);

        if (artifact.isSnapshot()) {
            Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
            if (matcher.matches()) {
                Snapshot snapshot = new Snapshot();
                snapshot.setTimestamp(matcher.group(2));
                try {
                    snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
                    artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
                } catch (NumberFormatException e) {
                    logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
                }
            }
        }
    }
}

From source file:org.janus_project.janus_maven_plugin.mojo.AbstractDistributionMojo.java

License:Open Source License

/**
 * Distribute the OSGi layout bundle files.
 * //from ww  w  . j a va2s.c om
 * @param outDir
 *            is the output directory, such as target/janus-dist.
 * @param layout
 *            is the current OSGi layout.
 * @throws MojoExecutionException
 * @throws ArtifactNotFoundException
 * @throws ArtifactResolutionException
 * @throws IOException
 */
protected void distributeBundles(File outDir, Layout layout)
        throws MojoExecutionException, ArtifactResolutionException, ArtifactNotFoundException, IOException {
    Set<File> deps = Utils.getOsgiDependencyFiles(getLog(), this.artifacts, this.excludes);

    resolveArtifact(this.projectArtifact.getGroupId(), this.projectArtifact.getArtifactId(),
            this.projectArtifact.getVersion());

    Build build = this.mavenProject.getBuild();
    File currentProjectJarFile = new File(this.outputDirectory, build.getFinalName() + ".jar"); //$NON-NLS-1$

    if (!currentProjectJarFile.exists()) {
        throw new ArtifactNotFoundException("Unable to find the output jar file for the project: " + //$NON-NLS-1$
                currentProjectJarFile.toString(), this.createArtifact(this.projectArtifact.getGroupId(),
                        this.projectArtifact.getArtifactId(), this.projectArtifact.getVersion()));
    }
    deps.add(currentProjectJarFile);

    distributeBundles(outDir, layout, deps);
}

From source file:org.jetbrains.idea.maven.server.embedder.CustomMaven32ArtifactResolver.java

License:Apache License

private void resolveOld(Artifact artifact, List<ArtifactRepository> remoteRepositories,
        RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
    if (artifact == null) {
        return;/*from  ww  w . j  a v  a2  s . c om*/
    }

    if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
        File systemFile = artifact.getFile();

        if (systemFile == null) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached",
                    artifact);
        }

        if (!systemFile.exists()) {
            throw new ArtifactNotFoundException(
                    "System artifact: " + artifact + " not found in path: " + systemFile, artifact);
        }

        if (!systemFile.isFile()) {
            throw new ArtifactNotFoundException(
                    "System artifact: " + artifact + " is not a file: " + systemFile, artifact);
        }

        artifact.setResolved(true);

        return;
    }

    if (!artifact.isResolved()) {
        ArtifactResult result;

        try {
            ArtifactRequest artifactRequest = new ArtifactRequest();
            artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
            artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));

            // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
            LocalRepositoryManager lrm = session.getLocalRepositoryManager();
            String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
            artifact.setFile(new File(lrm.getRepository().getBasedir(), path));

            result = repoSystem.resolveArtifact(session, artifactRequest);
        } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
            if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
                throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(),
                        artifact.getArtifactId(), artifact.getVersion(), artifact.getType(),
                        artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(),
                        artifact.getDependencyTrail(), e);
            } else {
                throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
            }
        }

        artifact.selectVersion(result.getArtifact().getVersion());
        artifact.setFile(result.getArtifact().getFile());
        artifact.setResolved(true);

        if (artifact.isSnapshot()) {
            Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
            if (matcher.matches()) {
                Snapshot snapshot = new Snapshot();
                snapshot.setTimestamp(matcher.group(2));
                try {
                    snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
                    artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
                } catch (NumberFormatException e) {
                    logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
                }
            }
        }
    }
}

From source file:org.sourcepit.osgifier.maven.context.MavenDependencyWalker.java

License:Apache License

private Set<Artifact> resolve(Request walkerRequest, Artifact artifact, MavenProject resolutionContext,
        boolean resolveRoot, List<Dependency> dependencies) {
    final ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);/*from   w  w  w.j  a v  a2s.  c  o m*/
    request.setResolveRoot(resolveRoot);
    request.setResolveTransitively(!resolveRoot);

    if (dependencies != null) {
        final Set<Artifact> artifactDependencies = new LinkedHashSet<Artifact>();
        for (Dependency dependency : dependencies) {
            artifactDependencies.add(repositorySystem.createArtifactWithClassifier(dependency.getGroupId(),
                    dependency.getArtifactId(), dependency.getVersion(), dependency.getType(),
                    dependency.getClassifier()));
        }
        request.setArtifactDependencies(artifactDependencies);
    }

    request.setLocalRepository(walkerRequest.getLocalRepository());

    final List<ArtifactRepository> remoteRepositories = new ArrayList<ArtifactRepository>();
    final Set<String> repoIds = new HashSet<String>();
    final List<ArtifactRepository> requestRepos = walkerRequest.getRemoteRepositories();
    if (requestRepos != null) {
        for (ArtifactRepository artifactRepository : requestRepos) {
            repoIds.add(artifactRepository.getId());
            remoteRepositories.add(artifactRepository);
        }
    }

    if (resolutionContext != null) {
        for (ArtifactRepository artifactRepository : resolutionContext.getRemoteArtifactRepositories()) {
            if (repoIds.add(artifactRepository.getId())) {
                remoteRepositories.add(artifactRepository);
            }
        }
        request.setManagedVersionMap(resolutionContext.getManagedVersionMap());
    }

    request.setRemoteRepositories(remoteRepositories);

    final ArtifactFilter artifactFilter = walkerRequest.getArtifactFilter();

    request.setCollectionFilter(artifactFilter);
    request.setResolutionFilter(artifactFilter);

    ArtifactResolutionResult result = repositorySystem.resolve(request);

    final Exception ex;
    if (result.hasExceptions()) {
        ex = result.getExceptions().get(0);
    } else if (result.hasCircularDependencyExceptions()) {
        ex = result.getCircularDependencyException(0);
    } else if (result.hasErrorArtifactExceptions()) {
        ex = result.getErrorArtifactExceptions().get(0);
    } else if (result.hasMetadataResolutionExceptions()) {
        ex = result.getMetadataResolutionException(0);
    } else {
        ex = null;
    }
    if (ex != null) {
        throw new IllegalStateException(ex);
    }

    for (Artifact missingArtifact : result.getMissingArtifacts()) {
        throw Exceptions.pipe(new ArtifactNotFoundException("Unable to resolve artifact", missingArtifact));
    }

    return result.getArtifacts();
}