Navigation Menu

Skip to content

Commit

Permalink
#1016 - working annotation processor, default schema, update message …
Browse files Browse the repository at this point in the history
…types to include domain fields
  • Loading branch information
jecollins committed Apr 19, 2019
1 parent 333efd8 commit 9dd5c9f
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 22 deletions.
20 changes: 20 additions & 0 deletions common/pom.xml
Expand Up @@ -31,6 +31,12 @@

<!-- Power TAC -->

<dependency>
<groupId>org.powertac</groupId>
<artifactId>powertac-metadata</artifactId>
<version>1.7.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.powertac</groupId>
<artifactId>powertac-aop</artifactId>
Expand Down Expand Up @@ -160,8 +166,22 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<proc>none</proc>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler.version}</version>
<configuration>
<!-- <fork>true</fork> -->
<compilerArgs>
<arg>-Acore.versionId=${project.version}</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>

</build>
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/org/powertac/common/ClearedTrade.java
Expand Up @@ -32,7 +32,7 @@
* timeslot in which a non-zero quantity was traded.
* @author Daniel Schnurr, John Collins
*/
@Domain
@Domain(fields = {"timeslot", "executionMWh", "executionPrice", "dateExecuted"})
@XStreamAlias("trade")
public class ClearedTrade
{
Expand Down
Expand Up @@ -36,7 +36,7 @@
*
* @author Carsten Block, David Dauer, John Collins
*/
@Domain
@Domain(fields = {"broker", "timeslot", "balance"})
@XStreamAlias("market-posn")
public class MarketPosition //implements Serializable
{
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/org/powertac/common/Orderbook.java
Expand Up @@ -40,7 +40,7 @@
* @author Daniel Schnurr, John Collins
* @version 1.2 , 05/02/2011
*/
@Domain
@Domain(fields = {"timeslot", "clearingPrice", "dateExecuted"})
@XStreamAlias("orderbook")
public class Orderbook
{
Expand Down
Expand Up @@ -26,7 +26,7 @@
* an Orderbook.
* @author Daniel Schnurr
*/
@Domain
@Domain(fields = {"mWh", "limitPrice"})
@XStreamAlias("orderbook-bid")
public class OrderbookOrder implements Comparable<Object>
{
Expand Down
Expand Up @@ -54,14 +54,19 @@
*
* @author John Collins
*/
@Domain(fields = {"broker", "powerType", "minDuration", "signupPayment",
"earlyWithdrawPayment", "periodicPayment", "expiration",
@Domain(fields = {"broker", "powerType", "expiration", "minDuration",
"signupPayment", "earlyWithdrawPayment", "periodicPayment",
"supersedes"})
@XStreamAlias("tariff-spec")
public class TariffSpecification extends TariffMessage
{
static private Logger log = LogManager.getLogger(TariffSpecification.class);

/** Last date, in msec past epoch, that new subscriptions will be accepted.
* Zero means never expire. */
@XStreamAsAttribute
private long expiration = 0l;

/** Minimum contract duration (in milliseconds) */
@XStreamAsAttribute
private long minDuration = 0l;
Expand All @@ -84,11 +89,6 @@ public class TariffSpecification extends TariffMessage
@XStreamAsAttribute
private double periodicPayment = 0.0;

/** Last date, in msec past epoch, that new subscriptions will be accepted.
* Zero means never expire. */
@XStreamAsAttribute
private long expiration = 0l;

private List<RateCore> rates;

private List<Long> supersedes;
Expand Down
Expand Up @@ -28,7 +28,8 @@
*
* @version 1.0 - 03/Jun/2011
*/
@Domain
@Domain(fields = {"forecastTime", "temperature", "windSpeed",
"windDirection", "cloudCover"})
@XStreamAlias("weather-prediction")
public class WeatherForecastPrediction
{
Expand Down
Expand Up @@ -32,7 +32,7 @@
*
* @version 1.0 - 03/May/2011
*/
@Domain
@Domain(fields = {"timeslot", "temperature", "windSpeed", "windDirection", "cloudCover"})
@XStreamAlias("weather-report")
public class WeatherReport
{
Expand Down
Expand Up @@ -29,7 +29,7 @@
* @author John Collins
*/
@XStreamAlias("balance-report")
@Domain
@Domain(fields = {"timeslotIndex", "newImbalance"})
public class BalanceReport
{
@XStreamAsAttribute
Expand Down
Expand Up @@ -32,7 +32,7 @@
*
* @author John Collins
*/
@Domain
@Domain(fields = {"broker", "orderId", "status"})
@XStreamAlias("order-status")
public class OrderStatus
extends XStreamStateLoggable
Expand Down
Expand Up @@ -28,7 +28,7 @@
* of a tariff.
* @author jcollins
*/
@Domain
@Domain(fields = {"broker", "tariffId", "updateId", "status"})
@XStreamAlias("tariff-status")
public class TariffStatus extends TariffMessage
{
Expand Down
29 changes: 29 additions & 0 deletions common/src/main/resources/metadata/default-log.schema
@@ -0,0 +1,29 @@
Domain-metadata-version:default
org.powertac.common.Order:broker,timeslot,MWh,limitPrice
org.powertac.common.DistributionTransaction:postedTimeslot,NSmall,NLarge,KWh,charge
org.powertac.common.RegulationRate:tariffId,response,upRegulationPayment,downRegulationPayment
org.powertac.common.msg.EconomicControlEvent:tariffId,curtailmentRatio,timeslotIndex
org.powertac.common.msg.VariableRateUpdate:broker,tariffId,payload,rateId
org.powertac.common.msg.TariffExpire:broker,tariffId,newExpiration
org.powertac.common.msg.DistributionReport:timeslot,totalConsumption,totalProduction
org.powertac.common.Rate:tariffId,weeklyBegin,weeklyEnd,dailyBegin,dailyEnd,tierThreshold,fixed,minValue,maxValue,noticeInterval,expectedMean,maxCurtailment
org.powertac.common.msg.BalancingOrder:exerciseRatio,price,tariffId,broker
org.powertac.common.msg.OrderStatus:broker,orderId,status
org.powertac.common.msg.TariffStatus:broker,tariffId,updateId,status
org.powertac.common.HourlyCharge:rateId,value,atTime
org.powertac.common.msg.TariffRevoke:broker,tariffId
org.powertac.common.BalancingTransaction:postedTimeslot,kWh,charge
org.powertac.common.TariffSpecification:broker,powerType,minDuration,signupPayment,earlyWithdrawPayment,periodicPayment,supersedes
org.powertac.common.MarketPosition:broker,timeslot,balance
org.powertac.common.WeatherForecastPrediction:forecastTime,temperature,windSpeed,windDirection,cloudCover
org.powertac.common.MarketTransaction:postedTimeslot,timeslot,MWh,price
org.powertac.common.CapacityTransaction:postedTimeslot,peakTimeslot,threshold,KWh,charge
org.powertac.common.msg.BalanceReport:timeslotIndex,newImbalance
org.powertac.common.OrderbookOrder:mWh,limitPrice
org.powertac.common.ClearedTrade:timeslot,executionMWh,executionPrice,dateExecuted
org.powertac.common.CashPosition:postedTimeslot,balance
org.powertac.common.BankTransaction:postedTimeslot,amount
org.powertac.common.Orderbook:timeslot,clearingPrice,dateExecuted
org.powertac.common.WeatherReport:timeslot,temperature,windSpeed,windDirection,cloudCover
org.powertac.common.msg.BalancingControlEvent:tariffId,kwh,payment,timeslotIndex
org.powertac.common.TariffTransaction:postedTimeslot,txType,customerInfo,customerCount,KWh,charge,regulation
30 changes: 30 additions & 0 deletions common/src/main/resources/metadata/domain-default.schema
@@ -0,0 +1,30 @@
Domain-schema-version:default
org.powertac.common.Order:broker,timeslot,MWh,limitPrice
org.powertac.common.DistributionTransaction:postedTimeslot,NSmall,NLarge,KWh,charge
org.powertac.common.RegulationRate:tariffId,response,upRegulationPayment,downRegulationPayment
org.powertac.common.msg.EconomicControlEvent:tariffId,curtailmentRatio,timeslotIndex
org.powertac.common.msg.VariableRateUpdate:broker,tariffId,payload,rateId
org.powertac.common.msg.TariffExpire:broker,tariffId,newExpiration
org.powertac.common.msg.DistributionReport:timeslot,totalConsumption,totalProduction
org.powertac.common.Rate:tariffId,weeklyBegin,weeklyEnd,dailyBegin,dailyEnd,tierThreshold,fixed,minValue,maxValue,noticeInterval,expectedMean,maxCurtailment
org.powertac.common.msg.BalancingOrder:exerciseRatio,price,tariffId,broker
org.powertac.common.msg.OrderStatus:broker,orderId,status
org.powertac.common.msg.TariffStatus:broker,tariffId,updateId,status
org.powertac.common.HourlyCharge:rateId,value,atTime
org.powertac.common.msg.TariffRevoke:broker,tariffId
org.powertac.common.BalancingTransaction:postedTimeslot,kWh,charge
org.powertac.common.TariffSpecification:broker,powerType,minDuration,signupPayment,earlyWithdrawPayment,periodicPayment,supersedes
org.powertac.common.MarketPosition:broker,timeslot,balance
org.powertac.common.WeatherForecastPrediction:forecastTime,temperature,windSpeed,windDirection,cloudCover
org.powertac.common.MarketTransaction:postedTimeslot,timeslot,MWh,price
org.powertac.common.CapacityTransaction:postedTimeslot,peakTimeslot,threshold,KWh,charge
org.powertac.common.msg.BalanceReport:timeslotIndex,newImbalance
org.powertac.common.OrderbookOrder:mWh,limitPrice
org.powertac.common.ClearedTrade:timeslot,executionMWh,executionPrice,dateExecuted
org.powertac.common.CashPosition:postedTimeslot,balance
org.powertac.common.BankTransaction:postedTimeslot,amount
org.powertac.common.Orderbook:timeslot,clearingPrice,dateExecuted
org.powertac.common.WeatherReport:timeslot,temperature,windSpeed,windDirection,cloudCover
org.powertac.common.msg.BalancingControlEvent:tariffId,kwh,payment,timeslotIndex
org.powertac.common.TariffTransaction:postedTimeslot,txType,customerInfo,customerCount,KWh,charge,regulation
schema.end
2 changes: 2 additions & 0 deletions pom.xml
Expand Up @@ -17,9 +17,11 @@

<!-- Require more or less recent Maven version -->
<!-- http://maven.apache.org/ref/3.2.1/maven-model-builder/super-pom.html -->
<!--
<prerequisites>
<maven>${maven.version}</maven>
</prerequisites>
-->


<!-- Core components -->
Expand Down
21 changes: 15 additions & 6 deletions powertac-metadata/pom.xml
Expand Up @@ -19,6 +19,13 @@

<dependencies>

<!-- Power TAC -->
<dependency>
<groupId>org.powertac</groupId>
<artifactId>powertac-aop</artifactId>
<version>1.7.0-SNAPSHOT</version>
</dependency>

<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
Expand Down Expand Up @@ -49,12 +56,14 @@
<build>

<plugins>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<compilerArgs>-proc:none</compilerArgs>
</configuration>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler.version}</version>
<configuration>
<compilerArgs>-proc:none</compilerArgs>
</configuration>
</plugin>
</plugins>

</build>
Expand Down
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2019 by John Collins
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.powertac.metadata;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.FilerException;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.SourceVersion;
import javax.tools.Diagnostic;
import javax.tools.FileObject;
import javax.tools.StandardLocation;

import org.powertac.common.state.Domain;

//import org.powertac.common.state.Domain;

/**
* @author John Collins
*
*/
@SupportedAnnotationTypes("org.powertac.common.state.Domain")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class DomainProcessor extends AbstractProcessor
{

public DomainProcessor ()
{
super();
}

/* (non-Javadoc)
* @see javax.annotation.processing.AbstractProcessor#process(java.util.Set, javax.annotation.processing.RoundEnvironment)
*/
@Override
public boolean process (Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv)
{
// start by opening a file for metadata recording
PrintWriter out;
try {
FileObject f =
processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT,
"",
"metadata/domain.schema");
out = new PrintWriter(f.openWriter(), true);
}
catch (FilerException e) {
// happens in normal processing
return true;
}
catch (IOException e) {
e.printStackTrace();
return true;
}

Map<String, String> opts = processingEnv.getOptions();
//System.out.println("Env options: " + opts.size());
//for (String key : opts.keySet())
// System.out.println("Key " + key);
String artifactVersion = opts.get("core.versionId");
out.format("Domain-schema-version:%s\n", artifactVersion);
if (annotations.size() != 1) {
System.out.println("Should be only one annotation, saw " + annotations.size());
}
for (TypeElement annotation : annotations) {
//System.out.println("annotation name: " + annotation.getQualifiedName());
for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
TypeMirror tm = element.asType();
if (tm.getKind() == TypeKind.DECLARED) {
Domain domain = element.getAnnotation(Domain.class);
if (domain.fields().length > 0) {
out.format("%s:", tm.toString());
String delim = "";
for (String field: domain.fields()) {
out.format("%s%s", delim, field);
delim = ",";
}
out.format("\n");
}
}
}
}
out.format("schema.end\n");
out.close();
return true;
}

}
@@ -0,0 +1,2 @@
# annotation processing services
org.powertac.metadata.DomainProcessor

0 comments on commit 9dd5c9f

Please sign in to comment.