Search in sources :

Example 1 with JavaModuleDetector

use of org.gradle.internal.jvm.JavaModuleDetector in project gradle by gradle.

the class CreateStartScripts method generate.

@TaskAction
public void generate() {
    StartScriptGenerator generator = new StartScriptGenerator(unixStartScriptGenerator, windowsStartScriptGenerator);
    JavaModuleDetector javaModuleDetector = getJavaModuleDetector();
    generator.setApplicationName(getApplicationName());
    generator.setMainClassName(fullMainArgument());
    generator.setDefaultJvmOpts(getDefaultJvmOpts());
    generator.setOptsEnvironmentVar(getOptsEnvironmentVar());
    generator.setExitEnvironmentVar(getExitEnvironmentVar());
    generator.setClasspath(getRelativePath(javaModuleDetector.inferClasspath(mainModule.isPresent(), getClasspath())));
    generator.setModulePath(getRelativePath(javaModuleDetector.inferModulePath(mainModule.isPresent(), getClasspath())));
    if (StringUtils.isEmpty(getExecutableDir())) {
        generator.setScriptRelPath(getUnixScript().getName());
    } else {
        generator.setScriptRelPath(getExecutableDir() + "/" + getUnixScript().getName());
    }
    generator.generateUnixScript(getUnixScript());
    generator.generateWindowsScript(getWindowsScript());
}
Also used : UnixStartScriptGenerator(org.gradle.api.internal.plugins.UnixStartScriptGenerator) WindowsStartScriptGenerator(org.gradle.api.internal.plugins.WindowsStartScriptGenerator) StartScriptGenerator(org.gradle.api.internal.plugins.StartScriptGenerator) JavaModuleDetector(org.gradle.internal.jvm.JavaModuleDetector) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with JavaModuleDetector

use of org.gradle.internal.jvm.JavaModuleDetector in project gradle by gradle.

the class IdeaDependenciesProvider method visitDependencies.

private IdeaDependenciesVisitor visitDependencies(IdeaModule ideaModule, GeneratedIdeaScope scope) {
    ProjectInternal projectInternal = (ProjectInternal) ideaModule.getProject();
    final DependencyHandler handler = projectInternal.getDependencies();
    final Collection<Configuration> plusConfigurations = getPlusConfigurations(ideaModule, scope);
    final Collection<Configuration> minusConfigurations = getMinusConfigurations(ideaModule, scope);
    final JavaModuleDetector javaModuleDetector = projectInternal.getServices().get(JavaModuleDetector.class);
    final IdeaDependenciesVisitor visitor = new IdeaDependenciesVisitor(ideaModule, scope.name());
    return projectInternal.getOwner().fromMutableState(p -> {
        new IdeDependencySet(handler, javaModuleDetector, plusConfigurations, minusConfigurations, false, gradleApiSourcesResolver).visit(visitor);
        return visitor;
    });
}
Also used : IdeDependencySet(org.gradle.plugins.ide.internal.resolver.IdeDependencySet) UnresolvedIdeDependencyHandler(org.gradle.plugins.ide.internal.resolver.UnresolvedIdeDependencyHandler) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) Configuration(org.gradle.api.artifacts.Configuration) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) JavaModuleDetector(org.gradle.internal.jvm.JavaModuleDetector)

Example 3 with JavaModuleDetector

use of org.gradle.internal.jvm.JavaModuleDetector in project gradle by gradle.

the class Javadoc method generate.

