Hi,

I am using the Maven 2 API to write a mojo.  (Should I be using the
Maven 3 API?)  My problem is that I am trying to retrieve the jar for
an artifact and I have a problem with finding a snapshot jar.   I use
the following code:

        private void resolveDendencies(final Artifact artifact) {
                getLog().info("+++ ProfilerMojo: attempting resolution
from " + localRepository.getUrl());
                final String localPath = localRepository.getUrl() +
"/" + localRepository.pathOf(artifact);
                if (fetch(localPath) != null) {
                        getLog().info("+++ ProfilerMojo: found " +
artifact + " at " + localPath);
                        return;
                }

                for (final ArtifactRepository repository : remoteRepositories) {
                        getLog().info("+++ ProfilerMojo: attempting
resolution from " + repository.getUrl());
                        final String remotePath = repository + "/" +
repository.pathOf(artifact);
                        if (fetch(remotePath) != null) {
                                getLog().info("+++ ProfilerMojo: found
" + artifact + " at " + remotePath);
                                return;
                        }
                }

                getLog().info("+++ ProfilerMojo: NOT FOUND " + artifact);
        }

        private Object fetch(final String urlAsString) {
                try {
                        final URL url = new URL(urlAsString);
                        final URLConnection connection = url.openConnection();
                        return connection.getContent();
                } catch (Exception e) {
                        return null;
                }

I realise that my problem is that snapshots have timestamps encoded in
the jar's name.   Any suggestions on how to handle this?

Thanks!
-- 
Johannes

Obligatory current favourite quotes:

"We are all atheists about most of the gods that societies have ever
believed in. Some of us just go one god further."
--Richard Dawkins

"Religion is regarded by the common people as true, by the wise as
false, and by the rulers as useful".
 -- Seneca
"I have more confidence in the methods of science, based on the amazing
record of science and its ability over the centuries to answer
unanswerable questions, than I do in the methods of faith (what are they?)."
 -- David J. Gross "Physics Nobel Laureate"

"Atheism is a religion to the same extent that not collecting stamps is a
 hobby."
 -- seen on Slashdot.org

http://xkcd.com/808/

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to