incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1467919 [1/2] - in /sling/trunk/contrib/extensions/muppet: ./ it/ it/src/ it/src/test/ it/src/test/java/ it/src/test/java/org/ it/src/test/java/org/apache/ it/src/test/java/org/apache/sling/ it/src/test/java/org/apache/sling/muppet/ it/src...
Date Mon, 15 Apr 2013 09:52:13 GMT
Author: bdelacretaz
Date: Mon Apr 15 09:52:11 2013
New Revision: 1467919

URL: http://svn.apache.org/r1467919
Log:
SLING-2822 - Muppet - extensible system health checking tool

Added:
    sling/trunk/contrib/extensions/muppet/   (with props)
    sling/trunk/contrib/extensions/muppet/.gitignore
    sling/trunk/contrib/extensions/muppet/README.md
    sling/trunk/contrib/extensions/muppet/it/   (with props)
    sling/trunk/contrib/extensions/muppet/it/pom.xml
    sling/trunk/contrib/extensions/muppet/it/src/
    sling/trunk/contrib/extensions/muppet/it/src/test/
    sling/trunk/contrib/extensions/muppet/it/src/test/java/
    sling/trunk/contrib/extensions/muppet/it/src/test/java/org/
    sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/
    sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/
    sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/
    sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/
    sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/
    sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/AllRulesTest.java
    sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/MuppetOsgiFacadeTest.java
    sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/OsgiRulesTest.java
    sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/U.java
    sling/trunk/contrib/extensions/muppet/muppet-core/   (with props)
    sling/trunk/contrib/extensions/muppet/muppet-core/pom.xml
    sling/trunk/contrib/extensions/muppet/muppet-core/src/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/EvaluationResult.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/Evaluator.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/MuppetFacade.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/Rule.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/RuleBuilder.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/RulesEngine.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/SystemAttribute.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/Activator.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/DefaultRuleBuilder.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/OSGiMuppetFacadeImpl.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/RulesEngineImpl.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/TextRulesParser.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/util/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/util/DefaultEvaluator.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/DefaultEvaluatorTest.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/RuleTest.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/RulesEngineTest.java
    sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/TextRulesParserTest.java
    sling/trunk/contrib/extensions/muppet/muppet-rules/   (with props)
    sling/trunk/contrib/extensions/muppet/muppet-rules/pom.xml
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/rules/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/rules/jmx/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/rules/jmx/JmxBeansRuleBuilder.java
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/rules/osgi/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/rules/osgi/Activator.java
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/rules/osgi/BundlesRuleBuilder.java
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/test/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/test/java/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/test/java/org/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/test/java/org/apache/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/test/java/org/apache/sling/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/test/java/org/apache/sling/muppet/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/test/java/org/apache/sling/muppet/rules/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/test/java/org/apache/sling/muppet/rules/impl/
    sling/trunk/contrib/extensions/muppet/muppet-rules/src/test/java/org/apache/sling/muppet/rules/impl/JmxBeansRuleBuilderTest.java
    sling/trunk/contrib/extensions/muppet/muppet-sling/   (with props)
    sling/trunk/contrib/extensions/muppet/muppet-sling/pom.xml
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/api/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/api/JsonResultRenderer.java
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/api/RulesResourceParser.java
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/JsonResultRendererImpl.java
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/MuppetSlingServlet.java
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/RulesResourceParserImpl.java
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/main/java/org/apache/sling/muppet/sling/impl/rules/LoginRuleBuilder.java
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/MockResolver.java
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/MockResource.java
    sling/trunk/contrib/extensions/muppet/muppet-sling/src/test/java/org/apache/sling/muppet/sling/RulesResourceParserTest.java
    sling/trunk/contrib/extensions/muppet/pom.xml

Propchange: sling/trunk/contrib/extensions/muppet/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Apr 15 09:52:11 2013
@@ -0,0 +1,13 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+
+
+

Added: sling/trunk/contrib/extensions/muppet/.gitignore
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/.gitignore?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/.gitignore (added)
+++ sling/trunk/contrib/extensions/muppet/.gitignore Mon Apr 15 09:52:11 2013
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings/
+target/

Added: sling/trunk/contrib/extensions/muppet/README.md
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/README.md?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/README.md (added)
+++ sling/trunk/contrib/extensions/muppet/README.md Mon Apr 15 09:52:11 2013
@@ -0,0 +1,4 @@
+muppet-prototype
+================
+
+Muppet system state checking/conforming tool prototype
\ No newline at end of file

Propchange: sling/trunk/contrib/extensions/muppet/it/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Apr 15 09:52:11 2013
@@ -0,0 +1,13 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+
+
+

