public Model read(final Reader input, final Map<String, ?> options) throws IOException { assert input != null; // Parse the token stream from our pom.atom configuration file. Project project = new AtomParser((ModelSource)options.get(ModelProcessor.SOURCE), new Tokenizer(IOUtil.toString(input)).tokenize()).parse(); return project.toMavenModel(); } }
List<Token> propKey; chewIndents(); while ((propKey = match(Kind.IDENT, Kind.COLON)) != null) { String atom = idFragment(); List<Token> tokens = match(Kind.STRING); if (tokens != null) atom = tokens.get(0).value; atom = atom.trim(); atom = stripQuotes(atom); match(Kind.EOL); } else { if (anyOf(Kind.LBRACKET, Kind.LBRACE) != null) { chewEols(); chewIndents(); Map<String, Object> childProps = configurationMap(); chewEols(); chewIndents(); if (match(Kind.RBRACKET) == null && match(Kind.RBRACE) == null) parseException("Expected ']' after configuration properties"); chewIndents();
/** * Dependencies of a project. The real meat of it. */ private List<Id> dependencies(Token.Kind kind, boolean allowNullVersion) { indent(); if (match(kind, Token.Kind.COLON, Token.Kind.LBRACKET) == null) { return null; // no deps. } List<Id> deps = new ArrayList<Id>(); chewEols(); chewIndents(); // Slurp up the dep ids. Id id; while ((id = id(allowNullVersion)) != null) { // Optional additional params at the end. String classifier = classifier(); if (null != classifier) { id.setClassifier(classifier); } chewEols(); chewIndents(); deps.add(id); } if (match(Token.Kind.RBRACKET) == null) { // ERROR! parseException("Expected ]"); } return deps; }
public Project parse() { chewEols(); Repositories repositories = repositories(); if (null == repositories) { // don't really need to log this. jvz. // log.warning("No repositories specified in atom file, defaulting to Maven Central."); } chewEols(); return project(repositories); }
private List<String> modules() { indent(); if (match(Token.Kind.MODULES, Token.Kind.COLON, Token.Kind.LBRACKET) == null) { return null; // no properties. } List<String> modules = new ArrayList<String>(); chewEols(); chewIndents(); String module; while ((module = idFragment()) != null) { chewEols(); chewIndents(); modules.add(module); } if (match(Token.Kind.RBRACKET) == null) { // ERROR! parseException("Expected ]"); } return modules; }
if (match(Token.Kind.PROJECT) == null) { return null; List<Token> signature = match(Token.Kind.STRING); if (null == signature) { log.severe("Expected string describing project after 'project'."); signature = match(Token.Kind.AT, Token.Kind.STRING); if (null != signature) { projectUrl = signature.get(1).value; List<Token> packagingTokens = match(Kind.PACKAGING, Kind.IDENT); String packaging = null; if (null != packagingTokens) { if (match(Token.Kind.EOL) == null) { log.severe("Expected end of line after project declaration"); return null; indent(); if (match(Token.Kind.ID) == null) { log.severe("Expected 'id' after project declaration"); return null; if (match(Token.Kind.COLON) == null) { log.severe("Expected ':' after 'id'"); return null; Id projectId = id();
private ScmElement scm() { chewIndents(); if (match(Token.Kind.SCM, Token.Kind.COLON, Token.Kind.LBRACKET) == null) { return null; // no scm element chewEols(); chewIndents(); while ((ident = match(Token.Kind.IDENT)) != null) { String label = ident.get(0).value; if (match(Token.Kind.COLON) == null) { parseException("Expected : after label"); List<Token> valueToken = match(Token.Kind.STRING); if (null == valueToken) { parseException("Expected String after :"); url = value; chewEols(); chewIndents(); if (match(Token.Kind.RBRACKET) == null) { parseException("Expected ] after srcs list");
private List<Property> properties(Token.Kind kind) { indent(); if (match(kind, Token.Kind.COLON, Token.Kind.LBRACKET) == null) { return null; // no properties. } List<Property> properties = new ArrayList<Property>(); chewEols(); chewIndents(); Property p; while ((p = property()) != null) { chewEols(); chewIndents(); properties.add(p); } if (match(Token.Kind.RBRACKET) == null) { // ERROR! parseException("Expected ]"); } return properties; }
private Plugin plugin(Kind keyword) { if (match(keyword) == null) return null; if (match(Kind.EOL) == null) { parseException("Expected newline after 'plugin' keyword"); chewIndents(); if (match(Kind.ID, Kind.COLON) == null) { log.severe("Plugin declaration is missing an 'id' tag"); return null; Id pluginId = id(true); if (pluginId == null) { log.severe("Plugin id declaration malformed"); if (match(Kind.EOL) == null) { log.severe("Expected newline after plugin id declaration"); return null; if ((config = configurationMap()) == null || config.isEmpty()) return plugin; plugin.setConfiguration(toXpp3DomTree("configuration", config));
indent(); if (match(Token.Kind.SRCS, Token.Kind.COLON, Token.Kind.LBRACKET) == null) { return null; // No dirs! chewEols(); chewIndents(); List<Token> aMatch = match(Token.Kind.IDENT); if (aMatch == null) { parseException("Expected 'src' or 'test'"); if (null == match(Token.Kind.COLON)) { parseException("Expected : after src"); List<Token> srcDirToken = match(Token.Kind.STRING); if (null == srcDirToken) { parseException("Expected string after src:"); aMatch = match(Token.Kind.IDENT); if (null == match(Token.Kind.COLON)) { parseException("Expected : after test"); List<Token> testDirToken = match(Token.Kind.STRING); if (null == testDirToken) { parseException("Expected string after test:"); dirs.put("src", stripQuotes(srcDir)); if (null != testDir) dirs.put("test", stripQuotes(testDir));
private String idFragment() { StringBuilder fragment = new StringBuilder(); Token idFragment; while ((idFragment = anyOf( Token.Kind.IDENT, Kind.PLUGIN, )) != null) { fragment.append(idFragment.value); if (match(Token.Kind.DOT) != null) { fragment.append('.'); if (match(Token.Kind.DASH) != null) { fragment.append('-'); List<Token> startOfExpr = match(Kind.LBRACE); if (startOfExpr == null) return null; String prop = idFragment(); if (prop == null) parseException("Expected a property expression after ${"); if (match(Kind.RBRACE) == null) parseException("Expected '}' after property expression");
private Property property() { String key = idFragment(); if (key == null) { return null; } // Now expect a colon. if (match(Token.Kind.COLON) == null) { return null; } List<Token> value = match(Kind.STRING); if (value == null) { return null; } String actual = stripQuotes(value.get(0).value); return new Property(key, actual); }
private Parent parent() { if (match(Kind.PARENT) == null) return null; if (match(Kind.COLON) == null) { log.severe("Expected ':' after 'inherits'"); return null; } Id parentId = id(true); if (parentId == null) { log.severe("Expected complete artifact identifier in 'parent' clause"); return null; } String relativePath = "../pom.atom"; if (match(Token.Kind.COLON) != null) { relativePath = relativePath(); if (relativePath == null) { return null; } } Parent parent = new Parent(); parent.setGroupId(parentId.getGroup()); parent.setArtifactId(parentId.getArtifact()); parent.setVersion(parentId.getVersion()); parent.setRelativePath(relativePath); return parent; }
private Id id(boolean allowNullVersion) { String groupId = idFragment(); if (groupId == null) { return null; } // Now expect a colon. if (match(Token.Kind.COLON) == null) { return null; } String artifactId = idFragment(); if (artifactId == null) { return null; } // Now expect a colon. String version; if (match(Token.Kind.COLON) == null && !allowNullVersion) { return null; } else { version = idFragment(); if (version == null && !allowNullVersion) { return null; } } return new Id(groupId, artifactId, StringUtils.isEmpty(version) ? null : version); }
request.headers = headers; AtomParser parser = new AtomParser(); parser.namespaceDictionary = Namespace.DICTIONARY; transport.addParser(parser);
/** * Id of a project definition. * <p/> * id := IDENT (DOT IDENT)* COLON IDENT (COLON IDENT)? EOL */ private Id id() { return id(false); }
if (match(Token.Kind.PROJECT) == null) { return null; List<Token> signature = match(Token.Kind.STRING); if (null == signature) { log.severe("Expected string describing project after 'project'."); signature = match(Token.Kind.AT, Token.Kind.STRING); if (null != signature) { projectUrl = signature.get(1).value; List<Token> packagingTokens = match(Kind.PACKAGING, Kind.IDENT); String packaging = null; if (null != packagingTokens) { if (match(Token.Kind.EOL) == null) { log.severe("Expected end of line after project declaration"); return null; indent(); if (match(Token.Kind.ID) == null) { log.severe("Expected 'id' after project declaration"); return null; if (match(Token.Kind.COLON) == null) { log.severe("Expected ':' after 'id'"); return null; Id projectId = id();
if (match(Token.Kind.REPOSITORIES, Token.Kind.LEFT_WAVE) == null) { return null; List<Token> repositories = match(Token.Kind.STRING); if (repositories == null) { parseException("Error: expected URL string after 'respositories"); repoUrls.add(validateUrl(url)); while ((repositories = match(Token.Kind.COMMA)) != null) { chewEols(); chewIndents(); repositories = match(Token.Kind.STRING); chewEols(); chewIndents(); if (null != repositories) { url = validateUrl(repositories.get(0).value);
private List<String> modules() { indent(); if (match(Token.Kind.MODULES, Token.Kind.COLON, Token.Kind.LBRACKET) == null) { return null; // no properties. } List<String> modules = new ArrayList<String>(); chewEols(); chewIndents(); String module; while ((module = idFragment()) != null) { chewEols(); chewIndents(); modules.add(module); } if (match(Token.Kind.RBRACKET) == null) { // ERROR! parseException("Expected ]"); } return modules; }