Skip to content

Commit

Permalink
Merge branch 'feature/axiom' into feature/metadata-mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jun 12, 2020
2 parents cce6de6 + 3043194 commit 52d4614
Show file tree
Hide file tree
Showing 77 changed files with 6,946 additions and 3 deletions.
81 changes: 81 additions & 0 deletions infra/axiom/pom.xml
@@ -0,0 +1,81 @@
<?xml version="1.0"?>
<!--
~ Copyright (c) 2010-2018 Evolveum and contributors
~
~ This work is dual-licensed under the Apache License 2.0
~ and European Union Public License. See LICENSE file for details.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>infra</artifactId>
<groupId>com.evolveum.midpoint.infra</groupId>
<version>4.2-SNAPSHOT</version>
</parent>

<groupId>com.evolveum.axiom</groupId>
<artifactId>axiom</artifactId>

<name>Axiom</name>

<properties>
<maven.test.skip>true</maven.test.skip>
</properties>

<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.8-1</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.evolveum.midpoint.tools</groupId>
<artifactId>test-ng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.8-1</version>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
<configuration>
<visitor>true</visitor>
<listener>true</listener>
</configuration>
</plugin>
</plugins>
</build>
</project>
45 changes: 45 additions & 0 deletions infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.g4
@@ -0,0 +1,45 @@
grammar Axiom;

SEMICOLON : ';';
LEFT_BRACE : '{';
RIGHT_BRACE : '}';
COLON : ':';
PLUS : '+';
LINE_COMMENT : [ \n\r\t]* ('//' (~[\r\n]*)) [ \n\r\t]* -> skip;
SEP: [ \n\r\t]+;
IDENTIFIER : [a-zA-Z_/][a-zA-Z0-9_\-./]*;

fragment SQOUTE : '\'';
fragment DQOUTE : '"';


//fragment SUB_STRING : ('"' (ESC | ~["])*? '"') | ('\'' (ESC | ~['])* '\'');
//fragment ESC : '\\' (["\\/bfnrt] | UNICODE);
//fragment UNICODE : 'u' HEX HEX HEX HEX;
//fragment HEX : [0-9a-fA-F] ;
//STRING: ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '\'' | '}' | '/' | '+')~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '}' )* ) | SUB_STRING );

fragment ESC : '\\';

STRING_SINGLEQUOTE: SQOUTE ((ESC SQOUTE) | ~[\n'])* SQOUTE;
STRING_DOUBLEQUOTE: DQOUTE ((ESC DQOUTE) | ~[\n"])* DQOUTE;
//STRING_MULTILINE: '"""' (ESC | ~('"""'))* '"""';
statement : SEP* identifier SEP* (argument)? SEP* (SEMICOLON | LEFT_BRACE SEP* (statement)* SEP* RIGHT_BRACE SEP*) SEP*;
identifier : (prefix COLON)? localIdentifier;
prefix : IDENTIFIER;
localIdentifier : IDENTIFIER;
// argument : STRING (SEP* PLUS SEP* STRING)* | IDENTIFIER;
argument : identifier | string;
string : singleQuoteString | doubleQuoteString | multilineString;
singleQuoteString : STRING_SINGLEQUOTE;
doubleQuoteString : STRING_DOUBLEQUOTE;
multilineString: '"""\n' (~('"""'))*'"""';
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.axiom.api;

import java.util.Objects;

import com.google.common.base.Preconditions;

public class AxiomIdentifier {

public static final String AXIOM_NAMESPACE = "https://ns.evolveum.com/axiom";
private final String namespace;
private final String localName;

public AxiomIdentifier(String namespace, String localName) {
this.namespace = Preconditions.checkNotNull(namespace, "namespace");
this.localName = Preconditions.checkNotNull(localName, "localName");
}

public String getNamespace() {
return namespace;
}

public String getLocalName() {
return localName;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((localName == null) ? 0 : localName.hashCode());
result = prime * result + ((namespace == null) ? 0 : namespace.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof AxiomIdentifier))
return false;
AxiomIdentifier other = (AxiomIdentifier) obj;
if (localName == null) {
if (other.localName != null)
return false;
} else if (!localName.equals(other.localName))
return false;
if (namespace == null) {
if (other.namespace != null)
return false;
} else if (!namespace.equals(other.namespace))
return false;
return true;
}

@Override
public String toString() {
return localName;
}

public static AxiomIdentifier axiom(String identifier) {
return new AxiomIdentifier(AXIOM_NAMESPACE, identifier);
}

public static AxiomIdentifier from(String namespace, String localName) {
return new AxiomIdentifier(namespace, localName);
}

}
45 changes: 45 additions & 0 deletions infra/axiom/src/main/java/com/evolveum/axiom/concepts/Lazy.java
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.axiom.concepts;

public class Lazy<T> implements java.util.function.Supplier<T> {

private static final Lazy NULL = Lazy.instant(null);
private Object value;

private Lazy(Object supplier) {
value = supplier;
}

public static final <T> Lazy<T> from(Supplier<? extends T> supplier) {
return new Lazy<>(supplier);
}


public static <T> Lazy<T> instant(T value) {
return new Lazy<T>(value);
}

@SuppressWarnings("unchecked")
public static <T> Lazy<T> nullValue() {
return NULL;
}

@SuppressWarnings("unchecked")
@Override
public T get() {
if(value instanceof Supplier<?>) {
value = ((Supplier<?>) value).get();
}
return (T) value;
}

public interface Supplier<T> extends java.util.function.Supplier<T> {

}

}
@@ -0,0 +1,16 @@
package com.evolveum.axiom.concepts;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;

public class Optionals {

public static <V> Optional<V>first(Collection<V> collection) {
if(collection.isEmpty()) {
return Optional.empty();
}
return Optional.ofNullable(collection.iterator().next());
}

}
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.axiom.lang.api;

import com.evolveum.axiom.api.AxiomIdentifier;

public interface AxiomBaseDefinition {

AxiomIdentifier name();
String documentation();
}

0 comments on commit 52d4614

Please sign in to comment.