Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: c15173db15
...
compare: 84da089bbb
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 31, 2013
@mirkoseifert mirkoseifert moved code to located ANTLR runtime source code to separate class and
added test to check whether locating this code works when the code is
contained in a JAR file
3fa549b
@mirkoseifert mirkoseifert added/fixed license headers
added missing class SourceCodeStreamFactory
84da089
View
35 .../org.emftext.sdk.codegen.antlr/src/org/emftext/sdk/codegen/antlr/creators/ANTLRPluginContentCreator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006-2012
+ * Copyright (c) 2006-2013
* Software Technology Group, Dresden University of Technology
* DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026
*
@@ -17,7 +17,7 @@
import java.io.File;
import java.io.IOException;
-import java.net.URL;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -44,17 +44,17 @@
import org.emftext.sdk.concretesyntax.OptionTypes;
/**
- * This class creates the contents of the org.emftext.commons.antlr_version plug-in
- * by copying the ANTLR runtime classes from the org.emftext.sdk.antlr_version
- * plug-in. The creation of the commons plug-in can be disable using the syntax
- * option OptionTypes.OVERRIDE_ANTLR_PLUGIN.
+ * This class creates the contents of the org.emftext.commons.antlr_version
+ * plug-in by copying the ANTLR runtime classes from the
+ * org.emftext.sdk.antlr_version plug-in. The creation of the commons plug-in
+ * can be disable using the syntax option OptionTypes.OVERRIDE_ANTLR_PLUGIN.
*/
public class ANTLRPluginContentCreator {
private static final String SRC_FOLDER = "src";
/**
- * A list of all class to copy.
+ * A list of all classes to copy.
*/
private Class<?>[] antlrClassNames = new Class<?>[] {
org.antlr.runtime3_4_0.ANTLRFileStream.class,
@@ -187,21 +187,22 @@ public void generate(ANTLRGenerationContext context, IProgressMonitor monitor) t
exports.add(ANTLRPluginArtifacts.PACKAGE_ANTLR_RUNTIME_TREE.getPackage().getName(context));
manifestParameters.setPlugin(antlrPlugin);
- manifestParameters.setBundleName("ANTLR 3.3.0 Runtime Classes");
+ // TODO Use constant for ANTLR version
+ manifestParameters.setBundleName("ANTLR 3.4.0 Runtime Classes");
creators.add(new ManifestCreator<ANTLRGenerationContext>(manifestParameters, true));
+ Class<?> referenceClass = EMFTextSDKAntlrPlugin.class;
+ SourceCodeStreamFactory sourceCodeStreamFactory = new SourceCodeStreamFactory();
// add copiers for ANTLR source files
for (Class<?> antlrClass : antlrClassNames) {
- String relativePathSourceFile = antlrClass.getName().replace(".", "/") + ".java";
+ String className = antlrClass.getName();
+ InputStream sourceStream = sourceCodeStreamFactory.getSourceCodeStream(referenceClass,
+ className);
String pathFile = antlrClass.getName().replace(".", File.separator) + ".java";
- Class<EMFTextSDKAntlrPlugin> antlrPluginClass = EMFTextSDKAntlrPlugin.class;
- URL url = antlrPluginClass.getResource("");
- String packagePath = antlrPluginClass.getPackage().getName().replace(".", "/");
- String urlString = url.toString().replace("bin/" + packagePath + "/", "");
- urlString = urlString.replace(packagePath + "/", "");
- String pathToSourceFile = urlString + "/src-runtime/" + relativePathSourceFile;
- creators.add(new FileCopier<ANTLRGenerationContext>(new URL(pathToSourceFile).openStream(),
- new File(sourceFolderPath + pathFile), true));
+ File targetFile = new File(sourceFolderPath + pathFile);
+ FileCopier<ANTLRGenerationContext> fileCopier = new FileCopier<ANTLRGenerationContext>(sourceStream,
+ targetFile, true);
+ creators.add(fileCopier);
}
for (IArtifactCreator<ANTLRGenerationContext> creator : creators) {
View
49 ...DK/org.emftext.sdk.codegen.antlr/src/org/emftext/sdk/codegen/antlr/creators/SourceCodeStreamFactory.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2013
+ * Software Technology Group, Dresden University of Technology
+ * DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026
+ *
+ * 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
+ *
+ * Contributors:
+ * Software Technology Group - TU Dresden, Germany;
+ * DevBoost GmbH - Berlin, Germany
+ * - initial API and implementation
+ ******************************************************************************/
+package org.emftext.sdk.codegen.antlr.creators;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * The {@link SourceCodeStreamFactory} provides access to source code files that
+ * are required by the EMFText code generators.
+ */
+public class SourceCodeStreamFactory {
+
+ /**
+ * Returns a stream from which the source code for class
+ * <code>className</code> can be read.
+ */
+ public InputStream getSourceCodeStream(Class<?> referenceClass,
+ String className) throws MalformedURLException, IOException {
+
+ String relativePathToSourceFile = className.replace(".", "/") + ".java";
+ String referenceClassFileName = referenceClass.getSimpleName() + ".class";
+ URL referenceURL = referenceClass.getResource(referenceClassFileName);
+ String referencePackageName = referenceClass.getPackage().getName();
+ String packagePath = referencePackageName.replace(".", "/");
+ String urlString = referenceURL.toString().replace("bin/" + packagePath + "/", "");
+ urlString = urlString.replace(packagePath + "/", "");
+ urlString = urlString.substring(0, urlString.length() - referenceClassFileName.length());
+ String pathToSourceFile = urlString + "src-runtime/" + relativePathToSourceFile;
+ URL sourceURL = new URL(pathToSourceFile);
+ InputStream sourceStream = sourceURL.openStream();
+ return sourceStream;
+ }
+}
View
1  Core/Tests/org.emftext.test/.classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
+ <classpathentry exported="true" kind="lib" path="lib/SourceCodeStreamTestArchive.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
View
2  Core/Tests/org.emftext.test/META-INF/MANIFEST.MF
@@ -47,4 +47,6 @@ Export-Package: org.emftext.sdk.codegen.composites,
org.emftext.test.resource,
org.emftext.test.syntax_analysis,
org.emftext.test.syntax_extension
+Bundle-ClassPath: lib/SourceCodeStreamTestArchive.jar,
+ .
View
3  Core/Tests/org.emftext.test/build.properties
@@ -1,4 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ lib/SourceCodeStreamTestArchive.jar
View
BIN  Core/Tests/org.emftext.test/lib/SourceCodeStreamTestArchive.jar
Binary file not shown
View
58 Core/Tests/org.emftext.test/src/org/emftext/sdk/codegen/antlr/creators/SourceCodeStreamFactoryTest.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2006-2013
+ * Software Technology Group, Dresden University of Technology
+ * DevBoost GmbH, Berlin, Amtsgericht Charlottenburg, HRB 140026
+ *
+ * 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
+ *
+ * Contributors:
+ * Software Technology Group - TU Dresden, Germany;
+ * DevBoost GmbH - Berlin, Germany
+ * - initial API and implementation
+ ******************************************************************************/
+package org.emftext.sdk.codegen.antlr.creators;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+
+import org.antlr.runtime3_4_0.ANTLRFileStream;
+import org.emftext.sdk.util.StreamUtil;
+import org.junit.Test;
+
+/**
+ * The {@link SourceCodeStreamFactoryTest} checks whether the ANTLR runtime
+ * source files can be found in packaged JAR files. This is somewhat tricky,
+ * because the localization of the source code of these classes must work both
+ * when the EMFText plug-ins are present as projects (i.e., not packaged as JAR
+ * files) and when they're packaged (e.g., when using them in builds that rely
+ * on EMFText).
+ */
+public class SourceCodeStreamFactoryTest {
+
+ @Test
+ public void testGetSourceCodeStream() {
+ SourceCodeStreamFactory streamFactory = new SourceCodeStreamFactory();
+ try {
+ InputStream stream = streamFactory.getSourceCodeStream(SourceCodeStreamTestReferenceClass.class, ANTLRFileStream.class.getName());
+ assertNotNull("Stream expected", stream);
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ StreamUtil.copy(stream, output);
+ stream.close();
+ String sourceCode = output.toString();
+ assertTrue("Source code must contain class definition.", sourceCode.contains("public class ANTLRFileStream"));
+ } catch (MalformedURLException e) {
+ fail(e.getMessage());
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ }
+}

No commit comments for this range

Something went wrong with that request. Please try again.