
org.rapidoid.commons.Env Maven / Gradle / Ivy
package org.rapidoid.commons;
import org.rapidoid.RapidoidThing;
import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since;
import org.rapidoid.config.Conf;
import org.rapidoid.scan.ClasspathUtil;
import org.rapidoid.util.Msc;
import java.util.Set;
/*
* #%L
* rapidoid-commons
* %%
* Copyright (C) 2014 - 2016 Nikolche Mihajlovski and contributors
* %%
* 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.
* #L%
*/
@Authors("Nikolche Mihajlovski")
@Since("5.1.0")
public class Env extends RapidoidThing {
public static final String PROFILE_DEFAULT = "default";
private static final Set PROFILES = Coll.synchronizedSet(PROFILE_DEFAULT);
public static boolean production() {
return Conf.ROOT.is("production") || Conf.ROOT.is("prod") || profile("production") || profile("prod");
}
public static boolean test() {
return Conf.ROOT.is("test") || profile("test") || Msc.insideTest();
}
public static boolean dev() {
return !production() && !test() && !ClasspathUtil.getClasspathFolders().isEmpty();
}
public static Set profiles() {
if (dev()) {
PROFILES.add("dev");
} else if (test()) {
PROFILES.add("test");
}
return PROFILES;
}
public static boolean profile(String profileName) {
return PROFILES.contains(profileName);
}
public static boolean hasAnyProfile(String... profileNames) {
for (String profileName : profileNames) {
if (profile(profileName)) {
return true;
}
}
return false;
}
public static String mode() {
return dev() ? "dev" : test() ? "test" : "production";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy