[
https://issues.jboss.org/browse/JBIDE-8973?page=com.atlassian.jira.plugin...
]
Fred Bricon edited comment on JBIDE-8973 at 12/19/11 6:29 AM:
--------------------------------------------------------------
So here are a few strategies we can apply to identify a jar :
1 : Check if the jar contains the maven metadata :
{code}
File jar = ...
org.apache.maven.shared.runtime.MavenRuntime r = new DefaultMavenRuntime();
MavenProjectProperties projectProperties = r.getProjectProperties(jar.toURL());
{code}
3 : Identify via the Nexus indexer :
{code}
File jar = ...
IndexedArtifactFile iaf= ((NexusIndexManager)MavenPlugin.getIndexManager()).identify(jar)
{code}
4 : Identify via the JBoss Nexus instance REST API if we're online, via a SHA1
search.:
Example in Groovy code (can be run in a GroovyConsole).
{code}
@Grab(group='org.codehaus.groovy.modules.http-builder',
module='http-builder', version='0.5.1' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder( 'https://repository.jboss.org' )
// perform a GET request, expecting JSON response data
http.request( GET, JSON ) {
uri.path = '/nexus/service/local/lucene/search'
uri.query = [ sha1:"e6ddfa5d1d3613668bbc33ff344c887950c21f67" ]
headers.'Accept' = 'application/json'
// response handler for a success response code:
response.success = { resp, json ->
def a = json.data.artifactId[0]
def g = json.data.groupId[0]
def v = json.data.version[0]
print "groupId:$g, artifactId:$a, version:$v"
//prints groupId:org.mvel, artifactId:mvel, version:1.2.24-java1.4
}
}
{code}
Here the mvel file taken from a Seam 2 project can not be found on maven central.
Calls to
https://repository.jboss.org take > 1s for me
4b : Call
http://search.maven.org/ REST API if we're online to perform a SHA1 search.
Example in Groovy code (can be run in a GroovyConsole)
{code}
import groovy.json.*
import groovy.time.*
def slurper = new JsonSlurper()
def sha1 = "5675fd96b29656504b86029551973d60fb41339b"
def q = URLEncoder.encode("1:\"$sha1\"")
def url =
"http://search.maven.org/solrsearch/select?q=$q&rows=2&wt=json"
def content = new URL(url).getText("UTF-8")
def root = slurper.parseText(content)
def docs = root.response.docs
def a = docs.a[0]
def g = docs.g[0]
def v = docs.v[0]
print "groupId:$g, artifactId:$a, version:$v"
//prints groupId:commons-beanutils, artifactId:commons-beanutils, version:1.7.0
{code}
Calls to
search.maven.org take ~ 250ms for me
was (Author: fbricon):
So here are a few strategies we can apply to identify a jar :
1 : Check if the jar contains the maven metadata :
{code}
File jar = ...
org.apache.maven.shared.runtime.MavenRuntime r = new DefaultMavenRuntime();
MavenProjectProperties projectProperties = r.getProjectProperties(jar.toURL());
{code}
3 : Identify via the Nexus indexer :
{code}
File jar = ...
IndexedArtifactFile iaf= ((NexusIndexManager)MavenPlugin.getIndexManager()).identify(jar)
{code}
4 : Identify via the JBoss Nexus instance REST API if we're online, via a SHA1
search.:
Example in Groovy code (can be run in a GroovyConsole).
{code}
@Grab(group='org.codehaus.groovy.modules.http-builder',
module='http-builder', version='0.5.1' )
import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
def http = new HTTPBuilder( 'https://repository.jboss.org' )
// perform a GET request, expecting JSON response data
http.request( GET, JSON ) {
uri.path = '/nexus/service/local/lucene/search'
uri.query = [ sha1:"e6ddfa5d1d3613668bbc33ff344c887950c21f67" ]
headers.'Accept' = 'application/json'
// response handler for a success response code:
response.success = { resp, json ->
def a = json.data.artifactId[0]
def g = json.data.groupId[0]
def v = json.data.version[0]
print "groupId:$g, artifactId:$a, version:$v"
//prints groupId:org.mvel, artifactId:mvel, version:1.2.24-java1.4
}
// handler for any failure status code:
response.failure = { resp ->
println "Unexpected error: ${resp.statusLine.statusCode} :
${resp.statusLine.reasonPhrase}"
}
}
{code}
Here the mvel file taken from a Seam 2 project can not be found on maven central.
Calls to
https://repository.jboss.org take > 1s for me
4b : Call
http://search.maven.org/ REST API if we're online to perform a SHA1 search.
Example in Groovy code (can be run in a GroovyConsole)
{code}
import groovy.json.*
import groovy.time.*
def slurper = new JsonSlurper()
def sha1 = "5675fd96b29656504b86029551973d60fb41339b"
def q = URLEncoder.encode("1:\"$sha1\"")
def url =
"http://search.maven.org/solrsearch/select?q=$q&rows=2&wt=json"
def content = new URL(url).getText("UTF-8")
def root = slurper.parseText(content)
def docs = root.response.docs
def a = root.response.docs.a[0]
def g = root.response.docs.g[0]
def v = root.response.docs.v[0]
print "groupId:$g, artifactId:$a, version:$v"
//prints groupId:commons-beanutils, artifactId:commons-beanutils, version:1.7.0
{code}
Calls to
search.maven.org take ~ 250ms for me
Provide a way to convert pure java libs into maven provided
dependencies
------------------------------------------------------------------------
Key: JBIDE-8973
URL:
https://issues.jboss.org/browse/JBIDE-8973
Project: Tools (JBoss Tools)
Issue Type: Feature Request
Components: maven
Affects Versions: 3.3.0.M1
Reporter: Max Rydahl Andersen
Assignee: Fred Bricon
Labels: new_and_noteworthy
Fix For: 3.3.x
Execute: multiple select lib dependencies, then right click and choose "Build path
> Convert to Maven dependencies"
Assert: UI is shown that shows which jars misses metadata and what can be automatically
detected based on maven metadata in the jar. UI has option to delete jars from project.
Execute: Press Ok
Assert: The jars are removed from classpath container, and now available in the classpath
container and if user chose to delete then the files are removed from the project.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira