Adding common JUnit infrastructure.
diff --git a/com.google.eclipse.protobuf.junit/.classpath b/com.google.eclipse.protobuf.junit/.classpath new file mode 100644 index 0000000..64c5e31 --- /dev/null +++ b/com.google.eclipse.protobuf.junit/.classpath
@@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath>
diff --git a/com.google.eclipse.protobuf.junit/.project b/com.google.eclipse.protobuf.junit/.project new file mode 100644 index 0000000..95821b0 --- /dev/null +++ b/com.google.eclipse.protobuf.junit/.project
@@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>com.google.eclipse.protobuf.junit</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
diff --git a/com.google.eclipse.protobuf.junit/.settings/org.eclipse.jdt.core.prefs b/com.google.eclipse.protobuf.junit/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7673078 --- /dev/null +++ b/com.google.eclipse.protobuf.junit/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@ +#Tue Apr 26 10:54:01 PDT 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5
diff --git a/com.google.eclipse.protobuf.junit/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.junit/META-INF/MANIFEST.MF new file mode 100644 index 0000000..283dcfa --- /dev/null +++ b/com.google.eclipse.protobuf.junit/META-INF/MANIFEST.MF
@@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: JUnit support for testing +Bundle-SymbolicName: com.google.eclipse.protobuf.junit +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: Google +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.junit;bundle-version="4.8.1", + org.junit.source;bundle-version="4.8.1", + com.google.eclipse.protobuf;bundle-version="1.0.0", + org.eclipse.xtext;bundle-version="2.0.0", + org.eclipse.xtext.source;bundle-version="2.0.0", + org.eclipse.xtext.junit;bundle-version="2.0.0", + org.eclipse.xtext.junit.source;bundle-version="2.0.0", + org.eclipse.xtext.junit4;bundle-version="2.0.0", + org.eclipse.xtext.junit4.source;bundle-version="2.0.0", + org.eclipse.xtext.ui.junit;bundle-version="2.0.0", + org.eclipse.xtext.ui.junit.source;bundle-version="2.0.0", + org.eclipse.emf.ecore, + org.eclipse.emf.common, + com.google.inject;bundle-version="2.0.0" +Export-Package: com.google.eclipse.protobuf.junit
diff --git a/com.google.eclipse.protobuf.junit/build.properties b/com.google.eclipse.protobuf.junit/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/com.google.eclipse.protobuf.junit/build.properties
@@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .
diff --git a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/XtextRule.java b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/XtextRule.java new file mode 100644 index 0000000..35c78f4 --- /dev/null +++ b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/XtextRule.java
@@ -0,0 +1,68 @@ +/* + * Copyright (c) 2011 Google Inc. + * + * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse + * Public License v1.0 which accompanies this distribution, and is available at + * + * http://www.eclipse.org/legal/epl-v10.html + */ +package com.google.eclipse.protobuf.junit; + +import java.io.InputStreamReader; + +import org.eclipse.xtext.parser.IParseResult; +import org.eclipse.xtext.util.StringInputStream; +import org.junit.rules.MethodRule; +import org.junit.runners.model.FrameworkMethod; +import org.junit.runners.model.Statement; + +import com.google.eclipse.protobuf.ProtobufStandaloneSetup; +import com.google.eclipse.protobuf.parser.antlr.ProtobufParser; +import com.google.eclipse.protobuf.protobuf.Protobuf; +import com.google.inject.Injector; + +/** + * Understands SOMETHING DUMMY. + * + * @author alruiz@google.com (Alex Ruiz) + */ +public class XtextRule implements MethodRule { + + private Injector injector; + + public Statement apply(Statement base, FrameworkMethod method, Object target) { + return new XtextStatement(base); + } + + public Injector injector() { + return injector; + } + + public <T> T getInstanceOf(Class<T> type) { + return injector.getInstance(type); + } + + public Protobuf parse(String text) { + ProtobufParser parser = injector.getInstance(ProtobufParser.class); + IParseResult parseResult = parser.parse(new InputStreamReader(new StringInputStream(text))); + return (Protobuf) parseResult.getRootASTElement(); + } + + private class XtextStatement extends Statement { + private final Statement base; + + public XtextStatement(Statement base) { + this.base = base; + } + + /** {@inheritDoc} */ + public void evaluate() throws Throwable { + setUpInjector(); + base.evaluate(); + } + + private void setUpInjector() { + injector = new ProtobufStandaloneSetup().createInjectorAndDoEMFRegistration(); + } + } +}