public int compare(ClasspathEntry o1, ClasspathEntry o2) { return prioritySolver.getPriorityOf(o2) - prioritySolver.getPriorityOf(o1); } });
public void copyFilesToJar(JarOutputStream jos, ClasspathFileFilter classpathFileFilter) { for (ClasspathFile classpathFile : this.getClasspathFilesFiltering(classpathFileFilter)) CopyUtils.addEntryToJar(jos, classpathFile.openInputStream(), classpathFile.getPath()); } }
public boolean accept(ClasspathFile classpathFile) { String string= classpathFile.getPath(); boolean isServerSideOnly= string.contains(File.separator + "serverside"); boolean isDebuggingPackage= string.contains(File.separator + "debugging"); if (!CompilerMode.Production.toString().equals(System.getProperty("dragome-compile-mode"))) isDebuggingPackage= false; return !(isServerSideOnly || isDebuggingPackage); } }
public Parser(ClassUnit theFileUnit) { fileUnit= theFileUnit; fileUnit.annotations= null; AttributeReader r= new AnnotationReader(fileUnit); Attribute.addAttributeReader("RuntimeVisibleAnnotations", r); try { InputStream openInputStream= fileUnit.getClassFile().openInputStream(); String filename= fileUnit.getName(); byte[] originalByteArray= IOUtils.toByteArray(openInputStream); byte[] transformedArray= originalByteArray; transformedArray= lambdaUsageBackporter.transform(filename, transformedArray); if (DragomeJsCompiler.compiler.bytecodeTransformer != null) if (DragomeJsCompiler.compiler.bytecodeTransformer.requiresTransformation(filename)) transformedArray= DragomeJsCompiler.compiler.bytecodeTransformer.transform(filename, transformedArray); fileUnit.setBytecodeArrayI(transformedArray); ClassParser cp= new ClassParser(new ByteArrayInputStream(transformedArray), filename); jc= cp.parse(); } catch (IOException e) { throw new RuntimeException(e); } } public TypeDeclaration parse()
public void configure(BytecodeToJavascriptCompilerConfiguration compilerConfiguration) { if (!initialized) { compiler= this; this.compilerConfiguration= compilerConfiguration; initFromCompilerType(compilerConfiguration.getCompilerType()); Project.singleton= null; // compiler.setBasedir(basedir); compiler.setClasspath(compilerConfiguration.getClasspath()); compiler.addClasspathFilter(compilerConfiguration.getClasspathFilter()); if (compilerConfiguration.getBytecodeTransformer() != null) compiler.setBytecodeTransformer(compilerConfiguration.getBytecodeTransformer()); Assembly assembly= new Assembly(); assembly.setEntryPointClassName(compilerConfiguration.getMainClassName()); assembly.setTargetLocation(new File(compilerConfiguration.getTargetDir())); compiler.addAssembly(assembly); compiler.setGenerateLineNumbers(false); compiler.setCompression(false); logger = Log.logger; initialized= true; } }
if (compilerConfiguration.isCaching() && cacheFile == null) project.setStopOnMissingClass(compilerConfiguration.isFailOnError()); setFailOnError(compilerConfiguration.isFailOnError()); assembly.setProject(project); assembly.setClasspathFilter(classpathFilter); for (ClasspathFile file : classpathFiles) if (file.getPath().contains(".class")) if (file.getPath().contains(".class")) classUnit.getClassFile().close();
public Object run() { // define a package if necessary. int i= classname.lastIndexOf('.'); if (i > 0) { String packageName= classname.substring(0, i); Package pkg= getPackage(packageName); if (pkg == null) { definePackage(packageName, null, null, null, null, null, null, null); } } byte[] newData; if (bytecodeTransformer == null || !bytecodeTransformer.requiresTransformation(classname) || loadingClass.contains(classname)) newData= classData; else { loadingClass.add(classname); Thread.currentThread().setContextClassLoader(last); newData= bytecodeTransformer.transform(classname, classData); Thread.currentThread().setContextClassLoader(DragomeInstrumentationClassLoader.this); } ProtectionDomain domain= this.getClass().getProtectionDomain(); return defineClass(classname, newData, 0, newData.length, domain); } }, acc);
public boolean requiresTransformation(String className) { boolean transform= false; for (InstrumentationDragomeConfigurator configurator : configurators) if (configurator.isEnabled()) transform|= configurator.getBytecodeTransformer().requiresTransformation(className); return transform; } };
public static void compileWithMainClass(Classpath classPath, String target) { ServiceLocator serviceLocator= ServiceLocator.getInstance(); DragomeConfigurator configurator= serviceLocator.getConfigurator(); String mainClassName= VisualActivity.class.getName(); CompilerType defaultCompilerType= configurator.getDefaultCompilerType(); BytecodeTransformer bytecodeTransformer= configurator.getBytecodeTransformer(); ClasspathFileFilter classpathFilter= configurator.getClasspathFilter(); if (classpathFilter == null) classpathFilter= new DefaultClasspathFileFilter(); BytecodeToJavascriptCompiler bytecodeToJavascriptCompiler= WebServiceLocator.getInstance().getBytecodeToJavascriptCompiler(); List<ClasspathEntry> extraClasspath= configurator.getExtraClasspath(classPath); classPath.addEntries(extraClasspath); configurator.sortClassPath(classPath); classPath= process(classPath, configurator); BytecodeToJavascriptCompilerConfiguration compilerConfiguration= new BytecodeToJavascriptCompilerConfiguration(classPath, target, mainClassName, defaultCompilerType, bytecodeTransformer, new DefaultClasspathFileFilter(), configurator.isCheckingCast(), configurator.isCaching(), configurator.isFailOnError()); bytecodeToJavascriptCompiler.configure(compilerConfiguration); bytecodeToJavascriptCompiler.compile(); }
final Classpath classPath= new Classpath(); classPath.addEntry(theClassPathEntry); else LOGGER.warning("Skipping, it is not configured as an included artifact."); LOGGER.info("Using Dragome compiler classpath : " + classPath.toString()); CopyUtils.copyFilesOfFolder(webappDirectory, theTargetDir);
public byte[] transform(String className, byte[] bytecode) { byte[] transformedBytecode= bytecode; for (InstrumentationDragomeConfigurator configurator : configurators) if (configurator.isEnabled()) transformedBytecode= configurator.getBytecodeTransformer().transform(className, transformedBytecode); return transformedBytecode; }
public void visit(CastExpression cast) { if (cast.getTypeBinding() != Type.VOID && DragomeJsCompiler.compiler.compilerConfiguration.isCheckingCast()) { print("dragomeJs.checkCast("); cast.getExpression().visit(this); String string= cast.getTypeBinding().toString(); String normalizeExpression= normalizeExpression(string); if (string.startsWith("[L")) normalizeExpression= "'" + string + "'"; print("," + normalizeExpression + ")"); } else { // TODO: Is it correct to remove casts to void (i.e. pop)? // print("void "); cast.getExpression().visit(this); } }
public Object run() { // define a package if necessary. int i= classname.lastIndexOf('.'); if (i > 0) { String packageName= classname.substring(0, i); Package pkg= getPackage(packageName); if (pkg == null) { definePackage(packageName, null, null, null, null, null, null, null); } } byte[] newData; if (!bytecodeTransformer.requiresTransformation(classname) || loadingClass.contains(classname)) newData= classData; else { loadingClass.add(classname); Thread.currentThread().setContextClassLoader(last); newData= transformer.transform(classData); Thread.currentThread().setContextClassLoader(DragomeContinuationClassLoader.this); } ProtectionDomain domain= this.getClass().getProtectionDomain(); return defineClass(classname, newData, 0, newData.length, domain); } }, acc);