Added: sling/trunk/contrib/extensions/muppet/it/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/it/pom.xml?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/it/pom.xml (added)
+++ sling/trunk/contrib/extensions/muppet/it/pom.xml Mon Apr 15 09:52:11 2013
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>15</version>
+        <relativePath>15</relativePath>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.muppet.it</artifactId>
+    <packaging>jar</packaging>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Muppet Integration Tests</name>
+    <inceptionYear>2013</inceptionYear>
+
+    <properties>
+        <exam.version>3.0.3</exam.version>
+        <url.version>1.5.2</url.version>
+        <org.ops4j.pax.logging.DefaultServiceLog.level>INFO</org.ops4j.pax.logging.DefaultServiceLog.level>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <systemProperties>
+                        <org.ops4j.pax.logging.DefaultServiceLog.level>${org.ops4j.pax.logging.DefaultServiceLog.level}</org.ops4j.pax.logging.DefaultServiceLog.level>
+                        <muppet.core.version>${project.version}</muppet.core.version>
+                    </systemProperties>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.muppet.core</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.muppet.rules</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.6.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <version>1.6.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-native</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-junit4</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-link-mvn</artifactId>
+            <version>${exam.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-aether</artifactId>
+            <version>${url.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>4.2.1</version>
+            <scope>test</scope>
+        </dependency>
+     </dependencies>
+</project>

Added: sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/AllRulesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/AllRulesTest.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/AllRulesTest.java (added)
+++ sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/AllRulesTest.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.it.core;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.apache.sling.muppet.api.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+/** Test our various types of {@link Rule} together */ 
+@RunWith(PaxExam.class)
+public class AllRulesTest {
+    
+    @Inject
+    private MuppetFacade facade;
+    
+    @Configuration
+    public Option[] config() {
+        return U.config(true);
+    }
+    
+    @Test
+    public void testMixOfRules() throws IOException {
+        // There should be at least one rule builder, but not a lot
+        final String [] rules = { 
+            "osgi:bundle.state:org.apache.sling.muppet.core:active",
+            "osgi:bundle.state:some.nonexistenbundle:BUNDLE_NOT_FOUND",
+            "jmxbeans:java.lang#type=ClassLoading:LoadedClassCount:> 100",
+            "muppet:RuleBuilderCount:between 2 and 10"
+        };
+        final List<EvaluationResult> r = U.evaluateRules(facade, rules);
+        
+        assertEquals(4, r.size());
+        int i=0;
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: bundle.state:org.apache.sling.muppet.core active");
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: bundle.state:some.nonexistenbundle BUNDLE_NOT_FOUND");
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: java.lang:type=ClassLoading:LoadedClassCount > 100");
+    }
+}

Added: sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/MuppetOsgiFacadeTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/MuppetOsgiFacadeTest.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/MuppetOsgiFacadeTest.java (added)
+++ sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/MuppetOsgiFacadeTest.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.it.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.RuleBuilder;
+import org.apache.sling.muppet.api.SystemAttribute;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+@RunWith(PaxExam.class)
+public class MuppetOsgiFacadeTest {
+    
+    @Inject
+    private MuppetFacade facade;
+    
+    @Inject
+    private BundleContext bundleContext;
+    
+    @Configuration
+    public Option[] config() {
+        return U.config(false);
+    }
+    
+    @Test
+    public void testFacadePresent() {
+        assertNotNull("Expecting MuppetFacade service to be provided", facade);
+    }
+    
+    @Test
+    public void testDefaultRules() throws IOException {
+        // There should be at least one rule builder, but not a lot
+        final String [] rules = { 
+            "muppet:RuleBuilderCount:> 0",
+            "muppet:RuleBuilderCount:> 42"
+        };
+        final List<EvaluationResult> r = U.evaluateRules(facade, rules);
+        
+        assertEquals(2, r.size());
+        int i=0;
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: RuleBuilderCount > 0");
+        U.assertResult(r.get(i++), EvaluationResult.Status.ERROR, "Rule: RuleBuilderCount > 42");
+    }
+    
+    @Test
+    public void testAddingCustomRule() throws IOException {
+        final String [] rules = { 
+            "muppet:RuleBuilderCount:> 0",
+            "muppet:RuleBuilderCount:> 42",
+            "test:constant:5",
+            "test:constant:12",
+        };
+        
+        final SystemAttribute five = new SystemAttribute() {
+            @Override
+            public String toString() {
+                return "five";
+            }
+            @Override
+            public Object getValue() {
+                return 5;
+            }
+        };
+        
+        // To add new rule types, just register RuleBuilder services
+        final RuleBuilder rb = new RuleBuilder() {
+            @Override
+            public Rule buildRule(String namespace, String ruleName, String qualifier, String expression) {
+                if("test".equals(namespace) && "constant".equals(ruleName)) {
+                    return new Rule(five, expression);
+                }
+                return null;
+            }
+        };
+        
+        final ServiceRegistration<?> reg = bundleContext.registerService(RuleBuilder.class.getName(), rb, null);
+
+        try {
+            final List<EvaluationResult> r = U.evaluateRules(facade, rules);
+            assertEquals(4, r.size());
+            int i=0;
+            U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: RuleBuilderCount > 0");
+            U.assertResult(r.get(i++), EvaluationResult.Status.ERROR, "Rule: RuleBuilderCount > 42");
+            U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: five 5");
+            U.assertResult(r.get(i++), EvaluationResult.Status.ERROR, "Rule: five 12");
+        } finally {
+            reg.unregister();
+        }
+        
+        final List<EvaluationResult> r = U.evaluateRules(facade, rules);
+        assertEquals("Expecting custom RuleBuilder to be gone", 2, r.size());
+    }
+}

Added: sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/OsgiRulesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/OsgiRulesTest.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/OsgiRulesTest.java (added)
+++ sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/OsgiRulesTest.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.it.core;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class OsgiRulesTest {
+    
+    @Inject
+    private MuppetFacade facade;
+    
+    @Configuration
+    public Option[] config() {
+        return U.config(true);
+    }
+    
+    
+    @Test
+    public void testBundleStateRules() throws IOException {
+        // There should be at least one rule builder, but not a lot
+        final String [] rules = { 
+            "osgi:bundle.state:org.apache.sling.muppet.core:active",
+            "osgi:bundle.state:some.nonexistenbundle:BUNDLE_NOT_FOUND",
+        };
+        final List<EvaluationResult> r = U.evaluateRules(facade, rules);
+        
+        assertEquals(2, r.size());
+        int i=0;
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: bundle.state:org.apache.sling.muppet.core active");
+        U.assertResult(r.get(i++), EvaluationResult.Status.OK, "Rule: bundle.state:some.nonexistenbundle BUNDLE_NOT_FOUND");
+    }
+}

Added: sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/U.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/U.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/U.java (added)
+++ sling/trunk/contrib/extensions/muppet/it/src/test/java/org/apache/sling/muppet/it/core/U.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.it.core;
+
+import static org.junit.Assert.assertEquals;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.apache.sling.muppet.api.RulesEngine;
+import org.ops4j.pax.exam.Option;
+
+/** Test utilities */
+public class U {
+    
+    static Option[] config(boolean includeRules) {
+        final String coreVersion = System.getProperty("muppet.core.version");
+
+        if(includeRules) {
+            return options(
+                    junitBundles(),
+                    provision(
+                            mavenBundle("org.apache.sling", "org.apache.sling.muppet.core", coreVersion),
+                            mavenBundle("org.apache.sling", "org.apache.sling.muppet.rules", coreVersion)
+                    )
+            );
+        } else {
+            return options(
+                    junitBundles(),
+                    provision(
+                            mavenBundle("org.apache.sling", "org.apache.sling.muppet.core", coreVersion)
+                    )
+            );
+        }
+    }
+    
+    static List<EvaluationResult> evaluateRules(MuppetFacade facade, String [] rules) throws IOException {
+        final RulesEngine e = facade.getNewRulesEngine();
+        final StringBuilder b = new StringBuilder();
+        for(String line : rules) {
+            b.append(line).append("\n");
+        }
+        e.addRules(facade.parseSimpleTextRules(new StringReader(b.toString())));
+        return e.evaluateRules();
+    }
+    
+    static void assertResult(EvaluationResult rr, EvaluationResult.Status status, String ruleString) {
+        assertEquals("Expecting " + rr.getRule() + " result to match", status, rr.getStatus());
+        assertEquals("Expecting " + rr.getRule() + " string to match", ruleString, rr.getRule().toString());
+    }
+}

Propchange: sling/trunk/contrib/extensions/muppet/muppet-core/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Apr 15 09:52:11 2013
@@ -0,0 +1,13 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+
+
+

Added: sling/trunk/contrib/extensions/muppet/muppet-core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/pom.xml?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/pom.xml (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/pom.xml Mon Apr 15 09:52:11 2013
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>15</version>
+        <relativePath>15</relativePath>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.muppet.core</artifactId>
+    <packaging>bundle</packaging>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Muppet Core</name>
+    <inceptionYear>2013</inceptionYear>
+    
+    <description>
+        The Muppet core OSGi bundle, can also be used outside of an OSGi environment.
+    </description>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Activator>
+                            org.apache.sling.muppet.impl.Activator
+                        </Bundle-Activator>
+                        <Export-Package>
+                            org.apache.sling.muppet.api,
+                            org.apache.sling.muppet.util
+                        </Export-Package>
+                        <Private-Package>
+                            org.apache.sling.muppet.impl.*
+                        </Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.6.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <version>1.6.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.1</version>
+            <scope>test</scope>
+        </dependency>
+     </dependencies>
+</project>

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/EvaluationResult.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/EvaluationResult.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/EvaluationResult.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/EvaluationResult.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.api;
+
+/** The result of evaluating a {@link Rule} */
+public class EvaluationResult {
+    
+    public enum Status {
+        OK,
+        ERROR
+    }
+    
+    private final Status status;
+    private final Rule rule;
+    
+    public EvaluationResult(Rule r) {
+        rule = r;
+        status = r.execute();
+    }
+    
+    public Rule getRule() {
+        return rule;
+    }
+    
+    public Status getStatus() {
+        return status;
+    }
+   
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/Evaluator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/Evaluator.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/Evaluator.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/Evaluator.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.api;
+
+/** Evaluates a String expression on the current value of a {@link SystemAttribute} */ 
+public interface Evaluator {
+    EvaluationResult.Status evaluate(SystemAttribute a, String expression);
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/MuppetFacade.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/MuppetFacade.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/MuppetFacade.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/MuppetFacade.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.api;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.List;
+
+/** Service facade for Muppet */
+public interface MuppetFacade {
+    /** Return a new, empty RulesEngine*/
+    RulesEngine getNewRulesEngine();
+    
+    /** Parse a set of rules defined in our simple text format */
+    List<Rule> parseSimpleTextRules(Reader textRules) throws IOException;
+    
+    /** Return our current list of RuleBuilder */
+    List<RuleBuilder> getRuleBuilders();
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/Rule.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/Rule.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/Rule.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/Rule.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.api;
+
+import org.apache.sling.muppet.util.DefaultEvaluator;
+
+/** Groups a {@link SystemAttribute}, {@link Evaluator} and
+ *  String expression to be able to check that the attribute's
+ *  value matches the supplied expression.
+ */
+public class Rule {
+    private final SystemAttribute attribute;
+    private final Evaluator evaluator;
+    private final String expression;
+    
+    public Rule(SystemAttribute attr, String expression) {
+        this(attr, expression, new DefaultEvaluator());
+    }
+    
+    public Rule(SystemAttribute attr, String expression, Evaluator e) {
+        this.attribute = attr;
+        this.expression = expression;
+        this.evaluator = e;
+    }
+    
+    public EvaluationResult.Status execute() {
+        return evaluator.evaluate(attribute, expression);
+    }
+    
+    @Override
+    public String toString() {
+        return getClass().getSimpleName() + ": " + attribute + " " + expression;
+    }
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/RuleBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/RuleBuilder.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/RuleBuilder.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/RuleBuilder.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.api;
+
+/** Builds {@link Rule} objects for namespaces and rule names that
+ *  match what this builder expects. Used when parsing rule definition
+ *  files or other rule definition data structures.
+ */
+public interface RuleBuilder {
+    Rule buildRule(String namespace, String ruleName, String qualifier, String expression);
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/RulesEngine.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/RulesEngine.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/RulesEngine.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/RulesEngine.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.api;
+
+import java.util.List;
+
+/** An engine that stores and evaluates a list of 
+ *  {@link Rule}.
+ */
+public interface RulesEngine {
+    /** Add a rule to this engine */
+    void addRule(Rule r);
+    
+    /** Add a list of rules to this engine */
+    void addRules(List<Rule> rules);
+    
+    /** Evaluate all the current rules.
+     *  TODO: we should use tags on rules to group
+     *  them in sets (performance, configuration etc.)
+     */
+    List<EvaluationResult> evaluateRules();
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/SystemAttribute.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/SystemAttribute.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/SystemAttribute.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/api/SystemAttribute.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.api;
+
+/** An attribute of the system that's being checked */
+public interface SystemAttribute {
+    Object getValue();
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/Activator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/Activator.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/Activator.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/Activator.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.apache.sling.muppet.api.RuleBuilder;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class Activator implements BundleActivator {
+    private OSGiMuppetFacadeImpl facade;
+    private List<ServiceRegistration> regs;
+
+    public void start(BundleContext ctx) throws Exception {
+        regs = new ArrayList<ServiceRegistration>();
+        
+        // Register a MuppetFacade service
+        facade = new OSGiMuppetFacadeImpl(ctx);
+        regs.add(ctx.registerService(MuppetFacade.class.getName(), facade, null));
+        
+        // Register our default RuleBuilder
+        regs.add(ctx.registerService(RuleBuilder.class.getName(), new DefaultRuleBuilder(facade), null));
+    }
+
+    public void stop(BundleContext ctx) throws Exception {
+        if(regs != null) {
+            for(ServiceRegistration reg : regs) {
+                reg.unregister();
+            }
+        }
+        regs = null;
+        
+        if(facade != null) {
+            facade.close();
+        }
+        facade = null;
+    }
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/DefaultRuleBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/DefaultRuleBuilder.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/DefaultRuleBuilder.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/DefaultRuleBuilder.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.impl;
+
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.RuleBuilder;
+import org.apache.sling.muppet.api.SystemAttribute;
+import org.apache.sling.muppet.util.DefaultEvaluator;
+
+/** {@link RuleBuilder} that provides a few default Rules. */
+public class DefaultRuleBuilder implements RuleBuilder {
+
+    public static final String NAMESPACE = "muppet";
+    public static final String RULE_BUILDER_COUNT = "RuleBuilderCount";
+    private final MuppetFacade facade;
+    
+    private class RuleBuilderCountAttribute implements SystemAttribute {
+        @Override
+        public String toString() {
+            return RULE_BUILDER_COUNT;
+        }
+        @Override
+        public Object getValue() {
+            return new Integer(facade.getRuleBuilders().size());
+        }
+    };
+    
+    public DefaultRuleBuilder(MuppetFacade facade) {
+        this.facade = facade;
+    }
+    
+    @Override
+    public Rule buildRule(String namespace, String ruleName, String qualifier, String expression) {
+        if(!NAMESPACE.equals(namespace)) {
+            return null;
+        }
+        
+        if(RULE_BUILDER_COUNT.equals(ruleName)) {
+            return new Rule(new RuleBuilderCountAttribute(), expression, new DefaultEvaluator());
+        }
+        
+        return null;
+    }
+}
\ No newline at end of file

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/OSGiMuppetFacadeImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/OSGiMuppetFacadeImpl.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/OSGiMuppetFacadeImpl.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/OSGiMuppetFacadeImpl.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.impl;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.sling.muppet.api.MuppetFacade;
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.RuleBuilder;
+import org.apache.sling.muppet.api.RulesEngine;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+/** {@link MuppetFacade} for an OSGi environment, where
+ *  {@link RuleBuilder} are provided as OSGi services.
+ */
+public class OSGiMuppetFacadeImpl implements MuppetFacade {
+
+    private TextRulesParser parser;
+    private List<RuleBuilder> ruleBuilders;
+    private final ServiceTracker ruleBuilderTracker;
+    private int trackingCount;
+    
+    public OSGiMuppetFacadeImpl(BundleContext ctx) {
+        ruleBuilderTracker = new ServiceTracker(ctx, RuleBuilder.class.getName(), null);
+        ruleBuilderTracker.open();
+    }
+    
+    public void close() {
+        ruleBuilderTracker.close();
+    }
+    
+    @Override
+    public RulesEngine getNewRulesEngine() {
+        return new RulesEngineImpl();
+    }
+
+    @Override
+    public List<Rule> parseSimpleTextRules(Reader input) throws IOException {
+        maybeSetupParser();
+        return parser.parse(input);
+    }
+    
+    @Override
+    public List<RuleBuilder> getRuleBuilders() {
+        maybeSetupParser();
+        return Collections.unmodifiableList(ruleBuilders);
+    }
+    
+    private void maybeSetupParser() {
+        if(parser == null || ruleBuilderTracker.getTrackingCount() != trackingCount) {
+            synchronized (this) {
+                trackingCount = ruleBuilderTracker.getTrackingCount();
+                parser = new TextRulesParser();
+                ruleBuilders = new ArrayList<RuleBuilder>();
+                final Object [] services = ruleBuilderTracker.getServices();
+                for(Object o : services) {
+                    final RuleBuilder rb = (RuleBuilder)o;
+                    ruleBuilders.add(rb);
+                    parser.addBuilder(rb);
+                }
+            }
+        }
+    }
+}
\ No newline at end of file

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/RulesEngineImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/RulesEngineImpl.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/RulesEngineImpl.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/RulesEngineImpl.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.RulesEngine;
+
+public class RulesEngineImpl implements RulesEngine {
+
+    private final List<Rule> rules = new ArrayList<Rule>();
+    
+    @Override
+    public void addRule(Rule r) {
+        rules.add(r);
+    }
+
+    @Override
+    public void addRules(List<Rule> r) {
+        rules.addAll(r);
+    }
+
+    @Override
+    public List<EvaluationResult> evaluateRules() {
+        final List<EvaluationResult> result = new ArrayList<EvaluationResult>();
+        for(Rule r : rules) {
+            result.add(new EvaluationResult(r));
+        }
+        return result;
+    }
+
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/TextRulesParser.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/TextRulesParser.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/TextRulesParser.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/impl/TextRulesParser.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.impl;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.RuleBuilder;
+
+public class TextRulesParser {
+    private final List<RuleBuilder> builders = new ArrayList<RuleBuilder>();
+    
+    public void addBuilder(RuleBuilder b) {
+        builders.add(b);
+    }
+    
+    public List<Rule> parse(Reader input) throws IOException {
+        final List<Rule> result = new ArrayList<Rule>();
+        final BufferedReader r = new BufferedReader(input);
+        String line = null;
+        while( (line = r.readLine()) != null) {
+            line = line.trim();
+            if(line.length() == 0 || line.startsWith("#")) {
+                continue;
+            }
+            
+            // parse line in the form
+            //  namespace:rule name:qualifier:expression
+            // where qualifier is optional
+            final String [] parts = line.split(":");
+            String namespace = null;
+            String name = null;
+            String qualifier = null;
+            String expression = null;
+            
+            if(parts.length == 4) {
+                namespace = parts[0].trim();
+                name = parts[1].trim();
+                qualifier = parts[2].trim();
+                expression = parts[3].trim();
+            } else if(parts.length == 3) {
+                namespace = parts[0].trim();
+                name = parts[1].trim();
+                expression = parts[2].trim();
+            } else {
+                // TODO for now, ignore parsing errors
+            }
+            
+            if(namespace != null) {
+                for(RuleBuilder b : builders) {
+                    final Rule toAdd = b.buildRule(namespace, name, qualifier, expression);
+                    if(toAdd != null) {
+                        // first builder wins
+                        result.add(toAdd);
+                    }
+                }
+            }
+        }
+        return result;
+    }
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/util/DefaultEvaluator.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/util/DefaultEvaluator.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/util/DefaultEvaluator.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/main/java/org/apache/sling/muppet/util/DefaultEvaluator.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.util;
+
+import org.apache.sling.muppet.api.Evaluator;
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.SystemAttribute;
+import org.apache.sling.muppet.api.EvaluationResult.Status;
+
+public class DefaultEvaluator implements Evaluator {
+    @Override
+    public Status evaluate(SystemAttribute a, String expression) {
+        final String [] parts = expression.split(" ");
+        boolean matches = false;
+        
+        if(expression.startsWith(">") && parts.length == 2) {
+            matches = Integer.valueOf(a.getValue().toString()).intValue() > Integer.valueOf(parts[1]);
+            
+        } else if(expression.startsWith("<") && parts.length == 2) {
+            matches = Integer.valueOf(a.getValue().toString()).intValue() < Integer.valueOf(parts[1]);
+            
+        } else if(parts.length == 4 && "between".equalsIgnoreCase(parts[0]) && "and".equalsIgnoreCase(parts[2]) ) {
+            final int aValue = Integer.valueOf(a.getValue().toString()).intValue();
+            final int lowerBound = Integer.valueOf(parts[1]);
+            final int upperBound = Integer.valueOf(parts[3]);
+            matches = aValue > lowerBound && aValue < upperBound;
+            
+        } else {
+            matches = expression.equals(a.getValue().toString()); 
+        }
+        
+        return matches ? EvaluationResult.Status.OK : EvaluationResult.Status.ERROR;
+    }
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/DefaultEvaluatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/DefaultEvaluatorTest.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/DefaultEvaluatorTest.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/DefaultEvaluatorTest.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.impl;
+
+import org.apache.sling.muppet.api.Evaluator;
+import org.apache.sling.muppet.api.SystemAttribute;
+import org.apache.sling.muppet.util.DefaultEvaluator;
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.apache.sling.muppet.api.EvaluationResult.Status.OK;
+import static org.apache.sling.muppet.api.EvaluationResult.Status.ERROR;
+
+public class DefaultEvaluatorTest {
+    private final Evaluator evaluator = new DefaultEvaluator();
+    
+    private final SystemAttribute five = new SystemAttribute() {
+        @Override
+        public Object getValue() {
+            return "5";
+        }
+    };
+    
+    @Test
+    public void testEquals() {
+        assertEquals(OK, evaluator.evaluate(five, "5"));
+        assertEquals(ERROR, evaluator.evaluate(five, "foo"));
+    }
+    
+    @Test
+    public void testGreaterThan() {
+        assertEquals(OK, evaluator.evaluate(five, "> 2"));
+        assertEquals(ERROR, evaluator.evaluate(five, "> 12"));
+    }
+    
+    @Test
+    public void testLessThan() {
+        assertEquals(OK, evaluator.evaluate(five, "< 12"));
+        assertEquals(ERROR, evaluator.evaluate(five, "< 2"));
+    }
+    
+    @Test
+    public void testBetween() {
+        assertEquals(OK, evaluator.evaluate(five, "between 2 and 6"));
+        assertEquals(ERROR, evaluator.evaluate(five, "between 2 and 5"));
+        assertEquals(ERROR, evaluator.evaluate(five, "between 5 and 7"));
+        assertEquals(OK, evaluator.evaluate(five, "between 4 and 7"));
+        assertEquals(OK, evaluator.evaluate(five, "BETWEEN 2 AND 6"));
+        assertEquals(ERROR, evaluator.evaluate(five, "between 12 and 61"));
+        assertEquals(ERROR, evaluator.evaluate(five, "BETWEEN 12 AND 61"));
+    }
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/RuleTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/RuleTest.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/RuleTest.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/RuleTest.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.impl;
+
+import static org.apache.sling.muppet.api.EvaluationResult.Status.ERROR;
+import static org.apache.sling.muppet.api.EvaluationResult.Status.OK;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.SystemAttribute;
+import org.junit.Test;
+
+public class RuleTest {
+    final SystemAttribute five = new SystemAttribute() {
+        @Override
+        public Object getValue() {
+            return 5;
+        }
+    };
+    
+    @Test
+    public void testWithDefaultEvaluator() {
+        assertEquals("== 5", OK, new Rule(five,"5").execute());
+        assertEquals("> 2", OK, new Rule(five,"> 2").execute());
+        assertEquals("> 12 is false", ERROR, new Rule(five,"> 12").execute());
+    }
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/RulesEngineTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/RulesEngineTest.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/RulesEngineTest.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/RulesEngineTest.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.RuleBuilder;
+import org.apache.sling.muppet.api.EvaluationResult;
+import org.apache.sling.muppet.api.SystemAttribute;
+import org.apache.sling.muppet.util.DefaultEvaluator;
+import org.junit.Test;
+
+public class RulesEngineTest {
+    
+    static class TestBuilder implements RuleBuilder {
+        @Override
+        public Rule buildRule(final String namespace, final String ruleName,final String qualifier, final String expression) {
+            if(!"test".equals(namespace)) {
+                return null;
+            }
+            
+            SystemAttribute attr = new SystemAttribute() {
+                @Override
+                public Object getValue() {
+                    if("constant".equals(ruleName)) {
+                        return Integer.valueOf(qualifier);
+                    } else if("invert".equals(ruleName)) {
+                            return Integer.valueOf("-" + qualifier);
+                    } else {
+                        return null;
+                    }
+                }
+                
+            };
+            
+            return new Rule(attr, expression, new DefaultEvaluator()) {
+                @Override
+                public String toString() {
+                    return "" + namespace + "_" + ruleName + "_" + qualifier + "_" + expression;
+                }
+            };
+        }
+    }
+    
+    private void assertResult(EvaluationResult rr, EvaluationResult.Status status, String ruleString) {
+        assertEquals("Rule " + rr.getRule() + " result matches", rr.getStatus(), status);
+        assertEquals("Rule " + rr.getRule() + " string matches", rr.getRule().toString(), ruleString);
+    }
+    
+    @Test
+    public void parseAndExecute() throws IOException {
+        final String rules =
+            "test:constant:5:5\n"
+            + "test:constant:5: > 2\n"
+            + "test:constant:5: < 12\n"
+            + "test:constant:5: between 4 and 6\n"
+            + "test:constant:5: between 12 and 21\n"
+            + "test:constant:5:42\n"
+            + "test:invert:12:-1\n"
+            + "test:invert:12:-12\n"
+        ;
+        
+        final TextRulesParser p = new TextRulesParser();
+        p.addBuilder(new TestBuilder());
+        
+        final RulesEngineImpl e = new RulesEngineImpl();
+        e.addRules(p.parse(new StringReader(rules)));
+        
+        final List<EvaluationResult> result = e.evaluateRules();
+        assertEquals(8, result.size());
+        
+        int i=0;
+        assertResult(result.get(i++), EvaluationResult.Status.OK, "test_constant_5_5");
+        assertResult(result.get(i++), EvaluationResult.Status.OK, "test_constant_5_> 2");
+        assertResult(result.get(i++), EvaluationResult.Status.OK, "test_constant_5_< 12");
+        assertResult(result.get(i++), EvaluationResult.Status.OK, "test_constant_5_between 4 and 6");
+        assertResult(result.get(i++), EvaluationResult.Status.ERROR, "test_constant_5_between 12 and 21");
+        assertResult(result.get(i++), EvaluationResult.Status.ERROR, "test_constant_5_42");
+        assertResult(result.get(i++), EvaluationResult.Status.ERROR, "test_invert_12_-1");
+        assertResult(result.get(i++), EvaluationResult.Status.OK, "test_invert_12_-12");
+    }
+}

Added: sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/TextRulesParserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/TextRulesParserTest.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/TextRulesParserTest.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-core/src/test/java/org/apache/sling/muppet/impl/TextRulesParserTest.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.List;
+
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.RuleBuilder;
+import org.junit.Test;
+
+public class TextRulesParserTest {
+    
+    static class TestBuilder implements RuleBuilder {
+        @Override
+        public Rule buildRule(final String namespace, final String ruleName,final String qualifier, final String expression) {
+            if(!"test".equals(namespace)) {
+                return null;
+            }
+            
+            return new Rule(null, null, null) {
+                @Override
+                public String toString() {
+                    return "" + namespace + "_" + ruleName + "_" + qualifier + "_" + expression;
+                }
+            };
+        }
+    }
+    
+    @Test
+    public void parse() throws IOException {
+        final String rules =
+            "test:constant:5:5\n"
+            + "test:constant:5:42\n"
+            + "# a comment here\n"
+            + "an invalid line\n"
+            + "othernamespace:constant:5:42\n"
+            + "\t\n\n\n\n\n"
+            + "test:invert:12:-1\n"
+            + "\ttest:invert:21:-21\n"
+            + "\ttest:nothing:ABC\n"
+            + "\ttest  :\twhitespace : QUAL :\t\t DEF\n"
+            + "\ttest  :\tWS2 : :\t\t foo\n"
+            + "\ttest  :\tWS3 :\t\t foo\n"
+        ;
+        
+        final TextRulesParser p = new TextRulesParser();
+        p.addBuilder(new TestBuilder());
+        final List<Rule> result = p.parse(new StringReader(rules));
+        assertEquals(8, result.size());
+        
+        final String [] expect = {
+            "test_constant_5_5",
+            "test_constant_5_42",
+            "test_invert_12_-1",
+            "test_invert_21_-21",
+            "test_nothing_null_ABC",
+            "test_whitespace_QUAL_DEF",
+            "test_WS2__foo",
+            "test_WS3_null_foo"
+        };
+        
+        for(int i=0; i < expect.length; i++) {
+            assertEquals(expect[i], result.get(i++).toString());
+        }
+        
+    }
+}

Propchange: sling/trunk/contrib/extensions/muppet/muppet-rules/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Apr 15 09:52:11 2013
@@ -0,0 +1,13 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+
+
+

Added: sling/trunk/contrib/extensions/muppet/muppet-rules/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-rules/pom.xml?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-rules/pom.xml (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-rules/pom.xml Mon Apr 15 09:52:11 2013
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>15</version>
+        <relativePath>15</relativePath>
+    </parent>
+
+    <groupId>org.apache.sling</groupId>
+    <artifactId>org.apache.sling.muppet.rules</artifactId>
+    <packaging>bundle</packaging>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <name>Muppet Rules</name>
+    <inceptionYear>2013</inceptionYear>
+    
+    <description>
+        Default Muppet Rules: JVM, JMX etc.
+    </description>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Bundle-Activator>
+                            org.apache.sling.muppet.rules.osgi.Activator
+                        </Bundle-Activator>
+                        <Private-Package>
+                            org.apache.sling.muppet.rules.*
+                        </Private-Package>
+                    </instructions>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.muppet.core</artifactId>
+            <version>${project.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <version>1.6.2</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <version>1.6.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.8.1</version>
+            <scope>test</scope>
+        </dependency>
+     </dependencies>
+</project>

Added: sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/rules/jmx/JmxBeansRuleBuilder.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/rules/jmx/JmxBeansRuleBuilder.java?rev=1467919&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/rules/jmx/JmxBeansRuleBuilder.java (added)
+++ sling/trunk/contrib/extensions/muppet/muppet-rules/src/main/java/org/apache/sling/muppet/rules/jmx/JmxBeansRuleBuilder.java Mon Apr 15 09:52:11 2013
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.sling.muppet.rules.jmx;
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.sling.muppet.api.Rule;
+import org.apache.sling.muppet.api.RuleBuilder;
+import org.apache.sling.muppet.api.SystemAttribute;
+
+/** Rules that give access to JMX beans */
+public class JmxBeansRuleBuilder implements RuleBuilder {
+
+    public static final String NAMESPACE = "jmxbeans";
+    private MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
+    
+    private class JmxBeanAttribute implements SystemAttribute {
+        private final String attributeName;
+        private final String beanName;
+        
+        JmxBeanAttribute(String beanName, String attributeName) {
+            // TODO we have a problem with : in bean names as it's used
+            // as a separator in the Muppet simple text rules format
+            // For now, convert to a comma so that bean names can be
+            // specified as java.lang#type=ClassLoading
+            this.beanName = beanName.replaceAll("#", ":");
+            this.attributeName = attributeName;
+        }
+        
+        @Override
+        public String toString() {
+            return beanName + ":" + attributeName;
+        }
+        
+        @Override
+        public Object getValue() {
+            try {
+                final ObjectName objectName = new ObjectName(beanName);
+                if(jmxServer.queryNames(objectName, null).size() == 0) {
+                    return "MBean not found: " + objectName;
+                }
+                return jmxServer.getAttribute(objectName, attributeName);
+            } catch(Exception e) {
+                return "MBean exception: " + e.toString();
+            }
+        }
+    }
+    
+    @Override
+    public Rule buildRule(String namespace, String ruleName, String qualifier, String expression) {
+        if(!NAMESPACE.equals(namespace)) {
+            return null;
+        }
+        return new Rule(new JmxBeanAttribute(ruleName, qualifier), expression);
+    }
+}



Mime
View raw message