private void configureAbstractJettyTask(final Project project, final JettyPluginConvention jettyConvention, AbstractJettyRunTask jettyTask) { jettyTask.setDaemon(false); jettyTask.setReload(RELOAD_AUTOMATIC); jettyTask.setScanIntervalSeconds(0); jettyTask.getConventionMapping().map("contextPath", new Callable<Object>() { public Object call() throws Exception { return ((War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME)).getBaseName(); } }); jettyTask.getConventionMapping().map("httpPort", new Callable<Object>() { public Object call() throws Exception { return jettyConvention.getHttpPort(); } }); jettyTask.getConventionMapping().map("stopPort", new Callable<Object>() { public Object call() throws Exception { return jettyConvention.getStopPort(); } }); jettyTask.getConventionMapping().map("stopKey", new Callable<Object>() { public Object call() throws Exception { return jettyConvention.getStopKey(); } }); }
@Override public void apply(Project project) { jSassBasePlugin = project.getPlugins().apply(JSassBasePlugin.class); project.getPlugins().apply(WarPlugin.class); SassCompile compileWebappSass = project.getTasks().create("compileWebappSass", SassCompile.class); compileWebappSass.setGroup(BasePlugin.BUILD_GROUP); compileWebappSass.setDescription("Compile sass and scss files for the webapp"); WarPluginConvention warPluginConvention = project.getConvention().getPlugin(WarPluginConvention.class); compileWebappSass.setSourceDir(warPluginConvention.getWebAppDir()); project.afterEvaluate(p -> { War war = (War) p.getTasks().getByName(WarPlugin.WAR_TASK_NAME); if (jSassBasePlugin.getExtension().isInplace()) { compileWebappSass.setDestinationDir(warPluginConvention.getWebAppDir()); } else { compileWebappSass.setDestinationDir(new File(p.getBuildDir(), "generated/webappCss")); war.from(compileWebappSass.getDestinationDir()); } war.dependsOn(compileWebappSass); }); }
@Override public void apply(Project project) { this.project = project; project.getPluginManager().apply(WarPlugin.class); project.getTasks().withType(War.class, warTask -> { NamedDomainObjectContainer<WarOverlay> warOverlays = project.container(WarOverlay.class, name -> new WarOverlay(name, warTask)); warTask.getExtensions().add("overlays", warOverlays); project.afterEvaluate(p -> warOverlays.all(overlay -> { if (overlay.isEnabled()) { configureOverlay(overlay); } else { Collection<CopySpecInternal> children = (Collection<CopySpecInternal>) overlay.getWarTask().getRootSpec().getChildren(); children.remove(overlay.getWarCopySpec()); } })); }); }
@Override public void apply(Project project) { project.getPlugins().apply(WarPlugin.class); WarAttachClassesConvention attachClassesConvention = new WarAttachClassesConvention(); War war = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME); war.getConvention().getPlugins().put("attachClasses", attachClassesConvention); project.afterEvaluate(p -> { if (attachClassesConvention.isAttachClasses()) { Jar jar = (Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME); jar.setClassifier(attachClassesConvention.getClassesClassifier()); project.getArtifacts().add(Dependency.ARCHIVES_CONFIGURATION, jar); } }); }
private Project setUpTestProject(String buildFileName) throws IOException { Path buildFile = testProjectDir.getRoot().toPath().resolve("build.gradle"); InputStream buildFileContent = getClass() .getClassLoader() .getResourceAsStream( "projects/AppEnginePluginTest/Extension/" + buildFileName + ".gradle"); Files.copy(buildFileContent, buildFile); Path webInf = testProjectDir.getRoot().toPath().resolve("src/main/webapp/WEB-INF"); Files.createDirectories(webInf); File appengineWebXml = Files.createFile(webInf.resolve("appengine-web.xml")).toFile(); Files.write(appengineWebXml.toPath(), "<appengine-web-app/>".getBytes(Charsets.UTF_8)); Project p = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build(); p.getPluginManager().apply(JavaPlugin.class); p.getPluginManager().apply(WarPlugin.class); p.getPluginManager().apply(AppEngineStandardPlugin.class); ((ProjectInternal) p).evaluate(); return p; }
@Test public void testDefaultConfiguration() throws IOException { File appengineWebXml = new File(testProjectDir.getRoot(), "src/main/webapp/WEB-INF/appengine-web.xml"); appengineWebXml.getParentFile().mkdirs(); appengineWebXml.createNewFile(); Files.write(appengineWebXml.toPath(), "<web-app/>".getBytes()); Project project = ProjectBuilder.builder().withProjectDir(testProjectDir.getRoot()).build(); project.getPluginManager().apply(JavaPlugin.class); project.getPluginManager().apply(WarPlugin.class); project.getPluginManager().apply(AppEngineStandardPlugin.class); project.getPluginManager().apply(SourceContextPlugin.class); ((ProjectInternal) project).evaluate(); ExtensionAware ext = (ExtensionAware) project.getExtensions().getByName(AppEngineCorePlugin.APPENGINE_EXTENSION); GenRepoInfoFileExtension genRepoInfoExt = new ExtensionUtil(ext).get(SourceContextPlugin.SOURCE_CONTEXT_EXTENSION); Assert.assertEquals( new File(project.getBuildDir(), "sourceContext"), genRepoInfoExt.getOutputDirectory()); }
/** * Returns the most suitable Archive-Task for wrapping in the swarm jar - in the following order: * * 1. Custom-JAR-Task defined in SwarmExtension 'archiveTask' * 2. WAR-Task * 3. JAR-Task */ private Jar getArchiveTask(Project project) { TaskCollection<Jar> existingArchiveTasks = project.getTasks().withType(Jar.class); Jar customArchiveTask = project.getExtensions().getByType(SwarmExtension.class).getArchiveTask(); if (customArchiveTask != null) { return existingArchiveTasks.getByName(customArchiveTask.getName()); } else if (existingArchiveTasks.findByName(WarPlugin.WAR_TASK_NAME) != null) { return existingArchiveTasks.getByName(WarPlugin.WAR_TASK_NAME); } else if (existingArchiveTasks.findByName(JavaPlugin.JAR_TASK_NAME) != null) { return existingArchiveTasks.getByName(JavaPlugin.JAR_TASK_NAME); } return null; }
@Override public void apply(final Project project) { Logger logger = project.getLogger(); logger.info("applying jsweet plugin"); if (!project.getPlugins().hasPlugin(JavaPlugin.class) && !project.getPlugins().hasPlugin(WarPlugin.class)) { logger.error("No java or war plugin detected. Enable java or war plugin."); throw new IllegalStateException("No java or war plugin detected. Enable java or war plugin."); } JSweetPluginExtension extension = project.getExtensions().create("jsweet", JSweetPluginExtension.class); JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class); SourceSetContainer sourceSets = javaPluginConvention.getSourceSets(); SourceSet mainSources = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); JSweetTranspileTask task = project.getTasks().create("jsweet", JSweetTranspileTask.class); task.setGroup("generate"); task.dependsOn(JavaPlugin.COMPILE_JAVA_TASK_NAME); task.setConfiguration(extension); task.setSources(mainSources.getAllJava()); task.setClasspath(mainSources.getCompileClasspath()); JSweetCleanTask cleanTask = project.getTasks().create("jsweetClean", JSweetCleanTask.class); cleanTask.setConfiguration(extension); }
public void configure(Project project, JettyOption jettyOption, File jettyConf) { ConfigurationContainer configs = project.getConfigurations(); Configuration runtimeConf = configs.getByName(WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME); Configuration jettyClassPath = configs.getByName(PwtLibPlugin.CONF_JETTY); configureJavaArgs(jettyOption); addClassPath(jettyClassPath.getAsPath()); addClassPath(runtimeConf.getAsPath()); if (jettyOption.getLogRequestFile() != null) { ResourceUtils.ensureDir(jettyOption.getLogRequestFile().getParentFile()); addArg("--log", jettyOption.getLogRequestFile()); } if (jettyOption.getLogFile() != null) { ResourceUtils.ensureDir(jettyOption.getLogFile().getParentFile()); addArg("--out", jettyOption.getLogFile()); } addArg("--host", jettyOption.getBindAddress()); addArg("--port", jettyOption.getPort()); addArg("--stop-port", jettyOption.getStopPort()); addArg("--stop-key", jettyOption.getStopKey()); addArg(jettyConf.getAbsolutePath()); }
/** * Setup the the 'providedCompile' and 'providedRuntime' configurations, just like War. * TODO See if we can recursively get all the dependent projects and apply it to them too. * But it would have to be a future action. */ public static void configureProvidedConfigurations(final Project project) { ConfigurationContainer configurationContainer = project.getConfigurations(); Configuration provideCompileConfiguration = configurationContainer.findByName(WarPlugin.PROVIDED_COMPILE_CONFIGURATION_NAME); if (provideCompileConfiguration==null) { provideCompileConfiguration = configurationContainer.create(WarPlugin.PROVIDED_COMPILE_CONFIGURATION_NAME) .setVisible(false) .setDescription("Additional compile classpath for libraries that should not be part of the archive."); configurationContainer.getByName(JavaPlugin.COMPILE_CONFIGURATION_NAME).extendsFrom(provideCompileConfiguration); } Configuration provideRuntimeConfiguration = configurationContainer.findByName(WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME); if (provideRuntimeConfiguration==null) { provideRuntimeConfiguration = configurationContainer.create(WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME) .setVisible(false) .extendsFrom(provideCompileConfiguration) .setDescription("Additional runtime classpath for libraries that should not be part of the archive."); configurationContainer.getByName(JavaPlugin.RUNTIME_CONFIGURATION_NAME).extendsFrom(provideRuntimeConfiguration); } }
public void apply(Project project) { DeprecationLogger.nagUserOfPluginReplacedWithExternalOne("Jetty", "Gretty (https://github.com/akhikhl/gretty)"); project.getPluginManager().apply(WarPlugin.class); JettyPluginConvention jettyConvention = new JettyPluginConvention(); Convention convention = project.getConvention(); convention.getPlugins().put("jetty", jettyConvention); configureMappingRules(project, jettyConvention); configureJettyRun(project); configureJettyRunWar(project); configureJettyStop(project, jettyConvention); }
private void configureJettyStop(Project project, final JettyPluginConvention jettyConvention) { JettyStop jettyStop = project.getTasks().create(JETTY_STOP, JettyStop.class); jettyStop.setDescription("Stops Jetty."); jettyStop.setGroup(WarPlugin.WEB_APP_GROUP); jettyStop.getConventionMapping().map("stopPort", new Callable<Object>() { public Object call() throws Exception { return jettyConvention.getStopPort(); } }); jettyStop.getConventionMapping().map("stopKey", new Callable<Object>() { public Object call() throws Exception { return jettyConvention.getStopKey(); } }); }
public WtpClasspathAttributeSupport(Project project, EclipseModel model) { isUtilityProject = !project.getPlugins().hasPlugin(WarPlugin.class) && !project.getPlugins().hasPlugin(EarPlugin.class); EclipseWtp eclipseWtp = model.getWtp(); EclipseWtpComponent wtpComponent = eclipseWtp.getComponent(); libDirName = wtpComponent.getLibDeployPath(); Set<Configuration> rootConfigs = wtpComponent.getRootConfigurations(); Set<Configuration> libConfigs = wtpComponent.getLibConfigurations(); Set<Configuration> minusConfigs = wtpComponent.getMinusConfigurations(); rootConfigFiles = collectFilesFromConfigs(rootConfigs, minusConfigs); libConfigFiles = collectFilesFromConfigs(libConfigs, minusConfigs); }
@Test public void testArchiveClassesProperty() { project.getPlugins().apply(WarPlugin.class); project.getPlugins().apply(WarArchiveClassesPlugin.class); War warTask = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME); assertThat(warTask.hasProperty("archiveClasses")).isTrue(); assertThat(warTask.property("archiveClasses")).isInstanceOf(Boolean.class); }
@Test public void testProperties() { project.getPlugins().apply(WarPlugin.class); project.getPlugins().apply(WarAttachClassesPlugin.class); War warTask = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME); assertThat(warTask.hasProperty("attachClasses")).isTrue(); assertThat(warTask.property("attachClasses")).isInstanceOf(Boolean.class); assertThat(warTask.hasProperty("classesClassifier")).isTrue(); assertThat(warTask.property("classesClassifier")).isInstanceOf(String.class); }
@Test public void testProperties() { Project project = ProjectBuilder.builder().build(); project.getPlugins().apply(WarPlugin.class); project.getPlugins().apply(WarOverlayPlugin.class); Task warTask = project.getTasks().getByName(WarPlugin.WAR_TASK_NAME); assertThat(warTask.hasProperty("overlays")).isTrue(); assertThat(warTask.property("overlays")).isInstanceOf(DomainObjectCollection.class); }
/** * @see me.seeber.gradle.plugin.AbstractProjectConfigPlugin#initialize() */ @Override public void initialize() { try { // HACK to avoid NullPointerException during resource loading URLConnection dummyConnection = new URLConnection(new URL("file:///")) { @Override public void connect() throws IOException { throw new IOException(); } }; dummyConnection.setDefaultUseCaches(false); } catch (IOException e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } getProject().getPlugins().apply(ProjectConfigPlugin.class); getProject().getPlugins().apply(EclipsePlugin.class); getProject().getPlugins().withType(WarPlugin.class, war -> { getProject().getPlugins().apply(EclipseWtpPlugin.class); }); getProject().getPlugins().withType(JavaPlugin.class, java -> { getProject().getConfigurations().create(ECLIPSE_ANNOTATIONS_CONFIGURATION, c -> { c.setDescription("Classpath used when generating Eclipse external annotations from JAR files"); c.setVisible(false); c.setTransitive(true); c.extendsFrom( getProject().getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)); c.getDependencies().add(getProject().getDependencies().create("com.google.code.findbugs:jsr305:3.0.1")); }); }); }
@Override public void apply(final Project project) { LOGGER.debug("apply pwt plugin"); project.getPlugins().apply(PwtLibPlugin.class); project.getPlugins().apply(WarPlugin.class); // createSetUpTask(project); createCheckTask(project); createCompileTask(project); createCodeServerTask(project); createDevTask(project); createRunTask(project); createStopTask(project); }
public void apply(Project project) { project.getPlugins().apply(WarPlugin.class); JettyPluginConvention jettyConvention = new JettyPluginConvention(); Convention convention = project.getConvention(); convention.getPlugins().put("jetty", jettyConvention); configureMappingRules(project, jettyConvention); configureJettyRun(project); configureJettyRunWar(project); configureJettyStop(project, jettyConvention); }
private Object getWebXml(Project project) { War war = (War) project.getTasks().getByName(WarPlugin.WAR_TASK_NAME); File webXml; if (war.getWebXml() != null) { webXml = war.getWebXml(); } else { webXml = new File(getWarConvention(project).getWebAppDir(), "WEB-INF/web.xml"); } return webXml; }
/** * Helper to get all the provided, providedRuntime, and provdedCompile files (jars) * from a project. non-recursively */ private static Set<File> getProvidedXFiles(final Project project) { Set<File> set = new HashSet<File>(); set.addAll(getConfigurationFiles(project, WarPlugin.PROVIDED_RUNTIME_CONFIGURATION_NAME)); set.addAll(getConfigurationFiles(project, "provided")); //from propdeps and maven set.addAll(getConfigurationFiles(project, WarPlugin.PROVIDED_COMPILE_CONFIGURATION_NAME)); return set; }
@Override public void apply(final Project project) { boolean javaPlugin = project.getPlugins().hasPlugin(JavaPlugin.class); boolean warPlugin = project.getPlugins().hasPlugin(WarPlugin.class); final Logger logger = project.getLogger(); if (!(javaPlugin && warPlugin)) { logger.error("st-js plugin can only be applied if jar or war plugin is applied, too!"); throw new IllegalStateException("st-js plugin can only be applied if jar or war plugin is applied, too!"); } final JavaPluginConvention javaPluginConvention = project.getConvention().getPlugin(JavaPluginConvention.class); final SourceSet main = javaPluginConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); final SourceDirectorySet allJava = main.getAllJava(); if (allJava.getSrcDirs().size() != 1) { throw new IllegalStateException("Only a single source directory is supported!"); } final GenerateStJsTask task = project.getTasks().create("stjs", GenerateStJsTask.class); task.setClasspath( main.getCompileClasspath() ); task.setWar(warPlugin); File generatedSourcesDirectory; if (warPlugin) { generatedSourcesDirectory = new File(project.getBuildDir(), "stjs"); project.getTasks().getByPath(WarPlugin.WAR_TASK_NAME).dependsOn(task); } else { generatedSourcesDirectory = main.getOutput().getClassesDir(); project.getTasks().getByPath(JavaPlugin.JAR_TASK_NAME).dependsOn(task); } task.setGeneratedSourcesDirectory(generatedSourcesDirectory); task.setCompileSourceRoots(allJava); task.setOutput(main.getOutput()); }
private void applyEclipseWtpPluginOnWebProjects(Project project) { Action<Plugin<Project>> action = createActionApplyingEclipseWtpPlugin(); project.getPlugins().withType(WarPlugin.class, action); project.getPlugins().withType(EarPlugin.class, action); }
private void configureEclipseWtpFacet(final Project project, final EclipseModel eclipseModel) { maybeAddTask(project, this, ECLIPSE_WTP_FACET_TASK_NAME, GenerateEclipseWtpFacet.class, new Action<GenerateEclipseWtpFacet>() { @Override public void execute(final GenerateEclipseWtpFacet task) { //task properties: task.setDescription("Generates the Eclipse WTP facet settings file."); task.setInputFile(project.file(".settings/org.eclipse.wst.common.project.facet.core.xml")); task.setOutputFile(project.file(".settings/org.eclipse.wst.common.project.facet.core.xml")); //model properties: eclipseModel.getWtp().setFacet(task.getFacet()); project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() { @Override public void execute(JavaPlugin javaPlugin) { if (hasWarOrEarPlugin(project)) { return; } ((IConventionAware) task.getFacet()).getConventionMapping().map("facets", new Callable<List<Facet>>() { @Override public List<Facet> call() throws Exception { return Lists.newArrayList( new Facet(Facet.FacetType.fixed, "jst.java", null), new Facet(Facet.FacetType.installed, "jst.utility", "1.0"), new Facet(Facet.FacetType.installed, "jst.java", toJavaFacetVersion(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility())) ); } }); } }); project.getPlugins().withType(WarPlugin.class, new Action<WarPlugin>() { @Override public void execute(WarPlugin warPlugin) { ((IConventionAware) task.getFacet()).getConventionMapping().map("facets", new Callable<List<Facet>>() { @Override public List<Facet> call() throws Exception { return Lists.newArrayList( new Facet(Facet.FacetType.fixed, "jst.java", null), new Facet(Facet.FacetType.fixed, "jst.web", null), new Facet(Facet.FacetType.installed, "jst.web", "2.4"), new Facet(Facet.FacetType.installed, "jst.java", toJavaFacetVersion(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility())) ); } }); } }); project.getPlugins().withType(EarPlugin.class, new Action<EarPlugin>() { @Override public void execute(EarPlugin earPlugin) { ((IConventionAware) task.getFacet()).getConventionMapping().map("facets", new Callable<List<Facet>>() { @Override public List<Facet> call() throws Exception { return Lists.newArrayList( new Facet(Facet.FacetType.fixed, "jst.ear", null), new Facet(Facet.FacetType.installed, "jst.ear", "5.0") ); } }); } }); } }); }
private boolean hasWarOrEarPlugin(Project project) { return project.getPlugins().hasPlugin(WarPlugin.class) || project.getPlugins().hasPlugin(EarPlugin.class); }
@Override protected Class<? extends Plugin> getPluginClass() { return WarPlugin.class; }
/** Run the project builder and return an evaluated project. */ public Project applyStandardProjectBuilder() throws IOException { return applyProjectBuilder(JavaPlugin.class, WarPlugin.class, AppEngineStandardPlugin.class); }
/** Run the project builder and return an evaluated project. */ public Project applyFlexibleWarProjectBuilder() throws IOException { return applyProjectBuilder(JavaPlugin.class, WarPlugin.class, AppEngineFlexiblePlugin.class); }
/** Run the project builder and return an evaluated project. */ public Project applyAutoDetectingProjectBuilder() throws IOException { return applyProjectBuilder(JavaPlugin.class, WarPlugin.class, AppEnginePlugin.class); }