You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by jl...@apache.org on 2014/01/14 09:27:43 UTC
svn commit: r1557968 [11/26] - in /ant/ivy/core/trunk:
src/java/org/apache/ivy/ src/java/org/apache/ivy/ant/
src/java/org/apache/ivy/core/ src/java/org/apache/ivy/core/cache/
src/java/org/apache/ivy/core/check/ src/java/org/apache/ivy/core/deliver/
src...
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java?rev=1557968&r1=1557967&r2=1557968&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorBuilder.java Tue Jan 14 08:27:37 2014
@@ -57,83 +57,85 @@ import org.apache.ivy.plugins.repository
import org.apache.ivy.plugins.resolver.DependencyResolver;
import org.apache.ivy.util.Message;
-
/**
- * Build a module descriptor. This class handle the complexity of the structure of an ivy
- * ModuleDescriptor and isolate the PomModuleDescriptorParser from it.
+ * Build a module descriptor. This class handle the complexity of the structure of an ivy
+ * ModuleDescriptor and isolate the PomModuleDescriptorParser from it.
*/
public class PomModuleDescriptorBuilder {
-
private static final int DEPENDENCY_MANAGEMENT_KEY_PARTS_COUNT = 4;
public static final Configuration[] MAVEN2_CONFIGURATIONS = new Configuration[] {
- new Configuration("default", Visibility.PUBLIC,
- "runtime dependencies and master artifact can be used with this conf",
- new String[] {"runtime", "master"}, true, null),
- new Configuration("master", Visibility.PUBLIC,
- "contains only the artifact published by this module itself, "
- + "with no transitive dependencies",
- new String[0], true, null),
- new Configuration("compile", Visibility.PUBLIC,
- "this is the default scope, used if none is specified. "
- + "Compile dependencies are available in all classpaths.",
- new String[0], true, null),
- new Configuration("provided", Visibility.PUBLIC,
- "this is much like compile, but indicates you expect the JDK or a container "
- + "to provide it. "
- + "It is only available on the compilation classpath, and is not transitive.",
- new String[0], true, null),
- new Configuration("runtime", Visibility.PUBLIC,
- "this scope indicates that the dependency is not required for compilation, "
- + "but is for execution. It is in the runtime and test classpaths, "
- + "but not the compile classpath.",
- new String[] {"compile"}, true, null),
- new Configuration("test", Visibility.PRIVATE,
- "this scope indicates that the dependency is not required for normal use of "
- + "the application, and is only available for the test compilation and "
- + "execution phases.",
- new String[] {"runtime"}, true, null),
- new Configuration("system", Visibility.PUBLIC,
- "this scope is similar to provided except that you have to provide the JAR "
- + "which contains it explicitly. The artifact is always available and is not "
- + "looked up in a repository.",
- new String[0], true, null),
- new Configuration("sources", Visibility.PUBLIC,
- "this configuration contains the source artifact of this module, if any.",
- new String[0], true, null),
- new Configuration("javadoc", Visibility.PUBLIC,
- "this configuration contains the javadoc artifact of this module, if any.",
- new String[0], true, null),
- new Configuration("optional", Visibility.PUBLIC,
- "contains all optional dependencies", new String[0], true, null)
- };
+ new Configuration("default", Visibility.PUBLIC,
+ "runtime dependencies and master artifact can be used with this conf",
+ new String[] {"runtime", "master"}, true, null),
+ new Configuration("master", Visibility.PUBLIC,
+ "contains only the artifact published by this module itself, "
+ + "with no transitive dependencies", new String[0], true, null),
+ new Configuration("compile", Visibility.PUBLIC,
+ "this is the default scope, used if none is specified. "
+ + "Compile dependencies are available in all classpaths.",
+ new String[0], true, null),
+ new Configuration(
+ "provided",
+ Visibility.PUBLIC,
+ "this is much like compile, but indicates you expect the JDK or a container "
+ + "to provide it. "
+ + "It is only available on the compilation classpath, and is not transitive.",
+ new String[0], true, null),
+ new Configuration("runtime", Visibility.PUBLIC,
+ "this scope indicates that the dependency is not required for compilation, "
+ + "but is for execution. It is in the runtime and test classpaths, "
+ + "but not the compile classpath.", new String[] {"compile"}, true,
+ null),
+ new Configuration(
+ "test",
+ Visibility.PRIVATE,
+ "this scope indicates that the dependency is not required for normal use of "
+ + "the application, and is only available for the test compilation and "
+ + "execution phases.", new String[] {"runtime"}, true, null),
+ new Configuration(
+ "system",
+ Visibility.PUBLIC,
+ "this scope is similar to provided except that you have to provide the JAR "
+ + "which contains it explicitly. The artifact is always available and is not "
+ + "looked up in a repository.", new String[0], true, null),
+ new Configuration("sources", Visibility.PUBLIC,
+ "this configuration contains the source artifact of this module, if any.",
+ new String[0], true, null),
+ new Configuration("javadoc", Visibility.PUBLIC,
+ "this configuration contains the javadoc artifact of this module, if any.",
+ new String[0], true, null),
+ new Configuration("optional", Visibility.PUBLIC, "contains all optional dependencies",
+ new String[0], true, null)};
static final Map MAVEN2_CONF_MAPPING = new HashMap();
- private static final String DEPENDENCY_MANAGEMENT = "m:dependency.management";
+ private static final String DEPENDENCY_MANAGEMENT = "m:dependency.management";
+
private static final String PROPERTIES = "m:properties";
+
private static final String EXTRA_INFO_DELIMITER = "__";
- private static final Collection/*<String>*/ JAR_PACKAGINGS = Arrays.asList(
- new String[] {"ejb", "bundle", "maven-plugin", "eclipse-plugin",
- "jbi-component", "jbi-shared-library", "orbit", "hk2-jar"});
-
+ private static final Collection/* <String> */JAR_PACKAGINGS = Arrays.asList(new String[] {
+ "ejb", "bundle", "maven-plugin", "eclipse-plugin", "jbi-component",
+ "jbi-shared-library", "orbit", "hk2-jar"});
+
static interface ConfMapper {
public void addMappingConfs(DefaultDependencyDescriptor dd, boolean isOptional);
}
-
+
static {
MAVEN2_CONF_MAPPING.put("compile", new ConfMapper() {
public void addMappingConfs(DefaultDependencyDescriptor dd, boolean isOptional) {
if (isOptional) {
dd.addDependencyConfiguration("optional", "compile(*)");
- //dd.addDependencyConfiguration("optional", "provided(*)");
+ // dd.addDependencyConfiguration("optional", "provided(*)");
dd.addDependencyConfiguration("optional", "master(*)");
-
+
} else {
dd.addDependencyConfiguration("compile", "compile(*)");
- //dd.addDependencyConfiguration("compile", "provided(*)");
+ // dd.addDependencyConfiguration("compile", "provided(*)");
dd.addDependencyConfiguration("compile", "master(*)");
dd.addDependencyConfiguration("runtime", "runtime(*)");
}
@@ -145,7 +147,7 @@ public class PomModuleDescriptorBuilder
dd.addDependencyConfiguration("optional", "compile(*)");
dd.addDependencyConfiguration("optional", "provided(*)");
dd.addDependencyConfiguration("optional", "runtime(*)");
- dd.addDependencyConfiguration("optional", "master(*)");
+ dd.addDependencyConfiguration("optional", "master(*)");
} else {
dd.addDependencyConfiguration("provided", "compile(*)");
dd.addDependencyConfiguration("provided", "provided(*)");
@@ -160,7 +162,7 @@ public class PomModuleDescriptorBuilder
dd.addDependencyConfiguration("optional", "compile(*)");
dd.addDependencyConfiguration("optional", "provided(*)");
dd.addDependencyConfiguration("optional", "master(*)");
-
+
} else {
dd.addDependencyConfiguration("runtime", "compile(*)");
dd.addDependencyConfiguration("runtime", "runtime(*)");
@@ -170,36 +172,32 @@ public class PomModuleDescriptorBuilder
});
MAVEN2_CONF_MAPPING.put("test", new ConfMapper() {
public void addMappingConfs(DefaultDependencyDescriptor dd, boolean isOptional) {
- //optional doesn't make sense in the test scope
+ // optional doesn't make sense in the test scope
dd.addDependencyConfiguration("test", "runtime(*)");
dd.addDependencyConfiguration("test", "master(*)");
}
});
MAVEN2_CONF_MAPPING.put("system", new ConfMapper() {
public void addMappingConfs(DefaultDependencyDescriptor dd, boolean isOptional) {
- //optional doesn't make sense in the system scope
+ // optional doesn't make sense in the system scope
dd.addDependencyConfiguration("system", "master(*)");
}
});
}
-
-
private final PomModuleDescriptor ivyModuleDescriptor;
-
private ModuleRevisionId mrid;
private DefaultArtifact mainArtifact;
-
+
private ParserSettings parserSettings;
private static final String WRONG_NUMBER_OF_PARTS_MSG = "what seemed to be a dependency "
+ "management extra info exclusion had the wrong number of parts (should have 2) ";
-
- public PomModuleDescriptorBuilder(
- ModuleDescriptorParser parser, Resource res, ParserSettings ivySettings) {
+ public PomModuleDescriptorBuilder(ModuleDescriptorParser parser, Resource res,
+ ParserSettings ivySettings) {
ivyModuleDescriptor = new PomModuleDescriptor(parser, res);
ivyModuleDescriptor.setResolvedPublicationDate(new Date(res.getLastModified()));
for (int i = 0; i < MAVEN2_CONFIGURATIONS.length; i++) {
@@ -210,23 +208,21 @@ public class PomModuleDescriptorBuilder
parserSettings = ivySettings;
}
-
public ModuleDescriptor getModuleDescriptor() {
return ivyModuleDescriptor;
}
-
public void setModuleRevId(String groupId, String artifactId, String version) {
mrid = ModuleRevisionId.newInstance(groupId, artifactId, version);
ivyModuleDescriptor.setModuleRevisionId(mrid);
-
+
if ((version == null) || version.endsWith("SNAPSHOT")) {
ivyModuleDescriptor.setStatus("integration");
} else {
ivyModuleDescriptor.setStatus("release");
}
- }
-
+ }
+
public void setHomePage(String homePage) {
ivyModuleDescriptor.setHomePage(homePage);
}
@@ -243,7 +239,7 @@ public class PomModuleDescriptorBuilder
public void addMainArtifact(String artifactId, String packaging) {
String ext;
-
+
/*
* TODO: we should make packaging to ext mapping configurable, since it's not possible to
* cover all cases.
@@ -251,12 +247,12 @@ public class PomModuleDescriptorBuilder
if ("pom".equals(packaging)) {
// no artifact defined! Add the default artifact if it exist.
DependencyResolver resolver = parserSettings.getResolver(mrid);
-
+
if (resolver != null) {
- DefaultArtifact artifact = new DefaultArtifact(
- mrid, new Date(), artifactId, "jar", "jar");
+ DefaultArtifact artifact = new DefaultArtifact(mrid, new Date(), artifactId, "jar",
+ "jar");
ArtifactOrigin artifactOrigin = resolver.locate(artifact);
-
+
if (!ArtifactOrigin.isUnknown(artifactOrigin)) {
mainArtifact = artifact;
ivyModuleDescriptor.addArtifact("master", mainArtifact);
@@ -282,11 +278,11 @@ public class PomModuleDescriptorBuilder
// unknown scope, defaulting to 'compile'
scope = "compile";
}
-
+
String version = dep.getVersion();
version = (version == null || version.length() == 0) ? getDefaultVersion(dep) : version;
- ModuleRevisionId moduleRevId = ModuleRevisionId.newInstance(dep.getGroupId(), dep
- .getArtifactId(), version);
+ ModuleRevisionId moduleRevId = ModuleRevisionId.newInstance(dep.getGroupId(),
+ dep.getArtifactId(), version);
// Some POMs depend on theirselfves, don't add this dependency: Ivy doesn't allow this!
// Example: http://repo2.maven.org/maven2/net/jini/jsk-platform/2.1/jsk-platform-2.1.pom
@@ -295,12 +291,14 @@ public class PomModuleDescriptorBuilder
return;
}
- DefaultDependencyDescriptor dd = new PomDependencyDescriptor(dep, ivyModuleDescriptor, moduleRevId);
+ DefaultDependencyDescriptor dd = new PomDependencyDescriptor(dep, ivyModuleDescriptor,
+ moduleRevId);
scope = (scope == null || scope.length() == 0) ? getDefaultScope(dep) : scope;
ConfMapper mapping = (ConfMapper) MAVEN2_CONF_MAPPING.get(scope);
mapping.addMappingConfs(dd, dep.isOptional());
Map extraAtt = new HashMap();
- if ((dep.getClassifier() != null) || ((dep.getType() != null) && !"jar".equals(dep.getType()))) {
+ if ((dep.getClassifier() != null)
+ || ((dep.getType() != null) && !"jar".equals(dep.getType()))) {
String type = "jar";
if (dep.getType() != null) {
type = dep.getType();
@@ -314,89 +312,89 @@ public class PomModuleDescriptorBuilder
extraAtt.put("m:classifier", "tests");
} else if (JAR_PACKAGINGS.contains(type)) {
ext = "jar";
- }
-
+ }
+
// we deal with classifiers by setting an extra attribute and forcing the
// dependency to assume such an artifact is published
if (dep.getClassifier() != null) {
extraAtt.put("m:classifier", dep.getClassifier());
}
- DefaultDependencyArtifactDescriptor depArtifact =
- new DefaultDependencyArtifactDescriptor(dd, dd.getDependencyId().getName(),
- type, ext, null, extraAtt);
+ DefaultDependencyArtifactDescriptor depArtifact = new DefaultDependencyArtifactDescriptor(
+ dd, dd.getDependencyId().getName(), type, ext, null, extraAtt);
// here we have to assume a type and ext for the artifact, so this is a limitation
// compared to how m2 behave with classifiers
String optionalizedScope = dep.isOptional() ? "optional" : scope;
dd.addDependencyArtifact(optionalizedScope, depArtifact);
}
-
+
// experimentation shows the following, excluded modules are
// inherited from parent POMs if either of the following is true:
// the <exclusions> element is missing or the <exclusions> element
// is present, but empty.
- List /*<ModuleId>*/ excluded = dep.getExcludedModules();
+ List /* <ModuleId> */excluded = dep.getExcludedModules();
if (excluded.isEmpty()) {
- excluded = getDependencyMgtExclusions(ivyModuleDescriptor, dep.getGroupId(), dep.getArtifactId());
+ excluded = getDependencyMgtExclusions(ivyModuleDescriptor, dep.getGroupId(),
+ dep.getArtifactId());
}
for (Iterator itExcl = excluded.iterator(); itExcl.hasNext();) {
ModuleId excludedModule = (ModuleId) itExcl.next();
String[] confs = dd.getModuleConfigurations();
for (int k = 0; k < confs.length; k++) {
- dd.addExcludeRule(confs[k], new DefaultExcludeRule(new ArtifactId(
- excludedModule, PatternMatcher.ANY_EXPRESSION,
- PatternMatcher.ANY_EXPRESSION,
- PatternMatcher.ANY_EXPRESSION),
- ExactPatternMatcher.INSTANCE, null));
+ dd.addExcludeRule(confs[k], new DefaultExcludeRule(new ArtifactId(excludedModule,
+ PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION,
+ PatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, null));
}
}
-
+
ivyModuleDescriptor.addDependency(dd);
}
public void addDependency(DependencyDescriptor descriptor) {
// Some POMs depend on themselves through their parent pom, don't add this dependency
// since Ivy doesn't allow this!
- // Example: http://repo2.maven.org/maven2/com/atomikos/atomikos-util/3.6.4/atomikos-util-3.6.4.pom
+ // Example:
+ // http://repo2.maven.org/maven2/com/atomikos/atomikos-util/3.6.4/atomikos-util-3.6.4.pom
ModuleId dependencyId = descriptor.getDependencyId();
ModuleRevisionId mRevId = ivyModuleDescriptor.getModuleRevisionId();
if ((mRevId != null) && mRevId.getModuleId().equals(dependencyId)) {
return;
}
-
+
ivyModuleDescriptor.addDependency(descriptor);
}
-
public void addDependencyMgt(PomDependencyMgt dep) {
ivyModuleDescriptor.addDependencyManagement(dep);
String key = getDependencyMgtExtraInfoKeyForVersion(dep.getGroupId(), dep.getArtifactId());
ivyModuleDescriptor.addExtraInfo(key, dep.getVersion());
if (dep.getScope() != null) {
- String scopeKey = getDependencyMgtExtraInfoKeyForScope(
- dep.getGroupId(), dep.getArtifactId());
+ String scopeKey = getDependencyMgtExtraInfoKeyForScope(dep.getGroupId(),
+ dep.getArtifactId());
ivyModuleDescriptor.addExtraInfo(scopeKey, dep.getScope());
}
if (!dep.getExcludedModules().isEmpty()) {
final String exclusionPrefix = getDependencyMgtExtraInfoPrefixForExclusion(
- dep.getGroupId(), dep.getArtifactId());
+ dep.getGroupId(), dep.getArtifactId());
int index = 0;
for (final Iterator iter = dep.getExcludedModules().iterator(); iter.hasNext();) {
final ModuleId excludedModule = (ModuleId) iter.next();
- ivyModuleDescriptor.addExtraInfo(exclusionPrefix + index,
- excludedModule.getOrganisation() + EXTRA_INFO_DELIMITER + excludedModule.getName());
+ ivyModuleDescriptor.addExtraInfo(
+ exclusionPrefix + index,
+ excludedModule.getOrganisation() + EXTRA_INFO_DELIMITER
+ + excludedModule.getName());
index += 1;
}
}
// dependency management info is also used for version mediation of transitive dependencies
ivyModuleDescriptor.addDependencyDescriptorMediator(
- ModuleId.newInstance(dep.getGroupId(), dep.getArtifactId()),
+ ModuleId.newInstance(dep.getGroupId(), dep.getArtifactId()),
ExactPatternMatcher.INSTANCE,
new OverrideDependencyDescriptorMediator(null, dep.getVersion()));
}
-
+
public void addPlugin(PomDependencyMgt plugin) {
- String pluginValue = plugin.getGroupId() + EXTRA_INFO_DELIMITER + plugin.getArtifactId()
+ String pluginValue = plugin.getGroupId() + EXTRA_INFO_DELIMITER + plugin.getArtifactId()
+ EXTRA_INFO_DELIMITER + plugin.getVersion();
String pluginExtraInfo = (String) ivyModuleDescriptor.getExtraInfo().get("m:maven.plugins");
if (pluginExtraInfo == null) {
@@ -406,8 +404,8 @@ public class PomModuleDescriptorBuilder
}
ivyModuleDescriptor.getExtraInfo().put("m:maven.plugins", pluginExtraInfo);
}
-
- public static List /*<PomDependencyMgt>*/ getPlugins(ModuleDescriptor md) {
+
+ public static List /* <PomDependencyMgt> */getPlugins(ModuleDescriptor md) {
List result = new ArrayList();
String plugins = (String) md.getExtraInfo().get("m:maven.plugins");
if (plugins == null) {
@@ -418,21 +416,23 @@ public class PomModuleDescriptorBuilder
String[] parts = pluginsArray[i].split(EXTRA_INFO_DELIMITER);
result.add(new PomPluginElement(parts[0], parts[1], parts[2]));
}
-
+
return result;
}
-
+
private static class PomPluginElement implements PomDependencyMgt {
private String groupId;
+
private String artifactId;
+
private String version;
-
+
public PomPluginElement(String groupId, String artifactId, String version) {
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
}
-
+
public String getGroupId() {
return groupId;
}
@@ -444,12 +444,12 @@ public class PomModuleDescriptorBuilder
public String getVersion() {
return version;
}
-
+
public String getScope() {
return null;
}
- public List /*<ModuleId>*/ getExcludedModules() {
+ public List /* <ModuleId> */getExcludedModules() {
return Collections.EMPTY_LIST; // probably not used?
}
}
@@ -480,31 +480,28 @@ public class PomModuleDescriptorBuilder
return result;
}
- private static String getDependencyMgtExtraInfoKeyForVersion(
- String groupId, String artifaceId) {
- return DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + groupId
- + EXTRA_INFO_DELIMITER + artifaceId + EXTRA_INFO_DELIMITER + "version";
+ private static String getDependencyMgtExtraInfoKeyForVersion(String groupId, String artifaceId) {
+ return DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + groupId + EXTRA_INFO_DELIMITER
+ + artifaceId + EXTRA_INFO_DELIMITER + "version";
}
-
+
private static String getDependencyMgtExtraInfoKeyForScope(String groupId, String artifaceId) {
- return DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + groupId
- + EXTRA_INFO_DELIMITER + artifaceId + EXTRA_INFO_DELIMITER + "scope";
+ return DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + groupId + EXTRA_INFO_DELIMITER
+ + artifaceId + EXTRA_INFO_DELIMITER + "scope";
}
-
+
private static String getPropertyExtraInfoKey(String propertyName) {
return PROPERTIES + EXTRA_INFO_DELIMITER + propertyName;
}
- private static String getDependencyMgtExtraInfoPrefixForExclusion(
- String groupId, String artifaceId) {
- return DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + groupId
- + EXTRA_INFO_DELIMITER + artifaceId + EXTRA_INFO_DELIMITER + "exclusion_";
+ private static String getDependencyMgtExtraInfoPrefixForExclusion(String groupId,
+ String artifaceId) {
+ return DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + groupId + EXTRA_INFO_DELIMITER
+ + artifaceId + EXTRA_INFO_DELIMITER + "exclusion_";
}
- private static List /*<ModuleId>*/ getDependencyMgtExclusions(
- ModuleDescriptor descriptor,
- String groupId,
- String artifactId) {
+ private static List /* <ModuleId> */getDependencyMgtExclusions(ModuleDescriptor descriptor,
+ String groupId, String artifactId) {
if (descriptor instanceof PomModuleDescriptor) {
PomDependencyMgt dependencyMgt = (PomDependencyMgt) ((PomModuleDescriptor) descriptor)
.getDependencyManagementMap().get(ModuleId.newInstance(groupId, artifactId));
@@ -512,12 +509,11 @@ public class PomModuleDescriptorBuilder
return dependencyMgt.getExcludedModules();
}
}
- String exclusionPrefix = getDependencyMgtExtraInfoPrefixForExclusion(
- groupId, artifactId);
- List /*<ModuleId>*/ exclusionIds = new LinkedList /*<ModuleId>*/ ();
- Map /*<String,String>*/ extras = descriptor.getExtraInfo();
+ String exclusionPrefix = getDependencyMgtExtraInfoPrefixForExclusion(groupId, artifactId);
+ List /* <ModuleId> */exclusionIds = new LinkedList /* <ModuleId> */();
+ Map /* <String,String> */extras = descriptor.getExtraInfo();
for (final Iterator entIter = extras.entrySet().iterator(); entIter.hasNext();) {
- Map.Entry /*<String,String>*/ ent = (Map.Entry) entIter.next();
+ Map.Entry /* <String,String> */ent = (Map.Entry) entIter.next();
String key = (String) ent.getKey();
if (key.startsWith(exclusionPrefix)) {
String fullExclusion = (String) ent.getValue();
@@ -533,11 +529,12 @@ public class PomModuleDescriptorBuilder
return exclusionIds;
}
- public static Map/*<ModuleId, String version>*/
- getDependencyManagementMap(ModuleDescriptor md) {
+ public static Map/* <ModuleId, String version> */
+ getDependencyManagementMap(ModuleDescriptor md) {
Map ret = new LinkedHashMap();
if (md instanceof PomModuleDescriptor) {
- for (final Iterator iterator = ((PomModuleDescriptor) md).getDependencyManagementMap().entrySet().iterator(); iterator.hasNext();) {
+ for (final Iterator iterator = ((PomModuleDescriptor) md).getDependencyManagementMap()
+ .entrySet().iterator(); iterator.hasNext();) {
Map.Entry e = (Entry) iterator.next();
PomDependencyMgt dependencyMgt = (PomDependencyMgt) e.getValue();
ret.put(e.getKey(), dependencyMgt.getVersion());
@@ -550,7 +547,7 @@ public class PomModuleDescriptorBuilder
String[] parts = key.split(EXTRA_INFO_DELIMITER);
if (parts.length != DEPENDENCY_MANAGEMENT_KEY_PARTS_COUNT) {
Message.warn("what seem to be a dependency management extra info "
- + "doesn't match expected pattern: " + key);
+ + "doesn't match expected pattern: " + key);
} else {
ret.put(ModuleId.newInstance(parts[1], parts[2]), entry.getValue());
}
@@ -559,10 +556,10 @@ public class PomModuleDescriptorBuilder
}
return ret;
}
-
+
public static List getDependencyManagements(ModuleDescriptor md) {
List result = new ArrayList();
-
+
if (md instanceof PomModuleDescriptor) {
result.addAll(((PomModuleDescriptor) md).getDependencyManagementMap().values());
} else {
@@ -573,20 +570,21 @@ public class PomModuleDescriptorBuilder
String[] parts = key.split(EXTRA_INFO_DELIMITER);
if (parts.length != DEPENDENCY_MANAGEMENT_KEY_PARTS_COUNT) {
Message.warn("what seem to be a dependency management extra info "
- + "doesn't match expected pattern: " + key);
+ + "doesn't match expected pattern: " + key);
} else {
- String versionKey = DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + parts[1]
- + EXTRA_INFO_DELIMITER + parts[2]
- + EXTRA_INFO_DELIMITER + "version";
- String scopeKey = DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + parts[1]
- + EXTRA_INFO_DELIMITER + parts[2]
- + EXTRA_INFO_DELIMITER + "scope";
-
+ String versionKey = DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + parts[1]
+ + EXTRA_INFO_DELIMITER + parts[2] + EXTRA_INFO_DELIMITER
+ + "version";
+ String scopeKey = DEPENDENCY_MANAGEMENT + EXTRA_INFO_DELIMITER + parts[1]
+ + EXTRA_INFO_DELIMITER + parts[2] + EXTRA_INFO_DELIMITER + "scope";
+
String version = (String) md.getExtraInfo().get(versionKey);
String scope = (String) md.getExtraInfo().get(scopeKey);
-
- List /*<ModuleId>*/ exclusions = getDependencyMgtExclusions(md, parts[1], parts[2]);
- result.add(new DefaultPomDependencyMgt(parts[1], parts[2], version, scope, exclusions));
+
+ List /* <ModuleId> */exclusions = getDependencyMgtExclusions(md, parts[1],
+ parts[2]);
+ result.add(new DefaultPomDependencyMgt(parts[1], parts[2], version, scope,
+ exclusions));
}
}
}
@@ -594,7 +592,6 @@ public class PomModuleDescriptorBuilder
return result;
}
-
public void addExtraInfos(Map extraAttributes) {
for (Iterator it = extraAttributes.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Entry) it.next();
@@ -604,15 +601,12 @@ public class PomModuleDescriptorBuilder
}
}
-
private void addExtraInfo(String key, String value) {
if (!ivyModuleDescriptor.getExtraInfo().containsKey(key)) {
ivyModuleDescriptor.addExtraInfo(key, value);
}
}
-
-
public static Map extractPomProperties(Map extraInfo) {
Map r = new HashMap();
for (Iterator it = extraInfo.entrySet().iterator(); it.hasNext();) {
@@ -626,7 +620,6 @@ public class PomModuleDescriptorBuilder
return r;
}
-
public void addProperty(String propertyName, String value) {
addExtraInfo(getPropertyExtraInfoKey(propertyName), value);
}
@@ -636,27 +629,24 @@ public class PomModuleDescriptorBuilder
}
public Artifact getSourceArtifact() {
- return new MDArtifact(
- ivyModuleDescriptor, mrid.getName(), "source", "jar",
- null, Collections.singletonMap("m:classifier", "sources"));
+ return new MDArtifact(ivyModuleDescriptor, mrid.getName(), "source", "jar", null,
+ Collections.singletonMap("m:classifier", "sources"));
}
public Artifact getSrcArtifact() {
- return new MDArtifact(
- ivyModuleDescriptor, mrid.getName(), "source", "jar",
- null, Collections.singletonMap("m:classifier", "src"));
+ return new MDArtifact(ivyModuleDescriptor, mrid.getName(), "source", "jar", null,
+ Collections.singletonMap("m:classifier", "src"));
}
public Artifact getJavadocArtifact() {
- return new MDArtifact(
- ivyModuleDescriptor, mrid.getName(), "javadoc", "jar",
- null, Collections.singletonMap("m:classifier", "javadoc"));
+ return new MDArtifact(ivyModuleDescriptor, mrid.getName(), "javadoc", "jar", null,
+ Collections.singletonMap("m:classifier", "javadoc"));
}
public void addSourceArtifact() {
ivyModuleDescriptor.addArtifact("sources", getSourceArtifact());
}
-
+
public void addSrcArtifact() {
ivyModuleDescriptor.addArtifact("sources", getSrcArtifact());
}
@@ -666,7 +656,8 @@ public class PomModuleDescriptorBuilder
}
/**
- * <code>DependencyDescriptor</code> that provides access to the original <code>PomDependencyData</code>.
+ * <code>DependencyDescriptor</code> that provides access to the original
+ * <code>PomDependencyData</code>.
*/
public static class PomDependencyDescriptor extends DefaultDependencyDescriptor {
private final PomDependencyData pomDependencyData;
@@ -679,6 +670,7 @@ public class PomModuleDescriptorBuilder
/**
* Get PomDependencyData.
+ *
* @return PomDependencyData
*/
public PomDependencyData getPomDependencyData() {
@@ -687,14 +679,16 @@ public class PomModuleDescriptorBuilder
}
public static class PomModuleDescriptor extends DefaultModuleDescriptor {
- private final Map/*<ModuleId, PomDependencyMgt>*/ dependencyManagementMap = new HashMap();
+ private final Map/* <ModuleId, PomDependencyMgt> */dependencyManagementMap = new HashMap();
public PomModuleDescriptor(ModuleDescriptorParser parser, Resource res) {
super(parser, res);
}
public void addDependencyManagement(PomDependencyMgt dependencyMgt) {
- dependencyManagementMap.put(ModuleId.newInstance(dependencyMgt.getGroupId(), dependencyMgt.getArtifactId()), dependencyMgt);
+ dependencyManagementMap.put(
+ ModuleId.newInstance(dependencyMgt.getGroupId(), dependencyMgt.getArtifactId()),
+ dependencyMgt);
}
public Map getDependencyManagementMap() {
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java?rev=1557968&r1=1557967&r2=1557968&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorParser.java Tue Jan 14 08:27:37 2014
@@ -59,14 +59,12 @@ import org.xml.sax.SAXException;
* <p>
* The configurations used in the generated module descriptor mimics the behavior defined by maven 2
* scopes, as documented here:<br/>
- * http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
- * The PomModuleDescriptorParser use a PomDomReader to read the pom, and the
- * PomModuleDescriptorBuilder to write the ivy module descriptor using the info read by the
- * PomDomReader.
+ * http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html The
+ * PomModuleDescriptorParser use a PomDomReader to read the pom, and the PomModuleDescriptorBuilder
+ * to write the ivy module descriptor using the info read by the PomDomReader.
*/
public final class PomModuleDescriptorParser implements ModuleDescriptorParser {
-
private static final PomModuleDescriptorParser INSTANCE = new PomModuleDescriptorParser();
public static PomModuleDescriptorParser getInstance() {
@@ -76,7 +74,6 @@ public final class PomModuleDescriptorPa
private PomModuleDescriptorParser() {
}
-
public void toIvyFile(InputStream is, Resource res, File destFile, ModuleDescriptor md)
throws ParseException, IOException {
try {
@@ -100,25 +97,25 @@ public final class PomModuleDescriptorPa
public Artifact getMetadataArtifact(ModuleRevisionId mrid, Resource res) {
return DefaultArtifact.newPomArtifact(mrid, new Date(res.getLastModified()));
}
-
+
public String getType() {
return "pom";
}
- public ModuleDescriptor parseDescriptor(ParserSettings ivySettings, URL descriptorURL,
- boolean validate) throws ParseException, IOException {
+ public ModuleDescriptor parseDescriptor(ParserSettings ivySettings, URL descriptorURL,
+ boolean validate) throws ParseException, IOException {
URLResource resource = new URLResource(descriptorURL);
return parseDescriptor(ivySettings, descriptorURL, resource, validate);
}
- public ModuleDescriptor parseDescriptor(ParserSettings ivySettings, URL descriptorURL,
+ public ModuleDescriptor parseDescriptor(ParserSettings ivySettings, URL descriptorURL,
Resource res, boolean validate) throws ParseException, IOException {
-
- PomModuleDescriptorBuilder mdBuilder = new PomModuleDescriptorBuilder(
- this, res, ivySettings);
-
- try {
- PomReader domReader = new PomReader(descriptorURL, res);
+
+ PomModuleDescriptorBuilder mdBuilder = new PomModuleDescriptorBuilder(this, res,
+ ivySettings);
+
+ try {
+ PomReader domReader = new PomReader(descriptorURL, res);
domReader.setProperty("parent.version", domReader.getParentVersion());
domReader.setProperty("parent.groupId", domReader.getParentGroupId());
domReader.setProperty("project.parent.version", domReader.getParentVersion());
@@ -130,44 +127,42 @@ public final class PomModuleDescriptorPa
domReader.setProperty((String) prop.getKey(), (String) prop.getValue());
mdBuilder.addProperty((String) prop.getKey(), (String) prop.getValue());
}
-
+
ModuleDescriptor parentDescr = null;
if (domReader.hasParent()) {
- //Is there any other parent properties?
-
+ // Is there any other parent properties?
+
ModuleRevisionId parentModRevID = ModuleRevisionId.newInstance(
- domReader.getParentGroupId(),
- domReader.getParentArtifactId(),
+ domReader.getParentGroupId(), domReader.getParentArtifactId(),
domReader.getParentVersion());
- ResolvedModuleRevision parentModule = parseOtherPom(ivySettings,
- parentModRevID);
+ ResolvedModuleRevision parentModule = parseOtherPom(ivySettings, parentModRevID);
if (parentModule != null) {
parentDescr = parentModule.getDescriptor();
} else {
throw new IOException("Impossible to load parent for " + res.getName() + "."
- + " Parent=" + parentModRevID);
+ + " Parent=" + parentModRevID);
}
if (parentDescr != null) {
- Map parentPomProps = PomModuleDescriptorBuilder.extractPomProperties(
- parentDescr.getExtraInfo());
+ Map parentPomProps = PomModuleDescriptorBuilder
+ .extractPomProperties(parentDescr.getExtraInfo());
for (Iterator iter = parentPomProps.entrySet().iterator(); iter.hasNext();) {
Map.Entry prop = (Map.Entry) iter.next();
domReader.setProperty((String) prop.getKey(), (String) prop.getValue());
- }
+ }
}
}
-
+
String groupId = domReader.getGroupId();
String artifactId = domReader.getArtifactId();
String version = domReader.getVersion();
- mdBuilder.setModuleRevId(groupId , artifactId , version);
-
+ mdBuilder.setModuleRevId(groupId, artifactId, version);
+
mdBuilder.setHomePage(domReader.getHomePage());
mdBuilder.setDescription(domReader.getDescription());
mdBuilder.setLicenses(domReader.getLicenses());
ModuleRevisionId relocation = domReader.getRelocation();
-
+
if (relocation != null) {
if (groupId != null && artifactId != null
&& artifactId.equals(relocation.getName())
@@ -180,10 +175,10 @@ public final class PomModuleDescriptorPa
+ " Artefact and other metadata will be ignored.");
ResolvedModuleRevision relocatedModule = parseOtherPom(ivySettings, relocation);
if (relocatedModule == null) {
- throw new ParseException("impossible to load module "
- + relocation + " to which "
- + mdBuilder.getModuleDescriptor().getModuleRevisionId()
- + " has been relocated", 0);
+ throw new ParseException("impossible to load module " + relocation
+ + " to which "
+ + mdBuilder.getModuleDescriptor().getModuleRevisionId()
+ + " has been relocated", 0);
}
DependencyDescriptor[] dds = relocatedModule.getDescriptor().getDependencies();
for (int i = 0; i < dds.length; i++) {
@@ -194,18 +189,19 @@ public final class PomModuleDescriptorPa
+ " is relocated to " + relocation
+ ". Please update your dependencies.");
Message.verbose("Relocated module will be considered as a dependency");
- DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mdBuilder
- .getModuleDescriptor(), relocation, true, false, true);
+ DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(
+ mdBuilder.getModuleDescriptor(), relocation, true, false, true);
/* Map all public dependencies */
Configuration[] m2Confs = PomModuleDescriptorBuilder.MAVEN2_CONFIGURATIONS;
for (int i = 0; i < m2Confs.length; i++) {
if (Visibility.PUBLIC.equals(m2Confs[i].getVisibility())) {
- dd.addDependencyConfiguration(m2Confs[i].getName(), m2Confs[i].getName());
+ dd.addDependencyConfiguration(m2Confs[i].getName(),
+ m2Confs[i].getName());
}
}
mdBuilder.addDependency(dd);
}
- } else {
+ } else {
domReader.setProperty("project.groupId", groupId);
domReader.setProperty("pom.groupId", groupId);
domReader.setProperty("groupId", groupId);
@@ -218,58 +214,57 @@ public final class PomModuleDescriptorPa
if (parentDescr != null) {
mdBuilder.addExtraInfos(parentDescr.getExtraInfo());
-
+
// add dependency management info from parent
List depMgt = PomModuleDescriptorBuilder.getDependencyManagements(parentDescr);
for (Iterator it = depMgt.iterator(); it.hasNext();) {
PomDependencyMgt dep = (PomDependencyMgt) it.next();
if (dep instanceof PomDependencyMgtElement) {
- dep = domReader.new PomDependencyMgtElement((PomDependencyMgtElement) dep);
+ dep = domReader.new PomDependencyMgtElement(
+ (PomDependencyMgtElement) dep);
}
mdBuilder.addDependencyMgt(dep);
}
-
+
// add plugins from parent
- List /*<PomDependencyMgt>*/ plugins =
- PomModuleDescriptorBuilder.getPlugins(parentDescr);
+ List /* <PomDependencyMgt> */plugins = PomModuleDescriptorBuilder
+ .getPlugins(parentDescr);
for (Iterator it = plugins.iterator(); it.hasNext();) {
mdBuilder.addPlugin((PomDependencyMgt) it.next());
}
}
-
+
for (Iterator it = domReader.getDependencyMgt().iterator(); it.hasNext();) {
PomDependencyMgt dep = (PomDependencyMgt) it.next();
if ("import".equals(dep.getScope())) {
ModuleRevisionId importModRevID = ModuleRevisionId.newInstance(
- dep.getGroupId(),
- dep.getArtifactId(),
- dep.getVersion());
- ResolvedModuleRevision importModule = parseOtherPom(ivySettings,
+ dep.getGroupId(), dep.getArtifactId(), dep.getVersion());
+ ResolvedModuleRevision importModule = parseOtherPom(ivySettings,
importModRevID);
if (importModule != null) {
ModuleDescriptor importDescr = importModule.getDescriptor();
-
+
// add dependency management info from imported module
- List depMgt = PomModuleDescriptorBuilder.getDependencyManagements(importDescr);
+ List depMgt = PomModuleDescriptorBuilder
+ .getDependencyManagements(importDescr);
for (Iterator it2 = depMgt.iterator(); it2.hasNext();) {
PomDependencyMgt importedDepMgt = (PomDependencyMgt) it2.next();
mdBuilder.addDependencyMgt(new DefaultPomDependencyMgt(
importedDepMgt.getGroupId(),
importedDepMgt.getArtifactId(),
- importedDepMgt.getVersion(),
- importedDepMgt.getScope(),
+ importedDepMgt.getVersion(), importedDepMgt.getScope(),
importedDepMgt.getExcludedModules()));
}
} else {
- throw new IOException("Impossible to import module for " + res.getName() + "."
- + " Import=" + importModRevID);
+ throw new IOException("Impossible to import module for "
+ + res.getName() + "." + " Import=" + importModRevID);
}
-
+
} else {
mdBuilder.addDependencyMgt(dep);
}
}
-
+
for (Iterator it = domReader.getDependencies().iterator(); it.hasNext();) {
PomReader.PomDependencyData dep = (PomReader.PomDependencyData) it.next();
mdBuilder.addDependency(res, dep);
@@ -279,7 +274,8 @@ public final class PomModuleDescriptorPa
for (int i = 0; i < parentDescr.getDependencies().length; i++) {
DependencyDescriptor descriptor = parentDescr.getDependencies()[i];
if (descriptor instanceof PomDependencyDescriptor) {
- PomDependencyData parentDep = ((PomDependencyDescriptor) descriptor).getPomDependencyData();
+ PomDependencyData parentDep = ((PomDependencyDescriptor) descriptor)
+ .getPomDependencyData();
PomDependencyData dep = domReader.new PomDependencyData(parentDep);
mdBuilder.addDependency(res, dep);
} else {
@@ -287,40 +283,39 @@ public final class PomModuleDescriptorPa
}
}
}
-
+
for (Iterator it = domReader.getPlugins().iterator(); it.hasNext();) {
PomReader.PomPluginElement plugin = (PomReader.PomPluginElement) it.next();
mdBuilder.addPlugin(plugin);
}
-
- mdBuilder.addMainArtifact(artifactId , domReader.getPackaging());
-
+
+ mdBuilder.addMainArtifact(artifactId, domReader.getPackaging());
+
addSourcesAndJavadocArtifactsIfPresent(mdBuilder, ivySettings);
- }
+ }
} catch (SAXException e) {
throw newParserException(e);
}
-
+
return mdBuilder.getModuleDescriptor();
}
- private void addSourcesAndJavadocArtifactsIfPresent(
- PomModuleDescriptorBuilder mdBuilder, ParserSettings ivySettings) {
+ private void addSourcesAndJavadocArtifactsIfPresent(PomModuleDescriptorBuilder mdBuilder,
+ ParserSettings ivySettings) {
if (mdBuilder.getMainArtifact() == null) {
// no main artifact in pom, we don't need to search for meta artifacts
return;
}
ModuleDescriptor md = mdBuilder.getModuleDescriptor();
ModuleRevisionId mrid = md.getModuleRevisionId();
- DependencyResolver resolver = ivySettings.getResolver(
- mrid);
-
+ DependencyResolver resolver = ivySettings.getResolver(mrid);
+
if (resolver == null) {
- Message.debug("no resolver found for " + mrid
- + ": no source or javadoc artifact lookup");
+ Message.debug("no resolver found for " + mrid
+ + ": no source or javadoc artifact lookup");
} else {
ArtifactOrigin mainArtifact = resolver.locate(mdBuilder.getMainArtifact());
-
+
if (!ArtifactOrigin.isUnknown(mainArtifact)) {
String mainArtifactLocation = mainArtifact.getLocation();
@@ -342,7 +337,7 @@ public final class PomModuleDescriptorPa
}
}
ArtifactOrigin javadocArtifact = resolver.locate(mdBuilder.getJavadocArtifact());
- if (!ArtifactOrigin.isUnknown(javadocArtifact)
+ if (!ArtifactOrigin.isUnknown(javadocArtifact)
&& !javadocArtifact.getLocation().equals(mainArtifactLocation)) {
Message.debug("javadoc artifact found for " + mrid);
mdBuilder.addJavadocArtifact();
@@ -363,7 +358,7 @@ public final class PomModuleDescriptorPa
options.setDownload(false);
data = new ResolveData(engine, options);
}
-
+
DependencyResolver resolver = ivySettings.getResolver(parentModRevID);
if (resolver == null) {
// TODO: Throw exception here?
@@ -377,7 +372,7 @@ public final class PomModuleDescriptorPa
private ParseException newParserException(Exception e) {
Message.error(e.getMessage());
- ParseException pe = new ParseException(e.getMessage() , 0);
+ ParseException pe = new ParseException(e.getMessage(), 0);
pe.initCause(e);
return pe;
}
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java?rev=1557968&r1=1557967&r2=1557968&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomModuleDescriptorWriter.java Tue Jan 14 08:27:37 2014
@@ -47,11 +47,11 @@ import org.apache.ivy.plugins.parser.m2.
import org.apache.ivy.util.ConfigurationUtils;
public final class PomModuleDescriptorWriter {
-
+
private static final String SKIP_LINE = "SKIP_LINE";
-
- private static final ConfigurationScopeMapping DEFAULT_MAPPING
- = new ConfigurationScopeMapping(new HashMap() {
+
+ private static final ConfigurationScopeMapping DEFAULT_MAPPING = new ConfigurationScopeMapping(
+ new HashMap() {
{
put("compile", "compile");
put("runtime", "runtime");
@@ -61,27 +61,30 @@ public final class PomModuleDescriptorWr
}
});
-
private PomModuleDescriptorWriter() {
}
-
+
public static void write(ModuleDescriptor md, File output, PomWriterOptions options)
throws IOException {
LineNumberReader in;
if (options.getTemplate() == null) {
- in = new LineNumberReader(new InputStreamReader(PomModuleDescriptorWriter.class.getResourceAsStream("pom.template")));
+ in = new LineNumberReader(new InputStreamReader(
+ PomModuleDescriptorWriter.class.getResourceAsStream("pom.template")));
} else {
- in = new LineNumberReader(new InputStreamReader(new FileInputStream(options.getTemplate())));
+ in = new LineNumberReader(new InputStreamReader(new FileInputStream(
+ options.getTemplate())));
}
-
+
if (output.getParentFile() != null) {
output.getParentFile().mkdirs();
}
- PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF-8"));
+ PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output),
+ "UTF-8"));
try {
IvySettings settings = IvyContext.getContext().getSettings();
- IvyVariableContainer variables = new IvyVariableContainerWrapper(settings.getVariableContainer());
-
+ IvyVariableContainer variables = new IvyVariableContainerWrapper(
+ settings.getVariableContainer());
+
variables.setVariable("ivy.pom.license", SKIP_LINE, true);
variables.setVariable("ivy.pom.header", SKIP_LINE, true);
variables.setVariable("ivy.pom.groupId", SKIP_LINE, true);
@@ -91,24 +94,21 @@ public final class PomModuleDescriptorWr
variables.setVariable("ivy.pom.name", SKIP_LINE, true);
variables.setVariable("ivy.pom.description", SKIP_LINE, true);
variables.setVariable("ivy.pom.url", SKIP_LINE, true);
-
+
if (options.getLicenseHeader() != null) {
variables.setVariable("ivy.pom.license", options.getLicenseHeader(), true);
}
if (options.isPrintIvyInfo()) {
- String header = "<!--\n"
- + " Apache Maven 2 POM generated by Apache Ivy\n"
- + " " + Ivy.getIvyHomeURL() + "\n"
- + " Apache Ivy version: " + Ivy.getIvyVersion()
- + " " + Ivy.getIvyDate() + "\n"
- + "-->";
+ String header = "<!--\n" + " Apache Maven 2 POM generated by Apache Ivy\n"
+ + " " + Ivy.getIvyHomeURL() + "\n" + " Apache Ivy version: "
+ + Ivy.getIvyVersion() + " " + Ivy.getIvyDate() + "\n" + "-->";
variables.setVariable("ivy.pom.header", header, true);
}
-
+
setModuleVariables(md, variables, options);
-
+
boolean dependenciesPrinted = false;
-
+
int lastIndent = 0;
int indent = 0;
String line = in.readLine();
@@ -119,22 +119,22 @@ public final class PomModuleDescriptorWr
line = in.readLine();
continue;
}
-
+
if (line.trim().length() == 0) {
// empty line
out.println(line);
line = in.readLine();
continue;
}
-
+
lastIndent = indent;
indent = line.indexOf('<');
-
+
if (!dependenciesPrinted && line.indexOf("</dependencies>") != -1) {
printDependencies(md, out, options, indent, false);
dependenciesPrinted = true;
}
-
+
if (!dependenciesPrinted && line.indexOf("</project>") != -1) {
printDependencies(md, out, options, lastIndent, true);
dependenciesPrinted = true;
@@ -149,15 +149,16 @@ public final class PomModuleDescriptorWr
}
}
- private static void setModuleVariables(ModuleDescriptor md, IvyVariableContainer variables, PomWriterOptions options) {
+ private static void setModuleVariables(ModuleDescriptor md, IvyVariableContainer variables,
+ PomWriterOptions options) {
ModuleRevisionId mrid = md.getModuleRevisionId();
variables.setVariable("ivy.pom.groupId", mrid.getOrganisation(), true);
-
+
String artifactId = options.getArtifactName();
if (artifactId == null) {
artifactId = mrid.getName();
}
-
+
String packaging = options.getArtifactPackaging();
if (packaging == null) {
// find artifact to determine the packaging
@@ -169,7 +170,7 @@ public final class PomModuleDescriptorWr
packaging = artifact.getType();
}
}
-
+
variables.setVariable("ivy.pom.artifactId", artifactId, true);
variables.setVariable("ivy.pom.packaging", packaging, true);
if (mrid.getRevision() != null) {
@@ -182,7 +183,7 @@ public final class PomModuleDescriptorWr
variables.setVariable("ivy.pom.url", md.getHomePage(), true);
}
}
-
+
/**
* Returns the first artifact with the correct name and without a classifier.
*/
@@ -194,17 +195,17 @@ public final class PomModuleDescriptorWr
return artifacts[i];
}
}
-
+
return null;
}
-
+
private static void indent(PrintWriter out, int indent) {
for (int i = 0; i < indent; i++) {
out.print(' ');
}
}
- private static void printDependencies(ModuleDescriptor md, PrintWriter out,
+ private static void printDependencies(ModuleDescriptor md, PrintWriter out,
PomWriterOptions options, int indent, boolean printDependencies) {
List extraDeps = options.getExtraDependencies();
DependencyDescriptor[] dds = getDependencies(md, options);
@@ -214,9 +215,9 @@ public final class PomModuleDescriptorWr
indent(out, indent);
out.println("<dependencies>");
}
-
+
// print the extra dependencies first
- for (Iterator it = extraDeps.iterator(); it.hasNext(); ) {
+ for (Iterator it = extraDeps.iterator(); it.hasNext();) {
PomWriterOptions.ExtraDependency dep = (ExtraDependency) it.next();
String groupId = dep.getGroup();
if (groupId == null) {
@@ -226,50 +227,49 @@ public final class PomModuleDescriptorWr
if (version == null) {
version = md.getModuleRevisionId().getRevision();
}
- printDependency(out, indent, groupId, dep.getArtifact(), version, dep.getType(),
- dep.getClassifier(), dep.getScope(), dep.isOptional(), null);
+ printDependency(out, indent, groupId, dep.getArtifact(), version, dep.getType(),
+ dep.getClassifier(), dep.getScope(), dep.isOptional(), null);
}
-
+
// now print the dependencies listed in the ModuleDescriptor
ConfigurationScopeMapping mapping = options.getMapping();
if (mapping == null) {
mapping = DEFAULT_MAPPING;
}
-
+
for (int i = 0; i < dds.length; i++) {
ModuleRevisionId mrid = dds[i].getDependencyRevisionId();
ExcludeRule[] excludes = null;
- if(dds[i].canExclude()){
+ if (dds[i].canExclude()) {
excludes = dds[i].getAllExcludeRules();
}
DependencyArtifactDescriptor[] dads = dds[i].getAllDependencyArtifacts();
- if(dads.length > 0) {
+ if (dads.length > 0) {
for (int j = 0; j < dads.length; j++) {
String type = dads[j].getType();
String classifier = dads[j].getExtraAttribute("classifier");
String scope = mapping.getScope(dds[i].getModuleConfigurations());
boolean optional = mapping.isOptional(dds[i].getModuleConfigurations());
- printDependency(out, indent, mrid.getOrganisation(), mrid.getName(),
- mrid.getRevision(), type, classifier, scope, optional, excludes);
+ printDependency(out, indent, mrid.getOrganisation(), mrid.getName(),
+ mrid.getRevision(), type, classifier, scope, optional, excludes);
}
- }
- else {
+ } else {
String scope = mapping.getScope(dds[i].getModuleConfigurations());
boolean optional = mapping.isOptional(dds[i].getModuleConfigurations());
- printDependency(out, indent, mrid.getOrganisation(), mrid.getName(),
- mrid.getRevision(), null, null, scope, optional, excludes);
+ printDependency(out, indent, mrid.getOrganisation(), mrid.getName(),
+ mrid.getRevision(), null, null, scope, optional, excludes);
}
}
-
+
if (printDependencies) {
indent(out, indent);
out.println("</dependencies>");
}
}
}
-
- private static void printDependency(PrintWriter out, int indent, String groupId,
- String artifactId, String version, String type, String classifier, String scope,
+
+ private static void printDependency(PrintWriter out, int indent, String groupId,
+ String artifactId, String version, String type, String classifier, String scope,
boolean isOptional, ExcludeRule[] excludes) {
indent(out, indent * 2);
out.println("<dependency>");
@@ -296,17 +296,17 @@ public final class PomModuleDescriptorWr
out.println("<optional>true</optional>");
}
if (excludes != null) {
- printExclusions(excludes, out, indent);
+ printExclusions(excludes, out, indent);
}
indent(out, indent * 2);
out.println("</dependency>");
}
-
+
private static void printExclusions(ExcludeRule[] exclusions, PrintWriter out, int indent) {
indent(out, indent * 3);
- out.println("<exclusions>");
-
- for(int i = 0; i < exclusions.length; i++ ){
+ out.println("<exclusions>");
+
+ for (int i = 0; i < exclusions.length; i++) {
indent(out, indent * 4);
out.println("<exclusion>");
ExcludeRule rule = exclusions[i];
@@ -315,14 +315,14 @@ public final class PomModuleDescriptorWr
indent(out, indent * 5);
out.println("<artifactId>" + rule.getId().getModuleId().getName() + "</artifactId>");
indent(out, indent * 4);
- out.println("</exclusion>");
+ out.println("</exclusion>");
}
-
+
indent(out, indent * 3);
- out.println("</exclusions>");
+ out.println("</exclusions>");
}
-
- private static DependencyDescriptor[] getDependencies(ModuleDescriptor md,
+
+ private static DependencyDescriptor[] getDependencies(ModuleDescriptor md,
PomWriterOptions options) {
String[] confs = ConfigurationUtils.replaceWildcards(options.getConfs(), md);
@@ -334,17 +334,17 @@ public final class PomModuleDescriptorWr
result.add(dds[i]);
}
}
-
+
return (DependencyDescriptor[]) result.toArray(new DependencyDescriptor[result.size()]);
}
-
+
/**
* Wraps an {@link IvyVariableContainer} delegating most method calls to the wrapped instance,
* except for a set of variables which are only stored locally in the wrapper, and not
* propagated to the wrapped instance.
*/
private static final class IvyVariableContainerWrapper implements IvyVariableContainer {
-
+
private final IvyVariableContainer variables;
private Map localVariables = new HashMap();
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java?rev=1557968&r1=1557967&r2=1557968&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/m2/PomReader.java Tue Jan 14 08:27:37 2014
@@ -49,65 +49,93 @@ import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
/**
- * Provides the method to read some data out of the DOM tree of a pom
- * file.
+ * Provides the method to read some data out of the DOM tree of a pom file.
*/
public class PomReader {
-
+
private static final String PACKAGING = "packaging";
+
private static final String DEPENDENCY = "dependency";
+
private static final String DEPENDENCIES = "dependencies";
+
private static final String DEPENDENCY_MGT = "dependencyManagement";
+
private static final String PROJECT = "project";
+
private static final String MODEL = "model";
+
private static final String GROUP_ID = "groupId";
+
private static final String ARTIFACT_ID = "artifactId";
+
private static final String VERSION = "version";
+
private static final String DESCRIPTION = "description";
+
private static final String HOMEPAGE = "url";
+
private static final String LICENSES = "licenses";
+
private static final String LICENSE = "license";
+
private static final String LICENSE_NAME = "name";
+
private static final String LICENSE_URL = "url";
+
private static final String PARENT = "parent";
+
private static final String SCOPE = "scope";
+
private static final String CLASSIFIER = "classifier";
+
private static final String OPTIONAL = "optional";
+
private static final String EXCLUSIONS = "exclusions";
+
private static final String EXCLUSION = "exclusion";
+
private static final String DISTRIBUTION_MGT = "distributionManagement";
+
private static final String RELOCATION = "relocation";
+
private static final String PROPERTIES = "properties";
+
private static final String PLUGINS = "plugins";
+
private static final String PLUGIN = "plugin";
+
private static final String TYPE = "type";
private HashMap properties = new HashMap();
-
+
private final Element projectElement;
+
private final Element parentElement;
-
+
public PomReader(URL descriptorURL, Resource res) throws IOException, SAXException {
- InputStream stream = new AddDTDFilterInputStream(URLHandlerRegistry.getDefault().openStream(descriptorURL));
+ InputStream stream = new AddDTDFilterInputStream(URLHandlerRegistry.getDefault()
+ .openStream(descriptorURL));
InputSource source = new InputSource(stream);
source.setSystemId(XMLHelper.toSystemId(descriptorURL));
try {
Document pomDomDoc = XMLHelper.parseToDom(source, new EntityResolver() {
- public InputSource resolveEntity(String publicId, String systemId)
- throws SAXException, IOException {
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws SAXException, IOException {
if ((systemId != null) && systemId.endsWith("m2-entities.ent")) {
- return new InputSource(
- PomReader.class.getResourceAsStream("m2-entities.ent"));
+ return new InputSource(PomReader.class
+ .getResourceAsStream("m2-entities.ent"));
}
return null;
}
});
projectElement = pomDomDoc.getDocumentElement();
- if (!PROJECT.equals(projectElement.getNodeName()) && !MODEL.equals(projectElement.getNodeName())) {
- throw new SAXParseException("project must be the root tag" , res.getName() ,
- res.getName(), 0, 0);
+ if (!PROJECT.equals(projectElement.getNodeName())
+ && !MODEL.equals(projectElement.getNodeName())) {
+ throw new SAXParseException("project must be the root tag", res.getName(),
+ res.getName(), 0, 0);
}
- parentElement = getFirstChildElement(projectElement , PARENT);
+ parentElement = getFirstChildElement(projectElement, PARENT);
} finally {
try {
stream.close();
@@ -117,15 +145,13 @@ public class PomReader {
}
}
-
public boolean hasParent() {
return parentElement != null;
}
-
+
/**
- * Add a property if not yet set and value is not null.
- * This garantee that property keep the first value that is put on it and that the properties
- * are never null.
+ * Add a property if not yet set and value is not null. This garantee that property keep the
+ * first value that is put on it and that the properties are never null.
*/
public void setProperty(String prop, String val) {
if (!properties.containsKey(prop) && val != null) {
@@ -133,28 +159,25 @@ public class PomReader {
}
}
-
public String getGroupId() {
- String groupId = getFirstChildText(projectElement , GROUP_ID);
+ String groupId = getFirstChildText(projectElement, GROUP_ID);
if (groupId == null) {
groupId = getFirstChildText(parentElement, GROUP_ID);
- }
+ }
return replaceProps(groupId);
}
public String getParentGroupId() {
- String groupId = getFirstChildText(parentElement , GROUP_ID);
+ String groupId = getFirstChildText(parentElement, GROUP_ID);
if (groupId == null) {
groupId = getFirstChildText(projectElement, GROUP_ID);
}
return replaceProps(groupId);
}
-
-
public String getArtifactId() {
- String val = getFirstChildText(projectElement , ARTIFACT_ID);
+ String val = getFirstChildText(projectElement, ARTIFACT_ID);
if (val == null) {
val = getFirstChildText(parentElement, ARTIFACT_ID);
}
@@ -162,41 +185,39 @@ public class PomReader {
}
public String getParentArtifactId() {
- String val = getFirstChildText(parentElement , ARTIFACT_ID);
+ String val = getFirstChildText(parentElement, ARTIFACT_ID);
if (val == null) {
val = getFirstChildText(projectElement, ARTIFACT_ID);
- }
+ }
return replaceProps(val);
}
-
public String getVersion() {
- String val = getFirstChildText(projectElement , VERSION);
+ String val = getFirstChildText(projectElement, VERSION);
if (val == null) {
val = getFirstChildText(parentElement, VERSION);
- }
+ }
return replaceProps(val);
}
public String getParentVersion() {
- String val = getFirstChildText(parentElement , VERSION);
+ String val = getFirstChildText(parentElement, VERSION);
if (val == null) {
val = getFirstChildText(projectElement, VERSION);
- }
+ }
return replaceProps(val);
}
-
public String getPackaging() {
- String val = getFirstChildText(projectElement , PACKAGING);
+ String val = getFirstChildText(projectElement, PACKAGING);
if (val == null) {
val = "jar";
}
return val;
}
-
+
public String getHomePage() {
- String val = getFirstChildText(projectElement , HOMEPAGE);
+ String val = getFirstChildText(projectElement, HOMEPAGE);
if (val == null) {
val = "";
}
@@ -204,7 +225,7 @@ public class PomReader {
}
public String getDescription() {
- String val = getFirstChildText(projectElement , DESCRIPTION);
+ String val = getFirstChildText(projectElement, DESCRIPTION);
if (val == null) {
val = "";
}
@@ -217,33 +238,32 @@ public class PomReader {
return new License[0];
}
licenses.normalize();
- List/*<License>*/ lics = new ArrayList();
+ List/* <License> */lics = new ArrayList();
for (Iterator it = getAllChilds(licenses).iterator(); it.hasNext();) {
Element license = (Element) it.next();
if (LICENSE.equals(license.getNodeName())) {
String name = getFirstChildText(license, LICENSE_NAME);
String url = getFirstChildText(license, LICENSE_URL);
-
+
if ((name == null) && (url == null)) {
// move to next license
continue;
}
-
+
if (name == null) {
// The license name is required in Ivy but not in a POM!
name = "Unknown License";
}
-
+
lics.add(new License(name, url));
}
}
return (License[]) lics.toArray(new License[lics.size()]);
}
-
public ModuleRevisionId getRelocation() {
Element distrMgt = getFirstChildElement(projectElement, DISTRIBUTION_MGT);
- Element relocation = getFirstChildElement(distrMgt , RELOCATION);
+ Element relocation = getFirstChildElement(distrMgt, RELOCATION);
if (relocation == null) {
return null;
} else {
@@ -256,8 +276,8 @@ public class PomReader {
return ModuleRevisionId.newInstance(relocGroupId, relocArtId, relocVersion);
}
}
-
- public List /* <PomDependencyData> */ getDependencies() {
+
+ public List /* <PomDependencyData> */getDependencies() {
Element dependenciesElement = getFirstChildElement(projectElement, DEPENDENCIES);
LinkedList dependencies = new LinkedList();
if (dependenciesElement != null) {
@@ -271,9 +291,8 @@ public class PomReader {
}
return dependencies;
}
-
- public List /* <PomDependencyMgt> */ getDependencyMgt() {
+ public List /* <PomDependencyMgt> */getDependencyMgt() {
Element dependenciesElement = getFirstChildElement(projectElement, DEPENDENCY_MGT);
dependenciesElement = getFirstChildElement(dependenciesElement, DEPENDENCIES);
LinkedList dependencies = new LinkedList();
@@ -291,45 +310,51 @@ public class PomReader {
public class PomDependencyMgtElement implements PomDependencyMgt {
private final Element depElement;
-
+
public PomDependencyMgtElement(PomDependencyMgtElement copyFrom) {
this(copyFrom.depElement);
}
PomDependencyMgtElement(Element depElement) {
- this.depElement = depElement;
+ this.depElement = depElement;
}
-
- /* (non-Javadoc)
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.ivy.plugins.parser.m2.PomDependencyMgt#getGroupId()
*/
public String getGroupId() {
- String val = getFirstChildText(depElement , GROUP_ID);
+ String val = getFirstChildText(depElement, GROUP_ID);
return replaceProps(val);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.ivy.plugins.parser.m2.PomDependencyMgt#getArtifaceId()
*/
public String getArtifactId() {
- String val = getFirstChildText(depElement , ARTIFACT_ID);
+ String val = getFirstChildText(depElement, ARTIFACT_ID);
return replaceProps(val);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.ivy.plugins.parser.m2.PomDependencyMgt#getVersion()
*/
public String getVersion() {
- String val = getFirstChildText(depElement , VERSION);
+ String val = getFirstChildText(depElement, VERSION);
return replaceProps(val);
}
-
+
public String getScope() {
- String val = getFirstChildText(depElement , SCOPE);
+ String val = getFirstChildText(depElement, SCOPE);
return replaceProps(val);
}
-
- public List /*<ModuleId>*/ getExcludedModules() {
+
+ public List /* <ModuleId> */getExcludedModules() {
Element exclusionsElement = getFirstChildElement(depElement, EXCLUSIONS);
LinkedList exclusions = new LinkedList();
if (exclusionsElement != null) {
@@ -348,15 +373,15 @@ public class PomReader {
return exclusions;
}
}
-
- public List /* <PomPluginElement> */ getPlugins() {
+
+ public List /* <PomPluginElement> */getPlugins() {
LinkedList plugins = new LinkedList();
Element buildElement = getFirstChildElement(projectElement, "build");
if (buildElement == null) {
return plugins;
}
-
+
Element pluginsElement = getFirstChildElement(buildElement, PLUGINS);
if (pluginsElement != null) {
NodeList childs = pluginsElement.getChildNodes();
@@ -372,36 +397,35 @@ public class PomReader {
public class PomPluginElement implements PomDependencyMgt {
private Element pluginElement;
-
+
PomPluginElement(Element pluginElement) {
- this.pluginElement = pluginElement;
+ this.pluginElement = pluginElement;
}
-
+
public String getGroupId() {
- String val = getFirstChildText(pluginElement , GROUP_ID);
+ String val = getFirstChildText(pluginElement, GROUP_ID);
return replaceProps(val);
}
public String getArtifactId() {
- String val = getFirstChildText(pluginElement , ARTIFACT_ID);
+ String val = getFirstChildText(pluginElement, ARTIFACT_ID);
return replaceProps(val);
}
public String getVersion() {
- String val = getFirstChildText(pluginElement , VERSION);
+ String val = getFirstChildText(pluginElement, VERSION);
return replaceProps(val);
}
-
+
public String getScope() {
return null; // not used
}
-
- public List /*<ModuleId>*/ getExcludedModules() {
+
+ public List /* <ModuleId> */getExcludedModules() {
return Collections.EMPTY_LIST; // probably not used?
}
}
-
-
+
public class PomDependencyData extends PomDependencyMgtElement {
private final Element depElement;
@@ -415,27 +439,27 @@ public class PomReader {
}
public String getScope() {
- String val = getFirstChildText(depElement , SCOPE);
+ String val = getFirstChildText(depElement, SCOPE);
return replaceProps(val);
}
-
+
public String getClassifier() {
- String val = getFirstChildText(depElement , CLASSIFIER);
+ String val = getFirstChildText(depElement, CLASSIFIER);
return replaceProps(val);
}
-
+
public String getType() {
String val = getFirstChildText(depElement, TYPE);
return replaceProps(val);
}
public boolean isOptional() {
- Element e = getFirstChildElement(depElement, OPTIONAL);
+ Element e = getFirstChildElement(depElement, OPTIONAL);
return (e != null) && "true".equalsIgnoreCase(getTextContent(e));
}
}
-
+
/**
* @return the content of the properties tag into the pom.
*/
@@ -462,11 +486,11 @@ public class PomReader {
private static String getTextContent(Element element) {
StringBuffer result = new StringBuffer();
-
+
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
-
+
switch (child.getNodeType()) {
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
@@ -476,10 +500,10 @@ public class PomReader {
break;
}
}
-
+
return result.toString();
}
-
+
private static String getFirstChildText(Element parentElem, String name) {
Element node = getFirstChildElement(parentElem, name);
if (node != null) {
@@ -502,7 +526,7 @@ public class PomReader {
}
return null;
}
-
+
private static List/* <Element> */getAllChilds(Element parent) {
List r = new LinkedList();
if (parent != null) {
@@ -519,14 +543,16 @@ public class PomReader {
private static final class AddDTDFilterInputStream extends FilterInputStream {
private static final int MARK = 10000;
+
private static final String DOCTYPE = "<!DOCTYPE project SYSTEM \"m2-entities.ent\">\n";
private int count;
+
private byte[] prefix = DOCTYPE.getBytes();
-
+
private AddDTDFilterInputStream(InputStream in) throws IOException {
super(new BufferedInputStream(in));
-
+
this.in.mark(MARK);
// TODO: we should really find a better solution for this...
@@ -534,16 +560,17 @@ public class PomReader {
int byte1 = this.in.read();
int byte2 = this.in.read();
int byte3 = this.in.read();
-
+
if (byte1 == 239 && byte2 == 187 && byte3 == 191) {
// skip the UTF-8 BOM
this.in.mark(MARK);
} else {
this.in.reset();
}
-
+
int bytesToSkip = 0;
- LineNumberReader reader = new LineNumberReader(new InputStreamReader(this.in, "UTF-8"), 100);
+ LineNumberReader reader = new LineNumberReader(new InputStreamReader(this.in, "UTF-8"),
+ 100);
String firstLine = reader.readLine();
if (firstLine != null) {
String trimmed = firstLine.trim();
@@ -556,7 +583,7 @@ public class PomReader {
} else {
prefix = new byte[0];
}
-
+
this.in.reset();
for (int i = 0; i < bytesToSkip; i++) {
this.in.read();
@@ -567,33 +594,33 @@ public class PomReader {
if (count < prefix.length) {
return prefix[count++];
}
-
+
int result = super.read();
return result;
}
-
+
public int read(byte[] b, int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
- } else if ((off < 0) || (off > b.length) || (len < 0)
- || ((off + len) > b.length) || ((off + len) < 0)) {
+ } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length)
+ || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
int nbrBytesCopied = 0;
-
+
if (count < prefix.length) {
int nbrBytesFromPrefix = Math.min(prefix.length - count, len);
System.arraycopy(prefix, count, b, off, nbrBytesFromPrefix);
nbrBytesCopied = nbrBytesFromPrefix;
}
-
+
if (nbrBytesCopied < len) {
nbrBytesCopied += in.read(b, off + nbrBytesCopied, len - nbrBytesCopied);
}
-
+
count += nbrBytesCopied;
return nbrBytesCopied;
}