Skip to content

Commit

Permalink
powsybl-config: move ClassicPlatformConfigProvider to another maven m…
Browse files Browse the repository at this point in the history
…odule and use a classpath only resolution mechanism

Signed-off-by: Jon Harper <jon.harper87@gmail.com>
  • Loading branch information
jonenst committed Sep 11, 2019
1 parent 4582f08 commit 9110377
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/commons/target/
/computation-local/target/
/computation/target/
/config-standard/target/
/config-test/target/
/contingency/target/
/contingency/contingency-api/target/
Expand Down
6 changes: 6 additions & 0 deletions action/action-simulator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-config-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-tools</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions afs/afs-ws/afs-ws-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-config-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public static WebArchive createTestArchive() {
.loadPomFromFile("pom.xml")
.importRuntimeDependencies()
.resolve("org.mockito:mockito-all",
"com.powsybl:powsybl-config-test",
"com.powsybl:powsybl-afs-mapdb")
.withTransitivity()
.asFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.nio.file.Path;
import java.util.*;
import java.util.ServiceLoader;
import java.util.stream.Collectors;

/**
*
Expand All @@ -28,8 +27,6 @@ public class PlatformConfig {

private static final Logger LOGGER = LoggerFactory.getLogger(PlatformConfig.class);

private static final String KEY = "powsybl.config.provider";

private static PlatformConfig defaultConfig;

protected final Path configDir;
Expand Down Expand Up @@ -67,30 +64,18 @@ public static ModuleConfigRepository loadModuleRepository(Path configDir, String

public static synchronized PlatformConfig defaultConfig() {
if (defaultConfig == null) {
String configName = System.getProperty(KEY);
if (configName != null) {
List<PlatformConfigProvider> platformConfigProviders = Lists
.newArrayList(ServiceLoader.load(PlatformConfigProvider.class));
Optional<PlatformConfigProvider> foundProvider = platformConfigProviders.stream()
.filter(platformConfigProvider -> configName.equals(platformConfigProvider.getName()))
.findFirst();
if (!foundProvider.isPresent()) {
if (LOGGER.isErrorEnabled()) {
List<String> available = platformConfigProviders.stream().map(PlatformConfigProvider::getName)
.collect(Collectors.toList());
LOGGER.error("Requested platform configuration provider {} = {} not found; available: {}", KEY,
configName, available);
}
} else {
LOGGER.info("Using platform configuration provider {} = {}", KEY, configName);
defaultConfig = foundProvider.get().getPlatformConfig();
}
List<PlatformConfigProvider> providers = Lists.newArrayList(ServiceLoader.load(PlatformConfigProvider.class));
if (providers.isEmpty()) {
LOGGER.error("Platform configuration provider not found. For tests, consider using TestPlatformConfigProvider in powsybl-config-test. Otherwise, consider using ClassicPlatformConfigProvider from powsybl-config-classic.");
throw new PowsyblException("Platform configuration provider not found");
}
if (defaultConfig == null) {
LOGGER.info("Using default platform configuration provider {}",
ClassicPlatformConfigProvider.class.getSimpleName());
defaultConfig = new ClassicPlatformConfigProvider().getPlatformConfig();
if (providers.size() > 1) {
LOGGER.error("Multiple platform configuration providers found: {}", providers);
throw new PowsyblException("Multiple platform configuration providers found");
}
PlatformConfigProvider p = providers.get(0);
LOGGER.info("Using platform configuration provider {}", p.getName());
defaultConfig = p.getPlatformConfig();
}
return defaultConfig;
}
Expand Down Expand Up @@ -123,4 +108,5 @@ public ModuleConfig getModuleConfig(String name) {
public Optional<ModuleConfig> getOptionalModuleConfig(String name) {
return getRepository().getModuleConfig(name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.commons.config;
package com.powsybl.configclassic;

import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
Expand All @@ -15,6 +15,13 @@
import java.util.Objects;
import java.util.stream.Collectors;

import com.powsybl.commons.config.ModuleConfigRepository;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.config.PlatformConfigProvider;
import com.powsybl.commons.config.PlatformEnv;
import com.powsybl.commons.config.EnvironmentModuleConfigRepository;
import com.powsybl.commons.config.StackedModuleConfigRepository;

import com.google.auto.service.AutoService;

/**
Expand Down
68 changes: 68 additions & 0 deletions config-classic/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2019, RTE (http://www.rte-france.com)
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-->
<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>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-core</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>

<artifactId>powsybl-config-classic</artifactId>
<name>Config Standard</name>
<description>Standard Config Provider</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>com.powsybl.config-classic</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- Compilation dependencies -->
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.commons.config;
package com.powsybl.configclassic;

import static org.junit.Assert.assertEquals;

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.commons.config.ModuleConfigRepository;

import org.junit.After;
import org.junit.Before;
Expand Down
15 changes: 15 additions & 0 deletions distribution-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-config-classic</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>

<!-- In provided scope, so that coverage is correctly reported but the jar is not packaged for distribution -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-config-test</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-action-dsl</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions loadflow/loadflow-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-config-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-scripting</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions loadflow/loadflow-validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
<artifactId>jimfs</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-config-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-iidm-api</artifactId>
Expand Down
10 changes: 1 addition & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<module>commons</module>
<module>computation</module>
<module>computation-local</module>
<module>config-classic</module>
<module>config-test</module>
<module>contingency</module>
<module>distribution-core</module>
Expand Down Expand Up @@ -222,15 +223,6 @@
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<powsybl.config.provider>test</powsybl.config.provider>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
Expand Down
6 changes: 6 additions & 0 deletions security-analysis/security-analysis-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-config-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-iidm-impl</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions sensitivity-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<artifactId>jimfs</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-config-test</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down

0 comments on commit 9110377

Please sign in to comment.