org.gradle.api.Project Java Examples

The following examples show how to use org.gradle.api.Project. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AffectedProjectFinder.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * Performs a post-order project tree traversal and returns a set of projects that own the
 * 'changedPaths'.
 */
private static Set<Project> changedSubProjects(Project project, Set<String> changedPaths) {
  // project.subprojects include all descendants of a given project, we only want immediate
  // children.
  Stream<Project> immediateChildProjects =
      project.getSubprojects().stream().filter(p -> project.equals(p.getParent()));

  Set<Project> projects =
      immediateChildProjects
          .flatMap(p -> changedSubProjects(p, changedPaths).stream())
          .collect(Collectors.toSet());
  String relativePath =
      project.getRootDir().toURI().relativize(project.getProjectDir().toURI()).toString();

  Iterator<String> itr = changedPaths.iterator();
  while (itr.hasNext()) {
    String file = itr.next();
    if (file.startsWith(relativePath)) {
      System.out.println("Claiming file " + file + " for project " + project);
      itr.remove();
      projects.add(project);
    }
  }
  return projects;
}
 
Example #2
Source File: JavaBasePlugin.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void configureJavaDoc(final Project project, final JavaPluginConvention convention) {
    project.getTasks().withType(Javadoc.class, new Action<Javadoc>() {
        public void execute(Javadoc javadoc) {
            javadoc.getConventionMapping().map("destinationDir", new Callable<Object>() {
                public Object call() throws Exception {
                    return new File(convention.getDocsDir(), "javadoc");
                }
            });
            javadoc.getConventionMapping().map("title", new Callable<Object>() {
                public Object call() throws Exception {
                    return project.getExtensions().getByType(ReportingExtension.class).getApiDocTitle();
                }
            });
        }
    });
}
 
Example #3
Source File: JigsawPlugin.java    From gradle-java-modules with Apache License 2.0 6 votes vote down vote up
private void configureTestTask(final Project project) {
    final Test testTask = (Test) project.getTasks().findByName(JavaPlugin.TEST_TASK_NAME);
    final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test");
    final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME);
    testTask.getInputs().property("moduleName", module.geName());
    testTask.doFirst(new Action<Task>() {
        @Override
        public void execute(Task task) {
            List<String> args = new ArrayList<>();
            args.add("--module-path");
            args.add(testTask.getClasspath().getAsPath());
            args.add("--add-modules");
            args.add("ALL-MODULE-PATH");
            args.add("--add-reads");
            args.add(module.geName() + "=junit");
            args.add("--patch-module");
            args.add(module.geName() + "=" + test.getJava().getOutputDir());
            testTask.setJvmArgs(args);
            testTask.setClasspath(project.files());
        }
    });
}
 
Example #4
Source File: AbstractReportTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@TaskAction
public void generate() {
    try {
        ReportRenderer renderer = getRenderer();
        File outputFile = getOutputFile();
        if (outputFile != null) {
            renderer.setOutputFile(outputFile);
        } else {
            renderer.setOutput(getServices().get(StyledTextOutputFactory.class).create(getClass()));
        }
        Set<Project> projects = new TreeSet<Project>(getProjects());
        for (Project project : projects) {
            renderer.startProject(project);
            generate(project);
            renderer.completeProject(project);
        }
        renderer.complete();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example #5
Source File: GaugeTask.java    From gauge-gradle-plugin with GNU General Public License v3.0 6 votes vote down vote up
@TaskAction
public void gauge() {
    Project project = getProject();
    GaugeExtension extension = project.getExtensions().findByType(GaugeExtension.class);
    PropertyManager propertyManager = new PropertyManager(project, extension);
    propertyManager.setProperties();

    ProcessBuilderFactory processBuilderFactory = new ProcessBuilderFactory(extension, project);
    ProcessBuilder builder = processBuilderFactory.create();
    log.info("Executing command => " + builder.command());

    try {
        Process process = builder.start();
        executeGaugeSpecs(process);
    } catch (IOException e) {
        throw new GaugeExecutionFailedException("Gauge or Java runner is not installed! Read http://getgauge.io/documentation/user/current/getting_started/download_and_install.html");
    }
}
 
Example #6
Source File: TaskDetailsFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public TaskDetails create(final Task task) {
    final String path;
    Project project = task.getProject();
    if (projects.contains(project)) {
        path = this.project.relativeProjectPath(task.getPath());
    } else {
        path = task.getPath();
    }
    return new TaskDetails() {
        public Path getPath() {
            return Path.path(path);
        }

        public String getDescription() {
            return task.getDescription();
        }

        public Set<TaskDetails> getDependencies() {
            return Collections.emptySet();
        }

        public Set<TaskDetails> getChildren() {
            return Collections.emptySet();
        }
    };
}
 
Example #7
Source File: ModuleSystemPlugin.java    From gradle-modules-plugin with MIT License 6 votes vote down vote up
private void configureModularity(Project project, String moduleName) {
    ExtensionContainer extensions = project.getExtensions();
    extensions.add("moduleName", moduleName);
    extensions.create("patchModules", PatchModuleExtension.class);
    extensions.create(ModularityExtension.class, "modularity", DefaultModularityExtension.class, project);

    new CompileTask(project).configureCompileJava();
    new CompileModuleInfoTask(project).configureCompileModuleInfoJava();
    new MergeClassesTask(project).configureMergeClasses();
    new CompileTestTask(project).configureCompileTestJava();
    new TestTask(project).configureTestJava();
    new RunTask(project).configureRun();
    new JavadocTask(project).configureJavaDoc();
    ModularJavaExec.configure(project);
    ModularCreateStartScripts.configure(project);
    PatchModuleContainer.configure(project);
}
 
Example #8
Source File: CodelabsPlugin.java    From curiostack with MIT License 6 votes vote down vote up
@Override
public void apply(Project project) {
  project.getRootProject().getPlugins().apply(CodelabsSetupPlugin.class);
  project.getPlugins().apply(BasePlugin.class);

  var setupClaat = DownloadToolUtil.getSetupTask(project, "claat");
  var exportDocs =
      project
          .getTasks()
          .register(
              "exportDocs",
              ExportDocsTask.class,
              t -> {
                t.dependsOn(setupClaat);

                var mdFileTree = project.fileTree("src");
                mdFileTree.exclude("build").include("**/*.md");

                t.getMdFiles().set(mdFileTree);
                t.getOutputDir().set(project.file("build/site"));
              });

  project.getTasks().named("assemble").configure(t -> t.dependsOn(exportDocs));
}
 
Example #9
Source File: SourceSetUtils.java    From transport with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Adds the provided dependency to the appropriate configurations of the given {@link SourceSet}
 */
static void addDependencyConfigurationToSourceSet(Project project, SourceSet sourceSet,
    DependencyConfiguration dependencyConfiguration) {
  addDependencyToConfiguration(project,
      SourceSetUtils.getConfigurationForSourceSet(project, sourceSet, dependencyConfiguration.getConfigurationType()),
      dependencyConfiguration.getDependencyString());
}
 
Example #10
Source File: GradleDependencyResolutionHelper.java    From thorntail with Apache License 2.0 5 votes vote down vote up
/**
 * Get the collection of Gradle projects along with their GAV definitions. This collection is used for determining if an
 * artifact specification represents a Gradle project or not.
 *
 * @param project the Gradle project that is being analyzed.
 * @return a map of GAV coordinates for each of the available projects (returned as keys).
 */
private static Map<String, Project> getAllProjects(final Project project) {
    return getCachedReference(project, "thorntail_project_gav_collection", () -> {
        Map<String, Project> gavMap = new HashMap<>();
        project.getRootProject().getAllprojects().forEach(p -> {
            gavMap.put(p.getGroup() + ":" + p.getName() + ":" + p.getVersion(), p);
        });
        return gavMap;
    });
}
 
Example #11
Source File: WebExtension.java    From curiostack with MIT License 5 votes vote down vote up
static ModifiableWebExtension createAndAdd(Project project) {
  return project
      .getExtensions()
      .create(NAME, ModifiableWebExtension.class)
      .setJavaPackage(project.getObjects().property(String.class))
      .setStorybookJavaPackage(project.getObjects().property(String.class));
}
 
Example #12
Source File: PipConfFile.java    From pygradle with Apache License 2.0 5 votes vote down vote up
public PipConfFile(Project project, PythonDetails pythonDetails) {
    this.project = project;
    this.pythonDetails = pythonDetails;

    if (OperatingSystem.current().isWindows()) {
        fileExtension = "ini";
    } else {
        fileExtension = "conf";
    }

}
 
Example #13
Source File: ShrinkerPlugin.java    From shrinker with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
    if (!project.getPlugins().hasPlugin(AppPlugin.class)) {
        throw new UnsupportedOperationException("Plugin 'shrinker' can only apply with 'com.android.application'");
    }
    AppExtension android = project.getExtensions().getByType(AppExtension.class);
    ShrinkerExtension config = project.getExtensions().create("shrinker", ShrinkerExtension.class);
    android.registerTransform(new InlineRTransform(config));
}
 
Example #14
Source File: DeleteModuleTaskTest.java    From scaffold-clean-architecture with MIT License 5 votes vote down vote up
@Before
public void setup() throws IOException, CleanException {
    Project project = ProjectBuilder.builder()
            .withName("cleanArchitecture")
            .withProjectDir(new File("build/unitTest"))
            .build();

    project.getTasks().create("ca", GenerateStructureTask.class);
    GenerateStructureTask generateStructureTask = (GenerateStructureTask) project.getTasks().getByName("ca");
    generateStructureTask.generateStructureTask();

    ProjectBuilder.builder()
            .withName("app-service")
            .withProjectDir(new File("build/unitTest/applications/app-service"))
            .withParent(project)
            .build();

    project.getTasks().create("gda", GenerateDrivenAdapterTask.class);
    GenerateDrivenAdapterTask generateDriven = (GenerateDrivenAdapterTask) project.getTasks().getByName("gda");
    generateDriven.setType(ModuleFactoryDrivenAdapter.DrivenAdapterType.MONGODB);
    generateDriven.generateDrivenAdapterTask();

    ProjectBuilder.builder()
            .withName("mongo-repository")
            .withProjectDir(new File("build/unitTest/infrastructure/driven-adapters/mongo-repository"))
            .withParent(project)
            .build();

    assertTrue(new File("build/unitTest/infrastructure/driven-adapters/mongo-repository/build.gradle").exists());

    project.getTasks().create("test", DeleteModuleTask.class);
    task = (DeleteModuleTask) project.getTasks().getByName("test");
}
 
Example #15
Source File: EarPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setupEarTask(final Project project, EarPluginConvention convention) {
    Ear ear = project.getTasks().create(EAR_TASK_NAME, Ear.class);
    ear.setDescription("Generates a ear archive with all the modules, the application descriptor and the libraries.");
    DeploymentDescriptor deploymentDescriptor = convention.getDeploymentDescriptor();
    if (deploymentDescriptor != null) {
        if (deploymentDescriptor.getDisplayName() == null) {
            deploymentDescriptor.setDisplayName(project.getName());
        }
        if (deploymentDescriptor.getDescription() == null) {
            deploymentDescriptor.setDescription(project.getDescription());
        }
    }
    ear.setGroup(BasePlugin.BUILD_GROUP);
    project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(new ArchivePublishArtifact(ear));

    project.getTasks().withType(Ear.class, new Action<Ear>() {
        public void execute(Ear task) {
            task.getLib().from(new Callable<FileCollection>() {
                public FileCollection call() throws Exception {
                    return project.getConfigurations().getByName(EARLIB_CONFIGURATION_NAME);
                }
            });
            task.from(new Callable<FileCollection>() {
                public FileCollection call() throws Exception {
                    // add the module configuration's files
                    return project.getConfigurations().getByName(DEPLOY_CONFIGURATION_NAME);
                }
            });
        }
    });
}
 
Example #16
Source File: GroovyPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureGroovydoc(final Project project) {
    Groovydoc groovyDoc = project.getTasks().create(GROOVYDOC_TASK_NAME, Groovydoc.class);
    groovyDoc.setDescription("Generates Groovydoc API documentation for the main source code.");
    groovyDoc.setGroup(JavaBasePlugin.DOCUMENTATION_GROUP);

    JavaPluginConvention convention = project.getConvention().getPlugin(JavaPluginConvention.class);
    SourceSet sourceSet = convention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    groovyDoc.setClasspath(sourceSet.getOutput().plus(sourceSet.getCompileClasspath()));

    GroovySourceSet groovySourceSet = new DslObject(sourceSet).getConvention().getPlugin(GroovySourceSet.class);
    groovyDoc.setSource(groovySourceSet.getGroovy());
}
 
Example #17
Source File: SemverGitflowPlugin.java    From gradle-gitsemver with Apache License 2.0 5 votes vote down vote up
public static SemverVersion getRepoTopoVersion(Project project)
        throws NoWorkTreeException, IOException, GitAPIException {
    String repoLocation = project.getProjectDir().getAbsolutePath()
            + "/.git";
    Integer buildNumber = getBuildNumber();
    return RepoSemanticVersions.getRepoTopoVersion(repoLocation, buildNumber);
}
 
Example #18
Source File: SdkUtil.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
public static File getAndroidJar(Project project) {
  LibraryExtension android = project.getExtensions().findByType(LibraryExtension.class);
  if (android == null) {
    throw new GradleException("Project " + project.getPath() + " is not an android library.");
  }
  return new File(
      getSdkDir(project),
      String.format("/platforms/%s/android.jar", android.getCompileSdkVersion()));
}
 
Example #19
Source File: EndpointsServerExtension.java    From endpoints-framework-gradle-plugin with Apache License 2.0 5 votes vote down vote up
/** Constructor. */
public EndpointsServerExtension(Project project) {
  this.project = project;
  discoveryDocDir = new File(project.getBuildDir(), "endpointsDiscoveryDocs");
  openApiDocDir = new File(project.getBuildDir(), "endpointsOpenApiDocs");
  clientLibDir = new File(project.getBuildDir(), "endpointsClientLibs");
  serviceClasses = new ArrayList<>();
}
 
Example #20
Source File: ProjectOutcomesModelBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private DefaultProjectOutcomes buildProjectOutput(Project project, ProjectOutcomes parent) {
    DefaultProjectOutcomes projectOutput = new DefaultProjectOutcomes(project.getName(), project.getPath(),
            project.getDescription(), project.getProjectDir(), getFileOutcomes(project), parent);
    for (Project child : project.getChildProjects().values()) {
        projectOutput.addChild(buildProjectOutput(child, projectOutput));
    }
    return projectOutput;
}
 
Example #21
Source File: GitVersionPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
@Override
public void apply(Project project) {
    this.project = project;
    this.logger = project.getLogger();
    project.setVersion(resolveVersion());

    project.allprojects(p -> p.setVersion(project.getVersion()));
}
 
Example #22
Source File: AppEnginePlugin.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(Project project) {
  checkGradleVersion();
  if (isAppEngineWebXmlBased(project)) {
    project.getPluginManager().apply(AppEngineStandardPlugin.class);
  } else {
    project.getPluginManager().apply(AppEngineAppYamlPlugin.class);
  }
}
 
Example #23
Source File: BootPlugin.java    From purplejs with Apache License 2.0 5 votes vote down vote up
@Override
public void apply( final Project project )
{
    this.project = project;
    this.ext = this.project.getExtensions().create( "purplejs", PurpleExtension.class, this.project );

    addPlugins();
    addRepositories();
    addDependencies();
    configureAppPlugin();
}
 
Example #24
Source File: JjdocProgramInvokerTest.java    From javaccPlugin with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    project = mock(Project.class);
    Configuration classpath = mock(Configuration.class);
    tempOutputDirectory = testFolder.newFolder("tempOutput");
    programInvoker = new JjdocProgramInvoker(project, classpath, tempOutputDirectory);
}
 
