Browse Source
Conflicts: gradle.properties spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java spring-core/src/main/java/org/springframework/core/env/ReadOnlySystemAttributesMap.java spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/AbstractLobHandler.java spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpRequestWrapper.java spring-web/src/main/java/org/springframework/http/client/SimpleBufferingClientHttpRequest.java spring-web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.javapull/249/head
1450 changed files with 17805 additions and 43125 deletions
@ -0,0 +1,158 @@
@@ -0,0 +1,158 @@
|
||||
/* |
||||
* Copyright 2002-2013 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package org.springframework.build.gradle |
||||
|
||||
import org.gradle.api.DefaultTask |
||||
import org.gradle.api.GradleException |
||||
import org.gradle.api.Plugin |
||||
import org.gradle.api.Project |
||||
import org.gradle.api.Task |
||||
import org.gradle.api.tasks.Input |
||||
import org.gradle.api.tasks.TaskAction |
||||
|
||||
|
||||
/** |
||||
* Gradle plugin that detects identically named, non-empty packages split across multiple |
||||
* subprojects, e.g. "org.springframework.context.annotation" existing in both spring-core |
||||
* and spring-aspects. Adds a 'detectSplitPackages' task to the current project's task |
||||
* collection. If the project already contains a 'check' task (i.e. is a typical Gradle |
||||
* project with the "java" plugin applied), the 'check' task will be updated to depend on |
||||
* the execution of 'detectSplitPackages'. |
||||
* |
||||
* By default, all subprojects will be scanned. Use the 'projectsToScan' task property to |
||||
* modify this value. Example usage: |
||||
* |
||||
* apply plugin: 'detect-split-packages // typically applied to root project |
||||
* |
||||
* detectSplitPackages { |
||||
* packagesToScan -= project(":spring-xyz") // scan every project but spring-xyz |
||||
* } |
||||
* |
||||
* @author Rob Winch |
||||
* @author Glyn Normington |
||||
* @author Chris Beams |
||||
*/ |
||||
public class DetectSplitPackagesPlugin implements Plugin<Project> { |
||||
public void apply(Project project) { |
||||
def tasks = project.tasks |
||||
Task detectSplitPackages = tasks.add("detectSplitPackages", DetectSplitPackagesTask.class) |
||||
if (tasks.asMap.containsKey("check")) { |
||||
tasks.getByName("check").dependsOn detectSplitPackages |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class DetectSplitPackagesTask extends DefaultTask { |
||||
|
||||
private static final String JAVA_FILE_SUFFIX = ".java" |
||||
private static final String PACKAGE_SEPARATOR = "." |
||||
private static final String HIDDEN_DIRECTORY_PREFIX = "." |
||||
|
||||
@Input |
||||
Set<Project> projectsToScan = project.subprojects |
||||
|
||||
public DetectSplitPackagesTask() { |
||||
this.group = "Verification" |
||||
this.description = "Detects packages split across two or more subprojects." |
||||
} |
||||
|
||||
@TaskAction |
||||
public void detectSplitPackages() { |
||||
def splitPackages = doDetectSplitPackages() |
||||
if (!splitPackages.isEmpty()) { |
||||
def message = "The following split package(s) have been detected:\n" |
||||
splitPackages.each { pkg, mod -> |
||||
message += " - ${pkg} (split across ${mod[0].name} and ${mod[1].name})\n" |
||||
} |
||||
throw new GradleException(message) |
||||
} |
||||
} |
||||
|
||||
private Map<String, List<Project>> doDetectSplitPackages() { |
||||
def splitPackages = [:] |
||||
def mergedProjects = findMergedProjects() |
||||
def packagesByProject = mapPackagesByProject() |
||||
|
||||
def projects = packagesByProject.keySet().toArray() |
||||
def nProjects = projects.length |
||||
|
||||
for (int i = 0; i < nProjects - 1; i++) { |
||||
for (int j = i + 1; j < nProjects - 1; j++) { |
||||
def prj_i = projects[i] |
||||
def prj_j = projects[j] |
||||
|
||||
def pkgs_i = new HashSet(packagesByProject.get(prj_i)) |
||||
def pkgs_j = packagesByProject.get(prj_j) |
||||
pkgs_i.retainAll(pkgs_j) |
||||
|
||||
if (!pkgs_i.isEmpty() |
||||
&& mergedProjects.get(prj_i) != prj_j |
||||
&& mergedProjects.get(prj_j) != prj_i) { |
||||
pkgs_i.each { pkg -> |
||||
def readablePkg = pkg.substring(1).replaceAll(File.separator, PACKAGE_SEPARATOR) |
||||
splitPackages[readablePkg] = [prj_i, prj_j] |
||||
} |
||||
} |
||||
} |
||||
} |
||||
return splitPackages; |
||||
} |
||||
|
||||
private Map<Project, Set<String>> mapPackagesByProject() { |
||||
def packagesByProject = [:] |
||||
this.projectsToScan.each { Project p -> |
||||
def packages = new HashSet<String>() |
||||
p.sourceSets.main.java.srcDirs.each { File dir -> |
||||
findPackages(packages, dir, "") |
||||
} |
||||
if (!packages.isEmpty()) { |
||||
packagesByProject.put(p, packages) |
||||
} |
||||
} |
||||
return packagesByProject; |
||||
} |
||||
|
||||
private Map<Project, Project> findMergedProjects() { |
||||
def mergedProjects = [:] |
||||
this.projectsToScan.findAll { p -> |
||||
p.plugins.findPlugin(MergePlugin) |
||||
}.findAll { p -> |
||||
p.merge.into |
||||
}.each { p -> |
||||
mergedProjects.put(p, p.merge.into) |
||||
} |
||||
return mergedProjects |
||||
} |
||||
|
||||
private static void findPackages(Set<String> packages, File dir, String packagePath) { |
||||
def scanDir = new File(dir, packagePath) |
||||
def File[] javaFiles = scanDir.listFiles({ file -> |
||||
!file.isDirectory() && file.name.endsWith(JAVA_FILE_SUFFIX) |
||||
} as FileFilter) |
||||
|
||||
if (javaFiles != null && javaFiles.length != 0) { |
||||
packages.add(packagePath) |
||||
} |
||||
|
||||
scanDir.listFiles({ File file -> |
||||
file.isDirectory() && !file.name.startsWith(HIDDEN_DIRECTORY_PREFIX) |
||||
} as FileFilter).each { File subDir -> |
||||
findPackages(packages, dir, packagePath + File.separator + subDir.name) |
||||
} |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
implementation-class=org.springframework.build.gradle.DetectSplitPackagesPlugin |
||||
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.aop; |
||||
|
||||
import java.io.Serializable; |
||||
import java.lang.reflect.Method; |
||||
import java.util.HashMap; |
||||
|
||||
/** |
||||
* Abstract superclass for counting advices etc. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Chris Beams |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class MethodCounter implements Serializable { |
||||
|
||||
/** Method name --> count, does not understand overloading */ |
||||
private HashMap<String, Integer> map = new HashMap<String, Integer>(); |
||||
|
||||
private int allCount; |
||||
|
||||
protected void count(Method m) { |
||||
count(m.getName()); |
||||
} |
||||
|
||||
protected void count(String methodName) { |
||||
Integer i = map.get(methodName); |
||||
i = (i != null) ? new Integer(i.intValue() + 1) : new Integer(1); |
||||
map.put(methodName, i); |
||||
++allCount; |
||||
} |
||||
|
||||
public int getCalls(String methodName) { |
||||
Integer i = map.get(methodName); |
||||
return (i != null ? i.intValue() : 0); |
||||
} |
||||
|
||||
public int getCalls() { |
||||
return allCount; |
||||
} |
||||
|
||||
/** |
||||
* A bit simplistic: just wants the same class. |
||||
* Doesn't worry about counts. |
||||
* @see java.lang.Object#equals(java.lang.Object) |
||||
*/ |
||||
public boolean equals(Object other) { |
||||
return (other != null && other.getClass() == this.getClass()); |
||||
} |
||||
|
||||
public int hashCode() { |
||||
return getClass().hashCode(); |
||||
} |
||||
|
||||
} |
||||
@ -1,58 +0,0 @@
@@ -1,58 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.aop; |
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor; |
||||
import org.aopalliance.intercept.MethodInvocation; |
||||
|
||||
/** |
||||
* Trivial interceptor that can be introduced in a chain to display it. |
||||
* |
||||
* @author Rod Johnson |
||||
*/ |
||||
public class NopInterceptor implements MethodInterceptor { |
||||
|
||||
private int count; |
||||
|
||||
/** |
||||
* @see org.aopalliance.intercept.MethodInterceptor#invoke(MethodInvocation) |
||||
*/ |
||||
@Override |
||||
public Object invoke(MethodInvocation invocation) throws Throwable { |
||||
increment(); |
||||
return invocation.proceed(); |
||||
} |
||||
|
||||
public int getCount() { |
||||
return this.count; |
||||
} |
||||
|
||||
protected void increment() { |
||||
++count; |
||||
} |
||||
|
||||
public boolean equals(Object other) { |
||||
if (!(other instanceof NopInterceptor)) { |
||||
return false; |
||||
} |
||||
if (this == other) { |
||||
return true; |
||||
} |
||||
return this.count == ((NopInterceptor) other).count; |
||||
} |
||||
|
||||
} |
||||
@ -1,50 +0,0 @@
@@ -1,50 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.aop; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
|
||||
|
||||
/** |
||||
* Subclass of NopInterceptor that is serializable and |
||||
* can be used to test proxy serialization. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Chris Beams |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class SerializableNopInterceptor extends NopInterceptor implements Serializable { |
||||
|
||||
/** |
||||
* We must override this field and the related methods as |
||||
* otherwise count won't be serialized from the non-serializable |
||||
* NopInterceptor superclass. |
||||
*/ |
||||
private int count; |
||||
|
||||
@Override |
||||
public int getCount() { |
||||
return this.count; |
||||
} |
||||
|
||||
@Override |
||||
protected void increment() { |
||||
++count; |
||||
} |
||||
|
||||
} |
||||
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2007 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.beans; |
||||
|
||||
import org.springframework.core.enums.ShortCodedLabeledEnum; |
||||
|
||||
/** |
||||
* @author Rob Harrop |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class Colour extends ShortCodedLabeledEnum { |
||||
|
||||
public static final Colour RED = new Colour(0, "RED"); |
||||
public static final Colour BLUE = new Colour(1, "BLUE"); |
||||
public static final Colour GREEN = new Colour(2, "GREEN"); |
||||
public static final Colour PURPLE = new Colour(3, "PURPLE"); |
||||
|
||||
private Colour(int code, String label) { |
||||
super(code, label); |
||||
} |
||||
|
||||
} |
||||
@ -1,90 +0,0 @@
@@ -1,90 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.beans; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
import org.springframework.beans.factory.BeanNameAware; |
||||
import org.springframework.beans.factory.DisposableBean; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
* @since 21.08.2003 |
||||
*/ |
||||
@SuppressWarnings("serial") |
||||
public class DerivedTestBean extends TestBean implements Serializable, BeanNameAware, DisposableBean { |
||||
|
||||
private String beanName; |
||||
|
||||
private boolean initialized; |
||||
|
||||
private boolean destroyed; |
||||
|
||||
|
||||
public DerivedTestBean() { |
||||
} |
||||
|
||||
public DerivedTestBean(String[] names) { |
||||
if (names == null || names.length < 2) { |
||||
throw new IllegalArgumentException("Invalid names array"); |
||||
} |
||||
setName(names[0]); |
||||
setBeanName(names[1]); |
||||
} |
||||
|
||||
public static DerivedTestBean create(String[] names) { |
||||
return new DerivedTestBean(names); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void setBeanName(String beanName) { |
||||
if (this.beanName == null || beanName == null) { |
||||
this.beanName = beanName; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public String getBeanName() { |
||||
return beanName; |
||||
} |
||||
|
||||
public void setSpouseRef(String name) { |
||||
setSpouse(new TestBean(name)); |
||||
} |
||||
|
||||
|
||||
public void initialize() { |
||||
this.initialized = true; |
||||
} |
||||
|
||||
public boolean wasInitialized() { |
||||
return initialized; |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void destroy() { |
||||
this.destroyed = true; |
||||
} |
||||
|
||||
@Override |
||||
public boolean wasDestroyed() { |
||||
return destroyed; |
||||
} |
||||
|
||||
} |
||||
@ -1,23 +0,0 @@
@@ -1,23 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.beans; |
||||
|
||||
public interface INestedTestBean { |
||||
|
||||
public String getCompany(); |
||||
|
||||
} |
||||
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.beans; |
||||
|
||||
public interface IOther { |
||||
|
||||
void absquatulate(); |
||||
|
||||
} |
||||
@ -1,69 +0,0 @@
@@ -1,69 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2007 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.beans; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
/** |
||||
* Interface used for {@link test.beans.TestBean}. |
||||
* |
||||
* <p>Two methods are the same as on Person, but if this |
||||
* extends person it breaks quite a few tests.. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Juergen Hoeller |
||||
*/ |
||||
public interface ITestBean { |
||||
|
||||
int getAge(); |
||||
|
||||
void setAge(int age); |
||||
|
||||
String getName(); |
||||
|
||||
void setName(String name); |
||||
|
||||
ITestBean getSpouse(); |
||||
|
||||
void setSpouse(ITestBean spouse); |
||||
|
||||
ITestBean[] getSpouses(); |
||||
|
||||
String[] getStringArray(); |
||||
|
||||
void setStringArray(String[] stringArray); |
||||
|
||||
/** |
||||
* Throws a given (non-null) exception. |
||||
*/ |
||||
void exceptional(Throwable t) throws Throwable; |
||||
|
||||
Object returnsThis(); |
||||
|
||||
INestedTestBean getDoctor(); |
||||
|
||||
INestedTestBean getLawyer(); |
||||
|
||||
/** |
||||
* Increment the age by one. |
||||
* @return the previous age |
||||
*/ |
||||
int haveBirthday(); |
||||
|
||||
void unreliableFileOperation() throws IOException; |
||||
|
||||
} |
||||
@ -1,61 +0,0 @@
@@ -1,61 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.beans; |
||||
|
||||
/** |
||||
* Simple nested test bean used for testing bean factories, AOP framework etc. |
||||
* |
||||
* @author Trevor D. Cook |
||||
* @since 30.09.2003 |
||||
*/ |
||||
public class NestedTestBean implements INestedTestBean { |
||||
|
||||
private String company = ""; |
||||
|
||||
public NestedTestBean() { |
||||
} |
||||
|
||||
public NestedTestBean(String company) { |
||||
setCompany(company); |
||||
} |
||||
|
||||
public void setCompany(String company) { |
||||
this.company = (company != null ? company : ""); |
||||
} |
||||
|
||||
@Override |
||||
public String getCompany() { |
||||
return company; |
||||
} |
||||
|
||||
public boolean equals(Object obj) { |
||||
if (!(obj instanceof NestedTestBean)) { |
||||
return false; |
||||
} |
||||
NestedTestBean ntb = (NestedTestBean) obj; |
||||
return this.company.equals(ntb.company); |
||||
} |
||||
|
||||
public int hashCode() { |
||||
return this.company.hashCode(); |
||||
} |
||||
|
||||
public String toString() { |
||||
return "NestedTestBean: " + this.company; |
||||
} |
||||
|
||||
} |
||||
@ -1,431 +0,0 @@
@@ -1,431 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.beans; |
||||
|
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.Collection; |
||||
import java.util.Date; |
||||
import java.util.HashMap; |
||||
import java.util.HashSet; |
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Properties; |
||||
import java.util.Set; |
||||
|
||||
import org.springframework.util.ObjectUtils; |
||||
|
||||
/** |
||||
* Simple test bean used for testing bean factories, the AOP framework etc. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Juergen Hoeller |
||||
* @since 15 April 2001 |
||||
*/ |
||||
public class TestBean implements ITestBean, IOther, Comparable<Object> { |
||||
|
||||
private String beanName; |
||||
|
||||
private String country; |
||||
|
||||
private boolean postProcessed; |
||||
|
||||
private String name; |
||||
|
||||
private String sex; |
||||
|
||||
private int age; |
||||
|
||||
private boolean jedi; |
||||
|
||||
private ITestBean[] spouses; |
||||
|
||||
private String touchy; |
||||
|
||||
private String[] stringArray; |
||||
|
||||
private Integer[] someIntegerArray; |
||||
|
||||
private Date date = new Date(); |
||||
|
||||
private Float myFloat = new Float(0.0); |
||||
|
||||
private Collection<?> friends = new LinkedList<Object>(); |
||||
|
||||
private Set<?> someSet = new HashSet<Object>(); |
||||
|
||||
private Map<?, ?> someMap = new HashMap<Object, Object>(); |
||||
|
||||
private List<?> someList = new ArrayList<Object>(); |
||||
|
||||
private Properties someProperties = new Properties(); |
||||
|
||||
private INestedTestBean doctor = new NestedTestBean(); |
||||
|
||||
private INestedTestBean lawyer = new NestedTestBean(); |
||||
|
||||
private boolean destroyed; |
||||
|
||||
private Number someNumber; |
||||
|
||||
private Colour favouriteColour; |
||||
|
||||
private Boolean someBoolean; |
||||
|
||||
private List<?> otherColours; |
||||
|
||||
private List<?> pets; |
||||
|
||||
|
||||
public TestBean() { |
||||
} |
||||
|
||||
public TestBean(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public TestBean(ITestBean spouse) { |
||||
this.spouses = new ITestBean[] {spouse}; |
||||
} |
||||
|
||||
public TestBean(String name, int age) { |
||||
this.name = name; |
||||
this.age = age; |
||||
} |
||||
|
||||
public TestBean(ITestBean spouse, Properties someProperties) { |
||||
this.spouses = new ITestBean[] {spouse}; |
||||
this.someProperties = someProperties; |
||||
} |
||||
|
||||
public TestBean(List<?> someList) { |
||||
this.someList = someList; |
||||
} |
||||
|
||||
public TestBean(Set<?> someSet) { |
||||
this.someSet = someSet; |
||||
} |
||||
|
||||
public TestBean(Map<?, ?> someMap) { |
||||
this.someMap = someMap; |
||||
} |
||||
|
||||
public TestBean(Properties someProperties) { |
||||
this.someProperties = someProperties; |
||||
} |
||||
|
||||
|
||||
public void setBeanName(String beanName) { |
||||
this.beanName = beanName; |
||||
} |
||||
|
||||
public String getBeanName() { |
||||
return beanName; |
||||
} |
||||
|
||||
public void setPostProcessed(boolean postProcessed) { |
||||
this.postProcessed = postProcessed; |
||||
} |
||||
|
||||
public boolean isPostProcessed() { |
||||
return postProcessed; |
||||
} |
||||
|
||||
@Override |
||||
public String getName() { |
||||
return name; |
||||
} |
||||
|
||||
@Override |
||||
public void setName(String name) { |
||||
this.name = name; |
||||
} |
||||
|
||||
public String getSex() { |
||||
return sex; |
||||
} |
||||
|
||||
public void setSex(String sex) { |
||||
this.sex = sex; |
||||
if (this.name == null) { |
||||
this.name = sex; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public int getAge() { |
||||
return age; |
||||
} |
||||
|
||||
@Override |
||||
public void setAge(int age) { |
||||
this.age = age; |
||||
} |
||||
|
||||
public boolean isJedi() { |
||||
return jedi; |
||||
} |
||||
|
||||
public void setJedi(boolean jedi) { |
||||
this.jedi = jedi; |
||||
} |
||||
|
||||
@Override |
||||
public ITestBean getSpouse() { |
||||
return (spouses != null ? spouses[0] : null); |
||||
} |
||||
|
||||
@Override |
||||
public void setSpouse(ITestBean spouse) { |
||||
this.spouses = new ITestBean[] {spouse}; |
||||
} |
||||
|
||||
@Override |
||||
public ITestBean[] getSpouses() { |
||||
return spouses; |
||||
} |
||||
|
||||
public String getTouchy() { |
||||
return touchy; |
||||
} |
||||
|
||||
public void setTouchy(String touchy) throws Exception { |
||||
if (touchy.indexOf('.') != -1) { |
||||
throw new Exception("Can't contain a ."); |
||||
} |
||||
if (touchy.indexOf(',') != -1) { |
||||
throw new NumberFormatException("Number format exception: contains a ,"); |
||||
} |
||||
this.touchy = touchy; |
||||
} |
||||
|
||||
public String getCountry() { |
||||
return country; |
||||
} |
||||
|
||||
public void setCountry(String country) { |
||||
this.country = country; |
||||
} |
||||
|
||||
@Override |
||||
public String[] getStringArray() { |
||||
return stringArray; |
||||
} |
||||
|
||||
@Override |
||||
public void setStringArray(String[] stringArray) { |
||||
this.stringArray = stringArray; |
||||
} |
||||
|
||||
public Integer[] getSomeIntegerArray() { |
||||
return someIntegerArray; |
||||
} |
||||
|
||||
public void setSomeIntegerArray(Integer[] someIntegerArray) { |
||||
this.someIntegerArray = someIntegerArray; |
||||
} |
||||
|
||||
public Date getDate() { |
||||
return date; |
||||
} |
||||
|
||||
public void setDate(Date date) { |
||||
this.date = date; |
||||
} |
||||
|
||||
public Float getMyFloat() { |
||||
return myFloat; |
||||
} |
||||
|
||||
public void setMyFloat(Float myFloat) { |
||||
this.myFloat = myFloat; |
||||
} |
||||
|
||||
public Collection<?> getFriends() { |
||||
return friends; |
||||
} |
||||
|
||||
public void setFriends(Collection<?> friends) { |
||||
this.friends = friends; |
||||
} |
||||
|
||||
public Set<?> getSomeSet() { |
||||
return someSet; |
||||
} |
||||
|
||||
public void setSomeSet(Set<?> someSet) { |
||||
this.someSet = someSet; |
||||
} |
||||
|
||||
public Map<?, ?> getSomeMap() { |
||||
return someMap; |
||||
} |
||||
|
||||
public void setSomeMap(Map<?, ?> someMap) { |
||||
this.someMap = someMap; |
||||
} |
||||
|
||||
public List<?> getSomeList() { |
||||
return someList; |
||||
} |
||||
|
||||
public void setSomeList(List<?> someList) { |
||||
this.someList = someList; |
||||
} |
||||
|
||||
public Properties getSomeProperties() { |
||||
return someProperties; |
||||
} |
||||
|
||||
public void setSomeProperties(Properties someProperties) { |
||||
this.someProperties = someProperties; |
||||
} |
||||
|
||||
@Override |
||||
public INestedTestBean getDoctor() { |
||||
return doctor; |
||||
} |
||||
|
||||
public void setDoctor(INestedTestBean doctor) { |
||||
this.doctor = doctor; |
||||
} |
||||
|
||||
@Override |
||||
public INestedTestBean getLawyer() { |
||||
return lawyer; |
||||
} |
||||
|
||||
public void setLawyer(INestedTestBean lawyer) { |
||||
this.lawyer = lawyer; |
||||
} |
||||
|
||||
public Number getSomeNumber() { |
||||
return someNumber; |
||||
} |
||||
|
||||
public void setSomeNumber(Number someNumber) { |
||||
this.someNumber = someNumber; |
||||
} |
||||
|
||||
public Colour getFavouriteColour() { |
||||
return favouriteColour; |
||||
} |
||||
|
||||
public void setFavouriteColour(Colour favouriteColour) { |
||||
this.favouriteColour = favouriteColour; |
||||
} |
||||
|
||||
public Boolean getSomeBoolean() { |
||||
return someBoolean; |
||||
} |
||||
|
||||
public void setSomeBoolean(Boolean someBoolean) { |
||||
this.someBoolean = someBoolean; |
||||
} |
||||
|
||||
public List<?> getOtherColours() { |
||||
return otherColours; |
||||
} |
||||
|
||||
public void setOtherColours(List<?> otherColours) { |
||||
this.otherColours = otherColours; |
||||
} |
||||
|
||||
public List<?> getPets() { |
||||
return pets; |
||||
} |
||||
|
||||
public void setPets(List<?> pets) { |
||||
this.pets = pets; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* @see ITestBean#exceptional(Throwable) |
||||
*/ |
||||
@Override |
||||
public void exceptional(Throwable t) throws Throwable { |
||||
if (t != null) { |
||||
throw t; |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public void unreliableFileOperation() throws IOException { |
||||
throw new IOException(); |
||||
} |
||||
/** |
||||
* @see ITestBean#returnsThis() |
||||
*/ |
||||
@Override |
||||
public Object returnsThis() { |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* @see IOther#absquatulate() |
||||
*/ |
||||
@Override |
||||
public void absquatulate() { |
||||
} |
||||
|
||||
@Override |
||||
public int haveBirthday() { |
||||
return age++; |
||||
} |
||||
|
||||
|
||||
public void destroy() { |
||||
this.destroyed = true; |
||||
} |
||||
|
||||
public boolean wasDestroyed() { |
||||
return destroyed; |
||||
} |
||||
|
||||
|
||||
public boolean equals(Object other) { |
||||
if (this == other) { |
||||
return true; |
||||
} |
||||
if (other == null || !(other instanceof TestBean)) { |
||||
return false; |
||||
} |
||||
TestBean tb2 = (TestBean) other; |
||||
return (ObjectUtils.nullSafeEquals(this.name, tb2.name) && this.age == tb2.age); |
||||
} |
||||
|
||||
public int hashCode() { |
||||
return this.age; |
||||
} |
||||
|
||||
@Override |
||||
public int compareTo(Object other) { |
||||
if (this.name != null && other instanceof TestBean) { |
||||
return this.name.compareTo(((TestBean) other).getName()); |
||||
} |
||||
else { |
||||
return 1; |
||||
} |
||||
} |
||||
|
||||
public String toString() { |
||||
return this.name; |
||||
} |
||||
|
||||
} |
||||
@ -1,97 +0,0 @@
@@ -1,97 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.parsing; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collection; |
||||
import java.util.Collections; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.LinkedList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.springframework.beans.factory.parsing.AliasDefinition; |
||||
import org.springframework.beans.factory.parsing.ComponentDefinition; |
||||
import org.springframework.beans.factory.parsing.DefaultsDefinition; |
||||
import org.springframework.beans.factory.parsing.ImportDefinition; |
||||
import org.springframework.beans.factory.parsing.ReaderEventListener; |
||||
|
||||
/** |
||||
* @author Rob Harrop |
||||
* @author Juergen Hoeller |
||||
* @author Chris Beams |
||||
*/ |
||||
public class CollectingReaderEventListener implements ReaderEventListener { |
||||
|
||||
private final List<DefaultsDefinition> defaults = new LinkedList<DefaultsDefinition>(); |
||||
|
||||
private final Map<String, Object> componentDefinitions = new LinkedHashMap<String, Object>(8); |
||||
|
||||
private final Map<String, Object> aliasMap = new LinkedHashMap<String, Object>(8); |
||||
|
||||
private final List<ImportDefinition> imports = new LinkedList<ImportDefinition>(); |
||||
|
||||
|
||||
@Override |
||||
public void defaultsRegistered(DefaultsDefinition defaultsDefinition) { |
||||
this.defaults.add(defaultsDefinition); |
||||
} |
||||
|
||||
public List<DefaultsDefinition> getDefaults() { |
||||
return Collections.unmodifiableList(this.defaults); |
||||
} |
||||
|
||||
@Override |
||||
public void componentRegistered(ComponentDefinition componentDefinition) { |
||||
this.componentDefinitions.put(componentDefinition.getName(), componentDefinition); |
||||
} |
||||
|
||||
public ComponentDefinition getComponentDefinition(String name) { |
||||
return (ComponentDefinition) this.componentDefinitions.get(name); |
||||
} |
||||
|
||||
public ComponentDefinition[] getComponentDefinitions() { |
||||
Collection<Object> collection = this.componentDefinitions.values(); |
||||
return collection.toArray(new ComponentDefinition[collection.size()]); |
||||
} |
||||
|
||||
@Override |
||||
@SuppressWarnings("unchecked") |
||||
public void aliasRegistered(AliasDefinition aliasDefinition) { |
||||
List aliases = (List) this.aliasMap.get(aliasDefinition.getBeanName()); |
||||
if(aliases == null) { |
||||
aliases = new ArrayList(); |
||||
this.aliasMap.put(aliasDefinition.getBeanName(), aliases); |
||||
} |
||||
aliases.add(aliasDefinition); |
||||
} |
||||
|
||||
public List<?> getAliases(String beanName) { |
||||
List<?> aliases = (List<?>) this.aliasMap.get(beanName); |
||||
return aliases == null ? null : Collections.unmodifiableList(aliases); |
||||
} |
||||
|
||||
@Override |
||||
public void importProcessed(ImportDefinition importDefinition) { |
||||
this.imports.add(importDefinition); |
||||
} |
||||
|
||||
public List<ImportDefinition> getImports() { |
||||
return Collections.unmodifiableList(this.imports); |
||||
} |
||||
|
||||
} |
||||
@ -1,100 +0,0 @@
@@ -1,100 +0,0 @@
|
||||
/* |
||||
* Copyright 2002-2012 the original author or authors. |
||||
* |
||||
* 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. |
||||
*/ |
||||
|
||||
package test.util; |
||||
|
||||
import java.awt.*; |
||||
import java.io.ByteArrayInputStream; |
||||
import java.io.ByteArrayOutputStream; |
||||
import java.io.IOException; |
||||
import java.io.NotSerializableException; |
||||
import java.io.ObjectInputStream; |
||||
import java.io.ObjectOutputStream; |
||||
import java.io.OutputStream; |
||||
import java.io.Serializable; |
||||
|
||||
import static org.junit.Assert.*; |
||||
import org.junit.Test; |
||||
import test.beans.TestBean; |
||||
|
||||
/** |
||||
* Utilities for testing serializability of objects. |
||||
* Exposes static methods for use in other test cases. |
||||
* Contains {@link org.junit.Test} methods to test itself. |
||||
* |
||||
* @author Rod Johnson |
||||
* @author Chris Beams |
||||
*/ |
||||
public final class SerializationTestUtils { |
||||
|
||||
public static void testSerialization(Object o) throws IOException { |
||||
OutputStream baos = new ByteArrayOutputStream(); |
||||
ObjectOutputStream oos = new ObjectOutputStream(baos); |
||||
oos.writeObject(o); |
||||
} |
||||
|
||||
public static boolean isSerializable(Object o) throws IOException { |
||||
try { |
||||
testSerialization(o); |
||||
return true; |
||||
} |
||||
catch (NotSerializableException ex) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException { |
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
||||
ObjectOutputStream oos = new ObjectOutputStream(baos); |
||||
oos.writeObject(o); |
||||
oos.flush(); |
||||
baos.flush(); |
||||
byte[] bytes = baos.toByteArray(); |
||||
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(bytes); |
||||
ObjectInputStream ois = new ObjectInputStream(is); |
||||
Object o2 = ois.readObject(); |
||||
return o2; |
||||
} |
||||
|
||||
|
||||
@Test(expected=NotSerializableException.class) |
||||
public void testWithNonSerializableObject() throws IOException { |
||||
TestBean o = new TestBean(); |
||||
assertFalse(o instanceof Serializable); |
||||
assertFalse(isSerializable(o)); |
||||
|
||||
testSerialization(o); |
||||
} |
||||
|
||||
@Test |
||||
public void testWithSerializableObject() throws Exception { |
||||
int x = 5; |
||||
int y = 10; |
||||
Point p = new Point(x, y); |
||||
assertTrue(p instanceof Serializable); |
||||
|
||||
testSerialization(p); |
||||
|
||||
assertTrue(isSerializable(p)); |
||||
|
||||
Point p2 = (Point) serializeAndDeserialize(p); |
||||
assertNotSame(p, p2); |
||||
assertEquals(x, (int) p2.getX()); |
||||
assertEquals(y, (int) p2.getY()); |
||||
} |
||||
|
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue