Code polishing and general cleanup

This commit is contained in:
Oleg Zhurakousky
2018-06-27 08:43:28 -04:00
parent bb397c6a07
commit 377c4d93f0
7 changed files with 61 additions and 89 deletions

View File

@@ -34,9 +34,7 @@ public class CompiledClassDefinition {
if (classname.startsWith("/")) { if (classname.startsWith("/")) {
classname = classname.substring(1); classname = classname.substring(1);
} }
classname = classname.replace('/', '.').substring(0, classname.length() - 6); // strip classname = classname.replace('/', '.').substring(0, classname.length() - 6); // strip off .class
// off
// .class
} }
public String getName() { public String getName() {

View File

@@ -29,8 +29,6 @@ import java.util.NoSuchElementException;
*/ */
public class DirEnumeration implements Enumeration<File> { public class DirEnumeration implements Enumeration<File> {
// private final static Logger logger = LoggerFactory.getLogger(DirEnumeration.class);
// The starting point // The starting point
private File basedir; private File basedir;
@@ -87,7 +85,6 @@ public class DirEnumeration implements Enumeration<File> {
} }
} }
} }
// logger.debug("after visiting {} filesToReturn=#{} dirsToExplore=#{}",dir,filesToReturn.size(), directoriesToExplore.size());
} }
public File getDirectory() { public File getDirectory() {

View File

@@ -143,7 +143,6 @@ public class IterableClasspath extends CloseableFilterableJavaFileObjectIterable
// nested jar in uber jar // nested jar in uber jar
logger.debug("opening nested archive {}",entry.getName()); logger.debug("opening nested archive {}",entry.getName());
ZipInputStream zis = new ZipInputStream(openArchive.getInputStream(entry)); ZipInputStream zis = new ZipInputStream(openArchive.getInputStream(entry));
// nextEntry = new NestedZipEntryJavaFileObject(openArchive.firstElement(),openArchive.peek(),entry);
Enumeration<? extends ZipEntry> nestedZipEnumerator = new ZipEnumerator(zis); Enumeration<? extends ZipEntry> nestedZipEnumerator = new ZipEnumerator(zis);
nestedZip = entry; nestedZip = entry;
openArchiveEnumeration.push(nestedZipEnumerator); openArchiveEnumeration.push(nestedZipEnumerator);

View File

@@ -68,8 +68,6 @@ public class MemoryBasedJavaFileManager implements JavaFileManager {
private CompilationOutputCollector outputCollector; private CompilationOutputCollector outputCollector;
// private List<CloseableFilterableJavaFileObjectIterable> toClose = new ArrayList<>();
private Map<String, File> resolvedAdditionalDependencies = new LinkedHashMap<>(); private Map<String, File> resolvedAdditionalDependencies = new LinkedHashMap<>();
private String platformClasspath; private String platformClasspath;
@@ -194,9 +192,6 @@ public class MemoryBasedJavaFileManager implements JavaFileManager {
} }
} else { } else {
int idx = name.lastIndexOf('/') + 1; int idx = name.lastIndexOf('/') + 1;
// if (name.contains("TestX")) {
// System.out.println("For TestX: "+name+" "+idx+" "+BOOT_PACKAGING_PREFIX_FOR_CLASSES.length());
// }
if (idx != 0 ) { if (idx != 0 ) {
// Normalize to forward slashes // Normalize to forward slashes
name = name.replace('\\', '/'); name = name.replace('\\', '/');

View File

@@ -58,14 +58,8 @@ public class RuntimeJavaCompiler {
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>(); DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
MemoryBasedJavaFileManager fileManager = new MemoryBasedJavaFileManager(); MemoryBasedJavaFileManager fileManager = new MemoryBasedJavaFileManager();
List<CompilationMessage> resolutionMessages = fileManager.addAndResolveDependencies(dependencies); List<CompilationMessage> resolutionMessages = fileManager.addAndResolveDependencies(dependencies);
// JavaFileObject sourceFile = new StringBasedJavaSourceFileObject(className, classSourceCode);
JavaFileObject sourceFile = InMemoryJavaFileObject.getSourceJavaFileObject(className, classSourceCode); JavaFileObject sourceFile = InMemoryJavaFileObject.getSourceJavaFileObject(className, classSourceCode);
// new InMemoryJavaFileObject(StandardLocation.SOURCE_PATH, className, javax.tools.JavaFileObject.Kind.SOURCE, null);
// try (Writer w = sourceFile.openWriter()) {
// w.write(classSourceCode);
// } catch (IOException ioe) {
// ioe.printStackTrace();
// }
Iterable<? extends JavaFileObject> compilationUnits = Arrays.asList(sourceFile); Iterable<? extends JavaFileObject> compilationUnits = Arrays.asList(sourceFile);
CompilationTask task = compiler.getTask(null, fileManager , diagnosticCollector, null, null, compilationUnits); CompilationTask task = compiler.getTask(null, fileManager , diagnosticCollector, null, null, compilationUnits);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2016-2017 the original author or authors. * Copyright 2016-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package org.springframework.cloud.function.context.catalog;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
@@ -66,28 +65,18 @@ public class InMemoryFunctionCatalog
@Override @Override
public <T> void register(FunctionRegistration<T> registration) { public <T> void register(FunctionRegistration<T> registration) {
FunctionRegistrationEvent event; Class<?> type = Object.class;
Class<?> type;
if (registration.getTarget() instanceof Function) { if (registration.getTarget() instanceof Function) {
type = Function.class; type = Function.class;
event = new FunctionRegistrationEvent(this, Function.class,
registration.getNames());
} }
else if (registration.getTarget() instanceof Supplier) { else if (registration.getTarget() instanceof Supplier) {
type = Supplier.class; type = Supplier.class;
event = new FunctionRegistrationEvent(this, Supplier.class,
registration.getNames());
} }
else if (registration.getTarget() instanceof Consumer) { else if (registration.getTarget() instanceof Consumer) {
type = Consumer.class; type = Consumer.class;
event = new FunctionRegistrationEvent(this, Consumer.class,
registration.getNames());
}
else {
type = Object.class;
event = new FunctionRegistrationEvent(this, Object.class,
registration.getNames());
} }
FunctionRegistrationEvent event = new FunctionRegistrationEvent(this, type, registration.getNames());
registrations.put(registration.getTarget(), registration); registrations.put(registration.getTarget(), registration);
FunctionRegistration<T> wrapped = registration.wrap(); FunctionRegistration<T> wrapped = registration.wrap();
if (wrapped != registration) { if (wrapped != registration) {

View File

@@ -71,7 +71,7 @@ public abstract class MessageUtils {
/** /**
* Convert a message from the handler into one that is safe to consume in the caller's * Convert a message from the handler into one that is safe to consume in the caller's
* class laoder. If the handler is a wrapper for a function in an isolated class * class loader. If the handler is a wrapper for a function in an isolated class
* loader, then the message will be created with the target class loader (therefore * loader, then the message will be created with the target class loader (therefore
* the {@link Message} class must be on the classpath of the target class loader). * the {@link Message} class must be on the classpath of the target class loader).
* *