List of usage examples for org.apache.maven.artifact.versioning DefaultArtifactVersion getBuildNumber
public int getBuildNumber()
From source file:org.abstracthorizon.proximity.maven.MavenItemInspector.java
License:Apache License
public void processItem(ItemProperties ip, File file) { if (MavenArtifactRecognizer.isPom(ip.getName())) { if (!MavenArtifactRecognizer.isChecksum(ip.getName())) { ip.setMetadata(M2KIND, KIND_POM); try { MavenXpp3Reader reader = new MavenXpp3Reader(); FileInputStream fis = new FileInputStream(file); InputStreamReader ir = new InputStreamReader(fis); Model pom = null;//from w ww . ja va 2 s .c o m try { pom = reader.read(ir); ir.close(); } finally { fis.close(); } if (pom.getGroupId() != null) { ip.setMetadata(POM_GID_KEY, pom.getGroupId()); } else { if (pom.getParent().getGroupId() != null) { ip.setMetadata(POM_GID_KEY, pom.getParent().getGroupId()); } } if (pom.getArtifactId() != null) { ip.setMetadata(POM_AID_KEY, pom.getArtifactId()); } if (pom.getPackaging() != null) { ip.setMetadata(POM_PCK_KEY, pom.getPackaging()); } if (pom.getVersion() != null) { ip.setMetadata(POM_VERSION_KEY, pom.getVersion()); } else { if (pom.getParent().getVersion() != null) { ip.setMetadata(POM_VERSION_KEY, pom.getParent().getVersion()); } } if (ip.getMetadata(POM_VERSION_KEY) != null) { DefaultArtifactVersion af = new DefaultArtifactVersion(ip.getMetadata(POM_VERSION_KEY)); ip.setMetadata(POM_VERSION_MAJOR_KEY, Integer.toString(af.getMajorVersion())); ip.setMetadata(POM_VERSION_MINOR_KEY, Integer.toString(af.getMinorVersion())); ip.setMetadata(POM_VERSION_INCREMENTAL_KEY, Integer.toString(af.getIncrementalVersion())); ip.setMetadata(POM_VERSION_BUILDNUM_KEY, Integer.toString(af.getBuildNumber())); // do not put null if (af.getQualifier() != null) { ip.setMetadata(POM_VERSION_QUALIFIER_KEY, af.getQualifier()); } } if (pom.getUrl() != null) { ip.setMetadata(POM_URL_KEY, pom.getUrl()); } if (pom.getDescription() != null) { ip.setMetadata(POM_DESCRIPTION_KEY, pom.getDescription()); } if (pom.getParent() != null) { StringBuffer parent = new StringBuffer(); parent.append(pom.getParent().getGroupId()); parent.append(":"); parent.append(pom.getParent().getArtifactId()); if (pom.getParent().getVersion() != null) { parent.append(":"); parent.append(pom.getParent().getVersion()); } ip.setMetadata(POM_PARENT_KEY, parent.toString()); } if (pom.getDependencies() != null) { StringBuffer deps = new StringBuffer(); for (Iterator i = pom.getDependencies().iterator(); i.hasNext();) { Dependency dep = (Dependency) i.next(); deps.append(dep.getGroupId()); deps.append(":"); deps.append(dep.getArtifactId()); // TODO: version ranges? if (dep.getVersion() != null && !(dep.getVersion().indexOf("[") > 0) && !(dep.getVersion().indexOf("(") > 0)) { deps.append(":"); deps.append(dep.getVersion()); } deps.append("\n"); } ip.setMetadata(POM_DEPENDENCIES_KEY, deps.toString()); } } catch (XmlPullParserException ex) { logger.warn("Got XmlPullParserException during reading POM, content will not be indexed on " + ip.getPath(), ex); } catch (IOException ex) { logger.error( "Got IOException during reading POM, content will not be indexed on " + ip.getPath(), ex); } } } else if (MavenArtifactRecognizer.isMetadata(ip.getName())) { ip.setMetadata(M2KIND, KIND_METADATA); } else if (MavenArtifactRecognizer.isSnapshot(ip.getDirectoryPath(), ip.getName())) { ip.setMetadata(M2KIND, KIND_SNAPSHOT); } }