]
Lincoln Baxter III closed SEAMFORGE-26.
---------------------------------------
Facets & Plugins need a way of determining the most current
available version of a dependency
---------------------------------------------------------------------------------------------
Key: SEAMFORGE-26
URL:
https://issues.jboss.org/browse/SEAMFORGE-26
Project: Seam Forge
Issue Type: Feature Request
Components: Plugin API
Affects Versions: 1.0.0.Alpha1
Reporter: Lincoln Baxter III
Assignee: Lincoln Baxter III
Fix For: 1.0.0.Alpha2
Right now, there is no good way of inspecting Dependency repositories for available
versions of a given artifact. For example:
=================================================
public class DataProcessor
{
@Inject
private HttpClient client;
/**
* @param client the client to set
*/
void setClient(HttpClient client)
{
this.client = client;
}
public <T> T process(URL url, final ContentHandler<T> handler)
{
HttpGet get = new HttpGet(url.toExternalForm());
try
{
return client.execute(get, new ResponseHandler<T>()
{
@Override
public T handleResponse(HttpResponse response) throws
ClientProtocolException, IOException
{
StringBuilder content = new StringBuilder();
BufferedReader in = new BufferedReader(new
InputStreamReader(response.getEntity().getContent()));
String line;
while( (line = in.readLine()) != null)
{
content.append(line);
}
in.close();
return handler.proces(content.toString());
}
});
}
catch (Exception e)
{
throw new RuntimeException(e);
}
}
public interface ContentHandler<T>
{
T proces(String content);
}
}
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.seam.forge.arquillian.util;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
/**
* HttpClientProducer
*
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
* @version $Revision: $
*/
public class HttpClientProducer
{
@Produces @Dependent
public HttpClient createClient()
{
return new DefaultHttpClient();
}
public void destroyClient(@Disposes HttpClient client)
{
}
}
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.seam.forge.arquillian.util;
import java.net.URL;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
/**
* VersionsProducer
*
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
* @version $Revision: $
*/
public class VersionsProducer
{
@Inject
private DataProcessor processor;
@Produces @ApplicationScoped
public List<String> fetchVersions() throws Exception
{
return processor.process(
new
URL("http://repository.jboss.org/nexus/content/groups/public/org/jbo...,
new ExtractVersionNumber());
}
}
/*
* JBoss, Home of Professional Open Source
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jboss.seam.forge.arquillian.util;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* ExtractVersionNumber
*
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
* @version $Revision: $
*/
public class ExtractVersionNumber implements
DataProcessor.ContentHandler<List<String>>
{
/* (non-Javadoc)
* @see
org.jboss.seam.forge.arquillian.util.DataProcessor.ContentHandler#proces(java.lang.String)
*/
@Override
public List<String> proces(String content)
{
List<String> versions = new ArrayList<String>();
try
{
Pattern pattern =
Pattern.compile("<a\\b[^>]*href=\"[^>]*>(.*?)/</a>");
Matcher matcher = pattern.matcher(content);
int mIdx = 0;
while (matcher.find())
{
mIdx++;
if(mIdx == 1)
{
continue;
}
String rawVersion = matcher.group(1);
if(include(rawVersion))
{
versions.add(rawVersion);
}
}
}
catch (Exception e)
{
throw new RuntimeException("Could not extract version numbers", e);
}
return versions;
}
/**
* @param rawVersion
* @return
*/
private boolean include(String rawVersion)
{
return !rawVersion.matches(".*(SP1|SP2|SP3|OSGi).*");
}
}
--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: