/*
(non-Javadoc)

@see org.eclipse.aether.util.listener.AbstractRepositoryListener#artifactResolved
(org.eclipse.aether.RepositoryEvent)
556203
@Override
    public void artifactResolved(RepositoryEvent event) {
        log.fine("Resolved artifact " + event.getArtifact() + " from " + event.getRepository());
    }
1275114
@Override
    public void metadataResolved(RepositoryEvent event) {
        log.fine("Resolved metadata " + event.getMetadata() + " from " + event.getRepository());
    }
838911
@Override
    public void metadataResolving(RepositoryEvent event) {
        log.finer("Resolving metadata " + event.getMetadata() + " from " + event.getRepository());
    }
808516
public void execute() throws MojoExecutionException {
        try {
            repositoryPath = findRepoPath(this.ceylonRepository);
            ArtifactRepositoryLayout layout = new CeylonRepoLayout();
            getLog().debug("Layout: " + layout.getClass());

            localRepository =
                new DefaultArtifactRepository(ceylonRepository, 
                    repositoryPath.toURI().toURL().toString(), layout);
            getLog().debug("Repository: " + localRepository);
        } catch (MalformedURLException e) {
            throw new MojoExecutionException("MalformedURLException: " + e.getMessage(), e);
        }
        
        if (project.getFile() != null) {
            readModel(project.getFile());
        }
        
        if (skip) {
            getLog().info("Skipping artifact installation");
            return;
        }

        if (!installAtEnd) {
            installProject(project);
        } else {
            MavenProject lastProject = reactorProjects.get(reactorProjects.size() - 1);
            if (lastProject.equals(project)) {
                for (MavenProject reactorProject : reactorProjects) {
                    installProject(reactorProject);
                }
            } else {
                getLog().info("Installing " + project.getGroupId() + ":" + project.getArtifactId() + ":"
                                   + project.getVersion() + " at end");
            }
        }
    }
1104247
@PostMapping(path = SamlIdPConstants.ENDPOINT_SAML1_SOAP_ARTIFACT_RESOLUTION)
    protected void handlePostRequest(final HttpServletResponse response,
                                     final HttpServletRequest request) {
        val ctx = decodeSoapRequest(request);
        val artifactMsg = (ArtifactResolve) ctx.getMessage();
        try {
            val issuer = artifactMsg.getIssuer().getValue();
            val service = verifySamlRegisteredService(issuer);
            val adaptor = getSamlMetadataFacadeFor(service, artifactMsg);
            if (adaptor.isEmpty()) {
                throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, "Cannot find metadata linked to " + issuer);
            }
            val facade = adaptor.get();
            verifyAuthenticationContextSignature(ctx, request, artifactMsg, facade);
            val artifactId = artifactMsg.getArtifact().getArtifact();
            val ticketId = getSamlProfileHandlerConfigurationContext().getArtifactTicketFactory().createTicketIdFor(artifactId);
            val ticket = getSamlProfileHandlerConfigurationContext().getTicketRegistry().getTicket(ticketId, SamlArtifactTicket.class);

            val issuerService = getSamlProfileHandlerConfigurationContext().getWebApplicationServiceFactory().createService(issuer);
            val casAssertion = buildCasAssertion(ticket.getTicketGrantingTicket().getAuthentication(),
                issuerService, service,
                CollectionUtils.wrap("artifact", ticket));
            getSamlProfileHandlerConfigurationContext().getResponseBuilder().build(artifactMsg, request, response, casAssertion,
                service, facade, SAMLConstants.SAML2_ARTIFACT_BINDING_URI, ctx);
        } catch (final Exception e) {
            LOGGER.error(e.getMessage(), e);
            request.setAttribute(SamlIdPConstants.REQUEST_ATTRIBUTE_ERROR, e.getMessage());
            getSamlProfileHandlerConfigurationContext().getSamlFaultResponseBuilder().build(artifactMsg, request, response,
                null, null, null, SAMLConstants.SAML2_ARTIFACT_BINDING_URI, ctx);
        }
    }
1232539
static Collection<MavenResolvedArtifact> postFilter(final Collection<MavenResolvedArtifact> artifactResults) {

        final MavenResolutionFilter postResolutionFilter = RestrictPomArtifactFilter.INSTANCE;
        final Collection<MavenResolvedArtifact> filteredArtifacts = new ArrayList<MavenResolvedArtifact>();
        final List<MavenDependency> emptyList = Collections.emptyList();

        for (final MavenResolvedArtifact artifact : artifactResults) {
            final MavenDependency dependency = MavenDependencies.createDependency(artifact.getCoordinate(),
                    ScopeType.COMPILE, false);
            // Empty lists OK here because we know the RestrictPOM Filter doesn't consult them
            if (postResolutionFilter.accepts(dependency, emptyList, emptyList)) {
                filteredArtifacts.add(artifact);
            }
        }
        return Collections.unmodifiableCollection(filteredArtifacts);
    }
448793
@Override
    public ARCHIVETYPE process(final MavenResolvedArtifact artifact, final Class<ARCHIVETYPE> returnType)
            throws IllegalArgumentException {

        if (artifact == null) {
            throw new IllegalArgumentException("Resolution artifact must be specified");
        }
        File file = artifact.asFile();
        if (file == null) {
            throw new IllegalArgumentException("Artifact was not resolved");
        }

        return ShrinkWrap.create(ZipImporter.class, file.getName()).importFrom(file).as(returnType);
    }
1011577
public void execute() throws MojoFailureException, MojoExecutionException {
        // Validate
        validateArtifactInformation();

        Artifact artifact =
                artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier );

        File existingFile = getLocalRepoFile(artifact);
        if (existingFile != null && existingFile.exists()) {
            System.out.println("Using cached remapped artifact "+ existingFile.getPath()); // delete file to reinstall
            return; // success
        }

        // Remap
        File outJar = null;
        try {
            // load input jar(s), as one combined jar (for jarmods)
            List<File> files = new ArrayList<File>();
            for (String filename : inJars) {
                files.add(FileLocator.getFile(filename));
            }
            Jar inJar = Jar.init(files);

            // temporary output file
            outJar = File.createTempFile(groupId + "." + artifactId + "-" + version, "." + packaging);

            // mappings
            JarMapping mapping = new JarMapping();
            if (excludedPackages != null) {
                for (String packageName : excludedPackages) {
                    mapping.addExcludedPackage(packageName);
                }
            }
            mapping.loadMappings(srgIn, reverse, numeric, inShadeRelocation, outShadeRelocation);
            mapping.setFallbackInheritanceProvider(new JarProvider(inJar));


            // access transformers
            RemapperProcessor preprocessor = null;
            if (accessTransformers != null) {
                AccessMap accessMap = new AccessMap();

                for (String filename : accessTransformers) {
                    if (filename != null && filename.length() != 0) {
                        accessMap.loadAccessTransformer(filename);
                    }
                }

                preprocessor = new RemapperProcessor(null, null, accessMap);
            }

            // Do the remap
            JarRemapper remapper = new JarRemapper(preprocessor, mapping);
            remapper.setGenerateAPI(generateAPI);
            remapper.remapJar(inJar, outJar);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MojoExecutionException("Error creating remapped jar at "+outJar+": " + ex.getMessage(), ex);
        }

        // Replace main artifact with this remapped artifact
        if (replaceMainArtifact) {
            getLog().info("Replacing original artifact with remapped artifact.");
            File originalArtifact = project.getArtifact().getFile();
            originalArtifact.delete();
            if (!outJar.renameTo(originalArtifact)) {
                throw new MojoExecutionException("Error replacing remapped jar at "+originalArtifact+" with "+outJar);
            }
        }

        // Attach output artifact to this project
        if (attachArtifact) {
            if (attachArtifactClassifier == null || attachArtifactClassifier.equals("")) {
                attachArtifactClassifier = null;
            }

            getLog().info("Attaching artifact " + outJar.getPath());
            projectHelper.attachArtifact(project, attachArtifactType, attachArtifactClassifier, outJar);
        }

        // Install output artifact to local repository
        if (installArtifact) {
            installArtifact(artifact, outJar);
        }
    }
790291
public void setBuildWorkspaceReader(List<Artifact> artifacts) {
        BuildWorkspaceReader reader = new BuildWorkspaceReader();
        
        for ( Artifact artifact : artifacts ) {
            reader.addArtifact( artifact );
        }
        
        systemSession = (MavenRepositorySystemSession)systemSession.setWorkspaceReader( reader );
        
    }
370815
public ArtifactResult resolveArtifact(final RepositorySystemSession session, final ArtifactRequest request)
            throws ArtifactResolutionException {
        return system.resolveArtifact(session, request);
    }
1208456
protected Set<Event> getResolvedEventsAsAttribute(final RequestContext context) {
        return context.getAttributes().get(RESOLVED_AUTHENTICATION_EVENTS, Set.class);
    }
460968
static MavenResolvedArtifact fromArtifactResult(final ArtifactResult artifactResult) {
        final Artifact artifact = artifactResult.getArtifact();
        final DependencyNode root = artifactResult.getRequest().getDependencyNode();

        // SHRINKRES-143 lets ignore invalid scope
        ScopeType scopeType = ScopeType.RUNTIME;
        try {
            scopeType = ScopeType.fromScopeType(root.getDependency().getScope());
        } catch (IllegalArgumentException e) {
            // let scope be RUNTIME
            log.log(Level.WARNING, "Invalid scope {0} of retrieved dependency {1} will be replaced by <scope>runtime</scope>",
                    new Object[] { root.getDependency().getScope(), root.getDependency().getArtifact() });
        }

        final List<DependencyNode> children = root.getChildren();
        final boolean optional = root.getDependency().isOptional();
        return new MavenResolvedArtifactImpl(artifact, scopeType, children, optional);
    }
525958
@Override
    protected MavenFormatStage createFormatStage(final Collection<MavenResolvedArtifact> filteredArtifacts)
            throws IllegalArgumentException {
        assert filteredArtifacts != null : "filtered artifacts are required";
        return new MavenFormatStageImpl(filteredArtifacts);
    }
168702
@Override
    public void artifactDescriptorInvalid(RepositoryEvent event) {
        log.warning("Invalid artifact descriptor for " + event.getArtifact() + ": " + event.getException().getMessage());
    }
356832
public static Protos.CommandInfo.URI uri(MesosArtifactResolver resolver, ContainerSpecification.Artifact artifact) {
		checkNotNull(resolver);
		checkNotNull(artifact);
		Option<URL> url = resolver.resolve(artifact.dest);
		if (url.isEmpty()) {
			throw new IllegalArgumentException("Unresolvable artifact: " + artifact.dest);
		}

		return Protos.CommandInfo.URI.newBuilder()
			.setValue(url.get().toExternalForm())
			.setOutputFile(artifact.dest.toString())
			.setExtract(artifact.extract)
			.setCache(artifact.cachable)
			.setExecutable(artifact.executable)
			.build();
	}
572871
private static void replaceRepositoryInputForValues(ArtifactoryClientConfiguration configuration,
                                                        Run build, String resolverReleaseInput,
                                                        String resolverSnapshotInput, Map<String, String> env) {
        if (StringUtils.isBlank(resolverReleaseInput) || StringUtils.isBlank(resolverSnapshotInput)) {
            build.setResult(Result.FAILURE);
            throw new IllegalStateException("Input for resolve repositories cannot be empty.");
        }
        String resolveReleaseRepo = Util.replaceMacro(resolverReleaseInput, env);
        String resolveSnapshotRepo = Util.replaceMacro(resolverSnapshotInput, env);
        if (StringUtils.isBlank(resolveReleaseRepo) || StringUtils.isBlank(resolveSnapshotRepo)) {
            build.setResult(Result.FAILURE);
            throw new IllegalStateException("Resolver repository variable cannot be replaces with empty value.");
        }
        configuration.resolver.setDownloadSnapshotRepoKey(resolveSnapshotRepo);
        configuration.resolver.setRepoKey(resolveReleaseRepo);
    }
1017603
public static WstxInputSource resolveEntityUsing
        (WstxInputSource refCtxt, String entityName,
         String publicId, String systemId,
         XMLResolver resolver, ReaderConfig cfg, int xmlVersion)
        throws IOException, XMLStreamException
    {
        URL ctxt = (refCtxt == null) ? null : refCtxt.getSource();
        if (ctxt == null) {
            ctxt = URLUtil.urlFromCurrentDir();
        }
        Object source = resolver.resolveEntity(publicId, systemId, ctxt.toExternalForm(), entityName);
        return (source == null) ? null : sourceFrom(refCtxt, cfg, entityName, xmlVersion, source);
    }