6690668: Updates implementations and tests for `module' support.
authorstanleyh
Fri Apr 18 01:02:32 2008 -0700 (19 months ago)
changeset 130092ec3194350
parent 129ae43ab45c2fb
child 1315366fb3db87f
6690668: Updates implementations and tests for `module' support.
Summary: Updated JSR 277 + 294 API.
Reviewed-by: mchung
src/share/classes/java/lang/ModuleInfo.java
src/share/classes/java/module/ImportDependency.java
src/share/classes/java/module/ImportPolicy.java
src/share/classes/java/module/JamModuleDefinition.java
src/share/classes/java/module/JamPackageDefinition.java
src/share/classes/java/module/ModuleDefinition.java
src/share/classes/java/module/ModuleDependency.java
src/share/classes/java/module/PackageDefinition.java
src/share/classes/java/module/Query.java
src/share/classes/java/module/UnsatisfiedDependencyException.java
src/share/classes/java/module/annotation/Attribute.java
src/share/classes/java/module/annotation/Attributes.java
src/share/classes/java/module/annotation/ImportModule.java
src/share/classes/java/module/annotation/ModuleAttribute.java
src/share/classes/java/module/annotation/ModuleAttributes.java
src/share/classes/java/module/annotation/Version.java
src/share/classes/sun/module/bootstrap/BootstrapModuleSystem.java
src/share/classes/sun/module/core/ModuleImpl.java
src/share/classes/sun/module/core/ModuleUtils.java
--- a/src/share/classes/java/lang/ModuleInfo.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/lang/ModuleInfo.java Fri Apr 18 01:02:32 2008 -0700
@@ -184,6 +184,8 @@ public final class ModuleInfo implements
* the module has no members.
*
* @return an array of the names of all member packages
+ * @throws UnsupporterOperationException if the packages cannot be
+ * determined.
*/
public String[] getMemberPackages() {
return members.toArray(S0);
@@ -200,6 +202,8 @@ public final class ModuleInfo implements
* the module has no members that are exported types.
*
* @return an array of the names of all packages that have exported types.
+ * @throws UnsupporterOperationException if the packages cannot be
+ * determined.
*/
public String[] getExportedPackages() {
return exported.toArray(S0);
--- a/src/share/classes/java/module/ImportDependency.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/module/ImportDependency.java Fri Apr 18 01:02:32 2008 -0700
@@ -25,27 +25,211 @@
package java.module;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+
/**
- * A tagging interface that all import dependencies must extend.
+ * This class represents an import dependency in a module definition.
* <p>
- * @see java.module.ModuleDependency
+ * @see java.module.VersionConstraint
+ * @see java.io.Serializable
*
* @since 1.7
+ * @serial include
*/
-public interface ImportDependency {
-
- /**
- * Returns true if the import dependency is optional. Otherwise, returns
- * false.
- *
- * @return true if the import dependency is optional; false otherwise.
- */
- public boolean isOptional();
-
- /**
- * Returns the granularity of the import dependency.
- *
- * @return the granularity of the import dependency.
- */
- public String getGranularity();
+public class ImportDependency implements java.io.Serializable {
+
+ private static final long serialVersionUID = -4888614342905988975L;
+
+ private final String type;
+ private final String name;
+ private final VersionConstraint constraint;
+ private final boolean reexport;
+ private final boolean optional;
+ private final Map<String, String> attributes;
+
+ /**
+ * Constructs a {@code ImportDependency} object.
+ *
+ * @param type the type of the import.
+ * @param name the name of the import.
+ * @param constraint the version constraint of the import.
+ * @param reexport true if the import is re-exported; otherwise, false.
+ * @param optional true if the import is optional; otherwise, false.
+ * @param attributes map of attributes of the import; null if there is no
+ * attributes.
+ * @throws NullPointerException if type is null, name is null or
+ * constraint is null.
+ */
+ public ImportDependency(String type, String name,
+ VersionConstraint constraint,
+ boolean reexport, boolean optional,
+ Map<String, String> attributes) {
+
+ if (type == null)
+ throw new NullPointerException("type must not be null.");
+
+ if (name == null)
+ throw new NullPointerException("name must not be null.");
+
+ if (constraint == null)
+ throw new NullPointerException("constraint must not be null.");
+
+ this.type = type;
+ this.name = name;
+ this.constraint = constraint;
+ this.reexport = reexport;
+ this.optional = optional;
+ if (attributes == null) {
+ this.attributes = Collections.emptyMap();;
+ } else {
+ this.attributes = new HashMap<String, String>(attributes);
+ }
+ }
+
+ /**
+ * Returns the name of the import.
+ *
+ * @return the name of the import.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Returns the version constraint of the import.
+ *
+ * @return the version constraint of the import.
+ */
+ public VersionConstraint getVersionConstraint() {
+ return constraint;
+ }
+
+ /**
+ * Returns true if the import is re-exported; otherwise, returns false.
+ *
+ * @return true if the import is re-exported; otherwise, returns false.
+ */
+ public boolean isReexported() {
+ return reexport;
+ }
+
+ /**
+ * Returns true if the import is optional; otherwise, returns false.
+ *
+ * @return true if the import is optional; otherwise, returns false.
+ */
+ public boolean isOptional() {
+ return optional;
+ }
+
+ /**
+ * Returns the type of the import dependency.
+ *
+ * @return the type of the import dependency.
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Returns an unmodifiable set of the names of the attributes associated
+ * with this {@code ImportDependency}.
+ *
+ * @return an unmodifiable set of the names of the attributes.
+ */
+ public Set<String> getAttributeNames() {
+ return attributes.keySet();
+ }
+
+ /**
+ * Returns the value corresponding to the specified attribute name that is
+ * associated with this {@code ImportDependency}.
+ *
+ * @param name the name of the attribute.
+ * @return the value of the attribute. Returns null if the specified
+ * attribute name is not found.
+ */
+ public String getAttribute(String name) {
+ return attributes.get(name);
+ }
+
+ /**
+ * Compare two {@code ImportDependency} objects for equality. The result is
+ * {@code true} if and only if the argument is not {@code null} and is a
+ * {@code ImportDependency} object that imported type, name, version
+ * constraint, reexport, optional, and attributes are the same as those of
+ * this {@code ImportDependency}.
+ *
+ * @param obj the object to compare with.
+ * @return whether or not the two objects are equal
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+
+ if (!(obj instanceof ImportDependency))
+ return false;
+
+ ImportDependency dep = (ImportDependency) obj;
+
+ return (type.equals(dep.getType())
+ && name.equals(dep.getName())
+ && constraint.equals(dep.getVersionConstraint())
+ && reexport == dep.isReexported()
+ && optional == dep.isOptional()
+ && attributes.equals(dep.attributes));
+ }
+
+ /**
+ * Returns a hash code for this {@code ImportDependency}.
+ *
+ * @return a hash code value for this {@code ImportDependency}.
+ */
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 37 * result + type.hashCode();
+ result = 37 * result + name.hashCode();
+ result = 37 * result + constraint.hashCode();
+ result = 37 * result + (reexport ? 0 : 1);
+ result = 37 * result + (optional ? 0 : 1);
+ result = 37 * result + attributes.hashCode();
+ return result;
+ }
+
+ /**
+ * Returns a {@code String} object representing this
+ * {@code ImportDependency}.
+ *
+ * @return a string representation of the {@code ImportDependency} object.
+ */
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+
+ builder.append("ImportDependency[type=");
+ builder.append(type);
+ builder.append(",name=");
+ builder.append(name);
+ builder.append(",version=");
+ builder.append(constraint.toString());
+ if (reexport) {
+ builder.append(",re-export");
+ }
+ if (optional) {
+ builder.append(",optional");
+ }
+ if (attributes != null) {
+ builder.append(",attributes=");
+ builder.append(attributes);
+ }
+ builder.append("]");
+
+ return builder.toString();
+ }
}
--- a/src/share/classes/java/module/ImportPolicy.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/module/ImportPolicy.java Fri Apr 18 01:02:32 2008 -0700
@@ -33,7 +33,6 @@ import java.util.Map;
* import policy is used to determine the list of imported module definitions
* in the resolving process to prepare the module instance.
* <p>
- * @see java.module.ImportDependency
* @see java.module.ImportOverridePolicy
* @see java.module.Module
* @see java.module.ModuleDefinition
@@ -49,7 +48,7 @@ public interface ImportPolicy {
* instance.
* <p>
* The list of import module dependencies that is returned from the
- * {@code getImportModuleDependencies()} method of the
+ * {@code getImportDependencies()} method of the
* {@code ModuleDefinition} object only reflects the import module
* dependencies with the original version constraints that were specified
* in the module definition at build time. However, it is possible that
@@ -83,6 +82,7 @@ public interface ImportPolicy {
* instance.
* @throws UnsatisfiedDependencyException if an import module dependency
* cannot be satisfied.
+ * @throws ModuleInitializationException if there is other error.
* @return a list of imported module definitions for preparing this module
* instance in the resolving process.
*/
--- a/src/share/classes/java/module/JamModuleDefinition.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/module/JamModuleDefinition.java Fri Apr 18 01:02:32 2008 -0700
@@ -41,12 +41,12 @@ import java.util.regex.Matcher;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import java.module.annotation.Attribute;
+import java.module.annotation.Attributes;
import java.module.annotation.ExportResources;
import java.module.annotation.ImportModule;
import java.module.annotation.ImportModules;
import java.module.annotation.MainClass;
-import java.module.annotation.ModuleAttribute;
-import java.module.annotation.ModuleAttributes;
import sun.module.annotation.LegacyClasses;
import sun.module.JamUtils;
@@ -77,7 +77,6 @@ final class JamModuleDefinition extends
private volatile Set<PackageDefinition> exportedPackageDefs;
private volatile Map<Class,Annotation> annotations = null;
private volatile List<ImportDependency> importDependencies = null;
- private volatile List<ModuleDependency> importModuleDependencies = null;
JamModuleDefinition(String name, Version version, byte[] metadata,
Callable<byte[]> metadataHandle, ModuleContent content,
@@ -159,16 +158,6 @@ final class JamModuleDefinition extends
public List<ImportDependency> getImportDependencies() {
if (importDependencies == null) {
List<ImportDependency> dependencies = new ArrayList<ImportDependency>();
- dependencies.addAll(getImportModuleDependencies());
- importDependencies = Collections.unmodifiableList(dependencies);
- }
- return importDependencies;
- }
-
- @Override
- public List<ModuleDependency> getImportModuleDependencies() {
- if (importModuleDependencies == null) {
- List<ModuleDependency> dependencies = new ArrayList<ModuleDependency>();
ModuleInfo mInfo = getModuleInfo();
ImportModules importModules = mInfo.getAnnotation(ImportModules.class);
if (importModules != null) {
@@ -177,20 +166,27 @@ final class JamModuleDefinition extends
VersionConstraint constraint = VersionConstraint.valueOf(importModule.version());
boolean reexport = importModule.reexport();
boolean optional = importModule.optional();
- dependencies.add(new ModuleDependency(name, constraint, reexport, optional));
- }
- }
- importModuleDependencies = Collections.unmodifiableList(dependencies);
- }
- return importModuleDependencies;
+ Attribute[] attributes = importModule.attributes();
+ Map<String, String> attrs = new HashMap<String, String>();
+ if (attributes != null) {
+ for (Attribute a : attributes) {
+ attrs.put(a.name(), a.value());
+ }
+ }
+ dependencies.add(new ImportDependency("module", name, constraint, reexport, optional, attrs));
+ }
+ }
+ importDependencies = dependencies;
+ }
+ return importDependencies;
}
@Override
public Set<String> getAttributeNames() {
HashSet<String> names = new HashSet<String>();
- ModuleAttributes attrs = getAnnotation(ModuleAttributes.class);
+ Attributes attrs = getAnnotation(Attributes.class);
if (attrs != null) {
- for (ModuleAttribute attr : attrs.value()) {
+ for (Attribute attr : attrs.value()) {
names.add(attr.name());
}
}
@@ -202,9 +198,9 @@ final class JamModuleDefinition extends
if (name == null) {
throw new NullPointerException("name must not be null.");
}
- ModuleAttributes attrs = getAnnotation(ModuleAttributes.class);
+ Attributes attrs = getAnnotation(Attributes.class);
if (attrs != null) {
- for (ModuleAttribute attr : attrs.value()) {
+ for (Attribute attr : attrs.value()) {
if (name.equals(attr.name())) {
return attr.value();
}
--- a/src/share/classes/java/module/JamPackageDefinition.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/module/JamPackageDefinition.java Fri Apr 18 01:02:32 2008 -0700
@@ -27,6 +27,8 @@ package java.module;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -53,44 +55,22 @@ class JamPackageDefinition extends Packa
this.moduleDef = moduleDef;
}
- /**
- * Returns the name of the package definition.
- *
- * @return the name of the package definition.
- */
+ @Override
public String getName() {
return packageName;
}
- /**
- * Returns the version of the package definition.
- *
- * @return the {@code Version} object.
- */
+ @Override
public Version getVersion() {
return version;
}
- /**
- * Returns the module definition that is associated with this package
- * definition.
- *
- * @return the {@code ModuleDefinition} object.
- */
+ @Override
public ModuleDefinition getModuleDefinition() {
return moduleDef;
}
- /**
- * Returns this element's annotation for the specified type or
- * the value of the specified attribute as an annotation.
- *
- * @param annotationClass the Class object corresponding to the
- * annotation type
- * @return this element's annotation for the specified annotation type if
- * present on this element, else null
- * @throws NullPointerException if the given annotation class is null
- */
+ @Override
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
if (annotationClass == null)
throw new NullPointerException();
@@ -98,14 +78,25 @@ class JamPackageDefinition extends Packa
return null;
}
- /**
- * Returns an unmodifiable list of all annotations present on this element.
- * If no annotations are present, an empty list is returned.
- *
- * @return an unmodifiable list of all annotations present on this element
- */
+ @Override
public List<Annotation> getAnnotations() {
// XXX: not yet implemented
return new ArrayList<Annotation>();
}
+
+ @Override
+ public Set<String> getAttributeNames() {
+ HashSet<String> names = new HashSet<String>();
+ // XXX: not yet implemented
+ return Collections.unmodifiableSet(names);
+ }
+
+ @Override
+ public String getAttribute(String name) {
+ if (name == null) {
+ throw new NullPointerException("name must not be null.");
+ }
+ // XXX: not yet implemented
+ return null;
+ }
}
--- a/src/share/classes/java/module/ModuleDefinition.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/module/ModuleDefinition.java Fri Apr 18 01:02:32 2008 -0700
@@ -95,23 +95,6 @@ public abstract class ModuleDefinition {
public abstract List<ImportDependency> getImportDependencies();
/**
- * Returns an unmodifiable list of import module dependencies. The order of
- * the import dependency in the list follows the declared import order in
- * the {@code ModuleDefinition}.
- *
- * @return an unmodifiable list of import module dependencies .
- */
- public List<ModuleDependency> getImportModuleDependencies() {
- List<ModuleDependency> moduleDependencies = new ArrayList<ModuleDependency>();
- for (ImportDependency impDep : getImportDependencies()) {
- if (impDep instanceof ModuleDependency) {
- moduleDependencies.add((ModuleDependency) impDep);
- }
- }
- return Collections.unmodifiableList(moduleDependencies);
- }
-
- /**
* Returns the repository that is associated with this
* {@code ModuleDefinition}.
*
--- a/src/share/classes/java/module/PackageDefinition.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/module/PackageDefinition.java Fri Apr 18 01:02:32 2008 -0700
@@ -92,6 +92,24 @@ public abstract class PackageDefinition
public abstract List<Annotation> getAnnotations();
/**
+ * Returns an unmodifiable set of the names of the attributes associated
+ * with this {@code PackageDefinition}.
+ *
+ * @return an unmodifiable set of the names of the attributes.
+ */
+ public abstract Set<String> getAttributeNames();
+
+ /**
+ * Returns the value corresponding to the specified attribute name that is
+ * associated with this {@code PackageDefinition}.
+ *
+ * @param name the name of the attribute.
+ * @return the value of the attribute. Returns null if the specified
+ * attribute name is not found.
+ */
+ public abstract String getAttribute(String name);
+
+ /**
* Compares the specified object with this {@code PackageDefinition} for
* equality.
* Returns {@code true} if and only if {@code obj} is the same object as
--- a/src/share/classes/java/module/Query.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/module/Query.java Fri Apr 18 01:02:32 2008 -0700
@@ -599,6 +599,26 @@ public abstract class Query implements S
}
/**
+ * Returns a {@code Query} that requires the name of a module definition
+ * equals to the specified name and that the version of a module definition
+ * to be contained within any of the ranges known to the specified version
+ * constraint.
+ *
+ * @param name the name of the module definition.
+ * @param constraint the string to be parsed as version constraint.
+ * @return the {@code Query} object.
+ * @throws IllegalArgumentException if the string cannot be parsed.
+ */
+ public static Query module(String name, String constraint) {
+ if (name == null)
+ throw new NullPointerException("name must not be null.");
+ if (constraint == null)
+ throw new NullPointerException("version constraint must not be null.");
+
+ return module(name, VersionConstraint.valueOf(constraint));
+ }
+
+ /**
* Returns a {@code Query} that requires the specified name of a module attribute
* exists.
*
@@ -677,6 +697,26 @@ public abstract class Query implements S
}
/**
+ * Returns a {@code Query} that requires a module definition to have an
+ * exported package definition of the specified name and that the version
+ * of the package definition to be contained within any of the ranges known
+ * to the specified version constraint.
+ *
+ * @param name the name of the package definition
+ * @param constraint the string to be parsed as version constraint.
+ * @return the {@code Query} object.
+ * @throws IllegalArgumentException if the string cannot be parsed.
+ */
+ public static Query exportedPackage(String name, String constraint) {
+ if (name == null)
+ throw new NullPointerException("name must not be null.");
+ if (constraint == null)
+ throw new NullPointerException("version constraint must not be null.");
+
+ return exportedPackage(name, VersionConstraint.valueOf(constraint));
+ }
+
+ /**
* Determine if the specified module definition matches this query.
*
* @param target the {@code ModuleDefinition} to be matched.
--- a/src/share/classes/java/module/UnsatisfiedDependencyException.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/module/UnsatisfiedDependencyException.java Fri Apr 18 01:02:32 2008 -0700
@@ -26,12 +26,12 @@ package java.module;
package java.module;
/**
- * Thrown to indicate that there is an unsatisifed module dependency during
- * module initialization.
+ * Thrown to indicate that there is an unsatisifed dependency during module
+ * initialization.
*
+ * @see java.module.ImportDependency
+ * @see java.module.ImportPolicy
* @see java.module.ModuleDefinition
- * @see java.module.ModuleDependency
- * @see java.module.ImportPolicy
*
* @since 1.7
*/
@@ -40,46 +40,46 @@ public class UnsatisfiedDependencyExcept
static final long serialVersionUID = -3333250440766142016L;
private final transient ModuleDefinition moduleDef;
- private final transient ModuleDependency moduleDependency;
+ private final transient ImportDependency dependency;
private final transient VersionConstraint versionConstraint;
/**
* Constructs a {@code UnsatisfiedDependencyException} with the detail
- * message, the specified module definition, the module dependency, and
+ * message, the specified module definition, the import dependency, and
* the override version constraint.
*
* @param s the detail message.
* @param moduleDef the module definition.
- * @param moduleDependency the unsatisifed module dependency.
+ * @param dependency the unsatisifed import dependency.
* @param versionConstraint the override version constraint.
*/
public UnsatisfiedDependencyException(String s, ModuleDefinition moduleDef,
- ModuleDependency moduleDependency, VersionConstraint versionConstraint)
+ ImportDependency dependency, VersionConstraint versionConstraint)
{
super(s);
this.moduleDef = moduleDef;
- this.moduleDependency = moduleDependency;
+ this.dependency = dependency;
this.versionConstraint = versionConstraint;
}
/**
* Constructs a {@code UnsatisfiedDependencyException} with the detail
- * message, the cause, the specified module definition, the module
+ * message, the cause, the specified module definition, the import
* dependency, and the override version constraint.
*
* @param s the detail message.
* @param cause the cause.
* @param moduleDef the module definition.
- * @param moduleDependency the unsatisifed module dependency.
+ * @param dependency the unsatisifed import dependency.
* @param versionConstraint the override version constraint.
*/
public UnsatisfiedDependencyException(String s, Throwable cause,
ModuleDefinition moduleDef,
- ModuleDependency moduleDependency,
+ ImportDependency dependency,
VersionConstraint versionConstraint) {
super(s, cause);
this.moduleDef = moduleDef;
- this.moduleDependency = moduleDependency;
+ this.dependency = dependency;
this.versionConstraint = versionConstraint;
}
@@ -93,8 +93,8 @@ public class UnsatisfiedDependencyExcept
/**
* Returns the module dependency that is unsatisfied.
*/
- public ModuleDependency getModuleDependency() {
- return moduleDependency;
+ public ImportDependency getImportDependency() {
+ return dependency;
}
/**
--- a/src/share/classes/java/module/annotation/ImportModule.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/module/annotation/ImportModule.java Fri Apr 18 01:02:32 2008 -0700
@@ -77,4 +77,9 @@ public @interface ImportModule {
* the default is false.
*/
boolean reexport() default false;
+
+ /**
+ * Other attributes. If no attributes is specified, the default is {}.
+ */
+ Attribute[] attributes() default {};
}
--- a/src/share/classes/java/module/annotation/Version.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/java/module/annotation/Version.java Fri Apr 18 01:02:32 2008 -0700
@@ -31,10 +31,10 @@ import java.lang.annotation.RetentionPol
import java.lang.annotation.RetentionPolicy;
/**
- * Indicates the version of a module definition. The version format must follow the
- * one described in the {@link java.module.Version} class. This metadata annotation
- * is applied to the development module, i.e. the <I>module</I> construct.
- * For examples,
+ * Indicates the version. The version format must follow the one described in
+ * the {@link java.module.Version} class. This metadata annotation can be
+ * applied to the development module, i.e. the <I>module</I> construct, or a
+ * Java package. For examples,
* <blockquote><pre>
* //
* // com/wombat/xyz/module-info.java
@@ -53,17 +53,23 @@ import java.lang.annotation.RetentionPol
* //
* &#064;Version("3.4.5.6-b44-rc")
* module p.q.r;
+ *
+ * //
+ * // org/foo/util/package-info.java
+ * //
+ * &#064;Version("2.0.0")
+ * package org.foo.util;
* </pre></blockquote>
*
* @see java.module.Version
* @since 1.7
*/
-@Target({ElementType.MODULE, ElementType.TYPE})
+@Target({ElementType.MODULE, ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Version {
/**
- * The version of the module definition.
+ * The version.
*/
String value();
}
--- a/src/share/classes/sun/module/bootstrap/BootstrapModuleSystem.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/sun/module/bootstrap/BootstrapModuleSystem.java Fri Apr 18 01:02:32 2008 -0700
@@ -28,7 +28,6 @@ import java.module.ImportDependency;
import java.module.ImportDependency;
import java.module.Module;
import java.module.ModuleDefinition;
-import java.module.ModuleDependency;
import java.module.ModuleInitializationException;
import java.module.ModuleSystem;
import java.module.ModuleSystemEvent;
@@ -85,7 +84,7 @@ public final class BootstrapModuleSystem
// Based on the import dependency, set up the appropriate imported
// modules for a virtual module.
- for (ModuleDependency dep : moduleDef.getImportModuleDependencies()) {
+ for (ImportDependency dep : moduleDef.getImportDependencies()) {
// Find the imported module only through the bootstrap repository.
ModuleDefinition md = Repository.getBootstrapRepository().find(dep.getName(), dep.getVersionConstraint());
--- a/src/share/classes/sun/module/core/ModuleImpl.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/sun/module/core/ModuleImpl.java Fri Apr 18 01:02:32 2008 -0700
@@ -467,14 +467,14 @@ final class ModuleImpl extends Module {
importingModules = new HashSet<Module>();
loader = new ModuleLoader(this, moduleDef);
- List<ModuleDependency> importModuleDependencies = moduleDef.getImportModuleDependencies();
+ List<ImportDependency> importDependencies = moduleDef.getImportDependencies();
if (DEBUG) {
- System.out.println("Import dependency: " + importModuleDependencies);
+ System.out.println("Import dependency: " + importDependencies);
}
// Build version constraint map from the ImportDependencies
Map<String,VersionConstraint> versionConstraints = new HashMap<String,VersionConstraint>();
- for (ModuleDependency dep : importModuleDependencies) {
+ for (ImportDependency dep : importDependencies) {
if (versionConstraints.put(dep.getName(), dep.getVersionConstraint()) != null) {
fail(null, "Module " + moduleString + " imports module "
+ dep.getName() + " more than once.");
@@ -583,14 +583,14 @@ final class ModuleImpl extends Module {
// import dependencies in order, name, and version constraints
// and that no non-optional imports are missing
int n = importedMDs.size();
- List<ModuleDependency> importModuleDependencies = moduleDef.getImportModuleDependencies();
- if (n != importModuleDependencies.size()) {
+ List<ImportDependency> importDependencies = moduleDef.getImportDependencies();
+ if (n != importDependencies.size()) {
fail(null, "Import policy error in module " + moduleString
+ ": mismatch in number of imported module definition in the returned list: "
- + n + " != " + importModuleDependencies.size());
+ + n + " != " + importDependencies.size());
}
for (int i = 0; i < n; i++) {
- ModuleDependency dep = importModuleDependencies.get(i);
+ ImportDependency dep = importDependencies.get(i);
ModuleDefinition md = importedMDs.get(i);
if (md == null) {
if (dep.isOptional() == false) {
@@ -632,8 +632,8 @@ final class ModuleImpl extends Module {
String moduleString = moduleDef.getName() + " v" + moduleDef.getVersion();
List<ModuleDefinition> importedMDs = new ArrayList<ModuleDefinition>();
Repository rep = moduleDef.getRepository();
- List<ModuleDependency> importModuleDependencies = moduleDef.getImportModuleDependencies();
- for (ModuleDependency dep : importModuleDependencies) {
+ List<ImportDependency> importDependencies = moduleDef.getImportDependencies();
+ for (ImportDependency dep : importDependencies) {
String name = dep.getName();
VersionConstraint constraint = constraints.get(name);
--- a/src/share/classes/sun/module/core/ModuleUtils.java Wed Apr 16 02:49:49 2008 -0700
+++ b/src/share/classes/sun/module/core/ModuleUtils.java Fri Apr 18 01:02:32 2008 -0700
@@ -28,7 +28,6 @@ import java.module.ImportDependency;
import java.module.ImportDependency;
import java.module.Module;
import java.module.ModuleDefinition;
-import java.module.ModuleDependency;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -50,7 +49,7 @@ public final class ModuleUtils {
* @param includeAll true if the expansion should include all imported modules
*/
public static void expandReexports(Module m, List<Module> modules, boolean includeAll) {
- for (ModuleDependency dep : m.getModuleDefinition().getImportModuleDependencies()) {
+ for (ImportDependency dep : m.getModuleDefinition().getImportDependencies()) {
if ((includeAll == false) && (dep.isReexported() == false)) {
continue;
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/module/annotation/Attribute.java Fri Apr 18 01:02:32 2008 -0700
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.module.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Indicates an attribute. This metadata annotation is used as nested
+ * annotation inside other enclosing annotations. For
+ * example,
+ * <blockquote><pre>
+ * //
+ * // com/wombat/xyz/module-info.java
+ * //
+ * &#064;Version("1.0.0")
+ * &#064;Attributes({
+ * &#064;Attribute(name="org.opensource.license", value="GPL"),
+ * &#064;Attribute(name="java.magic.number", value="CAFEBABE")
+ * })
+ * module com.wombat.xyz;
+ *
+ * //
+ * // org/foo/util/packge-info.java
+ * //
+ * &#064;Version("1.0.0")
+ * &#064;Attributes({
+ * &#064;Attribute(name="vendor.name", value="Foo, Inc.")
+ * })
+ * package org.foo.util;
+ * </pre></blockquote>
+ *
+ * @see java.module.annotation.Attributes
+ * @see java.module.annotation.ImportModule
+ * @since 1.7
+ */
+@Target({})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Attribute {
+
+ /**
+ * The name of the attribute.
+ */
+ String name();
+
+ /**
+ * The value of the attribute.
+ */
+ String value();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/module/annotation/Attributes.java Fri Apr 18 01:02:32 2008 -0700
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.module.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Indicates an array of attributes. This metadata annotation can be applied
+ * to the development module, i.e. the <I>module</I> construct, or a Java
+ * package. For example,
+ * <blockquote><pre>
+ * //
+ * // com/wombat/xyz/module-info.java
+ * //
+ * &#064;Version("1.0.0")
+ * &#064;Attributes({
+ * &#064;Attribute(name="org.opensource.license", value="GPL"),
+ * &#064;Attribute(name="java.magic.number", value="CAFEBABE")
+ * })
+ * module com.wombat.xyz;
+ *
+ * //
+ * // org/foo/util/package-info.java
+ * //
+ * &#064;Version("1.0.0")
+ * &#064;Attributes({
+ * &#064;Attribute(name="vendor.name", value="Foo, Inc."),
+ * })
+ * package org.foo.util;
+ *
+ * </pre></blockquote>
+ * @see java.module.annotation.Attribute
+ * @since 1.7
+ */
+@Target({ElementType.MODULE, ElementType.PACKAGE, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Attributes {
+ /**
+ * An array of attributes.
+ */
+ Attribute[] value();
+}
--- a/src/share/classes/java/module/ModuleDependency.java Wed Apr 16 02:49:49 2008 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,202 +0,0 @@
-/*
- * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package java.module;
-
-/**
- * This class represents an import dependency of the module definition.
- * <p>
- * @see java.module.ImportDependency
- * @see java.module.VersionConstraint
- * @see java.io.Serializable
- *
- * @since 1.7
- * @serial include
- */
-public class ModuleDependency implements ImportDependency, java.io.Serializable {
-
- private static final long serialVersionUID = -4888614342905988975L;
-
- private final String name;
- private final VersionConstraint constraint;
- private final boolean reexport;
- private final boolean optional;
-
- /**
- * Constructs a {@code ModuleDependency} object.
- * <p>
- * The imported module definition is neither re-exported nor optional.
- *
- * @param name the name of the module definition to import.
- * @param constraint the version constraint on the import dependency.
- * @throws NullPointerException if name is null or constraint is null.
- */
- public ModuleDependency(String name, VersionConstraint constraint) {
- this(name, constraint, false, false);
- }
-
- /**
- * Constructs a {@code ModuleDependency} object.
- *
- * @param name the name of the module definition to import.
- * @param constraint the version constraint on the import dependency.
- * @param reexport true if the imported module definition is re-exported;
- * otherwise, false.
- * @param optional true if the imported module definition is optional;
- * otherwise, false.
- * @throws NullPointerException if name is null or constraint is null.
- */
- public ModuleDependency(String name, VersionConstraint constraint, boolean reexport, boolean optional) {
-
- if (name == null)
- throw new NullPointerException("name must not be null.");
-
- if (constraint == null)
- throw new NullPointerException("constraint must not be null.");
-
- this.name = name;
- this.constraint = constraint;
- this.reexport = reexport;
- this.optional = optional;
- }
-
- /**
- * Returns the name of the module definition to import.
- *
- * @return the name of the module definition to import.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the version constraint of the module definition to import.
- *
- * @return the version constraint of the module definition to import.
- */
- public VersionConstraint getVersionConstraint() {
- return constraint;
- }
-
- /**
- * Returns true if the imported module definition is re-exported;
- * otherwise, returns false.
- *
- * @return true if the imported module definition is re-exported;
- * otherwise, returns false.
- */
- public boolean isReexported() {
- return reexport;
- }
-
- /**
- * Returns true if the imported module definition is optional; otherwise,
- * returns false.
- *
- * @return true if the imported module definition is optional; otherwise,
- * returns false.
- */
- @Override
- public boolean isOptional() {
- return optional;
- }
-
- /**
- * Returns the granularity of the import dependency. The granularity is the
- * string "module".
- *
- * @return the granularity of the import dependency.
- */
- @Override
- public String getGranularity() {
- return "module";
- }
-
- /**
- * Compare two {@code ModuleDependency} objects for equality. The result is
- * {@code true} if and only if the argument is not {@code null} and is a
- * {@code ModuleDependency} object that imported module name, version
- * constraint, reexport, and optional the same as those of this
- * {@code ModuleDependency}.
- *
- * @param obj the object to compare with.
- * @return whether or not the two objects are equal
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
-
- if (!(obj instanceof ModuleDependency))
- return false;
-
- ModuleDependency moduleDep = (ModuleDependency) obj;
-
- return (name.equals(moduleDep.getName())
- && constraint.equals(moduleDep.getVersionConstraint())
- && reexport == moduleDep.isReexported()
- && optional == moduleDep.isOptional());
- }
-
- /**
- * Returns a hash code for this {@code ModuleDependency}.
- *
- * @return a hash code value for this {@code ModuleDependency}.
- */
- @Override
- public int hashCode() {
- int result = 17;
- result = 37 * result + name.hashCode();
- result = 37 * result + constraint.hashCode();
- result = 37 * result + (reexport ? 0 : 1);
- result = 37 * result + (optional ? 0 : 1);
- return result;
- }
-
- /**
- * Returns a {@code String} object representing this
- * {@code ModuleDependency}.
- *
- * @return a string representation of the {@code ModuleDependency} object.
- */
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder();
-
- builder.append("ModuleDependency[module ");
- builder.append(name);
- builder.append(" ");
- builder.append(constraint.toString());
- if (reexport) {
- builder.append(",re-export");
- }
- if (optional) {
- builder.append(",optional");
- }
- builder.append("]");
-
- return builder.toString();
- }
-}
--- a/src/share/classes/java/module/annotation/ModuleAttribute.java Wed Apr 16 02:49:49 2008 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/*
- * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package java.module.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Target;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/**
- * Indicates an attribute of a module definition. This metadata annotation
- * is used as nested annotation inside other enclosing annotations. For
- * example,
- * <blockquote><pre>
- * //
- * // com/wombat/xyz/module-info.java
- * //
- * &#064;Version("1.0.0")
- * &#064;ModuleAttributes({
- * &#064;ModuleAttribute(name="org.opensource.license", value="GPL"),
- * &#064;ModuleAttribute(name="java.magic.number", value="CAFEBABE")
- * })
- * module com.wombat.xyz;
- * </pre></blockquote>
- * Module attributes are generally defined by higher layers. To minimize the
- * naming conflicts between module attributes, it is recommended that each
- * module attribute should be defined with a fully qualified name.
- *
- * @see java.module.annotation.ModuleAttributes
- * @since 1.7
- */
-@Target({})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface ModuleAttribute {
-
- /**
- * The name of the module attribute.
- */
- String name();
-
- /**
- * The value of the module attribute.
- */
- String value();
-}
--- a/src/share/classes/java/module/annotation/ModuleAttributes.java Wed Apr 16 02:49:49 2008 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/*
- * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package java.module.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Target;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-/**
- * Indicates an array of attributes of a module definition. This metadata
- * annotation is applied to the development module, i.e. the <I>module</I>
- * construct. For example,
- * <blockquote><pre>
- * //
- * // com/wombat/xyz/module-info.java
- * //
- * &#064;Version("1.0.0")
- * &#064;ModuleAttributes({
- * &#064;ModuleAttribute(name="org.opensource.license", value="GPL"),
- * &#064;ModuleAttribute(name="java.magic.number", value="CAFEBABE")
- * })
- * module com.wombat.xyz;
- * </pre></blockquote>
- * @see java.module.annotation.ModuleAttribute
- * @since 1.7
- */
-@Target({ElementType.MODULE, ElementType.TYPE})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface ModuleAttributes {
- /**
- * An array of module attributes.
- */
- ModuleAttribute[] value();
-}