Permalink
Browse files

HUDSON-8890: generic Service API for projects, builds, etc.

  • Loading branch information...
1 parent 9165d37 commit 0bbe2c45c6d61efe47043212299eac36d993cbff @mcculls committed Jun 10, 2011
Showing with 5,891 additions and 0 deletions.
  1. +126 −0 hudson-core/src/main/java/hudson/stapler/WebAppController.java
  2. +67 −0 hudson-service/pom.xml
  3. +38 −0 hudson-service/src/main/java/org/hudsonci/events/EventConsumer.java
  4. +43 −0 hudson-service/src/main/java/org/hudsonci/events/EventPublisher.java
  5. +51 −0 hudson-service/src/main/java/org/hudsonci/events/internal/DiagnosticEventConsumer.java
  6. +87 −0 hudson-service/src/main/java/org/hudsonci/events/internal/EventPublisherImpl.java
  7. +124 −0 hudson-service/src/main/java/org/hudsonci/events/ready/ReadyDetector.java
  8. +66 −0 hudson-service/src/main/java/org/hudsonci/events/ready/ReadyDetectorStarter.java
  9. +47 −0 hudson-service/src/main/java/org/hudsonci/events/ready/ReadyEvent.java
  10. +44 −0 hudson-service/src/main/java/org/hudsonci/service/BuildNotFoundException.java
  11. +146 −0 hudson-service/src/main/java/org/hudsonci/service/BuildService.java
  12. +48 −0 hudson-service/src/main/java/org/hudsonci/service/DependencyGraphService.java
  13. +52 −0 hudson-service/src/main/java/org/hudsonci/service/DescriptorService.java
  14. +40 −0 hudson-service/src/main/java/org/hudsonci/service/NodeNotFoundException.java
  15. +95 −0 hudson-service/src/main/java/org/hudsonci/service/NodeService.java
  16. +59 −0 hudson-service/src/main/java/org/hudsonci/service/NotFoundException.java
  17. +47 −0 hudson-service/src/main/java/org/hudsonci/service/ProjectNotFoundException.java
  18. +176 −0 hudson-service/src/main/java/org/hudsonci/service/ProjectService.java
  19. +48 −0 hudson-service/src/main/java/org/hudsonci/service/QueueService.java
  20. +46 −0 hudson-service/src/main/java/org/hudsonci/service/ScriptService.java
  21. +93 −0 hudson-service/src/main/java/org/hudsonci/service/SecurityService.java
  22. +51 −0 hudson-service/src/main/java/org/hudsonci/service/ServiceRuntimeException.java
  23. +51 −0 hudson-service/src/main/java/org/hudsonci/service/SystemIntegrityViolationException.java
  24. +106 −0 hudson-service/src/main/java/org/hudsonci/service/SystemService.java
  25. +141 −0 hudson-service/src/main/java/org/hudsonci/service/internal/BuildServiceImpl.java
  26. +69 −0 hudson-service/src/main/java/org/hudsonci/service/internal/DependencyGraphServiceImpl.java
  27. +79 −0 hudson-service/src/main/java/org/hudsonci/service/internal/DescriptorServiceImpl.java
  28. +393 −0 hudson-service/src/main/java/org/hudsonci/service/internal/DummyStaplerRequest.java
  29. +217 −0 hudson-service/src/main/java/org/hudsonci/service/internal/DummyStaplerResponse.java
  30. +119 −0 hudson-service/src/main/java/org/hudsonci/service/internal/NodeServiceImpl.java
  31. +197 −0 hudson-service/src/main/java/org/hudsonci/service/internal/ProjectServiceImpl.java
  32. +61 −0 hudson-service/src/main/java/org/hudsonci/service/internal/QueueServiceImpl.java
  33. +71 −0 hudson-service/src/main/java/org/hudsonci/service/internal/ScriptServiceImpl.java
  34. +128 −0 hudson-service/src/main/java/org/hudsonci/service/internal/SecurityServiceImpl.java
  35. +171 −0 hudson-service/src/main/java/org/hudsonci/service/internal/ServicePreconditions.java
  36. +66 −0 hudson-service/src/main/java/org/hudsonci/service/internal/ServiceSupport.java
  37. +240 −0 hudson-service/src/main/java/org/hudsonci/service/internal/SystemServiceImpl.java
  38. +30 −0 hudson-service/src/main/java/org/hudsonci/service/internal/package-info.java
  39. +47 −0 hudson-service/src/main/java/org/hudsonci/service/package-info.java
  40. +44 −0 hudson-service/src/main/java/org/hudsonci/servlets/ServletContainer.java
  41. +39 −0 hudson-service/src/main/java/org/hudsonci/servlets/ServletContainerAware.java
  42. +132 −0 hudson-service/src/main/java/org/hudsonci/servlets/ServletRegistration.java
  43. +138 −0 hudson-service/src/main/java/org/hudsonci/servlets/internal/ServletContainerImpl.java
  44. +69 −0 hudson-service/src/main/java/org/hudsonci/servlets/internal/ServletContainerStarter.java
  45. +183 −0 hudson-service/src/main/java/org/hudsonci/servlets/internal/ServletRegistrationFilterAdapter.java
  46. +402 −0 hudson-service/src/test/java/org/hudsonci/service/internal/BuildServiceImplTest.java
  47. +65 −0 hudson-service/src/test/java/org/hudsonci/service/internal/DependencyGraphServiceImplTest.java
  48. +73 −0 hudson-service/src/test/java/org/hudsonci/service/internal/DescriptorServiceImplTest.java
  49. +206 −0 hudson-service/src/test/java/org/hudsonci/service/internal/NodeServiceImplTest.java
  50. +378 −0 hudson-service/src/test/java/org/hudsonci/service/internal/ProjectServiceImplTest.java
  51. +80 −0 hudson-service/src/test/java/org/hudsonci/service/internal/QueueServiceImplTest.java
  52. +90 −0 hudson-service/src/test/java/org/hudsonci/service/internal/ScriptServiceImplTest.java
  53. +97 −0 hudson-service/src/test/java/org/hudsonci/service/internal/SecurityServiceImplTest.java
  54. +111 −0 hudson-service/src/test/java/org/hudsonci/service/internal/SystemServiceImplTest.java
  55. +3 −0 hudson-test-utils/pom.xml
  56. +1 −0 pom.xml
