Skip to content

Commit

Permalink
Merge pull request #1407 from aleksandy/cleanup-code
Browse files Browse the repository at this point in the history
Cleanup code
  • Loading branch information
xael-fry authored Oct 4, 2022
2 parents 576fcc0 + b51bea0 commit d6dae44
Show file tree
Hide file tree
Showing 122 changed files with 591 additions and 741 deletions.
10 changes: 0 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ nbproject/private
framework/tests-results
framework/src/version
framework/src/play/version
framework/src/play/version
framework/src/play/version
framework/tests/test-application/db
framework/play-*.jar
framework/docs
Expand All @@ -33,7 +31,6 @@ eclipse
.project
id
framework/tests-tmp
framework/docs
dist
modules/bespin/lib/bespin.jar
modules/ecss/lib/ecss.jar
Expand All @@ -42,7 +39,6 @@ resources/catalog.xml
resources/nbproject/private
modules/gae/lib/gae.jar
catalog.xml
modules/gae/lib/gae.jar
play-*.jar
modules/gae/bin
modules/gwt/lib/play-gwt.jar
Expand All @@ -51,7 +47,6 @@ test-result
logs
db
*.pyc
test-result
samples-and-tests/with-gwt/nbproject
samples-and-tests/jobboard/db
samples-and-tests/jobboard/tmp
Expand Down Expand Up @@ -133,11 +128,7 @@ atlassian-ide-plugin.xml
modules/*
build.classes
modules/crud/nbproject
nbproject
samples-and-tests/jobboard/attachments
samples-and-tests/jobboard/logs
samples-and-tests/jobboard/test-result
samples-and-tests/jobboard/tmp
samples-and-tests/validation/logs
samples-and-tests/zencontact/precompiled
!modules/docviewer
Expand All @@ -148,4 +139,3 @@ samples-and-tests/zencontact/precompiled
!modules/testrunner
!framework/src/play/db
!framework/test-src/play/db
*~
2 changes: 1 addition & 1 deletion framework/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
<!-- Tests -->

<target name="compile-tests" depends="compile">
<javac encoding="utf-8" nowarn="${compile.nowarn}" debug="true" destdir="classes" classpathref="project.classpath" srcdir="tests/src" source="1.8" target="1.8">
<javac encoding="utf-8" nowarn="${compile.nowarn}" debug="true" destdir="classes" classpathref="project.classpath" srcdir="tests/src" source="11" target="11">
<include name="**/*.java"/>
</javac>
</target>
Expand Down
3 changes: 1 addition & 2 deletions framework/src/play/Invoker.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,9 @@ public String getErrorDescription() {
static class WaitForTasksCompletion extends Thread {

static WaitForTasksCompletion instance;
Map<Future<?>, Invocation> queue;
final Map<Future<?>, Invocation> queue = new ConcurrentHashMap<>();

public WaitForTasksCompletion() {
queue = new ConcurrentHashMap<>();
setName("WaitForTasksCompletion");
setDaemon(true);
}
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class Logger {
/**
* When using java.util.logging.
*/
public static java.util.logging.Logger juli = java.util.logging.Logger.getLogger("play");
public static final java.util.logging.Logger juli = java.util.logging.Logger.getLogger("play");
/**
* true if logger is configured manually (log4j-config file supplied by application)
*/
Expand Down
10 changes: 5 additions & 5 deletions framework/src/play/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,23 @@ public boolean isProd() {
/**
* All paths to search for files
*/
public static List<VirtualFile> roots = new ArrayList<>(16);
public static final List<VirtualFile> roots = new ArrayList<>(16);
/**
* All paths to search for Java files
*/
public static List<VirtualFile> javaPath = new CopyOnWriteArrayList<>();
/**
* All paths to search for templates files
*/
public static List<VirtualFile> templatesPath = new ArrayList<>(2);
public static final List<VirtualFile> templatesPath = new ArrayList<>(2);
/**
* Main routes file
*/
public static VirtualFile routes;
/**
* Plugin routes files
*/
public static Map<String, VirtualFile> modulesRoutes = new HashMap<>(16);
public static final Map<String, VirtualFile> modulesRoutes = new HashMap<>(16);
/**
* The loaded configuration files
*/
Expand Down Expand Up @@ -166,7 +166,7 @@ public boolean isProd() {
/**
* Modules
*/
public static Map<String, VirtualFile> modules = new HashMap<>(16);
public static final Map<String, VirtualFile> modules = new HashMap<>(16);
/**
* Framework version
*/
Expand Down Expand Up @@ -426,7 +426,7 @@ private static Properties readOneConfigurationFile(String filename) {
for (Object key : propsFromFile.keySet()) {
String value = propsFromFile.getProperty(key.toString());
Matcher matcher = pattern.matcher(value);
StringBuffer newValue = new StringBuffer(100);
StringBuilder newValue = new StringBuilder(100);
while (matcher.find()) {
String jp = matcher.group(1);
String r;
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/PlayPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public Collection<Class> getFunctionalTests() {
* transaction around an action. The filter applies a transaction to the current Action.
*/
public abstract static class Filter<T> {
String name;
final String name;

public Filter(String name) {
this.name = name;
Expand Down
7 changes: 3 additions & 4 deletions framework/src/play/cache/EhCacheImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
*/
public class EhCacheImpl implements CacheImpl {

private static final String cacheName = "play";
private static EhCacheImpl uniqueInstance;

CacheManager cacheManager;
final CacheManager cacheManager = CacheManager.create();

net.sf.ehcache.Cache cache;
final net.sf.ehcache.Cache cache;

private static final String cacheName = "play";

private EhCacheImpl() {
this.cacheManager = CacheManager.create();
this.cacheManager.addCache(cacheName);
this.cache = cacheManager.getCache(cacheName);
}
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/classloading/ApplicationClasses.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ApplicationClasses {
/**
* Reference to the eclipse compiler.
*/
ApplicationCompiler compiler = new ApplicationCompiler(this);
final ApplicationCompiler compiler = new ApplicationCompiler(this);
/**
* Cache of all compiled classes
*/
Expand Down
5 changes: 2 additions & 3 deletions framework/src/play/classloading/ApplicationClassloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ public void detectChanges() throws RestartNeededException {
modifieds.add(applicationClass);
}
}
Set<ApplicationClass> modifiedWithDependencies = new HashSet<>();
modifiedWithDependencies.addAll(modifieds);
Set<ApplicationClass> modifiedWithDependencies = new HashSet<>(modifieds);
if (!modifieds.isEmpty()) {
modifiedWithDependencies.addAll(Play.pluginCollection.onClassesChange(modifieds));
}
Expand Down Expand Up @@ -446,7 +445,7 @@ public List<Class> getAllClasses() {
}
}

Collections.sort(result, Comparator.comparing(Class::getName));
result.sort(Comparator.comparing(Class::getName));
}

Map<String, ApplicationClass> byNormalizedName = new HashMap<>(result.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* they could check if the state of the ApplicationClassloader has changed..
*/
public class ApplicationClassloaderState {
private static AtomicLong nextStateValue = new AtomicLong();
private static final AtomicLong nextStateValue = new AtomicLong();

private final long currentStateValue = nextStateValue.getAndIncrement();

Expand All @@ -24,9 +24,7 @@ public boolean equals(Object o) {

ApplicationClassloaderState that = (ApplicationClassloaderState) o;

if (currentStateValue != that.currentStateValue) return false;

return true;
return this.currentStateValue == that.currentStateValue;
}

@Override
Expand Down
63 changes: 32 additions & 31 deletions framework/src/play/classloading/ApplicationCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@
*/
public class ApplicationCompiler {

Map<String, Boolean> packagesCache = new HashMap<>();
ApplicationClasses applicationClasses;
Map<String, String> settings;
private static final String JAVA_SOURCE_DEFAULT_VERSION = "11";
static final Map<String, String> compatibleJavaVersions = new HashMap<>();
static {
compatibleJavaVersions.put("11", CompilerOptions.VERSION_11);
compatibleJavaVersions.put("12", CompilerOptions.VERSION_12);
compatibleJavaVersions.put("13", CompilerOptions.VERSION_13);
compatibleJavaVersions.put("14", CompilerOptions.VERSION_14);
compatibleJavaVersions.put("15", CompilerOptions.VERSION_15);
compatibleJavaVersions.put("16", CompilerOptions.VERSION_16);
compatibleJavaVersions.put("17", CompilerOptions.VERSION_17);
compatibleJavaVersions.put("18", CompilerOptions.VERSION_18);
}
static final Map<String, String> compatibleJavaVersions = Map.of(
"11", CompilerOptions.VERSION_11,
"12", CompilerOptions.VERSION_12,
"13", CompilerOptions.VERSION_13,
"14", CompilerOptions.VERSION_14,
"15", CompilerOptions.VERSION_15,
"16", CompilerOptions.VERSION_16,
"17", CompilerOptions.VERSION_17,
"18", CompilerOptions.VERSION_18
);

final Map<String, Boolean> packagesCache = new HashMap<>();
final ApplicationClasses applicationClasses;
final Map<String, String> settings;

/**
* Try to guess the magic configuration options
Expand All @@ -57,32 +57,33 @@ public class ApplicationCompiler {
* The application classes container
*/
public ApplicationCompiler(ApplicationClasses applicationClasses) {
this.applicationClasses = applicationClasses;
this.settings = new HashMap<>();
this.settings.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE);
this.settings.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
this.settings.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE);
this.settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
this.settings.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE);
this.settings.put(CompilerOptions.OPTION_Encoding, "UTF-8");
this.settings.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);

final String runningJavaVersion = System.getProperty("java.version");
if (Stream.of("1.5", "1.6", "1.7", "1.8", "9", "10").anyMatch(runningJavaVersion::startsWith)) {
if (Stream.of("1.5", "1.6", "1.7", "1.8", "9", "10").anyMatch(runningJavaVersion::startsWith)) {
throw new CompilationException("JDK version prior to 11 are not supported to run the application");
}

final String configSourceVersion = Play.configuration.getProperty("java.source", JAVA_SOURCE_DEFAULT_VERSION);
final String jdtVersion = compatibleJavaVersions.get(configSourceVersion);
if (jdtVersion == null) {
throw new CompilationException(String.format("Incompatible Java version specified (%s). Compatible versions are: %s",
configSourceVersion, compatibleJavaVersions.keySet()));
configSourceVersion, compatibleJavaVersions.keySet()));
}

this.settings.put(CompilerOptions.OPTION_Source, jdtVersion);
this.settings.put(CompilerOptions.OPTION_TargetPlatform, jdtVersion);
this.settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE);
this.settings.put(CompilerOptions.OPTION_Compliance, jdtVersion);
this.settings.put(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE);
this.applicationClasses = applicationClasses;
this.settings = Map.ofEntries(
Map.entry(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE),
Map.entry(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE),
Map.entry(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.GENERATE),
Map.entry(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE),
Map.entry(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE),
Map.entry(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE),
Map.entry(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE),
Map.entry(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE),
Map.entry(CompilerOptions.OPTION_Encoding, "UTF-8"),
Map.entry(CompilerOptions.OPTION_Source, jdtVersion),
Map.entry(CompilerOptions.OPTION_TargetPlatform, jdtVersion),
Map.entry(CompilerOptions.OPTION_Compliance, jdtVersion)
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@

public class ContinuationEnhancer extends Enhancer {

static final List<String> continuationMethods = new ArrayList<>();

static {
continuationMethods.add("play.mvc.Controller.await(java.lang.String)");
continuationMethods.add("play.mvc.Controller.await(int)");
continuationMethods.add("play.mvc.Controller.await(java.util.concurrent.Future)");
continuationMethods.add("play.mvc.WebSocketController.await(java.lang.String)");
continuationMethods.add("play.mvc.WebSocketController.await(int)");
continuationMethods.add("play.mvc.WebSocketController.await(java.util.concurrent.Future)");
}
private static final List<String> continuationMethods = List.of(
"play.mvc.Controller.await(java.lang.String)",
"play.mvc.Controller.await(int)",
"play.mvc.Controller.await(java.util.concurrent.Future)",
"play.mvc.WebSocketController.await(java.lang.String)",
"play.mvc.WebSocketController.await(int)",
"play.mvc.WebSocketController.await(java.util.concurrent.Future)"
);

public static boolean isEnhanced(String appClassName) {
ApplicationClass appClass = Play.classes.getApplicationClass( appClassName);
Expand Down
2 changes: 1 addition & 1 deletion framework/src/play/classloading/enhancers/Enhancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
public abstract class Enhancer {

protected ClassPool classPool;
protected final ClassPool classPool;

public Enhancer() {
this.classPool = newClassPool();
Expand Down
Loading

0 comments on commit d6dae44

Please sign in to comment.