Example #25
Source File: EarPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void configureWithJavaPluginApplied(final Project project, final EarPluginConvention earPluginConvention, PluginContainer plugins) {
    plugins.withType(JavaPlugin.class, new Action<JavaPlugin>() {
        public void execute(JavaPlugin javaPlugin) {
            final JavaPluginConvention javaPluginConvention = project.getConvention().findPlugin(JavaPluginConvention.class);

            SourceSet sourceSet = javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
            sourceSet.getResources().srcDir(new Callable() {
                public Object call() throws Exception {
                    return earPluginConvention.getAppDirName();
                }
            });
            project.getTasks().withType(Ear.class, new Action<Ear>() {
                public void execute(final Ear task) {
                    task.dependsOn(new Callable<FileCollection>() {
                        public FileCollection call() throws Exception {
                            return javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME)
                                    .getRuntimeClasspath();
                        }
                    });
                    task.from(new Callable<FileCollection>() {
                        public FileCollection call() throws Exception {
                            return javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getOutput();
                        }
                    });
                }
            });
        }
    });
}
 
Example #26
Source File: ParallelTaskPlanExecutor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void startAdditionalWorkers(TaskExecutionPlan taskExecutionPlan, TaskExecutionListener taskListener, Executor executor) {
    List<Project> projects = getAllProjects(taskExecutionPlan);
    int numExecutors = Math.min(executorCount, projects.size());

    LOGGER.info("Using {} parallel executor threads", numExecutors);

    for (int i = 1; i < numExecutors; i++) {
        Runnable worker = taskWorker(taskExecutionPlan, taskListener);
        executor.execute(worker);
    }
}
 
Example #27
Source File: UploadRule.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Upload createUploadTask(String name, final Configuration configuration, final Project project) {
    Upload upload = project.getTasks().create(name, Upload.class);
    upload.setDescription(String.format("Uploads all artifacts belonging to %s", configuration));
    upload.setGroup(BasePlugin.UPLOAD_GROUP);
    upload.setConfiguration(configuration);
    upload.setUploadDescriptor(true);
    upload.getConventionMapping().map("descriptorDestination", new Callable<File>() {
        public File call() throws Exception {
            return new File(project.getBuildDir(), "ivy.xml");
        }
    });
    return upload;
}
 
Example #28
Source File: InitVersioning.java    From shipkit with MIT License 5 votes vote down vote up
private String determineVersion(Project project, File versionFile) {
    if ("unspecified".equals(project.getVersion())) {
        LOG.info("'project.version' is unspecified. Version will be set to '{}'. You can change it in '{}'.",
            FALLBACK_INITIAL_VERSION, versionFile.getName());
        return FALLBACK_INITIAL_VERSION;
    } else {
        LOG.lifecycle("  Configured '{}' version in '{}' file. Please remove 'version={}' setting from " +
                "*.gradle file. Version needs follow semantic versioning i.e. contains 3 numbers separated " +
                "by . (dot), e.g. 0.0.1 or 1.0.0 or 1.2.34 etc.",
            project.getVersion(), versionFile.getName(), project.getVersion());
        return project.getVersion().toString();
    }
}
 
