commons-jci-1.1-src/LICENSE.txt 100644 0 0 26446 10210074062 13354 0 ustar 0 0 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
commons-jci-1.1-src/NOTICE.txt 100644 0 0 261 12102311744 13201 0 ustar 0 0 Apache Commons JCI
Copyright 2004-2011 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
commons-jci-1.1-src/pom.xml 100644 0 0 31375 12225251543 13054 0 ustar 0 0
4.0.0
org.apache.commons
commons-parent
32
pom
org.apache.commons
commons-jci
1.1
Apache Commons JCI
Apache Commons JCI is a java compiler interface.
It can be used to compile Java itself, or any other language that can be compiled to Java classes (e.g. groovy or javascript).
It is well integrated with a FAM (FilesystemAlterationMonitor) that can be used with the JCI compiling/reloading classloader.
All the currently supported compilers feature in-memory compilation.
http://commons.apache.org/proper/commons-jci/
2004
JIRA
https://issues.apache.org/jira/browse/JCI
fam
core
compilers/eclipse
compilers/janino
compilers/groovy
compilers/rhino
examples
compiler-jsr199
compilers/jsr199
tcurdt
Torsten Curdt
tcurdt at apache.org
ASF
http://www.apache.org/
+1
Don Brown
mrdon at apache.org
ASF
http://www.apache.org/
Joerk Heinicke
joerg.heinicke at gmx.de
Mark Proctor
mproctor at codehaus.org
scm:svn:http://svn.apache.org/repos/asf/commons/proper/jci/trunk/
scm:svn:https://svn.apache.org/repos/asf/commons/proper/jci/trunk/
http://svn.apache.org/viewvc/commons/proper/jci/trunk/
org.apache.maven.plugins
maven-surefire-plugin
org.apache.commons.logging.impl.SimpleLog
error
org.codehaus.mojo
cobertura-maven-plugin
2.2
clean
maven-assembly-plugin
src/assembly/bin.xml
src/assembly/src.xml
gnu
org.apache.maven.plugins
maven-antrun-plugin
jci-jar-manifest
generate-sources
run
org.apache.maven.plugins
maven-site-plugin
${commons.site-plugin.version}
${maven-site-plugin.skip}
org.apache.maven.wagon
wagon-ssh-external
1.0-beta-2
org.codehaus.mojo
findbugs-maven-plugin
1.2
org.codehaus.mojo
taglist-maven-plugin
2.2
TODO
@todo
FIXME
@deprecated
true
org.apache.maven.plugins
maven-surefire-report-plugin
${commons.surefire.version}
true
org.apache.maven.plugins
maven-pmd-plugin
2.3
true
org.apache.maven.plugins
maven-jxr-plugin
${commons.jxr.version}
true
org.apache.maven.plugins
maven-javadoc-plugin
${commons.javadoc.version}
true
org.codehaus.mojo
cobertura-maven-plugin
${commons.cobertura.version}
true
false
1.5
1.5
jci
JCI
12310650
1.1
RC1
commons-logging
commons-logging
1.1.3
org.eclipse.jdt.core.compiler
ecj
4.2.2
org.codehaus.groovy
groovy-all
1.7.11
org.codehaus.janino
janino
2.6.1
rhino
js
1.7R2
commons-io
commons-io
2.2
commons-cli
commons-cli
1.2
javax.servlet
servlet-api
2.5
asm
asm
3.3.1
org.apache.commons
commons-lang3
3.1
junit
junit
4.11
commons-jci-1.1-src/README.txt 100644 0 0 635 10631474317 13175 0 ustar 0 0 In order to build commons-jci please use subversion to check it out via
svn co http://svn.apache.org/repos/asf/jakarta/commons/proper/jci/trunk/
You need to have maven 2.0.x installed. All you need to do is to call
mvn clean install
Releases are done with
mvn -Prelease release:prepare
mvn -Prelease release:perform
It is suggested to be using a ssh and gpg agent for the release process.
commons-jci-1.1-src/TODO.txt 100644 0 0 1520 12224753411 13012 0 ustar 0 0 ORDER BY IMPORTANCE
o simplify the maven build (right now uses custom modules and so on ... which always caused problems)
o update the maven build (bring it in line with the latest commons pom, plugins etc
o finish common configuration for some compilers
o finish implementation of jsr199 compiler
o removing of anonymous classes if parent class is being removed (could require interface changes)
o ability to add (contents of) jars to the store ...and be able to remove them again
o add exceptions to interfaces
o move the reader/store interfaces to streams
o documentation
o dependency analysis for proper re-try after errors
o maven plugin to compile with any of the compilers
o compiler discovery via META-INF
o new compiler implementations
o jikes
o pizza
o jruby (maybe?)
o jpython (maybe?)
o c# (maybe?)
commons-jci-1.1-src/core/src/ 40755 0 0 0 12060700110 13112 5 ustar 0 0 commons-jci-1.1-src/core/src/main/ 40755 0 0 0 12060700110 14036 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/ 40755 0 0 0 12060700110 14757 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/ 40755 0 0 0 12060700110 15546 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/ 40755 0 0 0 12060700110 16767 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/ 40755 0 0 0 12060700110 20442 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/ 40755 0 0 0 12224752676 21241 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/compilers/ 40755 0 0 0 12224752676 23236 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/listeners/ 40755 0 0 0 12224752676 23251 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/problems/ 40755 0 0 0 12224752676 23064 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/readers/ 40755 0 0 0 12224752676 22666 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/stores/ 40755 0 0 0 12224752676 22560 5 ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/utils/ 40755 0 0 0 12224752676 22401 5 ustar 0 0 commons-jci-1.1-src/core/src/main/resources/ 40755 0 0 0 12225261512 16063 5 ustar 0 0 commons-jci-1.1-src/core/src/site/ 40755 0 0 0 12060700110 14056 5 ustar 0 0 commons-jci-1.1-src/core/src/test/ 40755 0 0 0 12060700110 14071 5 ustar 0 0 commons-jci-1.1-src/core/src/test/java/ 40755 0 0 0 12060700110 15012 5 ustar 0 0 commons-jci-1.1-src/core/src/test/java/org/ 40755 0 0 0 12060700110 15601 5 ustar 0 0 commons-jci-1.1-src/core/src/test/java/org/apache/ 40755 0 0 0 12060700110 17022 5 ustar 0 0 commons-jci-1.1-src/core/src/test/java/org/apache/commons/ 40755 0 0 0 12060700110 20475 5 ustar 0 0 commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/ 40755 0 0 0 12224752676 21274 5 ustar 0 0 commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/classes/ 40755 0 0 0 12060700110 22677 5 ustar 0 0 commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/compilers/ 40755 0 0 0 12224752676 23271 5 ustar 0 0 commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/readers/ 40755 0 0 0 12060700110 22667 5 ustar 0 0 commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/stores/ 40755 0 0 0 12224752676 22613 5 ustar 0 0 commons-jci-1.1-src/core/src/test/resources/ 40755 0 0 0 12060700110 16103 5 ustar 0 0 commons-jci-1.1-src/core/pom.xml 100644 0 0 6534 12225250625 13763 0 ustar 0 0
4.0.0
org.apache.commons
commons-jci
1.1
commons-jci-core
1.1
Apache Commons JCI core
Apache Commons JCI core interfaces and implementations.
org.apache.commons
commons-jci-fam
${project.version}
commons-io
commons-io
commons-logging
commons-logging
asm
asm
test
org.apache.commons
commons-lang3
test
junit
junit
test
jci-core
true
org.apache.maven.plugins
maven-jar-plugin
test-jar
maven-assembly-plugin
true
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/compilers/AbstractJavaCompiler.java 100644 0 0 4122 10613666121 30222 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.compilers;
import org.apache.commons.jci.problems.CompilationProblemHandler;
import org.apache.commons.jci.readers.ResourceReader;
import org.apache.commons.jci.stores.ResourceStore;
/**
* Base class for compiler implementations. Provides just a few
* convenience methods.
*
* @author tcurdt
*/
public abstract class AbstractJavaCompiler implements JavaCompiler {
protected CompilationProblemHandler problemHandler;
public void setCompilationProblemHandler( final CompilationProblemHandler pHandler ) {
problemHandler = pHandler;
}
public CompilationResult compile( final String[] pClazzNames, final ResourceReader pReader, final ResourceStore pStore ) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = this.getClass().getClassLoader();
}
return compile(pClazzNames, pReader, pStore, classLoader, createDefaultSettings());
}
public CompilationResult compile( final String[] pClazzNames, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader ) {
return compile(pClazzNames, pReader, pStore, pClassLoader, createDefaultSettings());
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/compilers/CompilationResult.java 100644 0 0 4751 12204226200 27633 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.compilers;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.jci.problems.CompilationProblem;
/**
* A CompilationResult represents the result of a compilation.
* It includes errors (which failed the compilation) or warnings
* (that can be ignored and do not affect the creation of the
* class files)
*
* @author tcurdt
*/
public final class CompilationResult {
private final CompilationProblem[] errors;
private final CompilationProblem[] warnings;
public CompilationResult( final CompilationProblem[] pProblems ) {
final Collection errorsColl = new ArrayList();
final Collection warningsColl = new ArrayList();
for (CompilationProblem problem : pProblems) {
if (problem.isError()) {
errorsColl.add(problem);
} else {
warningsColl.add(problem);
}
}
errors = new CompilationProblem[errorsColl.size()];
errorsColl.toArray(errors);
warnings = new CompilationProblem[warningsColl.size()];
warningsColl.toArray(warnings);
}
public CompilationProblem[] getErrors() {
final CompilationProblem[] res = new CompilationProblem[errors.length];
System.arraycopy(errors, 0, res, 0, res.length);
return res;
}
public CompilationProblem[] getWarnings() {
final CompilationProblem[] res = new CompilationProblem[warnings.length];
System.arraycopy(warnings, 0, res, 0, res.length);
return res;
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/compilers/JavaCompiler.java 100644 0 0 6642 10613666121 26547 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.compilers;
import org.apache.commons.jci.problems.CompilationProblemHandler;
import org.apache.commons.jci.readers.ResourceReader;
import org.apache.commons.jci.stores.ResourceStore;
/**
* The general compiler interface. All compilers implementing
* this interface should read the resources from the reader
* and store the java class files into the ResourceStore.
*
* The actual compilation language does not matter. But the
* contract is that the result of the compilation will be a
* class file.
*
* If possible the compiler should notify the optional
* CompilationProblemHandler as soon as a problem is found.
*
* @author tcurdt
*/
public interface JavaCompiler {
/**
* Set the the handler that gets the notification of an error
* or warning as soon as this information is available from
* the compiler.
* Note: Some compilers might not support this feature.
*
* @param pHandler
*/
void setCompilationProblemHandler( final CompilationProblemHandler pHandler );
/**
* factory method to create the underlying default settings
*/
JavaCompilerSettings createDefaultSettings();
/**
* uses the default compiler settings and the current classloader
*/
CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore );
/**
* uses the default compiler settings
*/
CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader );
/**
* Compiles the java resources "some/path/to/MyJava.java"
* read through the ResourceReader and then stores the resulting
* classes in the ResourceStore under "some/path/to/MyJava.class".
* Note: As these are resource path you always have to use "/"
*
* The result of the compilation run including detailed error
* information is returned as CompilationResult. If you need to
* get notified already during the compilation process you can
* register a CompilationProblemHandler.
* Note: Not all compilers might support this notification mechanism.
*
* @param pResourcePaths
* @param pReader
* @param pStore
* @param pClassLoader
* @param pSettings
* @return always a CompilationResult
*/
CompilationResult compile( final String[] pResourcePaths, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings );
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerFactory.java 100644 0 0 5721 12204235717 30075 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.compilers;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.jci.utils.ConversionUtils;
/**
* Creates JavaCompilers
*
* TODO use META-INF discovery mechanism
*
* @author tcurdt
*/
public final class JavaCompilerFactory {
/**
* @deprecated will be remove after the next release, please create an instance yourself
*/
@Deprecated
private static final JavaCompilerFactory INSTANCE = new JavaCompilerFactory();
private final Map> classCache = new HashMap>();
/**
* @deprecated will be remove after the next release, please create an instance yourself
*/
@Deprecated
public static JavaCompilerFactory getInstance() {
return JavaCompilerFactory.INSTANCE;
}
/**
* Tries to guess the class name by convention. So for compilers
* following the naming convention
*
* org.apache.commons.jci.compilers.SomeJavaCompiler
*
* you can use the short-hands "some"/"Some"/"SOME". Otherwise
* you have to provide the full class name. The compiler is
* getting instanciated via (cached) reflection.
*
* @param pHint
* @return JavaCompiler or null
*/
public JavaCompiler createCompiler(final String pHint) {
final String className;
if (pHint.indexOf('.') < 0) {
className = "org.apache.commons.jci.compilers." + ConversionUtils.toJavaCasing(pHint) + "JavaCompiler";
} else {
className = pHint;
}
Class> clazz = classCache.get(className);
if (clazz == null) {
try {
clazz = Class.forName(className);
classCache.put(className, clazz);
} catch (ClassNotFoundException e) {
clazz = null;
}
}
if (clazz == null) {
return null;
}
try {
return (JavaCompiler) clazz.newInstance();
} catch (Throwable t) {
return null;
}
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/compilers/JavaCompilerSettings.java 100644 0 0 6276 12204235717 30274 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.compilers;
/**
* Most common denominator for JavaCompiler settings.
*
* If you need more specific settings you have to provide
* the native compiler configurations to the compilers.
* Writing of a custom factory is suggested.
*
* @author tcurdt
*/
public class JavaCompilerSettings {
private String targetVersion = "1.4";
private String sourceVersion = "1.4";
private String sourceEncoding = "UTF-8";
private boolean warnings = false;
private boolean deprecations = false;
private boolean debug = false;
/** @deprecated */
@Deprecated
private boolean verbose = false;
public JavaCompilerSettings() {
}
public JavaCompilerSettings( final JavaCompilerSettings pSettings ) {
targetVersion = pSettings.targetVersion;
sourceVersion = pSettings.sourceVersion;
sourceEncoding = pSettings.sourceEncoding;
warnings = pSettings.warnings;
deprecations = pSettings.deprecations;
debug = pSettings.debug;
}
public void setTargetVersion( final String pTargetVersion ) {
targetVersion = pTargetVersion;
}
public String getTargetVersion() {
return targetVersion;
}
public void setSourceVersion( final String pSourceVersion ) {
sourceVersion = pSourceVersion;
}
public String getSourceVersion() {
return sourceVersion;
}
public void setSourceEncoding( final String pSourceEncoding ) {
sourceEncoding = pSourceEncoding;
}
public String getSourceEncoding() {
return sourceEncoding;
}
public void setWarnings( final boolean pWarnings ) {
warnings = pWarnings;
}
public boolean isWarnings() {
return warnings;
}
public void setDeprecations( final boolean pDeprecations ) {
deprecations = pDeprecations;
}
public boolean isDeprecations() {
return deprecations;
}
public void setDebug( final boolean pDebug ) {
debug = pDebug;
}
public boolean isDebug() {
return debug;
}
/** @deprecated */
@Deprecated
public void setVerbose( final boolean pVerbose ) {
verbose = pVerbose;
}
/** @deprecated */
@Deprecated
public boolean isVerbose() {
return verbose;
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/compilers/package.html 100644 0 0 1626 10627343175 25614 0 ustar 0 0
Interfaces and abstract classes for the compiler abstraction itself.
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/listeners/CompilingListener.java 100644 0 0 16031 12204234514 27641 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.listeners;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.commons.jci.compilers.CompilationResult;
import org.apache.commons.jci.compilers.JavaCompiler;
import org.apache.commons.jci.compilers.JavaCompilerFactory;
import org.apache.commons.jci.monitor.FilesystemAlterationObserver;
import org.apache.commons.jci.problems.CompilationProblem;
import org.apache.commons.jci.readers.FileResourceReader;
import org.apache.commons.jci.readers.ResourceReader;
import org.apache.commons.jci.stores.MemoryResourceStore;
import org.apache.commons.jci.stores.ResourceStore;
import org.apache.commons.jci.stores.TransactionalResourceStore;
import org.apache.commons.jci.utils.ConversionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* A CompilingListener is an improved version of the ReloadingListener.
* It even compiles the classes from source before doing the reloading.
*
* @author tcurdt
*/
public class CompilingListener extends ReloadingListener {
private final Log log = LogFactory.getLog(CompilingListener.class);
private final JavaCompiler compiler;
private final TransactionalResourceStore transactionalStore;
private ResourceReader reader;
private CompilationResult lastResult;
public CompilingListener() {
this(new JavaCompilerFactory().createCompiler("eclipse"));
}
public CompilingListener( final JavaCompiler pCompiler ) {
this(pCompiler, new TransactionalResourceStore(new MemoryResourceStore()));
}
public CompilingListener( final JavaCompiler pCompiler, final TransactionalResourceStore pTransactionalStore ) {
super(pTransactionalStore);
compiler = pCompiler;
transactionalStore = pTransactionalStore;
lastResult = null;
}
public JavaCompiler getCompiler() {
return compiler;
}
public String getSourceFileExtension() {
return ".java";
}
public ResourceReader getReader( final FilesystemAlterationObserver pObserver ) {
return new FileResourceReader(pObserver.getRootDirectory());
}
public String getSourceNameFromFile( final FilesystemAlterationObserver pObserver, final File pFile ) {
return ConversionUtils.stripExtension(ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), pFile))) + getSourceFileExtension();
}
@Override
public ResourceStore getStore() {
return transactionalStore;
}
public synchronized CompilationResult getCompilationResult() {
return lastResult;
}
@Override
public void onStart( final FilesystemAlterationObserver pObserver ) {
super.onStart(pObserver);
reader = getReader(pObserver);
transactionalStore.onStart();
}
public String[] getResourcesToCompile( final FilesystemAlterationObserver pObserver ) {
final Collection created = getCreatedFiles();
final Collection changed = getChangedFiles();
final Collection resourceNames = new ArrayList();
for (File createdFile : created) {
if (createdFile.getName().endsWith(getSourceFileExtension())) {
resourceNames.add(getSourceNameFromFile(pObserver, createdFile));
}
}
for (File changedFile : changed) {
if (changedFile.getName().endsWith(getSourceFileExtension())) {
resourceNames.add(getSourceNameFromFile(pObserver, changedFile));
}
}
final String[] result = new String[resourceNames.size()];
resourceNames.toArray(result);
return result;
}
@Override
public boolean isReloadRequired( final FilesystemAlterationObserver pObserver ) {
boolean reload = false;
final Collection created = getCreatedFiles();
final Collection changed = getChangedFiles();
final Collection deleted = getDeletedFiles();
log.debug("created:" + created.size() + " changed:" + changed.size() + " deleted:" + deleted.size() + " resources");
if (deleted.size() > 0) {
for (File deletedFile : deleted) {
final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), deletedFile));
if (resourceName.endsWith(getSourceFileExtension())) {
// if source resource got removed delete the corresponding class
transactionalStore.remove(ConversionUtils.stripExtension(resourceName) + ".class");
} else {
// ordinary resource to be removed
transactionalStore.remove(resourceName);
}
// FIXME: does not remove nested classes
}
reload = true;
}
final String[] resourcesToCompile = getResourcesToCompile(pObserver);
if (resourcesToCompile.length > 0) {
log.debug(resourcesToCompile.length + " classes to compile");
final CompilationResult result = compiler.compile(resourcesToCompile, reader, transactionalStore);
synchronized(this) {
lastResult = result;
}
final CompilationProblem[] errors = result.getErrors();
final CompilationProblem[] warnings = result.getWarnings();
log.debug(errors.length + " errors, " + warnings.length + " warnings");
if (errors.length > 0) {
// FIXME: they need to be marked for re-compilation
// and then added as compileables again
for (int j = 0; j < resourcesToCompile.length; j++) {
transactionalStore.remove(resourcesToCompile[j]);
}
}
reload = true;
}
return reload;
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/listeners/FileChangeListener.java 100644 0 0 4076 12204234514 27673 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.listeners;
import java.io.File;
import org.apache.commons.jci.monitor.FilesystemAlterationObserver;
/**
* The most simple implemenation of an FilesystemAlterationListener.
*
* @author tcurdt
*/
public class FileChangeListener extends AbstractFilesystemAlterationListener {
private boolean changed;
public boolean hasChanged() {
return changed;
}
@Override
public void onStart( final FilesystemAlterationObserver pObserver ) {
changed = false;
super.onStart(pObserver);
}
@Override
public void onStop( final FilesystemAlterationObserver pObserver ) {
super.onStop(pObserver);
}
@Override
public void onFileChange( final File pFile ) {
changed = true;
}
@Override
public void onFileCreate( final File pFile ) {
changed = true;
}
@Override
public void onFileDelete( final File pFile ) {
changed = true;
}
@Override
public void onDirectoryChange( final File pDir ) {
}
@Override
public void onDirectoryCreate( final File pDir ) {
}
@Override
public void onDirectoryDelete( final File pDir ) {
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/listeners/package.html 100644 0 0 1656 10627343175 25632 0 ustar 0 0
Special FAM listeners for just collecting FAM statistics, to compilation or class reloading.
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/listeners/ReloadingListener.java 100644 0 0 13267 12204234514 27634 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.listeners;
import java.io.File;
import java.io.FileInputStream;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.io.IOUtils;
import org.apache.commons.jci.ReloadingClassLoader;
import org.apache.commons.jci.monitor.FilesystemAlterationObserver;
import org.apache.commons.jci.stores.MemoryResourceStore;
import org.apache.commons.jci.stores.ResourceStore;
import org.apache.commons.jci.stores.Transactional;
import org.apache.commons.jci.utils.ConversionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* This Listener waits for FAM events to trigger a reload of classes
* or resources.
*
* @author tcurdt
*/
public class ReloadingListener extends AbstractFilesystemAlterationListener {
private final Log log = LogFactory.getLog(ReloadingListener.class);
private final Set notificationListeners = new HashSet();
private final ResourceStore store;
public ReloadingListener() {
this(new MemoryResourceStore());
}
public ReloadingListener( final ResourceStore pStore ) {
store = pStore;
}
public ResourceStore getStore() {
return store;
}
public void addReloadNotificationListener( final ReloadNotificationListener pNotificationListener ) {
notificationListeners.add(pNotificationListener);
if (pNotificationListener instanceof ReloadingClassLoader) {
((ReloadingClassLoader)pNotificationListener).addResourceStore(store);
}
}
public boolean isReloadRequired( final FilesystemAlterationObserver pObserver ) {
boolean reload = false;
final Collection created = getCreatedFiles();
final Collection changed = getChangedFiles();
final Collection deleted = getDeletedFiles();
log.debug("created:" + created.size() + " changed:" + changed.size() + " deleted:" + deleted.size() + " resources");
if (deleted.size() > 0) {
for (File file : deleted) {
final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), file));
store.remove(resourceName);
}
reload = true;
}
if (created.size() > 0) {
for (File file : created) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
final byte[] bytes = IOUtils.toByteArray(is);
final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), file));
store.write(resourceName, bytes);
} catch(final Exception e) {
log.error("could not load " + file, e);
} finally {
IOUtils.closeQuietly(is);
}
}
}
if (changed.size() > 0) {
for (File file : changed) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
final byte[] bytes = IOUtils.toByteArray(is);
final String resourceName = ConversionUtils.getResourceNameFromFileName(ConversionUtils.relative(pObserver.getRootDirectory(), file));
store.write(resourceName, bytes);
} catch(final Exception e) {
log.error("could not load " + file, e);
} finally {
IOUtils.closeQuietly(is);
}
}
reload = true;
}
return reload;
}
@Override
public void onStop( final FilesystemAlterationObserver pObserver ) {
if (store instanceof Transactional) {
((Transactional)store).onStart();
}
final boolean reload = isReloadRequired(pObserver);
if (store instanceof Transactional) {
((Transactional)store).onStop();
}
if (reload) {
notifyReloadNotificationListeners();
}
super.onStop(pObserver);
}
void notifyReloadNotificationListeners() {
for (ReloadNotificationListener listener : notificationListeners) {
log.debug("notifying listener " + listener);
listener.handleNotification();
}
}
@Override
public void onDirectoryCreate( final File pDir ) {
}
@Override
public void onDirectoryChange( final File pDir ) {
}
@Override
public void onDirectoryDelete( final File pDir ) {
}
}
././@LongLink 100644 0 0 150 12225263274 10254 L ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/listeners/ReloadNotificationListener.java commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/listeners/ReloadNotificationListener.j100644 0 0 2051 10613666121 30767 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.listeners;
/**
* Classes implementing this interface can get notified by ReloadingListeners
*
* @author tcurdt
*/
public interface ReloadNotificationListener {
void handleNotification();
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/package.html 100644 0 0 1516 10627343175 23615 0 ustar 0 0
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/problems/CompilationProblem.java 100644 0 0 3635 12204154473 27617 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.problems;
/**
* An abstract definition of a compilation problem
*
* @author tcurdt
*/
public interface CompilationProblem {
/**
* is the problem an error and compilation cannot continue
* or just a warning and compilation can proceed
*
* @return true if the problem is an error
*/
boolean isError();
/**
* name of the file where the problem occurred
*
* @return name of the file where the problem occurred
*/
String getFileName();
/**
* position of where the problem starts in the source code
*
* @return position of where the problem starts in the source code
*/
int getStartLine();
int getStartColumn();
/**
* position of where the problem stops in the source code
*
* @return position of where the problem stops in the source code
*/
int getEndLine();
int getEndColumn();
/**
* the description of the problem
*
* @return the description of the problem
*/
String getMessage();
} ././@LongLink 100644 0 0 146 12225263274 10261 L ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/problems/CompilationProblemHandler.java commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/problems/CompilationProblemHandler.jav100644 0 0 2610 10613666121 30744 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.problems;
/**
* A CompilationProblemHandler gets access to a problem
* as soon as the problem is available while the
* CompilationResult only represents a summary at the
* end.
* The handler can be used to asynchronously update a
* GUI or stop compilation by returning false (e.g.
* when a maximum number of erros has been reached)
*
* NOTE:
* has to be supported by the compiler implementation!!
*
* @author tcurdt
*/
public interface CompilationProblemHandler {
boolean handle( final CompilationProblem pProblem );
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/problems/package.html 100644 0 0 1563 10627343175 25442 0 ustar 0 0
Compilation problems and related.
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/readers/FileResourceReader.java 100644 0 0 4520 12204235717 27327 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.readers;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
/**
* A simple file system based Reader implementation
*
* @author tcurdt
*/
public final class FileResourceReader implements ResourceReader {
private final File root;
public FileResourceReader( final File pRoot ) {
root = pRoot;
}
public boolean isAvailable( final String pResourceName ) {
return new File(root, pResourceName).exists();
}
public byte[] getBytes( final String pResourceName ) {
try {
return FileUtils.readFileToString(new File(root, pResourceName), "UTF-8").getBytes();
} catch(Exception e) {
return null;
}
}
/**
* @deprecated
*/
@Deprecated
public String[] list() {
final List files = new ArrayList();
list(root, files);
return files.toArray(new String[files.size()]);
}
/**
* @deprecated
*/
@Deprecated
private void list( final File pFile, final List pFiles ) {
if (pFile.isDirectory()) {
final File[] directoryFiles = pFile.listFiles();
for (int i = 0; i < directoryFiles.length; i++) {
list(directoryFiles[i], pFiles);
}
} else {
pFiles.add(pFile.getAbsolutePath().substring(root.getAbsolutePath().length()+1));
}
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/readers/MemoryResourceReader.java 100644 0 0 4075 12204235717 27725 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.readers;
import java.util.Map;
import java.util.HashMap;
/**
* A memory based reader to compile from memory
*
* @author tcurdt
*/
public class MemoryResourceReader implements ResourceReader {
private Map resources = null;
public boolean isAvailable( final String pResourceName ) {
if (resources == null) {
return false;
}
return resources.containsKey(pResourceName);
}
public void add( final String pResourceName, final byte[] pContent ) {
if (resources == null) {
resources = new HashMap();
}
resources.put(pResourceName, pContent);
}
public void remove( final String pResourceName ) {
if (resources != null) {
resources.remove(pResourceName);
}
}
public byte[] getBytes( final String pResourceName ) {
return resources.get(pResourceName);
}
/**
* @deprecated
*/
@Deprecated
public String[] list() {
if (resources == null) {
return new String[0];
}
return resources.keySet().toArray(new String[resources.size()]);
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/readers/package.html 100644 0 0 1561 10627343175 25242 0 ustar 0 0
Readers to read resources from.
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/readers/ResourceReader.java 100644 0 0 2135 10613666121 26526 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.readers;
/**
* A ResourceReader provide acces to resource like e.g. source code
*
* @author tcurdt
*/
public interface ResourceReader {
boolean isAvailable( final String pResourceName );
byte[] getBytes( final String pResourceName );
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/ReloadingClassLoader.java 100644 0 0 11064 12204235540 26224 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci;
import java.io.InputStream;
import java.net.URL;
import org.apache.commons.jci.listeners.ReloadNotificationListener;
import org.apache.commons.jci.stores.ResourceStore;
import org.apache.commons.jci.stores.ResourceStoreClassLoader;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* The ReloadingClassLoader uses a delegation mechansim to allow
* classes to be reloaded. That means that loadClass calls may
* return different results if the class was changed in the underlying
* ResourceStore.
*
* @author tcurdt
*/
public class ReloadingClassLoader extends ClassLoader implements ReloadNotificationListener {
private final Log log = LogFactory.getLog(ReloadingClassLoader.class);
private final ClassLoader parent;
private ResourceStore[] stores = new ResourceStore[0];
private ClassLoader delegate;
public ReloadingClassLoader( final ClassLoader pParent ) {
super(pParent);
parent = pParent;
delegate = new ResourceStoreClassLoader(parent, stores);
}
public boolean addResourceStore( final ResourceStore pStore ) {
try {
final int n = stores.length;
final ResourceStore[] newStores = new ResourceStore[n + 1];
System.arraycopy(stores, 0, newStores, 1, n);
newStores[0] = pStore;
stores = newStores;
delegate = new ResourceStoreClassLoader(parent, stores);
return true;
} catch ( final RuntimeException e ) {
log.error("could not add resource store " + pStore);
}
return false;
}
public boolean removeResourceStore( final ResourceStore pStore ) {
final int n = stores.length;
int i = 0;
// FIXME: this should be improved with a Map
// find the pStore and index position with var i
while ( ( i < n ) && ( stores[i] != pStore ) ) {
i++;
}
// pStore was not found
if ( i == n ) {
return false;
}
// if stores length > 1 then array copy old values, else create new empty store
final ResourceStore[] newStores = new ResourceStore[n - 1];
if (i > 0) {
System.arraycopy(stores, 0, newStores, 0, i);
}
if (i < n - 1) {
System.arraycopy(stores, i + 1, newStores, i, (n - i - 1));
}
stores = newStores;
delegate = new ResourceStoreClassLoader(parent, stores);
return true;
}
public void handleNotification() {
log.debug("reloading");
delegate = new ResourceStoreClassLoader(parent, stores);
}
@Override
public void clearAssertionStatus() {
delegate.clearAssertionStatus();
}
@Override
public URL getResource(String name) {
return delegate.getResource(name);
}
@Override
public InputStream getResourceAsStream(String name) {
return delegate.getResourceAsStream(name);
}
@Override
public Class> loadClass(String name) throws ClassNotFoundException {
return delegate.loadClass(name);
}
@Override
public void setClassAssertionStatus(String className, boolean enabled) {
delegate.setClassAssertionStatus(className, enabled);
}
@Override
public void setDefaultAssertionStatus(boolean enabled) {
delegate.setDefaultAssertionStatus(enabled);
}
@Override
public void setPackageAssertionStatus(String packageName, boolean enabled) {
delegate.setPackageAssertionStatus(packageName, enabled);
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/stores/FileResourceStore.java 100644 0 0 6713 12207137163 27120 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.stores;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
/**
* Stores the results on disk
*
* @author tcurdt
*/
public final class FileResourceStore implements ResourceStore {
private final File root;
public FileResourceStore( final File pFile ) {
root = pFile;
}
public byte[] read( final String pResourceName ) {
InputStream is = null;
try {
is = new FileInputStream(getFile(pResourceName));
final byte[] data = IOUtils.toByteArray(is);
return data;
} catch (Exception e) {
return null;
} finally {
IOUtils.closeQuietly(is);
}
}
public void write( final String pResourceName, final byte[] pData ) {
OutputStream os = null;
try {
final File file = getFile(pResourceName);
final File parent = file.getParentFile();
if (!parent.mkdirs() && !parent.isDirectory()) {
throw new IOException("could not create" + parent);
}
os = new FileOutputStream(file);
os.write(pData);
} catch (Exception e) {
// FIXME: now what?
} finally {
IOUtils.closeQuietly(os);
}
}
public void remove( final String pResourceName ) {
getFile(pResourceName).delete();
}
private File getFile( final String pResourceName ) {
final String fileName = pResourceName.replace('/', File.separatorChar);
return new File(root, fileName);
}
/**
* @deprecated
*/
@Deprecated
public String[] list() {
final List files = new ArrayList();
list(root, files);
return files.toArray(new String[files.size()]);
}
/**
* @deprecated
*/
@Deprecated
private void list(final File pFile, final List pFiles) {
if (pFile.isDirectory()) {
final File[] directoryFiles = pFile.listFiles();
for (int i=0; i < directoryFiles.length; i++) {
list(directoryFiles[i], pFiles);
}
} else {
pFiles.add(pFile.getAbsolutePath().substring(root.getAbsolutePath().length()+1));
}
}
@Override
public String toString() {
return this.getClass().getName() + root.toString();
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/stores/MemoryResourceStore.java 100644 0 0 4523 12204453271 27504 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.stores;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Store just in memory
*
* @author tcurdt
*/
public final class MemoryResourceStore implements ResourceStore {
private final Log log = LogFactory.getLog(MemoryResourceStore.class);
private final Map store = new HashMap();
public byte[] read( final String pResourceName ) {
log.debug("reading resource " + pResourceName);
return store.get(pResourceName);
}
public void write( final String pResourceName, final byte[] pData ) {
log.debug("writing resource " + pResourceName + "(" + pData.length + ")");
store.put(pResourceName, pData);
}
public void remove( final String pResourceName ) {
log.debug("removing resource " + pResourceName);
store.remove(pResourceName);
}
/**
* @deprecated
*/
@Deprecated
public String[] list() {
if (store == null) {
return new String[0];
}
final List names = new ArrayList();
for (String name : store.keySet()) {
names.add(name);
}
return names.toArray(new String[store.size()]);
}
@Override
public String toString() {
return this.getClass().getName() + store.toString();
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/stores/package.html 100644 0 0 1575 10627343175 25141 0 ustar 0 0
Stores to store the compilation results in.
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/stores/ResourceStore.java 100644 0 0 2272 10660136044 26312 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.stores;
/**
* A Store is where the compilers are storing the results
*
* @author tcurdt
*/
public interface ResourceStore {
void write( final String pResourceName, final byte[] pResourceData );
byte[] read( final String pResourceName );
//FIXME: return the result of the remove
void remove( final String pResourceName );
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/stores/ResourceStoreClassLoader.java 100644 0 0 6640 12204235540 30427 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.stores;
import org.apache.commons.jci.utils.ConversionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* A ClassLoader backed by an array of ResourceStores
*
* @author tcurdt
*/
public final class ResourceStoreClassLoader extends ClassLoader {
private final Log log = LogFactory.getLog(ResourceStoreClassLoader.class);
private final ResourceStore[] stores;
public ResourceStoreClassLoader( final ClassLoader pParent, final ResourceStore[] pStores ) {
super(pParent);
stores = new ResourceStore[pStores.length];
System.arraycopy(pStores, 0, stores, 0, stores.length);
}
private Class> fastFindClass(final String name) {
if (stores != null) {
for (ResourceStore store : stores) {
final byte[] clazzBytes = store.read(ConversionUtils.convertClassToResourcePath(name));
if (clazzBytes != null) {
log.debug(getId() + " found class: " + name + " (" + clazzBytes.length + " bytes)");
return defineClass(name, clazzBytes, 0, clazzBytes.length);
}
}
}
return null;
}
@Override
protected synchronized Class> loadClass(String name, boolean resolve) throws ClassNotFoundException {
// log.debug(getId() + " looking for: " + name);
Class> clazz = findLoadedClass(name);
if (clazz == null) {
clazz = fastFindClass(name);
if (clazz == null) {
final ClassLoader parent = getParent();
if (parent != null) {
clazz = parent.loadClass(name);
// log.debug(getId() + " delegating loading to parent: " + name);
} else {
throw new ClassNotFoundException(name);
}
} else {
log.debug(getId() + " loaded from store: " + name);
}
}
if (resolve) {
resolveClass(clazz);
}
return clazz;
}
@Override
protected Class> findClass( final String name ) throws ClassNotFoundException {
final Class> clazz = fastFindClass(name);
if (clazz == null) {
throw new ClassNotFoundException(name);
}
return clazz;
}
private String getId() {
return "" + this + "[" + this.getClass().getClassLoader() + "]";
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/stores/Transactional.java 100644 0 0 1761 10602276107 26313 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.stores;
/**
* Receive start/stop events
*
* @author tcurdt
*/
public interface Transactional {
void onStart();
void onStop();
}
././@LongLink 100644 0 0 145 12225263274 10260 L ustar 0 0 commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/stores/TransactionalResourceStore.java commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/stores/TransactionalResourceStore.java100644 0 0 3414 12204234514 31031 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.stores;
/**
* A TransactionalResourceStore get signals of the compilation process as a whole.
* When it started and when the compiler finished.
*
* @author tcurdt
*/
public class TransactionalResourceStore implements ResourceStore, Transactional {
private final ResourceStore store;
public TransactionalResourceStore( final ResourceStore pStore ) {
store = pStore;
}
public void onStart() {
}
public void onStop() {
}
public byte[] read( final String pResourceName ) {
return store.read(pResourceName);
}
public void remove( final String pResourceName ) {
store.remove(pResourceName);
}
public void write( final String pResourceName, final byte[] pResourceData ) {
store.write(pResourceName, pResourceData);
}
@Override
public String toString() {
return store.toString();
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/utils/ConversionUtils.java 100644 0 0 6436 12204154473 26505 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.utils;
import java.io.File;
import java.util.Locale;
/**
* Mainly common path manipultation helper methods
* NOT FOR USE OUTSIDE OF JCI
*
* @author tcurdt
*/
public final class ConversionUtils {
/**
* Please do not use - internal
* org/my/Class.xxx -> org.my.Class
*/
public static String convertResourceToClassName( final String pResourceName ) {
return ConversionUtils.stripExtension(pResourceName).replace('/', '.');
}
/**
* Please do not use - internal
* org.my.Class -> org/my/Class.class
*/
public static String convertClassToResourcePath( final String pName ) {
return pName.replace('.', '/') + ".class";
}
/**
* Please do not use - internal
* org/my/Class.xxx -> org/my/Class
*/
public static String stripExtension( final String pResourceName ) {
final int i = pResourceName.lastIndexOf('.');
if (i < 0) {
return pResourceName;
}
final String withoutExtension = pResourceName.substring(0, i);
return withoutExtension;
}
public static String toJavaCasing(final String pName) {
final char[] name = pName.toLowerCase(Locale.US).toCharArray();
name[0] = Character.toUpperCase(name[0]);
return new String(name);
}
/*
public static String clazzName( final File base, final File file ) {
final int rootLength = base.getAbsolutePath().length();
final String absFileName = file.getAbsolutePath();
final int p = absFileName.lastIndexOf('.');
final String relFileName = absFileName.substring(rootLength + 1, p);
final String clazzName = relFileName.replace(File.separatorChar, '.');
return clazzName;
}
*/
public static String relative( final File base, final File file ) {
final int rootLength = base.getAbsolutePath().length();
final String absFileName = file.getAbsolutePath();
final String relFileName = absFileName.substring(rootLength + 1);
return relFileName;
}
/**
* a/b/c.java -> a/b/c.java
* a\b\c.java -> a/b/c.java
* @param pFileName
* @return the converted name
*/
public static String getResourceNameFromFileName( final String pFileName ) {
if ('/' == File.separatorChar) {
return pFileName;
}
return pFileName.replace(File.separatorChar, '/');
}
}
commons-jci-1.1-src/core/src/main/java/org/apache/commons/jci/utils/package.html 100644 0 0 1533 10627343175 24754 0 ustar 0 0
Utilities
commons-jci-1.1-src/core/src/main/resources/LICENSE.txt 100644 0 0 26446 10607602354 20044 0 ustar 0 0 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
commons-jci-1.1-src/core/src/main/resources/NOTICE.txt 100644 0 0 270 12225261512 17661 0 ustar 0 0 Apache Commons JCI - Core
Copyright 2004-2013 The Apache Software Foundation
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
commons-jci-1.1-src/core/src/site/site.xml 100644 0 0 2350 10653675705 15674 0 ustar 0 0
Apache Commons JCI ROOT
jci-logo-white.png
http://commons.apache.org/jci/
commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/AbstractTestCase.java 100644 0 0 7465 12207137163 25434 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
*
* @author tcurdt
*/
public abstract class AbstractTestCase extends TestCase {
private final Log log = LogFactory.getLog(AbstractTestCase.class);
protected File directory;
@Override
protected void setUp() throws Exception {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
directory = createTempDirectory();
assertTrue(directory.exists());
assertTrue(directory.isDirectory());
}
protected File createDirectory( final String pName ) throws Exception {
final File newDirectory = new File(directory, pName);
assertTrue(newDirectory.mkdir());
assertTrue(newDirectory.exists());
assertTrue(newDirectory.isDirectory());
return newDirectory;
}
protected File writeFile( final String pName, final byte[] pData ) throws Exception {
final File file = new File(directory, pName);
final File parent = file.getParentFile();
if (!parent.mkdirs() && !parent.isDirectory()) {
throw new IOException("could not create" + parent);
}
log.debug("writing file " + pName + " (" + pData.length + " bytes)");
final FileOutputStream os = new FileOutputStream(file);
os.write(pData);
os.close();
assertTrue(file.exists());
assertTrue(file.isFile());
return file;
}
protected File writeFile( final String pName, final String pText ) throws Exception {
final File file = new File(directory, pName);
final File parent = file.getParentFile();
if (!parent.mkdirs() && !parent.isDirectory()) {
throw new IOException("could not create" + parent);
}
log.debug("writing " + file);
final FileWriter writer = new FileWriter(file);
writer.write(pText);
writer.close();
assertTrue(file.exists());
assertTrue(file.isFile());
return file;
}
protected void delay() {
try {
Thread.sleep(1500);
} catch (final InterruptedException e) {
}
}
protected File createTempDirectory() throws IOException {
final File tempFile = File.createTempFile("jci", null);
if (!tempFile.delete()) {
throw new IOException();
}
if (!tempFile.mkdir()) {
throw new IOException();
}
return tempFile;
}
@Override
protected void tearDown() throws Exception {
FileUtils.deleteDirectory(directory);
}
}
commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/classes/ExtendedDump.java 100644 0 0 6122 11134670534 26247 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.classes;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
public class ExtendedDump implements Opcodes {
public static byte[] dump() throws Exception {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
MethodVisitor mv;
cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Extended", null, "jci/Simple", null);
cw.visitSource("Extended.java", null);
{
mv = cw.visitMethod(ACC_PUBLIC, "", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLineNumber(3, l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "jci/Simple", "", "()V");
mv.visitInsn(RETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "Ljci/Extended;", null, l0, l1, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLineNumber(6, l0);
mv.visitTypeInsn(NEW, "java/lang/StringBuffer");
mv.visitInsn(DUP);
mv.visitLdcInsn("Extended:");
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuffer", "", "(Ljava/lang/String;)V");
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "jci/Simple", "toString", "()Ljava/lang/String;");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "append", "(Ljava/lang/String;)Ljava/lang/StringBuffer;");
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuffer", "toString", "()Ljava/lang/String;");
mv.visitInsn(ARETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "Ljci/Extended;", null, l0, l1, 0);
mv.visitMaxs(3, 1);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
}
commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/classes/SimpleDump.java 100644 0 0 5023 11134670534 25737 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.classes;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
public class SimpleDump implements Opcodes {
public static byte[] dump( final String to ) throws Exception {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
MethodVisitor mv;
cw.visit(V1_4, ACC_PUBLIC + ACC_SUPER, "jci/Simple", null, "java/lang/Object", null);
cw.visitSource("Simple.java", null);
{
mv = cw.visitMethod(ACC_PUBLIC, "", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLineNumber(3, l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "", "()V");
mv.visitInsn(RETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{
mv = cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLineNumber(6, l0);
mv.visitLdcInsn(to);
mv.visitInsn(ARETURN);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLocalVariable("this", "Ljci/Simple;", null, l0, l1, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
cw.visitEnd();
return cw.toByteArray();
}
}
././@LongLink 100644 0 0 146 12225263274 10261 L ustar 0 0 commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/compilers/AbstractCompilerTestCase.java commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/compilers/AbstractCompilerTestCase.jav100644 0 0 35045 12205113045 30765 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.compilers;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import org.apache.commons.jci.problems.CompilationProblem;
import org.apache.commons.jci.readers.ResourceReader;
import org.apache.commons.jci.stores.MemoryResourceStore;
/**
* Providing convenience methods for JavaCompiler TestCases
*
* @author tcurdt
*/
public abstract class AbstractCompilerTestCase extends TestCase {
public abstract JavaCompiler createJavaCompiler();
public abstract String getCompilerName();
public void testFactoryCreation() {
final JavaCompiler factoryCompiler = new JavaCompilerFactory().createCompiler(getCompilerName());
assertNotNull(factoryCompiler);
final JavaCompiler compiler = createJavaCompiler();
assertEquals(factoryCompiler.getClass().getName(), compiler.getClass().getName());
}
public void testSimpleCompile() throws Exception {
final JavaCompiler compiler = createJavaCompiler();
final ResourceReader reader = new ResourceReader() {
final private Map sources = new HashMap() {
private static final long serialVersionUID = 1L;
{
put("jci/Simple.java", (
"package jci;\n" +
"public class Simple {\n" +
" public String toString() {\n" +
" return \"Simple\";\n" +
" }\n" +
"}").getBytes());
}};
public byte[] getBytes( final String pResourceName ) {
return sources.get(pResourceName);
}
public boolean isAvailable( final String pResourceName ) {
return sources.containsKey(pResourceName);
}
};
final MemoryResourceStore store = new MemoryResourceStore();
final CompilationResult result = compiler.compile(
new String[] {
"jci/Simple.java"
}, reader, store);
assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
final byte[] clazzBytes = store.read("jci/Simple.class");
assertNotNull("jci/Simple.class is not null",clazzBytes);
assertTrue("jci/Simple.class is not empty", clazzBytes.length > 0);
}
public void testExtendedCompile() throws Exception {
final JavaCompiler compiler = createJavaCompiler();
final ResourceReader reader = new ResourceReader() {
final private Map sources = new HashMap() {
private static final long serialVersionUID = 1L;
{
put("jci/Simple.java", (
"package jci;\n" +
"public class Simple {\n" +
" public String toString() {\n" +
" return \"Simple\";\n" +
" }\n" +
"}").getBytes());
put("jci/Extended.java", (
"package jci;\n" +
"public class Extended extends Simple {\n" +
" public String toString() {\n" +
" return \"Extended\" + super.toString();\n" +
" }\n" +
"}").getBytes());
}};
public byte[] getBytes( final String pResourceName ) {
return sources.get(pResourceName);
}
public boolean isAvailable( final String pResourceName ) {
return sources.containsKey(pResourceName);
}
};
final MemoryResourceStore store = new MemoryResourceStore();
final CompilationResult result = compiler.compile(
new String[] {
"jci/Extended.java",
"jci/Simple.java"
}, reader, store);
assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
final byte[] clazzBytesSimple = store.read("jci/Simple.class");
assertNotNull("jci/Simple.class is not null", clazzBytesSimple);
assertTrue("jci/Simple.class is not empty", clazzBytesSimple.length > 0);
final byte[] clazzBytesExtended = store.read("jci/Extended.class");
assertNotNull("jci/Extended.class is not null", clazzBytesExtended);
assertTrue("jci/Extended.class is not empty",clazzBytesExtended.length > 0);
}
public void testInternalClassCompile() throws Exception {
final JavaCompiler compiler = createJavaCompiler();
final ResourceReader reader = new ResourceReader() {
final private Map sources = new HashMap() {
private static final long serialVersionUID = 1L;
{
put("jci/Simple.java", (
"package jci;\n" +
"public class Simple {\n" +
" private class Sub {\n" +
" }\n" +
" public String toString() {\n" +
" new Sub();\n" +
" return \"Simple\";\n" +
" }\n" +
"}").getBytes());
}};
public byte[] getBytes( final String pResourceName ) {
return sources.get(pResourceName);
}
public boolean isAvailable( final String pResourceName ) {
return sources.containsKey(pResourceName);
}
};
final MemoryResourceStore store = new MemoryResourceStore();
final CompilationResult result = compiler.compile(
new String[] {
"jci/Simple.java"
}, reader, store);
assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
final byte[] clazzBytes = store.read("jci/Simple.class");
assertNotNull("jci/Simple.class is not null", clazzBytes);
assertTrue("jci/Simple.class is not empty", clazzBytes.length > 0);
final byte[] subClazzBytes = store.read("jci/Simple$Sub.class");
assertNotNull("jci/Simple$Sub.class is not null", subClazzBytes);
assertTrue("jci/Simple$Sub.class is not empty", subClazzBytes.length > 0);
}
public void testUppercasePackageNameCompile() throws Exception {
final JavaCompiler compiler = createJavaCompiler();
final ResourceReader reader = new ResourceReader() {
final private Map sources = new HashMap() {
private static final long serialVersionUID = 1L;
{
put("Jci/Simple.java", (
"package Jci;\n" +
"public class Simple {\n" +
" public String toString() {\n" +
" return \"Simple\";\n" +
" }\n" +
"}").getBytes());
}};
public byte[] getBytes( final String pResourceName ) {
return sources.get(pResourceName);
}
public boolean isAvailable( final String pResourceName ) {
return sources.containsKey(pResourceName);
}
};
final MemoryResourceStore store = new MemoryResourceStore();
final CompilationResult result = compiler.compile(
new String[] {
"Jci/Simple.java"
}, reader, store);
assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
final byte[] clazzBytes = store.read("Jci/Simple.class");
assertNotNull("Jci/Simple.class is not null", clazzBytes);
assertTrue("Jci/Simple.class is not empty", clazzBytes.length > 0);
}
/*
* https://issues.apache.org/jira/browse/JCI-53
*/
public void testCrossReferenceCompilation() throws Exception {
final String javaVersion = System.getProperty("java.version");
final JavaCompiler compiler = createJavaCompiler();
final ResourceReader reader = new ResourceReader() {
final private Map sources = new HashMap() {
private static final long serialVersionUID = 1L;
{
put("jci/Func1.java", (
"package jci;\n" +
"import static jci.Func2.func2;" +
"public class Func1 {\n" +
" public static boolean func1() throws Exception {\n" +
" return true;\n" +
" }\n" +
"}").getBytes());
put("jci/Func2.java", (
"package jci;\n" +
"import static jci.Func1.func1;" +
"public class Func2 {\n" +
" public static boolean func2() throws Exception {\n" +
" return true;\n" +
" }\n" +
"}").getBytes());
}};
public byte[] getBytes( final String pResourceName ) {
return sources.get(pResourceName);
}
public boolean isAvailable( final String pResourceName ) {
return sources.containsKey(pResourceName);
}
};
final JavaCompilerSettings settings = compiler.createDefaultSettings();
settings.setTargetVersion("1.5");
settings.setSourceVersion("1.5");
final MemoryResourceStore store = new MemoryResourceStore();
final CompilationResult result = compiler.compile(
new String[] {
"jci/Func1.java",
"jci/Func2.java"
}, reader, store, this.getClass().getClassLoader(), settings);
assertEquals(toString(result.getErrors()), 0, result.getErrors().length);
assertEquals(toString(result.getWarnings()), 0, result.getWarnings().length);
final byte[] clazzBytesFunc1 = store.read("jci/Func1.class");
assertNotNull("jci/Func1.class is not null", clazzBytesFunc1);
assertTrue("jci/Func1.class is not empty", clazzBytesFunc1.length > 0);
final byte[] clazzBytesFunc2 = store.read("jci/Func2.class");
assertNotNull("jci/Func2.class is not null", clazzBytesFunc2);
assertTrue("jci/Func2.class is not empty", clazzBytesFunc2.length > 0);
}
/*
* https://issues.apache.org/jira/browse/JCI-59
*/
public void testAdditionalTopLevelClassCompile() throws Exception {
final JavaCompiler compiler = createJavaCompiler();
final ResourceReader reader = new ResourceReader() {
final private Map sources = new HashMap() {
private static final long serialVersionUID = 1L;
{
put("jci/Simple.java", (
"package jci;\n" +
"public class Simple {\n" +
" public String toString() {\n" +
" return \"Simple\";\n" +
" }\n" +
"}\n" +
"class AdditionalTopLevel {\n" +
" public String toString() {\n" +
" return \"AdditionalTopLevel\";\n" +
" }\n" +
"}").getBytes());
}};
public byte[] getBytes( final String pResourceName ) {
return sources.get(pResourceName);
}
public boolean isAvailable( final String pResourceName ) {
return sources.containsKey(pResourceName);
}
};
final MemoryResourceStore store = new MemoryResourceStore();
final CompilationResult result = compiler.compile(
new String[] {
"jci/Simple.java"
}, reader, store);
assertEquals("Unexpected errors(s): " + toString(result.getErrors()), 0, result.getErrors().length);
final byte[] clazzBytes = store.read("jci/Simple.class");
assertNotNull("Expected to find jci/Simple.class", clazzBytes);
assertTrue(clazzBytes.length > 0);
final byte[] additionalTopLevelBytes = store.read("jci/AdditionalTopLevel.class");
assertNotNull("Expected to find jci/AdditionalTopLevel.class", additionalTopLevelBytes);
assertTrue(additionalTopLevelBytes.length > 0);
assertEquals("Unexpected warning(s): " + toString(result.getWarnings()), 0, result.getWarnings().length);
}
public final String toString( final CompilationProblem[] pProblems ) {
final StringBuilder sb = new StringBuilder();
for (CompilationProblem problem : pProblems) {
sb.append(problem.getMessage()).append(", ");
}
return sb.toString();
}
}
commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/CompilingClassLoaderTestCase.java 100644 0 0 22115 12204234514 27727 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.commons.jci.classes.ExtendedDump;
import org.apache.commons.jci.classes.SimpleDump;
import org.apache.commons.jci.compilers.CompilationResult;
import org.apache.commons.jci.compilers.JavaCompiler;
import org.apache.commons.jci.compilers.JavaCompilerSettings;
import org.apache.commons.jci.listeners.CompilingListener;
import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
import org.apache.commons.jci.problems.CompilationProblem;
import org.apache.commons.jci.problems.CompilationProblemHandler;
import org.apache.commons.jci.readers.ResourceReader;
import org.apache.commons.jci.stores.ResourceStore;
import org.apache.commons.jci.utils.ConversionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
*
* @author tcurdt
*/
public final class CompilingClassLoaderTestCase extends AbstractTestCase {
private final Log log = LogFactory.getLog(CompilingClassLoaderTestCase.class);
private ReloadingClassLoader classloader;
private CompilingListener listener;
private FilesystemAlterationMonitor fam;
private final static class MockJavaCompiler implements JavaCompiler {
private final Log log = LogFactory.getLog(MockJavaCompiler.class);
public CompilationResult compile(String[] pResourcePaths, ResourceReader pReader, ResourceStore pStore, ClassLoader pClassLoader, JavaCompilerSettings pSettings ) {
for (int i = 0; i < pResourcePaths.length; i++) {
final String resourcePath = pResourcePaths[i];
final byte[] resourceContent = pReader.getBytes(resourcePath);
log.debug("resource " + resourcePath + " = " + ((resourceContent!=null)?new String(resourceContent):null) );
final byte[] data;
if ("jci/Simple.java".equals(resourcePath)) {
try {
data = SimpleDump.dump(new String(resourceContent));
} catch (Exception e) {
throw new RuntimeException("cannot handle resource " + resourcePath, e);
}
} else if ("jci/Extended.java".equals(resourcePath)) {
try {
data = ExtendedDump.dump();
} catch (Exception e) {
throw new RuntimeException("cannot handle resource " + resourcePath, e);
}
} else {
throw new RuntimeException("cannot handle resource " + resourcePath);
}
log.debug("compiling " + resourcePath + " (" + data.length + ")");
pStore.write(ConversionUtils.stripExtension(resourcePath) + ".class", data);
}
return new CompilationResult(new CompilationProblem[0]);
}
public CompilationResult compile(String[] pResourcePaths, ResourceReader pReader, ResourceStore pStore, ClassLoader pClassLoader) {
return compile(pResourcePaths, pReader, pStore, pClassLoader, null);
}
public CompilationResult compile(String[] pResourcePaths, ResourceReader pReader, ResourceStore pStore) {
return compile(pResourcePaths, pReader, pStore, null);
}
public void setCompilationProblemHandler(CompilationProblemHandler pHandler) {
}
public JavaCompilerSettings createDefaultSettings() {
return null;
}
}
@Override
protected void setUp() throws Exception {
super.setUp();
classloader = new ReloadingClassLoader(this.getClass().getClassLoader());
listener = new CompilingListener(new MockJavaCompiler());
listener.addReloadNotificationListener(classloader);
fam = new FilesystemAlterationMonitor();
fam.addListener(directory, listener);
fam.start();
}
private void initialCompile() throws Exception {
log.debug("initial compile");
listener.waitForFirstCheck();
writeFile("jci/Simple.java", "Simple1");
writeFile("jci/Extended.java", "Extended");
log.debug("waiting for compile changes to get applied");
listener.waitForCheck();
log.debug("*** ready to test");
}
public void testCreate() throws Exception {
initialCompile();
log.debug("loading Simple");
final Object simple = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple1", simple.toString());
log.debug("loading Extended");
final Object extended = classloader.loadClass("jci.Extended").newInstance();
assertEquals("Extended:Simple1", extended.toString());
}
public void testChange() throws Exception {
initialCompile();
final Object simple = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple1", simple.toString());
final Object extended = classloader.loadClass("jci.Extended").newInstance();
assertEquals("Extended:Simple1", extended.toString());
delay();
writeFile("jci/Simple.java", "Simple2");
listener.waitForCheck();
final Object simple2 = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple2", simple2.toString());
final Object newExtended = classloader.loadClass("jci.Extended").newInstance();
assertEquals("Extended:Simple2", newExtended.toString());
}
public void testDelete() throws Exception {
initialCompile();
final Object simple = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple1", simple.toString());
final Object extended = classloader.loadClass("jci.Extended").newInstance();
assertEquals("Extended:Simple1", extended.toString());
listener.waitForCheck();
log.debug("deleting source file");
assertTrue(new File(directory, "jci/Extended.java").delete());
listener.waitForCheck();
log.debug("loading Simple");
final Object oldSimple = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple1", oldSimple.toString());
log.debug("trying to loading Extended");
try {
classloader.loadClass("jci.Extended").newInstance();
fail();
} catch(final ClassNotFoundException e) {
assertEquals("jci.Extended", e.getMessage());
}
log.debug("deleting whole directory");
FileUtils.deleteDirectory(new File(directory, "jci"));
listener.waitForCheck();
log.debug("trying to loading Simple");
try {
classloader.loadClass("jci.Simple").newInstance();
fail();
} catch(final ClassNotFoundException e) {
assertEquals("jci.Simple", e.getMessage());
}
}
public void testDeleteDependency() throws Exception {
initialCompile();
final Object simple = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple1", simple.toString());
final Object extended = classloader.loadClass("jci.Extended").newInstance();
assertEquals("Extended:Simple1", extended.toString());
log.debug("deleting source file");
assertTrue(new File(directory, "jci/Simple.java").delete());
listener.waitForCheck();
log.debug("trying to load dependend class");
try {
classloader.loadClass("jci.Extended").newInstance();
fail();
} catch(final NoClassDefFoundError e) {
assertEquals("jci/Simple", e.getMessage());
}
}
@Override
protected void tearDown() throws Exception {
fam.removeListener(listener);
fam.stop();
super.tearDown();
}
}
commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/readers/ResourceReaderTestCase.java 100644 0 0 3650 10670640547 30227 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.readers;
import org.apache.commons.jci.AbstractTestCase;
/**
*
* @author tcurdt
*/
public final class ResourceReaderTestCase extends AbstractTestCase {
public void testFileResourceReader() throws Exception {
writeFile("test", "test");
checkRead(new FileResourceReader(directory));
}
public void testMemoryResourceReader() throws Exception {
final MemoryResourceReader reader = new MemoryResourceReader();
reader.add("test", "test".getBytes());
checkRead(reader);
reader.remove(null);
assertTrue(reader.isAvailable("test"));
reader.remove("test");
assertFalse(reader.isAvailable("test"));
}
private void checkRead( final ResourceReader reader ) throws Exception {
assertTrue(reader.isAvailable("test"));
final byte[] content = reader.getBytes("test");
assertTrue(content != null);
assertEquals("test", new String(content));
assertFalse(reader.isAvailable("bla"));
assertTrue(reader.getBytes("bla") == null);
}
}
././@LongLink 100644 0 0 146 12225263274 10261 L ustar 0 0 commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/ReloadingClassLoaderRemoveTestCase.java commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/ReloadingClassLoaderRemoveTestCase.jav100644 0 0 26626 12204236020 30734 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.jci.classes.SimpleDump;
import org.apache.commons.jci.stores.ResourceStore;
import org.apache.commons.jci.stores.MemoryResourceStore;
/**
* Test ReloadingClassLoader's removeResourceStore({@link ResourceStore})
* method.
*/
public class ReloadingClassLoaderRemoveTestCase extends TestCase {
private final Log log = LogFactory.getLog(ReloadingClassLoaderRemoveTestCase.class);
private final byte[] clazzSimpleA;
private MemoryResourceStore store1 = new MemoryResourceStore();
private MemoryResourceStore store2 = new MemoryResourceStore();
private MemoryResourceStore store3 = new MemoryResourceStore();
private MemoryResourceStore store4 = new MemoryResourceStore();
public ReloadingClassLoaderRemoveTestCase() throws Exception {
clazzSimpleA = SimpleDump.dump("SimpleA");
assertTrue(clazzSimpleA.length > 0);
}
@Override
protected void setUp() throws Exception {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
}
@Override
protected void tearDown() throws Exception {
}
/**
* Test trying to remove a ResourceStore from the ReloadingClassLoader
* which can't be found - when the ClassLoader contains NO other ResourceStore.
*
* Bug: The While loop in the removeResourceStore() throws an ArrayOutOfBoundsException
*/
public void testRemoveStoreNotFoundClassLoaderNoStores() {
ReloadingClassLoader loader = new ReloadingClassLoader(getClass().getClassLoader());
checkRemoveResourceStore("No ResourceStore", loader, store1, false);
}
/**
* Test trying to remove a ResourceStore from the ReloadingClassLoader
* which can't be found - when the ClassLoader DOES contain other ResourceStore.
*
* Bug: The While loop in the removeResourceStore() throws an ArrayOutOfBoundsException
*/
public void testRemoveStoreNotFoundClassLoaderHasStores() {
ReloadingClassLoader loader = new ReloadingClassLoader(getClass().getClassLoader());
loader.addResourceStore(store1);
loader.addResourceStore(store2);
checkRemoveResourceStore("Has ResourceStore", loader, store3, false);
}
/**
* Test trying to remove the first ResourceStore added
*
* Bug: ReloadingClassLoader addes ResourceStore at the start of the array. Removing the
* first one added (last in array) causes the second System.arraycopy() statement to throw a
* ArrayIndexOutOfBoundsException because the destination array position in the new smaller
* array is too large.
*/
public void testRemoveStoresOne() {
ReloadingClassLoader loader = new ReloadingClassLoader(getClass().getClassLoader());
loader.addResourceStore(store1);
loader.addResourceStore(store2);
loader.addResourceStore(store3);
loader.addResourceStore(store4);
checkRemoveResourceStore("One: Remove Store 1", loader, store1, true);
checkRemoveResourceStore("One: Store 1 Not Found", loader, store1, false);
checkRemoveResourceStore("One: Remove Store 2", loader, store2, true);
checkRemoveResourceStore("One: Store 2 Not Found", loader, store2, false);
checkRemoveResourceStore("One: Remove Store 3", loader, store3, true);
checkRemoveResourceStore("One: Store 3 Not Found", loader, store3, false);
checkRemoveResourceStore("One: Remove Store 4", loader, store4, true);
checkRemoveResourceStore("One: Store 4 Not Found", loader, store4, false);
}
/**
* Test trying to remove the second ResourceStore added
*
* Bug: ReloadingClassLoader addes ResourceStore at the start of the array. Removing the
* first one added (last in array) causes the second System.arraycopy() statement to throw a
* ArrayIndexOutOfBoundsException (??not sure why??)
*/
public void testRemoveStoresTwo() {
ReloadingClassLoader loader = new ReloadingClassLoader(getClass().getClassLoader());
loader.addResourceStore(store1);
loader.addResourceStore(store2);
loader.addResourceStore(store3);
loader.addResourceStore(store4);
checkRemoveResourceStore("Two: Remove Store 2", loader, store2, true);
checkRemoveResourceStore("Two: Store 2 Not Found", loader, store2, false);
checkRemoveResourceStore("Two: Remove Store 4", loader, store4, true);
checkRemoveResourceStore("Two: Store 4 Not Found", loader, store4, false);
checkRemoveResourceStore("Two: Remove Store 3", loader, store3, true);
checkRemoveResourceStore("Two: Store 3 Not Found", loader, store3, false);
checkRemoveResourceStore("Two: Remove Store 1", loader, store1, true);
checkRemoveResourceStore("Two: Store 1 Not Found", loader, store1, false);
}
/**
* Test trying to remove the third ResourceStore added
*
* Bug: In this scenario the two System.arraycopy() statements don't copy the correct
* ResourceStore - it creates a new array where the first resource store is null
* and copies store3 and store2 to their same positions
*/
public void testRemoveStoresThree() {
ReloadingClassLoader loader = new ReloadingClassLoader(getClass().getClassLoader());
loader.addResourceStore(store1);
loader.addResourceStore(store2);
loader.addResourceStore(store3);
loader.addResourceStore(store4);
checkRemoveResourceStore("Three: Remove Store 3", loader, store3, true);
checkRemoveResourceStore("Three: Store 3 Not Found", loader, store3, false);
checkRemoveResourceStore("Three: Remove Store 1", loader, store1, true);
checkRemoveResourceStore("Three: Store 1 Not Found", loader, store1, false);
checkRemoveResourceStore("Three: Remove Store 4", loader, store4, true);
checkRemoveResourceStore("Three: Store 4 Not Found", loader, store4, false);
checkRemoveResourceStore("Three: Remove Store 2", loader, store2, true);
checkRemoveResourceStore("Three: Store 2 Not Found", loader, store2, false);
}
/**
* Test trying to remove the fourth ResourceStore added
*
* Bug: ReloadingClassLoader addes ResourceStore at the start of the array. Removing the
* last one added (first in array) causes the first System.arraycopy() statement to throw a
* ArrayIndexOutOfBoundsException because the length to copy is -1
*/
public void testRemoveStoresFour() {
ReloadingClassLoader loader = new ReloadingClassLoader(getClass().getClassLoader());
loader.addResourceStore(store1);
loader.addResourceStore(store2);
loader.addResourceStore(store3);
loader.addResourceStore(store4);
checkRemoveResourceStore("Four: Remove Store 4", loader, store4, true);
checkRemoveResourceStore("Four: Store 4 Not Found", loader, store4, false);
checkRemoveResourceStore("Four: Remove Store 3", loader, store3, true);
checkRemoveResourceStore("Four: Store 3 Not Found", loader, store3, false);
checkRemoveResourceStore("Four: Remove Store 2", loader, store2, true);
checkRemoveResourceStore("Four: Store 2 Not Found", loader, store2, false);
checkRemoveResourceStore("Four: Remove Store 1", loader, store1, true);
checkRemoveResourceStore("Four: Store 1 Not Found", loader, store1, false);
}
/**
* Test that a class can't be loaded after the ResourceStore containing
* it has been removed.
*
* Bug: When theres a single ResourceStore in the ClassLoader and its removed
* a new "delegate" ClassLoader with the new ResourceStore array isn't being
* created - which means that calling loadClass() still returns the classes
* from the removed ResourceStore rather than throwing a ClassNotFoundException
*/
public void testLoadClassAfterResourceStoreRemoved() {
// Create a class loader & add resource store
ReloadingClassLoader loader = new ReloadingClassLoader(this.getClass().getClassLoader());
MemoryResourceStore store = new MemoryResourceStore();
loader.addResourceStore(store);
// Check "jci.Simple" class can't be loaded
try {
loader.loadClass("jci.Simple").newInstance();
fail("Success loadClass[1]");
} catch(ClassNotFoundException e) {
// expected not found
} catch(Exception e) {
log.error(e);
fail("Error loadClass[1]: " + e);
}
// Add "jci.Simple" class to the resource store
String toStringValue = "FooBar";
try {
byte[] classBytes = SimpleDump.dump(toStringValue);
store.write("jci/Simple.class", classBytes);
} catch(Exception e) {
log.error(e);
fail("Error adding class to store: " + e);
}
// Check "jci.Simple" class can now be loaded
try {
Object simple2 = loader.loadClass("jci.Simple").newInstance();
assertNotNull("Found loadClass[2]", simple2);
assertEquals("toString loadClass[2]", toStringValue, simple2.toString());
} catch(Exception e) {
log.error(e);
fail("Error loadClass[2]: " + e);
}
// Remove the resource store from the class loader
checkRemoveResourceStore("Remove Resource Store", loader, store, true);
// Test "jci.Simple" class can't be loaded after ResourceStore removed
try {
loader.loadClass("jci.Simple").newInstance();
fail("Success loadClass[3]");
} catch(ClassNotFoundException e) {
// expected not found
} catch(Exception e) {
log.error(e);
fail("Error loadClass[3]: " + e);
}
}
/**
* Check removing a ResourceStore from ReloadingClassLoader
*/
private void checkRemoveResourceStore(String label, ReloadingClassLoader loader, ResourceStore store, boolean expected) {
try {
assertEquals(label, expected, loader.removeResourceStore(store));
} catch(Exception e) {
log.error(label, e);
fail(label + " failed: " + e);
}
}
}
commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/ReloadingClassLoaderTestCase.java 100644 0 0 13622 12204234514 27715 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci;
import java.io.File;
import org.apache.commons.jci.classes.ExtendedDump;
import org.apache.commons.jci.classes.SimpleDump;
import org.apache.commons.jci.listeners.ReloadingListener;
import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
*
* @author tcurdt
*/
public final class ReloadingClassLoaderTestCase extends AbstractTestCase {
private final Log log = LogFactory.getLog(ReloadingClassLoaderTestCase.class);
private ReloadingClassLoader classloader;
private ReloadingListener listener;
private FilesystemAlterationMonitor fam;
private final byte[] clazzSimple1;
private final byte[] clazzSimple2;
private final byte[] clazzExtended;
public ReloadingClassLoaderTestCase() throws Exception {
clazzSimple1 = SimpleDump.dump("Simple1");
clazzSimple2 = SimpleDump.dump("Simple2");
clazzExtended = ExtendedDump.dump();
assertTrue(clazzSimple1.length > 0);
assertTrue(clazzSimple2.length > 0);
assertTrue(clazzExtended.length > 0);
}
@Override
protected void setUp() throws Exception {
super.setUp();
classloader = new ReloadingClassLoader(this.getClass().getClassLoader());
listener = new ReloadingListener();
listener.addReloadNotificationListener(classloader);
fam = new FilesystemAlterationMonitor();
fam.addListener(directory, listener);
fam.start();
}
public void testCreate() throws Exception {
listener.waitForFirstCheck();
log.debug("creating class");
writeFile("jci/Simple.class", clazzSimple1);
listener.waitForCheck();
final Object simple = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple1", simple.toString());
}
public void testChange() throws Exception {
listener.waitForFirstCheck();
log.debug("creating class");
writeFile("jci/Simple.class", clazzSimple1);
listener.waitForCheck();
final Object simple1 = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple1", simple1.toString());
log.debug("changing class");
writeFile("jci/Simple.class", clazzSimple2);
listener.waitForEvent();
final Object simple2 = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple2", simple2.toString());
}
public void testDelete() throws Exception {
listener.waitForFirstCheck();
log.debug("creating class");
writeFile("jci/Simple.class", clazzSimple1);
listener.waitForCheck();
final Object simple = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple1", simple.toString());
log.debug("deleting class");
assertTrue(new File(directory, "jci/Simple.class").delete());
listener.waitForEvent();
try {
classloader.loadClass("jci.Simple").newInstance();
fail();
} catch(final ClassNotFoundException e) {
assertEquals("jci.Simple", e.getMessage());
}
}
public void testDeleteDependency() throws Exception {
listener.waitForFirstCheck();
log.debug("creating classes");
writeFile("jci/Simple.class", clazzSimple1);
writeFile("jci/Extended.class", clazzExtended);
listener.waitForCheck();
final Object simple = classloader.loadClass("jci.Simple").newInstance();
assertEquals("Simple1", simple.toString());
final Object extended = classloader.loadClass("jci.Extended").newInstance();
assertEquals("Extended:Simple1", extended.toString());
log.debug("deleting class dependency");
assertTrue(new File(directory, "jci/Simple.class").delete());
listener.waitForEvent();
try {
classloader.loadClass("jci.Extended").newInstance();
fail();
} catch(final NoClassDefFoundError e) {
assertEquals("jci/Simple", e.getMessage());
}
}
public void testClassNotFound() {
try {
classloader.loadClass("bla");
fail();
} catch(final ClassNotFoundException e) {
}
}
public void testDelegation() {
classloader.clearAssertionStatus();
classloader.setClassAssertionStatus("org.apache.commons.jci.ReloadingClassLoader", true);
classloader.setDefaultAssertionStatus(false);
classloader.setPackageAssertionStatus("org.apache.commons.jci", true);
// FIXME: compare with delegation
}
@Override
protected void tearDown() throws Exception {
fam.removeListener(listener);
fam.stop();
super.tearDown();
}
}
commons-jci-1.1-src/core/src/test/java/org/apache/commons/jci/stores/ResourceStoreTestCase.java 100644 0 0 5054 12204370734 30004 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.stores;
import org.apache.commons.jci.AbstractTestCase;
import org.apache.commons.lang3.ArrayUtils;
/**
*
* @author tcurdt
*/
public final class ResourceStoreTestCase extends AbstractTestCase {
public void testMemoryResourceStore() {
checkReadWrite(new MemoryResourceStore());
checkRemove(new MemoryResourceStore());
}
public void testFileResourceStore() {
checkReadWrite(new FileResourceStore(directory));
checkRemove(new FileResourceStore(directory));
}
public void testTransactionalFileResourceStore() {
checkReadWrite(new TransactionalResourceStore(new FileResourceStore(directory)));
checkRemove(new TransactionalResourceStore(new FileResourceStore(directory)));
final ResourceStore rs = new FileResourceStore(directory);
final TransactionalResourceStore trs = new TransactionalResourceStore(rs);
assertEquals(rs.toString(), trs.toString());
}
private void checkReadWrite( final ResourceStore pStore ) {
final byte[] data = { 1, 2, 3 };
pStore.write("key", data);
final byte[] read = pStore.read("key");
assertTrue(read != null);
assertTrue(ArrayUtils.isEquals(data, read));
}
private void checkRemove( final ResourceStore pStore ) {
final byte[] data = { 1, 2, 3 };
pStore.write("key", data);
final byte[] read = pStore.read("key");
assertTrue(read != null);
assertTrue(ArrayUtils.isEquals(data, read));
pStore.remove("key");
final byte[] empty = pStore.read("key");
assertTrue(empty == null);
}
}
commons-jci-1.1-src/core/src/test/resources/simplelog.properties 100644 0 0 155 10573617463 22323 0 ustar 0 0 org.apache.commons.logging.simplelog.defaultlog=debug
org.apache.commons.logging.simplelog.showdatetime=true commons-jci-1.1-src/examples/src/ 40755 0 0 0 12060700107 14006 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/ 40755 0 0 0 12060700107 14732 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/java/ 40755 0 0 0 12060700107 15653 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/ 40755 0 0 0 12060700107 16442 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/ 40755 0 0 0 12060700107 17663 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/ 40755 0 0 0 12060700107 21336 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/ 40755 0 0 0 12060700107 22103 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/ 40755 0 0 0 12060700107 23721 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/commandline/ 40755 0 0 0 12225246462 26223 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/ 40755 0 0 0 12224752676 26614 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ 40755 0 0 0 12225247137 26263 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/resources/ 40755 0 0 0 12225261521 16751 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/webapp/ 40755 0 0 0 12060700107 16210 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/webapp/WEB-INF/ 40755 0 0 0 12060700107 17237 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/webapp/WEB-INF/jsp/ 40755 0 0 0 12060700107 20033 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/webapp/WEB-INF/jsp/org/ 40755 0 0 0 12060700107 20622 5 ustar 0 0 commons-jci-1.1-src/examples/src/main/webapp/WEB-INF/jsp/org/vafer/ 40755 0 0 0 12060700107 21725 5 ustar 0 0 commons-jci-1.1-src/examples/pom.xml 100644 0 0 7035 12225257517 14655 0 ustar 0 0
4.0.0
org.apache.commons
commons-jci
1.1
commons-jci-examples
1.1
Apache Commons JCI examples
Apache Commons JCI examples.
true
org.apache.commons
commons-jci-core
${project.version}
org.apache.commons
commons-jci-eclipse
${project.version}
commons-cli
commons-cli
javax.servlet
servlet-api
jci-examples
true
org.mortbay.jetty
maven-jetty-plugin
org.apache.commons.logging.Log
org.apache.commons.logging.impl.SimpleLog
maven-assembly-plugin
true
org.apache.maven.plugins
maven-deploy-plugin
2.7
true
././@LongLink 100644 0 0 160 12225263274 10255 L ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/commandline/CommandlineCompiler.java commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/commandline/CommandlineCo100644 0 0 16472 12225246462 31005 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.examples.commandline;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Iterator;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.jci.compilers.CompilationResult;
import org.apache.commons.jci.compilers.JavaCompiler;
import org.apache.commons.jci.compilers.JavaCompilerFactory;
import org.apache.commons.jci.compilers.JavaCompilerSettings;
import org.apache.commons.jci.problems.CompilationProblem;
import org.apache.commons.jci.problems.CompilationProblemHandler;
import org.apache.commons.jci.readers.FileResourceReader;
import org.apache.commons.jci.readers.ResourceReader;
import org.apache.commons.jci.stores.FileResourceStore;
import org.apache.commons.jci.stores.ResourceStore;
/**
* A simple front end to jci mimicking the javac command line
*
* @author tcurdt
*/
public final class CommandlineCompiler {
public static void main( String[] args ) throws Exception {
final Options options = new Options();
options.addOption(
OptionBuilder.withArgName("a.jar:b.jar")
.hasArg()
.withValueSeparator( ':' )
.withDescription("Specify where to find user class files")
.create( "classpath" ));
options.addOption(
OptionBuilder.withArgName("release")
.hasArg()
.withDescription("Provide source compatibility with specified release")
.create( "source" ));
options.addOption(
OptionBuilder.withArgName("release")
.hasArg()
.withDescription("Generate class files for specific VM version")
.create( "target" ));
options.addOption(
OptionBuilder.withArgName("path")
.hasArg()
.withDescription("Specify where to find input source files")
.create( "sourcepath" ));
options.addOption(
OptionBuilder.withArgName("directory")
.hasArg()
.withDescription("Specify where to place generated class files")
.create( "d" ));
options.addOption(
OptionBuilder.withArgName("num")
.hasArg()
.withDescription("Stop compilation after these number of errors")
.create( "Xmaxerrs" ));
options.addOption(
OptionBuilder.withArgName("num")
.hasArg()
.withDescription("Stop compilation after these number of warning")
.create( "Xmaxwarns" ));
options.addOption(
OptionBuilder.withDescription("Generate no warnings")
.create( "nowarn" ));
// final HelpFormatter formatter = new HelpFormatter();
// formatter.printHelp("jci", options);
final CommandLineParser parser = new GnuParser();
final CommandLine cmd = parser.parse(options, args, true);
ClassLoader classloader = CommandlineCompiler.class.getClassLoader();
File sourcepath = new File(".");
File targetpath = new File(".");
int maxerrs = 10;
int maxwarns = 10;
final boolean nowarn = cmd.hasOption("nowarn");
final JavaCompiler compiler = new JavaCompilerFactory().createCompiler("eclipse");
final JavaCompilerSettings settings = compiler.createDefaultSettings();
for (Iterator it = cmd.iterator(); it.hasNext();) {
final Option option = (Option) it.next();
if ("classpath".equals(option.getOpt())) {
final String[] values = option.getValues();
final URL[] urls = new URL[values.length];
for (int i = 0; i < urls.length; i++) {
urls[i] = new File(values[i]).toURL();
}
classloader = new URLClassLoader(urls);
} else if ("source".equals(option.getOpt())) {
settings.setSourceVersion(option.getValue());
} else if ("target".equals(option.getOpt())) {
settings.setTargetVersion(option.getValue());
} else if ("sourcepath".equals(option.getOpt())) {
sourcepath = new File(option.getValue());
} else if ("d".equals(option.getOpt())) {
targetpath = new File(option.getValue());
} else if ("Xmaxerrs".equals(option.getOpt())) {
maxerrs = Integer.parseInt(option.getValue());
} else if ("Xmaxwarns".equals(option.getOpt())) {
maxwarns = Integer.parseInt(option.getValue());
}
}
final ResourceReader reader = new FileResourceReader(sourcepath);
final ResourceStore store = new FileResourceStore(targetpath);
final int maxErrors = maxerrs;
final int maxWarnings = maxwarns;
compiler.setCompilationProblemHandler(new CompilationProblemHandler() {
int errors = 0;
int warnings = 0;
public boolean handle(final CompilationProblem pProblem) {
if (pProblem.isError()) {
System.err.println(pProblem);
errors++;
if (errors >= maxErrors) {
return false;
}
} else {
if (!nowarn) {
System.err.println(pProblem);
}
warnings++;
if (warnings >= maxWarnings) {
return false;
}
}
return true;
}
});
final String[] resource = cmd.getArgs();
for (int i = 0; i < resource.length; i++) {
System.out.println("compiling " + resource[i]);
}
final CompilationResult result = compiler.compile(resource, reader, store, classloader);
System.out.println( result.getErrors().length + " errors");
System.out.println( result.getWarnings().length + " warnings");
}
}
commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/commandline/package.html 100644 0 0 1647 10627343175 30614 0 ustar 0 0
Example demonstrating a simple front end to jci mimicking the javac command line.
././@LongLink 100644 0 0 153 12225263274 10257 L ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurable.java commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurabl100644 0 0 2003 10613666121 31047 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.examples.configuration;
import java.util.Properties;
public interface Configurable {
void configure( Properties properties ) throws ConfigurationException;
}
././@LongLink 100644 0 0 165 12225263274 10262 L ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationException.java commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurati100644 0 0 1745 10613666121 31102 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.examples.configuration;
public class ConfigurationException extends Exception {
private static final long serialVersionUID = 1L;
}
././@LongLink 100644 0 0 165 12225263274 10262 L ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/ConfigurationReloading.java commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/Configurati100644 0 0 6401 12204226200 31060 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.examples.configuration;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;
import org.apache.commons.jci.listeners.FileChangeListener;
import org.apache.commons.jci.monitor.FilesystemAlterationListener;
import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
import org.apache.commons.jci.monitor.FilesystemAlterationObserver;
/**
*
* @author tcurdt
*/
public final class ConfigurationReloading {
private final FilesystemAlterationMonitor fam = new FilesystemAlterationMonitor();
private void run(String[] args) {
final File configFile = new File("some.properties");
System.out.println("Watching " + configFile.getAbsolutePath());
final Collection configurables = new ArrayList();
final FilesystemAlterationListener listener = new FileChangeListener() {
public void onStop(FilesystemAlterationObserver pObserver) {
super.onStop(pObserver);
if (hasChanged()) {
System.out.println("Configuration change detected " + configFile);
final Properties props = new Properties();
InputStream is = null;
try {
is = new FileInputStream(configFile);
props.load(is);
System.out.println("Notifying about configuration change " + configFile);
for (Configurable configurable : configurables) {
configurable.configure(props);
}
} catch (Exception e) {
System.err.println("Failed to load configuration " + configFile);
} finally {
try {
is.close();
} catch (IOException e) {
}
}
}
}
};
fam.addListener(configFile, listener);
fam.start();
configurables.add(new Something());
while(true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
public static void main(String[] args) {
new ConfigurationReloading().run(args);
}
}
././@LongLink 100644 0 0 146 12225263274 10261 L ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/package.html commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/package.htm100644 0 0 1615 10627343175 31014 0 ustar 0 0
Example demonstrating auto-reloading of configurations.
././@LongLink 100644 0 0 150 12225263274 10254 L ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/Something.java commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/configuration/Something.j100644 0 0 2131 10613666121 31003 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.examples.configuration;
import java.util.Properties;
public class Something implements Configurable {
public void configure( Properties properties ) throws ConfigurationException {
System.out.println("Configuration changed");
}
}
commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/package.html 100644 0 0 1566 10627343175 26326 0 ustar 0 0
Examples showing how to use jci.
././@LongLink 100644 0 0 151 12225263274 10255 L ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.java commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspGenerator.100644 0 0 13145 12225247137 31010 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.examples.serverpages;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import org.apache.commons.jci.utils.ConversionUtils;
/**
* @author tcurdt
*/
public final class JspGenerator {
private String quote( final String s ) {
final StringBuilder sb = new StringBuilder();
final char[] input = s.toCharArray();
for (char c : input) {
if (c == '"') {
sb.append('\\');
}
if (c == '\\') {
sb.append('\\');
}
if (c == '\n') {
sb.append("\");\n").append(" out.write(\"");
continue;
}
sb.append(c);
}
return sb.toString();
}
private void wrap( final StringBuilder pInput, final Writer pOutput ) throws IOException {
pOutput.append(" out.write(\"");
pOutput.append(quote(pInput.toString()));
pOutput.append("\");").append('\n');
}
public byte[] generateJavaSource( final String pResourceName, final File pFile ) {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final Writer output = new OutputStreamWriter(outputStream);
try {
final Reader input = new InputStreamReader(new FileInputStream(pFile));
final int p = pResourceName.lastIndexOf('/');
final String className;
final String packageName;
if (p < 0) {
className = ConversionUtils.stripExtension(pResourceName);
packageName = "";
} else {
className = ConversionUtils.stripExtension(pResourceName.substring(p+1));
packageName = pResourceName.substring(0, p).replace('/', '.');
output.append("package ").append(packageName).append(";").append('\n');
}
output.append("import java.io.PrintWriter;").append('\n');
output.append("import java.io.IOException;").append('\n');
output.append("import javax.servlet.http.HttpServlet;").append('\n');
output.append("import javax.servlet.http.HttpServletRequest;").append('\n');
output.append("import javax.servlet.http.HttpServletResponse;").append('\n');
output.append("import javax.servlet.ServletException;").append('\n');
output.append("public class ").append(className).append(" extends HttpServlet {").append('\n');
output.append(" protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {").append('\n');
output.append(" final PrintWriter out = response.getWriter();").append('\n');
final char[] open = "".toCharArray();
final char[] close = "?>".toCharArray();
StringBuilder sb = new StringBuilder();
char[] watch = open;
int w = 0;
while(true) {
int c = input.read();
if (c < 0) {
break;
}
if (c == watch[w]) {
w++;
if (watch.length == w) {
if (watch == open) {
// found open
wrap(sb, output);
sb = new StringBuilder();
watch = close;
} else if (watch == close) {
// found close
// ... ?> is java
output.append(sb.toString());
sb = new StringBuilder();
watch = open;
}
w = 0;
}
} else {
if (w > 0) {
sb.append(watch, 0, w);
}
sb.append((char)c);
w = 0;
}
}
if (watch == open) {
wrap(sb, output);
}
output.append(" out.close();").append('\n');
output.append(" out.flush();").append('\n');
output.append(" }").append('\n');
output.append("}").append('\n');
return outputStream.toByteArray();
} catch (IOException e) {
return null;
} finally {
try {
output.close();
} catch (IOException e) {
}
}
}
}
././@LongLink 100644 0 0 146 12225263274 10261 L ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.java commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/serverpages/JspReader.jav100644 0 0 3335 12204226200 30726 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.examples.serverpages;
import java.util.Map;
import org.apache.commons.jci.readers.ResourceReader;
/**
* @author tcurdt
*/
public final class JspReader implements ResourceReader {
private final Map sources;
private final ResourceReader reader;
public JspReader( final Map pSources, final ResourceReader pReader ) {
reader = pReader;
sources = pSources;
}
public byte[] getBytes( String pResourceName ) {
final byte[] bytes = sources.get(pResourceName);
if (bytes != null) {
return bytes;
}
return reader.getBytes(pResourceName);
}
public boolean isAvailable( String pResourceName ) {
if (sources.containsKey(pResourceName)) {
return true;
}
return reader.isAvailable(pResourceName);
}
}
commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/serverpages/package.html 100644 0 0 1613 10627343175 30645 0 ustar 0 0
Example how to use jci to build a simple JSP servlet.
././@LongLink 100644 0 0 156 12225263274 10262 L ustar 0 0 commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageServlet.java commons-jci-1.1-src/examples/src/main/java/org/apache/commons/jci/examples/serverpages/ServerPageSer100644 0 0 21441 12225247030 31032 0 ustar 0 0 /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jci.examples.serverpages;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.String;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.jci.ReloadingClassLoader;
import org.apache.commons.jci.compilers.CompilationResult;
import org.apache.commons.jci.compilers.JavaCompilerFactory;
import org.apache.commons.jci.listeners.CompilingListener;
import org.apache.commons.jci.monitor.FilesystemAlterationMonitor;
import org.apache.commons.jci.monitor.FilesystemAlterationObserver;
import org.apache.commons.jci.problems.CompilationProblem;
import org.apache.commons.jci.readers.ResourceReader;
import org.apache.commons.jci.stores.MemoryResourceStore;
import org.apache.commons.jci.stores.TransactionalResourceStore;
import org.apache.commons.jci.utils.ConversionUtils;
/**
* A mini JSP servlet that monitors a certain directory and
* recompiles and then instantiates the JSP pages as soon as
* they have changed.
*
* @author tcurdt
*/
public final class ServerPageServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private final ReloadingClassLoader classloader = new ReloadingClassLoader(ServerPageServlet.class.getClassLoader());
private FilesystemAlterationMonitor fam;
private CompilingListener jspListener;
private Map servletsByClassname = new HashMap();
public void init() throws ServletException {
super.init();
final File serverpagesDir = new File(getServletContext().getRealPath("/") + getInitParameter("serverpagesDir"));
log("Monitoring serverpages in " + serverpagesDir);
final TransactionalResourceStore store = new TransactionalResourceStore(new MemoryResourceStore()) {
private Set newClasses;
private Map newServletsByClassname;
public void onStart() {
super.onStart();
newClasses = new HashSet();
newServletsByClassname = new HashMap(servletsByClassname);
}
public void onStop() {
super.onStop();
boolean reload = false;
for (String clazzName : newClasses) {
try {
final Class clazz = classloader.loadClass(clazzName);
if (!HttpServlet.class.isAssignableFrom(clazz)) {
log(clazzName + " is not a servlet");
continue;
}
// create new instance of jsp page
final HttpServlet servlet = (HttpServlet) clazz.newInstance();
newServletsByClassname.put(clazzName, servlet);
reload = true;
} catch(Exception e) {
log("", e);
}
}
if (reload) {
log("Activating new map of servlets "+ newServletsByClassname);
servletsByClassname = newServletsByClassname;
}
}
public void write(String pResourceName, byte[] pResourceData) {
super.write(pResourceName, pResourceData);
if (pResourceName.endsWith(".class")) {
// compiler writes a new class, remember the classes to reload
newClasses.add(pResourceName.replace('/', '.').substring(0, pResourceName.length() - ".class".length()));
}
}
};
// listener that generates the java code from the jsp page and provides that to the compiler
jspListener = new CompilingListener(new JavaCompilerFactory().createCompiler("eclipse"), store) {
private final JspGenerator transformer = new JspGenerator();
private final Map sources = new HashMap();
private final Set resourceToCompile = new HashSet();
public void onStart(FilesystemAlterationObserver pObserver) {
super.onStart(pObserver);
resourceToCompile.clear();
}
public void onFileChange(File pFile) {
if (pFile.getName().endsWith(".jsp")) {
final String resourceName = ConversionUtils.stripExtension(getSourceNameFromFile(observer, pFile)) + ".java";
log("Updating " + resourceName);
sources.put(resourceName, transformer.generateJavaSource(resourceName, pFile));
resourceToCompile.add(resourceName);
}
super.onFileChange(pFile);
}
public void onFileCreate(File pFile) {
if (pFile.getName().endsWith(".jsp")) {
final String resourceName = ConversionUtils.stripExtension(getSourceNameFromFile(observer, pFile)) + ".java";
log("Creating " + resourceName);
sources.put(resourceName, transformer.generateJavaSource(resourceName, pFile));
resourceToCompile.add(resourceName);
}
super.onFileCreate(pFile);
}
public String[] getResourcesToCompile(FilesystemAlterationObserver pObserver) {
// we only want to compile the jsp pages
final String[] resourceNames = new String[resourceToCompile.size()];
resourceToCompile.toArray(resourceNames);
return resourceNames;
}
public ResourceReader getReader( final FilesystemAlterationObserver pObserver ) {
return new JspReader(sources, super.getReader(pObserver));
}
};
jspListener.addReloadNotificationListener(classloader);
fam = new FilesystemAlterationMonitor();
fam.addListener(serverpagesDir, jspListener);
fam.start();
}
private String convertRequestToServletClassname( final HttpServletRequest request ) {
String path = request.getPathInfo().substring(1);
return ConversionUtils.stripExtension(path).replace('/', '.');
}
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log("Request " + request.getRequestURI());
final CompilationResult result = jspListener.getCompilationResult();
final CompilationProblem[] errors = result.getErrors();
if (errors.length > 0) {
// if there are errors we provide the compilation errors instead of the jsp page
final PrintWriter out = response.getWriter();
out.append("");
for (CompilationProblem problem : errors) {
out.append(problem.toString()).append("
").append('\n');
}
out.append("");
out.flush();
out.close();
return;
}
final String servletClassname = convertRequestToServletClassname(request);
log("Checking for serverpage " + servletClassname);
final HttpServlet servlet = servletsByClassname.get(servletClassname);
if (servlet == null) {
log("No servlet for " + request.getRequestURI());
response.sendError(404);
return;
}
log("Delegating request to " + servletClassname);
servlet.service(request, response);
}
public void destroy() {
fam.stop();
super.destroy();
}
}
commons-jci-1.1-src/examples/src/main/resources/LICENSE.txt 100644 0 0 26446 10607602354 20732 0 ustar 0 0 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
commons-jci-1.1-src/examples/src/main/resources/NOTICE.txt 100644 0 0 274 12225261521 20553 0 ustar 0 0 Apache Commons JCI - Examples
Copyright 2004-2013 The Apache Software Foundation
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
commons-jci-1.1-src/examples/src/main/webapp/WEB-INF/jsp/org/vafer/Test.jsp 100644 0 0 1532 10627343175 23477 0 ustar 0 0 org.vafer.Test