@TaskAction
protected void generate() {
    File destinationDir = getDestinationDir();
    try {
        getDeleter().ensureEmptyDirectory(destinationDir);
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
    StandardJavadocDocletOptions options = new StandardJavadocDocletOptions((StandardJavadocDocletOptions) getOptions());
    if (options.getDestinationDirectory() == null) {
        options.destinationDirectory(destinationDir);
    }
    boolean isModule = isModule();
    JavaModuleDetector javaModuleDetector = getJavaModuleDetector();
    options.classpath(new ArrayList<>(javaModuleDetector.inferClasspath(isModule, getClasspath()).getFiles()));
    options.modulePath(new ArrayList<>(javaModuleDetector.inferModulePath(isModule, getClasspath()).getFiles()));
    if (options.getBootClasspath() != null && !options.getBootClasspath().isEmpty()) {
        // Added so JavaDoc has the same behavior as JavaCompile regarding the bootClasspath
        getProjectLayout().files(options.getBootClasspath()).getAsPath();
    }
    // See #19726 for more
    if (isModule) {
        List<File> sourceDirectories = getSource().getFiles().stream().map(File::getParentFile).distinct().sorted().collect(Collectors.toList());
        options.setSourcePath(sourceDirectories);
    }
    if (!isTrue(options.getWindowTitle()) && isTrue(getTitle())) {
        options.windowTitle(getTitle());
    }
    if (!isTrue(options.getDocTitle()) && isTrue(getTitle())) {
        options.setDocTitle(getTitle());
    }
    String maxMemory = getMaxMemory();
    if (maxMemory != null) {
        final List<String> jFlags = options.getJFlags();
        final Iterator<String> jFlagsIt = jFlags.iterator();
        boolean containsXmx = false;
        while (!containsXmx && jFlagsIt.hasNext()) {
            final String jFlag = jFlagsIt.next();
            if (jFlag.startsWith("-Xmx")) {
                containsXmx = true;
            }
        }
        if (!containsXmx) {
            options.jFlags("-Xmx" + maxMemory);
        }
    }
    options.setSourceNames(sourceNames());
    executeExternalJavadoc(options);
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) JavaModuleDetector(org.gradle.internal.jvm.JavaModuleDetector) File(java.io.File) StandardJavadocDocletOptions(org.gradle.external.javadoc.StandardJavadocDocletOptions) TaskAction(org.gradle.api.tasks.TaskAction)

Example 4 with JavaModuleDetector

use of org.gradle.internal.jvm.JavaModuleDetector in project gradle by gradle.

the class Test method createTestExecutionSpec.

/**
 * {@inheritDoc}
 *
 * @since 4.4
 */
@Override
protected JvmTestExecutionSpec createTestExecutionSpec() {
    validateToolchainConfiguration();
    JavaForkOptions javaForkOptions = getForkOptionsFactory().newJavaForkOptions();
    copyTo(javaForkOptions);
    JavaModuleDetector javaModuleDetector = getJavaModuleDetector();
    boolean testIsModule = javaModuleDetector.isModule(modularity.getInferModulePath().get(), getTestClassesDirs());
    FileCollection classpath = javaModuleDetector.inferClasspath(testIsModule, stableClasspath);
    FileCollection modulePath = javaModuleDetector.inferModulePath(testIsModule, stableClasspath);
    return new JvmTestExecutionSpec(getTestFramework(), classpath, modulePath, getCandidateClassFiles(), isScanForTestClasses(), getTestClassesDirs(), getPath(), getIdentityPath(), getForkEvery(), javaForkOptions, getMaxParallelForks(), getPreviousFailedTestClasses());
}
Also used : JavaForkOptions(org.gradle.process.JavaForkOptions) JavaModuleDetector(org.gradle.internal.jvm.JavaModuleDetector) ConfigurableFileCollection(org.gradle.api.file.ConfigurableFileCollection) FileCollection(org.gradle.api.file.FileCollection) JvmTestExecutionSpec(org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec)

Example 5 with JavaModuleDetector

use of org.gradle.internal.jvm.JavaModuleDetector in project gradle by gradle.

the class JavaCompile method createSpec.

DefaultJavaCompileSpec createSpec() {
    validateConfiguration();
    List<File> sourcesRoots = CompilationSourceDirs.inferSourceRoots((FileTreeInternal) getStableSources().getAsFileTree());
    JavaModuleDetector javaModuleDetector = getJavaModuleDetector();
    boolean isModule = JavaModuleDetector.isModuleSource(modularity.getInferModulePath().get(), sourcesRoots);
    boolean toolchainCompatibleWithJava8 = isToolchainCompatibleWithJava8();
    boolean isSourcepathUserDefined = compileOptions.getSourcepath() != null && !compileOptions.getSourcepath().isEmpty();
    final DefaultJavaCompileSpec spec = createBaseSpec();
    spec.setDestinationDir(getDestinationDirectory().getAsFile().get());
    spec.setWorkingDir(getProjectLayout().getProjectDirectory().getAsFile());
    spec.setTempDir(getTemporaryDir());
    spec.setCompileClasspath(ImmutableList.copyOf(javaModuleDetector.inferClasspath(isModule, getClasspath())));
    spec.setModulePath(ImmutableList.copyOf(javaModuleDetector.inferModulePath(isModule, getClasspath())));
    if (isModule && !isSourcepathUserDefined) {
        compileOptions.setSourcepath(getProjectLayout().files(sourcesRoots));
    }
    spec.setAnnotationProcessorPath(compileOptions.getAnnotationProcessorPath() == null ? ImmutableList.of() : ImmutableList.copyOf(compileOptions.getAnnotationProcessorPath()));
    configureCompatibilityOptions(spec);
    spec.setSourcesRoots(sourcesRoots);
    if (!toolchainCompatibleWithJava8) {
        spec.getCompileOptions().setHeaderOutputDirectory(null);
    }
    return spec;
}
Also used : DefaultJavaCompileSpec(org.gradle.api.internal.tasks.compile.DefaultJavaCompileSpec) JavaModuleDetector(org.gradle.internal.jvm.JavaModuleDetector) OutputFile(org.gradle.api.tasks.OutputFile) File(java.io.File)

Aggregations

JavaModuleDetector (org.gradle.internal.jvm.JavaModuleDetector)5 File (java.io.File)2 TaskAction (org.gradle.api.tasks.TaskAction)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Configuration (org.gradle.api.artifacts.Configuration)1 DependencyHandler (org.gradle.api.artifacts.dsl.DependencyHandler)1 ConfigurableFileCollection (org.gradle.api.file.ConfigurableFileCollection)1 FileCollection (org.gradle.api.file.FileCollection)1 StartScriptGenerator (org.gradle.api.internal.plugins.StartScriptGenerator)1 UnixStartScriptGenerator (org.gradle.api.internal.plugins.UnixStartScriptGenerator)1 WindowsStartScriptGenerator (org.gradle.api.internal.plugins.WindowsStartScriptGenerator)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 DefaultJavaCompileSpec (org.gradle.api.internal.tasks.compile.DefaultJavaCompileSpec)1 JvmTestExecutionSpec (org.gradle.api.internal.tasks.testing.JvmTestExecutionSpec)1 OutputFile (org.gradle.api.tasks.OutputFile)1 StandardJavadocDocletOptions (org.gradle.external.javadoc.StandardJavadocDocletOptions)1 IdeDependencySet (org.gradle.plugins.ide.internal.resolver.IdeDependencySet)1 UnresolvedIdeDependencyHandler (org.gradle.plugins.ide.internal.resolver.UnresolvedIdeDependencyHandler)1 JavaForkOptions (org.gradle.process.JavaForkOptions)1