GetArtifactoryVersions
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class GetArtifactoryVersions {
public static void main(String[] args) throws XMLStreamException {
try {
JSONObject countryObj = new JSONObject();
JSONArray listOfVersions = new JSONArray();
URL url=null;
url = new URL("https://artifactory.corp.com/release-local/com/test/"+args[0]+"/maven-metadata.xml");
XMLStreamReader reader1 = XMLInputFactory.newInstance().createXMLStreamReader(url.openStream());
String version = null;
String[] arr = new String[100];
int i=0;
while (reader1.hasNext()) {
if (reader1.next() == XMLStreamConstants.START_ELEMENT) {
if (reader1.getLocalName().equals("version")) {
version = reader1.getElementText();
if (i > 0) {
System.out.println(version);
arr[i] = version;
}
i++;
}
}
}
for (int j = arr.length - 1; j >= 0; j--) {
if (arr[j] != null) {
JSONObject test = new JSONObject();
test.put("version", arr[j]);
test.put("isMetadata", false);
listOfVersions.add(test);
}
}
countryObj.put("data", listOfVersions);
System.out.print(countryObj);
ObjectMapper mapper = new ObjectMapper();
try {
File file=new File(args[0]+".json");
file.createNewFile();
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(mapper.defaultPrettyPrintingWriter().writeValueAsString(countryObj));
fileWriter.flush();
fileWriter.close();
}
catch (JsonGenerationException e)
{
e.printStackTrace();
}
catch (JsonMappingException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
} catch (IOException ex) {
// handle exception
ex.printStackTrace();
} catch (XMLStreamException ex) {
// handle exception
ex.printStackTrace();
} finally {
// close the stream
}
}
}
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
public class GetArtifactoryVersions {
public static void main(String[] args) throws XMLStreamException {
try {
JSONObject countryObj = new JSONObject();
JSONArray listOfVersions = new JSONArray();
URL url=null;
url = new URL("https://artifactory.corp.com/release-local/com/test/"+args[0]+"/maven-metadata.xml");
XMLStreamReader reader1 = XMLInputFactory.newInstance().createXMLStreamReader(url.openStream());
String version = null;
String[] arr = new String[100];
int i=0;
while (reader1.hasNext()) {
if (reader1.next() == XMLStreamConstants.START_ELEMENT) {
if (reader1.getLocalName().equals("version")) {
version = reader1.getElementText();
if (i > 0) {
System.out.println(version);
arr[i] = version;
}
i++;
}
}
}
for (int j = arr.length - 1; j >= 0; j--) {
if (arr[j] != null) {
JSONObject test = new JSONObject();
test.put("version", arr[j]);
test.put("isMetadata", false);
listOfVersions.add(test);
}
}
countryObj.put("data", listOfVersions);
System.out.print(countryObj);
ObjectMapper mapper = new ObjectMapper();
try {
File file=new File(args[0]+".json");
file.createNewFile();
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(mapper.defaultPrettyPrintingWriter().writeValueAsString(countryObj));
fileWriter.flush();
fileWriter.close();
}
catch (JsonGenerationException e)
{
e.printStackTrace();
}
catch (JsonMappingException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
} catch (IOException ex) {
// handle exception
ex.printStackTrace();
} catch (XMLStreamException ex) {
// handle exception
ex.printStackTrace();
} finally {
// close the stream
}
}
}
Comments
Post a Comment