Skip to content

Commit

Permalink
Made plugin search more specificly for the artifacts, removed unused …
Browse files Browse the repository at this point in the history
…code, added some more info to the most common error message, added ignore of DS_Store and made the plugin ignore inherited polopoly.version property when printing supported version.
  • Loading branch information
ssprang committed Jan 27, 2014
1 parent bf2a78a commit e374b7f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ target/
.settings/
.classpath
.project
.DS_Store
amps-standalone
23 changes: 8 additions & 15 deletions src/main/java/com/atex/confluence/plugin/nexus/MavenInfoMacro.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;

import javax.servlet.http.HttpServletRequest;

Expand Down Expand Up @@ -242,7 +241,8 @@ private String getPluginMetaDataTable(String groupId, String artifactId, String
result.append("</div>");
result.append("{html}");
} else {
result.append("{warning}Metadata model not available{warning}");
result.append("{warning}Metadata model not available through search{warning}");
result.append(String.format("{html}<p style='color: #666;font-size: .9em;'>For debugging purposes, search URL: %s </p>{html}", metadataManager.getSearchURI(groupId, artifactId)));
}
} catch (AddressNotFoundException e) {
result.append("{warning}Please make sure the Nexus url is correctly configured{warning}");
Expand Down Expand Up @@ -282,18 +282,6 @@ private String getCIEnv(CiManagement cim) {
return result.toString();
}

private String getVersions(ExtendedModel model) {
StringBuilder builder = new StringBuilder();
for(Artifact a: model.getArtifacts()) {
if(builder.length() != 0) {
builder.append("\n");
}
builder.append(a.getVersion());
}

return builder.toString();
}

/**
* This method gather all releases from the artifact and generate the code of a drop down field at front end.
* @param model
Expand Down Expand Up @@ -574,7 +562,12 @@ private String readSpecificDependencyVersion(List<Dependency> dependencies, Stri
if (artifactId!=null && !artifactId.isEmpty()) {
for (Dependency dependency: dependencies) {
if (artifactId.trim().equalsIgnoreCase(dependency.getArtifactId().trim())) {
return dependency.getVersion().trim();
//This results in e.g. ${polopoly.version} if read from parent
String dependencyVersion = dependency.getVersion().trim();
if (!org.apache.commons.lang.StringUtils.isBlank(dependencyVersion)
&& !dependencyVersion.startsWith("$")) {
return dependencyVersion;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
Expand Down Expand Up @@ -52,20 +53,10 @@ public MetadataManager(Configuration configuration) {
* @throws IOException when search failed
*/
public List<ExtendedModel> getMetadatas(String groupId) throws IOException {
Response result = getResponse(groupId);
Response result = getResponse(groupId, null);
return getPoms(result.getLatestReleases(), result.getRepositories());
}

/**
* Search maven model based on artifactId using default groupId
* @param artifactId of the maven to be search
* @return model of the maven, else null when not found
* @throws IOException when search failed
*/
// public Model getMetadata(String artifactId) throws IOException {
// return getMetadata(null, artifactId);
// }

/**
* Search maven model based on groupId and artifactId
* @param groupId of the artifacts to be search
Expand All @@ -75,7 +66,7 @@ public List<ExtendedModel> getMetadatas(String groupId) throws IOException {
* @throws IOException when search failed
*/
public ExtendedModel getMetadata(String groupId, String artifactId, String version) throws IOException {
Response result = getResponse(groupId);
Response result = getResponse(groupId, artifactId);
Artifact artifact = result.getByArtifactId(artifactId);
if(artifact == null) {
return null;
Expand All @@ -91,7 +82,6 @@ public ExtendedModel getMetadata(String groupId, String artifactId, String versi
}
}


public List<Repository> getRepositories() throws IOException, ParserConfigurationException, SAXException {
List<Repository> repositories = new ArrayList<Repository>();
HttpMethod get = doGetHttpMethod(configuration.getSearchRepositoriesURI());
Expand All @@ -109,16 +99,23 @@ public List<Repository> getRepositories() throws IOException, ParserConfiguratio
}
return repositories;
}

private synchronized Response getResponse(String groupId) throws IOException {

private synchronized Response getResponse(String groupId, String artifactId) throws IOException {
HttpMethod get = doGetHttpMethod(getSearchURI(groupId, artifactId));
return parseInputStreamToResponse(get.getResponseBodyAsStream());
}

public synchronized String getSearchURI(String groupId, String artifactId) {
if(groupId == null || groupId.trim().isEmpty()) {
groupId = configuration.getGroupId();
}

HttpMethod get = doGetHttpMethod(configuration.getSearchURI() + "?g=" + groupId);
return parseInputStreamToResponse(get.getResponseBodyAsStream());
String searchURI = configuration.getSearchURI() + "?g=" + groupId;
if(!StringUtils.isBlank(artifactId)) {
searchURI = searchURI + "&a=" + artifactId.trim();
}
return searchURI;
}

private Response parseInputStreamToResponse(InputStream inputStream) {
Response response = new Response();
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
Expand All @@ -144,15 +141,15 @@ private Response parseInputStreamToResponse(InputStream inputStream) {
}
return response;
}

private Repository getRepository(Element el) {
Repository repository = new Repository();
repository.setRepositoryId(getTextValue(el, "id"));
repository.setRepositoryURL(getTextValue(el, "contentResourceURI"));

return repository;
}

private Artifact getArtifact(Element el) {
Artifact artifact = new Artifact();
artifact.setGroupId(getTextValue(el, "groupId"));
Expand All @@ -165,7 +162,7 @@ private Artifact getArtifact(Element el) {

return artifact;
}

private String getTextValue(Element ele, String tagName) {
String textVal = null;
NodeList nl = ele.getElementsByTagName(tagName);
Expand All @@ -175,7 +172,7 @@ private String getTextValue(Element ele, String tagName) {
}
return textVal;
}

private List<ExtendedModel> getPoms(List<Artifact> artifacts, List<Repository> repositories) throws IOException {
List<ExtendedModel> poms = new ArrayList<ExtendedModel>();
for(Artifact artifact: artifacts) {
Expand Down Expand Up @@ -232,7 +229,6 @@ private List<ExtendedModel> getPoms(List<Artifact> artifacts, List<Repository> r
return poms;
}


private HttpMethod doGetHttpMethod(String url) throws IOException {
HttpMethod get = new GetMethod(url);
HttpClient client = new HttpClient();
Expand All @@ -253,18 +249,6 @@ private HttpMethod doGetHttpMethod(String url) throws IOException {
return get;
}

private String getUrl(Artifact artifact, List<Repository> repositories) {
String groupIdPath = artifact.getGroupId().replace(".", "/");
String url = "/" + groupIdPath + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + ".pom";
for(Repository repository: repositories) {
if(repository.getRepositoryId().equals(artifact.getLatestReleaseRepositoryId())) {
url = repository.getRepositoryURL() + url;
break;
}
}
return url;
}

/**
* This method get the url of the specific version/release of the plugin.
* Url of latest version will be return if version is null or empty.
Expand Down

0 comments on commit e374b7f

Please sign in to comment.