You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Johannes Ruscheinski <ru...@gmail.com> on 2011/02/18 23:19:55 UTC
Artifact Retrieval
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: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Artifact Retrieval
Posted by Johannes Ruscheinski <ru...@gmail.com>.
>
> This might be helpful:
> http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook#MojoDeveloperCookbook-Creatingandresolvinganartifact
>
I think that's all deprecated now. Anybody know what the new way of
creating Artifacts and resolving them is?
>
> Benjamin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>
--
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: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Artifact Retrieval
Posted by Johannes Ruscheinski <ru...@gmail.com>.
On 18 February 2011 14:41, Benjamin Bentmann <be...@udo.edu> wrote:
> Johannes Ruscheinski wrote:
>
>> 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;
>> }
>
> This might be helpful:
> http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook#MojoDeveloperCookbook-Creatingandresolvinganartifact
Yes, that looks very useful. Thank you!
>
>
> Benjamin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org
>
>
--
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: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org
Re: Artifact Retrieval
Posted by Benjamin Bentmann <be...@udo.edu>.
Johannes Ruscheinski wrote:
> 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;
> }
This might be helpful:
http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook#MojoDeveloperCookbook-Creatingandresolvinganartifact
Benjamin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org