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 void chewIndents() { // Chew up end-of-lines. while (match(Token.Kind.INDENT) != null) ; } }
/** * Id of a project definition. * <p/> * id := IDENT (DOT IDENT)* COLON IDENT (COLON IDENT)? EOL */ private Id id() { return id(false); }
/** * 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; }
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; }
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; }
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); return new Repositories(repoUrls);
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(); } }
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 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"); return new ScmElement(connection, developerConnection, url);
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 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); }
private String validateUrl(String url) { url = stripQuotes(url); // Validate URL... try { new URL(url); } catch (MalformedURLException e) { parseException("Invalid URL: " + url, e); } return url; }
@Override public int hashCode() { int result = value != null ? value.hashCode() : 0; result = 31 * result + (kind != null ? kind.hashCode() : 0); return result; }
private void indent() { if (match(Token.Kind.INDENT, Token.Kind.INDENT) != null) { // ERROR! } }
private void chewEols() { // Chew up end-of-lines. while (match(Token.Kind.EOL) != null) ; }
/** * classifier := LPAREN IDENT RPAREN */ private String classifier() { if (match(Token.Kind.LPAREN) == null) { return null; } List<Token> classifier = match(Token.Kind.IDENT); if (classifier == null) { log.severe("Expected identifier after '(' in classifier clause"); return null; } if (match(Token.Kind.RPAREN) == null) { log.severe("Expected ')' in classifier clause before end of line"); return null; } return classifier.get(0).value; }
private String relativePath() { StringBuilder fragment = new StringBuilder(); if (match(Token.Kind.DOT) != null) { fragment.append("."); } if (match(Token.Kind.DOT) != null) { fragment.append("."); } List<Token> idFragment; while ((idFragment = match(Token.Kind.IDENT)) != null) { fragment.append(idFragment.get(0).value); if (match(Token.Kind.DOT) != null) { fragment.append('.'); } } return fragment.toString(); }