
com.liferay.gradle.plugins.internal.util.GradleUtil Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.gradle.plugins.internal.util;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.file.SourceDirectorySet;
import org.gradle.api.plugins.BasePluginConvention;
import org.gradle.api.plugins.PluginContainer;
/**
* @author Andrea Di Giorgi
*/
public class GradleUtil extends com.liferay.gradle.util.GradleUtil {
public static String getArchivesBaseName(Project project) {
BasePluginConvention basePluginConvention = GradleUtil.getConvention(
project, BasePluginConvention.class);
return basePluginConvention.getArchivesBaseName();
}
public static File getSrcDir(SourceDirectorySet sourceDirectorySet) {
Set srcDirs = sourceDirectorySet.getSrcDirs();
Iterator iterator = srcDirs.iterator();
return iterator.next();
}
/**
* Copied from com.liferay.portal.kernel.util.ThreadUtil
.
*/
public static Thread[] getThreads() {
Thread currentThread = Thread.currentThread();
ThreadGroup threadGroup = currentThread.getThreadGroup();
while (threadGroup.getParent() != null) {
threadGroup = threadGroup.getParent();
}
int threadCountGuess = threadGroup.activeCount();
Thread[] threads = new Thread[threadCountGuess];
int threadCountActual = threadGroup.enumerate(threads);
while (threadCountActual == threadCountGuess) {
threadCountGuess *= 2;
threads = new Thread[threadCountGuess];
threadCountActual = threadGroup.enumerate(threads);
}
return threads;
}
public static boolean hasPlugin(
Project project, Class extends Plugin>> pluginClass) {
PluginContainer pluginContainer = project.getPlugins();
return pluginContainer.hasPlugin(pluginClass);
}
public static boolean hasPlugin(Project project, String pluginId) {
PluginContainer pluginContainer = project.getPlugins();
return pluginContainer.hasPlugin(pluginId);
}
public static boolean isRunningInsideDaemon() {
for (Thread thread : getThreads()) {
if (thread == null) {
continue;
}
String name = thread.getName();
if (name.startsWith("Daemon worker")) {
return true;
}
}
return false;
}
public static Map toStringMap(Map map) {
Map stringMap = new HashMap<>();
for (Map.Entry entry : map.entrySet()) {
String key = entry.getKey();
String value = toString(entry.getValue());
stringMap.put(key, value);
}
return stringMap;
}
public static > void withPlugin(
Project project, Class
pluginClass, Action
action) {
PluginContainer pluginContainer = project.getPlugins();
pluginContainer.withType(pluginClass, action);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy