return parse(content, defaultResource);
}
ToolkitConfig parse(String content, String defaultResource) throws IOException, MaxmlException {
MaxmlMap map = Maxml.parse(content);
if (map.containsKey(Key.requires.name())) {
// enforce a required minimum Moxie version
String req = map.getString(Key.requires.name(), null);
ArtifactVersion requires = new ArtifactVersion(req);
ArtifactVersion running = new ArtifactVersion(Toolkit.getVersion());
if (running.compareTo(requires) == -1) {
throw new MoxieException("Moxie {0} required for this script.", requires);
}
}
if (!StringUtils.isEmpty(defaultResource)) {
// build.moxie inheritance
File parentConfig = readFile(map, Key.parent, null);
if (parentConfig == null) {
File defaultFile = new File(Toolkit.getMxRoot(), defaultResource);
if (this.file == null || this.file.equals(defaultFile) || !defaultFile.exists()) {
// Moxie-shipped default resource
ToolkitConfig parent = new ToolkitConfig("/" + defaultResource);
setDefaultsFrom(parent);
} else {
// local filesystem default is available
ToolkitConfig parent = new ToolkitConfig(defaultFile, baseDirectory, defaultResource);
setDefaultsFrom(parent);
}
} else {
// parent has been specified
ToolkitConfig parent = new ToolkitConfig(parentConfig, baseDirectory, defaultResource);
setDefaultsFrom(parent);
}
}
// metadata (partially preserve inherited defaults)
pom.name = readString(map, Key.name, null);
pom.version = readString(map, Key.version, pom.version);
pom.groupId = readString(map, Key.groupId, pom.groupId);
pom.artifactId = readString(map, Key.artifactId, null);
pom.classifier = readString(map, Key.classifier, null);
pom.description = readString(map, Key.description, null);
pom.url = readString(map, Key.url, pom.url);
pom.organization = readString(map, Key.organization, pom.organization);
pom.organizationUrl = readString(map, Key.organizationUrl, pom.organizationUrl);
pom.issuesUrl = readString(map, Key.issuesUrl, pom.issuesUrl);
pom.inceptionYear = readString(map, Key.inceptionYear, pom.inceptionYear);
pom.packaging = readString(map, Key.packaging, pom.packaging);
pom.getDevelopers().addAll(readPersons(map, Key.developers));
pom.getContributors().addAll(readPersons(map, Key.contributors));
pom.getLicenses().addAll(readLicenses(map, Key.licenses));
pom.forumUrl = readString(map, Key.forumUrl, pom.forumUrl);
pom.socialNetworkUrl = readString(map, Key.socialNetworkUrl, pom.socialNetworkUrl);
pom.blogUrl = readString(map, Key.blogUrl, pom.blogUrl);
pom.ciUrl = readString(map, Key.ciUrl, pom.ciUrl);
pom.mavenUrl = readString(map, Key.mavenUrl, pom.mavenUrl);
String parentPom = map.getString(Key.parentPom.name(), null);
if (!StringUtils.isEmpty(parentPom)) {
// config specifies a parent pom
Dependency parent = new Dependency(parentPom);
pom.parentGroupId = parent.groupId;
pom.parentArtifactId = parent.artifactId;
pom.parentVersion = parent.version;
}
// scm metadata
if (map.containsKey(Key.scm)) {
MaxmlMap scm = map.getMap(Key.scm.name());
pom.scm.connection = scm.getString(Key.connection.name(), null);
pom.scm.developerConnection = scm.getString(Key.developerConnection.name(), null);
pom.scm.url = scm.getString(Key.url.name(), null);
pom.scm.tag = scm.getString(Key.tag.name(), null);
}
// set default name to artifact id
if (StringUtils.isEmpty(pom.name)) {
pom.name = pom.artifactId;
}
mainclass = readString(map, Key.mainclass, null);
pom.releaseVersion = readString(map, Key.releaseVersion, pom.releaseVersion);
pom.releaseDate = map.getDate(Key.releaseDate.name(), pom.releaseDate);
// build parameters
mavenCacheStrategy = MavenCacheStrategy.fromString(map.getString(Key.mavenCacheStrategy.name(), mavenCacheStrategy == null ? null : mavenCacheStrategy.name()));
parallelDownloads = map.getBoolean(Key.parallelDownloads.name(), parallelDownloads);
failFastOnArtifactResolution = map.getBoolean(Key.failFastOnArtifactResolution.name(), failFastOnArtifactResolution);
apply = new TreeSet<String>(readStrings(map, Key.apply, new ArrayList<String>(apply), true));
outputDirectory = readFile(map, Key.outputDirectory, new File(baseDirectory, "build"));
targetDirectory = readFile(map, Key.targetDirectory, new File(baseDirectory, "build/target"));
sourceDirectories = readSourceDirectories(map, Key.sourceDirectories, sourceDirectories);
if (sourceDirectories.isEmpty()) {
// container descriptors (e.g. POM) can define modules
modules = readModules(map, Key.modules);
} else {
// standard project/modules can define linked modules which are
// treated as extensions of this projects sourceDirectories and
// dependencies
linkedModules = readModules(map, Key.modules);
}
resourceDirectories = readSourceDirectories(map, Key.resourceDirectories, resourceDirectories);
dependencyDirectory = readFile(map, Key.dependencyDirectory, null);
dependencyNamePattern = map.getString(Key.dependencyNamePattern.name(), dependencyNamePattern);
String policy = readString(map, Key.updatePolicy, null);
if (!StringUtils.isEmpty(policy)) {
int mins = 0;
if (policy.indexOf(':') > -1) {
mins = Integer.parseInt(policy.substring(policy.indexOf(':') + 1));
policy = policy.substring(0, policy.indexOf(':'));
}
updatePolicy = UpdatePolicy.fromString(policy);
if (UpdatePolicy.interval.equals(updatePolicy) && mins > 0) {
updatePolicy.setMins(mins);
}
}
// default snapshot purge policy
revisionRetentionCount = Math.min(Toolkit.MAX_REVISIONS,
Math.max(1, map.getInt(Key.revisionRetentionCount.name(), revisionRetentionCount)));
revisionPurgeAfterDays = Math.min(Toolkit.MAX_PURGE_AFTER_DAYS,
Math.max(0, map.getInt(Key.revisionPurgeAfterDays.name(), revisionPurgeAfterDays)));
if (map.containsKey(Key.properties.name())) {
MaxmlMap props = map.getMap(Key.properties.name());
for (String key : props.keySet()) {
pom.setProperty(key, props.getString(key, null));
}
}
List<String> managedDependencies = readStrings(map, Key.dependencyManagement, new ArrayList<String>());
for (String dependency : managedDependencies) {
Dependency dep = new Dependency(dependency);
pom.addManagedDependency(dep, null);
}
registeredRepositories = parseRemoteRepositories(map, Key.registeredRepositories, registeredRepositories);
repositories = map.getStrings(Key.repositories.name(), repositories);
parseDependencyAliases(map, Key.dependencyAliases);
parseDependencies(map, Key.dependencies);
parseDependencyOverrides(map, Key.dependencyOverrides);
parseProxies(map, Key.proxies);
pom.addExclusions(readStrings(map, Key.exclusions, new ArrayList<String>(), true));
// all task attributes are inherited. individual attributes can be overridden
if (map.containsKey("tasks")) {
MaxmlMap taskOverrides = map.getMap("tasks");
for (Map.Entry<String, Object> entry : taskOverrides.entrySet()) {
String task = entry.getKey();
MaxmlMap taskAttributes = (MaxmlMap) entry.getValue();
if (tasks.containsKey(task)) {
// update existing entry with attribute overrides
tasks.getMap(task).putAll(taskAttributes);
} else {
// new entry