use of org.gradle.api.artifacts.UnknownConfigurationException in project tomee by apache.
the class TomEEEmbeddedPlugin method apply.
@Override
public void apply(final Project project) {
final List<String> extensions = asList(TomEEEmbeddedExtension.NAME, TomEEEmbeddedExtension.ALIAS);
for (final String name : extensions) {
project.getExtensions().create(name, TomEEEmbeddedExtension.class);
}
project.afterEvaluate(new Action<Project>() {
@Override
public void execute(final Project actionProject) {
for (final String name : extensions) {
final TomEEEmbeddedExtension extension = TomEEEmbeddedExtension.class.cast(actionProject.getExtensions().findByName(name));
if (extension == null) {
return;
}
if (extension.isSkipDefaultRepository() != null && !extension.isSkipDefaultRepository()) {
actionProject.getRepositories().mavenCentral();
return;
}
}
actionProject.getRepositories().mavenCentral();
}
});
String configName = TomEEEmbeddedExtension.ALIAS;
try {
project.getConfigurations().getByName(configName);
} catch (final UnknownConfigurationException uce) {
configName = TomEEEmbeddedExtension.NAME;
}
final Configuration configuration = project.getConfigurations().maybeCreate(configName);
configuration.getIncoming().beforeResolve(new Action<ResolvableDependencies>() {
@Override
public void execute(final ResolvableDependencies resolvableDependencies) {
String tomeeVersion = null;
for (final String name : extensions) {
final TomEEEmbeddedExtension extension = TomEEEmbeddedExtension.class.cast(project.getExtensions().findByName(name));
if (extension == null) {
return;
}
tomeeVersion = extension.getTomeeVersion();
if (tomeeVersion != null) {
break;
}
}
if (tomeeVersion == null) {
try {
try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/maven/org.apache.tomee.gradle/tomee-embedded/pom.properties")) {
final Properties p = new Properties();
p.load(is);
tomeeVersion = p.getProperty("version");
}
} catch (final IOException e) {
// we should never be there
tomeeVersion = "7.0.2";
}
}
final DependencyHandler dependencyHandler = project.getDependencies();
final DependencySet dependencies = configuration.getDependencies();
dependencies.add(dependencyHandler.create("org.apache.tomee:tomee-embedded:" + tomeeVersion));
}
});
project.task(new HashMap<String, Object>() {
{
put("type", TomEEEmbeddedTask.class);
put("group", "Embedded Application Server");
put("description", "Start an embedded Apache TomEE server deploying application classpath");
}
}, TomEEEmbeddedExtension.NAME);
}
use of org.gradle.api.artifacts.UnknownConfigurationException in project tomee by apache.
the class TomEEEmbeddedTask method fixConfig.
private void fixConfig() {
final Project project = getProject();
// defaults
if (classpath == null) {
try {
classpath.add(project.getConfigurations().getByName(TomEEEmbeddedExtension.ALIAS).fileCollection());
} catch (final UnknownConfigurationException uce) {
classpath = project.getConfigurations().getByName(TomEEEmbeddedExtension.NAME);
}
}
if (docBase == null) {
docBase = new File(project.getProjectDir(), "src/main/webapp");
}
if (workDir == null) {
workDir = new File(project.getBuildDir(), "tomee-embedded/work");
}
if (dir == null) {
dir = new File(project.getBuildDir(), "tomee-embedded/run").getAbsolutePath();
}
if (modules == null || modules.isEmpty()) {
final File main = new File(project.getBuildDir(), "classes/main");
if (main.isDirectory()) {
modules = new ArrayList<>(singletonList(main));
}
}
// extension override
for (final String name : asList(TomEEEmbeddedExtension.NAME, TomEEEmbeddedExtension.ALIAS)) {
final TomEEEmbeddedExtension extension = TomEEEmbeddedExtension.class.cast(project.getExtensions().findByName(name));
if (extension != null) {
for (final Field f : TomEEEmbeddedTask.class.getDeclaredFields()) {
if (f.isAnnotationPresent(Input.class)) {
try {
final Field extField = TomEEEmbeddedExtension.class.getDeclaredField(f.getName());
if (!extField.isAccessible()) {
extField.setAccessible(true);
}
final Object val = extField.get(extension);
if (val != null) {
if (!f.isAccessible()) {
f.setAccessible(true);
}
f.set(this, val);
}
} catch (final IllegalAccessException | NoSuchFieldException e) {
getLogger().warn("No field " + f.getName() + " in " + extension, e);
}
}
}
}
}
}
Aggregations