Example #29
Source File: ProjectReportTask.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void generate(Project project) throws IOException {
    BuildClientMetaData metaData = getClientMetaData();

    StyledTextOutput textOutput = getRenderer().getTextOutput();

    render(project, new GraphRenderer(textOutput), true, textOutput);
    if (project.getChildProjects().isEmpty()) {
        textOutput.withStyle(Info).text("No sub-projects");
        textOutput.println();
    }

    textOutput.println();
    textOutput.text("To see a list of the tasks of a project, run ");
    metaData.describeCommand(textOutput.withStyle(UserInput), String.format("<project-path>:%s",
            ProjectInternal.TASKS_TASK));
    textOutput.println();

    textOutput.text("For example, try running ");
    Project exampleProject = project.getChildProjects().isEmpty() ? project : getChildren(project).get(0);
    metaData.describeCommand(textOutput.withStyle(UserInput), exampleProject.absoluteProjectPath(
            ProjectInternal.TASKS_TASK));
    textOutput.println();

    if (project != project.getRootProject()) {
        textOutput.println();
        textOutput.text("To see a list of all the projects in this build, run ");
        metaData.describeCommand(textOutput.withStyle(UserInput), project.getRootProject().absoluteProjectPath(
                ProjectInternal.PROJECTS_TASK));
        textOutput.println();
    }
}
 
Example #30
Source File: TextReportRenderer.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected String createHeader(Project project) {
    String header;
    if (project.getRootProject() == project) {
        header = "Root project";
    } else {
        header = String.format("Project %s", project.getPath());
    }
    if (GUtil.isTrue(project.getDescription())) {
        header = header + " - " + project.getDescription();
    }
    return header;
}