From 8ac0faa2b83dde165d45ab62c932ba0f26f42e54 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 6 Dec 2012 08:58:12 +0100 Subject: o Adding support for new release events. --- .../io/trygvis/esper/testing/nexus/NexusDao.java | 20 +++++++++- .../esper/testing/nexus/NexusFeedParser.java | 44 +++++++++++++++++++--- .../trygvis/esper/testing/nexus/NexusImporter.java | 38 ++++++++++--------- src/main/resources/ddl-nexus.sql | 9 ++++- .../esper/testing/nexus/TestXmlParsing.java | 24 +++++++++++- .../resources/nexus/recentlyDeployedArtifacts.xml | 26 +++++++++++++ 6 files changed, 133 insertions(+), 28 deletions(-) (limited to 'src') 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 ."); + return null; + } + if (creator.isNone()) { + System.out.println("Missing ."); + return null; + } + if (date.isNone()) { + System.out.println("Missing "); 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 buildNumber = parseInt.f(matcher.group(3)); + + if(buildNumber.isNone()) { + System.out.println("Could not parse build number: " + matcher.group(3)); + return none(); + } + return Option.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.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 classifier, String creator, DateTime date, String snapshotTimestamp, URI url) { + NewSnapshotEvent(String guid, ArtifactId artifactId, Option 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 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> serverManager = new ObjectManager<>("Nexus server", Collections.emptySet(), new ObjectFactory>() { public ActorRef create(NexusServerDto server) { @@ -104,28 +104,32 @@ class NexusServer implements TransactionalActor { Option a = dao.findArtifact(repository.uuid, event.artifactId); - if(event instanceof NewSnapshotEvent) { - NewSnapshotEvent newSnapshotEvent = (NewSnapshotEvent) event; + UUID uuid; - Option 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 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()); } } diff --git a/src/main/resources/ddl-nexus.sql b/src/main/resources/ddl-nexus.sql index 1f7514f..7f84dac 100755 --- a/src/main/resources/ddl-nexus.sql +++ b/src/main/resources/ddl-nexus.sql @@ -38,17 +38,22 @@ CREATE TABLE nexus_event ( uuid CHAR(36) NOT NULL, artifact CHAR(36) NOT NULL, timestamp VARCHAR(100), + +-- From the RSS guid VARCHAR(1000), +-- Our type flag type VARCHAR(100) NOT NULL, -- new snapshot event - snapshot_timestamp VARCHAR(1000), + snapshot_timestamp TIMESTAMP, + build_number INT, file VARCHAR(1000), + who VARCHAR(1000), CONSTRAINT pk_nexus_event PRIMARY KEY (uuid), CONSTRAINT fk_nexus_artifact FOREIGN KEY (artifact) REFERENCES nexus_artifact (uuid), CONSTRAINT uq_guid UNIQUE (guid), - CONSTRAINT check_event_type CHECK (type IN ('new_snapshot')) + CONSTRAINT check_event_type CHECK (type IN ('new_snapshot', 'new_release')) -- CONSTRAINT pk_nexus_event PRIMARY KEY (timestamp, server_url, repository_id, group_id, artifact_id, version) ); diff --git a/src/test/java/io/trygvis/esper/testing/nexus/TestXmlParsing.java b/src/test/java/io/trygvis/esper/testing/nexus/TestXmlParsing.java index 038de34..8382fd3 100755 --- a/src/test/java/io/trygvis/esper/testing/nexus/TestXmlParsing.java +++ b/src/test/java/io/trygvis/esper/testing/nexus/TestXmlParsing.java @@ -53,14 +53,34 @@ public class TestXmlParsing extends TestCase { try (InputStream stream = getClass().getResourceAsStream("/nexus/recentlyDeployedArtifacts.xml")) { Document document = parser.parseDocument(stream).some(); - NexusEvent event = NexusFeedParser.parseEvent(document.getRootElement().getChild("channel").getChild("item")).some(); + List items = document.getRootElement().getChild("channel").getChildren("item"); + NexusEvent event = NexusFeedParser.parseEvent(items.get(0)).some(); assertTrue(event instanceof NewSnapshotEvent); NewSnapshotEvent nse = (NewSnapshotEvent) event; assertEquals("org.example", nse.artifactId.groupId); assertEquals("example", nse.artifactId.artifactId); assertEquals("1.0-SNAPSHOT", nse.artifactId.version); - assertEquals("20121204.122640-536", nse.snapshotTimestamp); + assertEquals("20121204.122640", nse.snapshotTimestamp); + assertEquals("536", nse.buildNumber); + + event = NexusFeedParser.parseEvent(items.get(1)).some(); + assertTrue(event instanceof NewSnapshotEvent); + nse = (NewSnapshotEvent) event; + assertEquals("org.example", nse.artifactId.groupId); + assertEquals("example", nse.artifactId.artifactId); + assertEquals("1.0-SNAPSHOT", nse.artifactId.version); + assertEquals("20121204.122640", nse.snapshotTimestamp); + assertEquals("536", nse.buildNumber); + + event = NexusFeedParser.parseEvent(items.get(2)).some(); + assertTrue(event instanceof NewReleaseEvent); + NewReleaseEvent nre = (NewReleaseEvent) event; + assertEquals("org.example", nre.artifactId.groupId); + assertEquals("example", nre.artifactId.artifactId); + assertEquals("1.10", nre.artifactId.version); + + assertEquals(3, items.size()); } } } diff --git a/src/test/resources/nexus/recentlyDeployedArtifacts.xml b/src/test/resources/nexus/recentlyDeployedArtifacts.xml index 1fe22d9..c1751dc 100755 --- a/src/test/resources/nexus/recentlyDeployedArtifacts.xml +++ b/src/test/resources/nexus/recentlyDeployedArtifacts.xml @@ -7,6 +7,7 @@ Tue, 04 Dec 2012 12:26:41 GMT Nexus 1.9.2.3 2012-12-04T12:26:41Z + org.example:example:1.0-20121204.122640-536 http://hostname/repository/content/repositories/snapshots/org/example/example/1.0-SNAPSHOT/example-1.0-20121204.122640-536.pom @@ -20,5 +21,30 @@ developer 2012-12-04T12:26:40Z + + + org.example:example:1.0-20121204.122640-536:tests + http://hostname/repository/content/repositories/snapshots/org/example/example/1.0-SNAPSHOT/example-1.0-20121204.122640-536-tests.jar + + The artifact 'org.example:example:1.0-20121204.122640-536:tests' in repository 'Snapshots' was + deployed.Action was initiated by user "developer". + Request originated from IP address 1.2.3.4. + + Tue, 04 Dec 2012 12:26:40 GMT + http://hostname/repository/content/repositories/snapshots/org/example/example/1.0-SNAPSHOT/example-1.0-20121204.122640-536:tests.jar + developer + 2012-12-04T12:26:40Z + + + + org.example:example:1.10 + http://hostname/repository/content/repositories/releases/org/example/example/1.10/example-1.10.pom + The artifact 'org.example:example:1.10' in repository 'Releases' was deployed.Action was initiated by user "foo". + Request originated from IP address 172.21.3.60. + Wed, 05 Dec 2012 13:33:47 GMT + http://hostname/repository/content/repositories/releases/org/example/example/1.10/example-1.10.pom + foo + 2012-12-05T13:33:47Z + -- cgit v1.2.3