-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed loading php parser from jar file
- Loading branch information
Showing
3 changed files
with
103 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<!-- WARNING: Eclipse auto-generated file. | ||
Any modifications will be overwritten. | ||
To include a user specific buildfile here, simply create one in the same | ||
directory with the processing instruction <?eclipse.ant.import?> | ||
as the first entry and export the buildfile again. --><project basedir="." default="build" name="php-analysis"> | ||
<property environment="env"/> | ||
<property name="ECLIPSE_HOME" value="../../../programs/eclipse"/> | ||
<property name="debuglevel" value="source,lines,vars"/> | ||
<property name="target" value="1.7"/> | ||
<property name="source" value="1.7"/> | ||
<path id="Plug-in Dependencies.libraryclasspath"> | ||
<pathelement location="../../../../../pdb.values"/> | ||
<pathelement location="../../../../../rascal"/> | ||
</path> | ||
<path id="php-analysis.classpath"> | ||
<path refid="Plug-in Dependencies.libraryclasspath"/> | ||
<pathelement location="bin"/> | ||
</path> | ||
<target name="init"> | ||
<mkdir dir="bin"/> | ||
<copy includeemptydirs="false" todir="bin"> | ||
<fileset dir="src"> | ||
<exclude name="**/*.java"/> | ||
<exclude name="**/tests/**"/> | ||
</fileset> | ||
</copy> | ||
<copy includeemptydirs="false" todir="bin"> | ||
<fileset dir="lib"> | ||
<exclude name="**/*.java"/> | ||
</fileset> | ||
</copy> | ||
</target> | ||
<target name="clean"> | ||
<delete dir="bin"/> | ||
</target> | ||
<target depends="clean" name="cleanall"/> | ||
<target depends="build-subprojects,build-project" name="build"/> | ||
<target name="build-subprojects"/> | ||
<target depends="init" name="build-project"> | ||
<echo message="${ant.project.name}: ${ant.file}"/> | ||
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}"> | ||
<src path="src"/> | ||
<src path="lib"/> | ||
<classpath refid="php-analysis.classpath"/> | ||
</javac> | ||
</target> | ||
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/> | ||
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler"> | ||
<copy todir="${ant.library.dir}"> | ||
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/> | ||
</copy> | ||
<unzip dest="${ant.library.dir}"> | ||
<patternset includes="jdtCompilerAdapter.jar"/> | ||
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/> | ||
</unzip> | ||
</target> | ||
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler"> | ||
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> | ||
<antcall target="build"/> | ||
</target> | ||
<target name="jar"> | ||
<mkdir dir="jar"/> | ||
<jar manifest="META-INF/MANIFEST.MF" destfile="jar/php-analysis.jar"> | ||
<fileset dir="." includes="src/**,META-INF/**" excludes="**/tests/**"/> | ||
<fileset dir="bin" includes="**/*.class"/> | ||
<fileset dir="lib"/> | ||
</jar> | ||
</target> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,50 @@ | ||
package org.rascal.phpanalysis; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.util.Enumeration; | ||
import java.nio.file.StandardCopyOption; | ||
import java.util.jar.JarEntry; | ||
import java.util.jar.JarFile; | ||
import java.util.jar.JarInputStream; | ||
|
||
import org.eclipse.imp.pdb.facts.ISourceLocation; | ||
import org.eclipse.imp.pdb.facts.IValue; | ||
import org.eclipse.imp.pdb.facts.IValueFactory; | ||
import org.rascalmpl.interpreter.utils.RuntimeExceptionFactory; | ||
|
||
public class PhpJarExtractor { | ||
protected final IValueFactory values; | ||
private static ISourceLocation phpParserLoc = null; | ||
|
||
public PhpJarExtractor(IValueFactory values){ | ||
this.values = values; | ||
} | ||
|
||
public IValue getPhpParserLocFromJar() throws IOException { | ||
InputStream is = null; | ||
FileOutputStream fo = null; | ||
JarFile jarFile = null; | ||
|
||
try { | ||
if (phpParserLoc == null) { | ||
File tempDir = Files.createTempDirectory("rascal-php-parser-jar").toAbsolutePath().toFile(); | ||
File tempJar = new File(tempDir, "php-parser.jar"); | ||
|
||
//System.out.println(getClass().getClassLoader().); | ||
|
||
if (!tempJar.exists()) { | ||
Files.copy(getClass().getClassLoader().getResourceAsStream("php-parser.jar"), tempJar.toPath()); | ||
} | ||
|
||
jarFile = new JarFile(tempJar); | ||
Enumeration<JarEntry> entries = jarFile.entries(); | ||
|
||
while (entries.hasMoreElements()) | ||
{ | ||
JarEntry je = entries.nextElement(); | ||
File fl = new File(tempDir, je.getName()); | ||
|
||
if (!fl.exists()) | ||
{ | ||
fl.getParentFile().mkdirs(); | ||
//fl = new File(tempDir, je.getName()); | ||
} | ||
if (je.isDirectory()) | ||
{ | ||
continue; | ||
} | ||
|
||
is = jarFile.getInputStream(je); | ||
fo = new FileOutputStream(fl); | ||
|
||
while (is.available() > 0) | ||
{ | ||
fo.write(is.read()); | ||
} | ||
|
||
fo.close(); | ||
is.close(); | ||
|
||
fo = null; | ||
is = null; | ||
} | ||
|
||
return values.sourceLocation(tempDir.getAbsolutePath()); | ||
} | ||
catch(IOException ioex) { | ||
throw RuntimeExceptionFactory.io(values.string(ioex.getMessage()), null, null); | ||
} | ||
finally { | ||
if (fo != null) fo.close(); | ||
if (is != null) is.close(); | ||
if (jarFile != null) jarFile.close(); | ||
try (JarInputStream jarStream = new JarInputStream(getClass().getClassLoader().getResourceAsStream("php-parser.jar"))) { | ||
JarEntry je; | ||
while ((je = jarStream.getNextJarEntry()) != null) | ||
{ | ||
File fl = new File(tempDir, je.getName()); | ||
|
||
if (!fl.exists()) | ||
{ | ||
fl.getParentFile().mkdirs(); | ||
//fl = new File(tempDir, je.getName()); | ||
} | ||
if (je.isDirectory()) | ||
{ | ||
continue; | ||
} | ||
|
||
Files.copy(jarStream, fl.toPath(), StandardCopyOption.REPLACE_EXISTING); | ||
} | ||
|
||
phpParserLoc = values.sourceLocation(tempDir.getAbsolutePath() + "/PHP-Parser/"); | ||
} | ||
} | ||
return phpParserLoc; | ||
} | ||
} |