@@ -0,0 +1,126 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2011 Sonatype, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package hudson.stapler;
+
+import javax.servlet.ServletContext;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Handles management of the Stapler root "app" object.
+ *
+ * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
+ * @since 2.1.0
+ */
+public class WebAppController {
+
+ private static final Logger log = Logger.getLogger(WebAppController.class.getName());
+ private static final String APP = "app";
+ private InstallStrategy installStrategy;
+ private ServletContext context;
+
+ // Sync everything, this class should not be used often, and needs to ensure consistent state
+ public synchronized ServletContext getContext() {
+ if (context == null) {
+ throw new IllegalStateException();
+ }
+ return context;
+ }
+
+ public synchronized void setContext(final ServletContext context) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+ if (this.context != null) {
+ throw new IllegalStateException();
+ }
+ if (log.isLoggable(Level.FINE)) {
+ log.fine("Context initialized: " + context);
+ }
+ this.context = context;
+ }
+
+ public synchronized InstallStrategy getInstallStrategy() {
+ return installStrategy;
+ }
+
+ public synchronized void setInstallStrategy(final InstallStrategy strategy) {
+ if (strategy == null) {
+ throw new NullPointerException();
+ }
+ if (this.installStrategy != null) {
+ throw new IllegalStateException();
+ }
+ if (log.isLoggable(Level.FINE)) {
+ log.fine("Strategy initialized: " + strategy);
+ }
+ this.installStrategy = strategy;
+ }
+
+ public synchronized void install(final Object app) {
+ if (app == null) {
+ throw new NullPointerException();
+ }
+
+ if (log.isLoggable(Level.FINE)) {
+ log.fine("Attempting to install app: " + app);
+ }
+ if (getInstallStrategy().isAllowed(app)) {
+ getContext().setAttribute(APP, app);
+ } else {
+ log.warning("Strategy denied install");
+ }
+ }
+
+ public synchronized Object current() {
+ return getContext().getAttribute(APP);
+ }
+
+ /**
+ * Strategy to control which object is installed.
+ */
+ public static interface InstallStrategy {
+
+ boolean isAllowed(Object app);
+ }
+
+ /**
+ * Always install the given object.
+ */
+ public static class DefaultInstallStrategy
+ implements InstallStrategy {
+
+ public boolean isAllowed(final Object app) {
+ return true;
+ }
+ }
+ //
+ // Instance access (since there is no DI setup at this point).
+ //
+ private static final WebAppController INSTANCE = new WebAppController();
+
+ public static WebAppController get() {
+ return INSTANCE;
+ }
+}
View
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+The MIT License
+
+Copyright (c) 2010-2011, Sonatype, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jvnet.hudson.main</groupId>
+ <artifactId>hudson</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>hudson-service</artifactId>
+ <name>Hudson :: Service</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jvnet.hudson.main</groupId>
+ <artifactId>hudson-plugin-utils</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jvnet.hudson.main</groupId>
+ <artifactId>hudson-test-utils</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>aspectj-maven-plugin</artifactId>
+ <configuration>
+ <aspectLibraries>
+ <aspectLibrary>
+ <groupId>org.jvnet.hudson.main</groupId>
+ <artifactId>hudson-inject</artifactId>
+ </aspectLibrary>
+ </aspectLibraries>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
@@ -0,0 +1,38 @@
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010-2011 Sonatype, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.hudsonci.events;
+
+import java.util.EventObject;
+
+/**
+ * Provides support for listening to generic events.
+ *
+ * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
+ * @since 2.1.0
+ */
+public interface EventConsumer
+{
+ void consume(EventObject event) throws Exception;
+}
@@ -0,0 +1,43 @@
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010-2011 Sonatype, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.hudsonci.events;
+
+import com.google.inject.ImplementedBy;
+
+import org.hudsonci.events.internal.EventPublisherImpl;
+
+import java.util.EventObject;
+
+/**
+ * Publishes events.
+ *
+ * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
+ * @since 2.1.0
+ */
+@ImplementedBy(EventPublisherImpl.class)
+public interface EventPublisher
+{
+ void publish(EventObject event);
+}
@@ -0,0 +1,51 @@
+/**
+ * The MIT License
+ *
+ * Copyright (c) 2010-2011 Sonatype, Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.hudsonci.events.internal;
+
+import org.hudsonci.events.EventConsumer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import java.util.EventObject;
+
+/**
+ * Adds diagnostic information when an event was published.
+ *
+ * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
+ * @since 2.1.0
+ */
+@Named
+@Singleton
+public class DiagnosticEventConsumer
+ implements EventConsumer
+{
+ private static final Logger log = LoggerFactory.getLogger(DiagnosticEventConsumer.class);
+
+ public void consume(final EventObject event) throws Exception {
+ log.trace("Event published: {}", event);
+ }
+}
Oops, something went wrong.

0 comments on commit 0bbe2c4

Please sign in to comment.