aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/trygvis/esper/testing/nexus
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-12-06 08:58:12 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2012-12-07 20:06:57 +0100
commit8ac0faa2b83dde165d45ab62c932ba0f26f42e54 (patch)
tree6f5656e783c5bb9de425e718690732ce796b5603 /src/main/java/io/trygvis/esper/testing/nexus
parent1c2c16858e95db9ae90726fa0da69b88457c1807 (diff)
downloadesper-testing-8ac0faa2b83dde165d45ab62c932ba0f26f42e54.tar.gz
esper-testing-8ac0faa2b83dde165d45ab62c932ba0f26f42e54.tar.bz2
esper-testing-8ac0faa2b83dde165d45ab62c932ba0f26f42e54.tar.xz
esper-testing-8ac0faa2b83dde165d45ab62c932ba0f26f42e54.zip
o Adding support for new release events.
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/nexus')
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/nexus/NexusDao.java20
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/nexus/NexusFeedParser.java44
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java38
3 files changed, 78 insertions, 24 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/nexus/NexusDao.java b/src/main/java/io/trygvis/esper/testing/nexus/NexusDao.java
index cb93a63..d8d013c 100755
--- a/src/main/java/io/trygvis/esper/testing/nexus/NexusDao.java
+++ b/src/main/java/io/trygvis/esper/testing/nexus/NexusDao.java
@@ -173,8 +173,8 @@ public class NexusDao {
// }
// }
- public UUID insertNewSnapshotEvent(UUID artifact, String guid, String file, String snapshotTimestamp) throws SQLException {
- try(PreparedStatement s = c.prepareStatement("INSERT INTO nexus_event(uuid, artifact, timestamp, guid, type, snapshot_timestamp, file) VALUES(?, ?, ?, ?, ?, ?, ?)")) {
+ public UUID insertNewSnapshotEvent(UUID artifact, String guid, String snapshotTimestamp, int buildNumber, String file) throws SQLException {
+ try(PreparedStatement s = c.prepareStatement("INSERT INTO nexus_event(uuid, artifact, timestamp, guid, type, snapshot_timestamp, build_number, file) VALUES(?, ?, ?, ?, ?, ?, ?, ?)")) {
UUID uuid = UUID.randomUUID();
int i = 1;
s.setString(i++, uuid.toString());
@@ -183,6 +183,22 @@ public class NexusDao {
s.setString(i++, guid);
s.setString(i++, "new_snapshot");
s.setString(i++, snapshotTimestamp);
+ s.setInt(i++, buildNumber);
+ s.setString(i, file);
+ s.executeUpdate();
+ return uuid;
+ }
+ }
+
+ public UUID insertNewReleaseEvent(UUID artifact, String guid, String file) throws SQLException {
+ try(PreparedStatement s = c.prepareStatement("INSERT INTO nexus_event(uuid, artifact, timestamp, guid, type, file) VALUES(?, ?, ?, ?, ?, ?)")) {
+ UUID uuid = UUID.randomUUID();
+ int i = 1;
+ s.setString(i++, uuid.toString());
+ s.setString(i++, artifact.toString());
+ s.setTimestamp(i++, new Timestamp(currentTimeMillis()));
+ s.setString(i++, guid);
+ s.setString(i++, "new_release");
s.setString(i, file);
s.executeUpdate();
return uuid;
diff --git a/src/main/java/io/trygvis/esper/testing/nexus/NexusFeedParser.java b/src/main/java/io/trygvis/esper/testing/nexus/NexusFeedParser.java
index d85803f..3d27436 100755
--- a/src/main/java/io/trygvis/esper/testing/nexus/NexusFeedParser.java
+++ b/src/main/java/io/trygvis/esper/testing/nexus/NexusFeedParser.java
@@ -78,21 +78,44 @@ public class NexusFeedParser {
return null;
}
- if (guid.isNone() || creator.isNone() || date.isNone()) {
+ if (guid.isNone()) {
+ System.out.println("Missing <guid>.");
+ return null;
+ }
+ if (creator.isNone()) {
+ System.out.println("Missing <dc:creator>.");
+ return null;
+ }
+ if (date.isNone()) {
+ System.out.println("Missing <dc:date>");
return null;
}
- Pattern regexp = Pattern.compile("(.*)-([0-9]{8}\\.[0-9]{6}-[0-9]*)$");
+ Pattern regexp = Pattern.compile("(.*)-([0-9]{8}\\.[0-9]{6})-([0-9]*)$");
Matcher matcher = regexp.matcher(version);
if (matcher.matches()) {
ArtifactId id = new ArtifactId(groupId, artifactId, matcher.group(1) + "-SNAPSHOT");
+ Option<Integer> buildNumber = parseInt.f(matcher.group(3));
+
+ if(buildNumber.isNone()) {
+ System.out.println("Could not parse build number: " + matcher.group(3));
+ return none();
+ }
+
return Option.<NexusEvent>some(new NewSnapshotEvent(guid.some(), id, classifier, creator.some(),
- date.some(), matcher.group(2), URI.create(item.getChildText("link"))));
+ date.some(), matcher.group(2), buildNumber.some(), URI.create(item.getChildText("link"))));
+ } else {
+ ArtifactId id = new ArtifactId(groupId, artifactId, version);
+
+ return Option.<NexusEvent>some(new NewReleaseEvent(guid.some(), id, classifier, creator.some(),
+ date.some(), URI.create(item.getChildText("link"))));
}
- return none();
+// System.out.println("Unknown event type.");
+//
+// return none();
}
}
@@ -122,11 +145,22 @@ abstract class NexusEvent {
class NewSnapshotEvent extends NexusEvent {
public final String snapshotTimestamp;
+ public final int buildNumber;
public final URI url;
- NewSnapshotEvent(String guid, ArtifactId artifactId, Option<String> classifier, String creator, DateTime date, String snapshotTimestamp, URI url) {
+ NewSnapshotEvent(String guid, ArtifactId artifactId, Option<String> classifier, String creator, DateTime date, String snapshotTimestamp, int buildNumber, URI url) {
super(guid, artifactId, classifier, creator, date);
this.snapshotTimestamp = snapshotTimestamp;
+ this.buildNumber = buildNumber;
+ this.url = url;
+ }
+}
+
+class NewReleaseEvent extends NexusEvent {
+ public final URI url;
+
+ NewReleaseEvent(String guid, ArtifactId artifactId, Option<String> classifier, String creator, DateTime date, URI url) {
+ super(guid, artifactId, classifier, creator, date);
this.url = url;
}
}
diff --git a/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java b/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java
index 8e49074..3d0aaf0 100755
--- a/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java
+++ b/src/main/java/io/trygvis/esper/testing/nexus/NexusImporter.java
@@ -21,7 +21,7 @@ public class NexusImporter {
final XmlParser xmlParser = new XmlParser();
final BoneCPDataSource boneCp = config.createBoneCp();
- XmlParser.debugXml = true;
+ XmlParser.debugXml = false;
ObjectManager<NexusServerDto, ActorRef<NexusServer>> serverManager = new ObjectManager<>("Nexus server", Collections.<NexusServerDto>emptySet(), new ObjectFactory<NexusServerDto, ActorRef<NexusServer>>() {
public ActorRef<NexusServer> create(NexusServerDto server) {
@@ -104,28 +104,32 @@ class NexusServer implements TransactionalActor {
Option<ArtifactDto> a = dao.findArtifact(repository.uuid, event.artifactId);
- if(event instanceof NewSnapshotEvent) {
- NewSnapshotEvent newSnapshotEvent = (NewSnapshotEvent) event;
+ UUID uuid;
- Option<String> snapshotTimestamp = Option.some(newSnapshotEvent.snapshotTimestamp);
+ if(a.isNone()) {
+ System.out.println("New artifact: " + event.artifactId);
+ uuid = dao.insertArtifact(repository.uuid, event.artifactId);
+ }
+ else {
+ ArtifactDto artifact = a.some();
- UUID uuid;
+ System.out.println("Updated artifact: " + event.artifactId);
+// dao.updateSnapshotTimestamp(artifact.uuid, newSnapshotEvent.snapshotTimestamp);
- if(a.isNone()) {
- System.out.println("New artifact: " + event.artifactId);
- List<ArtifactFile> files = Collections.emptyList();
- uuid = dao.insertArtifact(repository.uuid, event.artifactId);
- }
- else {
- ArtifactDto artifact = a.some();
+ uuid = artifact.uuid;
+ }
- System.out.println("Updated artifact: " + event.artifactId);
-// dao.updateSnapshotTimestamp(artifact.uuid, newSnapshotEvent.snapshotTimestamp);
+ if (event instanceof NewSnapshotEvent) {
+ NewSnapshotEvent newSnapshotEvent = (NewSnapshotEvent) event;
- uuid = artifact.uuid;
- }
+ dao.insertNewSnapshotEvent(uuid, event.guid, newSnapshotEvent.snapshotTimestamp,
+ newSnapshotEvent.buildNumber, newSnapshotEvent.url.toASCIIString());
+ } else if (event instanceof NewReleaseEvent) {
+ NewReleaseEvent nre = (NewReleaseEvent) event;
- dao.insertNewSnapshotEvent(uuid, event.guid, newSnapshotEvent.url.toASCIIString(), newSnapshotEvent.snapshotTimestamp);
+ dao.insertNewReleaseEvent(uuid, event.guid, nre.url.toASCIIString());
+ } else {
+ System.out.println("Unknown event type: " + event.getClass().getName());
}
}