br.com.objectos.schema.ThisAnnotationProcessor Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2016 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.schema;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
import br.com.objectos.code.AbstractAnnotationProcessor;
import br.com.objectos.code.ProcessingEnvironmentWrapper;
import br.com.objectos.code.ProcessorListener;
import br.com.objectos.code.tools.ClassPath;
import br.com.objectos.core.lang.Strings;
import br.com.objectos.db.DatabaseService;
import br.com.objectos.db.Dialect;
/**
* @author [email protected] (Marcio Endo)
*/
abstract class ThisAnnotationProcessor extends AbstractAnnotationProcessor implements ProcessorListener {
ClassPath classPath;
DatabaseService database;
@Override
public void onInit(ProcessingEnvironmentWrapper processingEnv) {
Map optionMap = this.processingEnv.getOptions();
String sourcePath = optionMap.get("sourcePath");
classPath = ClassPath.builder()
.sourcePath(sourcePath)
.addJarOf(getClass())
.addJarOf(Migration.class)
.addJarOf(Dialect.class)
.addPath(Strings.nullToEmpty(sourcePath))
.build();
Iterator databaseIterator = ServiceLoader
.load(DatabaseService.class, getClass().getClassLoader())
.iterator();
if (!databaseIterator.hasNext()) {
throw new IllegalStateException("No DatabaseService found in classpath!");
}
database = databaseIterator.next();
}
} © 2015 - 2025 Weber Informatics LLC | Privacy Policy