io.imqa.IMQAPlugin Maven / Gradle / Ivy
package io.imqa;
import com.google.gson.Gson;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.JavaVersion;
import org.gradle.internal.jvm.Jvm;
import io.imqa.injector.GJavacAction;
import io.imqa.injector.IMQAOption;
import io.imqa.injector.ResourceManager;
import io.imqa.injector.format.Version;
import io.imqa.injector.util.BuildOption;
import io.imqa.injector.util.Logger;
import io.imqa.injector.DependencyInjector;
import java.util.Set;
import java.lang.Iterable;
import java.util.Iterator;
public class IMQAPlugin implements Plugin {
public IMQAPlugin() {
}
@Override
public void apply(Project project) {
init(project);
project.afterEvaluate(new GJavacAction(project.getName()));
Logger.d("IMQAPlugin Applied");
}
public void init(Project project) {
Set allProject = project.getAllprojects();
Logger.d("All Project: "+allProject.toString());
Logger.d("All Project: "+project.getName());
ResourceManager rm = new ResourceManager();
IMQAOption option = rm.getServiceOption(project);
if (option != null) {
rm.setResValue(project, option);
IMQAOption.initOption(option);
}
BuildOption.init();
}
public static Version getGradleVersion(Project project) {
Version gradleVersion = new Version();
Iterator projIt = project.getRootProject().getBuildscript().getConfigurations().iterator();
while(projIt.hasNext()) {
Configuration conf = projIt.next();
Iterable depIts = conf.getAllDependencies();
Iterator depIt = depIts.iterator();
while (depIt.hasNext()) {
Dependency dep = depIt.next();
if (dep.getGroup().equals("com.android.tools.build")
&& dep.getName().equals("gradle")) {
String version = new String(dep.getVersion());
Logger.d("Gradle Version", version);
gradleVersion.parse(version);
}
}
}
return gradleVersion;
}
}