Search in sources :

Example 71 with Project

use of org.gradle.api.Project in project spring-security by spring-projects.

the class CheckAntoraVersionPluginTests method matchesWhenExplicitPrerelease.

@Test
void matchesWhenExplicitPrerelease() throws Exception {
    Project project = ProjectBuilder.builder().build();
    File rootDir = project.getRootDir();
    IOUtils.write("version: '1.0.0'\nprerelease: '-SNAPSHOT'", new FileOutputStream(new File(rootDir, "antora.yml")), StandardCharsets.UTF_8);
    project.getPluginManager().apply(CheckAntoraVersionPlugin.class);
    Task task = project.getTasks().findByName(CheckAntoraVersionPlugin.ANTORA_CHECK_VERSION_TASK_NAME);
    assertThat(task).isInstanceOf(CheckAntoraVersionTask.class);
    CheckAntoraVersionTask checkAntoraVersionTask = (CheckAntoraVersionTask) task;
    ((CheckAntoraVersionTask) task).getAntoraVersion().set("1.0.0");
    ((CheckAntoraVersionTask) task).getAntoraPrerelease().set("-SNAPSHOT");
    checkAntoraVersionTask.check();
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 72 with Project

use of org.gradle.api.Project in project atlas by alibaba.

the class AddLocalJarTask method run.

@TaskAction
void run() throws ExecutionException, InterruptedException, IOException, DocumentException {
    ExecutorServicesHelper executorServicesHelper = new ExecutorServicesHelper(taskName, getLogger(), 0);
    Project project = getProject();
    // TODO localjar for main dex must on
    for (AndroidLibrary androidLibrary : atlasDependencyTree.getMainBundle().getAllLibraryAars()) {
        List<File> localJars = getLocalJars(androidLibrary.getFolder());
        // System.out.println("get local libs");
        for (File file : localJars) {
            project.getLogger().info("add local jar to dependency " + file.getAbsolutePath() + "->" + androidLibrary.getResolvedCoordinates().toString());
        }
        androidLibrary.getLocalJars().addAll(localJars);
    }
    if (isLocalJarEnabled(project)) {
        List<AndroidLibrary> bundleLibraries = new ArrayList<>(atlasDependencyTree.getAllAndroidLibrarys());
        bundleLibraries.removeAll(atlasDependencyTree.getMainBundle().getAllLibraryAars());
        for (final AndroidLibrary aarBundle : bundleLibraries) {
            List<File> localJars = getLocalJars(aarBundle.getFolder());
            // System.out.println("get local libs");
            for (File file : localJars) {
                project.getLogger().info("add local jar to dependency " + file.getAbsolutePath() + "->" + aarBundle.getResolvedCoordinates().toString());
            }
            aarBundle.getLocalJars().addAll(localJars);
        }
    }
}
Also used : Project(org.gradle.api.Project) ExecutorServicesHelper(com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper) AndroidLibrary(com.android.builder.model.AndroidLibrary) ArrayList(java.util.ArrayList) File(java.io.File) MtlBaseTaskAction(com.taobao.android.builder.tasks.manager.MtlBaseTaskAction) TaskAction(org.gradle.api.tasks.TaskAction)

Example 73 with Project

use of org.gradle.api.Project in project atlas by alibaba.

the class AtlasListTask method executeTask.

@TaskAction
public void executeTask() {
    Project project = getProject();
    AtlasExtension atlasExtension = project.getExtensions().getByType(AtlasExtension.class);
    List<AtlasConfigField> list = null;
    try {
        list = AtlasConfigHelper.readConfig(atlasExtension, "atlas");
    } catch (Throwable e) {
        e.printStackTrace();
        return;
    }
    List<String> lines = new ArrayList<>();
    lines.add(" function  | The name of the configuration |  type | value ");
    lines.add(" ------------- | ------------- | ------------- | ------------- ");
    for (AtlasConfigField configField : list) {
        lines.add(configField.desc + "  | " + configField.name + " | " + configField.type + "  | " + configField.value);
    }
    for (String line : lines) {
        project.getLogger().error(line);
    }
    File file = new File(project.getProjectDir(), "atlasConfigList.MD");
    try {
        FileUtils.writeLines(file, lines);
        project.getLogger().error(file.getAbsolutePath() + " has generated");
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        FileUtils.write(new File(project.getProjectDir(), "atlasConfigList.json"), JSON.toJSONString(list, true));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Project(org.gradle.api.Project) AtlasExtension(com.taobao.android.builder.extension.AtlasExtension) AtlasConfigField(com.taobao.android.builder.tools.guide.AtlasConfigField) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Example 74 with Project

use of org.gradle.api.Project in project atlas by alibaba.

the class AwbGenerator method createAwbBundle.

public AwbBundle createAwbBundle(LibVariantContext libVariantContext) throws IOException {
    String variantName = libVariantContext.getVariantName();
    AtlasDependencyTree libDependencyTree = AtlasBuildContext.libDependencyTrees.get(variantName);
    // TODO 2.3
    if (null == libDependencyTree) {
        libDependencyTree = new AtlasDepTreeParser(libVariantContext.getProject(), new ExtraModelInfo(new ProjectOptions(libVariantContext.getProject()), null), new HashSet<>()).parseDependencyTree(libVariantContext.getVariantDependency());
        AtlasBuildContext.libDependencyTrees.put(variantName, libDependencyTree);
    }
    Project project = libVariantContext.getProject();
    String groupName = (String) project.getGroup();
    String name = "";
    String version = (String) project.getVersion();
    if (project.hasProperty("archivesBaseName")) {
        name = (String) project.getProperties().get("archivesBaseName");
    } else {
        name = project.getName();
    }
    File explodedDir = project.file(project.getBuildDir().getAbsolutePath() + "/" + FD_INTERMEDIATES + "/exploded-awb/" + computeArtifactPath(groupName, name, version));
    FileUtils.deleteDirectory(explodedDir);
    MavenCoordinates mavenCoordinates = new MavenCoordinatesImpl(groupName, name, version, "awb", "");
    ResolvedDependencyInfo resolvedDependencyInfo = new ResolvedDependencyInfo(groupName, name, version, "awb");
    resolvedDependencyInfo.setVariantName(libVariantContext.getVariantName());
    AwbBundle awbBundle = new AwbBundle(resolvedDependencyInfo, DependencyConvertUtils.toAndroidLibrary(mavenCoordinates, libVariantContext.getBundleTask().getArchivePath(), explodedDir));
    awbBundle.getSoLibraries().addAll(libDependencyTree.getMainBundle().getSoLibraries());
    awbBundle.getAndroidLibraries().addAll(libDependencyTree.getMainBundle().getAndroidLibraries());
    awbBundle.getJavaLibraries().addAll(libDependencyTree.getMainBundle().getJavaLibraries());
    return awbBundle;
}
Also used : Project(org.gradle.api.Project) MavenCoordinates(com.android.builder.model.MavenCoordinates) MavenCoordinatesImpl(com.android.builder.dependency.MavenCoordinatesImpl) ResolvedDependencyInfo(com.taobao.android.builder.dependency.parser.ResolvedDependencyInfo) AtlasDepTreeParser(com.taobao.android.builder.dependency.parser.AtlasDepTreeParser) ExtraModelInfo(com.android.build.gradle.internal.ExtraModelInfo) AwbBundle(com.taobao.android.builder.dependency.model.AwbBundle) AtlasDependencyTree(com.taobao.android.builder.dependency.AtlasDependencyTree) ProjectOptions(com.android.build.gradle.options.ProjectOptions) File(java.io.File)

Example 75 with Project

use of org.gradle.api.Project in project atlas by alibaba.

the class AwbGenerator method generateAwbArtifict.

/**
 * Create a basic AWB task
 */
public void generateAwbArtifict(final Zip bundleTask, LibVariantContext libVariantOutputData) {
    Project project = bundleTask.getProject();
    bundleTask.setExtension("awb");
    if (bundleTask instanceof AndroidZip) {
        String fileName = FilenameUtils.getBaseName(bundleTask.getArchiveName()) + ".awb";
        ((AndroidZip) bundleTask).setArchiveNameSupplier(() -> fileName);
    }
    bundleTask.setDestinationDir(new File(bundleTask.getDestinationDir().getParentFile(), "awb"));
    File destDir = libVariantOutputData.getScope().getBaseBundleDir();
    bundleTask.doFirst(task -> {
        File bundleBaseInfoFile = project.file("bundleBaseInfoFile.json");
        File customBundleIdFile = project.file("customPackageID.txt");
        if (bundleBaseInfoFile.exists()) {
            project.getLogger().warn("copy " + bundleBaseInfoFile.getAbsolutePath() + " to awb");
            try {
                FileUtils.copyFileToDirectory(bundleBaseInfoFile, destDir);
            } catch (IOException e) {
                throw new GradleException(e.getMessage(), e);
            }
        }
        if (customBundleIdFile.exists()) {
            try {
                FileUtils.copyFileToDirectory(customBundleIdFile, destDir);
            } catch (IOException e) {
                throw new GradleException(e.getMessage(), e);
            }
        }
    });
    bundleTask.doLast(task -> {
        File outputFile = new File(bundleTask.getDestinationDir(), bundleTask.getArchiveName());
        if (!outputFile.exists()) {
            return;
        }
        // Regenerating aar
        if (atlasExtension.getBundleConfig().isAwbBundle()) {
            try {
                FileUtils.copyFile(outputFile, new File(new File(bundleTask.getDestinationDir().getParentFile(), "aar"), FilenameUtils.getBaseName(bundleTask.getArchiveName()) + ".aar"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : Project(org.gradle.api.Project) GradleException(org.gradle.api.GradleException) AndroidZip(com.android.build.gradle.tasks.AndroidZip) IOException(java.io.IOException) File(java.io.File)

Aggregations

Project (org.gradle.api.Project)269 File (java.io.File)98 Task (org.gradle.api.Task)71 Plugin (org.gradle.api.Plugin)69 Configuration (org.gradle.api.artifacts.Configuration)53 List (java.util.List)40 ArrayList (java.util.ArrayList)39 SourceSet (org.gradle.api.tasks.SourceSet)38 TaskProvider (org.gradle.api.tasks.TaskProvider)38 IOException (java.io.IOException)35 Map (java.util.Map)35 Action (org.gradle.api.Action)34 Set (java.util.Set)32 JavaPlugin (org.gradle.api.plugins.JavaPlugin)31 FileCollection (org.gradle.api.file.FileCollection)30 Provider (org.gradle.api.provider.Provider)27 HashMap (java.util.HashMap)26 Collectors (java.util.stream.Collectors)26 ObjectFactory (org.gradle.api.model.ObjectFactory)25 Collections (java.util.Collections)24